| | @@ -1165,11 +1165,11 @@ |
| 1165 | 1165 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1166 | 1166 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1167 | 1167 | */ |
| 1168 | 1168 | #define SQLITE_VERSION "3.31.0" |
| 1169 | 1169 | #define SQLITE_VERSION_NUMBER 3031000 |
| 1170 | | -#define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3" |
| 1170 | +#define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68" |
| 1171 | 1171 | |
| 1172 | 1172 | /* |
| 1173 | 1173 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1174 | 1174 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1175 | 1175 | ** |
| | @@ -1576,10 +1576,11 @@ |
| 1576 | 1576 | #define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8)) |
| 1577 | 1577 | #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) |
| 1578 | 1578 | #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) |
| 1579 | 1579 | #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) |
| 1580 | 1580 | #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8)) |
| 1581 | +#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8)) |
| 1581 | 1582 | #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) |
| 1582 | 1583 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 1583 | 1584 | #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 1584 | 1585 | #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8)) |
| 1585 | 1586 | #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8)) |
| | @@ -3303,10 +3304,29 @@ |
| 3303 | 3304 | ** the legacy [double-quoted string literal] misfeature for DDL statements, |
| 3304 | 3305 | ** such as CREATE TABLE and CREATE INDEX. The |
| 3305 | 3306 | ** default value of this setting is determined by the [-DSQLITE_DQS] |
| 3306 | 3307 | ** compile-time option. |
| 3307 | 3308 | ** </dd> |
| 3309 | +** |
| 3310 | +** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]] |
| 3311 | +** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td> |
| 3312 | +** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells the SQLite to |
| 3313 | +** assume that database schemas are untainted by malicious content. |
| 3314 | +** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite |
| 3315 | +** takes additional defensive steps to protect the application from harm |
| 3316 | +** including, but not limited to, the following: |
| 3317 | +** <ul> |
| 3318 | +** <li> Prohibit the use of SQL functions inside triggers, views, |
| 3319 | +** CHECK constraints, DEFAULT VALUEs, index definitions, and/or |
| 3320 | +** generated columns unless those functions are tagged |
| 3321 | +** with [SQLITE_INNOCUOUS]. |
| 3322 | +** <li> Pohibit the use of virtual tables inside of triggers and/or views |
| 3323 | +** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS]. |
| 3324 | +** </ul> |
| 3325 | +** This setting defaults to "on" for legacy compatibility, however |
| 3326 | +** all applications are advised to turn it off if possible. |
| 3327 | +** </dd> |
| 3308 | 3328 | ** |
| 3309 | 3329 | ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]] |
| 3310 | 3330 | ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td> |
| 3311 | 3331 | ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates |
| 3312 | 3332 | ** the legacy file format flag. When activated, this flag causes all newly |
| | @@ -3344,11 +3364,12 @@ |
| 3344 | 3364 | #define SQLITE_DBCONFIG_LEGACY_ALTER_TABLE 1012 /* int int* */ |
| 3345 | 3365 | #define SQLITE_DBCONFIG_DQS_DML 1013 /* int int* */ |
| 3346 | 3366 | #define SQLITE_DBCONFIG_DQS_DDL 1014 /* int int* */ |
| 3347 | 3367 | #define SQLITE_DBCONFIG_ENABLE_VIEW 1015 /* int int* */ |
| 3348 | 3368 | #define SQLITE_DBCONFIG_LEGACY_FILE_FORMAT 1016 /* int int* */ |
| 3349 | | -#define SQLITE_DBCONFIG_MAX 1016 /* Largest DBCONFIG */ |
| 3369 | +#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */ |
| 3370 | +#define SQLITE_DBCONFIG_MAX 1017 /* Largest DBCONFIG */ |
| 3350 | 3371 | |
| 3351 | 3372 | /* |
| 3352 | 3373 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 3353 | 3374 | ** METHOD: sqlite3 |
| 3354 | 3375 | ** |
| | @@ -6035,16 +6056,30 @@ |
| 6035 | 6056 | ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument |
| 6036 | 6057 | ** to [sqlite3_create_function()], [sqlite3_create_function16()], or |
| 6037 | 6058 | ** [sqlite3_create_function_v2()]. |
| 6038 | 6059 | ** |
| 6039 | 6060 | ** The SQLITE_DETERMINISTIC flag means that the new function always gives |
| 6040 | | -** the same output when the input parameters are the same. The abs() function |
| 6041 | | -** is deterministic, for example, but randomblob() is not. Functions must |
| 6061 | +** the same output when the input parameters are the same. |
| 6062 | +** The [abs|abs() function] is deterministic, for example, but |
| 6063 | +** [randomblob|randomblob()] is not. Functions must |
| 6042 | 6064 | ** be deterministic in order to be used in certain contexts such as |
| 6043 | 6065 | ** [CHECK constraints] or [generated columns]. SQLite might also optimize |
| 6044 | 6066 | ** deterministic functions by factoring them out of inner loops. |
| 6045 | 6067 | ** |
| 6068 | +** The SQLITE_INNOCUOUS flag means that the new function is unlikely |
| 6069 | +** to cause problems even if misused. An innocuous function should have |
| 6070 | +** no side effects and consume few resources. The [abs|abs() function] |
| 6071 | +** is an example of an innocuous function. |
| 6072 | +** The [load_extension() SQL function] is not innocuous because of its |
| 6073 | +** side effects. Some heightened security settings |
| 6074 | +** ([SQLITE_DBCONFIG_UNSAFE_FUNC_IN_VIEW]) |
| 6075 | +** disable the use of SQLlfunctions inside views and triggers unless |
| 6076 | +** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions |
| 6077 | +** are innocuous. Developers are advised to avoid using the |
| 6078 | +** SQLITE_INNOCUOUS flag for application-defined functions unless the |
| 6079 | +** function is specifically intended for use inside of views and triggers. |
| 6080 | +** |
| 6046 | 6081 | ** The SQLITE_DIRECTONLY flag means that the function may only be invoked |
| 6047 | 6082 | ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is |
| 6048 | 6083 | ** a security feature which is recommended for all |
| 6049 | 6084 | ** [application-defined SQL functions] that have side-effects. This flag |
| 6050 | 6085 | ** prevents an attacker from adding triggers and views to a schema then |
| | @@ -6060,10 +6095,11 @@ |
| 6060 | 6095 | ** sqlite3_value_subtype() will always return 0). |
| 6061 | 6096 | */ |
| 6062 | 6097 | #define SQLITE_DETERMINISTIC 0x000000800 |
| 6063 | 6098 | #define SQLITE_DIRECTONLY 0x000080000 |
| 6064 | 6099 | #define SQLITE_SUBTYPE 0x000100000 |
| 6100 | +#define SQLITE_INNOCUOUS 0x000200000 |
| 6065 | 6101 | |
| 6066 | 6102 | /* |
| 6067 | 6103 | ** CAPI3REF: Deprecated Functions |
| 6068 | 6104 | ** DEPRECATED |
| 6069 | 6105 | ** |
| | @@ -6591,31 +6627,32 @@ |
| 6591 | 6627 | ** <li> [SQLITE_UTF16BE], |
| 6592 | 6628 | ** <li> [SQLITE_UTF16], or |
| 6593 | 6629 | ** <li> [SQLITE_UTF16_ALIGNED]. |
| 6594 | 6630 | ** </ul>)^ |
| 6595 | 6631 | ** ^The eTextRep argument determines the encoding of strings passed |
| 6596 | | -** to the collating function callback, xCallback. |
| 6632 | +** to the collating function callback, xCompare. |
| 6597 | 6633 | ** ^The [SQLITE_UTF16] and [SQLITE_UTF16_ALIGNED] values for eTextRep |
| 6598 | 6634 | ** force strings to be UTF16 with native byte order. |
| 6599 | 6635 | ** ^The [SQLITE_UTF16_ALIGNED] value for eTextRep forces strings to begin |
| 6600 | 6636 | ** on an even byte address. |
| 6601 | 6637 | ** |
| 6602 | 6638 | ** ^The fourth argument, pArg, is an application data pointer that is passed |
| 6603 | 6639 | ** through as the first argument to the collating function callback. |
| 6604 | 6640 | ** |
| 6605 | | -** ^The fifth argument, xCallback, is a pointer to the collating function. |
| 6641 | +** ^The fifth argument, xCompare, is a pointer to the collating function. |
| 6606 | 6642 | ** ^Multiple collating functions can be registered using the same name but |
| 6607 | 6643 | ** with different eTextRep parameters and SQLite will use whichever |
| 6608 | 6644 | ** function requires the least amount of data transformation. |
| 6609 | | -** ^If the xCallback argument is NULL then the collating function is |
| 6645 | +** ^If the xCompare argument is NULL then the collating function is |
| 6610 | 6646 | ** deleted. ^When all collating functions having the same name are deleted, |
| 6611 | 6647 | ** that collation is no longer usable. |
| 6612 | 6648 | ** |
| 6613 | 6649 | ** ^The collating function callback is invoked with a copy of the pArg |
| 6614 | 6650 | ** application data pointer and with two strings in the encoding specified |
| 6615 | | -** by the eTextRep argument. The collating function must return an |
| 6616 | | -** integer that is negative, zero, or positive |
| 6651 | +** by the eTextRep argument. The two integer parameters to the collating |
| 6652 | +** function callback are the length of the two strings, in bytes. The collating |
| 6653 | +** function must return an integer that is negative, zero, or positive |
| 6617 | 6654 | ** if the first string is less than, equal to, or greater than the second, |
| 6618 | 6655 | ** respectively. A collating function must always return the same answer |
| 6619 | 6656 | ** given the same inputs. If two or more collating functions are registered |
| 6620 | 6657 | ** to the same collation name (using different eTextRep values) then all |
| 6621 | 6658 | ** must give an equivalent answer when invoked with equivalent strings. |
| | @@ -9907,11 +9944,11 @@ |
| 9907 | 9944 | ** [sqlite3_vtab_config()] interface that [virtual table] implementations |
| 9908 | 9945 | ** can use to customize and optimize their behavior. |
| 9909 | 9946 | ** |
| 9910 | 9947 | ** <dl> |
| 9911 | 9948 | ** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]] |
| 9912 | | -** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT |
| 9949 | +** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT</dt> |
| 9913 | 9950 | ** <dd>Calls of the form |
| 9914 | 9951 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, |
| 9915 | 9952 | ** where X is an integer. If X is zero, then the [virtual table] whose |
| 9916 | 9953 | ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not |
| 9917 | 9954 | ** support constraints. In this configuration (which is the default) if |
| | @@ -9936,13 +9973,35 @@ |
| 9936 | 9973 | ** CONFLICT policy is REPLACE, the virtual table implementation should |
| 9937 | 9974 | ** silently replace the appropriate rows within the xUpdate callback and |
| 9938 | 9975 | ** return SQLITE_OK. Or, if this is not possible, it may return |
| 9939 | 9976 | ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT |
| 9940 | 9977 | ** constraint handling. |
| 9978 | +** </dd> |
| 9979 | +** |
| 9980 | +** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| 9981 | +** <dd>Calls of the form |
| 9982 | +** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the |
| 9983 | +** the [xConnect] or [xCreate] methods of a [virtual table] implmentation |
| 9984 | +** identify that virtual table as being safe to use from within triggers |
| 9985 | +** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the |
| 9986 | +** virtual table can do no serious harm even if it is controlled by a |
| 9987 | +** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS |
| 9988 | +** flag unless absolutely necessary. |
| 9989 | +** </dd> |
| 9990 | +** |
| 9991 | +** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 9992 | +** <dd>Calls of the form |
| 9993 | +** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 9994 | +** the [xConnect] or [xCreate] methods of a [virtual table] implmentation |
| 9995 | +** prohibits that virtual table from being used from within triggers and |
| 9996 | +** views. |
| 9997 | +** </dd> |
| 9941 | 9998 | ** </dl> |
| 9942 | 9999 | */ |
| 9943 | 10000 | #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 |
| 10001 | +#define SQLITE_VTAB_INNOCUOUS 2 |
| 10002 | +#define SQLITE_VTAB_DIRECTONLY 3 |
| 9944 | 10003 | |
| 9945 | 10004 | /* |
| 9946 | 10005 | ** CAPI3REF: Determine The Virtual Table Conflict Policy |
| 9947 | 10006 | ** |
| 9948 | 10007 | ** This function may only be called from within a call to the [xUpdate] method |
| | @@ -14415,10 +14474,11 @@ |
| 14415 | 14474 | |
| 14416 | 14475 | /* |
| 14417 | 14476 | ** A bit in a Bitmask |
| 14418 | 14477 | */ |
| 14419 | 14478 | #define MASKBIT(n) (((Bitmask)1)<<(n)) |
| 14479 | +#define MASKBIT64(n) (((u64)1)<<(n)) |
| 14420 | 14480 | #define MASKBIT32(n) (((unsigned int)1)<<(n)) |
| 14421 | 14481 | #define ALLBITS ((Bitmask)-1) |
| 14422 | 14482 | |
| 14423 | 14483 | /* A VList object records a mapping between parameters/variables/wildcards |
| 14424 | 14484 | ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer |
| | @@ -14741,10 +14801,12 @@ |
| 14741 | 14801 | SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| 14742 | 14802 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags); |
| 14743 | 14803 | SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); |
| 14744 | 14804 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags); |
| 14745 | 14805 | SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*); |
| 14806 | +SQLITE_PRIVATE void sqlite3BtreeCursorPin(BtCursor*); |
| 14807 | +SQLITE_PRIVATE void sqlite3BtreeCursorUnpin(BtCursor*); |
| 14746 | 14808 | #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 14747 | 14809 | SQLITE_PRIVATE i64 sqlite3BtreeOffset(BtCursor*); |
| 14748 | 14810 | #endif |
| 14749 | 14811 | SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*); |
| 14750 | 14812 | SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); |
| | @@ -15027,85 +15089,85 @@ |
| 15027 | 15089 | #define OP_IfNullRow 21 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ |
| 15028 | 15090 | #define OP_SeekLT 22 /* jump, synopsis: key=r[P3@P4] */ |
| 15029 | 15091 | #define OP_SeekLE 23 /* jump, synopsis: key=r[P3@P4] */ |
| 15030 | 15092 | #define OP_SeekGE 24 /* jump, synopsis: key=r[P3@P4] */ |
| 15031 | 15093 | #define OP_SeekGT 25 /* jump, synopsis: key=r[P3@P4] */ |
| 15032 | | -#define OP_IfNoHope 26 /* jump, synopsis: key=r[P3@P4] */ |
| 15033 | | -#define OP_NoConflict 27 /* jump, synopsis: key=r[P3@P4] */ |
| 15034 | | -#define OP_NotFound 28 /* jump, synopsis: key=r[P3@P4] */ |
| 15035 | | -#define OP_Found 29 /* jump, synopsis: key=r[P3@P4] */ |
| 15036 | | -#define OP_SeekRowid 30 /* jump, synopsis: intkey=r[P3] */ |
| 15037 | | -#define OP_NotExists 31 /* jump, synopsis: intkey=r[P3] */ |
| 15038 | | -#define OP_Last 32 /* jump */ |
| 15039 | | -#define OP_IfSmaller 33 /* jump */ |
| 15040 | | -#define OP_SorterSort 34 /* jump */ |
| 15041 | | -#define OP_Sort 35 /* jump */ |
| 15042 | | -#define OP_Rewind 36 /* jump */ |
| 15043 | | -#define OP_IdxLE 37 /* jump, synopsis: key=r[P3@P4] */ |
| 15044 | | -#define OP_IdxGT 38 /* jump, synopsis: key=r[P3@P4] */ |
| 15045 | | -#define OP_IdxLT 39 /* jump, synopsis: key=r[P3@P4] */ |
| 15046 | | -#define OP_IdxGE 40 /* jump, synopsis: key=r[P3@P4] */ |
| 15047 | | -#define OP_RowSetRead 41 /* jump, synopsis: r[P3]=rowset(P1) */ |
| 15048 | | -#define OP_RowSetTest 42 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 15094 | +#define OP_IfNotOpen 26 /* jump, synopsis: if( !csr[P1] ) goto P2 */ |
| 15095 | +#define OP_IfNoHope 27 /* jump, synopsis: key=r[P3@P4] */ |
| 15096 | +#define OP_NoConflict 28 /* jump, synopsis: key=r[P3@P4] */ |
| 15097 | +#define OP_NotFound 29 /* jump, synopsis: key=r[P3@P4] */ |
| 15098 | +#define OP_Found 30 /* jump, synopsis: key=r[P3@P4] */ |
| 15099 | +#define OP_SeekRowid 31 /* jump, synopsis: intkey=r[P3] */ |
| 15100 | +#define OP_NotExists 32 /* jump, synopsis: intkey=r[P3] */ |
| 15101 | +#define OP_Last 33 /* jump */ |
| 15102 | +#define OP_IfSmaller 34 /* jump */ |
| 15103 | +#define OP_SorterSort 35 /* jump */ |
| 15104 | +#define OP_Sort 36 /* jump */ |
| 15105 | +#define OP_Rewind 37 /* jump */ |
| 15106 | +#define OP_IdxLE 38 /* jump, synopsis: key=r[P3@P4] */ |
| 15107 | +#define OP_IdxGT 39 /* jump, synopsis: key=r[P3@P4] */ |
| 15108 | +#define OP_IdxLT 40 /* jump, synopsis: key=r[P3@P4] */ |
| 15109 | +#define OP_IdxGE 41 /* jump, synopsis: key=r[P3@P4] */ |
| 15110 | +#define OP_RowSetRead 42 /* jump, synopsis: r[P3]=rowset(P1) */ |
| 15049 | 15111 | #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| 15050 | 15112 | #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */ |
| 15051 | | -#define OP_Program 45 /* jump */ |
| 15052 | | -#define OP_FkIfZero 46 /* jump, synopsis: if fkctr[P1]==0 goto P2 */ |
| 15053 | | -#define OP_IfPos 47 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 15054 | | -#define OP_IfNotZero 48 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ |
| 15055 | | -#define OP_DecrJumpZero 49 /* jump, synopsis: if (--r[P1])==0 goto P2 */ |
| 15113 | +#define OP_RowSetTest 45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 15114 | +#define OP_Program 46 /* jump */ |
| 15115 | +#define OP_FkIfZero 47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */ |
| 15116 | +#define OP_IfPos 48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 15117 | +#define OP_IfNotZero 49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */ |
| 15056 | 15118 | #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */ |
| 15057 | 15119 | #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */ |
| 15058 | 15120 | #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */ |
| 15059 | 15121 | #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */ |
| 15060 | 15122 | #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */ |
| 15061 | 15123 | #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */ |
| 15062 | 15124 | #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */ |
| 15063 | 15125 | #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */ |
| 15064 | 15126 | #define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */ |
| 15065 | | -#define OP_IncrVacuum 59 /* jump */ |
| 15066 | | -#define OP_VNext 60 /* jump */ |
| 15067 | | -#define OP_Init 61 /* jump, synopsis: Start at P2 */ |
| 15068 | | -#define OP_PureFunc 62 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 15069 | | -#define OP_Function 63 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 15070 | | -#define OP_Return 64 |
| 15071 | | -#define OP_EndCoroutine 65 |
| 15072 | | -#define OP_HaltIfNull 66 /* synopsis: if r[P3]=null halt */ |
| 15073 | | -#define OP_Halt 67 |
| 15074 | | -#define OP_Integer 68 /* synopsis: r[P2]=P1 */ |
| 15075 | | -#define OP_Int64 69 /* synopsis: r[P2]=P4 */ |
| 15076 | | -#define OP_String 70 /* synopsis: r[P2]='P4' (len=P1) */ |
| 15077 | | -#define OP_Null 71 /* synopsis: r[P2..P3]=NULL */ |
| 15078 | | -#define OP_SoftNull 72 /* synopsis: r[P1]=NULL */ |
| 15079 | | -#define OP_Blob 73 /* synopsis: r[P2]=P4 (len=P1) */ |
| 15080 | | -#define OP_Variable 74 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 15081 | | -#define OP_Move 75 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 15082 | | -#define OP_Copy 76 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 15083 | | -#define OP_SCopy 77 /* synopsis: r[P2]=r[P1] */ |
| 15084 | | -#define OP_IntCopy 78 /* synopsis: r[P2]=r[P1] */ |
| 15085 | | -#define OP_ResultRow 79 /* synopsis: output=r[P1@P2] */ |
| 15086 | | -#define OP_CollSeq 80 |
| 15087 | | -#define OP_AddImm 81 /* synopsis: r[P1]=r[P1]+P2 */ |
| 15088 | | -#define OP_RealAffinity 82 |
| 15089 | | -#define OP_Cast 83 /* synopsis: affinity(r[P1]) */ |
| 15090 | | -#define OP_Permutation 84 |
| 15091 | | -#define OP_Compare 85 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 15092 | | -#define OP_IsTrue 86 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ |
| 15093 | | -#define OP_Offset 87 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 15094 | | -#define OP_Column 88 /* synopsis: r[P3]=PX */ |
| 15095 | | -#define OP_Affinity 89 /* synopsis: affinity(r[P1@P2]) */ |
| 15096 | | -#define OP_MakeRecord 90 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 15097 | | -#define OP_Count 91 /* synopsis: r[P2]=count() */ |
| 15098 | | -#define OP_ReadCookie 92 |
| 15099 | | -#define OP_SetCookie 93 |
| 15100 | | -#define OP_ReopenIdx 94 /* synopsis: root=P2 iDb=P3 */ |
| 15101 | | -#define OP_OpenRead 95 /* synopsis: root=P2 iDb=P3 */ |
| 15102 | | -#define OP_OpenWrite 96 /* synopsis: root=P2 iDb=P3 */ |
| 15103 | | -#define OP_OpenDup 97 |
| 15104 | | -#define OP_OpenAutoindex 98 /* synopsis: nColumn=P2 */ |
| 15105 | | -#define OP_OpenEphemeral 99 /* synopsis: nColumn=P2 */ |
| 15106 | | -#define OP_SorterOpen 100 |
| 15127 | +#define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */ |
| 15128 | +#define OP_IncrVacuum 60 /* jump */ |
| 15129 | +#define OP_VNext 61 /* jump */ |
| 15130 | +#define OP_Init 62 /* jump, synopsis: Start at P2 */ |
| 15131 | +#define OP_PureFunc 63 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 15132 | +#define OP_Function 64 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 15133 | +#define OP_Return 65 |
| 15134 | +#define OP_EndCoroutine 66 |
| 15135 | +#define OP_HaltIfNull 67 /* synopsis: if r[P3]=null halt */ |
| 15136 | +#define OP_Halt 68 |
| 15137 | +#define OP_Integer 69 /* synopsis: r[P2]=P1 */ |
| 15138 | +#define OP_Int64 70 /* synopsis: r[P2]=P4 */ |
| 15139 | +#define OP_String 71 /* synopsis: r[P2]='P4' (len=P1) */ |
| 15140 | +#define OP_Null 72 /* synopsis: r[P2..P3]=NULL */ |
| 15141 | +#define OP_SoftNull 73 /* synopsis: r[P1]=NULL */ |
| 15142 | +#define OP_Blob 74 /* synopsis: r[P2]=P4 (len=P1) */ |
| 15143 | +#define OP_Variable 75 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 15144 | +#define OP_Move 76 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 15145 | +#define OP_Copy 77 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 15146 | +#define OP_SCopy 78 /* synopsis: r[P2]=r[P1] */ |
| 15147 | +#define OP_IntCopy 79 /* synopsis: r[P2]=r[P1] */ |
| 15148 | +#define OP_ResultRow 80 /* synopsis: output=r[P1@P2] */ |
| 15149 | +#define OP_CollSeq 81 |
| 15150 | +#define OP_AddImm 82 /* synopsis: r[P1]=r[P1]+P2 */ |
| 15151 | +#define OP_RealAffinity 83 |
| 15152 | +#define OP_Cast 84 /* synopsis: affinity(r[P1]) */ |
| 15153 | +#define OP_Permutation 85 |
| 15154 | +#define OP_Compare 86 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 15155 | +#define OP_IsTrue 87 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */ |
| 15156 | +#define OP_Offset 88 /* synopsis: r[P3] = sqlite_offset(P1) */ |
| 15157 | +#define OP_Column 89 /* synopsis: r[P3]=PX */ |
| 15158 | +#define OP_Affinity 90 /* synopsis: affinity(r[P1@P2]) */ |
| 15159 | +#define OP_MakeRecord 91 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 15160 | +#define OP_Count 92 /* synopsis: r[P2]=count() */ |
| 15161 | +#define OP_ReadCookie 93 |
| 15162 | +#define OP_SetCookie 94 |
| 15163 | +#define OP_ReopenIdx 95 /* synopsis: root=P2 iDb=P3 */ |
| 15164 | +#define OP_OpenRead 96 /* synopsis: root=P2 iDb=P3 */ |
| 15165 | +#define OP_OpenWrite 97 /* synopsis: root=P2 iDb=P3 */ |
| 15166 | +#define OP_OpenDup 98 |
| 15167 | +#define OP_OpenAutoindex 99 /* synopsis: nColumn=P2 */ |
| 15168 | +#define OP_OpenEphemeral 100 /* synopsis: nColumn=P2 */ |
| 15107 | 15169 | #define OP_BitAnd 101 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 15108 | 15170 | #define OP_BitOr 102 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 15109 | 15171 | #define OP_ShiftLeft 103 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 15110 | 15172 | #define OP_ShiftRight 104 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 15111 | 15173 | #define OP_Add 105 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| | @@ -15112,71 +15174,75 @@ |
| 15112 | 15174 | #define OP_Subtract 106 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 15113 | 15175 | #define OP_Multiply 107 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 15114 | 15176 | #define OP_Divide 108 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 15115 | 15177 | #define OP_Remainder 109 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 15116 | 15178 | #define OP_Concat 110 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 15117 | | -#define OP_SequenceTest 111 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15179 | +#define OP_SorterOpen 111 |
| 15118 | 15180 | #define OP_BitNot 112 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */ |
| 15119 | | -#define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */ |
| 15120 | | -#define OP_Close 114 |
| 15181 | +#define OP_SequenceTest 113 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 15182 | +#define OP_OpenPseudo 114 /* synopsis: P3 columns in r[P2] */ |
| 15121 | 15183 | #define OP_String8 115 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 15122 | | -#define OP_ColumnsUsed 116 |
| 15123 | | -#define OP_SeekHit 117 /* synopsis: seekHit=P2 */ |
| 15124 | | -#define OP_Sequence 118 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15125 | | -#define OP_NewRowid 119 /* synopsis: r[P2]=rowid */ |
| 15126 | | -#define OP_Insert 120 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15127 | | -#define OP_Delete 121 |
| 15128 | | -#define OP_ResetCount 122 |
| 15129 | | -#define OP_SorterCompare 123 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 15130 | | -#define OP_SorterData 124 /* synopsis: r[P2]=data */ |
| 15131 | | -#define OP_RowData 125 /* synopsis: r[P2]=data */ |
| 15132 | | -#define OP_Rowid 126 /* synopsis: r[P2]=rowid */ |
| 15133 | | -#define OP_NullRow 127 |
| 15134 | | -#define OP_SeekEnd 128 |
| 15135 | | -#define OP_SorterInsert 129 /* synopsis: key=r[P2] */ |
| 15136 | | -#define OP_IdxInsert 130 /* synopsis: key=r[P2] */ |
| 15137 | | -#define OP_IdxDelete 131 /* synopsis: key=r[P2@P3] */ |
| 15138 | | -#define OP_DeferredSeek 132 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15139 | | -#define OP_IdxRowid 133 /* synopsis: r[P2]=rowid */ |
| 15140 | | -#define OP_Destroy 134 |
| 15141 | | -#define OP_Clear 135 |
| 15142 | | -#define OP_ResetSorter 136 |
| 15143 | | -#define OP_CreateBtree 137 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 15144 | | -#define OP_SqlExec 138 |
| 15145 | | -#define OP_ParseSchema 139 |
| 15146 | | -#define OP_LoadAnalysis 140 |
| 15147 | | -#define OP_DropTable 141 |
| 15148 | | -#define OP_DropIndex 142 |
| 15149 | | -#define OP_DropTrigger 143 |
| 15150 | | -#define OP_IntegrityCk 144 |
| 15151 | | -#define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */ |
| 15152 | | -#define OP_Param 146 |
| 15153 | | -#define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */ |
| 15154 | | -#define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 15155 | | -#define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 15184 | +#define OP_Close 116 |
| 15185 | +#define OP_ColumnsUsed 117 |
| 15186 | +#define OP_SeekHit 118 /* synopsis: seekHit=P2 */ |
| 15187 | +#define OP_Sequence 119 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 15188 | +#define OP_NewRowid 120 /* synopsis: r[P2]=rowid */ |
| 15189 | +#define OP_Insert 121 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 15190 | +#define OP_Delete 122 |
| 15191 | +#define OP_ResetCount 123 |
| 15192 | +#define OP_SorterCompare 124 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 15193 | +#define OP_SorterData 125 /* synopsis: r[P2]=data */ |
| 15194 | +#define OP_RowData 126 /* synopsis: r[P2]=data */ |
| 15195 | +#define OP_Rowid 127 /* synopsis: r[P2]=rowid */ |
| 15196 | +#define OP_NullRow 128 |
| 15197 | +#define OP_SeekEnd 129 |
| 15198 | +#define OP_SorterInsert 130 /* synopsis: key=r[P2] */ |
| 15199 | +#define OP_IdxInsert 131 /* synopsis: key=r[P2] */ |
| 15200 | +#define OP_IdxDelete 132 /* synopsis: key=r[P2@P3] */ |
| 15201 | +#define OP_DeferredSeek 133 /* synopsis: Move P3 to P1.rowid if needed */ |
| 15202 | +#define OP_IdxRowid 134 /* synopsis: r[P2]=rowid */ |
| 15203 | +#define OP_FinishSeek 135 |
| 15204 | +#define OP_Destroy 136 |
| 15205 | +#define OP_Clear 137 |
| 15206 | +#define OP_ResetSorter 138 |
| 15207 | +#define OP_CreateBtree 139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */ |
| 15208 | +#define OP_SqlExec 140 |
| 15209 | +#define OP_ParseSchema 141 |
| 15210 | +#define OP_LoadAnalysis 142 |
| 15211 | +#define OP_DropTable 143 |
| 15212 | +#define OP_DropIndex 144 |
| 15213 | +#define OP_DropTrigger 145 |
| 15214 | +#define OP_IntegrityCk 146 |
| 15215 | +#define OP_RowSetAdd 147 /* synopsis: rowset(P1)=r[P2] */ |
| 15216 | +#define OP_Param 148 |
| 15217 | +#define OP_FkCounter 149 /* synopsis: fkctr[P1]+=P2 */ |
| 15156 | 15218 | #define OP_Real 150 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 15157 | | -#define OP_AggInverse 151 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ |
| 15158 | | -#define OP_AggStep 152 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15159 | | -#define OP_AggStep1 153 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15160 | | -#define OP_AggValue 154 /* synopsis: r[P3]=value N=P2 */ |
| 15161 | | -#define OP_AggFinal 155 /* synopsis: accum=r[P1] N=P2 */ |
| 15162 | | -#define OP_Expire 156 |
| 15163 | | -#define OP_TableLock 157 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15164 | | -#define OP_VBegin 158 |
| 15165 | | -#define OP_VCreate 159 |
| 15166 | | -#define OP_VDestroy 160 |
| 15167 | | -#define OP_VOpen 161 |
| 15168 | | -#define OP_VColumn 162 /* synopsis: r[P3]=vcolumn(P2) */ |
| 15169 | | -#define OP_VRename 163 |
| 15170 | | -#define OP_Pagecount 164 |
| 15171 | | -#define OP_MaxPgcnt 165 |
| 15172 | | -#define OP_Trace 166 |
| 15173 | | -#define OP_CursorHint 167 |
| 15174 | | -#define OP_ReleaseReg 168 /* synopsis: release r[P1@P2] mask P3 */ |
| 15175 | | -#define OP_Noop 169 |
| 15176 | | -#define OP_Explain 170 |
| 15177 | | -#define OP_Abortable 171 |
| 15219 | +#define OP_MemMax 151 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 15220 | +#define OP_OffsetLimit 152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 15221 | +#define OP_AggInverse 153 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */ |
| 15222 | +#define OP_AggStep 154 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15223 | +#define OP_AggStep1 155 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 15224 | +#define OP_AggValue 156 /* synopsis: r[P3]=value N=P2 */ |
| 15225 | +#define OP_AggFinal 157 /* synopsis: accum=r[P1] N=P2 */ |
| 15226 | +#define OP_Expire 158 |
| 15227 | +#define OP_CursorLock 159 |
| 15228 | +#define OP_CursorUnlock 160 |
| 15229 | +#define OP_TableLock 161 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 15230 | +#define OP_VBegin 162 |
| 15231 | +#define OP_VCreate 163 |
| 15232 | +#define OP_VDestroy 164 |
| 15233 | +#define OP_VOpen 165 |
| 15234 | +#define OP_VColumn 166 /* synopsis: r[P3]=vcolumn(P2) */ |
| 15235 | +#define OP_VRename 167 |
| 15236 | +#define OP_Pagecount 168 |
| 15237 | +#define OP_MaxPgcnt 169 |
| 15238 | +#define OP_Trace 170 |
| 15239 | +#define OP_CursorHint 171 |
| 15240 | +#define OP_ReleaseReg 172 /* synopsis: release r[P1@P2] mask P3 */ |
| 15241 | +#define OP_Noop 173 |
| 15242 | +#define OP_Explain 174 |
| 15243 | +#define OP_Abortable 175 |
| 15178 | 15244 | |
| 15179 | 15245 | /* Properties such as "out2" or "jump" that are specified in |
| 15180 | 15246 | ** comments following the "case" for each opcode in the vdbe.c |
| 15181 | 15247 | ** are encoded into bitvectors as follows: |
| 15182 | 15248 | */ |
| | @@ -15188,37 +15254,38 @@ |
| 15188 | 15254 | #define OPFLG_OUT3 0x20 /* out3: P3 is an output */ |
| 15189 | 15255 | #define OPFLG_INITIALIZER {\ |
| 15190 | 15256 | /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\ |
| 15191 | 15257 | /* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\ |
| 15192 | 15258 | /* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x01, 0x09, 0x09,\ |
| 15193 | | -/* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\ |
| 15194 | | -/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 15195 | | -/* 40 */ 0x01, 0x23, 0x0b, 0x26, 0x26, 0x01, 0x01, 0x03,\ |
| 15259 | +/* 24 */ 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09,\ |
| 15260 | +/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 15261 | +/* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\ |
| 15196 | 15262 | /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 15197 | | -/* 56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\ |
| 15198 | | -/* 64 */ 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10,\ |
| 15199 | | -/* 72 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 15200 | | -/* 80 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12, 0x20,\ |
| 15201 | | -/* 88 */ 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\ |
| 15263 | +/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\ |
| 15264 | +/* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\ |
| 15265 | +/* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\ |
| 15266 | +/* 80 */ 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12,\ |
| 15267 | +/* 88 */ 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 15202 | 15268 | /* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x26,\ |
| 15203 | 15269 | /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\ |
| 15204 | | -/* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x10, 0x10,\ |
| 15205 | | -/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\ |
| 15206 | | -/* 128 */ 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 15207 | | -/* 136 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15208 | | -/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x10, 0x00,\ |
| 15209 | | -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15210 | | -/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 15211 | | -/* 168 */ 0x00, 0x00, 0x00, 0x00,} |
| 15270 | +/* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,\ |
| 15271 | +/* 120 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 15272 | +/* 128 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\ |
| 15273 | +/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\ |
| 15274 | +/* 144 */ 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x10, 0x04,\ |
| 15275 | +/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15276 | +/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15277 | +/* 168 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 15278 | +} |
| 15212 | 15279 | |
| 15213 | 15280 | /* The sqlite3P2Values() routine is able to run faster if it knows |
| 15214 | 15281 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 15215 | 15282 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 15216 | 15283 | ** generated this include file strives to group all JUMP opcodes |
| 15217 | 15284 | ** together near the beginning of the list. |
| 15218 | 15285 | */ |
| 15219 | | -#define SQLITE_MX_JUMP_OPCODE 61 /* Maximum JUMP opcode */ |
| 15286 | +#define SQLITE_MX_JUMP_OPCODE 62 /* Maximum JUMP opcode */ |
| 15220 | 15287 | |
| 15221 | 15288 | /************** End of opcodes.h *********************************************/ |
| 15222 | 15289 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 15223 | 15290 | |
| 15224 | 15291 | /* |
| | @@ -15284,13 +15351,13 @@ |
| 15284 | 15351 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5); |
| 15285 | 15352 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 15286 | 15353 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 15287 | 15354 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 15288 | 15355 | #ifdef SQLITE_DEBUG |
| 15289 | | -SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask); |
| 15356 | +SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse*,int addr, int n, u32 mask, int); |
| 15290 | 15357 | #else |
| 15291 | | -# define sqlite3VdbeReleaseRegisters(P,A,N,M) |
| 15358 | +# define sqlite3VdbeReleaseRegisters(P,A,N,M,F) |
| 15292 | 15359 | #endif |
| 15293 | 15360 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 15294 | 15361 | SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type); |
| 15295 | 15362 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 15296 | 15363 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| | @@ -16377,10 +16444,29 @@ |
| 16377 | 16444 | ** New lookaside allocations are only allowed if bDisable==0. When |
| 16378 | 16445 | ** bDisable is greater than zero, sz is set to zero which effectively |
| 16379 | 16446 | ** disables lookaside without adding a new test for the bDisable flag |
| 16380 | 16447 | ** in a performance-critical path. sz should be set by to szTrue whenever |
| 16381 | 16448 | ** bDisable changes back to zero. |
| 16449 | +** |
| 16450 | +** Lookaside buffers are initially held on the pInit list. As they are |
| 16451 | +** used and freed, they are added back to the pFree list. New allocations |
| 16452 | +** come off of pFree first, then pInit as a fallback. This dual-list |
| 16453 | +** allows use to compute a high-water mark - the maximum number of allocations |
| 16454 | +** outstanding at any point in the past - by subtracting the number of |
| 16455 | +** allocations on the pInit list from the total number of allocations. |
| 16456 | +** |
| 16457 | +** Enhancement on 2019-12-12: Two-size-lookaside |
| 16458 | +** The default lookaside configuration is 100 slots of 1200 bytes each. |
| 16459 | +** The larger slot sizes are important for performance, but they waste |
| 16460 | +** a lot of space, as most lookaside allocations are less than 128 bytes. |
| 16461 | +** The two-size-lookaside enhancement breaks up the lookaside allocation |
| 16462 | +** into two pools: One of 128-byte slots and the other of the default size |
| 16463 | +** (1200-byte) slots. Allocations are filled from the small-pool first, |
| 16464 | +** failing over to the full-size pool if that does not work. Thus more |
| 16465 | +** lookaside slots are available while also using less memory. |
| 16466 | +** This enhancement can be omitted by compiling with |
| 16467 | +** SQLITE_OMIT_TWOSIZE_LOOKASIDE. |
| 16382 | 16468 | */ |
| 16383 | 16469 | struct Lookaside { |
| 16384 | 16470 | u32 bDisable; /* Only operate the lookaside when zero */ |
| 16385 | 16471 | u16 sz; /* Size of each buffer in bytes */ |
| 16386 | 16472 | u16 szTrue; /* True value of sz, even if disabled */ |
| | @@ -16387,10 +16473,16 @@ |
| 16387 | 16473 | u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */ |
| 16388 | 16474 | u32 nSlot; /* Number of lookaside slots allocated */ |
| 16389 | 16475 | u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ |
| 16390 | 16476 | LookasideSlot *pInit; /* List of buffers not previously used */ |
| 16391 | 16477 | LookasideSlot *pFree; /* List of available buffers */ |
| 16478 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 16479 | + LookasideSlot *pSmallInit; /* List of small buffers not prediously used */ |
| 16480 | + LookasideSlot *pSmallFree; /* List of available small buffers */ |
| 16481 | + void *pMiddle; /* First byte past end of full-size buffers and |
| 16482 | + ** the first byte of LOOKASIDE_SMALL buffers */ |
| 16483 | +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 16392 | 16484 | void *pStart; /* First byte of available memory space */ |
| 16393 | 16485 | void *pEnd; /* First byte past end of available space */ |
| 16394 | 16486 | }; |
| 16395 | 16487 | struct LookasideSlot { |
| 16396 | 16488 | LookasideSlot *pNext; /* Next buffer in the list of free buffers */ |
| | @@ -16397,10 +16489,17 @@ |
| 16397 | 16489 | }; |
| 16398 | 16490 | |
| 16399 | 16491 | #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0 |
| 16400 | 16492 | #define EnableLookaside db->lookaside.bDisable--;\ |
| 16401 | 16493 | db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue |
| 16494 | + |
| 16495 | +/* Size of the smaller allocations in two-size lookside */ |
| 16496 | +#ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 16497 | +# define LOOKASIDE_SMALL 0 |
| 16498 | +#else |
| 16499 | +# define LOOKASIDE_SMALL 128 |
| 16500 | +#endif |
| 16402 | 16501 | |
| 16403 | 16502 | /* |
| 16404 | 16503 | ** A hash table for built-in function definitions. (Application-defined |
| 16405 | 16504 | ** functions use a regular table table from hash.h.) |
| 16406 | 16505 | ** |
| | @@ -16606,10 +16705,17 @@ |
| 16606 | 16705 | ** A macro to discover the encoding of a database. |
| 16607 | 16706 | */ |
| 16608 | 16707 | #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc) |
| 16609 | 16708 | #define ENC(db) ((db)->enc) |
| 16610 | 16709 | |
| 16710 | +/* |
| 16711 | +** A u64 constant where the lower 32 bits are all zeros. Only the |
| 16712 | +** upper 32 bits are included in the argument. Necessary because some |
| 16713 | +** C-compilers still do not accept LL integer literals. |
| 16714 | +*/ |
| 16715 | +#define HI(X) ((u64)(X)<<32) |
| 16716 | + |
| 16611 | 16717 | /* |
| 16612 | 16718 | ** Possible values for the sqlite3.flags. |
| 16613 | 16719 | ** |
| 16614 | 16720 | ** Value constraints (enforced via assert()): |
| 16615 | 16721 | ** SQLITE_FullFSync == PAGER_FULLFSYNC |
| | @@ -16621,13 +16727,12 @@ |
| 16621 | 16727 | #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */ |
| 16622 | 16728 | #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */ |
| 16623 | 16729 | #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */ |
| 16624 | 16730 | #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */ |
| 16625 | 16731 | #define SQLITE_ShortColNames 0x00000040 /* Show short columns names */ |
| 16626 | | -#define SQLITE_CountRows 0x00000080 /* Count rows changed by INSERT, */ |
| 16627 | | - /* DELETE, or UPDATE and return */ |
| 16628 | | - /* the count using a callback. */ |
| 16732 | +#define SQLITE_TrustedSchema 0x00000080 /* Allow unsafe functions and |
| 16733 | + ** vtabs in the schema definition */ |
| 16629 | 16734 | #define SQLITE_NullCallback 0x00000100 /* Invoke the callback once if the */ |
| 16630 | 16735 | /* result set is empty */ |
| 16631 | 16736 | #define SQLITE_IgnoreChecks 0x00000200 /* Do not enforce check constraints */ |
| 16632 | 16737 | #define SQLITE_ReadUncommit 0x00000400 /* READ UNCOMMITTED in shared-cache */ |
| 16633 | 16738 | #define SQLITE_NoCkptOnClose 0x00000800 /* No checkpoint on close()/DETACH */ |
| | @@ -16649,13 +16754,15 @@ |
| 16649 | 16754 | #define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/ |
| 16650 | 16755 | #define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */ |
| 16651 | 16756 | #define SQLITE_DqsDDL 0x20000000 /* dbl-quoted strings allowed in DDL*/ |
| 16652 | 16757 | #define SQLITE_DqsDML 0x40000000 /* dbl-quoted strings allowed in DML*/ |
| 16653 | 16758 | #define SQLITE_EnableView 0x80000000 /* Enable the use of views */ |
| 16759 | +#define SQLITE_CountRows HI(0x00001) /* Count rows changed by INSERT, */ |
| 16760 | + /* DELETE, or UPDATE and return */ |
| 16761 | + /* the count using a callback. */ |
| 16654 | 16762 | |
| 16655 | 16763 | /* Flags used only if debugging */ |
| 16656 | | -#define HI(X) ((u64)(X)<<32) |
| 16657 | 16764 | #ifdef SQLITE_DEBUG |
| 16658 | 16765 | #define SQLITE_SqlTrace HI(0x0100000) /* Debug print SQL as it executes */ |
| 16659 | 16766 | #define SQLITE_VdbeListing HI(0x0200000) /* Debug listings of VDBE progs */ |
| 16660 | 16767 | #define SQLITE_VdbeTrace HI(0x0400000) /* True to trace VDBE execution */ |
| 16661 | 16768 | #define SQLITE_VdbeAddopTrace HI(0x0800000) /* Trace sqlite3VdbeAddOp() calls */ |
| | @@ -16669,10 +16776,11 @@ |
| 16669 | 16776 | #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */ |
| 16670 | 16777 | #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */ |
| 16671 | 16778 | #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */ |
| 16672 | 16779 | #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */ |
| 16673 | 16780 | #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */ |
| 16781 | +#define DBFLAG_InternalFunc 0x0020 /* Allow use of internal functions */ |
| 16674 | 16782 | |
| 16675 | 16783 | /* |
| 16676 | 16784 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 16677 | 16785 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| 16678 | 16786 | ** selectively disable various optimizations. |
| | @@ -16776,10 +16884,11 @@ |
| 16776 | 16884 | ** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg |
| 16777 | 16885 | ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG |
| 16778 | 16886 | ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG |
| 16779 | 16887 | ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API |
| 16780 | 16888 | ** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API |
| 16889 | +** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS |
| 16781 | 16890 | ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API |
| 16782 | 16891 | */ |
| 16783 | 16892 | #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ |
| 16784 | 16893 | #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ |
| 16785 | 16894 | #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ |
| | @@ -16792,16 +16901,26 @@ |
| 16792 | 16901 | #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ |
| 16793 | 16902 | #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ |
| 16794 | 16903 | #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ |
| 16795 | 16904 | #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a |
| 16796 | 16905 | ** single query - might change over time */ |
| 16797 | | -#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */ |
| 16906 | +#define SQLITE_FUNC_TEST 0x4000 /* Built-in testing functions */ |
| 16798 | 16907 | #define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */ |
| 16799 | 16908 | #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */ |
| 16800 | 16909 | #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */ |
| 16801 | 16910 | #define SQLITE_FUNC_DIRECT 0x00080000 /* Not for use in TRIGGERs or VIEWs */ |
| 16802 | 16911 | #define SQLITE_FUNC_SUBTYPE 0x00100000 /* Result likely to have sub-type */ |
| 16912 | +#define SQLITE_FUNC_UNSAFE 0x00200000 /* Function has side effects */ |
| 16913 | +#define SQLITE_FUNC_INLINE 0x00400000 /* Functions implemented in-line */ |
| 16914 | + |
| 16915 | +/* Identifier numbers for each in-line function */ |
| 16916 | +#define INLINEFUNC_coalesce 0 |
| 16917 | +#define INLINEFUNC_implies_nonnull_row 1 |
| 16918 | +#define INLINEFUNC_expr_implies_expr 2 |
| 16919 | +#define INLINEFUNC_expr_compare 3 |
| 16920 | +#define INLINEFUNC_affinity 4 |
| 16921 | +#define INLINEFUNC_unlikely 99 /* Default case */ |
| 16803 | 16922 | |
| 16804 | 16923 | /* |
| 16805 | 16924 | ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 16806 | 16925 | ** used to create the initializers for the FuncDef structures. |
| 16807 | 16926 | ** |
| | @@ -16813,10 +16932,26 @@ |
| 16813 | 16932 | ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set. |
| 16814 | 16933 | ** |
| 16815 | 16934 | ** VFUNCTION(zName, nArg, iArg, bNC, xFunc) |
| 16816 | 16935 | ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag. |
| 16817 | 16936 | ** |
| 16937 | +** SFUNCTION(zName, nArg, iArg, bNC, xFunc) |
| 16938 | +** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and |
| 16939 | +** adds the SQLITE_DIRECTONLY flag. |
| 16940 | +** |
| 16941 | +** INLINE_FUNC(zName, nArg, iFuncId, mFlags) |
| 16942 | +** zName is the name of a function that is implemented by in-line |
| 16943 | +** byte code rather than by the usual callbacks. The iFuncId |
| 16944 | +** parameter determines the function id. The mFlags parameter is |
| 16945 | +** optional SQLITE_FUNC_ flags for this function. |
| 16946 | +** |
| 16947 | +** TEST_FUNC(zName, nArg, iFuncId, mFlags) |
| 16948 | +** zName is the name of a test-only function implemented by in-line |
| 16949 | +** byte code rather than by the usual callbacks. The iFuncId |
| 16950 | +** parameter determines the function id. The mFlags parameter is |
| 16951 | +** optional SQLITE_FUNC_ flags for this function. |
| 16952 | +** |
| 16818 | 16953 | ** DFUNCTION(zName, nArg, iArg, bNC, xFunc) |
| 16819 | 16954 | ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag and |
| 16820 | 16955 | ** adds the SQLITE_FUNC_SLOCHNG flag. Used for date & time functions |
| 16821 | 16956 | ** and functions like sqlite_version() that can change, but not during |
| 16822 | 16957 | ** a single query. The iArg is ignored. The user-data is always set |
| | @@ -16852,10 +16987,20 @@ |
| 16852 | 16987 | {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 16853 | 16988 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16854 | 16989 | #define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 16855 | 16990 | {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 16856 | 16991 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16992 | +#define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 16993 | + {nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \ |
| 16994 | + SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16995 | +#define INLINE_FUNC(zName, nArg, iArg, mFlags) \ |
| 16996 | + {nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ |
| 16997 | + SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } |
| 16998 | +#define TEST_FUNC(zName, nArg, iArg, mFlags) \ |
| 16999 | + {nArg, SQLITE_UTF8|SQLITE_FUNC_INTERNAL|SQLITE_FUNC_TEST| \ |
| 17000 | + SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \ |
| 17001 | + SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} } |
| 16857 | 17002 | #define DFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 16858 | 17003 | {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8, \ |
| 16859 | 17004 | 0, 0, xFunc, 0, 0, 0, #zName, {0} } |
| 16860 | 17005 | #define PURE_DATE(zName, nArg, iArg, bNC, xFunc) \ |
| 16861 | 17006 | {nArg, SQLITE_FUNC_SLOCHNG|SQLITE_UTF8|SQLITE_FUNC_CONSTANT, \ |
| | @@ -17068,13 +17213,20 @@ |
| 17068 | 17213 | sqlite3 *db; /* Database connection associated with this table */ |
| 17069 | 17214 | Module *pMod; /* Pointer to module implementation */ |
| 17070 | 17215 | sqlite3_vtab *pVtab; /* Pointer to vtab instance */ |
| 17071 | 17216 | int nRef; /* Number of pointers to this structure */ |
| 17072 | 17217 | u8 bConstraint; /* True if constraints are supported */ |
| 17218 | + u8 eVtabRisk; /* Riskiness of allowing hacker access */ |
| 17073 | 17219 | int iSavepoint; /* Depth of the SAVEPOINT stack */ |
| 17074 | 17220 | VTable *pNext; /* Next in linked list (see above) */ |
| 17075 | 17221 | }; |
| 17222 | + |
| 17223 | +/* Allowed values for VTable.eVtabRisk |
| 17224 | +*/ |
| 17225 | +#define SQLITE_VTABRISK_Low 0 |
| 17226 | +#define SQLITE_VTABRISK_Normal 1 |
| 17227 | +#define SQLITE_VTABRISK_High 2 |
| 17076 | 17228 | |
| 17077 | 17229 | /* |
| 17078 | 17230 | ** The schema for each SQL table and view is represented in memory |
| 17079 | 17231 | ** by an instance of the following structure. |
| 17080 | 17232 | */ |
| | @@ -17672,11 +17824,11 @@ |
| 17672 | 17824 | #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */ |
| 17673 | 17825 | #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */ |
| 17674 | 17826 | #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */ |
| 17675 | 17827 | #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */ |
| 17676 | 17828 | #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */ |
| 17677 | | -#define EP_Indirect 0x40000000 /* Contained within a TRIGGER or a VIEW */ |
| 17829 | +#define EP_FromDDL 0x40000000 /* Originates from sqlite_master */ |
| 17678 | 17830 | |
| 17679 | 17831 | /* |
| 17680 | 17832 | ** The EP_Propagate mask is a set of properties that automatically propagate |
| 17681 | 17833 | ** upwards into parent nodes. |
| 17682 | 17834 | */ |
| | @@ -17736,27 +17888,32 @@ |
| 17736 | 17888 | ** as the list of "expr AS ID" fields following a "SELECT" or in the |
| 17737 | 17889 | ** list of "ID = expr" items in an UPDATE. A list of expressions can |
| 17738 | 17890 | ** also be used as the argument to a function, in which case the a.zName |
| 17739 | 17891 | ** field is not used. |
| 17740 | 17892 | ** |
| 17741 | | -** By default the Expr.zSpan field holds a human-readable description of |
| 17742 | | -** the expression that is used in the generation of error messages and |
| 17743 | | -** column labels. In this case, Expr.zSpan is typically the text of a |
| 17744 | | -** column expression as it exists in a SELECT statement. However, if |
| 17745 | | -** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name |
| 17746 | | -** of the result column in the form: DATABASE.TABLE.COLUMN. This later |
| 17747 | | -** form is used for name resolution with nested FROM clauses. |
| 17893 | +** In order to try to keep memory usage down, the Expr.a.zEName field |
| 17894 | +** is used for multiple purposes: |
| 17895 | +** |
| 17896 | +** eEName Usage |
| 17897 | +** ---------- ------------------------- |
| 17898 | +** ENAME_NAME (1) the AS of result set column |
| 17899 | +** (2) COLUMN= of an UPDATE |
| 17900 | +** |
| 17901 | +** ENAME_TAB DB.TABLE.NAME used to resolve names |
| 17902 | +** of subqueries |
| 17903 | +** |
| 17904 | +** ENAME_SPAN Text of the original result set |
| 17905 | +** expression. |
| 17748 | 17906 | */ |
| 17749 | 17907 | struct ExprList { |
| 17750 | 17908 | int nExpr; /* Number of expressions on the list */ |
| 17751 | 17909 | struct ExprList_item { /* For each expression in the list */ |
| 17752 | 17910 | Expr *pExpr; /* The parse tree for this expression */ |
| 17753 | | - char *zName; /* Token associated with this expression */ |
| 17754 | | - char *zSpan; /* Original text of the expression */ |
| 17911 | + char *zEName; /* Token associated with this expression */ |
| 17755 | 17912 | u8 sortFlags; /* Mask of KEYINFO_ORDER_* flags */ |
| 17913 | + unsigned eEName :2; /* Meaning of zEName */ |
| 17756 | 17914 | unsigned done :1; /* A flag to indicate when processing is finished */ |
| 17757 | | - unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */ |
| 17758 | 17915 | unsigned reusable :1; /* Constant expression is reusable */ |
| 17759 | 17916 | unsigned bSorterRef :1; /* Defer evaluation until after sorting */ |
| 17760 | 17917 | unsigned bNulls: 1; /* True if explicit "NULLS FIRST/LAST" */ |
| 17761 | 17918 | union { |
| 17762 | 17919 | struct { |
| | @@ -17766,10 +17923,17 @@ |
| 17766 | 17923 | int iConstExprReg; /* Register in which Expr value is cached */ |
| 17767 | 17924 | } u; |
| 17768 | 17925 | } a[1]; /* One slot for each expression in the list */ |
| 17769 | 17926 | }; |
| 17770 | 17927 | |
| 17928 | +/* |
| 17929 | +** Allowed values for Expr.a.eEName |
| 17930 | +*/ |
| 17931 | +#define ENAME_NAME 0 /* The AS clause of a result set */ |
| 17932 | +#define ENAME_SPAN 1 /* Complete text of the result set expression */ |
| 17933 | +#define ENAME_TAB 2 /* "DB.TABLE.NAME" for the result set */ |
| 17934 | + |
| 17771 | 17935 | /* |
| 17772 | 17936 | ** An instance of this structure can hold a simple list of identifiers, |
| 17773 | 17937 | ** such as the list "a,b,c" in the following statements: |
| 17774 | 17938 | ** |
| 17775 | 17939 | ** INSERT INTO t(a,b,c) VALUES ...; |
| | @@ -17829,10 +17993,11 @@ |
| 17829 | 17993 | unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */ |
| 17830 | 17994 | unsigned isTabFunc :1; /* True if table-valued-function syntax */ |
| 17831 | 17995 | unsigned isCorrelated :1; /* True if sub-query is correlated */ |
| 17832 | 17996 | unsigned viaCoroutine :1; /* Implemented as a co-routine */ |
| 17833 | 17997 | unsigned isRecursive :1; /* True for recursive reference in WITH */ |
| 17998 | + unsigned fromDDL :1; /* Comes from sqlite_master */ |
| 17834 | 17999 | } fg; |
| 17835 | 18000 | int iCursor; /* The VDBE cursor number used to access this table */ |
| 17836 | 18001 | Expr *pOn; /* The ON clause of a join */ |
| 17837 | 18002 | IdList *pUsing; /* The USING clause of a join */ |
| 17838 | 18003 | Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */ |
| | @@ -17949,10 +18114,11 @@ |
| 17949 | 18114 | #define NC_Complex 0x02000 /* True if a function or subquery seen */ |
| 17950 | 18115 | #define NC_AllowWin 0x04000 /* Window functions are allowed here */ |
| 17951 | 18116 | #define NC_HasWin 0x08000 /* One or more window functions seen */ |
| 17952 | 18117 | #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */ |
| 17953 | 18118 | #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */ |
| 18119 | +#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_master */ |
| 17954 | 18120 | |
| 17955 | 18121 | /* |
| 17956 | 18122 | ** An instance of the following object describes a single ON CONFLICT |
| 17957 | 18123 | ** clause in an upsert. |
| 17958 | 18124 | ** |
| | @@ -18504,11 +18670,11 @@ |
| 18504 | 18670 | */ |
| 18505 | 18671 | typedef struct DbFixer DbFixer; |
| 18506 | 18672 | struct DbFixer { |
| 18507 | 18673 | Parse *pParse; /* The parsing context. Error messages written here */ |
| 18508 | 18674 | Schema *pSchema; /* Fix items to this schema */ |
| 18509 | | - int bVarOnly; /* Check for variable references only */ |
| 18675 | + u8 bTemp; /* True for TEMP schema entries */ |
| 18510 | 18676 | const char *zDb; /* Make sure all objects are contained in this database */ |
| 18511 | 18677 | const char *zType; /* Type of the container - used for error messages */ |
| 18512 | 18678 | const Token *pName; /* Name of the container - used for error messages */ |
| 18513 | 18679 | }; |
| 18514 | 18680 | |
| | @@ -18609,11 +18775,10 @@ |
| 18609 | 18775 | #endif |
| 18610 | 18776 | #ifndef SQLITE_UNTESTABLE |
| 18611 | 18777 | int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ |
| 18612 | 18778 | #endif |
| 18613 | 18779 | int bLocaltimeFault; /* True to fail localtime() calls */ |
| 18614 | | - int bInternalFunctions; /* Internal SQL functions are visible */ |
| 18615 | 18780 | int iOnceResetThreshold; /* When to reset OP_Once counters */ |
| 18616 | 18781 | u32 szSorterRef; /* Min size in bytes to use sorter-refs */ |
| 18617 | 18782 | unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */ |
| 18618 | 18783 | }; |
| 18619 | 18784 | |
| | @@ -18772,11 +18937,11 @@ |
| 18772 | 18937 | SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p); |
| 18773 | 18938 | SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8); |
| 18774 | 18939 | SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*); |
| 18775 | 18940 | SQLITE_PRIVATE void sqlite3WindowLink(Select *pSel, Window *pWin); |
| 18776 | 18941 | SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*, int); |
| 18777 | | -SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*); |
| 18942 | +SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Select*); |
| 18778 | 18943 | SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int); |
| 18779 | 18944 | SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*); |
| 18780 | 18945 | SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*); |
| 18781 | 18946 | SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*); |
| 18782 | 18947 | SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p); |
| | @@ -19038,10 +19203,11 @@ |
| 19038 | 19203 | SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*); |
| 19039 | 19204 | SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*); |
| 19040 | 19205 | SQLITE_PRIVATE Expr *sqlite3ExprAnd(Parse*,Expr*, Expr*); |
| 19041 | 19206 | SQLITE_PRIVATE Expr *sqlite3ExprSimplifiedAndOr(Expr*); |
| 19042 | 19207 | SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int); |
| 19208 | +SQLITE_PRIVATE void sqlite3ExprFunctionUsable(Parse*,Expr*,FuncDef*); |
| 19043 | 19209 | SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32); |
| 19044 | 19210 | SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*); |
| 19045 | 19211 | SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse*, Expr*); |
| 19046 | 19212 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); |
| 19047 | 19213 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*); |
| | @@ -19195,10 +19361,11 @@ |
| 19195 | 19361 | SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*); |
| 19196 | 19362 | SQLITE_PRIVATE int sqlite3WhereOkOnePass(WhereInfo*, int*); |
| 19197 | 19363 | #define ONEPASS_OFF 0 /* Use of ONEPASS not allowed */ |
| 19198 | 19364 | #define ONEPASS_SINGLE 1 /* ONEPASS valid for a single row update */ |
| 19199 | 19365 | #define ONEPASS_MULTI 2 /* ONEPASS is valid for multiple rows */ |
| 19366 | +SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek(WhereInfo*); |
| 19200 | 19367 | SQLITE_PRIVATE void sqlite3ExprCodeLoadIndexColumn(Parse*, Index*, int, int, int); |
| 19201 | 19368 | SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 19202 | 19369 | SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); |
| 19203 | 19370 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 19204 | 19371 | SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); |
| | @@ -19249,10 +19416,11 @@ |
| 19249 | 19416 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 19250 | 19417 | SQLITE_PRIVATE void sqlite3EndTransaction(Parse*,int); |
| 19251 | 19418 | SQLITE_PRIVATE void sqlite3Savepoint(Parse*, int, Token*); |
| 19252 | 19419 | SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *); |
| 19253 | 19420 | SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*); |
| 19421 | +SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse(const char*); |
| 19254 | 19422 | SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr*); |
| 19255 | 19423 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr*); |
| 19256 | 19424 | SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*); |
| 19257 | 19425 | SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*); |
| 19258 | 19426 | SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8); |
| | @@ -19505,11 +19673,16 @@ |
| 19505 | 19673 | SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int); |
| 19506 | 19674 | SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int); |
| 19507 | 19675 | SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*); |
| 19508 | 19676 | SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*); |
| 19509 | 19677 | SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p); |
| 19510 | | -SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*); |
| 19678 | +SQLITE_PRIVATE int sqlite3MatchEName( |
| 19679 | + const struct ExprList_item*, |
| 19680 | + const char*, |
| 19681 | + const char*, |
| 19682 | + const char* |
| 19683 | +); |
| 19511 | 19684 | SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*); |
| 19512 | 19685 | SQLITE_PRIVATE int sqlite3ResolveExprListNames(NameContext*, ExprList*); |
| 19513 | 19686 | SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*); |
| 19514 | 19687 | SQLITE_PRIVATE int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*); |
| 19515 | 19688 | SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*); |
| | @@ -19977,11 +20150,10 @@ |
| 19977 | 20150 | ** Bit 0x40 is set if the character is non-alphanumeric and can be used in an |
| 19978 | 20151 | ** SQLite identifier. Identifiers are alphanumerics, "_", "$", and any |
| 19979 | 20152 | ** non-ASCII UTF character. Hence the test for whether or not a character is |
| 19980 | 20153 | ** part of an identifier is 0x46. |
| 19981 | 20154 | */ |
| 19982 | | -#ifdef SQLITE_ASCII |
| 19983 | 20155 | SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = { |
| 19984 | 20156 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */ |
| 19985 | 20157 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */ |
| 19986 | 20158 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */ |
| 19987 | 20159 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */ |
| | @@ -20015,11 +20187,10 @@ |
| 20015 | 20187 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e0..e7 ........ */ |
| 20016 | 20188 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* e8..ef ........ */ |
| 20017 | 20189 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* f0..f7 ........ */ |
| 20018 | 20190 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 /* f8..ff ........ */ |
| 20019 | 20191 | }; |
| 20020 | | -#endif |
| 20021 | 20192 | |
| 20022 | 20193 | /* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards |
| 20023 | 20194 | ** compatibility for legacy applications, the URI filename capability is |
| 20024 | 20195 | ** disabled by default. |
| 20025 | 20196 | ** |
| | @@ -20080,13 +20251,22 @@ |
| 20080 | 20251 | ** number of bytes in each lookaside slot (should be a multiple of 8) |
| 20081 | 20252 | ** and N is the number of slots. The lookaside-configuration can be |
| 20082 | 20253 | ** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE) |
| 20083 | 20254 | ** or at run-time for an individual database connection using |
| 20084 | 20255 | ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE); |
| 20256 | +** |
| 20257 | +** With the two-size-lookaside enhancement, less lookaside is required. |
| 20258 | +** The default configuration of 1200,40 actually provides 30 1200-byte slots |
| 20259 | +** and 93 128-byte slots, which is more lookaside than is available |
| 20260 | +** using the older 1200,100 configuration without two-size-lookaside. |
| 20085 | 20261 | */ |
| 20086 | 20262 | #ifndef SQLITE_DEFAULT_LOOKASIDE |
| 20087 | | -# define SQLITE_DEFAULT_LOOKASIDE 1200,100 |
| 20263 | +# ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 20264 | +# define SQLITE_DEFAULT_LOOKASIDE 1200,100 /* 120KB of memory */ |
| 20265 | +# else |
| 20266 | +# define SQLITE_DEFAULT_LOOKASIDE 1200,40 /* 48KB of memory */ |
| 20267 | +# endif |
| 20088 | 20268 | #endif |
| 20089 | 20269 | |
| 20090 | 20270 | |
| 20091 | 20271 | /* The default maximum size of an in-memory database created using |
| 20092 | 20272 | ** sqlite3_deserialize() |
| | @@ -20148,11 +20328,10 @@ |
| 20148 | 20328 | #endif |
| 20149 | 20329 | #ifndef SQLITE_UNTESTABLE |
| 20150 | 20330 | 0, /* xTestCallback */ |
| 20151 | 20331 | #endif |
| 20152 | 20332 | 0, /* bLocaltimeFault */ |
| 20153 | | - 0, /* bInternalFunctions */ |
| 20154 | 20333 | 0x7ffffffe, /* iOnceResetThreshold */ |
| 20155 | 20334 | SQLITE_DEFAULT_SORTERREF_SIZE, /* szSorterRef */ |
| 20156 | 20335 | 0, /* iPrngSeed */ |
| 20157 | 20336 | }; |
| 20158 | 20337 | |
| | @@ -20710,10 +20889,11 @@ |
| 20710 | 20889 | ** Function prototypes |
| 20711 | 20890 | */ |
| 20712 | 20891 | SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); |
| 20713 | 20892 | SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); |
| 20714 | 20893 | void sqliteVdbePopStack(Vdbe*,int); |
| 20894 | +SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*); |
| 20715 | 20895 | SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, int*); |
| 20716 | 20896 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); |
| 20717 | 20897 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 20718 | 20898 | SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); |
| 20719 | 20899 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| | @@ -20822,11 +21002,11 @@ |
| 20822 | 21002 | # define sqlite3VdbeCheckFk(p,i) 0 |
| 20823 | 21003 | #endif |
| 20824 | 21004 | |
| 20825 | 21005 | #ifdef SQLITE_DEBUG |
| 20826 | 21006 | SQLITE_PRIVATE void sqlite3VdbePrintSql(Vdbe*); |
| 20827 | | -SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf); |
| 21007 | +SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr); |
| 20828 | 21008 | #endif |
| 20829 | 21009 | #ifndef SQLITE_OMIT_UTF16 |
| 20830 | 21010 | SQLITE_PRIVATE int sqlite3VdbeMemTranslate(Mem*, u8); |
| 20831 | 21011 | SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem); |
| 20832 | 21012 | #endif |
| | @@ -21014,10 +21194,14 @@ |
| 21014 | 21194 | ** Count the number of slots of lookaside memory that are outstanding |
| 21015 | 21195 | */ |
| 21016 | 21196 | SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){ |
| 21017 | 21197 | u32 nInit = countLookasideSlots(db->lookaside.pInit); |
| 21018 | 21198 | u32 nFree = countLookasideSlots(db->lookaside.pFree); |
| 21199 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 21200 | + nInit += countLookasideSlots(db->lookaside.pSmallInit); |
| 21201 | + nFree += countLookasideSlots(db->lookaside.pSmallFree); |
| 21202 | +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 21019 | 21203 | if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit; |
| 21020 | 21204 | return db->lookaside.nSlot - (nInit+nFree); |
| 21021 | 21205 | } |
| 21022 | 21206 | |
| 21023 | 21207 | /* |
| | @@ -21046,10 +21230,19 @@ |
| 21046 | 21230 | while( p->pNext ) p = p->pNext; |
| 21047 | 21231 | p->pNext = db->lookaside.pInit; |
| 21048 | 21232 | db->lookaside.pInit = db->lookaside.pFree; |
| 21049 | 21233 | db->lookaside.pFree = 0; |
| 21050 | 21234 | } |
| 21235 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 21236 | + p = db->lookaside.pSmallFree; |
| 21237 | + if( p ){ |
| 21238 | + while( p->pNext ) p = p->pNext; |
| 21239 | + p->pNext = db->lookaside.pSmallInit; |
| 21240 | + db->lookaside.pSmallInit = db->lookaside.pSmallFree; |
| 21241 | + db->lookaside.pSmallFree = 0; |
| 21242 | + } |
| 21243 | +#endif |
| 21051 | 21244 | } |
| 21052 | 21245 | break; |
| 21053 | 21246 | } |
| 21054 | 21247 | |
| 21055 | 21248 | case SQLITE_DBSTATUS_LOOKASIDE_HIT: |
| | @@ -27142,28 +27335,46 @@ |
| 27142 | 27335 | ** sqlite3Malloc() or sqlite3_malloc(). |
| 27143 | 27336 | */ |
| 27144 | 27337 | SQLITE_PRIVATE int sqlite3MallocSize(void *p){ |
| 27145 | 27338 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 27146 | 27339 | return sqlite3GlobalConfig.m.xSize(p); |
| 27340 | +} |
| 27341 | +static int lookasideMallocSize(sqlite3 *db, void *p){ |
| 27342 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 27343 | + return p<db->lookaside.pMiddle ? db->lookaside.szTrue : LOOKASIDE_SMALL; |
| 27344 | +#else |
| 27345 | + return db->lookaside.szTrue; |
| 27346 | +#endif |
| 27147 | 27347 | } |
| 27148 | 27348 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ |
| 27149 | 27349 | assert( p!=0 ); |
| 27350 | +#ifdef SQLITE_DEBUG |
| 27150 | 27351 | if( db==0 || !isLookaside(db,p) ){ |
| 27151 | | -#ifdef SQLITE_DEBUG |
| 27152 | 27352 | if( db==0 ){ |
| 27153 | 27353 | assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); |
| 27154 | 27354 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 27155 | 27355 | }else{ |
| 27156 | 27356 | assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27157 | 27357 | assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27158 | 27358 | } |
| 27359 | + } |
| 27159 | 27360 | #endif |
| 27160 | | - return sqlite3GlobalConfig.m.xSize(p); |
| 27161 | | - }else{ |
| 27162 | | - assert( sqlite3_mutex_held(db->mutex) ); |
| 27163 | | - return db->lookaside.szTrue; |
| 27361 | + if( db ){ |
| 27362 | + if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){ |
| 27363 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 27364 | + if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){ |
| 27365 | + assert( sqlite3_mutex_held(db->mutex) ); |
| 27366 | + return LOOKASIDE_SMALL; |
| 27367 | + } |
| 27368 | +#endif |
| 27369 | + if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){ |
| 27370 | + assert( sqlite3_mutex_held(db->mutex) ); |
| 27371 | + return db->lookaside.szTrue; |
| 27372 | + } |
| 27373 | + } |
| 27164 | 27374 | } |
| 27375 | + return sqlite3GlobalConfig.m.xSize(p); |
| 27165 | 27376 | } |
| 27166 | 27377 | SQLITE_API sqlite3_uint64 sqlite3_msize(void *p){ |
| 27167 | 27378 | assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_HEAP) ); |
| 27168 | 27379 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 27169 | 27380 | return p ? sqlite3GlobalConfig.m.xSize(p) : 0; |
| | @@ -27206,19 +27417,31 @@ |
| 27206 | 27417 | if( db ){ |
| 27207 | 27418 | if( db->pnBytesFreed ){ |
| 27208 | 27419 | measureAllocationSize(db, p); |
| 27209 | 27420 | return; |
| 27210 | 27421 | } |
| 27211 | | - if( isLookaside(db, p) ){ |
| 27212 | | - LookasideSlot *pBuf = (LookasideSlot*)p; |
| 27422 | + if( ((uptr)p)<(uptr)(db->lookaside.pEnd) ){ |
| 27423 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 27424 | + if( ((uptr)p)>=(uptr)(db->lookaside.pMiddle) ){ |
| 27425 | + LookasideSlot *pBuf = (LookasideSlot*)p; |
| 27213 | 27426 | #ifdef SQLITE_DEBUG |
| 27214 | | - /* Trash all content in the buffer being freed */ |
| 27215 | | - memset(p, 0xaa, db->lookaside.szTrue); |
| 27427 | + memset(p, 0xaa, LOOKASIDE_SMALL); /* Trash freed content */ |
| 27216 | 27428 | #endif |
| 27217 | | - pBuf->pNext = db->lookaside.pFree; |
| 27218 | | - db->lookaside.pFree = pBuf; |
| 27219 | | - return; |
| 27429 | + pBuf->pNext = db->lookaside.pSmallFree; |
| 27430 | + db->lookaside.pSmallFree = pBuf; |
| 27431 | + return; |
| 27432 | + } |
| 27433 | +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 27434 | + if( ((uptr)p)>=(uptr)(db->lookaside.pStart) ){ |
| 27435 | + LookasideSlot *pBuf = (LookasideSlot*)p; |
| 27436 | +#ifdef SQLITE_DEBUG |
| 27437 | + memset(p, 0xaa, db->lookaside.szTrue); /* Trash freed content */ |
| 27438 | +#endif |
| 27439 | + pBuf->pNext = db->lookaside.pFree; |
| 27440 | + db->lookaside.pFree = pBuf; |
| 27441 | + return; |
| 27442 | + } |
| 27220 | 27443 | } |
| 27221 | 27444 | } |
| 27222 | 27445 | assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27223 | 27446 | assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27224 | 27447 | assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| | @@ -27371,15 +27594,31 @@ |
| 27371 | 27594 | LookasideSlot *pBuf; |
| 27372 | 27595 | assert( db!=0 ); |
| 27373 | 27596 | assert( sqlite3_mutex_held(db->mutex) ); |
| 27374 | 27597 | assert( db->pnBytesFreed==0 ); |
| 27375 | 27598 | if( n>db->lookaside.sz ){ |
| 27376 | | - if( db->lookaside.bDisable ){ |
| 27377 | | - return db->mallocFailed ? 0 : dbMallocRawFinish(db, n); |
| 27599 | + if( !db->lookaside.bDisable ){ |
| 27600 | + db->lookaside.anStat[1]++; |
| 27601 | + }else if( db->mallocFailed ){ |
| 27602 | + return 0; |
| 27378 | 27603 | } |
| 27379 | | - db->lookaside.anStat[1]++; |
| 27380 | | - }else if( (pBuf = db->lookaside.pFree)!=0 ){ |
| 27604 | + return dbMallocRawFinish(db, n); |
| 27605 | + } |
| 27606 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 27607 | + if( n<=LOOKASIDE_SMALL ){ |
| 27608 | + if( (pBuf = db->lookaside.pSmallFree)!=0 ){ |
| 27609 | + db->lookaside.pSmallFree = pBuf->pNext; |
| 27610 | + db->lookaside.anStat[0]++; |
| 27611 | + return (void*)pBuf; |
| 27612 | + }else if( (pBuf = db->lookaside.pSmallInit)!=0 ){ |
| 27613 | + db->lookaside.pSmallInit = pBuf->pNext; |
| 27614 | + db->lookaside.anStat[0]++; |
| 27615 | + return (void*)pBuf; |
| 27616 | + } |
| 27617 | + } |
| 27618 | +#endif |
| 27619 | + if( (pBuf = db->lookaside.pFree)!=0 ){ |
| 27381 | 27620 | db->lookaside.pFree = pBuf->pNext; |
| 27382 | 27621 | db->lookaside.anStat[0]++; |
| 27383 | 27622 | return (void*)pBuf; |
| 27384 | 27623 | }else if( (pBuf = db->lookaside.pInit)!=0 ){ |
| 27385 | 27624 | db->lookaside.pInit = pBuf->pNext; |
| | @@ -27408,11 +27647,20 @@ |
| 27408 | 27647 | */ |
| 27409 | 27648 | SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *db, void *p, u64 n){ |
| 27410 | 27649 | assert( db!=0 ); |
| 27411 | 27650 | if( p==0 ) return sqlite3DbMallocRawNN(db, n); |
| 27412 | 27651 | assert( sqlite3_mutex_held(db->mutex) ); |
| 27413 | | - if( isLookaside(db,p) && n<=db->lookaside.szTrue ) return p; |
| 27652 | + if( ((uptr)p)<(uptr)db->lookaside.pEnd ){ |
| 27653 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 27654 | + if( ((uptr)p)>=(uptr)db->lookaside.pMiddle ){ |
| 27655 | + if( n<=LOOKASIDE_SMALL ) return p; |
| 27656 | + }else |
| 27657 | +#endif |
| 27658 | + if( ((uptr)p)>=(uptr)db->lookaside.pStart ){ |
| 27659 | + if( n<=db->lookaside.szTrue ) return p; |
| 27660 | + } |
| 27661 | + } |
| 27414 | 27662 | return dbReallocFinish(db, p, n); |
| 27415 | 27663 | } |
| 27416 | 27664 | static SQLITE_NOINLINE void *dbReallocFinish(sqlite3 *db, void *p, u64 n){ |
| 27417 | 27665 | void *pNew = 0; |
| 27418 | 27666 | assert( db!=0 ); |
| | @@ -27419,11 +27667,11 @@ |
| 27419 | 27667 | assert( p!=0 ); |
| 27420 | 27668 | if( db->mallocFailed==0 ){ |
| 27421 | 27669 | if( isLookaside(db, p) ){ |
| 27422 | 27670 | pNew = sqlite3DbMallocRawNN(db, n); |
| 27423 | 27671 | if( pNew ){ |
| 27424 | | - memcpy(pNew, p, db->lookaside.szTrue); |
| 27672 | + memcpy(pNew, p, lookasideMallocSize(db, p)); |
| 27425 | 27673 | sqlite3DbFree(db, p); |
| 27426 | 27674 | } |
| 27427 | 27675 | }else{ |
| 27428 | 27676 | assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| 27429 | 27677 | assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) ); |
| | @@ -28985,11 +29233,11 @@ |
| 28985 | 29233 | sqlite3_str_appendf(&x, "%s", pCte->zName); |
| 28986 | 29234 | if( pCte->pCols && pCte->pCols->nExpr>0 ){ |
| 28987 | 29235 | char cSep = '('; |
| 28988 | 29236 | int j; |
| 28989 | 29237 | for(j=0; j<pCte->pCols->nExpr; j++){ |
| 28990 | | - sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zName); |
| 29238 | + sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zEName); |
| 28991 | 29239 | cSep = ','; |
| 28992 | 29240 | } |
| 28993 | 29241 | sqlite3_str_appendf(&x, ")"); |
| 28994 | 29242 | } |
| 28995 | 29243 | sqlite3_str_appendf(&x, " AS"); |
| | @@ -29026,10 +29274,13 @@ |
| 29026 | 29274 | sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias); |
| 29027 | 29275 | } |
| 29028 | 29276 | if( pItem->fg.jointype & JT_LEFT ){ |
| 29029 | 29277 | sqlite3_str_appendf(&x, " LEFT-JOIN"); |
| 29030 | 29278 | } |
| 29279 | + if( pItem->fg.fromDDL ){ |
| 29280 | + sqlite3_str_appendf(&x, " DDL"); |
| 29281 | + } |
| 29031 | 29282 | sqlite3StrAccumFinish(&x); |
| 29032 | 29283 | sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); |
| 29033 | 29284 | if( pItem->pSelect ){ |
| 29034 | 29285 | sqlite3TreeViewSelect(pView, pItem->pSelect, 0); |
| 29035 | 29286 | } |
| | @@ -29282,18 +29533,21 @@ |
| 29282 | 29533 | sqlite3TreeViewLine(pView, "nil"); |
| 29283 | 29534 | sqlite3TreeViewPop(pView); |
| 29284 | 29535 | return; |
| 29285 | 29536 | } |
| 29286 | 29537 | if( pExpr->flags || pExpr->affExpr ){ |
| 29538 | + StrAccum x; |
| 29539 | + sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0); |
| 29540 | + sqlite3_str_appendf(&x, " fg.af=%x.%c", |
| 29541 | + pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); |
| 29287 | 29542 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 29288 | | - sqlite3_snprintf(sizeof(zFlgs),zFlgs," fg.af=%x.%c iRJT=%d", |
| 29289 | | - pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n', |
| 29290 | | - pExpr->iRightJoinTable); |
| 29291 | | - }else{ |
| 29292 | | - sqlite3_snprintf(sizeof(zFlgs),zFlgs," fg.af=%x.%c", |
| 29293 | | - pExpr->flags, pExpr->affExpr ? pExpr->affExpr : 'n'); |
| 29543 | + sqlite3_str_appendf(&x, " iRJT=%d", pExpr->iRightJoinTable); |
| 29294 | 29544 | } |
| 29545 | + if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 29546 | + sqlite3_str_appendf(&x, " DDL"); |
| 29547 | + } |
| 29548 | + sqlite3StrAccumFinish(&x); |
| 29295 | 29549 | }else{ |
| 29296 | 29550 | zFlgs[0] = 0; |
| 29297 | 29551 | } |
| 29298 | 29552 | switch( pExpr->op ){ |
| 29299 | 29553 | case TK_AGG_COLUMN: { |
| | @@ -29445,11 +29699,11 @@ |
| 29445 | 29699 | pFarg = 0; |
| 29446 | 29700 | pWin = 0; |
| 29447 | 29701 | }else{ |
| 29448 | 29702 | pFarg = pExpr->x.pList; |
| 29449 | 29703 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 29450 | | - pWin = pExpr->y.pWin; |
| 29704 | + pWin = ExprHasProperty(pExpr, EP_WinFunc) ? pExpr->y.pWin : 0; |
| 29451 | 29705 | #else |
| 29452 | 29706 | pWin = 0; |
| 29453 | 29707 | #endif |
| 29454 | 29708 | } |
| 29455 | 29709 | if( pExpr->op==TK_AGG_FUNCTION ){ |
| | @@ -29607,12 +29861,13 @@ |
| 29607 | 29861 | }else{ |
| 29608 | 29862 | int i; |
| 29609 | 29863 | sqlite3TreeViewLine(pView, "%s", zLabel); |
| 29610 | 29864 | for(i=0; i<pList->nExpr; i++){ |
| 29611 | 29865 | int j = pList->a[i].u.x.iOrderByCol; |
| 29612 | | - char *zName = pList->a[i].zName; |
| 29866 | + char *zName = pList->a[i].zEName; |
| 29613 | 29867 | int moreToFollow = i<pList->nExpr - 1; |
| 29868 | + if( pList->a[i].eEName!=ENAME_NAME ) zName = 0; |
| 29614 | 29869 | if( j || zName ){ |
| 29615 | 29870 | sqlite3TreeViewPush(pView, moreToFollow); |
| 29616 | 29871 | moreToFollow = 0; |
| 29617 | 29872 | sqlite3TreeViewLine(pView, 0); |
| 29618 | 29873 | if( zName ){ |
| | @@ -30275,13 +30530,15 @@ |
| 30275 | 30530 | assert( pMem->enc!=0 ); |
| 30276 | 30531 | assert( pMem->n>=0 ); |
| 30277 | 30532 | |
| 30278 | 30533 | #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG) |
| 30279 | 30534 | { |
| 30280 | | - char zBuf[100]; |
| 30281 | | - sqlite3VdbeMemPrettyPrint(pMem, zBuf); |
| 30282 | | - fprintf(stderr, "INPUT: %s\n", zBuf); |
| 30535 | + StrAccum acc; |
| 30536 | + char zBuf[1000]; |
| 30537 | + sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 30538 | + sqlite3VdbeMemPrettyPrint(pMem, &acc); |
| 30539 | + fprintf(stderr, "INPUT: %s\n", sqlite3StrAccumFinish(&acc)); |
| 30283 | 30540 | } |
| 30284 | 30541 | #endif |
| 30285 | 30542 | |
| 30286 | 30543 | /* If the translation is between UTF-16 little and big endian, then |
| 30287 | 30544 | ** all that is required is to swap the byte order. This case is handled |
| | @@ -30385,13 +30642,15 @@ |
| 30385 | 30642 | pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z); |
| 30386 | 30643 | |
| 30387 | 30644 | translate_out: |
| 30388 | 30645 | #if defined(TRANSLATE_TRACE) && defined(SQLITE_DEBUG) |
| 30389 | 30646 | { |
| 30390 | | - char zBuf[100]; |
| 30391 | | - sqlite3VdbeMemPrettyPrint(pMem, zBuf); |
| 30392 | | - fprintf(stderr, "OUTPUT: %s\n", zBuf); |
| 30647 | + StrAccum acc; |
| 30648 | + char zBuf[1000]; |
| 30649 | + sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 30650 | + sqlite3VdbeMemPrettyPrint(pMem, &acc); |
| 30651 | + fprintf(stderr, "OUTPUT: %s\n", sqlite3StrAccumFinish(&acc)); |
| 30393 | 30652 | } |
| 30394 | 30653 | #endif |
| 30395 | 30654 | return SQLITE_OK; |
| 30396 | 30655 | } |
| 30397 | 30656 | #endif /* SQLITE_OMIT_UTF16 */ |
| | @@ -31006,10 +31265,11 @@ |
| 31006 | 31265 | incr = 1; |
| 31007 | 31266 | zEnd = z + length; |
| 31008 | 31267 | }else{ |
| 31009 | 31268 | int i; |
| 31010 | 31269 | incr = 2; |
| 31270 | + length &= ~1; |
| 31011 | 31271 | assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); |
| 31012 | 31272 | testcase( enc==SQLITE_UTF16LE ); |
| 31013 | 31273 | testcase( enc==SQLITE_UTF16BE ); |
| 31014 | 31274 | for(i=3-enc; i<length && z[i]==0; i+=2){} |
| 31015 | 31275 | if( i<length ) eType = -100; |
| | @@ -32543,85 +32803,85 @@ |
| 32543 | 32803 | /* 21 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), |
| 32544 | 32804 | /* 22 */ "SeekLT" OpHelp("key=r[P3@P4]"), |
| 32545 | 32805 | /* 23 */ "SeekLE" OpHelp("key=r[P3@P4]"), |
| 32546 | 32806 | /* 24 */ "SeekGE" OpHelp("key=r[P3@P4]"), |
| 32547 | 32807 | /* 25 */ "SeekGT" OpHelp("key=r[P3@P4]"), |
| 32548 | | - /* 26 */ "IfNoHope" OpHelp("key=r[P3@P4]"), |
| 32549 | | - /* 27 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 32550 | | - /* 28 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 32551 | | - /* 29 */ "Found" OpHelp("key=r[P3@P4]"), |
| 32552 | | - /* 30 */ "SeekRowid" OpHelp("intkey=r[P3]"), |
| 32553 | | - /* 31 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 32554 | | - /* 32 */ "Last" OpHelp(""), |
| 32555 | | - /* 33 */ "IfSmaller" OpHelp(""), |
| 32556 | | - /* 34 */ "SorterSort" OpHelp(""), |
| 32557 | | - /* 35 */ "Sort" OpHelp(""), |
| 32558 | | - /* 36 */ "Rewind" OpHelp(""), |
| 32559 | | - /* 37 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 32560 | | - /* 38 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 32561 | | - /* 39 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 32562 | | - /* 40 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 32563 | | - /* 41 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 32564 | | - /* 42 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 32808 | + /* 26 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"), |
| 32809 | + /* 27 */ "IfNoHope" OpHelp("key=r[P3@P4]"), |
| 32810 | + /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 32811 | + /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 32812 | + /* 30 */ "Found" OpHelp("key=r[P3@P4]"), |
| 32813 | + /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"), |
| 32814 | + /* 32 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 32815 | + /* 33 */ "Last" OpHelp(""), |
| 32816 | + /* 34 */ "IfSmaller" OpHelp(""), |
| 32817 | + /* 35 */ "SorterSort" OpHelp(""), |
| 32818 | + /* 36 */ "Sort" OpHelp(""), |
| 32819 | + /* 37 */ "Rewind" OpHelp(""), |
| 32820 | + /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 32821 | + /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 32822 | + /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 32823 | + /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 32824 | + /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 32565 | 32825 | /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| 32566 | 32826 | /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), |
| 32567 | | - /* 45 */ "Program" OpHelp(""), |
| 32568 | | - /* 46 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 32569 | | - /* 47 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), |
| 32570 | | - /* 48 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), |
| 32571 | | - /* 49 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 32827 | + /* 45 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 32828 | + /* 46 */ "Program" OpHelp(""), |
| 32829 | + /* 47 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 32830 | + /* 48 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), |
| 32831 | + /* 49 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"), |
| 32572 | 32832 | /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), |
| 32573 | 32833 | /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), |
| 32574 | 32834 | /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"), |
| 32575 | 32835 | /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"), |
| 32576 | 32836 | /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"), |
| 32577 | 32837 | /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"), |
| 32578 | 32838 | /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"), |
| 32579 | 32839 | /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"), |
| 32580 | 32840 | /* 58 */ "ElseNotEq" OpHelp(""), |
| 32581 | | - /* 59 */ "IncrVacuum" OpHelp(""), |
| 32582 | | - /* 60 */ "VNext" OpHelp(""), |
| 32583 | | - /* 61 */ "Init" OpHelp("Start at P2"), |
| 32584 | | - /* 62 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"), |
| 32585 | | - /* 63 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 32586 | | - /* 64 */ "Return" OpHelp(""), |
| 32587 | | - /* 65 */ "EndCoroutine" OpHelp(""), |
| 32588 | | - /* 66 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 32589 | | - /* 67 */ "Halt" OpHelp(""), |
| 32590 | | - /* 68 */ "Integer" OpHelp("r[P2]=P1"), |
| 32591 | | - /* 69 */ "Int64" OpHelp("r[P2]=P4"), |
| 32592 | | - /* 70 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 32593 | | - /* 71 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 32594 | | - /* 72 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 32595 | | - /* 73 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 32596 | | - /* 74 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 32597 | | - /* 75 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 32598 | | - /* 76 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 32599 | | - /* 77 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 32600 | | - /* 78 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 32601 | | - /* 79 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 32602 | | - /* 80 */ "CollSeq" OpHelp(""), |
| 32603 | | - /* 81 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 32604 | | - /* 82 */ "RealAffinity" OpHelp(""), |
| 32605 | | - /* 83 */ "Cast" OpHelp("affinity(r[P1])"), |
| 32606 | | - /* 84 */ "Permutation" OpHelp(""), |
| 32607 | | - /* 85 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 32608 | | - /* 86 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), |
| 32609 | | - /* 87 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 32610 | | - /* 88 */ "Column" OpHelp("r[P3]=PX"), |
| 32611 | | - /* 89 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 32612 | | - /* 90 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 32613 | | - /* 91 */ "Count" OpHelp("r[P2]=count()"), |
| 32614 | | - /* 92 */ "ReadCookie" OpHelp(""), |
| 32615 | | - /* 93 */ "SetCookie" OpHelp(""), |
| 32616 | | - /* 94 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 32617 | | - /* 95 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 32618 | | - /* 96 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 32619 | | - /* 97 */ "OpenDup" OpHelp(""), |
| 32620 | | - /* 98 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 32621 | | - /* 99 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 32622 | | - /* 100 */ "SorterOpen" OpHelp(""), |
| 32841 | + /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 32842 | + /* 60 */ "IncrVacuum" OpHelp(""), |
| 32843 | + /* 61 */ "VNext" OpHelp(""), |
| 32844 | + /* 62 */ "Init" OpHelp("Start at P2"), |
| 32845 | + /* 63 */ "PureFunc" OpHelp("r[P3]=func(r[P2@P5])"), |
| 32846 | + /* 64 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 32847 | + /* 65 */ "Return" OpHelp(""), |
| 32848 | + /* 66 */ "EndCoroutine" OpHelp(""), |
| 32849 | + /* 67 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 32850 | + /* 68 */ "Halt" OpHelp(""), |
| 32851 | + /* 69 */ "Integer" OpHelp("r[P2]=P1"), |
| 32852 | + /* 70 */ "Int64" OpHelp("r[P2]=P4"), |
| 32853 | + /* 71 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 32854 | + /* 72 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 32855 | + /* 73 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 32856 | + /* 74 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 32857 | + /* 75 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 32858 | + /* 76 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 32859 | + /* 77 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 32860 | + /* 78 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 32861 | + /* 79 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 32862 | + /* 80 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 32863 | + /* 81 */ "CollSeq" OpHelp(""), |
| 32864 | + /* 82 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 32865 | + /* 83 */ "RealAffinity" OpHelp(""), |
| 32866 | + /* 84 */ "Cast" OpHelp("affinity(r[P1])"), |
| 32867 | + /* 85 */ "Permutation" OpHelp(""), |
| 32868 | + /* 86 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 32869 | + /* 87 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"), |
| 32870 | + /* 88 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"), |
| 32871 | + /* 89 */ "Column" OpHelp("r[P3]=PX"), |
| 32872 | + /* 90 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 32873 | + /* 91 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 32874 | + /* 92 */ "Count" OpHelp("r[P2]=count()"), |
| 32875 | + /* 93 */ "ReadCookie" OpHelp(""), |
| 32876 | + /* 94 */ "SetCookie" OpHelp(""), |
| 32877 | + /* 95 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 32878 | + /* 96 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 32879 | + /* 97 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 32880 | + /* 98 */ "OpenDup" OpHelp(""), |
| 32881 | + /* 99 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 32882 | + /* 100 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 32623 | 32883 | /* 101 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 32624 | 32884 | /* 102 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 32625 | 32885 | /* 103 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 32626 | 32886 | /* 104 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 32627 | 32887 | /* 105 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| | @@ -32628,71 +32888,75 @@ |
| 32628 | 32888 | /* 106 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 32629 | 32889 | /* 107 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 32630 | 32890 | /* 108 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 32631 | 32891 | /* 109 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 32632 | 32892 | /* 110 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 32633 | | - /* 111 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 32893 | + /* 111 */ "SorterOpen" OpHelp(""), |
| 32634 | 32894 | /* 112 */ "BitNot" OpHelp("r[P2]= ~r[P1]"), |
| 32635 | | - /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 32636 | | - /* 114 */ "Close" OpHelp(""), |
| 32895 | + /* 113 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 32896 | + /* 114 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 32637 | 32897 | /* 115 */ "String8" OpHelp("r[P2]='P4'"), |
| 32638 | | - /* 116 */ "ColumnsUsed" OpHelp(""), |
| 32639 | | - /* 117 */ "SeekHit" OpHelp("seekHit=P2"), |
| 32640 | | - /* 118 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 32641 | | - /* 119 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 32642 | | - /* 120 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 32643 | | - /* 121 */ "Delete" OpHelp(""), |
| 32644 | | - /* 122 */ "ResetCount" OpHelp(""), |
| 32645 | | - /* 123 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 32646 | | - /* 124 */ "SorterData" OpHelp("r[P2]=data"), |
| 32647 | | - /* 125 */ "RowData" OpHelp("r[P2]=data"), |
| 32648 | | - /* 126 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 32649 | | - /* 127 */ "NullRow" OpHelp(""), |
| 32650 | | - /* 128 */ "SeekEnd" OpHelp(""), |
| 32651 | | - /* 129 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 32652 | | - /* 130 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 32653 | | - /* 131 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 32654 | | - /* 132 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 32655 | | - /* 133 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 32656 | | - /* 134 */ "Destroy" OpHelp(""), |
| 32657 | | - /* 135 */ "Clear" OpHelp(""), |
| 32658 | | - /* 136 */ "ResetSorter" OpHelp(""), |
| 32659 | | - /* 137 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 32660 | | - /* 138 */ "SqlExec" OpHelp(""), |
| 32661 | | - /* 139 */ "ParseSchema" OpHelp(""), |
| 32662 | | - /* 140 */ "LoadAnalysis" OpHelp(""), |
| 32663 | | - /* 141 */ "DropTable" OpHelp(""), |
| 32664 | | - /* 142 */ "DropIndex" OpHelp(""), |
| 32665 | | - /* 143 */ "DropTrigger" OpHelp(""), |
| 32666 | | - /* 144 */ "IntegrityCk" OpHelp(""), |
| 32667 | | - /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 32668 | | - /* 146 */ "Param" OpHelp(""), |
| 32669 | | - /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 32670 | | - /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 32671 | | - /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 32898 | + /* 116 */ "Close" OpHelp(""), |
| 32899 | + /* 117 */ "ColumnsUsed" OpHelp(""), |
| 32900 | + /* 118 */ "SeekHit" OpHelp("seekHit=P2"), |
| 32901 | + /* 119 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 32902 | + /* 120 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 32903 | + /* 121 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 32904 | + /* 122 */ "Delete" OpHelp(""), |
| 32905 | + /* 123 */ "ResetCount" OpHelp(""), |
| 32906 | + /* 124 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 32907 | + /* 125 */ "SorterData" OpHelp("r[P2]=data"), |
| 32908 | + /* 126 */ "RowData" OpHelp("r[P2]=data"), |
| 32909 | + /* 127 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 32910 | + /* 128 */ "NullRow" OpHelp(""), |
| 32911 | + /* 129 */ "SeekEnd" OpHelp(""), |
| 32912 | + /* 130 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 32913 | + /* 131 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 32914 | + /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 32915 | + /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"), |
| 32916 | + /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 32917 | + /* 135 */ "FinishSeek" OpHelp(""), |
| 32918 | + /* 136 */ "Destroy" OpHelp(""), |
| 32919 | + /* 137 */ "Clear" OpHelp(""), |
| 32920 | + /* 138 */ "ResetSorter" OpHelp(""), |
| 32921 | + /* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"), |
| 32922 | + /* 140 */ "SqlExec" OpHelp(""), |
| 32923 | + /* 141 */ "ParseSchema" OpHelp(""), |
| 32924 | + /* 142 */ "LoadAnalysis" OpHelp(""), |
| 32925 | + /* 143 */ "DropTable" OpHelp(""), |
| 32926 | + /* 144 */ "DropIndex" OpHelp(""), |
| 32927 | + /* 145 */ "DropTrigger" OpHelp(""), |
| 32928 | + /* 146 */ "IntegrityCk" OpHelp(""), |
| 32929 | + /* 147 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 32930 | + /* 148 */ "Param" OpHelp(""), |
| 32931 | + /* 149 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 32672 | 32932 | /* 150 */ "Real" OpHelp("r[P2]=P4"), |
| 32673 | | - /* 151 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), |
| 32674 | | - /* 152 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 32675 | | - /* 153 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 32676 | | - /* 154 */ "AggValue" OpHelp("r[P3]=value N=P2"), |
| 32677 | | - /* 155 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 32678 | | - /* 156 */ "Expire" OpHelp(""), |
| 32679 | | - /* 157 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 32680 | | - /* 158 */ "VBegin" OpHelp(""), |
| 32681 | | - /* 159 */ "VCreate" OpHelp(""), |
| 32682 | | - /* 160 */ "VDestroy" OpHelp(""), |
| 32683 | | - /* 161 */ "VOpen" OpHelp(""), |
| 32684 | | - /* 162 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 32685 | | - /* 163 */ "VRename" OpHelp(""), |
| 32686 | | - /* 164 */ "Pagecount" OpHelp(""), |
| 32687 | | - /* 165 */ "MaxPgcnt" OpHelp(""), |
| 32688 | | - /* 166 */ "Trace" OpHelp(""), |
| 32689 | | - /* 167 */ "CursorHint" OpHelp(""), |
| 32690 | | - /* 168 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), |
| 32691 | | - /* 169 */ "Noop" OpHelp(""), |
| 32692 | | - /* 170 */ "Explain" OpHelp(""), |
| 32693 | | - /* 171 */ "Abortable" OpHelp(""), |
| 32933 | + /* 151 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 32934 | + /* 152 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 32935 | + /* 153 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"), |
| 32936 | + /* 154 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 32937 | + /* 155 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 32938 | + /* 156 */ "AggValue" OpHelp("r[P3]=value N=P2"), |
| 32939 | + /* 157 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 32940 | + /* 158 */ "Expire" OpHelp(""), |
| 32941 | + /* 159 */ "CursorLock" OpHelp(""), |
| 32942 | + /* 160 */ "CursorUnlock" OpHelp(""), |
| 32943 | + /* 161 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 32944 | + /* 162 */ "VBegin" OpHelp(""), |
| 32945 | + /* 163 */ "VCreate" OpHelp(""), |
| 32946 | + /* 164 */ "VDestroy" OpHelp(""), |
| 32947 | + /* 165 */ "VOpen" OpHelp(""), |
| 32948 | + /* 166 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 32949 | + /* 167 */ "VRename" OpHelp(""), |
| 32950 | + /* 168 */ "Pagecount" OpHelp(""), |
| 32951 | + /* 169 */ "MaxPgcnt" OpHelp(""), |
| 32952 | + /* 170 */ "Trace" OpHelp(""), |
| 32953 | + /* 171 */ "CursorHint" OpHelp(""), |
| 32954 | + /* 172 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"), |
| 32955 | + /* 173 */ "Noop" OpHelp(""), |
| 32956 | + /* 174 */ "Explain" OpHelp(""), |
| 32957 | + /* 175 */ "Abortable" OpHelp(""), |
| 32694 | 32958 | }; |
| 32695 | 32959 | return azName[i]; |
| 32696 | 32960 | } |
| 32697 | 32961 | #endif |
| 32698 | 32962 | |
| | @@ -39156,11 +39420,11 @@ |
| 39156 | 39420 | assert( flags==SQLITE_ACCESS_EXISTS || flags==SQLITE_ACCESS_READWRITE ); |
| 39157 | 39421 | |
| 39158 | 39422 | if( flags==SQLITE_ACCESS_EXISTS ){ |
| 39159 | 39423 | struct stat buf; |
| 39160 | 39424 | *pResOut = 0==osStat(zPath, &buf) && |
| 39161 | | - (S_ISDIR(buf.st_mode) || buf.st_size>0); |
| 39425 | + (!S_ISREG(buf.st_mode) || buf.st_size>0); |
| 39162 | 39426 | }else{ |
| 39163 | 39427 | *pResOut = osAccess(zPath, W_OK|R_OK)==0; |
| 39164 | 39428 | } |
| 39165 | 39429 | return SQLITE_OK; |
| 39166 | 39430 | } |
| | @@ -52175,10 +52439,11 @@ |
| 52175 | 52439 | if( pPager->eLock!=UNKNOWN_LOCK ){ |
| 52176 | 52440 | pPager->eLock = (u8)eLock; |
| 52177 | 52441 | } |
| 52178 | 52442 | IOTRACE(("UNLOCK %p %d\n", pPager, eLock)) |
| 52179 | 52443 | } |
| 52444 | + pPager->changeCountDone = pPager->tempFile; /* ticket fb3b3024ea238d5c */ |
| 52180 | 52445 | return rc; |
| 52181 | 52446 | } |
| 52182 | 52447 | |
| 52183 | 52448 | /* |
| 52184 | 52449 | ** Lock the database file to level eLock, which must be either SHARED_LOCK, |
| | @@ -52896,11 +53161,10 @@ |
| 52896 | 53161 | /* The pager state may be changed from PAGER_ERROR to PAGER_OPEN here |
| 52897 | 53162 | ** without clearing the error code. This is intentional - the error |
| 52898 | 53163 | ** code is cleared and the cache reset in the block below. |
| 52899 | 53164 | */ |
| 52900 | 53165 | assert( pPager->errCode || pPager->eState!=PAGER_ERROR ); |
| 52901 | | - pPager->changeCountDone = 0; |
| 52902 | 53166 | pPager->eState = PAGER_OPEN; |
| 52903 | 53167 | } |
| 52904 | 53168 | |
| 52905 | 53169 | /* If Pager.errCode is set, the contents of the pager cache cannot be |
| 52906 | 53170 | ** trusted. Now that there are no outstanding references to the pager, |
| | @@ -53160,11 +53424,10 @@ |
| 53160 | 53424 | |
| 53161 | 53425 | if( !pPager->exclusiveMode |
| 53162 | 53426 | && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0)) |
| 53163 | 53427 | ){ |
| 53164 | 53428 | rc2 = pagerUnlockDb(pPager, SHARED_LOCK); |
| 53165 | | - pPager->changeCountDone = 0; |
| 53166 | 53429 | } |
| 53167 | 53430 | pPager->eState = PAGER_READER; |
| 53168 | 53431 | pPager->setMaster = 0; |
| 53169 | 53432 | |
| 53170 | 53433 | return (rc==SQLITE_OK?rc2:rc); |
| | @@ -63178,10 +63441,11 @@ |
| 63178 | 63441 | #define BTCF_ValidNKey 0x02 /* True if info.nKey is valid */ |
| 63179 | 63442 | #define BTCF_ValidOvfl 0x04 /* True if aOverflow is valid */ |
| 63180 | 63443 | #define BTCF_AtLast 0x08 /* Cursor is pointing ot the last entry */ |
| 63181 | 63444 | #define BTCF_Incrblob 0x10 /* True if an incremental I/O handle */ |
| 63182 | 63445 | #define BTCF_Multiple 0x20 /* Maybe another cursor on the same btree */ |
| 63446 | +#define BTCF_Pinned 0x40 /* Cursor is busy and cannot be moved */ |
| 63183 | 63447 | |
| 63184 | 63448 | /* |
| 63185 | 63449 | ** Potential values for BtCursor.eState. |
| 63186 | 63450 | ** |
| 63187 | 63451 | ** CURSOR_INVALID: |
| | @@ -64343,10 +64607,13 @@ |
| 64343 | 64607 | |
| 64344 | 64608 | assert( CURSOR_VALID==pCur->eState || CURSOR_SKIPNEXT==pCur->eState ); |
| 64345 | 64609 | assert( 0==pCur->pKey ); |
| 64346 | 64610 | assert( cursorHoldsMutex(pCur) ); |
| 64347 | 64611 | |
| 64612 | + if( pCur->curFlags & BTCF_Pinned ){ |
| 64613 | + return SQLITE_CONSTRAINT_PINNED; |
| 64614 | + } |
| 64348 | 64615 | if( pCur->eState==CURSOR_SKIPNEXT ){ |
| 64349 | 64616 | pCur->eState = CURSOR_VALID; |
| 64350 | 64617 | }else{ |
| 64351 | 64618 | pCur->skipNext = 0; |
| 64352 | 64619 | } |
| | @@ -65090,20 +65357,20 @@ |
| 65090 | 65357 | u8 *pEnd = &data[cellOffset + nCell*2]; |
| 65091 | 65358 | u8 *pAddr; |
| 65092 | 65359 | int sz2 = 0; |
| 65093 | 65360 | int sz = get2byte(&data[iFree+2]); |
| 65094 | 65361 | int top = get2byte(&data[hdr+5]); |
| 65095 | | - if( top>=iFree ){ |
| 65362 | + if( NEVER(top>=iFree) ){ |
| 65096 | 65363 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65097 | 65364 | } |
| 65098 | 65365 | if( iFree2 ){ |
| 65099 | 65366 | if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65100 | 65367 | sz2 = get2byte(&data[iFree2+2]); |
| 65101 | 65368 | if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65102 | 65369 | memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz)); |
| 65103 | 65370 | sz += sz2; |
| 65104 | | - }else if( iFree+sz>usableSize ){ |
| 65371 | + }else if( NEVER(iFree+sz>usableSize) ){ |
| 65105 | 65372 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65106 | 65373 | } |
| 65107 | 65374 | |
| 65108 | 65375 | cbrk = top+sz; |
| 65109 | 65376 | assert( cbrk+(iFree-top) <= usableSize ); |
| | @@ -65291,12 +65558,14 @@ |
| 65291 | 65558 | testcase( gap+1==top ); |
| 65292 | 65559 | testcase( gap==top ); |
| 65293 | 65560 | if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){ |
| 65294 | 65561 | u8 *pSpace = pageFindSlot(pPage, nByte, &rc); |
| 65295 | 65562 | if( pSpace ){ |
| 65563 | + int g2; |
| 65296 | 65564 | assert( pSpace+nByte<=data+pPage->pBt->usableSize ); |
| 65297 | | - if( (*pIdx = (int)(pSpace-data))<=gap ){ |
| 65565 | + *pIdx = g2 = (int)(pSpace-data); |
| 65566 | + if( NEVER(g2<=gap) ){ |
| 65298 | 65567 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65299 | 65568 | }else{ |
| 65300 | 65569 | return SQLITE_OK; |
| 65301 | 65570 | } |
| 65302 | 65571 | }else if( rc ){ |
| | @@ -65370,16 +65639,16 @@ |
| 65370 | 65639 | if( data[iPtr+1]==0 && data[iPtr]==0 ){ |
| 65371 | 65640 | iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */ |
| 65372 | 65641 | }else{ |
| 65373 | 65642 | while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){ |
| 65374 | 65643 | if( iFreeBlk<iPtr+4 ){ |
| 65375 | | - if( iFreeBlk==0 ) break; |
| 65644 | + if( ALWAYS(iFreeBlk==0) ) break; |
| 65376 | 65645 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65377 | 65646 | } |
| 65378 | 65647 | iPtr = iFreeBlk; |
| 65379 | 65648 | } |
| 65380 | | - if( iFreeBlk>pPage->pBt->usableSize-4 ){ |
| 65649 | + if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */ |
| 65381 | 65650 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65382 | 65651 | } |
| 65383 | 65652 | assert( iFreeBlk>iPtr || iFreeBlk==0 ); |
| 65384 | 65653 | |
| 65385 | 65654 | /* At this point: |
| | @@ -65390,11 +65659,11 @@ |
| 65390 | 65659 | */ |
| 65391 | 65660 | if( iFreeBlk && iEnd+3>=iFreeBlk ){ |
| 65392 | 65661 | nFrag = iFreeBlk - iEnd; |
| 65393 | 65662 | if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65394 | 65663 | iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]); |
| 65395 | | - if( iEnd > pPage->pBt->usableSize ){ |
| 65664 | + if( NEVER(iEnd > pPage->pBt->usableSize) ){ |
| 65396 | 65665 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65397 | 65666 | } |
| 65398 | 65667 | iSize = iEnd - iStart; |
| 65399 | 65668 | iFreeBlk = get2byte(&data[iFreeBlk]); |
| 65400 | 65669 | } |
| | @@ -65418,11 +65687,12 @@ |
| 65418 | 65687 | x = get2byte(&data[hdr+5]); |
| 65419 | 65688 | if( iStart<=x ){ |
| 65420 | 65689 | /* The new freeblock is at the beginning of the cell content area, |
| 65421 | 65690 | ** so just extend the cell content area rather than create another |
| 65422 | 65691 | ** freelist entry */ |
| 65423 | | - if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65692 | + if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65693 | + if( NEVER(iPtr!=hdr+1) ) return SQLITE_CORRUPT_PAGE(pPage); |
| 65424 | 65694 | put2byte(&data[hdr+1], iFreeBlk); |
| 65425 | 65695 | put2byte(&data[hdr+5], iEnd); |
| 65426 | 65696 | }else{ |
| 65427 | 65697 | /* Insert the new freeblock into the freelist */ |
| 65428 | 65698 | put2byte(&data[iPtr], iStart); |
| | @@ -65538,11 +65808,11 @@ |
| 65538 | 65808 | ** freeblocks. */ |
| 65539 | 65809 | pc = get2byte(&data[hdr+1]); |
| 65540 | 65810 | nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */ |
| 65541 | 65811 | if( pc>0 ){ |
| 65542 | 65812 | u32 next, size; |
| 65543 | | - if( pc<iCellFirst ){ |
| 65813 | + if( pc<top ){ |
| 65544 | 65814 | /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will |
| 65545 | 65815 | ** always be at least one cell before the first freeblock. |
| 65546 | 65816 | */ |
| 65547 | 65817 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65548 | 65818 | } |
| | @@ -65775,16 +66045,16 @@ |
| 65775 | 66045 | /* |
| 65776 | 66046 | ** Return the size of the database file in pages. If there is any kind of |
| 65777 | 66047 | ** error, return ((unsigned int)-1). |
| 65778 | 66048 | */ |
| 65779 | 66049 | static Pgno btreePagecount(BtShared *pBt){ |
| 66050 | + assert( (pBt->nPage & 0x80000000)==0 || CORRUPT_DB ); |
| 65780 | 66051 | return pBt->nPage; |
| 65781 | 66052 | } |
| 65782 | 66053 | SQLITE_PRIVATE u32 sqlite3BtreeLastPage(Btree *p){ |
| 65783 | 66054 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 65784 | | - assert( ((p->pBt->nPage)&0x80000000)==0 ); |
| 65785 | | - return btreePagecount(p->pBt); |
| 66055 | + return btreePagecount(p->pBt) & 0x7fffffff; |
| 65786 | 66056 | } |
| 65787 | 66057 | |
| 65788 | 66058 | /* |
| 65789 | 66059 | ** Get a page from the pager and initialize it. |
| 65790 | 66060 | ** |
| | @@ -68205,10 +68475,22 @@ |
| 68205 | 68475 | assert( pCur->eState==CURSOR_VALID ); |
| 68206 | 68476 | assert( pCur->curIntKey ); |
| 68207 | 68477 | getCellInfo(pCur); |
| 68208 | 68478 | return pCur->info.nKey; |
| 68209 | 68479 | } |
| 68480 | + |
| 68481 | +/* |
| 68482 | +** Pin or unpin a cursor. |
| 68483 | +*/ |
| 68484 | +SQLITE_PRIVATE void sqlite3BtreeCursorPin(BtCursor *pCur){ |
| 68485 | + assert( (pCur->curFlags & BTCF_Pinned)==0 ); |
| 68486 | + pCur->curFlags |= BTCF_Pinned; |
| 68487 | +} |
| 68488 | +SQLITE_PRIVATE void sqlite3BtreeCursorUnpin(BtCursor *pCur){ |
| 68489 | + assert( (pCur->curFlags & BTCF_Pinned)!=0 ); |
| 68490 | + pCur->curFlags &= ~BTCF_Pinned; |
| 68491 | +} |
| 68210 | 68492 | |
| 68211 | 68493 | #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 68212 | 68494 | /* |
| 68213 | 68495 | ** Return the offset into the database file for the start of the |
| 68214 | 68496 | ** payload to which the cursor is pointing. |
| | @@ -70565,11 +70847,11 @@ |
| 70565 | 70847 | int k; /* Current slot in pCArray->apEnd[] */ |
| 70566 | 70848 | u8 *pSrcEnd; /* Current pCArray->apEnd[k] value */ |
| 70567 | 70849 | |
| 70568 | 70850 | assert( i<iEnd ); |
| 70569 | 70851 | j = get2byte(&aData[hdr+5]); |
| 70570 | | - if( j>(u32)usableSize ){ j = 0; } |
| 70852 | + if( NEVER(j>(u32)usableSize) ){ j = 0; } |
| 70571 | 70853 | memcpy(&pTmp[j], &aData[j], usableSize - j); |
| 70572 | 70854 | |
| 70573 | 70855 | for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){} |
| 70574 | 70856 | pSrcEnd = pCArray->apEnd[k]; |
| 70575 | 70857 | |
| | @@ -70591,11 +70873,11 @@ |
| 70591 | 70873 | put2byte(pCellptr, (pData - aData)); |
| 70592 | 70874 | pCellptr += 2; |
| 70593 | 70875 | if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT; |
| 70594 | 70876 | memcpy(pData, pCell, sz); |
| 70595 | 70877 | assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB ); |
| 70596 | | - testcase( sz!=pPg->xCellSize(pPg,pCell) ); |
| 70878 | + testcase( sz!=pPg->xCellSize(pPg,pCell) ) |
| 70597 | 70879 | i++; |
| 70598 | 70880 | if( i>=iEnd ) break; |
| 70599 | 70881 | if( pCArray->ixNx[k]<=i ){ |
| 70600 | 70882 | k++; |
| 70601 | 70883 | pSrcEnd = pCArray->apEnd[k]; |
| | @@ -72302,11 +72584,10 @@ |
| 72302 | 72584 | */ |
| 72303 | 72585 | #ifdef SQLITE_DEBUG |
| 72304 | 72586 | if( flags & BTREE_SAVEPOSITION ){ |
| 72305 | 72587 | assert( pCur->curFlags & BTCF_ValidNKey ); |
| 72306 | 72588 | assert( pX->nKey==pCur->info.nKey ); |
| 72307 | | - assert( pCur->info.nSize!=0 ); |
| 72308 | 72589 | assert( loc==0 ); |
| 72309 | 72590 | } |
| 72310 | 72591 | #endif |
| 72311 | 72592 | |
| 72312 | 72593 | /* On the other hand, BTREE_SAVEPOSITION==0 does not imply |
| | @@ -75906,27 +76187,34 @@ |
| 75906 | 76187 | /* |
| 75907 | 76188 | ** This routine prepares a memory cell for modification by breaking |
| 75908 | 76189 | ** its link to a shallow copy and by marking any current shallow |
| 75909 | 76190 | ** copies of this cell as invalid. |
| 75910 | 76191 | ** |
| 75911 | | -** This is used for testing and debugging only - to make sure shallow |
| 75912 | | -** copies are not misused. |
| 76192 | +** This is used for testing and debugging only - to help ensure that shallow |
| 76193 | +** copies (created by OP_SCopy) are not misused. |
| 75913 | 76194 | */ |
| 75914 | 76195 | SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){ |
| 75915 | 76196 | int i; |
| 75916 | 76197 | Mem *pX; |
| 75917 | | - for(i=0, pX=pVdbe->aMem; i<pVdbe->nMem; i++, pX++){ |
| 76198 | + for(i=1, pX=pVdbe->aMem+1; i<pVdbe->nMem; i++, pX++){ |
| 75918 | 76199 | if( pX->pScopyFrom==pMem ){ |
| 76200 | + u16 mFlags; |
| 76201 | + if( pVdbe->db->flags & SQLITE_VdbeTrace ){ |
| 76202 | + sqlite3DebugPrintf("Invalidate R[%d] due to change in R[%d]\n", |
| 76203 | + (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem)); |
| 76204 | + } |
| 75919 | 76205 | /* If pX is marked as a shallow copy of pMem, then verify that |
| 75920 | 76206 | ** no significant changes have been made to pX since the OP_SCopy. |
| 75921 | 76207 | ** A significant change would indicated a missed call to this |
| 75922 | 76208 | ** function for pX. Minor changes, such as adding or removing a |
| 75923 | 76209 | ** dual type, are allowed, as long as the underlying value is the |
| 75924 | 76210 | ** same. */ |
| 75925 | | - u16 mFlags = pMem->flags & pX->flags & pX->mScopyFlags; |
| 76211 | + mFlags = pMem->flags & pX->flags & pX->mScopyFlags; |
| 75926 | 76212 | assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i ); |
| 75927 | | - assert( (mFlags&MEM_Real)==0 || pMem->u.r==pX->u.r ); |
| 76213 | + /* assert( (mFlags&MEM_Real)==0 || pMem->u.r==pX->u.r ); */ |
| 76214 | + /* ^^ */ |
| 76215 | + /* Cannot reliably compare doubles for equality */ |
| 75928 | 76216 | assert( (mFlags&MEM_Str)==0 || (pMem->n==pX->n && pMem->z==pX->z) ); |
| 75929 | 76217 | assert( (mFlags&MEM_Blob)==0 || sqlite3BlobCompare(pMem,pX)==0 ); |
| 75930 | 76218 | |
| 75931 | 76219 | /* pMem is the register that is changing. But also mark pX as |
| 75932 | 76220 | ** undefined so that we can quickly detect the shallow-copy error */ |
| | @@ -75935,11 +76223,10 @@ |
| 75935 | 76223 | } |
| 75936 | 76224 | } |
| 75937 | 76225 | pMem->pScopyFrom = 0; |
| 75938 | 76226 | } |
| 75939 | 76227 | #endif /* SQLITE_DEBUG */ |
| 75940 | | - |
| 75941 | 76228 | |
| 75942 | 76229 | /* |
| 75943 | 76230 | ** Make an shallow copy of pFrom into pTo. Prior contents of |
| 75944 | 76231 | ** pTo are freed. The pFrom->z field is not duplicated. If |
| 75945 | 76232 | ** pFrom->z is used, then pTo->z points to the same thing as pFrom->z |
| | @@ -76082,14 +76369,23 @@ |
| 76082 | 76369 | } |
| 76083 | 76370 | } |
| 76084 | 76371 | |
| 76085 | 76372 | pMem->n = nByte; |
| 76086 | 76373 | pMem->flags = flags; |
| 76087 | | - pMem->enc = (enc==0 ? SQLITE_UTF8 : enc); |
| 76374 | + if( enc ){ |
| 76375 | + pMem->enc = enc; |
| 76376 | +#ifdef SQLITE_ENABLE_SESSION |
| 76377 | + }else if( pMem->db==0 ){ |
| 76378 | + pMem->enc = SQLITE_UTF8; |
| 76379 | +#endif |
| 76380 | + }else{ |
| 76381 | + assert( pMem->db!=0 ); |
| 76382 | + pMem->enc = ENC(pMem->db); |
| 76383 | + } |
| 76088 | 76384 | |
| 76089 | 76385 | #ifndef SQLITE_OMIT_UTF16 |
| 76090 | | - if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){ |
| 76386 | + if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){ |
| 76091 | 76387 | return SQLITE_NOMEM_BKPT; |
| 76092 | 76388 | } |
| 76093 | 76389 | #endif |
| 76094 | 76390 | |
| 76095 | 76391 | if( nByte>iLimit ){ |
| | @@ -77040,13 +77336,20 @@ |
| 77040 | 77336 | } |
| 77041 | 77337 | |
| 77042 | 77338 | #ifdef SQLITE_DEBUG |
| 77043 | 77339 | /* This routine is just a convenient place to set a breakpoint that will |
| 77044 | 77340 | ** fire after each opcode is inserted and displayed using |
| 77045 | | -** "PRAGMA vdbe_addoptrace=on". |
| 77341 | +** "PRAGMA vdbe_addoptrace=on". Parameters "pc" (program counter) and |
| 77342 | +** pOp are available to make the breakpoint conditional. |
| 77343 | +** |
| 77344 | +** Other useful labels for breakpoints include: |
| 77345 | +** test_trace_breakpoint(pc,pOp) |
| 77346 | +** sqlite3CorruptError(lineno) |
| 77347 | +** sqlite3MisuseError(lineno) |
| 77348 | +** sqlite3CantopenError(lineno) |
| 77046 | 77349 | */ |
| 77047 | | -static void test_addop_breakpoint(void){ |
| 77350 | +static void test_addop_breakpoint(int pc, Op *pOp){ |
| 77048 | 77351 | static int n = 0; |
| 77049 | 77352 | n++; |
| 77050 | 77353 | } |
| 77051 | 77354 | #endif |
| 77052 | 77355 | |
| | @@ -77095,11 +77398,11 @@ |
| 77095 | 77398 | pOp->zComment = 0; |
| 77096 | 77399 | #endif |
| 77097 | 77400 | #ifdef SQLITE_DEBUG |
| 77098 | 77401 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 77099 | 77402 | sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 77100 | | - test_addop_breakpoint(); |
| 77403 | + test_addop_breakpoint(i, &p->aOp[i]); |
| 77101 | 77404 | } |
| 77102 | 77405 | #endif |
| 77103 | 77406 | #ifdef VDBE_PROFILE |
| 77104 | 77407 | pOp->cycles = 0; |
| 77105 | 77408 | pOp->cnt = 0; |
| | @@ -78037,12 +78340,21 @@ |
| 78037 | 78340 | #ifdef SQLITE_DEBUG |
| 78038 | 78341 | /* |
| 78039 | 78342 | ** Generate an OP_ReleaseReg opcode to indicate that a range of |
| 78040 | 78343 | ** registers, except any identified by mask, are no longer in use. |
| 78041 | 78344 | */ |
| 78042 | | -SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters(Parse *pParse, int iFirst, int N, u32 mask){ |
| 78345 | +SQLITE_PRIVATE void sqlite3VdbeReleaseRegisters( |
| 78346 | + Parse *pParse, /* Parsing context */ |
| 78347 | + int iFirst, /* Index of first register to be released */ |
| 78348 | + int N, /* Number of registers to release */ |
| 78349 | + u32 mask, /* Mask of registers to NOT release */ |
| 78350 | + int bUndefine /* If true, mark registers as undefined */ |
| 78351 | +){ |
| 78352 | + if( N==0 ) return; |
| 78043 | 78353 | assert( pParse->pVdbe ); |
| 78354 | + assert( iFirst>=1 ); |
| 78355 | + assert( iFirst+N-1<=pParse->nMem ); |
| 78044 | 78356 | while( N>0 && (mask&1)!=0 ){ |
| 78045 | 78357 | mask >>= 1; |
| 78046 | 78358 | iFirst++; |
| 78047 | 78359 | N--; |
| 78048 | 78360 | } |
| | @@ -78050,10 +78362,11 @@ |
| 78050 | 78362 | mask &= ~MASKBIT32(N-1); |
| 78051 | 78363 | N--; |
| 78052 | 78364 | } |
| 78053 | 78365 | if( N>0 ){ |
| 78054 | 78366 | sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask); |
| 78367 | + if( bUndefine ) sqlite3VdbeChangeP5(pParse->pVdbe, 1); |
| 78055 | 78368 | } |
| 78056 | 78369 | } |
| 78057 | 78370 | #endif /* SQLITE_DEBUG */ |
| 78058 | 78371 | |
| 78059 | 78372 | |
| | @@ -80260,11 +80573,11 @@ |
| 80260 | 80573 | /* |
| 80261 | 80574 | ** The cursor "p" has a pending seek operation that has not yet been |
| 80262 | 80575 | ** carried out. Seek the cursor now. If an error occurs, return |
| 80263 | 80576 | ** the appropriate error code. |
| 80264 | 80577 | */ |
| 80265 | | -static int SQLITE_NOINLINE handleDeferredMoveto(VdbeCursor *p){ |
| 80578 | +SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor *p){ |
| 80266 | 80579 | int res, rc; |
| 80267 | 80580 | #ifdef SQLITE_TEST |
| 80268 | 80581 | extern int sqlite3_search_count; |
| 80269 | 80582 | #endif |
| 80270 | 80583 | assert( p->deferredMoveto ); |
| | @@ -80332,11 +80645,11 @@ |
| 80332 | 80645 | if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){ |
| 80333 | 80646 | *pp = p->pAltCursor; |
| 80334 | 80647 | *piCol = iMap - 1; |
| 80335 | 80648 | return SQLITE_OK; |
| 80336 | 80649 | } |
| 80337 | | - return handleDeferredMoveto(p); |
| 80650 | + return sqlite3VdbeFinishMoveto(p); |
| 80338 | 80651 | } |
| 80339 | 80652 | if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 80340 | 80653 | return handleMovedCursor(p); |
| 80341 | 80654 | } |
| 80342 | 80655 | return SQLITE_OK; |
| | @@ -84375,10 +84688,30 @@ |
| 84375 | 84688 | # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P) |
| 84376 | 84689 | #else |
| 84377 | 84690 | # define UPDATE_MAX_BLOBSIZE(P) |
| 84378 | 84691 | #endif |
| 84379 | 84692 | |
| 84693 | +#ifdef SQLITE_DEBUG |
| 84694 | +/* This routine provides a convenient place to set a breakpoint during |
| 84695 | +** tracing with PRAGMA vdbe_trace=on. The breakpoint fires right after |
| 84696 | +** each opcode is printed. Variables "pc" (program counter) and pOp are |
| 84697 | +** available to add conditionals to the breakpoint. GDB example: |
| 84698 | +** |
| 84699 | +** break test_trace_breakpoint if pc=22 |
| 84700 | +** |
| 84701 | +** Other useful labels for breakpoints include: |
| 84702 | +** test_addop_breakpoint(pc,pOp) |
| 84703 | +** sqlite3CorruptError(lineno) |
| 84704 | +** sqlite3MisuseError(lineno) |
| 84705 | +** sqlite3CantopenError(lineno) |
| 84706 | +*/ |
| 84707 | +static void test_trace_breakpoint(int pc, Op *pOp, Vdbe *v){ |
| 84708 | + static int n = 0; |
| 84709 | + n++; |
| 84710 | +} |
| 84711 | +#endif |
| 84712 | + |
| 84380 | 84713 | /* |
| 84381 | 84714 | ** Invoke the VDBE coverage callback, if that callback is defined. This |
| 84382 | 84715 | ** feature is used for test suite validation only and does not appear an |
| 84383 | 84716 | ** production builds. |
| 84384 | 84717 | ** |
| | @@ -84719,16 +85052,13 @@ |
| 84719 | 85052 | #ifdef SQLITE_DEBUG |
| 84720 | 85053 | /* |
| 84721 | 85054 | ** Write a nice string representation of the contents of cell pMem |
| 84722 | 85055 | ** into buffer zBuf, length nBuf. |
| 84723 | 85056 | */ |
| 84724 | | -SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, char *zBuf){ |
| 84725 | | - char *zCsr = zBuf; |
| 85057 | +SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr){ |
| 84726 | 85058 | int f = pMem->flags; |
| 84727 | | - |
| 84728 | 85059 | static const char *const encnames[] = {"(X)", "(8)", "(16LE)", "(16BE)"}; |
| 84729 | | - |
| 84730 | 85060 | if( f&MEM_Blob ){ |
| 84731 | 85061 | int i; |
| 84732 | 85062 | char c; |
| 84733 | 85063 | if( f & MEM_Dyn ){ |
| 84734 | 85064 | c = 'z'; |
| | @@ -84740,61 +85070,44 @@ |
| 84740 | 85070 | c = 'e'; |
| 84741 | 85071 | assert( (f & (MEM_Static|MEM_Dyn))==0 ); |
| 84742 | 85072 | }else{ |
| 84743 | 85073 | c = 's'; |
| 84744 | 85074 | } |
| 84745 | | - *(zCsr++) = c; |
| 84746 | | - *(zCsr++) = 'x'; |
| 84747 | | - sqlite3_snprintf(100, zCsr, "%d[", pMem->n); |
| 84748 | | - zCsr += sqlite3Strlen30(zCsr); |
| 85075 | + sqlite3_str_appendf(pStr, "%cx[", c); |
| 84749 | 85076 | for(i=0; i<25 && i<pMem->n; i++){ |
| 84750 | | - sqlite3_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF)); |
| 84751 | | - zCsr += sqlite3Strlen30(zCsr); |
| 85077 | + sqlite3_str_appendf(pStr, "%02X", ((int)pMem->z[i] & 0xFF)); |
| 84752 | 85078 | } |
| 84753 | | - *zCsr++ = '|'; |
| 85079 | + sqlite3_str_appendf(pStr, "|"); |
| 84754 | 85080 | for(i=0; i<25 && i<pMem->n; i++){ |
| 84755 | 85081 | char z = pMem->z[i]; |
| 84756 | | - if( z<32 || z>126 ) *zCsr++ = '.'; |
| 84757 | | - else *zCsr++ = z; |
| 85082 | + sqlite3_str_appendchar(pStr, 1, (z<32||z>126)?'.':z); |
| 84758 | 85083 | } |
| 84759 | | - *(zCsr++) = ']'; |
| 85084 | + sqlite3_str_appendf(pStr,"]"); |
| 84760 | 85085 | if( f & MEM_Zero ){ |
| 84761 | | - sqlite3_snprintf(100, zCsr,"+%dz",pMem->u.nZero); |
| 84762 | | - zCsr += sqlite3Strlen30(zCsr); |
| 85086 | + sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero); |
| 84763 | 85087 | } |
| 84764 | | - *zCsr = '\0'; |
| 84765 | 85088 | }else if( f & MEM_Str ){ |
| 84766 | | - int j, k; |
| 84767 | | - zBuf[0] = ' '; |
| 85089 | + int j; |
| 85090 | + int c; |
| 84768 | 85091 | if( f & MEM_Dyn ){ |
| 84769 | | - zBuf[1] = 'z'; |
| 85092 | + c = 'z'; |
| 84770 | 85093 | assert( (f & (MEM_Static|MEM_Ephem))==0 ); |
| 84771 | 85094 | }else if( f & MEM_Static ){ |
| 84772 | | - zBuf[1] = 't'; |
| 85095 | + c = 't'; |
| 84773 | 85096 | assert( (f & (MEM_Dyn|MEM_Ephem))==0 ); |
| 84774 | 85097 | }else if( f & MEM_Ephem ){ |
| 84775 | | - zBuf[1] = 'e'; |
| 85098 | + c = 'e'; |
| 84776 | 85099 | assert( (f & (MEM_Static|MEM_Dyn))==0 ); |
| 84777 | 85100 | }else{ |
| 84778 | | - zBuf[1] = 's'; |
| 85101 | + c = 's'; |
| 84779 | 85102 | } |
| 84780 | | - k = 2; |
| 84781 | | - sqlite3_snprintf(100, &zBuf[k], "%d", pMem->n); |
| 84782 | | - k += sqlite3Strlen30(&zBuf[k]); |
| 84783 | | - zBuf[k++] = '['; |
| 85103 | + sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n); |
| 84784 | 85104 | for(j=0; j<25 && j<pMem->n; j++){ |
| 84785 | 85105 | u8 c = pMem->z[j]; |
| 84786 | | - if( c>=0x20 && c<0x7f ){ |
| 84787 | | - zBuf[k++] = c; |
| 84788 | | - }else{ |
| 84789 | | - zBuf[k++] = '.'; |
| 84790 | | - } |
| 84791 | | - } |
| 84792 | | - zBuf[k++] = ']'; |
| 84793 | | - sqlite3_snprintf(100,&zBuf[k], encnames[pMem->enc]); |
| 84794 | | - k += sqlite3Strlen30(&zBuf[k]); |
| 84795 | | - zBuf[k++] = 0; |
| 85106 | + sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.'); |
| 85107 | + } |
| 85108 | + sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]); |
| 84796 | 85109 | } |
| 84797 | 85110 | } |
| 84798 | 85111 | #endif |
| 84799 | 85112 | |
| 84800 | 85113 | #ifdef SQLITE_DEBUG |
| | @@ -84817,23 +85130,40 @@ |
| 84817 | 85130 | printf(" r:%.17g", p->u.r); |
| 84818 | 85131 | #endif |
| 84819 | 85132 | }else if( sqlite3VdbeMemIsRowSet(p) ){ |
| 84820 | 85133 | printf(" (rowset)"); |
| 84821 | 85134 | }else{ |
| 84822 | | - char zBuf[200]; |
| 84823 | | - sqlite3VdbeMemPrettyPrint(p, zBuf); |
| 84824 | | - printf(" %s", zBuf); |
| 85135 | + StrAccum acc; |
| 85136 | + char zBuf[1000]; |
| 85137 | + sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0); |
| 85138 | + sqlite3VdbeMemPrettyPrint(p, &acc); |
| 85139 | + printf(" %s", sqlite3StrAccumFinish(&acc)); |
| 84825 | 85140 | } |
| 84826 | 85141 | if( p->flags & MEM_Subtype ) printf(" subtype=0x%02x", p->eSubtype); |
| 84827 | 85142 | } |
| 84828 | 85143 | static void registerTrace(int iReg, Mem *p){ |
| 84829 | | - printf("REG[%d] = ", iReg); |
| 85144 | + printf("R[%d] = ", iReg); |
| 84830 | 85145 | memTracePrint(p); |
| 85146 | + if( p->pScopyFrom ){ |
| 85147 | + printf(" <== R[%d]", (int)(p->pScopyFrom - &p[-iReg])); |
| 85148 | + } |
| 84831 | 85149 | printf("\n"); |
| 84832 | 85150 | sqlite3VdbeCheckMemInvariants(p); |
| 84833 | 85151 | } |
| 84834 | 85152 | #endif |
| 85153 | + |
| 85154 | +#ifdef SQLITE_DEBUG |
| 85155 | +/* |
| 85156 | +** Show the values of all registers in the virtual machine. Used for |
| 85157 | +** interactive debugging. |
| 85158 | +*/ |
| 85159 | +SQLITE_PRIVATE void sqlite3VdbeRegisterDump(Vdbe *v){ |
| 85160 | + int i; |
| 85161 | + for(i=1; i<v->nMem; i++) registerTrace(i, v->aMem+i); |
| 85162 | +} |
| 85163 | +#endif /* SQLITE_DEBUG */ |
| 85164 | + |
| 84835 | 85165 | |
| 84836 | 85166 | #ifdef SQLITE_DEBUG |
| 84837 | 85167 | # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M) |
| 84838 | 85168 | #else |
| 84839 | 85169 | # define REGISTER_TRACE(R,M) |
| | @@ -85085,10 +85415,11 @@ |
| 85085 | 85415 | /* Only allow tracing if SQLITE_DEBUG is defined. |
| 85086 | 85416 | */ |
| 85087 | 85417 | #ifdef SQLITE_DEBUG |
| 85088 | 85418 | if( db->flags & SQLITE_VdbeTrace ){ |
| 85089 | 85419 | sqlite3VdbePrintOp(stdout, (int)(pOp - aOp), pOp); |
| 85420 | + test_trace_breakpoint((int)(pOp - aOp),pOp,p); |
| 85090 | 85421 | } |
| 85091 | 85422 | #endif |
| 85092 | 85423 | |
| 85093 | 85424 | |
| 85094 | 85425 | /* Check to see if we need to simulate an interrupt. This only happens |
| | @@ -85192,10 +85523,24 @@ |
| 85192 | 85523 | ** is sometimes set to 1 instead of 0 as a hint to the command-line shell |
| 85193 | 85524 | ** that this Goto is the bottom of a loop and that the lines from P2 down |
| 85194 | 85525 | ** to the current line should be indented for EXPLAIN output. |
| 85195 | 85526 | */ |
| 85196 | 85527 | case OP_Goto: { /* jump */ |
| 85528 | + |
| 85529 | +#ifdef SQLITE_DEBUG |
| 85530 | + /* In debuggging mode, when the p5 flags is set on an OP_Goto, that |
| 85531 | + ** means we should really jump back to the preceeding OP_ReleaseReg |
| 85532 | + ** instruction. */ |
| 85533 | + if( pOp->p5 ){ |
| 85534 | + assert( pOp->p2 < (int)(pOp - aOp) ); |
| 85535 | + assert( pOp->p2 > 1 ); |
| 85536 | + pOp = &aOp[pOp->p2 - 2]; |
| 85537 | + assert( pOp[1].opcode==OP_ReleaseReg ); |
| 85538 | + goto check_for_interrupt; |
| 85539 | + } |
| 85540 | +#endif |
| 85541 | + |
| 85197 | 85542 | jump_to_p2_and_check_for_interrupt: |
| 85198 | 85543 | pOp = &aOp[pOp->p2 - 1]; |
| 85199 | 85544 | |
| 85200 | 85545 | /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev, |
| 85201 | 85546 | ** OP_VNext, or OP_SorterNext) all jump here upon |
| | @@ -85668,12 +86013,17 @@ |
| 85668 | 86013 | assert( pIn1<=&aMem[(p->nMem+1 - p->nCursor)] ); |
| 85669 | 86014 | assert( memIsValid(pIn1) ); |
| 85670 | 86015 | memAboutToChange(p, pOut); |
| 85671 | 86016 | sqlite3VdbeMemMove(pOut, pIn1); |
| 85672 | 86017 | #ifdef SQLITE_DEBUG |
| 85673 | | - if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<pOut ){ |
| 85674 | | - pOut->pScopyFrom += pOp->p2 - p1; |
| 86018 | + pIn1->pScopyFrom = 0; |
| 86019 | + { int i; |
| 86020 | + for(i=1; i<p->nMem; i++){ |
| 86021 | + if( aMem[i].pScopyFrom==pIn1 ){ |
| 86022 | + aMem[i].pScopyFrom = pOut; |
| 86023 | + } |
| 86024 | + } |
| 85675 | 86025 | } |
| 85676 | 86026 | #endif |
| 85677 | 86027 | Deephemeralize(pOut); |
| 85678 | 86028 | REGISTER_TRACE(p2++, pOut); |
| 85679 | 86029 | pIn1++; |
| | @@ -85810,16 +86160,25 @@ |
| 85810 | 86160 | Deephemeralize(&pMem[i]); |
| 85811 | 86161 | assert( (pMem[i].flags & MEM_Ephem)==0 |
| 85812 | 86162 | || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 ); |
| 85813 | 86163 | sqlite3VdbeMemNulTerminate(&pMem[i]); |
| 85814 | 86164 | REGISTER_TRACE(pOp->p1+i, &pMem[i]); |
| 86165 | +#ifdef SQLITE_DEBUG |
| 86166 | + /* The registers in the result will not be used again when the |
| 86167 | + ** prepared statement restarts. This is because sqlite3_column() |
| 86168 | + ** APIs might have caused type conversions of made other changes to |
| 86169 | + ** the register values. Therefore, we can go ahead and break any |
| 86170 | + ** OP_SCopy dependencies. */ |
| 86171 | + pMem[i].pScopyFrom = 0; |
| 86172 | +#endif |
| 85815 | 86173 | } |
| 85816 | 86174 | if( db->mallocFailed ) goto no_mem; |
| 85817 | 86175 | |
| 85818 | 86176 | if( db->mTrace & SQLITE_TRACE_ROW ){ |
| 85819 | 86177 | db->xTrace(SQLITE_TRACE_ROW, db->pTraceArg, p, 0); |
| 85820 | 86178 | } |
| 86179 | + |
| 85821 | 86180 | |
| 85822 | 86181 | /* Return SQLITE_ROW |
| 85823 | 86182 | */ |
| 85824 | 86183 | p->pc = (int)(pOp - aOp) + 1; |
| 85825 | 86184 | rc = SQLITE_ROW; |
| | @@ -87132,14 +87491,15 @@ |
| 87132 | 87491 | ** So we might as well use bogus content rather than reading |
| 87133 | 87492 | ** content from disk. |
| 87134 | 87493 | ** |
| 87135 | 87494 | ** Although sqlite3VdbeSerialGet() may read at most 8 bytes from the |
| 87136 | 87495 | ** buffer passed to it, debugging function VdbeMemPrettyPrint() may |
| 87137 | | - ** read up to 16. So 16 bytes of bogus content is supplied. |
| 87496 | + ** read more. Use the global constant sqlite3CtypeMap[] as the array, |
| 87497 | + ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint()) |
| 87498 | + ** and it begins with a bunch of zeros. |
| 87138 | 87499 | */ |
| 87139 | | - static u8 aZero[16]; /* This is the bogus content */ |
| 87140 | | - sqlite3VdbeSerialGet(aZero, t, pDest); |
| 87500 | + sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest); |
| 87141 | 87501 | }else{ |
| 87142 | 87502 | rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); |
| 87143 | 87503 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 87144 | 87504 | sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); |
| 87145 | 87505 | pDest->flags &= ~MEM_Ephem; |
| | @@ -88657,11 +89017,11 @@ |
| 88657 | 89017 | |
| 88658 | 89018 | /* Opcode: SeekHit P1 P2 * * * |
| 88659 | 89019 | ** Synopsis: seekHit=P2 |
| 88660 | 89020 | ** |
| 88661 | 89021 | ** Set the seekHit flag on cursor P1 to the value in P2. |
| 88662 | | -** The seekHit flag is used by the IfNoHope opcode. |
| 89022 | +* The seekHit flag is used by the IfNoHope opcode. |
| 88663 | 89023 | ** |
| 88664 | 89024 | ** P1 must be a valid b-tree cursor. P2 must be a boolean value, |
| 88665 | 89025 | ** either 0 or 1. |
| 88666 | 89026 | */ |
| 88667 | 89027 | case OP_SeekHit: { |
| | @@ -88671,10 +89031,24 @@ |
| 88671 | 89031 | assert( pC!=0 ); |
| 88672 | 89032 | assert( pOp->p2==0 || pOp->p2==1 ); |
| 88673 | 89033 | pC->seekHit = pOp->p2 & 1; |
| 88674 | 89034 | break; |
| 88675 | 89035 | } |
| 89036 | + |
| 89037 | +/* Opcode: IfNotOpen P1 P2 * * * |
| 89038 | +** Synopsis: if( !csr[P1] ) goto P2 |
| 89039 | +** |
| 89040 | +** If cursor P1 is not open, jump to instruction P2. Otherwise, fall through. |
| 89041 | +*/ |
| 89042 | +case OP_IfNotOpen: { /* jump */ |
| 89043 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 89044 | + VdbeBranchTaken(p->apCsr[pOp->p1]==0, 2); |
| 89045 | + if( !p->apCsr[pOp->p1] ){ |
| 89046 | + goto jump_to_p2_and_check_for_interrupt; |
| 89047 | + } |
| 89048 | + break; |
| 89049 | +} |
| 88676 | 89050 | |
| 88677 | 89051 | /* Opcode: Found P1 P2 P3 P4 * |
| 88678 | 89052 | ** Synopsis: key=r[P3@P4] |
| 88679 | 89053 | ** |
| 88680 | 89054 | ** If P4==0 then register P3 holds a blob constructed by MakeRecord. If |
| | @@ -89160,10 +89534,11 @@ |
| 89160 | 89534 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 89161 | 89535 | assert( memIsValid(pData) ); |
| 89162 | 89536 | pC = p->apCsr[pOp->p1]; |
| 89163 | 89537 | assert( pC!=0 ); |
| 89164 | 89538 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 89539 | + assert( pC->deferredMoveto==0 ); |
| 89165 | 89540 | assert( pC->uc.pCursor!=0 ); |
| 89166 | 89541 | assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable ); |
| 89167 | 89542 | assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC ); |
| 89168 | 89543 | REGISTER_TRACE(pOp->p2, pData); |
| 89169 | 89544 | sqlite3VdbeIncrWriteCounter(p, pC); |
| | @@ -89277,11 +89652,15 @@ |
| 89277 | 89652 | assert( pC->uc.pCursor!=0 ); |
| 89278 | 89653 | assert( pC->deferredMoveto==0 ); |
| 89279 | 89654 | sqlite3VdbeIncrWriteCounter(p, pC); |
| 89280 | 89655 | |
| 89281 | 89656 | #ifdef SQLITE_DEBUG |
| 89282 | | - if( pOp->p4type==P4_TABLE && HasRowid(pOp->p4.pTab) && pOp->p5==0 ){ |
| 89657 | + if( pOp->p4type==P4_TABLE |
| 89658 | + && HasRowid(pOp->p4.pTab) |
| 89659 | + && pOp->p5==0 |
| 89660 | + && sqlite3BtreeCursorIsValidNN(pC->uc.pCursor) |
| 89661 | + ){ |
| 89283 | 89662 | /* If p5 is zero, the seek operation that positioned the cursor prior to |
| 89284 | 89663 | ** OP_Delete will have also set the pC->movetoTarget field to the rowid of |
| 89285 | 89664 | ** the row that is being deleted */ |
| 89286 | 89665 | i64 iKey = sqlite3BtreeIntegerKey(pC->uc.pCursor); |
| 89287 | 89666 | assert( CORRUPT_DB || pC->movetoTarget==iKey ); |
| | @@ -90032,10 +90411,28 @@ |
| 90032 | 90411 | assert( pOp->opcode==OP_IdxRowid ); |
| 90033 | 90412 | sqlite3VdbeMemSetNull(&aMem[pOp->p2]); |
| 90034 | 90413 | } |
| 90035 | 90414 | break; |
| 90036 | 90415 | } |
| 90416 | + |
| 90417 | +/* Opcode: FinishSeek P1 * * * * |
| 90418 | +** |
| 90419 | +** If cursor P1 was previously moved via OP_DeferredSeek, complete that |
| 90420 | +** seek operation now, without further delay. If the cursor seek has |
| 90421 | +** already occurred, this instruction is a no-op. |
| 90422 | +*/ |
| 90423 | +case OP_FinishSeek: { |
| 90424 | + VdbeCursor *pC; /* The P1 index cursor */ |
| 90425 | + |
| 90426 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90427 | + pC = p->apCsr[pOp->p1]; |
| 90428 | + if( pC->deferredMoveto ){ |
| 90429 | + rc = sqlite3VdbeFinishMoveto(pC); |
| 90430 | + if( rc ) goto abort_due_to_error; |
| 90431 | + } |
| 90432 | + break; |
| 90433 | +} |
| 90037 | 90434 | |
| 90038 | 90435 | /* Opcode: IdxGE P1 P2 P3 P4 P5 |
| 90039 | 90436 | ** Synopsis: key=r[P3@P4] |
| 90040 | 90437 | ** |
| 90041 | 90438 | ** The P4 register values beginning with P3 form an unpacked index |
| | @@ -91338,10 +91735,40 @@ |
| 91338 | 91735 | }else{ |
| 91339 | 91736 | p->expired = pOp->p2+1; |
| 91340 | 91737 | } |
| 91341 | 91738 | break; |
| 91342 | 91739 | } |
| 91740 | + |
| 91741 | +/* Opcode: CursorLock P1 * * * * |
| 91742 | +** |
| 91743 | +** Lock the btree to which cursor P1 is pointing so that the btree cannot be |
| 91744 | +** written by an other cursor. |
| 91745 | +*/ |
| 91746 | +case OP_CursorLock: { |
| 91747 | + VdbeCursor *pC; |
| 91748 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 91749 | + pC = p->apCsr[pOp->p1]; |
| 91750 | + assert( pC!=0 ); |
| 91751 | + assert( pC->eCurType==CURTYPE_BTREE ); |
| 91752 | + sqlite3BtreeCursorPin(pC->uc.pCursor); |
| 91753 | + break; |
| 91754 | +} |
| 91755 | + |
| 91756 | +/* Opcode: CursorUnlock P1 * * * * |
| 91757 | +** |
| 91758 | +** Unlock the btree to which cursor P1 is pointing so that it can be |
| 91759 | +** written by other cursors. |
| 91760 | +*/ |
| 91761 | +case OP_CursorUnlock: { |
| 91762 | + VdbeCursor *pC; |
| 91763 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 91764 | + pC = p->apCsr[pOp->p1]; |
| 91765 | + assert( pC!=0 ); |
| 91766 | + assert( pC->eCurType==CURTYPE_BTREE ); |
| 91767 | + sqlite3BtreeCursorUnpin(pC->uc.pCursor); |
| 91768 | + break; |
| 91769 | +} |
| 91343 | 91770 | |
| 91344 | 91771 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 91345 | 91772 | /* Opcode: TableLock P1 P2 P3 P4 * |
| 91346 | 91773 | ** Synopsis: iDb=P1 root=P2 write=P3 |
| 91347 | 91774 | ** |
| | @@ -92045,11 +92472,11 @@ |
| 92045 | 92472 | break; |
| 92046 | 92473 | } |
| 92047 | 92474 | #endif |
| 92048 | 92475 | |
| 92049 | 92476 | #ifdef SQLITE_DEBUG |
| 92050 | | -/* Opcode: ReleaseReg P1 P2 P3 * * |
| 92477 | +/* Opcode: ReleaseReg P1 P2 P3 * P5 |
| 92051 | 92478 | ** Synopsis: release r[P1@P2] mask P3 |
| 92052 | 92479 | ** |
| 92053 | 92480 | ** Release registers from service. Any content that was in the |
| 92054 | 92481 | ** the registers is unreliable after this opcode completes. |
| 92055 | 92482 | ** |
| | @@ -92060,14 +92487,16 @@ |
| 92060 | 92487 | ** Releasing a register clears the Mem.pScopyFrom pointer. That means |
| 92061 | 92488 | ** that if the content of the released register was set using OP_SCopy, |
| 92062 | 92489 | ** a change to the value of the source register for the OP_SCopy will no longer |
| 92063 | 92490 | ** generate an assertion fault in sqlite3VdbeMemAboutToChange(). |
| 92064 | 92491 | ** |
| 92065 | | -** TODO: Released registers ought to also have their datatype set to |
| 92066 | | -** MEM_Undefined so that any subsequent attempt to read the released |
| 92492 | +** If P5 is set, then all released registers have their type set |
| 92493 | +** to MEM_Undefined so that any subsequent attempt to read the released |
| 92067 | 92494 | ** register (before it is reinitialized) will generate an assertion fault. |
| 92068 | | -** However, there are places in the code generator which release registers |
| 92495 | +** |
| 92496 | +** P5 ought to be set on every call to this opcode. |
| 92497 | +** However, there are places in the code generator will release registers |
| 92069 | 92498 | ** before their are used, under the (valid) assumption that the registers |
| 92070 | 92499 | ** will not be reallocated for some other purpose before they are used and |
| 92071 | 92500 | ** hence are safe to release. |
| 92072 | 92501 | ** |
| 92073 | 92502 | ** This opcode is only available in testing and debugging builds. It is |
| | @@ -92084,11 +92513,11 @@ |
| 92084 | 92513 | pMem = &aMem[pOp->p1]; |
| 92085 | 92514 | constMask = pOp->p3; |
| 92086 | 92515 | for(i=0; i<pOp->p2; i++, pMem++){ |
| 92087 | 92516 | if( i>=32 || (constMask & MASKBIT32(i))==0 ){ |
| 92088 | 92517 | pMem->pScopyFrom = 0; |
| 92089 | | - /* MemSetTypeFlag(pMem, MEM_Undefined); // See the TODO */ |
| 92518 | + if( i<32 && pOp->p5 ) MemSetTypeFlag(pMem, MEM_Undefined); |
| 92090 | 92519 | } |
| 92091 | 92520 | } |
| 92092 | 92521 | break; |
| 92093 | 92522 | } |
| 92094 | 92523 | #endif |
| | @@ -92142,10 +92571,16 @@ |
| 92142 | 92571 | registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]); |
| 92143 | 92572 | } |
| 92144 | 92573 | if( opProperty & OPFLG_OUT3 ){ |
| 92145 | 92574 | registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); |
| 92146 | 92575 | } |
| 92576 | + if( opProperty==0xff ){ |
| 92577 | + /* Never happens. This code exists to avoid a harmless linkage |
| 92578 | + ** warning aboud sqlite3VdbeRegisterDump() being defined but not |
| 92579 | + ** used. */ |
| 92580 | + sqlite3VdbeRegisterDump(p); |
| 92581 | + } |
| 92147 | 92582 | } |
| 92148 | 92583 | #endif /* SQLITE_DEBUG */ |
| 92149 | 92584 | #endif /* NDEBUG */ |
| 92150 | 92585 | } /* The end of the for(;;) loop the loops through opcodes */ |
| 92151 | 92586 | |
| | @@ -96270,17 +96705,20 @@ |
| 96270 | 96705 | ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN". |
| 96271 | 96706 | ** Check to see if the zSpan given to this routine matches the zDb, zTab, |
| 96272 | 96707 | ** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will |
| 96273 | 96708 | ** match anything. |
| 96274 | 96709 | */ |
| 96275 | | -SQLITE_PRIVATE int sqlite3MatchSpanName( |
| 96276 | | - const char *zSpan, |
| 96710 | +SQLITE_PRIVATE int sqlite3MatchEName( |
| 96711 | + const struct ExprList_item *pItem, |
| 96277 | 96712 | const char *zCol, |
| 96278 | 96713 | const char *zTab, |
| 96279 | 96714 | const char *zDb |
| 96280 | 96715 | ){ |
| 96281 | 96716 | int n; |
| 96717 | + const char *zSpan; |
| 96718 | + if( NEVER(pItem->eEName!=ENAME_TAB) ) return 0; |
| 96719 | + zSpan = pItem->zEName; |
| 96282 | 96720 | for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){} |
| 96283 | 96721 | if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){ |
| 96284 | 96722 | return 0; |
| 96285 | 96723 | } |
| 96286 | 96724 | zSpan += n+1; |
| | @@ -96405,11 +96843,11 @@ |
| 96405 | 96843 | assert( pTab->nCol>0 ); |
| 96406 | 96844 | if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){ |
| 96407 | 96845 | int hit = 0; |
| 96408 | 96846 | pEList = pItem->pSelect->pEList; |
| 96409 | 96847 | for(j=0; j<pEList->nExpr; j++){ |
| 96410 | | - if( sqlite3MatchSpanName(pEList->a[j].zSpan, zCol, zTab, zDb) ){ |
| 96848 | + if( sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){ |
| 96411 | 96849 | cnt++; |
| 96412 | 96850 | cntTab = 2; |
| 96413 | 96851 | pMatch = pItem; |
| 96414 | 96852 | pExpr->iColumn = j; |
| 96415 | 96853 | hit = 1; |
| | @@ -96586,22 +97024,26 @@ |
| 96586 | 97024 | && zTab==0 |
| 96587 | 97025 | ){ |
| 96588 | 97026 | pEList = pNC->uNC.pEList; |
| 96589 | 97027 | assert( pEList!=0 ); |
| 96590 | 97028 | for(j=0; j<pEList->nExpr; j++){ |
| 96591 | | - char *zAs = pEList->a[j].zName; |
| 96592 | | - if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ |
| 97029 | + char *zAs = pEList->a[j].zEName; |
| 97030 | + if( pEList->a[j].eEName==ENAME_NAME |
| 97031 | + && sqlite3_stricmp(zAs, zCol)==0 |
| 97032 | + ){ |
| 96593 | 97033 | Expr *pOrig; |
| 96594 | 97034 | assert( pExpr->pLeft==0 && pExpr->pRight==0 ); |
| 96595 | 97035 | assert( pExpr->x.pList==0 ); |
| 96596 | 97036 | assert( pExpr->x.pSelect==0 ); |
| 96597 | 97037 | pOrig = pEList->a[j].pExpr; |
| 96598 | 97038 | if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){ |
| 96599 | 97039 | sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); |
| 96600 | 97040 | return WRC_Abort; |
| 96601 | 97041 | } |
| 96602 | | - if( (pNC->ncFlags&NC_AllowWin)==0 && ExprHasProperty(pOrig, EP_Win) ){ |
| 97042 | + if( ExprHasProperty(pOrig, EP_Win) |
| 97043 | + && ((pNC->ncFlags&NC_AllowWin)==0 || pNC!=pTopNC ) |
| 97044 | + ){ |
| 96603 | 97045 | sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs); |
| 96604 | 97046 | return WRC_Abort; |
| 96605 | 97047 | } |
| 96606 | 97048 | if( sqlite3ExprVectorSize(pOrig)!=1 ){ |
| 96607 | 97049 | sqlite3ErrorMsg(pParse, "row value misused"); |
| | @@ -97007,28 +97449,27 @@ |
| 97007 | 97449 | sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions", |
| 97008 | 97450 | NC_SelfRef, 0); |
| 97009 | 97451 | }else{ |
| 97010 | 97452 | assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */ |
| 97011 | 97453 | pExpr->op2 = pNC->ncFlags & NC_SelfRef; |
| 97454 | + if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL); |
| 97012 | 97455 | } |
| 97013 | 97456 | if( (pDef->funcFlags & SQLITE_FUNC_INTERNAL)!=0 |
| 97014 | 97457 | && pParse->nested==0 |
| 97015 | | - && sqlite3Config.bInternalFunctions==0 |
| 97458 | + && (pParse->db->mDbFlags & DBFLAG_InternalFunc)==0 |
| 97016 | 97459 | ){ |
| 97017 | 97460 | /* Internal-use-only functions are disallowed unless the |
| 97018 | | - ** SQL is being compiled using sqlite3NestedParse() */ |
| 97461 | + ** SQL is being compiled using sqlite3NestedParse() or |
| 97462 | + ** the SQLITE_TESTCTRL_INTERNAL_FUNCTIONS test-control has be |
| 97463 | + ** used to activate internal functionsn for testing purposes */ |
| 97019 | 97464 | no_such_func = 1; |
| 97020 | 97465 | pDef = 0; |
| 97021 | 97466 | }else |
| 97022 | | - if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0 |
| 97023 | | - && ExprHasProperty(pExpr, EP_Indirect) |
| 97467 | + if( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 |
| 97024 | 97468 | && !IN_RENAME_OBJECT |
| 97025 | 97469 | ){ |
| 97026 | | - /* Functions tagged with SQLITE_DIRECTONLY may not be used |
| 97027 | | - ** inside of triggers and views */ |
| 97028 | | - sqlite3ErrorMsg(pParse, "%s() prohibited in triggers and views", |
| 97029 | | - pDef->zName); |
| 97470 | + sqlite3ExprFunctionUsable(pParse, pExpr, pDef); |
| 97030 | 97471 | } |
| 97031 | 97472 | } |
| 97032 | 97473 | |
| 97033 | 97474 | if( 0==IN_RENAME_OBJECT ){ |
| 97034 | 97475 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| | @@ -97253,12 +97694,13 @@ |
| 97253 | 97694 | UNUSED_PARAMETER(pParse); |
| 97254 | 97695 | |
| 97255 | 97696 | if( pE->op==TK_ID ){ |
| 97256 | 97697 | char *zCol = pE->u.zToken; |
| 97257 | 97698 | for(i=0; i<pEList->nExpr; i++){ |
| 97258 | | - char *zAs = pEList->a[i].zName; |
| 97259 | | - if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){ |
| 97699 | + if( pEList->a[i].eEName==ENAME_NAME |
| 97700 | + && sqlite3_stricmp(pEList->a[i].zEName, zCol)==0 |
| 97701 | + ){ |
| 97260 | 97702 | return i+1; |
| 97261 | 97703 | } |
| 97262 | 97704 | } |
| 97263 | 97705 | } |
| 97264 | 97706 | return 0; |
| | @@ -98015,10 +98457,15 @@ |
| 98015 | 98457 | if( pTab ){ |
| 98016 | 98458 | sSrc.nSrc = 1; |
| 98017 | 98459 | sSrc.a[0].zName = pTab->zName; |
| 98018 | 98460 | sSrc.a[0].pTab = pTab; |
| 98019 | 98461 | sSrc.a[0].iCursor = -1; |
| 98462 | + if( pTab->pSchema!=pParse->db->aDb[1].pSchema ){ |
| 98463 | + /* Cause EP_FromDDL to be set on TK_FUNCTION nodes of non-TEMP |
| 98464 | + ** schema elements */ |
| 98465 | + type |= NC_FromDDL; |
| 98466 | + } |
| 98020 | 98467 | } |
| 98021 | 98468 | sNC.pParse = pParse; |
| 98022 | 98469 | sNC.pSrcList = &sSrc; |
| 98023 | 98470 | sNC.ncFlags = type | NC_IsDDL; |
| 98024 | 98471 | if( (rc = sqlite3ResolveExprNames(&sNC, pExpr))!=SQLITE_OK ) return rc; |
| | @@ -98961,13 +99408,15 @@ |
| 98961 | 99408 | sqlite3 *db = pParse->db; |
| 98962 | 99409 | if( pLeft==0 ){ |
| 98963 | 99410 | return pRight; |
| 98964 | 99411 | }else if( pRight==0 ){ |
| 98965 | 99412 | return pLeft; |
| 98966 | | - }else if( ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight) ){ |
| 98967 | | - sqlite3ExprUnmapAndDelete(pParse, pLeft); |
| 98968 | | - sqlite3ExprUnmapAndDelete(pParse, pRight); |
| 99413 | + }else if( (ExprAlwaysFalse(pLeft) || ExprAlwaysFalse(pRight)) |
| 99414 | + && !IN_RENAME_OBJECT |
| 99415 | + ){ |
| 99416 | + sqlite3ExprDelete(db, pLeft); |
| 99417 | + sqlite3ExprDelete(db, pRight); |
| 98969 | 99418 | return sqlite3Expr(db, TK_INTEGER, "0"); |
| 98970 | 99419 | }else{ |
| 98971 | 99420 | return sqlite3PExpr(pParse, TK_AND, pLeft, pRight); |
| 98972 | 99421 | } |
| 98973 | 99422 | } |
| | @@ -98998,10 +99447,44 @@ |
| 98998 | 99447 | assert( !ExprHasProperty(pNew, EP_xIsSelect) ); |
| 98999 | 99448 | sqlite3ExprSetHeightAndFlags(pParse, pNew); |
| 99000 | 99449 | if( eDistinct==SF_Distinct ) ExprSetProperty(pNew, EP_Distinct); |
| 99001 | 99450 | return pNew; |
| 99002 | 99451 | } |
| 99452 | + |
| 99453 | +/* |
| 99454 | +** Check to see if a function is usable according to current access |
| 99455 | +** rules: |
| 99456 | +** |
| 99457 | +** SQLITE_FUNC_DIRECT - Only usable from top-level SQL |
| 99458 | +** |
| 99459 | +** SQLITE_FUNC_UNSAFE - Usable if TRUSTED_SCHEMA or from |
| 99460 | +** top-level SQL |
| 99461 | +** |
| 99462 | +** If the function is not usable, create an error. |
| 99463 | +*/ |
| 99464 | +SQLITE_PRIVATE void sqlite3ExprFunctionUsable( |
| 99465 | + Parse *pParse, /* Parsing and code generating context */ |
| 99466 | + Expr *pExpr, /* The function invocation */ |
| 99467 | + FuncDef *pDef /* The function being invoked */ |
| 99468 | +){ |
| 99469 | + assert( !IN_RENAME_OBJECT ); |
| 99470 | + assert( (pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE))!=0 ); |
| 99471 | + if( ExprHasProperty(pExpr, EP_FromDDL) ){ |
| 99472 | + if( (pDef->funcFlags & SQLITE_FUNC_DIRECT)!=0 |
| 99473 | + || (pParse->db->flags & SQLITE_TrustedSchema)==0 |
| 99474 | + ){ |
| 99475 | + /* Functions prohibited in triggers and views if: |
| 99476 | + ** (1) tagged with SQLITE_DIRECTONLY |
| 99477 | + ** (2) not tagged with SQLITE_INNOCUOUS (which means it |
| 99478 | + ** is tagged with SQLITE_FUNC_UNSAFE) and |
| 99479 | + ** SQLITE_DBCONFIG_TRUSTED_SCHEMA is off (meaning |
| 99480 | + ** that the schema is possibly tainted). |
| 99481 | + */ |
| 99482 | + sqlite3ErrorMsg(pParse, "unsafe use of %s()", pDef->zName); |
| 99483 | + } |
| 99484 | + } |
| 99485 | +} |
| 99003 | 99486 | |
| 99004 | 99487 | /* |
| 99005 | 99488 | ** Assign a variable number to an expression that encodes a wildcard |
| 99006 | 99489 | ** in the original SQL statement. |
| 99007 | 99490 | ** |
| | @@ -99466,16 +99949,15 @@ |
| 99466 | 99949 | assert( pNewExpr->iColumn==pItem[-1].pExpr->iColumn+1 ); |
| 99467 | 99950 | assert( pPriorSelectCol==pItem[-1].pExpr->pLeft ); |
| 99468 | 99951 | pNewExpr->pLeft = pPriorSelectCol; |
| 99469 | 99952 | } |
| 99470 | 99953 | } |
| 99471 | | - pItem->zName = sqlite3DbStrDup(db, pOldItem->zName); |
| 99472 | | - pItem->zSpan = sqlite3DbStrDup(db, pOldItem->zSpan); |
| 99954 | + pItem->zEName = sqlite3DbStrDup(db, pOldItem->zEName); |
| 99473 | 99955 | pItem->sortFlags = pOldItem->sortFlags; |
| 99956 | + pItem->eEName = pOldItem->eEName; |
| 99474 | 99957 | pItem->done = 0; |
| 99475 | 99958 | pItem->bNulls = pOldItem->bNulls; |
| 99476 | | - pItem->bSpanIsTab = pOldItem->bSpanIsTab; |
| 99477 | 99959 | pItem->bSorterRef = pOldItem->bSorterRef; |
| 99478 | 99960 | pItem->u = pOldItem->u; |
| 99479 | 99961 | } |
| 99480 | 99962 | return pNew; |
| 99481 | 99963 | } |
| | @@ -99638,13 +100120,13 @@ |
| 99638 | 100120 | goto no_mem; |
| 99639 | 100121 | } |
| 99640 | 100122 | pList = pNew; |
| 99641 | 100123 | } |
| 99642 | 100124 | pItem = &pList->a[pList->nExpr++]; |
| 99643 | | - assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) ); |
| 100125 | + assert( offsetof(struct ExprList_item,zEName)==sizeof(pItem->pExpr) ); |
| 99644 | 100126 | assert( offsetof(struct ExprList_item,pExpr)==0 ); |
| 99645 | | - memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName)); |
| 100127 | + memset(&pItem->zEName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zEName)); |
| 99646 | 100128 | pItem->pExpr = pExpr; |
| 99647 | 100129 | return pList; |
| 99648 | 100130 | |
| 99649 | 100131 | no_mem: |
| 99650 | 100132 | /* Avoid leaking memory if malloc has failed. */ |
| | @@ -99697,11 +100179,11 @@ |
| 99697 | 100179 | if( pSubExpr==0 ) continue; |
| 99698 | 100180 | pSubExpr->iTable = pColumns->nId; |
| 99699 | 100181 | pList = sqlite3ExprListAppend(pParse, pList, pSubExpr); |
| 99700 | 100182 | if( pList ){ |
| 99701 | 100183 | assert( pList->nExpr==iFirst+i+1 ); |
| 99702 | | - pList->a[pList->nExpr-1].zName = pColumns->a[i].zName; |
| 100184 | + pList->a[pList->nExpr-1].zEName = pColumns->a[i].zName; |
| 99703 | 100185 | pColumns->a[i].zName = 0; |
| 99704 | 100186 | } |
| 99705 | 100187 | } |
| 99706 | 100188 | |
| 99707 | 100189 | if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){ |
| | @@ -99757,11 +100239,11 @@ |
| 99757 | 100239 | } |
| 99758 | 100240 | } |
| 99759 | 100241 | } |
| 99760 | 100242 | |
| 99761 | 100243 | /* |
| 99762 | | -** Set the ExprList.a[].zName element of the most recently added item |
| 100244 | +** Set the ExprList.a[].zEName element of the most recently added item |
| 99763 | 100245 | ** on the expression list. |
| 99764 | 100246 | ** |
| 99765 | 100247 | ** pList might be NULL following an OOM error. But pName should never be |
| 99766 | 100248 | ** NULL. If a memory allocation fails, the pParse->db->mallocFailed flag |
| 99767 | 100249 | ** is set. |
| | @@ -99775,15 +100257,16 @@ |
| 99775 | 100257 | assert( pList!=0 || pParse->db->mallocFailed!=0 ); |
| 99776 | 100258 | if( pList ){ |
| 99777 | 100259 | struct ExprList_item *pItem; |
| 99778 | 100260 | assert( pList->nExpr>0 ); |
| 99779 | 100261 | pItem = &pList->a[pList->nExpr-1]; |
| 99780 | | - assert( pItem->zName==0 ); |
| 99781 | | - pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); |
| 99782 | | - if( dequote ) sqlite3Dequote(pItem->zName); |
| 100262 | + assert( pItem->zEName==0 ); |
| 100263 | + assert( pItem->eEName==ENAME_NAME ); |
| 100264 | + pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); |
| 100265 | + if( dequote ) sqlite3Dequote(pItem->zEName); |
| 99783 | 100266 | if( IN_RENAME_OBJECT ){ |
| 99784 | | - sqlite3RenameTokenMap(pParse, (void*)pItem->zName, pName); |
| 100267 | + sqlite3RenameTokenMap(pParse, (void*)pItem->zEName, pName); |
| 99785 | 100268 | } |
| 99786 | 100269 | } |
| 99787 | 100270 | } |
| 99788 | 100271 | |
| 99789 | 100272 | /* |
| | @@ -99803,12 +100286,14 @@ |
| 99803 | 100286 | sqlite3 *db = pParse->db; |
| 99804 | 100287 | assert( pList!=0 || db->mallocFailed!=0 ); |
| 99805 | 100288 | if( pList ){ |
| 99806 | 100289 | struct ExprList_item *pItem = &pList->a[pList->nExpr-1]; |
| 99807 | 100290 | assert( pList->nExpr>0 ); |
| 99808 | | - sqlite3DbFree(db, pItem->zSpan); |
| 99809 | | - pItem->zSpan = sqlite3DbSpanDup(db, zStart, zEnd); |
| 100291 | + if( pItem->zEName==0 ){ |
| 100292 | + pItem->zEName = sqlite3DbSpanDup(db, zStart, zEnd); |
| 100293 | + pItem->eEName = ENAME_SPAN; |
| 100294 | + } |
| 99810 | 100295 | } |
| 99811 | 100296 | } |
| 99812 | 100297 | |
| 99813 | 100298 | /* |
| 99814 | 100299 | ** If the expression list pEList contains more than iLimit elements, |
| | @@ -99834,12 +100319,11 @@ |
| 99834 | 100319 | int i = pList->nExpr; |
| 99835 | 100320 | struct ExprList_item *pItem = pList->a; |
| 99836 | 100321 | assert( pList->nExpr>0 ); |
| 99837 | 100322 | do{ |
| 99838 | 100323 | sqlite3ExprDelete(db, pItem->pExpr); |
| 99839 | | - sqlite3DbFree(db, pItem->zName); |
| 99840 | | - sqlite3DbFree(db, pItem->zSpan); |
| 100324 | + sqlite3DbFree(db, pItem->zEName); |
| 99841 | 100325 | pItem++; |
| 99842 | 100326 | }while( --i>0 ); |
| 99843 | 100327 | sqlite3DbFreeNN(db, pList); |
| 99844 | 100328 | } |
| 99845 | 100329 | SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){ |
| | @@ -99872,24 +100356,39 @@ |
| 99872 | 100356 | SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){ |
| 99873 | 100357 | UNUSED_PARAMETER(NotUsed); |
| 99874 | 100358 | pWalker->eCode = 0; |
| 99875 | 100359 | return WRC_Abort; |
| 99876 | 100360 | } |
| 100361 | + |
| 100362 | +/* |
| 100363 | +** Check the input string to see if it is "true" or "false" (in any case). |
| 100364 | +** |
| 100365 | +** If the string is.... Return |
| 100366 | +** "true" EP_IsTrue |
| 100367 | +** "false" EP_IsFalse |
| 100368 | +** anything else 0 |
| 100369 | +*/ |
| 100370 | +SQLITE_PRIVATE u32 sqlite3IsTrueOrFalse(const char *zIn){ |
| 100371 | + if( sqlite3StrICmp(zIn, "true")==0 ) return EP_IsTrue; |
| 100372 | + if( sqlite3StrICmp(zIn, "false")==0 ) return EP_IsFalse; |
| 100373 | + return 0; |
| 100374 | +} |
| 100375 | + |
| 99877 | 100376 | |
| 99878 | 100377 | /* |
| 99879 | 100378 | ** If the input expression is an ID with the name "true" or "false" |
| 99880 | 100379 | ** then convert it into an TK_TRUEFALSE term. Return non-zero if |
| 99881 | 100380 | ** the conversion happened, and zero if the expression is unaltered. |
| 99882 | 100381 | */ |
| 99883 | 100382 | SQLITE_PRIVATE int sqlite3ExprIdToTrueFalse(Expr *pExpr){ |
| 100383 | + u32 v; |
| 99884 | 100384 | assert( pExpr->op==TK_ID || pExpr->op==TK_STRING ); |
| 99885 | 100385 | if( !ExprHasProperty(pExpr, EP_Quoted) |
| 99886 | | - && (sqlite3StrICmp(pExpr->u.zToken, "true")==0 |
| 99887 | | - || sqlite3StrICmp(pExpr->u.zToken, "false")==0) |
| 100386 | + && (v = sqlite3IsTrueOrFalse(pExpr->u.zToken))!=0 |
| 99888 | 100387 | ){ |
| 99889 | 100388 | pExpr->op = TK_TRUEFALSE; |
| 99890 | | - ExprSetProperty(pExpr, pExpr->u.zToken[4]==0 ? EP_IsTrue : EP_IsFalse); |
| 100389 | + ExprSetProperty(pExpr, v); |
| 99891 | 100390 | return 1; |
| 99892 | 100391 | } |
| 99893 | 100392 | return 0; |
| 99894 | 100393 | } |
| 99895 | 100394 | |
| | @@ -99947,14 +100446,15 @@ |
| 99947 | 100446 | ** sqlite3ExprIsConstantOrFunction() pWalker->eCode==4 or 5 |
| 99948 | 100447 | ** |
| 99949 | 100448 | ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression |
| 99950 | 100449 | ** is found to not be a constant. |
| 99951 | 100450 | ** |
| 99952 | | -** The sqlite3ExprIsConstantOrFunction() is used for evaluating expressions |
| 99953 | | -** in a CREATE TABLE statement. The Walker.eCode value is 5 when parsing |
| 99954 | | -** an existing schema and 4 when processing a new statement. A bound |
| 99955 | | -** parameter raises an error for new statements, but is silently converted |
| 100451 | +** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT |
| 100452 | +** expressions in a CREATE TABLE statement. The Walker.eCode value is 5 |
| 100453 | +** when parsing an existing schema out of the sqlite_master table and 4 |
| 100454 | +** when processing a new CREATE TABLE statement. A bound parameter raises |
| 100455 | +** an error for new statements, but is silently converted |
| 99956 | 100456 | ** to NULL for existing schemas. This allows sqlite_master tables that |
| 99957 | 100457 | ** contain a bound parameter because they were generated by older versions |
| 99958 | 100458 | ** of SQLite to be parsed by newer versions of SQLite without raising a |
| 99959 | 100459 | ** malformed schema error. |
| 99960 | 100460 | */ |
| | @@ -99974,10 +100474,11 @@ |
| 99974 | 100474 | ** SQLITE_FUNC_CONST flag. */ |
| 99975 | 100475 | case TK_FUNCTION: |
| 99976 | 100476 | if( (pWalker->eCode>=4 || ExprHasProperty(pExpr,EP_ConstFunc)) |
| 99977 | 100477 | && !ExprHasProperty(pExpr, EP_WinFunc) |
| 99978 | 100478 | ){ |
| 100479 | + if( pWalker->eCode==5 ) ExprSetProperty(pExpr, EP_FromDDL); |
| 99979 | 100480 | return WRC_Continue; |
| 99980 | 100481 | }else{ |
| 99981 | 100482 | pWalker->eCode = 0; |
| 99982 | 100483 | return WRC_Abort; |
| 99983 | 100484 | } |
| | @@ -100137,13 +100638,25 @@ |
| 100137 | 100638 | sqlite3WalkExpr(&w, p); |
| 100138 | 100639 | return w.eCode; |
| 100139 | 100640 | } |
| 100140 | 100641 | |
| 100141 | 100642 | /* |
| 100142 | | -** Walk an expression tree. Return non-zero if the expression is constant |
| 100143 | | -** or a function call with constant arguments. Return and 0 if there |
| 100144 | | -** are any variables. |
| 100643 | +** Walk an expression tree for the DEFAULT field of a column definition |
| 100644 | +** in a CREATE TABLE statement. Return non-zero if the expression is |
| 100645 | +** acceptable for use as a DEFAULT. That is to say, return non-zero if |
| 100646 | +** the expression is constant or a function call with constant arguments. |
| 100647 | +** Return and 0 if there are any variables. |
| 100648 | +** |
| 100649 | +** isInit is true when parsing from sqlite_master. isInit is false when |
| 100650 | +** processing a new CREATE TABLE statement. When isInit is true, parameters |
| 100651 | +** (such as ? or $abc) in the expression are converted into NULL. When |
| 100652 | +** isInit is false, parameters raise an error. Parameters should not be |
| 100653 | +** allowed in a CREATE TABLE statement, but some legacy versions of SQLite |
| 100654 | +** allowed it, so we need to support it when reading sqlite_master for |
| 100655 | +** backwards compatibility. |
| 100656 | +** |
| 100657 | +** If isInit is true, set EP_FromDDL on every TK_FUNCTION node. |
| 100145 | 100658 | ** |
| 100146 | 100659 | ** For the purposes of this function, a double-quoted string (ex: "abc") |
| 100147 | 100660 | ** is considered a variable but a single-quoted string (ex: 'abc') is |
| 100148 | 100661 | ** a constant. |
| 100149 | 100662 | */ |
| | @@ -101219,10 +101732,11 @@ |
| 101219 | 101732 | r2 = sqlite3ExprCodeTemp(pParse, pList->a[ii].pExpr, ®ToFree); |
| 101220 | 101733 | } |
| 101221 | 101734 | if( regCkNull && sqlite3ExprCanBeNull(pList->a[ii].pExpr) ){ |
| 101222 | 101735 | sqlite3VdbeAddOp3(v, OP_BitAnd, regCkNull, r2, regCkNull); |
| 101223 | 101736 | } |
| 101737 | + sqlite3ReleaseTempReg(pParse, regToFree); |
| 101224 | 101738 | if( ii<pList->nExpr-1 || destIfNull!=destIfFalse ){ |
| 101225 | 101739 | int op = rLhs!=r2 ? OP_Eq : OP_NotNull; |
| 101226 | 101740 | sqlite3VdbeAddOp4(v, op, rLhs, labelOk, r2, |
| 101227 | 101741 | (void*)pColl, P4_COLLSEQ); |
| 101228 | 101742 | VdbeCoverageIf(v, ii<pList->nExpr-1 && op==OP_Eq); |
| | @@ -101237,11 +101751,10 @@ |
| 101237 | 101751 | (void*)pColl, P4_COLLSEQ); |
| 101238 | 101752 | VdbeCoverageIf(v, op==OP_Ne); |
| 101239 | 101753 | VdbeCoverageIf(v, op==OP_IsNull); |
| 101240 | 101754 | sqlite3VdbeChangeP5(v, zAff[0] | SQLITE_JUMPIFNULL); |
| 101241 | 101755 | } |
| 101242 | | - sqlite3ReleaseTempReg(pParse, regToFree); |
| 101243 | 101756 | } |
| 101244 | 101757 | if( regCkNull ){ |
| 101245 | 101758 | sqlite3VdbeAddOp2(v, OP_IsNull, regCkNull, destIfNull); VdbeCoverage(v); |
| 101246 | 101759 | sqlite3VdbeGoto(v, destIfFalse); |
| 101247 | 101760 | } |
| | @@ -101598,10 +102111,113 @@ |
| 101598 | 102111 | } |
| 101599 | 102112 | } |
| 101600 | 102113 | } |
| 101601 | 102114 | return iResult; |
| 101602 | 102115 | } |
| 102116 | + |
| 102117 | +/* |
| 102118 | +** Generate code to implement special SQL functions that are implemented |
| 102119 | +** in-line rather than by using the usual callbacks. |
| 102120 | +*/ |
| 102121 | +static int exprCodeInlineFunction( |
| 102122 | + Parse *pParse, /* Parsing context */ |
| 102123 | + ExprList *pFarg, /* List of function arguments */ |
| 102124 | + int iFuncId, /* Function ID. One of the INTFUNC_... values */ |
| 102125 | + int target /* Store function result in this register */ |
| 102126 | +){ |
| 102127 | + int nFarg; |
| 102128 | + Vdbe *v = pParse->pVdbe; |
| 102129 | + assert( v!=0 ); |
| 102130 | + assert( pFarg!=0 ); |
| 102131 | + nFarg = pFarg->nExpr; |
| 102132 | + assert( nFarg>0 ); /* All in-line functions have at least one argument */ |
| 102133 | + switch( iFuncId ){ |
| 102134 | + case INLINEFUNC_coalesce: { |
| 102135 | + /* Attempt a direct implementation of the built-in COALESCE() and |
| 102136 | + ** IFNULL() functions. This avoids unnecessary evaluation of |
| 102137 | + ** arguments past the first non-NULL argument. |
| 102138 | + */ |
| 102139 | + int endCoalesce = sqlite3VdbeMakeLabel(pParse); |
| 102140 | + int i; |
| 102141 | + assert( nFarg>=2 ); |
| 102142 | + sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target); |
| 102143 | + for(i=1; i<nFarg; i++){ |
| 102144 | + sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce); |
| 102145 | + VdbeCoverage(v); |
| 102146 | + sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target); |
| 102147 | + } |
| 102148 | + if( sqlite3VdbeGetOp(v, -1)->opcode==OP_Copy ){ |
| 102149 | + sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */ |
| 102150 | + } |
| 102151 | + sqlite3VdbeResolveLabel(v, endCoalesce); |
| 102152 | + break; |
| 102153 | + } |
| 102154 | + |
| 102155 | + default: { |
| 102156 | + /* The UNLIKELY() function is a no-op. The result is the value |
| 102157 | + ** of the first argument. |
| 102158 | + */ |
| 102159 | + assert( nFarg==1 || nFarg==2 ); |
| 102160 | + target = sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target); |
| 102161 | + break; |
| 102162 | + } |
| 102163 | + |
| 102164 | + /*********************************************************************** |
| 102165 | + ** Test-only SQL functions that are only usable if enabled |
| 102166 | + ** via SQLITE_TESTCTRL_INTERNAL_FUNCTIONS |
| 102167 | + */ |
| 102168 | + case INLINEFUNC_expr_compare: { |
| 102169 | + /* Compare two expressions using sqlite3ExprCompare() */ |
| 102170 | + assert( nFarg==2 ); |
| 102171 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 102172 | + sqlite3ExprCompare(0,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1), |
| 102173 | + target); |
| 102174 | + break; |
| 102175 | + } |
| 102176 | + |
| 102177 | + case INLINEFUNC_expr_implies_expr: { |
| 102178 | + /* Compare two expressions using sqlite3ExprImpliesExpr() */ |
| 102179 | + assert( nFarg==2 ); |
| 102180 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 102181 | + sqlite3ExprImpliesExpr(pParse,pFarg->a[0].pExpr, pFarg->a[1].pExpr,-1), |
| 102182 | + target); |
| 102183 | + break; |
| 102184 | + } |
| 102185 | + |
| 102186 | + case INLINEFUNC_implies_nonnull_row: { |
| 102187 | + /* REsult of sqlite3ExprImpliesNonNullRow() */ |
| 102188 | + Expr *pA1; |
| 102189 | + assert( nFarg==2 ); |
| 102190 | + pA1 = pFarg->a[1].pExpr; |
| 102191 | + if( pA1->op==TK_COLUMN ){ |
| 102192 | + sqlite3VdbeAddOp2(v, OP_Integer, |
| 102193 | + sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable), |
| 102194 | + target); |
| 102195 | + }else{ |
| 102196 | + sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| 102197 | + } |
| 102198 | + break; |
| 102199 | + } |
| 102200 | + |
| 102201 | +#ifdef SQLITE_DEBUG |
| 102202 | + case INLINEFUNC_affinity: { |
| 102203 | + /* The AFFINITY() function evaluates to a string that describes |
| 102204 | + ** the type affinity of the argument. This is used for testing of |
| 102205 | + ** the SQLite type logic. |
| 102206 | + */ |
| 102207 | + const char *azAff[] = { "blob", "text", "numeric", "integer", "real" }; |
| 102208 | + char aff; |
| 102209 | + assert( nFarg==1 ); |
| 102210 | + aff = sqlite3ExprAffinity(pFarg->a[0].pExpr); |
| 102211 | + sqlite3VdbeLoadString(v, target, |
| 102212 | + (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]); |
| 102213 | + break; |
| 102214 | + } |
| 102215 | +#endif |
| 102216 | + } |
| 102217 | + return target; |
| 102218 | +} |
| 101603 | 102219 | |
| 101604 | 102220 | |
| 101605 | 102221 | /* |
| 101606 | 102222 | ** Generate code into the current Vdbe to evaluate the given |
| 101607 | 102223 | ** expression. Attempt to store the results in register "target". |
| | @@ -101979,51 +102595,18 @@ |
| 101979 | 102595 | #endif |
| 101980 | 102596 | if( pDef==0 || pDef->xFinalize!=0 ){ |
| 101981 | 102597 | sqlite3ErrorMsg(pParse, "unknown function: %s()", zId); |
| 101982 | 102598 | break; |
| 101983 | 102599 | } |
| 101984 | | - |
| 101985 | | - /* Attempt a direct implementation of the built-in COALESCE() and |
| 101986 | | - ** IFNULL() functions. This avoids unnecessary evaluation of |
| 101987 | | - ** arguments past the first non-NULL argument. |
| 101988 | | - */ |
| 101989 | | - if( pDef->funcFlags & SQLITE_FUNC_COALESCE ){ |
| 101990 | | - int endCoalesce = sqlite3VdbeMakeLabel(pParse); |
| 101991 | | - assert( nFarg>=2 ); |
| 101992 | | - sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target); |
| 101993 | | - for(i=1; i<nFarg; i++){ |
| 101994 | | - sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce); |
| 101995 | | - VdbeCoverage(v); |
| 101996 | | - sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target); |
| 101997 | | - } |
| 101998 | | - sqlite3VdbeResolveLabel(v, endCoalesce); |
| 101999 | | - break; |
| 102000 | | - } |
| 102001 | | - |
| 102002 | | - /* The UNLIKELY() function is a no-op. The result is the value |
| 102003 | | - ** of the first argument. |
| 102004 | | - */ |
| 102005 | | - if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){ |
| 102006 | | - assert( nFarg>=1 ); |
| 102007 | | - return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target); |
| 102008 | | - } |
| 102009 | | - |
| 102010 | | -#ifdef SQLITE_DEBUG |
| 102011 | | - /* The AFFINITY() function evaluates to a string that describes |
| 102012 | | - ** the type affinity of the argument. This is used for testing of |
| 102013 | | - ** the SQLite type logic. |
| 102014 | | - */ |
| 102015 | | - if( pDef->funcFlags & SQLITE_FUNC_AFFINITY ){ |
| 102016 | | - const char *azAff[] = { "blob", "text", "numeric", "integer", "real" }; |
| 102017 | | - char aff; |
| 102018 | | - assert( nFarg==1 ); |
| 102019 | | - aff = sqlite3ExprAffinity(pFarg->a[0].pExpr); |
| 102020 | | - sqlite3VdbeLoadString(v, target, |
| 102021 | | - (aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]); |
| 102022 | | - return target; |
| 102023 | | - } |
| 102024 | | -#endif |
| 102600 | + if( pDef->funcFlags & SQLITE_FUNC_INLINE ){ |
| 102601 | + assert( (pDef->funcFlags & SQLITE_FUNC_UNSAFE)==0 ); |
| 102602 | + assert( (pDef->funcFlags & SQLITE_FUNC_DIRECT)==0 ); |
| 102603 | + return exprCodeInlineFunction(pParse, pFarg, |
| 102604 | + SQLITE_PTR_TO_INT(pDef->pUserData), target); |
| 102605 | + }else if( pDef->funcFlags & (SQLITE_FUNC_DIRECT|SQLITE_FUNC_UNSAFE) ){ |
| 102606 | + sqlite3ExprFunctionUsable(pParse, pExpr, pDef); |
| 102607 | + } |
| 102025 | 102608 | |
| 102026 | 102609 | for(i=0; i<nFarg; i++){ |
| 102027 | 102610 | if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){ |
| 102028 | 102611 | testcase( i==31 ); |
| 102029 | 102612 | constMask |= MASKBIT32(i); |
| | @@ -102103,11 +102686,11 @@ |
| 102103 | 102686 | } |
| 102104 | 102687 | if( nFarg ){ |
| 102105 | 102688 | if( constMask==0 ){ |
| 102106 | 102689 | sqlite3ReleaseTempRange(pParse, r1, nFarg); |
| 102107 | 102690 | }else{ |
| 102108 | | - sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask); |
| 102691 | + sqlite3VdbeReleaseRegisters(pParse, r1, nFarg, constMask, 1); |
| 102109 | 102692 | } |
| 102110 | 102693 | } |
| 102111 | 102694 | return target; |
| 102112 | 102695 | } |
| 102113 | 102696 | #ifndef SQLITE_OMIT_SUBQUERY |
| | @@ -102455,11 +103038,17 @@ |
| 102455 | 103038 | |
| 102456 | 103039 | assert( target>0 && target<=pParse->nMem ); |
| 102457 | 103040 | inReg = sqlite3ExprCodeTarget(pParse, pExpr, target); |
| 102458 | 103041 | assert( pParse->pVdbe!=0 || pParse->db->mallocFailed ); |
| 102459 | 103042 | if( inReg!=target && pParse->pVdbe ){ |
| 102460 | | - sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target); |
| 103043 | + u8 op; |
| 103044 | + if( ExprHasProperty(pExpr,EP_Subquery) ){ |
| 103045 | + op = OP_Copy; |
| 103046 | + }else{ |
| 103047 | + op = OP_SCopy; |
| 103048 | + } |
| 103049 | + sqlite3VdbeAddOp2(pParse->pVdbe, op, inReg, target); |
| 102461 | 103050 | } |
| 102462 | 103051 | } |
| 102463 | 103052 | |
| 102464 | 103053 | /* |
| 102465 | 103054 | ** Make a transient copy of expression pExpr and then code it using |
| | @@ -102548,10 +103137,11 @@ |
| 102548 | 103137 | VdbeOp *pOp; |
| 102549 | 103138 | if( copyOp==OP_Copy |
| 102550 | 103139 | && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy |
| 102551 | 103140 | && pOp->p1+pOp->p3+1==inReg |
| 102552 | 103141 | && pOp->p2+pOp->p3+1==target+i |
| 103142 | + && pOp->p5==0 /* The do-not-merge flag must be clear */ |
| 102553 | 103143 | ){ |
| 102554 | 103144 | pOp->p3++; |
| 102555 | 103145 | }else{ |
| 102556 | 103146 | sqlite3VdbeAddOp2(v, copyOp, inReg, target+i); |
| 102557 | 103147 | } |
| | @@ -103120,12 +103710,13 @@ |
| 103120 | 103710 | } |
| 103121 | 103711 | return 0; |
| 103122 | 103712 | } |
| 103123 | 103713 | |
| 103124 | 103714 | /* |
| 103125 | | -** Compare two ExprList objects. Return 0 if they are identical and |
| 103126 | | -** non-zero if they differ in any way. |
| 103715 | +** Compare two ExprList objects. Return 0 if they are identical, 1 |
| 103716 | +** if they are certainly different, or 2 if it is not possible to |
| 103717 | +** determine if they are identical or not. |
| 103127 | 103718 | ** |
| 103128 | 103719 | ** If any subelement of pB has Expr.iTable==(-1) then it is allowed |
| 103129 | 103720 | ** to compare equal to an equivalent element in pA with Expr.iTable==iTab. |
| 103130 | 103721 | ** |
| 103131 | 103722 | ** This routine might return non-zero for equivalent ExprLists. The |
| | @@ -103140,14 +103731,15 @@ |
| 103140 | 103731 | int i; |
| 103141 | 103732 | if( pA==0 && pB==0 ) return 0; |
| 103142 | 103733 | if( pA==0 || pB==0 ) return 1; |
| 103143 | 103734 | if( pA->nExpr!=pB->nExpr ) return 1; |
| 103144 | 103735 | for(i=0; i<pA->nExpr; i++){ |
| 103736 | + int res; |
| 103145 | 103737 | Expr *pExprA = pA->a[i].pExpr; |
| 103146 | 103738 | Expr *pExprB = pB->a[i].pExpr; |
| 103147 | 103739 | if( pA->a[i].sortFlags!=pB->a[i].sortFlags ) return 1; |
| 103148 | | - if( sqlite3ExprCompare(0, pExprA, pExprB, iTab) ) return 1; |
| 103740 | + if( (res = sqlite3ExprCompare(0, pExprA, pExprB, iTab)) ) return res; |
| 103149 | 103741 | } |
| 103150 | 103742 | return 0; |
| 103151 | 103743 | } |
| 103152 | 103744 | |
| 103153 | 103745 | /* |
| | @@ -103322,15 +103914,16 @@ |
| 103322 | 103914 | return WRC_Abort; |
| 103323 | 103915 | } |
| 103324 | 103916 | return WRC_Prune; |
| 103325 | 103917 | |
| 103326 | 103918 | case TK_AND: |
| 103327 | | - assert( pWalker->eCode==0 ); |
| 103328 | | - sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 103329 | | - if( pWalker->eCode ){ |
| 103330 | | - pWalker->eCode = 0; |
| 103331 | | - sqlite3WalkExpr(pWalker, pExpr->pRight); |
| 103919 | + if( pWalker->eCode==0 ){ |
| 103920 | + sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 103921 | + if( pWalker->eCode ){ |
| 103922 | + pWalker->eCode = 0; |
| 103923 | + sqlite3WalkExpr(pWalker, pExpr->pRight); |
| 103924 | + } |
| 103332 | 103925 | } |
| 103333 | 103926 | return WRC_Prune; |
| 103334 | 103927 | |
| 103335 | 103928 | case TK_BETWEEN: |
| 103336 | 103929 | if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){ |
| | @@ -103477,16 +104070,17 @@ |
| 103477 | 104070 | |
| 103478 | 104071 | /* |
| 103479 | 104072 | ** Count the number of references to columns. |
| 103480 | 104073 | */ |
| 103481 | 104074 | static int exprSrcCount(Walker *pWalker, Expr *pExpr){ |
| 103482 | | - /* The NEVER() on the second term is because sqlite3FunctionUsesThisSrc() |
| 103483 | | - ** is always called before sqlite3ExprAnalyzeAggregates() and so the |
| 103484 | | - ** TK_COLUMNs have not yet been converted into TK_AGG_COLUMN. If |
| 103485 | | - ** sqlite3FunctionUsesThisSrc() is used differently in the future, the |
| 103486 | | - ** NEVER() will need to be removed. */ |
| 103487 | | - if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){ |
| 104075 | + /* There was once a NEVER() on the second term on the grounds that |
| 104076 | + ** sqlite3FunctionUsesThisSrc() was always called before |
| 104077 | + ** sqlite3ExprAnalyzeAggregates() and so the TK_COLUMNs have not yet |
| 104078 | + ** been converted into TK_AGG_COLUMN. But this is no longer true due |
| 104079 | + ** to window functions - sqlite3WindowRewrite() may now indirectly call |
| 104080 | + ** FunctionUsesThisSrc() when creating a new sub-select. */ |
| 104081 | + if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){ |
| 103488 | 104082 | int i; |
| 103489 | 104083 | struct SrcCount *p = pWalker->u.pSrcCount; |
| 103490 | 104084 | SrcList *pSrc = p->pSrc; |
| 103491 | 104085 | int nSrc = pSrc ? pSrc->nSrc : 0; |
| 103492 | 104086 | for(i=0; i<nSrc; i++){ |
| | @@ -103520,10 +104114,15 @@ |
| 103520 | 104114 | w.u.pSrcCount = &cnt; |
| 103521 | 104115 | cnt.pSrc = pSrcList; |
| 103522 | 104116 | cnt.nThis = 0; |
| 103523 | 104117 | cnt.nOther = 0; |
| 103524 | 104118 | sqlite3WalkExprList(&w, pExpr->x.pList); |
| 104119 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 104120 | + if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 104121 | + sqlite3WalkExpr(&w, pExpr->y.pWin->pFilter); |
| 104122 | + } |
| 104123 | +#endif |
| 103525 | 104124 | return cnt.nThis>0 || cnt.nOther==0; |
| 103526 | 104125 | } |
| 103527 | 104126 | |
| 103528 | 104127 | /* |
| 103529 | 104128 | ** Add a new element to the pAggInfo->aCol[] array. Return the index of |
| | @@ -103749,11 +104348,11 @@ |
| 103749 | 104348 | ** Deallocate a register, making available for reuse for some other |
| 103750 | 104349 | ** purpose. |
| 103751 | 104350 | */ |
| 103752 | 104351 | SQLITE_PRIVATE void sqlite3ReleaseTempReg(Parse *pParse, int iReg){ |
| 103753 | 104352 | if( iReg ){ |
| 103754 | | - sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0); |
| 104353 | + sqlite3VdbeReleaseRegisters(pParse, iReg, 1, 0, 0); |
| 103755 | 104354 | if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){ |
| 103756 | 104355 | pParse->aTempReg[pParse->nTempReg++] = iReg; |
| 103757 | 104356 | } |
| 103758 | 104357 | } |
| 103759 | 104358 | } |
| | @@ -103778,11 +104377,11 @@ |
| 103778 | 104377 | SQLITE_PRIVATE void sqlite3ReleaseTempRange(Parse *pParse, int iReg, int nReg){ |
| 103779 | 104378 | if( nReg==1 ){ |
| 103780 | 104379 | sqlite3ReleaseTempReg(pParse, iReg); |
| 103781 | 104380 | return; |
| 103782 | 104381 | } |
| 103783 | | - sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0); |
| 104382 | + sqlite3VdbeReleaseRegisters(pParse, iReg, nReg, 0, 0); |
| 103784 | 104383 | if( nReg>pParse->nRangeReg ){ |
| 103785 | 104384 | pParse->nRangeReg = nReg; |
| 103786 | 104385 | pParse->iRangeReg = iReg; |
| 103787 | 104386 | } |
| 103788 | 104387 | } |
| | @@ -104591,12 +105190,12 @@ |
| 104591 | 105190 | if( pParse->nErr ) return WRC_Abort; |
| 104592 | 105191 | if( NEVER(p->selFlags & SF_View) ) return WRC_Prune; |
| 104593 | 105192 | if( ALWAYS(p->pEList) ){ |
| 104594 | 105193 | ExprList *pList = p->pEList; |
| 104595 | 105194 | for(i=0; i<pList->nExpr; i++){ |
| 104596 | | - if( pList->a[i].zName ){ |
| 104597 | | - sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zName); |
| 105195 | + if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){ |
| 105196 | + sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName); |
| 104598 | 105197 | } |
| 104599 | 105198 | } |
| 104600 | 105199 | } |
| 104601 | 105200 | if( ALWAYS(p->pSrc) ){ /* Every Select as a SrcList, even if it is empty */ |
| 104602 | 105201 | SrcList *pSrc = p->pSrc; |
| | @@ -104636,11 +105235,13 @@ |
| 104636 | 105235 | memset(&sWalker, 0, sizeof(Walker)); |
| 104637 | 105236 | sWalker.pParse = pParse; |
| 104638 | 105237 | sWalker.xExprCallback = renameUnmapExprCb; |
| 104639 | 105238 | sqlite3WalkExprList(&sWalker, pEList); |
| 104640 | 105239 | for(i=0; i<pEList->nExpr; i++){ |
| 104641 | | - sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zName); |
| 105240 | + if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) ){ |
| 105241 | + sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName); |
| 105242 | + } |
| 104642 | 105243 | } |
| 104643 | 105244 | } |
| 104644 | 105245 | } |
| 104645 | 105246 | |
| 104646 | 105247 | /* |
| | @@ -104774,12 +105375,15 @@ |
| 104774 | 105375 | const char *zOld |
| 104775 | 105376 | ){ |
| 104776 | 105377 | if( pEList ){ |
| 104777 | 105378 | int i; |
| 104778 | 105379 | for(i=0; i<pEList->nExpr; i++){ |
| 104779 | | - char *zName = pEList->a[i].zName; |
| 104780 | | - if( 0==sqlite3_stricmp(zName, zOld) ){ |
| 105380 | + char *zName = pEList->a[i].zEName; |
| 105381 | + if( ALWAYS(pEList->a[i].eEName==ENAME_NAME) |
| 105382 | + && ALWAYS(zName!=0) |
| 105383 | + && 0==sqlite3_stricmp(zName, zOld) |
| 105384 | + ){ |
| 104781 | 105385 | renameTokenFind(pParse, pCtx, (void*)zName); |
| 104782 | 105386 | } |
| 104783 | 105387 | } |
| 104784 | 105388 | } |
| 104785 | 105389 | } |
| | @@ -107879,11 +108483,11 @@ |
| 107879 | 108483 | pFix->pParse = pParse; |
| 107880 | 108484 | pFix->zDb = db->aDb[iDb].zDbSName; |
| 107881 | 108485 | pFix->pSchema = db->aDb[iDb].pSchema; |
| 107882 | 108486 | pFix->zType = zType; |
| 107883 | 108487 | pFix->pName = pName; |
| 107884 | | - pFix->bVarOnly = (iDb==1); |
| 108488 | + pFix->bTemp = (iDb==1); |
| 107885 | 108489 | } |
| 107886 | 108490 | |
| 107887 | 108491 | /* |
| 107888 | 108492 | ** The following set of routines walk through the parse tree and assign |
| 107889 | 108493 | ** a specific database to all table references where the database name |
| | @@ -107907,20 +108511,21 @@ |
| 107907 | 108511 | struct SrcList_item *pItem; |
| 107908 | 108512 | |
| 107909 | 108513 | if( NEVER(pList==0) ) return 0; |
| 107910 | 108514 | zDb = pFix->zDb; |
| 107911 | 108515 | for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){ |
| 107912 | | - if( pFix->bVarOnly==0 ){ |
| 108516 | + if( pFix->bTemp==0 ){ |
| 107913 | 108517 | if( pItem->zDatabase && sqlite3StrICmp(pItem->zDatabase, zDb) ){ |
| 107914 | 108518 | sqlite3ErrorMsg(pFix->pParse, |
| 107915 | 108519 | "%s %T cannot reference objects in database %s", |
| 107916 | 108520 | pFix->zType, pFix->pName, pItem->zDatabase); |
| 107917 | 108521 | return 1; |
| 107918 | 108522 | } |
| 107919 | 108523 | sqlite3DbFree(pFix->pParse->db, pItem->zDatabase); |
| 107920 | 108524 | pItem->zDatabase = 0; |
| 107921 | 108525 | pItem->pSchema = pFix->pSchema; |
| 108526 | + pItem->fg.fromDDL = 1; |
| 107922 | 108527 | } |
| 107923 | 108528 | #if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER) |
| 107924 | 108529 | if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1; |
| 107925 | 108530 | if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1; |
| 107926 | 108531 | #endif |
| | @@ -107972,11 +108577,11 @@ |
| 107972 | 108577 | SQLITE_PRIVATE int sqlite3FixExpr( |
| 107973 | 108578 | DbFixer *pFix, /* Context of the fixation */ |
| 107974 | 108579 | Expr *pExpr /* The expression to be fixed to one database */ |
| 107975 | 108580 | ){ |
| 107976 | 108581 | while( pExpr ){ |
| 107977 | | - ExprSetProperty(pExpr, EP_Indirect); |
| 108582 | + if( !pFix->bTemp ) ExprSetProperty(pExpr, EP_FromDDL); |
| 107978 | 108583 | if( pExpr->op==TK_VARIABLE ){ |
| 107979 | 108584 | if( pFix->pParse->db->init.busy ){ |
| 107980 | 108585 | pExpr->op = TK_NULL; |
| 107981 | 108586 | }else{ |
| 107982 | 108587 | sqlite3ErrorMsg(pFix->pParse, "%s cannot use variables", pFix->zType); |
| | @@ -109727,12 +110332,13 @@ |
| 109727 | 110332 | Table *p; |
| 109728 | 110333 | Column *pCol; |
| 109729 | 110334 | sqlite3 *db = pParse->db; |
| 109730 | 110335 | p = pParse->pNewTable; |
| 109731 | 110336 | if( p!=0 ){ |
| 110337 | + int isInit = db->init.busy && db->init.iDb!=1; |
| 109732 | 110338 | pCol = &(p->aCol[p->nCol-1]); |
| 109733 | | - if( !sqlite3ExprIsConstantOrFunction(pExpr, db->init.busy) ){ |
| 110339 | + if( !sqlite3ExprIsConstantOrFunction(pExpr, isInit) ){ |
| 109734 | 110340 | sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant", |
| 109735 | 110341 | pCol->zName); |
| 109736 | 110342 | #ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 109737 | 110343 | }else if( pCol->colFlags & COLFLAG_GENERATED ){ |
| 109738 | 110344 | testcase( pCol->colFlags & COLFLAG_VIRTUAL ); |
| | @@ -110948,11 +111554,14 @@ |
| 110948 | 111554 | db->xAuth = xAuth; |
| 110949 | 111555 | #else |
| 110950 | 111556 | pSelTab = sqlite3ResultSetOfSelect(pParse, pSel, SQLITE_AFF_NONE); |
| 110951 | 111557 | #endif |
| 110952 | 111558 | pParse->nTab = n; |
| 110953 | | - if( pTable->pCheck ){ |
| 111559 | + if( pSelTab==0 ){ |
| 111560 | + pTable->nCol = 0; |
| 111561 | + nErr++; |
| 111562 | + }else if( pTable->pCheck ){ |
| 110954 | 111563 | /* CREATE VIEW name(arglist) AS ... |
| 110955 | 111564 | ** The names of the columns in the table are taken from |
| 110956 | 111565 | ** arglist which is stored in pTable->pCheck. The pCheck field |
| 110957 | 111566 | ** normally holds CHECK constraints on an ordinary table, but for |
| 110958 | 111567 | ** a VIEW it holds the list of column names. |
| | @@ -110964,23 +111573,20 @@ |
| 110964 | 111573 | && pTable->nCol==pSel->pEList->nExpr |
| 110965 | 111574 | ){ |
| 110966 | 111575 | sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel, |
| 110967 | 111576 | SQLITE_AFF_NONE); |
| 110968 | 111577 | } |
| 110969 | | - }else if( pSelTab ){ |
| 111578 | + }else{ |
| 110970 | 111579 | /* CREATE VIEW name AS... without an argument list. Construct |
| 110971 | 111580 | ** the column names from the SELECT statement that defines the view. |
| 110972 | 111581 | */ |
| 110973 | 111582 | assert( pTable->aCol==0 ); |
| 110974 | 111583 | pTable->nCol = pSelTab->nCol; |
| 110975 | 111584 | pTable->aCol = pSelTab->aCol; |
| 110976 | 111585 | pSelTab->nCol = 0; |
| 110977 | 111586 | pSelTab->aCol = 0; |
| 110978 | 111587 | assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) ); |
| 110979 | | - }else{ |
| 110980 | | - pTable->nCol = 0; |
| 110981 | | - nErr++; |
| 110982 | 111588 | } |
| 110983 | 111589 | pTable->nNVCol = pTable->nCol; |
| 110984 | 111590 | sqlite3DeleteTable(db, pSelTab); |
| 110985 | 111591 | sqlite3SelectDelete(db, pSel); |
| 110986 | 111592 | EnableLookaside; |
| | @@ -111430,11 +112036,11 @@ |
| 111430 | 112036 | nCol = pFromCol->nExpr; |
| 111431 | 112037 | } |
| 111432 | 112038 | nByte = sizeof(*pFKey) + (nCol-1)*sizeof(pFKey->aCol[0]) + pTo->n + 1; |
| 111433 | 112039 | if( pToCol ){ |
| 111434 | 112040 | for(i=0; i<pToCol->nExpr; i++){ |
| 111435 | | - nByte += sqlite3Strlen30(pToCol->a[i].zName) + 1; |
| 112041 | + nByte += sqlite3Strlen30(pToCol->a[i].zEName) + 1; |
| 111436 | 112042 | } |
| 111437 | 112043 | } |
| 111438 | 112044 | pFKey = sqlite3DbMallocZero(db, nByte ); |
| 111439 | 112045 | if( pFKey==0 ){ |
| 111440 | 112046 | goto fk_end; |
| | @@ -111455,34 +112061,34 @@ |
| 111455 | 112061 | pFKey->aCol[0].iFrom = p->nCol-1; |
| 111456 | 112062 | }else{ |
| 111457 | 112063 | for(i=0; i<nCol; i++){ |
| 111458 | 112064 | int j; |
| 111459 | 112065 | for(j=0; j<p->nCol; j++){ |
| 111460 | | - if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zName)==0 ){ |
| 112066 | + if( sqlite3StrICmp(p->aCol[j].zName, pFromCol->a[i].zEName)==0 ){ |
| 111461 | 112067 | pFKey->aCol[i].iFrom = j; |
| 111462 | 112068 | break; |
| 111463 | 112069 | } |
| 111464 | 112070 | } |
| 111465 | 112071 | if( j>=p->nCol ){ |
| 111466 | 112072 | sqlite3ErrorMsg(pParse, |
| 111467 | 112073 | "unknown column \"%s\" in foreign key definition", |
| 111468 | | - pFromCol->a[i].zName); |
| 112074 | + pFromCol->a[i].zEName); |
| 111469 | 112075 | goto fk_end; |
| 111470 | 112076 | } |
| 111471 | 112077 | if( IN_RENAME_OBJECT ){ |
| 111472 | | - sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zName); |
| 112078 | + sqlite3RenameTokenRemap(pParse, &pFKey->aCol[i], pFromCol->a[i].zEName); |
| 111473 | 112079 | } |
| 111474 | 112080 | } |
| 111475 | 112081 | } |
| 111476 | 112082 | if( pToCol ){ |
| 111477 | 112083 | for(i=0; i<nCol; i++){ |
| 111478 | | - int n = sqlite3Strlen30(pToCol->a[i].zName); |
| 112084 | + int n = sqlite3Strlen30(pToCol->a[i].zEName); |
| 111479 | 112085 | pFKey->aCol[i].zCol = z; |
| 111480 | 112086 | if( IN_RENAME_OBJECT ){ |
| 111481 | | - sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zName); |
| 112087 | + sqlite3RenameTokenRemap(pParse, z, pToCol->a[i].zEName); |
| 111482 | 112088 | } |
| 111483 | | - memcpy(z, pToCol->a[i].zName, n); |
| 112089 | + memcpy(z, pToCol->a[i].zEName, n); |
| 111484 | 112090 | z[n] = 0; |
| 111485 | 112091 | z += n+1; |
| 111486 | 112092 | } |
| 111487 | 112093 | } |
| 111488 | 112094 | pFKey->isDeferred = 0; |
| | @@ -113637,16 +114243,17 @@ |
| 113637 | 114243 | FuncDef *p, /* The function we are evaluating for match quality */ |
| 113638 | 114244 | int nArg, /* Desired number of arguments. (-1)==any */ |
| 113639 | 114245 | u8 enc /* Desired text encoding */ |
| 113640 | 114246 | ){ |
| 113641 | 114247 | int match; |
| 113642 | | - |
| 113643 | | - /* nArg of -2 is a special case */ |
| 113644 | | - if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH; |
| 114248 | + assert( p->nArg>=-1 ); |
| 113645 | 114249 | |
| 113646 | 114250 | /* Wrong number of arguments means "no match" */ |
| 113647 | | - if( p->nArg!=nArg && p->nArg>=0 ) return 0; |
| 114251 | + if( p->nArg!=nArg ){ |
| 114252 | + if( nArg==(-2) ) return (p->xSFunc==0) ? 0 : FUNC_PERFECT_MATCH; |
| 114253 | + if( p->nArg>=0 ) return 0; |
| 114254 | + } |
| 113648 | 114255 | |
| 113649 | 114256 | /* Give a better score to a function with a specific number of arguments |
| 113650 | 114257 | ** than to function that accepts any number of arguments. */ |
| 113651 | 114258 | if( p->nArg==nArg ){ |
| 113652 | 114259 | match = 4; |
| | @@ -116747,30 +117354,35 @@ |
| 116747 | 117354 | ** are read-only after initialization is complete. |
| 116748 | 117355 | ** |
| 116749 | 117356 | ** For peak efficiency, put the most frequently used function last. |
| 116750 | 117357 | */ |
| 116751 | 117358 | static FuncDef aBuiltinFunc[] = { |
| 117359 | +/***** Functions only available with SQLITE_TESTCTRL_INTERNAL_FUNCTIONS *****/ |
| 117360 | + TEST_FUNC(implies_nonnull_row, 2, INLINEFUNC_implies_nonnull_row, 0), |
| 117361 | + TEST_FUNC(expr_compare, 2, INLINEFUNC_expr_compare, 0), |
| 117362 | + TEST_FUNC(expr_implies_expr, 2, INLINEFUNC_expr_implies_expr, 0), |
| 117363 | +#ifdef SQLITE_DEBUG |
| 117364 | + TEST_FUNC(affinity, 1, INLINEFUNC_affinity, 0), |
| 117365 | +#endif |
| 117366 | +/***** Regular functions *****/ |
| 116752 | 117367 | #ifdef SQLITE_SOUNDEX |
| 116753 | 117368 | FUNCTION(soundex, 1, 0, 0, soundexFunc ), |
| 116754 | 117369 | #endif |
| 116755 | 117370 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 116756 | | - VFUNCTION(load_extension, 1, 0, 0, loadExt ), |
| 116757 | | - VFUNCTION(load_extension, 2, 0, 0, loadExt ), |
| 117371 | + SFUNCTION(load_extension, 1, 0, 0, loadExt ), |
| 117372 | + SFUNCTION(load_extension, 2, 0, 0, loadExt ), |
| 116758 | 117373 | #endif |
| 116759 | 117374 | #if SQLITE_USER_AUTHENTICATION |
| 116760 | 117375 | FUNCTION(sqlite_crypt, 2, 0, 0, sqlite3CryptFunc ), |
| 116761 | 117376 | #endif |
| 116762 | 117377 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 116763 | 117378 | DFUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), |
| 116764 | 117379 | DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 116765 | 117380 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 116766 | | - FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 116767 | | - FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 116768 | | - FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 116769 | | -#ifdef SQLITE_DEBUG |
| 116770 | | - FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY), |
| 116771 | | -#endif |
| 117381 | + INLINE_FUNC(unlikely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), |
| 117382 | + INLINE_FUNC(likelihood, 2, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), |
| 117383 | + INLINE_FUNC(likely, 1, INLINEFUNC_unlikely, SQLITE_FUNC_UNLIKELY), |
| 116772 | 117384 | #ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC |
| 116773 | 117385 | FUNCTION2(sqlite_offset, 1, 0, 0, noopFunc, SQLITE_FUNC_OFFSET| |
| 116774 | 117386 | SQLITE_FUNC_TYPEOF), |
| 116775 | 117387 | #endif |
| 116776 | 117388 | FUNCTION(ltrim, 1, 1, 0, trimFunc ), |
| | @@ -116799,11 +117411,11 @@ |
| 116799 | 117411 | FUNCTION(round, 2, 0, 0, roundFunc ), |
| 116800 | 117412 | #endif |
| 116801 | 117413 | FUNCTION(upper, 1, 0, 0, upperFunc ), |
| 116802 | 117414 | FUNCTION(lower, 1, 0, 0, lowerFunc ), |
| 116803 | 117415 | FUNCTION(hex, 1, 0, 0, hexFunc ), |
| 116804 | | - FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), |
| 117416 | + INLINE_FUNC(ifnull, 2, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE), |
| 116805 | 117417 | VFUNCTION(random, 0, 0, 0, randomFunc ), |
| 116806 | 117418 | VFUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 116807 | 117419 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 116808 | 117420 | DFUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 116809 | 117421 | DFUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| | @@ -116839,11 +117451,11 @@ |
| 116839 | 117451 | #ifdef SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION |
| 116840 | 117452 | FUNCTION(unknown, -1, 0, 0, unknownFunc ), |
| 116841 | 117453 | #endif |
| 116842 | 117454 | FUNCTION(coalesce, 1, 0, 0, 0 ), |
| 116843 | 117455 | FUNCTION(coalesce, 0, 0, 0, 0 ), |
| 116844 | | - FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), |
| 117456 | + INLINE_FUNC(coalesce, -1, INLINEFUNC_coalesce, SQLITE_FUNC_COALESCE), |
| 116845 | 117457 | }; |
| 116846 | 117458 | #ifndef SQLITE_OMIT_ALTERTABLE |
| 116847 | 117459 | sqlite3AlterFunctions(); |
| 116848 | 117460 | #endif |
| 116849 | 117461 | sqlite3WindowFunctions(); |
| | @@ -119340,10 +119952,11 @@ |
| 119340 | 119952 | ** C: yield X, at EOF goto D |
| 119341 | 119953 | ** insert the select result into <table> from R..R+n |
| 119342 | 119954 | ** goto C |
| 119343 | 119955 | ** D: ... |
| 119344 | 119956 | */ |
| 119957 | + sqlite3VdbeReleaseRegisters(pParse, regData, pTab->nCol, 0, 0); |
| 119345 | 119958 | addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); |
| 119346 | 119959 | VdbeCoverage(v); |
| 119347 | 119960 | if( ipkColumn>=0 ){ |
| 119348 | 119961 | /* tag-20191021-001: If the INTEGER PRIMARY KEY is being generated by the |
| 119349 | 119962 | ** SELECT, go ahead and copy the value into the rowid slot now, so that |
| | @@ -119600,10 +120213,19 @@ |
| 119600 | 120213 | sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v); |
| 119601 | 120214 | sqlite3VdbeJumpHere(v, addrInsTop); |
| 119602 | 120215 | sqlite3VdbeAddOp1(v, OP_Close, srcTab); |
| 119603 | 120216 | }else if( pSelect ){ |
| 119604 | 120217 | sqlite3VdbeGoto(v, addrCont); |
| 120218 | +#ifdef SQLITE_DEBUG |
| 120219 | + /* If we are jumping back to an OP_Yield that is preceded by an |
| 120220 | + ** OP_ReleaseReg, set the p5 flag on the OP_Goto so that the |
| 120221 | + ** OP_ReleaseReg will be included in the loop. */ |
| 120222 | + if( sqlite3VdbeGetOp(v, addrCont-1)->opcode==OP_ReleaseReg ){ |
| 120223 | + assert( sqlite3VdbeGetOp(v, addrCont)->opcode==OP_Yield ); |
| 120224 | + sqlite3VdbeChangeP5(v, 1); |
| 120225 | + } |
| 120226 | +#endif |
| 119605 | 120227 | sqlite3VdbeJumpHere(v, addrInsTop); |
| 119606 | 120228 | } |
| 119607 | 120229 | |
| 119608 | 120230 | insert_end: |
| 119609 | 120231 | /* Update the sqlite_sequence table by storing the content of the |
| | @@ -119822,11 +120444,10 @@ |
| 119822 | 120444 | sqlite3 *db; /* Database connection */ |
| 119823 | 120445 | int i; /* loop counter */ |
| 119824 | 120446 | int ix; /* Index loop counter */ |
| 119825 | 120447 | int nCol; /* Number of columns */ |
| 119826 | 120448 | int onError; /* Conflict resolution strategy */ |
| 119827 | | - int addr1; /* Address of jump instruction */ |
| 119828 | 120449 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 119829 | 120450 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 119830 | 120451 | Index *pUpIdx = 0; /* Index to which to apply the upsert */ |
| 119831 | 120452 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| 119832 | 120453 | u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */ |
| | @@ -119866,75 +120487,104 @@ |
| 119866 | 120487 | iDataCur, iIdxCur, regNewData, regOldData, pkChng)); |
| 119867 | 120488 | |
| 119868 | 120489 | /* Test all NOT NULL constraints. |
| 119869 | 120490 | */ |
| 119870 | 120491 | if( pTab->tabFlags & TF_HasNotNull ){ |
| 119871 | | - for(i=0; i<nCol; i++){ |
| 119872 | | - int iReg; |
| 119873 | | - onError = pTab->aCol[i].notNull; |
| 119874 | | - if( onError==OE_None ) continue; /* No NOT NULL on this column */ |
| 119875 | | - if( i==pTab->iPKey ){ |
| 119876 | | - continue; /* ROWID is never NULL */ |
| 119877 | | - } |
| 119878 | | - if( aiChng && aiChng[i]<0 ){ |
| 119879 | | - /* Don't bother checking for NOT NULL on columns that do not change */ |
| 119880 | | - continue; |
| 119881 | | - } |
| 119882 | | - if( overrideError!=OE_Default ){ |
| 119883 | | - onError = overrideError; |
| 119884 | | - }else if( onError==OE_Default ){ |
| 119885 | | - onError = OE_Abort; |
| 119886 | | - } |
| 119887 | | - if( onError==OE_Replace && pTab->aCol[i].pDflt==0 ){ |
| 119888 | | - onError = OE_Abort; |
| 119889 | | - } |
| 119890 | | - assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail |
| 119891 | | - || onError==OE_Ignore || onError==OE_Replace ); |
| 119892 | | - addr1 = 0; |
| 119893 | | - testcase( i!=sqlite3TableColumnToStorage(pTab, i) ); |
| 119894 | | - testcase( pTab->aCol[i].colFlags & COLFLAG_VIRTUAL ); |
| 119895 | | - testcase( pTab->aCol[i].colFlags & COLFLAG_STORED ); |
| 119896 | | - iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1; |
| 119897 | | - switch( onError ){ |
| 119898 | | - case OE_Replace: { |
| 119899 | | - assert( onError==OE_Replace ); |
| 119900 | | - addr1 = sqlite3VdbeMakeLabel(pParse); |
| 119901 | | - sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1); |
| 119902 | | - VdbeCoverage(v); |
| 119903 | | - if( (pTab->aCol[i].colFlags & COLFLAG_GENERATED)==0 ){ |
| 119904 | | - sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i); |
| 119905 | | - sqlite3VdbeAddOp2(v, OP_NotNull, iReg, addr1); |
| 119906 | | - VdbeCoverage(v); |
| 119907 | | - } |
| 119908 | | - onError = OE_Abort; |
| 119909 | | - /* Fall through into the OE_Abort case to generate code that runs |
| 119910 | | - ** if both the input and the default value are NULL */ |
| 119911 | | - } |
| 119912 | | - case OE_Abort: |
| 119913 | | - sqlite3MayAbort(pParse); |
| 119914 | | - /* Fall through */ |
| 119915 | | - case OE_Rollback: |
| 119916 | | - case OE_Fail: { |
| 119917 | | - char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName, |
| 119918 | | - pTab->aCol[i].zName); |
| 119919 | | - sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, |
| 119920 | | - onError, iReg); |
| 119921 | | - sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC); |
| 119922 | | - sqlite3VdbeChangeP5(v, P5_ConstraintNotNull); |
| 119923 | | - VdbeCoverage(v); |
| 119924 | | - if( addr1 ) sqlite3VdbeResolveLabel(v, addr1); |
| 119925 | | - break; |
| 119926 | | - } |
| 119927 | | - default: { |
| 119928 | | - assert( onError==OE_Ignore ); |
| 119929 | | - sqlite3VdbeAddOp2(v, OP_IsNull, iReg, ignoreDest); |
| 119930 | | - VdbeCoverage(v); |
| 119931 | | - break; |
| 119932 | | - } |
| 119933 | | - } |
| 119934 | | - } |
| 119935 | | - } |
| 120492 | + int b2ndPass = 0; /* True if currently running 2nd pass */ |
| 120493 | + int nSeenReplace = 0; /* Number of ON CONFLICT REPLACE operations */ |
| 120494 | + int nGenerated = 0; /* Number of generated columns with NOT NULL */ |
| 120495 | + while(1){ /* Make 2 passes over columns. Exit loop via "break" */ |
| 120496 | + for(i=0; i<nCol; i++){ |
| 120497 | + int iReg; /* Register holding column value */ |
| 120498 | + Column *pCol = &pTab->aCol[i]; /* The column to check for NOT NULL */ |
| 120499 | + int isGenerated; /* non-zero if column is generated */ |
| 120500 | + onError = pCol->notNull; |
| 120501 | + if( onError==OE_None ) continue; /* No NOT NULL on this column */ |
| 120502 | + if( i==pTab->iPKey ){ |
| 120503 | + continue; /* ROWID is never NULL */ |
| 120504 | + } |
| 120505 | + isGenerated = pCol->colFlags & COLFLAG_GENERATED; |
| 120506 | + if( isGenerated && !b2ndPass ){ |
| 120507 | + nGenerated++; |
| 120508 | + continue; /* Generated columns processed on 2nd pass */ |
| 120509 | + } |
| 120510 | + if( aiChng && aiChng[i]<0 && !isGenerated ){ |
| 120511 | + /* Do not check NOT NULL on columns that do not change */ |
| 120512 | + continue; |
| 120513 | + } |
| 120514 | + if( overrideError!=OE_Default ){ |
| 120515 | + onError = overrideError; |
| 120516 | + }else if( onError==OE_Default ){ |
| 120517 | + onError = OE_Abort; |
| 120518 | + } |
| 120519 | + if( onError==OE_Replace ){ |
| 120520 | + if( b2ndPass /* REPLACE becomes ABORT on the 2nd pass */ |
| 120521 | + || pCol->pDflt==0 /* REPLACE is ABORT if no DEFAULT value */ |
| 120522 | + ){ |
| 120523 | + testcase( pCol->colFlags & COLFLAG_VIRTUAL ); |
| 120524 | + testcase( pCol->colFlags & COLFLAG_STORED ); |
| 120525 | + testcase( pCol->colFlags & COLFLAG_GENERATED ); |
| 120526 | + onError = OE_Abort; |
| 120527 | + }else{ |
| 120528 | + assert( !isGenerated ); |
| 120529 | + } |
| 120530 | + }else if( b2ndPass && !isGenerated ){ |
| 120531 | + continue; |
| 120532 | + } |
| 120533 | + assert( onError==OE_Rollback || onError==OE_Abort || onError==OE_Fail |
| 120534 | + || onError==OE_Ignore || onError==OE_Replace ); |
| 120535 | + testcase( i!=sqlite3TableColumnToStorage(pTab, i) ); |
| 120536 | + iReg = sqlite3TableColumnToStorage(pTab, i) + regNewData + 1; |
| 120537 | + switch( onError ){ |
| 120538 | + case OE_Replace: { |
| 120539 | + int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, iReg); |
| 120540 | + VdbeCoverage(v); |
| 120541 | + assert( (pCol->colFlags & COLFLAG_GENERATED)==0 ); |
| 120542 | + nSeenReplace++; |
| 120543 | + sqlite3ExprCode(pParse, pCol->pDflt, iReg); |
| 120544 | + sqlite3VdbeJumpHere(v, addr1); |
| 120545 | + break; |
| 120546 | + } |
| 120547 | + case OE_Abort: |
| 120548 | + sqlite3MayAbort(pParse); |
| 120549 | + /* Fall through */ |
| 120550 | + case OE_Rollback: |
| 120551 | + case OE_Fail: { |
| 120552 | + char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName, |
| 120553 | + pCol->zName); |
| 120554 | + sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, |
| 120555 | + onError, iReg); |
| 120556 | + sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC); |
| 120557 | + sqlite3VdbeChangeP5(v, P5_ConstraintNotNull); |
| 120558 | + VdbeCoverage(v); |
| 120559 | + break; |
| 120560 | + } |
| 120561 | + default: { |
| 120562 | + assert( onError==OE_Ignore ); |
| 120563 | + sqlite3VdbeAddOp2(v, OP_IsNull, iReg, ignoreDest); |
| 120564 | + VdbeCoverage(v); |
| 120565 | + break; |
| 120566 | + } |
| 120567 | + } /* end switch(onError) */ |
| 120568 | + } /* end loop i over columns */ |
| 120569 | + if( nGenerated==0 && nSeenReplace==0 ){ |
| 120570 | + /* If there are no generated columns with NOT NULL constraints |
| 120571 | + ** and no NOT NULL ON CONFLICT REPLACE constraints, then a single |
| 120572 | + ** pass is sufficient */ |
| 120573 | + break; |
| 120574 | + } |
| 120575 | + if( b2ndPass ) break; /* Never need more than 2 passes */ |
| 120576 | + b2ndPass = 1; |
| 120577 | + if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){ |
| 120578 | + /* If any NOT NULL ON CONFLICT REPLACE constraints fired on the |
| 120579 | + ** first pass, recomputed values for all generated columns, as |
| 120580 | + ** those values might depend on columns affected by the REPLACE. |
| 120581 | + */ |
| 120582 | + sqlite3ComputeGeneratedColumns(pParse, regNewData+1, pTab); |
| 120583 | + } |
| 120584 | + } /* end of 2-pass loop */ |
| 120585 | + } /* end if( has-not-null-constraints ) */ |
| 119936 | 120586 | |
| 119937 | 120587 | /* Test all CHECK constraints |
| 119938 | 120588 | */ |
| 119939 | 120589 | #ifndef SQLITE_OMIT_CHECK |
| 119940 | 120590 | if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){ |
| | @@ -119955,11 +120605,11 @@ |
| 119955 | 120605 | sqlite3VdbeVerifyAbortable(v, onError); |
| 119956 | 120606 | sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL); |
| 119957 | 120607 | if( onError==OE_Ignore ){ |
| 119958 | 120608 | sqlite3VdbeGoto(v, ignoreDest); |
| 119959 | 120609 | }else{ |
| 119960 | | - char *zName = pCheck->a[i].zName; |
| 120610 | + char *zName = pCheck->a[i].zEName; |
| 119961 | 120611 | if( zName==0 ) zName = pTab->zName; |
| 119962 | 120612 | if( onError==OE_Replace ) onError = OE_Abort; /* IMP: R-26383-51744 */ |
| 119963 | 120613 | sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_CHECK, |
| 119964 | 120614 | onError, zName, P4_TRANSIENT, |
| 119965 | 120615 | P5_ConstraintCheck); |
| | @@ -120258,10 +120908,11 @@ |
| 120258 | 120908 | #ifdef SQLITE_ENABLE_NULL_TRIM |
| 120259 | 120909 | if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){ |
| 120260 | 120910 | sqlite3SetMakeRecordP5(v, pIdx->pTable); |
| 120261 | 120911 | } |
| 120262 | 120912 | #endif |
| 120913 | + sqlite3VdbeReleaseRegisters(pParse, regIdx, pIdx->nColumn, 0, 0); |
| 120263 | 120914 | |
| 120264 | 120915 | /* In an UPDATE operation, if this index is the PRIMARY KEY index |
| 120265 | 120916 | ** of a WITHOUT ROWID table and there has been no change the |
| 120266 | 120917 | ** primary key, then no collision is possible. The collision detection |
| 120267 | 120918 | ** logic below can all be skipped. */ |
| | @@ -120411,13 +121062,19 @@ |
| 120411 | 121062 | testcase( nConflictCk>1 ); |
| 120412 | 121063 | if( regTrigCnt ){ |
| 120413 | 121064 | sqlite3MultiWrite(pParse); |
| 120414 | 121065 | nReplaceTrig++; |
| 120415 | 121066 | } |
| 121067 | + if( pTrigger && isUpdate ){ |
| 121068 | + sqlite3VdbeAddOp1(v, OP_CursorLock, iDataCur); |
| 121069 | + } |
| 120416 | 121070 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 120417 | 121071 | regR, nPkField, 0, OE_Replace, |
| 120418 | 121072 | (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur); |
| 121073 | + if( pTrigger && isUpdate ){ |
| 121074 | + sqlite3VdbeAddOp1(v, OP_CursorUnlock, iDataCur); |
| 121075 | + } |
| 120419 | 121076 | if( regTrigCnt ){ |
| 120420 | 121077 | int addrBypass; /* Jump destination to bypass recheck logic */ |
| 120421 | 121078 | |
| 120422 | 121079 | sqlite3VdbeAddOp2(v, OP_AddImm, regTrigCnt, 1); /* incr trigger cnt */ |
| 120423 | 121080 | addrBypass = sqlite3VdbeAddOp0(v, OP_Goto); /* Bypass recheck */ |
| | @@ -122889,39 +123546,43 @@ |
| 122889 | 123546 | /* 16 */ "cid", |
| 122890 | 123547 | /* 17 */ "name", |
| 122891 | 123548 | /* 18 */ "desc", |
| 122892 | 123549 | /* 19 */ "coll", |
| 122893 | 123550 | /* 20 */ "key", |
| 122894 | | - /* 21 */ "tbl", /* Used by: stats */ |
| 122895 | | - /* 22 */ "idx", |
| 122896 | | - /* 23 */ "wdth", |
| 122897 | | - /* 24 */ "hght", |
| 122898 | | - /* 25 */ "flgs", |
| 122899 | | - /* 26 */ "seq", /* Used by: index_list */ |
| 122900 | | - /* 27 */ "name", |
| 122901 | | - /* 28 */ "unique", |
| 122902 | | - /* 29 */ "origin", |
| 122903 | | - /* 30 */ "partial", |
| 122904 | | - /* 31 */ "table", /* Used by: foreign_key_check */ |
| 122905 | | - /* 32 */ "rowid", |
| 122906 | | - /* 33 */ "parent", |
| 122907 | | - /* 34 */ "fkid", |
| 123551 | + /* 21 */ "name", /* Used by: function_list */ |
| 123552 | + /* 22 */ "builtin", |
| 123553 | + /* 23 */ "type", |
| 123554 | + /* 24 */ "enc", |
| 123555 | + /* 25 */ "narg", |
| 123556 | + /* 26 */ "flags", |
| 123557 | + /* 27 */ "tbl", /* Used by: stats */ |
| 123558 | + /* 28 */ "idx", |
| 123559 | + /* 29 */ "wdth", |
| 123560 | + /* 30 */ "hght", |
| 123561 | + /* 31 */ "flgs", |
| 123562 | + /* 32 */ "seq", /* Used by: index_list */ |
| 123563 | + /* 33 */ "name", |
| 123564 | + /* 34 */ "unique", |
| 123565 | + /* 35 */ "origin", |
| 123566 | + /* 36 */ "partial", |
| 123567 | + /* 37 */ "table", /* Used by: foreign_key_check */ |
| 123568 | + /* 38 */ "rowid", |
| 123569 | + /* 39 */ "parent", |
| 123570 | + /* 40 */ "fkid", |
| 122908 | 123571 | /* index_info reuses 15 */ |
| 122909 | | - /* 35 */ "seq", /* Used by: database_list */ |
| 122910 | | - /* 36 */ "name", |
| 122911 | | - /* 37 */ "file", |
| 122912 | | - /* 38 */ "busy", /* Used by: wal_checkpoint */ |
| 122913 | | - /* 39 */ "log", |
| 122914 | | - /* 40 */ "checkpointed", |
| 122915 | | - /* 41 */ "name", /* Used by: function_list */ |
| 122916 | | - /* 42 */ "builtin", |
| 122917 | | - /* collation_list reuses 26 */ |
| 122918 | | - /* 43 */ "database", /* Used by: lock_status */ |
| 122919 | | - /* 44 */ "status", |
| 122920 | | - /* 45 */ "cache_size", /* Used by: default_cache_size */ |
| 123572 | + /* 41 */ "seq", /* Used by: database_list */ |
| 123573 | + /* 42 */ "name", |
| 123574 | + /* 43 */ "file", |
| 123575 | + /* 44 */ "busy", /* Used by: wal_checkpoint */ |
| 123576 | + /* 45 */ "log", |
| 123577 | + /* 46 */ "checkpointed", |
| 123578 | + /* collation_list reuses 32 */ |
| 123579 | + /* 47 */ "database", /* Used by: lock_status */ |
| 123580 | + /* 48 */ "status", |
| 123581 | + /* 49 */ "cache_size", /* Used by: default_cache_size */ |
| 122921 | 123582 | /* module_list pragma_list reuses 9 */ |
| 122922 | | - /* 46 */ "timeout", /* Used by: busy_timeout */ |
| 123583 | + /* 50 */ "timeout", /* Used by: busy_timeout */ |
| 122923 | 123584 | }; |
| 122924 | 123585 | |
| 122925 | 123586 | /* Definitions of all built-in pragmas */ |
| 122926 | 123587 | typedef struct PragmaName { |
| 122927 | 123588 | const char *const zName; /* Name of pragma */ |
| | @@ -122963,11 +123624,11 @@ |
| 122963 | 123624 | #endif |
| 122964 | 123625 | #endif |
| 122965 | 123626 | {/* zName: */ "busy_timeout", |
| 122966 | 123627 | /* ePragTyp: */ PragTyp_BUSY_TIMEOUT, |
| 122967 | 123628 | /* ePragFlg: */ PragFlg_Result0, |
| 122968 | | - /* ColNames: */ 46, 1, |
| 123629 | + /* ColNames: */ 50, 1, |
| 122969 | 123630 | /* iArg: */ 0 }, |
| 122970 | 123631 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 122971 | 123632 | {/* zName: */ "cache_size", |
| 122972 | 123633 | /* ePragTyp: */ PragTyp_CACHE_SIZE, |
| 122973 | 123634 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1, |
| | @@ -123002,11 +123663,11 @@ |
| 123002 | 123663 | #endif |
| 123003 | 123664 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 123004 | 123665 | {/* zName: */ "collation_list", |
| 123005 | 123666 | /* ePragTyp: */ PragTyp_COLLATION_LIST, |
| 123006 | 123667 | /* ePragFlg: */ PragFlg_Result0, |
| 123007 | | - /* ColNames: */ 26, 2, |
| 123668 | + /* ColNames: */ 32, 2, |
| 123008 | 123669 | /* iArg: */ 0 }, |
| 123009 | 123670 | #endif |
| 123010 | 123671 | #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS) |
| 123011 | 123672 | {/* zName: */ "compile_options", |
| 123012 | 123673 | /* ePragTyp: */ PragTyp_COMPILE_OPTIONS, |
| | @@ -123037,18 +123698,18 @@ |
| 123037 | 123698 | #endif |
| 123038 | 123699 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 123039 | 123700 | {/* zName: */ "database_list", |
| 123040 | 123701 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 123041 | 123702 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, |
| 123042 | | - /* ColNames: */ 35, 3, |
| 123703 | + /* ColNames: */ 41, 3, |
| 123043 | 123704 | /* iArg: */ 0 }, |
| 123044 | 123705 | #endif |
| 123045 | 123706 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 123046 | 123707 | {/* zName: */ "default_cache_size", |
| 123047 | 123708 | /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE, |
| 123048 | 123709 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1, |
| 123049 | | - /* ColNames: */ 45, 1, |
| 123710 | + /* ColNames: */ 49, 1, |
| 123050 | 123711 | /* iArg: */ 0 }, |
| 123051 | 123712 | #endif |
| 123052 | 123713 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 123053 | 123714 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 123054 | 123715 | {/* zName: */ "defer_foreign_keys", |
| | @@ -123074,11 +123735,11 @@ |
| 123074 | 123735 | #endif |
| 123075 | 123736 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 123076 | 123737 | {/* zName: */ "foreign_key_check", |
| 123077 | 123738 | /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, |
| 123078 | 123739 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, |
| 123079 | | - /* ColNames: */ 31, 4, |
| 123740 | + /* ColNames: */ 37, 4, |
| 123080 | 123741 | /* iArg: */ 0 }, |
| 123081 | 123742 | #endif |
| 123082 | 123743 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) |
| 123083 | 123744 | {/* zName: */ "foreign_key_list", |
| 123084 | 123745 | /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST, |
| | @@ -123117,11 +123778,11 @@ |
| 123117 | 123778 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 123118 | 123779 | #if !defined(SQLITE_OMIT_INTROSPECTION_PRAGMAS) |
| 123119 | 123780 | {/* zName: */ "function_list", |
| 123120 | 123781 | /* ePragTyp: */ PragTyp_FUNCTION_LIST, |
| 123121 | 123782 | /* ePragFlg: */ PragFlg_Result0, |
| 123122 | | - /* ColNames: */ 41, 2, |
| 123783 | + /* ColNames: */ 21, 6, |
| 123123 | 123784 | /* iArg: */ 0 }, |
| 123124 | 123785 | #endif |
| 123125 | 123786 | #endif |
| 123126 | 123787 | {/* zName: */ "hard_heap_limit", |
| 123127 | 123788 | /* ePragTyp: */ PragTyp_HARD_HEAP_LIMIT, |
| | @@ -123163,11 +123824,11 @@ |
| 123163 | 123824 | /* ColNames: */ 15, 3, |
| 123164 | 123825 | /* iArg: */ 0 }, |
| 123165 | 123826 | {/* zName: */ "index_list", |
| 123166 | 123827 | /* ePragTyp: */ PragTyp_INDEX_LIST, |
| 123167 | 123828 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 123168 | | - /* ColNames: */ 26, 5, |
| 123829 | + /* ColNames: */ 32, 5, |
| 123169 | 123830 | /* iArg: */ 0 }, |
| 123170 | 123831 | {/* zName: */ "index_xinfo", |
| 123171 | 123832 | /* ePragTyp: */ PragTyp_INDEX_INFO, |
| 123172 | 123833 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 123173 | 123834 | /* ColNames: */ 15, 6, |
| | @@ -123215,11 +123876,11 @@ |
| 123215 | 123876 | #endif |
| 123216 | 123877 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 123217 | 123878 | {/* zName: */ "lock_status", |
| 123218 | 123879 | /* ePragTyp: */ PragTyp_LOCK_STATUS, |
| 123219 | 123880 | /* ePragFlg: */ PragFlg_Result0, |
| 123220 | | - /* ColNames: */ 43, 2, |
| 123881 | + /* ColNames: */ 47, 2, |
| 123221 | 123882 | /* iArg: */ 0 }, |
| 123222 | 123883 | #endif |
| 123223 | 123884 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 123224 | 123885 | {/* zName: */ "locking_mode", |
| 123225 | 123886 | /* ePragTyp: */ PragTyp_LOCKING_MODE, |
| | @@ -123363,11 +124024,11 @@ |
| 123363 | 124024 | #endif |
| 123364 | 124025 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG) |
| 123365 | 124026 | {/* zName: */ "stats", |
| 123366 | 124027 | /* ePragTyp: */ PragTyp_STATS, |
| 123367 | 124028 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq, |
| 123368 | | - /* ColNames: */ 21, 5, |
| 124029 | + /* ColNames: */ 27, 5, |
| 123369 | 124030 | /* iArg: */ 0 }, |
| 123370 | 124031 | #endif |
| 123371 | 124032 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 123372 | 124033 | {/* zName: */ "synchronous", |
| 123373 | 124034 | /* ePragTyp: */ PragTyp_SYNCHRONOUS, |
| | @@ -123414,10 +124075,17 @@ |
| 123414 | 124075 | {/* zName: */ "threads", |
| 123415 | 124076 | /* ePragTyp: */ PragTyp_THREADS, |
| 123416 | 124077 | /* ePragFlg: */ PragFlg_Result0, |
| 123417 | 124078 | /* ColNames: */ 0, 0, |
| 123418 | 124079 | /* iArg: */ 0 }, |
| 124080 | +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 124081 | + {/* zName: */ "trusted_schema", |
| 124082 | + /* ePragTyp: */ PragTyp_FLAG, |
| 124083 | + /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124084 | + /* ColNames: */ 0, 0, |
| 124085 | + /* iArg: */ SQLITE_TrustedSchema }, |
| 124086 | +#endif |
| 123419 | 124087 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 123420 | 124088 | {/* zName: */ "user_version", |
| 123421 | 124089 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 123422 | 124090 | /* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0, |
| 123423 | 124091 | /* ColNames: */ 0, 0, |
| | @@ -123459,11 +124127,11 @@ |
| 123459 | 124127 | /* ColNames: */ 0, 0, |
| 123460 | 124128 | /* iArg: */ 0 }, |
| 123461 | 124129 | {/* zName: */ "wal_checkpoint", |
| 123462 | 124130 | /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, |
| 123463 | 124131 | /* ePragFlg: */ PragFlg_NeedSchema, |
| 123464 | | - /* ColNames: */ 38, 3, |
| 124132 | + /* ColNames: */ 44, 3, |
| 123465 | 124133 | /* iArg: */ 0 }, |
| 123466 | 124134 | #endif |
| 123467 | 124135 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 123468 | 124136 | {/* zName: */ "writable_schema", |
| 123469 | 124137 | /* ePragTyp: */ PragTyp_FLAG, |
| | @@ -123470,11 +124138,11 @@ |
| 123470 | 124138 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 123471 | 124139 | /* ColNames: */ 0, 0, |
| 123472 | 124140 | /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError }, |
| 123473 | 124141 | #endif |
| 123474 | 124142 | }; |
| 123475 | | -/* Number of pragmas: 65 on by default, 81 total. */ |
| 124143 | +/* Number of pragmas: 66 on by default, 82 total. */ |
| 123476 | 124144 | |
| 123477 | 124145 | /************** End of pragma.h **********************************************/ |
| 123478 | 124146 | /************** Continuing where we left off in pragma.c *********************/ |
| 123479 | 124147 | |
| 123480 | 124148 | /* |
| | @@ -123739,10 +124407,59 @@ |
| 123739 | 124407 | lwr = mid + 1; |
| 123740 | 124408 | } |
| 123741 | 124409 | } |
| 123742 | 124410 | return lwr>upr ? 0 : &aPragmaName[mid]; |
| 123743 | 124411 | } |
| 124412 | + |
| 124413 | +/* |
| 124414 | +** Create zero or more entries in the output for the SQL functions |
| 124415 | +** defined by FuncDef p. |
| 124416 | +*/ |
| 124417 | +static void pragmaFunclistLine( |
| 124418 | + Vdbe *v, /* The prepared statement being created */ |
| 124419 | + FuncDef *p, /* A particular function definition */ |
| 124420 | + int isBuiltin, /* True if this is a built-in function */ |
| 124421 | + int showInternFuncs /* True if showing internal functions */ |
| 124422 | +){ |
| 124423 | + for(; p; p=p->pNext){ |
| 124424 | + const char *zType; |
| 124425 | + static const u32 mask = |
| 124426 | + SQLITE_DETERMINISTIC | |
| 124427 | + SQLITE_DIRECTONLY | |
| 124428 | + SQLITE_SUBTYPE | |
| 124429 | + SQLITE_INNOCUOUS | |
| 124430 | + SQLITE_FUNC_INTERNAL |
| 124431 | + ; |
| 124432 | + static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; |
| 124433 | + |
| 124434 | + assert( SQLITE_FUNC_ENCMASK==0x3 ); |
| 124435 | + assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 ); |
| 124436 | + assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 ); |
| 124437 | + assert( strcmp(azEnc[SQLITE_UTF16BE],"utf16be")==0 ); |
| 124438 | + |
| 124439 | + if( p->xSFunc==0 ) continue; |
| 124440 | + if( (p->funcFlags & SQLITE_FUNC_INTERNAL)!=0 |
| 124441 | + && showInternFuncs==0 |
| 124442 | + ){ |
| 124443 | + continue; |
| 124444 | + } |
| 124445 | + if( p->xValue!=0 ){ |
| 124446 | + zType = "w"; |
| 124447 | + }else if( p->xFinalize!=0 ){ |
| 124448 | + zType = "a"; |
| 124449 | + }else{ |
| 124450 | + zType = "s"; |
| 124451 | + } |
| 124452 | + sqlite3VdbeMultiLoad(v, 1, "sissii", |
| 124453 | + p->zName, isBuiltin, |
| 124454 | + zType, azEnc[p->funcFlags&SQLITE_FUNC_ENCMASK], |
| 124455 | + p->nArg, |
| 124456 | + (p->funcFlags & mask) ^ SQLITE_INNOCUOUS |
| 124457 | + ); |
| 124458 | + } |
| 124459 | +} |
| 124460 | + |
| 123744 | 124461 | |
| 123745 | 124462 | /* |
| 123746 | 124463 | ** Helper subroutine for PRAGMA integrity_check: |
| 123747 | 124464 | ** |
| 123748 | 124465 | ** Generate code to output a single-column result row with a value of the |
| | @@ -124704,20 +125421,20 @@ |
| 124704 | 125421 | #ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS |
| 124705 | 125422 | case PragTyp_FUNCTION_LIST: { |
| 124706 | 125423 | int i; |
| 124707 | 125424 | HashElem *j; |
| 124708 | 125425 | FuncDef *p; |
| 124709 | | - pParse->nMem = 2; |
| 125426 | + int showInternFunc = (db->mDbFlags & DBFLAG_InternalFunc)!=0; |
| 125427 | + pParse->nMem = 6; |
| 124710 | 125428 | for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){ |
| 124711 | 125429 | for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){ |
| 124712 | | - if( p->funcFlags & SQLITE_FUNC_INTERNAL ) continue; |
| 124713 | | - sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 1); |
| 125430 | + pragmaFunclistLine(v, p, 1, showInternFunc); |
| 124714 | 125431 | } |
| 124715 | 125432 | } |
| 124716 | 125433 | for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){ |
| 124717 | 125434 | p = (FuncDef*)sqliteHashData(j); |
| 124718 | | - sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 0); |
| 125435 | + pragmaFunclistLine(v, p, 0, showInternFunc); |
| 124719 | 125436 | } |
| 124720 | 125437 | } |
| 124721 | 125438 | break; |
| 124722 | 125439 | |
| 124723 | 125440 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -127127,10 +127844,11 @@ |
| 127127 | 127844 | if( ALWAYS(p) ){ |
| 127128 | 127845 | clearSelect(pParse->db, p, 0); |
| 127129 | 127846 | memset(&p->iLimit, 0, sizeof(Select) - offsetof(Select,iLimit)); |
| 127130 | 127847 | p->pEList = sqlite3ExprListAppend(pParse, 0, |
| 127131 | 127848 | sqlite3ExprAlloc(pParse->db,TK_NULL,0,0)); |
| 127849 | + p->pSrc = sqlite3DbMallocZero(pParse->db, sizeof(SrcList)); |
| 127132 | 127850 | } |
| 127133 | 127851 | } |
| 127134 | 127852 | |
| 127135 | 127853 | /* |
| 127136 | 127854 | ** Return a pointer to the right-most SELECT statement in a compound. |
| | @@ -127238,19 +127956,22 @@ |
| 127238 | 127956 | static int tableAndColumnIndex( |
| 127239 | 127957 | SrcList *pSrc, /* Array of tables to search */ |
| 127240 | 127958 | int N, /* Number of tables in pSrc->a[] to search */ |
| 127241 | 127959 | const char *zCol, /* Name of the column we are looking for */ |
| 127242 | 127960 | int *piTab, /* Write index of pSrc->a[] here */ |
| 127243 | | - int *piCol /* Write index of pSrc->a[*piTab].pTab->aCol[] here */ |
| 127961 | + int *piCol, /* Write index of pSrc->a[*piTab].pTab->aCol[] here */ |
| 127962 | + int bIgnoreHidden /* True to ignore hidden columns */ |
| 127244 | 127963 | ){ |
| 127245 | 127964 | int i; /* For looping over tables in pSrc */ |
| 127246 | 127965 | int iCol; /* Index of column matching zCol */ |
| 127247 | 127966 | |
| 127248 | 127967 | assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */ |
| 127249 | 127968 | for(i=0; i<N; i++){ |
| 127250 | 127969 | iCol = columnIndex(pSrc->a[i].pTab, zCol); |
| 127251 | | - if( iCol>=0 ){ |
| 127970 | + if( iCol>=0 |
| 127971 | + && (bIgnoreHidden==0 || IsHiddenColumn(&pSrc->a[i].pTab->aCol[iCol])==0) |
| 127972 | + ){ |
| 127252 | 127973 | if( piTab ){ |
| 127253 | 127974 | *piTab = i; |
| 127254 | 127975 | *piCol = iCol; |
| 127255 | 127976 | } |
| 127256 | 127977 | return 1; |
| | @@ -127411,14 +128132,15 @@ |
| 127411 | 128132 | for(j=0; j<pRightTab->nCol; j++){ |
| 127412 | 128133 | char *zName; /* Name of column in the right table */ |
| 127413 | 128134 | int iLeft; /* Matching left table */ |
| 127414 | 128135 | int iLeftCol; /* Matching column in the left table */ |
| 127415 | 128136 | |
| 128137 | + if( IsHiddenColumn(&pRightTab->aCol[j]) ) continue; |
| 127416 | 128138 | zName = pRightTab->aCol[j].zName; |
| 127417 | | - if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol) ){ |
| 128139 | + if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 1) ){ |
| 127418 | 128140 | addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j, |
| 127419 | | - isOuter, &p->pWhere); |
| 128141 | + isOuter, &p->pWhere); |
| 127420 | 128142 | } |
| 127421 | 128143 | } |
| 127422 | 128144 | } |
| 127423 | 128145 | |
| 127424 | 128146 | /* Disallow both ON and USING clauses in the same join |
| | @@ -127454,11 +128176,11 @@ |
| 127454 | 128176 | int iRightCol; /* Column number of matching column on the right */ |
| 127455 | 128177 | |
| 127456 | 128178 | zName = pList->a[j].zName; |
| 127457 | 128179 | iRightCol = columnIndex(pRightTab, zName); |
| 127458 | 128180 | if( iRightCol<0 |
| 127459 | | - || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol) |
| 128181 | + || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol, 0) |
| 127460 | 128182 | ){ |
| 127461 | 128183 | sqlite3ErrorMsg(pParse, "cannot join using column %s - column " |
| 127462 | 128184 | "not present in both tables", zName); |
| 127463 | 128185 | return 1; |
| 127464 | 128186 | } |
| | @@ -127860,11 +128582,11 @@ |
| 127860 | 128582 | pDest->nSdst = nResultCol; |
| 127861 | 128583 | regOrig = regResult = pDest->iSdst; |
| 127862 | 128584 | if( srcTab>=0 ){ |
| 127863 | 128585 | for(i=0; i<nResultCol; i++){ |
| 127864 | 128586 | sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i); |
| 127865 | | - VdbeComment((v, "%s", p->pEList->a[i].zName)); |
| 128587 | + VdbeComment((v, "%s", p->pEList->a[i].zEName)); |
| 127866 | 128588 | } |
| 127867 | 128589 | }else if( eDest!=SRT_Exists ){ |
| 127868 | 128590 | #ifdef SQLITE_ENABLE_SORTER_REFERENCES |
| 127869 | 128591 | ExprList *pExtra = 0; |
| 127870 | 128592 | #endif |
| | @@ -128481,11 +129203,11 @@ |
| 128481 | 129203 | iRead = aOutEx[i].u.x.iOrderByCol-1; |
| 128482 | 129204 | }else{ |
| 128483 | 129205 | iRead = iCol--; |
| 128484 | 129206 | } |
| 128485 | 129207 | sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i); |
| 128486 | | - VdbeComment((v, "%s", aOutEx[i].zName?aOutEx[i].zName : aOutEx[i].zSpan)); |
| 129208 | + VdbeComment((v, "%s", aOutEx[i].zEName)); |
| 128487 | 129209 | } |
| 128488 | 129210 | } |
| 128489 | 129211 | switch( eDest ){ |
| 128490 | 129212 | case SRT_Table: |
| 128491 | 129213 | case SRT_EphemTab: { |
| | @@ -128815,13 +129537,13 @@ |
| 128815 | 129537 | Expr *p = pEList->a[i].pExpr; |
| 128816 | 129538 | |
| 128817 | 129539 | assert( p!=0 ); |
| 128818 | 129540 | assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ |
| 128819 | 129541 | assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */ |
| 128820 | | - if( pEList->a[i].zName ){ |
| 129542 | + if( pEList->a[i].zEName && pEList->a[i].eEName==ENAME_NAME ){ |
| 128821 | 129543 | /* An AS clause always takes first priority */ |
| 128822 | | - char *zName = pEList->a[i].zName; |
| 129544 | + char *zName = pEList->a[i].zEName; |
| 128823 | 129545 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); |
| 128824 | 129546 | }else if( srcName && p->op==TK_COLUMN ){ |
| 128825 | 129547 | char *zCol; |
| 128826 | 129548 | int iCol = p->iColumn; |
| 128827 | 129549 | pTab = p->y.pTab; |
| | @@ -128839,11 +129561,11 @@ |
| 128839 | 129561 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_DYNAMIC); |
| 128840 | 129562 | }else{ |
| 128841 | 129563 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zCol, SQLITE_TRANSIENT); |
| 128842 | 129564 | } |
| 128843 | 129565 | }else{ |
| 128844 | | - const char *z = pEList->a[i].zSpan; |
| 129566 | + const char *z = pEList->a[i].zEName; |
| 128845 | 129567 | z = z==0 ? sqlite3MPrintf(db, "column%d", i+1) : sqlite3DbStrDup(db, z); |
| 128846 | 129568 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, z, SQLITE_DYNAMIC); |
| 128847 | 129569 | } |
| 128848 | 129570 | } |
| 128849 | 129571 | generateColumnTypes(pParse, pTabList, pEList); |
| | @@ -128901,11 +129623,11 @@ |
| 128901 | 129623 | *paCol = aCol; |
| 128902 | 129624 | |
| 128903 | 129625 | for(i=0, pCol=aCol; i<nCol && !db->mallocFailed; i++, pCol++){ |
| 128904 | 129626 | /* Get an appropriate name for the column |
| 128905 | 129627 | */ |
| 128906 | | - if( (zName = pEList->a[i].zName)!=0 ){ |
| 129628 | + if( (zName = pEList->a[i].zEName)!=0 && pEList->a[i].eEName==ENAME_NAME ){ |
| 128907 | 129629 | /* If the column contains an "AS <name>" phrase, use <name> as the name */ |
| 128908 | 129630 | }else{ |
| 128909 | 129631 | Expr *pColExpr = sqlite3ExprSkipCollateAndLikely(pEList->a[i].pExpr); |
| 128910 | 129632 | while( pColExpr->op==TK_DOT ){ |
| 128911 | 129633 | pColExpr = pColExpr->pRight; |
| | @@ -128921,14 +129643,14 @@ |
| 128921 | 129643 | }else if( pColExpr->op==TK_ID ){ |
| 128922 | 129644 | assert( !ExprHasProperty(pColExpr, EP_IntValue) ); |
| 128923 | 129645 | zName = pColExpr->u.zToken; |
| 128924 | 129646 | }else{ |
| 128925 | 129647 | /* Use the original text of the column expression as its name */ |
| 128926 | | - zName = pEList->a[i].zSpan; |
| 129648 | + zName = pEList->a[i].zEName; |
| 128927 | 129649 | } |
| 128928 | 129650 | } |
| 128929 | | - if( zName ){ |
| 129651 | + if( zName && !sqlite3IsTrueOrFalse(zName) ){ |
| 128930 | 129652 | zName = sqlite3DbStrDup(db, zName); |
| 128931 | 129653 | }else{ |
| 128932 | 129654 | zName = sqlite3MPrintf(db,"column%d",i+1); |
| 128933 | 129655 | } |
| 128934 | 129656 | |
| | @@ -130594,10 +131316,11 @@ |
| 130594 | 131316 | ** (17c) every term within the subquery compound must have a FROM clause |
| 130595 | 131317 | ** (17d) the outer query may not be |
| 130596 | 131318 | ** (17d1) aggregate, or |
| 130597 | 131319 | ** (17d2) DISTINCT, or |
| 130598 | 131320 | ** (17d3) a join. |
| 131321 | +** (17e) the subquery may not contain window functions |
| 130599 | 131322 | ** |
| 130600 | 131323 | ** The parent and sub-query may contain WHERE clauses. Subject to |
| 130601 | 131324 | ** rules (11), (13) and (14), they may also contain ORDER BY, |
| 130602 | 131325 | ** LIMIT and OFFSET clauses. The subquery cannot use any compound |
| 130603 | 131326 | ** operator other than UNION ALL because all the other compound |
| | @@ -130778,10 +131501,11 @@ |
| 130778 | 131501 | assert( pSub->pSrc!=0 ); |
| 130779 | 131502 | assert( pSub->pEList->nExpr==pSub1->pEList->nExpr ); |
| 130780 | 131503 | if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */ |
| 130781 | 131504 | || (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */ |
| 130782 | 131505 | || pSub1->pSrc->nSrc<1 /* (17c) */ |
| 131506 | + || pSub1->pWin /* (17e) */ |
| 130783 | 131507 | ){ |
| 130784 | 131508 | return 0; |
| 130785 | 131509 | } |
| 130786 | 131510 | testcase( pSub1->pSrc->nSrc>1 ); |
| 130787 | 131511 | } |
| | @@ -131064,27 +131788,40 @@ |
| 131064 | 131788 | Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */ |
| 131065 | 131789 | }; |
| 131066 | 131790 | |
| 131067 | 131791 | /* |
| 131068 | 131792 | ** Add a new entry to the pConst object. Except, do not add duplicate |
| 131069 | | -** pColumn entires. |
| 131793 | +** pColumn entires. Also, do not add if doing so would not be appropriate. |
| 131794 | +** |
| 131795 | +** The caller guarantees the pColumn is a column and pValue is a constant. |
| 131796 | +** This routine has to do some additional checks before completing the |
| 131797 | +** insert. |
| 131070 | 131798 | */ |
| 131071 | 131799 | static void constInsert( |
| 131072 | | - WhereConst *pConst, /* The WhereConst into which we are inserting */ |
| 131073 | | - Expr *pColumn, /* The COLUMN part of the constraint */ |
| 131074 | | - Expr *pValue /* The VALUE part of the constraint */ |
| 131800 | + WhereConst *pConst, /* The WhereConst into which we are inserting */ |
| 131801 | + Expr *pColumn, /* The COLUMN part of the constraint */ |
| 131802 | + Expr *pValue, /* The VALUE part of the constraint */ |
| 131803 | + Expr *pExpr /* Overall expression: COLUMN=VALUE or VALUE=COLUMN */ |
| 131075 | 131804 | ){ |
| 131076 | 131805 | int i; |
| 131077 | 131806 | assert( pColumn->op==TK_COLUMN ); |
| 131807 | + assert( sqlite3ExprIsConstant(pValue) ); |
| 131808 | + |
| 131809 | + if( !ExprHasProperty(pValue, EP_FixedCol) && sqlite3ExprAffinity(pValue)!=0 ){ |
| 131810 | + return; |
| 131811 | + } |
| 131812 | + if( !sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) ){ |
| 131813 | + return; |
| 131814 | + } |
| 131078 | 131815 | |
| 131079 | 131816 | /* 2018-10-25 ticket [cf5ed20f] |
| 131080 | 131817 | ** Make sure the same pColumn is not inserted more than once */ |
| 131081 | 131818 | for(i=0; i<pConst->nConst; i++){ |
| 131082 | | - const Expr *pExpr = pConst->apExpr[i*2]; |
| 131083 | | - assert( pExpr->op==TK_COLUMN ); |
| 131084 | | - if( pExpr->iTable==pColumn->iTable |
| 131085 | | - && pExpr->iColumn==pColumn->iColumn |
| 131819 | + const Expr *pE2 = pConst->apExpr[i*2]; |
| 131820 | + assert( pE2->op==TK_COLUMN ); |
| 131821 | + if( pE2->iTable==pColumn->iTable |
| 131822 | + && pE2->iColumn==pColumn->iColumn |
| 131086 | 131823 | ){ |
| 131087 | 131824 | return; /* Already present. Return without doing anything. */ |
| 131088 | 131825 | } |
| 131089 | 131826 | } |
| 131090 | 131827 | |
| | @@ -131092,11 +131829,13 @@ |
| 131092 | 131829 | pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr, |
| 131093 | 131830 | pConst->nConst*2*sizeof(Expr*)); |
| 131094 | 131831 | if( pConst->apExpr==0 ){ |
| 131095 | 131832 | pConst->nConst = 0; |
| 131096 | 131833 | }else{ |
| 131097 | | - if( ExprHasProperty(pValue, EP_FixedCol) ) pValue = pValue->pLeft; |
| 131834 | + if( ExprHasProperty(pValue, EP_FixedCol) ){ |
| 131835 | + pValue = pValue->pLeft; |
| 131836 | + } |
| 131098 | 131837 | pConst->apExpr[pConst->nConst*2-2] = pColumn; |
| 131099 | 131838 | pConst->apExpr[pConst->nConst*2-1] = pValue; |
| 131100 | 131839 | } |
| 131101 | 131840 | } |
| 131102 | 131841 | |
| | @@ -131118,23 +131857,15 @@ |
| 131118 | 131857 | if( pExpr->op!=TK_EQ ) return; |
| 131119 | 131858 | pRight = pExpr->pRight; |
| 131120 | 131859 | pLeft = pExpr->pLeft; |
| 131121 | 131860 | assert( pRight!=0 ); |
| 131122 | 131861 | assert( pLeft!=0 ); |
| 131123 | | - if( pRight->op==TK_COLUMN |
| 131124 | | - && !ExprHasProperty(pRight, EP_FixedCol) |
| 131125 | | - && sqlite3ExprIsConstant(pLeft) |
| 131126 | | - && sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) |
| 131127 | | - ){ |
| 131128 | | - constInsert(pConst, pRight, pLeft); |
| 131129 | | - }else |
| 131130 | | - if( pLeft->op==TK_COLUMN |
| 131131 | | - && !ExprHasProperty(pLeft, EP_FixedCol) |
| 131132 | | - && sqlite3ExprIsConstant(pRight) |
| 131133 | | - && sqlite3IsBinary(sqlite3ExprCompareCollSeq(pConst->pParse,pExpr)) |
| 131134 | | - ){ |
| 131135 | | - constInsert(pConst, pLeft, pRight); |
| 131862 | + if( pRight->op==TK_COLUMN && sqlite3ExprIsConstant(pLeft) ){ |
| 131863 | + constInsert(pConst,pRight,pLeft,pExpr); |
| 131864 | + } |
| 131865 | + if( pLeft->op==TK_COLUMN && sqlite3ExprIsConstant(pRight) ){ |
| 131866 | + constInsert(pConst,pLeft,pRight,pExpr); |
| 131136 | 131867 | } |
| 131137 | 131868 | } |
| 131138 | 131869 | |
| 131139 | 131870 | /* |
| 131140 | 131871 | ** This is a Walker expression callback. pExpr is a candidate expression |
| | @@ -131166,14 +131897,13 @@ |
| 131166 | 131897 | |
| 131167 | 131898 | /* |
| 131168 | 131899 | ** The WHERE-clause constant propagation optimization. |
| 131169 | 131900 | ** |
| 131170 | 131901 | ** If the WHERE clause contains terms of the form COLUMN=CONSTANT or |
| 131171 | | -** CONSTANT=COLUMN that must be tree (in other words, if the terms top-level |
| 131172 | | -** AND-connected terms that are not part of a ON clause from a LEFT JOIN) |
| 131173 | | -** then throughout the query replace all other occurrences of COLUMN |
| 131174 | | -** with CONSTANT within the WHERE clause. |
| 131902 | +** CONSTANT=COLUMN that are top-level AND-connected terms that are not |
| 131903 | +** part of a ON clause from a LEFT JOIN, then throughout the query |
| 131904 | +** replace all other occurrences of COLUMN with CONSTANT. |
| 131175 | 131905 | ** |
| 131176 | 131906 | ** For example, the query: |
| 131177 | 131907 | ** |
| 131178 | 131908 | ** SELECT * FROM t1, t2, t3 WHERE t1.a=39 AND t2.b=t1.a AND t3.c=t2.b |
| 131179 | 131909 | ** |
| | @@ -131882,11 +132612,19 @@ |
| 131882 | 132612 | u8 eCodeOrig = pWalker->eCode; |
| 131883 | 132613 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| 131884 | 132614 | assert( pFrom->pSelect==0 ); |
| 131885 | 132615 | if( pTab->pSelect && (db->flags & SQLITE_EnableView)==0 ){ |
| 131886 | 132616 | sqlite3ErrorMsg(pParse, "access to view \"%s\" prohibited", |
| 131887 | | - pTab->zName); |
| 132617 | + pTab->zName); |
| 132618 | + } |
| 132619 | + if( IsVirtual(pTab) |
| 132620 | + && pFrom->fg.fromDDL |
| 132621 | + && ALWAYS(pTab->pVTable!=0) |
| 132622 | + && pTab->pVTable->eVtabRisk > ((db->flags & SQLITE_TrustedSchema)!=0) |
| 132623 | + ){ |
| 132624 | + sqlite3ErrorMsg(pParse, "unsafe use of virtual table \"%s\"", |
| 132625 | + pTab->zName); |
| 131888 | 132626 | } |
| 131889 | 132627 | pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0); |
| 131890 | 132628 | nCol = pTab->nCol; |
| 131891 | 132629 | pTab->nCol = -1; |
| 131892 | 132630 | pWalker->eCode = 1; /* Turn on Select.selId renumbering */ |
| | @@ -131903,11 +132641,11 @@ |
| 131903 | 132641 | } |
| 131904 | 132642 | } |
| 131905 | 132643 | |
| 131906 | 132644 | /* Process NATURAL keywords, and ON and USING clauses of joins. |
| 131907 | 132645 | */ |
| 131908 | | - if( db->mallocFailed || sqliteProcessJoin(pParse, p) ){ |
| 132646 | + if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){ |
| 131909 | 132647 | return WRC_Abort; |
| 131910 | 132648 | } |
| 131911 | 132649 | |
| 131912 | 132650 | /* For every "*" that occurs in the column list, insert the names of |
| 131913 | 132651 | ** all columns in all tables. And for every TABLE.* insert the names |
| | @@ -131950,14 +132688,13 @@ |
| 131950 | 132688 | ){ |
| 131951 | 132689 | /* This particular expression does not need to be expanded. |
| 131952 | 132690 | */ |
| 131953 | 132691 | pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr); |
| 131954 | 132692 | if( pNew ){ |
| 131955 | | - pNew->a[pNew->nExpr-1].zName = a[k].zName; |
| 131956 | | - pNew->a[pNew->nExpr-1].zSpan = a[k].zSpan; |
| 131957 | | - a[k].zName = 0; |
| 131958 | | - a[k].zSpan = 0; |
| 132693 | + pNew->a[pNew->nExpr-1].zEName = a[k].zEName; |
| 132694 | + pNew->a[pNew->nExpr-1].eEName = a[k].eEName; |
| 132695 | + a[k].zEName = 0; |
| 131959 | 132696 | } |
| 131960 | 132697 | a[k].pExpr = 0; |
| 131961 | 132698 | }else{ |
| 131962 | 132699 | /* This expression is a "*" or a "TABLE.*" and needs to be |
| 131963 | 132700 | ** expanded. */ |
| | @@ -131992,11 +132729,11 @@ |
| 131992 | 132729 | char *zToFree; /* Malloced string that needs to be freed */ |
| 131993 | 132730 | Token sColname; /* Computed column name as a token */ |
| 131994 | 132731 | |
| 131995 | 132732 | assert( zName ); |
| 131996 | 132733 | if( zTName && pSub |
| 131997 | | - && sqlite3MatchSpanName(pSub->pEList->a[j].zSpan, 0, zTName, 0)==0 |
| 132734 | + && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0 |
| 131998 | 132735 | ){ |
| 131999 | 132736 | continue; |
| 132000 | 132737 | } |
| 132001 | 132738 | |
| 132002 | 132739 | /* If a column is marked as 'hidden', omit it from the expanded |
| | @@ -132010,11 +132747,11 @@ |
| 132010 | 132747 | } |
| 132011 | 132748 | tableSeen = 1; |
| 132012 | 132749 | |
| 132013 | 132750 | if( i>0 && zTName==0 ){ |
| 132014 | 132751 | if( (pFrom->fg.jointype & JT_NATURAL)!=0 |
| 132015 | | - && tableAndColumnIndex(pTabList, i, zName, 0, 0) |
| 132752 | + && tableAndColumnIndex(pTabList, i, zName, 0, 0, 1) |
| 132016 | 132753 | ){ |
| 132017 | 132754 | /* In a NATURAL join, omit the join columns from the |
| 132018 | 132755 | ** table to the right of the join */ |
| 132019 | 132756 | continue; |
| 132020 | 132757 | } |
| | @@ -132045,19 +132782,20 @@ |
| 132045 | 132782 | pNew = sqlite3ExprListAppend(pParse, pNew, pExpr); |
| 132046 | 132783 | sqlite3TokenInit(&sColname, zColname); |
| 132047 | 132784 | sqlite3ExprListSetName(pParse, pNew, &sColname, 0); |
| 132048 | 132785 | if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){ |
| 132049 | 132786 | struct ExprList_item *pX = &pNew->a[pNew->nExpr-1]; |
| 132787 | + sqlite3DbFree(db, pX->zEName); |
| 132050 | 132788 | if( pSub ){ |
| 132051 | | - pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan); |
| 132052 | | - testcase( pX->zSpan==0 ); |
| 132789 | + pX->zEName = sqlite3DbStrDup(db, pSub->pEList->a[j].zEName); |
| 132790 | + testcase( pX->zEName==0 ); |
| 132053 | 132791 | }else{ |
| 132054 | | - pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s", |
| 132792 | + pX->zEName = sqlite3MPrintf(db, "%s.%s.%s", |
| 132055 | 132793 | zSchemaName, zTabName, zColname); |
| 132056 | | - testcase( pX->zSpan==0 ); |
| 132794 | + testcase( pX->zEName==0 ); |
| 132057 | 132795 | } |
| 132058 | | - pX->bSpanIsTab = 1; |
| 132796 | + pX->eEName = ENAME_TAB; |
| 132059 | 132797 | } |
| 132060 | 132798 | sqlite3DbFree(db, zToFree); |
| 132061 | 132799 | } |
| 132062 | 132800 | } |
| 132063 | 132801 | if( !tableSeen ){ |
| | @@ -133022,10 +133760,11 @@ |
| 133022 | 133760 | && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0 |
| 133023 | 133761 | && p->pWin==0 |
| 133024 | 133762 | ){ |
| 133025 | 133763 | p->selFlags &= ~SF_Distinct; |
| 133026 | 133764 | pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0); |
| 133765 | + p->selFlags |= SF_Aggregate; |
| 133027 | 133766 | /* Notice that even thought SF_Distinct has been cleared from p->selFlags, |
| 133028 | 133767 | ** the sDistinct.isTnct is still set. Hence, isTnct represents the |
| 133029 | 133768 | ** original setting of the SF_Distinct flag, not the current setting */ |
| 133030 | 133769 | assert( sDistinct.isTnct ); |
| 133031 | 133770 | |
| | @@ -133096,11 +133835,11 @@ |
| 133096 | 133835 | u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0) |
| 133097 | 133836 | | (p->selFlags & SF_FixedLimit); |
| 133098 | 133837 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 133099 | 133838 | Window *pWin = p->pWin; /* Master window object (or NULL) */ |
| 133100 | 133839 | if( pWin ){ |
| 133101 | | - sqlite3WindowCodeInit(pParse, pWin); |
| 133840 | + sqlite3WindowCodeInit(pParse, p); |
| 133102 | 133841 | } |
| 133103 | 133842 | #endif |
| 133104 | 133843 | assert( WHERE_USE_LIMIT==SF_FixedLimit ); |
| 133105 | 133844 | |
| 133106 | 133845 | |
| | @@ -134568,11 +135307,11 @@ |
| 134568 | 135307 | */ |
| 134569 | 135308 | static int checkColumnOverlap(IdList *pIdList, ExprList *pEList){ |
| 134570 | 135309 | int e; |
| 134571 | 135310 | if( pIdList==0 || NEVER(pEList==0) ) return 1; |
| 134572 | 135311 | for(e=0; e<pEList->nExpr; e++){ |
| 134573 | | - if( sqlite3IdListIndex(pIdList, pEList->a[e].zName)>=0 ) return 1; |
| 135312 | + if( sqlite3IdListIndex(pIdList, pEList->a[e].zEName)>=0 ) return 1; |
| 134574 | 135313 | } |
| 134575 | 135314 | return 0; |
| 134576 | 135315 | } |
| 134577 | 135316 | |
| 134578 | 135317 | /* |
| | @@ -135272,10 +136011,11 @@ |
| 135272 | 136011 | int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */ |
| 135273 | 136012 | int addrOpen = 0; /* Address of OP_OpenEphemeral */ |
| 135274 | 136013 | int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */ |
| 135275 | 136014 | i16 nPk = 0; /* Number of components of the PRIMARY KEY */ |
| 135276 | 136015 | int bReplace = 0; /* True if REPLACE conflict resolution might happen */ |
| 136016 | + int bFinishSeek = 1; /* The OP_FinishSeek opcode is needed */ |
| 135277 | 136017 | |
| 135278 | 136018 | /* Register Allocations */ |
| 135279 | 136019 | int regRowCount = 0; /* A count of rows changed */ |
| 135280 | 136020 | int regOldRowid = 0; /* The old rowid */ |
| 135281 | 136021 | int regNewRowid = 0; /* The new rowid */ |
| | @@ -135386,11 +136126,11 @@ |
| 135386 | 136126 | for(i=0; i<pChanges->nExpr; i++){ |
| 135387 | 136127 | if( sqlite3ResolveExprNames(&sNC, pChanges->a[i].pExpr) ){ |
| 135388 | 136128 | goto update_cleanup; |
| 135389 | 136129 | } |
| 135390 | 136130 | for(j=0; j<pTab->nCol; j++){ |
| 135391 | | - if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zName)==0 ){ |
| 136131 | + if( sqlite3StrICmp(pTab->aCol[j].zName, pChanges->a[i].zEName)==0 ){ |
| 135392 | 136132 | if( j==pTab->iPKey ){ |
| 135393 | 136133 | chngRowid = 1; |
| 135394 | 136134 | pRowidExpr = pChanges->a[i].pExpr; |
| 135395 | 136135 | }else if( pPk && (pTab->aCol[j].colFlags & COLFLAG_PRIMKEY)!=0 ){ |
| 135396 | 136136 | chngPk = 1; |
| | @@ -135408,16 +136148,16 @@ |
| 135408 | 136148 | aXRef[j] = i; |
| 135409 | 136149 | break; |
| 135410 | 136150 | } |
| 135411 | 136151 | } |
| 135412 | 136152 | if( j>=pTab->nCol ){ |
| 135413 | | - if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zName) ){ |
| 136153 | + if( pPk==0 && sqlite3IsRowid(pChanges->a[i].zEName) ){ |
| 135414 | 136154 | j = -1; |
| 135415 | 136155 | chngRowid = 1; |
| 135416 | 136156 | pRowidExpr = pChanges->a[i].pExpr; |
| 135417 | 136157 | }else{ |
| 135418 | | - sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zName); |
| 136158 | + sqlite3ErrorMsg(pParse, "no such column: %s", pChanges->a[i].zEName); |
| 135419 | 136159 | pParse->checkSchema = 1; |
| 135420 | 136160 | goto update_cleanup; |
| 135421 | 136161 | } |
| 135422 | 136162 | } |
| 135423 | 136163 | #ifndef SQLITE_OMIT_AUTHORIZATION |
| | @@ -135605,10 +136345,11 @@ |
| 135605 | 136345 | ** row(s) to be updated. |
| 135606 | 136346 | */ |
| 135607 | 136347 | pWInfo = 0; |
| 135608 | 136348 | eOnePass = ONEPASS_SINGLE; |
| 135609 | 136349 | sqlite3ExprIfFalse(pParse, pWhere, labelBreak, SQLITE_JUMPIFNULL); |
| 136350 | + bFinishSeek = 0; |
| 135610 | 136351 | }else{ |
| 135611 | 136352 | /* Begin the database scan. |
| 135612 | 136353 | ** |
| 135613 | 136354 | ** Do not consider a single-pass strategy for a multi-row update if |
| 135614 | 136355 | ** there are any triggers or foreign keys to process, or rows may |
| | @@ -135631,10 +136372,11 @@ |
| 135631 | 136372 | ** |
| 135632 | 136373 | ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI |
| 135633 | 136374 | ** strategy that uses an index for which one or more columns are being |
| 135634 | 136375 | ** updated. */ |
| 135635 | 136376 | eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); |
| 136377 | + bFinishSeek = sqlite3WhereUsesDeferredSeek(pWInfo); |
| 135636 | 136378 | if( eOnePass!=ONEPASS_SINGLE ){ |
| 135637 | 136379 | sqlite3MultiWrite(pParse); |
| 135638 | 136380 | if( eOnePass==ONEPASS_MULTI ){ |
| 135639 | 136381 | int iCur = aiCurOnePass[1]; |
| 135640 | 136382 | if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){ |
| | @@ -135794,10 +136536,11 @@ |
| 135794 | 136536 | ** a new.* reference in a trigger program. |
| 135795 | 136537 | */ |
| 135796 | 136538 | testcase( i==31 ); |
| 135797 | 136539 | testcase( i==32 ); |
| 135798 | 136540 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, k); |
| 136541 | + bFinishSeek = 0; |
| 135799 | 136542 | }else{ |
| 135800 | 136543 | sqlite3VdbeAddOp2(v, OP_Null, 0, k); |
| 135801 | 136544 | } |
| 135802 | 136545 | } |
| 135803 | 136546 | } |
| | @@ -135880,10 +136623,19 @@ |
| 135880 | 136623 | sqlite3FkCheck(pParse, pTab, regOldRowid, 0, aXRef, chngKey); |
| 135881 | 136624 | } |
| 135882 | 136625 | |
| 135883 | 136626 | /* Delete the index entries associated with the current record. */ |
| 135884 | 136627 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx, -1); |
| 136628 | + |
| 136629 | + /* We must run the OP_FinishSeek opcode to resolve a prior |
| 136630 | + ** OP_DeferredSeek if there is any possibility that there have been |
| 136631 | + ** no OP_Column opcodes since the OP_DeferredSeek was issued. But |
| 136632 | + ** we want to avoid the OP_FinishSeek if possible, as running it |
| 136633 | + ** costs CPU cycles. */ |
| 136634 | + if( bFinishSeek ){ |
| 136635 | + sqlite3VdbeAddOp1(v, OP_FinishSeek, iDataCur); |
| 136636 | + } |
| 135885 | 136637 | |
| 135886 | 136638 | /* If changing the rowid value, or if there are foreign key constraints |
| 135887 | 136639 | ** to process, delete the old record. Otherwise, add a noop OP_Delete |
| 135888 | 136640 | ** to invoke the pre-update hook. |
| 135889 | 136641 | ** |
| | @@ -136378,10 +137130,11 @@ |
| 136378 | 137130 | sqlite3VdbeVerifyAbortable(v, OE_Abort); |
| 136379 | 137131 | i = sqlite3VdbeAddOp4Int(v, OP_Found, iDataCur, 0, iPk, nPk); |
| 136380 | 137132 | VdbeCoverage(v); |
| 136381 | 137133 | sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_CORRUPT, OE_Abort, 0, |
| 136382 | 137134 | "corrupt database", P4_STATIC); |
| 137135 | + sqlite3MayAbort(pParse); |
| 136383 | 137136 | sqlite3VdbeJumpHere(v, i); |
| 136384 | 137137 | } |
| 136385 | 137138 | } |
| 136386 | 137139 | /* pUpsert does not own pUpsertSrc - the outer INSERT statement does. So |
| 136387 | 137140 | ** we have to make a copy before passing it down into sqlite3Update() */ |
| | @@ -137408,10 +138161,11 @@ |
| 137408 | 138161 | sqlite3DbFree(db, zModuleName); |
| 137409 | 138162 | return SQLITE_NOMEM_BKPT; |
| 137410 | 138163 | } |
| 137411 | 138164 | pVTable->db = db; |
| 137412 | 138165 | pVTable->pMod = pMod; |
| 138166 | + pVTable->eVtabRisk = SQLITE_VTABRISK_Normal; |
| 137413 | 138167 | |
| 137414 | 138168 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 137415 | 138169 | pTab->azModuleArg[1] = db->aDb[iDb].zDbSName; |
| 137416 | 138170 | |
| 137417 | 138171 | /* Invoke the virtual table constructor */ |
| | @@ -138097,32 +138851,42 @@ |
| 138097 | 138851 | ** of the virtual table being implemented. |
| 138098 | 138852 | */ |
| 138099 | 138853 | SQLITE_API int sqlite3_vtab_config(sqlite3 *db, int op, ...){ |
| 138100 | 138854 | va_list ap; |
| 138101 | 138855 | int rc = SQLITE_OK; |
| 138856 | + VtabCtx *p; |
| 138102 | 138857 | |
| 138103 | 138858 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 138104 | 138859 | if( !sqlite3SafetyCheckOk(db) ) return SQLITE_MISUSE_BKPT; |
| 138105 | 138860 | #endif |
| 138106 | 138861 | sqlite3_mutex_enter(db->mutex); |
| 138107 | | - va_start(ap, op); |
| 138108 | | - switch( op ){ |
| 138109 | | - case SQLITE_VTAB_CONSTRAINT_SUPPORT: { |
| 138110 | | - VtabCtx *p = db->pVtabCtx; |
| 138111 | | - if( !p ){ |
| 138112 | | - rc = SQLITE_MISUSE_BKPT; |
| 138113 | | - }else{ |
| 138114 | | - assert( p->pTab==0 || IsVirtual(p->pTab) ); |
| 138862 | + p = db->pVtabCtx; |
| 138863 | + if( !p ){ |
| 138864 | + rc = SQLITE_MISUSE_BKPT; |
| 138865 | + }else{ |
| 138866 | + assert( p->pTab==0 || IsVirtual(p->pTab) ); |
| 138867 | + va_start(ap, op); |
| 138868 | + switch( op ){ |
| 138869 | + case SQLITE_VTAB_CONSTRAINT_SUPPORT: { |
| 138115 | 138870 | p->pVTable->bConstraint = (u8)va_arg(ap, int); |
| 138116 | | - } |
| 138117 | | - break; |
| 138118 | | - } |
| 138119 | | - default: |
| 138120 | | - rc = SQLITE_MISUSE_BKPT; |
| 138121 | | - break; |
| 138122 | | - } |
| 138123 | | - va_end(ap); |
| 138871 | + break; |
| 138872 | + } |
| 138873 | + case SQLITE_VTAB_INNOCUOUS: { |
| 138874 | + p->pVTable->eVtabRisk = SQLITE_VTABRISK_Low; |
| 138875 | + break; |
| 138876 | + } |
| 138877 | + case SQLITE_VTAB_DIRECTONLY: { |
| 138878 | + p->pVTable->eVtabRisk = SQLITE_VTABRISK_High; |
| 138879 | + break; |
| 138880 | + } |
| 138881 | + default: { |
| 138882 | + rc = SQLITE_MISUSE_BKPT; |
| 138883 | + break; |
| 138884 | + } |
| 138885 | + } |
| 138886 | + va_end(ap); |
| 138887 | + } |
| 138124 | 138888 | |
| 138125 | 138889 | if( rc!=SQLITE_OK ) sqlite3Error(db, rc); |
| 138126 | 138890 | sqlite3_mutex_leave(db->mutex); |
| 138127 | 138891 | return rc; |
| 138128 | 138892 | } |
| | @@ -138586,10 +139350,24 @@ |
| 138586 | 139350 | #endif |
| 138587 | 139351 | #ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR |
| 138588 | 139352 | # define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000 |
| 138589 | 139353 | #endif |
| 138590 | 139354 | |
| 139355 | +/* |
| 139356 | +** Each instance of this object records a change to a single node |
| 139357 | +** in an expression tree to cause that node to point to a column |
| 139358 | +** of an index rather than an expression or a virtual column. All |
| 139359 | +** such transformations need to be undone at the end of WHERE clause |
| 139360 | +** processing. |
| 139361 | +*/ |
| 139362 | +typedef struct WhereExprMod WhereExprMod; |
| 139363 | +struct WhereExprMod { |
| 139364 | + WhereExprMod *pNext; /* Next translation on a list of them all */ |
| 139365 | + Expr *pExpr; /* The Expr node that was transformed */ |
| 139366 | + Expr orig; /* Original value of the Expr node */ |
| 139367 | +}; |
| 139368 | + |
| 138591 | 139369 | /* |
| 138592 | 139370 | ** The WHERE clause processing routine has two halves. The |
| 138593 | 139371 | ** first part does the start of the WHERE loop and the second |
| 138594 | 139372 | ** half does the tail of the WHERE loop. An instance of |
| 138595 | 139373 | ** this structure is returned by the first half and passed |
| | @@ -138602,27 +139380,29 @@ |
| 138602 | 139380 | Parse *pParse; /* Parsing and code generating context */ |
| 138603 | 139381 | SrcList *pTabList; /* List of tables in the join */ |
| 138604 | 139382 | ExprList *pOrderBy; /* The ORDER BY clause or NULL */ |
| 138605 | 139383 | ExprList *pResultSet; /* Result set of the query */ |
| 138606 | 139384 | Expr *pWhere; /* The complete WHERE clause */ |
| 138607 | | - LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */ |
| 138608 | 139385 | int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */ |
| 138609 | 139386 | int iContinue; /* Jump here to continue with next record */ |
| 138610 | 139387 | int iBreak; /* Jump here to break out of the loop */ |
| 138611 | 139388 | int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */ |
| 138612 | 139389 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| 139390 | + LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */ |
| 138613 | 139391 | u8 nLevel; /* Number of nested loop */ |
| 138614 | 139392 | i8 nOBSat; /* Number of ORDER BY terms satisfied by indices */ |
| 138615 | | - u8 sorted; /* True if really sorted (not just grouped) */ |
| 138616 | 139393 | u8 eOnePass; /* ONEPASS_OFF, or _SINGLE, or _MULTI */ |
| 138617 | | - u8 untestedTerms; /* Not all WHERE terms resolved by outer loop */ |
| 138618 | 139394 | u8 eDistinct; /* One of the WHERE_DISTINCT_* values */ |
| 138619 | | - u8 bOrderedInnerLoop; /* True if only the inner-most loop is ordered */ |
| 139395 | + unsigned bDeferredSeek :1; /* Uses OP_DeferredSeek */ |
| 139396 | + unsigned untestedTerms :1; /* Not all WHERE terms resolved by outer loop */ |
| 139397 | + unsigned bOrderedInnerLoop:1;/* True if only the inner-most loop is ordered */ |
| 139398 | + unsigned sorted :1; /* True if really sorted (not just grouped) */ |
| 139399 | + LogEst nRowOut; /* Estimated number of output rows */ |
| 138620 | 139400 | int iTop; /* The very beginning of the WHERE loop */ |
| 138621 | 139401 | WhereLoop *pLoops; /* List of all WhereLoop objects */ |
| 139402 | + WhereExprMod *pExprMods; /* Expression modifications */ |
| 138622 | 139403 | Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 138623 | | - LogEst nRowOut; /* Estimated number of output rows */ |
| 138624 | 139404 | WhereClause sWC; /* Decomposition of the WHERE clause */ |
| 138625 | 139405 | WhereMaskSet sMaskSet; /* Map cursor numbers to bitmasks */ |
| 138626 | 139406 | WhereLevel a[1]; /* Information about each nest loop in WHERE */ |
| 138627 | 139407 | }; |
| 138628 | 139408 | |
| | @@ -138632,10 +139412,12 @@ |
| 138632 | 139412 | ** where.c: |
| 138633 | 139413 | */ |
| 138634 | 139414 | SQLITE_PRIVATE Bitmask sqlite3WhereGetMask(WhereMaskSet*,int); |
| 138635 | 139415 | #ifdef WHERETRACE_ENABLED |
| 138636 | 139416 | SQLITE_PRIVATE void sqlite3WhereClausePrint(WhereClause *pWC); |
| 139417 | +SQLITE_PRIVATE void sqlite3WhereTermPrint(WhereTerm *pTerm, int iTerm); |
| 139418 | +SQLITE_PRIVATE void sqlite3WhereLoopPrint(WhereLoop *p, WhereClause *pWC); |
| 138637 | 139419 | #endif |
| 138638 | 139420 | SQLITE_PRIVATE WhereTerm *sqlite3WhereFindTerm( |
| 138639 | 139421 | WhereClause *pWC, /* The WHERE clause to be searched */ |
| 138640 | 139422 | int iCur, /* Cursor number of LHS */ |
| 138641 | 139423 | int iColumn, /* Column number of LHS */ |
| | @@ -139321,11 +140103,11 @@ |
| 139321 | 140103 | } |
| 139322 | 140104 | sqlite3VdbeAddOp1(v, OP_IsNull, iOut); VdbeCoverage(v); |
| 139323 | 140105 | if( i==iEq ){ |
| 139324 | 140106 | pIn->iCur = iTab; |
| 139325 | 140107 | pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next; |
| 139326 | | - if( iEq>0 && (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){ |
| 140108 | + if( iEq>0 ){ |
| 139327 | 140109 | pIn->iBase = iReg - i; |
| 139328 | 140110 | pIn->nPrefix = i; |
| 139329 | 140111 | pLoop->wsFlags |= WHERE_IN_EARLYOUT; |
| 139330 | 140112 | }else{ |
| 139331 | 140113 | pIn->nPrefix = 0; |
| | @@ -139773,10 +140555,11 @@ |
| 139773 | 140555 | Vdbe *v = pParse->pVdbe; /* Vdbe to generate code within */ |
| 139774 | 140556 | |
| 139775 | 140557 | assert( iIdxCur>0 ); |
| 139776 | 140558 | assert( pIdx->aiColumn[pIdx->nColumn-1]==-1 ); |
| 139777 | 140559 | |
| 140560 | + pWInfo->bDeferredSeek = 1; |
| 139778 | 140561 | sqlite3VdbeAddOp3(v, OP_DeferredSeek, iIdxCur, 0, iCur); |
| 139779 | 140562 | if( (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE) |
| 139780 | 140563 | && DbMaskAllZero(sqlite3ParseToplevel(pParse)->writeMask) |
| 139781 | 140564 | ){ |
| 139782 | 140565 | int i; |
| | @@ -139840,11 +140623,26 @@ |
| 139840 | 140623 | Expr *pIdxExpr; /* The index expression */ |
| 139841 | 140624 | int iTabCur; /* The cursor of the corresponding table */ |
| 139842 | 140625 | int iIdxCur; /* The cursor for the index */ |
| 139843 | 140626 | int iIdxCol; /* The column for the index */ |
| 139844 | 140627 | int iTabCol; /* The column for the table */ |
| 140628 | + WhereInfo *pWInfo; /* Complete WHERE clause information */ |
| 140629 | + sqlite3 *db; /* Database connection (for malloc()) */ |
| 139845 | 140630 | } IdxExprTrans; |
| 140631 | + |
| 140632 | +/* |
| 140633 | +** Preserve pExpr on the WhereETrans list of the WhereInfo. |
| 140634 | +*/ |
| 140635 | +static void preserveExpr(IdxExprTrans *pTrans, Expr *pExpr){ |
| 140636 | + WhereExprMod *pNew; |
| 140637 | + pNew = sqlite3DbMallocRaw(pTrans->db, sizeof(*pNew)); |
| 140638 | + if( pNew==0 ) return; |
| 140639 | + pNew->pNext = pTrans->pWInfo->pExprMods; |
| 140640 | + pTrans->pWInfo->pExprMods = pNew; |
| 140641 | + pNew->pExpr = pExpr; |
| 140642 | + memcpy(&pNew->orig, pExpr, sizeof(*pExpr)); |
| 140643 | +} |
| 139846 | 140644 | |
| 139847 | 140645 | /* The walker node callback used to transform matching expressions into |
| 139848 | 140646 | ** a reference to an index column for an index on an expression. |
| 139849 | 140647 | ** |
| 139850 | 140648 | ** If pExpr matches, then transform it into a reference to the index column |
| | @@ -139851,10 +140649,11 @@ |
| 139851 | 140649 | ** that contains the value of pExpr. |
| 139852 | 140650 | */ |
| 139853 | 140651 | static int whereIndexExprTransNode(Walker *p, Expr *pExpr){ |
| 139854 | 140652 | IdxExprTrans *pX = p->u.pIdxTrans; |
| 139855 | 140653 | if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){ |
| 140654 | + preserveExpr(pX, pExpr); |
| 139856 | 140655 | pExpr->affExpr = sqlite3ExprAffinity(pExpr); |
| 139857 | 140656 | pExpr->op = TK_COLUMN; |
| 139858 | 140657 | pExpr->iTable = pX->iIdxCur; |
| 139859 | 140658 | pExpr->iColumn = pX->iIdxCol; |
| 139860 | 140659 | pExpr->y.pTab = 0; |
| | @@ -139874,10 +140673,11 @@ |
| 139874 | 140673 | static int whereIndexExprTransColumn(Walker *p, Expr *pExpr){ |
| 139875 | 140674 | if( pExpr->op==TK_COLUMN ){ |
| 139876 | 140675 | IdxExprTrans *pX = p->u.pIdxTrans; |
| 139877 | 140676 | if( pExpr->iTable==pX->iTabCur && pExpr->iColumn==pX->iTabCol ){ |
| 139878 | 140677 | assert( pExpr->y.pTab!=0 ); |
| 140678 | + preserveExpr(pX, pExpr); |
| 139879 | 140679 | pExpr->affExpr = sqlite3TableColumnAffinity(pExpr->y.pTab,pExpr->iColumn); |
| 139880 | 140680 | pExpr->iTable = pX->iIdxCur; |
| 139881 | 140681 | pExpr->iColumn = pX->iIdxCol; |
| 139882 | 140682 | pExpr->y.pTab = 0; |
| 139883 | 140683 | } |
| | @@ -139915,10 +140715,12 @@ |
| 139915 | 140715 | pTab = pIdx->pTable; |
| 139916 | 140716 | memset(&w, 0, sizeof(w)); |
| 139917 | 140717 | w.u.pIdxTrans = &x; |
| 139918 | 140718 | x.iTabCur = iTabCur; |
| 139919 | 140719 | x.iIdxCur = iIdxCur; |
| 140720 | + x.pWInfo = pWInfo; |
| 140721 | + x.db = pWInfo->pParse->db; |
| 139920 | 140722 | for(iIdxCol=0; iIdxCol<pIdx->nColumn; iIdxCol++){ |
| 139921 | 140723 | i16 iRef = pIdx->aiColumn[iIdxCol]; |
| 139922 | 140724 | if( iRef==XN_EXPR ){ |
| 139923 | 140725 | assert( aColExpr->a[iIdxCol].pExpr!=0 ); |
| 139924 | 140726 | x.pIdxExpr = aColExpr->a[iIdxCol].pExpr; |
| | @@ -140012,10 +140814,25 @@ |
| 140012 | 140814 | pTabItem = &pWInfo->pTabList->a[pLevel->iFrom]; |
| 140013 | 140815 | iCur = pTabItem->iCursor; |
| 140014 | 140816 | pLevel->notReady = notReady & ~sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); |
| 140015 | 140817 | bRev = (pWInfo->revMask>>iLevel)&1; |
| 140016 | 140818 | VdbeModuleComment((v, "Begin WHERE-loop%d: %s",iLevel,pTabItem->pTab->zName)); |
| 140819 | +#if WHERETRACE_ENABLED /* 0x20800 */ |
| 140820 | + if( sqlite3WhereTrace & 0x800 ){ |
| 140821 | + sqlite3DebugPrintf("Coding level %d of %d: notReady=%llx iFrom=%d\n", |
| 140822 | + iLevel, pWInfo->nLevel, (u64)notReady, pLevel->iFrom); |
| 140823 | + sqlite3WhereLoopPrint(pLoop, pWC); |
| 140824 | + } |
| 140825 | + if( sqlite3WhereTrace & 0x20000 ){ |
| 140826 | + if( iLevel==0 ){ |
| 140827 | + sqlite3DebugPrintf("WHERE clause being coded:\n"); |
| 140828 | + sqlite3TreeViewExpr(0, pWInfo->pWhere, 0); |
| 140829 | + } |
| 140830 | + sqlite3DebugPrintf("All WHERE-clause terms before coding:\n"); |
| 140831 | + sqlite3WhereClausePrint(pWC); |
| 140832 | + } |
| 140833 | +#endif |
| 140017 | 140834 | |
| 140018 | 140835 | /* Create labels for the "break" and "continue" instructions |
| 140019 | 140836 | ** for the current loop. Jump to addrBrk to break out of a loop. |
| 140020 | 140837 | ** Jump to cont to go immediately to the next iteration of the |
| 140021 | 140838 | ** loop. |
| | @@ -140398,11 +141215,11 @@ |
| 140398 | 141215 | if( (pLoop->wsFlags & (WHERE_TOP_LIMIT|WHERE_BTM_LIMIT))==0 |
| 140399 | 141216 | && (pLoop->wsFlags & WHERE_BIGNULL_SORT)!=0 |
| 140400 | 141217 | ){ |
| 140401 | 141218 | assert( bSeekPastNull==0 && nExtraReg==0 && nBtm==0 && nTop==0 ); |
| 140402 | 141219 | assert( pRangeEnd==0 && pRangeStart==0 ); |
| 140403 | | - assert( pLoop->nSkip==0 ); |
| 141220 | + testcase( pLoop->nSkip>0 ); |
| 140404 | 141221 | nExtraReg = 1; |
| 140405 | 141222 | bSeekPastNull = 1; |
| 140406 | 141223 | pLevel->regBignull = regBignull = ++pParse->nMem; |
| 140407 | 141224 | pLevel->addrBignull = sqlite3VdbeMakeLabel(pParse); |
| 140408 | 141225 | } |
| | @@ -141067,10 +141884,14 @@ |
| 141067 | 141884 | #ifdef WHERETRACE_ENABLED /* 0xffff */ |
| 141068 | 141885 | if( sqlite3WhereTrace ){ |
| 141069 | 141886 | VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d", |
| 141070 | 141887 | pWC->nTerm-j, pTerm, iLoop)); |
| 141071 | 141888 | } |
| 141889 | + if( sqlite3WhereTrace & 0x800 ){ |
| 141890 | + sqlite3DebugPrintf("Coding auxiliary constraint:\n"); |
| 141891 | + sqlite3WhereTermPrint(pTerm, pWC->nTerm-j); |
| 141892 | + } |
| 141072 | 141893 | #endif |
| 141073 | 141894 | sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL); |
| 141074 | 141895 | if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr); |
| 141075 | 141896 | pTerm->wtFlags |= TERM_CODED; |
| 141076 | 141897 | } |
| | @@ -141090,12 +141911,18 @@ |
| 141090 | 141911 | WhereTerm *pAlt; |
| 141091 | 141912 | if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue; |
| 141092 | 141913 | if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) continue; |
| 141093 | 141914 | if( (pTerm->eOperator & WO_EQUIV)==0 ) continue; |
| 141094 | 141915 | if( pTerm->leftCursor!=iCur ) continue; |
| 141095 | | - if( pLevel->iLeftJoin ) continue; |
| 141916 | + if( pTabItem->fg.jointype & JT_LEFT ) continue; |
| 141096 | 141917 | pE = pTerm->pExpr; |
| 141918 | +#ifdef WHERETRACE_ENABLED /* 0x800 */ |
| 141919 | + if( sqlite3WhereTrace & 0x800 ){ |
| 141920 | + sqlite3DebugPrintf("Coding transitive constraint:\n"); |
| 141921 | + sqlite3WhereTermPrint(pTerm, pWC->nTerm-j); |
| 141922 | + } |
| 141923 | +#endif |
| 141097 | 141924 | assert( !ExprHasProperty(pE, EP_FromJoin) ); |
| 141098 | 141925 | assert( (pTerm->prereqRight & pLevel->notReady)!=0 ); |
| 141099 | 141926 | pAlt = sqlite3WhereFindTerm(pWC, iCur, pTerm->u.leftColumn, notReady, |
| 141100 | 141927 | WO_EQ|WO_IN|WO_IS, 0); |
| 141101 | 141928 | if( pAlt==0 ) continue; |
| | @@ -141134,10 +141961,21 @@ |
| 141134 | 141961 | sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL); |
| 141135 | 141962 | pTerm->wtFlags |= TERM_CODED; |
| 141136 | 141963 | } |
| 141137 | 141964 | } |
| 141138 | 141965 | |
| 141966 | +#if WHERETRACE_ENABLED /* 0x20800 */ |
| 141967 | + if( sqlite3WhereTrace & 0x20000 ){ |
| 141968 | + sqlite3DebugPrintf("All WHERE-clause terms after coding level %d:\n", |
| 141969 | + iLevel); |
| 141970 | + sqlite3WhereClausePrint(pWC); |
| 141971 | + } |
| 141972 | + if( sqlite3WhereTrace & 0x800 ){ |
| 141973 | + sqlite3DebugPrintf("End Coding level %d: notReady=%llx\n", |
| 141974 | + iLevel, (u64)pLevel->notReady); |
| 141975 | + } |
| 141976 | +#endif |
| 141139 | 141977 | return pLevel->notReady; |
| 141140 | 141978 | } |
| 141141 | 141979 | |
| 141142 | 141980 | /************** End of wherecode.c *******************************************/ |
| 141143 | 141981 | /************** Begin file whereexpr.c ***************************************/ |
| | @@ -142872,11 +143710,11 @@ |
| 142872 | 143710 | return pWInfo->iBreak; |
| 142873 | 143711 | } |
| 142874 | 143712 | |
| 142875 | 143713 | /* |
| 142876 | 143714 | ** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to |
| 142877 | | -** operate directly on the rowis returned by a WHERE clause. Return |
| 143715 | +** operate directly on the rowids returned by a WHERE clause. Return |
| 142878 | 143716 | ** ONEPASS_SINGLE (1) if the statement can operation directly because only |
| 142879 | 143717 | ** a single row is to be changed. Return ONEPASS_MULTI (2) if the one-pass |
| 142880 | 143718 | ** optimization can be used on multiple |
| 142881 | 143719 | ** |
| 142882 | 143720 | ** If the ONEPASS optimization is used (if this routine returns true) |
| | @@ -142898,10 +143736,18 @@ |
| 142898 | 143736 | aiCur[0], aiCur[1]); |
| 142899 | 143737 | } |
| 142900 | 143738 | #endif |
| 142901 | 143739 | return pWInfo->eOnePass; |
| 142902 | 143740 | } |
| 143741 | + |
| 143742 | +/* |
| 143743 | +** Return TRUE if the WHERE loop uses the OP_DeferredSeek opcode to move |
| 143744 | +** the data cursor to the row selected by the index cursor. |
| 143745 | +*/ |
| 143746 | +SQLITE_PRIVATE int sqlite3WhereUsesDeferredSeek(WhereInfo *pWInfo){ |
| 143747 | + return pWInfo->bDeferredSeek; |
| 143748 | +} |
| 142903 | 143749 | |
| 142904 | 143750 | /* |
| 142905 | 143751 | ** Move the content of pSrc into pDest |
| 142906 | 143752 | */ |
| 142907 | 143753 | static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc){ |
| | @@ -143357,11 +144203,11 @@ |
| 143357 | 144203 | ** structure. Used for testing and debugging only. If neither |
| 143358 | 144204 | ** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines |
| 143359 | 144205 | ** are no-ops. |
| 143360 | 144206 | */ |
| 143361 | 144207 | #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED) |
| 143362 | | -static void TRACE_IDX_INPUTS(sqlite3_index_info *p){ |
| 144208 | +static void whereTraceIndexInfoInputs(sqlite3_index_info *p){ |
| 143363 | 144209 | int i; |
| 143364 | 144210 | if( !sqlite3WhereTrace ) return; |
| 143365 | 144211 | for(i=0; i<p->nConstraint; i++){ |
| 143366 | 144212 | sqlite3DebugPrintf(" constraint[%d]: col=%d termid=%d op=%d usabled=%d\n", |
| 143367 | 144213 | i, |
| | @@ -143375,11 +144221,11 @@ |
| 143375 | 144221 | i, |
| 143376 | 144222 | p->aOrderBy[i].iColumn, |
| 143377 | 144223 | p->aOrderBy[i].desc); |
| 143378 | 144224 | } |
| 143379 | 144225 | } |
| 143380 | | -static void TRACE_IDX_OUTPUTS(sqlite3_index_info *p){ |
| 144226 | +static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){ |
| 143381 | 144227 | int i; |
| 143382 | 144228 | if( !sqlite3WhereTrace ) return; |
| 143383 | 144229 | for(i=0; i<p->nConstraint; i++){ |
| 143384 | 144230 | sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n", |
| 143385 | 144231 | i, |
| | @@ -143391,12 +144237,12 @@ |
| 143391 | 144237 | sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed); |
| 143392 | 144238 | sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost); |
| 143393 | 144239 | sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows); |
| 143394 | 144240 | } |
| 143395 | 144241 | #else |
| 143396 | | -#define TRACE_IDX_INPUTS(A) |
| 143397 | | -#define TRACE_IDX_OUTPUTS(A) |
| 144242 | +#define whereTraceIndexInfoInputs(A) |
| 144243 | +#define whereTraceIndexInfoOutputs(A) |
| 143398 | 144244 | #endif |
| 143399 | 144245 | |
| 143400 | 144246 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 143401 | 144247 | /* |
| 143402 | 144248 | ** Return TRUE if the WHERE clause term pTerm is of a form where it |
| | @@ -143622,12 +144468,12 @@ |
| 143622 | 144468 | pTabItem->regResult, pLevel->iIdxCur); |
| 143623 | 144469 | sqlite3VdbeGoto(v, addrTop); |
| 143624 | 144470 | pTabItem->fg.viaCoroutine = 0; |
| 143625 | 144471 | }else{ |
| 143626 | 144472 | sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v); |
| 144473 | + sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); |
| 143627 | 144474 | } |
| 143628 | | - sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); |
| 143629 | 144475 | sqlite3VdbeJumpHere(v, addrTop); |
| 143630 | 144476 | sqlite3ReleaseTempReg(pParse, regRecord); |
| 143631 | 144477 | |
| 143632 | 144478 | /* Jump here when skipping the initialization */ |
| 143633 | 144479 | sqlite3VdbeJumpHere(v, addrInit); |
| | @@ -143702,27 +144548,18 @@ |
| 143702 | 144548 | + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) ); |
| 143703 | 144549 | if( pIdxInfo==0 ){ |
| 143704 | 144550 | sqlite3ErrorMsg(pParse, "out of memory"); |
| 143705 | 144551 | return 0; |
| 143706 | 144552 | } |
| 143707 | | - |
| 143708 | | - /* Initialize the structure. The sqlite3_index_info structure contains |
| 143709 | | - ** many fields that are declared "const" to prevent xBestIndex from |
| 143710 | | - ** changing them. We have to do some funky casting in order to |
| 143711 | | - ** initialize those fields. |
| 143712 | | - */ |
| 143713 | 144553 | pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1]; |
| 143714 | 144554 | pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1]; |
| 143715 | 144555 | pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm]; |
| 143716 | 144556 | pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy]; |
| 143717 | | - *(int*)&pIdxInfo->nConstraint = nTerm; |
| 143718 | | - *(int*)&pIdxInfo->nOrderBy = nOrderBy; |
| 143719 | | - *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons; |
| 143720 | | - *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy; |
| 143721 | | - *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage = |
| 143722 | | - pUsage; |
| 143723 | | - |
| 144557 | + pIdxInfo->nOrderBy = nOrderBy; |
| 144558 | + pIdxInfo->aConstraint = pIdxCons; |
| 144559 | + pIdxInfo->aOrderBy = pIdxOrderBy; |
| 144560 | + pIdxInfo->aConstraintUsage = pUsage; |
| 143724 | 144561 | pHidden->pWC = pWC; |
| 143725 | 144562 | pHidden->pParse = pParse; |
| 143726 | 144563 | for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){ |
| 143727 | 144564 | u16 op; |
| 143728 | 144565 | if( pTerm->leftCursor != pSrc->iCursor ) continue; |
| | @@ -143778,10 +144615,11 @@ |
| 143778 | 144615 | } |
| 143779 | 144616 | } |
| 143780 | 144617 | |
| 143781 | 144618 | j++; |
| 143782 | 144619 | } |
| 144620 | + pIdxInfo->nConstraint = j; |
| 143783 | 144621 | for(i=0; i<nOrderBy; i++){ |
| 143784 | 144622 | Expr *pExpr = pOrderBy->a[i].pExpr; |
| 143785 | 144623 | pIdxOrderBy[i].iColumn = pExpr->iColumn; |
| 143786 | 144624 | pIdxOrderBy[i].desc = pOrderBy->a[i].sortFlags & KEYINFO_ORDER_DESC; |
| 143787 | 144625 | } |
| | @@ -143808,13 +144646,13 @@ |
| 143808 | 144646 | */ |
| 143809 | 144647 | static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ |
| 143810 | 144648 | sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab; |
| 143811 | 144649 | int rc; |
| 143812 | 144650 | |
| 143813 | | - TRACE_IDX_INPUTS(p); |
| 144651 | + whereTraceIndexInfoInputs(p); |
| 143814 | 144652 | rc = pVtab->pModule->xBestIndex(pVtab, p); |
| 143815 | | - TRACE_IDX_OUTPUTS(p); |
| 144653 | + whereTraceIndexInfoOutputs(p); |
| 143816 | 144654 | |
| 143817 | 144655 | if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){ |
| 143818 | 144656 | if( rc==SQLITE_NOMEM ){ |
| 143819 | 144657 | sqlite3OomFault(pParse->db); |
| 143820 | 144658 | }else if( !pVtab->zErrMsg ){ |
| | @@ -144491,20 +145329,21 @@ |
| 144491 | 145329 | |
| 144492 | 145330 | #ifdef WHERETRACE_ENABLED |
| 144493 | 145331 | /* |
| 144494 | 145332 | ** Print the content of a WhereTerm object |
| 144495 | 145333 | */ |
| 144496 | | -static void whereTermPrint(WhereTerm *pTerm, int iTerm){ |
| 145334 | +SQLITE_PRIVATE void sqlite3WhereTermPrint(WhereTerm *pTerm, int iTerm){ |
| 144497 | 145335 | if( pTerm==0 ){ |
| 144498 | 145336 | sqlite3DebugPrintf("TERM-%-3d NULL\n", iTerm); |
| 144499 | 145337 | }else{ |
| 144500 | | - char zType[4]; |
| 145338 | + char zType[8]; |
| 144501 | 145339 | char zLeft[50]; |
| 144502 | | - memcpy(zType, "...", 4); |
| 145340 | + memcpy(zType, "....", 5); |
| 144503 | 145341 | if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V'; |
| 144504 | 145342 | if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E'; |
| 144505 | 145343 | if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L'; |
| 145344 | + if( pTerm->wtFlags & TERM_CODED ) zType[3] = 'C'; |
| 144506 | 145345 | if( pTerm->eOperator & WO_SINGLE ){ |
| 144507 | 145346 | sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}", |
| 144508 | 145347 | pTerm->leftCursor, pTerm->u.leftColumn); |
| 144509 | 145348 | }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){ |
| 144510 | 145349 | sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%lld", |
| | @@ -144511,13 +145350,18 @@ |
| 144511 | 145350 | pTerm->u.pOrInfo->indexable); |
| 144512 | 145351 | }else{ |
| 144513 | 145352 | sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor); |
| 144514 | 145353 | } |
| 144515 | 145354 | sqlite3DebugPrintf( |
| 144516 | | - "TERM-%-3d %p %s %-12s prob=%-3d op=0x%03x wtFlags=0x%04x", |
| 144517 | | - iTerm, pTerm, zType, zLeft, pTerm->truthProb, |
| 144518 | | - pTerm->eOperator, pTerm->wtFlags); |
| 145355 | + "TERM-%-3d %p %s %-12s op=%03x wtFlags=%04x", |
| 145356 | + iTerm, pTerm, zType, zLeft, pTerm->eOperator, pTerm->wtFlags); |
| 145357 | + /* The 0x10000 .wheretrace flag causes extra information to be |
| 145358 | + ** shown about each Term */ |
| 145359 | + if( sqlite3WhereTrace & 0x10000 ){ |
| 145360 | + sqlite3DebugPrintf(" prob=%-3d prereq=%llx,%llx", |
| 145361 | + pTerm->truthProb, (u64)pTerm->prereqAll, (u64)pTerm->prereqRight); |
| 145362 | + } |
| 144519 | 145363 | if( pTerm->iField ){ |
| 144520 | 145364 | sqlite3DebugPrintf(" iField=%d", pTerm->iField); |
| 144521 | 145365 | } |
| 144522 | 145366 | if( pTerm->iParent>=0 ){ |
| 144523 | 145367 | sqlite3DebugPrintf(" iParent=%d", pTerm->iParent); |
| | @@ -144533,20 +145377,20 @@ |
| 144533 | 145377 | ** Show the complete content of a WhereClause |
| 144534 | 145378 | */ |
| 144535 | 145379 | SQLITE_PRIVATE void sqlite3WhereClausePrint(WhereClause *pWC){ |
| 144536 | 145380 | int i; |
| 144537 | 145381 | for(i=0; i<pWC->nTerm; i++){ |
| 144538 | | - whereTermPrint(&pWC->a[i], i); |
| 145382 | + sqlite3WhereTermPrint(&pWC->a[i], i); |
| 144539 | 145383 | } |
| 144540 | 145384 | } |
| 144541 | 145385 | #endif |
| 144542 | 145386 | |
| 144543 | 145387 | #ifdef WHERETRACE_ENABLED |
| 144544 | 145388 | /* |
| 144545 | 145389 | ** Print a WhereLoop object for debugging purposes |
| 144546 | 145390 | */ |
| 144547 | | -static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){ |
| 145391 | +SQLITE_PRIVATE void sqlite3WhereLoopPrint(WhereLoop *p, WhereClause *pWC){ |
| 144548 | 145392 | WhereInfo *pWInfo = pWC->pWInfo; |
| 144549 | 145393 | int nb = 1+(pWInfo->pTabList->nSrc+3)/4; |
| 144550 | 145394 | struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab; |
| 144551 | 145395 | Table *pTab = pItem->pTab; |
| 144552 | 145396 | Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1; |
| | @@ -144584,11 +145428,11 @@ |
| 144584 | 145428 | } |
| 144585 | 145429 | sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut); |
| 144586 | 145430 | if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){ |
| 144587 | 145431 | int i; |
| 144588 | 145432 | for(i=0; i<p->nLTerm; i++){ |
| 144589 | | - whereTermPrint(p->aLTerm[i], i); |
| 145433 | + sqlite3WhereTermPrint(p->aLTerm[i], i); |
| 144590 | 145434 | } |
| 144591 | 145435 | } |
| 144592 | 145436 | } |
| 144593 | 145437 | #endif |
| 144594 | 145438 | |
| | @@ -144688,10 +145532,11 @@ |
| 144688 | 145532 | while( pWInfo->pLoops ){ |
| 144689 | 145533 | WhereLoop *p = pWInfo->pLoops; |
| 144690 | 145534 | pWInfo->pLoops = p->pNextLoop; |
| 144691 | 145535 | whereLoopDelete(db, p); |
| 144692 | 145536 | } |
| 145537 | + assert( pWInfo->pExprMods==0 ); |
| 144693 | 145538 | sqlite3DbFreeNN(db, pWInfo); |
| 144694 | 145539 | } |
| 144695 | 145540 | |
| 144696 | 145541 | /* |
| 144697 | 145542 | ** Return TRUE if all of the following are true: |
| | @@ -144888,10 +145733,12 @@ |
| 144888 | 145733 | WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n")); |
| 144889 | 145734 | if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0; |
| 144890 | 145735 | return SQLITE_DONE; |
| 144891 | 145736 | } |
| 144892 | 145737 | pBuilder->iPlanLimit--; |
| 145738 | + |
| 145739 | + whereLoopAdjustCost(pWInfo->pLoops, pTemplate); |
| 144893 | 145740 | |
| 144894 | 145741 | /* If pBuilder->pOrSet is defined, then only keep track of the costs |
| 144895 | 145742 | ** and prereqs. |
| 144896 | 145743 | */ |
| 144897 | 145744 | if( pBuilder->pOrSet!=0 ){ |
| | @@ -144903,29 +145750,28 @@ |
| 144903 | 145750 | whereOrInsert(pBuilder->pOrSet, pTemplate->prereq, pTemplate->rRun, |
| 144904 | 145751 | pTemplate->nOut); |
| 144905 | 145752 | #if WHERETRACE_ENABLED /* 0x8 */ |
| 144906 | 145753 | if( sqlite3WhereTrace & 0x8 ){ |
| 144907 | 145754 | sqlite3DebugPrintf(x?" or-%d: ":" or-X: ", n); |
| 144908 | | - whereLoopPrint(pTemplate, pBuilder->pWC); |
| 145755 | + sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC); |
| 144909 | 145756 | } |
| 144910 | 145757 | #endif |
| 144911 | 145758 | } |
| 144912 | 145759 | return SQLITE_OK; |
| 144913 | 145760 | } |
| 144914 | 145761 | |
| 144915 | 145762 | /* Look for an existing WhereLoop to replace with pTemplate |
| 144916 | 145763 | */ |
| 144917 | | - whereLoopAdjustCost(pWInfo->pLoops, pTemplate); |
| 144918 | 145764 | ppPrev = whereLoopFindLesser(&pWInfo->pLoops, pTemplate); |
| 144919 | 145765 | |
| 144920 | 145766 | if( ppPrev==0 ){ |
| 144921 | 145767 | /* There already exists a WhereLoop on the list that is better |
| 144922 | 145768 | ** than pTemplate, so just ignore pTemplate */ |
| 144923 | 145769 | #if WHERETRACE_ENABLED /* 0x8 */ |
| 144924 | 145770 | if( sqlite3WhereTrace & 0x8 ){ |
| 144925 | 145771 | sqlite3DebugPrintf(" skip: "); |
| 144926 | | - whereLoopPrint(pTemplate, pBuilder->pWC); |
| 145772 | + sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC); |
| 144927 | 145773 | } |
| 144928 | 145774 | #endif |
| 144929 | 145775 | return SQLITE_OK; |
| 144930 | 145776 | }else{ |
| 144931 | 145777 | p = *ppPrev; |
| | @@ -144937,16 +145783,16 @@ |
| 144937 | 145783 | */ |
| 144938 | 145784 | #if WHERETRACE_ENABLED /* 0x8 */ |
| 144939 | 145785 | if( sqlite3WhereTrace & 0x8 ){ |
| 144940 | 145786 | if( p!=0 ){ |
| 144941 | 145787 | sqlite3DebugPrintf("replace: "); |
| 144942 | | - whereLoopPrint(p, pBuilder->pWC); |
| 145788 | + sqlite3WhereLoopPrint(p, pBuilder->pWC); |
| 144943 | 145789 | sqlite3DebugPrintf(" with: "); |
| 144944 | 145790 | }else{ |
| 144945 | 145791 | sqlite3DebugPrintf(" add: "); |
| 144946 | 145792 | } |
| 144947 | | - whereLoopPrint(pTemplate, pBuilder->pWC); |
| 145793 | + sqlite3WhereLoopPrint(pTemplate, pBuilder->pWC); |
| 144948 | 145794 | } |
| 144949 | 145795 | #endif |
| 144950 | 145796 | if( p==0 ){ |
| 144951 | 145797 | /* Allocate a new WhereLoop to add to the end of the list */ |
| 144952 | 145798 | *ppPrev = p = sqlite3DbMallocRawNN(db, sizeof(WhereLoop)); |
| | @@ -144966,11 +145812,11 @@ |
| 144966 | 145812 | if( pToDel==0 ) break; |
| 144967 | 145813 | *ppTail = pToDel->pNextLoop; |
| 144968 | 145814 | #if WHERETRACE_ENABLED /* 0x8 */ |
| 144969 | 145815 | if( sqlite3WhereTrace & 0x8 ){ |
| 144970 | 145816 | sqlite3DebugPrintf(" delete: "); |
| 144971 | | - whereLoopPrint(pToDel, pBuilder->pWC); |
| 145817 | + sqlite3WhereLoopPrint(pToDel, pBuilder->pWC); |
| 144972 | 145818 | } |
| 144973 | 145819 | #endif |
| 144974 | 145820 | whereLoopDelete(db, pToDel); |
| 144975 | 145821 | } |
| 144976 | 145822 | } |
| | @@ -145175,12 +146021,13 @@ |
| 145175 | 146021 | LogEst rLogSize; /* Logarithm of table size */ |
| 145176 | 146022 | WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */ |
| 145177 | 146023 | |
| 145178 | 146024 | pNew = pBuilder->pNew; |
| 145179 | 146025 | if( db->mallocFailed ) return SQLITE_NOMEM_BKPT; |
| 145180 | | - WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d\n", |
| 145181 | | - pProbe->pTable->zName,pProbe->zName, pNew->u.btree.nEq)); |
| 146026 | + WHERETRACE(0x800, ("BEGIN %s.addBtreeIdx(%s), nEq=%d, nSkip=%d\n", |
| 146027 | + pProbe->pTable->zName,pProbe->zName, |
| 146028 | + pNew->u.btree.nEq, pNew->nSkip)); |
| 145182 | 146029 | |
| 145183 | 146030 | assert( (pNew->wsFlags & WHERE_VIRTUALTABLE)==0 ); |
| 145184 | 146031 | assert( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 ); |
| 145185 | 146032 | if( pNew->wsFlags & WHERE_BTM_LIMIT ){ |
| 145186 | 146033 | opMask = WO_LT|WO_LE; |
| | @@ -145473,10 +146320,11 @@ |
| 145473 | 146320 | ** On the other hand, the extra seeks could end up being significantly |
| 145474 | 146321 | ** more expensive. */ |
| 145475 | 146322 | assert( 42==sqlite3LogEst(18) ); |
| 145476 | 146323 | if( saved_nEq==saved_nSkip |
| 145477 | 146324 | && saved_nEq+1<pProbe->nKeyCol |
| 146325 | + && saved_nEq==pNew->nLTerm |
| 145478 | 146326 | && pProbe->noSkipScan==0 |
| 145479 | 146327 | && OptimizationEnabled(db, SQLITE_SkipScan) |
| 145480 | 146328 | && pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */ |
| 145481 | 146329 | && (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK |
| 145482 | 146330 | ){ |
| | @@ -146254,11 +147102,12 @@ |
| 146254 | 147102 | rc = whereLoopAddBtree(&sSubBuild, mPrereq); |
| 146255 | 147103 | } |
| 146256 | 147104 | if( rc==SQLITE_OK ){ |
| 146257 | 147105 | rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable); |
| 146258 | 147106 | } |
| 146259 | | - assert( rc==SQLITE_OK || sCur.n==0 ); |
| 147107 | + assert( rc==SQLITE_OK || rc==SQLITE_DONE || sCur.n==0 ); |
| 147108 | + testcase( rc==SQLITE_DONE ); |
| 146260 | 147109 | if( sCur.n==0 ){ |
| 146261 | 147110 | sSum.n = 0; |
| 146262 | 147111 | break; |
| 146263 | 147112 | }else if( once ){ |
| 146264 | 147113 | whereOrMove(&sSum, &sCur); |
| | @@ -147584,11 +148433,11 @@ |
| 147584 | 148433 | int i; |
| 147585 | 148434 | static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz" |
| 147586 | 148435 | "ABCDEFGHIJKLMNOPQRSTUVWYXZ"; |
| 147587 | 148436 | for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){ |
| 147588 | 148437 | p->cId = zLabel[i%(sizeof(zLabel)-1)]; |
| 147589 | | - whereLoopPrint(p, sWLB.pWC); |
| 148438 | + sqlite3WhereLoopPrint(p, sWLB.pWC); |
| 147590 | 148439 | } |
| 147591 | 148440 | } |
| 147592 | 148441 | #endif |
| 147593 | 148442 | |
| 147594 | 148443 | wherePathSolver(pWInfo, 0); |
| | @@ -147624,11 +148473,11 @@ |
| 147624 | 148473 | break; |
| 147625 | 148474 | } |
| 147626 | 148475 | } |
| 147627 | 148476 | sqlite3DebugPrintf("\n"); |
| 147628 | 148477 | for(ii=0; ii<pWInfo->nLevel; ii++){ |
| 147629 | | - whereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC); |
| 148478 | + sqlite3WhereLoopPrint(pWInfo->a[ii].pWLoop, sWLB.pWC); |
| 147630 | 148479 | } |
| 147631 | 148480 | } |
| 147632 | 148481 | #endif |
| 147633 | 148482 | |
| 147634 | 148483 | /* Attempt to omit tables from the join that do not affect the result. |
| | @@ -148016,14 +148865,30 @@ |
| 148016 | 148865 | for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){ |
| 148017 | 148866 | sqlite3VdbeJumpHere(v, pIn->addrInTop+1); |
| 148018 | 148867 | if( pIn->eEndLoopOp!=OP_Noop ){ |
| 148019 | 148868 | if( pIn->nPrefix ){ |
| 148020 | 148869 | assert( pLoop->wsFlags & WHERE_IN_EARLYOUT ); |
| 148021 | | - sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur, |
| 148022 | | - sqlite3VdbeCurrentAddr(v)+2, |
| 148023 | | - pIn->iBase, pIn->nPrefix); |
| 148024 | | - VdbeCoverage(v); |
| 148870 | + if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 ){ |
| 148871 | + sqlite3VdbeAddOp4Int(v, OP_IfNoHope, pLevel->iIdxCur, |
| 148872 | + sqlite3VdbeCurrentAddr(v)+2+(pLevel->iLeftJoin!=0), |
| 148873 | + pIn->iBase, pIn->nPrefix); |
| 148874 | + VdbeCoverage(v); |
| 148875 | + } |
| 148876 | + if( pLevel->iLeftJoin ){ |
| 148877 | + /* For LEFT JOIN queries, cursor pIn->iCur may not have been |
| 148878 | + ** opened yet. This occurs for WHERE clauses such as |
| 148879 | + ** "a = ? AND b IN (...)", where the index is on (a, b). If |
| 148880 | + ** the RHS of the (a=?) is NULL, then the "b IN (...)" may |
| 148881 | + ** never have been coded, but the body of the loop run to |
| 148882 | + ** return the null-row. So, if the cursor is not open yet, |
| 148883 | + ** jump over the OP_Next or OP_Prev instruction about to |
| 148884 | + ** be coded. */ |
| 148885 | + sqlite3VdbeAddOp2(v, OP_IfNotOpen, pIn->iCur, |
| 148886 | + sqlite3VdbeCurrentAddr(v) + 2 |
| 148887 | + ); |
| 148888 | + VdbeCoverage(v); |
| 148889 | + } |
| 148025 | 148890 | } |
| 148026 | 148891 | sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop); |
| 148027 | 148892 | VdbeCoverage(v); |
| 148028 | 148893 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Prev); |
| 148029 | 148894 | VdbeCoverageIf(v, pIn->eEndLoopOp==OP_Next); |
| | @@ -148183,10 +149048,18 @@ |
| 148183 | 149048 | #ifdef SQLITE_DEBUG |
| 148184 | 149049 | if( db->flags & SQLITE_VdbeAddopTrace ) printf("TRANSLATE complete\n"); |
| 148185 | 149050 | #endif |
| 148186 | 149051 | } |
| 148187 | 149052 | } |
| 149053 | + |
| 149054 | + /* Undo all Expr node modifications */ |
| 149055 | + while( pWInfo->pExprMods ){ |
| 149056 | + WhereExprMod *p = pWInfo->pExprMods; |
| 149057 | + pWInfo->pExprMods = p->pNext; |
| 149058 | + memcpy(p->pExpr, &p->orig, sizeof(p->orig)); |
| 149059 | + sqlite3DbFree(db, p); |
| 149060 | + } |
| 148188 | 149061 | |
| 148189 | 149062 | /* Final cleanup |
| 148190 | 149063 | */ |
| 148191 | 149064 | pParse->nQueryLoop = pWInfo->savedNQueryLoop; |
| 148192 | 149065 | whereInfoFree(db, pWInfo); |
| | @@ -148994,10 +149867,11 @@ |
| 148994 | 149867 | } |
| 148995 | 149868 | } |
| 148996 | 149869 | } |
| 148997 | 149870 | if( iCol<0 ){ |
| 148998 | 149871 | Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 149872 | + if( pDup && pDup->op==TK_AGG_FUNCTION ) pDup->op = TK_FUNCTION; |
| 148999 | 149873 | p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup); |
| 149000 | 149874 | } |
| 149001 | 149875 | if( p->pSub ){ |
| 149002 | 149876 | assert( ExprHasProperty(pExpr, EP_Static)==0 ); |
| 149003 | 149877 | ExprSetProperty(pExpr, EP_Static); |
| | @@ -149089,13 +149963,14 @@ |
| 149089 | 149963 | ){ |
| 149090 | 149964 | if( pAppend ){ |
| 149091 | 149965 | int i; |
| 149092 | 149966 | int nInit = pList ? pList->nExpr : 0; |
| 149093 | 149967 | for(i=0; i<pAppend->nExpr; i++){ |
| 149968 | + int iDummy; |
| 149094 | 149969 | Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0); |
| 149095 | 149970 | assert( pDup==0 || !ExprHasProperty(pDup, EP_MemToken) ); |
| 149096 | | - if( bIntToNull && pDup && pDup->op==TK_INTEGER ){ |
| 149971 | + if( bIntToNull && pDup && sqlite3ExprIsInteger(pDup, &iDummy) ){ |
| 149097 | 149972 | pDup->op = TK_NULL; |
| 149098 | 149973 | pDup->flags &= ~(EP_IntValue|EP_IsTrue|EP_IsFalse); |
| 149099 | 149974 | pDup->u.zToken = 0; |
| 149100 | 149975 | } |
| 149101 | 149976 | pList = sqlite3ExprListAppend(pParse, pList, pDup); |
| | @@ -149142,11 +150017,11 @@ |
| 149142 | 150017 | p->selFlags |= SF_WinRewrite; |
| 149143 | 150018 | |
| 149144 | 150019 | /* Create the ORDER BY clause for the sub-select. This is the concatenation |
| 149145 | 150020 | ** of the window PARTITION and ORDER BY clauses. Then, if this makes it |
| 149146 | 150021 | ** redundant, remove the ORDER BY from the parent SELECT. */ |
| 149147 | | - pSort = sqlite3ExprListDup(db, pMWin->pPartition, 0); |
| 150022 | + pSort = exprListAppendList(pParse, 0, pMWin->pPartition, 1); |
| 149148 | 150023 | pSort = exprListAppendList(pParse, pSort, pMWin->pOrderBy, 1); |
| 149149 | 150024 | if( pSort && p->pOrderBy && p->pOrderBy->nExpr<=pSort->nExpr ){ |
| 149150 | 150025 | int nSave = pSort->nExpr; |
| 149151 | 150026 | pSort->nExpr = p->pOrderBy->nExpr; |
| 149152 | 150027 | if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0 ){ |
| | @@ -149226,14 +150101,10 @@ |
| 149226 | 150101 | memcpy(pTab, pTab2, sizeof(Table)); |
| 149227 | 150102 | pTab->tabFlags |= TF_Ephemeral; |
| 149228 | 150103 | p->pSrc->a[0].pTab = pTab; |
| 149229 | 150104 | pTab = pTab2; |
| 149230 | 150105 | } |
| 149231 | | - sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, pSublist->nExpr); |
| 149232 | | - sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr); |
| 149233 | | - sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr); |
| 149234 | | - sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr); |
| 149235 | 150106 | }else{ |
| 149236 | 150107 | sqlite3SelectDelete(db, pSub); |
| 149237 | 150108 | } |
| 149238 | 150109 | if( db->mallocFailed ) rc = SQLITE_NOMEM; |
| 149239 | 150110 | sqlite3DbFree(db, pTab); |
| | @@ -149476,25 +150347,33 @@ |
| 149476 | 150347 | pWin->ppThis = &pSel->pWin; |
| 149477 | 150348 | } |
| 149478 | 150349 | } |
| 149479 | 150350 | |
| 149480 | 150351 | /* |
| 149481 | | -** Return 0 if the two window objects are identical, or non-zero otherwise. |
| 149482 | | -** Identical window objects can be processed in a single scan. |
| 150352 | +** Return 0 if the two window objects are identical, 1 if they are |
| 150353 | +** different, or 2 if it cannot be determined if the objects are identical |
| 150354 | +** or not. Identical window objects can be processed in a single scan. |
| 149483 | 150355 | */ |
| 149484 | 150356 | SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2, int bFilter){ |
| 150357 | + int res; |
| 149485 | 150358 | if( NEVER(p1==0) || NEVER(p2==0) ) return 1; |
| 149486 | 150359 | if( p1->eFrmType!=p2->eFrmType ) return 1; |
| 149487 | 150360 | if( p1->eStart!=p2->eStart ) return 1; |
| 149488 | 150361 | if( p1->eEnd!=p2->eEnd ) return 1; |
| 149489 | 150362 | if( p1->eExclude!=p2->eExclude ) return 1; |
| 149490 | 150363 | if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1; |
| 149491 | 150364 | if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1; |
| 149492 | | - if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1) ) return 1; |
| 149493 | | - if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1; |
| 150365 | + if( (res = sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1)) ){ |
| 150366 | + return res; |
| 150367 | + } |
| 150368 | + if( (res = sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1)) ){ |
| 150369 | + return res; |
| 150370 | + } |
| 149494 | 150371 | if( bFilter ){ |
| 149495 | | - if( sqlite3ExprCompare(pParse, p1->pFilter, p2->pFilter, -1) ) return 1; |
| 150372 | + if( (res = sqlite3ExprCompare(pParse, p1->pFilter, p2->pFilter, -1)) ){ |
| 150373 | + return res; |
| 150374 | + } |
| 149496 | 150375 | } |
| 149497 | 150376 | return 0; |
| 149498 | 150377 | } |
| 149499 | 150378 | |
| 149500 | 150379 | |
| | @@ -149501,14 +150380,21 @@ |
| 149501 | 150380 | /* |
| 149502 | 150381 | ** This is called by code in select.c before it calls sqlite3WhereBegin() |
| 149503 | 150382 | ** to begin iterating through the sub-query results. It is used to allocate |
| 149504 | 150383 | ** and initialize registers and cursors used by sqlite3WindowCodeStep(). |
| 149505 | 150384 | */ |
| 149506 | | -SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Window *pMWin){ |
| 150385 | +SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Select *pSelect){ |
| 150386 | + int nEphExpr = pSelect->pSrc->a[0].pSelect->pEList->nExpr; |
| 150387 | + Window *pMWin = pSelect->pWin; |
| 149507 | 150388 | Window *pWin; |
| 149508 | 150389 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 149509 | 150390 | |
| 150391 | + sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, nEphExpr); |
| 150392 | + sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr); |
| 150393 | + sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr); |
| 150394 | + sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr); |
| 150395 | + |
| 149510 | 150396 | /* Allocate registers to use for PARTITION BY values, if any. Initialize |
| 149511 | 150397 | ** said registers to NULL. */ |
| 149512 | 150398 | if( pMWin->pPartition ){ |
| 149513 | 150399 | int nExpr = pMWin->pPartition->nExpr; |
| 149514 | 150400 | pMWin->regPart = pParse->nMem+1; |
| | @@ -149770,11 +150656,11 @@ |
| 149770 | 150656 | |
| 149771 | 150657 | assert( bInverse==0 || pWin->eStart!=TK_UNBOUNDED ); |
| 149772 | 150658 | |
| 149773 | 150659 | /* All OVER clauses in the same window function aggregate step must |
| 149774 | 150660 | ** be the same. */ |
| 149775 | | - assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)==0 ); |
| 150661 | + assert( pWin==pMWin || sqlite3WindowCompare(pParse,pWin,pMWin,0)!=1 ); |
| 149776 | 150662 | |
| 149777 | 150663 | for(i=0; i<nArg; i++){ |
| 149778 | 150664 | if( i!=1 || pFunc->zName!=nth_valueName ){ |
| 149779 | 150665 | sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i); |
| 149780 | 150666 | }else{ |
| | @@ -158619,10 +159505,13 @@ |
| 158619 | 159505 | ** the lookaside memory. |
| 158620 | 159506 | */ |
| 158621 | 159507 | static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ |
| 158622 | 159508 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 158623 | 159509 | void *pStart; |
| 159510 | + sqlite3_int64 szAlloc = sz*(sqlite3_int64)cnt; |
| 159511 | + int nBig; /* Number of full-size slots */ |
| 159512 | + int nSm; /* Number smaller LOOKASIDE_SMALL-byte slots */ |
| 158624 | 159513 | |
| 158625 | 159514 | if( sqlite3LookasideUsed(db,0)>0 ){ |
| 158626 | 159515 | return SQLITE_BUSY; |
| 158627 | 159516 | } |
| 158628 | 159517 | /* Free any existing lookaside buffer for this handle before |
| | @@ -158641,15 +159530,30 @@ |
| 158641 | 159530 | if( sz==0 || cnt==0 ){ |
| 158642 | 159531 | sz = 0; |
| 158643 | 159532 | pStart = 0; |
| 158644 | 159533 | }else if( pBuf==0 ){ |
| 158645 | 159534 | sqlite3BeginBenignMalloc(); |
| 158646 | | - pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */ |
| 159535 | + pStart = sqlite3Malloc( szAlloc ); /* IMP: R-61949-35727 */ |
| 158647 | 159536 | sqlite3EndBenignMalloc(); |
| 158648 | | - if( pStart ) cnt = sqlite3MallocSize(pStart)/sz; |
| 159537 | + if( pStart ) szAlloc = sqlite3MallocSize(pStart); |
| 158649 | 159538 | }else{ |
| 158650 | 159539 | pStart = pBuf; |
| 159540 | + } |
| 159541 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 159542 | + if( sz>=LOOKASIDE_SMALL*3 ){ |
| 159543 | + nBig = szAlloc/(3*LOOKASIDE_SMALL+sz); |
| 159544 | + nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL; |
| 159545 | + }else if( sz>=LOOKASIDE_SMALL*2 ){ |
| 159546 | + nBig = szAlloc/(LOOKASIDE_SMALL+sz); |
| 159547 | + nSm = (szAlloc - sz*nBig)/LOOKASIDE_SMALL; |
| 159548 | + }else |
| 159549 | +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 159550 | + if( sz>0 ){ |
| 159551 | + nBig = szAlloc/sz; |
| 159552 | + nSm = 0; |
| 159553 | + }else{ |
| 159554 | + nBig = nSm = 0; |
| 158651 | 159555 | } |
| 158652 | 159556 | db->lookaside.pStart = pStart; |
| 158653 | 159557 | db->lookaside.pInit = 0; |
| 158654 | 159558 | db->lookaside.pFree = 0; |
| 158655 | 159559 | db->lookaside.sz = (u16)sz; |
| | @@ -158656,28 +159560,45 @@ |
| 158656 | 159560 | db->lookaside.szTrue = (u16)sz; |
| 158657 | 159561 | if( pStart ){ |
| 158658 | 159562 | int i; |
| 158659 | 159563 | LookasideSlot *p; |
| 158660 | 159564 | assert( sz > (int)sizeof(LookasideSlot*) ); |
| 158661 | | - db->lookaside.nSlot = cnt; |
| 158662 | 159565 | p = (LookasideSlot*)pStart; |
| 158663 | | - for(i=cnt-1; i>=0; i--){ |
| 159566 | + for(i=0; i<nBig; i++){ |
| 158664 | 159567 | p->pNext = db->lookaside.pInit; |
| 158665 | 159568 | db->lookaside.pInit = p; |
| 158666 | 159569 | p = (LookasideSlot*)&((u8*)p)[sz]; |
| 158667 | 159570 | } |
| 159571 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 159572 | + db->lookaside.pSmallInit = 0; |
| 159573 | + db->lookaside.pSmallFree = 0; |
| 159574 | + db->lookaside.pMiddle = p; |
| 159575 | + for(i=0; i<nSm; i++){ |
| 159576 | + p->pNext = db->lookaside.pSmallInit; |
| 159577 | + db->lookaside.pSmallInit = p; |
| 159578 | + p = (LookasideSlot*)&((u8*)p)[LOOKASIDE_SMALL]; |
| 159579 | + } |
| 159580 | +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 159581 | + assert( ((uptr)p)<=szAlloc + (uptr)pStart ); |
| 158668 | 159582 | db->lookaside.pEnd = p; |
| 158669 | 159583 | db->lookaside.bDisable = 0; |
| 158670 | 159584 | db->lookaside.bMalloced = pBuf==0 ?1:0; |
| 159585 | + db->lookaside.nSlot = nBig+nSm; |
| 158671 | 159586 | }else{ |
| 158672 | 159587 | db->lookaside.pStart = db; |
| 159588 | +#ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 159589 | + db->lookaside.pSmallInit = 0; |
| 159590 | + db->lookaside.pSmallFree = 0; |
| 159591 | + db->lookaside.pMiddle = db; |
| 159592 | +#endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 158673 | 159593 | db->lookaside.pEnd = db; |
| 158674 | 159594 | db->lookaside.bDisable = 1; |
| 158675 | 159595 | db->lookaside.sz = 0; |
| 158676 | 159596 | db->lookaside.bMalloced = 0; |
| 158677 | 159597 | db->lookaside.nSlot = 0; |
| 158678 | 159598 | } |
| 159599 | + assert( sqlite3LookasideUsed(db,0)==0 ); |
| 158679 | 159600 | #endif /* SQLITE_OMIT_LOOKASIDE */ |
| 158680 | 159601 | return SQLITE_OK; |
| 158681 | 159602 | } |
| 158682 | 159603 | |
| 158683 | 159604 | /* |
| | @@ -158788,10 +159709,11 @@ |
| 158788 | 159709 | SQLITE_NoSchemaError }, |
| 158789 | 159710 | { SQLITE_DBCONFIG_LEGACY_ALTER_TABLE, SQLITE_LegacyAlter }, |
| 158790 | 159711 | { SQLITE_DBCONFIG_DQS_DDL, SQLITE_DqsDDL }, |
| 158791 | 159712 | { SQLITE_DBCONFIG_DQS_DML, SQLITE_DqsDML }, |
| 158792 | 159713 | { SQLITE_DBCONFIG_LEGACY_FILE_FORMAT, SQLITE_LegacyFileFmt }, |
| 159714 | + { SQLITE_DBCONFIG_TRUSTED_SCHEMA, SQLITE_TrustedSchema }, |
| 158793 | 159715 | }; |
| 158794 | 159716 | unsigned int i; |
| 158795 | 159717 | rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ |
| 158796 | 159718 | for(i=0; i<ArraySize(aFlagOp); i++){ |
| 158797 | 159719 | if( aFlagOp[i].op==op ){ |
| | @@ -159659,12 +160581,19 @@ |
| 159659 | 160581 | return SQLITE_MISUSE_BKPT; |
| 159660 | 160582 | } |
| 159661 | 160583 | |
| 159662 | 160584 | assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC ); |
| 159663 | 160585 | assert( SQLITE_FUNC_DIRECT==SQLITE_DIRECTONLY ); |
| 159664 | | - extraFlags = enc & (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY|SQLITE_SUBTYPE); |
| 160586 | + extraFlags = enc & (SQLITE_DETERMINISTIC|SQLITE_DIRECTONLY| |
| 160587 | + SQLITE_SUBTYPE|SQLITE_INNOCUOUS); |
| 159665 | 160588 | enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY); |
| 160589 | + |
| 160590 | + /* The SQLITE_INNOCUOUS flag is the same bit as SQLITE_FUNC_UNSAFE. But |
| 160591 | + ** the meaning is inverted. So flip the bit. */ |
| 160592 | + assert( SQLITE_FUNC_UNSAFE==SQLITE_INNOCUOUS ); |
| 160593 | + extraFlags ^= SQLITE_FUNC_UNSAFE; |
| 160594 | + |
| 159666 | 160595 | |
| 159667 | 160596 | #ifndef SQLITE_OMIT_UTF16 |
| 159668 | 160597 | /* If SQLITE_UTF16 is specified as the encoding type, transform this |
| 159669 | 160598 | ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
| 159670 | 160599 | ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
| | @@ -159674,15 +160603,17 @@ |
| 159674 | 160603 | */ |
| 159675 | 160604 | if( enc==SQLITE_UTF16 ){ |
| 159676 | 160605 | enc = SQLITE_UTF16NATIVE; |
| 159677 | 160606 | }else if( enc==SQLITE_ANY ){ |
| 159678 | 160607 | int rc; |
| 159679 | | - rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, |
| 160608 | + rc = sqlite3CreateFunc(db, zFunctionName, nArg, |
| 160609 | + (SQLITE_UTF8|extraFlags)^SQLITE_FUNC_UNSAFE, |
| 159680 | 160610 | pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 159681 | 160611 | if( rc==SQLITE_OK ){ |
| 159682 | | - rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, |
| 159683 | | - pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 160612 | + rc = sqlite3CreateFunc(db, zFunctionName, nArg, |
| 160613 | + (SQLITE_UTF16LE|extraFlags)^SQLITE_FUNC_UNSAFE, |
| 160614 | + pUserData, xSFunc, xStep, xFinal, xValue, xInverse, pDestructor); |
| 159684 | 160615 | } |
| 159685 | 160616 | if( rc!=SQLITE_OK ){ |
| 159686 | 160617 | return rc; |
| 159687 | 160618 | } |
| 159688 | 160619 | enc = SQLITE_UTF16BE; |
| | @@ -161018,11 +161949,13 @@ |
| 161018 | 161949 | db->nMaxSorterMmap = 0x7FFFFFFF; |
| 161019 | 161950 | db->flags |= SQLITE_ShortColNames |
| 161020 | 161951 | | SQLITE_EnableTrigger |
| 161021 | 161952 | | SQLITE_EnableView |
| 161022 | 161953 | | SQLITE_CacheSpill |
| 161023 | | - |
| 161954 | +#if !defined(SQLITE_TRUSTED_SCHEMA) || SQLITE_TRUSTED_SCHEMA+0!=0 |
| 161955 | + | SQLITE_TrustedSchema |
| 161956 | +#endif |
| 161024 | 161957 | /* The SQLITE_DQS compile-time option determines the default settings |
| 161025 | 161958 | ** for SQLITE_DBCONFIG_DQS_DDL and SQLITE_DBCONFIG_DQS_DML. |
| 161026 | 161959 | ** |
| 161027 | 161960 | ** SQLITE_DQS SQLITE_DBCONFIG_DQS_DDL SQLITE_DBCONFIG_DQS_DML |
| 161028 | 161961 | ** ---------- ----------------------- ----------------------- |
| | @@ -161247,10 +162180,17 @@ |
| 161247 | 162180 | #ifdef SQLITE_ENABLE_STMTVTAB |
| 161248 | 162181 | if( !db->mallocFailed && rc==SQLITE_OK){ |
| 161249 | 162182 | rc = sqlite3StmtVtabInit(db); |
| 161250 | 162183 | } |
| 161251 | 162184 | #endif |
| 162185 | + |
| 162186 | +#ifdef SQLITE_ENABLE_INTERNAL_FUNCTIONS |
| 162187 | + /* Testing use only!!! The -DSQLITE_ENABLE_INTERNAL_FUNCTIONS=1 compile-time |
| 162188 | + ** option gives access to internal functions by default. |
| 162189 | + ** Testing use only!!! */ |
| 162190 | + db->mDbFlags |= DBFLAG_InternalFunc; |
| 162191 | +#endif |
| 161252 | 162192 | |
| 161253 | 162193 | /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking |
| 161254 | 162194 | ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking |
| 161255 | 162195 | ** mode. Doing nothing at all also makes NORMAL the default. |
| 161256 | 162196 | */ |
| | @@ -161980,19 +162920,18 @@ |
| 161980 | 162920 | case SQLITE_TESTCTRL_LOCALTIME_FAULT: { |
| 161981 | 162921 | sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int); |
| 161982 | 162922 | break; |
| 161983 | 162923 | } |
| 161984 | 162924 | |
| 161985 | | - /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCS, int onoff); |
| 162925 | + /* sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS, sqlite3*); |
| 161986 | 162926 | ** |
| 161987 | | - ** If parameter onoff is non-zero, internal-use-only SQL functions |
| 161988 | | - ** are visible to ordinary SQL. This is useful for testing but is |
| 161989 | | - ** unsafe because invalid parameters to those internal-use-only functions |
| 161990 | | - ** can result in crashes or segfaults. |
| 162927 | + ** Toggle the ability to use internal functions on or off for |
| 162928 | + ** the database connection given in the argument. |
| 161991 | 162929 | */ |
| 161992 | 162930 | case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS: { |
| 161993 | | - sqlite3GlobalConfig.bInternalFunctions = va_arg(ap, int); |
| 162931 | + sqlite3 *db = va_arg(ap, sqlite3*); |
| 162932 | + db->mDbFlags ^= DBFLAG_InternalFunc; |
| 161994 | 162933 | break; |
| 161995 | 162934 | } |
| 161996 | 162935 | |
| 161997 | 162936 | /* sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, int); |
| 161998 | 162937 | ** |
| | @@ -173136,11 +174075,11 @@ |
| 173136 | 174075 | Fts3Hash *pHash, |
| 173137 | 174076 | const char *zName |
| 173138 | 174077 | ){ |
| 173139 | 174078 | int rc = SQLITE_OK; |
| 173140 | 174079 | void *p = (void *)pHash; |
| 173141 | | - const int any = SQLITE_ANY; |
| 174080 | + const int any = SQLITE_UTF8|SQLITE_DIRECTONLY; |
| 173142 | 174081 | |
| 173143 | 174082 | #ifdef SQLITE_TEST |
| 173144 | 174083 | char *zTest = 0; |
| 173145 | 174084 | char *zTest2 = 0; |
| 173146 | 174085 | void *pdb = (void *)db; |
| | @@ -174208,11 +175147,11 @@ |
| 174208 | 175147 | ** of the oldest level in the db that contains at least ? segments. Or, |
| 174209 | 175148 | ** if no level in the FTS index contains more than ? segments, the statement |
| 174210 | 175149 | ** returns zero rows. */ |
| 174211 | 175150 | /* 28 */ "SELECT level, count(*) AS cnt FROM %Q.'%q_segdir' " |
| 174212 | 175151 | " GROUP BY level HAVING cnt>=?" |
| 174213 | | - " ORDER BY (level %% 1024) ASC LIMIT 1", |
| 175152 | + " ORDER BY (level %% 1024) ASC, 2 DESC LIMIT 1", |
| 174214 | 175153 | |
| 174215 | 175154 | /* Estimate the upper limit on the number of leaf nodes in a new segment |
| 174216 | 175155 | ** created by merging the oldest :2 segments from absolute level :1. See |
| 174217 | 175156 | ** function sqlite3Fts3Incrmerge() for details. */ |
| 174218 | 175157 | /* 29 */ "SELECT 2 * total(1 + leaves_end_block - start_block) " |
| | @@ -178804,12 +179743,18 @@ |
| 178804 | 179743 | sqlite3_int64 iHintAbsLevel = 0; /* Hint level */ |
| 178805 | 179744 | int nHintSeg = 0; /* Hint number of segments */ |
| 178806 | 179745 | |
| 178807 | 179746 | rc = fts3IncrmergeHintPop(&hint, &iHintAbsLevel, &nHintSeg); |
| 178808 | 179747 | if( nSeg<0 || (iAbsLevel % nMod) >= (iHintAbsLevel % nMod) ){ |
| 179748 | + /* Based on the scan in the block above, it is known that there |
| 179749 | + ** are no levels with a relative level smaller than that of |
| 179750 | + ** iAbsLevel with more than nSeg segments, or if nSeg is -1, |
| 179751 | + ** no levels with more than nMin segments. Use this to limit the |
| 179752 | + ** value of nHintSeg to avoid a large memory allocation in case the |
| 179753 | + ** merge-hint is corrupt*/ |
| 178809 | 179754 | iAbsLevel = iHintAbsLevel; |
| 178810 | | - nSeg = nHintSeg; |
| 179755 | + nSeg = MIN(MAX(nMin,nSeg), nHintSeg); |
| 178811 | 179756 | bUseHint = 1; |
| 178812 | 179757 | bDirtyHint = 1; |
| 178813 | 179758 | }else{ |
| 178814 | 179759 | /* This undoes the effect of the HintPop() above - so that no entry |
| 178815 | 179760 | ** is removed from the hint blob. */ |
| | @@ -178818,11 +179763,11 @@ |
| 178818 | 179763 | } |
| 178819 | 179764 | |
| 178820 | 179765 | /* If nSeg is less that zero, then there is no level with at least |
| 178821 | 179766 | ** nMin segments and no hint in the %_stat table. No work to do. |
| 178822 | 179767 | ** Exit early in this case. */ |
| 178823 | | - if( nSeg<0 ) break; |
| 179768 | + if( nSeg<=0 ) break; |
| 178824 | 179769 | |
| 178825 | 179770 | /* Open a cursor to iterate through the contents of the oldest nSeg |
| 178826 | 179771 | ** indexes of absolute level iAbsLevel. If this cursor is opened using |
| 178827 | 179772 | ** the 'hint' parameters, it is possible that there are less than nSeg |
| 178828 | 179773 | ** segments available in level iAbsLevel. In this case, no work is |
| | @@ -180205,11 +181150,11 @@ |
| 180205 | 181150 | if( rc==SQLITE_OK ){ |
| 180206 | 181151 | |
| 180207 | 181152 | /* Set the *pmSeen output variable. */ |
| 180208 | 181153 | for(i=0; i<nList; i++){ |
| 180209 | 181154 | if( sIter.aPhrase[i].pHead ){ |
| 180210 | | - *pmSeen |= (u64)1 << i; |
| 181155 | + *pmSeen |= (u64)1 << (i%64); |
| 180211 | 181156 | } |
| 180212 | 181157 | } |
| 180213 | 181158 | |
| 180214 | 181159 | /* Loop through all candidate snippets. Store the best snippet in |
| 180215 | 181160 | ** *pFragment. Store its associated 'score' in iBestScore. |
| | @@ -184272,10 +185217,11 @@ |
| 184272 | 185217 | "json HIDDEN,root HIDDEN)"); |
| 184273 | 185218 | if( rc==SQLITE_OK ){ |
| 184274 | 185219 | pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) ); |
| 184275 | 185220 | if( pNew==0 ) return SQLITE_NOMEM; |
| 184276 | 185221 | memset(pNew, 0, sizeof(*pNew)); |
| 185222 | + sqlite3_vtab_config(db, SQLITE_VTAB_INNOCUOUS); |
| 184277 | 185223 | } |
| 184278 | 185224 | return rc; |
| 184279 | 185225 | } |
| 184280 | 185226 | |
| 184281 | 185227 | /* destructor for json_each virtual table */ |
| | @@ -184762,20 +185708,23 @@ |
| 184762 | 185708 | } aMod[] = { |
| 184763 | 185709 | { "json_each", &jsonEachModule }, |
| 184764 | 185710 | { "json_tree", &jsonTreeModule }, |
| 184765 | 185711 | }; |
| 184766 | 185712 | #endif |
| 185713 | + static const int enc = |
| 185714 | + SQLITE_UTF8 | |
| 185715 | + SQLITE_DETERMINISTIC | |
| 185716 | + SQLITE_INNOCUOUS; |
| 184767 | 185717 | for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){ |
| 184768 | | - rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg, |
| 184769 | | - SQLITE_UTF8 | SQLITE_DETERMINISTIC, |
| 185718 | + rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg, enc, |
| 184770 | 185719 | (void*)&aFunc[i].flag, |
| 184771 | 185720 | aFunc[i].xFunc, 0, 0); |
| 184772 | 185721 | } |
| 184773 | 185722 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 184774 | 185723 | for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){ |
| 184775 | 185724 | rc = sqlite3_create_window_function(db, aAgg[i].zName, aAgg[i].nArg, |
| 184776 | | - SQLITE_SUBTYPE | SQLITE_UTF8 | SQLITE_DETERMINISTIC, 0, |
| 185725 | + SQLITE_SUBTYPE | enc, 0, |
| 184777 | 185726 | aAgg[i].xStep, aAgg[i].xFinal, |
| 184778 | 185727 | aAgg[i].xValue, jsonGroupInverse, 0); |
| 184779 | 185728 | } |
| 184780 | 185729 | #endif |
| 184781 | 185730 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -190941,18 +191890,24 @@ |
| 190941 | 191890 | } aAgg[] = { |
| 190942 | 191891 | { geopolyBBoxStep, geopolyBBoxFinal, "geopoly_group_bbox" }, |
| 190943 | 191892 | }; |
| 190944 | 191893 | int i; |
| 190945 | 191894 | for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){ |
| 190946 | | - int enc = aFunc[i].bPure ? SQLITE_UTF8|SQLITE_DETERMINISTIC : SQLITE_UTF8; |
| 191895 | + int enc; |
| 191896 | + if( aFunc[i].bPure ){ |
| 191897 | + enc = SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS; |
| 191898 | + }else{ |
| 191899 | + enc = SQLITE_UTF8|SQLITE_DIRECTONLY; |
| 191900 | + } |
| 190947 | 191901 | rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg, |
| 190948 | 191902 | enc, 0, |
| 190949 | 191903 | aFunc[i].xFunc, 0, 0); |
| 190950 | 191904 | } |
| 190951 | 191905 | for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){ |
| 190952 | | - rc = sqlite3_create_function(db, aAgg[i].zName, 1, SQLITE_UTF8, 0, |
| 190953 | | - 0, aAgg[i].xStep, aAgg[i].xFinal); |
| 191906 | + rc = sqlite3_create_function(db, aAgg[i].zName, 1, |
| 191907 | + SQLITE_UTF8|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS, 0, |
| 191908 | + 0, aAgg[i].xStep, aAgg[i].xFinal); |
| 190954 | 191909 | } |
| 190955 | 191910 | if( rc==SQLITE_OK ){ |
| 190956 | 191911 | rc = sqlite3_create_module_v2(db, "geopoly", &geopolyModule, 0, 0); |
| 190957 | 191912 | } |
| 190958 | 191913 | return rc; |
| | @@ -191638,30 +192593,31 @@ |
| 191638 | 192593 | |
| 191639 | 192594 | /* |
| 191640 | 192595 | ** Register the ICU extension functions with database db. |
| 191641 | 192596 | */ |
| 191642 | 192597 | SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){ |
| 192598 | +# define SQLITEICU_EXTRAFLAGS (SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS) |
| 191643 | 192599 | static const struct IcuScalar { |
| 191644 | 192600 | const char *zName; /* Function name */ |
| 191645 | 192601 | unsigned char nArg; /* Number of arguments */ |
| 191646 | | - unsigned short enc; /* Optimal text encoding */ |
| 192602 | + unsigned int enc; /* Optimal text encoding */ |
| 191647 | 192603 | unsigned char iContext; /* sqlite3_user_data() context */ |
| 191648 | 192604 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**); |
| 191649 | 192605 | } scalars[] = { |
| 191650 | | - {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation}, |
| 192606 | + {"icu_load_collation",2,SQLITE_UTF8|SQLITE_DIRECTONLY,1, icuLoadCollation}, |
| 191651 | 192607 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) |
| 191652 | | - {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc}, |
| 191653 | | - {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 191654 | | - {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 191655 | | - {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 191656 | | - {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 191657 | | - {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 191658 | | - {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 191659 | | - {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 191660 | | - {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 191661 | | - {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, |
| 191662 | | - {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, |
| 192608 | + {"regexp", 2, SQLITE_ANY|SQLITEICU_EXTRAFLAGS, 0, icuRegexpFunc}, |
| 192609 | + {"lower", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16}, |
| 192610 | + {"lower", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16}, |
| 192611 | + {"upper", 1, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16}, |
| 192612 | + {"upper", 2, SQLITE_UTF16|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16}, |
| 192613 | + {"lower", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16}, |
| 192614 | + {"lower", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuCaseFunc16}, |
| 192615 | + {"upper", 1, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16}, |
| 192616 | + {"upper", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 1, icuCaseFunc16}, |
| 192617 | + {"like", 2, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc}, |
| 192618 | + {"like", 3, SQLITE_UTF8|SQLITEICU_EXTRAFLAGS, 0, icuLikeFunc}, |
| 191663 | 192619 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_ICU) */ |
| 191664 | 192620 | }; |
| 191665 | 192621 | int rc = SQLITE_OK; |
| 191666 | 192622 | int i; |
| 191667 | 192623 | |
| | @@ -198070,10 +199026,11 @@ |
| 198070 | 199026 | return SQLITE_ERROR; |
| 198071 | 199027 | } |
| 198072 | 199028 | }else{ |
| 198073 | 199029 | iDb = 0; |
| 198074 | 199030 | } |
| 199031 | + sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY); |
| 198075 | 199032 | rc = sqlite3_declare_vtab(db, zDbstatSchema); |
| 198076 | 199033 | if( rc==SQLITE_OK ){ |
| 198077 | 199034 | pTab = (StatTable *)sqlite3_malloc64(sizeof(StatTable)); |
| 198078 | 199035 | if( pTab==0 ) rc = SQLITE_NOMEM_BKPT; |
| 198079 | 199036 | } |
| | @@ -198140,21 +199097,18 @@ |
| 198140 | 199097 | } |
| 198141 | 199098 | } |
| 198142 | 199099 | i = 0; |
| 198143 | 199100 | if( iSchema>=0 ){ |
| 198144 | 199101 | pIdxInfo->aConstraintUsage[iSchema].argvIndex = ++i; |
| 198145 | | - pIdxInfo->aConstraintUsage[iSchema].omit = 1; |
| 198146 | 199102 | pIdxInfo->idxNum |= 0x01; |
| 198147 | 199103 | } |
| 198148 | 199104 | if( iName>=0 ){ |
| 198149 | 199105 | pIdxInfo->aConstraintUsage[iName].argvIndex = ++i; |
| 198150 | | - pIdxInfo->aConstraintUsage[iName].omit = 1; |
| 198151 | 199106 | pIdxInfo->idxNum |= 0x02; |
| 198152 | 199107 | } |
| 198153 | 199108 | if( iAgg>=0 ){ |
| 198154 | 199109 | pIdxInfo->aConstraintUsage[iAgg].argvIndex = ++i; |
| 198155 | | - pIdxInfo->aConstraintUsage[iAgg].omit = 1; |
| 198156 | 199110 | pIdxInfo->idxNum |= 0x04; |
| 198157 | 199111 | } |
| 198158 | 199112 | pIdxInfo->estimatedCost = 1.0; |
| 198159 | 199113 | |
| 198160 | 199114 | /* Records are always returned in ascending order of (name, path). |
| | @@ -198606,13 +199560,13 @@ |
| 198606 | 199560 | if( idxNum & 0x01 ){ |
| 198607 | 199561 | /* schema=? constraint is present. Get its value */ |
| 198608 | 199562 | const char *zDbase = (const char*)sqlite3_value_text(argv[iArg++]); |
| 198609 | 199563 | pCsr->iDb = sqlite3FindDbName(pTab->db, zDbase); |
| 198610 | 199564 | if( pCsr->iDb<0 ){ |
| 198611 | | - sqlite3_free(pCursor->pVtab->zErrMsg); |
| 198612 | | - pCursor->pVtab->zErrMsg = sqlite3_mprintf("no such schema: %s", zDbase); |
| 198613 | | - return pCursor->pVtab->zErrMsg ? SQLITE_ERROR : SQLITE_NOMEM_BKPT; |
| 199565 | + pCsr->iDb = 0; |
| 199566 | + pCsr->isEof = 1; |
| 199567 | + return SQLITE_OK; |
| 198614 | 199568 | } |
| 198615 | 199569 | }else{ |
| 198616 | 199570 | pCsr->iDb = pTab->iDb; |
| 198617 | 199571 | } |
| 198618 | 199572 | if( idxNum & 0x02 ){ |
| | @@ -198831,10 +199785,11 @@ |
| 198831 | 199785 | char **pzErr |
| 198832 | 199786 | ){ |
| 198833 | 199787 | DbpageTable *pTab = 0; |
| 198834 | 199788 | int rc = SQLITE_OK; |
| 198835 | 199789 | |
| 199790 | + sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY); |
| 198836 | 199791 | rc = sqlite3_declare_vtab(db, |
| 198837 | 199792 | "CREATE TABLE x(pgno INTEGER PRIMARY KEY, data BLOB, schema HIDDEN)"); |
| 198838 | 199793 | if( rc==SQLITE_OK ){ |
| 198839 | 199794 | pTab = (DbpageTable *)sqlite3_malloc64(sizeof(DbpageTable)); |
| 198840 | 199795 | if( pTab==0 ) rc = SQLITE_NOMEM_BKPT; |
| | @@ -220005,11 +220960,14 @@ |
| 220005 | 220960 | break; |
| 220006 | 220961 | |
| 220007 | 220962 | case FTS5_ROLLBACKTO: |
| 220008 | 220963 | assert( p->ts.eState==1 ); |
| 220009 | 220964 | assert( iSavepoint>=-1 ); |
| 220010 | | - assert( iSavepoint<=p->ts.iSavepoint ); |
| 220965 | + /* The following assert() can fail if another vtab strikes an error |
| 220966 | + ** within an xSavepoint() call then SQLite calls xRollbackTo() - without |
| 220967 | + ** having called xSavepoint() on this vtab. */ |
| 220968 | + /* assert( iSavepoint<=p->ts.iSavepoint ); */ |
| 220011 | 220969 | p->ts.iSavepoint = iSavepoint; |
| 220012 | 220970 | break; |
| 220013 | 220971 | } |
| 220014 | 220972 | } |
| 220015 | 220973 | #else |
| | @@ -222455,11 +223413,11 @@ |
| 222455 | 223413 | int nArg, /* Number of args */ |
| 222456 | 223414 | sqlite3_value **apUnused /* Function arguments */ |
| 222457 | 223415 | ){ |
| 222458 | 223416 | assert( nArg==0 ); |
| 222459 | 223417 | UNUSED_PARAM2(nArg, apUnused); |
| 222460 | | - sqlite3_result_text(pCtx, "fts5: 2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1bef22f3", -1, SQLITE_TRANSIENT); |
| 223418 | + sqlite3_result_text(pCtx, "fts5: 2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68", -1, SQLITE_TRANSIENT); |
| 222461 | 223419 | } |
| 222462 | 223420 | |
| 222463 | 223421 | /* |
| 222464 | 223422 | ** Return true if zName is the extension on one of the shadow tables used |
| 222465 | 223423 | ** by this module. |
| | @@ -227228,12 +228186,12 @@ |
| 227228 | 228186 | } |
| 227229 | 228187 | #endif /* SQLITE_CORE */ |
| 227230 | 228188 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 227231 | 228189 | |
| 227232 | 228190 | /************** End of stmt.c ************************************************/ |
| 227233 | | -#if __LINE__!=227233 |
| 228191 | +#if __LINE__!=228191 |
| 227234 | 228192 | #undef SQLITE_SOURCE_ID |
| 227235 | | -#define SQLITE_SOURCE_ID "2019-12-26 01:10:17 f482a4cdfa768941e22c399de8ec29a55e729529eeae86d3832077ad1befalt2" |
| 228193 | +#define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0falt2" |
| 227236 | 228194 | #endif |
| 227237 | 228195 | /* Return the source-id for this library */ |
| 227238 | 228196 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 227239 | 228197 | /************************** End of sqlite3.c ******************************/ |
| 227240 | 228198 | |