| | @@ -1,8 +1,8 @@ |
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | | -** version 3.25.2. By combining all the individual C code files into this |
| 3 | +** version 3.26.0. By combining all the individual C code files into this |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| | @@ -257,10 +257,13 @@ |
| 257 | 257 | #if SQLITE_ENABLE_FTS4 |
| 258 | 258 | "ENABLE_FTS4", |
| 259 | 259 | #endif |
| 260 | 260 | #if SQLITE_ENABLE_FTS5 |
| 261 | 261 | "ENABLE_FTS5", |
| 262 | +#endif |
| 263 | +#if SQLITE_ENABLE_GEOPOLY |
| 264 | + "ENABLE_GEOPOLY", |
| 262 | 265 | #endif |
| 263 | 266 | #if SQLITE_ENABLE_HIDDEN_COLUMNS |
| 264 | 267 | "ENABLE_HIDDEN_COLUMNS", |
| 265 | 268 | #endif |
| 266 | 269 | #if SQLITE_ENABLE_ICU |
| | @@ -287,10 +290,13 @@ |
| 287 | 290 | #if SQLITE_ENABLE_MEMSYS5 |
| 288 | 291 | "ENABLE_MEMSYS5", |
| 289 | 292 | #endif |
| 290 | 293 | #if SQLITE_ENABLE_MULTIPLEX |
| 291 | 294 | "ENABLE_MULTIPLEX", |
| 295 | +#endif |
| 296 | +#if SQLITE_ENABLE_NORMALIZE |
| 297 | + "ENABLE_NORMALIZE", |
| 292 | 298 | #endif |
| 293 | 299 | #if SQLITE_ENABLE_NULL_TRIM |
| 294 | 300 | "ENABLE_NULL_TRIM", |
| 295 | 301 | #endif |
| 296 | 302 | #if SQLITE_ENABLE_OVERSIZE_CELL_CHECK |
| | @@ -1154,13 +1160,13 @@ |
| 1154 | 1160 | ** |
| 1155 | 1161 | ** See also: [sqlite3_libversion()], |
| 1156 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1157 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1158 | 1164 | */ |
| 1159 | | -#define SQLITE_VERSION "3.25.2" |
| 1160 | | -#define SQLITE_VERSION_NUMBER 3025002 |
| 1161 | | -#define SQLITE_SOURCE_ID "2018-09-25 19:08:10 fb90e7189ae6d62e77ba3a308ca5d683f90bbe633cf681865365b8e92792d1c7" |
| 1165 | +#define SQLITE_VERSION "3.26.0" |
| 1166 | +#define SQLITE_VERSION_NUMBER 3026000 |
| 1167 | +#define SQLITE_SOURCE_ID "2018-11-12 15:20:44 f9755f81b1c0fd29f242dce78a2fba570fa2714d76e93b8563f426a040352513" |
| 1162 | 1168 | |
| 1163 | 1169 | /* |
| 1164 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1165 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1166 | 1172 | ** |
| | @@ -3048,10 +3054,11 @@ |
| 3048 | 3054 | ** the call worked. ^The [sqlite3_db_config()] interface will return a |
| 3049 | 3055 | ** non-zero [error code] if a discontinued or unsupported configuration option |
| 3050 | 3056 | ** is invoked. |
| 3051 | 3057 | ** |
| 3052 | 3058 | ** <dl> |
| 3059 | +** [[SQLITE_DBCONFIG_LOOKASIDE]] |
| 3053 | 3060 | ** <dt>SQLITE_DBCONFIG_LOOKASIDE</dt> |
| 3054 | 3061 | ** <dd> ^This option takes three additional arguments that determine the |
| 3055 | 3062 | ** [lookaside memory allocator] configuration for the [database connection]. |
| 3056 | 3063 | ** ^The first argument (the third parameter to [sqlite3_db_config()] is a |
| 3057 | 3064 | ** pointer to a memory buffer to use for lookaside memory. |
| | @@ -3070,10 +3077,11 @@ |
| 3070 | 3077 | ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero. |
| 3071 | 3078 | ** Any attempt to change the lookaside memory configuration when lookaside |
| 3072 | 3079 | ** memory is in use leaves the configuration unchanged and returns |
| 3073 | 3080 | ** [SQLITE_BUSY].)^</dd> |
| 3074 | 3081 | ** |
| 3082 | +** [[SQLITE_DBCONFIG_ENABLE_FKEY]] |
| 3075 | 3083 | ** <dt>SQLITE_DBCONFIG_ENABLE_FKEY</dt> |
| 3076 | 3084 | ** <dd> ^This option is used to enable or disable the enforcement of |
| 3077 | 3085 | ** [foreign key constraints]. There should be two additional arguments. |
| 3078 | 3086 | ** The first argument is an integer which is 0 to disable FK enforcement, |
| 3079 | 3087 | ** positive to enable FK enforcement or negative to leave FK enforcement |
| | @@ -3080,10 +3088,11 @@ |
| 3080 | 3088 | ** unchanged. The second parameter is a pointer to an integer into which |
| 3081 | 3089 | ** is written 0 or 1 to indicate whether FK enforcement is off or on |
| 3082 | 3090 | ** following this call. The second parameter may be a NULL pointer, in |
| 3083 | 3091 | ** which case the FK enforcement setting is not reported back. </dd> |
| 3084 | 3092 | ** |
| 3093 | +** [[SQLITE_DBCONFIG_ENABLE_TRIGGER]] |
| 3085 | 3094 | ** <dt>SQLITE_DBCONFIG_ENABLE_TRIGGER</dt> |
| 3086 | 3095 | ** <dd> ^This option is used to enable or disable [CREATE TRIGGER | triggers]. |
| 3087 | 3096 | ** There should be two additional arguments. |
| 3088 | 3097 | ** The first argument is an integer which is 0 to disable triggers, |
| 3089 | 3098 | ** positive to enable triggers or negative to leave the setting unchanged. |
| | @@ -3090,10 +3099,11 @@ |
| 3090 | 3099 | ** The second parameter is a pointer to an integer into which |
| 3091 | 3100 | ** is written 0 or 1 to indicate whether triggers are disabled or enabled |
| 3092 | 3101 | ** following this call. The second parameter may be a NULL pointer, in |
| 3093 | 3102 | ** which case the trigger setting is not reported back. </dd> |
| 3094 | 3103 | ** |
| 3104 | +** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]] |
| 3095 | 3105 | ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt> |
| 3096 | 3106 | ** <dd> ^This option is used to enable or disable the two-argument |
| 3097 | 3107 | ** version of the [fts3_tokenizer()] function which is part of the |
| 3098 | 3108 | ** [FTS3] full-text search engine extension. |
| 3099 | 3109 | ** There should be two additional arguments. |
| | @@ -3103,10 +3113,11 @@ |
| 3103 | 3113 | ** The second parameter is a pointer to an integer into which |
| 3104 | 3114 | ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled |
| 3105 | 3115 | ** following this call. The second parameter may be a NULL pointer, in |
| 3106 | 3116 | ** which case the new setting is not reported back. </dd> |
| 3107 | 3117 | ** |
| 3118 | +** [[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION]] |
| 3108 | 3119 | ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt> |
| 3109 | 3120 | ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()] |
| 3110 | 3121 | ** interface independently of the [load_extension()] SQL function. |
| 3111 | 3122 | ** The [sqlite3_enable_load_extension()] API enables or disables both the |
| 3112 | 3123 | ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()]. |
| | @@ -3120,19 +3131,20 @@ |
| 3120 | 3131 | ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface |
| 3121 | 3132 | ** is disabled or enabled following this call. The second parameter may |
| 3122 | 3133 | ** be a NULL pointer, in which case the new setting is not reported back. |
| 3123 | 3134 | ** </dd> |
| 3124 | 3135 | ** |
| 3125 | | -** <dt>SQLITE_DBCONFIG_MAINDBNAME</dt> |
| 3136 | +** [[SQLITE_DBCONFIG_MAINDBNAME]] <dt>SQLITE_DBCONFIG_MAINDBNAME</dt> |
| 3126 | 3137 | ** <dd> ^This option is used to change the name of the "main" database |
| 3127 | 3138 | ** schema. ^The sole argument is a pointer to a constant UTF8 string |
| 3128 | 3139 | ** which will become the new schema name in place of "main". ^SQLite |
| 3129 | 3140 | ** does not make a copy of the new main schema name string, so the application |
| 3130 | 3141 | ** must ensure that the argument passed into this DBCONFIG option is unchanged |
| 3131 | 3142 | ** until after the database connection closes. |
| 3132 | 3143 | ** </dd> |
| 3133 | 3144 | ** |
| 3145 | +** [[SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE]] |
| 3134 | 3146 | ** <dt>SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE</dt> |
| 3135 | 3147 | ** <dd> Usually, when a database in wal mode is closed or detached from a |
| 3136 | 3148 | ** database handle, SQLite checks if this will mean that there are now no |
| 3137 | 3149 | ** connections at all to the database. If so, it performs a checkpoint |
| 3138 | 3150 | ** operation before closing the connection. This option may be used to |
| | @@ -3142,11 +3154,11 @@ |
| 3142 | 3154 | ** The second parameter is a pointer to an integer |
| 3143 | 3155 | ** into which is written 0 or 1 to indicate whether checkpoints-on-close |
| 3144 | 3156 | ** have been disabled - 0 if they are not disabled, 1 if they are. |
| 3145 | 3157 | ** </dd> |
| 3146 | 3158 | ** |
| 3147 | | -** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt> |
| 3159 | +** [[SQLITE_DBCONFIG_ENABLE_QPSG]] <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt> |
| 3148 | 3160 | ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates |
| 3149 | 3161 | ** the [query planner stability guarantee] (QPSG). When the QPSG is active, |
| 3150 | 3162 | ** a single SQL query statement will always use the same algorithm regardless |
| 3151 | 3163 | ** of values of [bound parameters].)^ The QPSG disables some query optimizations |
| 3152 | 3164 | ** that look at the values of bound parameters, which can make some queries |
| | @@ -3158,11 +3170,11 @@ |
| 3158 | 3170 | ** unchanged. The second parameter is a pointer to an integer into which |
| 3159 | 3171 | ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled |
| 3160 | 3172 | ** following this call. |
| 3161 | 3173 | ** </dd> |
| 3162 | 3174 | ** |
| 3163 | | -** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt> |
| 3175 | +** [[SQLITE_DBCONFIG_TRIGGER_EQP]] <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt> |
| 3164 | 3176 | ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not |
| 3165 | 3177 | ** include output for any operations performed by trigger programs. This |
| 3166 | 3178 | ** option is used to set or clear (the default) a flag that governs this |
| 3167 | 3179 | ** behavior. The first parameter passed to this operation is an integer - |
| 3168 | 3180 | ** positive to enable output for trigger programs, or zero to disable it, |
| | @@ -3170,11 +3182,11 @@ |
| 3170 | 3182 | ** The second parameter is a pointer to an integer into which is written |
| 3171 | 3183 | ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if |
| 3172 | 3184 | ** it is not disabled, 1 if it is. |
| 3173 | 3185 | ** </dd> |
| 3174 | 3186 | ** |
| 3175 | | -** <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt> |
| 3187 | +** [[SQLITE_DBCONFIG_RESET_DATABASE]] <dt>SQLITE_DBCONFIG_RESET_DATABASE</dt> |
| 3176 | 3188 | ** <dd> Set the SQLITE_DBCONFIG_RESET_DATABASE flag and then run |
| 3177 | 3189 | ** [VACUUM] in order to reset a database back to an empty database |
| 3178 | 3190 | ** with no schema and no content. The following process works even for |
| 3179 | 3191 | ** a badly corrupted database file: |
| 3180 | 3192 | ** <ol> |
| | @@ -3189,10 +3201,22 @@ |
| 3189 | 3201 | ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0); |
| 3190 | 3202 | ** </ol> |
| 3191 | 3203 | ** Because resetting a database is destructive and irreversible, the |
| 3192 | 3204 | ** process requires the use of this obscure API and multiple steps to help |
| 3193 | 3205 | ** ensure that it does not happen by accident. |
| 3206 | +** |
| 3207 | +** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt> |
| 3208 | +** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the |
| 3209 | +** "defensive" flag for a database connection. When the defensive |
| 3210 | +** flag is enabled, language features that allow ordinary SQL to |
| 3211 | +** deliberately corrupt the database file are disabled. The disabled |
| 3212 | +** features include but are not limited to the following: |
| 3213 | +** <ul> |
| 3214 | +** <li> The [PRAGMA writable_schema=ON] statement. |
| 3215 | +** <li> Writes to the [sqlite_dbpage] virtual table. |
| 3216 | +** <li> Direct writes to [shadow tables]. |
| 3217 | +** </ul> |
| 3194 | 3218 | ** </dd> |
| 3195 | 3219 | ** </dl> |
| 3196 | 3220 | */ |
| 3197 | 3221 | #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */ |
| 3198 | 3222 | #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ |
| | @@ -3202,11 +3226,12 @@ |
| 3202 | 3226 | #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ |
| 3203 | 3227 | #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */ |
| 3204 | 3228 | #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */ |
| 3205 | 3229 | #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */ |
| 3206 | 3230 | #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */ |
| 3207 | | -#define SQLITE_DBCONFIG_MAX 1009 /* Largest DBCONFIG */ |
| 3231 | +#define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */ |
| 3232 | +#define SQLITE_DBCONFIG_MAX 1010 /* Largest DBCONFIG */ |
| 3208 | 3233 | |
| 3209 | 3234 | /* |
| 3210 | 3235 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 3211 | 3236 | ** METHOD: sqlite3 |
| 3212 | 3237 | ** |
| | @@ -4640,13 +4665,23 @@ |
| 4640 | 4665 | ** be used just once or at most a few times and then destroyed using |
| 4641 | 4666 | ** [sqlite3_finalize()] relatively soon. The current implementation acts |
| 4642 | 4667 | ** on this hint by avoiding the use of [lookaside memory] so as not to |
| 4643 | 4668 | ** deplete the limited store of lookaside memory. Future versions of |
| 4644 | 4669 | ** SQLite may act on this hint differently. |
| 4670 | +** |
| 4671 | +** [[SQLITE_PREPARE_NORMALIZE]] ^(<dt>SQLITE_PREPARE_NORMALIZE</dt> |
| 4672 | +** <dd>The SQLITE_PREPARE_NORMALIZE flag indicates that a normalized |
| 4673 | +** representation of the SQL statement should be calculated and then |
| 4674 | +** associated with the prepared statement, which can be obtained via |
| 4675 | +** the [sqlite3_normalized_sql()] interface. The semantics used to |
| 4676 | +** normalize a SQL statement are unspecified and subject to change. |
| 4677 | +** At a minimum, literal values will be replaced with suitable |
| 4678 | +** placeholders. |
| 4645 | 4679 | ** </dl> |
| 4646 | 4680 | */ |
| 4647 | 4681 | #define SQLITE_PREPARE_PERSISTENT 0x01 |
| 4682 | +#define SQLITE_PREPARE_NORMALIZE 0x02 |
| 4648 | 4683 | |
| 4649 | 4684 | /* |
| 4650 | 4685 | ** CAPI3REF: Compiling An SQL Statement |
| 4651 | 4686 | ** KEYWORDS: {SQL statement compiler} |
| 4652 | 4687 | ** METHOD: sqlite3 |
| | @@ -4800,10 +4835,15 @@ |
| 4800 | 4835 | ** created by [sqlite3_prepare_v2()], [sqlite3_prepare_v3()], |
| 4801 | 4836 | ** [sqlite3_prepare16_v2()], or [sqlite3_prepare16_v3()]. |
| 4802 | 4837 | ** ^The sqlite3_expanded_sql(P) interface returns a pointer to a UTF-8 |
| 4803 | 4838 | ** string containing the SQL text of prepared statement P with |
| 4804 | 4839 | ** [bound parameters] expanded. |
| 4840 | +** ^The sqlite3_normalized_sql(P) interface returns a pointer to a UTF-8 |
| 4841 | +** string containing the normalized SQL text of prepared statement P. The |
| 4842 | +** semantics used to normalize a SQL statement are unspecified and subject |
| 4843 | +** to change. At a minimum, literal values will be replaced with suitable |
| 4844 | +** placeholders. |
| 4805 | 4845 | ** |
| 4806 | 4846 | ** ^(For example, if a prepared statement is created using the SQL |
| 4807 | 4847 | ** text "SELECT $abc,:xyz" and if parameter $abc is bound to integer 2345 |
| 4808 | 4848 | ** and parameter :xyz is unbound, then sqlite3_sql() will return |
| 4809 | 4849 | ** the original string, "SELECT $abc,:xyz" but sqlite3_expanded_sql() |
| | @@ -4815,18 +4855,20 @@ |
| 4815 | 4855 | ** |
| 4816 | 4856 | ** ^The [SQLITE_TRACE_SIZE_LIMIT] compile-time option limits the size of |
| 4817 | 4857 | ** bound parameter expansions. ^The [SQLITE_OMIT_TRACE] compile-time |
| 4818 | 4858 | ** option causes sqlite3_expanded_sql() to always return NULL. |
| 4819 | 4859 | ** |
| 4820 | | -** ^The string returned by sqlite3_sql(P) is managed by SQLite and is |
| 4821 | | -** automatically freed when the prepared statement is finalized. |
| 4860 | +** ^The strings returned by sqlite3_sql(P) and sqlite3_normalized_sql(P) |
| 4861 | +** are managed by SQLite and are automatically freed when the prepared |
| 4862 | +** statement is finalized. |
| 4822 | 4863 | ** ^The string returned by sqlite3_expanded_sql(P), on the other hand, |
| 4823 | 4864 | ** is obtained from [sqlite3_malloc()] and must be free by the application |
| 4824 | 4865 | ** by passing it to [sqlite3_free()]. |
| 4825 | 4866 | */ |
| 4826 | 4867 | SQLITE_API const char *sqlite3_sql(sqlite3_stmt *pStmt); |
| 4827 | 4868 | SQLITE_API char *sqlite3_expanded_sql(sqlite3_stmt *pStmt); |
| 4869 | +SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt); |
| 4828 | 4870 | |
| 4829 | 4871 | /* |
| 4830 | 4872 | ** CAPI3REF: Determine If An SQL Statement Writes The Database |
| 4831 | 4873 | ** METHOD: sqlite3_stmt |
| 4832 | 4874 | ** |
| | @@ -7312,10 +7354,13 @@ |
| 7312 | 7354 | /* The methods above are in version 1 of the sqlite_module object. Those |
| 7313 | 7355 | ** below are for version 2 and greater. */ |
| 7314 | 7356 | int (*xSavepoint)(sqlite3_vtab *pVTab, int); |
| 7315 | 7357 | int (*xRelease)(sqlite3_vtab *pVTab, int); |
| 7316 | 7358 | int (*xRollbackTo)(sqlite3_vtab *pVTab, int); |
| 7359 | + /* The methods above are in versions 1 and 2 of the sqlite_module object. |
| 7360 | + ** Those below are for version 3 and greater. */ |
| 7361 | + int (*xShadowName)(const char*); |
| 7317 | 7362 | }; |
| 7318 | 7363 | |
| 7319 | 7364 | /* |
| 7320 | 7365 | ** CAPI3REF: Virtual Table Indexing Information |
| 7321 | 7366 | ** KEYWORDS: sqlite3_index_info |
| | @@ -9646,10 +9691,11 @@ |
| 9646 | 9691 | ** These macros define the various options to the |
| 9647 | 9692 | ** [sqlite3_vtab_config()] interface that [virtual table] implementations |
| 9648 | 9693 | ** can use to customize and optimize their behavior. |
| 9649 | 9694 | ** |
| 9650 | 9695 | ** <dl> |
| 9696 | +** [[SQLITE_VTAB_CONSTRAINT_SUPPORT]] |
| 9651 | 9697 | ** <dt>SQLITE_VTAB_CONSTRAINT_SUPPORT |
| 9652 | 9698 | ** <dd>Calls of the form |
| 9653 | 9699 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_CONSTRAINT_SUPPORT,X) are supported, |
| 9654 | 9700 | ** where X is an integer. If X is zero, then the [virtual table] whose |
| 9655 | 9701 | ** [xCreate] or [xConnect] method invoked [sqlite3_vtab_config()] does not |
| | @@ -10911,16 +10957,42 @@ |
| 10911 | 10957 | ** an application iterates through a changeset using an iterator created by |
| 10912 | 10958 | ** this function, all changes that relate to a single table are visited |
| 10913 | 10959 | ** consecutively. There is no chance that the iterator will visit a change |
| 10914 | 10960 | ** the applies to table X, then one for table Y, and then later on visit |
| 10915 | 10961 | ** another change for table X. |
| 10962 | +** |
| 10963 | +** The behavior of sqlite3changeset_start_v2() and its streaming equivalent |
| 10964 | +** may be modified by passing a combination of |
| 10965 | +** [SQLITE_CHANGESETSTART_INVERT | supported flags] as the 4th parameter. |
| 10966 | +** |
| 10967 | +** Note that the sqlite3changeset_start_v2() API is still <b>experimental</b> |
| 10968 | +** and therefore subject to change. |
| 10916 | 10969 | */ |
| 10917 | 10970 | SQLITE_API int sqlite3changeset_start( |
| 10918 | 10971 | sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ |
| 10919 | 10972 | int nChangeset, /* Size of changeset blob in bytes */ |
| 10920 | 10973 | void *pChangeset /* Pointer to blob containing changeset */ |
| 10921 | 10974 | ); |
| 10975 | +SQLITE_API int sqlite3changeset_start_v2( |
| 10976 | + sqlite3_changeset_iter **pp, /* OUT: New changeset iterator handle */ |
| 10977 | + int nChangeset, /* Size of changeset blob in bytes */ |
| 10978 | + void *pChangeset, /* Pointer to blob containing changeset */ |
| 10979 | + int flags /* SESSION_CHANGESETSTART_* flags */ |
| 10980 | +); |
| 10981 | + |
| 10982 | +/* |
| 10983 | +** CAPI3REF: Flags for sqlite3changeset_start_v2 |
| 10984 | +** |
| 10985 | +** The following flags may passed via the 4th parameter to |
| 10986 | +** [sqlite3changeset_start_v2] and [sqlite3changeset_start_v2_strm]: |
| 10987 | +** |
| 10988 | +** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd> |
| 10989 | +** Invert the changeset while iterating through it. This is equivalent to |
| 10990 | +** inverting a changeset using sqlite3changeset_invert() before applying it. |
| 10991 | +** It is an error to specify this flag with a patchset. |
| 10992 | +*/ |
| 10993 | +#define SQLITE_CHANGESETSTART_INVERT 0x0002 |
| 10922 | 10994 | |
| 10923 | 10995 | |
| 10924 | 10996 | /* |
| 10925 | 10997 | ** CAPI3REF: Advance A Changeset Iterator |
| 10926 | 10998 | ** METHOD: sqlite3_changeset_iter |
| | @@ -11571,11 +11643,11 @@ |
| 11571 | 11643 | int eConflict, /* DATA, MISSING, CONFLICT, CONSTRAINT */ |
| 11572 | 11644 | sqlite3_changeset_iter *p /* Handle describing change and conflict */ |
| 11573 | 11645 | ), |
| 11574 | 11646 | void *pCtx, /* First argument passed to xConflict */ |
| 11575 | 11647 | void **ppRebase, int *pnRebase, /* OUT: Rebase data */ |
| 11576 | | - int flags /* Combination of SESSION_APPLY_* flags */ |
| 11648 | + int flags /* SESSION_CHANGESETAPPLY_* flags */ |
| 11577 | 11649 | ); |
| 11578 | 11650 | |
| 11579 | 11651 | /* |
| 11580 | 11652 | ** CAPI3REF: Flags for sqlite3changeset_apply_v2 |
| 11581 | 11653 | ** |
| | @@ -11589,12 +11661,18 @@ |
| 11589 | 11661 | ** SAVEPOINT is committed if the changeset or patchset is successfully |
| 11590 | 11662 | ** applied, or rolled back if an error occurs. Specifying this flag |
| 11591 | 11663 | ** causes the sessions module to omit this savepoint. In this case, if the |
| 11592 | 11664 | ** caller has an open transaction or savepoint when apply_v2() is called, |
| 11593 | 11665 | ** it may revert the partially applied changeset by rolling it back. |
| 11666 | +** |
| 11667 | +** <dt>SQLITE_CHANGESETAPPLY_INVERT <dd> |
| 11668 | +** Invert the changeset before applying it. This is equivalent to inverting |
| 11669 | +** a changeset using sqlite3changeset_invert() before applying it. It is |
| 11670 | +** an error to specify this flag with a patchset. |
| 11594 | 11671 | */ |
| 11595 | 11672 | #define SQLITE_CHANGESETAPPLY_NOSAVEPOINT 0x0001 |
| 11673 | +#define SQLITE_CHANGESETAPPLY_INVERT 0x0002 |
| 11596 | 11674 | |
| 11597 | 11675 | /* |
| 11598 | 11676 | ** CAPI3REF: Constants Passed To The Conflict Handler |
| 11599 | 11677 | ** |
| 11600 | 11678 | ** Values that may be passed as the second argument to a conflict-handler. |
| | @@ -11983,10 +12061,16 @@ |
| 11983 | 12061 | ); |
| 11984 | 12062 | SQLITE_API int sqlite3changeset_start_strm( |
| 11985 | 12063 | sqlite3_changeset_iter **pp, |
| 11986 | 12064 | int (*xInput)(void *pIn, void *pData, int *pnData), |
| 11987 | 12065 | void *pIn |
| 12066 | +); |
| 12067 | +SQLITE_API int sqlite3changeset_start_v2_strm( |
| 12068 | + sqlite3_changeset_iter **pp, |
| 12069 | + int (*xInput)(void *pIn, void *pData, int *pnData), |
| 12070 | + void *pIn, |
| 12071 | + int flags |
| 11988 | 12072 | ); |
| 11989 | 12073 | SQLITE_API int sqlite3session_changeset_strm( |
| 11990 | 12074 | sqlite3_session *pSession, |
| 11991 | 12075 | int (*xOutput)(void *pOut, const void *pData, int nData), |
| 11992 | 12076 | void *pOut |
| | @@ -12010,10 +12094,49 @@ |
| 12010 | 12094 | void *pIn, |
| 12011 | 12095 | int (*xOutput)(void *pOut, const void *pData, int nData), |
| 12012 | 12096 | void *pOut |
| 12013 | 12097 | ); |
| 12014 | 12098 | |
| 12099 | +/* |
| 12100 | +** CAPI3REF: Configure global parameters |
| 12101 | +** |
| 12102 | +** The sqlite3session_config() interface is used to make global configuration |
| 12103 | +** changes to the sessions module in order to tune it to the specific needs |
| 12104 | +** of the application. |
| 12105 | +** |
| 12106 | +** The sqlite3session_config() interface is not threadsafe. If it is invoked |
| 12107 | +** while any other thread is inside any other sessions method then the |
| 12108 | +** results are undefined. Furthermore, if it is invoked after any sessions |
| 12109 | +** related objects have been created, the results are also undefined. |
| 12110 | +** |
| 12111 | +** The first argument to the sqlite3session_config() function must be one |
| 12112 | +** of the SQLITE_SESSION_CONFIG_XXX constants defined below. The |
| 12113 | +** interpretation of the (void*) value passed as the second parameter and |
| 12114 | +** the effect of calling this function depends on the value of the first |
| 12115 | +** parameter. |
| 12116 | +** |
| 12117 | +** <dl> |
| 12118 | +** <dt>SQLITE_SESSION_CONFIG_STRMSIZE<dd> |
| 12119 | +** By default, the sessions module streaming interfaces attempt to input |
| 12120 | +** and output data in approximately 1 KiB chunks. This operand may be used |
| 12121 | +** to set and query the value of this configuration setting. The pointer |
| 12122 | +** passed as the second argument must point to a value of type (int). |
| 12123 | +** If this value is greater than 0, it is used as the new streaming data |
| 12124 | +** chunk size for both input and output. Before returning, the (int) value |
| 12125 | +** pointed to by pArg is set to the final value of the streaming interface |
| 12126 | +** chunk size. |
| 12127 | +** </dl> |
| 12128 | +** |
| 12129 | +** This function returns SQLITE_OK if successful, or an SQLite error code |
| 12130 | +** otherwise. |
| 12131 | +*/ |
| 12132 | +SQLITE_API int sqlite3session_config(int op, void *pArg); |
| 12133 | + |
| 12134 | +/* |
| 12135 | +** CAPI3REF: Values for sqlite3session_config(). |
| 12136 | +*/ |
| 12137 | +#define SQLITE_SESSION_CONFIG_STRMSIZE 1 |
| 12015 | 12138 | |
| 12016 | 12139 | /* |
| 12017 | 12140 | ** Make sure we can call this stuff from C++. |
| 12018 | 12141 | */ |
| 12019 | 12142 | #if 0 |
| | @@ -16036,16 +16159,18 @@ |
| 16036 | 16159 | /* |
| 16037 | 16160 | ** A hash table for built-in function definitions. (Application-defined |
| 16038 | 16161 | ** functions use a regular table table from hash.h.) |
| 16039 | 16162 | ** |
| 16040 | 16163 | ** Hash each FuncDef structure into one of the FuncDefHash.a[] slots. |
| 16041 | | -** Collisions are on the FuncDef.u.pHash chain. |
| 16164 | +** Collisions are on the FuncDef.u.pHash chain. Use the SQLITE_FUNC_HASH() |
| 16165 | +** macro to compute a hash on the function name. |
| 16042 | 16166 | */ |
| 16043 | 16167 | #define SQLITE_FUNC_HASH_SZ 23 |
| 16044 | 16168 | struct FuncDefHash { |
| 16045 | 16169 | FuncDef *a[SQLITE_FUNC_HASH_SZ]; /* Hash table for functions */ |
| 16046 | 16170 | }; |
| 16171 | +#define SQLITE_FUNC_HASH(C,L) (((C)+(L))%SQLITE_FUNC_HASH_SZ) |
| 16047 | 16172 | |
| 16048 | 16173 | #ifdef SQLITE_USER_AUTHENTICATION |
| 16049 | 16174 | /* |
| 16050 | 16175 | ** Information held in the "sqlite3" database connection object and used |
| 16051 | 16176 | ** to manage user authentication. |
| | @@ -16102,11 +16227,11 @@ |
| 16102 | 16227 | CollSeq *pDfltColl; /* The default collating sequence (BINARY) */ |
| 16103 | 16228 | sqlite3_mutex *mutex; /* Connection mutex */ |
| 16104 | 16229 | Db *aDb; /* All backends */ |
| 16105 | 16230 | int nDb; /* Number of backends currently in use */ |
| 16106 | 16231 | u32 mDbFlags; /* flags recording internal state */ |
| 16107 | | - u32 flags; /* flags settable by pragmas. See below */ |
| 16232 | + u64 flags; /* flags settable by pragmas. See below */ |
| 16108 | 16233 | i64 lastRowid; /* ROWID of most recent insert (see above) */ |
| 16109 | 16234 | i64 szMmap; /* Default mmap_size setting */ |
| 16110 | 16235 | u32 nSchemaLock; /* Do not reset the schema when non-zero */ |
| 16111 | 16236 | unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
| 16112 | 16237 | int errCode; /* Most recent error code (SQLITE_*) */ |
| | @@ -16268,18 +16393,21 @@ |
| 16268 | 16393 | #define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */ |
| 16269 | 16394 | #define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee*/ |
| 16270 | 16395 | #define SQLITE_TriggerEQP 0x01000000 /* Show trigger EXPLAIN QUERY PLAN */ |
| 16271 | 16396 | #define SQLITE_ResetDatabase 0x02000000 /* Reset the database */ |
| 16272 | 16397 | #define SQLITE_LegacyAlter 0x04000000 /* Legacy ALTER TABLE behaviour */ |
| 16398 | +#define SQLITE_NoSchemaError 0x08000000 /* Do not report schema parse errors*/ |
| 16399 | +#define SQLITE_Defensive 0x10000000 /* Input SQL is likely hostile */ |
| 16273 | 16400 | |
| 16274 | 16401 | /* Flags used only if debugging */ |
| 16402 | +#define HI(X) ((u64)(X)<<32) |
| 16275 | 16403 | #ifdef SQLITE_DEBUG |
| 16276 | | -#define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */ |
| 16277 | | -#define SQLITE_VdbeListing 0x10000000 /* Debug listings of VDBE programs */ |
| 16278 | | -#define SQLITE_VdbeTrace 0x20000000 /* True to trace VDBE execution */ |
| 16279 | | -#define SQLITE_VdbeAddopTrace 0x40000000 /* Trace sqlite3VdbeAddOp() calls */ |
| 16280 | | -#define SQLITE_VdbeEQP 0x80000000 /* Debug EXPLAIN QUERY PLAN */ |
| 16404 | +#define SQLITE_SqlTrace HI(0x0001) /* Debug print SQL as it executes */ |
| 16405 | +#define SQLITE_VdbeListing HI(0x0002) /* Debug listings of VDBE progs */ |
| 16406 | +#define SQLITE_VdbeTrace HI(0x0004) /* True to trace VDBE execution */ |
| 16407 | +#define SQLITE_VdbeAddopTrace HI(0x0008) /* Trace sqlite3VdbeAddOp() calls */ |
| 16408 | +#define SQLITE_VdbeEQP HI(0x0010) /* Debug EXPLAIN QUERY PLAN */ |
| 16281 | 16409 | #endif |
| 16282 | 16410 | |
| 16283 | 16411 | /* |
| 16284 | 16412 | ** Allowed values for sqlite3.mDbFlags |
| 16285 | 16413 | */ |
| | @@ -16674,10 +16802,13 @@ |
| 16674 | 16802 | ** by an instance of the following structure. |
| 16675 | 16803 | */ |
| 16676 | 16804 | struct Table { |
| 16677 | 16805 | char *zName; /* Name of the table or view */ |
| 16678 | 16806 | Column *aCol; /* Information about each column */ |
| 16807 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 16808 | + Hash *pColHash; /* All columns indexed by name */ |
| 16809 | +#endif |
| 16679 | 16810 | Index *pIndex; /* List of SQL indexes on this table. */ |
| 16680 | 16811 | Select *pSelect; /* NULL for tables. Points to definition if a view. */ |
| 16681 | 16812 | FKey *pFKey; /* Linked list of all foreign keys in this table */ |
| 16682 | 16813 | char *zColAff; /* String defining the affinity of each column */ |
| 16683 | 16814 | ExprList *pCheck; /* All CHECK constraints */ |
| | @@ -16724,10 +16855,11 @@ |
| 16724 | 16855 | #define TF_NoVisibleRowid 0x0040 /* No user-visible "rowid" column */ |
| 16725 | 16856 | #define TF_OOOHidden 0x0080 /* Out-of-Order hidden columns */ |
| 16726 | 16857 | #define TF_StatsUsed 0x0100 /* Query planner decisions affected by |
| 16727 | 16858 | ** Index.aiRowLogEst[] values */ |
| 16728 | 16859 | #define TF_HasNotNull 0x0200 /* Contains NOT NULL constraints */ |
| 16860 | +#define TF_Shadow 0x0400 /* True for a shadow table */ |
| 16729 | 16861 | |
| 16730 | 16862 | /* |
| 16731 | 16863 | ** Test to see whether or not a table is a virtual table. This is |
| 16732 | 16864 | ** done as a macro so that it will be optimized out when virtual |
| 16733 | 16865 | ** table support is omitted from the build. |
| | @@ -17010,10 +17142,16 @@ |
| 17010 | 17142 | tRowcnt *anEq; /* Est. number of rows where the key equals this sample */ |
| 17011 | 17143 | tRowcnt *anLt; /* Est. number of rows where key is less than this sample */ |
| 17012 | 17144 | tRowcnt *anDLt; /* Est. number of distinct keys less than this sample */ |
| 17013 | 17145 | }; |
| 17014 | 17146 | |
| 17147 | +/* |
| 17148 | +** Possible values to use within the flags argument to sqlite3GetToken(). |
| 17149 | +*/ |
| 17150 | +#define SQLITE_TOKEN_QUOTED 0x1 /* Token is a quoted identifier. */ |
| 17151 | +#define SQLITE_TOKEN_KEYWORD 0x2 /* Token is a keyword. */ |
| 17152 | + |
| 17015 | 17153 | /* |
| 17016 | 17154 | ** Each token coming out of the lexer is an instance of |
| 17017 | 17155 | ** this structure. Tokens are also used as part of an expression. |
| 17018 | 17156 | ** |
| 17019 | 17157 | ** The memory that "z" points to is owned by other objects. Take care |
| | @@ -17191,15 +17329,15 @@ |
| 17191 | 17329 | i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 17192 | 17330 | u8 op2; /* TK_REGISTER: original value of Expr.op |
| 17193 | 17331 | ** TK_COLUMN: the value of p5 for OP_Column |
| 17194 | 17332 | ** TK_AGG_FUNCTION: nesting depth */ |
| 17195 | 17333 | AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ |
| 17196 | | - Table *pTab; /* Table for TK_COLUMN expressions. Can be NULL |
| 17197 | | - ** for a column of an index on an expression */ |
| 17198 | | -#ifndef SQLITE_OMIT_WINDOWFUNC |
| 17199 | | - Window *pWin; /* Window definition for window functions */ |
| 17200 | | -#endif |
| 17334 | + union { |
| 17335 | + Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL |
| 17336 | + ** for a column of an index on an expression */ |
| 17337 | + Window *pWin; /* TK_FUNCTION: Window definition for the func */ |
| 17338 | + } y; |
| 17201 | 17339 | }; |
| 17202 | 17340 | |
| 17203 | 17341 | /* |
| 17204 | 17342 | ** The following are the meanings of bits in the Expr.flags field. |
| 17205 | 17343 | */ |
| | @@ -17225,10 +17363,11 @@ |
| 17225 | 17363 | #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ |
| 17226 | 17364 | #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ |
| 17227 | 17365 | #define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */ |
| 17228 | 17366 | #define EP_Alias 0x400000 /* Is an alias for a result set column */ |
| 17229 | 17367 | #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */ |
| 17368 | +#define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */ |
| 17230 | 17369 | |
| 17231 | 17370 | /* |
| 17232 | 17371 | ** The EP_Propagate mask is a set of properties that automatically propagate |
| 17233 | 17372 | ** upwards into parent nodes. |
| 17234 | 17373 | */ |
| | @@ -17910,10 +18049,11 @@ |
| 17910 | 18049 | ** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION |
| 17911 | 18050 | ** OPFLAG_AUXDELETE == BTREE_AUXDELETE |
| 17912 | 18051 | */ |
| 17913 | 18052 | #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */ |
| 17914 | 18053 | /* Also used in P2 (not P5) of OP_Delete */ |
| 18054 | +#define OPFLAG_NOCHNG 0x01 /* OP_VColumn nochange for UPDATE */ |
| 17915 | 18055 | #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ |
| 17916 | 18056 | #define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */ |
| 17917 | 18057 | #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ |
| 17918 | 18058 | #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ |
| 17919 | 18059 | #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ |
| | @@ -18381,10 +18521,11 @@ |
| 18381 | 18521 | /* |
| 18382 | 18522 | ** Internal function prototypes |
| 18383 | 18523 | */ |
| 18384 | 18524 | SQLITE_PRIVATE int sqlite3StrICmp(const char*,const char*); |
| 18385 | 18525 | SQLITE_PRIVATE int sqlite3Strlen30(const char*); |
| 18526 | +#define sqlite3Strlen30NN(C) (strlen(C)&0x3fffffff) |
| 18386 | 18527 | SQLITE_PRIVATE char *sqlite3ColumnType(Column*,char*); |
| 18387 | 18528 | #define sqlite3StrNICmp sqlite3_strnicmp |
| 18388 | 18529 | |
| 18389 | 18530 | SQLITE_PRIVATE int sqlite3MallocInit(void); |
| 18390 | 18531 | SQLITE_PRIVATE void sqlite3MallocEnd(void); |
| | @@ -18497,10 +18638,11 @@ |
| 18497 | 18638 | |
| 18498 | 18639 | #if defined(SQLITE_DEBUG) |
| 18499 | 18640 | SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView*, const Expr*, u8); |
| 18500 | 18641 | SQLITE_PRIVATE void sqlite3TreeViewBareExprList(TreeView*, const ExprList*, const char*); |
| 18501 | 18642 | SQLITE_PRIVATE void sqlite3TreeViewExprList(TreeView*, const ExprList*, u8, const char*); |
| 18643 | +SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView*, const SrcList*); |
| 18502 | 18644 | SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView*, const Select*, u8); |
| 18503 | 18645 | SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView*, const With*, u8); |
| 18504 | 18646 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 18505 | 18647 | SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView*, const Window*, u8); |
| 18506 | 18648 | SQLITE_PRIVATE void sqlite3TreeViewWinFunc(TreeView*, const Window*, u8); |
| | @@ -18729,15 +18871,19 @@ |
| 18729 | 18871 | #endif |
| 18730 | 18872 | SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*); |
| 18731 | 18873 | SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*); |
| 18732 | 18874 | SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char); |
| 18733 | 18875 | SQLITE_PRIVATE int sqlite3IsRowid(const char*); |
| 18876 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 18877 | +SQLITE_PRIVATE int sqlite3IsRowidN(const char*, int); |
| 18878 | +#endif |
| 18734 | 18879 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 18735 | 18880 | Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8,int); |
| 18736 | 18881 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); |
| 18737 | 18882 | SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); |
| 18738 | 18883 | SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); |
| 18884 | +SQLITE_PRIVATE int sqlite3ExprReferencesUpdatedColumn(Expr*,int*,int); |
| 18739 | 18885 | SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, |
| 18740 | 18886 | u8,u8,int,int*,int*,Upsert*); |
| 18741 | 18887 | #ifdef SQLITE_ENABLE_NULL_TRIM |
| 18742 | 18888 | SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe*,Table*); |
| 18743 | 18889 | #else |
| | @@ -18754,10 +18900,13 @@ |
| 18754 | 18900 | SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3*,Expr*,int); |
| 18755 | 18901 | SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3*,ExprList*,int); |
| 18756 | 18902 | SQLITE_PRIVATE SrcList *sqlite3SrcListDup(sqlite3*,SrcList*,int); |
| 18757 | 18903 | SQLITE_PRIVATE IdList *sqlite3IdListDup(sqlite3*,IdList*); |
| 18758 | 18904 | SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3*,Select*,int); |
| 18905 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 18906 | +SQLITE_PRIVATE FuncDef *sqlite3FunctionSearchN(int,const char*,int); |
| 18907 | +#endif |
| 18759 | 18908 | SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs(FuncDef*,int); |
| 18760 | 18909 | SQLITE_PRIVATE FuncDef *sqlite3FindFunction(sqlite3*,const char*,int,u8,u8); |
| 18761 | 18910 | SQLITE_PRIVATE void sqlite3RegisterBuiltinFunctions(void); |
| 18762 | 18911 | SQLITE_PRIVATE void sqlite3RegisterDateTimeFunctions(void); |
| 18763 | 18912 | SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*); |
| | @@ -18911,10 +19060,11 @@ |
| 18911 | 19060 | SQLITE_PRIVATE int sqlite3ExprCollSeqMatch(Parse*,Expr*,Expr*); |
| 18912 | 19061 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int); |
| 18913 | 19062 | SQLITE_PRIVATE Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); |
| 18914 | 19063 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr*); |
| 18915 | 19064 | SQLITE_PRIVATE int sqlite3CheckCollSeq(Parse *, CollSeq *); |
| 19065 | +SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3*); |
| 18916 | 19066 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *, const char *); |
| 18917 | 19067 | SQLITE_PRIVATE void sqlite3VdbeSetChanges(sqlite3 *, int); |
| 18918 | 19068 | SQLITE_PRIVATE int sqlite3AddInt64(i64*,i64); |
| 18919 | 19069 | SQLITE_PRIVATE int sqlite3SubInt64(i64*,i64); |
| 18920 | 19070 | SQLITE_PRIVATE int sqlite3MulInt64(i64*,i64); |
| | @@ -18957,10 +19107,13 @@ |
| 18957 | 19107 | SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*); |
| 18958 | 19108 | SQLITE_PRIVATE void sqlite3AlterFunctions(void); |
| 18959 | 19109 | SQLITE_PRIVATE void sqlite3AlterRenameTable(Parse*, SrcList*, Token*); |
| 18960 | 19110 | SQLITE_PRIVATE void sqlite3AlterRenameColumn(Parse*, SrcList*, Token*, Token*); |
| 18961 | 19111 | SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *); |
| 19112 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 19113 | +SQLITE_PRIVATE int sqlite3GetTokenNormalized(const unsigned char *, int *, int *); |
| 19114 | +#endif |
| 18962 | 19115 | SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...); |
| 18963 | 19116 | SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int); |
| 18964 | 19117 | SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr *, int, int); |
| 18965 | 19118 | SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*); |
| 18966 | 19119 | SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p); |
| | @@ -19114,10 +19267,13 @@ |
| 19114 | 19267 | SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*); |
| 19115 | 19268 | SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*); |
| 19116 | 19269 | SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int); |
| 19117 | 19270 | SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *); |
| 19118 | 19271 | SQLITE_PRIVATE void sqlite3ParserReset(Parse*); |
| 19272 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 19273 | +SQLITE_PRIVATE void sqlite3Normalize(Vdbe*, const char*, int, u8); |
| 19274 | +#endif |
| 19119 | 19275 | SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*); |
| 19120 | 19276 | SQLITE_PRIVATE void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*); |
| 19121 | 19277 | SQLITE_PRIVATE CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *); |
| 19122 | 19278 | SQLITE_PRIVATE int sqlite3TempInMemory(const sqlite3*); |
| 19123 | 19279 | SQLITE_PRIVATE const char *sqlite3JournalModename(int); |
| | @@ -20066,10 +20222,13 @@ |
| 20066 | 20222 | bft bIsReader:1; /* True for statements that read */ |
| 20067 | 20223 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 20068 | 20224 | yDbMask lockMask; /* Subset of btreeMask that requires a lock */ |
| 20069 | 20225 | u32 aCounter[7]; /* Counters used by sqlite3_stmt_status() */ |
| 20070 | 20226 | char *zSql; /* Text of the SQL statement that generated this */ |
| 20227 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 20228 | + char *zNormSql; /* Normalization of the associated SQL statement */ |
| 20229 | +#endif |
| 20071 | 20230 | void *pFree; /* Free this when deleting the vdbe */ |
| 20072 | 20231 | VdbeFrame *pFrame; /* Parent frame */ |
| 20073 | 20232 | VdbeFrame *pDelFrame; /* List of frame objects to free on VM reset */ |
| 20074 | 20233 | int nFrame; /* Number of frames in pFrame list */ |
| 20075 | 20234 | u32 expmask; /* Binding to these vars invalidates VM */ |
| | @@ -28294,10 +28453,46 @@ |
| 28294 | 28453 | } |
| 28295 | 28454 | sqlite3TreeViewPop(pView); |
| 28296 | 28455 | } |
| 28297 | 28456 | } |
| 28298 | 28457 | |
| 28458 | +/* |
| 28459 | +** Generate a human-readable description of a SrcList object. |
| 28460 | +*/ |
| 28461 | +SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){ |
| 28462 | + int i; |
| 28463 | + for(i=0; i<pSrc->nSrc; i++){ |
| 28464 | + const struct SrcList_item *pItem = &pSrc->a[i]; |
| 28465 | + StrAccum x; |
| 28466 | + char zLine[100]; |
| 28467 | + sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
| 28468 | + sqlite3_str_appendf(&x, "{%d,*}", pItem->iCursor); |
| 28469 | + if( pItem->zDatabase ){ |
| 28470 | + sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName); |
| 28471 | + }else if( pItem->zName ){ |
| 28472 | + sqlite3_str_appendf(&x, " %s", pItem->zName); |
| 28473 | + } |
| 28474 | + if( pItem->pTab ){ |
| 28475 | + sqlite3_str_appendf(&x, " tabname=%Q", pItem->pTab->zName); |
| 28476 | + } |
| 28477 | + if( pItem->zAlias ){ |
| 28478 | + sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias); |
| 28479 | + } |
| 28480 | + if( pItem->fg.jointype & JT_LEFT ){ |
| 28481 | + sqlite3_str_appendf(&x, " LEFT-JOIN"); |
| 28482 | + } |
| 28483 | + sqlite3StrAccumFinish(&x); |
| 28484 | + sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); |
| 28485 | + if( pItem->pSelect ){ |
| 28486 | + sqlite3TreeViewSelect(pView, pItem->pSelect, 0); |
| 28487 | + } |
| 28488 | + if( pItem->fg.isTabFunc ){ |
| 28489 | + sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); |
| 28490 | + } |
| 28491 | + sqlite3TreeViewPop(pView); |
| 28492 | + } |
| 28493 | +} |
| 28299 | 28494 | |
| 28300 | 28495 | /* |
| 28301 | 28496 | ** Generate a human-readable description of a Select object. |
| 28302 | 28497 | */ |
| 28303 | 28498 | SQLITE_PRIVATE void sqlite3TreeViewSelect(TreeView *pView, const Select *p, u8 moreToFollow){ |
| | @@ -28348,43 +28543,13 @@ |
| 28348 | 28543 | } |
| 28349 | 28544 | sqlite3TreeViewPop(pView); |
| 28350 | 28545 | } |
| 28351 | 28546 | #endif |
| 28352 | 28547 | if( p->pSrc && p->pSrc->nSrc ){ |
| 28353 | | - int i; |
| 28354 | 28548 | pView = sqlite3TreeViewPush(pView, (n--)>0); |
| 28355 | 28549 | sqlite3TreeViewLine(pView, "FROM"); |
| 28356 | | - for(i=0; i<p->pSrc->nSrc; i++){ |
| 28357 | | - struct SrcList_item *pItem = &p->pSrc->a[i]; |
| 28358 | | - StrAccum x; |
| 28359 | | - char zLine[100]; |
| 28360 | | - sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0); |
| 28361 | | - sqlite3_str_appendf(&x, "{%d,*}", pItem->iCursor); |
| 28362 | | - if( pItem->zDatabase ){ |
| 28363 | | - sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName); |
| 28364 | | - }else if( pItem->zName ){ |
| 28365 | | - sqlite3_str_appendf(&x, " %s", pItem->zName); |
| 28366 | | - } |
| 28367 | | - if( pItem->pTab ){ |
| 28368 | | - sqlite3_str_appendf(&x, " tabname=%Q", pItem->pTab->zName); |
| 28369 | | - } |
| 28370 | | - if( pItem->zAlias ){ |
| 28371 | | - sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias); |
| 28372 | | - } |
| 28373 | | - if( pItem->fg.jointype & JT_LEFT ){ |
| 28374 | | - sqlite3_str_appendf(&x, " LEFT-JOIN"); |
| 28375 | | - } |
| 28376 | | - sqlite3StrAccumFinish(&x); |
| 28377 | | - sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1); |
| 28378 | | - if( pItem->pSelect ){ |
| 28379 | | - sqlite3TreeViewSelect(pView, pItem->pSelect, 0); |
| 28380 | | - } |
| 28381 | | - if( pItem->fg.isTabFunc ){ |
| 28382 | | - sqlite3TreeViewExprList(pView, pItem->u1.pFuncArg, 0, "func-args:"); |
| 28383 | | - } |
| 28384 | | - sqlite3TreeViewPop(pView); |
| 28385 | | - } |
| 28550 | + sqlite3TreeViewSrcList(pView, p->pSrc); |
| 28386 | 28551 | sqlite3TreeViewPop(pView); |
| 28387 | 28552 | } |
| 28388 | 28553 | if( p->pWhere ){ |
| 28389 | 28554 | sqlite3TreeViewItem(pView, "WHERE", (n--)>0); |
| 28390 | 28555 | sqlite3TreeViewExpr(pView, p->pWhere, 0); |
| | @@ -28670,11 +28835,11 @@ |
| 28670 | 28835 | pFarg = 0; |
| 28671 | 28836 | pWin = 0; |
| 28672 | 28837 | }else{ |
| 28673 | 28838 | pFarg = pExpr->x.pList; |
| 28674 | 28839 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 28675 | | - pWin = pExpr->pWin; |
| 28840 | + pWin = pExpr->y.pWin; |
| 28676 | 28841 | #else |
| 28677 | 28842 | pWin = 0; |
| 28678 | 28843 | #endif |
| 28679 | 28844 | } |
| 28680 | 28845 | if( pExpr->op==TK_AGG_FUNCTION ){ |
| | @@ -31498,10 +31663,24 @@ |
| 31498 | 31663 | h += sqlite3UpperToLower[c]; |
| 31499 | 31664 | h *= 0x9e3779b1; |
| 31500 | 31665 | } |
| 31501 | 31666 | return h; |
| 31502 | 31667 | } |
| 31668 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 31669 | +static unsigned int strHashN(const char *z, int n){ |
| 31670 | + unsigned int h = 0; |
| 31671 | + int i; |
| 31672 | + for(i=0; i<n; i++){ |
| 31673 | + /* Knuth multiplicative hashing. (Sorting & Searching, p. 510). |
| 31674 | + ** 0x9e3779b1 is 2654435761 which is the closest prime number to |
| 31675 | + ** (2**32)*golden_ratio, where golden_ratio = (sqrt(5) - 1)/2. */ |
| 31676 | + h += sqlite3UpperToLower[z[i]]; |
| 31677 | + h *= 0x9e3779b1; |
| 31678 | + } |
| 31679 | + return h; |
| 31680 | +} |
| 31681 | +#endif /* SQLITE_ENABLE_NORMALIZE */ |
| 31503 | 31682 | |
| 31504 | 31683 | |
| 31505 | 31684 | /* Link pNew element into the hash table pH. If pEntry!=0 then also |
| 31506 | 31685 | ** insert pNew into the pEntry hash bucket. |
| 31507 | 31686 | */ |
| | @@ -31609,10 +31788,44 @@ |
| 31609 | 31788 | } |
| 31610 | 31789 | elem = elem->next; |
| 31611 | 31790 | } |
| 31612 | 31791 | return &nullElement; |
| 31613 | 31792 | } |
| 31793 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 31794 | +static HashElem *findElementWithHashN( |
| 31795 | + const Hash *pH, /* The pH to be searched */ |
| 31796 | + const char *pKey, /* The key we are searching for */ |
| 31797 | + int nKey, /* Number of key bytes to use */ |
| 31798 | + unsigned int *pHash /* Write the hash value here */ |
| 31799 | +){ |
| 31800 | + HashElem *elem; /* Used to loop thru the element list */ |
| 31801 | + int count; /* Number of elements left to test */ |
| 31802 | + unsigned int h; /* The computed hash */ |
| 31803 | + static HashElem nullElement = { 0, 0, 0, 0 }; |
| 31804 | + |
| 31805 | + if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/ |
| 31806 | + struct _ht *pEntry; |
| 31807 | + h = strHashN(pKey, nKey) % pH->htsize; |
| 31808 | + pEntry = &pH->ht[h]; |
| 31809 | + elem = pEntry->chain; |
| 31810 | + count = pEntry->count; |
| 31811 | + }else{ |
| 31812 | + h = 0; |
| 31813 | + elem = pH->first; |
| 31814 | + count = pH->count; |
| 31815 | + } |
| 31816 | + if( pHash ) *pHash = h; |
| 31817 | + while( count-- ){ |
| 31818 | + assert( elem!=0 ); |
| 31819 | + if( sqlite3StrNICmp(elem->pKey,pKey,nKey)==0 ){ |
| 31820 | + return elem; |
| 31821 | + } |
| 31822 | + elem = elem->next; |
| 31823 | + } |
| 31824 | + return &nullElement; |
| 31825 | +} |
| 31826 | +#endif /* SQLITE_ENABLE_NORMALIZE */ |
| 31614 | 31827 | |
| 31615 | 31828 | /* Remove a single entry from the hash table given a pointer to that |
| 31616 | 31829 | ** element and a hash on the element's key. |
| 31617 | 31830 | */ |
| 31618 | 31831 | static void removeElementGivenHash( |
| | @@ -31653,10 +31866,18 @@ |
| 31653 | 31866 | SQLITE_PRIVATE void *sqlite3HashFind(const Hash *pH, const char *pKey){ |
| 31654 | 31867 | assert( pH!=0 ); |
| 31655 | 31868 | assert( pKey!=0 ); |
| 31656 | 31869 | return findElementWithHash(pH, pKey, 0)->data; |
| 31657 | 31870 | } |
| 31871 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 31872 | +SQLITE_PRIVATE void *sqlite3HashFindN(const Hash *pH, const char *pKey, int nKey){ |
| 31873 | + assert( pH!=0 ); |
| 31874 | + assert( pKey!=0 ); |
| 31875 | + assert( nKey>=0 ); |
| 31876 | + return findElementWithHashN(pH, pKey, nKey, 0)->data; |
| 31877 | +} |
| 31878 | +#endif /* SQLITE_ENABLE_NORMALIZE */ |
| 31658 | 31879 | |
| 31659 | 31880 | /* Insert an element into the hash table pH. The key is pKey |
| 31660 | 31881 | ** and the data is "data". |
| 31661 | 31882 | ** |
| 31662 | 31883 | ** If no element exists with a matching key, then a new |
| | @@ -32035,16 +32256,14 @@ |
| 32035 | 32256 | ** Allowed values of unixFile.fsFlags |
| 32036 | 32257 | */ |
| 32037 | 32258 | #define SQLITE_FSFLAGS_IS_MSDOS 0x1 |
| 32038 | 32259 | |
| 32039 | 32260 | /* |
| 32040 | | -** If we are to be thread-safe, include the pthreads header and define |
| 32041 | | -** the SQLITE_UNIX_THREADS macro. |
| 32261 | +** If we are to be thread-safe, include the pthreads header. |
| 32042 | 32262 | */ |
| 32043 | 32263 | #if SQLITE_THREADSAFE |
| 32044 | 32264 | /* # include <pthread.h> */ |
| 32045 | | -# define SQLITE_UNIX_THREADS 1 |
| 32046 | 32265 | #endif |
| 32047 | 32266 | |
| 32048 | 32267 | /* |
| 32049 | 32268 | ** Default permissions when creating a new file |
| 32050 | 32269 | */ |
| | @@ -33216,12 +33435,11 @@ |
| 33216 | 33435 | #endif |
| 33217 | 33436 | }; |
| 33218 | 33437 | |
| 33219 | 33438 | /* |
| 33220 | 33439 | ** An instance of the following structure is allocated for each open |
| 33221 | | -** inode. Or, on LinuxThreads, there is one of these structures for |
| 33222 | | -** each inode opened by each thread. |
| 33440 | +** inode. |
| 33223 | 33441 | ** |
| 33224 | 33442 | ** A single inode can have multiple file descriptors, so each unixFile |
| 33225 | 33443 | ** structure contains a pointer to an instance of this object and this |
| 33226 | 33444 | ** object keeps a count of the number of unixFile pointing to it. |
| 33227 | 33445 | ** |
| | @@ -33263,17 +33481,20 @@ |
| 33263 | 33481 | #endif |
| 33264 | 33482 | }; |
| 33265 | 33483 | |
| 33266 | 33484 | /* |
| 33267 | 33485 | ** A lists of all unixInodeInfo objects. |
| 33486 | +** |
| 33487 | +** Must hold unixBigLock in order to read or write this variable. |
| 33268 | 33488 | */ |
| 33269 | 33489 | static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */ |
| 33270 | 33490 | |
| 33271 | 33491 | #ifdef SQLITE_DEBUG |
| 33272 | 33492 | /* |
| 33273 | | -** True if the inode mutex is held, or not. Used only within assert() |
| 33274 | | -** to help verify correct mutex usage. |
| 33493 | +** True if the inode mutex (on the unixFile.pFileMutex field) is held, or not. |
| 33494 | +** This routine is used only within assert() to help verify correct mutex |
| 33495 | +** usage. |
| 33275 | 33496 | */ |
| 33276 | 33497 | int unixFileMutexHeld(unixFile *pFile){ |
| 33277 | 33498 | assert( pFile->pInode ); |
| 33278 | 33499 | return sqlite3_mutex_held(pFile->pInode->pLockMutex); |
| 33279 | 33500 | } |
| | @@ -33397,12 +33618,12 @@ |
| 33397 | 33618 | } |
| 33398 | 33619 | |
| 33399 | 33620 | /* |
| 33400 | 33621 | ** Release a unixInodeInfo structure previously allocated by findInodeInfo(). |
| 33401 | 33622 | ** |
| 33402 | | -** The mutex entered using the unixEnterMutex() function must be held |
| 33403 | | -** when this function is called. |
| 33623 | +** The global mutex must be held when this routine is called, but the mutex |
| 33624 | +** on the inode being deleted must NOT be held. |
| 33404 | 33625 | */ |
| 33405 | 33626 | static void releaseInodeInfo(unixFile *pFile){ |
| 33406 | 33627 | unixInodeInfo *pInode = pFile->pInode; |
| 33407 | 33628 | assert( unixMutexHeld() ); |
| 33408 | 33629 | assert( unixFileMutexNotheld(pFile) ); |
| | @@ -33433,12 +33654,11 @@ |
| 33433 | 33654 | /* |
| 33434 | 33655 | ** Given a file descriptor, locate the unixInodeInfo object that |
| 33435 | 33656 | ** describes that file descriptor. Create a new one if necessary. The |
| 33436 | 33657 | ** return value might be uninitialized if an error occurs. |
| 33437 | 33658 | ** |
| 33438 | | -** The mutex entered using the unixEnterMutex() function must be held |
| 33439 | | -** when this function is called. |
| 33659 | +** The global mutex must held when calling this routine. |
| 33440 | 33660 | ** |
| 33441 | 33661 | ** Return an appropriate error code. |
| 33442 | 33662 | */ |
| 33443 | 33663 | static int findInodeInfo( |
| 33444 | 33664 | unixFile *pFile, /* Unix file with file desc used in the key */ |
| | @@ -33495,10 +33715,11 @@ |
| 33495 | 33715 | #if OS_VXWORKS |
| 33496 | 33716 | fileId.pId = pFile->pId; |
| 33497 | 33717 | #else |
| 33498 | 33718 | fileId.ino = (u64)statbuf.st_ino; |
| 33499 | 33719 | #endif |
| 33720 | + assert( unixMutexHeld() ); |
| 33500 | 33721 | pInode = inodeList; |
| 33501 | 33722 | while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ |
| 33502 | 33723 | pInode = pInode->pNext; |
| 33503 | 33724 | } |
| 33504 | 33725 | if( pInode==0 ){ |
| | @@ -33514,10 +33735,11 @@ |
| 33514 | 33735 | sqlite3_free(pInode); |
| 33515 | 33736 | return SQLITE_NOMEM_BKPT; |
| 33516 | 33737 | } |
| 33517 | 33738 | } |
| 33518 | 33739 | pInode->nRef = 1; |
| 33740 | + assert( unixMutexHeld() ); |
| 33519 | 33741 | pInode->pNext = inodeList; |
| 33520 | 33742 | pInode->pPrev = 0; |
| 33521 | 33743 | if( inodeList ) inodeList->pPrev = pInode; |
| 33522 | 33744 | inodeList = pInode; |
| 33523 | 33745 | }else{ |
| | @@ -36311,22 +36533,22 @@ |
| 36311 | 36533 | ** |
| 36312 | 36534 | ** nRef |
| 36313 | 36535 | ** |
| 36314 | 36536 | ** The following fields are read-only after the object is created: |
| 36315 | 36537 | ** |
| 36316 | | -** fid |
| 36538 | +** hShm |
| 36317 | 36539 | ** zFilename |
| 36318 | 36540 | ** |
| 36319 | | -** Either unixShmNode.mutex must be held or unixShmNode.nRef==0 and |
| 36541 | +** Either unixShmNode.pShmMutex must be held or unixShmNode.nRef==0 and |
| 36320 | 36542 | ** unixMutexHeld() is true when reading or writing any other field |
| 36321 | 36543 | ** in this structure. |
| 36322 | 36544 | */ |
| 36323 | 36545 | struct unixShmNode { |
| 36324 | 36546 | unixInodeInfo *pInode; /* unixInodeInfo that owns this SHM node */ |
| 36325 | | - sqlite3_mutex *mutex; /* Mutex to access this object */ |
| 36547 | + sqlite3_mutex *pShmMutex; /* Mutex to access this object */ |
| 36326 | 36548 | char *zFilename; /* Name of the mmapped file */ |
| 36327 | | - int h; /* Open file descriptor */ |
| 36549 | + int hShm; /* Open file descriptor */ |
| 36328 | 36550 | int szRegion; /* Size of shared-memory regions */ |
| 36329 | 36551 | u16 nRegion; /* Size of array apRegion */ |
| 36330 | 36552 | u8 isReadonly; /* True if read-only */ |
| 36331 | 36553 | u8 isUnlocked; /* True if no DMS lock held */ |
| 36332 | 36554 | char **apRegion; /* Array of mapped shared-memory regions */ |
| | @@ -36344,20 +36566,20 @@ |
| 36344 | 36566 | ** open shared memory connection. |
| 36345 | 36567 | ** |
| 36346 | 36568 | ** The following fields are initialized when this object is created and |
| 36347 | 36569 | ** are read-only thereafter: |
| 36348 | 36570 | ** |
| 36349 | | -** unixShm.pFile |
| 36571 | +** unixShm.pShmNode |
| 36350 | 36572 | ** unixShm.id |
| 36351 | 36573 | ** |
| 36352 | | -** All other fields are read/write. The unixShm.pFile->mutex must be held |
| 36353 | | -** while accessing any read/write fields. |
| 36574 | +** All other fields are read/write. The unixShm.pShmNode->pShmMutex must |
| 36575 | +** be held while accessing any read/write fields. |
| 36354 | 36576 | */ |
| 36355 | 36577 | struct unixShm { |
| 36356 | 36578 | unixShmNode *pShmNode; /* The underlying unixShmNode object */ |
| 36357 | 36579 | unixShm *pNext; /* Next unixShm with the same unixShmNode */ |
| 36358 | | - u8 hasMutex; /* True if holding the unixShmNode mutex */ |
| 36580 | + u8 hasMutex; /* True if holding the unixShmNode->pShmMutex */ |
| 36359 | 36581 | u8 id; /* Id of this connection within its unixShmNode */ |
| 36360 | 36582 | u16 sharedMask; /* Mask of shared locks held */ |
| 36361 | 36583 | u16 exclMask; /* Mask of exclusive locks held */ |
| 36362 | 36584 | }; |
| 36363 | 36585 | |
| | @@ -36383,25 +36605,26 @@ |
| 36383 | 36605 | struct flock f; /* The posix advisory locking structure */ |
| 36384 | 36606 | int rc = SQLITE_OK; /* Result code form fcntl() */ |
| 36385 | 36607 | |
| 36386 | 36608 | /* Access to the unixShmNode object is serialized by the caller */ |
| 36387 | 36609 | pShmNode = pFile->pInode->pShmNode; |
| 36388 | | - assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->mutex) ); |
| 36610 | + assert( pShmNode->nRef==0 || sqlite3_mutex_held(pShmNode->pShmMutex) ); |
| 36611 | + assert( pShmNode->nRef>0 || unixMutexHeld() ); |
| 36389 | 36612 | |
| 36390 | 36613 | /* Shared locks never span more than one byte */ |
| 36391 | 36614 | assert( n==1 || lockType!=F_RDLCK ); |
| 36392 | 36615 | |
| 36393 | 36616 | /* Locks are within range */ |
| 36394 | 36617 | assert( n>=1 && n<=SQLITE_SHM_NLOCK ); |
| 36395 | 36618 | |
| 36396 | | - if( pShmNode->h>=0 ){ |
| 36619 | + if( pShmNode->hShm>=0 ){ |
| 36397 | 36620 | /* Initialize the locking parameters */ |
| 36398 | 36621 | f.l_type = lockType; |
| 36399 | 36622 | f.l_whence = SEEK_SET; |
| 36400 | 36623 | f.l_start = ofst; |
| 36401 | 36624 | f.l_len = n; |
| 36402 | | - rc = osSetPosixAdvisoryLock(pShmNode->h, &f, pFile); |
| 36625 | + rc = osSetPosixAdvisoryLock(pShmNode->hShm, &f, pFile); |
| 36403 | 36626 | rc = (rc!=(-1)) ? SQLITE_OK : SQLITE_BUSY; |
| 36404 | 36627 | } |
| 36405 | 36628 | |
| 36406 | 36629 | /* Update the global lock state and do debug tracing */ |
| 36407 | 36630 | #ifdef SQLITE_DEBUG |
| | @@ -36469,22 +36692,22 @@ |
| 36469 | 36692 | assert( unixMutexHeld() ); |
| 36470 | 36693 | if( p && ALWAYS(p->nRef==0) ){ |
| 36471 | 36694 | int nShmPerMap = unixShmRegionPerMap(); |
| 36472 | 36695 | int i; |
| 36473 | 36696 | assert( p->pInode==pFd->pInode ); |
| 36474 | | - sqlite3_mutex_free(p->mutex); |
| 36697 | + sqlite3_mutex_free(p->pShmMutex); |
| 36475 | 36698 | for(i=0; i<p->nRegion; i+=nShmPerMap){ |
| 36476 | | - if( p->h>=0 ){ |
| 36699 | + if( p->hShm>=0 ){ |
| 36477 | 36700 | osMunmap(p->apRegion[i], p->szRegion); |
| 36478 | 36701 | }else{ |
| 36479 | 36702 | sqlite3_free(p->apRegion[i]); |
| 36480 | 36703 | } |
| 36481 | 36704 | } |
| 36482 | 36705 | sqlite3_free(p->apRegion); |
| 36483 | | - if( p->h>=0 ){ |
| 36484 | | - robust_close(pFd, p->h, __LINE__); |
| 36485 | | - p->h = -1; |
| 36706 | + if( p->hShm>=0 ){ |
| 36707 | + robust_close(pFd, p->hShm, __LINE__); |
| 36708 | + p->hShm = -1; |
| 36486 | 36709 | } |
| 36487 | 36710 | p->pInode->pShmNode = 0; |
| 36488 | 36711 | sqlite3_free(p); |
| 36489 | 36712 | } |
| 36490 | 36713 | } |
| | @@ -36522,19 +36745,24 @@ |
| 36522 | 36745 | ** system crash, the database itself may also become corrupt. */ |
| 36523 | 36746 | lock.l_whence = SEEK_SET; |
| 36524 | 36747 | lock.l_start = UNIX_SHM_DMS; |
| 36525 | 36748 | lock.l_len = 1; |
| 36526 | 36749 | lock.l_type = F_WRLCK; |
| 36527 | | - if( osFcntl(pShmNode->h, F_GETLK, &lock)!=0 ) { |
| 36750 | + if( osFcntl(pShmNode->hShm, F_GETLK, &lock)!=0 ) { |
| 36528 | 36751 | rc = SQLITE_IOERR_LOCK; |
| 36529 | 36752 | }else if( lock.l_type==F_UNLCK ){ |
| 36530 | 36753 | if( pShmNode->isReadonly ){ |
| 36531 | 36754 | pShmNode->isUnlocked = 1; |
| 36532 | 36755 | rc = SQLITE_READONLY_CANTINIT; |
| 36533 | 36756 | }else{ |
| 36534 | 36757 | rc = unixShmSystemLock(pDbFd, F_WRLCK, UNIX_SHM_DMS, 1); |
| 36535 | | - if( rc==SQLITE_OK && robust_ftruncate(pShmNode->h, 0) ){ |
| 36758 | + /* The first connection to attach must truncate the -shm file. We |
| 36759 | + ** truncate to 3 bytes (an arbitrary small number, less than the |
| 36760 | + ** -shm header size) rather than 0 as a system debugging aid, to |
| 36761 | + ** help detect if a -shm file truncation is legitimate or is the work |
| 36762 | + ** or a rogue process. */ |
| 36763 | + if( rc==SQLITE_OK && robust_ftruncate(pShmNode->hShm, 3) ){ |
| 36536 | 36764 | rc = unixLogError(SQLITE_IOERR_SHMOPEN,"ftruncate",pShmNode->zFilename); |
| 36537 | 36765 | } |
| 36538 | 36766 | } |
| 36539 | 36767 | }else if( lock.l_type==F_WRLCK ){ |
| 36540 | 36768 | rc = SQLITE_BUSY; |
| | @@ -36636,28 +36864,28 @@ |
| 36636 | 36864 | (u32)sStat.st_ino, (u32)sStat.st_dev); |
| 36637 | 36865 | #else |
| 36638 | 36866 | sqlite3_snprintf(nShmFilename, zShm, "%s-shm", zBasePath); |
| 36639 | 36867 | sqlite3FileSuffix3(pDbFd->zPath, zShm); |
| 36640 | 36868 | #endif |
| 36641 | | - pShmNode->h = -1; |
| 36869 | + pShmNode->hShm = -1; |
| 36642 | 36870 | pDbFd->pInode->pShmNode = pShmNode; |
| 36643 | 36871 | pShmNode->pInode = pDbFd->pInode; |
| 36644 | 36872 | if( sqlite3GlobalConfig.bCoreMutex ){ |
| 36645 | | - pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| 36646 | | - if( pShmNode->mutex==0 ){ |
| 36873 | + pShmNode->pShmMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| 36874 | + if( pShmNode->pShmMutex==0 ){ |
| 36647 | 36875 | rc = SQLITE_NOMEM_BKPT; |
| 36648 | 36876 | goto shm_open_err; |
| 36649 | 36877 | } |
| 36650 | 36878 | } |
| 36651 | 36879 | |
| 36652 | 36880 | if( pInode->bProcessLock==0 ){ |
| 36653 | 36881 | if( 0==sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ |
| 36654 | | - pShmNode->h = robust_open(zShm, O_RDWR|O_CREAT, (sStat.st_mode&0777)); |
| 36882 | + pShmNode->hShm = robust_open(zShm, O_RDWR|O_CREAT,(sStat.st_mode&0777)); |
| 36655 | 36883 | } |
| 36656 | | - if( pShmNode->h<0 ){ |
| 36657 | | - pShmNode->h = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777)); |
| 36658 | | - if( pShmNode->h<0 ){ |
| 36884 | + if( pShmNode->hShm<0 ){ |
| 36885 | + pShmNode->hShm = robust_open(zShm, O_RDONLY, (sStat.st_mode&0777)); |
| 36886 | + if( pShmNode->hShm<0 ){ |
| 36659 | 36887 | rc = unixLogError(SQLITE_CANTOPEN_BKPT, "open", zShm); |
| 36660 | 36888 | goto shm_open_err; |
| 36661 | 36889 | } |
| 36662 | 36890 | pShmNode->isReadonly = 1; |
| 36663 | 36891 | } |
| | @@ -36664,11 +36892,11 @@ |
| 36664 | 36892 | |
| 36665 | 36893 | /* If this process is running as root, make sure that the SHM file |
| 36666 | 36894 | ** is owned by the same user that owns the original database. Otherwise, |
| 36667 | 36895 | ** the original owner will not be able to connect. |
| 36668 | 36896 | */ |
| 36669 | | - robustFchown(pShmNode->h, sStat.st_uid, sStat.st_gid); |
| 36897 | + robustFchown(pShmNode->hShm, sStat.st_uid, sStat.st_gid); |
| 36670 | 36898 | |
| 36671 | 36899 | rc = unixLockSharedMemory(pDbFd, pShmNode); |
| 36672 | 36900 | if( rc!=SQLITE_OK && rc!=SQLITE_READONLY_CANTINIT ) goto shm_open_err; |
| 36673 | 36901 | } |
| 36674 | 36902 | } |
| | @@ -36684,17 +36912,17 @@ |
| 36684 | 36912 | |
| 36685 | 36913 | /* The reference count on pShmNode has already been incremented under |
| 36686 | 36914 | ** the cover of the unixEnterMutex() mutex and the pointer from the |
| 36687 | 36915 | ** new (struct unixShm) object to the pShmNode has been set. All that is |
| 36688 | 36916 | ** left to do is to link the new object into the linked list starting |
| 36689 | | - ** at pShmNode->pFirst. This must be done while holding the pShmNode->mutex |
| 36690 | | - ** mutex. |
| 36917 | + ** at pShmNode->pFirst. This must be done while holding the |
| 36918 | + ** pShmNode->pShmMutex. |
| 36691 | 36919 | */ |
| 36692 | | - sqlite3_mutex_enter(pShmNode->mutex); |
| 36920 | + sqlite3_mutex_enter(pShmNode->pShmMutex); |
| 36693 | 36921 | p->pNext = pShmNode->pFirst; |
| 36694 | 36922 | pShmNode->pFirst = p; |
| 36695 | | - sqlite3_mutex_leave(pShmNode->mutex); |
| 36923 | + sqlite3_mutex_leave(pShmNode->pShmMutex); |
| 36696 | 36924 | return rc; |
| 36697 | 36925 | |
| 36698 | 36926 | /* Jump here on any error */ |
| 36699 | 36927 | shm_open_err: |
| 36700 | 36928 | unixShmPurge(pDbFd); /* This call frees pShmNode if required */ |
| | @@ -36742,20 +36970,20 @@ |
| 36742 | 36970 | if( rc!=SQLITE_OK ) return rc; |
| 36743 | 36971 | } |
| 36744 | 36972 | |
| 36745 | 36973 | p = pDbFd->pShm; |
| 36746 | 36974 | pShmNode = p->pShmNode; |
| 36747 | | - sqlite3_mutex_enter(pShmNode->mutex); |
| 36975 | + sqlite3_mutex_enter(pShmNode->pShmMutex); |
| 36748 | 36976 | if( pShmNode->isUnlocked ){ |
| 36749 | 36977 | rc = unixLockSharedMemory(pDbFd, pShmNode); |
| 36750 | 36978 | if( rc!=SQLITE_OK ) goto shmpage_out; |
| 36751 | 36979 | pShmNode->isUnlocked = 0; |
| 36752 | 36980 | } |
| 36753 | 36981 | assert( szRegion==pShmNode->szRegion || pShmNode->nRegion==0 ); |
| 36754 | 36982 | assert( pShmNode->pInode==pDbFd->pInode ); |
| 36755 | | - assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 ); |
| 36756 | | - assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 ); |
| 36983 | + assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); |
| 36984 | + assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); |
| 36757 | 36985 | |
| 36758 | 36986 | /* Minimum number of regions required to be mapped. */ |
| 36759 | 36987 | nReqRegion = ((iRegion+nShmPerMap) / nShmPerMap) * nShmPerMap; |
| 36760 | 36988 | |
| 36761 | 36989 | if( pShmNode->nRegion<nReqRegion ){ |
| | @@ -36763,16 +36991,16 @@ |
| 36763 | 36991 | int nByte = nReqRegion*szRegion; /* Minimum required file size */ |
| 36764 | 36992 | struct stat sStat; /* Used by fstat() */ |
| 36765 | 36993 | |
| 36766 | 36994 | pShmNode->szRegion = szRegion; |
| 36767 | 36995 | |
| 36768 | | - if( pShmNode->h>=0 ){ |
| 36996 | + if( pShmNode->hShm>=0 ){ |
| 36769 | 36997 | /* The requested region is not mapped into this processes address space. |
| 36770 | 36998 | ** Check to see if it has been allocated (i.e. if the wal-index file is |
| 36771 | 36999 | ** large enough to contain the requested region). |
| 36772 | 37000 | */ |
| 36773 | | - if( osFstat(pShmNode->h, &sStat) ){ |
| 37001 | + if( osFstat(pShmNode->hShm, &sStat) ){ |
| 36774 | 37002 | rc = SQLITE_IOERR_SHMSIZE; |
| 36775 | 37003 | goto shmpage_out; |
| 36776 | 37004 | } |
| 36777 | 37005 | |
| 36778 | 37006 | if( sStat.st_size<nByte ){ |
| | @@ -36796,11 +37024,11 @@ |
| 36796 | 37024 | |
| 36797 | 37025 | /* Write to the last byte of each newly allocated or extended page */ |
| 36798 | 37026 | assert( (nByte % pgsz)==0 ); |
| 36799 | 37027 | for(iPg=(sStat.st_size/pgsz); iPg<(nByte/pgsz); iPg++){ |
| 36800 | 37028 | int x = 0; |
| 36801 | | - if( seekAndWriteFd(pShmNode->h, iPg*pgsz + pgsz-1, "", 1, &x)!=1 ){ |
| 37029 | + if( seekAndWriteFd(pShmNode->hShm, iPg*pgsz + pgsz-1,"",1,&x)!=1 ){ |
| 36802 | 37030 | const char *zFile = pShmNode->zFilename; |
| 36803 | 37031 | rc = unixLogError(SQLITE_IOERR_SHMSIZE, "write", zFile); |
| 36804 | 37032 | goto shmpage_out; |
| 36805 | 37033 | } |
| 36806 | 37034 | } |
| | @@ -36819,26 +37047,26 @@ |
| 36819 | 37047 | pShmNode->apRegion = apNew; |
| 36820 | 37048 | while( pShmNode->nRegion<nReqRegion ){ |
| 36821 | 37049 | int nMap = szRegion*nShmPerMap; |
| 36822 | 37050 | int i; |
| 36823 | 37051 | void *pMem; |
| 36824 | | - if( pShmNode->h>=0 ){ |
| 37052 | + if( pShmNode->hShm>=0 ){ |
| 36825 | 37053 | pMem = osMmap(0, nMap, |
| 36826 | 37054 | pShmNode->isReadonly ? PROT_READ : PROT_READ|PROT_WRITE, |
| 36827 | | - MAP_SHARED, pShmNode->h, szRegion*(i64)pShmNode->nRegion |
| 37055 | + MAP_SHARED, pShmNode->hShm, szRegion*(i64)pShmNode->nRegion |
| 36828 | 37056 | ); |
| 36829 | 37057 | if( pMem==MAP_FAILED ){ |
| 36830 | 37058 | rc = unixLogError(SQLITE_IOERR_SHMMAP, "mmap", pShmNode->zFilename); |
| 36831 | 37059 | goto shmpage_out; |
| 36832 | 37060 | } |
| 36833 | 37061 | }else{ |
| 36834 | | - pMem = sqlite3_malloc64(szRegion); |
| 37062 | + pMem = sqlite3_malloc64(nMap); |
| 36835 | 37063 | if( pMem==0 ){ |
| 36836 | 37064 | rc = SQLITE_NOMEM_BKPT; |
| 36837 | 37065 | goto shmpage_out; |
| 36838 | 37066 | } |
| 36839 | | - memset(pMem, 0, szRegion); |
| 37067 | + memset(pMem, 0, nMap); |
| 36840 | 37068 | } |
| 36841 | 37069 | |
| 36842 | 37070 | for(i=0; i<nShmPerMap; i++){ |
| 36843 | 37071 | pShmNode->apRegion[pShmNode->nRegion+i] = &((char*)pMem)[szRegion*i]; |
| 36844 | 37072 | } |
| | @@ -36851,11 +37079,11 @@ |
| 36851 | 37079 | *pp = pShmNode->apRegion[iRegion]; |
| 36852 | 37080 | }else{ |
| 36853 | 37081 | *pp = 0; |
| 36854 | 37082 | } |
| 36855 | 37083 | if( pShmNode->isReadonly && rc==SQLITE_OK ) rc = SQLITE_READONLY; |
| 36856 | | - sqlite3_mutex_leave(pShmNode->mutex); |
| 37084 | + sqlite3_mutex_leave(pShmNode->pShmMutex); |
| 36857 | 37085 | return rc; |
| 36858 | 37086 | } |
| 36859 | 37087 | |
| 36860 | 37088 | /* |
| 36861 | 37089 | ** Change the lock state for a shared-memory segment. |
| | @@ -36885,16 +37113,16 @@ |
| 36885 | 37113 | assert( flags==(SQLITE_SHM_LOCK | SQLITE_SHM_SHARED) |
| 36886 | 37114 | || flags==(SQLITE_SHM_LOCK | SQLITE_SHM_EXCLUSIVE) |
| 36887 | 37115 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_SHARED) |
| 36888 | 37116 | || flags==(SQLITE_SHM_UNLOCK | SQLITE_SHM_EXCLUSIVE) ); |
| 36889 | 37117 | assert( n==1 || (flags & SQLITE_SHM_EXCLUSIVE)!=0 ); |
| 36890 | | - assert( pShmNode->h>=0 || pDbFd->pInode->bProcessLock==1 ); |
| 36891 | | - assert( pShmNode->h<0 || pDbFd->pInode->bProcessLock==0 ); |
| 37118 | + assert( pShmNode->hShm>=0 || pDbFd->pInode->bProcessLock==1 ); |
| 37119 | + assert( pShmNode->hShm<0 || pDbFd->pInode->bProcessLock==0 ); |
| 36892 | 37120 | |
| 36893 | 37121 | mask = (1<<(ofst+n)) - (1<<ofst); |
| 36894 | 37122 | assert( n>1 || mask==(1<<ofst) ); |
| 36895 | | - sqlite3_mutex_enter(pShmNode->mutex); |
| 37123 | + sqlite3_mutex_enter(pShmNode->pShmMutex); |
| 36896 | 37124 | if( flags & SQLITE_SHM_UNLOCK ){ |
| 36897 | 37125 | u16 allMask = 0; /* Mask of locks held by siblings */ |
| 36898 | 37126 | |
| 36899 | 37127 | /* See if any siblings hold this same lock */ |
| 36900 | 37128 | for(pX=pShmNode->pFirst; pX; pX=pX->pNext){ |
| | @@ -36963,11 +37191,11 @@ |
| 36963 | 37191 | assert( (p->sharedMask & mask)==0 ); |
| 36964 | 37192 | p->exclMask |= mask; |
| 36965 | 37193 | } |
| 36966 | 37194 | } |
| 36967 | 37195 | } |
| 36968 | | - sqlite3_mutex_leave(pShmNode->mutex); |
| 37196 | + sqlite3_mutex_leave(pShmNode->pShmMutex); |
| 36969 | 37197 | OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n", |
| 36970 | 37198 | p->id, osGetpid(0), p->sharedMask, p->exclMask)); |
| 36971 | 37199 | return rc; |
| 36972 | 37200 | } |
| 36973 | 37201 | |
| | @@ -37013,27 +37241,27 @@ |
| 37013 | 37241 | assert( pShmNode==pDbFd->pInode->pShmNode ); |
| 37014 | 37242 | assert( pShmNode->pInode==pDbFd->pInode ); |
| 37015 | 37243 | |
| 37016 | 37244 | /* Remove connection p from the set of connections associated |
| 37017 | 37245 | ** with pShmNode */ |
| 37018 | | - sqlite3_mutex_enter(pShmNode->mutex); |
| 37246 | + sqlite3_mutex_enter(pShmNode->pShmMutex); |
| 37019 | 37247 | for(pp=&pShmNode->pFirst; (*pp)!=p; pp = &(*pp)->pNext){} |
| 37020 | 37248 | *pp = p->pNext; |
| 37021 | 37249 | |
| 37022 | 37250 | /* Free the connection p */ |
| 37023 | 37251 | sqlite3_free(p); |
| 37024 | 37252 | pDbFd->pShm = 0; |
| 37025 | | - sqlite3_mutex_leave(pShmNode->mutex); |
| 37253 | + sqlite3_mutex_leave(pShmNode->pShmMutex); |
| 37026 | 37254 | |
| 37027 | 37255 | /* If pShmNode->nRef has reached 0, then close the underlying |
| 37028 | 37256 | ** shared-memory file, too */ |
| 37029 | 37257 | assert( unixFileMutexNotheld(pDbFd) ); |
| 37030 | 37258 | unixEnterMutex(); |
| 37031 | 37259 | assert( pShmNode->nRef>0 ); |
| 37032 | 37260 | pShmNode->nRef--; |
| 37033 | 37261 | if( pShmNode->nRef==0 ){ |
| 37034 | | - if( deleteFlag && pShmNode->h>=0 ){ |
| 37262 | + if( deleteFlag && pShmNode->hShm>=0 ){ |
| 37035 | 37263 | osUnlink(pShmNode->zFilename); |
| 37036 | 37264 | } |
| 37037 | 37265 | unixShmPurge(pDbFd); |
| 37038 | 37266 | } |
| 37039 | 37267 | unixLeaveMutex(); |
| | @@ -47321,11 +47549,11 @@ |
| 47321 | 47549 | ** pDirtyTail to the last (oldest). |
| 47322 | 47550 | ** |
| 47323 | 47551 | ** The PCache.pSynced variable is used to optimize searching for a dirty |
| 47324 | 47552 | ** page to eject from the cache mid-transaction. It is better to eject |
| 47325 | 47553 | ** a page that does not require a journal sync than one that does. |
| 47326 | | -** Therefore, pSynced is maintained to that it *almost* always points |
| 47554 | +** Therefore, pSynced is maintained so that it *almost* always points |
| 47327 | 47555 | ** to either the oldest page in the pDirty/pDirtyTail list that has a |
| 47328 | 47556 | ** clear PGHDR_NEED_SYNC flag or to a page that is older than this one |
| 47329 | 47557 | ** (so that the right page to eject can be found by following pDirtyPrev |
| 47330 | 47558 | ** pointers). |
| 47331 | 47559 | */ |
| | @@ -57104,10 +57332,11 @@ |
| 57104 | 57332 | void *(*xCodec)(void*,void*,Pgno,int), |
| 57105 | 57333 | void (*xCodecSizeChng)(void*,int,int), |
| 57106 | 57334 | void (*xCodecFree)(void*), |
| 57107 | 57335 | void *pCodec |
| 57108 | 57336 | ){ |
| 57337 | + pager_reset(pPager); |
| 57109 | 57338 | if( pPager->xCodecFree ) pPager->xCodecFree(pPager->pCodec); |
| 57110 | 57339 | pPager->xCodec = pPager->memDb ? 0 : xCodec; |
| 57111 | 57340 | pPager->xCodecSizeChng = xCodecSizeChng; |
| 57112 | 57341 | pPager->xCodecFree = xCodecFree; |
| 57113 | 57342 | pPager->pCodec = pCodec; |
| | @@ -65764,11 +65993,11 @@ |
| 65764 | 65993 | freeTempSpace(pBt); |
| 65765 | 65994 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, |
| 65766 | 65995 | pageSize-usableSize); |
| 65767 | 65996 | return rc; |
| 65768 | 65997 | } |
| 65769 | | - if( (pBt->db->flags & SQLITE_WriteSchema)==0 && nPage>nPageFile ){ |
| 65998 | + if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){ |
| 65770 | 65999 | rc = SQLITE_CORRUPT_BKPT; |
| 65771 | 66000 | goto page1_init_failed; |
| 65772 | 66001 | } |
| 65773 | 66002 | /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to |
| 65774 | 66003 | ** be less than 480. In other words, if the page size is 512, then the |
| | @@ -66238,10 +66467,11 @@ |
| 66238 | 66467 | |
| 66239 | 66468 | assert( eType==PTRMAP_OVERFLOW2 || eType==PTRMAP_OVERFLOW1 || |
| 66240 | 66469 | eType==PTRMAP_BTREE || eType==PTRMAP_ROOTPAGE ); |
| 66241 | 66470 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 66242 | 66471 | assert( pDbPage->pBt==pBt ); |
| 66472 | + if( iDbPage<3 ) return SQLITE_CORRUPT_BKPT; |
| 66243 | 66473 | |
| 66244 | 66474 | /* Move page iDbPage from its current location to page number iFreePage */ |
| 66245 | 66475 | TRACE(("AUTOVACUUM: Moving %d to free page %d (ptr page %d type %d)\n", |
| 66246 | 66476 | iDbPage, iFreePage, iPtrPage, eType)); |
| 66247 | 66477 | rc = sqlite3PagerMovepage(pPager, pDbPage->pDbPage, iFreePage, isCommit); |
| | @@ -74033,11 +74263,12 @@ |
| 74033 | 74263 | sqlite3_snprintf(nByte, pMem->z, "%lld", pMem->u.i); |
| 74034 | 74264 | }else{ |
| 74035 | 74265 | assert( fg & MEM_Real ); |
| 74036 | 74266 | sqlite3_snprintf(nByte, pMem->z, "%!.15g", pMem->u.r); |
| 74037 | 74267 | } |
| 74038 | | - pMem->n = sqlite3Strlen30(pMem->z); |
| 74268 | + assert( pMem->z!=0 ); |
| 74269 | + pMem->n = sqlite3Strlen30NN(pMem->z); |
| 74039 | 74270 | pMem->enc = SQLITE_UTF8; |
| 74040 | 74271 | pMem->flags |= MEM_Str|MEM_Term; |
| 74041 | 74272 | if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real); |
| 74042 | 74273 | sqlite3VdbeChangeEncoding(pMem, enc); |
| 74043 | 74274 | return SQLITE_OK; |
| | @@ -75608,10 +75839,17 @@ |
| 75608 | 75839 | if( (prepFlags & SQLITE_PREPARE_SAVESQL)==0 ){ |
| 75609 | 75840 | p->expmask = 0; |
| 75610 | 75841 | } |
| 75611 | 75842 | assert( p->zSql==0 ); |
| 75612 | 75843 | p->zSql = sqlite3DbStrNDup(p->db, z, n); |
| 75844 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 75845 | + assert( p->zNormSql==0 ); |
| 75846 | + if( p->zSql && (prepFlags & SQLITE_PREPARE_NORMALIZE)!=0 ){ |
| 75847 | + sqlite3Normalize(p, p->zSql, n, prepFlags); |
| 75848 | + assert( p->zNormSql!=0 || p->db->mallocFailed ); |
| 75849 | + } |
| 75850 | +#endif |
| 75613 | 75851 | } |
| 75614 | 75852 | |
| 75615 | 75853 | /* |
| 75616 | 75854 | ** Swap all content between two VDBE structures. |
| 75617 | 75855 | */ |
| | @@ -75629,10 +75867,15 @@ |
| 75629 | 75867 | pA->pPrev = pB->pPrev; |
| 75630 | 75868 | pB->pPrev = pTmp; |
| 75631 | 75869 | zTmp = pA->zSql; |
| 75632 | 75870 | pA->zSql = pB->zSql; |
| 75633 | 75871 | pB->zSql = zTmp; |
| 75872 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 75873 | + zTmp = pA->zNormSql; |
| 75874 | + pA->zNormSql = pB->zNormSql; |
| 75875 | + pB->zNormSql = zTmp; |
| 75876 | +#endif |
| 75634 | 75877 | pB->expmask = pA->expmask; |
| 75635 | 75878 | pB->prepFlags = pA->prepFlags; |
| 75636 | 75879 | memcpy(pB->aCounter, pA->aCounter, sizeof(pB->aCounter)); |
| 75637 | 75880 | pB->aCounter[SQLITE_STMTSTATUS_REPREPARE]++; |
| 75638 | 75881 | } |
| | @@ -78700,10 +78943,13 @@ |
| 78700 | 78943 | sqlite3DbFree(db, p->pFree); |
| 78701 | 78944 | } |
| 78702 | 78945 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 78703 | 78946 | sqlite3DbFree(db, p->aColName); |
| 78704 | 78947 | sqlite3DbFree(db, p->zSql); |
| 78948 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 78949 | + sqlite3DbFree(db, p->zNormSql); |
| 78950 | +#endif |
| 78705 | 78951 | #ifdef SQLITE_ENABLE_STMT_SCANSTATUS |
| 78706 | 78952 | { |
| 78707 | 78953 | int i; |
| 78708 | 78954 | for(i=0; i<p->nScan; i++){ |
| 78709 | 78955 | sqlite3DbFree(db, p->aScan[i].zName); |
| | @@ -80101,11 +80347,13 @@ |
| 80101 | 80347 | |
| 80102 | 80348 | /* The index entry must begin with a header size */ |
| 80103 | 80349 | (void)getVarint32((u8*)m.z, szHdr); |
| 80104 | 80350 | testcase( szHdr==3 ); |
| 80105 | 80351 | testcase( szHdr==m.n ); |
| 80106 | | - if( unlikely(szHdr<3 || (int)szHdr>m.n) ){ |
| 80352 | + testcase( szHdr>0x7fffffff ); |
| 80353 | + assert( m.n>=0 ); |
| 80354 | + if( unlikely(szHdr<3 || szHdr>(unsigned)m.n) ){ |
| 80107 | 80355 | goto idx_rowid_corruption; |
| 80108 | 80356 | } |
| 80109 | 80357 | |
| 80110 | 80358 | /* The last field of the index should be an integer - the ROWID. |
| 80111 | 80359 | ** Verify that the last entry really is an integer. */ |
| | @@ -82112,10 +82360,20 @@ |
| 82112 | 82360 | } |
| 82113 | 82361 | return z; |
| 82114 | 82362 | #endif |
| 82115 | 82363 | } |
| 82116 | 82364 | |
| 82365 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 82366 | +/* |
| 82367 | +** Return the normalized SQL associated with a prepared statement. |
| 82368 | +*/ |
| 82369 | +SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt){ |
| 82370 | + Vdbe *p = (Vdbe *)pStmt; |
| 82371 | + return p ? p->zNormSql : 0; |
| 82372 | +} |
| 82373 | +#endif /* SQLITE_ENABLE_NORMALIZE */ |
| 82374 | + |
| 82117 | 82375 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 82118 | 82376 | /* |
| 82119 | 82377 | ** Allocate and populate an UnpackedRecord structure based on the serialized |
| 82120 | 82378 | ** record in nKey/pKey. Return a pointer to the new UnpackedRecord structure |
| 82121 | 82379 | ** if successful, or a NULL pointer if an OOM error is encountered. |
| | @@ -85551,21 +85809,29 @@ |
| 85551 | 85809 | nVarint = sqlite3VarintLen(nHdr); |
| 85552 | 85810 | nHdr += nVarint; |
| 85553 | 85811 | if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; |
| 85554 | 85812 | } |
| 85555 | 85813 | nByte = nHdr+nData; |
| 85556 | | - if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 85557 | | - goto too_big; |
| 85558 | | - } |
| 85559 | 85814 | |
| 85560 | 85815 | /* Make sure the output register has a buffer large enough to store |
| 85561 | 85816 | ** the new record. The output register (pOp->p3) is not allowed to |
| 85562 | 85817 | ** be one of the input registers (because the following call to |
| 85563 | 85818 | ** sqlite3VdbeMemClearAndResize() could clobber the value before it is used). |
| 85564 | 85819 | */ |
| 85565 | | - if( sqlite3VdbeMemClearAndResize(pOut, (int)nByte) ){ |
| 85566 | | - goto no_mem; |
| 85820 | + if( nByte+nZero<=pOut->szMalloc ){ |
| 85821 | + /* The output register is already large enough to hold the record. |
| 85822 | + ** No error checks or buffer enlargement is required */ |
| 85823 | + pOut->z = pOut->zMalloc; |
| 85824 | + }else{ |
| 85825 | + /* Need to make sure that the output is not too big and then enlarge |
| 85826 | + ** the output register to hold the full result */ |
| 85827 | + if( nByte+nZero>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 85828 | + goto too_big; |
| 85829 | + } |
| 85830 | + if( sqlite3VdbeMemClearAndResize(pOut, (int)nByte) ){ |
| 85831 | + goto no_mem; |
| 85832 | + } |
| 85567 | 85833 | } |
| 85568 | 85834 | zNewRecord = (u8 *)pOut->z; |
| 85569 | 85835 | |
| 85570 | 85836 | /* Write the record */ |
| 85571 | 85837 | i = putVarint32(zNewRecord, nHdr); |
| | @@ -88417,11 +88683,11 @@ |
| 88417 | 88683 | }else |
| 88418 | 88684 | #endif |
| 88419 | 88685 | { |
| 88420 | 88686 | zMaster = MASTER_NAME; |
| 88421 | 88687 | initData.db = db; |
| 88422 | | - initData.iDb = pOp->p1; |
| 88688 | + initData.iDb = iDb; |
| 88423 | 88689 | initData.pzErrMsg = &p->zErrMsg; |
| 88424 | 88690 | initData.mInitFlags = 0; |
| 88425 | 88691 | zSql = sqlite3MPrintf(db, |
| 88426 | 88692 | "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid", |
| 88427 | 88693 | db->aDb[iDb].zDbSName, zMaster, pOp->p4.z); |
| | @@ -89614,14 +89880,15 @@ |
| 89614 | 89880 | ** Store in register P3 the value of the P2-th column of |
| 89615 | 89881 | ** the current row of the virtual-table of cursor P1. |
| 89616 | 89882 | ** |
| 89617 | 89883 | ** If the VColumn opcode is being used to fetch the value of |
| 89618 | 89884 | ** an unchanging column during an UPDATE operation, then the P5 |
| 89619 | | -** value is 1. Otherwise, P5 is 0. The P5 value is returned |
| 89620 | | -** by sqlite3_vtab_nochange() routine and can be used |
| 89621 | | -** by virtual table implementations to return special "no-change" |
| 89622 | | -** marks which can be more efficient, depending on the virtual table. |
| 89885 | +** value is OPFLAG_NOCHNG. This will cause the sqlite3_vtab_nochange() |
| 89886 | +** function to return true inside the xColumn method of the virtual |
| 89887 | +** table implementation. The P5 column might also contain other |
| 89888 | +** bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are |
| 89889 | +** unused by OP_VColumn. |
| 89623 | 89890 | */ |
| 89624 | 89891 | case OP_VColumn: { |
| 89625 | 89892 | sqlite3_vtab *pVtab; |
| 89626 | 89893 | const sqlite3_module *pModule; |
| 89627 | 89894 | Mem *pDest; |
| | @@ -89639,11 +89906,12 @@ |
| 89639 | 89906 | pVtab = pCur->uc.pVCur->pVtab; |
| 89640 | 89907 | pModule = pVtab->pModule; |
| 89641 | 89908 | assert( pModule->xColumn ); |
| 89642 | 89909 | memset(&sContext, 0, sizeof(sContext)); |
| 89643 | 89910 | sContext.pOut = pDest; |
| 89644 | | - if( pOp->p5 ){ |
| 89911 | + testcase( (pOp->p5 & OPFLAG_NOCHNG)==0 && pOp->p5!=0 ); |
| 89912 | + if( pOp->p5 & OPFLAG_NOCHNG ){ |
| 89645 | 89913 | sqlite3VdbeMemSetNull(pDest); |
| 89646 | 89914 | pDest->flags = MEM_Null|MEM_Zero; |
| 89647 | 89915 | pDest->u.nZero = 0; |
| 89648 | 89916 | }else{ |
| 89649 | 89917 | MemSetTypeFlag(pDest, MEM_Null); |
| | @@ -93998,12 +94266,12 @@ |
| 93998 | 94266 | if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort; |
| 93999 | 94267 | }else if( pExpr->x.pList ){ |
| 94000 | 94268 | if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort; |
| 94001 | 94269 | } |
| 94002 | 94270 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 94003 | | - if( !ExprHasProperty(pExpr, EP_Reduced) && pExpr->pWin ){ |
| 94004 | | - Window *pWin = pExpr->pWin; |
| 94271 | + if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 94272 | + Window *pWin = pExpr->y.pWin; |
| 94005 | 94273 | if( sqlite3WalkExprList(pWalker, pWin->pPartition) ) return WRC_Abort; |
| 94006 | 94274 | if( sqlite3WalkExprList(pWalker, pWin->pOrderBy) ) return WRC_Abort; |
| 94007 | 94275 | if( sqlite3WalkExpr(pWalker, pWin->pFilter) ) return WRC_Abort; |
| 94008 | 94276 | } |
| 94009 | 94277 | #endif |
| | @@ -94272,11 +94540,11 @@ |
| 94272 | 94540 | ** |
| 94273 | 94541 | ** pExpr->iDb Set the index in db->aDb[] of the database X |
| 94274 | 94542 | ** (even if X is implied). |
| 94275 | 94543 | ** pExpr->iTable Set to the cursor number for the table obtained |
| 94276 | 94544 | ** from pSrcList. |
| 94277 | | -** pExpr->pTab Points to the Table structure of X.Y (even if |
| 94545 | +** pExpr->y.pTab Points to the Table structure of X.Y (even if |
| 94278 | 94546 | ** X and/or Y are implied.) |
| 94279 | 94547 | ** pExpr->iColumn Set to the column number within the table. |
| 94280 | 94548 | ** pExpr->op Set to TK_COLUMN. |
| 94281 | 94549 | ** pExpr->pLeft Any expression this points to is deleted |
| 94282 | 94550 | ** pExpr->pRight Any expression this points to is deleted. |
| | @@ -94316,11 +94584,10 @@ |
| 94316 | 94584 | assert( zCol ); /* The Z in X.Y.Z cannot be NULL */ |
| 94317 | 94585 | assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) ); |
| 94318 | 94586 | |
| 94319 | 94587 | /* Initialize the node to no-match */ |
| 94320 | 94588 | pExpr->iTable = -1; |
| 94321 | | - pExpr->pTab = 0; |
| 94322 | 94589 | ExprSetVVAProperty(pExpr, EP_NoReduce); |
| 94323 | 94590 | |
| 94324 | 94591 | /* Translate the schema name in zDb into a pointer to the corresponding |
| 94325 | 94592 | ** schema. If not found, pSchema will remain NULL and nothing will match |
| 94326 | 94593 | ** resulting in an appropriate error message toward the end of this routine |
| | @@ -94378,11 +94645,11 @@ |
| 94378 | 94645 | assert( zTabName!=0 ); |
| 94379 | 94646 | if( sqlite3StrICmp(zTabName, zTab)!=0 ){ |
| 94380 | 94647 | continue; |
| 94381 | 94648 | } |
| 94382 | 94649 | if( IN_RENAME_OBJECT && pItem->zAlias ){ |
| 94383 | | - sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->pTab); |
| 94650 | + sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab); |
| 94384 | 94651 | } |
| 94385 | 94652 | } |
| 94386 | 94653 | if( 0==(cntTab++) ){ |
| 94387 | 94654 | pMatch = pItem; |
| 94388 | 94655 | } |
| | @@ -94404,17 +94671,17 @@ |
| 94404 | 94671 | } |
| 94405 | 94672 | } |
| 94406 | 94673 | } |
| 94407 | 94674 | if( pMatch ){ |
| 94408 | 94675 | pExpr->iTable = pMatch->iCursor; |
| 94409 | | - pExpr->pTab = pMatch->pTab; |
| 94676 | + pExpr->y.pTab = pMatch->pTab; |
| 94410 | 94677 | /* RIGHT JOIN not (yet) supported */ |
| 94411 | 94678 | assert( (pMatch->fg.jointype & JT_RIGHT)==0 ); |
| 94412 | 94679 | if( (pMatch->fg.jointype & JT_LEFT)!=0 ){ |
| 94413 | 94680 | ExprSetProperty(pExpr, EP_CanBeNull); |
| 94414 | 94681 | } |
| 94415 | | - pSchema = pExpr->pTab->pSchema; |
| 94682 | + pSchema = pExpr->y.pTab->pSchema; |
| 94416 | 94683 | } |
| 94417 | 94684 | } /* if( pSrcList ) */ |
| 94418 | 94685 | |
| 94419 | 94686 | #if !defined(SQLITE_OMIT_TRIGGER) || !defined(SQLITE_OMIT_UPSERT) |
| 94420 | 94687 | /* If we have not already resolved the name, then maybe |
| | @@ -94467,11 +94734,11 @@ |
| 94467 | 94734 | #ifndef SQLITE_OMIT_UPSERT |
| 94468 | 94735 | if( pExpr->iTable==2 ){ |
| 94469 | 94736 | testcase( iCol==(-1) ); |
| 94470 | 94737 | if( IN_RENAME_OBJECT ){ |
| 94471 | 94738 | pExpr->iColumn = iCol; |
| 94472 | | - pExpr->pTab = pTab; |
| 94739 | + pExpr->y.pTab = pTab; |
| 94473 | 94740 | eNewExprOp = TK_COLUMN; |
| 94474 | 94741 | }else{ |
| 94475 | 94742 | pExpr->iTable = pNC->uNC.pUpsert->regData + iCol; |
| 94476 | 94743 | eNewExprOp = TK_REGISTER; |
| 94477 | 94744 | ExprSetProperty(pExpr, EP_Alias); |
| | @@ -94489,11 +94756,11 @@ |
| 94489 | 94756 | }else{ |
| 94490 | 94757 | testcase( iCol==31 ); |
| 94491 | 94758 | testcase( iCol==32 ); |
| 94492 | 94759 | pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol)); |
| 94493 | 94760 | } |
| 94494 | | - pExpr->pTab = pTab; |
| 94761 | + pExpr->y.pTab = pTab; |
| 94495 | 94762 | pExpr->iColumn = (i16)iCol; |
| 94496 | 94763 | eNewExprOp = TK_TRIGGER; |
| 94497 | 94764 | #endif /* SQLITE_OMIT_TRIGGER */ |
| 94498 | 94765 | } |
| 94499 | 94766 | } |
| | @@ -94589,11 +94856,11 @@ |
| 94589 | 94856 | */ |
| 94590 | 94857 | if( cnt==0 && zTab==0 ){ |
| 94591 | 94858 | assert( pExpr->op==TK_ID ); |
| 94592 | 94859 | if( ExprHasProperty(pExpr,EP_DblQuoted) ){ |
| 94593 | 94860 | pExpr->op = TK_STRING; |
| 94594 | | - pExpr->pTab = 0; |
| 94861 | + pExpr->y.pTab = 0; |
| 94595 | 94862 | return WRC_Prune; |
| 94596 | 94863 | } |
| 94597 | 94864 | if( sqlite3ExprIdToTrueFalse(pExpr) ){ |
| 94598 | 94865 | return WRC_Prune; |
| 94599 | 94866 | } |
| | @@ -94667,13 +94934,13 @@ |
| 94667 | 94934 | */ |
| 94668 | 94935 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *db, SrcList *pSrc, int iSrc, int iCol){ |
| 94669 | 94936 | Expr *p = sqlite3ExprAlloc(db, TK_COLUMN, 0, 0); |
| 94670 | 94937 | if( p ){ |
| 94671 | 94938 | struct SrcList_item *pItem = &pSrc->a[iSrc]; |
| 94672 | | - p->pTab = pItem->pTab; |
| 94939 | + p->y.pTab = pItem->pTab; |
| 94673 | 94940 | p->iTable = pItem->iCursor; |
| 94674 | | - if( p->pTab->iPKey==iCol ){ |
| 94941 | + if( p->y.pTab->iPKey==iCol ){ |
| 94675 | 94942 | p->iColumn = -1; |
| 94676 | 94943 | }else{ |
| 94677 | 94944 | p->iColumn = (ynVar)iCol; |
| 94678 | 94945 | testcase( iCol==BMS ); |
| 94679 | 94946 | testcase( iCol==BMS-1 ); |
| | @@ -94759,11 +95026,11 @@ |
| 94759 | 95026 | struct SrcList_item *pItem; |
| 94760 | 95027 | assert( pSrcList && pSrcList->nSrc==1 ); |
| 94761 | 95028 | pItem = pSrcList->a; |
| 94762 | 95029 | assert( HasRowid(pItem->pTab) && pItem->pTab->pSelect==0 ); |
| 94763 | 95030 | pExpr->op = TK_COLUMN; |
| 94764 | | - pExpr->pTab = pItem->pTab; |
| 95031 | + pExpr->y.pTab = pItem->pTab; |
| 94765 | 95032 | pExpr->iTable = pItem->iCursor; |
| 94766 | 95033 | pExpr->iColumn = -1; |
| 94767 | 95034 | pExpr->affinity = SQLITE_AFF_INTEGER; |
| 94768 | 95035 | break; |
| 94769 | 95036 | } |
| | @@ -94803,13 +95070,11 @@ |
| 94803 | 95070 | } |
| 94804 | 95071 | zTable = pLeft->u.zToken; |
| 94805 | 95072 | zColumn = pRight->u.zToken; |
| 94806 | 95073 | if( IN_RENAME_OBJECT ){ |
| 94807 | 95074 | sqlite3RenameTokenRemap(pParse, (void*)pExpr, (void*)pRight); |
| 94808 | | - } |
| 94809 | | - if( IN_RENAME_OBJECT ){ |
| 94810 | | - sqlite3RenameTokenRemap(pParse, (void*)&pExpr->pTab, (void*)pLeft); |
| 95075 | + sqlite3RenameTokenRemap(pParse, (void*)&pExpr->y.pTab, (void*)pLeft); |
| 94811 | 95076 | } |
| 94812 | 95077 | } |
| 94813 | 95078 | return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr); |
| 94814 | 95079 | } |
| 94815 | 95080 | |
| | @@ -94895,22 +95160,22 @@ |
| 94895 | 95160 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 94896 | 95161 | assert( is_agg==0 || (pDef->funcFlags & SQLITE_FUNC_MINMAX) |
| 94897 | 95162 | || (pDef->xValue==0 && pDef->xInverse==0) |
| 94898 | 95163 | || (pDef->xValue && pDef->xInverse && pDef->xSFunc && pDef->xFinalize) |
| 94899 | 95164 | ); |
| 94900 | | - if( pDef && pDef->xValue==0 && pExpr->pWin ){ |
| 95165 | + if( pDef && pDef->xValue==0 && ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 94901 | 95166 | sqlite3ErrorMsg(pParse, |
| 94902 | 95167 | "%.*s() may not be used as a window function", nId, zId |
| 94903 | 95168 | ); |
| 94904 | 95169 | pNC->nErr++; |
| 94905 | 95170 | }else if( |
| 94906 | 95171 | (is_agg && (pNC->ncFlags & NC_AllowAgg)==0) |
| 94907 | | - || (is_agg && (pDef->funcFlags & SQLITE_FUNC_WINDOW) && !pExpr->pWin) |
| 94908 | | - || (is_agg && pExpr->pWin && (pNC->ncFlags & NC_AllowWin)==0) |
| 95172 | + || (is_agg && (pDef->funcFlags&SQLITE_FUNC_WINDOW) && !pExpr->y.pWin) |
| 95173 | + || (is_agg && pExpr->y.pWin && (pNC->ncFlags & NC_AllowWin)==0) |
| 94909 | 95174 | ){ |
| 94910 | 95175 | const char *zType; |
| 94911 | | - if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pExpr->pWin ){ |
| 95176 | + if( (pDef->funcFlags & SQLITE_FUNC_WINDOW) || pExpr->y.pWin ){ |
| 94912 | 95177 | zType = "window"; |
| 94913 | 95178 | }else{ |
| 94914 | 95179 | zType = "aggregate"; |
| 94915 | 95180 | } |
| 94916 | 95181 | sqlite3ErrorMsg(pParse, "misuse of %s function %.*s()",zType,nId,zId); |
| | @@ -94936,30 +95201,30 @@ |
| 94936 | 95201 | nId, zId); |
| 94937 | 95202 | pNC->nErr++; |
| 94938 | 95203 | } |
| 94939 | 95204 | if( is_agg ){ |
| 94940 | 95205 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 94941 | | - pNC->ncFlags &= ~(pExpr->pWin ? NC_AllowWin : NC_AllowAgg); |
| 95206 | + pNC->ncFlags &= ~(pExpr->y.pWin ? NC_AllowWin : NC_AllowAgg); |
| 94942 | 95207 | #else |
| 94943 | 95208 | pNC->ncFlags &= ~NC_AllowAgg; |
| 94944 | 95209 | #endif |
| 94945 | 95210 | } |
| 94946 | 95211 | } |
| 94947 | 95212 | sqlite3WalkExprList(pWalker, pList); |
| 94948 | 95213 | if( is_agg ){ |
| 94949 | 95214 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 94950 | | - if( pExpr->pWin ){ |
| 95215 | + if( pExpr->y.pWin ){ |
| 94951 | 95216 | Select *pSel = pNC->pWinSelect; |
| 94952 | | - sqlite3WalkExprList(pWalker, pExpr->pWin->pPartition); |
| 94953 | | - sqlite3WalkExprList(pWalker, pExpr->pWin->pOrderBy); |
| 94954 | | - sqlite3WalkExpr(pWalker, pExpr->pWin->pFilter); |
| 94955 | | - sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->pWin, pDef); |
| 95217 | + sqlite3WalkExprList(pWalker, pExpr->y.pWin->pPartition); |
| 95218 | + sqlite3WalkExprList(pWalker, pExpr->y.pWin->pOrderBy); |
| 95219 | + sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter); |
| 95220 | + sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef); |
| 94956 | 95221 | if( 0==pSel->pWin |
| 94957 | | - || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->pWin) |
| 95222 | + || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin) |
| 94958 | 95223 | ){ |
| 94959 | | - pExpr->pWin->pNextWin = pSel->pWin; |
| 94960 | | - pSel->pWin = pExpr->pWin; |
| 95224 | + pExpr->y.pWin->pNextWin = pSel->pWin; |
| 95225 | + pSel->pWin = pExpr->y.pWin; |
| 94961 | 95226 | } |
| 94962 | 95227 | pNC->ncFlags |= NC_AllowWin; |
| 94963 | 95228 | }else |
| 94964 | 95229 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 94965 | 95230 | { |
| | @@ -95378,17 +95643,17 @@ |
| 95378 | 95643 | return 1; |
| 95379 | 95644 | } |
| 95380 | 95645 | for(j=0; j<pSelect->pEList->nExpr; j++){ |
| 95381 | 95646 | if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){ |
| 95382 | 95647 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 95383 | | - if( pE->pWin ){ |
| 95648 | + if( ExprHasProperty(pE, EP_WinFunc) ){ |
| 95384 | 95649 | /* Since this window function is being changed into a reference |
| 95385 | 95650 | ** to the same window function the result set, remove the instance |
| 95386 | 95651 | ** of this window function from the Select.pWin list. */ |
| 95387 | 95652 | Window **pp; |
| 95388 | 95653 | for(pp=&pSelect->pWin; *pp; pp=&(*pp)->pNextWin){ |
| 95389 | | - if( *pp==pE->pWin ){ |
| 95654 | + if( *pp==pE->y.pWin ){ |
| 95390 | 95655 | *pp = (*pp)->pNextWin; |
| 95391 | 95656 | } |
| 95392 | 95657 | } |
| 95393 | 95658 | } |
| 95394 | 95659 | #endif |
| | @@ -95847,12 +96112,12 @@ |
| 95847 | 96112 | if( op==TK_CAST ){ |
| 95848 | 96113 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 95849 | 96114 | return sqlite3AffinityType(pExpr->u.zToken, 0); |
| 95850 | 96115 | } |
| 95851 | 96116 | #endif |
| 95852 | | - if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){ |
| 95853 | | - return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn); |
| 96117 | + if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->y.pTab ){ |
| 96118 | + return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 95854 | 96119 | } |
| 95855 | 96120 | if( op==TK_SELECT_COLUMN ){ |
| 95856 | 96121 | assert( pExpr->pLeft->flags&EP_xIsSelect ); |
| 95857 | 96122 | return sqlite3ExprAffinity( |
| 95858 | 96123 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| | @@ -95932,17 +96197,17 @@ |
| 95932 | 96197 | while( p ){ |
| 95933 | 96198 | int op = p->op; |
| 95934 | 96199 | if( p->flags & EP_Generic ) break; |
| 95935 | 96200 | if( (op==TK_AGG_COLUMN || op==TK_COLUMN |
| 95936 | 96201 | || op==TK_REGISTER || op==TK_TRIGGER) |
| 95937 | | - && p->pTab!=0 |
| 96202 | + && p->y.pTab!=0 |
| 95938 | 96203 | ){ |
| 95939 | | - /* op==TK_REGISTER && p->pTab!=0 happens when pExpr was originally |
| 96204 | + /* op==TK_REGISTER && p->y.pTab!=0 happens when pExpr was originally |
| 95940 | 96205 | ** a TK_COLUMN but was previously evaluated and cached in a register */ |
| 95941 | 96206 | int j = p->iColumn; |
| 95942 | 96207 | if( j>=0 ){ |
| 95943 | | - const char *zColl = p->pTab->aCol[j].zColl; |
| 96208 | + const char *zColl = p->y.pTab->aCol[j].zColl; |
| 95944 | 96209 | pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0); |
| 95945 | 96210 | } |
| 95946 | 96211 | break; |
| 95947 | 96212 | } |
| 95948 | 96213 | if( op==TK_CAST || op==TK_UPLUS ){ |
| | @@ -96841,10 +97106,14 @@ |
| 96841 | 97106 | */ |
| 96842 | 97107 | static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){ |
| 96843 | 97108 | assert( p!=0 ); |
| 96844 | 97109 | /* Sanity check: Assert that the IntValue is non-negative if it exists */ |
| 96845 | 97110 | assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 ); |
| 97111 | + |
| 97112 | + assert( !ExprHasProperty(p, EP_WinFunc) || p->y.pWin!=0 || db->mallocFailed ); |
| 97113 | + assert( p->op!=TK_FUNCTION || ExprHasProperty(p, EP_TokenOnly|EP_Reduced) |
| 97114 | + || p->y.pWin==0 || ExprHasProperty(p, EP_WinFunc) ); |
| 96846 | 97115 | #ifdef SQLITE_DEBUG |
| 96847 | 97116 | if( ExprHasProperty(p, EP_Leaf) && !ExprHasProperty(p, EP_TokenOnly) ){ |
| 96848 | 97117 | assert( p->pLeft==0 ); |
| 96849 | 97118 | assert( p->pRight==0 ); |
| 96850 | 97119 | assert( p->x.pSelect==0 ); |
| | @@ -96859,12 +97128,13 @@ |
| 96859 | 97128 | }else if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 96860 | 97129 | sqlite3SelectDelete(db, p->x.pSelect); |
| 96861 | 97130 | }else{ |
| 96862 | 97131 | sqlite3ExprListDelete(db, p->x.pList); |
| 96863 | 97132 | } |
| 96864 | | - if( !ExprHasProperty(p, EP_Reduced) ){ |
| 96865 | | - sqlite3WindowDelete(db, p->pWin); |
| 97133 | + if( ExprHasProperty(p, EP_WinFunc) ){ |
| 97134 | + assert( p->op==TK_FUNCTION ); |
| 97135 | + sqlite3WindowDelete(db, p->y.pWin); |
| 96866 | 97136 | } |
| 96867 | 97137 | } |
| 96868 | 97138 | if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken); |
| 96869 | 97139 | if( !ExprHasProperty(p, EP_Static) ){ |
| 96870 | 97140 | sqlite3DbFreeNN(db, p); |
| | @@ -96924,11 +97194,11 @@ |
| 96924 | 97194 | assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */ |
| 96925 | 97195 | assert( EXPR_FULLSIZE<=0xfff ); |
| 96926 | 97196 | assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 ); |
| 96927 | 97197 | if( 0==flags || p->op==TK_SELECT_COLUMN |
| 96928 | 97198 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 96929 | | - || p->pWin |
| 97199 | + || ExprHasProperty(p, EP_WinFunc) |
| 96930 | 97200 | #endif |
| 96931 | 97201 | ){ |
| 96932 | 97202 | nSize = EXPR_FULLSIZE; |
| 96933 | 97203 | }else{ |
| 96934 | 97204 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| | @@ -96951,11 +97221,11 @@ |
| 96951 | 97221 | ** string is defined.) |
| 96952 | 97222 | */ |
| 96953 | 97223 | static int dupedExprNodeSize(Expr *p, int flags){ |
| 96954 | 97224 | int nByte = dupedExprStructSize(p, flags) & 0xfff; |
| 96955 | 97225 | if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){ |
| 96956 | | - nByte += sqlite3Strlen30(p->u.zToken)+1; |
| 97226 | + nByte += sqlite3Strlen30NN(p->u.zToken)+1; |
| 96957 | 97227 | } |
| 96958 | 97228 | return ROUND8(nByte); |
| 96959 | 97229 | } |
| 96960 | 97230 | |
| 96961 | 97231 | /* |
| | @@ -97054,26 +97324,28 @@ |
| 97054 | 97324 | pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags); |
| 97055 | 97325 | } |
| 97056 | 97326 | } |
| 97057 | 97327 | |
| 97058 | 97328 | /* Fill in pNew->pLeft and pNew->pRight. */ |
| 97059 | | - zAlloc += dupedExprNodeSize(p, dupFlags); |
| 97060 | | - if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){ |
| 97329 | + if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly|EP_WinFunc) ){ |
| 97330 | + zAlloc += dupedExprNodeSize(p, dupFlags); |
| 97061 | 97331 | if( !ExprHasProperty(pNew, EP_TokenOnly|EP_Leaf) ){ |
| 97062 | 97332 | pNew->pLeft = p->pLeft ? |
| 97063 | 97333 | exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc) : 0; |
| 97064 | 97334 | pNew->pRight = p->pRight ? |
| 97065 | 97335 | exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc) : 0; |
| 97066 | 97336 | } |
| 97067 | | - }else{ |
| 97068 | 97337 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 97069 | | - if( ExprHasProperty(p, EP_Reduced|EP_TokenOnly) ){ |
| 97070 | | - pNew->pWin = 0; |
| 97071 | | - }else{ |
| 97072 | | - pNew->pWin = sqlite3WindowDup(db, pNew, p->pWin); |
| 97338 | + if( ExprHasProperty(p, EP_WinFunc) ){ |
| 97339 | + pNew->y.pWin = sqlite3WindowDup(db, pNew, p->y.pWin); |
| 97340 | + assert( ExprHasProperty(pNew, EP_WinFunc) ); |
| 97073 | 97341 | } |
| 97074 | 97342 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 97343 | + if( pzBuffer ){ |
| 97344 | + *pzBuffer = zAlloc; |
| 97345 | + } |
| 97346 | + }else{ |
| 97075 | 97347 | if( !ExprHasProperty(p, EP_TokenOnly|EP_Leaf) ){ |
| 97076 | 97348 | if( pNew->op==TK_SELECT_COLUMN ){ |
| 97077 | 97349 | pNew->pLeft = p->pLeft; |
| 97078 | 97350 | assert( p->iColumn==0 || p->pRight==0 ); |
| 97079 | 97351 | assert( p->pRight==0 || p->pRight==p->pLeft ); |
| | @@ -97081,13 +97353,10 @@ |
| 97081 | 97353 | pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0); |
| 97082 | 97354 | } |
| 97083 | 97355 | pNew->pRight = sqlite3ExprDup(db, p->pRight, 0); |
| 97084 | 97356 | } |
| 97085 | 97357 | } |
| 97086 | | - if( pzBuffer ){ |
| 97087 | | - *pzBuffer = zAlloc; |
| 97088 | | - } |
| 97089 | 97358 | } |
| 97090 | 97359 | return pNew; |
| 97091 | 97360 | } |
| 97092 | 97361 | |
| 97093 | 97362 | /* |
| | @@ -97878,12 +98147,12 @@ |
| 97878 | 98147 | case TK_FLOAT: |
| 97879 | 98148 | case TK_BLOB: |
| 97880 | 98149 | return 0; |
| 97881 | 98150 | case TK_COLUMN: |
| 97882 | 98151 | return ExprHasProperty(p, EP_CanBeNull) || |
| 97883 | | - p->pTab==0 || /* Reference to column of index on expression */ |
| 97884 | | - (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0); |
| 98152 | + p->y.pTab==0 || /* Reference to column of index on expression */ |
| 98153 | + (p->iColumn>=0 && p->y.pTab->aCol[p->iColumn].notNull==0); |
| 97885 | 98154 | default: |
| 97886 | 98155 | return 1; |
| 97887 | 98156 | } |
| 97888 | 98157 | } |
| 97889 | 98158 | |
| | @@ -97934,10 +98203,18 @@ |
| 97934 | 98203 | if( sqlite3StrICmp(z, "_ROWID_")==0 ) return 1; |
| 97935 | 98204 | if( sqlite3StrICmp(z, "ROWID")==0 ) return 1; |
| 97936 | 98205 | if( sqlite3StrICmp(z, "OID")==0 ) return 1; |
| 97937 | 98206 | return 0; |
| 97938 | 98207 | } |
| 98208 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 98209 | +SQLITE_PRIVATE int sqlite3IsRowidN(const char *z, int n){ |
| 98210 | + if( sqlite3StrNICmp(z, "_ROWID_", n)==0 ) return 1; |
| 98211 | + if( sqlite3StrNICmp(z, "ROWID", n)==0 ) return 1; |
| 98212 | + if( sqlite3StrNICmp(z, "OID", n)==0 ) return 1; |
| 98213 | + return 0; |
| 98214 | +} |
| 98215 | +#endif |
| 97939 | 98216 | |
| 97940 | 98217 | /* |
| 97941 | 98218 | ** pX is the RHS of an IN operator. If pX is a SELECT statement |
| 97942 | 98219 | ** that can be simplified to a direct table access, then return |
| 97943 | 98220 | ** a pointer to the SELECT statement. If pX is not a SELECT statement, |
| | @@ -99167,11 +99444,11 @@ |
| 99167 | 99444 | ** expresssion. However, make sure the constant has the correct |
| 99168 | 99445 | ** datatype by applying the Affinity of the table column to the |
| 99169 | 99446 | ** constant. |
| 99170 | 99447 | */ |
| 99171 | 99448 | int iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); |
| 99172 | | - int aff = sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn); |
| 99449 | + int aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn); |
| 99173 | 99450 | if( aff!=SQLITE_AFF_BLOB ){ |
| 99174 | 99451 | static const char zAff[] = "B\000C\000D\000E"; |
| 99175 | 99452 | assert( SQLITE_AFF_BLOB=='A' ); |
| 99176 | 99453 | assert( SQLITE_AFF_TEXT=='B' ); |
| 99177 | 99454 | if( iReg!=target ){ |
| | @@ -99191,11 +99468,11 @@ |
| 99191 | 99468 | /* Coding an expression that is part of an index where column names |
| 99192 | 99469 | ** in the index refer to the table to which the index belongs */ |
| 99193 | 99470 | iTab = pParse->iSelfTab - 1; |
| 99194 | 99471 | } |
| 99195 | 99472 | } |
| 99196 | | - return sqlite3ExprCodeGetColumn(pParse, pExpr->pTab, |
| 99473 | + return sqlite3ExprCodeGetColumn(pParse, pExpr->y.pTab, |
| 99197 | 99474 | pExpr->iColumn, iTab, target, |
| 99198 | 99475 | pExpr->op2); |
| 99199 | 99476 | } |
| 99200 | 99477 | case TK_INTEGER: { |
| 99201 | 99478 | codeInteger(pParse, pExpr, 0, target); |
| | @@ -99405,12 +99682,12 @@ |
| 99405 | 99682 | sqlite3 *db = pParse->db; /* The database connection */ |
| 99406 | 99683 | u8 enc = ENC(db); /* The text encoding used by this database */ |
| 99407 | 99684 | CollSeq *pColl = 0; /* A collating sequence */ |
| 99408 | 99685 | |
| 99409 | 99686 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 99410 | | - if( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) && pExpr->pWin ){ |
| 99411 | | - return pExpr->pWin->regResult; |
| 99687 | + if( ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 99688 | + return pExpr->y.pWin->regResult; |
| 99412 | 99689 | } |
| 99413 | 99690 | #endif |
| 99414 | 99691 | |
| 99415 | 99692 | if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){ |
| 99416 | 99693 | /* SQL functions can be expensive. So try to move constant functions |
| | @@ -99649,11 +99926,11 @@ |
| 99649 | 99926 | ** |
| 99650 | 99927 | ** p1==0 -> old.rowid p1==3 -> new.rowid |
| 99651 | 99928 | ** p1==1 -> old.a p1==4 -> new.a |
| 99652 | 99929 | ** p1==2 -> old.b p1==5 -> new.b |
| 99653 | 99930 | */ |
| 99654 | | - Table *pTab = pExpr->pTab; |
| 99931 | + Table *pTab = pExpr->y.pTab; |
| 99655 | 99932 | int p1 = pExpr->iTable * (pTab->nCol+1) + 1 + pExpr->iColumn; |
| 99656 | 99933 | |
| 99657 | 99934 | assert( pExpr->iTable==0 || pExpr->iTable==1 ); |
| 99658 | 99935 | assert( pExpr->iColumn>=-1 && pExpr->iColumn<pTab->nCol ); |
| 99659 | 99936 | assert( pTab->iPKey<0 || pExpr->iColumn!=pTab->iPKey ); |
| | @@ -99660,11 +99937,11 @@ |
| 99660 | 99937 | assert( p1>=0 && p1<(pTab->nCol*2+2) ); |
| 99661 | 99938 | |
| 99662 | 99939 | sqlite3VdbeAddOp2(v, OP_Param, p1, target); |
| 99663 | 99940 | VdbeComment((v, "r[%d]=%s.%s", target, |
| 99664 | 99941 | (pExpr->iTable ? "new" : "old"), |
| 99665 | | - (pExpr->iColumn<0 ? "rowid" : pExpr->pTab->aCol[pExpr->iColumn].zName) |
| 99942 | + (pExpr->iColumn<0 ? "rowid" : pExpr->y.pTab->aCol[pExpr->iColumn].zName) |
| 99666 | 99943 | )); |
| 99667 | 99944 | |
| 99668 | 99945 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 99669 | 99946 | /* If the column has REAL affinity, it may currently be stored as an |
| 99670 | 99947 | ** integer. Use OP_RealAffinity to make sure it is really real. |
| | @@ -100511,10 +100788,24 @@ |
| 100511 | 100788 | return 2; |
| 100512 | 100789 | } |
| 100513 | 100790 | if( pA->op!=TK_COLUMN && pA->op!=TK_AGG_COLUMN && pA->u.zToken ){ |
| 100514 | 100791 | if( pA->op==TK_FUNCTION ){ |
| 100515 | 100792 | if( sqlite3StrICmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; |
| 100793 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 100794 | + /* Justification for the assert(): |
| 100795 | + ** window functions have p->op==TK_FUNCTION but aggregate functions |
| 100796 | + ** have p->op==TK_AGG_FUNCTION. So any comparison between an aggregate |
| 100797 | + ** function and a window function should have failed before reaching |
| 100798 | + ** this point. And, it is not possible to have a window function and |
| 100799 | + ** a scalar function with the same name and number of arguments. So |
| 100800 | + ** if we reach this point, either A and B both window functions or |
| 100801 | + ** neither are a window functions. */ |
| 100802 | + assert( ExprHasProperty(pA,EP_WinFunc)==ExprHasProperty(pB,EP_WinFunc) ); |
| 100803 | + if( ExprHasProperty(pA,EP_WinFunc) ){ |
| 100804 | + if( sqlite3WindowCompare(pParse,pA->y.pWin,pB->y.pWin)!=0 ) return 2; |
| 100805 | + } |
| 100806 | +#endif |
| 100516 | 100807 | }else if( pA->op==TK_COLLATE ){ |
| 100517 | 100808 | if( sqlite3_stricmp(pA->u.zToken,pB->u.zToken)!=0 ) return 2; |
| 100518 | 100809 | }else if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){ |
| 100519 | 100810 | return 2; |
| 100520 | 100811 | } |
| | @@ -100530,25 +100821,10 @@ |
| 100530 | 100821 | if( pA->op!=TK_STRING && pA->op!=TK_TRUEFALSE ){ |
| 100531 | 100822 | if( pA->iColumn!=pB->iColumn ) return 2; |
| 100532 | 100823 | if( pA->iTable!=pB->iTable |
| 100533 | 100824 | && (pA->iTable!=iTab || NEVER(pB->iTable>=0)) ) return 2; |
| 100534 | 100825 | } |
| 100535 | | -#ifndef SQLITE_OMIT_WINDOWFUNC |
| 100536 | | - /* Justification for the assert(): |
| 100537 | | - ** window functions have p->op==TK_FUNCTION but aggregate functions |
| 100538 | | - ** have p->op==TK_AGG_FUNCTION. So any comparison between an aggregate |
| 100539 | | - ** function and a window function should have failed before reaching |
| 100540 | | - ** this point. And, it is not possible to have a window function and |
| 100541 | | - ** a scalar function with the same name and number of arguments. So |
| 100542 | | - ** if we reach this point, either A and B both window functions or |
| 100543 | | - ** neither are a window functions. */ |
| 100544 | | - assert( (pA->pWin==0)==(pB->pWin==0) ); |
| 100545 | | - |
| 100546 | | - if( pA->pWin!=0 ){ |
| 100547 | | - if( sqlite3WindowCompare(pParse,pA->pWin,pB->pWin)!=0 ) return 2; |
| 100548 | | - } |
| 100549 | | -#endif |
| 100550 | 100826 | } |
| 100551 | 100827 | return 0; |
| 100552 | 100828 | } |
| 100553 | 100829 | |
| 100554 | 100830 | /* |
| | @@ -100685,12 +100961,12 @@ |
| 100685 | 100961 | testcase( pExpr->op==TK_NE ); |
| 100686 | 100962 | testcase( pExpr->op==TK_LT ); |
| 100687 | 100963 | testcase( pExpr->op==TK_LE ); |
| 100688 | 100964 | testcase( pExpr->op==TK_GT ); |
| 100689 | 100965 | testcase( pExpr->op==TK_GE ); |
| 100690 | | - if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->pTab)) |
| 100691 | | - || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->pTab)) |
| 100966 | + if( (pExpr->pLeft->op==TK_COLUMN && IsVirtual(pExpr->pLeft->y.pTab)) |
| 100967 | + || (pExpr->pRight->op==TK_COLUMN && IsVirtual(pExpr->pRight->y.pTab)) |
| 100692 | 100968 | ){ |
| 100693 | 100969 | return WRC_Prune; |
| 100694 | 100970 | } |
| 100695 | 100971 | default: |
| 100696 | 100972 | return WRC_Continue; |
| | @@ -100917,11 +101193,11 @@ |
| 100917 | 101193 | } |
| 100918 | 101194 | if( (k>=pAggInfo->nColumn) |
| 100919 | 101195 | && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0 |
| 100920 | 101196 | ){ |
| 100921 | 101197 | pCol = &pAggInfo->aCol[k]; |
| 100922 | | - pCol->pTab = pExpr->pTab; |
| 101198 | + pCol->pTab = pExpr->y.pTab; |
| 100923 | 101199 | pCol->iTable = pExpr->iTable; |
| 100924 | 101200 | pCol->iColumn = pExpr->iColumn; |
| 100925 | 101201 | pCol->iMem = ++pParse->nMem; |
| 100926 | 101202 | pCol->iSorterColumn = -1; |
| 100927 | 101203 | pCol->pExpr = pExpr; |
| | @@ -101936,11 +102212,11 @@ |
| 101936 | 102212 | && pWalker->pParse->pTriggerTab==p->pTab |
| 101937 | 102213 | ){ |
| 101938 | 102214 | renameTokenFind(pWalker->pParse, p, (void*)pExpr); |
| 101939 | 102215 | }else if( pExpr->op==TK_COLUMN |
| 101940 | 102216 | && pExpr->iColumn==p->iCol |
| 101941 | | - && p->pTab==pExpr->pTab |
| 102217 | + && p->pTab==pExpr->y.pTab |
| 101942 | 102218 | ){ |
| 101943 | 102219 | renameTokenFind(pWalker->pParse, p, (void*)pExpr); |
| 101944 | 102220 | } |
| 101945 | 102221 | return WRC_Continue; |
| 101946 | 102222 | } |
| | @@ -102194,13 +102470,18 @@ |
| 102194 | 102470 | assert( pNew->pTabSchema ); |
| 102195 | 102471 | pParse->pTriggerTab = sqlite3FindTable(db, pNew->table, |
| 102196 | 102472 | db->aDb[sqlite3SchemaToIndex(db, pNew->pTabSchema)].zDbSName |
| 102197 | 102473 | ); |
| 102198 | 102474 | pParse->eTriggerOp = pNew->op; |
| 102475 | + /* ALWAYS() because if the table of the trigger does not exist, the |
| 102476 | + ** error would have been hit before this point */ |
| 102477 | + if( ALWAYS(pParse->pTriggerTab) ){ |
| 102478 | + rc = sqlite3ViewGetColumnNames(pParse, pParse->pTriggerTab); |
| 102479 | + } |
| 102199 | 102480 | |
| 102200 | 102481 | /* Resolve symbols in WHEN clause */ |
| 102201 | | - if( pNew->pWhen ){ |
| 102482 | + if( rc==SQLITE_OK && pNew->pWhen ){ |
| 102202 | 102483 | rc = sqlite3ResolveExprNames(&sNC, pNew->pWhen); |
| 102203 | 102484 | } |
| 102204 | 102485 | |
| 102205 | 102486 | for(pStep=pNew->step_list; rc==SQLITE_OK && pStep; pStep=pStep->pNext){ |
| 102206 | 102487 | if( pStep->pSelect ){ |
| | @@ -102474,12 +102755,12 @@ |
| 102474 | 102755 | /* |
| 102475 | 102756 | ** Walker expression callback used by "RENAME TABLE". |
| 102476 | 102757 | */ |
| 102477 | 102758 | static int renameTableExprCb(Walker *pWalker, Expr *pExpr){ |
| 102478 | 102759 | RenameCtx *p = pWalker->u.pRename; |
| 102479 | | - if( pExpr->op==TK_COLUMN && p->pTab==pExpr->pTab ){ |
| 102480 | | - renameTokenFind(pWalker->pParse, p, (void*)&pExpr->pTab); |
| 102760 | + if( pExpr->op==TK_COLUMN && p->pTab==pExpr->y.pTab ){ |
| 102761 | + renameTokenFind(pWalker->pParse, p, (void*)&pExpr->y.pTab); |
| 102481 | 102762 | } |
| 102482 | 102763 | return WRC_Continue; |
| 102483 | 102764 | } |
| 102484 | 102765 | |
| 102485 | 102766 | /* |
| | @@ -102572,11 +102853,11 @@ |
| 102572 | 102853 | sqlite3WalkSelect(&sWalker, pTab->pSelect); |
| 102573 | 102854 | } |
| 102574 | 102855 | }else{ |
| 102575 | 102856 | /* Modify any FK definitions to point to the new table. */ |
| 102576 | 102857 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 102577 | | - if( db->flags & SQLITE_ForeignKeys ){ |
| 102858 | + if( isLegacy==0 || (db->flags & SQLITE_ForeignKeys) ){ |
| 102578 | 102859 | FKey *pFKey; |
| 102579 | 102860 | for(pFKey=pTab->pFKey; pFKey; pFKey=pFKey->pNextFrom){ |
| 102580 | 102861 | if( sqlite3_stricmp(pFKey->zTo, zOld)==0 ){ |
| 102581 | 102862 | renameTokenFind(&sParse, &sCtx, (void*)pFKey->zTo); |
| 102582 | 102863 | } |
| | @@ -105457,10 +105738,11 @@ |
| 105457 | 105738 | int iSrc; /* Index in pTabList->a[] of table being read */ |
| 105458 | 105739 | int iDb; /* The index of the database the expression refers to */ |
| 105459 | 105740 | int iCol; /* Index of column in table */ |
| 105460 | 105741 | |
| 105461 | 105742 | assert( pExpr->op==TK_COLUMN || pExpr->op==TK_TRIGGER ); |
| 105743 | + assert( !IN_RENAME_OBJECT || db->xAuth==0 ); |
| 105462 | 105744 | if( db->xAuth==0 ) return; |
| 105463 | 105745 | iDb = sqlite3SchemaToIndex(pParse->db, pSchema); |
| 105464 | 105746 | if( iDb<0 ){ |
| 105465 | 105747 | /* An attempt to read a column out of a subquery or other |
| 105466 | 105748 | ** temporary table. */ |
| | @@ -105513,10 +105795,11 @@ |
| 105513 | 105795 | int rc; |
| 105514 | 105796 | |
| 105515 | 105797 | /* Don't do any authorization checks if the database is initialising |
| 105516 | 105798 | ** or if the parser is being invoked from within sqlite3_declare_vtab. |
| 105517 | 105799 | */ |
| 105800 | + assert( !IN_RENAME_OBJECT || db->xAuth==0 ); |
| 105518 | 105801 | if( db->init.busy || IN_SPECIAL_PARSE ){ |
| 105519 | 105802 | return SQLITE_OK; |
| 105520 | 105803 | } |
| 105521 | 105804 | |
| 105522 | 105805 | if( db->xAuth==0 ){ |
| | @@ -105936,21 +106219,19 @@ |
| 105936 | 106219 | |
| 105937 | 106220 | p = sqlite3FindTable(db, zName, zDbase); |
| 105938 | 106221 | if( p==0 ){ |
| 105939 | 106222 | const char *zMsg = flags & LOCATE_VIEW ? "no such view" : "no such table"; |
| 105940 | 106223 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 105941 | | - if( sqlite3FindDbName(db, zDbase)<1 ){ |
| 105942 | | - /* If zName is the not the name of a table in the schema created using |
| 105943 | | - ** CREATE, then check to see if it is the name of an virtual table that |
| 105944 | | - ** can be an eponymous virtual table. */ |
| 105945 | | - Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName); |
| 105946 | | - if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){ |
| 105947 | | - pMod = sqlite3PragmaVtabRegister(db, zName); |
| 105948 | | - } |
| 105949 | | - if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){ |
| 105950 | | - return pMod->pEpoTab; |
| 105951 | | - } |
| 106224 | + /* If zName is the not the name of a table in the schema created using |
| 106225 | + ** CREATE, then check to see if it is the name of an virtual table that |
| 106226 | + ** can be an eponymous virtual table. */ |
| 106227 | + Module *pMod = (Module*)sqlite3HashFind(&db->aModule, zName); |
| 106228 | + if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){ |
| 106229 | + pMod = sqlite3PragmaVtabRegister(db, zName); |
| 106230 | + } |
| 106231 | + if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){ |
| 106232 | + return pMod->pEpoTab; |
| 105952 | 106233 | } |
| 105953 | 106234 | #endif |
| 105954 | 106235 | if( (flags & LOCATE_NOERR)==0 ){ |
| 105955 | 106236 | if( zDbase ){ |
| 105956 | 106237 | sqlite3ErrorMsg(pParse, "%s: %s.%s", zMsg, zDbase, zName); |
| | @@ -106213,10 +106494,16 @@ |
| 106213 | 106494 | /* Delete any foreign keys attached to this table. */ |
| 106214 | 106495 | sqlite3FkDelete(db, pTable); |
| 106215 | 106496 | |
| 106216 | 106497 | /* Delete the Table structure itself. |
| 106217 | 106498 | */ |
| 106499 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 106500 | + if( pTable->pColHash ){ |
| 106501 | + sqlite3HashClear(pTable->pColHash); |
| 106502 | + sqlite3_free(pTable->pColHash); |
| 106503 | + } |
| 106504 | +#endif |
| 106218 | 106505 | sqlite3DeleteColumnNames(db, pTable); |
| 106219 | 106506 | sqlite3DbFree(db, pTable->zName); |
| 106220 | 106507 | sqlite3DbFree(db, pTable->zColAff); |
| 106221 | 106508 | sqlite3SelectDelete(db, pTable->pSelect); |
| 106222 | 106509 | sqlite3ExprListDelete(db, pTable->pCheck); |
| | @@ -106370,10 +106657,24 @@ |
| 106370 | 106657 | iDb = db->init.iDb; |
| 106371 | 106658 | *pUnqual = pName1; |
| 106372 | 106659 | } |
| 106373 | 106660 | return iDb; |
| 106374 | 106661 | } |
| 106662 | + |
| 106663 | +/* |
| 106664 | +** True if PRAGMA writable_schema is ON |
| 106665 | +*/ |
| 106666 | +SQLITE_PRIVATE int sqlite3WritableSchema(sqlite3 *db){ |
| 106667 | + testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==0 ); |
| 106668 | + testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))== |
| 106669 | + SQLITE_WriteSchema ); |
| 106670 | + testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))== |
| 106671 | + SQLITE_Defensive ); |
| 106672 | + testcase( (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))== |
| 106673 | + (SQLITE_WriteSchema|SQLITE_Defensive) ); |
| 106674 | + return (db->flags&(SQLITE_WriteSchema|SQLITE_Defensive))==SQLITE_WriteSchema; |
| 106675 | +} |
| 106375 | 106676 | |
| 106376 | 106677 | /* |
| 106377 | 106678 | ** This routine is used to check if the UTF-8 string zName is a legal |
| 106378 | 106679 | ** unqualified name for a new schema object (table, index, view or |
| 106379 | 106680 | ** trigger). All names are legal except those that begin with the string |
| | @@ -106380,11 +106681,11 @@ |
| 106380 | 106681 | ** "sqlite_" (in upper, lower or mixed case). This portion of the namespace |
| 106381 | 106682 | ** is reserved for internal use. |
| 106382 | 106683 | */ |
| 106383 | 106684 | SQLITE_PRIVATE int sqlite3CheckObjectName(Parse *pParse, const char *zName){ |
| 106384 | 106685 | if( !pParse->db->init.busy && pParse->nested==0 |
| 106385 | | - && (pParse->db->flags & SQLITE_WriteSchema)==0 |
| 106686 | + && sqlite3WritableSchema(pParse->db)==0 |
| 106386 | 106687 | && 0==sqlite3StrNICmp(zName, "sqlite_", 7) ){ |
| 106387 | 106688 | sqlite3ErrorMsg(pParse, "object name reserved for internal use: %s", zName); |
| 106388 | 106689 | return SQLITE_ERROR; |
| 106389 | 106690 | } |
| 106390 | 106691 | return SQLITE_OK; |
| | @@ -107455,10 +107756,36 @@ |
| 107455 | 107756 | }else{ |
| 107456 | 107757 | pPk->nColumn = pTab->nCol; |
| 107457 | 107758 | } |
| 107458 | 107759 | recomputeColumnsNotIndexed(pPk); |
| 107459 | 107760 | } |
| 107761 | + |
| 107762 | +/* |
| 107763 | +** Return true if zName is a shadow table name in the current database |
| 107764 | +** connection. |
| 107765 | +** |
| 107766 | +** zName is temporarily modified while this routine is running, but is |
| 107767 | +** restored to its original value prior to this routine returning. |
| 107768 | +*/ |
| 107769 | +static int isShadowTableName(sqlite3 *db, char *zName){ |
| 107770 | + char *zTail; /* Pointer to the last "_" in zName */ |
| 107771 | + Table *pTab; /* Table that zName is a shadow of */ |
| 107772 | + Module *pMod; /* Module for the virtual table */ |
| 107773 | + |
| 107774 | + zTail = strrchr(zName, '_'); |
| 107775 | + if( zTail==0 ) return 0; |
| 107776 | + *zTail = 0; |
| 107777 | + pTab = sqlite3FindTable(db, zName, 0); |
| 107778 | + *zTail = '_'; |
| 107779 | + if( pTab==0 ) return 0; |
| 107780 | + if( !IsVirtual(pTab) ) return 0; |
| 107781 | + pMod = (Module*)sqlite3HashFind(&db->aModule, pTab->azModuleArg[0]); |
| 107782 | + if( pMod==0 ) return 0; |
| 107783 | + if( pMod->pModule->iVersion<3 ) return 0; |
| 107784 | + if( pMod->pModule->xShadowName==0 ) return 0; |
| 107785 | + return pMod->pModule->xShadowName(zTail+1); |
| 107786 | +} |
| 107460 | 107787 | |
| 107461 | 107788 | /* |
| 107462 | 107789 | ** This routine is called to report the final ")" that terminates |
| 107463 | 107790 | ** a CREATE TABLE statement. |
| 107464 | 107791 | ** |
| | @@ -107494,10 +107821,14 @@ |
| 107494 | 107821 | return; |
| 107495 | 107822 | } |
| 107496 | 107823 | assert( !db->mallocFailed ); |
| 107497 | 107824 | p = pParse->pNewTable; |
| 107498 | 107825 | if( p==0 ) return; |
| 107826 | + |
| 107827 | + if( pSelect==0 && isShadowTableName(db, p->zName) ){ |
| 107828 | + p->tabFlags |= TF_Shadow; |
| 107829 | + } |
| 107499 | 107830 | |
| 107500 | 107831 | /* If the db->init.busy is 1 it means we are reading the SQL off the |
| 107501 | 107832 | ** "sqlite_master" or "sqlite_temp_master" table on the disk. |
| 107502 | 107833 | ** So do not write to the disk again. Extract the root page number |
| 107503 | 107834 | ** for the table from the db->init.newTnum field. (The page number |
| | @@ -108002,11 +108333,11 @@ |
| 108002 | 108333 | ** erasing iTable (this can happen with an auto-vacuum database). |
| 108003 | 108334 | */ |
| 108004 | 108335 | static void destroyRootPage(Parse *pParse, int iTable, int iDb){ |
| 108005 | 108336 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 108006 | 108337 | int r1 = sqlite3GetTempReg(pParse); |
| 108007 | | - assert( iTable>1 ); |
| 108338 | + if( iTable<2 ) sqlite3ErrorMsg(pParse, "corrupt schema"); |
| 108008 | 108339 | sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb); |
| 108009 | 108340 | sqlite3MayAbort(pParse); |
| 108010 | 108341 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 108011 | 108342 | /* OP_Destroy stores an in integer r1. If this integer |
| 108012 | 108343 | ** is non-zero, then it is the root page number of a table moved to |
| | @@ -110457,10 +110788,25 @@ |
| 110457 | 110788 | return p; |
| 110458 | 110789 | } |
| 110459 | 110790 | } |
| 110460 | 110791 | return 0; |
| 110461 | 110792 | } |
| 110793 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 110794 | +SQLITE_PRIVATE FuncDef *sqlite3FunctionSearchN( |
| 110795 | + int h, /* Hash of the name */ |
| 110796 | + const char *zFunc, /* Name of function */ |
| 110797 | + int nFunc /* Length of the name */ |
| 110798 | +){ |
| 110799 | + FuncDef *p; |
| 110800 | + for(p=sqlite3BuiltinFunctions.a[h]; p; p=p->u.pHash){ |
| 110801 | + if( sqlite3StrNICmp(p->zName, zFunc, nFunc)==0 ){ |
| 110802 | + return p; |
| 110803 | + } |
| 110804 | + } |
| 110805 | + return 0; |
| 110806 | +} |
| 110807 | +#endif /* SQLITE_ENABLE_NORMALIZE */ |
| 110462 | 110808 | |
| 110463 | 110809 | /* |
| 110464 | 110810 | ** Insert a new FuncDef into a FuncDefHash hash table. |
| 110465 | 110811 | */ |
| 110466 | 110812 | SQLITE_PRIVATE void sqlite3InsertBuiltinFuncs( |
| | @@ -110470,11 +110816,11 @@ |
| 110470 | 110816 | int i; |
| 110471 | 110817 | for(i=0; i<nDef; i++){ |
| 110472 | 110818 | FuncDef *pOther; |
| 110473 | 110819 | const char *zName = aDef[i].zName; |
| 110474 | 110820 | int nName = sqlite3Strlen30(zName); |
| 110475 | | - int h = (zName[0] + nName) % SQLITE_FUNC_HASH_SZ; |
| 110821 | + int h = SQLITE_FUNC_HASH(zName[0], nName); |
| 110476 | 110822 | assert( zName[0]>='a' && zName[0]<='z' ); |
| 110477 | 110823 | pOther = functionSearch(h, zName); |
| 110478 | 110824 | if( pOther ){ |
| 110479 | 110825 | assert( pOther!=&aDef[i] && pOther->pNext!=&aDef[i] ); |
| 110480 | 110826 | aDef[i].pNext = pOther->pNext; |
| | @@ -110549,11 +110895,11 @@ |
| 110549 | 110895 | ** new function. But the FuncDefs for built-in functions are read-only. |
| 110550 | 110896 | ** So we must not search for built-ins when creating a new function. |
| 110551 | 110897 | */ |
| 110552 | 110898 | if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){ |
| 110553 | 110899 | bestScore = 0; |
| 110554 | | - h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % SQLITE_FUNC_HASH_SZ; |
| 110900 | + h = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zName[0]], nName); |
| 110555 | 110901 | p = functionSearch(h, zName); |
| 110556 | 110902 | while( p ){ |
| 110557 | 110903 | int score = matchQuality(p, nArg, enc); |
| 110558 | 110904 | if( score>bestScore ){ |
| 110559 | 110905 | pBest = p; |
| | @@ -110696,37 +111042,52 @@ |
| 110696 | 111042 | if( sqlite3IndexedByLookup(pParse, pItem) ){ |
| 110697 | 111043 | pTab = 0; |
| 110698 | 111044 | } |
| 110699 | 111045 | return pTab; |
| 110700 | 111046 | } |
| 111047 | + |
| 111048 | +/* Return true if table pTab is read-only. |
| 111049 | +** |
| 111050 | +** A table is read-only if any of the following are true: |
| 111051 | +** |
| 111052 | +** 1) It is a virtual table and no implementation of the xUpdate method |
| 111053 | +** has been provided |
| 111054 | +** |
| 111055 | +** 2) It is a system table (i.e. sqlite_master), this call is not |
| 111056 | +** part of a nested parse and writable_schema pragma has not |
| 111057 | +** been specified |
| 111058 | +** |
| 111059 | +** 3) The table is a shadow table, the database connection is in |
| 111060 | +** defensive mode, and the current sqlite3_prepare() |
| 111061 | +** is for a top-level SQL statement. |
| 111062 | +*/ |
| 111063 | +static int tabIsReadOnly(Parse *pParse, Table *pTab){ |
| 111064 | + sqlite3 *db; |
| 111065 | + if( IsVirtual(pTab) ){ |
| 111066 | + return sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0; |
| 111067 | + } |
| 111068 | + if( (pTab->tabFlags & (TF_Readonly|TF_Shadow))==0 ) return 0; |
| 111069 | + db = pParse->db; |
| 111070 | + if( (pTab->tabFlags & TF_Readonly)!=0 ){ |
| 111071 | + return sqlite3WritableSchema(db)==0 && pParse->nested==0; |
| 111072 | + } |
| 111073 | + assert( pTab->tabFlags & TF_Shadow ); |
| 111074 | + return (db->flags & SQLITE_Defensive)!=0 |
| 111075 | + && db->nVdbeExec==0 |
| 111076 | + && db->pVtabCtx==0; |
| 111077 | +} |
| 110701 | 111078 | |
| 110702 | 111079 | /* |
| 110703 | 111080 | ** Check to make sure the given table is writable. If it is not |
| 110704 | 111081 | ** writable, generate an error message and return 1. If it is |
| 110705 | 111082 | ** writable return 0; |
| 110706 | 111083 | */ |
| 110707 | 111084 | SQLITE_PRIVATE int sqlite3IsReadOnly(Parse *pParse, Table *pTab, int viewOk){ |
| 110708 | | - /* A table is not writable under the following circumstances: |
| 110709 | | - ** |
| 110710 | | - ** 1) It is a virtual table and no implementation of the xUpdate method |
| 110711 | | - ** has been provided, or |
| 110712 | | - ** 2) It is a system table (i.e. sqlite_master), this call is not |
| 110713 | | - ** part of a nested parse and writable_schema pragma has not |
| 110714 | | - ** been specified. |
| 110715 | | - ** |
| 110716 | | - ** In either case leave an error message in pParse and return non-zero. |
| 110717 | | - */ |
| 110718 | | - if( ( IsVirtual(pTab) |
| 110719 | | - && sqlite3GetVTable(pParse->db, pTab)->pMod->pModule->xUpdate==0 ) |
| 110720 | | - || ( (pTab->tabFlags & TF_Readonly)!=0 |
| 110721 | | - && (pParse->db->flags & SQLITE_WriteSchema)==0 |
| 110722 | | - && pParse->nested==0 ) |
| 110723 | | - ){ |
| 111085 | + if( tabIsReadOnly(pParse, pTab) ){ |
| 110724 | 111086 | sqlite3ErrorMsg(pParse, "table %s may not be modified", pTab->zName); |
| 110725 | 111087 | return 1; |
| 110726 | 111088 | } |
| 110727 | | - |
| 110728 | 111089 | #ifndef SQLITE_OMIT_VIEW |
| 110729 | 111090 | if( !viewOk && pTab->pSelect ){ |
| 110730 | 111091 | sqlite3ErrorMsg(pParse,"cannot modify %s because it is a view",pTab->zName); |
| 110731 | 111092 | return 1; |
| 110732 | 111093 | } |
| | @@ -114126,11 +114487,11 @@ |
| 114126 | 114487 | int iCursor, /* The open cursor on the table */ |
| 114127 | 114488 | i16 iCol /* The column that is wanted */ |
| 114128 | 114489 | ){ |
| 114129 | 114490 | Expr *pExpr = sqlite3Expr(db, TK_COLUMN, 0); |
| 114130 | 114491 | if( pExpr ){ |
| 114131 | | - pExpr->pTab = pTab; |
| 114492 | + pExpr->y.pTab = pTab; |
| 114132 | 114493 | pExpr->iTable = iCursor; |
| 114133 | 114494 | pExpr->iColumn = iCol; |
| 114134 | 114495 | } |
| 114135 | 114496 | return pExpr; |
| 114136 | 114497 | } |
| | @@ -115202,11 +115563,12 @@ |
| 115202 | 115563 | do{ |
| 115203 | 115564 | zColAff[i--] = 0; |
| 115204 | 115565 | }while( i>=0 && zColAff[i]==SQLITE_AFF_BLOB ); |
| 115205 | 115566 | pTab->zColAff = zColAff; |
| 115206 | 115567 | } |
| 115207 | | - i = sqlite3Strlen30(zColAff); |
| 115568 | + assert( zColAff!=0 ); |
| 115569 | + i = sqlite3Strlen30NN(zColAff); |
| 115208 | 115570 | if( i ){ |
| 115209 | 115571 | if( iReg ){ |
| 115210 | 115572 | sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i); |
| 115211 | 115573 | }else{ |
| 115212 | 115574 | sqlite3VdbeChangeP4(v, -1, zColAff, i); |
| | @@ -116182,18 +116544,19 @@ |
| 116182 | 116544 | #ifdef tmask |
| 116183 | 116545 | #undef tmask |
| 116184 | 116546 | #endif |
| 116185 | 116547 | |
| 116186 | 116548 | /* |
| 116187 | | -** Meanings of bits in of pWalker->eCode for checkConstraintUnchanged() |
| 116549 | +** Meanings of bits in of pWalker->eCode for |
| 116550 | +** sqlite3ExprReferencesUpdatedColumn() |
| 116188 | 116551 | */ |
| 116189 | 116552 | #define CKCNSTRNT_COLUMN 0x01 /* CHECK constraint uses a changing column */ |
| 116190 | 116553 | #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */ |
| 116191 | 116554 | |
| 116192 | | -/* This is the Walker callback from checkConstraintUnchanged(). Set |
| 116193 | | -** bit 0x01 of pWalker->eCode if |
| 116194 | | -** pWalker->eCode to 0 if this expression node references any of the |
| 116555 | +/* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn(). |
| 116556 | +* Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this |
| 116557 | +** expression node references any of the |
| 116195 | 116558 | ** columns that are being modifed by an UPDATE statement. |
| 116196 | 116559 | */ |
| 116197 | 116560 | static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr){ |
| 116198 | 116561 | if( pExpr->op==TK_COLUMN ){ |
| 116199 | 116562 | assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 ); |
| | @@ -116211,16 +116574,25 @@ |
| 116211 | 116574 | /* |
| 116212 | 116575 | ** pExpr is a CHECK constraint on a row that is being UPDATE-ed. The |
| 116213 | 116576 | ** only columns that are modified by the UPDATE are those for which |
| 116214 | 116577 | ** aiChng[i]>=0, and also the ROWID is modified if chngRowid is true. |
| 116215 | 116578 | ** |
| 116216 | | -** Return true if CHECK constraint pExpr does not use any of the |
| 116579 | +** Return true if CHECK constraint pExpr uses any of the |
| 116217 | 116580 | ** changing columns (or the rowid if it is changing). In other words, |
| 116218 | | -** return true if this CHECK constraint can be skipped when validating |
| 116581 | +** return true if this CHECK constraint must be validated for |
| 116219 | 116582 | ** the new row in the UPDATE statement. |
| 116583 | +** |
| 116584 | +** 2018-09-15: pExpr might also be an expression for an index-on-expressions. |
| 116585 | +** The operation of this routine is the same - return true if an only if |
| 116586 | +** the expression uses one or more of columns identified by the second and |
| 116587 | +** third arguments. |
| 116220 | 116588 | */ |
| 116221 | | -static int checkConstraintUnchanged(Expr *pExpr, int *aiChng, int chngRowid){ |
| 116589 | +SQLITE_PRIVATE int sqlite3ExprReferencesUpdatedColumn( |
| 116590 | + Expr *pExpr, /* The expression to be checked */ |
| 116591 | + int *aiChng, /* aiChng[x]>=0 if column x changed by the UPDATE */ |
| 116592 | + int chngRowid /* True if UPDATE changes the rowid */ |
| 116593 | +){ |
| 116222 | 116594 | Walker w; |
| 116223 | 116595 | memset(&w, 0, sizeof(w)); |
| 116224 | 116596 | w.eCode = 0; |
| 116225 | 116597 | w.xExprCallback = checkConstraintExprNode; |
| 116226 | 116598 | w.u.aiCol = aiChng; |
| | @@ -116231,11 +116603,11 @@ |
| 116231 | 116603 | } |
| 116232 | 116604 | testcase( w.eCode==0 ); |
| 116233 | 116605 | testcase( w.eCode==CKCNSTRNT_COLUMN ); |
| 116234 | 116606 | testcase( w.eCode==CKCNSTRNT_ROWID ); |
| 116235 | 116607 | testcase( w.eCode==(CKCNSTRNT_ROWID|CKCNSTRNT_COLUMN) ); |
| 116236 | | - return !w.eCode; |
| 116608 | + return w.eCode!=0; |
| 116237 | 116609 | } |
| 116238 | 116610 | |
| 116239 | 116611 | /* |
| 116240 | 116612 | ** Generate code to do constraint checks prior to an INSERT or an UPDATE |
| 116241 | 116613 | ** on table pTab. |
| | @@ -116437,11 +116809,17 @@ |
| 116437 | 116809 | pParse->iSelfTab = -(regNewData+1); |
| 116438 | 116810 | onError = overrideError!=OE_Default ? overrideError : OE_Abort; |
| 116439 | 116811 | for(i=0; i<pCheck->nExpr; i++){ |
| 116440 | 116812 | int allOk; |
| 116441 | 116813 | Expr *pExpr = pCheck->a[i].pExpr; |
| 116442 | | - if( aiChng && checkConstraintUnchanged(pExpr, aiChng, pkChng) ) continue; |
| 116814 | + if( aiChng |
| 116815 | + && !sqlite3ExprReferencesUpdatedColumn(pExpr, aiChng, pkChng) |
| 116816 | + ){ |
| 116817 | + /* The check constraints do not reference any of the columns being |
| 116818 | + ** updated so there is no point it verifying the check constraint */ |
| 116819 | + continue; |
| 116820 | + } |
| 116443 | 116821 | allOk = sqlite3VdbeMakeLabel(v); |
| 116444 | 116822 | sqlite3VdbeVerifyAbortable(v, onError); |
| 116445 | 116823 | sqlite3ExprIfTrue(pParse, pExpr, allOk, SQLITE_JUMPIFNULL); |
| 116446 | 116824 | if( onError==OE_Ignore ){ |
| 116447 | 116825 | sqlite3VdbeGoto(v, ignoreDest); |
| | @@ -117938,16 +118316,19 @@ |
| 117938 | 118316 | void (*str_appendchar)(sqlite3_str*, int N, char C); |
| 117939 | 118317 | void (*str_reset)(sqlite3_str*); |
| 117940 | 118318 | int (*str_errcode)(sqlite3_str*); |
| 117941 | 118319 | int (*str_length)(sqlite3_str*); |
| 117942 | 118320 | char *(*str_value)(sqlite3_str*); |
| 118321 | + /* Version 3.25.0 and later */ |
| 117943 | 118322 | int (*create_window_function)(sqlite3*,const char*,int,int,void*, |
| 117944 | 118323 | void (*xStep)(sqlite3_context*,int,sqlite3_value**), |
| 117945 | 118324 | void (*xFinal)(sqlite3_context*), |
| 117946 | 118325 | void (*xValue)(sqlite3_context*), |
| 117947 | 118326 | void (*xInv)(sqlite3_context*,int,sqlite3_value**), |
| 117948 | 118327 | void(*xDestroy)(void*)); |
| 118328 | + /* Version 3.26.0 and later */ |
| 118329 | + const char *(*normalized_sql)(sqlite3_stmt*); |
| 117949 | 118330 | }; |
| 117950 | 118331 | |
| 117951 | 118332 | /* |
| 117952 | 118333 | ** This is the function signature used for all extension entry points. It |
| 117953 | 118334 | ** is also defined in the file "loadext.c". |
| | @@ -118231,10 +118612,12 @@ |
| 118231 | 118612 | #define sqlite3_str_errcode sqlite3_api->str_errcode |
| 118232 | 118613 | #define sqlite3_str_length sqlite3_api->str_length |
| 118233 | 118614 | #define sqlite3_str_value sqlite3_api->str_value |
| 118234 | 118615 | /* Version 3.25.0 and later */ |
| 118235 | 118616 | #define sqlite3_create_window_function sqlite3_api->create_window_function |
| 118617 | +/* Version 3.26.0 and later */ |
| 118618 | +#define sqlite3_normalized_sql sqlite3_api->normalized_sql |
| 118236 | 118619 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 118237 | 118620 | |
| 118238 | 118621 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 118239 | 118622 | /* This case when the file really is being compiled as a loadable |
| 118240 | 118623 | ** extension */ |
| | @@ -118686,11 +119069,17 @@ |
| 118686 | 119069 | sqlite3_str_reset, |
| 118687 | 119070 | sqlite3_str_errcode, |
| 118688 | 119071 | sqlite3_str_length, |
| 118689 | 119072 | sqlite3_str_value, |
| 118690 | 119073 | /* Version 3.25.0 and later */ |
| 118691 | | - sqlite3_create_window_function |
| 119074 | + sqlite3_create_window_function, |
| 119075 | + /* Version 3.26.0 and later */ |
| 119076 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 119077 | + sqlite3_normalized_sql |
| 119078 | +#else |
| 119079 | + 0 |
| 119080 | +#endif |
| 118692 | 119081 | }; |
| 118693 | 119082 | |
| 118694 | 119083 | /* |
| 118695 | 119084 | ** Attempt to load an SQLite extension library contained in the file |
| 118696 | 119085 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| | @@ -119136,14 +119525,13 @@ |
| 119136 | 119525 | #define PragTyp_WAL_AUTOCHECKPOINT 38 |
| 119137 | 119526 | #define PragTyp_WAL_CHECKPOINT 39 |
| 119138 | 119527 | #define PragTyp_ACTIVATE_EXTENSIONS 40 |
| 119139 | 119528 | #define PragTyp_HEXKEY 41 |
| 119140 | 119529 | #define PragTyp_KEY 42 |
| 119141 | | -#define PragTyp_REKEY 43 |
| 119142 | | -#define PragTyp_LOCK_STATUS 44 |
| 119143 | | -#define PragTyp_PARSER_TRACE 45 |
| 119144 | | -#define PragTyp_STATS 46 |
| 119530 | +#define PragTyp_LOCK_STATUS 43 |
| 119531 | +#define PragTyp_PARSER_TRACE 44 |
| 119532 | +#define PragTyp_STATS 45 |
| 119145 | 119533 | |
| 119146 | 119534 | /* Property flags associated with various pragma. */ |
| 119147 | 119535 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 119148 | 119536 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 119149 | 119537 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| | @@ -119156,72 +119544,71 @@ |
| 119156 | 119544 | /* Names of columns for pragmas that return multi-column result |
| 119157 | 119545 | ** or that return single-column results where the name of the |
| 119158 | 119546 | ** result column is different from the name of the pragma |
| 119159 | 119547 | */ |
| 119160 | 119548 | static const char *const pragCName[] = { |
| 119161 | | - /* 0 */ "cache_size", /* Used by: default_cache_size */ |
| 119162 | | - /* 1 */ "cid", /* Used by: table_info */ |
| 119163 | | - /* 2 */ "name", |
| 119164 | | - /* 3 */ "type", |
| 119165 | | - /* 4 */ "notnull", |
| 119166 | | - /* 5 */ "dflt_value", |
| 119167 | | - /* 6 */ "pk", |
| 119168 | | - /* 7 */ "tbl", /* Used by: stats */ |
| 119169 | | - /* 8 */ "idx", |
| 119170 | | - /* 9 */ "wdth", |
| 119171 | | - /* 10 */ "hght", |
| 119172 | | - /* 11 */ "flgs", |
| 119173 | | - /* 12 */ "seqno", /* Used by: index_info */ |
| 119174 | | - /* 13 */ "cid", |
| 119175 | | - /* 14 */ "name", |
| 119549 | + /* 0 */ "id", /* Used by: foreign_key_list */ |
| 119550 | + /* 1 */ "seq", |
| 119551 | + /* 2 */ "table", |
| 119552 | + /* 3 */ "from", |
| 119553 | + /* 4 */ "to", |
| 119554 | + /* 5 */ "on_update", |
| 119555 | + /* 6 */ "on_delete", |
| 119556 | + /* 7 */ "match", |
| 119557 | + /* 8 */ "cid", /* Used by: table_xinfo */ |
| 119558 | + /* 9 */ "name", |
| 119559 | + /* 10 */ "type", |
| 119560 | + /* 11 */ "notnull", |
| 119561 | + /* 12 */ "dflt_value", |
| 119562 | + /* 13 */ "pk", |
| 119563 | + /* 14 */ "hidden", |
| 119564 | + /* table_info reuses 8 */ |
| 119176 | 119565 | /* 15 */ "seqno", /* Used by: index_xinfo */ |
| 119177 | 119566 | /* 16 */ "cid", |
| 119178 | 119567 | /* 17 */ "name", |
| 119179 | 119568 | /* 18 */ "desc", |
| 119180 | 119569 | /* 19 */ "coll", |
| 119181 | 119570 | /* 20 */ "key", |
| 119182 | | - /* 21 */ "seq", /* Used by: index_list */ |
| 119183 | | - /* 22 */ "name", |
| 119184 | | - /* 23 */ "unique", |
| 119185 | | - /* 24 */ "origin", |
| 119186 | | - /* 25 */ "partial", |
| 119187 | | - /* 26 */ "seq", /* Used by: database_list */ |
| 119571 | + /* 21 */ "tbl", /* Used by: stats */ |
| 119572 | + /* 22 */ "idx", |
| 119573 | + /* 23 */ "wdth", |
| 119574 | + /* 24 */ "hght", |
| 119575 | + /* 25 */ "flgs", |
| 119576 | + /* 26 */ "seq", /* Used by: index_list */ |
| 119188 | 119577 | /* 27 */ "name", |
| 119189 | | - /* 28 */ "file", |
| 119190 | | - /* 29 */ "name", /* Used by: function_list */ |
| 119191 | | - /* 30 */ "builtin", |
| 119192 | | - /* 31 */ "name", /* Used by: module_list pragma_list */ |
| 119193 | | - /* 32 */ "seq", /* Used by: collation_list */ |
| 119194 | | - /* 33 */ "name", |
| 119195 | | - /* 34 */ "id", /* Used by: foreign_key_list */ |
| 119196 | | - /* 35 */ "seq", |
| 119197 | | - /* 36 */ "table", |
| 119198 | | - /* 37 */ "from", |
| 119199 | | - /* 38 */ "to", |
| 119200 | | - /* 39 */ "on_update", |
| 119201 | | - /* 40 */ "on_delete", |
| 119202 | | - /* 41 */ "match", |
| 119203 | | - /* 42 */ "table", /* Used by: foreign_key_check */ |
| 119204 | | - /* 43 */ "rowid", |
| 119205 | | - /* 44 */ "parent", |
| 119206 | | - /* 45 */ "fkid", |
| 119207 | | - /* 46 */ "busy", /* Used by: wal_checkpoint */ |
| 119208 | | - /* 47 */ "log", |
| 119209 | | - /* 48 */ "checkpointed", |
| 119210 | | - /* 49 */ "timeout", /* Used by: busy_timeout */ |
| 119211 | | - /* 50 */ "database", /* Used by: lock_status */ |
| 119212 | | - /* 51 */ "status", |
| 119578 | + /* 28 */ "unique", |
| 119579 | + /* 29 */ "origin", |
| 119580 | + /* 30 */ "partial", |
| 119581 | + /* 31 */ "table", /* Used by: foreign_key_check */ |
| 119582 | + /* 32 */ "rowid", |
| 119583 | + /* 33 */ "parent", |
| 119584 | + /* 34 */ "fkid", |
| 119585 | + /* index_info reuses 15 */ |
| 119586 | + /* 35 */ "seq", /* Used by: database_list */ |
| 119587 | + /* 36 */ "name", |
| 119588 | + /* 37 */ "file", |
| 119589 | + /* 38 */ "busy", /* Used by: wal_checkpoint */ |
| 119590 | + /* 39 */ "log", |
| 119591 | + /* 40 */ "checkpointed", |
| 119592 | + /* 41 */ "name", /* Used by: function_list */ |
| 119593 | + /* 42 */ "builtin", |
| 119594 | + /* collation_list reuses 26 */ |
| 119595 | + /* 43 */ "database", /* Used by: lock_status */ |
| 119596 | + /* 44 */ "status", |
| 119597 | + /* 45 */ "cache_size", /* Used by: default_cache_size */ |
| 119598 | + /* module_list pragma_list reuses 9 */ |
| 119599 | + /* 46 */ "timeout", /* Used by: busy_timeout */ |
| 119213 | 119600 | }; |
| 119214 | 119601 | |
| 119215 | 119602 | /* Definitions of all built-in pragmas */ |
| 119216 | 119603 | typedef struct PragmaName { |
| 119217 | 119604 | const char *const zName; /* Name of pragma */ |
| 119218 | 119605 | u8 ePragTyp; /* PragTyp_XXX value */ |
| 119219 | 119606 | u8 mPragFlg; /* Zero or more PragFlg_XXX values */ |
| 119220 | 119607 | u8 iPragCName; /* Start of column names in pragCName[] */ |
| 119221 | 119608 | u8 nPragCName; /* Num of col names. 0 means use pragma name */ |
| 119222 | | - u32 iArg; /* Extra argument */ |
| 119609 | + u64 iArg; /* Extra argument */ |
| 119223 | 119610 | } PragmaName; |
| 119224 | 119611 | static const PragmaName aPragmaName[] = { |
| 119225 | 119612 | #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD) |
| 119226 | 119613 | {/* zName: */ "activate_extensions", |
| 119227 | 119614 | /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, |
| | @@ -119253,11 +119640,11 @@ |
| 119253 | 119640 | #endif |
| 119254 | 119641 | #endif |
| 119255 | 119642 | {/* zName: */ "busy_timeout", |
| 119256 | 119643 | /* ePragTyp: */ PragTyp_BUSY_TIMEOUT, |
| 119257 | 119644 | /* ePragFlg: */ PragFlg_Result0, |
| 119258 | | - /* ColNames: */ 49, 1, |
| 119645 | + /* ColNames: */ 46, 1, |
| 119259 | 119646 | /* iArg: */ 0 }, |
| 119260 | 119647 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 119261 | 119648 | {/* zName: */ "cache_size", |
| 119262 | 119649 | /* ePragTyp: */ PragTyp_CACHE_SIZE, |
| 119263 | 119650 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1, |
| | @@ -119290,11 +119677,11 @@ |
| 119290 | 119677 | #endif |
| 119291 | 119678 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 119292 | 119679 | {/* zName: */ "collation_list", |
| 119293 | 119680 | /* ePragTyp: */ PragTyp_COLLATION_LIST, |
| 119294 | 119681 | /* ePragFlg: */ PragFlg_Result0, |
| 119295 | | - /* ColNames: */ 32, 2, |
| 119682 | + /* ColNames: */ 26, 2, |
| 119296 | 119683 | /* iArg: */ 0 }, |
| 119297 | 119684 | #endif |
| 119298 | 119685 | #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS) |
| 119299 | 119686 | {/* zName: */ "compile_options", |
| 119300 | 119687 | /* ePragTyp: */ PragTyp_COMPILE_OPTIONS, |
| | @@ -119325,18 +119712,18 @@ |
| 119325 | 119712 | #endif |
| 119326 | 119713 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 119327 | 119714 | {/* zName: */ "database_list", |
| 119328 | 119715 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 119329 | 119716 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, |
| 119330 | | - /* ColNames: */ 26, 3, |
| 119717 | + /* ColNames: */ 35, 3, |
| 119331 | 119718 | /* iArg: */ 0 }, |
| 119332 | 119719 | #endif |
| 119333 | 119720 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 119334 | 119721 | {/* zName: */ "default_cache_size", |
| 119335 | 119722 | /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE, |
| 119336 | 119723 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1, |
| 119337 | | - /* ColNames: */ 0, 1, |
| 119724 | + /* ColNames: */ 45, 1, |
| 119338 | 119725 | /* iArg: */ 0 }, |
| 119339 | 119726 | #endif |
| 119340 | 119727 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 119341 | 119728 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 119342 | 119729 | {/* zName: */ "defer_foreign_keys", |
| | @@ -119362,18 +119749,18 @@ |
| 119362 | 119749 | #endif |
| 119363 | 119750 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 119364 | 119751 | {/* zName: */ "foreign_key_check", |
| 119365 | 119752 | /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, |
| 119366 | 119753 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, |
| 119367 | | - /* ColNames: */ 42, 4, |
| 119754 | + /* ColNames: */ 31, 4, |
| 119368 | 119755 | /* iArg: */ 0 }, |
| 119369 | 119756 | #endif |
| 119370 | 119757 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) |
| 119371 | 119758 | {/* zName: */ "foreign_key_list", |
| 119372 | 119759 | /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST, |
| 119373 | 119760 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 119374 | | - /* ColNames: */ 34, 8, |
| 119761 | + /* ColNames: */ 0, 8, |
| 119375 | 119762 | /* iArg: */ 0 }, |
| 119376 | 119763 | #endif |
| 119377 | 119764 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 119378 | 119765 | #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
| 119379 | 119766 | {/* zName: */ "foreign_keys", |
| | @@ -119405,25 +119792,25 @@ |
| 119405 | 119792 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 119406 | 119793 | #if defined(SQLITE_INTROSPECTION_PRAGMAS) |
| 119407 | 119794 | {/* zName: */ "function_list", |
| 119408 | 119795 | /* ePragTyp: */ PragTyp_FUNCTION_LIST, |
| 119409 | 119796 | /* ePragFlg: */ PragFlg_Result0, |
| 119410 | | - /* ColNames: */ 29, 2, |
| 119797 | + /* ColNames: */ 41, 2, |
| 119411 | 119798 | /* iArg: */ 0 }, |
| 119412 | 119799 | #endif |
| 119413 | 119800 | #endif |
| 119414 | 119801 | #if defined(SQLITE_HAS_CODEC) |
| 119415 | 119802 | {/* zName: */ "hexkey", |
| 119416 | 119803 | /* ePragTyp: */ PragTyp_HEXKEY, |
| 119417 | 119804 | /* ePragFlg: */ 0, |
| 119418 | 119805 | /* ColNames: */ 0, 0, |
| 119419 | | - /* iArg: */ 0 }, |
| 119806 | + /* iArg: */ 2 }, |
| 119420 | 119807 | {/* zName: */ "hexrekey", |
| 119421 | 119808 | /* ePragTyp: */ PragTyp_HEXKEY, |
| 119422 | 119809 | /* ePragFlg: */ 0, |
| 119423 | 119810 | /* ColNames: */ 0, 0, |
| 119424 | | - /* iArg: */ 0 }, |
| 119811 | + /* iArg: */ 3 }, |
| 119425 | 119812 | #endif |
| 119426 | 119813 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 119427 | 119814 | #if !defined(SQLITE_OMIT_CHECK) |
| 119428 | 119815 | {/* zName: */ "ignore_check_constraints", |
| 119429 | 119816 | /* ePragTyp: */ PragTyp_FLAG, |
| | @@ -119441,16 +119828,16 @@ |
| 119441 | 119828 | #endif |
| 119442 | 119829 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 119443 | 119830 | {/* zName: */ "index_info", |
| 119444 | 119831 | /* ePragTyp: */ PragTyp_INDEX_INFO, |
| 119445 | 119832 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 119446 | | - /* ColNames: */ 12, 3, |
| 119833 | + /* ColNames: */ 15, 3, |
| 119447 | 119834 | /* iArg: */ 0 }, |
| 119448 | 119835 | {/* zName: */ "index_list", |
| 119449 | 119836 | /* ePragTyp: */ PragTyp_INDEX_LIST, |
| 119450 | 119837 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 119451 | | - /* ColNames: */ 21, 5, |
| 119838 | + /* ColNames: */ 26, 5, |
| 119452 | 119839 | /* iArg: */ 0 }, |
| 119453 | 119840 | {/* zName: */ "index_xinfo", |
| 119454 | 119841 | /* ePragTyp: */ PragTyp_INDEX_INFO, |
| 119455 | 119842 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 119456 | 119843 | /* ColNames: */ 15, 6, |
| | @@ -119503,11 +119890,11 @@ |
| 119503 | 119890 | #endif |
| 119504 | 119891 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 119505 | 119892 | {/* zName: */ "lock_status", |
| 119506 | 119893 | /* ePragTyp: */ PragTyp_LOCK_STATUS, |
| 119507 | 119894 | /* ePragFlg: */ PragFlg_Result0, |
| 119508 | | - /* ColNames: */ 50, 2, |
| 119895 | + /* ColNames: */ 43, 2, |
| 119509 | 119896 | /* iArg: */ 0 }, |
| 119510 | 119897 | #endif |
| 119511 | 119898 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 119512 | 119899 | {/* zName: */ "locking_mode", |
| 119513 | 119900 | /* ePragTyp: */ PragTyp_LOCKING_MODE, |
| | @@ -119529,11 +119916,11 @@ |
| 119529 | 119916 | #if !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 119530 | 119917 | #if defined(SQLITE_INTROSPECTION_PRAGMAS) |
| 119531 | 119918 | {/* zName: */ "module_list", |
| 119532 | 119919 | /* ePragTyp: */ PragTyp_MODULE_LIST, |
| 119533 | 119920 | /* ePragFlg: */ PragFlg_Result0, |
| 119534 | | - /* ColNames: */ 31, 1, |
| 119921 | + /* ColNames: */ 9, 1, |
| 119535 | 119922 | /* iArg: */ 0 }, |
| 119536 | 119923 | #endif |
| 119537 | 119924 | #endif |
| 119538 | 119925 | #endif |
| 119539 | 119926 | {/* zName: */ "optimize", |
| | @@ -119562,11 +119949,11 @@ |
| 119562 | 119949 | #endif |
| 119563 | 119950 | #if defined(SQLITE_INTROSPECTION_PRAGMAS) |
| 119564 | 119951 | {/* zName: */ "pragma_list", |
| 119565 | 119952 | /* ePragTyp: */ PragTyp_PRAGMA_LIST, |
| 119566 | 119953 | /* ePragFlg: */ PragFlg_Result0, |
| 119567 | | - /* ColNames: */ 31, 1, |
| 119954 | + /* ColNames: */ 9, 1, |
| 119568 | 119955 | /* iArg: */ 0 }, |
| 119569 | 119956 | #endif |
| 119570 | 119957 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 119571 | 119958 | {/* zName: */ "query_only", |
| 119572 | 119959 | /* ePragTyp: */ PragTyp_FLAG, |
| | @@ -119593,14 +119980,14 @@ |
| 119593 | 119980 | /* ColNames: */ 0, 0, |
| 119594 | 119981 | /* iArg: */ SQLITE_RecTriggers }, |
| 119595 | 119982 | #endif |
| 119596 | 119983 | #if defined(SQLITE_HAS_CODEC) |
| 119597 | 119984 | {/* zName: */ "rekey", |
| 119598 | | - /* ePragTyp: */ PragTyp_REKEY, |
| 119985 | + /* ePragTyp: */ PragTyp_KEY, |
| 119599 | 119986 | /* ePragFlg: */ 0, |
| 119600 | 119987 | /* ColNames: */ 0, 0, |
| 119601 | | - /* iArg: */ 0 }, |
| 119988 | + /* iArg: */ 1 }, |
| 119602 | 119989 | #endif |
| 119603 | 119990 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 119604 | 119991 | {/* zName: */ "reverse_unordered_selects", |
| 119605 | 119992 | /* ePragTyp: */ PragTyp_FLAG, |
| 119606 | 119993 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| | @@ -119649,11 +120036,11 @@ |
| 119649 | 120036 | #endif |
| 119650 | 120037 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG) |
| 119651 | 120038 | {/* zName: */ "stats", |
| 119652 | 120039 | /* ePragTyp: */ PragTyp_STATS, |
| 119653 | 120040 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq, |
| 119654 | | - /* ColNames: */ 7, 5, |
| 120041 | + /* ColNames: */ 21, 5, |
| 119655 | 120042 | /* iArg: */ 0 }, |
| 119656 | 120043 | #endif |
| 119657 | 120044 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 119658 | 120045 | {/* zName: */ "synchronous", |
| 119659 | 120046 | /* ePragTyp: */ PragTyp_SYNCHRONOUS, |
| | @@ -119663,12 +120050,17 @@ |
| 119663 | 120050 | #endif |
| 119664 | 120051 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 119665 | 120052 | {/* zName: */ "table_info", |
| 119666 | 120053 | /* ePragTyp: */ PragTyp_TABLE_INFO, |
| 119667 | 120054 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 119668 | | - /* ColNames: */ 1, 6, |
| 120055 | + /* ColNames: */ 8, 6, |
| 119669 | 120056 | /* iArg: */ 0 }, |
| 120057 | + {/* zName: */ "table_xinfo", |
| 120058 | + /* ePragTyp: */ PragTyp_TABLE_INFO, |
| 120059 | + /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt, |
| 120060 | + /* ColNames: */ 8, 7, |
| 120061 | + /* iArg: */ 1 }, |
| 119670 | 120062 | #endif |
| 119671 | 120063 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) |
| 119672 | 120064 | {/* zName: */ "temp_store", |
| 119673 | 120065 | /* ePragTyp: */ PragTyp_TEMP_STORE, |
| 119674 | 120066 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| | @@ -119677,10 +120069,22 @@ |
| 119677 | 120069 | {/* zName: */ "temp_store_directory", |
| 119678 | 120070 | /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY, |
| 119679 | 120071 | /* ePragFlg: */ PragFlg_NoColumns1, |
| 119680 | 120072 | /* ColNames: */ 0, 0, |
| 119681 | 120073 | /* iArg: */ 0 }, |
| 120074 | +#endif |
| 120075 | +#if defined(SQLITE_HAS_CODEC) |
| 120076 | + {/* zName: */ "textkey", |
| 120077 | + /* ePragTyp: */ PragTyp_KEY, |
| 120078 | + /* ePragFlg: */ 0, |
| 120079 | + /* ColNames: */ 0, 0, |
| 120080 | + /* iArg: */ 4 }, |
| 120081 | + {/* zName: */ "textrekey", |
| 120082 | + /* ePragTyp: */ PragTyp_KEY, |
| 120083 | + /* ePragFlg: */ 0, |
| 120084 | + /* ColNames: */ 0, 0, |
| 120085 | + /* iArg: */ 5 }, |
| 119682 | 120086 | #endif |
| 119683 | 120087 | {/* zName: */ "threads", |
| 119684 | 120088 | /* ePragTyp: */ PragTyp_THREADS, |
| 119685 | 120089 | /* ePragFlg: */ PragFlg_Result0, |
| 119686 | 120090 | /* ColNames: */ 0, 0, |
| | @@ -119728,22 +120132,22 @@ |
| 119728 | 120132 | /* ColNames: */ 0, 0, |
| 119729 | 120133 | /* iArg: */ 0 }, |
| 119730 | 120134 | {/* zName: */ "wal_checkpoint", |
| 119731 | 120135 | /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, |
| 119732 | 120136 | /* ePragFlg: */ PragFlg_NeedSchema, |
| 119733 | | - /* ColNames: */ 46, 3, |
| 120137 | + /* ColNames: */ 38, 3, |
| 119734 | 120138 | /* iArg: */ 0 }, |
| 119735 | 120139 | #endif |
| 119736 | 120140 | #if !defined(SQLITE_OMIT_FLAG_PRAGMAS) |
| 119737 | 120141 | {/* zName: */ "writable_schema", |
| 119738 | 120142 | /* ePragTyp: */ PragTyp_FLAG, |
| 119739 | 120143 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 119740 | 120144 | /* ColNames: */ 0, 0, |
| 119741 | | - /* iArg: */ SQLITE_WriteSchema }, |
| 120145 | + /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError }, |
| 119742 | 120146 | #endif |
| 119743 | 120147 | }; |
| 119744 | | -/* Number of pragmas: 61 on by default, 78 total. */ |
| 120148 | +/* Number of pragmas: 62 on by default, 81 total. */ |
| 119745 | 120149 | |
| 119746 | 120150 | /************** End of pragma.h **********************************************/ |
| 119747 | 120151 | /************** Continuing where we left off in pragma.c *********************/ |
| 119748 | 120152 | |
| 119749 | 120153 | /* |
| | @@ -120751,11 +121155,11 @@ |
| 120751 | 121155 | case PragTyp_FLAG: { |
| 120752 | 121156 | if( zRight==0 ){ |
| 120753 | 121157 | setPragmaResultColumnNames(v, pPragma); |
| 120754 | 121158 | returnSingleInt(v, (db->flags & pPragma->iArg)!=0 ); |
| 120755 | 121159 | }else{ |
| 120756 | | - int mask = pPragma->iArg; /* Mask of bits to set or clear. */ |
| 121160 | + u64 mask = pPragma->iArg; /* Mask of bits to set or clear. */ |
| 120757 | 121161 | if( db->autoCommit==0 ){ |
| 120758 | 121162 | /* Foreign key support may not be enabled or disabled while not |
| 120759 | 121163 | ** in auto-commit mode. */ |
| 120760 | 121164 | mask &= ~(SQLITE_ForeignKeys); |
| 120761 | 121165 | } |
| | @@ -120804,15 +121208,16 @@ |
| 120804 | 121208 | if( pTab ){ |
| 120805 | 121209 | int i, k; |
| 120806 | 121210 | int nHidden = 0; |
| 120807 | 121211 | Column *pCol; |
| 120808 | 121212 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 120809 | | - pParse->nMem = 6; |
| 121213 | + pParse->nMem = 7; |
| 120810 | 121214 | sqlite3CodeVerifySchema(pParse, iDb); |
| 120811 | 121215 | sqlite3ViewGetColumnNames(pParse, pTab); |
| 120812 | 121216 | for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){ |
| 120813 | | - if( IsHiddenColumn(pCol) ){ |
| 121217 | + int isHidden = IsHiddenColumn(pCol); |
| 121218 | + if( isHidden && pPragma->iArg==0 ){ |
| 120814 | 121219 | nHidden++; |
| 120815 | 121220 | continue; |
| 120816 | 121221 | } |
| 120817 | 121222 | if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){ |
| 120818 | 121223 | k = 0; |
| | @@ -120820,17 +121225,18 @@ |
| 120820 | 121225 | k = 1; |
| 120821 | 121226 | }else{ |
| 120822 | 121227 | for(k=1; k<=pTab->nCol && pPk->aiColumn[k-1]!=i; k++){} |
| 120823 | 121228 | } |
| 120824 | 121229 | assert( pCol->pDflt==0 || pCol->pDflt->op==TK_SPAN ); |
| 120825 | | - sqlite3VdbeMultiLoad(v, 1, "issisi", |
| 121230 | + sqlite3VdbeMultiLoad(v, 1, pPragma->iArg ? "issisii" : "issisi", |
| 120826 | 121231 | i-nHidden, |
| 120827 | 121232 | pCol->zName, |
| 120828 | 121233 | sqlite3ColumnType(pCol,""), |
| 120829 | 121234 | pCol->notNull ? 1 : 0, |
| 120830 | 121235 | pCol->pDflt ? pCol->pDflt->u.zToken : 0, |
| 120831 | | - k); |
| 121236 | + k, |
| 121237 | + isHidden); |
| 120832 | 121238 | } |
| 120833 | 121239 | } |
| 120834 | 121240 | } |
| 120835 | 121241 | break; |
| 120836 | 121242 | |
| | @@ -121830,16 +122236,28 @@ |
| 121830 | 122236 | break; |
| 121831 | 122237 | } |
| 121832 | 122238 | #endif |
| 121833 | 122239 | |
| 121834 | 122240 | #ifdef SQLITE_HAS_CODEC |
| 122241 | + /* Pragma iArg |
| 122242 | + ** ---------- ------ |
| 122243 | + ** key 0 |
| 122244 | + ** rekey 1 |
| 122245 | + ** hexkey 2 |
| 122246 | + ** hexrekey 3 |
| 122247 | + ** textkey 4 |
| 122248 | + ** textrekey 5 |
| 122249 | + */ |
| 121835 | 122250 | case PragTyp_KEY: { |
| 121836 | | - if( zRight ) sqlite3_key_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); |
| 121837 | | - break; |
| 121838 | | - } |
| 121839 | | - case PragTyp_REKEY: { |
| 121840 | | - if( zRight ) sqlite3_rekey_v2(db, zDb, zRight, sqlite3Strlen30(zRight)); |
| 122251 | + if( zRight ){ |
| 122252 | + int n = pPragma->iArg<4 ? sqlite3Strlen30(zRight) : -1; |
| 122253 | + if( (pPragma->iArg & 1)==0 ){ |
| 122254 | + sqlite3_key_v2(db, zDb, zRight, n); |
| 122255 | + }else{ |
| 122256 | + sqlite3_rekey_v2(db, zDb, zRight, n); |
| 122257 | + } |
| 122258 | + } |
| 121841 | 122259 | break; |
| 121842 | 122260 | } |
| 121843 | 122261 | case PragTyp_HEXKEY: { |
| 121844 | 122262 | if( zRight ){ |
| 121845 | 122263 | u8 iByte; |
| | @@ -121847,11 +122265,11 @@ |
| 121847 | 122265 | char zKey[40]; |
| 121848 | 122266 | for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zRight[i]); i++){ |
| 121849 | 122267 | iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]); |
| 121850 | 122268 | if( (i&1)!=0 ) zKey[i/2] = iByte; |
| 121851 | 122269 | } |
| 121852 | | - if( (zLeft[3] & 0xf)==0xb ){ |
| 122270 | + if( (pPragma->iArg & 1)==0 ){ |
| 121853 | 122271 | sqlite3_key_v2(db, zDb, zKey, i/2); |
| 121854 | 122272 | }else{ |
| 121855 | 122273 | sqlite3_rekey_v2(db, zDb, zKey, i/2); |
| 121856 | 122274 | } |
| 121857 | 122275 | } |
| | @@ -122177,11 +122595,12 @@ |
| 122177 | 122595 | 0, /* xRollback - rollback transaction */ |
| 122178 | 122596 | 0, /* xFindFunction - function overloading */ |
| 122179 | 122597 | 0, /* xRename - rename the table */ |
| 122180 | 122598 | 0, /* xSavepoint */ |
| 122181 | 122599 | 0, /* xRelease */ |
| 122182 | | - 0 /* xRollbackTo */ |
| 122600 | + 0, /* xRollbackTo */ |
| 122601 | + 0 /* xShadowName */ |
| 122183 | 122602 | }; |
| 122184 | 122603 | |
| 122185 | 122604 | /* |
| 122186 | 122605 | ** Check to see if zTabName is really the name of a pragma. If it is, |
| 122187 | 122606 | ** then register an eponymous virtual table for that pragma and return |
| | @@ -122530,12 +122949,12 @@ |
| 122530 | 122949 | } |
| 122531 | 122950 | if( db->mallocFailed ){ |
| 122532 | 122951 | rc = SQLITE_NOMEM_BKPT; |
| 122533 | 122952 | sqlite3ResetAllSchemasOfConnection(db); |
| 122534 | 122953 | } |
| 122535 | | - if( rc==SQLITE_OK || (db->flags&SQLITE_WriteSchema)){ |
| 122536 | | - /* Black magic: If the SQLITE_WriteSchema flag is set, then consider |
| 122954 | + if( rc==SQLITE_OK || (db->flags&SQLITE_NoSchemaError)){ |
| 122955 | + /* Black magic: If the SQLITE_NoSchemaError flag is set, then consider |
| 122537 | 122956 | ** the schema loaded, even if errors occurred. In this situation the |
| 122538 | 122957 | ** current sqlite3_prepare() operation will fail, but the following one |
| 122539 | 122958 | ** will attempt to compile the supplied statement against whatever subset |
| 122540 | 122959 | ** of the schema was loaded before the error occurred. The primary |
| 122541 | 122960 | ** purpose of this is to allow access to the sqlite_master table |
| | @@ -122912,10 +123331,298 @@ |
| 122912 | 123331 | assert( (rc&db->errMask)==rc ); |
| 122913 | 123332 | sqlite3_mutex_leave(db->mutex); |
| 122914 | 123333 | return rc; |
| 122915 | 123334 | } |
| 122916 | 123335 | |
| 123336 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 123337 | +/* |
| 123338 | +** Checks if the specified token is a table, column, or function name, |
| 123339 | +** based on the databases associated with the statement being prepared. |
| 123340 | +** If the function fails, zero is returned and pRc is filled with the |
| 123341 | +** error code. |
| 123342 | +*/ |
| 123343 | +static int shouldTreatAsIdentifier( |
| 123344 | + sqlite3 *db, /* Database handle. */ |
| 123345 | + const char *zToken, /* Pointer to start of token to be checked */ |
| 123346 | + int nToken, /* Length of token to be checked */ |
| 123347 | + int *pRc /* Pointer to error code upon failure */ |
| 123348 | +){ |
| 123349 | + int bFound = 0; /* Non-zero if token is an identifier name. */ |
| 123350 | + int i, j; /* Database and column loop indexes. */ |
| 123351 | + Schema *pSchema; /* Schema for current database. */ |
| 123352 | + Hash *pHash; /* Hash table of tables for current database. */ |
| 123353 | + HashElem *e; /* Hash element for hash table iteration. */ |
| 123354 | + Table *pTab; /* Database table for columns being checked. */ |
| 123355 | + |
| 123356 | + if( sqlite3IsRowidN(zToken, nToken) ){ |
| 123357 | + return 1; |
| 123358 | + } |
| 123359 | + if( nToken>0 ){ |
| 123360 | + int hash = SQLITE_FUNC_HASH(sqlite3UpperToLower[(u8)zToken[0]], nToken); |
| 123361 | + if( sqlite3FunctionSearchN(hash, zToken, nToken) ) return 1; |
| 123362 | + } |
| 123363 | + assert( db!=0 ); |
| 123364 | + sqlite3_mutex_enter(db->mutex); |
| 123365 | + sqlite3BtreeEnterAll(db); |
| 123366 | + for(i=0; i<db->nDb; i++){ |
| 123367 | + pHash = &db->aFunc; |
| 123368 | + if( sqlite3HashFindN(pHash, zToken, nToken) ){ |
| 123369 | + bFound = 1; |
| 123370 | + break; |
| 123371 | + } |
| 123372 | + pSchema = db->aDb[i].pSchema; |
| 123373 | + if( pSchema==0 ) continue; |
| 123374 | + pHash = &pSchema->tblHash; |
| 123375 | + if( sqlite3HashFindN(pHash, zToken, nToken) ){ |
| 123376 | + bFound = 1; |
| 123377 | + break; |
| 123378 | + } |
| 123379 | + for(e=sqliteHashFirst(pHash); e; e=sqliteHashNext(e)){ |
| 123380 | + pTab = sqliteHashData(e); |
| 123381 | + if( pTab==0 ) continue; |
| 123382 | + pHash = pTab->pColHash; |
| 123383 | + if( pHash==0 ){ |
| 123384 | + pTab->pColHash = pHash = sqlite3_malloc(sizeof(Hash)); |
| 123385 | + if( pHash ){ |
| 123386 | + sqlite3HashInit(pHash); |
| 123387 | + for(j=0; j<pTab->nCol; j++){ |
| 123388 | + Column *pCol = &pTab->aCol[j]; |
| 123389 | + sqlite3HashInsert(pHash, pCol->zName, pCol); |
| 123390 | + } |
| 123391 | + }else{ |
| 123392 | + *pRc = SQLITE_NOMEM_BKPT; |
| 123393 | + bFound = 0; |
| 123394 | + goto done; |
| 123395 | + } |
| 123396 | + } |
| 123397 | + if( pHash && sqlite3HashFindN(pHash, zToken, nToken) ){ |
| 123398 | + bFound = 1; |
| 123399 | + goto done; |
| 123400 | + } |
| 123401 | + } |
| 123402 | + } |
| 123403 | +done: |
| 123404 | + sqlite3BtreeLeaveAll(db); |
| 123405 | + sqlite3_mutex_leave(db->mutex); |
| 123406 | + return bFound; |
| 123407 | +} |
| 123408 | + |
| 123409 | +/* |
| 123410 | +** Attempt to estimate the final output buffer size needed for the fully |
| 123411 | +** normalized version of the specified SQL string. This should take into |
| 123412 | +** account any potential expansion that could occur (e.g. via IN clauses |
| 123413 | +** being expanded, etc). This size returned is the total number of bytes |
| 123414 | +** including the NUL terminator. |
| 123415 | +*/ |
| 123416 | +static int estimateNormalizedSize( |
| 123417 | + const char *zSql, /* The original SQL string */ |
| 123418 | + int nSql, /* Length of original SQL string */ |
| 123419 | + u8 prepFlags /* The flags passed to sqlite3_prepare_v3() */ |
| 123420 | +){ |
| 123421 | + int nOut = nSql + 4; |
| 123422 | + const char *z = zSql; |
| 123423 | + while( nOut<nSql*5 ){ |
| 123424 | + while( z[0]!=0 && z[0]!='I' && z[0]!='i' ){ z++; } |
| 123425 | + if( z[0]==0 ) break; |
| 123426 | + z++; |
| 123427 | + if( z[0]!='N' && z[0]!='n' ) break; |
| 123428 | + z++; |
| 123429 | + while( sqlite3Isspace(z[0]) ){ z++; } |
| 123430 | + if( z[0]!='(' ) break; |
| 123431 | + z++; |
| 123432 | + nOut += 5; /* ?,?,? */ |
| 123433 | + } |
| 123434 | + return nOut; |
| 123435 | +} |
| 123436 | + |
| 123437 | +/* |
| 123438 | +** Copy the current token into the output buffer while dealing with quoted |
| 123439 | +** identifiers. By default, all letters will be converted into lowercase. |
| 123440 | +** If the bUpper flag is set, uppercase will be used. The piOut argument |
| 123441 | +** will be used to update the target index into the output string. |
| 123442 | +*/ |
| 123443 | +static void copyNormalizedToken( |
| 123444 | + const char *zSql, /* The original SQL string */ |
| 123445 | + int iIn, /* Current index into the original SQL string */ |
| 123446 | + int nToken, /* Number of bytes in the current token */ |
| 123447 | + int tokenFlags, /* Flags returned by the tokenizer */ |
| 123448 | + char *zOut, /* The output string */ |
| 123449 | + int *piOut /* Pointer to target index into the output string */ |
| 123450 | +){ |
| 123451 | + int bQuoted = tokenFlags & SQLITE_TOKEN_QUOTED; |
| 123452 | + int bKeyword = tokenFlags & SQLITE_TOKEN_KEYWORD; |
| 123453 | + int j = *piOut, k = 0; |
| 123454 | + for(; k<nToken; k++){ |
| 123455 | + if( bQuoted ){ |
| 123456 | + if( k==0 && iIn>0 ){ |
| 123457 | + zOut[j++] = '"'; |
| 123458 | + continue; |
| 123459 | + }else if( k==nToken-1 ){ |
| 123460 | + zOut[j++] = '"'; |
| 123461 | + continue; |
| 123462 | + } |
| 123463 | + } |
| 123464 | + if( bKeyword ){ |
| 123465 | + zOut[j++] = sqlite3Toupper(zSql[iIn+k]); |
| 123466 | + }else{ |
| 123467 | + zOut[j++] = sqlite3Tolower(zSql[iIn+k]); |
| 123468 | + } |
| 123469 | + } |
| 123470 | + *piOut = j; |
| 123471 | +} |
| 123472 | + |
| 123473 | +/* |
| 123474 | +** Perform normalization of the SQL contained in the prepared statement and |
| 123475 | +** store the result in the zNormSql field. The schema for the associated |
| 123476 | +** databases are consulted while performing the normalization in order to |
| 123477 | +** determine if a token appears to be an identifier. All identifiers are |
| 123478 | +** left intact in the normalized SQL and all literals are replaced with a |
| 123479 | +** single '?'. |
| 123480 | +*/ |
| 123481 | +SQLITE_PRIVATE void sqlite3Normalize( |
| 123482 | + Vdbe *pVdbe, /* VM being reprepared */ |
| 123483 | + const char *zSql, /* The original SQL string */ |
| 123484 | + int nSql, /* Size of the input string in bytes */ |
| 123485 | + u8 prepFlags /* The flags passed to sqlite3_prepare_v3() */ |
| 123486 | +){ |
| 123487 | + sqlite3 *db; /* Database handle. */ |
| 123488 | + char *z; /* The output string */ |
| 123489 | + int nZ; /* Size of the output string in bytes */ |
| 123490 | + int i; /* Next character to read from zSql[] */ |
| 123491 | + int j; /* Next character to fill in on z[] */ |
| 123492 | + int tokenType = 0; /* Type of the next token */ |
| 123493 | + int prevTokenType = 0; /* Type of the previous token, except spaces */ |
| 123494 | + int n; /* Size of the next token */ |
| 123495 | + int nParen = 0; /* Nesting level of parenthesis */ |
| 123496 | + Hash inHash; /* Table of parenthesis levels to output index. */ |
| 123497 | + |
| 123498 | + db = sqlite3VdbeDb(pVdbe); |
| 123499 | + assert( db!=0 ); |
| 123500 | + assert( pVdbe->zNormSql==0 ); |
| 123501 | + if( zSql==0 ) return; |
| 123502 | + nZ = estimateNormalizedSize(zSql, nSql, prepFlags); |
| 123503 | + z = sqlite3DbMallocRawNN(db, nZ); |
| 123504 | + if( z==0 ) return; |
| 123505 | + sqlite3HashInit(&inHash); |
| 123506 | + for(i=j=0; i<nSql && zSql[i]; i+=n){ |
| 123507 | + int flags = 0; |
| 123508 | + if( tokenType!=TK_SPACE ) prevTokenType = tokenType; |
| 123509 | + n = sqlite3GetTokenNormalized((unsigned char*)zSql+i, &tokenType, &flags); |
| 123510 | + switch( tokenType ){ |
| 123511 | + case TK_SPACE: { |
| 123512 | + break; |
| 123513 | + } |
| 123514 | + case TK_ILLEGAL: { |
| 123515 | + sqlite3DbFree(db, z); |
| 123516 | + sqlite3HashClear(&inHash); |
| 123517 | + return; |
| 123518 | + } |
| 123519 | + case TK_STRING: |
| 123520 | + case TK_INTEGER: |
| 123521 | + case TK_FLOAT: |
| 123522 | + case TK_VARIABLE: |
| 123523 | + case TK_BLOB: { |
| 123524 | + z[j++] = '?'; |
| 123525 | + break; |
| 123526 | + } |
| 123527 | + case TK_LP: |
| 123528 | + case TK_RP: { |
| 123529 | + if( tokenType==TK_LP ){ |
| 123530 | + nParen++; |
| 123531 | + if( prevTokenType==TK_IN ){ |
| 123532 | + assert( nParen<nSql ); |
| 123533 | + sqlite3HashInsert(&inHash, zSql+nParen, SQLITE_INT_TO_PTR(j)); |
| 123534 | + } |
| 123535 | + }else{ |
| 123536 | + int jj; |
| 123537 | + assert( nParen<nSql ); |
| 123538 | + jj = SQLITE_PTR_TO_INT(sqlite3HashFind(&inHash, zSql+nParen)); |
| 123539 | + if( jj>0 ){ |
| 123540 | + sqlite3HashInsert(&inHash, zSql+nParen, 0); |
| 123541 | + assert( jj+6<nZ ); |
| 123542 | + memcpy(z+jj+1, "?,?,?", 5); |
| 123543 | + j = jj+6; |
| 123544 | + assert( nZ-1-j>=0 ); |
| 123545 | + assert( nZ-1-j<nZ ); |
| 123546 | + memset(z+j, 0, nZ-1-j); |
| 123547 | + } |
| 123548 | + nParen--; |
| 123549 | + } |
| 123550 | + assert( nParen>=0 ); |
| 123551 | + /* Fall through */ |
| 123552 | + } |
| 123553 | + case TK_MINUS: |
| 123554 | + case TK_SEMI: |
| 123555 | + case TK_PLUS: |
| 123556 | + case TK_STAR: |
| 123557 | + case TK_SLASH: |
| 123558 | + case TK_REM: |
| 123559 | + case TK_EQ: |
| 123560 | + case TK_LE: |
| 123561 | + case TK_NE: |
| 123562 | + case TK_LSHIFT: |
| 123563 | + case TK_LT: |
| 123564 | + case TK_RSHIFT: |
| 123565 | + case TK_GT: |
| 123566 | + case TK_GE: |
| 123567 | + case TK_BITOR: |
| 123568 | + case TK_CONCAT: |
| 123569 | + case TK_COMMA: |
| 123570 | + case TK_BITAND: |
| 123571 | + case TK_BITNOT: |
| 123572 | + case TK_DOT: |
| 123573 | + case TK_IN: |
| 123574 | + case TK_IS: |
| 123575 | + case TK_NOT: |
| 123576 | + case TK_NULL: |
| 123577 | + case TK_ID: { |
| 123578 | + if( tokenType==TK_NULL ){ |
| 123579 | + if( prevTokenType==TK_IS || prevTokenType==TK_NOT ){ |
| 123580 | + /* NULL is a keyword in this case, not a literal value */ |
| 123581 | + }else{ |
| 123582 | + /* Here the NULL is a literal value */ |
| 123583 | + z[j++] = '?'; |
| 123584 | + break; |
| 123585 | + } |
| 123586 | + } |
| 123587 | + if( j>0 && sqlite3IsIdChar(z[j-1]) && sqlite3IsIdChar(zSql[i]) ){ |
| 123588 | + z[j++] = ' '; |
| 123589 | + } |
| 123590 | + if( tokenType==TK_ID ){ |
| 123591 | + int i2 = i, n2 = n, rc = SQLITE_OK; |
| 123592 | + if( nParen>0 ){ |
| 123593 | + assert( nParen<nSql ); |
| 123594 | + sqlite3HashInsert(&inHash, zSql+nParen, 0); |
| 123595 | + } |
| 123596 | + if( flags&SQLITE_TOKEN_QUOTED ){ i2++; n2-=2; } |
| 123597 | + if( shouldTreatAsIdentifier(db, zSql+i2, n2, &rc)==0 ){ |
| 123598 | + if( rc!=SQLITE_OK ){ |
| 123599 | + sqlite3DbFree(db, z); |
| 123600 | + sqlite3HashClear(&inHash); |
| 123601 | + return; |
| 123602 | + } |
| 123603 | + if( sqlite3_keyword_check(zSql+i2, n2)==0 ){ |
| 123604 | + z[j++] = '?'; |
| 123605 | + break; |
| 123606 | + } |
| 123607 | + } |
| 123608 | + } |
| 123609 | + copyNormalizedToken(zSql, i, n, flags, z, &j); |
| 123610 | + break; |
| 123611 | + } |
| 123612 | + } |
| 123613 | + } |
| 123614 | + assert( j<nZ && "one" ); |
| 123615 | + while( j>0 && z[j-1]==' ' ){ j--; } |
| 123616 | + if( j>0 && z[j-1]!=';' ){ z[j++] = ';'; } |
| 123617 | + z[j] = 0; |
| 123618 | + assert( j<nZ && "two" ); |
| 123619 | + pVdbe->zNormSql = z; |
| 123620 | + sqlite3HashClear(&inHash); |
| 123621 | +} |
| 123622 | +#endif /* SQLITE_ENABLE_NORMALIZE */ |
| 123623 | + |
| 122917 | 123624 | /* |
| 122918 | 123625 | ** Rerun the compilation of a statement after a schema change. |
| 122919 | 123626 | ** |
| 122920 | 123627 | ** If the statement is successfully recompiled, return SQLITE_OK. Otherwise, |
| 122921 | 123628 | ** if the statement cannot be recompiled because another connection has |
| | @@ -123924,11 +124631,11 @@ |
| 123924 | 124631 | ExprList *pExtra = 0; |
| 123925 | 124632 | for(i=0; i<pEList->nExpr; i++){ |
| 123926 | 124633 | struct ExprList_item *pItem = &pEList->a[i]; |
| 123927 | 124634 | if( pItem->u.x.iOrderByCol==0 ){ |
| 123928 | 124635 | Expr *pExpr = pItem->pExpr; |
| 123929 | | - Table *pTab = pExpr->pTab; |
| 124636 | + Table *pTab = pExpr->y.pTab; |
| 123930 | 124637 | if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 && pTab && !IsVirtual(pTab) |
| 123931 | 124638 | && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF) |
| 123932 | 124639 | ){ |
| 123933 | 124640 | int j; |
| 123934 | 124641 | for(j=0; j<nDefer; j++){ |
| | @@ -123947,16 +124654,16 @@ |
| 123947 | 124654 | } |
| 123948 | 124655 | for(k=0; k<nKey; k++){ |
| 123949 | 124656 | Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0); |
| 123950 | 124657 | if( pNew ){ |
| 123951 | 124658 | pNew->iTable = pExpr->iTable; |
| 123952 | | - pNew->pTab = pExpr->pTab; |
| 124659 | + pNew->y.pTab = pExpr->y.pTab; |
| 123953 | 124660 | pNew->iColumn = pPk ? pPk->aiColumn[k] : -1; |
| 123954 | 124661 | pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew); |
| 123955 | 124662 | } |
| 123956 | 124663 | } |
| 123957 | | - pSort->aDefer[nDefer].pTab = pExpr->pTab; |
| 124664 | + pSort->aDefer[nDefer].pTab = pExpr->y.pTab; |
| 123958 | 124665 | pSort->aDefer[nDefer].iCsr = pExpr->iTable; |
| 123959 | 124666 | pSort->aDefer[nDefer].nKey = nKey; |
| 123960 | 124667 | nDefer++; |
| 123961 | 124668 | } |
| 123962 | 124669 | } |
| | @@ -124801,11 +125508,11 @@ |
| 124801 | 125508 | ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT |
| 124802 | 125509 | ** branch below. */ |
| 124803 | 125510 | break; |
| 124804 | 125511 | } |
| 124805 | 125512 | |
| 124806 | | - assert( pTab && pExpr->pTab==pTab ); |
| 125513 | + assert( pTab && pExpr->y.pTab==pTab ); |
| 124807 | 125514 | if( pS ){ |
| 124808 | 125515 | /* The "table" is actually a sub-select or a view in the FROM clause |
| 124809 | 125516 | ** of the SELECT statement. Return the declaration type and origin |
| 124810 | 125517 | ** data for the result-set column of the sub-select. |
| 124811 | 125518 | */ |
| | @@ -124986,19 +125693,19 @@ |
| 124986 | 125693 | for(i=0; i<pEList->nExpr; i++){ |
| 124987 | 125694 | Expr *p = pEList->a[i].pExpr; |
| 124988 | 125695 | |
| 124989 | 125696 | assert( p!=0 ); |
| 124990 | 125697 | assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */ |
| 124991 | | - assert( p->op!=TK_COLUMN || p->pTab!=0 ); /* Covering idx not yet coded */ |
| 125698 | + assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */ |
| 124992 | 125699 | if( pEList->a[i].zName ){ |
| 124993 | 125700 | /* An AS clause always takes first priority */ |
| 124994 | 125701 | char *zName = pEList->a[i].zName; |
| 124995 | 125702 | sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); |
| 124996 | 125703 | }else if( srcName && p->op==TK_COLUMN ){ |
| 124997 | 125704 | char *zCol; |
| 124998 | 125705 | int iCol = p->iColumn; |
| 124999 | | - pTab = p->pTab; |
| 125706 | + pTab = p->y.pTab; |
| 125000 | 125707 | assert( pTab!=0 ); |
| 125001 | 125708 | if( iCol<0 ) iCol = pTab->iPKey; |
| 125002 | 125709 | assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); |
| 125003 | 125710 | if( iCol<0 ){ |
| 125004 | 125711 | zCol = "rowid"; |
| | @@ -125085,11 +125792,11 @@ |
| 125085 | 125792 | } |
| 125086 | 125793 | assert( pColExpr->op!=TK_AGG_COLUMN ); |
| 125087 | 125794 | if( pColExpr->op==TK_COLUMN ){ |
| 125088 | 125795 | /* For columns use the column name name */ |
| 125089 | 125796 | int iCol = pColExpr->iColumn; |
| 125090 | | - Table *pTab = pColExpr->pTab; |
| 125797 | + Table *pTab = pColExpr->y.pTab; |
| 125091 | 125798 | assert( pTab!=0 ); |
| 125092 | 125799 | if( iCol<0 ) iCol = pTab->iPKey; |
| 125093 | 125800 | zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid"; |
| 125094 | 125801 | }else if( pColExpr->op==TK_ID ){ |
| 125095 | 125802 | assert( !ExprHasProperty(pColExpr, EP_IntValue) ); |
| | @@ -125438,10 +126145,17 @@ |
| 125438 | 126145 | int i; /* Loop counter */ |
| 125439 | 126146 | int rc; /* Result code */ |
| 125440 | 126147 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| 125441 | 126148 | Expr *pLimit; /* Saved LIMIT and OFFSET */ |
| 125442 | 126149 | int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */ |
| 126150 | + |
| 126151 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 126152 | + if( p->pWin ){ |
| 126153 | + sqlite3ErrorMsg(pParse, "cannot use window functions in recursive queries"); |
| 126154 | + return; |
| 126155 | + } |
| 126156 | +#endif |
| 125443 | 126157 | |
| 125444 | 126158 | /* Obtain authorization to do a recursive query */ |
| 125445 | 126159 | if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return; |
| 125446 | 126160 | |
| 125447 | 126161 | /* Process the LIMIT and OFFSET clauses, if they exist */ |
| | @@ -127188,11 +127902,11 @@ |
| 127188 | 127902 | return 1; |
| 127189 | 127903 | } |
| 127190 | 127904 | #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ |
| 127191 | 127905 | |
| 127192 | 127906 | /* |
| 127193 | | -** A structure to keep track of all of the column values that fixed to |
| 127907 | +** A structure to keep track of all of the column values that are fixed to |
| 127194 | 127908 | ** a known value due to WHERE clause constraints of the form COLUMN=VALUE. |
| 127195 | 127909 | */ |
| 127196 | 127910 | typedef struct WhereConst WhereConst; |
| 127197 | 127911 | struct WhereConst { |
| 127198 | 127912 | Parse *pParse; /* Parsing context */ |
| | @@ -127200,17 +127914,32 @@ |
| 127200 | 127914 | int nChng; /* Number of times a constant is propagated */ |
| 127201 | 127915 | Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */ |
| 127202 | 127916 | }; |
| 127203 | 127917 | |
| 127204 | 127918 | /* |
| 127205 | | -** Add a new entry to the pConst object |
| 127919 | +** Add a new entry to the pConst object. Except, do not add duplicate |
| 127920 | +** pColumn entires. |
| 127206 | 127921 | */ |
| 127207 | 127922 | static void constInsert( |
| 127208 | | - WhereConst *pConst, |
| 127209 | | - Expr *pColumn, |
| 127210 | | - Expr *pValue |
| 127923 | + WhereConst *pConst, /* The WhereConst into which we are inserting */ |
| 127924 | + Expr *pColumn, /* The COLUMN part of the constraint */ |
| 127925 | + Expr *pValue /* The VALUE part of the constraint */ |
| 127211 | 127926 | ){ |
| 127927 | + int i; |
| 127928 | + assert( pColumn->op==TK_COLUMN ); |
| 127929 | + |
| 127930 | + /* 2018-10-25 ticket [cf5ed20f] |
| 127931 | + ** Make sure the same pColumn is not inserted more than once */ |
| 127932 | + for(i=0; i<pConst->nConst; i++){ |
| 127933 | + const Expr *pExpr = pConst->apExpr[i*2]; |
| 127934 | + assert( pExpr->op==TK_COLUMN ); |
| 127935 | + if( pExpr->iTable==pColumn->iTable |
| 127936 | + && pExpr->iColumn==pColumn->iColumn |
| 127937 | + ){ |
| 127938 | + return; /* Already present. Return without doing anything. */ |
| 127939 | + } |
| 127940 | + } |
| 127212 | 127941 | |
| 127213 | 127942 | pConst->nConst++; |
| 127214 | 127943 | pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr, |
| 127215 | 127944 | pConst->nConst*2*sizeof(Expr*)); |
| 127216 | 127945 | if( pConst->apExpr==0 ){ |
| | @@ -131187,10 +131916,61 @@ |
| 131187 | 131916 | if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 131188 | 131917 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 131189 | 131918 | } |
| 131190 | 131919 | #endif |
| 131191 | 131920 | } |
| 131921 | + |
| 131922 | +/* |
| 131923 | +** Check to see if column iCol of index pIdx references any of the |
| 131924 | +** columns defined by aXRef and chngRowid. Return true if it does |
| 131925 | +** and false if not. This is an optimization. False-positives are a |
| 131926 | +** performance degradation, but false-negatives can result in a corrupt |
| 131927 | +** index and incorrect answers. |
| 131928 | +** |
| 131929 | +** aXRef[j] will be non-negative if column j of the original table is |
| 131930 | +** being updated. chngRowid will be true if the rowid of the table is |
| 131931 | +** being updated. |
| 131932 | +*/ |
| 131933 | +static int indexColumnIsBeingUpdated( |
| 131934 | + Index *pIdx, /* The index to check */ |
| 131935 | + int iCol, /* Which column of the index to check */ |
| 131936 | + int *aXRef, /* aXRef[j]>=0 if column j is being updated */ |
| 131937 | + int chngRowid /* true if the rowid is being updated */ |
| 131938 | +){ |
| 131939 | + i16 iIdxCol = pIdx->aiColumn[iCol]; |
| 131940 | + assert( iIdxCol!=XN_ROWID ); /* Cannot index rowid */ |
| 131941 | + if( iIdxCol>=0 ){ |
| 131942 | + return aXRef[iIdxCol]>=0; |
| 131943 | + } |
| 131944 | + assert( iIdxCol==XN_EXPR ); |
| 131945 | + assert( pIdx->aColExpr!=0 ); |
| 131946 | + assert( pIdx->aColExpr->a[iCol].pExpr!=0 ); |
| 131947 | + return sqlite3ExprReferencesUpdatedColumn(pIdx->aColExpr->a[iCol].pExpr, |
| 131948 | + aXRef,chngRowid); |
| 131949 | +} |
| 131950 | + |
| 131951 | +/* |
| 131952 | +** Check to see if index pIdx is a partial index whose conditional |
| 131953 | +** expression might change values due to an UPDATE. Return true if |
| 131954 | +** the index is subject to change and false if the index is guaranteed |
| 131955 | +** to be unchanged. This is an optimization. False-positives are a |
| 131956 | +** performance degradation, but false-negatives can result in a corrupt |
| 131957 | +** index and incorrect answers. |
| 131958 | +** |
| 131959 | +** aXRef[j] will be non-negative if column j of the original table is |
| 131960 | +** being updated. chngRowid will be true if the rowid of the table is |
| 131961 | +** being updated. |
| 131962 | +*/ |
| 131963 | +static int indexWhereClauseMightChange( |
| 131964 | + Index *pIdx, /* The index to check */ |
| 131965 | + int *aXRef, /* aXRef[j]>=0 if column j is being updated */ |
| 131966 | + int chngRowid /* true if the rowid is being updated */ |
| 131967 | +){ |
| 131968 | + if( pIdx->pPartIdxWhere==0 ) return 0; |
| 131969 | + return sqlite3ExprReferencesUpdatedColumn(pIdx->pPartIdxWhere, |
| 131970 | + aXRef, chngRowid); |
| 131971 | +} |
| 131192 | 131972 | |
| 131193 | 131973 | /* |
| 131194 | 131974 | ** Process an UPDATE statement. |
| 131195 | 131975 | ** |
| 131196 | 131976 | ** UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL; |
| | @@ -131411,23 +132191,22 @@ |
| 131411 | 132191 | hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey); |
| 131412 | 132192 | |
| 131413 | 132193 | /* There is one entry in the aRegIdx[] array for each index on the table |
| 131414 | 132194 | ** being updated. Fill in aRegIdx[] with a register number that will hold |
| 131415 | 132195 | ** the key for accessing each index. |
| 131416 | | - ** |
| 131417 | | - ** FIXME: Be smarter about omitting indexes that use expressions. |
| 131418 | 132196 | */ |
| 131419 | 132197 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 131420 | 132198 | int reg; |
| 131421 | | - if( chngKey || hasFK>1 || pIdx->pPartIdxWhere || pIdx==pPk ){ |
| 132199 | + if( chngKey || hasFK>1 || pIdx==pPk |
| 132200 | + || indexWhereClauseMightChange(pIdx,aXRef,chngRowid) |
| 132201 | + ){ |
| 131422 | 132202 | reg = ++pParse->nMem; |
| 131423 | 132203 | pParse->nMem += pIdx->nColumn; |
| 131424 | 132204 | }else{ |
| 131425 | 132205 | reg = 0; |
| 131426 | 132206 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 131427 | | - i16 iIdxCol = pIdx->aiColumn[i]; |
| 131428 | | - if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){ |
| 132207 | + if( indexColumnIsBeingUpdated(pIdx, i, aXRef, chngRowid) ){ |
| 131429 | 132208 | reg = ++pParse->nMem; |
| 131430 | 132209 | pParse->nMem += pIdx->nColumn; |
| 131431 | 132210 | if( (onError==OE_Replace) |
| 131432 | 132211 | || (onError==OE_Default && pIdx->onError==OE_Replace) |
| 131433 | 132212 | ){ |
| | @@ -131972,11 +132751,11 @@ |
| 131972 | 132751 | for(i=0; i<pTab->nCol; i++){ |
| 131973 | 132752 | if( aXRef[i]>=0 ){ |
| 131974 | 132753 | sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i); |
| 131975 | 132754 | }else{ |
| 131976 | 132755 | sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i); |
| 131977 | | - sqlite3VdbeChangeP5(v, 1); /* Enable sqlite3_vtab_nochange() */ |
| 132756 | + sqlite3VdbeChangeP5(v, OPFLAG_NOCHNG);/* Enable sqlite3_vtab_nochange() */ |
| 131978 | 132757 | } |
| 131979 | 132758 | } |
| 131980 | 132759 | if( HasRowid(pTab) ){ |
| 131981 | 132760 | sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg); |
| 131982 | 132761 | if( pRowid ){ |
| | @@ -132473,11 +133252,12 @@ |
| 132473 | 133252 | saved_nChange = db->nChange; |
| 132474 | 133253 | saved_nTotalChange = db->nTotalChange; |
| 132475 | 133254 | saved_mTrace = db->mTrace; |
| 132476 | 133255 | db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks; |
| 132477 | 133256 | db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum; |
| 132478 | | - db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows); |
| 133257 | + db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder |
| 133258 | + | SQLITE_Defensive | SQLITE_CountRows); |
| 132479 | 133259 | db->mTrace = 0; |
| 132480 | 133260 | |
| 132481 | 133261 | zDbMain = db->aDb[iDb].zDbSName; |
| 132482 | 133262 | pMain = db->aDb[iDb].pBt; |
| 132483 | 133263 | isMemDb = sqlite3PagerIsMemdb(sqlite3BtreePager(pMain)); |
| | @@ -133015,22 +133795,19 @@ |
| 133015 | 133795 | Token *pName1, /* Name of new table, or database name */ |
| 133016 | 133796 | Token *pName2, /* Name of new table or NULL */ |
| 133017 | 133797 | Token *pModuleName, /* Name of the module for the virtual table */ |
| 133018 | 133798 | int ifNotExists /* No error if the table already exists */ |
| 133019 | 133799 | ){ |
| 133020 | | - int iDb; /* The database the table is being created in */ |
| 133021 | 133800 | Table *pTable; /* The new virtual table */ |
| 133022 | 133801 | sqlite3 *db; /* Database connection */ |
| 133023 | 133802 | |
| 133024 | 133803 | sqlite3StartTable(pParse, pName1, pName2, 0, 0, 1, ifNotExists); |
| 133025 | 133804 | pTable = pParse->pNewTable; |
| 133026 | 133805 | if( pTable==0 ) return; |
| 133027 | 133806 | assert( 0==pTable->pIndex ); |
| 133028 | 133807 | |
| 133029 | 133808 | db = pParse->db; |
| 133030 | | - iDb = sqlite3SchemaToIndex(db, pTable->pSchema); |
| 133031 | | - assert( iDb>=0 ); |
| 133032 | 133809 | |
| 133033 | 133810 | assert( pTable->nModuleArg==0 ); |
| 133034 | 133811 | addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName)); |
| 133035 | 133812 | addModuleArgument(db, pTable, 0); |
| 133036 | 133813 | addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName)); |
| | @@ -133046,10 +133823,12 @@ |
| 133046 | 133823 | ** The first invocation, to obtain permission to INSERT a row into the |
| 133047 | 133824 | ** sqlite_master table, has already been made by sqlite3StartTable(). |
| 133048 | 133825 | ** The second call, to obtain permission to create the table, is made now. |
| 133049 | 133826 | */ |
| 133050 | 133827 | if( pTable->azModuleArg ){ |
| 133828 | + int iDb = sqlite3SchemaToIndex(db, pTable->pSchema); |
| 133829 | + assert( iDb>=0 ); /* The database the table is being created in */ |
| 133051 | 133830 | sqlite3AuthCheck(pParse, SQLITE_CREATE_VTABLE, pTable->zName, |
| 133052 | 133831 | pTable->azModuleArg[0], pParse->db->aDb[iDb].zDbSName); |
| 133053 | 133832 | } |
| 133054 | 133833 | #endif |
| 133055 | 133834 | } |
| | @@ -133740,11 +134519,11 @@ |
| 133740 | 134519 | int rc = 0; |
| 133741 | 134520 | |
| 133742 | 134521 | /* Check to see the left operand is a column in a virtual table */ |
| 133743 | 134522 | if( NEVER(pExpr==0) ) return pDef; |
| 133744 | 134523 | if( pExpr->op!=TK_COLUMN ) return pDef; |
| 133745 | | - pTab = pExpr->pTab; |
| 134524 | + pTab = pExpr->y.pTab; |
| 133746 | 134525 | if( pTab==0 ) return pDef; |
| 133747 | 134526 | if( !IsVirtual(pTab) ) return pDef; |
| 133748 | 134527 | pVtab = sqlite3GetVTable(db, pTab)->pVtab; |
| 133749 | 134528 | assert( pVtab!=0 ); |
| 133750 | 134529 | assert( pVtab->pModule!=0 ); |
| | @@ -134360,15 +135139,36 @@ |
| 134360 | 135139 | #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 |
| 134361 | 135140 | UnpackedRecord *pRec; /* Probe for stat4 (if required) */ |
| 134362 | 135141 | int nRecValid; /* Number of valid fields currently in pRec */ |
| 134363 | 135142 | #endif |
| 134364 | 135143 | unsigned int bldFlags; /* SQLITE_BLDF_* flags */ |
| 135144 | + unsigned int iPlanLimit; /* Search limiter */ |
| 134365 | 135145 | }; |
| 134366 | 135146 | |
| 134367 | 135147 | /* Allowed values for WhereLoopBuider.bldFlags */ |
| 134368 | 135148 | #define SQLITE_BLDF_INDEXED 0x0001 /* An index is used */ |
| 134369 | 135149 | #define SQLITE_BLDF_UNIQUE 0x0002 /* All keys of a UNIQUE index used */ |
| 135150 | + |
| 135151 | +/* The WhereLoopBuilder.iPlanLimit is used to limit the number of |
| 135152 | +** index+constraint combinations the query planner will consider for a |
| 135153 | +** particular query. If this parameter is unlimited, then certain |
| 135154 | +** pathological queries can spend excess time in the sqlite3WhereBegin() |
| 135155 | +** routine. The limit is high enough that is should not impact real-world |
| 135156 | +** queries. |
| 135157 | +** |
| 135158 | +** SQLITE_QUERY_PLANNER_LIMIT is the baseline limit. The limit is |
| 135159 | +** increased by SQLITE_QUERY_PLANNER_LIMIT_INCR before each term of the FROM |
| 135160 | +** clause is processed, so that every table in a join is guaranteed to be |
| 135161 | +** able to propose a some index+constraint combinations even if the initial |
| 135162 | +** baseline limit was exhausted by prior tables of the join. |
| 135163 | +*/ |
| 135164 | +#ifndef SQLITE_QUERY_PLANNER_LIMIT |
| 135165 | +# define SQLITE_QUERY_PLANNER_LIMIT 20000 |
| 135166 | +#endif |
| 135167 | +#ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR |
| 135168 | +# define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000 |
| 135169 | +#endif |
| 134370 | 135170 | |
| 134371 | 135171 | /* |
| 134372 | 135172 | ** The WHERE clause processing routine has two halves. The |
| 134373 | 135173 | ** first part does the start of the WHERE loop and the second |
| 134374 | 135174 | ** half does the tail of the WHERE loop. An instance of |
| | @@ -134927,11 +135727,11 @@ |
| 134927 | 135727 | Select *pSelect; /* Pointer to the SELECT on the RHS */ |
| 134928 | 135728 | |
| 134929 | 135729 | for(i=iEq; i<pLoop->nLTerm; i++){ |
| 134930 | 135730 | if( pLoop->aLTerm[i]->pExpr==pX ){ |
| 134931 | 135731 | int iField = pLoop->aLTerm[i]->iField - 1; |
| 134932 | | - assert( pOrigRhs->a[iField].pExpr!=0 ); |
| 135732 | + if( pOrigRhs->a[iField].pExpr==0 ) continue; /* Duplicate PK column */ |
| 134933 | 135733 | pRhs = sqlite3ExprListAppend(pParse, pRhs, pOrigRhs->a[iField].pExpr); |
| 134934 | 135734 | pOrigRhs->a[iField].pExpr = 0; |
| 134935 | 135735 | assert( pOrigLhs->a[iField].pExpr!=0 ); |
| 134936 | 135736 | pLhs = sqlite3ExprListAppend(pParse, pLhs, pOrigLhs->a[iField].pExpr); |
| 134937 | 135737 | pOrigLhs->a[iField].pExpr = 0; |
| | @@ -135619,11 +136419,11 @@ |
| 135619 | 136419 | IdxExprTrans *pX = p->u.pIdxTrans; |
| 135620 | 136420 | if( sqlite3ExprCompare(0, pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){ |
| 135621 | 136421 | pExpr->op = TK_COLUMN; |
| 135622 | 136422 | pExpr->iTable = pX->iIdxCur; |
| 135623 | 136423 | pExpr->iColumn = pX->iIdxCol; |
| 135624 | | - pExpr->pTab = 0; |
| 136424 | + pExpr->y.pTab = 0; |
| 135625 | 136425 | return WRC_Prune; |
| 135626 | 136426 | }else{ |
| 135627 | 136427 | return WRC_Continue; |
| 135628 | 136428 | } |
| 135629 | 136429 | } |
| | @@ -137019,11 +137819,11 @@ |
| 137019 | 137819 | || zNew[0]=='-' |
| 137020 | 137820 | || (zNew[0]+1=='0' && iTo==1) |
| 137021 | 137821 | ){ |
| 137022 | 137822 | if( pLeft->op!=TK_COLUMN |
| 137023 | 137823 | || sqlite3ExprAffinity(pLeft)!=SQLITE_AFF_TEXT |
| 137024 | | - || IsVirtual(pLeft->pTab) /* Value might be numeric */ |
| 137824 | + || IsVirtual(pLeft->y.pTab) /* Value might be numeric */ |
| 137025 | 137825 | ){ |
| 137026 | 137826 | sqlite3ExprDelete(db, pPrefix); |
| 137027 | 137827 | sqlite3ValueFree(pVal); |
| 137028 | 137828 | return 0; |
| 137029 | 137829 | } |
| | @@ -137120,11 +137920,11 @@ |
| 137120 | 137920 | ** |
| 137121 | 137921 | ** vtab_column MATCH expression |
| 137122 | 137922 | ** MATCH(expression,vtab_column) |
| 137123 | 137923 | */ |
| 137124 | 137924 | pCol = pList->a[1].pExpr; |
| 137125 | | - if( pCol->op==TK_COLUMN && IsVirtual(pCol->pTab) ){ |
| 137925 | + if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){ |
| 137126 | 137926 | for(i=0; i<ArraySize(aOp); i++){ |
| 137127 | 137927 | if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){ |
| 137128 | 137928 | *peOp2 = aOp[i].eOp2; |
| 137129 | 137929 | *ppRight = pList->a[0].pExpr; |
| 137130 | 137930 | *ppLeft = pCol; |
| | @@ -137142,16 +137942,16 @@ |
| 137142 | 137942 | ** Historically, xFindFunction expected to see lower-case function |
| 137143 | 137943 | ** names. But for this use case, xFindFunction is expected to deal |
| 137144 | 137944 | ** with function names in an arbitrary case. |
| 137145 | 137945 | */ |
| 137146 | 137946 | pCol = pList->a[0].pExpr; |
| 137147 | | - if( pCol->op==TK_COLUMN && IsVirtual(pCol->pTab) ){ |
| 137947 | + if( pCol->op==TK_COLUMN && IsVirtual(pCol->y.pTab) ){ |
| 137148 | 137948 | sqlite3_vtab *pVtab; |
| 137149 | 137949 | sqlite3_module *pMod; |
| 137150 | 137950 | void (*xNotUsed)(sqlite3_context*,int,sqlite3_value**); |
| 137151 | 137951 | void *pNotUsed; |
| 137152 | | - pVtab = sqlite3GetVTable(db, pCol->pTab)->pVtab; |
| 137952 | + pVtab = sqlite3GetVTable(db, pCol->y.pTab)->pVtab; |
| 137153 | 137953 | assert( pVtab!=0 ); |
| 137154 | 137954 | assert( pVtab->pModule!=0 ); |
| 137155 | 137955 | pMod = (sqlite3_module *)pVtab->pModule; |
| 137156 | 137956 | if( pMod->xFindFunction!=0 ){ |
| 137157 | 137957 | i = pMod->xFindFunction(pVtab,2, pExpr->u.zToken, &xNotUsed, &pNotUsed); |
| | @@ -137165,14 +137965,14 @@ |
| 137165 | 137965 | } |
| 137166 | 137966 | }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){ |
| 137167 | 137967 | int res = 0; |
| 137168 | 137968 | Expr *pLeft = pExpr->pLeft; |
| 137169 | 137969 | Expr *pRight = pExpr->pRight; |
| 137170 | | - if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->pTab) ){ |
| 137970 | + if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->y.pTab) ){ |
| 137171 | 137971 | res++; |
| 137172 | 137972 | } |
| 137173 | | - if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->pTab) ){ |
| 137973 | + if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->y.pTab) ){ |
| 137174 | 137974 | res++; |
| 137175 | 137975 | SWAP(Expr*, pLeft, pRight); |
| 137176 | 137976 | } |
| 137177 | 137977 | *ppLeft = pLeft; |
| 137178 | 137978 | *ppRight = pRight; |
| | @@ -138120,10 +138920,11 @@ |
| 138120 | 138920 | ** Note that the virtual term must be tagged with TERM_VNULL. |
| 138121 | 138921 | */ |
| 138122 | 138922 | if( pExpr->op==TK_NOTNULL |
| 138123 | 138923 | && pExpr->pLeft->op==TK_COLUMN |
| 138124 | 138924 | && pExpr->pLeft->iColumn>=0 |
| 138925 | + && !ExprHasProperty(pExpr, EP_FromJoin) |
| 138125 | 138926 | && OptimizationEnabled(db, SQLITE_Stat34) |
| 138126 | 138927 | ){ |
| 138127 | 138928 | Expr *pNewExpr; |
| 138128 | 138929 | Expr *pLeft = pExpr->pLeft; |
| 138129 | 138930 | int idxNew; |
| | @@ -138311,10 +139112,11 @@ |
| 138311 | 139112 | pTab = pItem->pTab; |
| 138312 | 139113 | assert( pTab!=0 ); |
| 138313 | 139114 | pArgs = pItem->u1.pFuncArg; |
| 138314 | 139115 | if( pArgs==0 ) return; |
| 138315 | 139116 | for(j=k=0; j<pArgs->nExpr; j++){ |
| 139117 | + Expr *pRhs; |
| 138316 | 139118 | while( k<pTab->nCol && (pTab->aCol[k].colFlags & COLFLAG_HIDDEN)==0 ){k++;} |
| 138317 | 139119 | if( k>=pTab->nCol ){ |
| 138318 | 139120 | sqlite3ErrorMsg(pParse, "too many arguments on %s() - max %d", |
| 138319 | 139121 | pTab->zName, j); |
| 138320 | 139122 | return; |
| | @@ -138321,13 +139123,14 @@ |
| 138321 | 139123 | } |
| 138322 | 139124 | pColRef = sqlite3ExprAlloc(pParse->db, TK_COLUMN, 0, 0); |
| 138323 | 139125 | if( pColRef==0 ) return; |
| 138324 | 139126 | pColRef->iTable = pItem->iCursor; |
| 138325 | 139127 | pColRef->iColumn = k++; |
| 138326 | | - pColRef->pTab = pTab; |
| 138327 | | - pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, |
| 138328 | | - sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0)); |
| 139128 | + pColRef->y.pTab = pTab; |
| 139129 | + pRhs = sqlite3PExpr(pParse, TK_UPLUS, |
| 139130 | + sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0); |
| 139131 | + pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs); |
| 138329 | 139132 | whereClauseInsert(pWC, pTerm, TERM_DYNAMIC); |
| 138330 | 139133 | } |
| 138331 | 139134 | } |
| 138332 | 139135 | |
| 138333 | 139136 | /************** End of whereexpr.c *******************************************/ |
| | @@ -139186,11 +139989,10 @@ |
| 139186 | 139989 | sqlite3VdbeChangeP2(v, addrCounter, regBase+n); |
| 139187 | 139990 | testcase( pParse->db->mallocFailed ); |
| 139188 | 139991 | translateColumnToCopy(pParse, addrTop, pLevel->iTabCur, |
| 139189 | 139992 | pTabItem->regResult, 1); |
| 139190 | 139993 | sqlite3VdbeGoto(v, addrTop); |
| 139191 | | - pTabItem->fg.viaCoroutine = 0; |
| 139192 | 139994 | }else{ |
| 139193 | 139995 | sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v); |
| 139194 | 139996 | } |
| 139195 | 139997 | sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX); |
| 139196 | 139998 | sqlite3VdbeJumpHere(v, addrTop); |
| | @@ -140457,10 +141259,18 @@ |
| 140457 | 141259 | static int whereLoopInsert(WhereLoopBuilder *pBuilder, WhereLoop *pTemplate){ |
| 140458 | 141260 | WhereLoop **ppPrev, *p; |
| 140459 | 141261 | WhereInfo *pWInfo = pBuilder->pWInfo; |
| 140460 | 141262 | sqlite3 *db = pWInfo->pParse->db; |
| 140461 | 141263 | int rc; |
| 141264 | + |
| 141265 | + /* Stop the search once we hit the query planner search limit */ |
| 141266 | + if( pBuilder->iPlanLimit==0 ){ |
| 141267 | + WHERETRACE(0xffffffff,("=== query planner search limit reached ===\n")); |
| 141268 | + if( pBuilder->pOrSet ) pBuilder->pOrSet->n = 0; |
| 141269 | + return SQLITE_DONE; |
| 141270 | + } |
| 141271 | + pBuilder->iPlanLimit--; |
| 140462 | 141272 | |
| 140463 | 141273 | /* If pBuilder->pOrSet is defined, then only keep track of the costs |
| 140464 | 141274 | ** and prereqs. |
| 140465 | 141275 | */ |
| 140466 | 141276 | if( pBuilder->pOrSet!=0 ){ |
| | @@ -141864,13 +142674,15 @@ |
| 141864 | 142674 | u8 priorJointype = 0; |
| 141865 | 142675 | |
| 141866 | 142676 | /* Loop over the tables in the join, from left to right */ |
| 141867 | 142677 | pNew = pBuilder->pNew; |
| 141868 | 142678 | whereLoopInit(pNew); |
| 142679 | + pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT; |
| 141869 | 142680 | for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){ |
| 141870 | 142681 | Bitmask mUnusable = 0; |
| 141871 | 142682 | pNew->iTab = iTab; |
| 142683 | + pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR; |
| 141872 | 142684 | pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor); |
| 141873 | 142685 | if( ((pItem->fg.jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){ |
| 141874 | 142686 | /* This condition is true when pItem is the FROM clause term on the |
| 141875 | 142687 | ** right-hand-side of a LEFT or CROSS JOIN. */ |
| 141876 | 142688 | mPrereq = mPrior; |
| | @@ -141892,11 +142704,19 @@ |
| 141892 | 142704 | } |
| 141893 | 142705 | if( rc==SQLITE_OK && pBuilder->pWC->hasOr ){ |
| 141894 | 142706 | rc = whereLoopAddOr(pBuilder, mPrereq, mUnusable); |
| 141895 | 142707 | } |
| 141896 | 142708 | mPrior |= pNew->maskSelf; |
| 141897 | | - if( rc || db->mallocFailed ) break; |
| 142709 | + if( rc || db->mallocFailed ){ |
| 142710 | + if( rc==SQLITE_DONE ){ |
| 142711 | + /* We hit the query planner search limit set by iPlanLimit */ |
| 142712 | + sqlite3_log(SQLITE_WARNING, "abbreviated query algorithm search"); |
| 142713 | + rc = SQLITE_OK; |
| 142714 | + }else{ |
| 142715 | + break; |
| 142716 | + } |
| 142717 | + } |
| 141898 | 142718 | } |
| 141899 | 142719 | |
| 141900 | 142720 | whereLoopClear(db, pNew); |
| 141901 | 142721 | return rc; |
| 141902 | 142722 | } |
| | @@ -144274,16 +145094,16 @@ |
| 144274 | 145094 | } |
| 144275 | 145095 | |
| 144276 | 145096 | switch( pExpr->op ){ |
| 144277 | 145097 | |
| 144278 | 145098 | case TK_FUNCTION: |
| 144279 | | - if( pExpr->pWin==0 ){ |
| 145099 | + if( !ExprHasProperty(pExpr, EP_WinFunc) ){ |
| 144280 | 145100 | break; |
| 144281 | 145101 | }else{ |
| 144282 | 145102 | Window *pWin; |
| 144283 | 145103 | for(pWin=p->pWin; pWin; pWin=pWin->pNextWin){ |
| 144284 | | - if( pExpr->pWin==pWin ){ |
| 145104 | + if( pExpr->y.pWin==pWin ){ |
| 144285 | 145105 | assert( pWin->pOwner==pExpr ); |
| 144286 | 145106 | return WRC_Prune; |
| 144287 | 145107 | } |
| 144288 | 145108 | } |
| 144289 | 145109 | } |
| | @@ -144396,11 +145216,11 @@ |
| 144396 | 145216 | ** are invoked in the correct order as described under "SELECT REWRITING" |
| 144397 | 145217 | ** at the top of this file. |
| 144398 | 145218 | */ |
| 144399 | 145219 | SQLITE_PRIVATE int sqlite3WindowRewrite(Parse *pParse, Select *p){ |
| 144400 | 145220 | int rc = SQLITE_OK; |
| 144401 | | - if( p->pWin ){ |
| 145221 | + if( p->pWin && p->pPrior==0 ){ |
| 144402 | 145222 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 144403 | 145223 | sqlite3 *db = pParse->db; |
| 144404 | 145224 | Select *pSub = 0; /* The subquery */ |
| 144405 | 145225 | SrcList *pSrc = p->pSrc; |
| 144406 | 145226 | Expr *pWhere = p->pWhere; |
| | @@ -144609,15 +145429,17 @@ |
| 144609 | 145429 | /* |
| 144610 | 145430 | ** Attach window object pWin to expression p. |
| 144611 | 145431 | */ |
| 144612 | 145432 | SQLITE_PRIVATE void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){ |
| 144613 | 145433 | if( p ){ |
| 145434 | + assert( p->op==TK_FUNCTION ); |
| 144614 | 145435 | /* This routine is only called for the parser. If pWin was not |
| 144615 | 145436 | ** allocated due to an OOM, then the parser would fail before ever |
| 144616 | 145437 | ** invoking this routine */ |
| 144617 | 145438 | if( ALWAYS(pWin) ){ |
| 144618 | | - p->pWin = pWin; |
| 145439 | + p->y.pWin = pWin; |
| 145440 | + ExprSetProperty(p, EP_WinFunc); |
| 144619 | 145441 | pWin->pOwner = p; |
| 144620 | 145442 | if( p->flags & EP_Distinct ){ |
| 144621 | 145443 | sqlite3ErrorMsg(pParse, |
| 144622 | 145444 | "DISTINCT is not supported for window functions"); |
| 144623 | 145445 | } |
| | @@ -145776,11 +146598,11 @@ |
| 145776 | 146598 | ** third argument. Set the Window.pOwner field of the new object to |
| 145777 | 146599 | ** pOwner. |
| 145778 | 146600 | */ |
| 145779 | 146601 | SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p){ |
| 145780 | 146602 | Window *pNew = 0; |
| 145781 | | - if( p ){ |
| 146603 | + if( ALWAYS(p) ){ |
| 145782 | 146604 | pNew = sqlite3DbMallocZero(db, sizeof(Window)); |
| 145783 | 146605 | if( pNew ){ |
| 145784 | 146606 | pNew->zName = sqlite3DbStrDup(db, p->zName); |
| 145785 | 146607 | pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0); |
| 145786 | 146608 | pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0); |
| | @@ -146029,17 +146851,14 @@ |
| 146029 | 146851 | p->flags = EP_Leaf; |
| 146030 | 146852 | p->iAgg = -1; |
| 146031 | 146853 | p->pLeft = p->pRight = 0; |
| 146032 | 146854 | p->x.pList = 0; |
| 146033 | 146855 | p->pAggInfo = 0; |
| 146034 | | - p->pTab = 0; |
| 146856 | + p->y.pTab = 0; |
| 146035 | 146857 | p->op2 = 0; |
| 146036 | 146858 | p->iTable = 0; |
| 146037 | 146859 | p->iColumn = 0; |
| 146038 | | -#ifndef SQLITE_OMIT_WINDOWFUNC |
| 146039 | | - p->pWin = 0; |
| 146040 | | -#endif |
| 146041 | 146860 | p->u.zToken = (char*)&p[1]; |
| 146042 | 146861 | memcpy(p->u.zToken, t.z, t.n); |
| 146043 | 146862 | p->u.zToken[t.n] = 0; |
| 146044 | 146863 | if( sqlite3Isquote(p->u.zToken[0]) ){ |
| 146045 | 146864 | if( p->u.zToken[0]=='"' ) p->flags |= EP_DblQuoted; |
| | @@ -146186,21 +147005,21 @@ |
| 146186 | 147005 | #define sqlite3ParserCTX_PDECL ,Parse *pParse |
| 146187 | 147006 | #define sqlite3ParserCTX_PARAM ,pParse |
| 146188 | 147007 | #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse; |
| 146189 | 147008 | #define sqlite3ParserCTX_STORE yypParser->pParse=pParse; |
| 146190 | 147009 | #define YYFALLBACK 1 |
| 146191 | | -#define YYNSTATE 521 |
| 147010 | +#define YYNSTATE 525 |
| 146192 | 147011 | #define YYNRULE 367 |
| 146193 | 147012 | #define YYNTOKEN 155 |
| 146194 | | -#define YY_MAX_SHIFT 520 |
| 146195 | | -#define YY_MIN_SHIFTREDUCE 756 |
| 146196 | | -#define YY_MAX_SHIFTREDUCE 1122 |
| 146197 | | -#define YY_ERROR_ACTION 1123 |
| 146198 | | -#define YY_ACCEPT_ACTION 1124 |
| 146199 | | -#define YY_NO_ACTION 1125 |
| 146200 | | -#define YY_MIN_REDUCE 1126 |
| 146201 | | -#define YY_MAX_REDUCE 1492 |
| 147013 | +#define YY_MAX_SHIFT 524 |
| 147014 | +#define YY_MIN_SHIFTREDUCE 760 |
| 147015 | +#define YY_MAX_SHIFTREDUCE 1126 |
| 147016 | +#define YY_ERROR_ACTION 1127 |
| 147017 | +#define YY_ACCEPT_ACTION 1128 |
| 147018 | +#define YY_NO_ACTION 1129 |
| 147019 | +#define YY_MIN_REDUCE 1130 |
| 147020 | +#define YY_MAX_REDUCE 1496 |
| 146202 | 147021 | /************* End control #defines *******************************************/ |
| 146203 | 147022 | #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) |
| 146204 | 147023 | |
| 146205 | 147024 | /* Define the yytestcase() macro to be a no-op if is not already defined |
| 146206 | 147025 | ** otherwise. |
| | @@ -146265,211 +147084,211 @@ |
| 146265 | 147084 | ** yy_default[] Default action for each state. |
| 146266 | 147085 | ** |
| 146267 | 147086 | *********** Begin parsing tables **********************************************/ |
| 146268 | 147087 | #define YY_ACTTAB_COUNT (2009) |
| 146269 | 147088 | static const YYACTIONTYPE yy_action[] = { |
| 146270 | | - /* 0 */ 368, 105, 102, 197, 105, 102, 197, 515, 1124, 1, |
| 146271 | | - /* 10 */ 1, 520, 2, 1128, 515, 1192, 1171, 1456, 275, 370, |
| 146272 | | - /* 20 */ 127, 1389, 1197, 1197, 1192, 1166, 178, 1205, 64, 64, |
| 146273 | | - /* 30 */ 477, 887, 322, 428, 348, 37, 37, 808, 362, 888, |
| 146274 | | - /* 40 */ 509, 509, 509, 112, 113, 103, 1100, 1100, 953, 956, |
| 146275 | | - /* 50 */ 946, 946, 110, 110, 111, 111, 111, 111, 365, 252, |
| 146276 | | - /* 60 */ 252, 515, 252, 252, 497, 515, 309, 515, 459, 515, |
| 146277 | | - /* 70 */ 1079, 491, 512, 478, 6, 512, 809, 134, 498, 228, |
| 146278 | | - /* 80 */ 194, 428, 37, 37, 515, 208, 64, 64, 64, 64, |
| 147089 | + /* 0 */ 372, 105, 102, 197, 105, 102, 197, 519, 1128, 1, |
| 147090 | + /* 10 */ 1, 524, 2, 1132, 519, 1196, 1175, 1460, 275, 374, |
| 147091 | + /* 20 */ 127, 1393, 1201, 1201, 1196, 1170, 178, 1209, 64, 64, |
| 147092 | + /* 30 */ 481, 891, 326, 432, 352, 37, 37, 812, 366, 892, |
| 147093 | + /* 40 */ 513, 513, 513, 112, 113, 103, 1104, 1104, 957, 960, |
| 147094 | + /* 50 */ 950, 950, 110, 110, 111, 111, 111, 111, 369, 252, |
| 147095 | + /* 60 */ 252, 519, 252, 252, 501, 519, 313, 519, 463, 519, |
| 147096 | + /* 70 */ 1083, 495, 516, 482, 6, 516, 813, 134, 502, 228, |
| 147097 | + /* 80 */ 194, 432, 37, 37, 519, 208, 64, 64, 64, 64, |
| 146279 | 147098 | /* 90 */ 13, 13, 109, 109, 109, 109, 108, 108, 107, 107, |
| 146280 | | - /* 100 */ 107, 106, 401, 258, 381, 13, 13, 398, 397, 428, |
| 146281 | | - /* 110 */ 252, 252, 370, 476, 405, 1104, 1079, 1080, 1081, 386, |
| 146282 | | - /* 120 */ 1106, 390, 497, 512, 497, 1423, 1419, 304, 1105, 307, |
| 146283 | | - /* 130 */ 1256, 496, 370, 499, 16, 16, 112, 113, 103, 1100, |
| 146284 | | - /* 140 */ 1100, 953, 956, 946, 946, 110, 110, 111, 111, 111, |
| 146285 | | - /* 150 */ 111, 262, 1107, 495, 1107, 401, 112, 113, 103, 1100, |
| 146286 | | - /* 160 */ 1100, 953, 956, 946, 946, 110, 110, 111, 111, 111, |
| 146287 | | - /* 170 */ 111, 129, 1425, 343, 1420, 339, 1059, 492, 1057, 263, |
| 146288 | | - /* 180 */ 73, 105, 102, 197, 994, 109, 109, 109, 109, 108, |
| 146289 | | - /* 190 */ 108, 107, 107, 107, 106, 401, 370, 111, 111, 111, |
| 146290 | | - /* 200 */ 111, 104, 492, 89, 1432, 109, 109, 109, 109, 108, |
| 146291 | | - /* 210 */ 108, 107, 107, 107, 106, 401, 111, 111, 111, 111, |
| 146292 | | - /* 220 */ 112, 113, 103, 1100, 1100, 953, 956, 946, 946, 110, |
| 147099 | + /* 100 */ 107, 106, 405, 258, 385, 13, 13, 402, 401, 432, |
| 147100 | + /* 110 */ 252, 252, 374, 480, 409, 1108, 1083, 1084, 1085, 390, |
| 147101 | + /* 120 */ 1110, 394, 501, 516, 501, 1427, 1423, 308, 1109, 311, |
| 147102 | + /* 130 */ 1260, 500, 374, 503, 16, 16, 112, 113, 103, 1104, |
| 147103 | + /* 140 */ 1104, 957, 960, 950, 950, 110, 110, 111, 111, 111, |
| 147104 | + /* 150 */ 111, 262, 1111, 499, 1111, 405, 112, 113, 103, 1104, |
| 147105 | + /* 160 */ 1104, 957, 960, 950, 950, 110, 110, 111, 111, 111, |
| 147106 | + /* 170 */ 111, 129, 1429, 347, 1424, 343, 1063, 496, 1061, 263, |
| 147107 | + /* 180 */ 73, 105, 102, 197, 998, 109, 109, 109, 109, 108, |
| 147108 | + /* 190 */ 108, 107, 107, 107, 106, 405, 374, 111, 111, 111, |
| 147109 | + /* 200 */ 111, 104, 496, 89, 1436, 109, 109, 109, 109, 108, |
| 147110 | + /* 210 */ 108, 107, 107, 107, 106, 405, 111, 111, 111, 111, |
| 147111 | + /* 220 */ 112, 113, 103, 1104, 1104, 957, 960, 950, 950, 110, |
| 146293 | 147112 | /* 230 */ 110, 111, 111, 111, 111, 109, 109, 109, 109, 108, |
| 146294 | | - /* 240 */ 108, 107, 107, 107, 106, 401, 114, 108, 108, 107, |
| 146295 | | - /* 250 */ 107, 107, 106, 401, 109, 109, 109, 109, 108, 108, |
| 146296 | | - /* 260 */ 107, 107, 107, 106, 401, 152, 399, 399, 399, 109, |
| 146297 | | - /* 270 */ 109, 109, 109, 108, 108, 107, 107, 107, 106, 401, |
| 146298 | | - /* 280 */ 178, 493, 1412, 434, 1037, 1486, 1079, 515, 1486, 370, |
| 146299 | | - /* 290 */ 421, 297, 357, 412, 74, 1079, 109, 109, 109, 109, |
| 146300 | | - /* 300 */ 108, 108, 107, 107, 107, 106, 401, 1413, 37, 37, |
| 146301 | | - /* 310 */ 1431, 274, 506, 112, 113, 103, 1100, 1100, 953, 956, |
| 146302 | | - /* 320 */ 946, 946, 110, 110, 111, 111, 111, 111, 1436, 520, |
| 146303 | | - /* 330 */ 2, 1128, 1079, 1080, 1081, 430, 275, 1079, 127, 366, |
| 146304 | | - /* 340 */ 933, 1079, 1080, 1081, 220, 1205, 913, 458, 455, 454, |
| 146305 | | - /* 350 */ 392, 167, 515, 1035, 152, 445, 924, 453, 152, 874, |
| 146306 | | - /* 360 */ 923, 289, 109, 109, 109, 109, 108, 108, 107, 107, |
| 146307 | | - /* 370 */ 107, 106, 401, 13, 13, 261, 853, 252, 252, 227, |
| 146308 | | - /* 380 */ 106, 401, 370, 1079, 1080, 1081, 311, 388, 1079, 296, |
| 146309 | | - /* 390 */ 512, 923, 923, 925, 231, 323, 1255, 1388, 1423, 490, |
| 146310 | | - /* 400 */ 274, 506, 12, 208, 274, 506, 112, 113, 103, 1100, |
| 146311 | | - /* 410 */ 1100, 953, 956, 946, 946, 110, 110, 111, 111, 111, |
| 146312 | | - /* 420 */ 111, 1440, 286, 1128, 288, 1079, 1097, 247, 275, 1098, |
| 146313 | | - /* 430 */ 127, 387, 405, 389, 1079, 1080, 1081, 1205, 159, 238, |
| 146314 | | - /* 440 */ 255, 321, 461, 316, 460, 225, 790, 105, 102, 197, |
| 146315 | | - /* 450 */ 513, 314, 842, 842, 445, 109, 109, 109, 109, 108, |
| 146316 | | - /* 460 */ 108, 107, 107, 107, 106, 401, 515, 514, 515, 252, |
| 146317 | | - /* 470 */ 252, 1079, 1080, 1081, 435, 370, 1098, 933, 1460, 794, |
| 146318 | | - /* 480 */ 274, 506, 512, 105, 102, 197, 336, 63, 63, 64, |
| 146319 | | - /* 490 */ 64, 27, 790, 924, 287, 208, 1354, 923, 515, 112, |
| 146320 | | - /* 500 */ 113, 103, 1100, 1100, 953, 956, 946, 946, 110, 110, |
| 146321 | | - /* 510 */ 111, 111, 111, 111, 107, 107, 107, 106, 401, 49, |
| 146322 | | - /* 520 */ 49, 515, 28, 1079, 405, 497, 421, 297, 923, 923, |
| 146323 | | - /* 530 */ 925, 186, 468, 1079, 467, 999, 999, 442, 515, 1079, |
| 146324 | | - /* 540 */ 334, 515, 45, 45, 1083, 342, 173, 168, 109, 109, |
| 146325 | | - /* 550 */ 109, 109, 108, 108, 107, 107, 107, 106, 401, 13, |
| 146326 | | - /* 560 */ 13, 205, 13, 13, 252, 252, 1195, 1195, 370, 1079, |
| 146327 | | - /* 570 */ 1080, 1081, 787, 265, 5, 359, 494, 512, 469, 1079, |
| 146328 | | - /* 580 */ 1080, 1081, 398, 397, 1079, 1079, 1080, 1081, 3, 282, |
| 146329 | | - /* 590 */ 1079, 1083, 112, 113, 103, 1100, 1100, 953, 956, 946, |
| 146330 | | - /* 600 */ 946, 110, 110, 111, 111, 111, 111, 252, 252, 1015, |
| 146331 | | - /* 610 */ 220, 1079, 873, 458, 455, 454, 943, 943, 954, 957, |
| 146332 | | - /* 620 */ 512, 252, 252, 453, 1016, 1079, 445, 1107, 1209, 1107, |
| 146333 | | - /* 630 */ 1079, 1080, 1081, 515, 512, 426, 1079, 1080, 1081, 1017, |
| 146334 | | - /* 640 */ 512, 109, 109, 109, 109, 108, 108, 107, 107, 107, |
| 146335 | | - /* 650 */ 106, 401, 1052, 515, 50, 50, 515, 1079, 1080, 1081, |
| 146336 | | - /* 660 */ 828, 370, 1051, 379, 411, 1064, 1358, 207, 408, 773, |
| 146337 | | - /* 670 */ 829, 1079, 1080, 1081, 64, 64, 322, 64, 64, 1302, |
| 146338 | | - /* 680 */ 947, 411, 410, 1358, 1360, 112, 113, 103, 1100, 1100, |
| 146339 | | - /* 690 */ 953, 956, 946, 946, 110, 110, 111, 111, 111, 111, |
| 146340 | | - /* 700 */ 294, 482, 515, 1037, 1487, 515, 434, 1487, 354, 1120, |
| 146341 | | - /* 710 */ 483, 996, 913, 485, 466, 996, 132, 178, 33, 450, |
| 146342 | | - /* 720 */ 1203, 136, 406, 64, 64, 479, 64, 64, 419, 369, |
| 146343 | | - /* 730 */ 283, 1146, 252, 252, 109, 109, 109, 109, 108, 108, |
| 146344 | | - /* 740 */ 107, 107, 107, 106, 401, 512, 224, 440, 411, 266, |
| 146345 | | - /* 750 */ 1358, 266, 252, 252, 370, 296, 416, 284, 934, 396, |
| 146346 | | - /* 760 */ 976, 470, 400, 252, 252, 512, 9, 473, 231, 500, |
| 146347 | | - /* 770 */ 354, 1036, 1035, 1488, 355, 374, 512, 1121, 112, 113, |
| 146348 | | - /* 780 */ 103, 1100, 1100, 953, 956, 946, 946, 110, 110, 111, |
| 146349 | | - /* 790 */ 111, 111, 111, 252, 252, 1015, 515, 1347, 295, 252, |
| 146350 | | - /* 800 */ 252, 252, 252, 1098, 375, 249, 512, 445, 872, 322, |
| 146351 | | - /* 810 */ 1016, 480, 512, 195, 512, 434, 273, 15, 15, 515, |
| 146352 | | - /* 820 */ 314, 515, 95, 515, 93, 1017, 367, 109, 109, 109, |
| 146353 | | - /* 830 */ 109, 108, 108, 107, 107, 107, 106, 401, 515, 1121, |
| 146354 | | - /* 840 */ 39, 39, 51, 51, 52, 52, 503, 370, 515, 1204, |
| 146355 | | - /* 850 */ 1098, 918, 439, 341, 133, 436, 223, 222, 221, 53, |
| 146356 | | - /* 860 */ 53, 322, 1400, 761, 762, 763, 515, 370, 88, 54, |
| 146357 | | - /* 870 */ 54, 112, 113, 103, 1100, 1100, 953, 956, 946, 946, |
| 146358 | | - /* 880 */ 110, 110, 111, 111, 111, 111, 407, 55, 55, 196, |
| 146359 | | - /* 890 */ 515, 112, 113, 103, 1100, 1100, 953, 956, 946, 946, |
| 146360 | | - /* 900 */ 110, 110, 111, 111, 111, 111, 135, 264, 1149, 376, |
| 146361 | | - /* 910 */ 515, 40, 40, 515, 872, 515, 993, 515, 993, 116, |
| 147113 | + /* 240 */ 108, 107, 107, 107, 106, 405, 114, 108, 108, 107, |
| 147114 | + /* 250 */ 107, 107, 106, 405, 109, 109, 109, 109, 108, 108, |
| 147115 | + /* 260 */ 107, 107, 107, 106, 405, 152, 403, 403, 403, 109, |
| 147116 | + /* 270 */ 109, 109, 109, 108, 108, 107, 107, 107, 106, 405, |
| 147117 | + /* 280 */ 178, 497, 1416, 438, 1041, 1490, 1083, 519, 1490, 374, |
| 147118 | + /* 290 */ 425, 301, 361, 416, 74, 1083, 109, 109, 109, 109, |
| 147119 | + /* 300 */ 108, 108, 107, 107, 107, 106, 405, 1417, 37, 37, |
| 147120 | + /* 310 */ 1435, 274, 510, 112, 113, 103, 1104, 1104, 957, 960, |
| 147121 | + /* 320 */ 950, 950, 110, 110, 111, 111, 111, 111, 1440, 524, |
| 147122 | + /* 330 */ 2, 1132, 1083, 1084, 1085, 434, 275, 1083, 127, 370, |
| 147123 | + /* 340 */ 937, 1083, 1084, 1085, 220, 1209, 917, 462, 459, 458, |
| 147124 | + /* 350 */ 396, 167, 519, 1039, 152, 449, 928, 457, 152, 878, |
| 147125 | + /* 360 */ 927, 293, 109, 109, 109, 109, 108, 108, 107, 107, |
| 147126 | + /* 370 */ 107, 106, 405, 13, 13, 261, 857, 252, 252, 227, |
| 147127 | + /* 380 */ 106, 405, 374, 1083, 1084, 1085, 315, 392, 1083, 300, |
| 147128 | + /* 390 */ 516, 927, 927, 929, 231, 327, 1259, 1392, 1427, 494, |
| 147129 | + /* 400 */ 274, 510, 12, 208, 274, 510, 112, 113, 103, 1104, |
| 147130 | + /* 410 */ 1104, 957, 960, 950, 950, 110, 110, 111, 111, 111, |
| 147131 | + /* 420 */ 111, 1444, 290, 1132, 292, 1083, 1101, 247, 275, 1102, |
| 147132 | + /* 430 */ 127, 391, 409, 393, 1083, 1084, 1085, 1209, 159, 238, |
| 147133 | + /* 440 */ 255, 325, 465, 320, 464, 225, 794, 105, 102, 197, |
| 147134 | + /* 450 */ 517, 318, 846, 846, 449, 109, 109, 109, 109, 108, |
| 147135 | + /* 460 */ 108, 107, 107, 107, 106, 405, 519, 518, 519, 252, |
| 147136 | + /* 470 */ 252, 1083, 1084, 1085, 439, 374, 1102, 937, 1464, 798, |
| 147137 | + /* 480 */ 274, 510, 516, 105, 102, 197, 340, 63, 63, 64, |
| 147138 | + /* 490 */ 64, 27, 794, 928, 291, 208, 1358, 927, 519, 112, |
| 147139 | + /* 500 */ 113, 103, 1104, 1104, 957, 960, 950, 950, 110, 110, |
| 147140 | + /* 510 */ 111, 111, 111, 111, 107, 107, 107, 106, 405, 49, |
| 147141 | + /* 520 */ 49, 519, 28, 1083, 409, 501, 425, 301, 927, 927, |
| 147142 | + /* 530 */ 929, 186, 472, 1083, 471, 1003, 1003, 446, 519, 1083, |
| 147143 | + /* 540 */ 338, 519, 45, 45, 1087, 346, 173, 168, 109, 109, |
| 147144 | + /* 550 */ 109, 109, 108, 108, 107, 107, 107, 106, 405, 13, |
| 147145 | + /* 560 */ 13, 205, 13, 13, 252, 252, 1199, 1199, 374, 1083, |
| 147146 | + /* 570 */ 1084, 1085, 791, 265, 5, 363, 498, 516, 473, 1083, |
| 147147 | + /* 580 */ 1084, 1085, 402, 401, 1083, 1083, 1084, 1085, 3, 282, |
| 147148 | + /* 590 */ 1083, 1087, 112, 113, 103, 1104, 1104, 957, 960, 950, |
| 147149 | + /* 600 */ 950, 110, 110, 111, 111, 111, 111, 252, 252, 1019, |
| 147150 | + /* 610 */ 220, 1083, 877, 462, 459, 458, 947, 947, 958, 961, |
| 147151 | + /* 620 */ 516, 252, 252, 457, 1020, 1083, 449, 1111, 1213, 1111, |
| 147152 | + /* 630 */ 1083, 1084, 1085, 519, 516, 430, 1083, 1084, 1085, 1021, |
| 147153 | + /* 640 */ 516, 109, 109, 109, 109, 108, 108, 107, 107, 107, |
| 147154 | + /* 650 */ 106, 405, 1056, 519, 50, 50, 519, 1083, 1084, 1085, |
| 147155 | + /* 660 */ 832, 374, 1055, 383, 415, 1068, 1362, 207, 412, 777, |
| 147156 | + /* 670 */ 833, 1083, 1084, 1085, 64, 64, 326, 64, 64, 1306, |
| 147157 | + /* 680 */ 951, 415, 414, 1362, 1364, 112, 113, 103, 1104, 1104, |
| 147158 | + /* 690 */ 957, 960, 950, 950, 110, 110, 111, 111, 111, 111, |
| 147159 | + /* 700 */ 298, 486, 519, 1041, 1491, 519, 438, 1491, 358, 1124, |
| 147160 | + /* 710 */ 487, 1000, 917, 489, 470, 1000, 132, 178, 33, 454, |
| 147161 | + /* 720 */ 1207, 136, 410, 64, 64, 483, 64, 64, 423, 373, |
| 147162 | + /* 730 */ 283, 1150, 252, 252, 109, 109, 109, 109, 108, 108, |
| 147163 | + /* 740 */ 107, 107, 107, 106, 405, 516, 224, 444, 415, 266, |
| 147164 | + /* 750 */ 1362, 266, 252, 252, 374, 300, 420, 286, 938, 400, |
| 147165 | + /* 760 */ 980, 474, 404, 252, 252, 516, 9, 477, 231, 504, |
| 147166 | + /* 770 */ 358, 1040, 1039, 1492, 359, 378, 516, 1125, 112, 113, |
| 147167 | + /* 780 */ 103, 1104, 1104, 957, 960, 950, 950, 110, 110, 111, |
| 147168 | + /* 790 */ 111, 111, 111, 252, 252, 1019, 519, 1351, 299, 252, |
| 147169 | + /* 800 */ 252, 252, 252, 1102, 379, 249, 516, 449, 876, 326, |
| 147170 | + /* 810 */ 1020, 484, 516, 195, 516, 438, 273, 15, 15, 519, |
| 147171 | + /* 820 */ 318, 519, 95, 519, 93, 1021, 371, 109, 109, 109, |
| 147172 | + /* 830 */ 109, 108, 108, 107, 107, 107, 106, 405, 519, 1125, |
| 147173 | + /* 840 */ 39, 39, 51, 51, 52, 52, 507, 374, 519, 1208, |
| 147174 | + /* 850 */ 1102, 922, 443, 345, 133, 440, 223, 222, 221, 53, |
| 147175 | + /* 860 */ 53, 326, 1404, 765, 766, 767, 519, 374, 88, 54, |
| 147176 | + /* 870 */ 54, 112, 113, 103, 1104, 1104, 957, 960, 950, 950, |
| 147177 | + /* 880 */ 110, 110, 111, 111, 111, 111, 411, 55, 55, 196, |
| 147178 | + /* 890 */ 519, 112, 113, 103, 1104, 1104, 957, 960, 950, 950, |
| 147179 | + /* 900 */ 110, 110, 111, 111, 111, 111, 135, 264, 1153, 380, |
| 147180 | + /* 910 */ 519, 40, 40, 519, 876, 519, 997, 519, 997, 116, |
| 146362 | 147181 | /* 920 */ 109, 109, 109, 109, 108, 108, 107, 107, 107, 106, |
| 146363 | | - /* 930 */ 401, 41, 41, 515, 43, 43, 44, 44, 56, 56, |
| 147182 | + /* 930 */ 405, 41, 41, 519, 43, 43, 44, 44, 56, 56, |
| 146364 | 147183 | /* 940 */ 109, 109, 109, 109, 108, 108, 107, 107, 107, 106, |
| 146365 | | - /* 950 */ 401, 515, 379, 515, 57, 57, 515, 799, 515, 379, |
| 146366 | | - /* 960 */ 515, 445, 200, 515, 323, 515, 1397, 515, 1459, 515, |
| 146367 | | - /* 970 */ 1287, 817, 58, 58, 14, 14, 515, 59, 59, 118, |
| 146368 | | - /* 980 */ 118, 60, 60, 515, 46, 46, 61, 61, 62, 62, |
| 146369 | | - /* 990 */ 47, 47, 515, 190, 189, 91, 515, 140, 140, 515, |
| 146370 | | - /* 1000 */ 394, 515, 277, 1200, 141, 141, 515, 1115, 515, 992, |
| 146371 | | - /* 1010 */ 515, 992, 515, 69, 69, 370, 278, 48, 48, 259, |
| 147184 | + /* 950 */ 405, 519, 383, 519, 57, 57, 519, 803, 519, 383, |
| 147185 | + /* 960 */ 519, 449, 200, 519, 327, 519, 1401, 519, 1463, 519, |
| 147186 | + /* 970 */ 1291, 821, 58, 58, 14, 14, 519, 59, 59, 118, |
| 147187 | + /* 980 */ 118, 60, 60, 519, 46, 46, 61, 61, 62, 62, |
| 147188 | + /* 990 */ 47, 47, 519, 190, 189, 91, 519, 140, 140, 519, |
| 147189 | + /* 1000 */ 398, 519, 277, 1204, 141, 141, 519, 1119, 519, 996, |
| 147190 | + /* 1010 */ 519, 996, 519, 69, 69, 374, 278, 48, 48, 259, |
| 146372 | 147191 | /* 1020 */ 65, 65, 119, 119, 246, 246, 260, 66, 66, 120, |
| 146373 | | - /* 1030 */ 120, 121, 121, 117, 117, 370, 515, 512, 383, 112, |
| 146374 | | - /* 1040 */ 113, 103, 1100, 1100, 953, 956, 946, 946, 110, 110, |
| 146375 | | - /* 1050 */ 111, 111, 111, 111, 515, 872, 515, 139, 139, 112, |
| 146376 | | - /* 1060 */ 113, 103, 1100, 1100, 953, 956, 946, 946, 110, 110, |
| 146377 | | - /* 1070 */ 111, 111, 111, 111, 1287, 138, 138, 125, 125, 515, |
| 146378 | | - /* 1080 */ 12, 515, 281, 1287, 515, 445, 131, 1287, 109, 109, |
| 146379 | | - /* 1090 */ 109, 109, 108, 108, 107, 107, 107, 106, 401, 515, |
| 146380 | | - /* 1100 */ 124, 124, 122, 122, 515, 123, 123, 515, 109, 109, |
| 146381 | | - /* 1110 */ 109, 109, 108, 108, 107, 107, 107, 106, 401, 515, |
| 146382 | | - /* 1120 */ 68, 68, 463, 783, 515, 70, 70, 302, 67, 67, |
| 146383 | | - /* 1130 */ 1032, 253, 253, 356, 1287, 191, 196, 1433, 465, 1301, |
| 146384 | | - /* 1140 */ 38, 38, 384, 94, 512, 42, 42, 177, 848, 274, |
| 146385 | | - /* 1150 */ 506, 385, 420, 847, 1356, 441, 508, 376, 377, 153, |
| 146386 | | - /* 1160 */ 423, 872, 432, 370, 224, 251, 194, 887, 182, 293, |
| 146387 | | - /* 1170 */ 783, 848, 88, 254, 466, 888, 847, 915, 807, 806, |
| 146388 | | - /* 1180 */ 230, 1241, 910, 370, 17, 413, 797, 112, 113, 103, |
| 146389 | | - /* 1190 */ 1100, 1100, 953, 956, 946, 946, 110, 110, 111, 111, |
| 146390 | | - /* 1200 */ 111, 111, 395, 814, 815, 1175, 983, 112, 101, 103, |
| 146391 | | - /* 1210 */ 1100, 1100, 953, 956, 946, 946, 110, 110, 111, 111, |
| 146392 | | - /* 1220 */ 111, 111, 375, 422, 427, 429, 298, 230, 230, 88, |
| 146393 | | - /* 1230 */ 1240, 451, 312, 797, 226, 88, 109, 109, 109, 109, |
| 146394 | | - /* 1240 */ 108, 108, 107, 107, 107, 106, 401, 86, 433, 979, |
| 146395 | | - /* 1250 */ 927, 881, 226, 983, 230, 415, 109, 109, 109, 109, |
| 146396 | | - /* 1260 */ 108, 108, 107, 107, 107, 106, 401, 320, 845, 781, |
| 146397 | | - /* 1270 */ 846, 100, 130, 100, 1403, 290, 370, 319, 1377, 1376, |
| 146398 | | - /* 1280 */ 437, 1449, 299, 1237, 303, 306, 308, 310, 1188, 1174, |
| 146399 | | - /* 1290 */ 1173, 1172, 315, 324, 325, 1228, 370, 927, 1249, 271, |
| 146400 | | - /* 1300 */ 1286, 113, 103, 1100, 1100, 953, 956, 946, 946, 110, |
| 146401 | | - /* 1310 */ 110, 111, 111, 111, 111, 1224, 1235, 502, 501, 1292, |
| 146402 | | - /* 1320 */ 1221, 1155, 103, 1100, 1100, 953, 956, 946, 946, 110, |
| 146403 | | - /* 1330 */ 110, 111, 111, 111, 111, 1148, 1137, 1136, 1138, 1443, |
| 146404 | | - /* 1340 */ 446, 244, 184, 98, 507, 188, 4, 353, 327, 109, |
| 146405 | | - /* 1350 */ 109, 109, 109, 108, 108, 107, 107, 107, 106, 401, |
| 146406 | | - /* 1360 */ 510, 329, 331, 199, 414, 456, 292, 285, 318, 109, |
| 146407 | | - /* 1370 */ 109, 109, 109, 108, 108, 107, 107, 107, 106, 401, |
| 146408 | | - /* 1380 */ 11, 1271, 1279, 402, 361, 192, 1171, 1351, 431, 505, |
| 146409 | | - /* 1390 */ 346, 1350, 333, 98, 507, 504, 4, 187, 1446, 1115, |
| 146410 | | - /* 1400 */ 233, 1396, 155, 1394, 1112, 152, 72, 75, 378, 425, |
| 146411 | | - /* 1410 */ 510, 165, 149, 157, 933, 1276, 86, 30, 1268, 417, |
| 146412 | | - /* 1420 */ 96, 96, 8, 160, 161, 162, 163, 97, 418, 402, |
| 146413 | | - /* 1430 */ 517, 516, 449, 402, 923, 210, 358, 424, 1282, 438, |
| 146414 | | - /* 1440 */ 169, 214, 360, 1345, 80, 504, 31, 444, 1365, 301, |
| 146415 | | - /* 1450 */ 245, 274, 506, 216, 174, 305, 488, 447, 217, 462, |
| 146416 | | - /* 1460 */ 1139, 487, 218, 363, 933, 923, 923, 925, 926, 24, |
| 146417 | | - /* 1470 */ 96, 96, 1191, 1190, 1189, 391, 1182, 97, 1163, 402, |
| 146418 | | - /* 1480 */ 517, 516, 799, 364, 923, 1162, 317, 1161, 98, 507, |
| 146419 | | - /* 1490 */ 1181, 4, 1458, 472, 393, 269, 270, 475, 481, 1232, |
| 146420 | | - /* 1500 */ 85, 1233, 326, 328, 232, 510, 495, 1231, 330, 98, |
| 146421 | | - /* 1510 */ 507, 1230, 4, 486, 335, 923, 923, 925, 926, 24, |
| 146422 | | - /* 1520 */ 1435, 1068, 404, 181, 336, 256, 510, 115, 402, 332, |
| 146423 | | - /* 1530 */ 352, 352, 351, 241, 349, 1214, 1414, 770, 338, 10, |
| 146424 | | - /* 1540 */ 504, 340, 272, 92, 1331, 1213, 87, 183, 484, 402, |
| 146425 | | - /* 1550 */ 201, 488, 280, 239, 344, 345, 489, 1145, 29, 933, |
| 146426 | | - /* 1560 */ 279, 504, 1074, 518, 240, 96, 96, 242, 243, 519, |
| 146427 | | - /* 1570 */ 1134, 1129, 97, 154, 402, 517, 516, 372, 373, 923, |
| 146428 | | - /* 1580 */ 933, 142, 143, 128, 1381, 267, 96, 96, 852, 757, |
| 146429 | | - /* 1590 */ 203, 144, 403, 97, 1382, 402, 517, 516, 204, 1380, |
| 146430 | | - /* 1600 */ 923, 146, 1379, 1159, 1158, 71, 1156, 276, 202, 185, |
| 146431 | | - /* 1610 */ 923, 923, 925, 926, 24, 198, 257, 126, 991, 989, |
| 146432 | | - /* 1620 */ 907, 98, 507, 156, 4, 145, 158, 206, 831, 209, |
| 146433 | | - /* 1630 */ 291, 923, 923, 925, 926, 24, 1005, 911, 510, 164, |
| 146434 | | - /* 1640 */ 147, 380, 371, 382, 166, 76, 77, 274, 506, 148, |
| 146435 | | - /* 1650 */ 78, 79, 1008, 211, 212, 1004, 137, 213, 18, 300, |
| 146436 | | - /* 1660 */ 230, 402, 997, 1109, 443, 215, 32, 170, 171, 772, |
| 146437 | | - /* 1670 */ 409, 448, 319, 504, 219, 172, 452, 81, 19, 457, |
| 146438 | | - /* 1680 */ 313, 20, 82, 268, 488, 150, 810, 179, 83, 487, |
| 146439 | | - /* 1690 */ 464, 151, 933, 180, 959, 84, 1040, 34, 96, 96, |
| 146440 | | - /* 1700 */ 471, 1041, 35, 474, 193, 97, 248, 402, 517, 516, |
| 146441 | | - /* 1710 */ 1068, 404, 923, 250, 256, 880, 229, 175, 875, 352, |
| 146442 | | - /* 1720 */ 352, 351, 241, 349, 100, 21, 770, 22, 1054, 1056, |
| 146443 | | - /* 1730 */ 7, 98, 507, 1045, 4, 337, 1058, 23, 974, 201, |
| 146444 | | - /* 1740 */ 176, 280, 88, 923, 923, 925, 926, 24, 510, 279, |
| 146445 | | - /* 1750 */ 960, 958, 962, 1014, 963, 1013, 235, 234, 25, 36, |
| 146446 | | - /* 1760 */ 99, 90, 507, 928, 4, 511, 350, 782, 26, 841, |
| 146447 | | - /* 1770 */ 236, 402, 347, 1069, 237, 1125, 1125, 1451, 510, 203, |
| 146448 | | - /* 1780 */ 1450, 1125, 1125, 504, 1125, 1125, 1125, 204, 1125, 1125, |
| 146449 | | - /* 1790 */ 146, 1125, 1125, 1125, 1125, 1125, 1125, 202, 1125, 1125, |
| 146450 | | - /* 1800 */ 1125, 402, 933, 1125, 1125, 1125, 1125, 1125, 96, 96, |
| 146451 | | - /* 1810 */ 1125, 1125, 1125, 504, 1125, 97, 1125, 402, 517, 516, |
| 146452 | | - /* 1820 */ 1125, 1125, 923, 1125, 1125, 1125, 1125, 1125, 1125, 1125, |
| 146453 | | - /* 1830 */ 1125, 371, 933, 1125, 1125, 1125, 274, 506, 96, 96, |
| 146454 | | - /* 1840 */ 1125, 1125, 1125, 1125, 1125, 97, 1125, 402, 517, 516, |
| 146455 | | - /* 1850 */ 1125, 1125, 923, 923, 923, 925, 926, 24, 1125, 409, |
| 146456 | | - /* 1860 */ 1125, 1125, 1125, 256, 1125, 1125, 1125, 1125, 352, 352, |
| 146457 | | - /* 1870 */ 351, 241, 349, 1125, 1125, 770, 1125, 1125, 1125, 1125, |
| 146458 | | - /* 1880 */ 1125, 1125, 1125, 923, 923, 925, 926, 24, 201, 1125, |
| 146459 | | - /* 1890 */ 280, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 279, 1125, |
| 146460 | | - /* 1900 */ 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, |
| 146461 | | - /* 1910 */ 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, |
| 146462 | | - /* 1920 */ 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 203, 1125, |
| 146463 | | - /* 1930 */ 1125, 1125, 1125, 1125, 1125, 1125, 204, 1125, 1125, 146, |
| 146464 | | - /* 1940 */ 1125, 1125, 1125, 1125, 1125, 1125, 202, 1125, 1125, 1125, |
| 146465 | | - /* 1950 */ 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, |
| 146466 | | - /* 1960 */ 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, |
| 146467 | | - /* 1970 */ 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, |
| 146468 | | - /* 1980 */ 371, 1125, 1125, 1125, 1125, 274, 506, 1125, 1125, 1125, |
| 146469 | | - /* 1990 */ 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, |
| 146470 | | - /* 2000 */ 1125, 1125, 1125, 1125, 1125, 1125, 1125, 1125, 409, |
| 147192 | + /* 1030 */ 120, 121, 121, 117, 117, 374, 519, 516, 387, 112, |
| 147193 | + /* 1040 */ 113, 103, 1104, 1104, 957, 960, 950, 950, 110, 110, |
| 147194 | + /* 1050 */ 111, 111, 111, 111, 519, 876, 519, 139, 139, 112, |
| 147195 | + /* 1060 */ 113, 103, 1104, 1104, 957, 960, 950, 950, 110, 110, |
| 147196 | + /* 1070 */ 111, 111, 111, 111, 1291, 138, 138, 125, 125, 519, |
| 147197 | + /* 1080 */ 12, 519, 281, 1291, 519, 449, 131, 1291, 109, 109, |
| 147198 | + /* 1090 */ 109, 109, 108, 108, 107, 107, 107, 106, 405, 519, |
| 147199 | + /* 1100 */ 124, 124, 122, 122, 519, 123, 123, 519, 109, 109, |
| 147200 | + /* 1110 */ 109, 109, 108, 108, 107, 107, 107, 106, 405, 519, |
| 147201 | + /* 1120 */ 68, 68, 467, 787, 519, 70, 70, 306, 67, 67, |
| 147202 | + /* 1130 */ 1036, 253, 253, 360, 1291, 191, 196, 1437, 469, 1305, |
| 147203 | + /* 1140 */ 38, 38, 388, 94, 516, 42, 42, 177, 852, 274, |
| 147204 | + /* 1150 */ 510, 389, 424, 851, 1360, 445, 512, 380, 381, 153, |
| 147205 | + /* 1160 */ 427, 876, 436, 374, 224, 251, 194, 891, 182, 297, |
| 147206 | + /* 1170 */ 787, 852, 88, 254, 470, 892, 851, 919, 811, 810, |
| 147207 | + /* 1180 */ 230, 1245, 914, 374, 17, 417, 801, 112, 113, 103, |
| 147208 | + /* 1190 */ 1104, 1104, 957, 960, 950, 950, 110, 110, 111, 111, |
| 147209 | + /* 1200 */ 111, 111, 399, 818, 819, 1179, 987, 112, 101, 103, |
| 147210 | + /* 1210 */ 1104, 1104, 957, 960, 950, 950, 110, 110, 111, 111, |
| 147211 | + /* 1220 */ 111, 111, 379, 426, 431, 433, 302, 230, 230, 88, |
| 147212 | + /* 1230 */ 1244, 455, 316, 801, 226, 88, 109, 109, 109, 109, |
| 147213 | + /* 1240 */ 108, 108, 107, 107, 107, 106, 405, 86, 437, 983, |
| 147214 | + /* 1250 */ 931, 885, 226, 987, 230, 419, 109, 109, 109, 109, |
| 147215 | + /* 1260 */ 108, 108, 107, 107, 107, 106, 405, 324, 849, 785, |
| 147216 | + /* 1270 */ 850, 100, 130, 100, 1407, 294, 374, 323, 1381, 1380, |
| 147217 | + /* 1280 */ 441, 1453, 303, 1241, 307, 310, 312, 314, 1192, 1178, |
| 147218 | + /* 1290 */ 1177, 1176, 319, 328, 329, 1232, 374, 931, 1253, 271, |
| 147219 | + /* 1300 */ 1290, 113, 103, 1104, 1104, 957, 960, 950, 950, 110, |
| 147220 | + /* 1310 */ 110, 111, 111, 111, 111, 1228, 1239, 506, 505, 1296, |
| 147221 | + /* 1320 */ 1225, 1159, 103, 1104, 1104, 957, 960, 950, 950, 110, |
| 147222 | + /* 1330 */ 110, 111, 111, 111, 111, 1152, 1141, 1140, 1142, 1447, |
| 147223 | + /* 1340 */ 450, 244, 184, 98, 511, 188, 4, 357, 331, 109, |
| 147224 | + /* 1350 */ 109, 109, 109, 108, 108, 107, 107, 107, 106, 405, |
| 147225 | + /* 1360 */ 514, 333, 335, 199, 418, 460, 296, 289, 322, 109, |
| 147226 | + /* 1370 */ 109, 109, 109, 108, 108, 107, 107, 107, 106, 405, |
| 147227 | + /* 1380 */ 11, 285, 1283, 406, 365, 192, 1175, 1355, 435, 509, |
| 147228 | + /* 1390 */ 350, 1354, 337, 98, 511, 508, 4, 187, 1450, 1119, |
| 147229 | + /* 1400 */ 233, 1400, 155, 1398, 1116, 152, 72, 75, 382, 429, |
| 147230 | + /* 1410 */ 514, 165, 115, 499, 937, 1280, 1275, 30, 149, 157, |
| 147231 | + /* 1420 */ 96, 96, 8, 284, 86, 288, 287, 97, 1272, 406, |
| 147232 | + /* 1430 */ 521, 520, 421, 406, 927, 422, 453, 210, 160, 161, |
| 147233 | + /* 1440 */ 162, 163, 362, 428, 1286, 508, 442, 214, 80, 364, |
| 147234 | + /* 1450 */ 31, 274, 510, 169, 1349, 448, 492, 245, 1369, 216, |
| 147235 | + /* 1460 */ 174, 491, 451, 309, 937, 927, 927, 929, 930, 24, |
| 147236 | + /* 1470 */ 96, 96, 305, 217, 367, 466, 1143, 97, 218, 406, |
| 147237 | + /* 1480 */ 521, 520, 1195, 1194, 927, 1193, 395, 803, 98, 511, |
| 147238 | + /* 1490 */ 368, 4, 1186, 1167, 1185, 269, 1166, 321, 1165, 1462, |
| 147239 | + /* 1500 */ 397, 270, 485, 476, 479, 514, 85, 232, 1236, 98, |
| 147240 | + /* 1510 */ 511, 330, 4, 490, 340, 927, 927, 929, 930, 24, |
| 147241 | + /* 1520 */ 1439, 1072, 408, 1237, 339, 256, 514, 1418, 406, 10, |
| 147242 | + /* 1530 */ 356, 356, 355, 241, 353, 181, 92, 774, 1235, 1218, |
| 147243 | + /* 1540 */ 508, 342, 87, 332, 334, 1217, 1234, 336, 344, 406, |
| 147244 | + /* 1550 */ 201, 492, 280, 183, 488, 348, 493, 349, 239, 937, |
| 147245 | + /* 1560 */ 279, 508, 1335, 29, 1149, 96, 96, 522, 1078, 272, |
| 147246 | + /* 1570 */ 243, 240, 97, 242, 406, 521, 520, 523, 1138, 927, |
| 147247 | + /* 1580 */ 937, 142, 1133, 1385, 143, 1386, 96, 96, 856, 376, |
| 147248 | + /* 1590 */ 203, 761, 154, 97, 1384, 406, 521, 520, 204, 377, |
| 147249 | + /* 1600 */ 927, 146, 144, 1383, 407, 1163, 1162, 128, 202, 71, |
| 147250 | + /* 1610 */ 927, 927, 929, 930, 24, 267, 1160, 185, 276, 198, |
| 147251 | + /* 1620 */ 257, 98, 511, 126, 4, 911, 995, 156, 993, 145, |
| 147252 | + /* 1630 */ 206, 927, 927, 929, 930, 24, 158, 835, 514, 209, |
| 147253 | + /* 1640 */ 295, 1009, 375, 164, 915, 147, 384, 274, 510, 386, |
| 147254 | + /* 1650 */ 166, 76, 77, 78, 148, 1012, 211, 212, 1008, 137, |
| 147255 | + /* 1660 */ 18, 406, 79, 213, 304, 1001, 1113, 230, 447, 215, |
| 147256 | + /* 1670 */ 413, 171, 32, 508, 323, 776, 170, 452, 172, 219, |
| 147257 | + /* 1680 */ 456, 81, 19, 20, 492, 317, 461, 82, 268, 491, |
| 147258 | + /* 1690 */ 150, 814, 937, 179, 83, 468, 151, 180, 96, 96, |
| 147259 | + /* 1700 */ 963, 84, 1044, 34, 475, 97, 1045, 406, 521, 520, |
| 147260 | + /* 1710 */ 1072, 408, 927, 35, 256, 884, 478, 248, 193, 356, |
| 147261 | + /* 1720 */ 356, 355, 241, 353, 250, 175, 774, 229, 879, 21, |
| 147262 | + /* 1730 */ 100, 98, 511, 22, 4, 1058, 1049, 176, 341, 201, |
| 147263 | + /* 1740 */ 7, 280, 1062, 927, 927, 929, 930, 24, 514, 279, |
| 147264 | + /* 1750 */ 88, 1060, 23, 978, 964, 962, 966, 1018, 1017, 967, |
| 147265 | + /* 1760 */ 235, 90, 511, 234, 4, 25, 36, 515, 932, 786, |
| 147266 | + /* 1770 */ 845, 406, 99, 26, 236, 237, 351, 1455, 514, 203, |
| 147267 | + /* 1780 */ 354, 1454, 1073, 508, 1129, 1129, 1129, 204, 1129, 1129, |
| 147268 | + /* 1790 */ 146, 1129, 1129, 1129, 1129, 1129, 1129, 202, 1129, 1129, |
| 147269 | + /* 1800 */ 1129, 406, 937, 1129, 1129, 1129, 1129, 1129, 96, 96, |
| 147270 | + /* 1810 */ 1129, 1129, 1129, 508, 1129, 97, 1129, 406, 521, 520, |
| 147271 | + /* 1820 */ 1129, 1129, 927, 1129, 1129, 1129, 1129, 1129, 1129, 1129, |
| 147272 | + /* 1830 */ 1129, 375, 937, 1129, 1129, 1129, 274, 510, 96, 96, |
| 147273 | + /* 1840 */ 1129, 1129, 1129, 1129, 1129, 97, 1129, 406, 521, 520, |
| 147274 | + /* 1850 */ 1129, 1129, 927, 927, 927, 929, 930, 24, 1129, 413, |
| 147275 | + /* 1860 */ 1129, 1129, 1129, 256, 1129, 1129, 1129, 1129, 356, 356, |
| 147276 | + /* 1870 */ 355, 241, 353, 1129, 1129, 774, 1129, 1129, 1129, 1129, |
| 147277 | + /* 1880 */ 1129, 1129, 1129, 927, 927, 929, 930, 24, 201, 1129, |
| 147278 | + /* 1890 */ 280, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 279, 1129, |
| 147279 | + /* 1900 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, |
| 147280 | + /* 1910 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, |
| 147281 | + /* 1920 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 203, 1129, |
| 147282 | + /* 1930 */ 1129, 1129, 1129, 1129, 1129, 1129, 204, 1129, 1129, 146, |
| 147283 | + /* 1940 */ 1129, 1129, 1129, 1129, 1129, 1129, 202, 1129, 1129, 1129, |
| 147284 | + /* 1950 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, |
| 147285 | + /* 1960 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, |
| 147286 | + /* 1970 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, |
| 147287 | + /* 1980 */ 375, 1129, 1129, 1129, 1129, 274, 510, 1129, 1129, 1129, |
| 147288 | + /* 1990 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, |
| 147289 | + /* 2000 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 413, |
| 146471 | 147290 | }; |
| 146472 | 147291 | static const YYCODETYPE yy_lookahead[] = { |
| 146473 | 147292 | /* 0 */ 184, 238, 239, 240, 238, 239, 240, 163, 155, 156, |
| 146474 | 147293 | /* 10 */ 157, 158, 159, 160, 163, 191, 192, 183, 165, 19, |
| 146475 | 147294 | /* 20 */ 167, 258, 202, 203, 200, 191, 163, 174, 184, 185, |
| | @@ -146609,48 +147428,48 @@ |
| 146609 | 147428 | /* 1360 */ 36, 222, 222, 260, 226, 188, 256, 226, 187, 92, |
| 146610 | 147429 | /* 1370 */ 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, |
| 146611 | 147430 | /* 1380 */ 210, 213, 213, 59, 213, 196, 192, 187, 256, 244, |
| 146612 | 147431 | /* 1390 */ 212, 187, 226, 19, 20, 71, 22, 210, 166, 60, |
| 146613 | 147432 | /* 1400 */ 130, 170, 260, 170, 38, 81, 257, 257, 170, 104, |
| 146614 | | - /* 1410 */ 36, 22, 43, 201, 90, 236, 138, 235, 213, 18, |
| 146615 | | - /* 1420 */ 96, 97, 48, 204, 204, 204, 204, 103, 170, 105, |
| 146616 | | - /* 1430 */ 106, 107, 18, 59, 110, 169, 213, 213, 201, 170, |
| 146617 | | - /* 1440 */ 201, 169, 236, 213, 146, 71, 235, 62, 253, 252, |
| 146618 | | - /* 1450 */ 170, 127, 128, 169, 22, 170, 82, 189, 169, 104, |
| 146619 | | - /* 1460 */ 170, 87, 169, 189, 90, 141, 142, 143, 144, 145, |
| 146620 | | - /* 1470 */ 96, 97, 186, 186, 186, 64, 194, 103, 186, 105, |
| 146621 | | - /* 1480 */ 106, 107, 115, 189, 110, 188, 186, 186, 19, 20, |
| 146622 | | - /* 1490 */ 194, 22, 186, 189, 102, 246, 246, 189, 133, 228, |
| 146623 | | - /* 1500 */ 104, 228, 227, 227, 170, 36, 134, 228, 227, 19, |
| 146624 | | - /* 1510 */ 20, 228, 22, 84, 271, 141, 142, 143, 144, 145, |
| 146625 | | - /* 1520 */ 0, 1, 2, 216, 22, 5, 36, 137, 59, 227, |
| 146626 | | - /* 1530 */ 10, 11, 12, 13, 14, 217, 269, 17, 216, 22, |
| 146627 | | - /* 1540 */ 71, 170, 243, 146, 241, 217, 136, 215, 135, 59, |
| 146628 | | - /* 1550 */ 30, 82, 32, 25, 214, 213, 87, 173, 26, 90, |
| 146629 | | - /* 1560 */ 40, 71, 13, 172, 164, 96, 97, 164, 6, 162, |
| 146630 | | - /* 1570 */ 162, 162, 103, 263, 105, 106, 107, 266, 266, 110, |
| 146631 | | - /* 1580 */ 90, 176, 176, 190, 182, 190, 96, 97, 98, 4, |
| 146632 | | - /* 1590 */ 70, 176, 3, 103, 182, 105, 106, 107, 78, 182, |
| 146633 | | - /* 1600 */ 110, 81, 182, 182, 182, 182, 182, 151, 88, 22, |
| 146634 | | - /* 1610 */ 141, 142, 143, 144, 145, 15, 89, 16, 23, 23, |
| 146635 | | - /* 1620 */ 128, 19, 20, 139, 22, 119, 131, 24, 20, 133, |
| 146636 | | - /* 1630 */ 16, 141, 142, 143, 144, 145, 1, 140, 36, 131, |
| 146637 | | - /* 1640 */ 119, 61, 122, 37, 139, 53, 53, 127, 128, 119, |
| 146638 | | - /* 1650 */ 53, 53, 105, 34, 130, 1, 5, 104, 22, 149, |
| 146639 | | - /* 1660 */ 26, 59, 68, 75, 41, 130, 24, 68, 104, 20, |
| 146640 | | - /* 1670 */ 150, 19, 120, 71, 114, 22, 67, 22, 22, 67, |
| 146641 | | - /* 1680 */ 23, 22, 22, 67, 82, 37, 28, 23, 138, 87, |
| 146642 | | - /* 1690 */ 22, 153, 90, 23, 23, 26, 23, 22, 96, 97, |
| 146643 | | - /* 1700 */ 24, 23, 22, 24, 130, 103, 23, 105, 106, 107, |
| 146644 | | - /* 1710 */ 1, 2, 110, 23, 5, 105, 34, 22, 132, 10, |
| 146645 | | - /* 1720 */ 11, 12, 13, 14, 26, 34, 17, 34, 85, 83, |
| 146646 | | - /* 1730 */ 44, 19, 20, 23, 22, 24, 75, 34, 23, 30, |
| 146647 | | - /* 1740 */ 26, 32, 26, 141, 142, 143, 144, 145, 36, 40, |
| 146648 | | - /* 1750 */ 23, 23, 23, 23, 11, 23, 22, 26, 22, 22, |
| 146649 | | - /* 1760 */ 22, 19, 20, 23, 22, 26, 15, 23, 22, 124, |
| 146650 | | - /* 1770 */ 130, 59, 23, 1, 130, 277, 277, 130, 36, 70, |
| 146651 | | - /* 1780 */ 130, 277, 277, 71, 277, 277, 277, 78, 277, 277, |
| 147433 | + /* 1410 */ 36, 22, 137, 134, 90, 236, 217, 235, 43, 201, |
| 147434 | + /* 1420 */ 96, 97, 48, 216, 138, 213, 216, 103, 217, 105, |
| 147435 | + /* 1430 */ 106, 107, 18, 59, 110, 170, 18, 169, 204, 204, |
| 147436 | + /* 1440 */ 204, 204, 213, 213, 201, 71, 170, 169, 146, 236, |
| 147437 | + /* 1450 */ 235, 127, 128, 201, 213, 62, 82, 170, 253, 169, |
| 147438 | + /* 1460 */ 22, 87, 189, 170, 90, 141, 142, 143, 144, 145, |
| 147439 | + /* 1470 */ 96, 97, 252, 169, 189, 104, 170, 103, 169, 105, |
| 147440 | + /* 1480 */ 106, 107, 186, 186, 110, 186, 64, 115, 19, 20, |
| 147441 | + /* 1490 */ 189, 22, 194, 186, 194, 246, 188, 186, 186, 186, |
| 147442 | + /* 1500 */ 102, 246, 133, 189, 189, 36, 104, 170, 228, 19, |
| 147443 | + /* 1510 */ 20, 227, 22, 84, 22, 141, 142, 143, 144, 145, |
| 147444 | + /* 1520 */ 0, 1, 2, 228, 271, 5, 36, 269, 59, 22, |
| 147445 | + /* 1530 */ 10, 11, 12, 13, 14, 216, 146, 17, 228, 217, |
| 147446 | + /* 1540 */ 71, 216, 136, 227, 227, 217, 228, 227, 170, 59, |
| 147447 | + /* 1550 */ 30, 82, 32, 215, 135, 214, 87, 213, 25, 90, |
| 147448 | + /* 1560 */ 40, 71, 241, 26, 173, 96, 97, 172, 13, 243, |
| 147449 | + /* 1570 */ 6, 164, 103, 164, 105, 106, 107, 162, 162, 110, |
| 147450 | + /* 1580 */ 90, 176, 162, 182, 176, 182, 96, 97, 98, 266, |
| 147451 | + /* 1590 */ 70, 4, 263, 103, 182, 105, 106, 107, 78, 266, |
| 147452 | + /* 1600 */ 110, 81, 176, 182, 3, 182, 182, 190, 88, 182, |
| 147453 | + /* 1610 */ 141, 142, 143, 144, 145, 190, 182, 22, 151, 15, |
| 147454 | + /* 1620 */ 89, 19, 20, 16, 22, 128, 23, 139, 23, 119, |
| 147455 | + /* 1630 */ 24, 141, 142, 143, 144, 145, 131, 20, 36, 133, |
| 147456 | + /* 1640 */ 16, 1, 122, 131, 140, 119, 61, 127, 128, 37, |
| 147457 | + /* 1650 */ 139, 53, 53, 53, 119, 105, 34, 130, 1, 5, |
| 147458 | + /* 1660 */ 22, 59, 53, 104, 149, 68, 75, 26, 41, 130, |
| 147459 | + /* 1670 */ 150, 104, 24, 71, 120, 20, 68, 19, 22, 114, |
| 147460 | + /* 1680 */ 67, 22, 22, 22, 82, 23, 67, 22, 67, 87, |
| 147461 | + /* 1690 */ 37, 28, 90, 23, 138, 22, 153, 23, 96, 97, |
| 147462 | + /* 1700 */ 23, 26, 23, 22, 24, 103, 23, 105, 106, 107, |
| 147463 | + /* 1710 */ 1, 2, 110, 22, 5, 105, 24, 23, 130, 10, |
| 147464 | + /* 1720 */ 11, 12, 13, 14, 23, 22, 17, 34, 132, 34, |
| 147465 | + /* 1730 */ 26, 19, 20, 34, 22, 85, 23, 26, 24, 30, |
| 147466 | + /* 1740 */ 44, 32, 75, 141, 142, 143, 144, 145, 36, 40, |
| 147467 | + /* 1750 */ 26, 83, 34, 23, 23, 23, 23, 23, 23, 11, |
| 147468 | + /* 1760 */ 22, 19, 20, 26, 22, 22, 22, 26, 23, 23, |
| 147469 | + /* 1770 */ 124, 59, 22, 22, 130, 130, 23, 130, 36, 70, |
| 147470 | + /* 1780 */ 15, 130, 1, 71, 277, 277, 277, 78, 277, 277, |
| 146652 | 147471 | /* 1790 */ 81, 277, 277, 277, 277, 277, 277, 88, 277, 277, |
| 146653 | 147472 | /* 1800 */ 277, 59, 90, 277, 277, 277, 277, 277, 96, 97, |
| 146654 | 147473 | /* 1810 */ 277, 277, 277, 71, 277, 103, 277, 105, 106, 107, |
| 146655 | 147474 | /* 1820 */ 277, 277, 110, 277, 277, 277, 277, 277, 277, 277, |
| 146656 | 147475 | /* 1830 */ 277, 122, 90, 277, 277, 277, 127, 128, 96, 97, |
| | @@ -146671,11 +147490,11 @@ |
| 146671 | 147490 | /* 1980 */ 122, 277, 277, 277, 277, 127, 128, 277, 277, 277, |
| 146672 | 147491 | /* 1990 */ 277, 277, 277, 277, 277, 277, 277, 277, 277, 277, |
| 146673 | 147492 | /* 2000 */ 277, 277, 277, 277, 277, 277, 277, 277, 150, 277, |
| 146674 | 147493 | /* 2010 */ 277, 277, 277, 277, 277, 277, 277, 277, 277, |
| 146675 | 147494 | }; |
| 146676 | | -#define YY_SHIFT_COUNT (520) |
| 147495 | +#define YY_SHIFT_COUNT (524) |
| 146677 | 147496 | #define YY_SHIFT_MIN (0) |
| 146678 | 147497 | #define YY_SHIFT_MAX (1858) |
| 146679 | 147498 | static const unsigned short int yy_shift_ofst[] = { |
| 146680 | 147499 | /* 0 */ 1709, 1520, 1858, 1324, 1324, 277, 1374, 1469, 1602, 1712, |
| 146681 | 147500 | /* 10 */ 1712, 1712, 273, 0, 0, 113, 1016, 1712, 1712, 1712, |
| | @@ -146703,39 +147522,39 @@ |
| 146703 | 147522 | /* 230 */ 531, 531, 744, 531, 531, 783, 531, 531, 531, 531, |
| 146704 | 147523 | /* 240 */ 531, 531, 531, 531, 419, 682, 327, 370, 370, 370, |
| 146705 | 147524 | /* 250 */ 370, 1029, 327, 327, 1024, 897, 856, 947, 1109, 706, |
| 146706 | 147525 | /* 260 */ 706, 1143, 1109, 1109, 1143, 842, 945, 1118, 1136, 1136, |
| 146707 | 147526 | /* 270 */ 1136, 706, 676, 400, 1047, 694, 1339, 1270, 1270, 1366, |
| 146708 | | - /* 280 */ 1366, 1270, 1305, 1389, 1369, 1278, 1401, 1401, 1401, 1401, |
| 146709 | | - /* 290 */ 1270, 1414, 1278, 1278, 1305, 1389, 1369, 1369, 1278, 1270, |
| 146710 | | - /* 300 */ 1414, 1298, 1385, 1270, 1414, 1432, 1270, 1414, 1270, 1414, |
| 146711 | | - /* 310 */ 1432, 1355, 1355, 1355, 1411, 1432, 1355, 1367, 1355, 1411, |
| 146712 | | - /* 320 */ 1355, 1355, 1432, 1392, 1392, 1432, 1365, 1396, 1365, 1396, |
| 146713 | | - /* 330 */ 1365, 1396, 1365, 1396, 1270, 1372, 1429, 1502, 1390, 1372, |
| 146714 | | - /* 340 */ 1517, 1270, 1397, 1390, 1410, 1413, 1278, 1528, 1532, 1549, |
| 146715 | | - /* 350 */ 1549, 1562, 1562, 1562, 2009, 2009, 2009, 2009, 2009, 2009, |
| 147527 | + /* 280 */ 1366, 1270, 1305, 1389, 1275, 1279, 1375, 1275, 1279, 1286, |
| 147528 | + /* 290 */ 1414, 1414, 1414, 1414, 1270, 1418, 1286, 1286, 1305, 1389, |
| 147529 | + /* 300 */ 1375, 1375, 1286, 1270, 1418, 1302, 1393, 1270, 1418, 1438, |
| 147530 | + /* 310 */ 1270, 1418, 1270, 1418, 1438, 1371, 1371, 1371, 1422, 1438, |
| 147531 | + /* 320 */ 1371, 1372, 1371, 1422, 1371, 1371, 1438, 1398, 1398, 1438, |
| 147532 | + /* 330 */ 1369, 1402, 1369, 1402, 1369, 1402, 1369, 1402, 1270, 1279, |
| 147533 | + /* 340 */ 1429, 1492, 1275, 1279, 1507, 1270, 1390, 1275, 1406, 1419, |
| 147534 | + /* 350 */ 1286, 1533, 1537, 1555, 1555, 1564, 1564, 1564, 2009, 2009, |
| 146716 | 147535 | /* 360 */ 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, |
| 146717 | | - /* 370 */ 570, 345, 686, 748, 50, 740, 1064, 1107, 469, 537, |
| 146718 | | - /* 380 */ 1042, 1146, 1162, 1154, 1201, 1202, 1203, 1208, 1209, 1127, |
| 146719 | | - /* 390 */ 1069, 1196, 1157, 1147, 1226, 1228, 1245, 775, 868, 1246, |
| 146720 | | - /* 400 */ 1247, 1191, 1151, 1585, 1589, 1587, 1456, 1600, 1527, 1601, |
| 146721 | | - /* 410 */ 1595, 1596, 1492, 1484, 1506, 1603, 1495, 1608, 1496, 1614, |
| 146722 | | - /* 420 */ 1635, 1508, 1497, 1521, 1580, 1606, 1505, 1592, 1593, 1597, |
| 146723 | | - /* 430 */ 1598, 1530, 1547, 1619, 1524, 1654, 1651, 1636, 1553, 1510, |
| 146724 | | - /* 440 */ 1594, 1634, 1599, 1588, 1623, 1535, 1564, 1642, 1649, 1652, |
| 146725 | | - /* 450 */ 1552, 1560, 1653, 1609, 1655, 1656, 1657, 1659, 1612, 1658, |
| 146726 | | - /* 460 */ 1660, 1616, 1648, 1664, 1550, 1668, 1538, 1670, 1671, 1669, |
| 146727 | | - /* 470 */ 1673, 1675, 1676, 1678, 1680, 1679, 1574, 1683, 1690, 1610, |
| 146728 | | - /* 480 */ 1682, 1695, 1586, 1698, 1691, 1698, 1693, 1643, 1661, 1646, |
| 146729 | | - /* 490 */ 1686, 1710, 1711, 1714, 1716, 1703, 1715, 1698, 1727, 1728, |
| 146730 | | - /* 500 */ 1729, 1730, 1731, 1732, 1734, 1743, 1736, 1737, 1740, 1744, |
| 146731 | | - /* 510 */ 1738, 1746, 1739, 1645, 1640, 1644, 1647, 1650, 1749, 1751, |
| 146732 | | - /* 520 */ 1772, |
| 147536 | + /* 370 */ 2009, 2009, 2009, 2009, 570, 345, 686, 748, 50, 740, |
| 147537 | + /* 380 */ 1064, 1107, 469, 537, 1042, 1146, 1162, 1154, 1201, 1202, |
| 147538 | + /* 390 */ 1203, 1208, 1209, 1127, 1069, 1196, 1157, 1147, 1226, 1228, |
| 147539 | + /* 400 */ 1245, 775, 868, 1246, 1247, 1191, 1151, 1587, 1601, 1595, |
| 147540 | + /* 410 */ 1467, 1604, 1531, 1607, 1603, 1605, 1497, 1488, 1510, 1606, |
| 147541 | + /* 420 */ 1505, 1617, 1506, 1624, 1640, 1512, 1504, 1526, 1585, 1612, |
| 147542 | + /* 430 */ 1511, 1598, 1599, 1600, 1609, 1535, 1550, 1622, 1527, 1657, |
| 147543 | + /* 440 */ 1654, 1638, 1559, 1515, 1597, 1641, 1608, 1591, 1627, 1539, |
| 147544 | + /* 450 */ 1567, 1648, 1655, 1658, 1554, 1565, 1656, 1613, 1659, 1660, |
| 147545 | + /* 460 */ 1662, 1661, 1619, 1663, 1665, 1621, 1653, 1670, 1556, 1673, |
| 147546 | + /* 470 */ 1543, 1674, 1677, 1675, 1679, 1681, 1680, 1683, 1691, 1692, |
| 147547 | + /* 480 */ 1588, 1694, 1701, 1610, 1693, 1703, 1596, 1704, 1695, 1704, |
| 147548 | + /* 490 */ 1699, 1650, 1667, 1668, 1696, 1713, 1714, 1711, 1724, 1718, |
| 147549 | + /* 500 */ 1730, 1704, 1731, 1732, 1733, 1734, 1737, 1735, 1738, 1748, |
| 147550 | + /* 510 */ 1743, 1744, 1745, 1746, 1750, 1751, 1741, 1646, 1644, 1645, |
| 147551 | + /* 520 */ 1647, 1651, 1753, 1765, 1781, |
| 146733 | 147552 | }; |
| 146734 | | -#define YY_REDUCE_COUNT (369) |
| 147553 | +#define YY_REDUCE_COUNT (373) |
| 146735 | 147554 | #define YY_REDUCE_MIN (-237) |
| 146736 | | -#define YY_REDUCE_MAX (1424) |
| 147555 | +#define YY_REDUCE_MAX (1434) |
| 146737 | 147556 | static const short yy_reduce_ofst[] = { |
| 146738 | 147557 | /* 0 */ -147, 171, 263, -96, 358, -144, -149, -102, 124, -156, |
| 146739 | 147558 | /* 10 */ -98, 305, 401, -57, 209, -237, 245, -94, -79, 189, |
| 146740 | 147559 | /* 20 */ 375, 490, 493, 378, 303, 539, 542, 501, 503, 554, |
| 146741 | 147560 | /* 30 */ 415, 526, 546, 557, 587, 593, 595, -234, -234, -234, |
| | @@ -146761,74 +147580,75 @@ |
| 146761 | 147580 | /* 230 */ 1137, 1152, 1077, 1153, 1155, 1114, 1156, 304, 1158, 1172, |
| 146762 | 147581 | /* 240 */ 1173, 1174, 1175, 1176, 1089, 1091, 1133, 1098, 1126, 1139, |
| 146763 | 147582 | /* 250 */ 1140, 1070, 1133, 1133, 1170, 1163, 1186, 1103, 1168, 1138, |
| 146764 | 147583 | /* 260 */ 1141, 1110, 1169, 1171, 1132, 1177, 1189, 1194, 1181, 1200, |
| 146765 | 147584 | /* 270 */ 1204, 1166, 1145, 1178, 1187, 1232, 1142, 1231, 1233, 1149, |
| 146766 | | - /* 280 */ 1150, 1238, 1179, 1182, 1212, 1205, 1219, 1220, 1221, 1222, |
| 146767 | | - /* 290 */ 1258, 1266, 1223, 1224, 1206, 1211, 1237, 1239, 1230, 1269, |
| 146768 | | - /* 300 */ 1272, 1195, 1197, 1280, 1284, 1268, 1285, 1289, 1290, 1293, |
| 146769 | | - /* 310 */ 1274, 1286, 1287, 1288, 1282, 1294, 1292, 1297, 1300, 1296, |
| 146770 | | - /* 320 */ 1301, 1306, 1304, 1249, 1250, 1308, 1271, 1275, 1273, 1276, |
| 146771 | | - /* 330 */ 1279, 1281, 1283, 1302, 1334, 1307, 1243, 1267, 1318, 1322, |
| 146772 | | - /* 340 */ 1303, 1371, 1299, 1328, 1332, 1340, 1342, 1384, 1391, 1400, |
| 146773 | | - /* 350 */ 1403, 1407, 1408, 1409, 1311, 1312, 1310, 1405, 1402, 1412, |
| 146774 | | - /* 360 */ 1417, 1420, 1406, 1393, 1395, 1421, 1422, 1423, 1424, 1415, |
| 147585 | + /* 280 */ 1150, 1238, 1179, 1182, 1199, 1207, 1218, 1211, 1210, 1212, |
| 147586 | + /* 290 */ 1234, 1235, 1236, 1237, 1265, 1268, 1229, 1230, 1213, 1215, |
| 147587 | + /* 300 */ 1243, 1252, 1241, 1276, 1278, 1205, 1220, 1287, 1290, 1273, |
| 147588 | + /* 310 */ 1293, 1304, 1306, 1309, 1285, 1296, 1297, 1299, 1298, 1301, |
| 147589 | + /* 320 */ 1307, 1308, 1311, 1300, 1312, 1313, 1314, 1249, 1255, 1315, |
| 147590 | + /* 330 */ 1280, 1284, 1295, 1316, 1310, 1317, 1318, 1320, 1337, 1319, |
| 147591 | + /* 340 */ 1253, 1258, 1322, 1325, 1321, 1378, 1326, 1328, 1338, 1341, |
| 147592 | + /* 350 */ 1344, 1391, 1395, 1407, 1409, 1415, 1416, 1420, 1323, 1333, |
| 147593 | + /* 360 */ 1329, 1405, 1401, 1403, 1412, 1421, 1408, 1417, 1425, 1423, |
| 147594 | + /* 370 */ 1424, 1427, 1434, 1426, |
| 146775 | 147595 | }; |
| 146776 | 147596 | static const YYACTIONTYPE yy_default[] = { |
| 146777 | | - /* 0 */ 1492, 1492, 1492, 1340, 1123, 1229, 1123, 1123, 1123, 1340, |
| 146778 | | - /* 10 */ 1340, 1340, 1123, 1259, 1259, 1391, 1154, 1123, 1123, 1123, |
| 146779 | | - /* 20 */ 1123, 1123, 1123, 1123, 1339, 1123, 1123, 1123, 1123, 1123, |
| 146780 | | - /* 30 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1265, 1123, |
| 146781 | | - /* 40 */ 1123, 1123, 1123, 1123, 1341, 1342, 1123, 1123, 1123, 1390, |
| 146782 | | - /* 50 */ 1392, 1275, 1274, 1273, 1272, 1373, 1246, 1270, 1263, 1267, |
| 146783 | | - /* 60 */ 1335, 1336, 1334, 1338, 1342, 1341, 1123, 1266, 1306, 1320, |
| 146784 | | - /* 70 */ 1305, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146785 | | - /* 80 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146786 | | - /* 90 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146787 | | - /* 100 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146788 | | - /* 110 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1314, 1319, 1325, |
| 146789 | | - /* 120 */ 1318, 1315, 1308, 1307, 1309, 1310, 1123, 1144, 1193, 1123, |
| 146790 | | - /* 130 */ 1123, 1123, 1123, 1409, 1408, 1123, 1123, 1154, 1311, 1312, |
| 146791 | | - /* 140 */ 1322, 1321, 1398, 1448, 1447, 1123, 1123, 1123, 1123, 1123, |
| 146792 | | - /* 150 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146793 | | - /* 160 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146794 | | - /* 170 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1154, 1150, 1300, |
| 146795 | | - /* 180 */ 1299, 1418, 1150, 1253, 1123, 1404, 1229, 1220, 1123, 1123, |
| 146796 | | - /* 190 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146797 | | - /* 200 */ 1123, 1395, 1393, 1123, 1355, 1123, 1123, 1123, 1123, 1123, |
| 146798 | | - /* 210 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146799 | | - /* 220 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146800 | | - /* 230 */ 1123, 1123, 1225, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146801 | | - /* 240 */ 1123, 1123, 1123, 1442, 1123, 1368, 1207, 1225, 1225, 1225, |
| 146802 | | - /* 250 */ 1225, 1227, 1208, 1206, 1219, 1154, 1130, 1484, 1269, 1248, |
| 146803 | | - /* 260 */ 1248, 1481, 1269, 1269, 1481, 1168, 1462, 1165, 1259, 1259, |
| 146804 | | - /* 270 */ 1259, 1248, 1337, 1226, 1219, 1123, 1484, 1234, 1234, 1483, |
| 146805 | | - /* 280 */ 1483, 1234, 1278, 1284, 1196, 1269, 1202, 1202, 1202, 1202, |
| 146806 | | - /* 290 */ 1234, 1141, 1269, 1269, 1278, 1284, 1196, 1196, 1269, 1234, |
| 146807 | | - /* 300 */ 1141, 1372, 1478, 1234, 1141, 1348, 1234, 1141, 1234, 1141, |
| 146808 | | - /* 310 */ 1348, 1194, 1194, 1194, 1183, 1348, 1194, 1168, 1194, 1183, |
| 146809 | | - /* 320 */ 1194, 1194, 1348, 1352, 1352, 1348, 1252, 1247, 1252, 1247, |
| 146810 | | - /* 330 */ 1252, 1247, 1252, 1247, 1234, 1253, 1417, 1123, 1264, 1253, |
| 146811 | | - /* 340 */ 1343, 1234, 1123, 1264, 1262, 1260, 1269, 1147, 1186, 1445, |
| 146812 | | - /* 350 */ 1445, 1441, 1441, 1441, 1489, 1489, 1404, 1457, 1154, 1154, |
| 146813 | | - /* 360 */ 1154, 1154, 1457, 1170, 1170, 1154, 1154, 1154, 1154, 1457, |
| 146814 | | - /* 370 */ 1123, 1123, 1123, 1123, 1123, 1123, 1452, 1123, 1357, 1238, |
| 146815 | | - /* 380 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146816 | | - /* 390 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146817 | | - /* 400 */ 1123, 1123, 1289, 1123, 1126, 1401, 1123, 1123, 1399, 1123, |
| 146818 | | - /* 410 */ 1123, 1123, 1123, 1123, 1123, 1239, 1123, 1123, 1123, 1123, |
| 146819 | | - /* 420 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146820 | | - /* 430 */ 1123, 1123, 1123, 1123, 1480, 1123, 1123, 1123, 1123, 1123, |
| 146821 | | - /* 440 */ 1123, 1371, 1370, 1123, 1123, 1236, 1123, 1123, 1123, 1123, |
| 146822 | | - /* 450 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146823 | | - /* 460 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146824 | | - /* 470 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146825 | | - /* 480 */ 1123, 1123, 1123, 1261, 1123, 1416, 1123, 1123, 1123, 1123, |
| 146826 | | - /* 490 */ 1123, 1123, 1123, 1430, 1254, 1123, 1123, 1471, 1123, 1123, |
| 146827 | | - /* 500 */ 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, 1123, |
| 146828 | | - /* 510 */ 1123, 1123, 1466, 1210, 1291, 1123, 1290, 1294, 1123, 1135, |
| 146829 | | - /* 520 */ 1123, |
| 147597 | + /* 0 */ 1496, 1496, 1496, 1344, 1127, 1233, 1127, 1127, 1127, 1344, |
| 147598 | + /* 10 */ 1344, 1344, 1127, 1263, 1263, 1395, 1158, 1127, 1127, 1127, |
| 147599 | + /* 20 */ 1127, 1127, 1127, 1127, 1343, 1127, 1127, 1127, 1127, 1127, |
| 147600 | + /* 30 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1269, 1127, |
| 147601 | + /* 40 */ 1127, 1127, 1127, 1127, 1345, 1346, 1127, 1127, 1127, 1394, |
| 147602 | + /* 50 */ 1396, 1279, 1278, 1277, 1276, 1377, 1250, 1274, 1267, 1271, |
| 147603 | + /* 60 */ 1339, 1340, 1338, 1342, 1346, 1345, 1127, 1270, 1310, 1324, |
| 147604 | + /* 70 */ 1309, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147605 | + /* 80 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147606 | + /* 90 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147607 | + /* 100 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147608 | + /* 110 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1318, 1323, 1329, |
| 147609 | + /* 120 */ 1322, 1319, 1312, 1311, 1313, 1314, 1127, 1148, 1197, 1127, |
| 147610 | + /* 130 */ 1127, 1127, 1127, 1413, 1412, 1127, 1127, 1158, 1315, 1316, |
| 147611 | + /* 140 */ 1326, 1325, 1402, 1452, 1451, 1127, 1127, 1127, 1127, 1127, |
| 147612 | + /* 150 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147613 | + /* 160 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147614 | + /* 170 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1158, 1154, 1304, |
| 147615 | + /* 180 */ 1303, 1422, 1154, 1257, 1127, 1408, 1233, 1224, 1127, 1127, |
| 147616 | + /* 190 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147617 | + /* 200 */ 1127, 1399, 1397, 1127, 1359, 1127, 1127, 1127, 1127, 1127, |
| 147618 | + /* 210 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147619 | + /* 220 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147620 | + /* 230 */ 1127, 1127, 1229, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147621 | + /* 240 */ 1127, 1127, 1127, 1446, 1127, 1372, 1211, 1229, 1229, 1229, |
| 147622 | + /* 250 */ 1229, 1231, 1212, 1210, 1223, 1158, 1134, 1488, 1273, 1252, |
| 147623 | + /* 260 */ 1252, 1485, 1273, 1273, 1485, 1172, 1466, 1169, 1263, 1263, |
| 147624 | + /* 270 */ 1263, 1252, 1341, 1230, 1223, 1127, 1488, 1238, 1238, 1487, |
| 147625 | + /* 280 */ 1487, 1238, 1282, 1288, 1268, 1257, 1200, 1268, 1257, 1273, |
| 147626 | + /* 290 */ 1206, 1206, 1206, 1206, 1238, 1145, 1273, 1273, 1282, 1288, |
| 147627 | + /* 300 */ 1200, 1200, 1273, 1238, 1145, 1376, 1482, 1238, 1145, 1352, |
| 147628 | + /* 310 */ 1238, 1145, 1238, 1145, 1352, 1198, 1198, 1198, 1187, 1352, |
| 147629 | + /* 320 */ 1198, 1172, 1198, 1187, 1198, 1198, 1352, 1356, 1356, 1352, |
| 147630 | + /* 330 */ 1256, 1251, 1256, 1251, 1256, 1251, 1256, 1251, 1238, 1257, |
| 147631 | + /* 340 */ 1421, 1127, 1268, 1257, 1347, 1238, 1127, 1268, 1266, 1264, |
| 147632 | + /* 350 */ 1273, 1151, 1190, 1449, 1449, 1445, 1445, 1445, 1493, 1493, |
| 147633 | + /* 360 */ 1408, 1461, 1158, 1158, 1158, 1158, 1461, 1174, 1174, 1158, |
| 147634 | + /* 370 */ 1158, 1158, 1158, 1461, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147635 | + /* 380 */ 1456, 1127, 1361, 1242, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147636 | + /* 390 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147637 | + /* 400 */ 1127, 1127, 1127, 1127, 1127, 1127, 1293, 1127, 1130, 1405, |
| 147638 | + /* 410 */ 1127, 1127, 1403, 1127, 1127, 1127, 1127, 1127, 1127, 1243, |
| 147639 | + /* 420 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147640 | + /* 430 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1484, 1127, |
| 147641 | + /* 440 */ 1127, 1127, 1127, 1127, 1127, 1375, 1374, 1127, 1127, 1240, |
| 147642 | + /* 450 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147643 | + /* 460 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147644 | + /* 470 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147645 | + /* 480 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1265, 1127, 1420, |
| 147646 | + /* 490 */ 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1434, 1258, 1127, |
| 147647 | + /* 500 */ 1127, 1475, 1127, 1127, 1127, 1127, 1127, 1127, 1127, 1127, |
| 147648 | + /* 510 */ 1127, 1127, 1127, 1127, 1127, 1127, 1470, 1214, 1295, 1127, |
| 147649 | + /* 520 */ 1294, 1298, 1127, 1139, 1127, |
| 146830 | 147650 | }; |
| 146831 | 147651 | /********** End of lemon-generated parsing tables *****************************/ |
| 146832 | 147652 | |
| 146833 | 147653 | /* The next table maps tokens (terminal symbols) into fallback tokens. |
| 146834 | 147654 | ** If a construct like the following: |
| | @@ -147448,14 +148268,14 @@ |
| 147448 | 148268 | /* 137 */ "having_opt ::= HAVING expr", |
| 147449 | 148269 | /* 138 */ "limit_opt ::=", |
| 147450 | 148270 | /* 139 */ "limit_opt ::= LIMIT expr", |
| 147451 | 148271 | /* 140 */ "limit_opt ::= LIMIT expr OFFSET expr", |
| 147452 | 148272 | /* 141 */ "limit_opt ::= LIMIT expr COMMA expr", |
| 147453 | | - /* 142 */ "cmd ::= with DELETE FROM xfullname indexed_opt where_opt", |
| 148273 | + /* 142 */ "cmd ::= with DELETE FROM xfullname indexed_opt where_opt orderby_opt limit_opt", |
| 147454 | 148274 | /* 143 */ "where_opt ::=", |
| 147455 | 148275 | /* 144 */ "where_opt ::= WHERE expr", |
| 147456 | | - /* 145 */ "cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt", |
| 148276 | + /* 145 */ "cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt orderby_opt limit_opt", |
| 147457 | 148277 | /* 146 */ "setlist ::= setlist COMMA nm EQ expr", |
| 147458 | 148278 | /* 147 */ "setlist ::= setlist COMMA LP idlist RP EQ expr", |
| 147459 | 148279 | /* 148 */ "setlist ::= nm EQ expr", |
| 147460 | 148280 | /* 149 */ "setlist ::= LP idlist RP EQ expr", |
| 147461 | 148281 | /* 150 */ "cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert", |
| | @@ -148328,14 +149148,14 @@ |
| 148328 | 149148 | { 215, -2 }, /* (137) having_opt ::= HAVING expr */ |
| 148329 | 149149 | { 217, 0 }, /* (138) limit_opt ::= */ |
| 148330 | 149150 | { 217, -2 }, /* (139) limit_opt ::= LIMIT expr */ |
| 148331 | 149151 | { 217, -4 }, /* (140) limit_opt ::= LIMIT expr OFFSET expr */ |
| 148332 | 149152 | { 217, -4 }, /* (141) limit_opt ::= LIMIT expr COMMA expr */ |
| 148333 | | - { 160, -6 }, /* (142) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */ |
| 149153 | + { 160, -8 }, /* (142) cmd ::= with DELETE FROM xfullname indexed_opt where_opt orderby_opt limit_opt */ |
| 148334 | 149154 | { 213, 0 }, /* (143) where_opt ::= */ |
| 148335 | 149155 | { 213, -2 }, /* (144) where_opt ::= WHERE expr */ |
| 148336 | | - { 160, -8 }, /* (145) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */ |
| 149156 | + { 160, -10 }, /* (145) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt orderby_opt limit_opt */ |
| 148337 | 149157 | { 233, -5 }, /* (146) setlist ::= setlist COMMA nm EQ expr */ |
| 148338 | 149158 | { 233, -7 }, /* (147) setlist ::= setlist COMMA LP idlist RP EQ expr */ |
| 148339 | 149159 | { 233, -3 }, /* (148) setlist ::= nm EQ expr */ |
| 148340 | 149160 | { 233, -5 }, /* (149) setlist ::= LP idlist RP EQ expr */ |
| 148341 | 149161 | { 160, -7 }, /* (150) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */ |
| | @@ -149215,21 +150035,21 @@ |
| 149215 | 150035 | {yymsp[-3].minor.yy18 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy18,yymsp[0].minor.yy18);} |
| 149216 | 150036 | break; |
| 149217 | 150037 | case 141: /* limit_opt ::= LIMIT expr COMMA expr */ |
| 149218 | 150038 | {yymsp[-3].minor.yy18 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy18,yymsp[-2].minor.yy18);} |
| 149219 | 150039 | break; |
| 149220 | | - case 142: /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt */ |
| 149221 | | -{ |
| 149222 | | - sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy135, &yymsp[-1].minor.yy0); |
| 149223 | | - sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy135,yymsp[0].minor.yy18,0,0); |
| 149224 | | -} |
| 149225 | | - break; |
| 149226 | | - case 145: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */ |
| 150040 | + case 142: /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt orderby_opt limit_opt */ |
| 149227 | 150041 | { |
| 149228 | 150042 | sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy135, &yymsp[-3].minor.yy0); |
| 149229 | | - sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy420,"set list"); |
| 149230 | | - sqlite3Update(pParse,yymsp[-4].minor.yy135,yymsp[-1].minor.yy420,yymsp[0].minor.yy18,yymsp[-5].minor.yy70,0,0,0); |
| 150043 | + sqlite3DeleteFrom(pParse,yymsp[-4].minor.yy135,yymsp[-2].minor.yy18,yymsp[-1].minor.yy420,yymsp[0].minor.yy18); |
| 150044 | +} |
| 150045 | + break; |
| 150046 | + case 145: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt orderby_opt limit_opt */ |
| 150047 | +{ |
| 150048 | + sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy135, &yymsp[-5].minor.yy0); |
| 150049 | + sqlite3ExprListCheckLength(pParse,yymsp[-3].minor.yy420,"set list"); |
| 150050 | + sqlite3Update(pParse,yymsp[-6].minor.yy135,yymsp[-3].minor.yy420,yymsp[-2].minor.yy18,yymsp[-7].minor.yy70,yymsp[-1].minor.yy420,yymsp[0].minor.yy18,0); |
| 149231 | 150051 | } |
| 149232 | 150052 | break; |
| 149233 | 150053 | case 146: /* setlist ::= setlist COMMA nm EQ expr */ |
| 149234 | 150054 | { |
| 149235 | 150055 | yymsp[-4].minor.yy420 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy420, yymsp[0].minor.yy18); |
| | @@ -151197,10 +152017,77 @@ |
| 151197 | 152017 | while( IdChar(z[i]) ){ i++; } |
| 151198 | 152018 | *tokenType = TK_ID; |
| 151199 | 152019 | return i; |
| 151200 | 152020 | } |
| 151201 | 152021 | |
| 152022 | +#ifdef SQLITE_ENABLE_NORMALIZE |
| 152023 | +/* |
| 152024 | +** Return the length (in bytes) of the token that begins at z[0]. |
| 152025 | +** Store the token type in *tokenType before returning. If flags has |
| 152026 | +** SQLITE_TOKEN_NORMALIZE flag enabled, use the identifier token type |
| 152027 | +** for keywords. Add SQLITE_TOKEN_QUOTED to flags if the token was |
| 152028 | +** actually a quoted identifier. Add SQLITE_TOKEN_KEYWORD to flags |
| 152029 | +** if the token was recognized as a keyword; this is useful when the |
| 152030 | +** SQLITE_TOKEN_NORMALIZE flag is used, because it enables the caller |
| 152031 | +** to differentiate between a keyword being treated as an identifier |
| 152032 | +** (for normalization purposes) and an actual identifier. |
| 152033 | +*/ |
| 152034 | +SQLITE_PRIVATE int sqlite3GetTokenNormalized( |
| 152035 | + const unsigned char *z, |
| 152036 | + int *tokenType, |
| 152037 | + int *flags |
| 152038 | +){ |
| 152039 | + int n; |
| 152040 | + unsigned char iClass = aiClass[*z]; |
| 152041 | + if( iClass==CC_KYWD ){ |
| 152042 | + int i; |
| 152043 | + for(i=1; aiClass[z[i]]<=CC_KYWD; i++){} |
| 152044 | + if( IdChar(z[i]) ){ |
| 152045 | + /* This token started out using characters that can appear in keywords, |
| 152046 | + ** but z[i] is a character not allowed within keywords, so this must |
| 152047 | + ** be an identifier instead */ |
| 152048 | + i++; |
| 152049 | + while( IdChar(z[i]) ){ i++; } |
| 152050 | + *tokenType = TK_ID; |
| 152051 | + return i; |
| 152052 | + } |
| 152053 | + *tokenType = TK_ID; |
| 152054 | + n = keywordCode((char*)z, i, tokenType); |
| 152055 | + /* If the token is no longer considered to be an identifier, then it is a |
| 152056 | + ** keyword of some kind. Make the token back into an identifier and then |
| 152057 | + ** set the SQLITE_TOKEN_KEYWORD flag. Several non-identifier tokens are |
| 152058 | + ** used verbatim, including IN, IS, NOT, and NULL. */ |
| 152059 | + switch( *tokenType ){ |
| 152060 | + case TK_ID: { |
| 152061 | + /* do nothing, handled by caller */ |
| 152062 | + break; |
| 152063 | + } |
| 152064 | + case TK_IN: |
| 152065 | + case TK_IS: |
| 152066 | + case TK_NOT: |
| 152067 | + case TK_NULL: { |
| 152068 | + *flags |= SQLITE_TOKEN_KEYWORD; |
| 152069 | + break; |
| 152070 | + } |
| 152071 | + default: { |
| 152072 | + *tokenType = TK_ID; |
| 152073 | + *flags |= SQLITE_TOKEN_KEYWORD; |
| 152074 | + break; |
| 152075 | + } |
| 152076 | + } |
| 152077 | + }else{ |
| 152078 | + n = sqlite3GetToken(z, tokenType); |
| 152079 | + /* If the token is considered to be an identifier and the character class |
| 152080 | + ** of the first character is a quote, set the SQLITE_TOKEN_QUOTED flag. */ |
| 152081 | + if( *tokenType==TK_ID && (iClass==CC_QUOTE || iClass==CC_QUOTE2) ){ |
| 152082 | + *flags |= SQLITE_TOKEN_QUOTED; |
| 152083 | + } |
| 152084 | + } |
| 152085 | + return n; |
| 152086 | +} |
| 152087 | +#endif /* SQLITE_ENABLE_NORMALIZE */ |
| 152088 | + |
| 151202 | 152089 | /* |
| 151203 | 152090 | ** Run the parser on the given SQL string. The parser structure is |
| 151204 | 152091 | ** passed in. An SQLITE_ status code is returned. If an error occurs |
| 151205 | 152092 | ** then an and attempt is made to write an error message into |
| 151206 | 152093 | ** memory obtained from sqlite3_malloc() and to make *pzErrMsg point to that |
| | @@ -152594,10 +153481,11 @@ |
| 152594 | 153481 | { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension }, |
| 152595 | 153482 | { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose }, |
| 152596 | 153483 | { SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG }, |
| 152597 | 153484 | { SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP }, |
| 152598 | 153485 | { SQLITE_DBCONFIG_RESET_DATABASE, SQLITE_ResetDatabase }, |
| 153486 | + { SQLITE_DBCONFIG_DEFENSIVE, SQLITE_Defensive }, |
| 152599 | 153487 | }; |
| 152600 | 153488 | unsigned int i; |
| 152601 | 153489 | rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ |
| 152602 | 153490 | for(i=0; i<ArraySize(aFlagOp); i++){ |
| 152603 | 153491 | if( aFlagOp[i].op==op ){ |
| | @@ -154820,10 +155708,13 @@ |
| 154820 | 155708 | #if defined(SQLITE_ENABLE_FTS3_TOKENIZER) |
| 154821 | 155709 | | SQLITE_Fts3Tokenizer |
| 154822 | 155710 | #endif |
| 154823 | 155711 | #if defined(SQLITE_ENABLE_QPSG) |
| 154824 | 155712 | | SQLITE_EnableQPSG |
| 155713 | +#endif |
| 155714 | +#if defined(SQLITE_DEFAULT_DEFENSIVE) |
| 155715 | + | SQLITE_Defensive |
| 154825 | 155716 | #endif |
| 154826 | 155717 | ; |
| 154827 | 155718 | sqlite3HashInit(&db->aCollSeq); |
| 154828 | 155719 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 154829 | 155720 | sqlite3HashInit(&db->aModule); |
| | @@ -159159,11 +160050,11 @@ |
| 159159 | 160050 | ){ |
| 159160 | 160051 | int rc = SQLITE_OK; /* Return code */ |
| 159161 | 160052 | const char *zCsr = zNode; /* Cursor to iterate through node */ |
| 159162 | 160053 | const char *zEnd = &zCsr[nNode];/* End of interior node buffer */ |
| 159163 | 160054 | char *zBuffer = 0; /* Buffer to load terms into */ |
| 159164 | | - int nAlloc = 0; /* Size of allocated buffer */ |
| 160055 | + i64 nAlloc = 0; /* Size of allocated buffer */ |
| 159165 | 160056 | int isFirstTerm = 1; /* True when processing first term on page */ |
| 159166 | 160057 | sqlite3_int64 iChild; /* Block id of child node to descend to */ |
| 159167 | 160058 | |
| 159168 | 160059 | /* Skip over the 'height' varint that occurs at the start of every |
| 159169 | 160060 | ** interior node. Then load the blockid of the left-child of the b-tree |
| | @@ -159197,18 +160088,18 @@ |
| 159197 | 160088 | } |
| 159198 | 160089 | isFirstTerm = 0; |
| 159199 | 160090 | zCsr += fts3GetVarint32(zCsr, &nSuffix); |
| 159200 | 160091 | |
| 159201 | 160092 | assert( nPrefix>=0 && nSuffix>=0 ); |
| 159202 | | - if( &zCsr[nSuffix]>zEnd ){ |
| 160093 | + if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){ |
| 159203 | 160094 | rc = FTS_CORRUPT_VTAB; |
| 159204 | 160095 | goto finish_scan; |
| 159205 | 160096 | } |
| 159206 | | - if( nPrefix+nSuffix>nAlloc ){ |
| 160097 | + if( (i64)nPrefix+nSuffix>nAlloc ){ |
| 159207 | 160098 | char *zNew; |
| 159208 | | - nAlloc = (nPrefix+nSuffix) * 2; |
| 159209 | | - zNew = (char *)sqlite3_realloc(zBuffer, nAlloc); |
| 160099 | + nAlloc = ((i64)nPrefix+nSuffix) * 2; |
| 160100 | + zNew = (char *)sqlite3_realloc64(zBuffer, nAlloc); |
| 159210 | 160101 | if( !zNew ){ |
| 159211 | 160102 | rc = SQLITE_NOMEM; |
| 159212 | 160103 | goto finish_scan; |
| 159213 | 160104 | } |
| 159214 | 160105 | zBuffer = zNew; |
| | @@ -161183,13 +162074,28 @@ |
| 161183 | 162074 | assert( p->mxSavepoint >= iSavepoint ); |
| 161184 | 162075 | TESTONLY( p->mxSavepoint = iSavepoint ); |
| 161185 | 162076 | sqlite3Fts3PendingTermsClear(p); |
| 161186 | 162077 | return SQLITE_OK; |
| 161187 | 162078 | } |
| 162079 | + |
| 162080 | +/* |
| 162081 | +** Return true if zName is the extension on one of the shadow tables used |
| 162082 | +** by this module. |
| 162083 | +*/ |
| 162084 | +static int fts3ShadowName(const char *zName){ |
| 162085 | + static const char *azName[] = { |
| 162086 | + "content", "docsize", "segdir", "segments", "stat", |
| 162087 | + }; |
| 162088 | + unsigned int i; |
| 162089 | + for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){ |
| 162090 | + if( sqlite3_stricmp(zName, azName[i])==0 ) return 1; |
| 162091 | + } |
| 162092 | + return 0; |
| 162093 | +} |
| 161188 | 162094 | |
| 161189 | 162095 | static const sqlite3_module fts3Module = { |
| 161190 | | - /* iVersion */ 2, |
| 162096 | + /* iVersion */ 3, |
| 161191 | 162097 | /* xCreate */ fts3CreateMethod, |
| 161192 | 162098 | /* xConnect */ fts3ConnectMethod, |
| 161193 | 162099 | /* xBestIndex */ fts3BestIndexMethod, |
| 161194 | 162100 | /* xDisconnect */ fts3DisconnectMethod, |
| 161195 | 162101 | /* xDestroy */ fts3DestroyMethod, |
| | @@ -161208,10 +162114,11 @@ |
| 161208 | 162114 | /* xFindFunction */ fts3FindFunctionMethod, |
| 161209 | 162115 | /* xRename */ fts3RenameMethod, |
| 161210 | 162116 | /* xSavepoint */ fts3SavepointMethod, |
| 161211 | 162117 | /* xRelease */ fts3ReleaseMethod, |
| 161212 | 162118 | /* xRollbackTo */ fts3RollbackToMethod, |
| 162119 | + /* xShadowName */ fts3ShadowName, |
| 161213 | 162120 | }; |
| 161214 | 162121 | |
| 161215 | 162122 | /* |
| 161216 | 162123 | ** This function is registered as the module destructor (called when an |
| 161217 | 162124 | ** FTS3 enabled database connection is closed). It frees the memory |
| | @@ -163839,11 +164746,12 @@ |
| 163839 | 164746 | 0, /* xRollback */ |
| 163840 | 164747 | 0, /* xFindFunction */ |
| 163841 | 164748 | 0, /* xRename */ |
| 163842 | 164749 | 0, /* xSavepoint */ |
| 163843 | 164750 | 0, /* xRelease */ |
| 163844 | | - 0 /* xRollbackTo */ |
| 164751 | + 0, /* xRollbackTo */ |
| 164752 | + 0 /* xShadowName */ |
| 163845 | 164753 | }; |
| 163846 | 164754 | int rc; /* Return code */ |
| 163847 | 164755 | |
| 163848 | 164756 | rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0); |
| 163849 | 164757 | return rc; |
| | @@ -167398,11 +168306,12 @@ |
| 167398 | 168306 | 0, /* xRollback */ |
| 167399 | 168307 | 0, /* xFindFunction */ |
| 167400 | 168308 | 0, /* xRename */ |
| 167401 | 168309 | 0, /* xSavepoint */ |
| 167402 | 168310 | 0, /* xRelease */ |
| 167403 | | - 0 /* xRollbackTo */ |
| 168311 | + 0, /* xRollbackTo */ |
| 168312 | + 0 /* xShadowName */ |
| 167404 | 168313 | }; |
| 167405 | 168314 | int rc; /* Return code */ |
| 167406 | 168315 | |
| 167407 | 168316 | rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash); |
| 167408 | 168317 | return rc; |
| | @@ -168786,19 +169695,23 @@ |
| 168786 | 169695 | |
| 168787 | 169696 | /* Because of the FTS3_NODE_PADDING bytes of padding, the following is |
| 168788 | 169697 | ** safe (no risk of overread) even if the node data is corrupted. */ |
| 168789 | 169698 | pNext += fts3GetVarint32(pNext, &nPrefix); |
| 168790 | 169699 | pNext += fts3GetVarint32(pNext, &nSuffix); |
| 168791 | | - if( nPrefix<0 || nSuffix<=0 |
| 168792 | | - || &pNext[nSuffix]>&pReader->aNode[pReader->nNode] |
| 169700 | + if( nSuffix<=0 |
| 169701 | + || (&pReader->aNode[pReader->nNode] - pNext)<nSuffix |
| 169702 | + || nPrefix>pReader->nTermAlloc |
| 168793 | 169703 | ){ |
| 168794 | 169704 | return FTS_CORRUPT_VTAB; |
| 168795 | 169705 | } |
| 168796 | 169706 | |
| 168797 | | - if( nPrefix+nSuffix>pReader->nTermAlloc ){ |
| 168798 | | - int nNew = (nPrefix+nSuffix)*2; |
| 168799 | | - char *zNew = sqlite3_realloc(pReader->zTerm, nNew); |
| 169707 | + /* Both nPrefix and nSuffix were read by fts3GetVarint32() and so are |
| 169708 | + ** between 0 and 0x7FFFFFFF. But the sum of the two may cause integer |
| 169709 | + ** overflow - hence the (i64) casts. */ |
| 169710 | + if( (i64)nPrefix+nSuffix>(i64)pReader->nTermAlloc ){ |
| 169711 | + i64 nNew = ((i64)nPrefix+nSuffix)*2; |
| 169712 | + char *zNew = sqlite3_realloc64(pReader->zTerm, nNew); |
| 168800 | 169713 | if( !zNew ){ |
| 168801 | 169714 | return SQLITE_NOMEM; |
| 168802 | 169715 | } |
| 168803 | 169716 | pReader->zTerm = zNew; |
| 168804 | 169717 | pReader->nTermAlloc = nNew; |
| | @@ -168816,11 +169729,11 @@ |
| 168816 | 169729 | |
| 168817 | 169730 | /* Check that the doclist does not appear to extend past the end of the |
| 168818 | 169731 | ** b-tree node. And that the final byte of the doclist is 0x00. If either |
| 168819 | 169732 | ** of these statements is untrue, then the data structure is corrupt. |
| 168820 | 169733 | */ |
| 168821 | | - if( &pReader->aDoclist[pReader->nDoclist]>&pReader->aNode[pReader->nNode] |
| 169734 | + if( (&pReader->aNode[pReader->nNode] - pReader->aDoclist)<pReader->nDoclist |
| 168822 | 169735 | || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1]) |
| 168823 | 169736 | ){ |
| 168824 | 169737 | return FTS_CORRUPT_VTAB; |
| 168825 | 169738 | } |
| 168826 | 169739 | return SQLITE_OK; |
| | @@ -171142,25 +172055,30 @@ |
| 171142 | 172055 | if( bFirst==0 ){ |
| 171143 | 172056 | p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nPrefix); |
| 171144 | 172057 | } |
| 171145 | 172058 | p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nSuffix); |
| 171146 | 172059 | |
| 172060 | + if( nPrefix>p->iOff || nSuffix>p->nNode-p->iOff ){ |
| 172061 | + return SQLITE_CORRUPT_VTAB; |
| 172062 | + } |
| 171147 | 172063 | blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc); |
| 171148 | 172064 | if( rc==SQLITE_OK ){ |
| 171149 | 172065 | memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix); |
| 171150 | 172066 | p->term.n = nPrefix+nSuffix; |
| 171151 | 172067 | p->iOff += nSuffix; |
| 171152 | 172068 | if( p->iChild==0 ){ |
| 171153 | 172069 | p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist); |
| 172070 | + if( (p->nNode-p->iOff)<p->nDoclist ){ |
| 172071 | + return SQLITE_CORRUPT_VTAB; |
| 172072 | + } |
| 171154 | 172073 | p->aDoclist = &p->aNode[p->iOff]; |
| 171155 | 172074 | p->iOff += p->nDoclist; |
| 171156 | 172075 | } |
| 171157 | 172076 | } |
| 171158 | 172077 | } |
| 171159 | 172078 | |
| 171160 | 172079 | assert( p->iOff<=p->nNode ); |
| 171161 | | - |
| 171162 | 172080 | return rc; |
| 171163 | 172081 | } |
| 171164 | 172082 | |
| 171165 | 172083 | /* |
| 171166 | 172084 | ** Release all dynamic resources held by node-reader object *p. |
| | @@ -177960,11 +178878,12 @@ |
| 177960 | 178878 | 0, /* xRollback */ |
| 177961 | 178879 | 0, /* xFindMethod */ |
| 177962 | 178880 | 0, /* xRename */ |
| 177963 | 178881 | 0, /* xSavepoint */ |
| 177964 | 178882 | 0, /* xRelease */ |
| 177965 | | - 0 /* xRollbackTo */ |
| 178883 | + 0, /* xRollbackTo */ |
| 178884 | + 0 /* xShadowName */ |
| 177966 | 178885 | }; |
| 177967 | 178886 | |
| 177968 | 178887 | /* The methods of the json_tree virtual table. */ |
| 177969 | 178888 | static sqlite3_module jsonTreeModule = { |
| 177970 | 178889 | 0, /* iVersion */ |
| | @@ -177987,11 +178906,12 @@ |
| 177987 | 178906 | 0, /* xRollback */ |
| 177988 | 178907 | 0, /* xFindMethod */ |
| 177989 | 178908 | 0, /* xRename */ |
| 177990 | 178909 | 0, /* xSavepoint */ |
| 177991 | 178910 | 0, /* xRelease */ |
| 177992 | | - 0 /* xRollbackTo */ |
| 178911 | + 0, /* xRollbackTo */ |
| 178912 | + 0 /* xShadowName */ |
| 177993 | 178913 | }; |
| 177994 | 178914 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 177995 | 178915 | |
| 177996 | 178916 | /**************************************************************************** |
| 177997 | 178917 | ** The following routines are the only publically visible identifiers in this |
| | @@ -181417,12 +182337,28 @@ |
| 181417 | 182337 | } |
| 181418 | 182338 | |
| 181419 | 182339 | return rc; |
| 181420 | 182340 | } |
| 181421 | 182341 | |
| 182342 | + |
| 182343 | +/* |
| 182344 | +** Return true if zName is the extension on one of the shadow tables used |
| 182345 | +** by this module. |
| 182346 | +*/ |
| 182347 | +static int rtreeShadowName(const char *zName){ |
| 182348 | + static const char *azName[] = { |
| 182349 | + "node", "parent", "rowid" |
| 182350 | + }; |
| 182351 | + unsigned int i; |
| 182352 | + for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){ |
| 182353 | + if( sqlite3_stricmp(zName, azName[i])==0 ) return 1; |
| 182354 | + } |
| 182355 | + return 0; |
| 182356 | +} |
| 182357 | + |
| 181422 | 182358 | static sqlite3_module rtreeModule = { |
| 181423 | | - 2, /* iVersion */ |
| 182359 | + 3, /* iVersion */ |
| 181424 | 182360 | rtreeCreate, /* xCreate - create a table */ |
| 181425 | 182361 | rtreeConnect, /* xConnect - connect to an existing table */ |
| 181426 | 182362 | rtreeBestIndex, /* xBestIndex - Determine search strategy */ |
| 181427 | 182363 | rtreeDisconnect, /* xDisconnect - Disconnect from a table */ |
| 181428 | 182364 | rtreeDestroy, /* xDestroy - Drop a table */ |
| | @@ -181441,10 +182377,11 @@ |
| 181441 | 182377 | 0, /* xFindFunction - function overloading */ |
| 181442 | 182378 | rtreeRename, /* xRename - rename the table */ |
| 181443 | 182379 | rtreeSavepoint, /* xSavepoint */ |
| 181444 | 182380 | 0, /* xRelease */ |
| 181445 | 182381 | 0, /* xRollbackTo */ |
| 182382 | + rtreeShadowName /* xShadowName */ |
| 181446 | 182383 | }; |
| 181447 | 182384 | |
| 181448 | 182385 | static int rtreeSqlInit( |
| 181449 | 182386 | Rtree *pRtree, |
| 181450 | 182387 | sqlite3 *db, |
| | @@ -182431,17 +183368,27 @@ |
| 182431 | 183368 | ** The on-disk representation consists of a 4-byte header followed by |
| 182432 | 183369 | ** the values. The 4-byte header is: |
| 182433 | 183370 | ** |
| 182434 | 183371 | ** encoding (1 byte) 0=big-endian, 1=little-endian |
| 182435 | 183372 | ** nvertex (3 bytes) Number of vertexes as a big-endian integer |
| 183373 | +** |
| 183374 | +** Enough space is allocated for 4 coordinates, to work around over-zealous |
| 183375 | +** warnings coming from some compiler (notably, clang). In reality, the size |
| 183376 | +** of each GeoPoly memory allocate is adjusted as necessary so that the |
| 183377 | +** GeoPoly.a[] array at the end is the appropriate size. |
| 182436 | 183378 | */ |
| 182437 | 183379 | typedef struct GeoPoly GeoPoly; |
| 182438 | 183380 | struct GeoPoly { |
| 182439 | 183381 | int nVertex; /* Number of vertexes */ |
| 182440 | 183382 | unsigned char hdr[4]; /* Header for on-disk representation */ |
| 182441 | | - GeoCoord a[2]; /* 2*nVertex values. X (longitude) first, then Y */ |
| 183383 | + GeoCoord a[8]; /* 2*nVertex values. X (longitude) first, then Y */ |
| 182442 | 183384 | }; |
| 183385 | + |
| 183386 | +/* The size of a memory allocation needed for a GeoPoly object sufficient |
| 183387 | +** to hold N coordinate pairs. |
| 183388 | +*/ |
| 183389 | +#define GEOPOLY_SZ(N) (sizeof(GeoPoly) + sizeof(GeoCoord)*2*((N)-4)) |
| 182443 | 183390 | |
| 182444 | 183391 | /* |
| 182445 | 183392 | ** State of a parse of a GeoJSON input. |
| 182446 | 183393 | */ |
| 182447 | 183394 | typedef struct GeoParse GeoParse; |
| | @@ -182463,11 +183410,11 @@ |
| 182463 | 183410 | a[2] = t; |
| 182464 | 183411 | } |
| 182465 | 183412 | |
| 182466 | 183413 | /* Skip whitespace. Return the next non-whitespace character. */ |
| 182467 | 183414 | static char geopolySkipSpace(GeoParse *p){ |
| 182468 | | - while( p->z[0] && safe_isspace(p->z[0]) ) p->z++; |
| 183415 | + while( safe_isspace(p->z[0]) ) p->z++; |
| 182469 | 183416 | return p->z[0]; |
| 182470 | 183417 | } |
| 182471 | 183418 | |
| 182472 | 183419 | /* Parse out a number. Write the value into *pVal if pVal!=0. |
| 182473 | 183420 | ** return non-zero on success and zero if the next token is not a number. |
| | @@ -182483,11 +183430,11 @@ |
| 182483 | 183430 | c = z[j]; |
| 182484 | 183431 | } |
| 182485 | 183432 | if( c=='0' && z[j+1]>='0' && z[j+1]<='9' ) return 0; |
| 182486 | 183433 | for(;; j++){ |
| 182487 | 183434 | c = z[j]; |
| 182488 | | - if( c>='0' && c<='9' ) continue; |
| 183435 | + if( safe_isdigit(c) ) continue; |
| 182489 | 183436 | if( c=='.' ){ |
| 182490 | 183437 | if( z[j-1]=='-' ) return 0; |
| 182491 | 183438 | if( seenDP ) return 0; |
| 182492 | 183439 | seenDP = 1; |
| 182493 | 183440 | continue; |
| | @@ -182505,11 +183452,21 @@ |
| 182505 | 183452 | continue; |
| 182506 | 183453 | } |
| 182507 | 183454 | break; |
| 182508 | 183455 | } |
| 182509 | 183456 | if( z[j-1]<'0' ) return 0; |
| 182510 | | - if( pVal ) *pVal = (GeoCoord)atof((const char*)p->z); |
| 183457 | + if( pVal ){ |
| 183458 | +#ifdef SQLITE_AMALGAMATION |
| 183459 | + /* The sqlite3AtoF() routine is much much faster than atof(), if it |
| 183460 | + ** is available */ |
| 183461 | + double r; |
| 183462 | + (void)sqlite3AtoF((const char*)p->z, &r, j, SQLITE_UTF8); |
| 183463 | + *pVal = r; |
| 183464 | +#else |
| 183465 | + *pVal = (GeoCoord)atof((const char*)p->z); |
| 183466 | +#endif |
| 183467 | + } |
| 182511 | 183468 | p->z += j; |
| 182512 | 183469 | return 1; |
| 182513 | 183470 | } |
| 182514 | 183471 | |
| 182515 | 183472 | /* |
| | @@ -182563,16 +183520,14 @@ |
| 182563 | 183520 | && s.nVertex>=4 |
| 182564 | 183521 | && s.a[0]==s.a[s.nVertex*2-2] |
| 182565 | 183522 | && s.a[1]==s.a[s.nVertex*2-1] |
| 182566 | 183523 | && (s.z++, geopolySkipSpace(&s)==0) |
| 182567 | 183524 | ){ |
| 182568 | | - int nByte; |
| 182569 | 183525 | GeoPoly *pOut; |
| 182570 | 183526 | int x = 1; |
| 182571 | 183527 | s.nVertex--; /* Remove the redundant vertex at the end */ |
| 182572 | | - nByte = sizeof(GeoPoly) * s.nVertex*2*sizeof(GeoCoord); |
| 182573 | | - pOut = sqlite3_malloc64( nByte ); |
| 183528 | + pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) ); |
| 182574 | 183529 | x = 1; |
| 182575 | 183530 | if( pOut==0 ) goto parse_json_err; |
| 182576 | 183531 | pOut->nVertex = s.nVertex; |
| 182577 | 183532 | memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord)); |
| 182578 | 183533 | pOut->hdr[0] = *(unsigned char*)&x; |
| | @@ -182770,10 +183725,31 @@ |
| 182770 | 183725 | sqlite3_result_blob(context, p->hdr, |
| 182771 | 183726 | 4+8*p->nVertex, SQLITE_TRANSIENT); |
| 182772 | 183727 | sqlite3_free(p); |
| 182773 | 183728 | } |
| 182774 | 183729 | } |
| 183730 | + |
| 183731 | +/* |
| 183732 | +** Compute the area enclosed by the polygon. |
| 183733 | +** |
| 183734 | +** This routine can also be used to detect polygons that rotate in |
| 183735 | +** the wrong direction. Polygons are suppose to be counter-clockwise (CCW). |
| 183736 | +** This routine returns a negative value for clockwise (CW) polygons. |
| 183737 | +*/ |
| 183738 | +static double geopolyArea(GeoPoly *p){ |
| 183739 | + double rArea = 0.0; |
| 183740 | + int ii; |
| 183741 | + for(ii=0; ii<p->nVertex-1; ii++){ |
| 183742 | + rArea += (p->a[ii*2] - p->a[ii*2+2]) /* (x0 - x1) */ |
| 183743 | + * (p->a[ii*2+1] + p->a[ii*2+3]) /* (y0 + y1) */ |
| 183744 | + * 0.5; |
| 183745 | + } |
| 183746 | + rArea += (p->a[ii*2] - p->a[0]) /* (xN - x0) */ |
| 183747 | + * (p->a[ii*2+1] + p->a[1]) /* (yN + y0) */ |
| 183748 | + * 0.5; |
| 183749 | + return rArea; |
| 183750 | +} |
| 182775 | 183751 | |
| 182776 | 183752 | /* |
| 182777 | 183753 | ** Implementation of the geopoly_area(X) function. |
| 182778 | 183754 | ** |
| 182779 | 183755 | ** If the input is a well-formed Geopoly BLOB then return the area |
| | @@ -182786,24 +183762,109 @@ |
| 182786 | 183762 | int argc, |
| 182787 | 183763 | sqlite3_value **argv |
| 182788 | 183764 | ){ |
| 182789 | 183765 | GeoPoly *p = geopolyFuncParam(context, argv[0], 0); |
| 182790 | 183766 | if( p ){ |
| 182791 | | - double rArea = 0.0; |
| 182792 | | - int ii; |
| 182793 | | - for(ii=0; ii<p->nVertex-1; ii++){ |
| 182794 | | - rArea += (p->a[ii*2] - p->a[ii*2+2]) /* (x0 - x1) */ |
| 182795 | | - * (p->a[ii*2+1] + p->a[ii*2+3]) /* (y0 + y1) */ |
| 182796 | | - * 0.5; |
| 182797 | | - } |
| 182798 | | - rArea += (p->a[ii*2] - p->a[0]) /* (xN - x0) */ |
| 182799 | | - * (p->a[ii*2+1] + p->a[1]) /* (yN + y0) */ |
| 182800 | | - * 0.5; |
| 182801 | | - sqlite3_result_double(context, rArea); |
| 183767 | + sqlite3_result_double(context, geopolyArea(p)); |
| 183768 | + sqlite3_free(p); |
| 183769 | + } |
| 183770 | +} |
| 183771 | + |
| 183772 | +/* |
| 183773 | +** Implementation of the geopoly_ccw(X) function. |
| 183774 | +** |
| 183775 | +** If the rotation of polygon X is clockwise (incorrect) instead of |
| 183776 | +** counter-clockwise (the correct winding order according to RFC7946) |
| 183777 | +** then reverse the order of the vertexes in polygon X. |
| 183778 | +** |
| 183779 | +** In other words, this routine returns a CCW polygon regardless of the |
| 183780 | +** winding order of its input. |
| 183781 | +** |
| 183782 | +** Use this routine to sanitize historical inputs that that sometimes |
| 183783 | +** contain polygons that wind in the wrong direction. |
| 183784 | +*/ |
| 183785 | +static void geopolyCcwFunc( |
| 183786 | + sqlite3_context *context, |
| 183787 | + int argc, |
| 183788 | + sqlite3_value **argv |
| 183789 | +){ |
| 183790 | + GeoPoly *p = geopolyFuncParam(context, argv[0], 0); |
| 183791 | + if( p ){ |
| 183792 | + if( geopolyArea(p)<0.0 ){ |
| 183793 | + int ii, jj; |
| 183794 | + for(ii=2, jj=p->nVertex*2 - 4; ii<jj; ii+=2, jj-=2){ |
| 183795 | + GeoCoord t = p->a[ii]; |
| 183796 | + p->a[ii] = p->a[jj]; |
| 183797 | + p->a[jj] = t; |
| 183798 | + t = p->a[ii+1]; |
| 183799 | + p->a[ii+1] = p->a[jj+1]; |
| 183800 | + p->a[jj+1] = t; |
| 183801 | + } |
| 183802 | + } |
| 183803 | + sqlite3_result_blob(context, p->hdr, |
| 183804 | + 4+8*p->nVertex, SQLITE_TRANSIENT); |
| 182802 | 183805 | sqlite3_free(p); |
| 182803 | 183806 | } |
| 182804 | 183807 | } |
| 183808 | + |
| 183809 | +#define GEOPOLY_PI 3.1415926535897932385 |
| 183810 | + |
| 183811 | +/* Fast approximation for cosine(X) for X between -0.5*pi and 2*pi |
| 183812 | +*/ |
| 183813 | +static double geopolyCosine(double r){ |
| 183814 | + assert( r>=-0.5*GEOPOLY_PI && r<=2.0*GEOPOLY_PI ); |
| 183815 | + if( r>=1.5*GEOPOLY_PI ){ |
| 183816 | + r -= 2.0*GEOPOLY_PI; |
| 183817 | + } |
| 183818 | + if( r>=0.5*GEOPOLY_PI ){ |
| 183819 | + return -geopolyCosine(r-GEOPOLY_PI); |
| 183820 | + }else{ |
| 183821 | + double r2 = r*r; |
| 183822 | + double r3 = r2*r; |
| 183823 | + double r5 = r3*r2; |
| 183824 | + return 0.9996949*r - 0.1656700*r3 + 0.0075134*r5; |
| 183825 | + } |
| 183826 | +} |
| 183827 | + |
| 183828 | +/* |
| 183829 | +** Function: geopoly_regular(X,Y,R,N) |
| 183830 | +** |
| 183831 | +** Construct a simple, convex, regular polygon centered at X, Y |
| 183832 | +** with circumradius R and with N sides. |
| 183833 | +*/ |
| 183834 | +static void geopolyRegularFunc( |
| 183835 | + sqlite3_context *context, |
| 183836 | + int argc, |
| 183837 | + sqlite3_value **argv |
| 183838 | +){ |
| 183839 | + double x = sqlite3_value_double(argv[0]); |
| 183840 | + double y = sqlite3_value_double(argv[1]); |
| 183841 | + double r = sqlite3_value_double(argv[2]); |
| 183842 | + int n = sqlite3_value_int(argv[3]); |
| 183843 | + int i; |
| 183844 | + GeoPoly *p; |
| 183845 | + |
| 183846 | + if( n<3 || r<=0.0 ) return; |
| 183847 | + if( n>1000 ) n = 1000; |
| 183848 | + p = sqlite3_malloc64( sizeof(*p) + (n-1)*2*sizeof(GeoCoord) ); |
| 183849 | + if( p==0 ){ |
| 183850 | + sqlite3_result_error_nomem(context); |
| 183851 | + return; |
| 183852 | + } |
| 183853 | + i = 1; |
| 183854 | + p->hdr[0] = *(unsigned char*)&i; |
| 183855 | + p->hdr[1] = 0; |
| 183856 | + p->hdr[2] = (n>>8)&0xff; |
| 183857 | + p->hdr[3] = n&0xff; |
| 183858 | + for(i=0; i<n; i++){ |
| 183859 | + double rAngle = 2.0*GEOPOLY_PI*i/n; |
| 183860 | + p->a[i*2] = x - r*geopolyCosine(rAngle-0.5*GEOPOLY_PI); |
| 183861 | + p->a[i*2+1] = y + r*geopolyCosine(rAngle); |
| 183862 | + } |
| 183863 | + sqlite3_result_blob(context, p->hdr, 4+8*n, SQLITE_TRANSIENT); |
| 183864 | + sqlite3_free(p); |
| 183865 | +} |
| 182805 | 183866 | |
| 182806 | 183867 | /* |
| 182807 | 183868 | ** If pPoly is a polygon, compute its bounding box. Then: |
| 182808 | 183869 | ** |
| 182809 | 183870 | ** (1) if aCoord!=0 store the bounding box in aCoord, returning NULL |
| | @@ -182845,11 +183906,11 @@ |
| 182845 | 183906 | else if( r>mxY ) mxY = (float)r; |
| 182846 | 183907 | } |
| 182847 | 183908 | if( pRc ) *pRc = SQLITE_OK; |
| 182848 | 183909 | if( aCoord==0 ){ |
| 182849 | 183910 | geopolyBboxFill: |
| 182850 | | - pOut = sqlite3_realloc(p, sizeof(GeoPoly)+sizeof(GeoCoord)*6); |
| 183911 | + pOut = sqlite3_realloc(p, GEOPOLY_SZ(4)); |
| 182851 | 183912 | if( pOut==0 ){ |
| 182852 | 183913 | sqlite3_free(p); |
| 182853 | 183914 | if( context ) sqlite3_result_error_nomem(context); |
| 182854 | 183915 | if( pRc ) *pRc = SQLITE_NOMEM; |
| 182855 | 183916 | return 0; |
| | @@ -183873,11 +184934,20 @@ |
| 183873 | 184934 | sqlite3_bind_int64(pUp, 1, cell.iRowid); |
| 183874 | 184935 | assert( pRtree->nAux>=1 ); |
| 183875 | 184936 | if( sqlite3_value_nochange(aData[2]) ){ |
| 183876 | 184937 | sqlite3_bind_null(pUp, 2); |
| 183877 | 184938 | }else{ |
| 183878 | | - sqlite3_bind_value(pUp, 2, aData[2]); |
| 184939 | + GeoPoly *p = 0; |
| 184940 | + if( sqlite3_value_type(aData[2])==SQLITE_TEXT |
| 184941 | + && (p = geopolyFuncParam(0, aData[2], &rc))!=0 |
| 184942 | + && rc==SQLITE_OK |
| 184943 | + ){ |
| 184944 | + sqlite3_bind_blob(pUp, 2, p->hdr, 4+8*p->nVertex, SQLITE_TRANSIENT); |
| 184945 | + }else{ |
| 184946 | + sqlite3_bind_value(pUp, 2, aData[2]); |
| 184947 | + } |
| 184948 | + sqlite3_free(p); |
| 183879 | 184949 | nChange = 1; |
| 183880 | 184950 | } |
| 183881 | 184951 | for(jj=1; jj<pRtree->nAux; jj++){ |
| 183882 | 184952 | nChange++; |
| 183883 | 184953 | sqlite3_bind_value(pUp, jj+2, aData[jj+2]); |
| | @@ -183917,11 +184987,11 @@ |
| 183917 | 184987 | return 0; |
| 183918 | 184988 | } |
| 183919 | 184989 | |
| 183920 | 184990 | |
| 183921 | 184991 | static sqlite3_module geopolyModule = { |
| 183922 | | - 2, /* iVersion */ |
| 184992 | + 3, /* iVersion */ |
| 183923 | 184993 | geopolyCreate, /* xCreate - create a table */ |
| 183924 | 184994 | geopolyConnect, /* xConnect - connect to an existing table */ |
| 183925 | 184995 | geopolyBestIndex, /* xBestIndex - Determine search strategy */ |
| 183926 | 184996 | rtreeDisconnect, /* xDisconnect - Disconnect from a table */ |
| 183927 | 184997 | rtreeDestroy, /* xDestroy - Drop a table */ |
| | @@ -183940,29 +185010,33 @@ |
| 183940 | 185010 | geopolyFindFunction, /* xFindFunction - function overloading */ |
| 183941 | 185011 | rtreeRename, /* xRename - rename the table */ |
| 183942 | 185012 | rtreeSavepoint, /* xSavepoint */ |
| 183943 | 185013 | 0, /* xRelease */ |
| 183944 | 185014 | 0, /* xRollbackTo */ |
| 185015 | + rtreeShadowName /* xShadowName */ |
| 183945 | 185016 | }; |
| 183946 | 185017 | |
| 183947 | 185018 | static int sqlite3_geopoly_init(sqlite3 *db){ |
| 183948 | 185019 | int rc = SQLITE_OK; |
| 183949 | 185020 | static const struct { |
| 183950 | 185021 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**); |
| 183951 | | - int nArg; |
| 185022 | + signed char nArg; |
| 185023 | + unsigned char bPure; |
| 183952 | 185024 | const char *zName; |
| 183953 | 185025 | } aFunc[] = { |
| 183954 | | - { geopolyAreaFunc, 1, "geopoly_area" }, |
| 183955 | | - { geopolyBlobFunc, 1, "geopoly_blob" }, |
| 183956 | | - { geopolyJsonFunc, 1, "geopoly_json" }, |
| 183957 | | - { geopolySvgFunc, -1, "geopoly_svg" }, |
| 183958 | | - { geopolyWithinFunc, 2, "geopoly_within" }, |
| 183959 | | - { geopolyContainsPointFunc, 3, "geopoly_contains_point" }, |
| 183960 | | - { geopolyOverlapFunc, 2, "geopoly_overlap" }, |
| 183961 | | - { geopolyDebugFunc, 1, "geopoly_debug" }, |
| 183962 | | - { geopolyBBoxFunc, 1, "geopoly_bbox" }, |
| 183963 | | - { geopolyXformFunc, 7, "geopoly_xform" }, |
| 185026 | + { geopolyAreaFunc, 1, 1, "geopoly_area" }, |
| 185027 | + { geopolyBlobFunc, 1, 1, "geopoly_blob" }, |
| 185028 | + { geopolyJsonFunc, 1, 1, "geopoly_json" }, |
| 185029 | + { geopolySvgFunc, -1, 1, "geopoly_svg" }, |
| 185030 | + { geopolyWithinFunc, 2, 1, "geopoly_within" }, |
| 185031 | + { geopolyContainsPointFunc, 3, 1, "geopoly_contains_point" }, |
| 185032 | + { geopolyOverlapFunc, 2, 1, "geopoly_overlap" }, |
| 185033 | + { geopolyDebugFunc, 1, 0, "geopoly_debug" }, |
| 185034 | + { geopolyBBoxFunc, 1, 1, "geopoly_bbox" }, |
| 185035 | + { geopolyXformFunc, 7, 1, "geopoly_xform" }, |
| 185036 | + { geopolyRegularFunc, 4, 1, "geopoly_regular" }, |
| 185037 | + { geopolyCcwFunc, 1, 1, "geopoly_ccw" }, |
| 183964 | 185038 | }; |
| 183965 | 185039 | static const struct { |
| 183966 | 185040 | void (*xStep)(sqlite3_context*,int,sqlite3_value**); |
| 183967 | 185041 | void (*xFinal)(sqlite3_context*); |
| 183968 | 185042 | const char *zName; |
| | @@ -183969,12 +185043,13 @@ |
| 183969 | 185043 | } aAgg[] = { |
| 183970 | 185044 | { geopolyBBoxStep, geopolyBBoxFinal, "geopoly_group_bbox" }, |
| 183971 | 185045 | }; |
| 183972 | 185046 | int i; |
| 183973 | 185047 | for(i=0; i<sizeof(aFunc)/sizeof(aFunc[0]) && rc==SQLITE_OK; i++){ |
| 185048 | + int enc = aFunc[i].bPure ? SQLITE_UTF8|SQLITE_DETERMINISTIC : SQLITE_UTF8; |
| 183974 | 185049 | rc = sqlite3_create_function(db, aFunc[i].zName, aFunc[i].nArg, |
| 183975 | | - SQLITE_UTF8, 0, |
| 185050 | + enc, 0, |
| 183976 | 185051 | aFunc[i].xFunc, 0, 0); |
| 183977 | 185052 | } |
| 183978 | 185053 | for(i=0; i<sizeof(aAgg)/sizeof(aAgg[0]) && rc==SQLITE_OK; i++){ |
| 183979 | 185054 | rc = sqlite3_create_function(db, aAgg[i].zName, 1, SQLITE_UTF8, 0, |
| 183980 | 185055 | 0, aAgg[i].xStep, aAgg[i].xFinal); |
| | @@ -185997,11 +187072,12 @@ |
| 185997 | 187072 | struct rbu_vfs { |
| 185998 | 187073 | sqlite3_vfs base; /* rbu VFS shim methods */ |
| 185999 | 187074 | sqlite3_vfs *pRealVfs; /* Underlying VFS */ |
| 186000 | 187075 | sqlite3_mutex *mutex; /* Mutex to protect pMain */ |
| 186001 | 187076 | sqlite3rbu *pRbu; /* Owner RBU object */ |
| 186002 | | - rbu_file *pMain; /* Linked list of main db files */ |
| 187077 | + rbu_file *pMain; /* List of main db files */ |
| 187078 | + rbu_file *pMainRbu; /* List of main db files with pRbu!=0 */ |
| 186003 | 187079 | }; |
| 186004 | 187080 | |
| 186005 | 187081 | /* |
| 186006 | 187082 | ** Each file opened by an rbu VFS is represented by an instance of |
| 186007 | 187083 | ** the following structure. |
| | @@ -186026,10 +187102,11 @@ |
| 186026 | 187102 | char *zDel; /* Delete this when closing file */ |
| 186027 | 187103 | |
| 186028 | 187104 | const char *zWal; /* Wal filename for this main db file */ |
| 186029 | 187105 | rbu_file *pWalFd; /* Wal file descriptor for this main db */ |
| 186030 | 187106 | rbu_file *pMainNext; /* Next MAIN_DB file */ |
| 187107 | + rbu_file *pMainRbuNext; /* Next MAIN_DB file with pRbu!=0 */ |
| 186031 | 187108 | }; |
| 186032 | 187109 | |
| 186033 | 187110 | /* |
| 186034 | 187111 | ** True for an RBU vacuum handle, or false otherwise. |
| 186035 | 187112 | */ |
| | @@ -189621,10 +190698,73 @@ |
| 189621 | 190698 | pFd->sz = nNew; |
| 189622 | 190699 | assert( pRbu->szTemp>=0 ); |
| 189623 | 190700 | if( pRbu->szTempLimit && pRbu->szTemp>pRbu->szTempLimit ) return SQLITE_FULL; |
| 189624 | 190701 | return SQLITE_OK; |
| 189625 | 190702 | } |
| 190703 | + |
| 190704 | +/* |
| 190705 | +** Add an item to the main-db lists, if it is not already present. |
| 190706 | +** |
| 190707 | +** There are two main-db lists. One for all file descriptors, and one |
| 190708 | +** for all file descriptors with rbu_file.pDb!=0. If the argument has |
| 190709 | +** rbu_file.pDb!=0, then it is assumed to already be present on the |
| 190710 | +** main list and is only added to the pDb!=0 list. |
| 190711 | +*/ |
| 190712 | +static void rbuMainlistAdd(rbu_file *p){ |
| 190713 | + rbu_vfs *pRbuVfs = p->pRbuVfs; |
| 190714 | + rbu_file *pIter; |
| 190715 | + assert( (p->openFlags & SQLITE_OPEN_MAIN_DB) ); |
| 190716 | + sqlite3_mutex_enter(pRbuVfs->mutex); |
| 190717 | + if( p->pRbu==0 ){ |
| 190718 | + for(pIter=pRbuVfs->pMain; pIter; pIter=pIter->pMainNext); |
| 190719 | + p->pMainNext = pRbuVfs->pMain; |
| 190720 | + pRbuVfs->pMain = p; |
| 190721 | + }else{ |
| 190722 | + for(pIter=pRbuVfs->pMainRbu; pIter && pIter!=p; pIter=pIter->pMainRbuNext){} |
| 190723 | + if( pIter==0 ){ |
| 190724 | + p->pMainRbuNext = pRbuVfs->pMainRbu; |
| 190725 | + pRbuVfs->pMainRbu = p; |
| 190726 | + } |
| 190727 | + } |
| 190728 | + sqlite3_mutex_leave(pRbuVfs->mutex); |
| 190729 | +} |
| 190730 | + |
| 190731 | +/* |
| 190732 | +** Remove an item from the main-db lists. |
| 190733 | +*/ |
| 190734 | +static void rbuMainlistRemove(rbu_file *p){ |
| 190735 | + rbu_file **pp; |
| 190736 | + sqlite3_mutex_enter(p->pRbuVfs->mutex); |
| 190737 | + for(pp=&p->pRbuVfs->pMain; *pp && *pp!=p; pp=&((*pp)->pMainNext)){} |
| 190738 | + if( *pp ) *pp = p->pMainNext; |
| 190739 | + p->pMainNext = 0; |
| 190740 | + for(pp=&p->pRbuVfs->pMainRbu; *pp && *pp!=p; pp=&((*pp)->pMainRbuNext)){} |
| 190741 | + if( *pp ) *pp = p->pMainRbuNext; |
| 190742 | + p->pMainRbuNext = 0; |
| 190743 | + sqlite3_mutex_leave(p->pRbuVfs->mutex); |
| 190744 | +} |
| 190745 | + |
| 190746 | +/* |
| 190747 | +** Given that zWal points to a buffer containing a wal file name passed to |
| 190748 | +** either the xOpen() or xAccess() VFS method, search the main-db list for |
| 190749 | +** a file-handle opened by the same database connection on the corresponding |
| 190750 | +** database file. |
| 190751 | +** |
| 190752 | +** If parameter bRbu is true, only search for file-descriptors with |
| 190753 | +** rbu_file.pDb!=0. |
| 190754 | +*/ |
| 190755 | +static rbu_file *rbuFindMaindb(rbu_vfs *pRbuVfs, const char *zWal, int bRbu){ |
| 190756 | + rbu_file *pDb; |
| 190757 | + sqlite3_mutex_enter(pRbuVfs->mutex); |
| 190758 | + if( bRbu ){ |
| 190759 | + for(pDb=pRbuVfs->pMainRbu; pDb && pDb->zWal!=zWal; pDb=pDb->pMainRbuNext){} |
| 190760 | + }else{ |
| 190761 | + for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){} |
| 190762 | + } |
| 190763 | + sqlite3_mutex_leave(pRbuVfs->mutex); |
| 190764 | + return pDb; |
| 190765 | +} |
| 189626 | 190766 | |
| 189627 | 190767 | /* |
| 189628 | 190768 | ** Close an rbu file. |
| 189629 | 190769 | */ |
| 189630 | 190770 | static int rbuVfsClose(sqlite3_file *pFile){ |
| | @@ -189639,21 +190779,18 @@ |
| 189639 | 190779 | sqlite3_free(p->apShm); |
| 189640 | 190780 | p->apShm = 0; |
| 189641 | 190781 | sqlite3_free(p->zDel); |
| 189642 | 190782 | |
| 189643 | 190783 | if( p->openFlags & SQLITE_OPEN_MAIN_DB ){ |
| 189644 | | - rbu_file **pp; |
| 189645 | | - sqlite3_mutex_enter(p->pRbuVfs->mutex); |
| 189646 | | - for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext)); |
| 189647 | | - *pp = p->pMainNext; |
| 189648 | | - sqlite3_mutex_leave(p->pRbuVfs->mutex); |
| 190784 | + rbuMainlistRemove(p); |
| 189649 | 190785 | rbuUnlockShm(p); |
| 189650 | 190786 | p->pReal->pMethods->xShmUnmap(p->pReal, 0); |
| 189651 | 190787 | } |
| 189652 | 190788 | else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){ |
| 189653 | 190789 | rbuUpdateTempSize(p, 0); |
| 189654 | 190790 | } |
| 190791 | + assert( p->pMainNext==0 && p->pRbuVfs->pMain!=p ); |
| 189655 | 190792 | |
| 189656 | 190793 | /* Close the underlying file handle */ |
| 189657 | 190794 | rc = p->pReal->pMethods->xClose(p->pReal); |
| 189658 | 190795 | return rc; |
| 189659 | 190796 | } |
| | @@ -189908,10 +191045,13 @@ |
| 189908 | 191045 | rc = SQLITE_ERROR; |
| 189909 | 191046 | pRbu->zErrmsg = sqlite3_mprintf("rbu/zipvfs setup error"); |
| 189910 | 191047 | }else if( rc==SQLITE_NOTFOUND ){ |
| 189911 | 191048 | pRbu->pTargetFd = p; |
| 189912 | 191049 | p->pRbu = pRbu; |
| 191050 | + if( p->openFlags & SQLITE_OPEN_MAIN_DB ){ |
| 191051 | + rbuMainlistAdd(p); |
| 191052 | + } |
| 189913 | 191053 | if( p->pWalFd ) p->pWalFd->pRbu = pRbu; |
| 189914 | 191054 | rc = SQLITE_OK; |
| 189915 | 191055 | } |
| 189916 | 191056 | } |
| 189917 | 191057 | return rc; |
| | @@ -190069,24 +191209,10 @@ |
| 190069 | 191209 | rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag); |
| 190070 | 191210 | } |
| 190071 | 191211 | return rc; |
| 190072 | 191212 | } |
| 190073 | 191213 | |
| 190074 | | -/* |
| 190075 | | -** Given that zWal points to a buffer containing a wal file name passed to |
| 190076 | | -** either the xOpen() or xAccess() VFS method, return a pointer to the |
| 190077 | | -** file-handle opened by the same database connection on the corresponding |
| 190078 | | -** database file. |
| 190079 | | -*/ |
| 190080 | | -static rbu_file *rbuFindMaindb(rbu_vfs *pRbuVfs, const char *zWal){ |
| 190081 | | - rbu_file *pDb; |
| 190082 | | - sqlite3_mutex_enter(pRbuVfs->mutex); |
| 190083 | | - for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){} |
| 190084 | | - sqlite3_mutex_leave(pRbuVfs->mutex); |
| 190085 | | - return pDb; |
| 190086 | | -} |
| 190087 | | - |
| 190088 | 191214 | /* |
| 190089 | 191215 | ** A main database named zName has just been opened. The following |
| 190090 | 191216 | ** function returns a pointer to a buffer owned by SQLite that contains |
| 190091 | 191217 | ** the name of the *-wal file this db connection will use. SQLite |
| 190092 | 191218 | ** happens to pass a pointer to this buffer when using xAccess() |
| | @@ -190161,11 +191287,11 @@ |
| 190161 | 191287 | ** happens to pass a pointer to this buffer when using xAccess() |
| 190162 | 191288 | ** or xOpen() to operate on the *-wal file. */ |
| 190163 | 191289 | pFd->zWal = rbuMainToWal(zName, flags); |
| 190164 | 191290 | } |
| 190165 | 191291 | else if( flags & SQLITE_OPEN_WAL ){ |
| 190166 | | - rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName); |
| 191292 | + rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0); |
| 190167 | 191293 | if( pDb ){ |
| 190168 | 191294 | if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ |
| 190169 | 191295 | /* This call is to open a *-wal file. Intead, open the *-oal. This |
| 190170 | 191296 | ** code ensures that the string passed to xOpen() is terminated by a |
| 190171 | 191297 | ** pair of '\0' bytes in case the VFS attempts to extract a URI |
| | @@ -190213,14 +191339,11 @@ |
| 190213 | 191339 | /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods |
| 190214 | 191340 | ** pointer and, if the file is a main database file, link it into the |
| 190215 | 191341 | ** mutex protected linked list of all such files. */ |
| 190216 | 191342 | pFile->pMethods = &rbuvfs_io_methods; |
| 190217 | 191343 | if( flags & SQLITE_OPEN_MAIN_DB ){ |
| 190218 | | - sqlite3_mutex_enter(pRbuVfs->mutex); |
| 190219 | | - pFd->pMainNext = pRbuVfs->pMain; |
| 190220 | | - pRbuVfs->pMain = pFd; |
| 190221 | | - sqlite3_mutex_leave(pRbuVfs->mutex); |
| 191344 | + rbuMainlistAdd(pFd); |
| 190222 | 191345 | } |
| 190223 | 191346 | }else{ |
| 190224 | 191347 | sqlite3_free(pFd->zDel); |
| 190225 | 191348 | } |
| 190226 | 191349 | |
| | @@ -190264,11 +191387,11 @@ |
| 190264 | 191387 | ** causing SQLite to call xOpen() to open it. This call will also |
| 190265 | 191388 | ** be intercepted (see the rbuVfsOpen() function) and the *-oal |
| 190266 | 191389 | ** file opened instead. |
| 190267 | 191390 | */ |
| 190268 | 191391 | if( rc==SQLITE_OK && flags==SQLITE_ACCESS_EXISTS ){ |
| 190269 | | - rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath); |
| 191392 | + rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath, 1); |
| 190270 | 191393 | if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ |
| 190271 | 191394 | if( *pResOut ){ |
| 190272 | 191395 | rc = SQLITE_CANTOPEN; |
| 190273 | 191396 | }else{ |
| 190274 | 191397 | sqlite3_int64 sz = 0; |
| | @@ -190737,18 +191860,24 @@ |
| 190737 | 191860 | |
| 190738 | 191861 | *ppCursor = (sqlite3_vtab_cursor *)pCsr; |
| 190739 | 191862 | return SQLITE_OK; |
| 190740 | 191863 | } |
| 190741 | 191864 | |
| 190742 | | -static void statClearPage(StatPage *p){ |
| 191865 | +static void statClearCells(StatPage *p){ |
| 190743 | 191866 | int i; |
| 190744 | 191867 | if( p->aCell ){ |
| 190745 | 191868 | for(i=0; i<p->nCell; i++){ |
| 190746 | 191869 | sqlite3_free(p->aCell[i].aOvfl); |
| 190747 | 191870 | } |
| 190748 | 191871 | sqlite3_free(p->aCell); |
| 190749 | 191872 | } |
| 191873 | + p->nCell = 0; |
| 191874 | + p->aCell = 0; |
| 191875 | +} |
| 191876 | + |
| 191877 | +static void statClearPage(StatPage *p){ |
| 191878 | + statClearCells(p); |
| 190750 | 191879 | sqlite3PagerUnref(p->pPg); |
| 190751 | 191880 | sqlite3_free(p->zPath); |
| 190752 | 191881 | memset(p, 0, sizeof(StatPage)); |
| 190753 | 191882 | } |
| 190754 | 191883 | |
| | @@ -190807,26 +191936,37 @@ |
| 190807 | 191936 | |
| 190808 | 191937 | u8 *aData = sqlite3PagerGetData(p->pPg); |
| 190809 | 191938 | u8 *aHdr = &aData[p->iPgno==1 ? 100 : 0]; |
| 190810 | 191939 | |
| 190811 | 191940 | p->flags = aHdr[0]; |
| 191941 | + if( p->flags==0x0A || p->flags==0x0D ){ |
| 191942 | + isLeaf = 1; |
| 191943 | + nHdr = 8; |
| 191944 | + }else if( p->flags==0x05 || p->flags==0x02 ){ |
| 191945 | + isLeaf = 0; |
| 191946 | + nHdr = 12; |
| 191947 | + }else{ |
| 191948 | + goto statPageIsCorrupt; |
| 191949 | + } |
| 191950 | + if( p->iPgno==1 ) nHdr += 100; |
| 190812 | 191951 | p->nCell = get2byte(&aHdr[3]); |
| 190813 | 191952 | p->nMxPayload = 0; |
| 190814 | | - |
| 190815 | | - isLeaf = (p->flags==0x0A || p->flags==0x0D); |
| 190816 | | - nHdr = 12 - isLeaf*4 + (p->iPgno==1)*100; |
| 191953 | + szPage = sqlite3BtreeGetPageSize(pBt); |
| 190817 | 191954 | |
| 190818 | 191955 | nUnused = get2byte(&aHdr[5]) - nHdr - 2*p->nCell; |
| 190819 | 191956 | nUnused += (int)aHdr[7]; |
| 190820 | 191957 | iOff = get2byte(&aHdr[1]); |
| 190821 | 191958 | while( iOff ){ |
| 191959 | + int iNext; |
| 191960 | + if( iOff>=szPage ) goto statPageIsCorrupt; |
| 190822 | 191961 | nUnused += get2byte(&aData[iOff+2]); |
| 190823 | | - iOff = get2byte(&aData[iOff]); |
| 191962 | + iNext = get2byte(&aData[iOff]); |
| 191963 | + if( iNext<iOff+4 && iNext>0 ) goto statPageIsCorrupt; |
| 191964 | + iOff = iNext; |
| 190824 | 191965 | } |
| 190825 | 191966 | p->nUnused = nUnused; |
| 190826 | 191967 | p->iRightChildPg = isLeaf ? 0 : sqlite3Get4byte(&aHdr[8]); |
| 190827 | | - szPage = sqlite3BtreeGetPageSize(pBt); |
| 190828 | 191968 | |
| 190829 | 191969 | if( p->nCell ){ |
| 190830 | 191970 | int i; /* Used to iterate through cells */ |
| 190831 | 191971 | int nUsable; /* Usable bytes per page */ |
| 190832 | 191972 | |
| | @@ -190839,10 +191979,11 @@ |
| 190839 | 191979 | |
| 190840 | 191980 | for(i=0; i<p->nCell; i++){ |
| 190841 | 191981 | StatCell *pCell = &p->aCell[i]; |
| 190842 | 191982 | |
| 190843 | 191983 | iOff = get2byte(&aData[nHdr+i*2]); |
| 191984 | + if( iOff<nHdr || iOff>=szPage ) goto statPageIsCorrupt; |
| 190844 | 191985 | if( !isLeaf ){ |
| 190845 | 191986 | pCell->iChildPg = sqlite3Get4byte(&aData[iOff]); |
| 190846 | 191987 | iOff += 4; |
| 190847 | 191988 | } |
| 190848 | 191989 | if( p->flags==0x05 ){ |
| | @@ -190855,12 +191996,12 @@ |
| 190855 | 191996 | u64 dummy; |
| 190856 | 191997 | iOff += sqlite3GetVarint(&aData[iOff], &dummy); |
| 190857 | 191998 | } |
| 190858 | 191999 | if( nPayload>(u32)p->nMxPayload ) p->nMxPayload = nPayload; |
| 190859 | 192000 | getLocalPayload(nUsable, p->flags, nPayload, &nLocal); |
| 192001 | + if( nLocal<0 ) goto statPageIsCorrupt; |
| 190860 | 192002 | pCell->nLocal = nLocal; |
| 190861 | | - assert( nLocal>=0 ); |
| 190862 | 192003 | assert( nPayload>=(u32)nLocal ); |
| 190863 | 192004 | assert( nLocal<=(nUsable-35) ); |
| 190864 | 192005 | if( nPayload>(u32)nLocal ){ |
| 190865 | 192006 | int j; |
| 190866 | 192007 | int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4); |
| | @@ -190885,10 +192026,15 @@ |
| 190885 | 192026 | } |
| 190886 | 192027 | } |
| 190887 | 192028 | } |
| 190888 | 192029 | |
| 190889 | 192030 | return SQLITE_OK; |
| 192031 | + |
| 192032 | +statPageIsCorrupt: |
| 192033 | + p->flags = 0; |
| 192034 | + statClearCells(p); |
| 192035 | + return SQLITE_OK; |
| 190890 | 192036 | } |
| 190891 | 192037 | |
| 190892 | 192038 | /* |
| 190893 | 192039 | ** Populate the pCsr->iOffset and pCsr->szPage member variables. Based on |
| 190894 | 192040 | ** the current value of pCsr->iPageno. |
| | @@ -191180,10 +192326,11 @@ |
| 191180 | 192326 | 0, /* xFindMethod */ |
| 191181 | 192327 | 0, /* xRename */ |
| 191182 | 192328 | 0, /* xSavepoint */ |
| 191183 | 192329 | 0, /* xRelease */ |
| 191184 | 192330 | 0, /* xRollbackTo */ |
| 192331 | + 0 /* xShadowName */ |
| 191185 | 192332 | }; |
| 191186 | 192333 | return sqlite3_create_module(db, "dbstat", &dbstat_module, 0); |
| 191187 | 192334 | } |
| 191188 | 192335 | #elif defined(SQLITE_ENABLE_DBSTAT_VTAB) |
| 191189 | 192336 | SQLITE_PRIVATE int sqlite3DbstatRegister(sqlite3 *db){ return SQLITE_OK; } |
| | @@ -191504,10 +192651,14 @@ |
| 191504 | 192651 | int iDb; |
| 191505 | 192652 | Btree *pBt; |
| 191506 | 192653 | Pager *pPager; |
| 191507 | 192654 | int szPage; |
| 191508 | 192655 | |
| 192656 | + if( pTab->db->flags & SQLITE_Defensive ){ |
| 192657 | + zErr = "read-only"; |
| 192658 | + goto update_fail; |
| 192659 | + } |
| 191509 | 192660 | if( argc==1 ){ |
| 191510 | 192661 | zErr = "cannot delete"; |
| 191511 | 192662 | goto update_fail; |
| 191512 | 192663 | } |
| 191513 | 192664 | pgno = sqlite3_value_int(argv[0]); |
| | @@ -191594,10 +192745,11 @@ |
| 191594 | 192745 | 0, /* xFindMethod */ |
| 191595 | 192746 | 0, /* xRename */ |
| 191596 | 192747 | 0, /* xSavepoint */ |
| 191597 | 192748 | 0, /* xRelease */ |
| 191598 | 192749 | 0, /* xRollbackTo */ |
| 192750 | + 0 /* xShadowName */ |
| 191599 | 192751 | }; |
| 191600 | 192752 | return sqlite3_create_module(db, "sqlite_dbpage", &dbpage_module, 0); |
| 191601 | 192753 | } |
| 191602 | 192754 | #elif defined(SQLITE_ENABLE_DBPAGE_VTAB) |
| 191603 | 192755 | SQLITE_PRIVATE int sqlite3DbpageRegister(sqlite3 *db){ return SQLITE_OK; } |
| | @@ -191629,10 +192781,12 @@ |
| 191629 | 192781 | # define SESSIONS_STRM_CHUNK_SIZE 64 |
| 191630 | 192782 | # else |
| 191631 | 192783 | # define SESSIONS_STRM_CHUNK_SIZE 1024 |
| 191632 | 192784 | # endif |
| 191633 | 192785 | #endif |
| 192786 | + |
| 192787 | +static int sessions_strm_chunk_size = SESSIONS_STRM_CHUNK_SIZE; |
| 191634 | 192788 | |
| 191635 | 192789 | typedef struct SessionHook SessionHook; |
| 191636 | 192790 | struct SessionHook { |
| 191637 | 192791 | void *pCtx; |
| 191638 | 192792 | int (*xOld)(void*,int,sqlite3_value**); |
| | @@ -191692,10 +192846,11 @@ |
| 191692 | 192846 | */ |
| 191693 | 192847 | struct sqlite3_changeset_iter { |
| 191694 | 192848 | SessionInput in; /* Input buffer or stream */ |
| 191695 | 192849 | SessionBuffer tblhdr; /* Buffer to hold apValue/zTab/abPK/ */ |
| 191696 | 192850 | int bPatchset; /* True if this is a patchset */ |
| 192851 | + int bInvert; /* True to invert changeset */ |
| 191697 | 192852 | int rc; /* Iterator error code */ |
| 191698 | 192853 | sqlite3_stmt *pConflict; /* Points to conflicting row, if any */ |
| 191699 | 192854 | char *zTab; /* Current table */ |
| 191700 | 192855 | int nCol; /* Number of columns in zTab */ |
| 191701 | 192856 | int op; /* Current operation */ |
| | @@ -191848,10 +193003,46 @@ |
| 191848 | 193003 | ** and fields associated with modified columns contain the new column values. |
| 191849 | 193004 | ** |
| 191850 | 193005 | ** The records associated with INSERT changes are in the same format as for |
| 191851 | 193006 | ** changesets. It is not possible for a record associated with an INSERT |
| 191852 | 193007 | ** change to contain a field set to "undefined". |
| 193008 | +** |
| 193009 | +** REBASE BLOB FORMAT: |
| 193010 | +** |
| 193011 | +** A rebase blob may be output by sqlite3changeset_apply_v2() and its |
| 193012 | +** streaming equivalent for use with the sqlite3_rebaser APIs to rebase |
| 193013 | +** existing changesets. A rebase blob contains one entry for each conflict |
| 193014 | +** resolved using either the OMIT or REPLACE strategies within the apply_v2() |
| 193015 | +** call. |
| 193016 | +** |
| 193017 | +** The format used for a rebase blob is very similar to that used for |
| 193018 | +** changesets. All entries related to a single table are grouped together. |
| 193019 | +** |
| 193020 | +** Each group of entries begins with a table header in changeset format: |
| 193021 | +** |
| 193022 | +** 1 byte: Constant 0x54 (capital 'T') |
| 193023 | +** Varint: Number of columns in the table. |
| 193024 | +** nCol bytes: 0x01 for PK columns, 0x00 otherwise. |
| 193025 | +** N bytes: Unqualified table name (encoded using UTF-8). Nul-terminated. |
| 193026 | +** |
| 193027 | +** Followed by one or more entries associated with the table. |
| 193028 | +** |
| 193029 | +** 1 byte: Either SQLITE_INSERT (0x12), DELETE (0x09). |
| 193030 | +** 1 byte: Flag. 0x01 for REPLACE, 0x00 for OMIT. |
| 193031 | +** record: (in the record format defined above). |
| 193032 | +** |
| 193033 | +** In a rebase blob, the first field is set to SQLITE_INSERT if the change |
| 193034 | +** that caused the conflict was an INSERT or UPDATE, or to SQLITE_DELETE if |
| 193035 | +** it was a DELETE. The second field is set to 0x01 if the conflict |
| 193036 | +** resolution strategy was REPLACE, or 0x00 if it was OMIT. |
| 193037 | +** |
| 193038 | +** If the change that caused the conflict was a DELETE, then the single |
| 193039 | +** record is a copy of the old.* record from the original changeset. If it |
| 193040 | +** was an INSERT, then the single record is a copy of the new.* record. If |
| 193041 | +** the conflicting change was an UPDATE, then the single record is a copy |
| 193042 | +** of the new.* record with the PK fields filled in based on the original |
| 193043 | +** old.* record. |
| 191853 | 193044 | */ |
| 191854 | 193045 | |
| 191855 | 193046 | /* |
| 191856 | 193047 | ** For each row modified during a session, there exists a single instance of |
| 191857 | 193048 | ** this structure stored in a SessionTable.aChange[] hash table. |
| | @@ -193398,16 +194589,16 @@ |
| 193398 | 194589 | ** set *pRc to SQLITE_NOMEM and return non-zero. |
| 193399 | 194590 | */ |
| 193400 | 194591 | static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){ |
| 193401 | 194592 | if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){ |
| 193402 | 194593 | u8 *aNew; |
| 193403 | | - int nNew = p->nAlloc ? p->nAlloc : 128; |
| 194594 | + i64 nNew = p->nAlloc ? p->nAlloc : 128; |
| 193404 | 194595 | do { |
| 193405 | 194596 | nNew = nNew*2; |
| 193406 | | - }while( nNew<(p->nBuf+nByte) ); |
| 194597 | + }while( (nNew-p->nBuf)<nByte ); |
| 193407 | 194598 | |
| 193408 | | - aNew = (u8 *)sqlite3_realloc(p->aBuf, nNew); |
| 194599 | + aNew = (u8 *)sqlite3_realloc64(p->aBuf, nNew); |
| 193409 | 194600 | if( 0==aNew ){ |
| 193410 | 194601 | *pRc = SQLITE_NOMEM; |
| 193411 | 194602 | }else{ |
| 193412 | 194603 | p->aBuf = aNew; |
| 193413 | 194604 | p->nAlloc = nNew; |
| | @@ -194001,16 +195192,16 @@ |
| 194001 | 195192 | } |
| 194002 | 195193 | if( rc==SQLITE_OK ){ |
| 194003 | 195194 | rc = sqlite3_reset(pSel); |
| 194004 | 195195 | } |
| 194005 | 195196 | |
| 194006 | | - /* If the buffer is now larger than SESSIONS_STRM_CHUNK_SIZE, pass |
| 195197 | + /* If the buffer is now larger than sessions_strm_chunk_size, pass |
| 194007 | 195198 | ** its contents to the xOutput() callback. */ |
| 194008 | 195199 | if( xOutput |
| 194009 | 195200 | && rc==SQLITE_OK |
| 194010 | 195201 | && buf.nBuf>nNoop |
| 194011 | | - && buf.nBuf>SESSIONS_STRM_CHUNK_SIZE |
| 195202 | + && buf.nBuf>sessions_strm_chunk_size |
| 194012 | 195203 | ){ |
| 194013 | 195204 | rc = xOutput(pOut, (void*)buf.aBuf, buf.nBuf); |
| 194014 | 195205 | nNoop = -1; |
| 194015 | 195206 | buf.nBuf = 0; |
| 194016 | 195207 | } |
| | @@ -194145,11 +195336,12 @@ |
| 194145 | 195336 | static int sessionChangesetStart( |
| 194146 | 195337 | sqlite3_changeset_iter **pp, /* OUT: Changeset iterator handle */ |
| 194147 | 195338 | int (*xInput)(void *pIn, void *pData, int *pnData), |
| 194148 | 195339 | void *pIn, |
| 194149 | 195340 | int nChangeset, /* Size of buffer pChangeset in bytes */ |
| 194150 | | - void *pChangeset /* Pointer to buffer containing changeset */ |
| 195341 | + void *pChangeset, /* Pointer to buffer containing changeset */ |
| 195342 | + int bInvert /* True to invert changeset */ |
| 194151 | 195343 | ){ |
| 194152 | 195344 | sqlite3_changeset_iter *pRet; /* Iterator to return */ |
| 194153 | 195345 | int nByte; /* Number of bytes to allocate for iterator */ |
| 194154 | 195346 | |
| 194155 | 195347 | assert( xInput==0 || (pChangeset==0 && nChangeset==0) ); |
| | @@ -194165,10 +195357,11 @@ |
| 194165 | 195357 | pRet->in.aData = (u8 *)pChangeset; |
| 194166 | 195358 | pRet->in.nData = nChangeset; |
| 194167 | 195359 | pRet->in.xInput = xInput; |
| 194168 | 195360 | pRet->in.pIn = pIn; |
| 194169 | 195361 | pRet->in.bEof = (xInput ? 0 : 1); |
| 195362 | + pRet->bInvert = bInvert; |
| 194170 | 195363 | |
| 194171 | 195364 | /* Populate the output variable and return success. */ |
| 194172 | 195365 | *pp = pRet; |
| 194173 | 195366 | return SQLITE_OK; |
| 194174 | 195367 | } |
| | @@ -194179,11 +195372,20 @@ |
| 194179 | 195372 | SQLITE_API int sqlite3changeset_start( |
| 194180 | 195373 | sqlite3_changeset_iter **pp, /* OUT: Changeset iterator handle */ |
| 194181 | 195374 | int nChangeset, /* Size of buffer pChangeset in bytes */ |
| 194182 | 195375 | void *pChangeset /* Pointer to buffer containing changeset */ |
| 194183 | 195376 | ){ |
| 194184 | | - return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset); |
| 195377 | + return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, 0); |
| 195378 | +} |
| 195379 | +SQLITE_API int sqlite3changeset_start_v2( |
| 195380 | + sqlite3_changeset_iter **pp, /* OUT: Changeset iterator handle */ |
| 195381 | + int nChangeset, /* Size of buffer pChangeset in bytes */ |
| 195382 | + void *pChangeset, /* Pointer to buffer containing changeset */ |
| 195383 | + int flags |
| 195384 | +){ |
| 195385 | + int bInvert = !!(flags & SQLITE_CHANGESETSTART_INVERT); |
| 195386 | + return sessionChangesetStart(pp, 0, 0, nChangeset, pChangeset, bInvert); |
| 194185 | 195387 | } |
| 194186 | 195388 | |
| 194187 | 195389 | /* |
| 194188 | 195390 | ** Streaming version of sqlite3changeset_start(). |
| 194189 | 195391 | */ |
| | @@ -194190,19 +195392,28 @@ |
| 194190 | 195392 | SQLITE_API int sqlite3changeset_start_strm( |
| 194191 | 195393 | sqlite3_changeset_iter **pp, /* OUT: Changeset iterator handle */ |
| 194192 | 195394 | int (*xInput)(void *pIn, void *pData, int *pnData), |
| 194193 | 195395 | void *pIn |
| 194194 | 195396 | ){ |
| 194195 | | - return sessionChangesetStart(pp, xInput, pIn, 0, 0); |
| 195397 | + return sessionChangesetStart(pp, xInput, pIn, 0, 0, 0); |
| 195398 | +} |
| 195399 | +SQLITE_API int sqlite3changeset_start_v2_strm( |
| 195400 | + sqlite3_changeset_iter **pp, /* OUT: Changeset iterator handle */ |
| 195401 | + int (*xInput)(void *pIn, void *pData, int *pnData), |
| 195402 | + void *pIn, |
| 195403 | + int flags |
| 195404 | +){ |
| 195405 | + int bInvert = !!(flags & SQLITE_CHANGESETSTART_INVERT); |
| 195406 | + return sessionChangesetStart(pp, xInput, pIn, 0, 0, bInvert); |
| 194196 | 195407 | } |
| 194197 | 195408 | |
| 194198 | 195409 | /* |
| 194199 | 195410 | ** If the SessionInput object passed as the only argument is a streaming |
| 194200 | 195411 | ** object and the buffer is full, discard some data to free up space. |
| 194201 | 195412 | */ |
| 194202 | 195413 | static void sessionDiscardData(SessionInput *pIn){ |
| 194203 | | - if( pIn->xInput && pIn->iNext>=SESSIONS_STRM_CHUNK_SIZE ){ |
| 195414 | + if( pIn->xInput && pIn->iNext>=sessions_strm_chunk_size ){ |
| 194204 | 195415 | int nMove = pIn->buf.nBuf - pIn->iNext; |
| 194205 | 195416 | assert( nMove>=0 ); |
| 194206 | 195417 | if( nMove>0 ){ |
| 194207 | 195418 | memmove(pIn->buf.aBuf, &pIn->buf.aBuf[pIn->iNext], nMove); |
| 194208 | 195419 | } |
| | @@ -194221,11 +195432,11 @@ |
| 194221 | 195432 | */ |
| 194222 | 195433 | static int sessionInputBuffer(SessionInput *pIn, int nByte){ |
| 194223 | 195434 | int rc = SQLITE_OK; |
| 194224 | 195435 | if( pIn->xInput ){ |
| 194225 | 195436 | while( !pIn->bEof && (pIn->iNext+nByte)>=pIn->nData && rc==SQLITE_OK ){ |
| 194226 | | - int nNew = SESSIONS_STRM_CHUNK_SIZE; |
| 195437 | + int nNew = sessions_strm_chunk_size; |
| 194227 | 195438 | |
| 194228 | 195439 | if( pIn->bNoDiscard==0 ) sessionDiscardData(pIn); |
| 194229 | 195440 | if( SQLITE_OK==sessionBufferGrow(&pIn->buf, nNew, &rc) ){ |
| 194230 | 195441 | rc = pIn->xInput(pIn->pIn, &pIn->buf.aBuf[pIn->buf.nBuf], &nNew); |
| 194231 | 195442 | if( nNew==0 ){ |
| | @@ -194569,14 +195780,14 @@ |
| 194569 | 195780 | p->in.iCurrent = p->in.iNext; |
| 194570 | 195781 | if( p->in.iNext>=p->in.nData ) return SQLITE_DONE; |
| 194571 | 195782 | op = p->in.aData[p->in.iNext++]; |
| 194572 | 195783 | } |
| 194573 | 195784 | |
| 194574 | | - if( p->zTab==0 ){ |
| 195785 | + if( p->zTab==0 || (p->bPatchset && p->bInvert) ){ |
| 194575 | 195786 | /* The first record in the changeset is not a table header. Must be a |
| 194576 | 195787 | ** corrupt changeset. */ |
| 194577 | | - assert( p->in.iNext==1 ); |
| 195788 | + assert( p->in.iNext==1 || p->zTab ); |
| 194578 | 195789 | return (p->rc = SQLITE_CORRUPT_BKPT); |
| 194579 | 195790 | } |
| 194580 | 195791 | |
| 194581 | 195792 | p->op = op; |
| 194582 | 195793 | p->bIndirect = p->in.aData[p->in.iNext++]; |
| | @@ -194597,37 +195808,43 @@ |
| 194597 | 195808 | p->rc = sessionChangesetBufferRecord(&p->in, nVal, pnRec); |
| 194598 | 195809 | if( p->rc!=SQLITE_OK ) return p->rc; |
| 194599 | 195810 | *paRec = &p->in.aData[p->in.iNext]; |
| 194600 | 195811 | p->in.iNext += *pnRec; |
| 194601 | 195812 | }else{ |
| 195813 | + sqlite3_value **apOld = (p->bInvert ? &p->apValue[p->nCol] : p->apValue); |
| 195814 | + sqlite3_value **apNew = (p->bInvert ? p->apValue : &p->apValue[p->nCol]); |
| 194602 | 195815 | |
| 194603 | 195816 | /* If this is an UPDATE or DELETE, read the old.* record. */ |
| 194604 | 195817 | if( p->op!=SQLITE_INSERT && (p->bPatchset==0 || p->op==SQLITE_DELETE) ){ |
| 194605 | 195818 | u8 *abPK = p->bPatchset ? p->abPK : 0; |
| 194606 | | - p->rc = sessionReadRecord(&p->in, p->nCol, abPK, p->apValue); |
| 195819 | + p->rc = sessionReadRecord(&p->in, p->nCol, abPK, apOld); |
| 194607 | 195820 | if( p->rc!=SQLITE_OK ) return p->rc; |
| 194608 | 195821 | } |
| 194609 | 195822 | |
| 194610 | 195823 | /* If this is an INSERT or UPDATE, read the new.* record. */ |
| 194611 | 195824 | if( p->op!=SQLITE_DELETE ){ |
| 194612 | | - p->rc = sessionReadRecord(&p->in, p->nCol, 0, &p->apValue[p->nCol]); |
| 195825 | + p->rc = sessionReadRecord(&p->in, p->nCol, 0, apNew); |
| 194613 | 195826 | if( p->rc!=SQLITE_OK ) return p->rc; |
| 194614 | 195827 | } |
| 194615 | 195828 | |
| 194616 | | - if( p->bPatchset && p->op==SQLITE_UPDATE ){ |
| 195829 | + if( (p->bPatchset || p->bInvert) && p->op==SQLITE_UPDATE ){ |
| 194617 | 195830 | /* If this is an UPDATE that is part of a patchset, then all PK and |
| 194618 | 195831 | ** modified fields are present in the new.* record. The old.* record |
| 194619 | 195832 | ** is currently completely empty. This block shifts the PK fields from |
| 194620 | 195833 | ** new.* to old.*, to accommodate the code that reads these arrays. */ |
| 194621 | 195834 | for(i=0; i<p->nCol; i++){ |
| 194622 | | - assert( p->apValue[i]==0 ); |
| 195835 | + assert( p->bPatchset==0 || p->apValue[i]==0 ); |
| 194623 | 195836 | if( p->abPK[i] ){ |
| 195837 | + assert( p->apValue[i]==0 ); |
| 194624 | 195838 | p->apValue[i] = p->apValue[i+p->nCol]; |
| 194625 | 195839 | if( p->apValue[i]==0 ) return (p->rc = SQLITE_CORRUPT_BKPT); |
| 194626 | 195840 | p->apValue[i+p->nCol] = 0; |
| 194627 | 195841 | } |
| 194628 | 195842 | } |
| 195843 | + }else if( p->bInvert ){ |
| 195844 | + if( p->op==SQLITE_INSERT ) p->op = SQLITE_DELETE; |
| 195845 | + else if( p->op==SQLITE_DELETE ) p->op = SQLITE_INSERT; |
| 194629 | 195846 | } |
| 194630 | 195847 | } |
| 194631 | 195848 | |
| 194632 | 195849 | return SQLITE_ROW; |
| 194633 | 195850 | } |
| | @@ -194940,11 +196157,11 @@ |
| 194940 | 196157 | rc = SQLITE_CORRUPT_BKPT; |
| 194941 | 196158 | goto finished_invert; |
| 194942 | 196159 | } |
| 194943 | 196160 | |
| 194944 | 196161 | assert( rc==SQLITE_OK ); |
| 194945 | | - if( xOutput && sOut.nBuf>=SESSIONS_STRM_CHUNK_SIZE ){ |
| 196162 | + if( xOutput && sOut.nBuf>=sessions_strm_chunk_size ){ |
| 194946 | 196163 | rc = xOutput(pOut, sOut.aBuf, sOut.nBuf); |
| 194947 | 196164 | sOut.nBuf = 0; |
| 194948 | 196165 | if( rc!=SQLITE_OK ) goto finished_invert; |
| 194949 | 196166 | } |
| 194950 | 196167 | } |
| | @@ -195019,11 +196236,12 @@ |
| 195019 | 196236 | u8 *abPK; /* Boolean array - true if column is in PK */ |
| 195020 | 196237 | int bStat1; /* True if table is sqlite_stat1 */ |
| 195021 | 196238 | int bDeferConstraints; /* True to defer constraints */ |
| 195022 | 196239 | SessionBuffer constraints; /* Deferred constraints are stored here */ |
| 195023 | 196240 | SessionBuffer rebase; /* Rebase information (if any) here */ |
| 195024 | | - int bRebaseStarted; /* If table header is already in rebase */ |
| 196241 | + u8 bRebaseStarted; /* If table header is already in rebase */ |
| 196242 | + u8 bRebase; /* True to collect rebase information */ |
| 195025 | 196243 | }; |
| 195026 | 196244 | |
| 195027 | 196245 | /* |
| 195028 | 196246 | ** Formulate a statement to DELETE a row from database db. Assuming a table |
| 195029 | 196247 | ** structure like this: |
| | @@ -195416,39 +196634,40 @@ |
| 195416 | 196634 | SessionApplyCtx *p, /* Apply context */ |
| 195417 | 196635 | int eType, /* Conflict resolution (OMIT or REPLACE) */ |
| 195418 | 196636 | sqlite3_changeset_iter *pIter /* Iterator pointing at current change */ |
| 195419 | 196637 | ){ |
| 195420 | 196638 | int rc = SQLITE_OK; |
| 195421 | | - int i; |
| 195422 | | - int eOp = pIter->op; |
| 195423 | | - if( p->bRebaseStarted==0 ){ |
| 195424 | | - /* Append a table-header to the rebase buffer */ |
| 195425 | | - const char *zTab = pIter->zTab; |
| 195426 | | - sessionAppendByte(&p->rebase, 'T', &rc); |
| 195427 | | - sessionAppendVarint(&p->rebase, p->nCol, &rc); |
| 195428 | | - sessionAppendBlob(&p->rebase, p->abPK, p->nCol, &rc); |
| 195429 | | - sessionAppendBlob(&p->rebase, (u8*)zTab, (int)strlen(zTab)+1, &rc); |
| 195430 | | - p->bRebaseStarted = 1; |
| 195431 | | - } |
| 195432 | | - |
| 195433 | | - assert( eType==SQLITE_CHANGESET_REPLACE||eType==SQLITE_CHANGESET_OMIT ); |
| 195434 | | - assert( eOp==SQLITE_DELETE || eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE ); |
| 195435 | | - |
| 195436 | | - sessionAppendByte(&p->rebase, |
| 195437 | | - (eOp==SQLITE_DELETE ? SQLITE_DELETE : SQLITE_INSERT), &rc |
| 195438 | | - ); |
| 195439 | | - sessionAppendByte(&p->rebase, (eType==SQLITE_CHANGESET_REPLACE), &rc); |
| 195440 | | - for(i=0; i<p->nCol; i++){ |
| 195441 | | - sqlite3_value *pVal = 0; |
| 195442 | | - if( eOp==SQLITE_DELETE || (eOp==SQLITE_UPDATE && p->abPK[i]) ){ |
| 195443 | | - sqlite3changeset_old(pIter, i, &pVal); |
| 195444 | | - }else{ |
| 195445 | | - sqlite3changeset_new(pIter, i, &pVal); |
| 195446 | | - } |
| 195447 | | - sessionAppendValue(&p->rebase, pVal, &rc); |
| 195448 | | - } |
| 195449 | | - |
| 196639 | + if( p->bRebase ){ |
| 196640 | + int i; |
| 196641 | + int eOp = pIter->op; |
| 196642 | + if( p->bRebaseStarted==0 ){ |
| 196643 | + /* Append a table-header to the rebase buffer */ |
| 196644 | + const char *zTab = pIter->zTab; |
| 196645 | + sessionAppendByte(&p->rebase, 'T', &rc); |
| 196646 | + sessionAppendVarint(&p->rebase, p->nCol, &rc); |
| 196647 | + sessionAppendBlob(&p->rebase, p->abPK, p->nCol, &rc); |
| 196648 | + sessionAppendBlob(&p->rebase, (u8*)zTab, (int)strlen(zTab)+1, &rc); |
| 196649 | + p->bRebaseStarted = 1; |
| 196650 | + } |
| 196651 | + |
| 196652 | + assert( eType==SQLITE_CHANGESET_REPLACE||eType==SQLITE_CHANGESET_OMIT ); |
| 196653 | + assert( eOp==SQLITE_DELETE || eOp==SQLITE_INSERT || eOp==SQLITE_UPDATE ); |
| 196654 | + |
| 196655 | + sessionAppendByte(&p->rebase, |
| 196656 | + (eOp==SQLITE_DELETE ? SQLITE_DELETE : SQLITE_INSERT), &rc |
| 196657 | + ); |
| 196658 | + sessionAppendByte(&p->rebase, (eType==SQLITE_CHANGESET_REPLACE), &rc); |
| 196659 | + for(i=0; i<p->nCol; i++){ |
| 196660 | + sqlite3_value *pVal = 0; |
| 196661 | + if( eOp==SQLITE_DELETE || (eOp==SQLITE_UPDATE && p->abPK[i]) ){ |
| 196662 | + sqlite3changeset_old(pIter, i, &pVal); |
| 196663 | + }else{ |
| 196664 | + sqlite3changeset_new(pIter, i, &pVal); |
| 196665 | + } |
| 196666 | + sessionAppendValue(&p->rebase, pVal, &rc); |
| 196667 | + } |
| 196668 | + } |
| 195450 | 196669 | return rc; |
| 195451 | 196670 | } |
| 195452 | 196671 | |
| 195453 | 196672 | /* |
| 195454 | 196673 | ** Invoke the conflict handler for the change that the changeset iterator |
| | @@ -195787,11 +197006,11 @@ |
| 195787 | 197006 | while( pApply->constraints.nBuf ){ |
| 195788 | 197007 | sqlite3_changeset_iter *pIter2 = 0; |
| 195789 | 197008 | SessionBuffer cons = pApply->constraints; |
| 195790 | 197009 | memset(&pApply->constraints, 0, sizeof(SessionBuffer)); |
| 195791 | 197010 | |
| 195792 | | - rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf); |
| 197011 | + rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0); |
| 195793 | 197012 | if( rc==SQLITE_OK ){ |
| 195794 | 197013 | int nByte = 2*pApply->nCol*sizeof(sqlite3_value*); |
| 195795 | 197014 | int rc2; |
| 195796 | 197015 | pIter2->bPatchset = bPatchset; |
| 195797 | 197016 | pIter2->zTab = (char*)zTab; |
| | @@ -195853,10 +197072,11 @@ |
| 195853 | 197072 | |
| 195854 | 197073 | assert( xConflict!=0 ); |
| 195855 | 197074 | |
| 195856 | 197075 | pIter->in.bNoDiscard = 1; |
| 195857 | 197076 | memset(&sApply, 0, sizeof(sApply)); |
| 197077 | + sApply.bRebase = (ppRebase && pnRebase); |
| 195858 | 197078 | sqlite3_mutex_enter(sqlite3_db_mutex(db)); |
| 195859 | 197079 | if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){ |
| 195860 | 197080 | rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0); |
| 195861 | 197081 | } |
| 195862 | 197082 | if( rc==SQLITE_OK ){ |
| | @@ -196003,11 +197223,12 @@ |
| 196003 | 197223 | sqlite3_exec(db, "ROLLBACK TO changeset_apply", 0, 0, 0); |
| 196004 | 197224 | sqlite3_exec(db, "RELEASE changeset_apply", 0, 0, 0); |
| 196005 | 197225 | } |
| 196006 | 197226 | } |
| 196007 | 197227 | |
| 196008 | | - if( rc==SQLITE_OK && bPatchset==0 && ppRebase && pnRebase ){ |
| 197228 | + assert( sApply.bRebase || sApply.rebase.nBuf==0 ); |
| 197229 | + if( rc==SQLITE_OK && bPatchset==0 && sApply.bRebase ){ |
| 196009 | 197230 | *ppRebase = (void*)sApply.rebase.aBuf; |
| 196010 | 197231 | *pnRebase = sApply.rebase.nBuf; |
| 196011 | 197232 | sApply.rebase.aBuf = 0; |
| 196012 | 197233 | } |
| 196013 | 197234 | sqlite3_finalize(sApply.pInsert); |
| | @@ -196041,11 +197262,12 @@ |
| 196041 | 197262 | void *pCtx, /* First argument passed to xConflict */ |
| 196042 | 197263 | void **ppRebase, int *pnRebase, |
| 196043 | 197264 | int flags |
| 196044 | 197265 | ){ |
| 196045 | 197266 | sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */ |
| 196046 | | - int rc = sqlite3changeset_start(&pIter, nChangeset, pChangeset); |
| 197267 | + int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT); |
| 197268 | + int rc = sessionChangesetStart(&pIter, 0, 0, nChangeset, pChangeset,bInverse); |
| 196047 | 197269 | if( rc==SQLITE_OK ){ |
| 196048 | 197270 | rc = sessionChangesetApply( |
| 196049 | 197271 | db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags |
| 196050 | 197272 | ); |
| 196051 | 197273 | } |
| | @@ -196098,11 +197320,12 @@ |
| 196098 | 197320 | void *pCtx, /* First argument passed to xConflict */ |
| 196099 | 197321 | void **ppRebase, int *pnRebase, |
| 196100 | 197322 | int flags |
| 196101 | 197323 | ){ |
| 196102 | 197324 | sqlite3_changeset_iter *pIter; /* Iterator to skip through changeset */ |
| 196103 | | - int rc = sqlite3changeset_start_strm(&pIter, xInput, pIn); |
| 197325 | + int bInverse = !!(flags & SQLITE_CHANGESETAPPLY_INVERT); |
| 197326 | + int rc = sessionChangesetStart(&pIter, xInput, pIn, 0, 0, bInverse); |
| 196104 | 197327 | if( rc==SQLITE_OK ){ |
| 196105 | 197328 | rc = sessionChangesetApply( |
| 196106 | 197329 | db, pIter, xFilter, xConflict, pCtx, ppRebase, pnRebase, flags |
| 196107 | 197330 | ); |
| 196108 | 197331 | } |
| | @@ -196471,17 +197694,16 @@ |
| 196471 | 197694 | SessionChange *p; |
| 196472 | 197695 | for(p=pTab->apChange[i]; p; p=p->pNext){ |
| 196473 | 197696 | sessionAppendByte(&buf, p->op, &rc); |
| 196474 | 197697 | sessionAppendByte(&buf, p->bIndirect, &rc); |
| 196475 | 197698 | sessionAppendBlob(&buf, p->aRecord, p->nRecord, &rc); |
| 197699 | + if( rc==SQLITE_OK && xOutput && buf.nBuf>=sessions_strm_chunk_size ){ |
| 197700 | + rc = xOutput(pOut, buf.aBuf, buf.nBuf); |
| 197701 | + buf.nBuf = 0; |
| 197702 | + } |
| 196476 | 197703 | } |
| 196477 | 197704 | } |
| 196478 | | - |
| 196479 | | - if( rc==SQLITE_OK && xOutput && buf.nBuf>=SESSIONS_STRM_CHUNK_SIZE ){ |
| 196480 | | - rc = xOutput(pOut, buf.aBuf, buf.nBuf); |
| 196481 | | - buf.nBuf = 0; |
| 196482 | | - } |
| 196483 | 197705 | } |
| 196484 | 197706 | |
| 196485 | 197707 | if( rc==SQLITE_OK ){ |
| 196486 | 197708 | if( xOutput ){ |
| 196487 | 197709 | if( buf.nBuf>0 ) rc = xOutput(pOut, buf.aBuf, buf.nBuf); |
| | @@ -196868,11 +198090,11 @@ |
| 196868 | 198090 | if( bDone==0 ){ |
| 196869 | 198091 | sessionAppendByte(&sOut, pIter->op, &rc); |
| 196870 | 198092 | sessionAppendByte(&sOut, pIter->bIndirect, &rc); |
| 196871 | 198093 | sessionAppendBlob(&sOut, aRec, nRec, &rc); |
| 196872 | 198094 | } |
| 196873 | | - if( rc==SQLITE_OK && xOutput && sOut.nBuf>SESSIONS_STRM_CHUNK_SIZE ){ |
| 198095 | + if( rc==SQLITE_OK && xOutput && sOut.nBuf>sessions_strm_chunk_size ){ |
| 196874 | 198096 | rc = xOutput(pOut, sOut.aBuf, sOut.nBuf); |
| 196875 | 198097 | sOut.nBuf = 0; |
| 196876 | 198098 | } |
| 196877 | 198099 | if( rc ) break; |
| 196878 | 198100 | } |
| | @@ -196978,10 +198200,31 @@ |
| 196978 | 198200 | if( p ){ |
| 196979 | 198201 | sessionDeleteTable(p->grp.pList); |
| 196980 | 198202 | sqlite3_free(p); |
| 196981 | 198203 | } |
| 196982 | 198204 | } |
| 198205 | + |
| 198206 | +/* |
| 198207 | +** Global configuration |
| 198208 | +*/ |
| 198209 | +SQLITE_API int sqlite3session_config(int op, void *pArg){ |
| 198210 | + int rc = SQLITE_OK; |
| 198211 | + switch( op ){ |
| 198212 | + case SQLITE_SESSION_CONFIG_STRMSIZE: { |
| 198213 | + int *pInt = (int*)pArg; |
| 198214 | + if( *pInt>0 ){ |
| 198215 | + sessions_strm_chunk_size = *pInt; |
| 198216 | + } |
| 198217 | + *pInt = sessions_strm_chunk_size; |
| 198218 | + break; |
| 198219 | + } |
| 198220 | + default: |
| 198221 | + rc = SQLITE_MISUSE; |
| 198222 | + break; |
| 198223 | + } |
| 198224 | + return rc; |
| 198225 | +} |
| 196983 | 198226 | |
| 196984 | 198227 | #endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 196985 | 198228 | |
| 196986 | 198229 | /************** End of sqlite3session.c **************************************/ |
| 196987 | 198230 | /************** Begin file fts5.c ********************************************/ |
| | @@ -210693,11 +211936,11 @@ |
| 210693 | 211936 | sqlite3Fts5IterClose((Fts5IndexIter*)pRet); |
| 210694 | 211937 | pRet = 0; |
| 210695 | 211938 | fts5CloseReader(p); |
| 210696 | 211939 | } |
| 210697 | 211940 | |
| 210698 | | - *ppIter = &pRet->base; |
| 211941 | + *ppIter = (Fts5IndexIter*)pRet; |
| 210699 | 211942 | sqlite3Fts5BufferFree(&buf); |
| 210700 | 211943 | } |
| 210701 | 211944 | return fts5IndexReturn(p); |
| 210702 | 211945 | } |
| 210703 | 211946 | |
| | @@ -214442,16 +215685,31 @@ |
| 214442 | 215685 | int nArg, /* Number of args */ |
| 214443 | 215686 | sqlite3_value **apUnused /* Function arguments */ |
| 214444 | 215687 | ){ |
| 214445 | 215688 | assert( nArg==0 ); |
| 214446 | 215689 | UNUSED_PARAM2(nArg, apUnused); |
| 214447 | | - sqlite3_result_text(pCtx, "fts5: 2018-09-25 19:08:10 fb90e7189ae6d62e77ba3a308ca5d683f90bbe633cf681865365b8e92792d1c7", -1, SQLITE_TRANSIENT); |
| 215690 | + sqlite3_result_text(pCtx, "fts5: 2018-11-12 15:20:44 f9755f81b1c0fd29f242dce78a2fba570fa2714d76e93b8563f426a040352513", -1, SQLITE_TRANSIENT); |
| 215691 | +} |
| 215692 | + |
| 215693 | +/* |
| 215694 | +** Return true if zName is the extension on one of the shadow tables used |
| 215695 | +** by this module. |
| 215696 | +*/ |
| 215697 | +static int fts5ShadowName(const char *zName){ |
| 215698 | + static const char *azName[] = { |
| 215699 | + "config", "content", "data", "docsize", "idx" |
| 215700 | + }; |
| 215701 | + unsigned int i; |
| 215702 | + for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){ |
| 215703 | + if( sqlite3_stricmp(zName, azName[i])==0 ) return 1; |
| 215704 | + } |
| 215705 | + return 0; |
| 214448 | 215706 | } |
| 214449 | 215707 | |
| 214450 | 215708 | static int fts5Init(sqlite3 *db){ |
| 214451 | 215709 | static const sqlite3_module fts5Mod = { |
| 214452 | | - /* iVersion */ 2, |
| 215710 | + /* iVersion */ 3, |
| 214453 | 215711 | /* xCreate */ fts5CreateMethod, |
| 214454 | 215712 | /* xConnect */ fts5ConnectMethod, |
| 214455 | 215713 | /* xBestIndex */ fts5BestIndexMethod, |
| 214456 | 215714 | /* xDisconnect */ fts5DisconnectMethod, |
| 214457 | 215715 | /* xDestroy */ fts5DestroyMethod, |
| | @@ -214470,10 +215728,11 @@ |
| 214470 | 215728 | /* xFindFunction */ fts5FindFunctionMethod, |
| 214471 | 215729 | /* xRename */ fts5RenameMethod, |
| 214472 | 215730 | /* xSavepoint */ fts5SavepointMethod, |
| 214473 | 215731 | /* xRelease */ fts5ReleaseMethod, |
| 214474 | 215732 | /* xRollbackTo */ fts5RollbackToMethod, |
| 215733 | + /* xShadowName */ fts5ShadowName |
| 214475 | 215734 | }; |
| 214476 | 215735 | |
| 214477 | 215736 | int rc; |
| 214478 | 215737 | Fts5Global *pGlobal = 0; |
| 214479 | 215738 | |
| | @@ -218514,20 +219773,22 @@ |
| 218514 | 219773 | int rc = SQLITE_OK; |
| 218515 | 219774 | Fts5IndexIter *pIter = pCsr->pIter; |
| 218516 | 219775 | i64 *pp = &pCsr->iInstPos; |
| 218517 | 219776 | int *po = &pCsr->iInstOff; |
| 218518 | 219777 | |
| 219778 | + assert( sqlite3Fts5IterEof(pIter)==0 ); |
| 219779 | + assert( pCsr->bEof==0 ); |
| 218519 | 219780 | while( eDetail==FTS5_DETAIL_NONE |
| 218520 | 219781 | || sqlite3Fts5PoslistNext64(pIter->pData, pIter->nData, po, pp) |
| 218521 | 219782 | ){ |
| 218522 | 219783 | pCsr->iInstPos = 0; |
| 218523 | 219784 | pCsr->iInstOff = 0; |
| 218524 | 219785 | |
| 218525 | 219786 | rc = sqlite3Fts5IterNextScan(pCsr->pIter); |
| 218526 | 219787 | if( rc==SQLITE_OK ){ |
| 218527 | 219788 | rc = fts5VocabInstanceNewTerm(pCsr); |
| 218528 | | - if( eDetail==FTS5_DETAIL_NONE ) break; |
| 219789 | + if( pCsr->bEof || eDetail==FTS5_DETAIL_NONE ) break; |
| 218529 | 219790 | } |
| 218530 | 219791 | if( rc ){ |
| 218531 | 219792 | pCsr->bEof = 1; |
| 218532 | 219793 | break; |
| 218533 | 219794 | } |
| | @@ -218838,17 +220099,16 @@ |
| 218838 | 220099 | /* xFindFunction */ 0, |
| 218839 | 220100 | /* xRename */ 0, |
| 218840 | 220101 | /* xSavepoint */ 0, |
| 218841 | 220102 | /* xRelease */ 0, |
| 218842 | 220103 | /* xRollbackTo */ 0, |
| 220104 | + /* xShadowName */ 0 |
| 218843 | 220105 | }; |
| 218844 | 220106 | void *p = (void*)pGlobal; |
| 218845 | 220107 | |
| 218846 | 220108 | return sqlite3_create_module_v2(db, "fts5vocab", &fts5Vocab, p, 0); |
| 218847 | 220109 | } |
| 218848 | | - |
| 218849 | | - |
| 218850 | 220110 | |
| 218851 | 220111 | |
| 218852 | 220112 | |
| 218853 | 220113 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS5) */ |
| 218854 | 220114 | |
| | @@ -219120,10 +220380,11 @@ |
| 219120 | 220380 | 0, /* xFindMethod */ |
| 219121 | 220381 | 0, /* xRename */ |
| 219122 | 220382 | 0, /* xSavepoint */ |
| 219123 | 220383 | 0, /* xRelease */ |
| 219124 | 220384 | 0, /* xRollbackTo */ |
| 220385 | + 0, /* xShadowName */ |
| 219125 | 220386 | }; |
| 219126 | 220387 | |
| 219127 | 220388 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 219128 | 220389 | |
| 219129 | 220390 | SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3 *db){ |
| | @@ -219152,12 +220413,12 @@ |
| 219152 | 220413 | } |
| 219153 | 220414 | #endif /* SQLITE_CORE */ |
| 219154 | 220415 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 219155 | 220416 | |
| 219156 | 220417 | /************** End of stmt.c ************************************************/ |
| 219157 | | -#if __LINE__!=219157 |
| 220418 | +#if __LINE__!=220418 |
| 219158 | 220419 | #undef SQLITE_SOURCE_ID |
| 219159 | | -#define SQLITE_SOURCE_ID "2018-09-25 19:08:10 fb90e7189ae6d62e77ba3a308ca5d683f90bbe633cf681865365b8e92792alt2" |
| 220420 | +#define SQLITE_SOURCE_ID "2018-11-12 15:20:44 f9755f81b1c0fd29f242dce78a2fba570fa2714d76e93b8563f426a04035alt2" |
| 219160 | 220421 | #endif |
| 219161 | 220422 | /* Return the source-id for this library */ |
| 219162 | 220423 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 219163 | 220424 | /************************** End of sqlite3.c ******************************/ |
| 219164 | 220425 | |