| | @@ -38,10 +38,37 @@ |
| 38 | 38 | ** |
| 39 | 39 | */ |
| 40 | 40 | #ifndef _SQLITEINT_H_ |
| 41 | 41 | #define _SQLITEINT_H_ |
| 42 | 42 | |
| 43 | +/* Special Comments: |
| 44 | +** |
| 45 | +** Some comments have special meaning to the tools that measure test |
| 46 | +** coverage: |
| 47 | +** |
| 48 | +** NO_TEST - The branches on this line are not |
| 49 | +** measured by branch coverage. This is |
| 50 | +** used on lines of code that actually |
| 51 | +** implement parts of coverage testing. |
| 52 | +** |
| 53 | +** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false |
| 54 | +** and the correct answer is still obtained, |
| 55 | +** though perhaps more slowly. |
| 56 | +** |
| 57 | +** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true |
| 58 | +** and the correct answer is still obtained, |
| 59 | +** though perhaps more slowly. |
| 60 | +** |
| 61 | +** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread |
| 62 | +** that would be harmless and undetectable |
| 63 | +** if it did occur. |
| 64 | +** |
| 65 | +** In all cases, the special comment must be enclosed in the usual |
| 66 | +** slash-asterisk...asterisk-slash comment marks, with no spaces between the |
| 67 | +** asterisks and the comment text. |
| 68 | +*/ |
| 69 | + |
| 43 | 70 | /* |
| 44 | 71 | ** Make sure that rand_s() is available on Windows systems with MSVC 2005 |
| 45 | 72 | ** or higher. |
| 46 | 73 | */ |
| 47 | 74 | #if defined(_MSC_VER) && _MSC_VER>=1400 |
| | @@ -336,11 +363,11 @@ |
| 336 | 363 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 337 | 364 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 338 | 365 | */ |
| 339 | 366 | #define SQLITE_VERSION "3.13.0" |
| 340 | 367 | #define SQLITE_VERSION_NUMBER 3013000 |
| 341 | | -#define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802" |
| 368 | +#define SQLITE_SOURCE_ID "2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2" |
| 342 | 369 | |
| 343 | 370 | /* |
| 344 | 371 | ** CAPI3REF: Run-Time Library Version Numbers |
| 345 | 372 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 346 | 373 | ** |
| | @@ -2155,16 +2182,34 @@ |
| 2155 | 2182 | ** The second parameter is a pointer to an integer into which |
| 2156 | 2183 | ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled |
| 2157 | 2184 | ** following this call. The second parameter may be a NULL pointer, in |
| 2158 | 2185 | ** which case the new setting is not reported back. </dd> |
| 2159 | 2186 | ** |
| 2187 | +** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt> |
| 2188 | +** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()] |
| 2189 | +** interface independently of the [load_extension()] SQL function. |
| 2190 | +** The [sqlite3_enable_load_extension()] API enables or disables both the |
| 2191 | +** C-API [sqlite3_load_extension()] and the SQL function [load_extension()]. |
| 2192 | +** There should be two additional arguments. |
| 2193 | +** When the first argument to this interface is 1, then only the C-API is |
| 2194 | +** enabled and the SQL function remains disabled. If the first argment to |
| 2195 | +** this interface is 0, then both the C-API and the SQL function are disabled. |
| 2196 | +** If the first argument is -1, then no changes are made to state of either the |
| 2197 | +** C-API or the SQL function. |
| 2198 | +** The second parameter is a pointer to an integer into which |
| 2199 | +** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface |
| 2200 | +** is disabled or enabled following this call. The second parameter may |
| 2201 | +** be a NULL pointer, in which case the new setting is not reported back. |
| 2202 | +** </dd> |
| 2203 | +** |
| 2160 | 2204 | ** </dl> |
| 2161 | 2205 | */ |
| 2162 | 2206 | #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */ |
| 2163 | 2207 | #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */ |
| 2164 | 2208 | #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */ |
| 2165 | 2209 | #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */ |
| 2210 | +#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */ |
| 2166 | 2211 | |
| 2167 | 2212 | |
| 2168 | 2213 | /* |
| 2169 | 2214 | ** CAPI3REF: Enable Or Disable Extended Result Codes |
| 2170 | 2215 | ** METHOD: sqlite3 |
| | @@ -5697,12 +5742,21 @@ |
| 5697 | 5742 | ** fill *pzErrMsg with error message text stored in memory |
| 5698 | 5743 | ** obtained from [sqlite3_malloc()]. The calling function |
| 5699 | 5744 | ** should free this memory by calling [sqlite3_free()]. |
| 5700 | 5745 | ** |
| 5701 | 5746 | ** ^Extension loading must be enabled using |
| 5702 | | -** [sqlite3_enable_load_extension()] prior to calling this API, |
| 5747 | +** [sqlite3_enable_load_extension()] or |
| 5748 | +** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL) |
| 5749 | +** prior to calling this API, |
| 5703 | 5750 | ** otherwise an error will be returned. |
| 5751 | +** |
| 5752 | +** <b>Security warning:</b> It is recommended that the |
| 5753 | +** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this |
| 5754 | +** interface. The use of the [sqlite3_enable_load_extension()] interface |
| 5755 | +** should be avoided. This will keep the SQL function [load_extension()] |
| 5756 | +** disabled and prevent SQL injections from giving attackers |
| 5757 | +** access to extension loading capabilities. |
| 5704 | 5758 | ** |
| 5705 | 5759 | ** See also the [load_extension() SQL function]. |
| 5706 | 5760 | */ |
| 5707 | 5761 | SQLITE_API int SQLITE_STDCALL sqlite3_load_extension( |
| 5708 | 5762 | sqlite3 *db, /* Load the extension into this database connection */ |
| | @@ -5722,10 +5776,21 @@ |
| 5722 | 5776 | ** |
| 5723 | 5777 | ** ^Extension loading is off by default. |
| 5724 | 5778 | ** ^Call the sqlite3_enable_load_extension() routine with onoff==1 |
| 5725 | 5779 | ** to turn extension loading on and call it with onoff==0 to turn |
| 5726 | 5780 | ** it back off again. |
| 5781 | +** |
| 5782 | +** ^This interface enables or disables both the C-API |
| 5783 | +** [sqlite3_load_extension()] and the SQL function [load_extension()]. |
| 5784 | +** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..) |
| 5785 | +** to enable or disable only the C-API. |
| 5786 | +** |
| 5787 | +** <b>Security warning:</b> It is recommended that extension loading |
| 5788 | +** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method |
| 5789 | +** rather than this interface, so the [load_extension()] SQL function |
| 5790 | +** remains disabled. This will prevent SQL injections from giving attackers |
| 5791 | +** access to extension loading capabilities. |
| 5727 | 5792 | */ |
| 5728 | 5793 | SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff); |
| 5729 | 5794 | |
| 5730 | 5795 | /* |
| 5731 | 5796 | ** CAPI3REF: Automatically Load Statically Linked Extensions |
| | @@ -8304,24 +8369,33 @@ |
| 8304 | 8369 | |
| 8305 | 8370 | /* |
| 8306 | 8371 | ** CAPI3REF: Start a read transaction on an historical snapshot |
| 8307 | 8372 | ** EXPERIMENTAL |
| 8308 | 8373 | ** |
| 8309 | | -** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the |
| 8310 | | -** read transaction that is currently open on schema S of |
| 8311 | | -** [database connection] D so that it refers to historical [snapshot] P. |
| 8374 | +** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a |
| 8375 | +** read transaction for schema S of |
| 8376 | +** [database connection] D such that the read transaction |
| 8377 | +** refers to historical [snapshot] P, rather than the most |
| 8378 | +** recent change to the database. |
| 8312 | 8379 | ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success |
| 8313 | 8380 | ** or an appropriate [error code] if it fails. |
| 8314 | 8381 | ** |
| 8315 | 8382 | ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be |
| 8316 | | -** the first operation, apart from other sqlite3_snapshot_open() calls, |
| 8317 | | -** following the [BEGIN] that starts a new read transaction. |
| 8318 | | -** ^A [snapshot] will fail to open if it has been overwritten by a |
| 8383 | +** the first operation following the [BEGIN] that takes the schema S |
| 8384 | +** out of [autocommit mode]. |
| 8385 | +** ^In other words, schema S must not currently be in |
| 8386 | +** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the |
| 8387 | +** database connection D must be out of [autocommit mode]. |
| 8388 | +** ^A [snapshot] will fail to open if it has been overwritten by a |
| 8319 | 8389 | ** [checkpoint]. |
| 8320 | | -** ^A [snapshot] will fail to open if the database connection D has not |
| 8321 | | -** previously completed at least one read operation against the database |
| 8322 | | -** file. (Hint: Run "[PRAGMA application_id]" against a newly opened |
| 8390 | +** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the |
| 8391 | +** database connection D does not know that the database file for |
| 8392 | +** schema S is in [WAL mode]. A database connection might not know |
| 8393 | +** that the database file is in [WAL mode] if there has been no prior |
| 8394 | +** I/O on that database connection, or if the database entered [WAL mode] |
| 8395 | +** after the most recent I/O on the database connection.)^ |
| 8396 | +** (Hint: Run "[PRAGMA application_id]" against a newly opened |
| 8323 | 8397 | ** database connection in order to make it ready to use snapshots.) |
| 8324 | 8398 | ** |
| 8325 | 8399 | ** The [sqlite3_snapshot_open()] interface is only available when the |
| 8326 | 8400 | ** SQLITE_ENABLE_SNAPSHOT compile-time option is used. |
| 8327 | 8401 | */ |
| | @@ -8341,10 +8415,37 @@ |
| 8341 | 8415 | ** |
| 8342 | 8416 | ** The [sqlite3_snapshot_free()] interface is only available when the |
| 8343 | 8417 | ** SQLITE_ENABLE_SNAPSHOT compile-time option is used. |
| 8344 | 8418 | */ |
| 8345 | 8419 | SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*); |
| 8420 | + |
| 8421 | +/* |
| 8422 | +** CAPI3REF: Compare the ages of two snapshot handles. |
| 8423 | +** EXPERIMENTAL |
| 8424 | +** |
| 8425 | +** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages |
| 8426 | +** of two valid snapshot handles. |
| 8427 | +** |
| 8428 | +** If the two snapshot handles are not associated with the same database |
| 8429 | +** file, the result of the comparison is undefined. |
| 8430 | +** |
| 8431 | +** Additionally, the result of the comparison is only valid if both of the |
| 8432 | +** snapshot handles were obtained by calling sqlite3_snapshot_get() since the |
| 8433 | +** last time the wal file was deleted. The wal file is deleted when the |
| 8434 | +** database is changed back to rollback mode or when the number of database |
| 8435 | +** clients drops to zero. If either snapshot handle was obtained before the |
| 8436 | +** wal file was last deleted, the value returned by this function |
| 8437 | +** is undefined. |
| 8438 | +** |
| 8439 | +** Otherwise, this API returns a negative value if P1 refers to an older |
| 8440 | +** snapshot than P2, zero if the two handles refer to the same database |
| 8441 | +** snapshot, and a positive value if P1 is a newer snapshot than P2. |
| 8442 | +*/ |
| 8443 | +SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp( |
| 8444 | + sqlite3_snapshot *p1, |
| 8445 | + sqlite3_snapshot *p2 |
| 8446 | +); |
| 8346 | 8447 | |
| 8347 | 8448 | /* |
| 8348 | 8449 | ** Undo the hack that converts floating point types to integer for |
| 8349 | 8450 | ** builds on processors without floating point support. |
| 8350 | 8451 | */ |
| | @@ -8476,11 +8577,11 @@ |
| 8476 | 8577 | #endif /* ifndef _SQLITE3RTREE_H_ */ |
| 8477 | 8578 | |
| 8478 | 8579 | /******** End of sqlite3rtree.h *********/ |
| 8479 | 8580 | /******** Begin file sqlite3session.h *********/ |
| 8480 | 8581 | |
| 8481 | | -#ifndef __SQLITESESSION_H_ |
| 8582 | +#if !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) |
| 8482 | 8583 | #define __SQLITESESSION_H_ 1 |
| 8483 | 8584 | |
| 8484 | 8585 | /* |
| 8485 | 8586 | ** Make sure we can call this stuff from C++. |
| 8486 | 8587 | */ |
| | @@ -9750,11 +9851,11 @@ |
| 9750 | 9851 | */ |
| 9751 | 9852 | #if 0 |
| 9752 | 9853 | } |
| 9753 | 9854 | #endif |
| 9754 | 9855 | |
| 9755 | | -#endif /* SQLITE_ENABLE_SESSION && SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 9856 | +#endif /* !defined(__SQLITESESSION_H_) && defined(SQLITE_ENABLE_SESSION) */ |
| 9756 | 9857 | |
| 9757 | 9858 | /******** End of sqlite3session.h *********/ |
| 9758 | 9859 | /******** Begin file fts5.h *********/ |
| 9759 | 9860 | /* |
| 9760 | 9861 | ** 2014 May 31 |
| | @@ -9898,15 +9999,17 @@ |
| 9898 | 9999 | ** of the current query. Specifically, a query equivalent to: |
| 9899 | 10000 | ** |
| 9900 | 10001 | ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid |
| 9901 | 10002 | ** |
| 9902 | 10003 | ** with $p set to a phrase equivalent to the phrase iPhrase of the |
| 9903 | | -** current query is executed. For each row visited, the callback function |
| 9904 | | -** passed as the fourth argument is invoked. The context and API objects |
| 9905 | | -** passed to the callback function may be used to access the properties of |
| 9906 | | -** each matched row. Invoking Api.xUserData() returns a copy of the pointer |
| 9907 | | -** passed as the third argument to pUserData. |
| 10004 | +** current query is executed. Any column filter that applies to |
| 10005 | +** phrase iPhrase of the current query is included in $p. For each |
| 10006 | +** row visited, the callback function passed as the fourth argument |
| 10007 | +** is invoked. The context and API objects passed to the callback |
| 10008 | +** function may be used to access the properties of each matched row. |
| 10009 | +** Invoking Api.xUserData() returns a copy of the pointer passed as |
| 10010 | +** the third argument to pUserData. |
| 9908 | 10011 | ** |
| 9909 | 10012 | ** If the callback function returns any value other than SQLITE_OK, the |
| 9910 | 10013 | ** query is abandoned and the xQueryPhrase function returns immediately. |
| 9911 | 10014 | ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK. |
| 9912 | 10015 | ** Otherwise, the error code is propagated upwards. |
| | @@ -10814,11 +10917,11 @@ |
| 10814 | 10917 | ** |
| 10815 | 10918 | ** When doing coverage testing ALWAYS and NEVER are hard-coded to |
| 10816 | 10919 | ** be true and false so that the unreachable code they specify will |
| 10817 | 10920 | ** not be counted as untested code. |
| 10818 | 10921 | */ |
| 10819 | | -#if defined(SQLITE_COVERAGE_TEST) |
| 10922 | +#if defined(SQLITE_COVERAGE_TEST) || defined(SQLITE_MUTATION_TEST) |
| 10820 | 10923 | # define ALWAYS(X) (1) |
| 10821 | 10924 | # define NEVER(X) (0) |
| 10822 | 10925 | #elif !defined(NDEBUG) |
| 10823 | 10926 | # define ALWAYS(X) ((X)?1:(assert(0),0)) |
| 10824 | 10927 | # define NEVER(X) ((X)?(assert(0),1):0) |
| | @@ -11019,80 +11122,80 @@ |
| 11019 | 11122 | #define TK_LP 22 |
| 11020 | 11123 | #define TK_RP 23 |
| 11021 | 11124 | #define TK_AS 24 |
| 11022 | 11125 | #define TK_WITHOUT 25 |
| 11023 | 11126 | #define TK_COMMA 26 |
| 11024 | | -#define TK_ID 27 |
| 11025 | | -#define TK_INDEXED 28 |
| 11026 | | -#define TK_ABORT 29 |
| 11027 | | -#define TK_ACTION 30 |
| 11028 | | -#define TK_AFTER 31 |
| 11029 | | -#define TK_ANALYZE 32 |
| 11030 | | -#define TK_ASC 33 |
| 11031 | | -#define TK_ATTACH 34 |
| 11032 | | -#define TK_BEFORE 35 |
| 11033 | | -#define TK_BY 36 |
| 11034 | | -#define TK_CASCADE 37 |
| 11035 | | -#define TK_CAST 38 |
| 11036 | | -#define TK_COLUMNKW 39 |
| 11037 | | -#define TK_CONFLICT 40 |
| 11038 | | -#define TK_DATABASE 41 |
| 11039 | | -#define TK_DESC 42 |
| 11040 | | -#define TK_DETACH 43 |
| 11041 | | -#define TK_EACH 44 |
| 11042 | | -#define TK_FAIL 45 |
| 11043 | | -#define TK_FOR 46 |
| 11044 | | -#define TK_IGNORE 47 |
| 11045 | | -#define TK_INITIALLY 48 |
| 11046 | | -#define TK_INSTEAD 49 |
| 11047 | | -#define TK_LIKE_KW 50 |
| 11048 | | -#define TK_MATCH 51 |
| 11049 | | -#define TK_NO 52 |
| 11050 | | -#define TK_KEY 53 |
| 11051 | | -#define TK_OF 54 |
| 11052 | | -#define TK_OFFSET 55 |
| 11053 | | -#define TK_PRAGMA 56 |
| 11054 | | -#define TK_RAISE 57 |
| 11055 | | -#define TK_RECURSIVE 58 |
| 11056 | | -#define TK_REPLACE 59 |
| 11057 | | -#define TK_RESTRICT 60 |
| 11058 | | -#define TK_ROW 61 |
| 11059 | | -#define TK_TRIGGER 62 |
| 11060 | | -#define TK_VACUUM 63 |
| 11061 | | -#define TK_VIEW 64 |
| 11062 | | -#define TK_VIRTUAL 65 |
| 11063 | | -#define TK_WITH 66 |
| 11064 | | -#define TK_REINDEX 67 |
| 11065 | | -#define TK_RENAME 68 |
| 11066 | | -#define TK_CTIME_KW 69 |
| 11067 | | -#define TK_ANY 70 |
| 11068 | | -#define TK_OR 71 |
| 11069 | | -#define TK_AND 72 |
| 11070 | | -#define TK_IS 73 |
| 11071 | | -#define TK_BETWEEN 74 |
| 11072 | | -#define TK_IN 75 |
| 11073 | | -#define TK_ISNULL 76 |
| 11074 | | -#define TK_NOTNULL 77 |
| 11075 | | -#define TK_NE 78 |
| 11076 | | -#define TK_EQ 79 |
| 11077 | | -#define TK_GT 80 |
| 11078 | | -#define TK_LE 81 |
| 11079 | | -#define TK_LT 82 |
| 11080 | | -#define TK_GE 83 |
| 11081 | | -#define TK_ESCAPE 84 |
| 11082 | | -#define TK_BITAND 85 |
| 11083 | | -#define TK_BITOR 86 |
| 11084 | | -#define TK_LSHIFT 87 |
| 11085 | | -#define TK_RSHIFT 88 |
| 11086 | | -#define TK_PLUS 89 |
| 11087 | | -#define TK_MINUS 90 |
| 11088 | | -#define TK_STAR 91 |
| 11089 | | -#define TK_SLASH 92 |
| 11090 | | -#define TK_REM 93 |
| 11091 | | -#define TK_CONCAT 94 |
| 11092 | | -#define TK_COLLATE 95 |
| 11093 | | -#define TK_BITNOT 96 |
| 11127 | +#define TK_OR 27 |
| 11128 | +#define TK_AND 28 |
| 11129 | +#define TK_IS 29 |
| 11130 | +#define TK_MATCH 30 |
| 11131 | +#define TK_LIKE_KW 31 |
| 11132 | +#define TK_BETWEEN 32 |
| 11133 | +#define TK_IN 33 |
| 11134 | +#define TK_ISNULL 34 |
| 11135 | +#define TK_NOTNULL 35 |
| 11136 | +#define TK_NE 36 |
| 11137 | +#define TK_EQ 37 |
| 11138 | +#define TK_GT 38 |
| 11139 | +#define TK_LE 39 |
| 11140 | +#define TK_LT 40 |
| 11141 | +#define TK_GE 41 |
| 11142 | +#define TK_ESCAPE 42 |
| 11143 | +#define TK_BITAND 43 |
| 11144 | +#define TK_BITOR 44 |
| 11145 | +#define TK_LSHIFT 45 |
| 11146 | +#define TK_RSHIFT 46 |
| 11147 | +#define TK_PLUS 47 |
| 11148 | +#define TK_MINUS 48 |
| 11149 | +#define TK_STAR 49 |
| 11150 | +#define TK_SLASH 50 |
| 11151 | +#define TK_REM 51 |
| 11152 | +#define TK_CONCAT 52 |
| 11153 | +#define TK_COLLATE 53 |
| 11154 | +#define TK_BITNOT 54 |
| 11155 | +#define TK_ID 55 |
| 11156 | +#define TK_INDEXED 56 |
| 11157 | +#define TK_ABORT 57 |
| 11158 | +#define TK_ACTION 58 |
| 11159 | +#define TK_AFTER 59 |
| 11160 | +#define TK_ANALYZE 60 |
| 11161 | +#define TK_ASC 61 |
| 11162 | +#define TK_ATTACH 62 |
| 11163 | +#define TK_BEFORE 63 |
| 11164 | +#define TK_BY 64 |
| 11165 | +#define TK_CASCADE 65 |
| 11166 | +#define TK_CAST 66 |
| 11167 | +#define TK_COLUMNKW 67 |
| 11168 | +#define TK_CONFLICT 68 |
| 11169 | +#define TK_DATABASE 69 |
| 11170 | +#define TK_DESC 70 |
| 11171 | +#define TK_DETACH 71 |
| 11172 | +#define TK_EACH 72 |
| 11173 | +#define TK_FAIL 73 |
| 11174 | +#define TK_FOR 74 |
| 11175 | +#define TK_IGNORE 75 |
| 11176 | +#define TK_INITIALLY 76 |
| 11177 | +#define TK_INSTEAD 77 |
| 11178 | +#define TK_NO 78 |
| 11179 | +#define TK_KEY 79 |
| 11180 | +#define TK_OF 80 |
| 11181 | +#define TK_OFFSET 81 |
| 11182 | +#define TK_PRAGMA 82 |
| 11183 | +#define TK_RAISE 83 |
| 11184 | +#define TK_RECURSIVE 84 |
| 11185 | +#define TK_REPLACE 85 |
| 11186 | +#define TK_RESTRICT 86 |
| 11187 | +#define TK_ROW 87 |
| 11188 | +#define TK_TRIGGER 88 |
| 11189 | +#define TK_VACUUM 89 |
| 11190 | +#define TK_VIEW 90 |
| 11191 | +#define TK_VIRTUAL 91 |
| 11192 | +#define TK_WITH 92 |
| 11193 | +#define TK_REINDEX 93 |
| 11194 | +#define TK_RENAME 94 |
| 11195 | +#define TK_CTIME_KW 95 |
| 11196 | +#define TK_ANY 96 |
| 11094 | 11197 | #define TK_STRING 97 |
| 11095 | 11198 | #define TK_JOIN_KW 98 |
| 11096 | 11199 | #define TK_CONSTRAINT 99 |
| 11097 | 11200 | #define TK_DEFAULT 100 |
| 11098 | 11201 | #define TK_NULL 101 |
| | @@ -12103,11 +12206,11 @@ |
| 12103 | 12206 | ** as an instance of the following structure: |
| 12104 | 12207 | */ |
| 12105 | 12208 | struct VdbeOp { |
| 12106 | 12209 | u8 opcode; /* What operation to perform */ |
| 12107 | 12210 | signed char p4type; /* One of the P4_xxx constants for p4 */ |
| 12108 | | - u8 opflags; /* Mask of the OPFLG_* flags in opcodes.h */ |
| 12211 | + u8 notUsed1; |
| 12109 | 12212 | u8 p5; /* Fifth parameter is an unsigned character */ |
| 12110 | 12213 | int p1; /* First operand */ |
| 12111 | 12214 | int p2; /* Second parameter (often the jump destination) */ |
| 12112 | 12215 | int p3; /* The third parameter */ |
| 12113 | 12216 | union p4union { /* fourth parameter */ |
| | @@ -12246,157 +12349,156 @@ |
| 12246 | 12349 | #define OP_Vacuum 10 |
| 12247 | 12350 | #define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */ |
| 12248 | 12351 | #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */ |
| 12249 | 12352 | #define OP_Goto 13 |
| 12250 | 12353 | #define OP_Gosub 14 |
| 12251 | | -#define OP_Return 15 |
| 12252 | | -#define OP_InitCoroutine 16 |
| 12253 | | -#define OP_EndCoroutine 17 |
| 12254 | | -#define OP_Yield 18 |
| 12354 | +#define OP_InitCoroutine 15 |
| 12355 | +#define OP_Yield 16 |
| 12356 | +#define OP_MustBeInt 17 |
| 12357 | +#define OP_Jump 18 |
| 12255 | 12358 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 12256 | | -#define OP_HaltIfNull 20 /* synopsis: if r[P3]=null halt */ |
| 12257 | | -#define OP_Halt 21 |
| 12258 | | -#define OP_Integer 22 /* synopsis: r[P2]=P1 */ |
| 12259 | | -#define OP_Int64 23 /* synopsis: r[P2]=P4 */ |
| 12260 | | -#define OP_String 24 /* synopsis: r[P2]='P4' (len=P1) */ |
| 12261 | | -#define OP_Null 25 /* synopsis: r[P2..P3]=NULL */ |
| 12262 | | -#define OP_SoftNull 26 /* synopsis: r[P1]=NULL */ |
| 12263 | | -#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */ |
| 12264 | | -#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 12265 | | -#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 12266 | | -#define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 12267 | | -#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */ |
| 12268 | | -#define OP_IntCopy 32 /* synopsis: r[P2]=r[P1] */ |
| 12269 | | -#define OP_ResultRow 33 /* synopsis: output=r[P1@P2] */ |
| 12270 | | -#define OP_CollSeq 34 |
| 12271 | | -#define OP_Function0 35 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12272 | | -#define OP_Function 36 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12273 | | -#define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */ |
| 12274 | | -#define OP_MustBeInt 38 |
| 12275 | | -#define OP_RealAffinity 39 |
| 12276 | | -#define OP_Cast 40 /* synopsis: affinity(r[P1]) */ |
| 12277 | | -#define OP_Permutation 41 |
| 12278 | | -#define OP_Compare 42 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 12279 | | -#define OP_Jump 43 |
| 12280 | | -#define OP_Once 44 |
| 12281 | | -#define OP_If 45 |
| 12282 | | -#define OP_IfNot 46 |
| 12283 | | -#define OP_Column 47 /* synopsis: r[P3]=PX */ |
| 12284 | | -#define OP_Affinity 48 /* synopsis: affinity(r[P1@P2]) */ |
| 12285 | | -#define OP_MakeRecord 49 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 12286 | | -#define OP_Count 50 /* synopsis: r[P2]=count() */ |
| 12287 | | -#define OP_ReadCookie 51 |
| 12288 | | -#define OP_SetCookie 52 |
| 12289 | | -#define OP_ReopenIdx 53 /* synopsis: root=P2 iDb=P3 */ |
| 12290 | | -#define OP_OpenRead 54 /* synopsis: root=P2 iDb=P3 */ |
| 12291 | | -#define OP_OpenWrite 55 /* synopsis: root=P2 iDb=P3 */ |
| 12292 | | -#define OP_OpenAutoindex 56 /* synopsis: nColumn=P2 */ |
| 12293 | | -#define OP_OpenEphemeral 57 /* synopsis: nColumn=P2 */ |
| 12294 | | -#define OP_SorterOpen 58 |
| 12295 | | -#define OP_SequenceTest 59 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 12296 | | -#define OP_OpenPseudo 60 /* synopsis: P3 columns in r[P2] */ |
| 12297 | | -#define OP_Close 61 |
| 12298 | | -#define OP_ColumnsUsed 62 |
| 12299 | | -#define OP_SeekLT 63 /* synopsis: key=r[P3@P4] */ |
| 12300 | | -#define OP_SeekLE 64 /* synopsis: key=r[P3@P4] */ |
| 12301 | | -#define OP_SeekGE 65 /* synopsis: key=r[P3@P4] */ |
| 12302 | | -#define OP_SeekGT 66 /* synopsis: key=r[P3@P4] */ |
| 12303 | | -#define OP_NoConflict 67 /* synopsis: key=r[P3@P4] */ |
| 12304 | | -#define OP_NotFound 68 /* synopsis: key=r[P3@P4] */ |
| 12305 | | -#define OP_Found 69 /* synopsis: key=r[P3@P4] */ |
| 12306 | | -#define OP_NotExists 70 /* synopsis: intkey=r[P3] */ |
| 12307 | | -#define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| 12308 | | -#define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */ |
| 12309 | | -#define OP_Sequence 73 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 12310 | | -#define OP_NewRowid 74 /* synopsis: r[P2]=rowid */ |
| 12311 | | -#define OP_Insert 75 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 12312 | | -#define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */ |
| 12313 | | -#define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */ |
| 12314 | | -#define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */ |
| 12315 | | -#define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */ |
| 12316 | | -#define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */ |
| 12317 | | -#define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */ |
| 12318 | | -#define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */ |
| 12319 | | -#define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */ |
| 12320 | | -#define OP_InsertInt 84 /* synopsis: intkey=P3 data=r[P2] */ |
| 12321 | | -#define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 12322 | | -#define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 12323 | | -#define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 12324 | | -#define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 12325 | | -#define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| 12326 | | -#define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 12327 | | -#define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 12328 | | -#define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 12329 | | -#define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 12330 | | -#define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 12331 | | -#define OP_Delete 95 |
| 12332 | | -#define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ |
| 12359 | +#define OP_Once 20 |
| 12360 | +#define OP_If 21 |
| 12361 | +#define OP_IfNot 22 |
| 12362 | +#define OP_SeekLT 23 /* synopsis: key=r[P3@P4] */ |
| 12363 | +#define OP_SeekLE 24 /* synopsis: key=r[P3@P4] */ |
| 12364 | +#define OP_SeekGE 25 /* synopsis: key=r[P3@P4] */ |
| 12365 | +#define OP_SeekGT 26 /* synopsis: key=r[P3@P4] */ |
| 12366 | +#define OP_Or 27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| 12367 | +#define OP_And 28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */ |
| 12368 | +#define OP_NoConflict 29 /* synopsis: key=r[P3@P4] */ |
| 12369 | +#define OP_NotFound 30 /* synopsis: key=r[P3@P4] */ |
| 12370 | +#define OP_Found 31 /* synopsis: key=r[P3@P4] */ |
| 12371 | +#define OP_NotExists 32 /* synopsis: intkey=r[P3] */ |
| 12372 | +#define OP_Last 33 |
| 12373 | +#define OP_IsNull 34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */ |
| 12374 | +#define OP_NotNull 35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */ |
| 12375 | +#define OP_Ne 36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */ |
| 12376 | +#define OP_Eq 37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */ |
| 12377 | +#define OP_Gt 38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */ |
| 12378 | +#define OP_Le 39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */ |
| 12379 | +#define OP_Lt 40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */ |
| 12380 | +#define OP_Ge 41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */ |
| 12381 | +#define OP_SorterSort 42 |
| 12382 | +#define OP_BitAnd 43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 12383 | +#define OP_BitOr 44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 12384 | +#define OP_ShiftLeft 45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 12385 | +#define OP_ShiftRight 46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 12386 | +#define OP_Add 47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| 12387 | +#define OP_Subtract 48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 12388 | +#define OP_Multiply 49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 12389 | +#define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 12390 | +#define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 12391 | +#define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 12392 | +#define OP_Sort 53 |
| 12393 | +#define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ |
| 12394 | +#define OP_Rewind 55 |
| 12395 | +#define OP_IdxLE 56 /* synopsis: key=r[P3@P4] */ |
| 12396 | +#define OP_IdxGT 57 /* synopsis: key=r[P3@P4] */ |
| 12397 | +#define OP_IdxLT 58 /* synopsis: key=r[P3@P4] */ |
| 12398 | +#define OP_IdxGE 59 /* synopsis: key=r[P3@P4] */ |
| 12399 | +#define OP_RowSetRead 60 /* synopsis: r[P3]=rowset(P1) */ |
| 12400 | +#define OP_RowSetTest 61 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 12401 | +#define OP_Program 62 |
| 12402 | +#define OP_FkIfZero 63 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 12403 | +#define OP_IfPos 64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 12404 | +#define OP_IfNotZero 65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */ |
| 12405 | +#define OP_DecrJumpZero 66 /* synopsis: if (--r[P1])==0 goto P2 */ |
| 12406 | +#define OP_IncrVacuum 67 |
| 12407 | +#define OP_VNext 68 |
| 12408 | +#define OP_Init 69 /* synopsis: Start at P2 */ |
| 12409 | +#define OP_Return 70 |
| 12410 | +#define OP_EndCoroutine 71 |
| 12411 | +#define OP_HaltIfNull 72 /* synopsis: if r[P3]=null halt */ |
| 12412 | +#define OP_Halt 73 |
| 12413 | +#define OP_Integer 74 /* synopsis: r[P2]=P1 */ |
| 12414 | +#define OP_Int64 75 /* synopsis: r[P2]=P4 */ |
| 12415 | +#define OP_String 76 /* synopsis: r[P2]='P4' (len=P1) */ |
| 12416 | +#define OP_Null 77 /* synopsis: r[P2..P3]=NULL */ |
| 12417 | +#define OP_SoftNull 78 /* synopsis: r[P1]=NULL */ |
| 12418 | +#define OP_Blob 79 /* synopsis: r[P2]=P4 (len=P1) */ |
| 12419 | +#define OP_Variable 80 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 12420 | +#define OP_Move 81 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 12421 | +#define OP_Copy 82 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 12422 | +#define OP_SCopy 83 /* synopsis: r[P2]=r[P1] */ |
| 12423 | +#define OP_IntCopy 84 /* synopsis: r[P2]=r[P1] */ |
| 12424 | +#define OP_ResultRow 85 /* synopsis: output=r[P1@P2] */ |
| 12425 | +#define OP_CollSeq 86 |
| 12426 | +#define OP_Function0 87 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12427 | +#define OP_Function 88 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 12428 | +#define OP_AddImm 89 /* synopsis: r[P1]=r[P1]+P2 */ |
| 12429 | +#define OP_RealAffinity 90 |
| 12430 | +#define OP_Cast 91 /* synopsis: affinity(r[P1]) */ |
| 12431 | +#define OP_Permutation 92 |
| 12432 | +#define OP_Compare 93 /* synopsis: r[P1@P3] <-> r[P2@P3] */ |
| 12433 | +#define OP_Column 94 /* synopsis: r[P3]=PX */ |
| 12434 | +#define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */ |
| 12435 | +#define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 12333 | 12436 | #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 12334 | | -#define OP_ResetCount 98 |
| 12335 | | -#define OP_SorterCompare 99 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 12336 | | -#define OP_SorterData 100 /* synopsis: r[P2]=data */ |
| 12337 | | -#define OP_RowKey 101 /* synopsis: r[P2]=key */ |
| 12338 | | -#define OP_RowData 102 /* synopsis: r[P2]=data */ |
| 12339 | | -#define OP_Rowid 103 /* synopsis: r[P2]=rowid */ |
| 12340 | | -#define OP_NullRow 104 |
| 12341 | | -#define OP_Last 105 |
| 12342 | | -#define OP_SorterSort 106 |
| 12343 | | -#define OP_Sort 107 |
| 12344 | | -#define OP_Rewind 108 |
| 12345 | | -#define OP_SorterInsert 109 |
| 12346 | | -#define OP_IdxInsert 110 /* synopsis: key=r[P2] */ |
| 12347 | | -#define OP_IdxDelete 111 /* synopsis: key=r[P2@P3] */ |
| 12348 | | -#define OP_Seek 112 /* synopsis: Move P3 to P1.rowid */ |
| 12349 | | -#define OP_IdxRowid 113 /* synopsis: r[P2]=rowid */ |
| 12350 | | -#define OP_IdxLE 114 /* synopsis: key=r[P3@P4] */ |
| 12351 | | -#define OP_IdxGT 115 /* synopsis: key=r[P3@P4] */ |
| 12352 | | -#define OP_IdxLT 116 /* synopsis: key=r[P3@P4] */ |
| 12353 | | -#define OP_IdxGE 117 /* synopsis: key=r[P3@P4] */ |
| 12354 | | -#define OP_Destroy 118 |
| 12355 | | -#define OP_Clear 119 |
| 12356 | | -#define OP_ResetSorter 120 |
| 12357 | | -#define OP_CreateIndex 121 /* synopsis: r[P2]=root iDb=P1 */ |
| 12358 | | -#define OP_CreateTable 122 /* synopsis: r[P2]=root iDb=P1 */ |
| 12359 | | -#define OP_ParseSchema 123 |
| 12360 | | -#define OP_LoadAnalysis 124 |
| 12361 | | -#define OP_DropTable 125 |
| 12362 | | -#define OP_DropIndex 126 |
| 12363 | | -#define OP_DropTrigger 127 |
| 12364 | | -#define OP_IntegrityCk 128 |
| 12365 | | -#define OP_RowSetAdd 129 /* synopsis: rowset(P1)=r[P2] */ |
| 12366 | | -#define OP_RowSetRead 130 /* synopsis: r[P3]=rowset(P1) */ |
| 12367 | | -#define OP_RowSetTest 131 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 12368 | | -#define OP_Program 132 |
| 12437 | +#define OP_Count 98 /* synopsis: r[P2]=count() */ |
| 12438 | +#define OP_ReadCookie 99 |
| 12439 | +#define OP_SetCookie 100 |
| 12440 | +#define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */ |
| 12441 | +#define OP_OpenRead 102 /* synopsis: root=P2 iDb=P3 */ |
| 12442 | +#define OP_OpenWrite 103 /* synopsis: root=P2 iDb=P3 */ |
| 12443 | +#define OP_OpenAutoindex 104 /* synopsis: nColumn=P2 */ |
| 12444 | +#define OP_OpenEphemeral 105 /* synopsis: nColumn=P2 */ |
| 12445 | +#define OP_SorterOpen 106 |
| 12446 | +#define OP_SequenceTest 107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */ |
| 12447 | +#define OP_OpenPseudo 108 /* synopsis: P3 columns in r[P2] */ |
| 12448 | +#define OP_Close 109 |
| 12449 | +#define OP_ColumnsUsed 110 |
| 12450 | +#define OP_Sequence 111 /* synopsis: r[P2]=cursor[P1].ctr++ */ |
| 12451 | +#define OP_NewRowid 112 /* synopsis: r[P2]=rowid */ |
| 12452 | +#define OP_Insert 113 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 12453 | +#define OP_InsertInt 114 /* synopsis: intkey=P3 data=r[P2] */ |
| 12454 | +#define OP_Delete 115 |
| 12455 | +#define OP_ResetCount 116 |
| 12456 | +#define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 12457 | +#define OP_SorterData 118 /* synopsis: r[P2]=data */ |
| 12458 | +#define OP_RowKey 119 /* synopsis: r[P2]=key */ |
| 12459 | +#define OP_RowData 120 /* synopsis: r[P2]=data */ |
| 12460 | +#define OP_Rowid 121 /* synopsis: r[P2]=rowid */ |
| 12461 | +#define OP_NullRow 122 |
| 12462 | +#define OP_SorterInsert 123 |
| 12463 | +#define OP_IdxInsert 124 /* synopsis: key=r[P2] */ |
| 12464 | +#define OP_IdxDelete 125 /* synopsis: key=r[P2@P3] */ |
| 12465 | +#define OP_Seek 126 /* synopsis: Move P3 to P1.rowid */ |
| 12466 | +#define OP_IdxRowid 127 /* synopsis: r[P2]=rowid */ |
| 12467 | +#define OP_Destroy 128 |
| 12468 | +#define OP_Clear 129 |
| 12469 | +#define OP_ResetSorter 130 |
| 12470 | +#define OP_CreateIndex 131 /* synopsis: r[P2]=root iDb=P1 */ |
| 12471 | +#define OP_CreateTable 132 /* synopsis: r[P2]=root iDb=P1 */ |
| 12369 | 12472 | #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 12370 | | -#define OP_Param 134 |
| 12371 | | -#define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */ |
| 12372 | | -#define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 12373 | | -#define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 12374 | | -#define OP_IfPos 138 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */ |
| 12375 | | -#define OP_OffsetLimit 139 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 12376 | | -#define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */ |
| 12377 | | -#define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */ |
| 12378 | | -#define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */ |
| 12379 | | -#define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12380 | | -#define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12381 | | -#define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */ |
| 12382 | | -#define OP_IncrVacuum 146 |
| 12383 | | -#define OP_Expire 147 |
| 12384 | | -#define OP_TableLock 148 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 12385 | | -#define OP_VBegin 149 |
| 12386 | | -#define OP_VCreate 150 |
| 12387 | | -#define OP_VDestroy 151 |
| 12388 | | -#define OP_VOpen 152 |
| 12389 | | -#define OP_VColumn 153 /* synopsis: r[P3]=vcolumn(P2) */ |
| 12390 | | -#define OP_VNext 154 |
| 12473 | +#define OP_ParseSchema 134 |
| 12474 | +#define OP_LoadAnalysis 135 |
| 12475 | +#define OP_DropTable 136 |
| 12476 | +#define OP_DropIndex 137 |
| 12477 | +#define OP_DropTrigger 138 |
| 12478 | +#define OP_IntegrityCk 139 |
| 12479 | +#define OP_RowSetAdd 140 /* synopsis: rowset(P1)=r[P2] */ |
| 12480 | +#define OP_Param 141 |
| 12481 | +#define OP_FkCounter 142 /* synopsis: fkctr[P1]+=P2 */ |
| 12482 | +#define OP_MemMax 143 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 12483 | +#define OP_OffsetLimit 144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 12484 | +#define OP_AggStep0 145 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12485 | +#define OP_AggStep 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12486 | +#define OP_AggFinal 147 /* synopsis: accum=r[P1] N=P2 */ |
| 12487 | +#define OP_Expire 148 |
| 12488 | +#define OP_TableLock 149 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 12489 | +#define OP_VBegin 150 |
| 12490 | +#define OP_VCreate 151 |
| 12491 | +#define OP_VDestroy 152 |
| 12492 | +#define OP_VOpen 153 |
| 12493 | +#define OP_VColumn 154 /* synopsis: r[P3]=vcolumn(P2) */ |
| 12391 | 12494 | #define OP_VRename 155 |
| 12392 | 12495 | #define OP_Pagecount 156 |
| 12393 | 12496 | #define OP_MaxPgcnt 157 |
| 12394 | | -#define OP_Init 158 /* synopsis: Start at P2 */ |
| 12395 | | -#define OP_CursorHint 159 |
| 12396 | | -#define OP_Noop 160 |
| 12397 | | -#define OP_Explain 161 |
| 12497 | +#define OP_CursorHint 158 |
| 12498 | +#define OP_Noop 159 |
| 12499 | +#define OP_Explain 160 |
| 12398 | 12500 | |
| 12399 | 12501 | /* Properties such as "out2" or "jump" that are specified in |
| 12400 | 12502 | ** comments following the "case" for each opcode in the vdbe.c |
| 12401 | 12503 | ** are encoded into bitvectors as follows: |
| 12402 | 12504 | */ |
| | @@ -12406,30 +12508,38 @@ |
| 12406 | 12508 | #define OPFLG_IN3 0x08 /* in3: P3 is an input */ |
| 12407 | 12509 | #define OPFLG_OUT2 0x10 /* out2: P2 is an output */ |
| 12408 | 12510 | #define OPFLG_OUT3 0x20 /* out3: P3 is an output */ |
| 12409 | 12511 | #define OPFLG_INITIALIZER {\ |
| 12410 | 12512 | /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 12411 | | -/* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x02,\ |
| 12412 | | -/* 16 */ 0x01, 0x02, 0x03, 0x12, 0x08, 0x00, 0x10, 0x10,\ |
| 12413 | | -/* 24 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\ |
| 12414 | | -/* 32 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x02,\ |
| 12415 | | -/* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\ |
| 12416 | | -/* 48 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\ |
| 12417 | | -/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,\ |
| 12418 | | -/* 64 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x26,\ |
| 12419 | | -/* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\ |
| 12420 | | -/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\ |
| 12421 | | -/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\ |
| 12422 | | -/* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 12423 | | -/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\ |
| 12424 | | -/* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\ |
| 12425 | | -/* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12426 | | -/* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\ |
| 12427 | | -/* 136 */ 0x01, 0x04, 0x03, 0x1a, 0x03, 0x03, 0x03, 0x00,\ |
| 12428 | | -/* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12429 | | -/* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\ |
| 12430 | | -/* 160 */ 0x00, 0x00,} |
| 12513 | +/* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\ |
| 12514 | +/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\ |
| 12515 | +/* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\ |
| 12516 | +/* 32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 12517 | +/* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\ |
| 12518 | +/* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\ |
| 12519 | +/* 56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\ |
| 12520 | +/* 64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\ |
| 12521 | +/* 72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\ |
| 12522 | +/* 80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\ |
| 12523 | +/* 88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\ |
| 12524 | +/* 96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\ |
| 12525 | +/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\ |
| 12526 | +/* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12527 | +/* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\ |
| 12528 | +/* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\ |
| 12529 | +/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\ |
| 12530 | +/* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12531 | +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 12532 | +/* 160 */ 0x00,} |
| 12533 | + |
| 12534 | +/* The sqlite3P2Values() routine is able to run faster if it knows |
| 12535 | +** the value of the largest JUMP opcode. The smaller the maximum |
| 12536 | +** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 12537 | +** generated this include file strives to group all JUMP opcodes |
| 12538 | +** together near the beginning of the list. |
| 12539 | +*/ |
| 12540 | +#define SQLITE_MX_JUMP_OPCODE 69 /* Maximum JUMP opcode */ |
| 12431 | 12541 | |
| 12432 | 12542 | /************** End of opcodes.h *********************************************/ |
| 12433 | 12543 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 12434 | 12544 | |
| 12435 | 12545 | /* |
| | @@ -12648,11 +12758,15 @@ |
| 12648 | 12758 | #define PAGER_LOCKINGMODE_QUERY -1 |
| 12649 | 12759 | #define PAGER_LOCKINGMODE_NORMAL 0 |
| 12650 | 12760 | #define PAGER_LOCKINGMODE_EXCLUSIVE 1 |
| 12651 | 12761 | |
| 12652 | 12762 | /* |
| 12653 | | -** Numeric constants that encode the journalmode. |
| 12763 | +** Numeric constants that encode the journalmode. |
| 12764 | +** |
| 12765 | +** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY) |
| 12766 | +** are exposed in the API via the "PRAGMA journal_mode" command and |
| 12767 | +** therefore cannot be changed without a compatibility break. |
| 12654 | 12768 | */ |
| 12655 | 12769 | #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */ |
| 12656 | 12770 | #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */ |
| 12657 | 12771 | #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */ |
| 12658 | 12772 | #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */ |
| | @@ -12666,10 +12780,15 @@ |
| 12666 | 12780 | #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */ |
| 12667 | 12781 | #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */ |
| 12668 | 12782 | |
| 12669 | 12783 | /* |
| 12670 | 12784 | ** Flags for sqlite3PagerSetFlags() |
| 12785 | +** |
| 12786 | +** Value constraints (enforced via assert()): |
| 12787 | +** PAGER_FULLFSYNC == SQLITE_FullFSync |
| 12788 | +** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync |
| 12789 | +** PAGER_CACHE_SPILL == SQLITE_CacheSpill |
| 12671 | 12790 | */ |
| 12672 | 12791 | #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */ |
| 12673 | 12792 | #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */ |
| 12674 | 12793 | #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */ |
| 12675 | 12794 | #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */ |
| | @@ -12835,11 +12954,11 @@ |
| 12835 | 12954 | */ |
| 12836 | 12955 | struct PgHdr { |
| 12837 | 12956 | sqlite3_pcache_page *pPage; /* Pcache object page handle */ |
| 12838 | 12957 | void *pData; /* Page data */ |
| 12839 | 12958 | void *pExtra; /* Extra content */ |
| 12840 | | - PgHdr *pDirty; /* Transient list of dirty pages */ |
| 12959 | + PgHdr *pDirty; /* Transient list of dirty sorted by pgno */ |
| 12841 | 12960 | Pager *pPager; /* The pager this page is part of */ |
| 12842 | 12961 | Pgno pgno; /* Page number for this page */ |
| 12843 | 12962 | #ifdef SQLITE_CHECK_PAGES |
| 12844 | 12963 | u32 pageHash; /* Hash of page content */ |
| 12845 | 12964 | #endif |
| | @@ -12860,15 +12979,14 @@ |
| 12860 | 12979 | #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */ |
| 12861 | 12980 | #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */ |
| 12862 | 12981 | #define PGHDR_WRITEABLE 0x004 /* Journaled and ready to modify */ |
| 12863 | 12982 | #define PGHDR_NEED_SYNC 0x008 /* Fsync the rollback journal before |
| 12864 | 12983 | ** writing this page to the database */ |
| 12865 | | -#define PGHDR_NEED_READ 0x010 /* Content is unread */ |
| 12866 | | -#define PGHDR_DONT_WRITE 0x020 /* Do not write content to disk */ |
| 12867 | | -#define PGHDR_MMAP 0x040 /* This is an mmap page object */ |
| 12984 | +#define PGHDR_DONT_WRITE 0x010 /* Do not write content to disk */ |
| 12985 | +#define PGHDR_MMAP 0x020 /* This is an mmap page object */ |
| 12868 | 12986 | |
| 12869 | | -#define PGHDR_WAL_APPEND 0x080 /* Appended to wal file */ |
| 12987 | +#define PGHDR_WAL_APPEND 0x040 /* Appended to wal file */ |
| 12870 | 12988 | |
| 12871 | 12989 | /* Initialize and shutdown the page cache subsystem */ |
| 12872 | 12990 | SQLITE_PRIVATE int sqlite3PcacheInitialize(void); |
| 12873 | 12991 | SQLITE_PRIVATE void sqlite3PcacheShutdown(void); |
| 12874 | 12992 | |
| | @@ -12908,10 +13026,11 @@ |
| 12908 | 13026 | |
| 12909 | 13027 | SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */ |
| 12910 | 13028 | SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */ |
| 12911 | 13029 | SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */ |
| 12912 | 13030 | SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */ |
| 13031 | +SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache*); |
| 12913 | 13032 | |
| 12914 | 13033 | /* Change a page number. Used by incr-vacuum. */ |
| 12915 | 13034 | SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno); |
| 12916 | 13035 | |
| 12917 | 13036 | /* Remove all pages with pgno>x. Reset the cache if x==0 */ |
| | @@ -12945,10 +13064,15 @@ |
| 12945 | 13064 | ** interface is only available if SQLITE_CHECK_PAGES is defined when the |
| 12946 | 13065 | ** library is built. |
| 12947 | 13066 | */ |
| 12948 | 13067 | SQLITE_PRIVATE void sqlite3PcacheIterateDirty(PCache *pCache, void (*xIter)(PgHdr *)); |
| 12949 | 13068 | #endif |
| 13069 | + |
| 13070 | +#if defined(SQLITE_DEBUG) |
| 13071 | +/* Check invariants on a PgHdr object */ |
| 13072 | +SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr*); |
| 13073 | +#endif |
| 12950 | 13074 | |
| 12951 | 13075 | /* Set and get the suggested cache-size for the specified pager-cache. |
| 12952 | 13076 | ** |
| 12953 | 13077 | ** If no global maximum is configured, then the system attempts to limit |
| 12954 | 13078 | ** the total number of pages cached by purgeable pager-caches to the sum |
| | @@ -12981,10 +13105,13 @@ |
| 12981 | 13105 | SQLITE_PRIVATE void sqlite3PCacheSetDefault(void); |
| 12982 | 13106 | |
| 12983 | 13107 | /* Return the header size */ |
| 12984 | 13108 | SQLITE_PRIVATE int sqlite3HeaderSizePcache(void); |
| 12985 | 13109 | SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void); |
| 13110 | + |
| 13111 | +/* Number of dirty pages as a percentage of the configured cache size */ |
| 13112 | +SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache*); |
| 12986 | 13113 | |
| 12987 | 13114 | #endif /* _PCACHE_H_ */ |
| 12988 | 13115 | |
| 12989 | 13116 | /************** End of pcache.h **********************************************/ |
| 12990 | 13117 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| | @@ -13211,11 +13338,11 @@ |
| 13211 | 13338 | SQLITE_PRIVATE int sqlite3OsInit(void); |
| 13212 | 13339 | |
| 13213 | 13340 | /* |
| 13214 | 13341 | ** Functions for accessing sqlite3_file methods |
| 13215 | 13342 | */ |
| 13216 | | -SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file*); |
| 13343 | +SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*); |
| 13217 | 13344 | SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset); |
| 13218 | 13345 | SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset); |
| 13219 | 13346 | SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size); |
| 13220 | 13347 | SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int); |
| 13221 | 13348 | SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize); |
| | @@ -13256,11 +13383,11 @@ |
| 13256 | 13383 | /* |
| 13257 | 13384 | ** Convenience functions for opening and closing files using |
| 13258 | 13385 | ** sqlite3_malloc() to obtain space for the file-handle structure. |
| 13259 | 13386 | */ |
| 13260 | 13387 | SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*); |
| 13261 | | -SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *); |
| 13388 | +SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *); |
| 13262 | 13389 | |
| 13263 | 13390 | #endif /* _SQLITE_OS_H_ */ |
| 13264 | 13391 | |
| 13265 | 13392 | /************** End of os.h **************************************************/ |
| 13266 | 13393 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| | @@ -13665,10 +13792,15 @@ |
| 13665 | 13792 | #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc) |
| 13666 | 13793 | #define ENC(db) ((db)->enc) |
| 13667 | 13794 | |
| 13668 | 13795 | /* |
| 13669 | 13796 | ** Possible values for the sqlite3.flags. |
| 13797 | +** |
| 13798 | +** Value constraints (enforced via assert()): |
| 13799 | +** SQLITE_FullFSync == PAGER_FULLFSYNC |
| 13800 | +** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC |
| 13801 | +** SQLITE_CacheSpill == PAGER_CACHE_SPILL |
| 13670 | 13802 | */ |
| 13671 | 13803 | #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */ |
| 13672 | 13804 | #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */ |
| 13673 | 13805 | #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */ |
| 13674 | 13806 | #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */ |
| | @@ -13692,17 +13824,18 @@ |
| 13692 | 13824 | #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */ |
| 13693 | 13825 | #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */ |
| 13694 | 13826 | #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */ |
| 13695 | 13827 | #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */ |
| 13696 | 13828 | #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */ |
| 13697 | | -#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */ |
| 13698 | | -#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */ |
| 13699 | | -#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */ |
| 13700 | | -#define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */ |
| 13701 | | -#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */ |
| 13702 | | -#define SQLITE_CellSizeCk 0x10000000 /* Check btree cell sizes on load */ |
| 13703 | | -#define SQLITE_Fts3Tokenizer 0x20000000 /* Enable fts3_tokenizer(2) */ |
| 13829 | +#define SQLITE_LoadExtFunc 0x00800000 /* Enable load_extension() SQL func */ |
| 13830 | +#define SQLITE_EnableTrigger 0x01000000 /* True to enable triggers */ |
| 13831 | +#define SQLITE_DeferFKs 0x02000000 /* Defer all FK constraints */ |
| 13832 | +#define SQLITE_QueryOnly 0x04000000 /* Disable database changes */ |
| 13833 | +#define SQLITE_VdbeEQP 0x08000000 /* Debug EXPLAIN QUERY PLAN */ |
| 13834 | +#define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */ |
| 13835 | +#define SQLITE_CellSizeCk 0x20000000 /* Check btree cell sizes on load */ |
| 13836 | +#define SQLITE_Fts3Tokenizer 0x40000000 /* Enable fts3_tokenizer(2) */ |
| 13704 | 13837 | |
| 13705 | 13838 | |
| 13706 | 13839 | /* |
| 13707 | 13840 | ** Bits of the sqlite3.dbOptFlags field that are used by the |
| 13708 | 13841 | ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to |
| | @@ -13799,10 +13932,17 @@ |
| 13799 | 13932 | /* |
| 13800 | 13933 | ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF |
| 13801 | 13934 | ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And |
| 13802 | 13935 | ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There |
| 13803 | 13936 | ** are assert() statements in the code to verify this. |
| 13937 | +** |
| 13938 | +** Value constraints (enforced via assert()): |
| 13939 | +** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg |
| 13940 | +** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG |
| 13941 | +** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG |
| 13942 | +** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API |
| 13943 | +** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API |
| 13804 | 13944 | */ |
| 13805 | 13945 | #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ |
| 13806 | 13946 | #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ |
| 13807 | 13947 | #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */ |
| 13808 | 13948 | #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */ |
| | @@ -14798,10 +14938,13 @@ |
| 14798 | 14938 | |
| 14799 | 14939 | |
| 14800 | 14940 | /* |
| 14801 | 14941 | ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin() |
| 14802 | 14942 | ** and the WhereInfo.wctrlFlags member. |
| 14943 | +** |
| 14944 | +** Value constraints (enforced via assert()): |
| 14945 | +** WHERE_USE_LIMIT == SF_FixedLimit |
| 14803 | 14946 | */ |
| 14804 | 14947 | #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */ |
| 14805 | 14948 | #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */ |
| 14806 | 14949 | #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */ |
| 14807 | 14950 | #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */ |
| | @@ -14815,10 +14958,11 @@ |
| 14815 | 14958 | #define WHERE_WANT_DISTINCT 0x0400 /* All output needs to be distinct */ |
| 14816 | 14959 | #define WHERE_SORTBYGROUP 0x0800 /* Support sqlite3WhereIsSorted() */ |
| 14817 | 14960 | #define WHERE_REOPEN_IDX 0x1000 /* Try to use OP_ReopenIdx */ |
| 14818 | 14961 | #define WHERE_ONEPASS_MULTIROW 0x2000 /* ONEPASS is ok with multiple rows */ |
| 14819 | 14962 | #define WHERE_USE_LIMIT 0x4000 /* There is a constant LIMIT clause */ |
| 14963 | +#define WHERE_SEEK_TABLE 0x8000 /* Do not defer seeks on main table */ |
| 14820 | 14964 | |
| 14821 | 14965 | /* Allowed return values from sqlite3WhereIsDistinct() |
| 14822 | 14966 | */ |
| 14823 | 14967 | #define WHERE_DISTINCT_NOOP 0 /* DISTINCT keyword not used */ |
| 14824 | 14968 | #define WHERE_DISTINCT_UNIQUE 1 /* No duplicates */ |
| | @@ -14858,20 +15002,22 @@ |
| 14858 | 15002 | }; |
| 14859 | 15003 | |
| 14860 | 15004 | /* |
| 14861 | 15005 | ** Allowed values for the NameContext, ncFlags field. |
| 14862 | 15006 | ** |
| 14863 | | -** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and |
| 14864 | | -** SQLITE_FUNC_MINMAX. |
| 15007 | +** Value constraints (all checked via assert()): |
| 15008 | +** NC_HasAgg == SF_HasAgg |
| 15009 | +** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX |
| 14865 | 15010 | ** |
| 14866 | 15011 | */ |
| 14867 | 15012 | #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */ |
| 14868 | | -#define NC_HasAgg 0x0002 /* One or more aggregate functions seen */ |
| 15013 | +#define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */ |
| 14869 | 15014 | #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */ |
| 14870 | 15015 | #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */ |
| 14871 | | -#define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */ |
| 15016 | +#define NC_HasAgg 0x0010 /* One or more aggregate functions seen */ |
| 14872 | 15017 | #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */ |
| 15018 | +#define NC_VarSelect 0x0040 /* A correlated subquery has been seen */ |
| 14873 | 15019 | #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */ |
| 14874 | 15020 | |
| 14875 | 15021 | /* |
| 14876 | 15022 | ** An instance of the following structure contains all information |
| 14877 | 15023 | ** needed to generate code for a single SELECT statement. |
| | @@ -14915,28 +15061,34 @@ |
| 14915 | 15061 | }; |
| 14916 | 15062 | |
| 14917 | 15063 | /* |
| 14918 | 15064 | ** Allowed values for Select.selFlags. The "SF" prefix stands for |
| 14919 | 15065 | ** "Select Flag". |
| 15066 | +** |
| 15067 | +** Value constraints (all checked via assert()) |
| 15068 | +** SF_HasAgg == NC_HasAgg |
| 15069 | +** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX |
| 15070 | +** SF_FixedLimit == WHERE_USE_LIMIT |
| 14920 | 15071 | */ |
| 14921 | 15072 | #define SF_Distinct 0x00001 /* Output should be DISTINCT */ |
| 14922 | 15073 | #define SF_All 0x00002 /* Includes the ALL keyword */ |
| 14923 | 15074 | #define SF_Resolved 0x00004 /* Identifiers have been resolved */ |
| 14924 | | -#define SF_Aggregate 0x00008 /* Contains aggregate functions */ |
| 14925 | | -#define SF_UsesEphemeral 0x00010 /* Uses the OpenEphemeral opcode */ |
| 14926 | | -#define SF_Expanded 0x00020 /* sqlite3SelectExpand() called on this */ |
| 14927 | | -#define SF_HasTypeInfo 0x00040 /* FROM subqueries have Table metadata */ |
| 14928 | | -#define SF_Compound 0x00080 /* Part of a compound query */ |
| 14929 | | -#define SF_Values 0x00100 /* Synthesized from VALUES clause */ |
| 14930 | | -#define SF_MultiValue 0x00200 /* Single VALUES term with multiple rows */ |
| 14931 | | -#define SF_NestedFrom 0x00400 /* Part of a parenthesized FROM clause */ |
| 14932 | | -#define SF_MaybeConvert 0x00800 /* Need convertCompoundSelectToSubquery() */ |
| 15075 | +#define SF_Aggregate 0x00008 /* Contains agg functions or a GROUP BY */ |
| 15076 | +#define SF_HasAgg 0x00010 /* Contains aggregate functions */ |
| 15077 | +#define SF_UsesEphemeral 0x00020 /* Uses the OpenEphemeral opcode */ |
| 15078 | +#define SF_Expanded 0x00040 /* sqlite3SelectExpand() called on this */ |
| 15079 | +#define SF_HasTypeInfo 0x00080 /* FROM subqueries have Table metadata */ |
| 15080 | +#define SF_Compound 0x00100 /* Part of a compound query */ |
| 15081 | +#define SF_Values 0x00200 /* Synthesized from VALUES clause */ |
| 15082 | +#define SF_MultiValue 0x00400 /* Single VALUES term with multiple rows */ |
| 15083 | +#define SF_NestedFrom 0x00800 /* Part of a parenthesized FROM clause */ |
| 14933 | 15084 | #define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */ |
| 14934 | 15085 | #define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */ |
| 14935 | 15086 | #define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */ |
| 14936 | | -#define SF_Converted 0x08000 /* By convertCompoundSelectToSubquery() */ |
| 14937 | | -#define SF_IncludeHidden 0x10000 /* Include hidden columns in output */ |
| 15087 | +#define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */ |
| 15088 | +#define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */ |
| 15089 | +#define SF_IncludeHidden 0x20000 /* Include hidden columns in output */ |
| 14938 | 15090 | |
| 14939 | 15091 | |
| 14940 | 15092 | /* |
| 14941 | 15093 | ** The results of a SELECT can be distributed in several ways, as defined |
| 14942 | 15094 | ** by one of the following macros. The "SRT" prefix means "SELECT Result |
| | @@ -15129,10 +15281,11 @@ |
| 15129 | 15281 | u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ |
| 15130 | 15282 | u8 mayAbort; /* True if statement may throw an ABORT exception */ |
| 15131 | 15283 | u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */ |
| 15132 | 15284 | u8 okConstFactor; /* OK to factor out constants */ |
| 15133 | 15285 | u8 disableLookaside; /* Number of times lookaside has been disabled */ |
| 15286 | + u8 nColCache; /* Number of entries in aColCache[] */ |
| 15134 | 15287 | int aTempReg[8]; /* Holding area for temporary registers */ |
| 15135 | 15288 | int nRangeReg; /* Size of the temporary register block */ |
| 15136 | 15289 | int iRangeReg; /* First register in temporary register block */ |
| 15137 | 15290 | int nErr; /* Number of errors seen */ |
| 15138 | 15291 | int nTab; /* Number of previously allocated VDBE cursors */ |
| | @@ -15242,10 +15395,19 @@ |
| 15242 | 15395 | Parse *pParse; /* The Parse structure */ |
| 15243 | 15396 | }; |
| 15244 | 15397 | |
| 15245 | 15398 | /* |
| 15246 | 15399 | ** Bitfield flags for P5 value in various opcodes. |
| 15400 | +** |
| 15401 | +** Value constraints (enforced via assert()): |
| 15402 | +** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH |
| 15403 | +** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF |
| 15404 | +** OPFLAG_BULKCSR == BTREE_BULKLOAD |
| 15405 | +** OPFLAG_SEEKEQ == BTREE_SEEK_EQ |
| 15406 | +** OPFLAG_FORDELETE == BTREE_FORDELETE |
| 15407 | +** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION |
| 15408 | +** OPFLAG_AUXDELETE == BTREE_AUXDELETE |
| 15247 | 15409 | */ |
| 15248 | 15410 | #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */ |
| 15249 | 15411 | /* Also used in P2 (not P5) of OP_Delete */ |
| 15250 | 15412 | #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ |
| 15251 | 15413 | #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */ |
| | @@ -15616,18 +15778,20 @@ |
| 15616 | 15778 | # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06) |
| 15617 | 15779 | # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02) |
| 15618 | 15780 | # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04) |
| 15619 | 15781 | # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08) |
| 15620 | 15782 | # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)]) |
| 15783 | +# define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80) |
| 15621 | 15784 | #else |
| 15622 | 15785 | # define sqlite3Toupper(x) toupper((unsigned char)(x)) |
| 15623 | 15786 | # define sqlite3Isspace(x) isspace((unsigned char)(x)) |
| 15624 | 15787 | # define sqlite3Isalnum(x) isalnum((unsigned char)(x)) |
| 15625 | 15788 | # define sqlite3Isalpha(x) isalpha((unsigned char)(x)) |
| 15626 | 15789 | # define sqlite3Isdigit(x) isdigit((unsigned char)(x)) |
| 15627 | 15790 | # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x)) |
| 15628 | 15791 | # define sqlite3Tolower(x) tolower((unsigned char)(x)) |
| 15792 | +# define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`') |
| 15629 | 15793 | #endif |
| 15630 | 15794 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 15631 | 15795 | SQLITE_PRIVATE int sqlite3IsIdChar(u8); |
| 15632 | 15796 | #endif |
| 15633 | 15797 | |
| | @@ -15747,11 +15911,11 @@ |
| 15747 | 15911 | #endif |
| 15748 | 15912 | |
| 15749 | 15913 | |
| 15750 | 15914 | SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*); |
| 15751 | 15915 | SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...); |
| 15752 | | -SQLITE_PRIVATE int sqlite3Dequote(char*); |
| 15916 | +SQLITE_PRIVATE void sqlite3Dequote(char*); |
| 15753 | 15917 | SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*); |
| 15754 | 15918 | SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int); |
| 15755 | 15919 | SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **); |
| 15756 | 15920 | SQLITE_PRIVATE void sqlite3FinishCoding(Parse*); |
| 15757 | 15921 | SQLITE_PRIVATE int sqlite3GetTempReg(Parse*); |
| | @@ -15764,10 +15928,11 @@ |
| 15764 | 15928 | #endif |
| 15765 | 15929 | SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int); |
| 15766 | 15930 | SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*); |
| 15767 | 15931 | SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); |
| 15768 | 15932 | SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); |
| 15933 | +SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*); |
| 15769 | 15934 | SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); |
| 15770 | 15935 | SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); |
| 15771 | 15936 | SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*); |
| 15772 | 15937 | SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*); |
| 15773 | 15938 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*); |
| | @@ -16559,10 +16724,11 @@ |
| 16559 | 16724 | ** isdigit() 0x04 |
| 16560 | 16725 | ** isalnum() 0x06 |
| 16561 | 16726 | ** isxdigit() 0x08 |
| 16562 | 16727 | ** toupper() 0x20 |
| 16563 | 16728 | ** SQLite identifier character 0x40 |
| 16729 | +** Quote character 0x80 |
| 16564 | 16730 | ** |
| 16565 | 16731 | ** Bit 0x20 is set if the mapped character requires translation to upper |
| 16566 | 16732 | ** case. i.e. if the character is a lower-case ASCII character. |
| 16567 | 16733 | ** If x is a lower-case ASCII character, then its upper-case equivalent |
| 16568 | 16734 | ** is (x - 0x20). Therefore toupper() can be implemented as: |
| | @@ -16584,20 +16750,20 @@ |
| 16584 | 16750 | SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = { |
| 16585 | 16751 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */ |
| 16586 | 16752 | 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */ |
| 16587 | 16753 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */ |
| 16588 | 16754 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */ |
| 16589 | | - 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, /* 20..27 !"#$%&' */ |
| 16755 | + 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */ |
| 16590 | 16756 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */ |
| 16591 | 16757 | 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */ |
| 16592 | 16758 | 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */ |
| 16593 | 16759 | |
| 16594 | 16760 | 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */ |
| 16595 | 16761 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */ |
| 16596 | 16762 | 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */ |
| 16597 | | - 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */ |
| 16598 | | - 0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */ |
| 16763 | + 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */ |
| 16764 | + 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */ |
| 16599 | 16765 | 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */ |
| 16600 | 16766 | 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */ |
| 16601 | 16767 | 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */ |
| 16602 | 16768 | |
| 16603 | 16769 | 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */ |
| | @@ -18181,10 +18347,19 @@ |
| 18181 | 18347 | /* #include <assert.h> */ |
| 18182 | 18348 | #include <time.h> |
| 18183 | 18349 | |
| 18184 | 18350 | #ifndef SQLITE_OMIT_DATETIME_FUNCS |
| 18185 | 18351 | |
| 18352 | +/* |
| 18353 | +** The MSVC CRT on Windows CE may not have a localtime() function. |
| 18354 | +** So declare a substitute. The substitute function itself is |
| 18355 | +** defined in "os_win.c". |
| 18356 | +*/ |
| 18357 | +#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \ |
| 18358 | + (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API) |
| 18359 | +struct tm *__cdecl localtime(const time_t *); |
| 18360 | +#endif |
| 18186 | 18361 | |
| 18187 | 18362 | /* |
| 18188 | 18363 | ** A structure for holding a single date and time. |
| 18189 | 18364 | */ |
| 18190 | 18365 | typedef struct DateTime DateTime; |
| | @@ -18549,10 +18724,11 @@ |
| 18549 | 18724 | p->validYMD = 0; |
| 18550 | 18725 | p->validHMS = 0; |
| 18551 | 18726 | p->validTZ = 0; |
| 18552 | 18727 | } |
| 18553 | 18728 | |
| 18729 | +#ifndef SQLITE_OMIT_LOCALTIME |
| 18554 | 18730 | /* |
| 18555 | 18731 | ** On recent Windows platforms, the localtime_s() function is available |
| 18556 | 18732 | ** as part of the "Secure CRT". It is essentially equivalent to |
| 18557 | 18733 | ** localtime_r() available under most POSIX platforms, except that the |
| 18558 | 18734 | ** order of the parameters is reversed. |
| | @@ -18567,11 +18743,10 @@ |
| 18567 | 18743 | && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE) |
| 18568 | 18744 | #undef HAVE_LOCALTIME_S |
| 18569 | 18745 | #define HAVE_LOCALTIME_S 1 |
| 18570 | 18746 | #endif |
| 18571 | 18747 | |
| 18572 | | -#ifndef SQLITE_OMIT_LOCALTIME |
| 18573 | 18748 | /* |
| 18574 | 18749 | ** The following routine implements the rough equivalent of localtime_r() |
| 18575 | 18750 | ** using whatever operating-system specific localtime facility that |
| 18576 | 18751 | ** is available. This routine returns 0 on success and |
| 18577 | 18752 | ** non-zero on any kind of error. |
| | @@ -19371,17 +19546,15 @@ |
| 19371 | 19546 | ** The following routines are convenience wrappers around methods |
| 19372 | 19547 | ** of the sqlite3_file object. This is mostly just syntactic sugar. All |
| 19373 | 19548 | ** of this would be completely automatic if SQLite were coded using |
| 19374 | 19549 | ** C++ instead of plain old C. |
| 19375 | 19550 | */ |
| 19376 | | -SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file *pId){ |
| 19377 | | - int rc = SQLITE_OK; |
| 19551 | +SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file *pId){ |
| 19378 | 19552 | if( pId->pMethods ){ |
| 19379 | | - rc = pId->pMethods->xClose(pId); |
| 19553 | + pId->pMethods->xClose(pId); |
| 19380 | 19554 | pId->pMethods = 0; |
| 19381 | 19555 | } |
| 19382 | | - return rc; |
| 19383 | 19556 | } |
| 19384 | 19557 | SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){ |
| 19385 | 19558 | DO_OS_MALLOC_TEST(id); |
| 19386 | 19559 | return id->pMethods->xRead(id, pBuf, amt, offset); |
| 19387 | 19560 | } |
| | @@ -19595,16 +19768,14 @@ |
| 19595 | 19768 | }else{ |
| 19596 | 19769 | rc = SQLITE_NOMEM_BKPT; |
| 19597 | 19770 | } |
| 19598 | 19771 | return rc; |
| 19599 | 19772 | } |
| 19600 | | -SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *pFile){ |
| 19601 | | - int rc = SQLITE_OK; |
| 19773 | +SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){ |
| 19602 | 19774 | assert( pFile ); |
| 19603 | | - rc = sqlite3OsClose(pFile); |
| 19775 | + sqlite3OsClose(pFile); |
| 19604 | 19776 | sqlite3_free(pFile); |
| 19605 | | - return rc; |
| 19606 | 19777 | } |
| 19607 | 19778 | |
| 19608 | 19779 | /* |
| 19609 | 19780 | ** This function is a wrapper around the OS specific implementation of |
| 19610 | 19781 | ** sqlite3_os_init(). The purpose of the wrapper is to provide the |
| | @@ -24280,30 +24451,30 @@ |
| 24280 | 24451 | |
| 24281 | 24452 | /* |
| 24282 | 24453 | ** Conversion types fall into various categories as defined by the |
| 24283 | 24454 | ** following enumeration. |
| 24284 | 24455 | */ |
| 24285 | | -#define etRADIX 1 /* Integer types. %d, %x, %o, and so forth */ |
| 24286 | | -#define etFLOAT 2 /* Floating point. %f */ |
| 24287 | | -#define etEXP 3 /* Exponentional notation. %e and %E */ |
| 24288 | | -#define etGENERIC 4 /* Floating or exponential, depending on exponent. %g */ |
| 24289 | | -#define etSIZE 5 /* Return number of characters processed so far. %n */ |
| 24290 | | -#define etSTRING 6 /* Strings. %s */ |
| 24291 | | -#define etDYNSTRING 7 /* Dynamically allocated strings. %z */ |
| 24292 | | -#define etPERCENT 8 /* Percent symbol. %% */ |
| 24293 | | -#define etCHARX 9 /* Characters. %c */ |
| 24456 | +#define etRADIX 0 /* Integer types. %d, %x, %o, and so forth */ |
| 24457 | +#define etFLOAT 1 /* Floating point. %f */ |
| 24458 | +#define etEXP 2 /* Exponentional notation. %e and %E */ |
| 24459 | +#define etGENERIC 3 /* Floating or exponential, depending on exponent. %g */ |
| 24460 | +#define etSIZE 4 /* Return number of characters processed so far. %n */ |
| 24461 | +#define etSTRING 5 /* Strings. %s */ |
| 24462 | +#define etDYNSTRING 6 /* Dynamically allocated strings. %z */ |
| 24463 | +#define etPERCENT 7 /* Percent symbol. %% */ |
| 24464 | +#define etCHARX 8 /* Characters. %c */ |
| 24294 | 24465 | /* The rest are extensions, not normally found in printf() */ |
| 24295 | | -#define etSQLESCAPE 10 /* Strings with '\'' doubled. %q */ |
| 24296 | | -#define etSQLESCAPE2 11 /* Strings with '\'' doubled and enclosed in '', |
| 24466 | +#define etSQLESCAPE 9 /* Strings with '\'' doubled. %q */ |
| 24467 | +#define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '', |
| 24297 | 24468 | NULL pointers replaced by SQL NULL. %Q */ |
| 24298 | | -#define etTOKEN 12 /* a pointer to a Token structure */ |
| 24299 | | -#define etSRCLIST 13 /* a pointer to a SrcList */ |
| 24300 | | -#define etPOINTER 14 /* The %p conversion */ |
| 24301 | | -#define etSQLESCAPE3 15 /* %w -> Strings with '\"' doubled */ |
| 24302 | | -#define etORDINAL 16 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */ |
| 24469 | +#define etTOKEN 11 /* a pointer to a Token structure */ |
| 24470 | +#define etSRCLIST 12 /* a pointer to a SrcList */ |
| 24471 | +#define etPOINTER 13 /* The %p conversion */ |
| 24472 | +#define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */ |
| 24473 | +#define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */ |
| 24303 | 24474 | |
| 24304 | | -#define etINVALID 0 /* Any unrecognized conversion type */ |
| 24475 | +#define etINVALID 16 /* Any unrecognized conversion type */ |
| 24305 | 24476 | |
| 24306 | 24477 | |
| 24307 | 24478 | /* |
| 24308 | 24479 | ** An "etByte" is an 8-bit unsigned value. |
| 24309 | 24480 | */ |
| | @@ -24454,11 +24625,11 @@ |
| 24454 | 24625 | etByte flag_altform2; /* True if "!" flag is present */ |
| 24455 | 24626 | etByte flag_zeropad; /* True if field width constant starts with zero */ |
| 24456 | 24627 | etByte flag_long; /* True if "l" flag is present */ |
| 24457 | 24628 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 24458 | 24629 | etByte done; /* Loop termination flag */ |
| 24459 | | - etByte xtype = 0; /* Conversion paradigm */ |
| 24630 | + etByte xtype = etINVALID; /* Conversion paradigm */ |
| 24460 | 24631 | u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ |
| 24461 | 24632 | u8 useIntern; /* Ok to use internal conversions (ex: %T) */ |
| 24462 | 24633 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 24463 | 24634 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 24464 | 24635 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| | @@ -27045,22 +27216,17 @@ |
| 27045 | 27216 | ** |
| 27046 | 27217 | ** 2002-Feb-14: This routine is extended to remove MS-Access style |
| 27047 | 27218 | ** brackets from around identifiers. For example: "[a-b-c]" becomes |
| 27048 | 27219 | ** "a-b-c". |
| 27049 | 27220 | */ |
| 27050 | | -SQLITE_PRIVATE int sqlite3Dequote(char *z){ |
| 27221 | +SQLITE_PRIVATE void sqlite3Dequote(char *z){ |
| 27051 | 27222 | char quote; |
| 27052 | 27223 | int i, j; |
| 27053 | | - if( z==0 ) return -1; |
| 27224 | + if( z==0 ) return; |
| 27054 | 27225 | quote = z[0]; |
| 27055 | | - switch( quote ){ |
| 27056 | | - case '\'': break; |
| 27057 | | - case '"': break; |
| 27058 | | - case '`': break; /* For MySQL compatibility */ |
| 27059 | | - case '[': quote = ']'; break; /* For MS SqlServer compatibility */ |
| 27060 | | - default: return -1; |
| 27061 | | - } |
| 27226 | + if( !sqlite3Isquote(quote) ) return; |
| 27227 | + if( quote=='[' ) quote = ']'; |
| 27062 | 27228 | for(i=1, j=0;; i++){ |
| 27063 | 27229 | assert( z[i] ); |
| 27064 | 27230 | if( z[i]==quote ){ |
| 27065 | 27231 | if( z[i+1]==quote ){ |
| 27066 | 27232 | z[j++] = quote; |
| | @@ -27071,11 +27237,10 @@ |
| 27071 | 27237 | }else{ |
| 27072 | 27238 | z[j++] = z[i]; |
| 27073 | 27239 | } |
| 27074 | 27240 | } |
| 27075 | 27241 | z[j] = 0; |
| 27076 | | - return j; |
| 27077 | 27242 | } |
| 27078 | 27243 | |
| 27079 | 27244 | /* |
| 27080 | 27245 | ** Generate a Token object from a string |
| 27081 | 27246 | */ |
| | @@ -27164,11 +27329,11 @@ |
| 27164 | 27329 | int esign = 1; /* sign of exponent */ |
| 27165 | 27330 | int e = 0; /* exponent */ |
| 27166 | 27331 | int eValid = 1; /* True exponent is either not used or is well-formed */ |
| 27167 | 27332 | double result; |
| 27168 | 27333 | int nDigits = 0; |
| 27169 | | - int nonNum = 0; |
| 27334 | + int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */ |
| 27170 | 27335 | |
| 27171 | 27336 | assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); |
| 27172 | 27337 | *pResult = 0.0; /* Default return value, in case of an error */ |
| 27173 | 27338 | |
| 27174 | 27339 | if( enc==SQLITE_UTF8 ){ |
| | @@ -27177,11 +27342,11 @@ |
| 27177 | 27342 | int i; |
| 27178 | 27343 | incr = 2; |
| 27179 | 27344 | assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); |
| 27180 | 27345 | for(i=3-enc; i<length && z[i]==0; i+=2){} |
| 27181 | 27346 | nonNum = i<length; |
| 27182 | | - zEnd = z+i+enc-3; |
| 27347 | + zEnd = &z[i^1]; |
| 27183 | 27348 | z += (enc&1); |
| 27184 | 27349 | } |
| 27185 | 27350 | |
| 27186 | 27351 | /* skip leading spaces */ |
| 27187 | 27352 | while( z<zEnd && sqlite3Isspace(*z) ) z+=incr; |
| | @@ -27193,13 +27358,10 @@ |
| 27193 | 27358 | z+=incr; |
| 27194 | 27359 | }else if( *z=='+' ){ |
| 27195 | 27360 | z+=incr; |
| 27196 | 27361 | } |
| 27197 | 27362 | |
| 27198 | | - /* skip leading zeroes */ |
| 27199 | | - while( z<zEnd && z[0]=='0' ) z+=incr, nDigits++; |
| 27200 | | - |
| 27201 | 27363 | /* copy max significant digits to significand */ |
| 27202 | 27364 | while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){ |
| 27203 | 27365 | s = s*10 + (*z - '0'); |
| 27204 | 27366 | z+=incr, nDigits++; |
| 27205 | 27367 | } |
| | @@ -27212,24 +27374,30 @@ |
| 27212 | 27374 | /* if decimal point is present */ |
| 27213 | 27375 | if( *z=='.' ){ |
| 27214 | 27376 | z+=incr; |
| 27215 | 27377 | /* copy digits from after decimal to significand |
| 27216 | 27378 | ** (decrease exponent by d to shift decimal right) */ |
| 27217 | | - while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){ |
| 27218 | | - s = s*10 + (*z - '0'); |
| 27219 | | - z+=incr, nDigits++, d--; |
| 27379 | + while( z<zEnd && sqlite3Isdigit(*z) ){ |
| 27380 | + if( s<((LARGEST_INT64-9)/10) ){ |
| 27381 | + s = s*10 + (*z - '0'); |
| 27382 | + d--; |
| 27383 | + } |
| 27384 | + z+=incr, nDigits++; |
| 27220 | 27385 | } |
| 27221 | | - /* skip non-significant digits */ |
| 27222 | | - while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++; |
| 27223 | 27386 | } |
| 27224 | 27387 | if( z>=zEnd ) goto do_atof_calc; |
| 27225 | 27388 | |
| 27226 | 27389 | /* if exponent is present */ |
| 27227 | 27390 | if( *z=='e' || *z=='E' ){ |
| 27228 | 27391 | z+=incr; |
| 27229 | 27392 | eValid = 0; |
| 27230 | | - if( z>=zEnd ) goto do_atof_calc; |
| 27393 | + |
| 27394 | + /* This branch is needed to avoid a (harmless) buffer overread. The |
| 27395 | + ** special comment alerts the mutation tester that the correct answer |
| 27396 | + ** is obtained even if the branch is omitted */ |
| 27397 | + if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/ |
| 27398 | + |
| 27231 | 27399 | /* get sign of exponent */ |
| 27232 | 27400 | if( *z=='-' ){ |
| 27233 | 27401 | esign = -1; |
| 27234 | 27402 | z+=incr; |
| 27235 | 27403 | }else if( *z=='+' ){ |
| | @@ -27242,13 +27410,11 @@ |
| 27242 | 27410 | eValid = 1; |
| 27243 | 27411 | } |
| 27244 | 27412 | } |
| 27245 | 27413 | |
| 27246 | 27414 | /* skip trailing spaces */ |
| 27247 | | - if( nDigits && eValid ){ |
| 27248 | | - while( z<zEnd && sqlite3Isspace(*z) ) z+=incr; |
| 27249 | | - } |
| 27415 | + while( z<zEnd && sqlite3Isspace(*z) ) z+=incr; |
| 27250 | 27416 | |
| 27251 | 27417 | do_atof_calc: |
| 27252 | 27418 | /* adjust exponent by d, and update sign */ |
| 27253 | 27419 | e = (e*esign) + d; |
| 27254 | 27420 | if( e<0 ) { |
| | @@ -27256,45 +27422,55 @@ |
| 27256 | 27422 | e *= -1; |
| 27257 | 27423 | } else { |
| 27258 | 27424 | esign = 1; |
| 27259 | 27425 | } |
| 27260 | 27426 | |
| 27261 | | - /* if 0 significand */ |
| 27262 | | - if( !s ) { |
| 27263 | | - /* In the IEEE 754 standard, zero is signed. |
| 27264 | | - ** Add the sign if we've seen at least one digit */ |
| 27265 | | - result = (sign<0 && nDigits) ? -(double)0 : (double)0; |
| 27427 | + if( s==0 ) { |
| 27428 | + /* In the IEEE 754 standard, zero is signed. */ |
| 27429 | + result = sign<0 ? -(double)0 : (double)0; |
| 27266 | 27430 | } else { |
| 27267 | | - /* attempt to reduce exponent */ |
| 27268 | | - if( esign>0 ){ |
| 27269 | | - while( s<(LARGEST_INT64/10) && e>0 ) e--,s*=10; |
| 27270 | | - }else{ |
| 27271 | | - while( !(s%10) && e>0 ) e--,s/=10; |
| 27431 | + /* Attempt to reduce exponent. |
| 27432 | + ** |
| 27433 | + ** Branches that are not required for the correct answer but which only |
| 27434 | + ** help to obtain the correct answer faster are marked with special |
| 27435 | + ** comments, as a hint to the mutation tester. |
| 27436 | + */ |
| 27437 | + while( e>0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 27438 | + if( esign>0 ){ |
| 27439 | + if( s>=(LARGEST_INT64/10) ) break; /*OPTIMIZATION-IF-FALSE*/ |
| 27440 | + s *= 10; |
| 27441 | + }else{ |
| 27442 | + if( s%10!=0 ) break; /*OPTIMIZATION-IF-FALSE*/ |
| 27443 | + s /= 10; |
| 27444 | + } |
| 27445 | + e--; |
| 27272 | 27446 | } |
| 27273 | 27447 | |
| 27274 | 27448 | /* adjust the sign of significand */ |
| 27275 | 27449 | s = sign<0 ? -s : s; |
| 27276 | 27450 | |
| 27277 | | - /* if exponent, scale significand as appropriate |
| 27278 | | - ** and store in result. */ |
| 27279 | | - if( e ){ |
| 27451 | + if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 27452 | + result = (double)s; |
| 27453 | + }else{ |
| 27280 | 27454 | LONGDOUBLE_TYPE scale = 1.0; |
| 27281 | 27455 | /* attempt to handle extremely small/large numbers better */ |
| 27282 | | - if( e>307 && e<342 ){ |
| 27283 | | - while( e%308 ) { scale *= 1.0e+1; e -= 1; } |
| 27284 | | - if( esign<0 ){ |
| 27285 | | - result = s / scale; |
| 27286 | | - result /= 1.0e+308; |
| 27287 | | - }else{ |
| 27288 | | - result = s * scale; |
| 27289 | | - result *= 1.0e+308; |
| 27290 | | - } |
| 27291 | | - }else if( e>=342 ){ |
| 27292 | | - if( esign<0 ){ |
| 27293 | | - result = 0.0*s; |
| 27294 | | - }else{ |
| 27295 | | - result = 1e308*1e308*s; /* Infinity */ |
| 27456 | + if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 27457 | + if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 27458 | + while( e%308 ) { scale *= 1.0e+1; e -= 1; } |
| 27459 | + if( esign<0 ){ |
| 27460 | + result = s / scale; |
| 27461 | + result /= 1.0e+308; |
| 27462 | + }else{ |
| 27463 | + result = s * scale; |
| 27464 | + result *= 1.0e+308; |
| 27465 | + } |
| 27466 | + }else{ assert( e>=342 ); |
| 27467 | + if( esign<0 ){ |
| 27468 | + result = 0.0*s; |
| 27469 | + }else{ |
| 27470 | + result = 1e308*1e308*s; /* Infinity */ |
| 27471 | + } |
| 27296 | 27472 | } |
| 27297 | 27473 | }else{ |
| 27298 | 27474 | /* 1.0e+22 is the largest power of 10 than can be |
| 27299 | 27475 | ** represented exactly. */ |
| 27300 | 27476 | while( e%22 ) { scale *= 1.0e+1; e -= 1; } |
| | @@ -27303,20 +27479,18 @@ |
| 27303 | 27479 | result = s / scale; |
| 27304 | 27480 | }else{ |
| 27305 | 27481 | result = s * scale; |
| 27306 | 27482 | } |
| 27307 | 27483 | } |
| 27308 | | - } else { |
| 27309 | | - result = (double)s; |
| 27310 | 27484 | } |
| 27311 | 27485 | } |
| 27312 | 27486 | |
| 27313 | 27487 | /* store the result */ |
| 27314 | 27488 | *pResult = result; |
| 27315 | 27489 | |
| 27316 | 27490 | /* return true if number and no extra non-whitespace chracters after */ |
| 27317 | | - return z>=zEnd && nDigits>0 && eValid && nonNum==0; |
| 27491 | + return z==zEnd && nDigits>0 && eValid && nonNum==0; |
| 27318 | 27492 | #else |
| 27319 | 27493 | return !sqlite3Atoi64(z, pResult, length, enc); |
| 27320 | 27494 | #endif /* SQLITE_OMIT_FLOATING_POINT */ |
| 27321 | 27495 | } |
| 27322 | 27496 | |
| | @@ -27374,11 +27548,11 @@ |
| 27374 | 27548 | int incr; |
| 27375 | 27549 | u64 u = 0; |
| 27376 | 27550 | int neg = 0; /* assume positive */ |
| 27377 | 27551 | int i; |
| 27378 | 27552 | int c = 0; |
| 27379 | | - int nonNum = 0; |
| 27553 | + int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */ |
| 27380 | 27554 | const char *zStart; |
| 27381 | 27555 | const char *zEnd = zNum + length; |
| 27382 | 27556 | assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); |
| 27383 | 27557 | if( enc==SQLITE_UTF8 ){ |
| 27384 | 27558 | incr = 1; |
| | @@ -27385,11 +27559,11 @@ |
| 27385 | 27559 | }else{ |
| 27386 | 27560 | incr = 2; |
| 27387 | 27561 | assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 ); |
| 27388 | 27562 | for(i=3-enc; i<length && zNum[i]==0; i+=2){} |
| 27389 | 27563 | nonNum = i<length; |
| 27390 | | - zEnd = zNum+i+enc-3; |
| 27564 | + zEnd = &zNum[i^1]; |
| 27391 | 27565 | zNum += (enc&1); |
| 27392 | 27566 | } |
| 27393 | 27567 | while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr; |
| 27394 | 27568 | if( zNum<zEnd ){ |
| 27395 | 27569 | if( *zNum=='-' ){ |
| | @@ -27412,12 +27586,15 @@ |
| 27412 | 27586 | *pNum = (i64)u; |
| 27413 | 27587 | } |
| 27414 | 27588 | testcase( i==18 ); |
| 27415 | 27589 | testcase( i==19 ); |
| 27416 | 27590 | testcase( i==20 ); |
| 27417 | | - if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum) |
| 27418 | | - || i>19*incr || nonNum ){ |
| 27591 | + if( &zNum[i]<zEnd /* Extra bytes at the end */ |
| 27592 | + || (i==0 && zStart==zNum) /* No digits */ |
| 27593 | + || i>19*incr /* Too many digits */ |
| 27594 | + || nonNum /* UTF16 with high-order bytes non-zero */ |
| 27595 | + ){ |
| 27419 | 27596 | /* zNum is empty or contains non-numeric text or is longer |
| 27420 | 27597 | ** than 19 digits (thus guaranteeing that it is too large) */ |
| 27421 | 27598 | return 1; |
| 27422 | 27599 | }else if( i<19*incr ){ |
| 27423 | 27600 | /* Less than 19 digits, so we know that it fits in 64 bits */ |
| | @@ -27455,11 +27632,10 @@ |
| 27455 | 27632 | */ |
| 27456 | 27633 | SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){ |
| 27457 | 27634 | #ifndef SQLITE_OMIT_HEX_INTEGER |
| 27458 | 27635 | if( z[0]=='0' |
| 27459 | 27636 | && (z[1]=='x' || z[1]=='X') |
| 27460 | | - && sqlite3Isxdigit(z[2]) |
| 27461 | 27637 | ){ |
| 27462 | 27638 | u64 u = 0; |
| 27463 | 27639 | int i, k; |
| 27464 | 27640 | for(i=2; z[i]=='0'; i++){} |
| 27465 | 27641 | for(k=i; sqlite3Isxdigit(z[k]); k++){ |
| | @@ -28217,11 +28393,11 @@ |
| 28217 | 28393 | LogEst y = 40; |
| 28218 | 28394 | if( x<8 ){ |
| 28219 | 28395 | if( x<2 ) return 0; |
| 28220 | 28396 | while( x<8 ){ y -= 10; x <<= 1; } |
| 28221 | 28397 | }else{ |
| 28222 | | - while( x>255 ){ y += 40; x >>= 4; } |
| 28398 | + while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/ |
| 28223 | 28399 | while( x>15 ){ y += 10; x >>= 1; } |
| 28224 | 28400 | } |
| 28225 | 28401 | return a[x&7] + y - 10; |
| 28226 | 28402 | } |
| 28227 | 28403 | |
| | @@ -28326,11 +28502,11 @@ |
| 28326 | 28502 | ** The hashing function. |
| 28327 | 28503 | */ |
| 28328 | 28504 | static unsigned int strHash(const char *z){ |
| 28329 | 28505 | unsigned int h = 0; |
| 28330 | 28506 | unsigned char c; |
| 28331 | | - while( (c = (unsigned char)*z++)!=0 ){ |
| 28507 | + while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 28332 | 28508 | h = (h<<3) ^ h ^ sqlite3UpperToLower[c]; |
| 28333 | 28509 | } |
| 28334 | 28510 | return h; |
| 28335 | 28511 | } |
| 28336 | 28512 | |
| | @@ -28419,11 +28595,11 @@ |
| 28419 | 28595 | ){ |
| 28420 | 28596 | HashElem *elem; /* Used to loop thru the element list */ |
| 28421 | 28597 | int count; /* Number of elements left to test */ |
| 28422 | 28598 | unsigned int h; /* The computed hash */ |
| 28423 | 28599 | |
| 28424 | | - if( pH->ht ){ |
| 28600 | + if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/ |
| 28425 | 28601 | struct _ht *pEntry; |
| 28426 | 28602 | h = strHash(pKey) % pH->htsize; |
| 28427 | 28603 | pEntry = &pH->ht[h]; |
| 28428 | 28604 | elem = pEntry->chain; |
| 28429 | 28605 | count = pEntry->count; |
| | @@ -28566,157 +28742,156 @@ |
| 28566 | 28742 | /* 10 */ "Vacuum" OpHelp(""), |
| 28567 | 28743 | /* 11 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), |
| 28568 | 28744 | /* 12 */ "VUpdate" OpHelp("data=r[P3@P2]"), |
| 28569 | 28745 | /* 13 */ "Goto" OpHelp(""), |
| 28570 | 28746 | /* 14 */ "Gosub" OpHelp(""), |
| 28571 | | - /* 15 */ "Return" OpHelp(""), |
| 28572 | | - /* 16 */ "InitCoroutine" OpHelp(""), |
| 28573 | | - /* 17 */ "EndCoroutine" OpHelp(""), |
| 28574 | | - /* 18 */ "Yield" OpHelp(""), |
| 28747 | + /* 15 */ "InitCoroutine" OpHelp(""), |
| 28748 | + /* 16 */ "Yield" OpHelp(""), |
| 28749 | + /* 17 */ "MustBeInt" OpHelp(""), |
| 28750 | + /* 18 */ "Jump" OpHelp(""), |
| 28575 | 28751 | /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), |
| 28576 | | - /* 20 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 28577 | | - /* 21 */ "Halt" OpHelp(""), |
| 28578 | | - /* 22 */ "Integer" OpHelp("r[P2]=P1"), |
| 28579 | | - /* 23 */ "Int64" OpHelp("r[P2]=P4"), |
| 28580 | | - /* 24 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 28581 | | - /* 25 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 28582 | | - /* 26 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 28583 | | - /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 28584 | | - /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 28585 | | - /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 28586 | | - /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 28587 | | - /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 28588 | | - /* 32 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 28589 | | - /* 33 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 28590 | | - /* 34 */ "CollSeq" OpHelp(""), |
| 28591 | | - /* 35 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), |
| 28592 | | - /* 36 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 28593 | | - /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 28594 | | - /* 38 */ "MustBeInt" OpHelp(""), |
| 28595 | | - /* 39 */ "RealAffinity" OpHelp(""), |
| 28596 | | - /* 40 */ "Cast" OpHelp("affinity(r[P1])"), |
| 28597 | | - /* 41 */ "Permutation" OpHelp(""), |
| 28598 | | - /* 42 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 28599 | | - /* 43 */ "Jump" OpHelp(""), |
| 28600 | | - /* 44 */ "Once" OpHelp(""), |
| 28601 | | - /* 45 */ "If" OpHelp(""), |
| 28602 | | - /* 46 */ "IfNot" OpHelp(""), |
| 28603 | | - /* 47 */ "Column" OpHelp("r[P3]=PX"), |
| 28604 | | - /* 48 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 28605 | | - /* 49 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 28606 | | - /* 50 */ "Count" OpHelp("r[P2]=count()"), |
| 28607 | | - /* 51 */ "ReadCookie" OpHelp(""), |
| 28608 | | - /* 52 */ "SetCookie" OpHelp(""), |
| 28609 | | - /* 53 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 28610 | | - /* 54 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 28611 | | - /* 55 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 28612 | | - /* 56 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 28613 | | - /* 57 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 28614 | | - /* 58 */ "SorterOpen" OpHelp(""), |
| 28615 | | - /* 59 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 28616 | | - /* 60 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 28617 | | - /* 61 */ "Close" OpHelp(""), |
| 28618 | | - /* 62 */ "ColumnsUsed" OpHelp(""), |
| 28619 | | - /* 63 */ "SeekLT" OpHelp("key=r[P3@P4]"), |
| 28620 | | - /* 64 */ "SeekLE" OpHelp("key=r[P3@P4]"), |
| 28621 | | - /* 65 */ "SeekGE" OpHelp("key=r[P3@P4]"), |
| 28622 | | - /* 66 */ "SeekGT" OpHelp("key=r[P3@P4]"), |
| 28623 | | - /* 67 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 28624 | | - /* 68 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 28625 | | - /* 69 */ "Found" OpHelp("key=r[P3@P4]"), |
| 28626 | | - /* 70 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 28627 | | - /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| 28628 | | - /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), |
| 28629 | | - /* 73 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 28630 | | - /* 74 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 28631 | | - /* 75 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 28632 | | - /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), |
| 28633 | | - /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), |
| 28634 | | - /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"), |
| 28635 | | - /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"), |
| 28636 | | - /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"), |
| 28637 | | - /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"), |
| 28638 | | - /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"), |
| 28639 | | - /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"), |
| 28640 | | - /* 84 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 28641 | | - /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 28642 | | - /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 28643 | | - /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 28644 | | - /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 28645 | | - /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| 28646 | | - /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 28647 | | - /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 28648 | | - /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 28649 | | - /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 28650 | | - /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 28651 | | - /* 95 */ "Delete" OpHelp(""), |
| 28652 | | - /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), |
| 28752 | + /* 20 */ "Once" OpHelp(""), |
| 28753 | + /* 21 */ "If" OpHelp(""), |
| 28754 | + /* 22 */ "IfNot" OpHelp(""), |
| 28755 | + /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"), |
| 28756 | + /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"), |
| 28757 | + /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"), |
| 28758 | + /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"), |
| 28759 | + /* 27 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| 28760 | + /* 28 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), |
| 28761 | + /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 28762 | + /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 28763 | + /* 31 */ "Found" OpHelp("key=r[P3@P4]"), |
| 28764 | + /* 32 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 28765 | + /* 33 */ "Last" OpHelp(""), |
| 28766 | + /* 34 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), |
| 28767 | + /* 35 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), |
| 28768 | + /* 36 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"), |
| 28769 | + /* 37 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"), |
| 28770 | + /* 38 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"), |
| 28771 | + /* 39 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"), |
| 28772 | + /* 40 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"), |
| 28773 | + /* 41 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"), |
| 28774 | + /* 42 */ "SorterSort" OpHelp(""), |
| 28775 | + /* 43 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 28776 | + /* 44 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 28777 | + /* 45 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 28778 | + /* 46 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 28779 | + /* 47 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| 28780 | + /* 48 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 28781 | + /* 49 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 28782 | + /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 28783 | + /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 28784 | + /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 28785 | + /* 53 */ "Sort" OpHelp(""), |
| 28786 | + /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), |
| 28787 | + /* 55 */ "Rewind" OpHelp(""), |
| 28788 | + /* 56 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 28789 | + /* 57 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 28790 | + /* 58 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 28791 | + /* 59 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 28792 | + /* 60 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 28793 | + /* 61 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 28794 | + /* 62 */ "Program" OpHelp(""), |
| 28795 | + /* 63 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 28796 | + /* 64 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), |
| 28797 | + /* 65 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"), |
| 28798 | + /* 66 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 28799 | + /* 67 */ "IncrVacuum" OpHelp(""), |
| 28800 | + /* 68 */ "VNext" OpHelp(""), |
| 28801 | + /* 69 */ "Init" OpHelp("Start at P2"), |
| 28802 | + /* 70 */ "Return" OpHelp(""), |
| 28803 | + /* 71 */ "EndCoroutine" OpHelp(""), |
| 28804 | + /* 72 */ "HaltIfNull" OpHelp("if r[P3]=null halt"), |
| 28805 | + /* 73 */ "Halt" OpHelp(""), |
| 28806 | + /* 74 */ "Integer" OpHelp("r[P2]=P1"), |
| 28807 | + /* 75 */ "Int64" OpHelp("r[P2]=P4"), |
| 28808 | + /* 76 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 28809 | + /* 77 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 28810 | + /* 78 */ "SoftNull" OpHelp("r[P1]=NULL"), |
| 28811 | + /* 79 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 28812 | + /* 80 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 28813 | + /* 81 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 28814 | + /* 82 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 28815 | + /* 83 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 28816 | + /* 84 */ "IntCopy" OpHelp("r[P2]=r[P1]"), |
| 28817 | + /* 85 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 28818 | + /* 86 */ "CollSeq" OpHelp(""), |
| 28819 | + /* 87 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"), |
| 28820 | + /* 88 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 28821 | + /* 89 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 28822 | + /* 90 */ "RealAffinity" OpHelp(""), |
| 28823 | + /* 91 */ "Cast" OpHelp("affinity(r[P1])"), |
| 28824 | + /* 92 */ "Permutation" OpHelp(""), |
| 28825 | + /* 93 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"), |
| 28826 | + /* 94 */ "Column" OpHelp("r[P3]=PX"), |
| 28827 | + /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 28828 | + /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 28653 | 28829 | /* 97 */ "String8" OpHelp("r[P2]='P4'"), |
| 28654 | | - /* 98 */ "ResetCount" OpHelp(""), |
| 28655 | | - /* 99 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 28656 | | - /* 100 */ "SorterData" OpHelp("r[P2]=data"), |
| 28657 | | - /* 101 */ "RowKey" OpHelp("r[P2]=key"), |
| 28658 | | - /* 102 */ "RowData" OpHelp("r[P2]=data"), |
| 28659 | | - /* 103 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 28660 | | - /* 104 */ "NullRow" OpHelp(""), |
| 28661 | | - /* 105 */ "Last" OpHelp(""), |
| 28662 | | - /* 106 */ "SorterSort" OpHelp(""), |
| 28663 | | - /* 107 */ "Sort" OpHelp(""), |
| 28664 | | - /* 108 */ "Rewind" OpHelp(""), |
| 28665 | | - /* 109 */ "SorterInsert" OpHelp(""), |
| 28666 | | - /* 110 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 28667 | | - /* 111 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 28668 | | - /* 112 */ "Seek" OpHelp("Move P3 to P1.rowid"), |
| 28669 | | - /* 113 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 28670 | | - /* 114 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 28671 | | - /* 115 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 28672 | | - /* 116 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 28673 | | - /* 117 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 28674 | | - /* 118 */ "Destroy" OpHelp(""), |
| 28675 | | - /* 119 */ "Clear" OpHelp(""), |
| 28676 | | - /* 120 */ "ResetSorter" OpHelp(""), |
| 28677 | | - /* 121 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 28678 | | - /* 122 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 28679 | | - /* 123 */ "ParseSchema" OpHelp(""), |
| 28680 | | - /* 124 */ "LoadAnalysis" OpHelp(""), |
| 28681 | | - /* 125 */ "DropTable" OpHelp(""), |
| 28682 | | - /* 126 */ "DropIndex" OpHelp(""), |
| 28683 | | - /* 127 */ "DropTrigger" OpHelp(""), |
| 28684 | | - /* 128 */ "IntegrityCk" OpHelp(""), |
| 28685 | | - /* 129 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 28686 | | - /* 130 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 28687 | | - /* 131 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 28688 | | - /* 132 */ "Program" OpHelp(""), |
| 28830 | + /* 98 */ "Count" OpHelp("r[P2]=count()"), |
| 28831 | + /* 99 */ "ReadCookie" OpHelp(""), |
| 28832 | + /* 100 */ "SetCookie" OpHelp(""), |
| 28833 | + /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"), |
| 28834 | + /* 102 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 28835 | + /* 103 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 28836 | + /* 104 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 28837 | + /* 105 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 28838 | + /* 106 */ "SorterOpen" OpHelp(""), |
| 28839 | + /* 107 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"), |
| 28840 | + /* 108 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"), |
| 28841 | + /* 109 */ "Close" OpHelp(""), |
| 28842 | + /* 110 */ "ColumnsUsed" OpHelp(""), |
| 28843 | + /* 111 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"), |
| 28844 | + /* 112 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 28845 | + /* 113 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 28846 | + /* 114 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 28847 | + /* 115 */ "Delete" OpHelp(""), |
| 28848 | + /* 116 */ "ResetCount" OpHelp(""), |
| 28849 | + /* 117 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 28850 | + /* 118 */ "SorterData" OpHelp("r[P2]=data"), |
| 28851 | + /* 119 */ "RowKey" OpHelp("r[P2]=key"), |
| 28852 | + /* 120 */ "RowData" OpHelp("r[P2]=data"), |
| 28853 | + /* 121 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 28854 | + /* 122 */ "NullRow" OpHelp(""), |
| 28855 | + /* 123 */ "SorterInsert" OpHelp(""), |
| 28856 | + /* 124 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 28857 | + /* 125 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 28858 | + /* 126 */ "Seek" OpHelp("Move P3 to P1.rowid"), |
| 28859 | + /* 127 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 28860 | + /* 128 */ "Destroy" OpHelp(""), |
| 28861 | + /* 129 */ "Clear" OpHelp(""), |
| 28862 | + /* 130 */ "ResetSorter" OpHelp(""), |
| 28863 | + /* 131 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 28864 | + /* 132 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 28689 | 28865 | /* 133 */ "Real" OpHelp("r[P2]=P4"), |
| 28690 | | - /* 134 */ "Param" OpHelp(""), |
| 28691 | | - /* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 28692 | | - /* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 28693 | | - /* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 28694 | | - /* 138 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"), |
| 28695 | | - /* 139 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 28696 | | - /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"), |
| 28697 | | - /* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"), |
| 28698 | | - /* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"), |
| 28699 | | - /* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 28700 | | - /* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 28701 | | - /* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 28702 | | - /* 146 */ "IncrVacuum" OpHelp(""), |
| 28703 | | - /* 147 */ "Expire" OpHelp(""), |
| 28704 | | - /* 148 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 28705 | | - /* 149 */ "VBegin" OpHelp(""), |
| 28706 | | - /* 150 */ "VCreate" OpHelp(""), |
| 28707 | | - /* 151 */ "VDestroy" OpHelp(""), |
| 28708 | | - /* 152 */ "VOpen" OpHelp(""), |
| 28709 | | - /* 153 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 28710 | | - /* 154 */ "VNext" OpHelp(""), |
| 28866 | + /* 134 */ "ParseSchema" OpHelp(""), |
| 28867 | + /* 135 */ "LoadAnalysis" OpHelp(""), |
| 28868 | + /* 136 */ "DropTable" OpHelp(""), |
| 28869 | + /* 137 */ "DropIndex" OpHelp(""), |
| 28870 | + /* 138 */ "DropTrigger" OpHelp(""), |
| 28871 | + /* 139 */ "IntegrityCk" OpHelp(""), |
| 28872 | + /* 140 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 28873 | + /* 141 */ "Param" OpHelp(""), |
| 28874 | + /* 142 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 28875 | + /* 143 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 28876 | + /* 144 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 28877 | + /* 145 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 28878 | + /* 146 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 28879 | + /* 147 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 28880 | + /* 148 */ "Expire" OpHelp(""), |
| 28881 | + /* 149 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 28882 | + /* 150 */ "VBegin" OpHelp(""), |
| 28883 | + /* 151 */ "VCreate" OpHelp(""), |
| 28884 | + /* 152 */ "VDestroy" OpHelp(""), |
| 28885 | + /* 153 */ "VOpen" OpHelp(""), |
| 28886 | + /* 154 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 28711 | 28887 | /* 155 */ "VRename" OpHelp(""), |
| 28712 | 28888 | /* 156 */ "Pagecount" OpHelp(""), |
| 28713 | 28889 | /* 157 */ "MaxPgcnt" OpHelp(""), |
| 28714 | | - /* 158 */ "Init" OpHelp("Start at P2"), |
| 28715 | | - /* 159 */ "CursorHint" OpHelp(""), |
| 28716 | | - /* 160 */ "Noop" OpHelp(""), |
| 28717 | | - /* 161 */ "Explain" OpHelp(""), |
| 28890 | + /* 158 */ "CursorHint" OpHelp(""), |
| 28891 | + /* 159 */ "Noop" OpHelp(""), |
| 28892 | + /* 160 */ "Explain" OpHelp(""), |
| 28718 | 28893 | }; |
| 28719 | 28894 | return azName[i]; |
| 28720 | 28895 | } |
| 28721 | 28896 | #endif |
| 28722 | 28897 | |
| | @@ -29325,11 +29500,11 @@ |
| 29325 | 29500 | #if defined(USE_PREAD64) |
| 29326 | 29501 | { "pread64", (sqlite3_syscall_ptr)pread64, 0 }, |
| 29327 | 29502 | #else |
| 29328 | 29503 | { "pread64", (sqlite3_syscall_ptr)0, 0 }, |
| 29329 | 29504 | #endif |
| 29330 | | -#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent) |
| 29505 | +#define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent) |
| 29331 | 29506 | |
| 29332 | 29507 | { "write", (sqlite3_syscall_ptr)write, 0 }, |
| 29333 | 29508 | #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent) |
| 29334 | 29509 | |
| 29335 | 29510 | #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE |
| | @@ -29343,11 +29518,11 @@ |
| 29343 | 29518 | #if defined(USE_PREAD64) |
| 29344 | 29519 | { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 }, |
| 29345 | 29520 | #else |
| 29346 | 29521 | { "pwrite64", (sqlite3_syscall_ptr)0, 0 }, |
| 29347 | 29522 | #endif |
| 29348 | | -#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\ |
| 29523 | +#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\ |
| 29349 | 29524 | aSyscall[13].pCurrent) |
| 29350 | 29525 | |
| 29351 | 29526 | { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 }, |
| 29352 | 29527 | #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent) |
| 29353 | 29528 | |
| | @@ -33208,14 +33383,16 @@ |
| 33208 | 33383 | sqlite3FileSuffix3(pDbFd->zPath, zShmFilename); |
| 33209 | 33384 | #endif |
| 33210 | 33385 | pShmNode->h = -1; |
| 33211 | 33386 | pDbFd->pInode->pShmNode = pShmNode; |
| 33212 | 33387 | pShmNode->pInode = pDbFd->pInode; |
| 33213 | | - pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| 33214 | | - if( pShmNode->mutex==0 ){ |
| 33215 | | - rc = SQLITE_NOMEM_BKPT; |
| 33216 | | - goto shm_open_err; |
| 33388 | + if( sqlite3GlobalConfig.bCoreMutex ){ |
| 33389 | + pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| 33390 | + if( pShmNode->mutex==0 ){ |
| 33391 | + rc = SQLITE_NOMEM_BKPT; |
| 33392 | + goto shm_open_err; |
| 33393 | + } |
| 33217 | 33394 | } |
| 33218 | 33395 | |
| 33219 | 33396 | if( pInode->bProcessLock==0 ){ |
| 33220 | 33397 | int openFlags = O_RDWR | O_CREAT; |
| 33221 | 33398 | if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){ |
| | @@ -34330,24 +34507,28 @@ |
| 34330 | 34507 | "/var/tmp", |
| 34331 | 34508 | "/usr/tmp", |
| 34332 | 34509 | "/tmp", |
| 34333 | 34510 | "." |
| 34334 | 34511 | }; |
| 34335 | | - unsigned int i; |
| 34512 | + unsigned int i = 0; |
| 34336 | 34513 | struct stat buf; |
| 34337 | 34514 | const char *zDir = sqlite3_temp_directory; |
| 34338 | 34515 | |
| 34339 | 34516 | if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR"); |
| 34340 | 34517 | if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR"); |
| 34341 | | - for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){ |
| 34342 | | - if( zDir==0 ) continue; |
| 34343 | | - if( osStat(zDir, &buf) ) continue; |
| 34344 | | - if( !S_ISDIR(buf.st_mode) ) continue; |
| 34345 | | - if( osAccess(zDir, 07) ) continue; |
| 34346 | | - break; |
| 34347 | | - } |
| 34348 | | - return zDir; |
| 34518 | + while(1){ |
| 34519 | + if( zDir!=0 |
| 34520 | + && osStat(zDir, &buf)==0 |
| 34521 | + && S_ISDIR(buf.st_mode) |
| 34522 | + && osAccess(zDir, 03)==0 |
| 34523 | + ){ |
| 34524 | + return zDir; |
| 34525 | + } |
| 34526 | + if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break; |
| 34527 | + zDir = azDirs[i++]; |
| 34528 | + } |
| 34529 | + return 0; |
| 34349 | 34530 | } |
| 34350 | 34531 | |
| 34351 | 34532 | /* |
| 34352 | 34533 | ** Create a temporary file name in zBuf. zBuf must be allocated |
| 34353 | 34534 | ** by the calling process and must be big enough to hold at least |
| | @@ -34359,13 +34540,15 @@ |
| 34359 | 34540 | |
| 34360 | 34541 | /* It's odd to simulate an io-error here, but really this is just |
| 34361 | 34542 | ** using the io-error infrastructure to test that SQLite handles this |
| 34362 | 34543 | ** function failing. |
| 34363 | 34544 | */ |
| 34545 | + zBuf[0] = 0; |
| 34364 | 34546 | SimulateIOError( return SQLITE_IOERR ); |
| 34365 | 34547 | |
| 34366 | 34548 | zDir = unixTempFileDir(); |
| 34549 | + if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH; |
| 34367 | 34550 | do{ |
| 34368 | 34551 | u64 r; |
| 34369 | 34552 | sqlite3_randomness(sizeof(r), &r); |
| 34370 | 34553 | assert( nBuf>2 ); |
| 34371 | 34554 | zBuf[nBuf-2] = 0; |
| | @@ -37963,12 +38146,12 @@ |
| 37963 | 38146 | */ |
| 37964 | 38147 | SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){ |
| 37965 | 38148 | int rc; |
| 37966 | 38149 | MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ |
| 37967 | 38150 | MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */ |
| 37968 | | - MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 37969 | | - MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); ) |
| 38151 | + MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); ) |
| 38152 | + MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); ) |
| 37970 | 38153 | sqlite3_mutex_enter(pMaster); |
| 37971 | 38154 | sqlite3_mutex_enter(pMem); |
| 37972 | 38155 | winMemAssertMagic(); |
| 37973 | 38156 | if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){ |
| 37974 | 38157 | /* |
| | @@ -38821,20 +39004,21 @@ |
| 38821 | 39004 | winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno |
| 38822 | 39005 | ); |
| 38823 | 39006 | } |
| 38824 | 39007 | } |
| 38825 | 39008 | |
| 38826 | | -#if SQLITE_OS_WINCE |
| 38827 | | -/************************************************************************* |
| 38828 | | -** This section contains code for WinCE only. |
| 38829 | | -*/ |
| 38830 | | -#if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API |
| 38831 | | -/* |
| 38832 | | -** The MSVC CRT on Windows CE may not have a localtime() function. So |
| 38833 | | -** create a substitute. |
| 38834 | | -*/ |
| 38835 | | -/* #include <time.h> */ |
| 39009 | +/* |
| 39010 | +** This #if does not rely on the SQLITE_OS_WINCE define because the |
| 39011 | +** corresponding section in "date.c" cannot use it. |
| 39012 | +*/ |
| 39013 | +#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \ |
| 39014 | + (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API) |
| 39015 | +/* |
| 39016 | +** The MSVC CRT on Windows CE may not have a localtime() function. |
| 39017 | +** So define a substitute. |
| 39018 | +*/ |
| 39019 | +/* # include <time.h> */ |
| 38836 | 39020 | struct tm *__cdecl localtime(const time_t *t) |
| 38837 | 39021 | { |
| 38838 | 39022 | static struct tm y; |
| 38839 | 39023 | FILETIME uTm, lTm; |
| 38840 | 39024 | SYSTEMTIME pTm; |
| | @@ -38854,10 +39038,14 @@ |
| 38854 | 39038 | y.tm_sec = pTm.wSecond; |
| 38855 | 39039 | return &y; |
| 38856 | 39040 | } |
| 38857 | 39041 | #endif |
| 38858 | 39042 | |
| 39043 | +#if SQLITE_OS_WINCE |
| 39044 | +/************************************************************************* |
| 39045 | +** This section contains code for WinCE only. |
| 39046 | +*/ |
| 38859 | 39047 | #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)] |
| 38860 | 39048 | |
| 38861 | 39049 | /* |
| 38862 | 39050 | ** Acquire a lock on the handle h |
| 38863 | 39051 | */ |
| | @@ -39867,13 +40055,12 @@ |
| 39867 | 40055 | /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or |
| 39868 | 40056 | ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of |
| 39869 | 40057 | ** the PENDING_LOCK byte is temporary. |
| 39870 | 40058 | */ |
| 39871 | 40059 | newLocktype = pFile->locktype; |
| 39872 | | - if( (pFile->locktype==NO_LOCK) |
| 39873 | | - || ( (locktype==EXCLUSIVE_LOCK) |
| 39874 | | - && (pFile->locktype==RESERVED_LOCK)) |
| 40060 | + if( pFile->locktype==NO_LOCK |
| 40061 | + || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK) |
| 39875 | 40062 | ){ |
| 39876 | 40063 | int cnt = 3; |
| 39877 | 40064 | while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS, |
| 39878 | 40065 | PENDING_BYTE, 0, 1, 0))==0 ){ |
| 39879 | 40066 | /* Try 3 times to get the pending lock. This is needed to work |
| | @@ -40463,14 +40650,16 @@ |
| 40463 | 40650 | pNew = 0; |
| 40464 | 40651 | ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE; |
| 40465 | 40652 | pShmNode->pNext = winShmNodeList; |
| 40466 | 40653 | winShmNodeList = pShmNode; |
| 40467 | 40654 | |
| 40468 | | - pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| 40469 | | - if( pShmNode->mutex==0 ){ |
| 40470 | | - rc = SQLITE_IOERR_NOMEM_BKPT; |
| 40471 | | - goto shm_open_err; |
| 40655 | + if( sqlite3GlobalConfig.bCoreMutex ){ |
| 40656 | + pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST); |
| 40657 | + if( pShmNode->mutex==0 ){ |
| 40658 | + rc = SQLITE_IOERR_NOMEM_BKPT; |
| 40659 | + goto shm_open_err; |
| 40660 | + } |
| 40472 | 40661 | } |
| 40473 | 40662 | |
| 40474 | 40663 | rc = winOpen(pDbFd->pVfs, |
| 40475 | 40664 | pShmNode->zFilename, /* Name of the file (UTF-8) */ |
| 40476 | 40665 | (sqlite3_file*)&pShmNode->hFile, /* File handle here */ |
| | @@ -42930,11 +43119,33 @@ |
| 42930 | 43119 | ** This file implements that page cache. |
| 42931 | 43120 | */ |
| 42932 | 43121 | /* #include "sqliteInt.h" */ |
| 42933 | 43122 | |
| 42934 | 43123 | /* |
| 42935 | | -** A complete page cache is an instance of this structure. |
| 43124 | +** A complete page cache is an instance of this structure. Every |
| 43125 | +** entry in the cache holds a single page of the database file. The |
| 43126 | +** btree layer only operates on the cached copy of the database pages. |
| 43127 | +** |
| 43128 | +** A page cache entry is "clean" if it exactly matches what is currently |
| 43129 | +** on disk. A page is "dirty" if it has been modified and needs to be |
| 43130 | +** persisted to disk. |
| 43131 | +** |
| 43132 | +** pDirty, pDirtyTail, pSynced: |
| 43133 | +** All dirty pages are linked into the doubly linked list using |
| 43134 | +** PgHdr.pDirtyNext and pDirtyPrev. The list is maintained in LRU order |
| 43135 | +** such that p was added to the list more recently than p->pDirtyNext. |
| 43136 | +** PCache.pDirty points to the first (newest) element in the list and |
| 43137 | +** pDirtyTail to the last (oldest). |
| 43138 | +** |
| 43139 | +** The PCache.pSynced variable is used to optimize searching for a dirty |
| 43140 | +** page to eject from the cache mid-transaction. It is better to eject |
| 43141 | +** a page that does not require a journal sync than one that does. |
| 43142 | +** Therefore, pSynced is maintained to that it *almost* always points |
| 43143 | +** to either the oldest page in the pDirty/pDirtyTail list that has a |
| 43144 | +** clear PGHDR_NEED_SYNC flag or to a page that is older than this one |
| 43145 | +** (so that the right page to eject can be found by following pDirtyPrev |
| 43146 | +** pointers). |
| 42936 | 43147 | */ |
| 42937 | 43148 | struct PCache { |
| 42938 | 43149 | PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */ |
| 42939 | 43150 | PgHdr *pSynced; /* Last synced page in dirty page list */ |
| 42940 | 43151 | int nRefSum; /* Sum of ref counts over all pages */ |
| | @@ -42946,10 +43157,99 @@ |
| 42946 | 43157 | u8 eCreate; /* eCreate value for for xFetch() */ |
| 42947 | 43158 | int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */ |
| 42948 | 43159 | void *pStress; /* Argument to xStress */ |
| 42949 | 43160 | sqlite3_pcache *pCache; /* Pluggable cache module */ |
| 42950 | 43161 | }; |
| 43162 | + |
| 43163 | +/********************************** Test and Debug Logic **********************/ |
| 43164 | +/* |
| 43165 | +** Debug tracing macros. Enable by by changing the "0" to "1" and |
| 43166 | +** recompiling. |
| 43167 | +** |
| 43168 | +** When sqlite3PcacheTrace is 1, single line trace messages are issued. |
| 43169 | +** When sqlite3PcacheTrace is 2, a dump of the pcache showing all cache entries |
| 43170 | +** is displayed for many operations, resulting in a lot of output. |
| 43171 | +*/ |
| 43172 | +#if defined(SQLITE_DEBUG) && 0 |
| 43173 | + int sqlite3PcacheTrace = 2; /* 0: off 1: simple 2: cache dumps */ |
| 43174 | + int sqlite3PcacheMxDump = 9999; /* Max cache entries for pcacheDump() */ |
| 43175 | +# define pcacheTrace(X) if(sqlite3PcacheTrace){sqlite3DebugPrintf X;} |
| 43176 | + void pcacheDump(PCache *pCache){ |
| 43177 | + int N; |
| 43178 | + int i, j; |
| 43179 | + sqlite3_pcache_page *pLower; |
| 43180 | + PgHdr *pPg; |
| 43181 | + unsigned char *a; |
| 43182 | + |
| 43183 | + if( sqlite3PcacheTrace<2 ) return; |
| 43184 | + if( pCache->pCache==0 ) return; |
| 43185 | + N = sqlite3PcachePagecount(pCache); |
| 43186 | + if( N>sqlite3PcacheMxDump ) N = sqlite3PcacheMxDump; |
| 43187 | + for(i=1; i<=N; i++){ |
| 43188 | + pLower = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, i, 0); |
| 43189 | + if( pLower==0 ) continue; |
| 43190 | + pPg = (PgHdr*)pLower->pExtra; |
| 43191 | + printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags); |
| 43192 | + a = (unsigned char *)pLower->pBuf; |
| 43193 | + for(j=0; j<12; j++) printf("%02x", a[j]); |
| 43194 | + printf("\n"); |
| 43195 | + if( pPg->pPage==0 ){ |
| 43196 | + sqlite3GlobalConfig.pcache2.xUnpin(pCache->pCache, pLower, 0); |
| 43197 | + } |
| 43198 | + } |
| 43199 | + } |
| 43200 | + #else |
| 43201 | +# define pcacheTrace(X) |
| 43202 | +# define pcacheDump(X) |
| 43203 | +#endif |
| 43204 | + |
| 43205 | +/* |
| 43206 | +** Check invariants on a PgHdr entry. Return true if everything is OK. |
| 43207 | +** Return false if any invariant is violated. |
| 43208 | +** |
| 43209 | +** This routine is for use inside of assert() statements only. For |
| 43210 | +** example: |
| 43211 | +** |
| 43212 | +** assert( sqlite3PcachePageSanity(pPg) ); |
| 43213 | +*/ |
| 43214 | +#if SQLITE_DEBUG |
| 43215 | +SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){ |
| 43216 | + PCache *pCache; |
| 43217 | + assert( pPg!=0 ); |
| 43218 | + assert( pPg->pgno>0 ); /* Page number is 1 or more */ |
| 43219 | + pCache = pPg->pCache; |
| 43220 | + assert( pCache!=0 ); /* Every page has an associated PCache */ |
| 43221 | + if( pPg->flags & PGHDR_CLEAN ){ |
| 43222 | + assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */ |
| 43223 | + assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */ |
| 43224 | + assert( pCache->pDirtyTail!=pPg ); |
| 43225 | + } |
| 43226 | + /* WRITEABLE pages must also be DIRTY */ |
| 43227 | + if( pPg->flags & PGHDR_WRITEABLE ){ |
| 43228 | + assert( pPg->flags & PGHDR_DIRTY ); /* WRITEABLE implies DIRTY */ |
| 43229 | + } |
| 43230 | + /* NEED_SYNC can be set independently of WRITEABLE. This can happen, |
| 43231 | + ** for example, when using the sqlite3PagerDontWrite() optimization: |
| 43232 | + ** (1) Page X is journalled, and gets WRITEABLE and NEED_SEEK. |
| 43233 | + ** (2) Page X moved to freelist, WRITEABLE is cleared |
| 43234 | + ** (3) Page X reused, WRITEABLE is set again |
| 43235 | + ** If NEED_SYNC had been cleared in step 2, then it would not be reset |
| 43236 | + ** in step 3, and page might be written into the database without first |
| 43237 | + ** syncing the rollback journal, which might cause corruption on a power |
| 43238 | + ** loss. |
| 43239 | + ** |
| 43240 | + ** Another example is when the database page size is smaller than the |
| 43241 | + ** disk sector size. When any page of a sector is journalled, all pages |
| 43242 | + ** in that sector are marked NEED_SYNC even if they are still CLEAN, just |
| 43243 | + ** in case they are later modified, since all pages in the same sector |
| 43244 | + ** must be journalled and synced before any of those pages can be safely |
| 43245 | + ** written. |
| 43246 | + */ |
| 43247 | + return 1; |
| 43248 | +} |
| 43249 | +#endif /* SQLITE_DEBUG */ |
| 43250 | + |
| 42951 | 43251 | |
| 42952 | 43252 | /********************************** Linked List Management ********************/ |
| 42953 | 43253 | |
| 42954 | 43254 | /* Allowed values for second argument to pcacheManageDirtyList() */ |
| 42955 | 43255 | #define PCACHE_DIRTYLIST_REMOVE 1 /* Remove pPage from dirty list */ |
| | @@ -42963,21 +43263,20 @@ |
| 42963 | 43263 | ** the dirty list. Doing both moves pPage to the front of the dirty list. |
| 42964 | 43264 | */ |
| 42965 | 43265 | static void pcacheManageDirtyList(PgHdr *pPage, u8 addRemove){ |
| 42966 | 43266 | PCache *p = pPage->pCache; |
| 42967 | 43267 | |
| 43268 | + pcacheTrace(("%p.DIRTYLIST.%s %d\n", p, |
| 43269 | + addRemove==1 ? "REMOVE" : addRemove==2 ? "ADD" : "FRONT", |
| 43270 | + pPage->pgno)); |
| 42968 | 43271 | if( addRemove & PCACHE_DIRTYLIST_REMOVE ){ |
| 42969 | 43272 | assert( pPage->pDirtyNext || pPage==p->pDirtyTail ); |
| 42970 | 43273 | assert( pPage->pDirtyPrev || pPage==p->pDirty ); |
| 42971 | 43274 | |
| 42972 | 43275 | /* Update the PCache1.pSynced variable if necessary. */ |
| 42973 | 43276 | if( p->pSynced==pPage ){ |
| 42974 | | - PgHdr *pSynced = pPage->pDirtyPrev; |
| 42975 | | - while( pSynced && (pSynced->flags&PGHDR_NEED_SYNC) ){ |
| 42976 | | - pSynced = pSynced->pDirtyPrev; |
| 42977 | | - } |
| 42978 | | - p->pSynced = pSynced; |
| 43277 | + p->pSynced = pPage->pDirtyPrev; |
| 42979 | 43278 | } |
| 42980 | 43279 | |
| 42981 | 43280 | if( pPage->pDirtyNext ){ |
| 42982 | 43281 | pPage->pDirtyNext->pDirtyPrev = pPage->pDirtyPrev; |
| 42983 | 43282 | }else{ |
| | @@ -42985,14 +43284,19 @@ |
| 42985 | 43284 | p->pDirtyTail = pPage->pDirtyPrev; |
| 42986 | 43285 | } |
| 42987 | 43286 | if( pPage->pDirtyPrev ){ |
| 42988 | 43287 | pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext; |
| 42989 | 43288 | }else{ |
| 43289 | + /* If there are now no dirty pages in the cache, set eCreate to 2. |
| 43290 | + ** This is an optimization that allows sqlite3PcacheFetch() to skip |
| 43291 | + ** searching for a dirty page to eject from the cache when it might |
| 43292 | + ** otherwise have to. */ |
| 42990 | 43293 | assert( pPage==p->pDirty ); |
| 42991 | 43294 | p->pDirty = pPage->pDirtyNext; |
| 42992 | | - if( p->pDirty==0 && p->bPurgeable ){ |
| 42993 | | - assert( p->eCreate==1 ); |
| 43295 | + assert( p->bPurgeable || p->eCreate==2 ); |
| 43296 | + if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 43297 | + assert( p->bPurgeable==0 || p->eCreate==1 ); |
| 42994 | 43298 | p->eCreate = 2; |
| 42995 | 43299 | } |
| 42996 | 43300 | } |
| 42997 | 43301 | pPage->pDirtyNext = 0; |
| 42998 | 43302 | pPage->pDirtyPrev = 0; |
| | @@ -43010,23 +43314,34 @@ |
| 43010 | 43314 | assert( p->eCreate==2 ); |
| 43011 | 43315 | p->eCreate = 1; |
| 43012 | 43316 | } |
| 43013 | 43317 | } |
| 43014 | 43318 | p->pDirty = pPage; |
| 43015 | | - if( !p->pSynced && 0==(pPage->flags&PGHDR_NEED_SYNC) ){ |
| 43319 | + |
| 43320 | + /* If pSynced is NULL and this page has a clear NEED_SYNC flag, set |
| 43321 | + ** pSynced to point to it. Checking the NEED_SYNC flag is an |
| 43322 | + ** optimization, as if pSynced points to a page with the NEED_SYNC |
| 43323 | + ** flag set sqlite3PcacheFetchStress() searches through all newer |
| 43324 | + ** entries of the dirty-list for a page with NEED_SYNC clear anyway. */ |
| 43325 | + if( !p->pSynced |
| 43326 | + && 0==(pPage->flags&PGHDR_NEED_SYNC) /*OPTIMIZATION-IF-FALSE*/ |
| 43327 | + ){ |
| 43016 | 43328 | p->pSynced = pPage; |
| 43017 | 43329 | } |
| 43018 | 43330 | } |
| 43331 | + pcacheDump(p); |
| 43019 | 43332 | } |
| 43020 | 43333 | |
| 43021 | 43334 | /* |
| 43022 | 43335 | ** Wrapper around the pluggable caches xUnpin method. If the cache is |
| 43023 | 43336 | ** being used for an in-memory database, this function is a no-op. |
| 43024 | 43337 | */ |
| 43025 | 43338 | static void pcacheUnpin(PgHdr *p){ |
| 43026 | 43339 | if( p->pCache->bPurgeable ){ |
| 43340 | + pcacheTrace(("%p.UNPIN %d\n", p->pCache, p->pgno)); |
| 43027 | 43341 | sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 0); |
| 43342 | + pcacheDump(p->pCache); |
| 43028 | 43343 | } |
| 43029 | 43344 | } |
| 43030 | 43345 | |
| 43031 | 43346 | /* |
| 43032 | 43347 | ** Compute the number of pages of cache requested. p->szCache is the |
| | @@ -43092,10 +43407,11 @@ |
| 43092 | 43407 | p->eCreate = 2; |
| 43093 | 43408 | p->xStress = xStress; |
| 43094 | 43409 | p->pStress = pStress; |
| 43095 | 43410 | p->szCache = 100; |
| 43096 | 43411 | p->szSpill = 1; |
| 43412 | + pcacheTrace(("%p.OPEN szPage %d bPurgeable %d\n",p,szPage,bPurgeable)); |
| 43097 | 43413 | return sqlite3PcacheSetPageSize(p, szPage); |
| 43098 | 43414 | } |
| 43099 | 43415 | |
| 43100 | 43416 | /* |
| 43101 | 43417 | ** Change the page size for PCache object. The caller must ensure that there |
| | @@ -43114,10 +43430,11 @@ |
| 43114 | 43430 | if( pCache->pCache ){ |
| 43115 | 43431 | sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache); |
| 43116 | 43432 | } |
| 43117 | 43433 | pCache->pCache = pNew; |
| 43118 | 43434 | pCache->szPage = szPage; |
| 43435 | + pcacheTrace(("%p.PAGESIZE %d\n",pCache,szPage)); |
| 43119 | 43436 | } |
| 43120 | 43437 | return SQLITE_OK; |
| 43121 | 43438 | } |
| 43122 | 43439 | |
| 43123 | 43440 | /* |
| | @@ -43148,15 +43465,17 @@ |
| 43148 | 43465 | PCache *pCache, /* Obtain the page from this cache */ |
| 43149 | 43466 | Pgno pgno, /* Page number to obtain */ |
| 43150 | 43467 | int createFlag /* If true, create page if it does not exist already */ |
| 43151 | 43468 | ){ |
| 43152 | 43469 | int eCreate; |
| 43470 | + sqlite3_pcache_page *pRes; |
| 43153 | 43471 | |
| 43154 | 43472 | assert( pCache!=0 ); |
| 43155 | 43473 | assert( pCache->pCache!=0 ); |
| 43156 | 43474 | assert( createFlag==3 || createFlag==0 ); |
| 43157 | 43475 | assert( pgno>0 ); |
| 43476 | + assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) ); |
| 43158 | 43477 | |
| 43159 | 43478 | /* eCreate defines what to do if the page does not exist. |
| 43160 | 43479 | ** 0 Do not allocate a new page. (createFlag==0) |
| 43161 | 43480 | ** 1 Allocate a new page if doing so is inexpensive. |
| 43162 | 43481 | ** (createFlag==1 AND bPurgeable AND pDirty) |
| | @@ -43165,16 +43484,19 @@ |
| 43165 | 43484 | */ |
| 43166 | 43485 | eCreate = createFlag & pCache->eCreate; |
| 43167 | 43486 | assert( eCreate==0 || eCreate==1 || eCreate==2 ); |
| 43168 | 43487 | assert( createFlag==0 || pCache->eCreate==eCreate ); |
| 43169 | 43488 | assert( createFlag==0 || eCreate==1+(!pCache->bPurgeable||!pCache->pDirty) ); |
| 43170 | | - return sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate); |
| 43489 | + pRes = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate); |
| 43490 | + pcacheTrace(("%p.FETCH %d%s (result: %p)\n",pCache,pgno, |
| 43491 | + createFlag?" create":"",pRes)); |
| 43492 | + return pRes; |
| 43171 | 43493 | } |
| 43172 | 43494 | |
| 43173 | 43495 | /* |
| 43174 | 43496 | ** If the sqlite3PcacheFetch() routine is unable to allocate a new |
| 43175 | | -** page because new clean pages are available for reuse and the cache |
| 43497 | +** page because no clean pages are available for reuse and the cache |
| 43176 | 43498 | ** size limit has been reached, then this routine can be invoked to |
| 43177 | 43499 | ** try harder to allocate a page. This routine might invoke the stress |
| 43178 | 43500 | ** callback to spill dirty pages to the journal. It will then try to |
| 43179 | 43501 | ** allocate the new page and will only fail to allocate a new page on |
| 43180 | 43502 | ** an OOM error. |
| | @@ -43192,11 +43514,15 @@ |
| 43192 | 43514 | if( sqlite3PcachePagecount(pCache)>pCache->szSpill ){ |
| 43193 | 43515 | /* Find a dirty page to write-out and recycle. First try to find a |
| 43194 | 43516 | ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC |
| 43195 | 43517 | ** cleared), but if that is not possible settle for any other |
| 43196 | 43518 | ** unreferenced dirty page. |
| 43197 | | - */ |
| 43519 | + ** |
| 43520 | + ** If the LRU page in the dirty list that has a clear PGHDR_NEED_SYNC |
| 43521 | + ** flag is currently referenced, then the following may leave pSynced |
| 43522 | + ** set incorrectly (pointing to other than the LRU page with NEED_SYNC |
| 43523 | + ** cleared). This is Ok, as pSynced is just an optimization. */ |
| 43198 | 43524 | for(pPg=pCache->pSynced; |
| 43199 | 43525 | pPg && (pPg->nRef || (pPg->flags&PGHDR_NEED_SYNC)); |
| 43200 | 43526 | pPg=pPg->pDirtyPrev |
| 43201 | 43527 | ); |
| 43202 | 43528 | pCache->pSynced = pPg; |
| | @@ -43210,11 +43536,13 @@ |
| 43210 | 43536 | "spill page %d making room for %d - cache used: %d/%d", |
| 43211 | 43537 | pPg->pgno, pgno, |
| 43212 | 43538 | sqlite3GlobalConfig.pcache.xPagecount(pCache->pCache), |
| 43213 | 43539 | numberOfCachePages(pCache)); |
| 43214 | 43540 | #endif |
| 43541 | + pcacheTrace(("%p.SPILL %d\n",pCache,pPg->pgno)); |
| 43215 | 43542 | rc = pCache->xStress(pCache->pStress, pPg); |
| 43543 | + pcacheDump(pCache); |
| 43216 | 43544 | if( rc!=SQLITE_OK && rc!=SQLITE_BUSY ){ |
| 43217 | 43545 | return rc; |
| 43218 | 43546 | } |
| 43219 | 43547 | } |
| 43220 | 43548 | } |
| | @@ -43270,10 +43598,11 @@ |
| 43270 | 43598 | if( !pPgHdr->pPage ){ |
| 43271 | 43599 | return pcacheFetchFinishWithInit(pCache, pgno, pPage); |
| 43272 | 43600 | } |
| 43273 | 43601 | pCache->nRefSum++; |
| 43274 | 43602 | pPgHdr->nRef++; |
| 43603 | + assert( sqlite3PcachePageSanity(pPgHdr) ); |
| 43275 | 43604 | return pPgHdr; |
| 43276 | 43605 | } |
| 43277 | 43606 | |
| 43278 | 43607 | /* |
| 43279 | 43608 | ** Decrement the reference count on a page. If the page is clean and the |
| | @@ -43283,12 +43612,15 @@ |
| 43283 | 43612 | assert( p->nRef>0 ); |
| 43284 | 43613 | p->pCache->nRefSum--; |
| 43285 | 43614 | if( (--p->nRef)==0 ){ |
| 43286 | 43615 | if( p->flags&PGHDR_CLEAN ){ |
| 43287 | 43616 | pcacheUnpin(p); |
| 43288 | | - }else if( p->pDirtyPrev!=0 ){ |
| 43289 | | - /* Move the page to the head of the dirty list. */ |
| 43617 | + }else if( p->pDirtyPrev!=0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 43618 | + /* Move the page to the head of the dirty list. If p->pDirtyPrev==0, |
| 43619 | + ** then page p is already at the head of the dirty list and the |
| 43620 | + ** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE |
| 43621 | + ** tag above. */ |
| 43290 | 43622 | pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT); |
| 43291 | 43623 | } |
| 43292 | 43624 | } |
| 43293 | 43625 | } |
| 43294 | 43626 | |
| | @@ -43295,10 +43627,11 @@ |
| 43295 | 43627 | /* |
| 43296 | 43628 | ** Increase the reference count of a supplied page by 1. |
| 43297 | 43629 | */ |
| 43298 | 43630 | SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr *p){ |
| 43299 | 43631 | assert(p->nRef>0); |
| 43632 | + assert( sqlite3PcachePageSanity(p) ); |
| 43300 | 43633 | p->nRef++; |
| 43301 | 43634 | p->pCache->nRefSum++; |
| 43302 | 43635 | } |
| 43303 | 43636 | |
| 43304 | 43637 | /* |
| | @@ -43306,10 +43639,11 @@ |
| 43306 | 43639 | ** page. This function deletes that reference, so after it returns the |
| 43307 | 43640 | ** page pointed to by p is invalid. |
| 43308 | 43641 | */ |
| 43309 | 43642 | SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr *p){ |
| 43310 | 43643 | assert( p->nRef==1 ); |
| 43644 | + assert( sqlite3PcachePageSanity(p) ); |
| 43311 | 43645 | if( p->flags&PGHDR_DIRTY ){ |
| 43312 | 43646 | pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE); |
| 43313 | 43647 | } |
| 43314 | 43648 | p->pCache->nRefSum--; |
| 43315 | 43649 | sqlite3GlobalConfig.pcache2.xUnpin(p->pCache->pCache, p->pPage, 1); |
| | @@ -43319,30 +43653,36 @@ |
| 43319 | 43653 | ** Make sure the page is marked as dirty. If it isn't dirty already, |
| 43320 | 43654 | ** make it so. |
| 43321 | 43655 | */ |
| 43322 | 43656 | SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){ |
| 43323 | 43657 | assert( p->nRef>0 ); |
| 43324 | | - if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ |
| 43658 | + assert( sqlite3PcachePageSanity(p) ); |
| 43659 | + if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/ |
| 43325 | 43660 | p->flags &= ~PGHDR_DONT_WRITE; |
| 43326 | 43661 | if( p->flags & PGHDR_CLEAN ){ |
| 43327 | 43662 | p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN); |
| 43663 | + pcacheTrace(("%p.DIRTY %d\n",p->pCache,p->pgno)); |
| 43328 | 43664 | assert( (p->flags & (PGHDR_DIRTY|PGHDR_CLEAN))==PGHDR_DIRTY ); |
| 43329 | 43665 | pcacheManageDirtyList(p, PCACHE_DIRTYLIST_ADD); |
| 43330 | 43666 | } |
| 43667 | + assert( sqlite3PcachePageSanity(p) ); |
| 43331 | 43668 | } |
| 43332 | 43669 | } |
| 43333 | 43670 | |
| 43334 | 43671 | /* |
| 43335 | 43672 | ** Make sure the page is marked as clean. If it isn't clean already, |
| 43336 | 43673 | ** make it so. |
| 43337 | 43674 | */ |
| 43338 | 43675 | SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr *p){ |
| 43339 | | - if( (p->flags & PGHDR_DIRTY) ){ |
| 43676 | + assert( sqlite3PcachePageSanity(p) ); |
| 43677 | + if( ALWAYS((p->flags & PGHDR_DIRTY)!=0) ){ |
| 43340 | 43678 | assert( (p->flags & PGHDR_CLEAN)==0 ); |
| 43341 | 43679 | pcacheManageDirtyList(p, PCACHE_DIRTYLIST_REMOVE); |
| 43342 | 43680 | p->flags &= ~(PGHDR_DIRTY|PGHDR_NEED_SYNC|PGHDR_WRITEABLE); |
| 43343 | 43681 | p->flags |= PGHDR_CLEAN; |
| 43682 | + pcacheTrace(("%p.CLEAN %d\n",p->pCache,p->pgno)); |
| 43683 | + assert( sqlite3PcachePageSanity(p) ); |
| 43344 | 43684 | if( p->nRef==0 ){ |
| 43345 | 43685 | pcacheUnpin(p); |
| 43346 | 43686 | } |
| 43347 | 43687 | } |
| 43348 | 43688 | } |
| | @@ -43350,14 +43690,27 @@ |
| 43350 | 43690 | /* |
| 43351 | 43691 | ** Make every page in the cache clean. |
| 43352 | 43692 | */ |
| 43353 | 43693 | SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache *pCache){ |
| 43354 | 43694 | PgHdr *p; |
| 43695 | + pcacheTrace(("%p.CLEAN-ALL\n",pCache)); |
| 43355 | 43696 | while( (p = pCache->pDirty)!=0 ){ |
| 43356 | 43697 | sqlite3PcacheMakeClean(p); |
| 43357 | 43698 | } |
| 43358 | 43699 | } |
| 43700 | + |
| 43701 | +/* |
| 43702 | +** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages. |
| 43703 | +*/ |
| 43704 | +SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){ |
| 43705 | + PgHdr *p; |
| 43706 | + pcacheTrace(("%p.CLEAR-WRITEABLE\n",pCache)); |
| 43707 | + for(p=pCache->pDirty; p; p=p->pDirtyNext){ |
| 43708 | + p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE); |
| 43709 | + } |
| 43710 | + pCache->pSynced = pCache->pDirtyTail; |
| 43711 | +} |
| 43359 | 43712 | |
| 43360 | 43713 | /* |
| 43361 | 43714 | ** Clear the PGHDR_NEED_SYNC flag from all dirty pages. |
| 43362 | 43715 | */ |
| 43363 | 43716 | SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){ |
| | @@ -43373,10 +43726,12 @@ |
| 43373 | 43726 | */ |
| 43374 | 43727 | SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr *p, Pgno newPgno){ |
| 43375 | 43728 | PCache *pCache = p->pCache; |
| 43376 | 43729 | assert( p->nRef>0 ); |
| 43377 | 43730 | assert( newPgno>0 ); |
| 43731 | + assert( sqlite3PcachePageSanity(p) ); |
| 43732 | + pcacheTrace(("%p.MOVE %d -> %d\n",pCache,p->pgno,newPgno)); |
| 43378 | 43733 | sqlite3GlobalConfig.pcache2.xRekey(pCache->pCache, p->pPage, p->pgno,newPgno); |
| 43379 | 43734 | p->pgno = newPgno; |
| 43380 | 43735 | if( (p->flags&PGHDR_DIRTY) && (p->flags&PGHDR_NEED_SYNC) ){ |
| 43381 | 43736 | pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT); |
| 43382 | 43737 | } |
| | @@ -43393,18 +43748,19 @@ |
| 43393 | 43748 | */ |
| 43394 | 43749 | SQLITE_PRIVATE void sqlite3PcacheTruncate(PCache *pCache, Pgno pgno){ |
| 43395 | 43750 | if( pCache->pCache ){ |
| 43396 | 43751 | PgHdr *p; |
| 43397 | 43752 | PgHdr *pNext; |
| 43753 | + pcacheTrace(("%p.TRUNCATE %d\n",pCache,pgno)); |
| 43398 | 43754 | for(p=pCache->pDirty; p; p=pNext){ |
| 43399 | 43755 | pNext = p->pDirtyNext; |
| 43400 | 43756 | /* This routine never gets call with a positive pgno except right |
| 43401 | 43757 | ** after sqlite3PcacheCleanAll(). So if there are dirty pages, |
| 43402 | 43758 | ** it must be that pgno==0. |
| 43403 | 43759 | */ |
| 43404 | 43760 | assert( p->pgno>0 ); |
| 43405 | | - if( ALWAYS(p->pgno>pgno) ){ |
| 43761 | + if( p->pgno>pgno ){ |
| 43406 | 43762 | assert( p->flags&PGHDR_DIRTY ); |
| 43407 | 43763 | sqlite3PcacheMakeClean(p); |
| 43408 | 43764 | } |
| 43409 | 43765 | } |
| 43410 | 43766 | if( pgno==0 && pCache->nRefSum ){ |
| | @@ -43423,10 +43779,11 @@ |
| 43423 | 43779 | /* |
| 43424 | 43780 | ** Close a cache. |
| 43425 | 43781 | */ |
| 43426 | 43782 | SQLITE_PRIVATE void sqlite3PcacheClose(PCache *pCache){ |
| 43427 | 43783 | assert( pCache->pCache!=0 ); |
| 43784 | + pcacheTrace(("%p.CLOSE\n",pCache)); |
| 43428 | 43785 | sqlite3GlobalConfig.pcache2.xDestroy(pCache->pCache); |
| 43429 | 43786 | } |
| 43430 | 43787 | |
| 43431 | 43788 | /* |
| 43432 | 43789 | ** Discard the contents of the cache. |
| | @@ -43591,10 +43948,21 @@ |
| 43591 | 43948 | ** Return the size of the header added by this middleware layer |
| 43592 | 43949 | ** in the page-cache hierarchy. |
| 43593 | 43950 | */ |
| 43594 | 43951 | SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); } |
| 43595 | 43952 | |
| 43953 | +/* |
| 43954 | +** Return the number of dirty pages currently in the cache, as a percentage |
| 43955 | +** of the configured cache size. |
| 43956 | +*/ |
| 43957 | +SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){ |
| 43958 | + PgHdr *pDirty; |
| 43959 | + int nDirty = 0; |
| 43960 | + int nCache = numberOfCachePages(pCache); |
| 43961 | + for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++; |
| 43962 | + return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0; |
| 43963 | +} |
| 43596 | 43964 | |
| 43597 | 43965 | #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG) |
| 43598 | 43966 | /* |
| 43599 | 43967 | ** For all dirty pages currently in the cache, invoke the specified |
| 43600 | 43968 | ** callback. This is only used if the SQLITE_CHECK_PAGES macro is |
| | @@ -44300,12 +44668,12 @@ |
| 44300 | 44668 | pcache1.separateCache = sqlite3GlobalConfig.pPage==0; |
| 44301 | 44669 | #endif |
| 44302 | 44670 | |
| 44303 | 44671 | #if SQLITE_THREADSAFE |
| 44304 | 44672 | if( sqlite3GlobalConfig.bCoreMutex ){ |
| 44305 | | - pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU); |
| 44306 | | - pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM); |
| 44673 | + pcache1.grp.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU); |
| 44674 | + pcache1.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PMEM); |
| 44307 | 44675 | } |
| 44308 | 44676 | #endif |
| 44309 | 44677 | if( pcache1.separateCache |
| 44310 | 44678 | && sqlite3GlobalConfig.nPage!=0 |
| 44311 | 44679 | && sqlite3GlobalConfig.pPage==0 |
| | @@ -44907,12 +45275,13 @@ |
| 44907 | 45275 | ** batch number is O(NlogN) where N is the number of elements in the RowSet. |
| 44908 | 45276 | ** The cost of a TEST using the same batch number is O(logN). The cost |
| 44909 | 45277 | ** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST |
| 44910 | 45278 | ** primitives are constant time. The cost of DESTROY is O(N). |
| 44911 | 45279 | ** |
| 44912 | | -** There is an added cost of O(N) when switching between TEST and |
| 44913 | | -** SMALLEST primitives. |
| 45280 | +** TEST and SMALLEST may not be used by the same RowSet. This used to |
| 45281 | +** be possible, but the feature was not used, so it was removed in order |
| 45282 | +** to simplify the code. |
| 44914 | 45283 | */ |
| 44915 | 45284 | /* #include "sqliteInt.h" */ |
| 44916 | 45285 | |
| 44917 | 45286 | |
| 44918 | 45287 | /* |
| | @@ -45029,11 +45398,13 @@ |
| 45029 | 45398 | ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this |
| 45030 | 45399 | ** routine returns NULL. |
| 45031 | 45400 | */ |
| 45032 | 45401 | static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){ |
| 45033 | 45402 | assert( p!=0 ); |
| 45034 | | - if( p->nFresh==0 ){ |
| 45403 | + if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 45404 | + /* We could allocate a fresh RowSetEntry each time one is needed, but it |
| 45405 | + ** is more efficient to pull a preallocated entry from the pool */ |
| 45035 | 45406 | struct RowSetChunk *pNew; |
| 45036 | 45407 | pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew)); |
| 45037 | 45408 | if( pNew==0 ){ |
| 45038 | 45409 | return 0; |
| 45039 | 45410 | } |
| | @@ -45063,11 +45434,13 @@ |
| 45063 | 45434 | if( pEntry==0 ) return; |
| 45064 | 45435 | pEntry->v = rowid; |
| 45065 | 45436 | pEntry->pRight = 0; |
| 45066 | 45437 | pLast = p->pLast; |
| 45067 | 45438 | if( pLast ){ |
| 45068 | | - if( (p->rsFlags & ROWSET_SORTED)!=0 && rowid<=pLast->v ){ |
| 45439 | + if( rowid<=pLast->v ){ /*OPTIMIZATION-IF-FALSE*/ |
| 45440 | + /* Avoid unnecessary sorts by preserving the ROWSET_SORTED flags |
| 45441 | + ** where possible */ |
| 45069 | 45442 | p->rsFlags &= ~ROWSET_SORTED; |
| 45070 | 45443 | } |
| 45071 | 45444 | pLast->pRight = pEntry; |
| 45072 | 45445 | }else{ |
| 45073 | 45446 | p->pEntry = pEntry; |
| | @@ -45185,27 +45558,33 @@ |
| 45185 | 45558 | struct RowSetEntry **ppList, |
| 45186 | 45559 | int iDepth |
| 45187 | 45560 | ){ |
| 45188 | 45561 | struct RowSetEntry *p; /* Root of the new tree */ |
| 45189 | 45562 | struct RowSetEntry *pLeft; /* Left subtree */ |
| 45190 | | - if( *ppList==0 ){ |
| 45191 | | - return 0; |
| 45563 | + if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 45564 | + /* Prevent unnecessary deep recursion when we run out of entries */ |
| 45565 | + return 0; |
| 45192 | 45566 | } |
| 45193 | | - if( iDepth==1 ){ |
| 45567 | + if( iDepth>1 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 45568 | + /* This branch causes a *balanced* tree to be generated. A valid tree |
| 45569 | + ** is still generated without this branch, but the tree is wildly |
| 45570 | + ** unbalanced and inefficient. */ |
| 45571 | + pLeft = rowSetNDeepTree(ppList, iDepth-1); |
| 45572 | + p = *ppList; |
| 45573 | + if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 45574 | + /* It is safe to always return here, but the resulting tree |
| 45575 | + ** would be unbalanced */ |
| 45576 | + return pLeft; |
| 45577 | + } |
| 45578 | + p->pLeft = pLeft; |
| 45579 | + *ppList = p->pRight; |
| 45580 | + p->pRight = rowSetNDeepTree(ppList, iDepth-1); |
| 45581 | + }else{ |
| 45194 | 45582 | p = *ppList; |
| 45195 | 45583 | *ppList = p->pRight; |
| 45196 | 45584 | p->pLeft = p->pRight = 0; |
| 45197 | | - return p; |
| 45198 | | - } |
| 45199 | | - pLeft = rowSetNDeepTree(ppList, iDepth-1); |
| 45200 | | - p = *ppList; |
| 45201 | | - if( p==0 ){ |
| 45202 | | - return pLeft; |
| 45203 | | - } |
| 45204 | | - p->pLeft = pLeft; |
| 45205 | | - *ppList = p->pRight; |
| 45206 | | - p->pRight = rowSetNDeepTree(ppList, iDepth-1); |
| 45585 | + } |
| 45207 | 45586 | return p; |
| 45208 | 45587 | } |
| 45209 | 45588 | |
| 45210 | 45589 | /* |
| 45211 | 45590 | ** Convert a sorted list of elements into a binary tree. Make the tree |
| | @@ -45228,63 +45607,41 @@ |
| 45228 | 45607 | p->pRight = rowSetNDeepTree(&pList, iDepth); |
| 45229 | 45608 | } |
| 45230 | 45609 | return p; |
| 45231 | 45610 | } |
| 45232 | 45611 | |
| 45233 | | -/* |
| 45234 | | -** Take all the entries on p->pEntry and on the trees in p->pForest and |
| 45235 | | -** sort them all together into one big ordered list on p->pEntry. |
| 45236 | | -** |
| 45237 | | -** This routine should only be called once in the life of a RowSet. |
| 45238 | | -*/ |
| 45239 | | -static void rowSetToList(RowSet *p){ |
| 45240 | | - |
| 45241 | | - /* This routine is called only once */ |
| 45242 | | - assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 ); |
| 45243 | | - |
| 45244 | | - if( (p->rsFlags & ROWSET_SORTED)==0 ){ |
| 45245 | | - p->pEntry = rowSetEntrySort(p->pEntry); |
| 45246 | | - } |
| 45247 | | - |
| 45248 | | - /* While this module could theoretically support it, sqlite3RowSetNext() |
| 45249 | | - ** is never called after sqlite3RowSetText() for the same RowSet. So |
| 45250 | | - ** there is never a forest to deal with. Should this change, simply |
| 45251 | | - ** remove the assert() and the #if 0. */ |
| 45252 | | - assert( p->pForest==0 ); |
| 45253 | | -#if 0 |
| 45254 | | - while( p->pForest ){ |
| 45255 | | - struct RowSetEntry *pTree = p->pForest->pLeft; |
| 45256 | | - if( pTree ){ |
| 45257 | | - struct RowSetEntry *pHead, *pTail; |
| 45258 | | - rowSetTreeToList(pTree, &pHead, &pTail); |
| 45259 | | - p->pEntry = rowSetEntryMerge(p->pEntry, pHead); |
| 45260 | | - } |
| 45261 | | - p->pForest = p->pForest->pRight; |
| 45262 | | - } |
| 45263 | | -#endif |
| 45264 | | - p->rsFlags |= ROWSET_NEXT; /* Verify this routine is never called again */ |
| 45265 | | -} |
| 45266 | | - |
| 45267 | 45612 | /* |
| 45268 | 45613 | ** Extract the smallest element from the RowSet. |
| 45269 | 45614 | ** Write the element into *pRowid. Return 1 on success. Return |
| 45270 | 45615 | ** 0 if the RowSet is already empty. |
| 45271 | 45616 | ** |
| 45272 | 45617 | ** After this routine has been called, the sqlite3RowSetInsert() |
| 45273 | | -** routine may not be called again. |
| 45618 | +** routine may not be called again. |
| 45619 | +** |
| 45620 | +** This routine may not be called after sqlite3RowSetTest() has |
| 45621 | +** been used. Older versions of RowSet allowed that, but as the |
| 45622 | +** capability was not used by the code generator, it was removed |
| 45623 | +** for code economy. |
| 45274 | 45624 | */ |
| 45275 | 45625 | SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){ |
| 45276 | 45626 | assert( p!=0 ); |
| 45627 | + assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */ |
| 45277 | 45628 | |
| 45278 | 45629 | /* Merge the forest into a single sorted list on first call */ |
| 45279 | | - if( (p->rsFlags & ROWSET_NEXT)==0 ) rowSetToList(p); |
| 45630 | + if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 45631 | + if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 45632 | + p->pEntry = rowSetEntrySort(p->pEntry); |
| 45633 | + } |
| 45634 | + p->rsFlags |= ROWSET_SORTED|ROWSET_NEXT; |
| 45635 | + } |
| 45280 | 45636 | |
| 45281 | 45637 | /* Return the next entry on the list */ |
| 45282 | 45638 | if( p->pEntry ){ |
| 45283 | 45639 | *pRowid = p->pEntry->v; |
| 45284 | 45640 | p->pEntry = p->pEntry->pRight; |
| 45285 | | - if( p->pEntry==0 ){ |
| 45641 | + if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 45642 | + /* Free memory immediately, rather than waiting on sqlite3_finalize() */ |
| 45286 | 45643 | sqlite3RowSetClear(p); |
| 45287 | 45644 | } |
| 45288 | 45645 | return 1; |
| 45289 | 45646 | }else{ |
| 45290 | 45647 | return 0; |
| | @@ -45303,17 +45660,19 @@ |
| 45303 | 45660 | struct RowSetEntry *p, *pTree; |
| 45304 | 45661 | |
| 45305 | 45662 | /* This routine is never called after sqlite3RowSetNext() */ |
| 45306 | 45663 | assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 ); |
| 45307 | 45664 | |
| 45308 | | - /* Sort entries into the forest on the first test of a new batch |
| 45665 | + /* Sort entries into the forest on the first test of a new batch. |
| 45666 | + ** To save unnecessary work, only do this when the batch number changes. |
| 45309 | 45667 | */ |
| 45310 | | - if( iBatch!=pRowSet->iBatch ){ |
| 45668 | + if( iBatch!=pRowSet->iBatch ){ /*OPTIMIZATION-IF-FALSE*/ |
| 45311 | 45669 | p = pRowSet->pEntry; |
| 45312 | 45670 | if( p ){ |
| 45313 | 45671 | struct RowSetEntry **ppPrevTree = &pRowSet->pForest; |
| 45314 | | - if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ |
| 45672 | + if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 45673 | + /* Only sort the current set of entiries if they need it */ |
| 45315 | 45674 | p = rowSetEntrySort(p); |
| 45316 | 45675 | } |
| 45317 | 45676 | for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){ |
| 45318 | 45677 | ppPrevTree = &pTree->pRight; |
| 45319 | 45678 | if( pTree->pLeft==0 ){ |
| | @@ -46383,10 +46742,11 @@ |
| 46383 | 46742 | ** return SQLITE_IOERR_NOMEM while the journal file is being written). It |
| 46384 | 46743 | ** is therefore not possible for an in-memory pager to enter the ERROR |
| 46385 | 46744 | ** state. |
| 46386 | 46745 | */ |
| 46387 | 46746 | if( MEMDB ){ |
| 46747 | + assert( !isOpen(p->fd) ); |
| 46388 | 46748 | assert( p->noSync ); |
| 46389 | 46749 | assert( p->journalMode==PAGER_JOURNALMODE_OFF |
| 46390 | 46750 | || p->journalMode==PAGER_JOURNALMODE_MEMORY |
| 46391 | 46751 | ); |
| 46392 | 46752 | assert( p->eState!=PAGER_ERROR && p->eState!=PAGER_OPEN ); |
| | @@ -46469,11 +46829,11 @@ |
| 46469 | 46829 | /* There must be at least one outstanding reference to the pager if |
| 46470 | 46830 | ** in ERROR state. Otherwise the pager should have already dropped |
| 46471 | 46831 | ** back to OPEN state. |
| 46472 | 46832 | */ |
| 46473 | 46833 | assert( pPager->errCode!=SQLITE_OK ); |
| 46474 | | - assert( sqlite3PcacheRefCount(pPager->pPCache)>0 ); |
| 46834 | + assert( sqlite3PcacheRefCount(pPager->pPCache)>0 || pPager->tempFile ); |
| 46475 | 46835 | break; |
| 46476 | 46836 | } |
| 46477 | 46837 | |
| 46478 | 46838 | return 1; |
| 46479 | 46839 | } |
| | @@ -46681,10 +47041,12 @@ |
| 46681 | 47041 | } |
| 46682 | 47042 | } |
| 46683 | 47043 | |
| 46684 | 47044 | return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager); |
| 46685 | 47045 | } |
| 47046 | +#else |
| 47047 | +# define jrnlBufferSize(x) 0 |
| 46686 | 47048 | #endif |
| 46687 | 47049 | |
| 46688 | 47050 | /* |
| 46689 | 47051 | ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking |
| 46690 | 47052 | ** on the cache using a hash function. This is used for testing |
| | @@ -47329,17 +47691,21 @@ |
| 47329 | 47691 | /* If Pager.errCode is set, the contents of the pager cache cannot be |
| 47330 | 47692 | ** trusted. Now that there are no outstanding references to the pager, |
| 47331 | 47693 | ** it can safely move back to PAGER_OPEN state. This happens in both |
| 47332 | 47694 | ** normal and exclusive-locking mode. |
| 47333 | 47695 | */ |
| 47696 | + assert( pPager->errCode==SQLITE_OK || !MEMDB ); |
| 47334 | 47697 | if( pPager->errCode ){ |
| 47335 | | - assert( !MEMDB ); |
| 47336 | | - pager_reset(pPager); |
| 47337 | | - pPager->changeCountDone = pPager->tempFile; |
| 47338 | | - pPager->eState = PAGER_OPEN; |
| 47339 | | - pPager->errCode = SQLITE_OK; |
| 47698 | + if( pPager->tempFile==0 ){ |
| 47699 | + pager_reset(pPager); |
| 47700 | + pPager->changeCountDone = 0; |
| 47701 | + pPager->eState = PAGER_OPEN; |
| 47702 | + }else{ |
| 47703 | + pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER); |
| 47704 | + } |
| 47340 | 47705 | if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0); |
| 47706 | + pPager->errCode = SQLITE_OK; |
| 47341 | 47707 | } |
| 47342 | 47708 | |
| 47343 | 47709 | pPager->journalOff = 0; |
| 47344 | 47710 | pPager->journalHdr = 0; |
| 47345 | 47711 | pPager->setMaster = 0; |
| | @@ -47378,10 +47744,33 @@ |
| 47378 | 47744 | } |
| 47379 | 47745 | return rc; |
| 47380 | 47746 | } |
| 47381 | 47747 | |
| 47382 | 47748 | static int pager_truncate(Pager *pPager, Pgno nPage); |
| 47749 | + |
| 47750 | +/* |
| 47751 | +** The write transaction open on pPager is being committed (bCommit==1) |
| 47752 | +** or rolled back (bCommit==0). |
| 47753 | +** |
| 47754 | +** Return TRUE if and only if all dirty pages should be flushed to disk. |
| 47755 | +** |
| 47756 | +** Rules: |
| 47757 | +** |
| 47758 | +** * For non-TEMP databases, always sync to disk. This is necessary |
| 47759 | +** for transactions to be durable. |
| 47760 | +** |
| 47761 | +** * Sync TEMP database only on a COMMIT (not a ROLLBACK) when the backing |
| 47762 | +** file has been created already (via a spill on pagerStress()) and |
| 47763 | +** when the number of dirty pages in memory exceeds 25% of the total |
| 47764 | +** cache size. |
| 47765 | +*/ |
| 47766 | +static int pagerFlushOnCommit(Pager *pPager, int bCommit){ |
| 47767 | + if( pPager->tempFile==0 ) return 1; |
| 47768 | + if( !bCommit ) return 0; |
| 47769 | + if( !isOpen(pPager->fd) ) return 0; |
| 47770 | + return (sqlite3PCachePercentDirty(pPager->pPCache)>=25); |
| 47771 | +} |
| 47383 | 47772 | |
| 47384 | 47773 | /* |
| 47385 | 47774 | ** This routine ends a transaction. A transaction is usually ended by |
| 47386 | 47775 | ** either a COMMIT or a ROLLBACK operation. This routine may be called |
| 47387 | 47776 | ** after rollback of a hot-journal, or if an error occurs while opening |
| | @@ -47482,11 +47871,11 @@ |
| 47482 | 47871 | } |
| 47483 | 47872 | pPager->journalOff = 0; |
| 47484 | 47873 | }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST |
| 47485 | 47874 | || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL) |
| 47486 | 47875 | ){ |
| 47487 | | - rc = zeroJournalHdr(pPager, hasMaster); |
| 47876 | + rc = zeroJournalHdr(pPager, hasMaster||pPager->tempFile); |
| 47488 | 47877 | pPager->journalOff = 0; |
| 47489 | 47878 | }else{ |
| 47490 | 47879 | /* This branch may be executed with Pager.journalMode==MEMORY if |
| 47491 | 47880 | ** a hot-journal was just rolled back. In this case the journal |
| 47492 | 47881 | ** file should be closed and deleted. If this connection writes to |
| | @@ -47517,12 +47906,18 @@ |
| 47517 | 47906 | #endif |
| 47518 | 47907 | |
| 47519 | 47908 | sqlite3BitvecDestroy(pPager->pInJournal); |
| 47520 | 47909 | pPager->pInJournal = 0; |
| 47521 | 47910 | pPager->nRec = 0; |
| 47522 | | - sqlite3PcacheCleanAll(pPager->pPCache); |
| 47523 | | - sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize); |
| 47911 | + if( rc==SQLITE_OK ){ |
| 47912 | + if( pagerFlushOnCommit(pPager, bCommit) ){ |
| 47913 | + sqlite3PcacheCleanAll(pPager->pPCache); |
| 47914 | + }else{ |
| 47915 | + sqlite3PcacheClearWritable(pPager->pPCache); |
| 47916 | + } |
| 47917 | + sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize); |
| 47918 | + } |
| 47524 | 47919 | |
| 47525 | 47920 | if( pagerUseWal(pPager) ){ |
| 47526 | 47921 | /* Drop the WAL write-lock, if any. Also, if the connection was in |
| 47527 | 47922 | ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE |
| 47528 | 47923 | ** lock held on the database file. |
| | @@ -47802,11 +48197,11 @@ |
| 47802 | 48197 | pPg = 0; |
| 47803 | 48198 | }else{ |
| 47804 | 48199 | pPg = sqlite3PagerLookup(pPager, pgno); |
| 47805 | 48200 | } |
| 47806 | 48201 | assert( pPg || !MEMDB ); |
| 47807 | | - assert( pPager->eState!=PAGER_OPEN || pPg==0 ); |
| 48202 | + assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile ); |
| 47808 | 48203 | PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n", |
| 47809 | 48204 | PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData), |
| 47810 | 48205 | (isMainJrnl?"main-journal":"sub-journal") |
| 47811 | 48206 | )); |
| 47812 | 48207 | if( isMainJrnl ){ |
| | @@ -47852,11 +48247,10 @@ |
| 47852 | 48247 | pPager->doNotSpill |= SPILLFLAG_ROLLBACK; |
| 47853 | 48248 | rc = sqlite3PagerGet(pPager, pgno, &pPg, 1); |
| 47854 | 48249 | assert( (pPager->doNotSpill & SPILLFLAG_ROLLBACK)!=0 ); |
| 47855 | 48250 | pPager->doNotSpill &= ~SPILLFLAG_ROLLBACK; |
| 47856 | 48251 | if( rc!=SQLITE_OK ) return rc; |
| 47857 | | - pPg->flags &= ~PGHDR_NEED_READ; |
| 47858 | 48252 | sqlite3PcacheMakeDirty(pPg); |
| 47859 | 48253 | } |
| 47860 | 48254 | if( pPg ){ |
| 47861 | 48255 | /* No page should ever be explicitly rolled back that is in use, except |
| 47862 | 48256 | ** for page 1 which is held in use in order to keep the lock on the |
| | @@ -47866,33 +48260,14 @@ |
| 47866 | 48260 | */ |
| 47867 | 48261 | void *pData; |
| 47868 | 48262 | pData = pPg->pData; |
| 47869 | 48263 | memcpy(pData, (u8*)aData, pPager->pageSize); |
| 47870 | 48264 | pPager->xReiniter(pPg); |
| 47871 | | - if( isMainJrnl && (!isSavepnt || *pOffset<=pPager->journalHdr) ){ |
| 47872 | | - /* If the contents of this page were just restored from the main |
| 47873 | | - ** journal file, then its content must be as they were when the |
| 47874 | | - ** transaction was first opened. In this case we can mark the page |
| 47875 | | - ** as clean, since there will be no need to write it out to the |
| 47876 | | - ** database. |
| 47877 | | - ** |
| 47878 | | - ** There is one exception to this rule. If the page is being rolled |
| 47879 | | - ** back as part of a savepoint (or statement) rollback from an |
| 47880 | | - ** unsynced portion of the main journal file, then it is not safe |
| 47881 | | - ** to mark the page as clean. This is because marking the page as |
| 47882 | | - ** clean will clear the PGHDR_NEED_SYNC flag. Since the page is |
| 47883 | | - ** already in the journal file (recorded in Pager.pInJournal) and |
| 47884 | | - ** the PGHDR_NEED_SYNC flag is cleared, if the page is written to |
| 47885 | | - ** again within this transaction, it will be marked as dirty but |
| 47886 | | - ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially |
| 47887 | | - ** be written out into the database file before its journal file |
| 47888 | | - ** segment is synced. If a crash occurs during or following this, |
| 47889 | | - ** database corruption may ensue. |
| 47890 | | - */ |
| 47891 | | - assert( !pagerUseWal(pPager) ); |
| 47892 | | - sqlite3PcacheMakeClean(pPg); |
| 47893 | | - } |
| 48265 | + /* It used to be that sqlite3PcacheMakeClean(pPg) was called here. But |
| 48266 | + ** that call was dangerous and had no detectable benefit since the cache |
| 48267 | + ** is normally cleaned by sqlite3PcacheCleanAll() after rollback and so |
| 48268 | + ** has been removed. */ |
| 47894 | 48269 | pager_set_pagehash(pPg); |
| 47895 | 48270 | |
| 47896 | 48271 | /* If this was page 1, then restore the value of Pager.dbFileVers. |
| 47897 | 48272 | ** Do this before any decoding. */ |
| 47898 | 48273 | if( pgno==1 ){ |
| | @@ -48679,25 +49054,24 @@ |
| 48679 | 49054 | ** available from the WAL sub-system if the log file is empty or |
| 48680 | 49055 | ** contains no valid committed transactions. |
| 48681 | 49056 | */ |
| 48682 | 49057 | assert( pPager->eState==PAGER_OPEN ); |
| 48683 | 49058 | assert( pPager->eLock>=SHARED_LOCK ); |
| 49059 | + assert( isOpen(pPager->fd) ); |
| 49060 | + assert( pPager->tempFile==0 ); |
| 48684 | 49061 | nPage = sqlite3WalDbsize(pPager->pWal); |
| 48685 | 49062 | |
| 48686 | 49063 | /* If the number of pages in the database is not available from the |
| 48687 | 49064 | ** WAL sub-system, determine the page counte based on the size of |
| 48688 | 49065 | ** the database file. If the size of the database file is not an |
| 48689 | 49066 | ** integer multiple of the page-size, round up the result. |
| 48690 | 49067 | */ |
| 48691 | | - if( nPage==0 ){ |
| 49068 | + if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){ |
| 48692 | 49069 | i64 n = 0; /* Size of db file in bytes */ |
| 48693 | | - assert( isOpen(pPager->fd) || pPager->tempFile ); |
| 48694 | | - if( isOpen(pPager->fd) ){ |
| 48695 | | - int rc = sqlite3OsFileSize(pPager->fd, &n); |
| 48696 | | - if( rc!=SQLITE_OK ){ |
| 48697 | | - return rc; |
| 48698 | | - } |
| 49070 | + int rc = sqlite3OsFileSize(pPager->fd, &n); |
| 49071 | + if( rc!=SQLITE_OK ){ |
| 49072 | + return rc; |
| 48699 | 49073 | } |
| 48700 | 49074 | nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize); |
| 48701 | 49075 | } |
| 48702 | 49076 | |
| 48703 | 49077 | /* If the current number of pages in the file is greater than the |
| | @@ -49769,12 +50143,13 @@ |
| 49769 | 50143 | static int pager_write_pagelist(Pager *pPager, PgHdr *pList){ |
| 49770 | 50144 | int rc = SQLITE_OK; /* Return code */ |
| 49771 | 50145 | |
| 49772 | 50146 | /* This function is only called for rollback pagers in WRITER_DBMOD state. */ |
| 49773 | 50147 | assert( !pagerUseWal(pPager) ); |
| 49774 | | - assert( pPager->eState==PAGER_WRITER_DBMOD ); |
| 50148 | + assert( pPager->tempFile || pPager->eState==PAGER_WRITER_DBMOD ); |
| 49775 | 50149 | assert( pPager->eLock==EXCLUSIVE_LOCK ); |
| 50150 | + assert( isOpen(pPager->fd) || pList->pDirty==0 ); |
| 49776 | 50151 | |
| 49777 | 50152 | /* If the file is a temp-file has not yet been opened, open it now. It |
| 49778 | 50153 | ** is not possible for rc to be other than SQLITE_OK if this branch |
| 49779 | 50154 | ** is taken, as pager_wait_on_lock() is a no-op for temp-files. |
| 49780 | 50155 | */ |
| | @@ -50438,10 +50813,11 @@ |
| 50438 | 50813 | */ |
| 50439 | 50814 | rc = sqlite3OsCheckReservedLock(pPager->fd, &locked); |
| 50440 | 50815 | if( rc==SQLITE_OK && !locked ){ |
| 50441 | 50816 | Pgno nPage; /* Number of pages in database file */ |
| 50442 | 50817 | |
| 50818 | + assert( pPager->tempFile==0 ); |
| 50443 | 50819 | rc = pagerPagecount(pPager, &nPage); |
| 50444 | 50820 | if( rc==SQLITE_OK ){ |
| 50445 | 50821 | /* If the database is zero pages in size, that means that either (1) the |
| 50446 | 50822 | ** journal is a remnant from a prior database with the same name where |
| 50447 | 50823 | ** the database file but not the journal was deleted, or (2) the initial |
| | @@ -50530,21 +50906,21 @@ |
| 50530 | 50906 | int rc = SQLITE_OK; /* Return code */ |
| 50531 | 50907 | |
| 50532 | 50908 | /* This routine is only called from b-tree and only when there are no |
| 50533 | 50909 | ** outstanding pages. This implies that the pager state should either |
| 50534 | 50910 | ** be OPEN or READER. READER is only possible if the pager is or was in |
| 50535 | | - ** exclusive access mode. |
| 50536 | | - */ |
| 50911 | + ** exclusive access mode. */ |
| 50537 | 50912 | assert( sqlite3PcacheRefCount(pPager->pPCache)==0 ); |
| 50538 | 50913 | assert( assert_pager_state(pPager) ); |
| 50539 | 50914 | assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER ); |
| 50540 | | - if( NEVER(MEMDB && pPager->errCode) ){ return pPager->errCode; } |
| 50915 | + assert( pPager->errCode==SQLITE_OK ); |
| 50541 | 50916 | |
| 50542 | 50917 | if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){ |
| 50543 | 50918 | int bHotJournal = 1; /* True if there exists a hot journal-file */ |
| 50544 | 50919 | |
| 50545 | 50920 | assert( !MEMDB ); |
| 50921 | + assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK ); |
| 50546 | 50922 | |
| 50547 | 50923 | rc = pager_wait_on_lock(pPager, SHARED_LOCK); |
| 50548 | 50924 | if( rc!=SQLITE_OK ){ |
| 50549 | 50925 | assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK ); |
| 50550 | 50926 | goto failed; |
| | @@ -50626,11 +51002,11 @@ |
| 50626 | 51002 | */ |
| 50627 | 51003 | if( isOpen(pPager->jfd) ){ |
| 50628 | 51004 | assert( rc==SQLITE_OK ); |
| 50629 | 51005 | rc = pagerSyncHotJournal(pPager); |
| 50630 | 51006 | if( rc==SQLITE_OK ){ |
| 50631 | | - rc = pager_playback(pPager, 1); |
| 51007 | + rc = pager_playback(pPager, !pPager->tempFile); |
| 50632 | 51008 | pPager->eState = PAGER_OPEN; |
| 50633 | 51009 | } |
| 50634 | 51010 | }else if( !pPager->exclusiveMode ){ |
| 50635 | 51011 | pagerUnlockDb(pPager, SHARED_LOCK); |
| 50636 | 51012 | } |
| | @@ -50722,11 +51098,11 @@ |
| 50722 | 51098 | if( pagerUseWal(pPager) ){ |
| 50723 | 51099 | assert( rc==SQLITE_OK ); |
| 50724 | 51100 | rc = pagerBeginReadTransaction(pPager); |
| 50725 | 51101 | } |
| 50726 | 51102 | |
| 50727 | | - if( pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){ |
| 51103 | + if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){ |
| 50728 | 51104 | rc = pagerPagecount(pPager, &pPager->dbSize); |
| 50729 | 51105 | } |
| 50730 | 51106 | |
| 50731 | 51107 | failed: |
| 50732 | 51108 | if( rc!=SQLITE_OK ){ |
| | @@ -50855,11 +51231,11 @@ |
| 50855 | 51231 | rc = sqlite3OsFetch(pPager->fd, |
| 50856 | 51232 | (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData |
| 50857 | 51233 | ); |
| 50858 | 51234 | |
| 50859 | 51235 | if( rc==SQLITE_OK && pData ){ |
| 50860 | | - if( pPager->eState>PAGER_READER ){ |
| 51236 | + if( pPager->eState>PAGER_READER || pPager->tempFile ){ |
| 50861 | 51237 | pPg = sqlite3PagerLookup(pPager, pgno); |
| 50862 | 51238 | } |
| 50863 | 51239 | if( pPg==0 ){ |
| 50864 | 51240 | rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg); |
| 50865 | 51241 | }else{ |
| | @@ -50922,11 +51298,12 @@ |
| 50922 | 51298 | if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){ |
| 50923 | 51299 | rc = SQLITE_CORRUPT_BKPT; |
| 50924 | 51300 | goto pager_acquire_err; |
| 50925 | 51301 | } |
| 50926 | 51302 | |
| 50927 | | - if( MEMDB || pPager->dbSize<pgno || noContent || !isOpen(pPager->fd) ){ |
| 51303 | + assert( !isOpen(pPager->fd) || !MEMDB ); |
| 51304 | + if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){ |
| 50928 | 51305 | if( pgno>pPager->mxPgno ){ |
| 50929 | 51306 | rc = SQLITE_FULL; |
| 50930 | 51307 | goto pager_acquire_err; |
| 50931 | 51308 | } |
| 50932 | 51309 | if( noContent ){ |
| | @@ -51064,28 +51441,28 @@ |
| 51064 | 51441 | /* Open the journal file if it is not already open. */ |
| 51065 | 51442 | if( !isOpen(pPager->jfd) ){ |
| 51066 | 51443 | if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){ |
| 51067 | 51444 | sqlite3MemJournalOpen(pPager->jfd); |
| 51068 | 51445 | }else{ |
| 51069 | | - const int flags = /* VFS flags to open journal file */ |
| 51070 | | - SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| |
| 51071 | | - (pPager->tempFile ? |
| 51072 | | - (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL): |
| 51073 | | - (SQLITE_OPEN_MAIN_JOURNAL) |
| 51074 | | - ); |
| 51446 | + int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE; |
| 51447 | + int nSpill; |
| 51075 | 51448 | |
| 51449 | + if( pPager->tempFile ){ |
| 51450 | + flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL); |
| 51451 | + nSpill = sqlite3Config.nStmtSpill; |
| 51452 | + }else{ |
| 51453 | + flags |= SQLITE_OPEN_MAIN_JOURNAL; |
| 51454 | + nSpill = jrnlBufferSize(pPager); |
| 51455 | + } |
| 51456 | + |
| 51076 | 51457 | /* Verify that the database still has the same name as it did when |
| 51077 | 51458 | ** it was originally opened. */ |
| 51078 | 51459 | rc = databaseIsUnmoved(pPager); |
| 51079 | 51460 | if( rc==SQLITE_OK ){ |
| 51080 | | -#ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 51081 | | - rc = sqlite3JournalOpen( |
| 51082 | | - pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager) |
| 51461 | + rc = sqlite3JournalOpen ( |
| 51462 | + pVfs, pPager->zJournal, pPager->jfd, flags, nSpill |
| 51083 | 51463 | ); |
| 51084 | | -#else |
| 51085 | | - rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0); |
| 51086 | | -#endif |
| 51087 | 51464 | } |
| 51088 | 51465 | } |
| 51089 | 51466 | assert( rc!=SQLITE_OK || isOpen(pPager->jfd) ); |
| 51090 | 51467 | } |
| 51091 | 51468 | |
| | @@ -51452,10 +51829,11 @@ |
| 51452 | 51829 | return pPager->errCode; |
| 51453 | 51830 | }else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){ |
| 51454 | 51831 | if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg); |
| 51455 | 51832 | return SQLITE_OK; |
| 51456 | 51833 | }else if( pPager->sectorSize > (u32)pPager->pageSize ){ |
| 51834 | + assert( pPager->tempFile==0 ); |
| 51457 | 51835 | return pagerWriteLargeSector(pPg); |
| 51458 | 51836 | }else{ |
| 51459 | 51837 | return pager_write(pPg); |
| 51460 | 51838 | } |
| 51461 | 51839 | } |
| | @@ -51482,18 +51860,25 @@ |
| 51482 | 51860 | ** on the given page is unused. The pager marks the page as clean so |
| 51483 | 51861 | ** that it does not get written to disk. |
| 51484 | 51862 | ** |
| 51485 | 51863 | ** Tests show that this optimization can quadruple the speed of large |
| 51486 | 51864 | ** DELETE operations. |
| 51865 | +** |
| 51866 | +** This optimization cannot be used with a temp-file, as the page may |
| 51867 | +** have been dirty at the start of the transaction. In that case, if |
| 51868 | +** memory pressure forces page pPg out of the cache, the data does need |
| 51869 | +** to be written out to disk so that it may be read back in if the |
| 51870 | +** current transaction is rolled back. |
| 51487 | 51871 | */ |
| 51488 | 51872 | SQLITE_PRIVATE void sqlite3PagerDontWrite(PgHdr *pPg){ |
| 51489 | 51873 | Pager *pPager = pPg->pPager; |
| 51490 | | - if( (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){ |
| 51874 | + if( !pPager->tempFile && (pPg->flags&PGHDR_DIRTY) && pPager->nSavepoint==0 ){ |
| 51491 | 51875 | PAGERTRACE(("DONT_WRITE page %d of %d\n", pPg->pgno, PAGERID(pPager))); |
| 51492 | 51876 | IOTRACE(("CLEAN %p %d\n", pPager, pPg->pgno)) |
| 51493 | 51877 | pPg->flags |= PGHDR_DONT_WRITE; |
| 51494 | 51878 | pPg->flags &= ~PGHDR_WRITEABLE; |
| 51879 | + testcase( pPg->flags & PGHDR_NEED_SYNC ); |
| 51495 | 51880 | pager_set_pagehash(pPg); |
| 51496 | 51881 | } |
| 51497 | 51882 | } |
| 51498 | 51883 | |
| 51499 | 51884 | /* |
| | @@ -51683,22 +52068,26 @@ |
| 51683 | 52068 | ); |
| 51684 | 52069 | assert( assert_pager_state(pPager) ); |
| 51685 | 52070 | |
| 51686 | 52071 | /* If a prior error occurred, report that error again. */ |
| 51687 | 52072 | if( NEVER(pPager->errCode) ) return pPager->errCode; |
| 52073 | + |
| 52074 | + /* Provide the ability to easily simulate an I/O error during testing */ |
| 52075 | + if( sqlite3FaultSim(400) ) return SQLITE_IOERR; |
| 51688 | 52076 | |
| 51689 | 52077 | PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n", |
| 51690 | 52078 | pPager->zFilename, zMaster, pPager->dbSize)); |
| 51691 | 52079 | |
| 51692 | 52080 | /* If no database changes have been made, return early. */ |
| 51693 | 52081 | if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK; |
| 51694 | 52082 | |
| 51695 | | - if( MEMDB ){ |
| 52083 | + assert( MEMDB==0 || pPager->tempFile ); |
| 52084 | + assert( isOpen(pPager->fd) || pPager->tempFile ); |
| 52085 | + if( 0==pagerFlushOnCommit(pPager, 1) ){ |
| 51696 | 52086 | /* If this is an in-memory db, or no pages have been written to, or this |
| 51697 | 52087 | ** function has already been called, it is mostly a no-op. However, any |
| 51698 | | - ** backup in progress needs to be restarted. |
| 51699 | | - */ |
| 52088 | + ** backup in progress needs to be restarted. */ |
| 51700 | 52089 | sqlite3BackupRestart(pPager->pBackup); |
| 51701 | 52090 | }else{ |
| 51702 | 52091 | if( pagerUseWal(pPager) ){ |
| 51703 | 52092 | PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache); |
| 51704 | 52093 | PgHdr *pPageOne = 0; |
| | @@ -52033,14 +52422,14 @@ |
| 52033 | 52422 | pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0; |
| 52034 | 52423 | } |
| 52035 | 52424 | } |
| 52036 | 52425 | |
| 52037 | 52426 | /* |
| 52038 | | -** Return true if this is an in-memory pager. |
| 52427 | +** Return true if this is an in-memory or temp-file backed pager. |
| 52039 | 52428 | */ |
| 52040 | 52429 | SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){ |
| 52041 | | - return MEMDB; |
| 52430 | + return pPager->tempFile; |
| 52042 | 52431 | } |
| 52043 | 52432 | |
| 52044 | 52433 | /* |
| 52045 | 52434 | ** Check that there are at least nSavepoint savepoints open. If there are |
| 52046 | 52435 | ** currently less than nSavepoints open, then open one or more savepoints |
| | @@ -52316,11 +52705,12 @@ |
| 52316 | 52705 | assert( assert_pager_state(pPager) ); |
| 52317 | 52706 | |
| 52318 | 52707 | /* In order to be able to rollback, an in-memory database must journal |
| 52319 | 52708 | ** the page we are moving from. |
| 52320 | 52709 | */ |
| 52321 | | - if( MEMDB ){ |
| 52710 | + assert( pPager->tempFile || !MEMDB ); |
| 52711 | + if( pPager->tempFile ){ |
| 52322 | 52712 | rc = sqlite3PagerWrite(pPg); |
| 52323 | 52713 | if( rc ) return rc; |
| 52324 | 52714 | } |
| 52325 | 52715 | |
| 52326 | 52716 | /* If the page being moved is dirty and has not been saved by the latest |
| | @@ -52373,11 +52763,11 @@ |
| 52373 | 52763 | pPg->flags &= ~PGHDR_NEED_SYNC; |
| 52374 | 52764 | pPgOld = sqlite3PagerLookup(pPager, pgno); |
| 52375 | 52765 | assert( !pPgOld || pPgOld->nRef==1 ); |
| 52376 | 52766 | if( pPgOld ){ |
| 52377 | 52767 | pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC); |
| 52378 | | - if( MEMDB ){ |
| 52768 | + if( pPager->tempFile ){ |
| 52379 | 52769 | /* Do not discard pages from an in-memory database since we might |
| 52380 | 52770 | ** need to rollback later. Just move the page out of the way. */ |
| 52381 | 52771 | sqlite3PcacheMove(pPgOld, pPager->dbSize+1); |
| 52382 | 52772 | }else{ |
| 52383 | 52773 | sqlite3PcacheDrop(pPgOld); |
| | @@ -52390,12 +52780,11 @@ |
| 52390 | 52780 | |
| 52391 | 52781 | /* For an in-memory database, make sure the original page continues |
| 52392 | 52782 | ** to exist, in case the transaction needs to roll back. Use pPgOld |
| 52393 | 52783 | ** as the original page since it has already been allocated. |
| 52394 | 52784 | */ |
| 52395 | | - if( MEMDB ){ |
| 52396 | | - assert( pPgOld ); |
| 52785 | + if( pPager->tempFile && pPgOld ){ |
| 52397 | 52786 | sqlite3PcacheMove(pPgOld, origPgno); |
| 52398 | 52787 | sqlite3PagerUnrefNotNull(pPgOld); |
| 52399 | 52788 | } |
| 52400 | 52789 | |
| 52401 | 52790 | if( needSyncPgno ){ |
| | @@ -52643,11 +53032,12 @@ |
| 52643 | 53032 | #ifndef SQLITE_OMIT_VACUUM |
| 52644 | 53033 | /* |
| 52645 | 53034 | ** Unless this is an in-memory or temporary database, clear the pager cache. |
| 52646 | 53035 | */ |
| 52647 | 53036 | SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *pPager){ |
| 52648 | | - if( !MEMDB && pPager->tempFile==0 ) pager_reset(pPager); |
| 53037 | + assert( MEMDB==0 || pPager->tempFile ); |
| 53038 | + if( pPager->tempFile==0 ) pager_reset(pPager); |
| 52649 | 53039 | } |
| 52650 | 53040 | #endif |
| 52651 | 53041 | |
| 52652 | 53042 | #ifndef SQLITE_OMIT_WAL |
| 52653 | 53043 | /* |
| | @@ -52822,10 +53212,11 @@ |
| 52822 | 53212 | if( rc==SQLITE_OK ){ |
| 52823 | 53213 | rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags, |
| 52824 | 53214 | pPager->pageSize, (u8*)pPager->pTmpSpace); |
| 52825 | 53215 | pPager->pWal = 0; |
| 52826 | 53216 | pagerFixMaplimit(pPager); |
| 53217 | + if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK); |
| 52827 | 53218 | } |
| 52828 | 53219 | } |
| 52829 | 53220 | return rc; |
| 52830 | 53221 | } |
| 52831 | 53222 | |
| | @@ -56277,10 +56668,27 @@ |
| 56277 | 56668 | /* Try to open on pSnapshot when the next read-transaction starts |
| 56278 | 56669 | */ |
| 56279 | 56670 | SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){ |
| 56280 | 56671 | pWal->pSnapshot = (WalIndexHdr*)pSnapshot; |
| 56281 | 56672 | } |
| 56673 | + |
| 56674 | +/* |
| 56675 | +** Return a +ve value if snapshot p1 is newer than p2. A -ve value if |
| 56676 | +** p1 is older than p2 and zero if p1 and p2 are the same snapshot. |
| 56677 | +*/ |
| 56678 | +SQLITE_API int SQLITE_STDCALL sqlite3_snapshot_cmp(sqlite3_snapshot *p1, sqlite3_snapshot *p2){ |
| 56679 | + WalIndexHdr *pHdr1 = (WalIndexHdr*)p1; |
| 56680 | + WalIndexHdr *pHdr2 = (WalIndexHdr*)p2; |
| 56681 | + |
| 56682 | + /* aSalt[0] is a copy of the value stored in the wal file header. It |
| 56683 | + ** is incremented each time the wal file is restarted. */ |
| 56684 | + if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1; |
| 56685 | + if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1; |
| 56686 | + if( pHdr1->mxFrame<pHdr2->mxFrame ) return -1; |
| 56687 | + if( pHdr1->mxFrame>pHdr2->mxFrame ) return +1; |
| 56688 | + return 0; |
| 56689 | +} |
| 56282 | 56690 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
| 56283 | 56691 | |
| 56284 | 56692 | #ifdef SQLITE_ENABLE_ZIPVFS |
| 56285 | 56693 | /* |
| 56286 | 56694 | ** If the argument is not NULL, it points to a Wal object that holds a |
| | @@ -58992,15 +59400,15 @@ |
| 58992 | 59400 | flagByte &= ~PTF_LEAF; |
| 58993 | 59401 | pPage->childPtrSize = 4-4*pPage->leaf; |
| 58994 | 59402 | pPage->xCellSize = cellSizePtr; |
| 58995 | 59403 | pBt = pPage->pBt; |
| 58996 | 59404 | if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){ |
| 58997 | | - /* EVIDENCE-OF: R-03640-13415 A value of 5 means the page is an interior |
| 58998 | | - ** table b-tree page. */ |
| 59405 | + /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an |
| 59406 | + ** interior table b-tree page. */ |
| 58999 | 59407 | assert( (PTF_LEAFDATA|PTF_INTKEY)==5 ); |
| 59000 | | - /* EVIDENCE-OF: R-20501-61796 A value of 13 means the page is a leaf |
| 59001 | | - ** table b-tree page. */ |
| 59408 | + /* EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a |
| 59409 | + ** leaf table b-tree page. */ |
| 59002 | 59410 | assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 ); |
| 59003 | 59411 | pPage->intKey = 1; |
| 59004 | 59412 | if( pPage->leaf ){ |
| 59005 | 59413 | pPage->intKeyLeaf = 1; |
| 59006 | 59414 | pPage->xParseCell = btreeParseCellPtr; |
| | @@ -59010,15 +59418,15 @@ |
| 59010 | 59418 | pPage->xParseCell = btreeParseCellPtrNoPayload; |
| 59011 | 59419 | } |
| 59012 | 59420 | pPage->maxLocal = pBt->maxLeaf; |
| 59013 | 59421 | pPage->minLocal = pBt->minLeaf; |
| 59014 | 59422 | }else if( flagByte==PTF_ZERODATA ){ |
| 59015 | | - /* EVIDENCE-OF: R-27225-53936 A value of 2 means the page is an interior |
| 59016 | | - ** index b-tree page. */ |
| 59423 | + /* EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an |
| 59424 | + ** interior index b-tree page. */ |
| 59017 | 59425 | assert( (PTF_ZERODATA)==2 ); |
| 59018 | | - /* EVIDENCE-OF: R-16571-11615 A value of 10 means the page is a leaf |
| 59019 | | - ** index b-tree page. */ |
| 59426 | + /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a |
| 59427 | + ** leaf index b-tree page. */ |
| 59020 | 59428 | assert( (PTF_ZERODATA|PTF_LEAF)==10 ); |
| 59021 | 59429 | pPage->intKey = 0; |
| 59022 | 59430 | pPage->intKeyLeaf = 0; |
| 59023 | 59431 | pPage->xParseCell = btreeParseCellPtrIndex; |
| 59024 | 59432 | pPage->maxLocal = pBt->maxLocal; |
| | @@ -65455,10 +65863,32 @@ |
| 65455 | 65863 | |
| 65456 | 65864 | iCellDepth = pCur->iPage; |
| 65457 | 65865 | iCellIdx = pCur->aiIdx[iCellDepth]; |
| 65458 | 65866 | pPage = pCur->apPage[iCellDepth]; |
| 65459 | 65867 | pCell = findCell(pPage, iCellIdx); |
| 65868 | + |
| 65869 | + /* If the bPreserve flag is set to true, then the cursor position must |
| 65870 | + ** be preserved following this delete operation. If the current delete |
| 65871 | + ** will cause a b-tree rebalance, then this is done by saving the cursor |
| 65872 | + ** key and leaving the cursor in CURSOR_REQUIRESEEK state before |
| 65873 | + ** returning. |
| 65874 | + ** |
| 65875 | + ** Or, if the current delete will not cause a rebalance, then the cursor |
| 65876 | + ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately |
| 65877 | + ** before or after the deleted entry. In this case set bSkipnext to true. */ |
| 65878 | + if( bPreserve ){ |
| 65879 | + if( !pPage->leaf |
| 65880 | + || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) |
| 65881 | + ){ |
| 65882 | + /* A b-tree rebalance will be required after deleting this entry. |
| 65883 | + ** Save the cursor key. */ |
| 65884 | + rc = saveCursorKey(pCur); |
| 65885 | + if( rc ) return rc; |
| 65886 | + }else{ |
| 65887 | + bSkipnext = 1; |
| 65888 | + } |
| 65889 | + } |
| 65460 | 65890 | |
| 65461 | 65891 | /* If the page containing the entry to delete is not a leaf page, move |
| 65462 | 65892 | ** the cursor to the largest entry in the tree that is smaller than |
| 65463 | 65893 | ** the entry being deleted. This cell will replace the cell being deleted |
| 65464 | 65894 | ** from the internal node. The 'previous' entry is used for this instead |
| | @@ -65482,32 +65912,10 @@ |
| 65482 | 65912 | ** invalidate any incrblob cursors open on the row being deleted. */ |
| 65483 | 65913 | if( pCur->pKeyInfo==0 ){ |
| 65484 | 65914 | invalidateIncrblobCursors(p, pCur->info.nKey, 0); |
| 65485 | 65915 | } |
| 65486 | 65916 | |
| 65487 | | - /* If the bPreserve flag is set to true, then the cursor position must |
| 65488 | | - ** be preserved following this delete operation. If the current delete |
| 65489 | | - ** will cause a b-tree rebalance, then this is done by saving the cursor |
| 65490 | | - ** key and leaving the cursor in CURSOR_REQUIRESEEK state before |
| 65491 | | - ** returning. |
| 65492 | | - ** |
| 65493 | | - ** Or, if the current delete will not cause a rebalance, then the cursor |
| 65494 | | - ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately |
| 65495 | | - ** before or after the deleted entry. In this case set bSkipnext to true. */ |
| 65496 | | - if( bPreserve ){ |
| 65497 | | - if( !pPage->leaf |
| 65498 | | - || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) |
| 65499 | | - ){ |
| 65500 | | - /* A b-tree rebalance will be required after deleting this entry. |
| 65501 | | - ** Save the cursor key. */ |
| 65502 | | - rc = saveCursorKey(pCur); |
| 65503 | | - if( rc ) return rc; |
| 65504 | | - }else{ |
| 65505 | | - bSkipnext = 1; |
| 65506 | | - } |
| 65507 | | - } |
| 65508 | | - |
| 65509 | 65917 | /* Make the page containing the entry to be deleted writable. Then free any |
| 65510 | 65918 | ** overflow pages associated with the entry and finally remove the cell |
| 65511 | 65919 | ** itself from within the page. */ |
| 65512 | 65920 | rc = sqlite3PagerWrite(pPage->pDbPage); |
| 65513 | 65921 | if( rc ) return rc; |
| | @@ -70082,77 +70490,88 @@ |
| 70082 | 70490 | ** indicate what the prepared statement actually does. |
| 70083 | 70491 | ** |
| 70084 | 70492 | ** (4) Initialize the p4.xAdvance pointer on opcodes that use it. |
| 70085 | 70493 | ** |
| 70086 | 70494 | ** (5) Reclaim the memory allocated for storing labels. |
| 70495 | +** |
| 70496 | +** This routine will only function correctly if the mkopcodeh.tcl generator |
| 70497 | +** script numbers the opcodes correctly. Changes to this routine must be |
| 70498 | +** coordinated with changes to mkopcodeh.tcl. |
| 70087 | 70499 | */ |
| 70088 | 70500 | static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ |
| 70089 | | - int i; |
| 70090 | 70501 | int nMaxArgs = *pMaxFuncArgs; |
| 70091 | 70502 | Op *pOp; |
| 70092 | 70503 | Parse *pParse = p->pParse; |
| 70093 | 70504 | int *aLabel = pParse->aLabel; |
| 70094 | 70505 | p->readOnly = 1; |
| 70095 | 70506 | p->bIsReader = 0; |
| 70096 | | - for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ |
| 70097 | | - u8 opcode = pOp->opcode; |
| 70098 | | - |
| 70099 | | - /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing |
| 70100 | | - ** cases from this switch! */ |
| 70101 | | - switch( opcode ){ |
| 70102 | | - case OP_Transaction: { |
| 70103 | | - if( pOp->p2!=0 ) p->readOnly = 0; |
| 70104 | | - /* fall thru */ |
| 70105 | | - } |
| 70106 | | - case OP_AutoCommit: |
| 70107 | | - case OP_Savepoint: { |
| 70108 | | - p->bIsReader = 1; |
| 70109 | | - break; |
| 70110 | | - } |
| 70507 | + pOp = &p->aOp[p->nOp-1]; |
| 70508 | + while(1){ |
| 70509 | + |
| 70510 | + /* Only JUMP opcodes and the short list of special opcodes in the switch |
| 70511 | + ** below need to be considered. The mkopcodeh.tcl generator script groups |
| 70512 | + ** all these opcodes together near the front of the opcode list. Skip |
| 70513 | + ** any opcode that does not need processing by virtual of the fact that |
| 70514 | + ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization. |
| 70515 | + */ |
| 70516 | + if( pOp->opcode<=SQLITE_MX_JUMP_OPCODE ){ |
| 70517 | + /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing |
| 70518 | + ** cases from this switch! */ |
| 70519 | + switch( pOp->opcode ){ |
| 70520 | + case OP_Transaction: { |
| 70521 | + if( pOp->p2!=0 ) p->readOnly = 0; |
| 70522 | + /* fall thru */ |
| 70523 | + } |
| 70524 | + case OP_AutoCommit: |
| 70525 | + case OP_Savepoint: { |
| 70526 | + p->bIsReader = 1; |
| 70527 | + break; |
| 70528 | + } |
| 70111 | 70529 | #ifndef SQLITE_OMIT_WAL |
| 70112 | | - case OP_Checkpoint: |
| 70530 | + case OP_Checkpoint: |
| 70113 | 70531 | #endif |
| 70114 | | - case OP_Vacuum: |
| 70115 | | - case OP_JournalMode: { |
| 70116 | | - p->readOnly = 0; |
| 70117 | | - p->bIsReader = 1; |
| 70118 | | - break; |
| 70119 | | - } |
| 70532 | + case OP_Vacuum: |
| 70533 | + case OP_JournalMode: { |
| 70534 | + p->readOnly = 0; |
| 70535 | + p->bIsReader = 1; |
| 70536 | + break; |
| 70537 | + } |
| 70120 | 70538 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 70121 | | - case OP_VUpdate: { |
| 70122 | | - if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; |
| 70123 | | - break; |
| 70124 | | - } |
| 70125 | | - case OP_VFilter: { |
| 70126 | | - int n; |
| 70127 | | - assert( p->nOp - i >= 3 ); |
| 70128 | | - assert( pOp[-1].opcode==OP_Integer ); |
| 70129 | | - n = pOp[-1].p1; |
| 70130 | | - if( n>nMaxArgs ) nMaxArgs = n; |
| 70131 | | - break; |
| 70132 | | - } |
| 70133 | | -#endif |
| 70134 | | - case OP_Next: |
| 70135 | | - case OP_NextIfOpen: |
| 70136 | | - case OP_SorterNext: { |
| 70137 | | - pOp->p4.xAdvance = sqlite3BtreeNext; |
| 70138 | | - pOp->p4type = P4_ADVANCE; |
| 70139 | | - break; |
| 70140 | | - } |
| 70141 | | - case OP_Prev: |
| 70142 | | - case OP_PrevIfOpen: { |
| 70143 | | - pOp->p4.xAdvance = sqlite3BtreePrevious; |
| 70144 | | - pOp->p4type = P4_ADVANCE; |
| 70145 | | - break; |
| 70146 | | - } |
| 70147 | | - } |
| 70148 | | - |
| 70149 | | - pOp->opflags = sqlite3OpcodeProperty[opcode]; |
| 70150 | | - if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 70151 | | - assert( ADDR(pOp->p2)<pParse->nLabel ); |
| 70152 | | - pOp->p2 = aLabel[ADDR(pOp->p2)]; |
| 70153 | | - } |
| 70539 | + case OP_VUpdate: { |
| 70540 | + if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; |
| 70541 | + break; |
| 70542 | + } |
| 70543 | + case OP_VFilter: { |
| 70544 | + int n; |
| 70545 | + assert( (pOp - p->aOp) >= 3 ); |
| 70546 | + assert( pOp[-1].opcode==OP_Integer ); |
| 70547 | + n = pOp[-1].p1; |
| 70548 | + if( n>nMaxArgs ) nMaxArgs = n; |
| 70549 | + break; |
| 70550 | + } |
| 70551 | +#endif |
| 70552 | + case OP_Next: |
| 70553 | + case OP_NextIfOpen: |
| 70554 | + case OP_SorterNext: { |
| 70555 | + pOp->p4.xAdvance = sqlite3BtreeNext; |
| 70556 | + pOp->p4type = P4_ADVANCE; |
| 70557 | + break; |
| 70558 | + } |
| 70559 | + case OP_Prev: |
| 70560 | + case OP_PrevIfOpen: { |
| 70561 | + pOp->p4.xAdvance = sqlite3BtreePrevious; |
| 70562 | + pOp->p4type = P4_ADVANCE; |
| 70563 | + break; |
| 70564 | + } |
| 70565 | + } |
| 70566 | + if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 70567 | + assert( ADDR(pOp->p2)<pParse->nLabel ); |
| 70568 | + pOp->p2 = aLabel[ADDR(pOp->p2)]; |
| 70569 | + } |
| 70570 | + } |
| 70571 | + if( pOp==p->aOp ) break; |
| 70572 | + pOp--; |
| 70154 | 70573 | } |
| 70155 | 70574 | sqlite3DbFree(p->db, pParse->aLabel); |
| 70156 | 70575 | pParse->aLabel = 0; |
| 70157 | 70576 | pParse->nLabel = 0; |
| 70158 | 70577 | *pMaxFuncArgs = nMaxArgs; |
| | @@ -76380,11 +76799,11 @@ |
| 76380 | 76799 | nByte = |
| 76381 | 76800 | ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + |
| 76382 | 76801 | (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0); |
| 76383 | 76802 | |
| 76384 | 76803 | assert( iCur>=0 && iCur<p->nCursor ); |
| 76385 | | - if( p->apCsr[iCur] ){ |
| 76804 | + if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/ |
| 76386 | 76805 | sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); |
| 76387 | 76806 | p->apCsr[iCur] = 0; |
| 76388 | 76807 | } |
| 76389 | 76808 | if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){ |
| 76390 | 76809 | p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; |
| | @@ -76457,24 +76876,27 @@ |
| 76457 | 76876 | u8 enc /* Use this text encoding */ |
| 76458 | 76877 | ){ |
| 76459 | 76878 | if( affinity>=SQLITE_AFF_NUMERIC ){ |
| 76460 | 76879 | assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL |
| 76461 | 76880 | || affinity==SQLITE_AFF_NUMERIC ); |
| 76462 | | - if( (pRec->flags & MEM_Int)==0 ){ |
| 76881 | + if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/ |
| 76463 | 76882 | if( (pRec->flags & MEM_Real)==0 ){ |
| 76464 | 76883 | if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1); |
| 76465 | 76884 | }else{ |
| 76466 | 76885 | sqlite3VdbeIntegerAffinity(pRec); |
| 76467 | 76886 | } |
| 76468 | 76887 | } |
| 76469 | 76888 | }else if( affinity==SQLITE_AFF_TEXT ){ |
| 76470 | 76889 | /* Only attempt the conversion to TEXT if there is an integer or real |
| 76471 | 76890 | ** representation (blob and NULL do not get converted) but no string |
| 76472 | | - ** representation. |
| 76473 | | - */ |
| 76474 | | - if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){ |
| 76475 | | - sqlite3VdbeMemStringify(pRec, enc, 1); |
| 76891 | + ** representation. It would be harmless to repeat the conversion if |
| 76892 | + ** there is already a string rep, but it is pointless to waste those |
| 76893 | + ** CPU cycles. */ |
| 76894 | + if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/ |
| 76895 | + if( (pRec->flags&(MEM_Real|MEM_Int)) ){ |
| 76896 | + sqlite3VdbeMemStringify(pRec, enc, 1); |
| 76897 | + } |
| 76476 | 76898 | } |
| 76477 | 76899 | pRec->flags &= ~(MEM_Real|MEM_Int); |
| 76478 | 76900 | } |
| 76479 | 76901 | } |
| 76480 | 76902 | |
| | @@ -76796,11 +77218,11 @@ |
| 76796 | 77218 | Mem *pOut; |
| 76797 | 77219 | assert( pOp->p2>0 ); |
| 76798 | 77220 | assert( pOp->p2<=(p->nMem+1 - p->nCursor) ); |
| 76799 | 77221 | pOut = &p->aMem[pOp->p2]; |
| 76800 | 77222 | memAboutToChange(p, pOut); |
| 76801 | | - if( VdbeMemDynamic(pOut) ){ |
| 77223 | + if( VdbeMemDynamic(pOut) ){ /*OPTIMIZATION-IF-FALSE*/ |
| 76802 | 77224 | return out2PrereleaseWithClear(pOut); |
| 76803 | 77225 | }else{ |
| 76804 | 77226 | pOut->flags = MEM_Int; |
| 76805 | 77227 | return pOut; |
| 76806 | 77228 | } |
| | @@ -76928,41 +77350,43 @@ |
| 76928 | 77350 | } |
| 76929 | 77351 | #endif |
| 76930 | 77352 | |
| 76931 | 77353 | /* Sanity checking on other operands */ |
| 76932 | 77354 | #ifdef SQLITE_DEBUG |
| 76933 | | - assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] ); |
| 76934 | | - if( (pOp->opflags & OPFLG_IN1)!=0 ){ |
| 76935 | | - assert( pOp->p1>0 ); |
| 76936 | | - assert( pOp->p1<=(p->nMem+1 - p->nCursor) ); |
| 76937 | | - assert( memIsValid(&aMem[pOp->p1]) ); |
| 76938 | | - assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) ); |
| 76939 | | - REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]); |
| 76940 | | - } |
| 76941 | | - if( (pOp->opflags & OPFLG_IN2)!=0 ){ |
| 76942 | | - assert( pOp->p2>0 ); |
| 76943 | | - assert( pOp->p2<=(p->nMem+1 - p->nCursor) ); |
| 76944 | | - assert( memIsValid(&aMem[pOp->p2]) ); |
| 76945 | | - assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) ); |
| 76946 | | - REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]); |
| 76947 | | - } |
| 76948 | | - if( (pOp->opflags & OPFLG_IN3)!=0 ){ |
| 76949 | | - assert( pOp->p3>0 ); |
| 76950 | | - assert( pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 76951 | | - assert( memIsValid(&aMem[pOp->p3]) ); |
| 76952 | | - assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) ); |
| 76953 | | - REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]); |
| 76954 | | - } |
| 76955 | | - if( (pOp->opflags & OPFLG_OUT2)!=0 ){ |
| 76956 | | - assert( pOp->p2>0 ); |
| 76957 | | - assert( pOp->p2<=(p->nMem+1 - p->nCursor) ); |
| 76958 | | - memAboutToChange(p, &aMem[pOp->p2]); |
| 76959 | | - } |
| 76960 | | - if( (pOp->opflags & OPFLG_OUT3)!=0 ){ |
| 76961 | | - assert( pOp->p3>0 ); |
| 76962 | | - assert( pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 76963 | | - memAboutToChange(p, &aMem[pOp->p3]); |
| 77355 | + { |
| 77356 | + u8 opProperty = sqlite3OpcodeProperty[pOp->opcode]; |
| 77357 | + if( (opProperty & OPFLG_IN1)!=0 ){ |
| 77358 | + assert( pOp->p1>0 ); |
| 77359 | + assert( pOp->p1<=(p->nMem+1 - p->nCursor) ); |
| 77360 | + assert( memIsValid(&aMem[pOp->p1]) ); |
| 77361 | + assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) ); |
| 77362 | + REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]); |
| 77363 | + } |
| 77364 | + if( (opProperty & OPFLG_IN2)!=0 ){ |
| 77365 | + assert( pOp->p2>0 ); |
| 77366 | + assert( pOp->p2<=(p->nMem+1 - p->nCursor) ); |
| 77367 | + assert( memIsValid(&aMem[pOp->p2]) ); |
| 77368 | + assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) ); |
| 77369 | + REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]); |
| 77370 | + } |
| 77371 | + if( (opProperty & OPFLG_IN3)!=0 ){ |
| 77372 | + assert( pOp->p3>0 ); |
| 77373 | + assert( pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 77374 | + assert( memIsValid(&aMem[pOp->p3]) ); |
| 77375 | + assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) ); |
| 77376 | + REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]); |
| 77377 | + } |
| 77378 | + if( (opProperty & OPFLG_OUT2)!=0 ){ |
| 77379 | + assert( pOp->p2>0 ); |
| 77380 | + assert( pOp->p2<=(p->nMem+1 - p->nCursor) ); |
| 77381 | + memAboutToChange(p, &aMem[pOp->p2]); |
| 77382 | + } |
| 77383 | + if( (opProperty & OPFLG_OUT3)!=0 ){ |
| 77384 | + assert( pOp->p3>0 ); |
| 77385 | + assert( pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 77386 | + memAboutToChange(p, &aMem[pOp->p3]); |
| 77387 | + } |
| 76964 | 77388 | } |
| 76965 | 77389 | #endif |
| 76966 | 77390 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 76967 | 77391 | pOrigOp = pOp; |
| 76968 | 77392 | #endif |
| | @@ -77198,12 +77622,10 @@ |
| 77198 | 77622 | ** There is an implied "Halt 0 0 0" instruction inserted at the very end of |
| 77199 | 77623 | ** every program. So a jump past the last instruction of the program |
| 77200 | 77624 | ** is the same as executing Halt. |
| 77201 | 77625 | */ |
| 77202 | 77626 | case OP_Halt: { |
| 77203 | | - const char *zType; |
| 77204 | | - const char *zLogFmt; |
| 77205 | 77627 | VdbeFrame *pFrame; |
| 77206 | 77628 | int pcx; |
| 77207 | 77629 | |
| 77208 | 77630 | pcx = (int)(pOp - aOp); |
| 77209 | 77631 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| | @@ -77228,38 +77650,32 @@ |
| 77228 | 77650 | break; |
| 77229 | 77651 | } |
| 77230 | 77652 | p->rc = pOp->p1; |
| 77231 | 77653 | p->errorAction = (u8)pOp->p2; |
| 77232 | 77654 | p->pc = pcx; |
| 77655 | + assert( pOp->p5>=0 && pOp->p5<=4 ); |
| 77233 | 77656 | if( p->rc ){ |
| 77234 | 77657 | if( pOp->p5 ){ |
| 77235 | 77658 | static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK", |
| 77236 | 77659 | "FOREIGN KEY" }; |
| 77237 | | - assert( pOp->p5>=1 && pOp->p5<=4 ); |
| 77238 | 77660 | testcase( pOp->p5==1 ); |
| 77239 | 77661 | testcase( pOp->p5==2 ); |
| 77240 | 77662 | testcase( pOp->p5==3 ); |
| 77241 | 77663 | testcase( pOp->p5==4 ); |
| 77242 | | - zType = azType[pOp->p5-1]; |
| 77664 | + sqlite3VdbeError(p, "%s constraint failed", azType[pOp->p5-1]); |
| 77665 | + if( pOp->p4.z ){ |
| 77666 | + p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z); |
| 77667 | + } |
| 77243 | 77668 | }else{ |
| 77244 | | - zType = 0; |
| 77245 | | - } |
| 77246 | | - assert( zType!=0 || pOp->p4.z!=0 ); |
| 77247 | | - zLogFmt = "abort at %d in [%s]: %s"; |
| 77248 | | - if( zType && pOp->p4.z ){ |
| 77249 | | - sqlite3VdbeError(p, "%s constraint failed: %s", zType, pOp->p4.z); |
| 77250 | | - }else if( pOp->p4.z ){ |
| 77251 | 77669 | sqlite3VdbeError(p, "%s", pOp->p4.z); |
| 77252 | | - }else{ |
| 77253 | | - sqlite3VdbeError(p, "%s constraint failed", zType); |
| 77254 | 77670 | } |
| 77255 | | - sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg); |
| 77671 | + sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg); |
| 77256 | 77672 | } |
| 77257 | 77673 | rc = sqlite3VdbeHalt(p); |
| 77258 | 77674 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 77259 | 77675 | if( rc==SQLITE_BUSY ){ |
| 77260 | | - p->rc = rc = SQLITE_BUSY; |
| 77676 | + p->rc = SQLITE_BUSY; |
| 77261 | 77677 | }else{ |
| 77262 | 77678 | assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT ); |
| 77263 | 77679 | assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 ); |
| 77264 | 77680 | rc = p->rc ? SQLITE_ERROR : SQLITE_DONE; |
| 77265 | 77681 | } |
| | @@ -77321,14 +77737,11 @@ |
| 77321 | 77737 | pOp->p1 = sqlite3Strlen30(pOp->p4.z); |
| 77322 | 77738 | |
| 77323 | 77739 | #ifndef SQLITE_OMIT_UTF16 |
| 77324 | 77740 | if( encoding!=SQLITE_UTF8 ){ |
| 77325 | 77741 | rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC); |
| 77326 | | - if( rc ){ |
| 77327 | | - assert( rc==SQLITE_TOOBIG ); /* This is the only possible error here */ |
| 77328 | | - goto too_big; |
| 77329 | | - } |
| 77742 | + assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG ); |
| 77330 | 77743 | if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem; |
| 77331 | 77744 | assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z ); |
| 77332 | 77745 | assert( VdbeMemDynamic(pOut)==0 ); |
| 77333 | 77746 | pOut->szMalloc = 0; |
| 77334 | 77747 | pOut->flags |= MEM_Static; |
| | @@ -77337,26 +77750,30 @@ |
| 77337 | 77750 | } |
| 77338 | 77751 | pOp->p4type = P4_DYNAMIC; |
| 77339 | 77752 | pOp->p4.z = pOut->z; |
| 77340 | 77753 | pOp->p1 = pOut->n; |
| 77341 | 77754 | } |
| 77755 | + testcase( rc==SQLITE_TOOBIG ); |
| 77342 | 77756 | #endif |
| 77343 | 77757 | if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 77344 | 77758 | goto too_big; |
| 77345 | 77759 | } |
| 77760 | + assert( rc==SQLITE_OK ); |
| 77346 | 77761 | /* Fall through to the next case, OP_String */ |
| 77347 | 77762 | } |
| 77348 | 77763 | |
| 77349 | 77764 | /* Opcode: String P1 P2 P3 P4 P5 |
| 77350 | 77765 | ** Synopsis: r[P2]='P4' (len=P1) |
| 77351 | 77766 | ** |
| 77352 | 77767 | ** The string value P4 of length P1 (bytes) is stored in register P2. |
| 77353 | 77768 | ** |
| 77354 | | -** If P5!=0 and the content of register P3 is greater than zero, then |
| 77769 | +** If P3 is not zero and the content of register P3 is equal to P5, then |
| 77355 | 77770 | ** the datatype of the register P2 is converted to BLOB. The content is |
| 77356 | 77771 | ** the same sequence of bytes, it is merely interpreted as a BLOB instead |
| 77357 | | -** of a string, as if it had been CAST. |
| 77772 | +** of a string, as if it had been CAST. In other words: |
| 77773 | +** |
| 77774 | +** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB) |
| 77358 | 77775 | */ |
| 77359 | 77776 | case OP_String: { /* out2 */ |
| 77360 | 77777 | assert( pOp->p4.z!=0 ); |
| 77361 | 77778 | pOut = out2Prerelease(p, pOp); |
| 77362 | 77779 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| | @@ -77363,16 +77780,15 @@ |
| 77363 | 77780 | pOut->z = pOp->p4.z; |
| 77364 | 77781 | pOut->n = pOp->p1; |
| 77365 | 77782 | pOut->enc = encoding; |
| 77366 | 77783 | UPDATE_MAX_BLOBSIZE(pOut); |
| 77367 | 77784 | #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 77368 | | - if( pOp->p5 ){ |
| 77369 | | - assert( pOp->p3>0 ); |
| 77785 | + if( pOp->p3>0 ){ |
| 77370 | 77786 | assert( pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 77371 | 77787 | pIn3 = &aMem[pOp->p3]; |
| 77372 | 77788 | assert( pIn3->flags & MEM_Int ); |
| 77373 | | - if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term; |
| 77789 | + if( pIn3->u.i==pOp->p5 ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term; |
| 77374 | 77790 | } |
| 77375 | 77791 | #endif |
| 77376 | 77792 | break; |
| 77377 | 77793 | } |
| 77378 | 77794 | |
| | @@ -82224,25 +82640,10 @@ |
| 82224 | 82640 | if( pIn1->u.i==0 ) goto jump_to_p2; |
| 82225 | 82641 | break; |
| 82226 | 82642 | } |
| 82227 | 82643 | |
| 82228 | 82644 | |
| 82229 | | -/* Opcode: JumpZeroIncr P1 P2 * * * |
| 82230 | | -** Synopsis: if (r[P1]++)==0 ) goto P2 |
| 82231 | | -** |
| 82232 | | -** The register P1 must contain an integer. If register P1 is initially |
| 82233 | | -** zero, then jump to P2. Increment register P1 regardless of whether or |
| 82234 | | -** not the jump is taken. |
| 82235 | | -*/ |
| 82236 | | -case OP_JumpZeroIncr: { /* jump, in1 */ |
| 82237 | | - pIn1 = &aMem[pOp->p1]; |
| 82238 | | - assert( pIn1->flags&MEM_Int ); |
| 82239 | | - VdbeBranchTaken(pIn1->u.i==0, 2); |
| 82240 | | - if( (pIn1->u.i++)==0 ) goto jump_to_p2; |
| 82241 | | - break; |
| 82242 | | -} |
| 82243 | | - |
| 82244 | 82645 | /* Opcode: AggStep0 * P2 P3 P4 P5 |
| 82245 | 82646 | ** Synopsis: accum=r[P3] step(r[P2@P5]) |
| 82246 | 82647 | ** |
| 82247 | 82648 | ** Execute the step function for an aggregate. The |
| 82248 | 82649 | ** function has P5 arguments. P4 is a pointer to the FuncDef |
| | @@ -83131,15 +83532,16 @@ |
| 83131 | 83532 | #ifndef NDEBUG |
| 83132 | 83533 | assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] ); |
| 83133 | 83534 | |
| 83134 | 83535 | #ifdef SQLITE_DEBUG |
| 83135 | 83536 | if( db->flags & SQLITE_VdbeTrace ){ |
| 83537 | + u8 opProperty = sqlite3OpcodeProperty[pOrigOp->opcode]; |
| 83136 | 83538 | if( rc!=0 ) printf("rc=%d\n",rc); |
| 83137 | | - if( pOrigOp->opflags & (OPFLG_OUT2) ){ |
| 83539 | + if( opProperty & (OPFLG_OUT2) ){ |
| 83138 | 83540 | registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]); |
| 83139 | 83541 | } |
| 83140 | | - if( pOrigOp->opflags & OPFLG_OUT3 ){ |
| 83542 | + if( opProperty & OPFLG_OUT3 ){ |
| 83141 | 83543 | registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); |
| 83142 | 83544 | } |
| 83143 | 83545 | } |
| 83144 | 83546 | #endif /* SQLITE_DEBUG */ |
| 83145 | 83547 | #endif /* NDEBUG */ |
| | @@ -84648,11 +85050,10 @@ |
| 84648 | 85050 | int nField, /* Number of key fields in each record */ |
| 84649 | 85051 | VdbeCursor *pCsr /* Cursor that holds the new sorter */ |
| 84650 | 85052 | ){ |
| 84651 | 85053 | int pgsz; /* Page size of main database */ |
| 84652 | 85054 | int i; /* Used to iterate through aTask[] */ |
| 84653 | | - int mxCache; /* Cache size */ |
| 84654 | 85055 | VdbeSorter *pSorter; /* The new sorter */ |
| 84655 | 85056 | KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */ |
| 84656 | 85057 | int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */ |
| 84657 | 85058 | int sz; /* Size of pSorter in bytes */ |
| 84658 | 85059 | int rc = SQLITE_OK; |
| | @@ -84705,15 +85106,24 @@ |
| 84705 | 85106 | SortSubtask *pTask = &pSorter->aTask[i]; |
| 84706 | 85107 | pTask->pSorter = pSorter; |
| 84707 | 85108 | } |
| 84708 | 85109 | |
| 84709 | 85110 | if( !sqlite3TempInMemory(db) ){ |
| 85111 | + i64 mxCache; /* Cache size in bytes*/ |
| 84710 | 85112 | u32 szPma = sqlite3GlobalConfig.szPma; |
| 84711 | 85113 | pSorter->mnPmaSize = szPma * pgsz; |
| 85114 | + |
| 84712 | 85115 | mxCache = db->aDb[0].pSchema->cache_size; |
| 84713 | | - if( mxCache<(int)szPma ) mxCache = (int)szPma; |
| 84714 | | - pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ); |
| 85116 | + if( mxCache<0 ){ |
| 85117 | + /* A negative cache-size value C indicates that the cache is abs(C) |
| 85118 | + ** KiB in size. */ |
| 85119 | + mxCache = mxCache * -1024; |
| 85120 | + }else{ |
| 85121 | + mxCache = mxCache * pgsz; |
| 85122 | + } |
| 85123 | + mxCache = MIN(mxCache, SQLITE_MAX_PMASZ); |
| 85124 | + pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache); |
| 84715 | 85125 | |
| 84716 | 85126 | /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of |
| 84717 | 85127 | ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary |
| 84718 | 85128 | ** large heap allocations. |
| 84719 | 85129 | */ |
| | @@ -86473,10 +86883,19 @@ |
| 86473 | 86883 | ************************************************************************* |
| 86474 | 86884 | ** |
| 86475 | 86885 | ** This file contains code use to implement an in-memory rollback journal. |
| 86476 | 86886 | ** The in-memory rollback journal is used to journal transactions for |
| 86477 | 86887 | ** ":memory:" databases and when the journal_mode=MEMORY pragma is used. |
| 86888 | +** |
| 86889 | +** Update: The in-memory journal is also used to temporarily cache |
| 86890 | +** smaller journals that are not critical for power-loss recovery. |
| 86891 | +** For example, statement journals that are not too big will be held |
| 86892 | +** entirely in memory, thus reducing the number of file I/O calls, and |
| 86893 | +** more importantly, reducing temporary file creation events. If these |
| 86894 | +** journals become too large for memory, they are spilled to disk. But |
| 86895 | +** in the common case, they are usually small and no file I/O needs to |
| 86896 | +** occur. |
| 86478 | 86897 | */ |
| 86479 | 86898 | /* #include "sqliteInt.h" */ |
| 86480 | 86899 | |
| 86481 | 86900 | /* Forward references to internal structures */ |
| 86482 | 86901 | typedef struct MemJournal MemJournal; |
| | @@ -87799,10 +88218,11 @@ |
| 87799 | 88218 | notValid(pParse, pNC, "subqueries", NC_IsCheck|NC_PartIdx|NC_IdxExpr); |
| 87800 | 88219 | sqlite3WalkSelect(pWalker, pExpr->x.pSelect); |
| 87801 | 88220 | assert( pNC->nRef>=nRef ); |
| 87802 | 88221 | if( nRef!=pNC->nRef ){ |
| 87803 | 88222 | ExprSetProperty(pExpr, EP_VarSelect); |
| 88223 | + pNC->ncFlags |= NC_VarSelect; |
| 87804 | 88224 | } |
| 87805 | 88225 | } |
| 87806 | 88226 | break; |
| 87807 | 88227 | } |
| 87808 | 88228 | case TK_VARIABLE: { |
| | @@ -89006,19 +89426,17 @@ |
| 89006 | 89426 | if( pToken ){ |
| 89007 | 89427 | if( nExtra==0 ){ |
| 89008 | 89428 | pNew->flags |= EP_IntValue; |
| 89009 | 89429 | pNew->u.iValue = iValue; |
| 89010 | 89430 | }else{ |
| 89011 | | - int c; |
| 89012 | 89431 | pNew->u.zToken = (char*)&pNew[1]; |
| 89013 | 89432 | assert( pToken->z!=0 || pToken->n==0 ); |
| 89014 | 89433 | if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n); |
| 89015 | 89434 | pNew->u.zToken[pToken->n] = 0; |
| 89016 | | - if( dequote && nExtra>=3 |
| 89017 | | - && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){ |
| 89435 | + if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){ |
| 89436 | + if( pNew->u.zToken[0]=='"' ) pNew->flags |= EP_DblQuoted; |
| 89018 | 89437 | sqlite3Dequote(pNew->u.zToken); |
| 89019 | | - if( c=='"' ) pNew->flags |= EP_DblQuoted; |
| 89020 | 89438 | } |
| 89021 | 89439 | } |
| 89022 | 89440 | } |
| 89023 | 89441 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 89024 | 89442 | pNew->nHeight = 1; |
| | @@ -89096,10 +89514,26 @@ |
| 89096 | 89514 | if( p ) { |
| 89097 | 89515 | sqlite3ExprCheckHeight(pParse, p->nHeight); |
| 89098 | 89516 | } |
| 89099 | 89517 | return p; |
| 89100 | 89518 | } |
| 89519 | + |
| 89520 | +/* |
| 89521 | +** Add pSelect to the Expr.x.pSelect field. Or, if pExpr is NULL (due |
| 89522 | +** do a memory allocation failure) then delete the pSelect object. |
| 89523 | +*/ |
| 89524 | +SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse *pParse, Expr *pExpr, Select *pSelect){ |
| 89525 | + if( pExpr ){ |
| 89526 | + pExpr->x.pSelect = pSelect; |
| 89527 | + ExprSetProperty(pExpr, EP_xIsSelect|EP_Subquery); |
| 89528 | + sqlite3ExprSetHeightAndFlags(pParse, pExpr); |
| 89529 | + }else{ |
| 89530 | + assert( pParse->db->mallocFailed ); |
| 89531 | + sqlite3SelectDelete(pParse->db, pSelect); |
| 89532 | + } |
| 89533 | +} |
| 89534 | + |
| 89101 | 89535 | |
| 89102 | 89536 | /* |
| 89103 | 89537 | ** If the expression is always either TRUE or FALSE (respectively), |
| 89104 | 89538 | ** then return 1. If one cannot determine the truth value of the |
| 89105 | 89539 | ** expression at compile-time return 0. |
| | @@ -89257,12 +89691,12 @@ |
| 89257 | 89691 | } |
| 89258 | 89692 | |
| 89259 | 89693 | /* |
| 89260 | 89694 | ** Recursively delete an expression tree. |
| 89261 | 89695 | */ |
| 89262 | | -SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){ |
| 89263 | | - if( p==0 ) return; |
| 89696 | +static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){ |
| 89697 | + assert( p!=0 ); |
| 89264 | 89698 | /* Sanity check: Assert that the IntValue is non-negative if it exists */ |
| 89265 | 89699 | assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 ); |
| 89266 | 89700 | if( !ExprHasProperty(p, EP_TokenOnly) ){ |
| 89267 | 89701 | /* The Expr.x union is never used at the same time as Expr.pRight */ |
| 89268 | 89702 | assert( p->x.pList==0 || p->pRight==0 ); |
| | @@ -89276,10 +89710,13 @@ |
| 89276 | 89710 | } |
| 89277 | 89711 | } |
| 89278 | 89712 | if( !ExprHasProperty(p, EP_Static) ){ |
| 89279 | 89713 | sqlite3DbFree(db, p); |
| 89280 | 89714 | } |
| 89715 | +} |
| 89716 | +SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){ |
| 89717 | + if( p ) sqlite3ExprDeleteNN(db, p); |
| 89281 | 89718 | } |
| 89282 | 89719 | |
| 89283 | 89720 | /* |
| 89284 | 89721 | ** Return the number of bytes allocated for the expression structure |
| 89285 | 89722 | ** passed as the first argument. This is always one of EXPR_FULLSIZE, |
| | @@ -89328,11 +89765,11 @@ |
| 89328 | 89765 | static int dupedExprStructSize(Expr *p, int flags){ |
| 89329 | 89766 | int nSize; |
| 89330 | 89767 | assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */ |
| 89331 | 89768 | assert( EXPR_FULLSIZE<=0xfff ); |
| 89332 | 89769 | assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 ); |
| 89333 | | - if( 0==(flags&EXPRDUP_REDUCE) ){ |
| 89770 | + if( 0==flags ){ |
| 89334 | 89771 | nSize = EXPR_FULLSIZE; |
| 89335 | 89772 | }else{ |
| 89336 | 89773 | assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); |
| 89337 | 89774 | assert( !ExprHasProperty(p, EP_FromJoin) ); |
| 89338 | 89775 | assert( !ExprHasProperty(p, EP_MemToken) ); |
| | @@ -89390,92 +89827,92 @@ |
| 89390 | 89827 | ** to store the copy of expression p, the copies of p->u.zToken |
| 89391 | 89828 | ** (if applicable), and the copies of the p->pLeft and p->pRight expressions, |
| 89392 | 89829 | ** if any. Before returning, *pzBuffer is set to the first byte past the |
| 89393 | 89830 | ** portion of the buffer copied into by this function. |
| 89394 | 89831 | */ |
| 89395 | | -static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){ |
| 89396 | | - Expr *pNew = 0; /* Value to return */ |
| 89397 | | - assert( flags==0 || flags==EXPRDUP_REDUCE ); |
| 89832 | +static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){ |
| 89833 | + Expr *pNew; /* Value to return */ |
| 89834 | + u8 *zAlloc; /* Memory space from which to build Expr object */ |
| 89835 | + u32 staticFlag; /* EP_Static if space not obtained from malloc */ |
| 89836 | + |
| 89398 | 89837 | assert( db!=0 ); |
| 89399 | | - if( p ){ |
| 89400 | | - const int isReduced = (flags&EXPRDUP_REDUCE); |
| 89401 | | - u8 *zAlloc; |
| 89402 | | - u32 staticFlag = 0; |
| 89403 | | - |
| 89404 | | - assert( pzBuffer==0 || isReduced ); |
| 89405 | | - |
| 89406 | | - /* Figure out where to write the new Expr structure. */ |
| 89407 | | - if( pzBuffer ){ |
| 89408 | | - zAlloc = *pzBuffer; |
| 89409 | | - staticFlag = EP_Static; |
| 89410 | | - }else{ |
| 89411 | | - zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, flags)); |
| 89412 | | - } |
| 89413 | | - pNew = (Expr *)zAlloc; |
| 89414 | | - |
| 89415 | | - if( pNew ){ |
| 89416 | | - /* Set nNewSize to the size allocated for the structure pointed to |
| 89417 | | - ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or |
| 89418 | | - ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed |
| 89419 | | - ** by the copy of the p->u.zToken string (if any). |
| 89420 | | - */ |
| 89421 | | - const unsigned nStructSize = dupedExprStructSize(p, flags); |
| 89422 | | - const int nNewSize = nStructSize & 0xfff; |
| 89423 | | - int nToken; |
| 89424 | | - if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){ |
| 89425 | | - nToken = sqlite3Strlen30(p->u.zToken) + 1; |
| 89426 | | - }else{ |
| 89427 | | - nToken = 0; |
| 89428 | | - } |
| 89429 | | - if( isReduced ){ |
| 89430 | | - assert( ExprHasProperty(p, EP_Reduced)==0 ); |
| 89431 | | - memcpy(zAlloc, p, nNewSize); |
| 89432 | | - }else{ |
| 89433 | | - u32 nSize = (u32)exprStructSize(p); |
| 89434 | | - memcpy(zAlloc, p, nSize); |
| 89435 | | - if( nSize<EXPR_FULLSIZE ){ |
| 89436 | | - memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize); |
| 89437 | | - } |
| 89438 | | - } |
| 89439 | | - |
| 89440 | | - /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */ |
| 89441 | | - pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken); |
| 89442 | | - pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly); |
| 89443 | | - pNew->flags |= staticFlag; |
| 89444 | | - |
| 89445 | | - /* Copy the p->u.zToken string, if any. */ |
| 89446 | | - if( nToken ){ |
| 89447 | | - char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize]; |
| 89448 | | - memcpy(zToken, p->u.zToken, nToken); |
| 89449 | | - } |
| 89450 | | - |
| 89451 | | - if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){ |
| 89452 | | - /* Fill in the pNew->x.pSelect or pNew->x.pList member. */ |
| 89453 | | - if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 89454 | | - pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced); |
| 89455 | | - }else{ |
| 89456 | | - pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced); |
| 89457 | | - } |
| 89458 | | - } |
| 89459 | | - |
| 89460 | | - /* Fill in pNew->pLeft and pNew->pRight. */ |
| 89461 | | - if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){ |
| 89462 | | - zAlloc += dupedExprNodeSize(p, flags); |
| 89463 | | - if( ExprHasProperty(pNew, EP_Reduced) ){ |
| 89464 | | - pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc); |
| 89465 | | - pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc); |
| 89466 | | - } |
| 89467 | | - if( pzBuffer ){ |
| 89468 | | - *pzBuffer = zAlloc; |
| 89469 | | - } |
| 89470 | | - }else{ |
| 89471 | | - if( !ExprHasProperty(p, EP_TokenOnly) ){ |
| 89472 | | - pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0); |
| 89473 | | - pNew->pRight = sqlite3ExprDup(db, p->pRight, 0); |
| 89474 | | - } |
| 89475 | | - } |
| 89476 | | - |
| 89838 | + assert( p ); |
| 89839 | + assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE ); |
| 89840 | + assert( pzBuffer==0 || dupFlags==EXPRDUP_REDUCE ); |
| 89841 | + |
| 89842 | + /* Figure out where to write the new Expr structure. */ |
| 89843 | + if( pzBuffer ){ |
| 89844 | + zAlloc = *pzBuffer; |
| 89845 | + staticFlag = EP_Static; |
| 89846 | + }else{ |
| 89847 | + zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags)); |
| 89848 | + staticFlag = 0; |
| 89849 | + } |
| 89850 | + pNew = (Expr *)zAlloc; |
| 89851 | + |
| 89852 | + if( pNew ){ |
| 89853 | + /* Set nNewSize to the size allocated for the structure pointed to |
| 89854 | + ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or |
| 89855 | + ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed |
| 89856 | + ** by the copy of the p->u.zToken string (if any). |
| 89857 | + */ |
| 89858 | + const unsigned nStructSize = dupedExprStructSize(p, dupFlags); |
| 89859 | + const int nNewSize = nStructSize & 0xfff; |
| 89860 | + int nToken; |
| 89861 | + if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){ |
| 89862 | + nToken = sqlite3Strlen30(p->u.zToken) + 1; |
| 89863 | + }else{ |
| 89864 | + nToken = 0; |
| 89865 | + } |
| 89866 | + if( dupFlags ){ |
| 89867 | + assert( ExprHasProperty(p, EP_Reduced)==0 ); |
| 89868 | + memcpy(zAlloc, p, nNewSize); |
| 89869 | + }else{ |
| 89870 | + u32 nSize = (u32)exprStructSize(p); |
| 89871 | + memcpy(zAlloc, p, nSize); |
| 89872 | + if( nSize<EXPR_FULLSIZE ){ |
| 89873 | + memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize); |
| 89874 | + } |
| 89875 | + } |
| 89876 | + |
| 89877 | + /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */ |
| 89878 | + pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken); |
| 89879 | + pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly); |
| 89880 | + pNew->flags |= staticFlag; |
| 89881 | + |
| 89882 | + /* Copy the p->u.zToken string, if any. */ |
| 89883 | + if( nToken ){ |
| 89884 | + char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize]; |
| 89885 | + memcpy(zToken, p->u.zToken, nToken); |
| 89886 | + } |
| 89887 | + |
| 89888 | + if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){ |
| 89889 | + /* Fill in the pNew->x.pSelect or pNew->x.pList member. */ |
| 89890 | + if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 89891 | + pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags); |
| 89892 | + }else{ |
| 89893 | + pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags); |
| 89894 | + } |
| 89895 | + } |
| 89896 | + |
| 89897 | + /* Fill in pNew->pLeft and pNew->pRight. */ |
| 89898 | + if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){ |
| 89899 | + zAlloc += dupedExprNodeSize(p, dupFlags); |
| 89900 | + if( ExprHasProperty(pNew, EP_Reduced) ){ |
| 89901 | + pNew->pLeft = p->pLeft ? |
| 89902 | + exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc) : 0; |
| 89903 | + pNew->pRight = p->pRight ? |
| 89904 | + exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc) : 0; |
| 89905 | + } |
| 89906 | + if( pzBuffer ){ |
| 89907 | + *pzBuffer = zAlloc; |
| 89908 | + } |
| 89909 | + }else{ |
| 89910 | + if( !ExprHasProperty(p, EP_TokenOnly) ){ |
| 89911 | + pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0); |
| 89912 | + pNew->pRight = sqlite3ExprDup(db, p->pRight, 0); |
| 89913 | + } |
| 89477 | 89914 | } |
| 89478 | 89915 | } |
| 89479 | 89916 | return pNew; |
| 89480 | 89917 | } |
| 89481 | 89918 | |
| | @@ -89523,11 +89960,11 @@ |
| 89523 | 89960 | ** truncated version of the usual Expr structure that will be stored as |
| 89524 | 89961 | ** part of the in-memory representation of the database schema. |
| 89525 | 89962 | */ |
| 89526 | 89963 | SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){ |
| 89527 | 89964 | assert( flags==0 || flags==EXPRDUP_REDUCE ); |
| 89528 | | - return exprDup(db, p, flags, 0); |
| 89965 | + return p ? exprDup(db, p, flags, 0) : 0; |
| 89529 | 89966 | } |
| 89530 | 89967 | SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){ |
| 89531 | 89968 | ExprList *pNew; |
| 89532 | 89969 | struct ExprList_item *pItem, *pOldItem; |
| 89533 | 89970 | int i; |
| | @@ -89745,11 +90182,11 @@ |
| 89745 | 90182 | struct ExprList_item *pItem; |
| 89746 | 90183 | assert( pList->nExpr>0 ); |
| 89747 | 90184 | pItem = &pList->a[pList->nExpr-1]; |
| 89748 | 90185 | assert( pItem->zName==0 ); |
| 89749 | 90186 | pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n); |
| 89750 | | - if( dequote && pItem->zName ) sqlite3Dequote(pItem->zName); |
| 90187 | + if( dequote ) sqlite3Dequote(pItem->zName); |
| 89751 | 90188 | } |
| 89752 | 90189 | } |
| 89753 | 90190 | |
| 89754 | 90191 | /* |
| 89755 | 90192 | ** Set the ExprList.a[].zSpan element of the most recently added item |
| | @@ -89794,22 +90231,24 @@ |
| 89794 | 90231 | } |
| 89795 | 90232 | |
| 89796 | 90233 | /* |
| 89797 | 90234 | ** Delete an entire expression list. |
| 89798 | 90235 | */ |
| 89799 | | -SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){ |
| 90236 | +static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){ |
| 89800 | 90237 | int i; |
| 89801 | 90238 | struct ExprList_item *pItem; |
| 89802 | | - if( pList==0 ) return; |
| 89803 | 90239 | assert( pList->a!=0 || pList->nExpr==0 ); |
| 89804 | 90240 | for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){ |
| 89805 | 90241 | sqlite3ExprDelete(db, pItem->pExpr); |
| 89806 | 90242 | sqlite3DbFree(db, pItem->zName); |
| 89807 | 90243 | sqlite3DbFree(db, pItem->zSpan); |
| 89808 | 90244 | } |
| 89809 | 90245 | sqlite3DbFree(db, pList->a); |
| 89810 | 90246 | sqlite3DbFree(db, pList); |
| 90247 | +} |
| 90248 | +SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){ |
| 90249 | + if( pList ) exprListDeleteNN(db, pList); |
| 89811 | 90250 | } |
| 89812 | 90251 | |
| 89813 | 90252 | /* |
| 89814 | 90253 | ** Return the bitwise-OR of all Expr.flags fields in the given |
| 89815 | 90254 | ** ExprList. |
| | @@ -90851,10 +91290,23 @@ |
| 90851 | 91290 | #endif |
| 90852 | 91291 | } |
| 90853 | 91292 | } |
| 90854 | 91293 | } |
| 90855 | 91294 | |
| 91295 | +#if defined(SQLITE_DEBUG) |
| 91296 | +/* |
| 91297 | +** Verify the consistency of the column cache |
| 91298 | +*/ |
| 91299 | +static int cacheIsValid(Parse *pParse){ |
| 91300 | + int i, n; |
| 91301 | + for(i=n=0; i<SQLITE_N_COLCACHE; i++){ |
| 91302 | + if( pParse->aColCache[i].iReg>0 ) n++; |
| 91303 | + } |
| 91304 | + return n==pParse->nColCache; |
| 91305 | +} |
| 91306 | +#endif |
| 91307 | + |
| 90856 | 91308 | /* |
| 90857 | 91309 | ** Clear a cache entry. |
| 90858 | 91310 | */ |
| 90859 | 91311 | static void cacheEntryClear(Parse *pParse, struct yColCache *p){ |
| 90860 | 91312 | if( p->tempReg ){ |
| | @@ -90861,10 +91313,13 @@ |
| 90861 | 91313 | if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){ |
| 90862 | 91314 | pParse->aTempReg[pParse->nTempReg++] = p->iReg; |
| 90863 | 91315 | } |
| 90864 | 91316 | p->tempReg = 0; |
| 90865 | 91317 | } |
| 91318 | + p->iReg = 0; |
| 91319 | + pParse->nColCache--; |
| 91320 | + assert( pParse->db->mallocFailed || cacheIsValid(pParse) ); |
| 90866 | 91321 | } |
| 90867 | 91322 | |
| 90868 | 91323 | |
| 90869 | 91324 | /* |
| 90870 | 91325 | ** Record in the column cache that a particular column from a |
| | @@ -90904,10 +91359,12 @@ |
| 90904 | 91359 | p->iTable = iTab; |
| 90905 | 91360 | p->iColumn = iCol; |
| 90906 | 91361 | p->iReg = iReg; |
| 90907 | 91362 | p->tempReg = 0; |
| 90908 | 91363 | p->lru = pParse->iCacheCnt++; |
| 91364 | + pParse->nColCache++; |
| 91365 | + assert( pParse->db->mallocFailed || cacheIsValid(pParse) ); |
| 90909 | 91366 | return; |
| 90910 | 91367 | } |
| 90911 | 91368 | } |
| 90912 | 91369 | |
| 90913 | 91370 | /* Replace the last recently used */ |
| | @@ -90925,28 +91382,27 @@ |
| 90925 | 91382 | p->iTable = iTab; |
| 90926 | 91383 | p->iColumn = iCol; |
| 90927 | 91384 | p->iReg = iReg; |
| 90928 | 91385 | p->tempReg = 0; |
| 90929 | 91386 | p->lru = pParse->iCacheCnt++; |
| 91387 | + assert( cacheIsValid(pParse) ); |
| 90930 | 91388 | return; |
| 90931 | 91389 | } |
| 90932 | 91390 | } |
| 90933 | 91391 | |
| 90934 | 91392 | /* |
| 90935 | 91393 | ** Indicate that registers between iReg..iReg+nReg-1 are being overwritten. |
| 90936 | 91394 | ** Purge the range of registers from the column cache. |
| 90937 | 91395 | */ |
| 90938 | 91396 | SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){ |
| 90939 | | - int i; |
| 90940 | | - int iLast = iReg + nReg - 1; |
| 90941 | 91397 | struct yColCache *p; |
| 90942 | | - for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 90943 | | - int r = p->iReg; |
| 90944 | | - if( r>=iReg && r<=iLast ){ |
| 90945 | | - cacheEntryClear(pParse, p); |
| 90946 | | - p->iReg = 0; |
| 90947 | | - } |
| 91398 | + if( iReg<=0 || pParse->nColCache==0 ) return; |
| 91399 | + p = &pParse->aColCache[SQLITE_N_COLCACHE-1]; |
| 91400 | + while(1){ |
| 91401 | + if( p->iReg >= iReg && p->iReg < iReg+nReg ) cacheEntryClear(pParse, p); |
| 91402 | + if( p==pParse->aColCache ) break; |
| 91403 | + p--; |
| 90948 | 91404 | } |
| 90949 | 91405 | } |
| 90950 | 91406 | |
| 90951 | 91407 | /* |
| 90952 | 91408 | ** Remember the current column cache context. Any new entries added |
| | @@ -90978,11 +91434,10 @@ |
| 90978 | 91434 | } |
| 90979 | 91435 | #endif |
| 90980 | 91436 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 90981 | 91437 | if( p->iReg && p->iLevel>pParse->iCacheLevel ){ |
| 90982 | 91438 | cacheEntryClear(pParse, p); |
| 90983 | | - p->iReg = 0; |
| 90984 | 91439 | } |
| 90985 | 91440 | } |
| 90986 | 91441 | } |
| 90987 | 91442 | |
| 90988 | 91443 | /* |
| | @@ -91113,11 +91568,10 @@ |
| 91113 | 91568 | } |
| 91114 | 91569 | #endif |
| 91115 | 91570 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 91116 | 91571 | if( p->iReg ){ |
| 91117 | 91572 | cacheEntryClear(pParse, p); |
| 91118 | | - p->iReg = 0; |
| 91119 | 91573 | } |
| 91120 | 91574 | } |
| 91121 | 91575 | } |
| 91122 | 91576 | |
| 91123 | 91577 | /* |
| | @@ -91154,10 +91608,11 @@ |
| 91154 | 91608 | if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/ |
| 91155 | 91609 | } |
| 91156 | 91610 | return 0; |
| 91157 | 91611 | } |
| 91158 | 91612 | #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */ |
| 91613 | + |
| 91159 | 91614 | |
| 91160 | 91615 | /* |
| 91161 | 91616 | ** Convert an expression node to a TK_REGISTER |
| 91162 | 91617 | */ |
| 91163 | 91618 | static void exprToRegister(Expr *p, int iReg){ |
| | @@ -96951,20 +97406,14 @@ |
| 96951 | 97406 | ** contains lookaside memory. (Table objects in the schema do not use |
| 96952 | 97407 | ** lookaside memory, but some ephemeral Table objects do.) Or the |
| 96953 | 97408 | ** db parameter can be used with db->pnBytesFreed to measure the memory |
| 96954 | 97409 | ** used by the Table object. |
| 96955 | 97410 | */ |
| 96956 | | -SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ |
| 97411 | +static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){ |
| 96957 | 97412 | Index *pIndex, *pNext; |
| 96958 | 97413 | TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */ |
| 96959 | 97414 | |
| 96960 | | - assert( !pTable || pTable->nRef>0 ); |
| 96961 | | - |
| 96962 | | - /* Do not delete the table until the reference count reaches zero. */ |
| 96963 | | - if( !pTable ) return; |
| 96964 | | - if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return; |
| 96965 | | - |
| 96966 | 97415 | /* Record the number of outstanding lookaside allocations in schema Tables |
| 96967 | 97416 | ** prior to doing any free() operations. Since schema Tables do not use |
| 96968 | 97417 | ** lookaside, this number should not change. */ |
| 96969 | 97418 | TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ? |
| 96970 | 97419 | db->lookaside.nOut : 0 ); |
| | @@ -97000,10 +97449,17 @@ |
| 97000 | 97449 | sqlite3DbFree(db, pTable); |
| 97001 | 97450 | |
| 97002 | 97451 | /* Verify that no lookaside memory was used by schema tables */ |
| 97003 | 97452 | assert( nLookaside==0 || nLookaside==db->lookaside.nOut ); |
| 97004 | 97453 | } |
| 97454 | +SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){ |
| 97455 | + /* Do not delete the table until the reference count reaches zero. */ |
| 97456 | + if( !pTable ) return; |
| 97457 | + if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return; |
| 97458 | + deleteTable(db, pTable); |
| 97459 | +} |
| 97460 | + |
| 97005 | 97461 | |
| 97006 | 97462 | /* |
| 97007 | 97463 | ** Unlink the given table from the hash tables and the delete the |
| 97008 | 97464 | ** table structure with all its indices and foreign keys. |
| 97009 | 97465 | */ |
| | @@ -97445,10 +97901,11 @@ |
| 97445 | 97901 | pCol->szEst = 1; |
| 97446 | 97902 | }else{ |
| 97447 | 97903 | zType = z + sqlite3Strlen30(z) + 1; |
| 97448 | 97904 | memcpy(zType, pType->z, pType->n); |
| 97449 | 97905 | zType[pType->n] = 0; |
| 97906 | + sqlite3Dequote(zType); |
| 97450 | 97907 | pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst); |
| 97451 | 97908 | pCol->colFlags |= COLFLAG_HASTYPE; |
| 97452 | 97909 | } |
| 97453 | 97910 | p->nCol++; |
| 97454 | 97911 | pParse->constraintName.n = 0; |
| | @@ -98579,11 +99036,11 @@ |
| 98579 | 99036 | assert( sqlite3SchemaMutexHeld(db, 0, pTable->pSchema) ); |
| 98580 | 99037 | }else{ |
| 98581 | 99038 | pTable->nCol = 0; |
| 98582 | 99039 | nErr++; |
| 98583 | 99040 | } |
| 98584 | | - if( pSelTab ) sqlite3DeleteTable(db, pSelTab); |
| 99041 | + sqlite3DeleteTable(db, pSelTab); |
| 98585 | 99042 | sqlite3SelectDelete(db, pSel); |
| 98586 | 99043 | db->lookaside.bDisable--; |
| 98587 | 99044 | } else { |
| 98588 | 99045 | nErr++; |
| 98589 | 99046 | } |
| | @@ -101410,11 +101867,11 @@ |
| 101410 | 101867 | |
| 101411 | 101868 | /* Check that there isn't an ORDER BY without a LIMIT clause. |
| 101412 | 101869 | */ |
| 101413 | 101870 | if( pOrderBy && (pLimit == 0) ) { |
| 101414 | 101871 | sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType); |
| 101415 | | - goto limit_where_cleanup_2; |
| 101872 | + goto limit_where_cleanup; |
| 101416 | 101873 | } |
| 101417 | 101874 | |
| 101418 | 101875 | /* We only need to generate a select expression if there |
| 101419 | 101876 | ** is a limit/offset term to enforce. |
| 101420 | 101877 | */ |
| | @@ -101432,44 +101889,34 @@ |
| 101432 | 101889 | ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1 |
| 101433 | 101890 | ** ); |
| 101434 | 101891 | */ |
| 101435 | 101892 | |
| 101436 | 101893 | pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0); |
| 101437 | | - if( pSelectRowid == 0 ) goto limit_where_cleanup_2; |
| 101894 | + if( pSelectRowid == 0 ) goto limit_where_cleanup; |
| 101438 | 101895 | pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid); |
| 101439 | | - if( pEList == 0 ) goto limit_where_cleanup_2; |
| 101896 | + if( pEList == 0 ) goto limit_where_cleanup; |
| 101440 | 101897 | |
| 101441 | 101898 | /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree |
| 101442 | 101899 | ** and the SELECT subtree. */ |
| 101443 | 101900 | pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0); |
| 101444 | 101901 | if( pSelectSrc == 0 ) { |
| 101445 | 101902 | sqlite3ExprListDelete(pParse->db, pEList); |
| 101446 | | - goto limit_where_cleanup_2; |
| 101903 | + goto limit_where_cleanup; |
| 101447 | 101904 | } |
| 101448 | 101905 | |
| 101449 | 101906 | /* generate the SELECT expression tree. */ |
| 101450 | 101907 | pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0, |
| 101451 | 101908 | pOrderBy,0,pLimit,pOffset); |
| 101452 | 101909 | if( pSelect == 0 ) return 0; |
| 101453 | 101910 | |
| 101454 | 101911 | /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */ |
| 101455 | 101912 | pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0); |
| 101456 | | - if( pWhereRowid == 0 ) goto limit_where_cleanup_1; |
| 101457 | | - pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0); |
| 101458 | | - if( pInClause == 0 ) goto limit_where_cleanup_1; |
| 101459 | | - |
| 101460 | | - pInClause->x.pSelect = pSelect; |
| 101461 | | - pInClause->flags |= EP_xIsSelect; |
| 101462 | | - sqlite3ExprSetHeightAndFlags(pParse, pInClause); |
| 101913 | + pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0; |
| 101914 | + sqlite3PExprAddSelect(pParse, pInClause, pSelect); |
| 101463 | 101915 | return pInClause; |
| 101464 | 101916 | |
| 101465 | | - /* something went wrong. clean up anything allocated. */ |
| 101466 | | -limit_where_cleanup_1: |
| 101467 | | - sqlite3SelectDelete(pParse->db, pSelect); |
| 101468 | | - return 0; |
| 101469 | | - |
| 101470 | | -limit_where_cleanup_2: |
| 101917 | +limit_where_cleanup: |
| 101471 | 101918 | sqlite3ExprDelete(pParse->db, pWhere); |
| 101472 | 101919 | sqlite3ExprListDelete(pParse->db, pOrderBy); |
| 101473 | 101920 | sqlite3ExprDelete(pParse->db, pLimit); |
| 101474 | 101921 | sqlite3ExprDelete(pParse->db, pOffset); |
| 101475 | 101922 | return 0; |
| | @@ -101516,15 +101963,16 @@ |
| 101516 | 101963 | int iEphCur = 0; /* Ephemeral table holding all primary key values */ |
| 101517 | 101964 | int iRowSet = 0; /* Register for rowset of rows to delete */ |
| 101518 | 101965 | int addrBypass = 0; /* Address of jump over the delete logic */ |
| 101519 | 101966 | int addrLoop = 0; /* Top of the delete loop */ |
| 101520 | 101967 | int addrEphOpen = 0; /* Instruction to open the Ephemeral table */ |
| 101968 | + int bComplex; /* True if there are triggers or FKs or |
| 101969 | + ** subqueries in the WHERE clause */ |
| 101521 | 101970 | |
| 101522 | 101971 | #ifndef SQLITE_OMIT_TRIGGER |
| 101523 | 101972 | int isView; /* True if attempting to delete from a view */ |
| 101524 | 101973 | Trigger *pTrigger; /* List of table triggers, if required */ |
| 101525 | | - int bComplex; /* True if there are either triggers or FKs */ |
| 101526 | 101974 | #endif |
| 101527 | 101975 | |
| 101528 | 101976 | memset(&sContext, 0, sizeof(sContext)); |
| 101529 | 101977 | db = pParse->db; |
| 101530 | 101978 | if( pParse->nErr || db->mallocFailed ){ |
| | @@ -101548,11 +101996,10 @@ |
| 101548 | 101996 | isView = pTab->pSelect!=0; |
| 101549 | 101997 | bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0); |
| 101550 | 101998 | #else |
| 101551 | 101999 | # define pTrigger 0 |
| 101552 | 102000 | # define isView 0 |
| 101553 | | -# define bComplex 0 |
| 101554 | 102001 | #endif |
| 101555 | 102002 | #ifdef SQLITE_OMIT_VIEW |
| 101556 | 102003 | # undef isView |
| 101557 | 102004 | # define isView 0 |
| 101558 | 102005 | #endif |
| | @@ -101650,11 +102097,12 @@ |
| 101650 | 102097 | sqlite3VdbeAddOp2(v, OP_Clear, pIdx->tnum, iDb); |
| 101651 | 102098 | } |
| 101652 | 102099 | }else |
| 101653 | 102100 | #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */ |
| 101654 | 102101 | { |
| 101655 | | - u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK; |
| 102102 | + u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK|WHERE_SEEK_TABLE; |
| 102103 | + if( sNC.ncFlags & NC_VarSelect ) bComplex = 1; |
| 101656 | 102104 | wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW); |
| 101657 | 102105 | if( HasRowid(pTab) ){ |
| 101658 | 102106 | /* For a rowid table, initialize the RowSet to an empty set */ |
| 101659 | 102107 | pPk = 0; |
| 101660 | 102108 | nPk = 1; |
| | @@ -103561,10 +104009,18 @@ |
| 103561 | 104009 | static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){ |
| 103562 | 104010 | const char *zFile = (const char *)sqlite3_value_text(argv[0]); |
| 103563 | 104011 | const char *zProc; |
| 103564 | 104012 | sqlite3 *db = sqlite3_context_db_handle(context); |
| 103565 | 104013 | char *zErrMsg = 0; |
| 104014 | + |
| 104015 | + /* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc |
| 104016 | + ** flag is set. See the sqlite3_enable_load_extension() API. |
| 104017 | + */ |
| 104018 | + if( (db->flags & SQLITE_LoadExtFunc)==0 ){ |
| 104019 | + sqlite3_result_error(context, "not authorized", -1); |
| 104020 | + return; |
| 104021 | + } |
| 103566 | 104022 | |
| 103567 | 104023 | if( argc==2 ){ |
| 103568 | 104024 | zProc = (const char *)sqlite3_value_text(argv[1]); |
| 103569 | 104025 | }else{ |
| 103570 | 104026 | zProc = 0; |
| | @@ -108756,12 +109212,13 @@ |
| 108756 | 109212 | if( pzErrMsg ) *pzErrMsg = 0; |
| 108757 | 109213 | |
| 108758 | 109214 | /* Ticket #1863. To avoid a creating security problems for older |
| 108759 | 109215 | ** applications that relink against newer versions of SQLite, the |
| 108760 | 109216 | ** ability to run load_extension is turned off by default. One |
| 108761 | | - ** must call sqlite3_enable_load_extension() to turn on extension |
| 108762 | | - ** loading. Otherwise you get the following error. |
| 109217 | + ** must call either sqlite3_enable_load_extension(db) or |
| 109218 | + ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0) |
| 109219 | + ** to turn on extension loading. |
| 108763 | 109220 | */ |
| 108764 | 109221 | if( (db->flags & SQLITE_LoadExtension)==0 ){ |
| 108765 | 109222 | if( pzErrMsg ){ |
| 108766 | 109223 | *pzErrMsg = sqlite3_mprintf("not authorized"); |
| 108767 | 109224 | } |
| | @@ -108896,13 +109353,13 @@ |
| 108896 | 109353 | ** default so as not to open security holes in older applications. |
| 108897 | 109354 | */ |
| 108898 | 109355 | SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){ |
| 108899 | 109356 | sqlite3_mutex_enter(db->mutex); |
| 108900 | 109357 | if( onoff ){ |
| 108901 | | - db->flags |= SQLITE_LoadExtension; |
| 109358 | + db->flags |= SQLITE_LoadExtension|SQLITE_LoadExtFunc; |
| 108902 | 109359 | }else{ |
| 108903 | | - db->flags &= ~SQLITE_LoadExtension; |
| 109360 | + db->flags &= ~(SQLITE_LoadExtension|SQLITE_LoadExtFunc); |
| 108904 | 109361 | } |
| 108905 | 109362 | sqlite3_mutex_leave(db->mutex); |
| 108906 | 109363 | return SQLITE_OK; |
| 108907 | 109364 | } |
| 108908 | 109365 | |
| | @@ -112475,11 +112932,11 @@ |
| 112475 | 112932 | sqlite3ExprListDelete(db, p->pGroupBy); |
| 112476 | 112933 | sqlite3ExprDelete(db, p->pHaving); |
| 112477 | 112934 | sqlite3ExprListDelete(db, p->pOrderBy); |
| 112478 | 112935 | sqlite3ExprDelete(db, p->pLimit); |
| 112479 | 112936 | sqlite3ExprDelete(db, p->pOffset); |
| 112480 | | - sqlite3WithDelete(db, p->pWith); |
| 112937 | + if( p->pWith ) sqlite3WithDelete(db, p->pWith); |
| 112481 | 112938 | if( bFree ) sqlite3DbFree(db, p); |
| 112482 | 112939 | p = pPrior; |
| 112483 | 112940 | bFree = 1; |
| 112484 | 112941 | } |
| 112485 | 112942 | } |
| | @@ -112570,11 +113027,11 @@ |
| 112570 | 113027 | |
| 112571 | 113028 | /* |
| 112572 | 113029 | ** Delete the given Select structure and all of its substructures. |
| 112573 | 113030 | */ |
| 112574 | 113031 | SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){ |
| 112575 | | - clearSelect(db, p, 1); |
| 113032 | + if( p ) clearSelect(db, p, 1); |
| 112576 | 113033 | } |
| 112577 | 113034 | |
| 112578 | 113035 | /* |
| 112579 | 113036 | ** Return a pointer to the right-most SELECT statement in a compound. |
| 112580 | 113037 | */ |
| | @@ -114190,23 +114647,23 @@ |
| 114190 | 114647 | |
| 114191 | 114648 | /* |
| 114192 | 114649 | ** Get a VDBE for the given parser context. Create a new one if necessary. |
| 114193 | 114650 | ** If an error occurs, return NULL and leave a message in pParse. |
| 114194 | 114651 | */ |
| 114195 | | -SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ |
| 114196 | | - Vdbe *v = pParse->pVdbe; |
| 114197 | | - if( v==0 ){ |
| 114198 | | - v = pParse->pVdbe = sqlite3VdbeCreate(pParse); |
| 114199 | | - if( v ) sqlite3VdbeAddOp0(v, OP_Init); |
| 114200 | | - if( pParse->pToplevel==0 |
| 114201 | | - && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst) |
| 114202 | | - ){ |
| 114203 | | - pParse->okConstFactor = 1; |
| 114204 | | - } |
| 114205 | | - |
| 114652 | +static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){ |
| 114653 | + Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse); |
| 114654 | + if( v ) sqlite3VdbeAddOp0(v, OP_Init); |
| 114655 | + if( pParse->pToplevel==0 |
| 114656 | + && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst) |
| 114657 | + ){ |
| 114658 | + pParse->okConstFactor = 1; |
| 114206 | 114659 | } |
| 114207 | 114660 | return v; |
| 114661 | +} |
| 114662 | +SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ |
| 114663 | + Vdbe *v = pParse->pVdbe; |
| 114664 | + return v ? v : allocVdbe(pParse); |
| 114208 | 114665 | } |
| 114209 | 114666 | |
| 114210 | 114667 | |
| 114211 | 114668 | /* |
| 114212 | 114669 | ** Compute the iLimit and iOffset fields of the SELECT based on the |
| | @@ -116186,16 +116643,22 @@ |
| 116186 | 116643 | Expr *pWhere, /* The WHERE clause of the outer query */ |
| 116187 | 116644 | int iCursor /* Cursor number of the subquery */ |
| 116188 | 116645 | ){ |
| 116189 | 116646 | Expr *pNew; |
| 116190 | 116647 | int nChng = 0; |
| 116648 | + Select *pX; /* For looping over compound SELECTs in pSubq */ |
| 116191 | 116649 | if( pWhere==0 ) return 0; |
| 116192 | | - if( (pSubq->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){ |
| 116193 | | - return 0; /* restrictions (1) and (2) */ |
| 116650 | + for(pX=pSubq; pX; pX=pX->pPrior){ |
| 116651 | + if( (pX->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){ |
| 116652 | + testcase( pX->selFlags & SF_Aggregate ); |
| 116653 | + testcase( pX->selFlags & SF_Recursive ); |
| 116654 | + testcase( pX!=pSubq ); |
| 116655 | + return 0; /* restrictions (1) and (2) */ |
| 116656 | + } |
| 116194 | 116657 | } |
| 116195 | 116658 | if( pSubq->pLimit!=0 ){ |
| 116196 | | - return 0; /* restriction (3) */ |
| 116659 | + return 0; /* restriction (3) */ |
| 116197 | 116660 | } |
| 116198 | 116661 | while( pWhere->op==TK_AND ){ |
| 116199 | 116662 | nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor); |
| 116200 | 116663 | pWhere = pWhere->pLeft; |
| 116201 | 116664 | } |
| | @@ -117493,10 +117956,17 @@ |
| 117493 | 117956 | pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0); |
| 117494 | 117957 | /* Notice that even thought SF_Distinct has been cleared from p->selFlags, |
| 117495 | 117958 | ** the sDistinct.isTnct is still set. Hence, isTnct represents the |
| 117496 | 117959 | ** original setting of the SF_Distinct flag, not the current setting */ |
| 117497 | 117960 | assert( sDistinct.isTnct ); |
| 117961 | + |
| 117962 | +#if SELECTTRACE_ENABLED |
| 117963 | + if( sqlite3SelectTrace & 0x400 ){ |
| 117964 | + SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n")); |
| 117965 | + sqlite3TreeViewSelect(0, p, 0); |
| 117966 | + } |
| 117967 | +#endif |
| 117498 | 117968 | } |
| 117499 | 117969 | |
| 117500 | 117970 | /* If there is an ORDER BY clause, then create an ephemeral index to |
| 117501 | 117971 | ** do the sorting. But this sorting ephemeral index might end up |
| 117502 | 117972 | ** being unused if the data can be extracted in pre-sorted order. |
| | @@ -119731,11 +120201,12 @@ |
| 119731 | 120201 | /* Begin the database scan |
| 119732 | 120202 | */ |
| 119733 | 120203 | if( HasRowid(pTab) ){ |
| 119734 | 120204 | sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid); |
| 119735 | 120205 | pWInfo = sqlite3WhereBegin( |
| 119736 | | - pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, iIdxCur |
| 120206 | + pParse, pTabList, pWhere, 0, 0, |
| 120207 | + WHERE_ONEPASS_DESIRED | WHERE_SEEK_TABLE, iIdxCur |
| 119737 | 120208 | ); |
| 119738 | 120209 | if( pWInfo==0 ) goto update_cleanup; |
| 119739 | 120210 | okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); |
| 119740 | 120211 | |
| 119741 | 120212 | /* Remember the rowid of every item to be updated. |
| | @@ -121888,11 +122359,11 @@ |
| 121888 | 122359 | int addrSkip; /* Jump here for next iteration of skip-scan */ |
| 121889 | 122360 | int addrCont; /* Jump here to continue with the next loop cycle */ |
| 121890 | 122361 | int addrFirst; /* First instruction of interior of the loop */ |
| 121891 | 122362 | int addrBody; /* Beginning of the body of this loop */ |
| 121892 | 122363 | #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 121893 | | - int iLikeRepCntr; /* LIKE range processing counter register */ |
| 122364 | + u32 iLikeRepCntr; /* LIKE range processing counter register (times 2) */ |
| 121894 | 122365 | int addrLikeRep; /* LIKE range processing address */ |
| 121895 | 122366 | #endif |
| 121896 | 122367 | u8 iFrom; /* Which entry in the FROM clause */ |
| 121897 | 122368 | u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */ |
| 121898 | 122369 | int p1, p2; /* Operands of the opcode used to ends the loop */ |
| | @@ -122226,11 +122697,11 @@ |
| 122226 | 122697 | */ |
| 122227 | 122698 | struct WhereInfo { |
| 122228 | 122699 | Parse *pParse; /* Parsing and code generating context */ |
| 122229 | 122700 | SrcList *pTabList; /* List of tables in the join */ |
| 122230 | 122701 | ExprList *pOrderBy; /* The ORDER BY clause or NULL */ |
| 122231 | | - ExprList *pResultSet; /* Result set. DISTINCT operates on these */ |
| 122702 | + ExprList *pDistinctSet; /* DISTINCT over all these values */ |
| 122232 | 122703 | WhereLoop *pLoops; /* List of all WhereLoop objects */ |
| 122233 | 122704 | Bitmask revMask; /* Mask of ORDER BY terms that need reversing */ |
| 122234 | 122705 | LogEst nRowOut; /* Estimated number of output rows */ |
| 122235 | 122706 | LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */ |
| 122236 | 122707 | u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */ |
| | @@ -122310,10 +122781,18 @@ |
| 122310 | 122781 | /* |
| 122311 | 122782 | ** Bitmasks for the operators on WhereTerm objects. These are all |
| 122312 | 122783 | ** operators that are of interest to the query planner. An |
| 122313 | 122784 | ** OR-ed combination of these values can be used when searching for |
| 122314 | 122785 | ** particular WhereTerms within a WhereClause. |
| 122786 | +** |
| 122787 | +** Value constraints: |
| 122788 | +** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ |
| 122789 | +** WO_LT == SQLITE_INDEX_CONSTRAINT_LT |
| 122790 | +** WO_LE == SQLITE_INDEX_CONSTRAINT_LE |
| 122791 | +** WO_GT == SQLITE_INDEX_CONSTRAINT_GT |
| 122792 | +** WO_GE == SQLITE_INDEX_CONSTRAINT_GE |
| 122793 | +** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH |
| 122315 | 122794 | */ |
| 122316 | 122795 | #define WO_IN 0x0001 |
| 122317 | 122796 | #define WO_EQ 0x0002 |
| 122318 | 122797 | #define WO_LT (WO_EQ<<(TK_LT-TK_EQ)) |
| 122319 | 122798 | #define WO_LE (WO_EQ<<(TK_LE-TK_EQ)) |
| | @@ -122896,13 +123375,14 @@ |
| 122896 | 123375 | return regBase; |
| 122897 | 123376 | } |
| 122898 | 123377 | |
| 122899 | 123378 | #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 122900 | 123379 | /* |
| 122901 | | -** If the most recently coded instruction is a constant range contraint |
| 122902 | | -** that originated from the LIKE optimization, then change the P3 to be |
| 122903 | | -** pLoop->iLikeRepCntr and set P5. |
| 123380 | +** If the most recently coded instruction is a constant range constraint |
| 123381 | +** (a string literal) that originated from the LIKE optimization, then |
| 123382 | +** set P3 and P5 on the OP_String opcode so that the string will be cast |
| 123383 | +** to a BLOB at appropriate times. |
| 122904 | 123384 | ** |
| 122905 | 123385 | ** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range |
| 122906 | 123386 | ** expression: "x>='ABC' AND x<'abd'". But this requires that the range |
| 122907 | 123387 | ** scan loop run twice, once for strings and a second time for BLOBs. |
| 122908 | 123388 | ** The OP_String opcodes on the second pass convert the upper and lower |
| | @@ -122923,12 +123403,12 @@ |
| 122923 | 123403 | assert( pLevel->iLikeRepCntr>0 ); |
| 122924 | 123404 | pOp = sqlite3VdbeGetOp(v, -1); |
| 122925 | 123405 | assert( pOp!=0 ); |
| 122926 | 123406 | assert( pOp->opcode==OP_String8 |
| 122927 | 123407 | || pTerm->pWC->pWInfo->pParse->db->mallocFailed ); |
| 122928 | | - pOp->p3 = pLevel->iLikeRepCntr; |
| 122929 | | - pOp->p5 = 1; |
| 123408 | + pOp->p3 = (int)(pLevel->iLikeRepCntr>>1); /* Register holding counter */ |
| 123409 | + pOp->p5 = (u8)(pLevel->iLikeRepCntr&1); /* ASC or DESC */ |
| 122930 | 123410 | } |
| 122931 | 123411 | } |
| 122932 | 123412 | #else |
| 122933 | 123413 | # define whereLikeOptimizationStringFixup(A,B,C) |
| 122934 | 123414 | #endif |
| | @@ -123277,11 +123757,17 @@ |
| 123277 | 123757 | pCompare->pLeft = 0; |
| 123278 | 123758 | sqlite3ExprDelete(db, pCompare); |
| 123279 | 123759 | } |
| 123280 | 123760 | } |
| 123281 | 123761 | } |
| 123282 | | - sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2); |
| 123762 | + /* These registers need to be preserved in case there is an IN operator |
| 123763 | + ** loop. So we could deallocate the registers here (and potentially |
| 123764 | + ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems |
| 123765 | + ** simpler and safer to simply not reuse the registers. |
| 123766 | + ** |
| 123767 | + ** sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2); |
| 123768 | + */ |
| 123283 | 123769 | sqlite3ExprCachePop(pParse); |
| 123284 | 123770 | }else |
| 123285 | 123771 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 123286 | 123772 | |
| 123287 | 123773 | if( (pLoop->wsFlags & WHERE_IPK)!=0 |
| | @@ -123505,18 +123991,21 @@ |
| 123505 | 123991 | nExtraReg = 1; |
| 123506 | 123992 | #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 123507 | 123993 | if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){ |
| 123508 | 123994 | assert( pRangeStart!=0 ); /* LIKE opt constraints */ |
| 123509 | 123995 | assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */ |
| 123510 | | - pLevel->iLikeRepCntr = ++pParse->nMem; |
| 123996 | + pLevel->iLikeRepCntr = (u32)++pParse->nMem; |
| 123997 | + sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)pLevel->iLikeRepCntr); |
| 123998 | + VdbeComment((v, "LIKE loop counter")); |
| 123999 | + pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v); |
| 124000 | + /* iLikeRepCntr actually stores 2x the counter register number. The |
| 124001 | + ** bottom bit indicates whether the search order is ASC or DESC. */ |
| 123511 | 124002 | testcase( bRev ); |
| 123512 | 124003 | testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC ); |
| 123513 | | - sqlite3VdbeAddOp2(v, OP_Integer, |
| 123514 | | - bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC), |
| 123515 | | - pLevel->iLikeRepCntr); |
| 123516 | | - VdbeComment((v, "LIKE loop counter")); |
| 123517 | | - pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v); |
| 124004 | + assert( (bRev & ~1)==0 ); |
| 124005 | + pLevel->iLikeRepCntr <<=1; |
| 124006 | + pLevel->iLikeRepCntr |= bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC); |
| 123518 | 124007 | } |
| 123519 | 124008 | #endif |
| 123520 | 124009 | if( pRangeStart==0 |
| 123521 | 124010 | && (j = pIdx->aiColumn[nEq])>=0 |
| 123522 | 124011 | && pIdx->pTable->aCol[j].notNull==0 |
| | @@ -123650,11 +124139,11 @@ |
| 123650 | 124139 | disableTerm(pLevel, pRangeStart); |
| 123651 | 124140 | disableTerm(pLevel, pRangeEnd); |
| 123652 | 124141 | if( omitTable ){ |
| 123653 | 124142 | /* pIdx is a covering index. No need to access the main table. */ |
| 123654 | 124143 | }else if( HasRowid(pIdx->pTable) ){ |
| 123655 | | - if( pWInfo->eOnePass!=ONEPASS_OFF ){ |
| 124144 | + if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0 ){ |
| 123656 | 124145 | iRowidReg = ++pParse->nMem; |
| 123657 | 124146 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); |
| 123658 | 124147 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 123659 | 124148 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg); |
| 123660 | 124149 | VdbeCoverage(v); |
| | @@ -123846,11 +124335,12 @@ |
| 123846 | 124335 | ** sub-WHERE clause is to to invoke the main loop body as a subroutine. |
| 123847 | 124336 | */ |
| 123848 | 124337 | wctrlFlags = WHERE_OMIT_OPEN_CLOSE |
| 123849 | 124338 | | WHERE_FORCE_TABLE |
| 123850 | 124339 | | WHERE_ONETABLE_ONLY |
| 123851 | | - | WHERE_NO_AUTOINDEX; |
| 124340 | + | WHERE_NO_AUTOINDEX |
| 124341 | + | (pWInfo->wctrlFlags & WHERE_SEEK_TABLE); |
| 123852 | 124342 | for(ii=0; ii<pOrWc->nTerm; ii++){ |
| 123853 | 124343 | WhereTerm *pOrTerm = &pOrWc->a[ii]; |
| 123854 | 124344 | if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){ |
| 123855 | 124345 | WhereInfo *pSubWInfo; /* Info for single OR-term scan */ |
| 123856 | 124346 | Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */ |
| | @@ -124026,15 +124516,21 @@ |
| 124026 | 124516 | assert( pE!=0 ); |
| 124027 | 124517 | if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){ |
| 124028 | 124518 | continue; |
| 124029 | 124519 | } |
| 124030 | 124520 | if( pTerm->wtFlags & TERM_LIKECOND ){ |
| 124521 | + /* If the TERM_LIKECOND flag is set, that means that the range search |
| 124522 | + ** is sufficient to guarantee that the LIKE operator is true, so we |
| 124523 | + ** can skip the call to the like(A,B) function. But this only works |
| 124524 | + ** for strings. So do not skip the call to the function on the pass |
| 124525 | + ** that compares BLOBs. */ |
| 124031 | 124526 | #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 124032 | 124527 | continue; |
| 124033 | 124528 | #else |
| 124034 | | - assert( pLevel->iLikeRepCntr>0 ); |
| 124035 | | - skipLikeAddr = sqlite3VdbeAddOp1(v, OP_IfNot, pLevel->iLikeRepCntr); |
| 124529 | + u32 x = pLevel->iLikeRepCntr; |
| 124530 | + assert( x>0 ); |
| 124531 | + skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1)); |
| 124036 | 124532 | VdbeCoverage(v); |
| 124037 | 124533 | #endif |
| 124038 | 124534 | } |
| 124039 | 124535 | sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL); |
| 124040 | 124536 | if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr); |
| | @@ -125386,14 +125882,14 @@ |
| 125386 | 125882 | if( p->op==TK_COLUMN ){ |
| 125387 | 125883 | mask = sqlite3WhereGetMask(pMaskSet, p->iTable); |
| 125388 | 125884 | return mask; |
| 125389 | 125885 | } |
| 125390 | 125886 | mask = sqlite3WhereExprUsage(pMaskSet, p->pRight); |
| 125391 | | - mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft); |
| 125887 | + if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft); |
| 125392 | 125888 | if( ExprHasProperty(p, EP_xIsSelect) ){ |
| 125393 | 125889 | mask |= exprSelectUsage(pMaskSet, p->x.pSelect); |
| 125394 | | - }else{ |
| 125890 | + }else if( p->x.pList ){ |
| 125395 | 125891 | mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList); |
| 125396 | 125892 | } |
| 125397 | 125893 | return mask; |
| 125398 | 125894 | } |
| 125399 | 125895 | SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){ |
| | @@ -125729,11 +126225,14 @@ |
| 125729 | 126225 | ** Initialize a WHERE clause scanner object. Return a pointer to the |
| 125730 | 126226 | ** first match. Return NULL if there are no matches. |
| 125731 | 126227 | ** |
| 125732 | 126228 | ** The scanner will be searching the WHERE clause pWC. It will look |
| 125733 | 126229 | ** for terms of the form "X <op> <expr>" where X is column iColumn of table |
| 125734 | | -** iCur. The <op> must be one of the operators described by opMask. |
| 126230 | +** iCur. Or if pIdx!=0 then X is column iColumn of index pIdx. pIdx |
| 126231 | +** must be one of the indexes of table iCur. |
| 126232 | +** |
| 126233 | +** The <op> must be one of the operators described by opMask. |
| 125735 | 126234 | ** |
| 125736 | 126235 | ** If the search is for X and the WHERE clause contains terms of the |
| 125737 | 126236 | ** form X=Y then this routine might also return terms of the form |
| 125738 | 126237 | ** "Y <op> <expr>". The number of levels of transitivity is limited, |
| 125739 | 126238 | ** but is enough to handle most commonly occurring SQL statements. |
| | @@ -125777,15 +126276,16 @@ |
| 125777 | 126276 | return whereScanNext(pScan); |
| 125778 | 126277 | } |
| 125779 | 126278 | |
| 125780 | 126279 | /* |
| 125781 | 126280 | ** Search for a term in the WHERE clause that is of the form "X <op> <expr>" |
| 125782 | | -** where X is a reference to the iColumn of table iCur and <op> is one of |
| 125783 | | -** the WO_xx operator codes specified by the op parameter. |
| 125784 | | -** Return a pointer to the term. Return 0 if not found. |
| 126281 | +** where X is a reference to the iColumn of table iCur or of index pIdx |
| 126282 | +** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by |
| 126283 | +** the op parameter. Return a pointer to the term. Return 0 if not found. |
| 125785 | 126284 | ** |
| 125786 | | -** If pIdx!=0 then search for terms matching the iColumn-th column of pIdx |
| 126285 | +** If pIdx!=0 then it must be one of the indexes of table iCur. |
| 126286 | +** Search for terms matching the iColumn-th column of pIdx |
| 125787 | 126287 | ** rather than the iColumn-th column of table iCur. |
| 125788 | 126288 | ** |
| 125789 | 126289 | ** The term returned might by Y=<expr> if there is another constraint in |
| 125790 | 126290 | ** the WHERE clause that specifies that X=Y. Any such constraints will be |
| 125791 | 126291 | ** identified by the WO_EQUIV bit in the pTerm->eOperator field. The |
| | @@ -127119,15 +127619,16 @@ |
| 127119 | 127619 | /* |
| 127120 | 127620 | ** Print a WhereLoop object for debugging purposes |
| 127121 | 127621 | */ |
| 127122 | 127622 | static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){ |
| 127123 | 127623 | WhereInfo *pWInfo = pWC->pWInfo; |
| 127124 | | - int nb = 1+(pWInfo->pTabList->nSrc+7)/8; |
| 127624 | + int nb = 1+(pWInfo->pTabList->nSrc+3)/4; |
| 127125 | 127625 | struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab; |
| 127126 | 127626 | Table *pTab = pItem->pTab; |
| 127627 | + Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1; |
| 127127 | 127628 | sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId, |
| 127128 | | - p->iTab, nb, p->maskSelf, nb, p->prereq); |
| 127629 | + p->iTab, nb, p->maskSelf, nb, p->prereq & mAll); |
| 127129 | 127630 | sqlite3DebugPrintf(" %12s", |
| 127130 | 127631 | pItem->zAlias ? pItem->zAlias : pTab->zName); |
| 127131 | 127632 | if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){ |
| 127132 | 127633 | const char *zName; |
| 127133 | 127634 | if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){ |
| | @@ -129348,13 +129849,13 @@ |
| 129348 | 129849 | && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0 |
| 129349 | 129850 | && pWInfo->eDistinct==WHERE_DISTINCT_NOOP |
| 129350 | 129851 | && nRowEst |
| 129351 | 129852 | ){ |
| 129352 | 129853 | Bitmask notUsed; |
| 129353 | | - int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom, |
| 129854 | + int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinctSet, pFrom, |
| 129354 | 129855 | WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], ¬Used); |
| 129355 | | - if( rc==pWInfo->pResultSet->nExpr ){ |
| 129856 | + if( rc==pWInfo->pDistinctSet->nExpr ){ |
| 129356 | 129857 | pWInfo->eDistinct = WHERE_DISTINCT_ORDERED; |
| 129357 | 129858 | } |
| 129358 | 129859 | } |
| 129359 | 129860 | if( pWInfo->pOrderBy ){ |
| 129360 | 129861 | if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){ |
| | @@ -129565,18 +130066,18 @@ |
| 129565 | 130066 | ** the first cursor in an array of cursors for all indices. iIdxCur should |
| 129566 | 130067 | ** be used to compute the appropriate cursor depending on which index is |
| 129567 | 130068 | ** used. |
| 129568 | 130069 | */ |
| 129569 | 130070 | SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( |
| 129570 | | - Parse *pParse, /* The parser context */ |
| 129571 | | - SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */ |
| 129572 | | - Expr *pWhere, /* The WHERE clause */ |
| 129573 | | - ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */ |
| 129574 | | - ExprList *pResultSet, /* Result set of the query */ |
| 129575 | | - u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */ |
| 129576 | | - int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number, |
| 129577 | | - ** If WHERE_USE_LIMIT, then the limit amount */ |
| 130071 | + Parse *pParse, /* The parser context */ |
| 130072 | + SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */ |
| 130073 | + Expr *pWhere, /* The WHERE clause */ |
| 130074 | + ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */ |
| 130075 | + ExprList *pDistinctSet, /* Try not to output two rows that duplicate these */ |
| 130076 | + u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */ |
| 130077 | + int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number |
| 130078 | + ** If WHERE_USE_LIMIT, then the limit amount */ |
| 129578 | 130079 | ){ |
| 129579 | 130080 | int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */ |
| 129580 | 130081 | int nTabList; /* Number of elements in pTabList */ |
| 129581 | 130082 | WhereInfo *pWInfo; /* Will become the return value of this function */ |
| 129582 | 130083 | Vdbe *v = pParse->pVdbe; /* The virtual database engine */ |
| | @@ -129647,11 +130148,11 @@ |
| 129647 | 130148 | pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1; |
| 129648 | 130149 | pWInfo->nLevel = nTabList; |
| 129649 | 130150 | pWInfo->pParse = pParse; |
| 129650 | 130151 | pWInfo->pTabList = pTabList; |
| 129651 | 130152 | pWInfo->pOrderBy = pOrderBy; |
| 129652 | | - pWInfo->pResultSet = pResultSet; |
| 130153 | + pWInfo->pDistinctSet = pDistinctSet; |
| 129653 | 130154 | pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v); |
| 129654 | 130155 | pWInfo->wctrlFlags = wctrlFlags; |
| 129655 | 130156 | pWInfo->iLimit = iAuxArg; |
| 129656 | 130157 | pWInfo->savedNQueryLoop = pParse->nQueryLoop; |
| 129657 | 130158 | assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */ |
| | @@ -129720,17 +130221,17 @@ |
| 129720 | 130221 | /* Analyze all of the subexpressions. */ |
| 129721 | 130222 | sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC); |
| 129722 | 130223 | if( db->mallocFailed ) goto whereBeginError; |
| 129723 | 130224 | |
| 129724 | 130225 | if( wctrlFlags & WHERE_WANT_DISTINCT ){ |
| 129725 | | - if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ |
| 130226 | + if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pDistinctSet) ){ |
| 129726 | 130227 | /* The DISTINCT marking is pointless. Ignore it. */ |
| 129727 | 130228 | pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE; |
| 129728 | 130229 | }else if( pOrderBy==0 ){ |
| 129729 | 130230 | /* Try to ORDER BY the result set to make distinct processing easier */ |
| 129730 | 130231 | pWInfo->wctrlFlags |= WHERE_DISTINCTBY; |
| 129731 | | - pWInfo->pOrderBy = pResultSet; |
| 130232 | + pWInfo->pOrderBy = pDistinctSet; |
| 129732 | 130233 | } |
| 129733 | 130234 | } |
| 129734 | 130235 | |
| 129735 | 130236 | /* Construct the WhereLoop objects */ |
| 129736 | 130237 | #if defined(WHERETRACE_ENABLED) |
| | @@ -129805,14 +130306,14 @@ |
| 129805 | 130306 | } |
| 129806 | 130307 | } |
| 129807 | 130308 | #endif |
| 129808 | 130309 | /* Attempt to omit tables from the join that do not effect the result */ |
| 129809 | 130310 | if( pWInfo->nLevel>=2 |
| 129810 | | - && pResultSet!=0 |
| 130311 | + && pDistinctSet!=0 |
| 129811 | 130312 | && OptimizationEnabled(db, SQLITE_OmitNoopJoin) |
| 129812 | 130313 | ){ |
| 129813 | | - Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet); |
| 130314 | + Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pDistinctSet); |
| 129814 | 130315 | if( sWLB.pOrderBy ){ |
| 129815 | 130316 | tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy); |
| 129816 | 130317 | } |
| 129817 | 130318 | while( pWInfo->nLevel>=2 ){ |
| 129818 | 130319 | WhereTerm *pTerm, *pEnd; |
| | @@ -130074,17 +130575,12 @@ |
| 130074 | 130575 | sqlite3VdbeJumpHere(v, pLevel->addrSkip); |
| 130075 | 130576 | sqlite3VdbeJumpHere(v, pLevel->addrSkip-2); |
| 130076 | 130577 | } |
| 130077 | 130578 | #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS |
| 130078 | 130579 | if( pLevel->addrLikeRep ){ |
| 130079 | | - int op; |
| 130080 | | - if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){ |
| 130081 | | - op = OP_DecrJumpZero; |
| 130082 | | - }else{ |
| 130083 | | - op = OP_JumpZeroIncr; |
| 130084 | | - } |
| 130085 | | - sqlite3VdbeAddOp2(v, op, pLevel->iLikeRepCntr, pLevel->addrLikeRep); |
| 130580 | + sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1), |
| 130581 | + pLevel->addrLikeRep); |
| 130086 | 130582 | VdbeCoverage(v); |
| 130087 | 130583 | } |
| 130088 | 130584 | #endif |
| 130089 | 130585 | if( pLevel->iLeftJoin ){ |
| 130090 | 130586 | addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v); |
| | @@ -130486,11 +130982,11 @@ |
| 130486 | 130982 | #endif |
| 130487 | 130983 | /************* Begin control #defines *****************************************/ |
| 130488 | 130984 | #define YYCODETYPE unsigned char |
| 130489 | 130985 | #define YYNOCODE 251 |
| 130490 | 130986 | #define YYACTIONTYPE unsigned short int |
| 130491 | | -#define YYWILDCARD 70 |
| 130987 | +#define YYWILDCARD 96 |
| 130492 | 130988 | #define sqlite3ParserTOKENTYPE Token |
| 130493 | 130989 | typedef union { |
| 130494 | 130990 | int yyinit; |
| 130495 | 130991 | sqlite3ParserTOKENTYPE yy0; |
| 130496 | 130992 | struct LimitVal yy64; |
| | @@ -130590,402 +131086,404 @@ |
| 130590 | 131086 | ** yy_reduce_ofst[] For each state, the offset into yy_action for |
| 130591 | 131087 | ** shifting non-terminals after a reduce. |
| 130592 | 131088 | ** yy_default[] Default action for each state. |
| 130593 | 131089 | ** |
| 130594 | 131090 | *********** Begin parsing tables **********************************************/ |
| 130595 | | -#define YY_ACTTAB_COUNT (1499) |
| 131091 | +#define YY_ACTTAB_COUNT (1501) |
| 130596 | 131092 | static const YYACTIONTYPE yy_action[] = { |
| 130597 | | - /* 0 */ 315, 1302, 146, 921, 2, 194, 922, 342, 952, 91, |
| 130598 | | - /* 10 */ 91, 91, 91, 84, 89, 89, 89, 89, 88, 88, |
| 130599 | | - /* 20 */ 87, 87, 87, 86, 339, 87, 87, 87, 86, 339, |
| 130600 | | - /* 30 */ 331, 819, 819, 91, 91, 91, 91, 339, 89, 89, |
| 130601 | | - /* 40 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 319, |
| 130602 | | - /* 50 */ 933, 933, 92, 93, 83, 831, 834, 823, 823, 90, |
| 130603 | | - /* 60 */ 90, 91, 91, 91, 91, 123, 89, 89, 89, 89, |
| 130604 | | - /* 70 */ 88, 88, 87, 87, 87, 86, 339, 315, 952, 89, |
| 130605 | | - /* 80 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339, |
| 130606 | | - /* 90 */ 365, 772, 360, 24, 933, 933, 947, 694, 933, 933, |
| 130607 | | - /* 100 */ 773, 937, 933, 933, 434, 715, 328, 434, 819, 819, |
| 130608 | | - /* 110 */ 203, 160, 278, 391, 273, 390, 190, 933, 933, 370, |
| 130609 | | - /* 120 */ 934, 935, 367, 271, 953, 48, 679, 953, 48, 92, |
| 130610 | | - /* 130 */ 93, 83, 831, 834, 823, 823, 90, 90, 91, 91, |
| 130611 | | - /* 140 */ 91, 91, 123, 89, 89, 89, 89, 88, 88, 87, |
| 130612 | | - /* 150 */ 87, 87, 86, 339, 315, 682, 337, 336, 218, 412, |
| 130613 | | - /* 160 */ 398, 68, 412, 403, 934, 935, 743, 959, 934, 935, |
| 130614 | | - /* 170 */ 810, 937, 934, 935, 957, 221, 958, 88, 88, 87, |
| 130615 | | - /* 180 */ 87, 87, 86, 339, 291, 819, 819, 934, 935, 185, |
| 130616 | | - /* 190 */ 94, 792, 388, 385, 384, 1240, 1240, 792, 804, 960, |
| 130617 | | - /* 200 */ 960, 290, 798, 383, 123, 315, 92, 93, 83, 831, |
| 130618 | | - /* 210 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326, |
| 130619 | | - /* 220 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86, |
| 130620 | | - /* 230 */ 339, 681, 741, 803, 803, 803, 819, 819, 944, 56, |
| 130621 | | - /* 240 */ 253, 353, 242, 85, 82, 168, 253, 358, 252, 110, |
| 130622 | | - /* 250 */ 96, 233, 397, 698, 677, 683, 683, 92, 93, 83, |
| 130623 | | - /* 260 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91, |
| 130624 | | - /* 270 */ 433, 89, 89, 89, 89, 88, 88, 87, 87, 87, |
| 130625 | | - /* 280 */ 86, 339, 315, 434, 439, 651, 396, 57, 733, 733, |
| 130626 | | - /* 290 */ 234, 291, 107, 287, 395, 86, 339, 810, 427, 728, |
| 130627 | | - /* 300 */ 933, 933, 185, 953, 30, 388, 385, 384, 215, 949, |
| 130628 | | - /* 310 */ 434, 933, 933, 819, 819, 697, 383, 162, 161, 407, |
| 130629 | | - /* 320 */ 400, 85, 82, 168, 677, 804, 335, 113, 771, 798, |
| 130630 | | - /* 330 */ 953, 48, 22, 351, 92, 93, 83, 831, 834, 823, |
| 130631 | | - /* 340 */ 823, 90, 90, 91, 91, 91, 91, 870, 89, 89, |
| 130632 | | - /* 350 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 315, |
| 130633 | | - /* 360 */ 803, 803, 803, 268, 123, 412, 394, 1, 933, 933, |
| 130634 | | - /* 370 */ 934, 935, 933, 933, 85, 82, 168, 232, 5, 343, |
| 130635 | | - /* 380 */ 194, 934, 935, 952, 85, 82, 168, 54, 956, 434, |
| 130636 | | - /* 390 */ 819, 819, 431, 938, 939, 792, 67, 759, 350, 144, |
| 130637 | | - /* 400 */ 166, 770, 123, 896, 889, 955, 348, 288, 758, 953, |
| 130638 | | - /* 410 */ 47, 92, 93, 83, 831, 834, 823, 823, 90, 90, |
| 130639 | | - /* 420 */ 91, 91, 91, 91, 892, 89, 89, 89, 89, 88, |
| 130640 | | - /* 430 */ 88, 87, 87, 87, 86, 339, 315, 113, 934, 935, |
| 130641 | | - /* 440 */ 687, 893, 934, 935, 253, 358, 252, 85, 82, 168, |
| 130642 | | - /* 450 */ 820, 820, 956, 952, 338, 938, 939, 894, 701, 721, |
| 130643 | | - /* 460 */ 359, 289, 233, 397, 434, 349, 434, 819, 819, 955, |
| 130644 | | - /* 470 */ 866, 722, 23, 389, 832, 835, 692, 357, 904, 667, |
| 130645 | | - /* 480 */ 194, 702, 402, 952, 953, 48, 953, 48, 92, 93, |
| 130646 | | - /* 490 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91, |
| 130647 | | - /* 500 */ 91, 824, 89, 89, 89, 89, 88, 88, 87, 87, |
| 130648 | | - /* 510 */ 87, 86, 339, 315, 434, 113, 434, 680, 434, 332, |
| 130649 | | - /* 520 */ 434, 408, 889, 356, 380, 940, 401, 720, 948, 864, |
| 130650 | | - /* 530 */ 191, 165, 329, 689, 953, 9, 953, 9, 953, 9, |
| 130651 | | - /* 540 */ 953, 9, 718, 948, 819, 819, 953, 8, 325, 111, |
| 130652 | | - /* 550 */ 327, 153, 224, 952, 410, 113, 189, 337, 336, 913, |
| 130653 | | - /* 560 */ 1295, 852, 75, 1295, 73, 92, 93, 83, 831, 834, |
| 130654 | | - /* 570 */ 823, 823, 90, 90, 91, 91, 91, 91, 359, 89, |
| 130655 | | - /* 580 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339, |
| 130656 | | - /* 590 */ 315, 730, 148, 236, 797, 366, 789, 892, 1179, 434, |
| 130657 | | - /* 600 */ 960, 960, 400, 148, 314, 212, 873, 911, 757, 404, |
| 130658 | | - /* 610 */ 872, 300, 320, 434, 893, 311, 237, 271, 405, 953, |
| 130659 | | - /* 620 */ 34, 819, 819, 225, 371, 945, 360, 913, 1296, 113, |
| 130660 | | - /* 630 */ 894, 1296, 417, 953, 35, 1245, 922, 342, 259, 247, |
| 130661 | | - /* 640 */ 290, 315, 92, 93, 83, 831, 834, 823, 823, 90, |
| 130662 | | - /* 650 */ 90, 91, 91, 91, 91, 148, 89, 89, 89, 89, |
| 130663 | | - /* 660 */ 88, 88, 87, 87, 87, 86, 339, 310, 434, 796, |
| 130664 | | - /* 670 */ 434, 240, 819, 819, 266, 911, 876, 876, 373, 346, |
| 130665 | | - /* 680 */ 167, 654, 655, 656, 259, 244, 19, 246, 953, 11, |
| 130666 | | - /* 690 */ 953, 26, 222, 92, 93, 83, 831, 834, 823, 823, |
| 130667 | | - /* 700 */ 90, 90, 91, 91, 91, 91, 757, 89, 89, 89, |
| 130668 | | - /* 710 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 434, |
| 130669 | | - /* 720 */ 261, 434, 264, 696, 434, 241, 434, 344, 971, 308, |
| 130670 | | - /* 730 */ 757, 434, 796, 434, 324, 434, 393, 423, 434, 953, |
| 130671 | | - /* 740 */ 36, 953, 37, 20, 953, 38, 953, 27, 434, 819, |
| 130672 | | - /* 750 */ 819, 953, 28, 953, 39, 953, 40, 738, 953, 41, |
| 130673 | | - /* 760 */ 71, 738, 737, 245, 307, 973, 737, 259, 953, 10, |
| 130674 | | - /* 770 */ 92, 93, 83, 831, 834, 823, 823, 90, 90, 91, |
| 130675 | | - /* 780 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88, |
| 130676 | | - /* 790 */ 87, 87, 87, 86, 339, 315, 434, 372, 434, 259, |
| 130677 | | - /* 800 */ 149, 434, 167, 953, 42, 188, 187, 186, 219, 434, |
| 130678 | | - /* 810 */ 748, 434, 974, 434, 796, 434, 953, 98, 953, 43, |
| 130679 | | - /* 820 */ 862, 953, 44, 434, 920, 2, 819, 819, 757, 953, |
| 130680 | | - /* 830 */ 31, 953, 45, 953, 46, 953, 32, 74, 307, 912, |
| 130681 | | - /* 840 */ 220, 259, 259, 953, 115, 909, 315, 92, 93, 83, |
| 130682 | | - /* 850 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91, |
| 130683 | | - /* 860 */ 434, 89, 89, 89, 89, 88, 88, 87, 87, 87, |
| 130684 | | - /* 870 */ 86, 339, 434, 248, 434, 215, 949, 819, 819, 333, |
| 130685 | | - /* 880 */ 953, 116, 895, 860, 176, 259, 974, 400, 361, 259, |
| 130686 | | - /* 890 */ 951, 887, 953, 117, 953, 52, 884, 315, 92, 93, |
| 130687 | | - /* 900 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91, |
| 130688 | | - /* 910 */ 91, 434, 89, 89, 89, 89, 88, 88, 87, 87, |
| 130689 | | - /* 920 */ 87, 86, 339, 434, 113, 434, 258, 883, 819, 819, |
| 130690 | | - /* 930 */ 727, 953, 33, 363, 259, 673, 321, 189, 430, 321, |
| 130691 | | - /* 940 */ 368, 365, 364, 953, 99, 953, 49, 365, 315, 92, |
| 130692 | | - /* 950 */ 81, 83, 831, 834, 823, 823, 90, 90, 91, 91, |
| 130693 | | - /* 960 */ 91, 91, 434, 89, 89, 89, 89, 88, 88, 87, |
| 130694 | | - /* 970 */ 87, 87, 86, 339, 434, 723, 434, 214, 165, 819, |
| 130695 | | - /* 980 */ 819, 772, 953, 100, 322, 124, 1269, 158, 65, 710, |
| 130696 | | - /* 990 */ 773, 700, 699, 320, 953, 101, 953, 97, 255, 315, |
| 130697 | | - /* 1000 */ 216, 93, 83, 831, 834, 823, 823, 90, 90, 91, |
| 130698 | | - /* 1010 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88, |
| 130699 | | - /* 1020 */ 87, 87, 87, 86, 339, 434, 251, 434, 707, 708, |
| 130700 | | - /* 1030 */ 819, 819, 223, 953, 114, 908, 794, 254, 309, 193, |
| 130701 | | - /* 1040 */ 67, 381, 869, 869, 199, 953, 112, 953, 105, 269, |
| 130702 | | - /* 1050 */ 726, 260, 67, 83, 831, 834, 823, 823, 90, 90, |
| 130703 | | - /* 1060 */ 91, 91, 91, 91, 263, 89, 89, 89, 89, 88, |
| 130704 | | - /* 1070 */ 88, 87, 87, 87, 86, 339, 79, 429, 690, 3, |
| 130705 | | - /* 1080 */ 1174, 228, 434, 113, 340, 340, 868, 868, 265, 79, |
| 130706 | | - /* 1090 */ 429, 735, 3, 859, 70, 432, 434, 340, 340, 434, |
| 130707 | | - /* 1100 */ 1259, 434, 953, 104, 434, 670, 416, 766, 432, 434, |
| 130708 | | - /* 1110 */ 193, 434, 413, 434, 418, 806, 953, 102, 420, 953, |
| 130709 | | - /* 1120 */ 103, 953, 48, 123, 953, 51, 810, 418, 424, 953, |
| 130710 | | - /* 1130 */ 53, 953, 50, 953, 25, 267, 123, 711, 113, 810, |
| 130711 | | - /* 1140 */ 428, 277, 695, 272, 764, 113, 76, 77, 690, 434, |
| 130712 | | - /* 1150 */ 795, 113, 276, 78, 436, 435, 412, 414, 798, 76, |
| 130713 | | - /* 1160 */ 77, 113, 855, 859, 376, 199, 78, 436, 435, 953, |
| 130714 | | - /* 1170 */ 29, 798, 744, 113, 755, 79, 429, 675, 3, 415, |
| 130715 | | - /* 1180 */ 109, 292, 293, 340, 340, 806, 802, 678, 672, 803, |
| 130716 | | - /* 1190 */ 803, 803, 805, 18, 432, 661, 660, 662, 927, 209, |
| 130717 | | - /* 1200 */ 150, 352, 803, 803, 803, 805, 18, 6, 306, 280, |
| 130718 | | - /* 1210 */ 282, 284, 786, 418, 250, 386, 243, 886, 694, 362, |
| 130719 | | - /* 1220 */ 286, 163, 275, 79, 429, 810, 3, 857, 856, 159, |
| 130720 | | - /* 1230 */ 419, 340, 340, 298, 930, 968, 126, 196, 965, 903, |
| 130721 | | - /* 1240 */ 901, 323, 432, 136, 55, 76, 77, 742, 147, 58, |
| 130722 | | - /* 1250 */ 121, 129, 78, 436, 435, 65, 783, 798, 354, 131, |
| 130723 | | - /* 1260 */ 355, 418, 379, 132, 133, 134, 175, 139, 151, 369, |
| 130724 | | - /* 1270 */ 888, 180, 791, 810, 61, 851, 871, 69, 429, 375, |
| 130725 | | - /* 1280 */ 3, 756, 210, 257, 181, 340, 340, 145, 803, 803, |
| 130726 | | - /* 1290 */ 803, 805, 18, 76, 77, 377, 432, 262, 182, 183, |
| 130727 | | - /* 1300 */ 78, 436, 435, 663, 312, 798, 392, 714, 713, 712, |
| 130728 | | - /* 1310 */ 330, 705, 692, 313, 704, 418, 686, 406, 752, 685, |
| 130729 | | - /* 1320 */ 274, 684, 942, 64, 279, 195, 281, 810, 753, 839, |
| 130730 | | - /* 1330 */ 751, 283, 72, 750, 285, 422, 803, 803, 803, 805, |
| 130731 | | - /* 1340 */ 18, 334, 426, 95, 411, 229, 409, 76, 77, 230, |
| 130732 | | - /* 1350 */ 734, 66, 231, 294, 78, 436, 435, 204, 295, 798, |
| 130733 | | - /* 1360 */ 217, 296, 297, 669, 21, 305, 304, 303, 206, 301, |
| 130734 | | - /* 1370 */ 437, 928, 664, 205, 208, 207, 438, 658, 657, 652, |
| 130735 | | - /* 1380 */ 118, 108, 119, 226, 650, 341, 157, 170, 169, 239, |
| 130736 | | - /* 1390 */ 803, 803, 803, 805, 18, 125, 120, 235, 238, 317, |
| 130737 | | - /* 1400 */ 318, 345, 106, 790, 867, 127, 865, 128, 130, 724, |
| 130738 | | - /* 1410 */ 249, 172, 174, 882, 135, 137, 59, 138, 173, 60, |
| 130739 | | - /* 1420 */ 885, 123, 171, 177, 178, 881, 7, 12, 179, 256, |
| 130740 | | - /* 1430 */ 874, 140, 193, 962, 374, 141, 666, 152, 378, 276, |
| 130741 | | - /* 1440 */ 184, 382, 142, 122, 62, 13, 387, 703, 270, 14, |
| 130742 | | - /* 1450 */ 63, 227, 809, 808, 837, 732, 15, 841, 736, 4, |
| 130743 | | - /* 1460 */ 765, 211, 399, 164, 213, 143, 760, 201, 70, 316, |
| 130744 | | - /* 1470 */ 67, 838, 836, 891, 198, 192, 16, 197, 890, 917, |
| 130745 | | - /* 1480 */ 154, 17, 202, 421, 918, 155, 200, 156, 425, 840, |
| 130746 | | - /* 1490 */ 807, 1261, 676, 80, 302, 299, 347, 1260, 923, |
| 131093 | + /* 0 */ 315, 810, 339, 804, 5, 194, 194, 798, 92, 93, |
| 131094 | + /* 10 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91, |
| 131095 | + /* 20 */ 91, 91, 91, 290, 89, 89, 89, 89, 88, 88, |
| 131096 | + /* 30 */ 87, 87, 87, 86, 339, 315, 952, 952, 803, 803, |
| 131097 | + /* 40 */ 803, 922, 342, 92, 93, 83, 819, 819, 831, 834, |
| 131098 | + /* 50 */ 823, 823, 90, 90, 91, 91, 91, 91, 123, 89, |
| 131099 | + /* 60 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339, |
| 131100 | + /* 70 */ 88, 88, 87, 87, 87, 86, 339, 772, 952, 952, |
| 131101 | + /* 80 */ 315, 87, 87, 87, 86, 339, 773, 68, 92, 93, |
| 131102 | + /* 90 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91, |
| 131103 | + /* 100 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88, |
| 131104 | + /* 110 */ 87, 87, 87, 86, 339, 1302, 146, 921, 2, 315, |
| 131105 | + /* 120 */ 427, 24, 679, 953, 48, 86, 339, 92, 93, 83, |
| 131106 | + /* 130 */ 819, 819, 831, 834, 823, 823, 90, 90, 91, 91, |
| 131107 | + /* 140 */ 91, 91, 94, 89, 89, 89, 89, 88, 88, 87, |
| 131108 | + /* 150 */ 87, 87, 86, 339, 933, 933, 315, 259, 412, 398, |
| 131109 | + /* 160 */ 396, 57, 733, 733, 92, 93, 83, 819, 819, 831, |
| 131110 | + /* 170 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 56, |
| 131111 | + /* 180 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86, |
| 131112 | + /* 190 */ 339, 315, 1245, 922, 342, 268, 934, 935, 241, 92, |
| 131113 | + /* 200 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90, |
| 131114 | + /* 210 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88, |
| 131115 | + /* 220 */ 88, 87, 87, 87, 86, 339, 315, 913, 1295, 682, |
| 131116 | + /* 230 */ 687, 1295, 233, 397, 92, 93, 83, 819, 819, 831, |
| 131117 | + /* 240 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326, |
| 131118 | + /* 250 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86, |
| 131119 | + /* 260 */ 339, 315, 85, 82, 168, 680, 431, 938, 939, 92, |
| 131120 | + /* 270 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90, |
| 131121 | + /* 280 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88, |
| 131122 | + /* 290 */ 88, 87, 87, 87, 86, 339, 315, 319, 913, 1296, |
| 131123 | + /* 300 */ 797, 911, 1296, 681, 92, 93, 83, 819, 819, 831, |
| 131124 | + /* 310 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 335, |
| 131125 | + /* 320 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86, |
| 131126 | + /* 330 */ 339, 315, 876, 876, 373, 85, 82, 168, 944, 92, |
| 131127 | + /* 340 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90, |
| 131128 | + /* 350 */ 91, 91, 91, 91, 896, 89, 89, 89, 89, 88, |
| 131129 | + /* 360 */ 88, 87, 87, 87, 86, 339, 315, 370, 307, 973, |
| 131130 | + /* 370 */ 367, 1, 911, 433, 92, 93, 83, 819, 819, 831, |
| 131131 | + /* 380 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 189, |
| 131132 | + /* 390 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86, |
| 131133 | + /* 400 */ 339, 315, 720, 948, 933, 933, 149, 718, 948, 92, |
| 131134 | + /* 410 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90, |
| 131135 | + /* 420 */ 91, 91, 91, 91, 434, 89, 89, 89, 89, 88, |
| 131136 | + /* 430 */ 88, 87, 87, 87, 86, 339, 338, 938, 939, 947, |
| 131137 | + /* 440 */ 694, 940, 974, 315, 953, 48, 934, 935, 715, 689, |
| 131138 | + /* 450 */ 71, 92, 93, 83, 819, 819, 831, 834, 823, 823, |
| 131139 | + /* 460 */ 90, 90, 91, 91, 91, 91, 320, 89, 89, 89, |
| 131140 | + /* 470 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 412, |
| 131141 | + /* 480 */ 403, 820, 820, 832, 835, 74, 92, 81, 83, 819, |
| 131142 | + /* 490 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91, |
| 131143 | + /* 500 */ 91, 698, 89, 89, 89, 89, 88, 88, 87, 87, |
| 131144 | + /* 510 */ 87, 86, 339, 315, 259, 654, 655, 656, 393, 111, |
| 131145 | + /* 520 */ 331, 153, 93, 83, 819, 819, 831, 834, 823, 823, |
| 131146 | + /* 530 */ 90, 90, 91, 91, 91, 91, 434, 89, 89, 89, |
| 131147 | + /* 540 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 188, |
| 131148 | + /* 550 */ 187, 186, 824, 937, 328, 219, 953, 48, 83, 819, |
| 131149 | + /* 560 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91, |
| 131150 | + /* 570 */ 91, 956, 89, 89, 89, 89, 88, 88, 87, 87, |
| 131151 | + /* 580 */ 87, 86, 339, 79, 429, 738, 3, 1174, 955, 348, |
| 131152 | + /* 590 */ 737, 332, 792, 933, 933, 937, 79, 429, 730, 3, |
| 131153 | + /* 600 */ 203, 160, 278, 391, 273, 390, 190, 892, 434, 400, |
| 131154 | + /* 610 */ 741, 76, 77, 271, 287, 253, 353, 242, 78, 340, |
| 131155 | + /* 620 */ 340, 85, 82, 168, 76, 77, 233, 397, 953, 48, |
| 131156 | + /* 630 */ 432, 78, 340, 340, 277, 934, 935, 185, 439, 651, |
| 131157 | + /* 640 */ 388, 385, 384, 432, 234, 276, 107, 418, 349, 337, |
| 131158 | + /* 650 */ 336, 383, 893, 728, 215, 949, 123, 971, 308, 810, |
| 131159 | + /* 660 */ 418, 436, 435, 412, 394, 798, 400, 873, 894, 123, |
| 131160 | + /* 670 */ 721, 872, 810, 889, 436, 435, 215, 949, 798, 351, |
| 131161 | + /* 680 */ 722, 697, 380, 434, 771, 371, 22, 434, 400, 79, |
| 131162 | + /* 690 */ 429, 232, 3, 189, 413, 870, 803, 803, 803, 805, |
| 131163 | + /* 700 */ 18, 54, 148, 953, 48, 956, 113, 953, 9, 803, |
| 131164 | + /* 710 */ 803, 803, 805, 18, 310, 123, 748, 76, 77, 742, |
| 131165 | + /* 720 */ 123, 325, 955, 866, 78, 340, 340, 113, 350, 359, |
| 131166 | + /* 730 */ 85, 82, 168, 343, 960, 960, 432, 770, 412, 414, |
| 131167 | + /* 740 */ 407, 23, 1240, 1240, 79, 429, 357, 3, 166, 91, |
| 131168 | + /* 750 */ 91, 91, 91, 418, 89, 89, 89, 89, 88, 88, |
| 131169 | + /* 760 */ 87, 87, 87, 86, 339, 810, 434, 436, 435, 792, |
| 131170 | + /* 770 */ 320, 798, 76, 77, 789, 271, 123, 434, 360, 78, |
| 131171 | + /* 780 */ 340, 340, 864, 85, 82, 168, 953, 9, 395, 743, |
| 131172 | + /* 790 */ 360, 432, 253, 358, 252, 933, 933, 953, 30, 889, |
| 131173 | + /* 800 */ 327, 216, 803, 803, 803, 805, 18, 113, 418, 89, |
| 131174 | + /* 810 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339, |
| 131175 | + /* 820 */ 810, 113, 436, 435, 792, 185, 798, 288, 388, 385, |
| 131176 | + /* 830 */ 384, 123, 113, 920, 2, 796, 696, 934, 935, 383, |
| 131177 | + /* 840 */ 69, 429, 434, 3, 218, 110, 738, 253, 358, 252, |
| 131178 | + /* 850 */ 434, 737, 933, 933, 892, 359, 222, 803, 803, 803, |
| 131179 | + /* 860 */ 805, 18, 953, 47, 933, 933, 933, 933, 76, 77, |
| 131180 | + /* 870 */ 953, 9, 366, 904, 217, 78, 340, 340, 677, 305, |
| 131181 | + /* 880 */ 304, 303, 206, 301, 224, 259, 664, 432, 337, 336, |
| 131182 | + /* 890 */ 434, 228, 247, 144, 934, 935, 933, 933, 667, 893, |
| 131183 | + /* 900 */ 324, 1259, 96, 434, 418, 796, 934, 935, 934, 935, |
| 131184 | + /* 910 */ 953, 48, 401, 148, 289, 894, 810, 417, 436, 435, |
| 131185 | + /* 920 */ 677, 759, 798, 953, 9, 314, 220, 162, 161, 170, |
| 131186 | + /* 930 */ 402, 239, 953, 8, 194, 683, 683, 410, 934, 935, |
| 131187 | + /* 940 */ 238, 959, 933, 933, 225, 408, 945, 365, 957, 212, |
| 131188 | + /* 950 */ 958, 172, 757, 803, 803, 803, 805, 18, 173, 365, |
| 131189 | + /* 960 */ 176, 123, 171, 113, 244, 952, 246, 434, 356, 796, |
| 131190 | + /* 970 */ 372, 365, 236, 960, 960, 810, 290, 804, 191, 165, |
| 131191 | + /* 980 */ 852, 798, 259, 316, 934, 935, 237, 953, 34, 404, |
| 131192 | + /* 990 */ 91, 91, 91, 91, 84, 89, 89, 89, 89, 88, |
| 131193 | + /* 1000 */ 88, 87, 87, 87, 86, 339, 701, 952, 434, 240, |
| 131194 | + /* 1010 */ 347, 758, 803, 803, 803, 434, 245, 1179, 434, 389, |
| 131195 | + /* 1020 */ 434, 376, 434, 895, 167, 434, 405, 702, 953, 35, |
| 131196 | + /* 1030 */ 673, 321, 221, 434, 333, 953, 11, 434, 953, 26, |
| 131197 | + /* 1040 */ 953, 36, 953, 37, 251, 953, 38, 434, 259, 434, |
| 131198 | + /* 1050 */ 757, 434, 329, 953, 27, 434, 223, 953, 28, 434, |
| 131199 | + /* 1060 */ 690, 434, 67, 434, 65, 434, 862, 953, 39, 953, |
| 131200 | + /* 1070 */ 40, 953, 41, 423, 434, 953, 10, 434, 772, 953, |
| 131201 | + /* 1080 */ 42, 953, 98, 953, 43, 953, 44, 773, 434, 346, |
| 131202 | + /* 1090 */ 434, 75, 434, 73, 953, 31, 434, 953, 45, 434, |
| 131203 | + /* 1100 */ 259, 434, 690, 434, 757, 434, 887, 434, 953, 46, |
| 131204 | + /* 1110 */ 953, 32, 953, 115, 434, 266, 953, 116, 951, 953, |
| 131205 | + /* 1120 */ 117, 953, 52, 953, 33, 953, 99, 953, 49, 726, |
| 131206 | + /* 1130 */ 434, 909, 434, 19, 953, 100, 434, 344, 434, 113, |
| 131207 | + /* 1140 */ 434, 258, 692, 434, 259, 434, 670, 434, 20, 434, |
| 131208 | + /* 1150 */ 953, 101, 953, 97, 434, 259, 953, 114, 953, 112, |
| 131209 | + /* 1160 */ 953, 105, 113, 953, 104, 953, 102, 953, 103, 953, |
| 131210 | + /* 1170 */ 51, 434, 148, 434, 953, 53, 167, 434, 259, 113, |
| 131211 | + /* 1180 */ 300, 307, 912, 363, 311, 860, 248, 261, 209, 264, |
| 131212 | + /* 1190 */ 416, 953, 50, 953, 25, 420, 727, 953, 29, 430, |
| 131213 | + /* 1200 */ 321, 424, 757, 428, 322, 124, 1269, 214, 165, 710, |
| 131214 | + /* 1210 */ 859, 908, 806, 794, 309, 158, 193, 361, 254, 723, |
| 131215 | + /* 1220 */ 364, 67, 381, 269, 735, 199, 67, 70, 113, 700, |
| 131216 | + /* 1230 */ 699, 707, 708, 884, 113, 766, 113, 855, 193, 883, |
| 131217 | + /* 1240 */ 199, 869, 869, 675, 868, 868, 109, 368, 255, 260, |
| 131218 | + /* 1250 */ 263, 280, 859, 265, 806, 974, 267, 711, 695, 272, |
| 131219 | + /* 1260 */ 764, 282, 795, 284, 150, 744, 755, 415, 292, 293, |
| 131220 | + /* 1270 */ 802, 678, 672, 661, 660, 662, 927, 6, 306, 386, |
| 131221 | + /* 1280 */ 352, 786, 243, 250, 886, 362, 163, 286, 419, 298, |
| 131222 | + /* 1290 */ 930, 159, 968, 196, 126, 903, 901, 965, 55, 58, |
| 131223 | + /* 1300 */ 323, 275, 857, 136, 147, 694, 856, 121, 65, 354, |
| 131224 | + /* 1310 */ 355, 379, 175, 61, 151, 369, 180, 871, 375, 129, |
| 131225 | + /* 1320 */ 257, 756, 210, 181, 145, 131, 132, 377, 262, 663, |
| 131226 | + /* 1330 */ 133, 134, 139, 783, 791, 182, 392, 183, 312, 330, |
| 131227 | + /* 1340 */ 714, 888, 713, 851, 692, 195, 712, 406, 686, 705, |
| 131228 | + /* 1350 */ 313, 685, 64, 839, 274, 72, 684, 334, 942, 95, |
| 131229 | + /* 1360 */ 752, 279, 281, 704, 753, 751, 422, 283, 411, 750, |
| 131230 | + /* 1370 */ 426, 66, 204, 409, 21, 285, 928, 669, 437, 205, |
| 131231 | + /* 1380 */ 207, 208, 438, 658, 657, 652, 118, 108, 119, 226, |
| 131232 | + /* 1390 */ 650, 341, 157, 235, 169, 345, 106, 734, 790, 296, |
| 131233 | + /* 1400 */ 294, 295, 120, 297, 867, 865, 127, 128, 130, 724, |
| 131234 | + /* 1410 */ 229, 174, 249, 882, 137, 230, 138, 135, 885, 231, |
| 131235 | + /* 1420 */ 59, 60, 177, 881, 7, 178, 12, 179, 256, 874, |
| 131236 | + /* 1430 */ 140, 193, 962, 374, 141, 152, 666, 378, 276, 184, |
| 131237 | + /* 1440 */ 270, 122, 142, 382, 387, 62, 13, 14, 703, 63, |
| 131238 | + /* 1450 */ 125, 317, 318, 227, 809, 808, 837, 732, 15, 164, |
| 131239 | + /* 1460 */ 736, 4, 765, 211, 399, 213, 192, 143, 760, 70, |
| 131240 | + /* 1470 */ 67, 16, 17, 838, 836, 891, 841, 890, 198, 197, |
| 131241 | + /* 1480 */ 917, 154, 421, 923, 918, 155, 200, 977, 425, 840, |
| 131242 | + /* 1490 */ 156, 201, 807, 676, 80, 302, 299, 977, 202, 1261, |
| 131243 | + /* 1500 */ 1260, |
| 130747 | 131244 | }; |
| 130748 | 131245 | static const YYCODETYPE yy_lookahead[] = { |
| 130749 | | - /* 0 */ 19, 144, 145, 146, 147, 24, 1, 2, 27, 80, |
| 130750 | | - /* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, |
| 130751 | | - /* 20 */ 91, 92, 93, 94, 95, 91, 92, 93, 94, 95, |
| 130752 | | - /* 30 */ 19, 50, 51, 80, 81, 82, 83, 95, 85, 86, |
| 130753 | | - /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 157, |
| 130754 | | - /* 50 */ 27, 28, 71, 72, 73, 74, 75, 76, 77, 78, |
| 130755 | | - /* 60 */ 79, 80, 81, 82, 83, 66, 85, 86, 87, 88, |
| 130756 | | - /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 85, |
| 130757 | | - /* 80 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, |
| 130758 | | - /* 90 */ 152, 33, 152, 22, 27, 28, 179, 180, 27, 28, |
| 130759 | | - /* 100 */ 42, 27, 27, 28, 152, 188, 95, 152, 50, 51, |
| 130760 | | - /* 110 */ 99, 100, 101, 102, 103, 104, 105, 27, 28, 227, |
| 130761 | | - /* 120 */ 97, 98, 230, 112, 172, 173, 172, 172, 173, 71, |
| 130762 | | - /* 130 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, |
| 130763 | | - /* 140 */ 82, 83, 66, 85, 86, 87, 88, 89, 90, 91, |
| 130764 | | - /* 150 */ 92, 93, 94, 95, 19, 172, 89, 90, 218, 207, |
| 130765 | | - /* 160 */ 208, 26, 207, 208, 97, 98, 91, 100, 97, 98, |
| 130766 | | - /* 170 */ 69, 97, 97, 98, 107, 237, 109, 89, 90, 91, |
| 130767 | | - /* 180 */ 92, 93, 94, 95, 152, 50, 51, 97, 98, 99, |
| 130768 | | - /* 190 */ 55, 59, 102, 103, 104, 119, 120, 59, 97, 132, |
| 130769 | | - /* 200 */ 133, 152, 101, 113, 66, 19, 71, 72, 73, 74, |
| 130770 | | - /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 187, |
| 130771 | | - /* 220 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, |
| 130772 | | - /* 230 */ 95, 172, 210, 132, 133, 134, 50, 51, 185, 53, |
| 130773 | | - /* 240 */ 108, 109, 110, 221, 222, 223, 108, 109, 110, 22, |
| 130774 | | - /* 250 */ 22, 119, 120, 181, 27, 27, 28, 71, 72, 73, |
| 130775 | | - /* 260 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, |
| 130776 | | - /* 270 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93, |
| 130777 | | - /* 280 */ 94, 95, 19, 152, 148, 149, 115, 24, 117, 118, |
| 130778 | | - /* 290 */ 154, 152, 156, 152, 163, 94, 95, 69, 249, 163, |
| 130779 | | - /* 300 */ 27, 28, 99, 172, 173, 102, 103, 104, 194, 195, |
| 130780 | | - /* 310 */ 152, 27, 28, 50, 51, 181, 113, 89, 90, 152, |
| 130781 | | - /* 320 */ 206, 221, 222, 223, 97, 97, 187, 196, 175, 101, |
| 130782 | | - /* 330 */ 172, 173, 196, 219, 71, 72, 73, 74, 75, 76, |
| 130783 | | - /* 340 */ 77, 78, 79, 80, 81, 82, 83, 11, 85, 86, |
| 130784 | | - /* 350 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 19, |
| 130785 | | - /* 360 */ 132, 133, 134, 23, 66, 207, 208, 22, 27, 28, |
| 130786 | | - /* 370 */ 97, 98, 27, 28, 221, 222, 223, 199, 22, 243, |
| 130787 | | - /* 380 */ 24, 97, 98, 27, 221, 222, 223, 209, 152, 152, |
| 130788 | | - /* 390 */ 50, 51, 168, 169, 170, 59, 26, 124, 100, 58, |
| 130789 | | - /* 400 */ 152, 175, 66, 240, 163, 169, 170, 152, 124, 172, |
| 130790 | | - /* 410 */ 173, 71, 72, 73, 74, 75, 76, 77, 78, 79, |
| 130791 | | - /* 420 */ 80, 81, 82, 83, 12, 85, 86, 87, 88, 89, |
| 130792 | | - /* 430 */ 90, 91, 92, 93, 94, 95, 19, 196, 97, 98, |
| 130793 | | - /* 440 */ 23, 29, 97, 98, 108, 109, 110, 221, 222, 223, |
| 130794 | | - /* 450 */ 50, 51, 152, 97, 168, 169, 170, 45, 37, 47, |
| 130795 | | - /* 460 */ 219, 224, 119, 120, 152, 229, 152, 50, 51, 169, |
| 130796 | | - /* 470 */ 170, 59, 231, 52, 74, 75, 106, 236, 152, 21, |
| 130797 | | - /* 480 */ 24, 60, 163, 27, 172, 173, 172, 173, 71, 72, |
| 130798 | | - /* 490 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, |
| 130799 | | - /* 500 */ 83, 101, 85, 86, 87, 88, 89, 90, 91, 92, |
| 130800 | | - /* 510 */ 93, 94, 95, 19, 152, 196, 152, 23, 152, 207, |
| 130801 | | - /* 520 */ 152, 207, 163, 65, 19, 171, 152, 190, 191, 229, |
| 130802 | | - /* 530 */ 211, 212, 111, 179, 172, 173, 172, 173, 172, 173, |
| 130803 | | - /* 540 */ 172, 173, 190, 191, 50, 51, 172, 173, 186, 22, |
| 130804 | | - /* 550 */ 186, 24, 186, 97, 186, 196, 51, 89, 90, 22, |
| 130805 | | - /* 560 */ 23, 103, 137, 26, 139, 71, 72, 73, 74, 75, |
| 130806 | | - /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 219, 85, |
| 130807 | | - /* 580 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, |
| 130808 | | - /* 590 */ 19, 195, 152, 152, 23, 236, 163, 12, 140, 152, |
| 130809 | | - /* 600 */ 132, 133, 206, 152, 164, 23, 31, 70, 26, 19, |
| 130810 | | - /* 610 */ 35, 160, 107, 152, 29, 164, 152, 112, 28, 172, |
| 130811 | | - /* 620 */ 173, 50, 51, 183, 49, 185, 152, 22, 23, 196, |
| 130812 | | - /* 630 */ 45, 26, 47, 172, 173, 0, 1, 2, 152, 16, |
| 130813 | | - /* 640 */ 152, 19, 71, 72, 73, 74, 75, 76, 77, 78, |
| 130814 | | - /* 650 */ 79, 80, 81, 82, 83, 152, 85, 86, 87, 88, |
| 130815 | | - /* 660 */ 89, 90, 91, 92, 93, 94, 95, 164, 152, 152, |
| 130816 | | - /* 670 */ 152, 152, 50, 51, 16, 70, 108, 109, 110, 193, |
| 130817 | | - /* 680 */ 98, 7, 8, 9, 152, 62, 22, 64, 172, 173, |
| 130818 | | - /* 690 */ 172, 173, 218, 71, 72, 73, 74, 75, 76, 77, |
| 130819 | | - /* 700 */ 78, 79, 80, 81, 82, 83, 124, 85, 86, 87, |
| 130820 | | - /* 710 */ 88, 89, 90, 91, 92, 93, 94, 95, 19, 152, |
| 130821 | | - /* 720 */ 62, 152, 64, 181, 152, 193, 152, 241, 246, 247, |
| 130822 | | - /* 730 */ 26, 152, 152, 152, 217, 152, 91, 249, 152, 172, |
| 130823 | | - /* 740 */ 173, 172, 173, 79, 172, 173, 172, 173, 152, 50, |
| 130824 | | - /* 750 */ 51, 172, 173, 172, 173, 172, 173, 116, 172, 173, |
| 130825 | | - /* 760 */ 138, 116, 121, 140, 22, 23, 121, 152, 172, 173, |
| 130826 | | - /* 770 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 130827 | | - /* 780 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90, |
| 130828 | | - /* 790 */ 91, 92, 93, 94, 95, 19, 152, 217, 152, 152, |
| 130829 | | - /* 800 */ 24, 152, 98, 172, 173, 108, 109, 110, 193, 152, |
| 130830 | | - /* 810 */ 213, 152, 70, 152, 152, 152, 172, 173, 172, 173, |
| 130831 | | - /* 820 */ 152, 172, 173, 152, 146, 147, 50, 51, 124, 172, |
| 130832 | | - /* 830 */ 173, 172, 173, 172, 173, 172, 173, 138, 22, 23, |
| 130833 | | - /* 840 */ 193, 152, 152, 172, 173, 152, 19, 71, 72, 73, |
| 130834 | | - /* 850 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, |
| 130835 | | - /* 860 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93, |
| 130836 | | - /* 870 */ 94, 95, 152, 152, 152, 194, 195, 50, 51, 217, |
| 130837 | | - /* 880 */ 172, 173, 193, 193, 26, 152, 70, 206, 152, 152, |
| 130838 | | - /* 890 */ 26, 163, 172, 173, 172, 173, 152, 19, 71, 72, |
| 130839 | | - /* 900 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, |
| 130840 | | - /* 910 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92, |
| 130841 | | - /* 920 */ 93, 94, 95, 152, 196, 152, 193, 152, 50, 51, |
| 130842 | | - /* 930 */ 193, 172, 173, 19, 152, 166, 167, 51, 166, 167, |
| 130843 | | - /* 940 */ 152, 152, 28, 172, 173, 172, 173, 152, 19, 71, |
| 130844 | | - /* 950 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, |
| 130845 | | - /* 960 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91, |
| 130846 | | - /* 970 */ 92, 93, 94, 95, 152, 193, 152, 211, 212, 50, |
| 130847 | | - /* 980 */ 51, 33, 172, 173, 244, 245, 23, 123, 130, 26, |
| 130848 | | - /* 990 */ 42, 100, 101, 107, 172, 173, 172, 173, 152, 19, |
| 130849 | | - /* 1000 */ 22, 72, 73, 74, 75, 76, 77, 78, 79, 80, |
| 130850 | | - /* 1010 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90, |
| 130851 | | - /* 1020 */ 91, 92, 93, 94, 95, 152, 237, 152, 7, 8, |
| 130852 | | - /* 1030 */ 50, 51, 237, 172, 173, 23, 23, 23, 26, 26, |
| 130853 | | - /* 1040 */ 26, 23, 132, 133, 26, 172, 173, 172, 173, 23, |
| 130854 | | - /* 1050 */ 163, 152, 26, 73, 74, 75, 76, 77, 78, 79, |
| 130855 | | - /* 1060 */ 80, 81, 82, 83, 152, 85, 86, 87, 88, 89, |
| 130856 | | - /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 27, 22, |
| 130857 | | - /* 1080 */ 23, 210, 152, 196, 27, 28, 132, 133, 152, 19, |
| 130858 | | - /* 1090 */ 20, 23, 22, 27, 26, 38, 152, 27, 28, 152, |
| 130859 | | - /* 1100 */ 122, 152, 172, 173, 152, 163, 191, 23, 38, 152, |
| 130860 | | - /* 1110 */ 26, 152, 163, 152, 57, 27, 172, 173, 163, 172, |
| 130861 | | - /* 1120 */ 173, 172, 173, 66, 172, 173, 69, 57, 163, 172, |
| 130862 | | - /* 1130 */ 173, 172, 173, 172, 173, 152, 66, 152, 196, 69, |
| 130863 | | - /* 1140 */ 163, 101, 152, 152, 152, 196, 89, 90, 97, 152, |
| 130864 | | - /* 1150 */ 152, 196, 112, 96, 97, 98, 207, 208, 101, 89, |
| 130865 | | - /* 1160 */ 90, 196, 23, 97, 233, 26, 96, 97, 98, 172, |
| 130866 | | - /* 1170 */ 173, 101, 152, 196, 152, 19, 20, 23, 22, 152, |
| 130867 | | - /* 1180 */ 26, 152, 152, 27, 28, 97, 152, 152, 152, 132, |
| 130868 | | - /* 1190 */ 133, 134, 135, 136, 38, 152, 152, 152, 152, 232, |
| 130869 | | - /* 1200 */ 197, 214, 132, 133, 134, 135, 136, 198, 150, 210, |
| 130870 | | - /* 1210 */ 210, 210, 201, 57, 238, 176, 214, 201, 180, 238, |
| 130871 | | - /* 1220 */ 214, 184, 175, 19, 20, 69, 22, 175, 175, 198, |
| 130872 | | - /* 1230 */ 226, 27, 28, 200, 155, 39, 242, 122, 41, 159, |
| 130873 | | - /* 1240 */ 159, 159, 38, 22, 239, 89, 90, 91, 220, 239, |
| 130874 | | - /* 1250 */ 71, 189, 96, 97, 98, 130, 201, 101, 18, 192, |
| 130875 | | - /* 1260 */ 159, 57, 18, 192, 192, 192, 158, 189, 220, 159, |
| 130876 | | - /* 1270 */ 201, 158, 189, 69, 137, 201, 235, 19, 20, 46, |
| 130877 | | - /* 1280 */ 22, 159, 159, 234, 158, 27, 28, 22, 132, 133, |
| 130878 | | - /* 1290 */ 134, 135, 136, 89, 90, 177, 38, 159, 158, 158, |
| 130879 | | - /* 1300 */ 96, 97, 98, 159, 177, 101, 107, 174, 174, 174, |
| 130880 | | - /* 1310 */ 48, 182, 106, 177, 182, 57, 174, 125, 216, 176, |
| 130881 | | - /* 1320 */ 174, 174, 174, 107, 215, 159, 215, 69, 216, 159, |
| 130882 | | - /* 1330 */ 216, 215, 137, 216, 215, 177, 132, 133, 134, 135, |
| 130883 | | - /* 1340 */ 136, 95, 177, 129, 126, 225, 127, 89, 90, 228, |
| 130884 | | - /* 1350 */ 205, 128, 228, 204, 96, 97, 98, 25, 203, 101, |
| 130885 | | - /* 1360 */ 5, 202, 201, 162, 26, 10, 11, 12, 13, 14, |
| 130886 | | - /* 1370 */ 161, 13, 17, 153, 6, 153, 151, 151, 151, 151, |
| 130887 | | - /* 1380 */ 165, 178, 165, 178, 4, 3, 22, 32, 15, 34, |
| 130888 | | - /* 1390 */ 132, 133, 134, 135, 136, 245, 165, 142, 43, 248, |
| 130889 | | - /* 1400 */ 248, 68, 16, 120, 23, 131, 23, 111, 123, 20, |
| 130890 | | - /* 1410 */ 16, 56, 125, 1, 123, 131, 79, 111, 63, 79, |
| 130891 | | - /* 1420 */ 28, 66, 67, 36, 122, 1, 5, 22, 107, 140, |
| 130892 | | - /* 1430 */ 54, 54, 26, 61, 44, 107, 20, 24, 19, 112, |
| 130893 | | - /* 1440 */ 105, 53, 22, 40, 22, 22, 53, 30, 23, 22, |
| 130894 | | - /* 1450 */ 22, 53, 23, 23, 23, 116, 22, 11, 23, 22, |
| 130895 | | - /* 1460 */ 28, 23, 26, 122, 23, 22, 124, 122, 26, 114, |
| 130896 | | - /* 1470 */ 26, 23, 23, 23, 22, 36, 36, 26, 23, 23, |
| 130897 | | - /* 1480 */ 22, 36, 122, 24, 23, 22, 26, 22, 24, 23, |
| 130898 | | - /* 1490 */ 23, 122, 23, 22, 15, 23, 141, 122, 1, |
| 130899 | | -}; |
| 130900 | | -#define YY_SHIFT_USE_DFLT (-72) |
| 131246 | + /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28, |
| 131247 | + /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, |
| 131248 | + /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48, |
| 131249 | + /* 30 */ 49, 50, 51, 52, 53, 19, 55, 55, 132, 133, |
| 131250 | + /* 40 */ 134, 1, 2, 27, 28, 29, 30, 31, 32, 33, |
| 131251 | + /* 50 */ 34, 35, 36, 37, 38, 39, 40, 41, 92, 43, |
| 131252 | + /* 60 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 131253 | + /* 70 */ 47, 48, 49, 50, 51, 52, 53, 61, 97, 97, |
| 131254 | + /* 80 */ 19, 49, 50, 51, 52, 53, 70, 26, 27, 28, |
| 131255 | + /* 90 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, |
| 131256 | + /* 100 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48, |
| 131257 | + /* 110 */ 49, 50, 51, 52, 53, 144, 145, 146, 147, 19, |
| 131258 | + /* 120 */ 249, 22, 172, 172, 173, 52, 53, 27, 28, 29, |
| 131259 | + /* 130 */ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, |
| 131260 | + /* 140 */ 40, 41, 81, 43, 44, 45, 46, 47, 48, 49, |
| 131261 | + /* 150 */ 50, 51, 52, 53, 55, 56, 19, 152, 207, 208, |
| 131262 | + /* 160 */ 115, 24, 117, 118, 27, 28, 29, 30, 31, 32, |
| 131263 | + /* 170 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 79, |
| 131264 | + /* 180 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, |
| 131265 | + /* 190 */ 53, 19, 0, 1, 2, 23, 97, 98, 193, 27, |
| 131266 | + /* 200 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, |
| 131267 | + /* 210 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47, |
| 131268 | + /* 220 */ 48, 49, 50, 51, 52, 53, 19, 22, 23, 172, |
| 131269 | + /* 230 */ 23, 26, 119, 120, 27, 28, 29, 30, 31, 32, |
| 131270 | + /* 240 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187, |
| 131271 | + /* 250 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, |
| 131272 | + /* 260 */ 53, 19, 221, 222, 223, 23, 168, 169, 170, 27, |
| 131273 | + /* 270 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, |
| 131274 | + /* 280 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47, |
| 131275 | + /* 290 */ 48, 49, 50, 51, 52, 53, 19, 157, 22, 23, |
| 131276 | + /* 300 */ 23, 96, 26, 172, 27, 28, 29, 30, 31, 32, |
| 131277 | + /* 310 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187, |
| 131278 | + /* 320 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, |
| 131279 | + /* 330 */ 53, 19, 108, 109, 110, 221, 222, 223, 185, 27, |
| 131280 | + /* 340 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, |
| 131281 | + /* 350 */ 38, 39, 40, 41, 240, 43, 44, 45, 46, 47, |
| 131282 | + /* 360 */ 48, 49, 50, 51, 52, 53, 19, 227, 22, 23, |
| 131283 | + /* 370 */ 230, 22, 96, 152, 27, 28, 29, 30, 31, 32, |
| 131284 | + /* 380 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 30, |
| 131285 | + /* 390 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, |
| 131286 | + /* 400 */ 53, 19, 190, 191, 55, 56, 24, 190, 191, 27, |
| 131287 | + /* 410 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, |
| 131288 | + /* 420 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47, |
| 131289 | + /* 430 */ 48, 49, 50, 51, 52, 53, 168, 169, 170, 179, |
| 131290 | + /* 440 */ 180, 171, 96, 19, 172, 173, 97, 98, 188, 179, |
| 131291 | + /* 450 */ 138, 27, 28, 29, 30, 31, 32, 33, 34, 35, |
| 131292 | + /* 460 */ 36, 37, 38, 39, 40, 41, 107, 43, 44, 45, |
| 131293 | + /* 470 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 207, |
| 131294 | + /* 480 */ 208, 30, 31, 32, 33, 138, 27, 28, 29, 30, |
| 131295 | + /* 490 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
| 131296 | + /* 500 */ 41, 181, 43, 44, 45, 46, 47, 48, 49, 50, |
| 131297 | + /* 510 */ 51, 52, 53, 19, 152, 7, 8, 9, 49, 22, |
| 131298 | + /* 520 */ 19, 24, 28, 29, 30, 31, 32, 33, 34, 35, |
| 131299 | + /* 530 */ 36, 37, 38, 39, 40, 41, 152, 43, 44, 45, |
| 131300 | + /* 540 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 108, |
| 131301 | + /* 550 */ 109, 110, 101, 55, 53, 193, 172, 173, 29, 30, |
| 131302 | + /* 560 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, |
| 131303 | + /* 570 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50, |
| 131304 | + /* 580 */ 51, 52, 53, 19, 20, 116, 22, 23, 169, 170, |
| 131305 | + /* 590 */ 121, 207, 85, 55, 56, 97, 19, 20, 195, 22, |
| 131306 | + /* 600 */ 99, 100, 101, 102, 103, 104, 105, 12, 152, 206, |
| 131307 | + /* 610 */ 210, 47, 48, 112, 152, 108, 109, 110, 54, 55, |
| 131308 | + /* 620 */ 56, 221, 222, 223, 47, 48, 119, 120, 172, 173, |
| 131309 | + /* 630 */ 66, 54, 55, 56, 101, 97, 98, 99, 148, 149, |
| 131310 | + /* 640 */ 102, 103, 104, 66, 154, 112, 156, 83, 229, 47, |
| 131311 | + /* 650 */ 48, 113, 57, 163, 194, 195, 92, 246, 247, 95, |
| 131312 | + /* 660 */ 83, 97, 98, 207, 208, 101, 206, 59, 73, 92, |
| 131313 | + /* 670 */ 75, 63, 95, 163, 97, 98, 194, 195, 101, 219, |
| 131314 | + /* 680 */ 85, 181, 19, 152, 175, 77, 196, 152, 206, 19, |
| 131315 | + /* 690 */ 20, 199, 22, 30, 163, 11, 132, 133, 134, 135, |
| 131316 | + /* 700 */ 136, 209, 152, 172, 173, 152, 196, 172, 173, 132, |
| 131317 | + /* 710 */ 133, 134, 135, 136, 164, 92, 213, 47, 48, 49, |
| 131318 | + /* 720 */ 92, 186, 169, 170, 54, 55, 56, 196, 100, 219, |
| 131319 | + /* 730 */ 221, 222, 223, 243, 132, 133, 66, 175, 207, 208, |
| 131320 | + /* 740 */ 152, 231, 119, 120, 19, 20, 236, 22, 152, 38, |
| 131321 | + /* 750 */ 39, 40, 41, 83, 43, 44, 45, 46, 47, 48, |
| 131322 | + /* 760 */ 49, 50, 51, 52, 53, 95, 152, 97, 98, 85, |
| 131323 | + /* 770 */ 107, 101, 47, 48, 163, 112, 92, 152, 152, 54, |
| 131324 | + /* 780 */ 55, 56, 229, 221, 222, 223, 172, 173, 163, 49, |
| 131325 | + /* 790 */ 152, 66, 108, 109, 110, 55, 56, 172, 173, 163, |
| 131326 | + /* 800 */ 186, 22, 132, 133, 134, 135, 136, 196, 83, 43, |
| 131327 | + /* 810 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, |
| 131328 | + /* 820 */ 95, 196, 97, 98, 85, 99, 101, 152, 102, 103, |
| 131329 | + /* 830 */ 104, 92, 196, 146, 147, 152, 181, 97, 98, 113, |
| 131330 | + /* 840 */ 19, 20, 152, 22, 218, 22, 116, 108, 109, 110, |
| 131331 | + /* 850 */ 152, 121, 55, 56, 12, 219, 218, 132, 133, 134, |
| 131332 | + /* 860 */ 135, 136, 172, 173, 55, 56, 55, 56, 47, 48, |
| 131333 | + /* 870 */ 172, 173, 236, 152, 5, 54, 55, 56, 55, 10, |
| 131334 | + /* 880 */ 11, 12, 13, 14, 186, 152, 17, 66, 47, 48, |
| 131335 | + /* 890 */ 152, 210, 16, 84, 97, 98, 55, 56, 21, 57, |
| 131336 | + /* 900 */ 217, 122, 22, 152, 83, 152, 97, 98, 97, 98, |
| 131337 | + /* 910 */ 172, 173, 152, 152, 224, 73, 95, 75, 97, 98, |
| 131338 | + /* 920 */ 97, 124, 101, 172, 173, 164, 193, 47, 48, 60, |
| 131339 | + /* 930 */ 163, 62, 172, 173, 24, 55, 56, 186, 97, 98, |
| 131340 | + /* 940 */ 71, 100, 55, 56, 183, 207, 185, 152, 107, 23, |
| 131341 | + /* 950 */ 109, 82, 26, 132, 133, 134, 135, 136, 89, 152, |
| 131342 | + /* 960 */ 26, 92, 93, 196, 88, 55, 90, 152, 91, 152, |
| 131343 | + /* 970 */ 217, 152, 152, 132, 133, 95, 152, 97, 211, 212, |
| 131344 | + /* 980 */ 103, 101, 152, 114, 97, 98, 152, 172, 173, 19, |
| 131345 | + /* 990 */ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, |
| 131346 | + /* 1000 */ 48, 49, 50, 51, 52, 53, 65, 97, 152, 152, |
| 131347 | + /* 1010 */ 141, 124, 132, 133, 134, 152, 140, 140, 152, 78, |
| 131348 | + /* 1020 */ 152, 233, 152, 193, 98, 152, 56, 86, 172, 173, |
| 131349 | + /* 1030 */ 166, 167, 237, 152, 217, 172, 173, 152, 172, 173, |
| 131350 | + /* 1040 */ 172, 173, 172, 173, 237, 172, 173, 152, 152, 152, |
| 131351 | + /* 1050 */ 124, 152, 111, 172, 173, 152, 237, 172, 173, 152, |
| 131352 | + /* 1060 */ 55, 152, 26, 152, 130, 152, 152, 172, 173, 172, |
| 131353 | + /* 1070 */ 173, 172, 173, 249, 152, 172, 173, 152, 61, 172, |
| 131354 | + /* 1080 */ 173, 172, 173, 172, 173, 172, 173, 70, 152, 193, |
| 131355 | + /* 1090 */ 152, 137, 152, 139, 172, 173, 152, 172, 173, 152, |
| 131356 | + /* 1100 */ 152, 152, 97, 152, 26, 152, 163, 152, 172, 173, |
| 131357 | + /* 1110 */ 172, 173, 172, 173, 152, 16, 172, 173, 26, 172, |
| 131358 | + /* 1120 */ 173, 172, 173, 172, 173, 172, 173, 172, 173, 163, |
| 131359 | + /* 1130 */ 152, 152, 152, 22, 172, 173, 152, 241, 152, 196, |
| 131360 | + /* 1140 */ 152, 193, 106, 152, 152, 152, 163, 152, 37, 152, |
| 131361 | + /* 1150 */ 172, 173, 172, 173, 152, 152, 172, 173, 172, 173, |
| 131362 | + /* 1160 */ 172, 173, 196, 172, 173, 172, 173, 172, 173, 172, |
| 131363 | + /* 1170 */ 173, 152, 152, 152, 172, 173, 98, 152, 152, 196, |
| 131364 | + /* 1180 */ 160, 22, 23, 19, 164, 193, 152, 88, 232, 90, |
| 131365 | + /* 1190 */ 191, 172, 173, 172, 173, 163, 193, 172, 173, 166, |
| 131366 | + /* 1200 */ 167, 163, 124, 163, 244, 245, 23, 211, 212, 26, |
| 131367 | + /* 1210 */ 55, 23, 55, 23, 26, 123, 26, 152, 23, 193, |
| 131368 | + /* 1220 */ 56, 26, 23, 23, 23, 26, 26, 26, 196, 100, |
| 131369 | + /* 1230 */ 101, 7, 8, 152, 196, 23, 196, 23, 26, 152, |
| 131370 | + /* 1240 */ 26, 132, 133, 23, 132, 133, 26, 152, 152, 152, |
| 131371 | + /* 1250 */ 152, 210, 97, 152, 97, 96, 152, 152, 152, 152, |
| 131372 | + /* 1260 */ 152, 210, 152, 210, 197, 152, 152, 152, 152, 152, |
| 131373 | + /* 1270 */ 152, 152, 152, 152, 152, 152, 152, 198, 150, 176, |
| 131374 | + /* 1280 */ 214, 201, 214, 238, 201, 238, 184, 214, 226, 200, |
| 131375 | + /* 1290 */ 155, 198, 67, 122, 242, 159, 159, 69, 239, 239, |
| 131376 | + /* 1300 */ 159, 175, 175, 22, 220, 180, 175, 27, 130, 18, |
| 131377 | + /* 1310 */ 159, 18, 158, 137, 220, 159, 158, 235, 74, 189, |
| 131378 | + /* 1320 */ 234, 159, 159, 158, 22, 192, 192, 177, 159, 159, |
| 131379 | + /* 1330 */ 192, 192, 189, 201, 189, 158, 107, 158, 177, 76, |
| 131380 | + /* 1340 */ 174, 201, 174, 201, 106, 159, 174, 125, 174, 182, |
| 131381 | + /* 1350 */ 177, 176, 107, 159, 174, 137, 174, 53, 174, 129, |
| 131382 | + /* 1360 */ 216, 215, 215, 182, 216, 216, 177, 215, 126, 216, |
| 131383 | + /* 1370 */ 177, 128, 25, 127, 26, 215, 13, 162, 161, 153, |
| 131384 | + /* 1380 */ 153, 6, 151, 151, 151, 151, 165, 178, 165, 178, |
| 131385 | + /* 1390 */ 4, 3, 22, 142, 15, 94, 16, 205, 120, 202, |
| 131386 | + /* 1400 */ 204, 203, 165, 201, 23, 23, 131, 111, 123, 20, |
| 131387 | + /* 1410 */ 225, 125, 16, 1, 131, 228, 111, 123, 56, 228, |
| 131388 | + /* 1420 */ 37, 37, 64, 1, 5, 122, 22, 107, 140, 80, |
| 131389 | + /* 1430 */ 80, 26, 87, 72, 107, 24, 20, 19, 112, 105, |
| 131390 | + /* 1440 */ 23, 68, 22, 79, 79, 22, 22, 22, 58, 22, |
| 131391 | + /* 1450 */ 245, 248, 248, 79, 23, 23, 23, 116, 22, 122, |
| 131392 | + /* 1460 */ 23, 22, 56, 23, 26, 23, 64, 22, 124, 26, |
| 131393 | + /* 1470 */ 26, 64, 64, 23, 23, 23, 11, 23, 22, 26, |
| 131394 | + /* 1480 */ 23, 22, 24, 1, 23, 22, 26, 250, 24, 23, |
| 131395 | + /* 1490 */ 22, 122, 23, 23, 22, 15, 23, 250, 122, 122, |
| 131396 | + /* 1500 */ 122, |
| 131397 | +}; |
| 131398 | +#define YY_SHIFT_USE_DFLT (-95) |
| 130901 | 131399 | #define YY_SHIFT_COUNT (439) |
| 130902 | | -#define YY_SHIFT_MIN (-71) |
| 130903 | | -#define YY_SHIFT_MAX (1497) |
| 131400 | +#define YY_SHIFT_MIN (-94) |
| 131401 | +#define YY_SHIFT_MAX (1482) |
| 130904 | 131402 | static const short yy_shift_ofst[] = { |
| 130905 | | - /* 0 */ 5, 1057, 1355, 1070, 1204, 1204, 1204, 138, -19, 58, |
| 130906 | | - /* 10 */ 58, 186, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 67, |
| 130907 | | - /* 20 */ 67, 90, 132, 336, 76, 135, 263, 340, 417, 494, |
| 130908 | | - /* 30 */ 571, 622, 699, 776, 827, 827, 827, 827, 827, 827, |
| 130909 | | - /* 40 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 878, |
| 130910 | | - /* 50 */ 827, 929, 980, 980, 1156, 1204, 1204, 1204, 1204, 1204, |
| 130911 | | - /* 60 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, |
| 130912 | | - /* 70 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, |
| 130913 | | - /* 80 */ 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204, 1204, |
| 130914 | | - /* 90 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, -71, -47, -47, |
| 130915 | | - /* 100 */ -47, -47, -47, -6, 88, -66, 23, 458, 505, 468, |
| 130916 | | - /* 110 */ 468, 23, 201, 343, -58, -72, -72, -72, 11, 11, |
| 130917 | | - /* 120 */ 11, 412, 412, 341, 537, 605, 23, 23, 23, 23, |
| 130918 | | - /* 130 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, |
| 130919 | | - /* 140 */ 23, 23, 23, 23, 23, 23, 635, 298, 74, 74, |
| 130920 | | - /* 150 */ 343, -1, -1, -1, -1, -1, -1, -72, -72, -72, |
| 130921 | | - /* 160 */ 228, 101, 101, 203, 75, 71, 273, 284, 345, 23, |
| 130922 | | - /* 170 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, |
| 130923 | | - /* 180 */ 23, 23, 23, 23, 23, 23, 421, 421, 421, 23, |
| 130924 | | - /* 190 */ 23, 582, 23, 23, 23, 356, 23, 23, 585, 23, |
| 130925 | | - /* 200 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 568, |
| 130926 | | - /* 210 */ 575, 456, 456, 456, 704, 171, 645, 674, 858, 590, |
| 130927 | | - /* 220 */ 590, 914, 858, 914, 370, 963, 886, 948, 590, 425, |
| 130928 | | - /* 230 */ 948, 948, 864, 641, 527, 1196, 1115, 1115, 1197, 1197, |
| 130929 | | - /* 240 */ 1115, 1221, 1179, 1125, 1240, 1240, 1240, 1240, 1115, 1244, |
| 130930 | | - /* 250 */ 1125, 1221, 1179, 1179, 1125, 1115, 1244, 1137, 1233, 1115, |
| 130931 | | - /* 260 */ 1115, 1244, 1265, 1115, 1244, 1115, 1244, 1265, 1199, 1199, |
| 130932 | | - /* 270 */ 1199, 1262, 1265, 1199, 1206, 1199, 1262, 1199, 1199, 1192, |
| 130933 | | - /* 280 */ 1216, 1192, 1216, 1192, 1216, 1192, 1216, 1115, 1115, 1195, |
| 130934 | | - /* 290 */ 1265, 1246, 1246, 1265, 1214, 1218, 1223, 1219, 1125, 1332, |
| 130935 | | - /* 300 */ 1338, 1358, 1358, 1368, 1368, 1368, 1368, -72, -72, -72, |
| 130936 | | - /* 310 */ -72, -72, -72, -72, -72, 400, 623, 742, 816, 658, |
| 130937 | | - /* 320 */ 697, 227, 1012, 664, 1013, 1014, 1018, 1026, 1051, 891, |
| 130938 | | - /* 330 */ 1021, 1040, 1068, 1084, 1066, 1139, 910, 954, 1154, 1088, |
| 130939 | | - /* 340 */ 978, 1380, 1382, 1364, 1255, 1373, 1333, 1386, 1381, 1383, |
| 130940 | | - /* 350 */ 1283, 1274, 1296, 1285, 1389, 1287, 1394, 1412, 1291, 1284, |
| 130941 | | - /* 360 */ 1337, 1340, 1306, 1392, 1387, 1302, 1424, 1421, 1405, 1321, |
| 130942 | | - /* 370 */ 1289, 1376, 1406, 1377, 1372, 1390, 1328, 1413, 1416, 1419, |
| 130943 | | - /* 380 */ 1327, 1335, 1420, 1388, 1422, 1423, 1425, 1427, 1393, 1417, |
| 130944 | | - /* 390 */ 1428, 1398, 1403, 1429, 1430, 1431, 1339, 1434, 1435, 1437, |
| 130945 | | - /* 400 */ 1436, 1341, 1438, 1441, 1432, 1439, 1443, 1342, 1442, 1440, |
| 130946 | | - /* 410 */ 1444, 1445, 1442, 1448, 1449, 1450, 1451, 1455, 1452, 1446, |
| 130947 | | - /* 420 */ 1456, 1458, 1459, 1460, 1461, 1463, 1464, 1460, 1466, 1465, |
| 130948 | | - /* 430 */ 1467, 1469, 1471, 1345, 1360, 1369, 1375, 1472, 1479, 1497, |
| 131403 | + /* 0 */ 40, 564, 869, 577, 725, 725, 725, 739, -19, 16, |
| 131404 | + /* 10 */ 16, 100, 725, 725, 725, 725, 725, 725, 725, 841, |
| 131405 | + /* 20 */ 841, 538, 507, 684, 623, 61, 137, 172, 207, 242, |
| 131406 | + /* 30 */ 277, 312, 347, 382, 424, 424, 424, 424, 424, 424, |
| 131407 | + /* 40 */ 424, 424, 424, 424, 424, 424, 424, 424, 424, 459, |
| 131408 | + /* 50 */ 424, 494, 529, 529, 670, 725, 725, 725, 725, 725, |
| 131409 | + /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725, |
| 131410 | + /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725, |
| 131411 | + /* 80 */ 725, 725, 725, 821, 725, 725, 725, 725, 725, 725, |
| 131412 | + /* 90 */ 725, 725, 725, 725, 725, 725, 725, 952, 711, 711, |
| 131413 | + /* 100 */ 711, 711, 711, 766, 23, 32, 811, 877, 663, 602, |
| 131414 | + /* 110 */ 602, 811, 73, 113, -51, -95, -95, -95, 501, 501, |
| 131415 | + /* 120 */ 501, 595, 595, 809, 205, 276, 811, 811, 811, 811, |
| 131416 | + /* 130 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811, |
| 131417 | + /* 140 */ 811, 811, 811, 811, 811, 811, 192, 628, 498, 498, |
| 131418 | + /* 150 */ 113, -34, -34, -34, -34, -34, -34, -95, -95, -95, |
| 131419 | + /* 160 */ 880, -94, -94, 726, 740, 99, 797, 887, 349, 811, |
| 131420 | + /* 170 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811, |
| 131421 | + /* 180 */ 811, 811, 811, 811, 811, 811, 941, 941, 941, 811, |
| 131422 | + /* 190 */ 811, 926, 811, 811, 811, -18, 811, 811, 842, 811, |
| 131423 | + /* 200 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 224, |
| 131424 | + /* 210 */ 608, 910, 910, 910, 1078, 45, 469, 508, 934, 970, |
| 131425 | + /* 220 */ 970, 1164, 934, 1164, 1036, 1183, 359, 1017, 970, 954, |
| 131426 | + /* 230 */ 1017, 1017, 1092, 730, 497, 1225, 1171, 1171, 1228, 1228, |
| 131427 | + /* 240 */ 1171, 1281, 1280, 1178, 1291, 1291, 1291, 1291, 1171, 1293, |
| 131428 | + /* 250 */ 1178, 1281, 1280, 1280, 1178, 1171, 1293, 1176, 1244, 1171, |
| 131429 | + /* 260 */ 1171, 1293, 1302, 1171, 1293, 1171, 1293, 1302, 1229, 1229, |
| 131430 | + /* 270 */ 1229, 1263, 1302, 1229, 1238, 1229, 1263, 1229, 1229, 1222, |
| 131431 | + /* 280 */ 1245, 1222, 1245, 1222, 1245, 1222, 1245, 1171, 1171, 1218, |
| 131432 | + /* 290 */ 1302, 1304, 1304, 1302, 1230, 1242, 1243, 1246, 1178, 1347, |
| 131433 | + /* 300 */ 1348, 1363, 1363, 1375, 1375, 1375, 1375, -95, -95, -95, |
| 131434 | + /* 310 */ -95, -95, -95, -95, -95, 451, 876, 346, 1159, 1099, |
| 131435 | + /* 320 */ 441, 823, 1188, 1111, 1190, 1195, 1199, 1200, 1005, 1129, |
| 131436 | + /* 330 */ 1224, 533, 1201, 1212, 1155, 1214, 1109, 1112, 1220, 1157, |
| 131437 | + /* 340 */ 779, 1386, 1388, 1370, 1251, 1379, 1301, 1380, 1381, 1382, |
| 131438 | + /* 350 */ 1278, 1275, 1296, 1285, 1389, 1286, 1396, 1412, 1294, 1283, |
| 131439 | + /* 360 */ 1383, 1384, 1305, 1362, 1358, 1303, 1422, 1419, 1404, 1320, |
| 131440 | + /* 370 */ 1288, 1349, 1405, 1350, 1345, 1361, 1327, 1411, 1416, 1418, |
| 131441 | + /* 380 */ 1326, 1334, 1420, 1364, 1423, 1424, 1417, 1425, 1365, 1390, |
| 131442 | + /* 390 */ 1427, 1374, 1373, 1431, 1432, 1433, 1341, 1436, 1437, 1439, |
| 131443 | + /* 400 */ 1438, 1337, 1440, 1442, 1406, 1402, 1445, 1344, 1443, 1407, |
| 131444 | + /* 410 */ 1444, 1408, 1443, 1450, 1451, 1452, 1453, 1454, 1456, 1465, |
| 131445 | + /* 420 */ 1457, 1459, 1458, 1460, 1461, 1463, 1464, 1460, 1466, 1468, |
| 131446 | + /* 430 */ 1469, 1470, 1472, 1369, 1376, 1377, 1378, 1473, 1480, 1482, |
| 130949 | 131447 | }; |
| 130950 | | -#define YY_REDUCE_USE_DFLT (-144) |
| 131448 | +#define YY_REDUCE_USE_DFLT (-130) |
| 130951 | 131449 | #define YY_REDUCE_COUNT (314) |
| 130952 | | -#define YY_REDUCE_MIN (-143) |
| 130953 | | -#define YY_REDUCE_MAX (1231) |
| 131450 | +#define YY_REDUCE_MIN (-129) |
| 131451 | +#define YY_REDUCE_MAX (1237) |
| 130954 | 131452 | static const short yy_reduce_ofst[] = { |
| 130955 | | - /* 0 */ -143, 949, 136, 131, -48, -45, 158, 241, 22, 153, |
| 130956 | | - /* 10 */ 226, 163, 362, 364, 366, 312, 314, 368, 237, 236, |
| 130957 | | - /* 20 */ 300, 440, 114, 359, 319, 100, 100, 100, 100, 100, |
| 130958 | | - /* 30 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, |
| 130959 | | - /* 40 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, |
| 130960 | | - /* 50 */ 100, 100, 100, 100, 374, 447, 461, 516, 518, 567, |
| 130961 | | - /* 60 */ 569, 572, 574, 579, 581, 583, 586, 596, 631, 644, |
| 130962 | | - /* 70 */ 646, 649, 657, 659, 661, 663, 671, 708, 720, 722, |
| 130963 | | - /* 80 */ 759, 771, 773, 810, 822, 824, 861, 873, 875, 930, |
| 130964 | | - /* 90 */ 944, 947, 952, 957, 959, 961, 997, 100, 100, 100, |
| 130965 | | - /* 100 */ 100, 100, 100, 100, 100, 100, 486, -108, -83, 224, |
| 130966 | | - /* 110 */ 286, 451, 100, 681, 100, 100, 100, 100, 354, 354, |
| 130967 | | - /* 120 */ 354, 337, 352, 49, 482, 482, 503, 532, -60, 615, |
| 130968 | | - /* 130 */ 647, 689, 690, 737, 782, -62, 517, 789, 474, 795, |
| 130969 | | - /* 140 */ 580, 733, 32, 662, 488, 139, 678, 433, 769, 772, |
| 130970 | | - /* 150 */ 396, 728, 887, 942, 955, 965, 977, 740, 766, 178, |
| 130971 | | - /* 160 */ -46, -17, 59, 53, 118, 141, 167, 248, 255, 326, |
| 130972 | | - /* 170 */ 441, 464, 519, 668, 693, 721, 736, 744, 775, 788, |
| 130973 | | - /* 180 */ 846, 899, 912, 936, 983, 985, 72, 134, 542, 990, |
| 130974 | | - /* 190 */ 991, 597, 992, 998, 1020, 871, 1022, 1027, 915, 1029, |
| 130975 | | - /* 200 */ 1030, 1034, 118, 1035, 1036, 1043, 1044, 1045, 1046, 931, |
| 130976 | | - /* 210 */ 967, 999, 1000, 1001, 597, 1003, 1009, 1058, 1011, 987, |
| 130977 | | - /* 220 */ 1002, 976, 1016, 981, 1039, 1037, 1038, 1047, 1006, 1004, |
| 130978 | | - /* 230 */ 1052, 1053, 1033, 1031, 1079, 994, 1080, 1081, 1005, 1010, |
| 130979 | | - /* 240 */ 1082, 1028, 1062, 1055, 1067, 1071, 1072, 1073, 1101, 1108, |
| 130980 | | - /* 250 */ 1069, 1048, 1078, 1083, 1074, 1110, 1113, 1041, 1049, 1122, |
| 130981 | | - /* 260 */ 1123, 1126, 1118, 1138, 1140, 1144, 1141, 1127, 1133, 1134, |
| 130982 | | - /* 270 */ 1135, 1129, 1136, 1142, 1143, 1146, 1132, 1147, 1148, 1102, |
| 130983 | | - /* 280 */ 1109, 1112, 1111, 1114, 1116, 1117, 1119, 1166, 1170, 1120, |
| 130984 | | - /* 290 */ 1158, 1121, 1124, 1165, 1145, 1149, 1155, 1159, 1161, 1201, |
| 130985 | | - /* 300 */ 1209, 1220, 1222, 1225, 1226, 1227, 1228, 1151, 1152, 1150, |
| 130986 | | - /* 310 */ 1215, 1217, 1203, 1205, 1231, |
| 131453 | + /* 0 */ -29, 531, 490, 625, -49, 272, 456, 510, 400, 509, |
| 131454 | + /* 10 */ 562, 114, 535, 614, 698, 384, 738, 751, 690, 419, |
| 131455 | + /* 20 */ 553, 761, 460, 636, 767, 41, 41, 41, 41, 41, |
| 131456 | + /* 30 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, |
| 131457 | + /* 40 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, |
| 131458 | + /* 50 */ 41, 41, 41, 41, 760, 815, 856, 863, 866, 868, |
| 131459 | + /* 60 */ 870, 873, 881, 885, 895, 897, 899, 903, 907, 909, |
| 131460 | + /* 70 */ 911, 913, 922, 925, 936, 938, 940, 944, 947, 949, |
| 131461 | + /* 80 */ 951, 953, 955, 962, 978, 980, 984, 986, 988, 991, |
| 131462 | + /* 90 */ 993, 995, 997, 1002, 1019, 1021, 1025, 41, 41, 41, |
| 131463 | + /* 100 */ 41, 41, 41, 41, 41, 41, 896, 140, 260, 98, |
| 131464 | + /* 110 */ 268, 1020, 41, 482, 41, 41, 41, 41, 270, 270, |
| 131465 | + /* 120 */ 270, 212, 217, -129, 411, 411, 550, 5, 626, 362, |
| 131466 | + /* 130 */ 733, 830, 992, 1003, 1026, 795, 683, 807, 638, 819, |
| 131467 | + /* 140 */ 753, 948, 62, 817, 824, 132, 687, 611, 864, 1033, |
| 131468 | + /* 150 */ 403, 943, 966, 983, 1032, 1038, 1040, 960, 996, 492, |
| 131469 | + /* 160 */ -50, 57, 131, 153, 221, 462, 588, 596, 675, 721, |
| 131470 | + /* 170 */ 820, 834, 857, 914, 979, 1034, 1065, 1081, 1087, 1095, |
| 131471 | + /* 180 */ 1096, 1097, 1098, 1101, 1104, 1105, 320, 500, 655, 1106, |
| 131472 | + /* 190 */ 1107, 503, 1108, 1110, 1113, 681, 1114, 1115, 999, 1116, |
| 131473 | + /* 200 */ 1117, 1118, 221, 1119, 1120, 1121, 1122, 1123, 1124, 788, |
| 131474 | + /* 210 */ 956, 1041, 1051, 1053, 503, 1067, 1079, 1128, 1080, 1066, |
| 131475 | + /* 220 */ 1068, 1045, 1083, 1047, 1103, 1102, 1125, 1126, 1073, 1062, |
| 131476 | + /* 230 */ 1127, 1131, 1089, 1093, 1135, 1052, 1136, 1137, 1059, 1060, |
| 131477 | + /* 240 */ 1141, 1084, 1130, 1132, 1133, 1134, 1138, 1139, 1151, 1154, |
| 131478 | + /* 250 */ 1140, 1094, 1143, 1145, 1142, 1156, 1158, 1082, 1086, 1162, |
| 131479 | + /* 260 */ 1163, 1165, 1150, 1169, 1177, 1170, 1179, 1161, 1166, 1168, |
| 131480 | + /* 270 */ 1172, 1167, 1173, 1174, 1175, 1180, 1181, 1182, 1184, 1144, |
| 131481 | + /* 280 */ 1146, 1148, 1147, 1149, 1152, 1153, 1160, 1186, 1194, 1185, |
| 131482 | + /* 290 */ 1189, 1187, 1191, 1193, 1192, 1196, 1198, 1197, 1202, 1215, |
| 131483 | + /* 300 */ 1217, 1226, 1227, 1231, 1232, 1233, 1234, 1203, 1204, 1205, |
| 131484 | + /* 310 */ 1221, 1223, 1209, 1211, 1237, |
| 130987 | 131485 | }; |
| 130988 | 131486 | static const YYACTIONTYPE yy_default[] = { |
| 130989 | 131487 | /* 0 */ 1250, 1240, 1240, 1240, 1174, 1174, 1174, 1240, 1071, 1100, |
| 130990 | 131488 | /* 10 */ 1100, 1224, 1301, 1301, 1301, 1301, 1301, 1301, 1173, 1301, |
| 130991 | 131489 | /* 20 */ 1301, 1301, 1301, 1240, 1075, 1106, 1301, 1301, 1301, 1301, |
| | @@ -131049,78 +131547,104 @@ |
| 131049 | 131547 | */ |
| 131050 | 131548 | #ifdef YYFALLBACK |
| 131051 | 131549 | static const YYCODETYPE yyFallback[] = { |
| 131052 | 131550 | 0, /* $ => nothing */ |
| 131053 | 131551 | 0, /* SEMI => nothing */ |
| 131054 | | - 27, /* EXPLAIN => ID */ |
| 131055 | | - 27, /* QUERY => ID */ |
| 131056 | | - 27, /* PLAN => ID */ |
| 131057 | | - 27, /* BEGIN => ID */ |
| 131552 | + 55, /* EXPLAIN => ID */ |
| 131553 | + 55, /* QUERY => ID */ |
| 131554 | + 55, /* PLAN => ID */ |
| 131555 | + 55, /* BEGIN => ID */ |
| 131058 | 131556 | 0, /* TRANSACTION => nothing */ |
| 131059 | | - 27, /* DEFERRED => ID */ |
| 131060 | | - 27, /* IMMEDIATE => ID */ |
| 131061 | | - 27, /* EXCLUSIVE => ID */ |
| 131557 | + 55, /* DEFERRED => ID */ |
| 131558 | + 55, /* IMMEDIATE => ID */ |
| 131559 | + 55, /* EXCLUSIVE => ID */ |
| 131062 | 131560 | 0, /* COMMIT => nothing */ |
| 131063 | | - 27, /* END => ID */ |
| 131064 | | - 27, /* ROLLBACK => ID */ |
| 131065 | | - 27, /* SAVEPOINT => ID */ |
| 131066 | | - 27, /* RELEASE => ID */ |
| 131561 | + 55, /* END => ID */ |
| 131562 | + 55, /* ROLLBACK => ID */ |
| 131563 | + 55, /* SAVEPOINT => ID */ |
| 131564 | + 55, /* RELEASE => ID */ |
| 131067 | 131565 | 0, /* TO => nothing */ |
| 131068 | 131566 | 0, /* TABLE => nothing */ |
| 131069 | 131567 | 0, /* CREATE => nothing */ |
| 131070 | | - 27, /* IF => ID */ |
| 131568 | + 55, /* IF => ID */ |
| 131071 | 131569 | 0, /* NOT => nothing */ |
| 131072 | 131570 | 0, /* EXISTS => nothing */ |
| 131073 | | - 27, /* TEMP => ID */ |
| 131571 | + 55, /* TEMP => ID */ |
| 131074 | 131572 | 0, /* LP => nothing */ |
| 131075 | 131573 | 0, /* RP => nothing */ |
| 131076 | 131574 | 0, /* AS => nothing */ |
| 131077 | | - 27, /* WITHOUT => ID */ |
| 131575 | + 55, /* WITHOUT => ID */ |
| 131078 | 131576 | 0, /* COMMA => nothing */ |
| 131577 | + 0, /* OR => nothing */ |
| 131578 | + 0, /* AND => nothing */ |
| 131579 | + 0, /* IS => nothing */ |
| 131580 | + 55, /* MATCH => ID */ |
| 131581 | + 55, /* LIKE_KW => ID */ |
| 131582 | + 0, /* BETWEEN => nothing */ |
| 131583 | + 0, /* IN => nothing */ |
| 131584 | + 0, /* ISNULL => nothing */ |
| 131585 | + 0, /* NOTNULL => nothing */ |
| 131586 | + 0, /* NE => nothing */ |
| 131587 | + 0, /* EQ => nothing */ |
| 131588 | + 0, /* GT => nothing */ |
| 131589 | + 0, /* LE => nothing */ |
| 131590 | + 0, /* LT => nothing */ |
| 131591 | + 0, /* GE => nothing */ |
| 131592 | + 0, /* ESCAPE => nothing */ |
| 131593 | + 0, /* BITAND => nothing */ |
| 131594 | + 0, /* BITOR => nothing */ |
| 131595 | + 0, /* LSHIFT => nothing */ |
| 131596 | + 0, /* RSHIFT => nothing */ |
| 131597 | + 0, /* PLUS => nothing */ |
| 131598 | + 0, /* MINUS => nothing */ |
| 131599 | + 0, /* STAR => nothing */ |
| 131600 | + 0, /* SLASH => nothing */ |
| 131601 | + 0, /* REM => nothing */ |
| 131602 | + 0, /* CONCAT => nothing */ |
| 131603 | + 0, /* COLLATE => nothing */ |
| 131604 | + 0, /* BITNOT => nothing */ |
| 131079 | 131605 | 0, /* ID => nothing */ |
| 131080 | 131606 | 0, /* INDEXED => nothing */ |
| 131081 | | - 27, /* ABORT => ID */ |
| 131082 | | - 27, /* ACTION => ID */ |
| 131083 | | - 27, /* AFTER => ID */ |
| 131084 | | - 27, /* ANALYZE => ID */ |
| 131085 | | - 27, /* ASC => ID */ |
| 131086 | | - 27, /* ATTACH => ID */ |
| 131087 | | - 27, /* BEFORE => ID */ |
| 131088 | | - 27, /* BY => ID */ |
| 131089 | | - 27, /* CASCADE => ID */ |
| 131090 | | - 27, /* CAST => ID */ |
| 131091 | | - 27, /* COLUMNKW => ID */ |
| 131092 | | - 27, /* CONFLICT => ID */ |
| 131093 | | - 27, /* DATABASE => ID */ |
| 131094 | | - 27, /* DESC => ID */ |
| 131095 | | - 27, /* DETACH => ID */ |
| 131096 | | - 27, /* EACH => ID */ |
| 131097 | | - 27, /* FAIL => ID */ |
| 131098 | | - 27, /* FOR => ID */ |
| 131099 | | - 27, /* IGNORE => ID */ |
| 131100 | | - 27, /* INITIALLY => ID */ |
| 131101 | | - 27, /* INSTEAD => ID */ |
| 131102 | | - 27, /* LIKE_KW => ID */ |
| 131103 | | - 27, /* MATCH => ID */ |
| 131104 | | - 27, /* NO => ID */ |
| 131105 | | - 27, /* KEY => ID */ |
| 131106 | | - 27, /* OF => ID */ |
| 131107 | | - 27, /* OFFSET => ID */ |
| 131108 | | - 27, /* PRAGMA => ID */ |
| 131109 | | - 27, /* RAISE => ID */ |
| 131110 | | - 27, /* RECURSIVE => ID */ |
| 131111 | | - 27, /* REPLACE => ID */ |
| 131112 | | - 27, /* RESTRICT => ID */ |
| 131113 | | - 27, /* ROW => ID */ |
| 131114 | | - 27, /* TRIGGER => ID */ |
| 131115 | | - 27, /* VACUUM => ID */ |
| 131116 | | - 27, /* VIEW => ID */ |
| 131117 | | - 27, /* VIRTUAL => ID */ |
| 131118 | | - 27, /* WITH => ID */ |
| 131119 | | - 27, /* REINDEX => ID */ |
| 131120 | | - 27, /* RENAME => ID */ |
| 131121 | | - 27, /* CTIME_KW => ID */ |
| 131607 | + 55, /* ABORT => ID */ |
| 131608 | + 55, /* ACTION => ID */ |
| 131609 | + 55, /* AFTER => ID */ |
| 131610 | + 55, /* ANALYZE => ID */ |
| 131611 | + 55, /* ASC => ID */ |
| 131612 | + 55, /* ATTACH => ID */ |
| 131613 | + 55, /* BEFORE => ID */ |
| 131614 | + 55, /* BY => ID */ |
| 131615 | + 55, /* CASCADE => ID */ |
| 131616 | + 55, /* CAST => ID */ |
| 131617 | + 55, /* COLUMNKW => ID */ |
| 131618 | + 55, /* CONFLICT => ID */ |
| 131619 | + 55, /* DATABASE => ID */ |
| 131620 | + 55, /* DESC => ID */ |
| 131621 | + 55, /* DETACH => ID */ |
| 131622 | + 55, /* EACH => ID */ |
| 131623 | + 55, /* FAIL => ID */ |
| 131624 | + 55, /* FOR => ID */ |
| 131625 | + 55, /* IGNORE => ID */ |
| 131626 | + 55, /* INITIALLY => ID */ |
| 131627 | + 55, /* INSTEAD => ID */ |
| 131628 | + 55, /* NO => ID */ |
| 131629 | + 55, /* KEY => ID */ |
| 131630 | + 55, /* OF => ID */ |
| 131631 | + 55, /* OFFSET => ID */ |
| 131632 | + 55, /* PRAGMA => ID */ |
| 131633 | + 55, /* RAISE => ID */ |
| 131634 | + 55, /* RECURSIVE => ID */ |
| 131635 | + 55, /* REPLACE => ID */ |
| 131636 | + 55, /* RESTRICT => ID */ |
| 131637 | + 55, /* ROW => ID */ |
| 131638 | + 55, /* TRIGGER => ID */ |
| 131639 | + 55, /* VACUUM => ID */ |
| 131640 | + 55, /* VIEW => ID */ |
| 131641 | + 55, /* VIRTUAL => ID */ |
| 131642 | + 55, /* WITH => ID */ |
| 131643 | + 55, /* REINDEX => ID */ |
| 131644 | + 55, /* RENAME => ID */ |
| 131645 | + 55, /* CTIME_KW => ID */ |
| 131122 | 131646 | }; |
| 131123 | 131647 | #endif /* YYFALLBACK */ |
| 131124 | 131648 | |
| 131125 | 131649 | /* The following structure represents a single element of the |
| 131126 | 131650 | ** parser's stack. Information stored includes: |
| | @@ -131207,29 +131731,29 @@ |
| 131207 | 131731 | "PLAN", "BEGIN", "TRANSACTION", "DEFERRED", |
| 131208 | 131732 | "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END", |
| 131209 | 131733 | "ROLLBACK", "SAVEPOINT", "RELEASE", "TO", |
| 131210 | 131734 | "TABLE", "CREATE", "IF", "NOT", |
| 131211 | 131735 | "EXISTS", "TEMP", "LP", "RP", |
| 131212 | | - "AS", "WITHOUT", "COMMA", "ID", |
| 131736 | + "AS", "WITHOUT", "COMMA", "OR", |
| 131737 | + "AND", "IS", "MATCH", "LIKE_KW", |
| 131738 | + "BETWEEN", "IN", "ISNULL", "NOTNULL", |
| 131739 | + "NE", "EQ", "GT", "LE", |
| 131740 | + "LT", "GE", "ESCAPE", "BITAND", |
| 131741 | + "BITOR", "LSHIFT", "RSHIFT", "PLUS", |
| 131742 | + "MINUS", "STAR", "SLASH", "REM", |
| 131743 | + "CONCAT", "COLLATE", "BITNOT", "ID", |
| 131213 | 131744 | "INDEXED", "ABORT", "ACTION", "AFTER", |
| 131214 | 131745 | "ANALYZE", "ASC", "ATTACH", "BEFORE", |
| 131215 | 131746 | "BY", "CASCADE", "CAST", "COLUMNKW", |
| 131216 | 131747 | "CONFLICT", "DATABASE", "DESC", "DETACH", |
| 131217 | 131748 | "EACH", "FAIL", "FOR", "IGNORE", |
| 131218 | | - "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH", |
| 131219 | | - "NO", "KEY", "OF", "OFFSET", |
| 131220 | | - "PRAGMA", "RAISE", "RECURSIVE", "REPLACE", |
| 131221 | | - "RESTRICT", "ROW", "TRIGGER", "VACUUM", |
| 131222 | | - "VIEW", "VIRTUAL", "WITH", "REINDEX", |
| 131223 | | - "RENAME", "CTIME_KW", "ANY", "OR", |
| 131224 | | - "AND", "IS", "BETWEEN", "IN", |
| 131225 | | - "ISNULL", "NOTNULL", "NE", "EQ", |
| 131226 | | - "GT", "LE", "LT", "GE", |
| 131227 | | - "ESCAPE", "BITAND", "BITOR", "LSHIFT", |
| 131228 | | - "RSHIFT", "PLUS", "MINUS", "STAR", |
| 131229 | | - "SLASH", "REM", "CONCAT", "COLLATE", |
| 131230 | | - "BITNOT", "STRING", "JOIN_KW", "CONSTRAINT", |
| 131749 | + "INITIALLY", "INSTEAD", "NO", "KEY", |
| 131750 | + "OF", "OFFSET", "PRAGMA", "RAISE", |
| 131751 | + "RECURSIVE", "REPLACE", "RESTRICT", "ROW", |
| 131752 | + "TRIGGER", "VACUUM", "VIEW", "VIRTUAL", |
| 131753 | + "WITH", "REINDEX", "RENAME", "CTIME_KW", |
| 131754 | + "ANY", "STRING", "JOIN_KW", "CONSTRAINT", |
| 131231 | 131755 | "DEFAULT", "NULL", "PRIMARY", "UNIQUE", |
| 131232 | 131756 | "CHECK", "REFERENCES", "AUTOINCR", "ON", |
| 131233 | 131757 | "INSERT", "DELETE", "UPDATE", "SET", |
| 131234 | 131758 | "DEFERRABLE", "FOREIGN", "DROP", "UNION", |
| 131235 | 131759 | "ALL", "EXCEPT", "INTERSECT", "SELECT", |
| | @@ -133005,26 +133529,27 @@ |
| 133005 | 133529 | yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0); |
| 133006 | 133530 | } |
| 133007 | 133531 | break; |
| 133008 | 133532 | case 156: /* expr ::= VARIABLE */ |
| 133009 | 133533 | { |
| 133010 | | - Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/ |
| 133011 | | - if( t.n>=2 && t.z[0]=='#' && sqlite3Isdigit(t.z[1]) ){ |
| 133534 | + if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){ |
| 133535 | + spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, yymsp[0].minor.yy0); |
| 133536 | + sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr); |
| 133537 | + }else{ |
| 133012 | 133538 | /* When doing a nested parse, one can include terms in an expression |
| 133013 | 133539 | ** that look like this: #1 #2 ... These terms refer to registers |
| 133014 | 133540 | ** in the virtual machine. #N is the N-th register. */ |
| 133541 | + Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/ |
| 133542 | + assert( t.n>=2 ); |
| 133015 | 133543 | spanSet(&yymsp[0].minor.yy342, &t, &t); |
| 133016 | 133544 | if( pParse->nested==0 ){ |
| 133017 | 133545 | sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t); |
| 133018 | 133546 | yymsp[0].minor.yy342.pExpr = 0; |
| 133019 | 133547 | }else{ |
| 133020 | 133548 | yymsp[0].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &t); |
| 133021 | 133549 | if( yymsp[0].minor.yy342.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy342.pExpr->iTable); |
| 133022 | 133550 | } |
| 133023 | | - }else{ |
| 133024 | | - spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, t); |
| 133025 | | - sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr); |
| 133026 | 133551 | } |
| 133027 | 133552 | } |
| 133028 | 133553 | break; |
| 133029 | 133554 | case 157: /* expr ::= expr COLLATE ID|STRING */ |
| 133030 | 133555 | { |
| | @@ -133205,60 +133730,37 @@ |
| 133205 | 133730 | break; |
| 133206 | 133731 | case 188: /* expr ::= LP select RP */ |
| 133207 | 133732 | { |
| 133208 | 133733 | spanSet(&yymsp[-2].minor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ |
| 133209 | 133734 | yymsp[-2].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0); |
| 133210 | | - if( yymsp[-2].minor.yy342.pExpr ){ |
| 133211 | | - yymsp[-2].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159; |
| 133212 | | - ExprSetProperty(yymsp[-2].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery); |
| 133213 | | - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-2].minor.yy342.pExpr); |
| 133214 | | - }else{ |
| 133215 | | - sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159); |
| 133216 | | - } |
| 133735 | + sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy342.pExpr, yymsp[-1].minor.yy159); |
| 133217 | 133736 | } |
| 133218 | 133737 | break; |
| 133219 | 133738 | case 189: /* expr ::= expr in_op LP select RP */ |
| 133220 | 133739 | { |
| 133221 | 133740 | yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0); |
| 133222 | | - if( yymsp[-4].minor.yy342.pExpr ){ |
| 133223 | | - yymsp[-4].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159; |
| 133224 | | - ExprSetProperty(yymsp[-4].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery); |
| 133225 | | - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy342.pExpr); |
| 133226 | | - }else{ |
| 133227 | | - sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159); |
| 133228 | | - } |
| 133741 | + sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy342.pExpr, yymsp[-1].minor.yy159); |
| 133229 | 133742 | exprNot(pParse, yymsp[-3].minor.yy392, &yymsp[-4].minor.yy342); |
| 133230 | 133743 | yymsp[-4].minor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 133231 | 133744 | } |
| 133232 | 133745 | break; |
| 133233 | 133746 | case 190: /* expr ::= expr in_op nm dbnm */ |
| 133234 | 133747 | { |
| 133235 | 133748 | SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0); |
| 133749 | + Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); |
| 133236 | 133750 | yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0); |
| 133237 | | - if( yymsp[-3].minor.yy342.pExpr ){ |
| 133238 | | - yymsp[-3].minor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); |
| 133239 | | - ExprSetProperty(yymsp[-3].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery); |
| 133240 | | - sqlite3ExprSetHeightAndFlags(pParse, yymsp[-3].minor.yy342.pExpr); |
| 133241 | | - }else{ |
| 133242 | | - sqlite3SrcListDelete(pParse->db, pSrc); |
| 133243 | | - } |
| 133751 | + sqlite3PExprAddSelect(pParse, yymsp[-3].minor.yy342.pExpr, pSelect); |
| 133244 | 133752 | exprNot(pParse, yymsp[-2].minor.yy392, &yymsp[-3].minor.yy342); |
| 133245 | 133753 | yymsp[-3].minor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n]; |
| 133246 | 133754 | } |
| 133247 | 133755 | break; |
| 133248 | 133756 | case 191: /* expr ::= EXISTS LP select RP */ |
| 133249 | 133757 | { |
| 133250 | 133758 | Expr *p; |
| 133251 | 133759 | spanSet(&yymsp[-3].minor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ |
| 133252 | 133760 | p = yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0); |
| 133253 | | - if( p ){ |
| 133254 | | - p->x.pSelect = yymsp[-1].minor.yy159; |
| 133255 | | - ExprSetProperty(p, EP_xIsSelect|EP_Subquery); |
| 133256 | | - sqlite3ExprSetHeightAndFlags(pParse, p); |
| 133257 | | - }else{ |
| 133258 | | - sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159); |
| 133259 | | - } |
| 133761 | + sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy159); |
| 133260 | 133762 | } |
| 133261 | 133763 | break; |
| 133262 | 133764 | case 192: /* expr ::= CASE case_operand case_exprlist case_else END */ |
| 133263 | 133765 | { |
| 133264 | 133766 | spanSet(&yymsp[-4].minor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/ |
| | @@ -134739,11 +135241,11 @@ |
| 134739 | 135241 | ** will take responsibility for freeing the Table structure. |
| 134740 | 135242 | */ |
| 134741 | 135243 | sqlite3DeleteTable(db, pParse->pNewTable); |
| 134742 | 135244 | } |
| 134743 | 135245 | |
| 134744 | | - sqlite3WithDelete(db, pParse->pWithToFree); |
| 135246 | + if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree); |
| 134745 | 135247 | sqlite3DeleteTrigger(db, pParse->pNewTrigger); |
| 134746 | 135248 | for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]); |
| 134747 | 135249 | sqlite3DbFree(db, pParse->azVar); |
| 134748 | 135250 | while( pParse->pAinc ){ |
| 134749 | 135251 | AutoincInfo *p = pParse->pAinc; |
| | @@ -135949,10 +136451,11 @@ |
| 135949 | 136451 | u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */ |
| 135950 | 136452 | } aFlagOp[] = { |
| 135951 | 136453 | { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys }, |
| 135952 | 136454 | { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger }, |
| 135953 | 136455 | { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer }, |
| 136456 | + { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension }, |
| 135954 | 136457 | }; |
| 135955 | 136458 | unsigned int i; |
| 135956 | 136459 | rc = SQLITE_ERROR; /* IMP: R-42790-23372 */ |
| 135957 | 136460 | for(i=0; i<ArraySize(aFlagOp); i++){ |
| 135958 | 136461 | if( aFlagOp[i].op==op ){ |
| | @@ -162447,19 +162950,21 @@ |
| 162447 | 162950 | ** lower('I', 'tr_tr') -> 'ı' (small dotless i) |
| 162448 | 162951 | ** |
| 162449 | 162952 | ** http://www.icu-project.org/userguide/posix.html#case_mappings |
| 162450 | 162953 | */ |
| 162451 | 162954 | static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ |
| 162452 | | - const UChar *zInput; |
| 162453 | | - UChar *zOutput = 0; |
| 162454 | | - int nInput; |
| 162455 | | - int nOut; |
| 162955 | + const UChar *zInput; /* Pointer to input string */ |
| 162956 | + UChar *zOutput = 0; /* Pointer to output buffer */ |
| 162957 | + int nInput; /* Size of utf-16 input string in bytes */ |
| 162958 | + int nOut; /* Size of output buffer in bytes */ |
| 162456 | 162959 | int cnt; |
| 162960 | + int bToUpper; /* True for toupper(), false for tolower() */ |
| 162457 | 162961 | UErrorCode status; |
| 162458 | 162962 | const char *zLocale = 0; |
| 162459 | 162963 | |
| 162460 | 162964 | assert(nArg==1 || nArg==2); |
| 162965 | + bToUpper = (sqlite3_user_data(p)!=0); |
| 162461 | 162966 | if( nArg==2 ){ |
| 162462 | 162967 | zLocale = (const char *)sqlite3_value_text(apArg[1]); |
| 162463 | 162968 | } |
| 162464 | 162969 | |
| 162465 | 162970 | zInput = sqlite3_value_text16(apArg[0]); |
| | @@ -162479,23 +162984,27 @@ |
| 162479 | 162984 | sqlite3_result_error_nomem(p); |
| 162480 | 162985 | return; |
| 162481 | 162986 | } |
| 162482 | 162987 | zOutput = zNew; |
| 162483 | 162988 | status = U_ZERO_ERROR; |
| 162484 | | - if( sqlite3_user_data(p) ){ |
| 162989 | + if( bToUpper ){ |
| 162485 | 162990 | nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); |
| 162486 | 162991 | }else{ |
| 162487 | 162992 | nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); |
| 162488 | 162993 | } |
| 162489 | | - if( !U_SUCCESS(status) ){ |
| 162490 | | - if( status==U_BUFFER_OVERFLOW_ERROR ) continue; |
| 162491 | | - icuFunctionError(p, |
| 162492 | | - sqlite3_user_data(p) ? "u_strToUpper" : "u_strToLower", status); |
| 162493 | | - return; |
| 162494 | | - } |
| 162495 | | - } |
| 162496 | | - sqlite3_result_text16(p, zOutput, nOut, xFree); |
| 162994 | + |
| 162995 | + if( U_SUCCESS(status) ){ |
| 162996 | + sqlite3_result_text16(p, zOutput, nOut, xFree); |
| 162997 | + }else if( status==U_BUFFER_OVERFLOW_ERROR ){ |
| 162998 | + assert( cnt==0 ); |
| 162999 | + continue; |
| 163000 | + }else{ |
| 163001 | + icuFunctionError(p, bToUpper ? "u_strToUpper" : "u_strToLower", status); |
| 163002 | + } |
| 163003 | + return; |
| 163004 | + } |
| 163005 | + assert( 0 ); /* Unreachable */ |
| 162497 | 163006 | } |
| 162498 | 163007 | |
| 162499 | 163008 | /* |
| 162500 | 163009 | ** Collation sequence destructor function. The pCtx argument points to |
| 162501 | 163010 | ** a UCollator structure previously allocated using ucol_open(). |
| | @@ -163308,10 +163817,42 @@ |
| 163308 | 163817 | const char *zTarget, |
| 163309 | 163818 | const char *zRbu, |
| 163310 | 163819 | const char *zState |
| 163311 | 163820 | ); |
| 163312 | 163821 | |
| 163822 | +/* |
| 163823 | +** Open an RBU handle to perform an RBU vacuum on database file zTarget. |
| 163824 | +** An RBU vacuum is similar to SQLite's built-in VACUUM command, except |
| 163825 | +** that it can be suspended and resumed like an RBU update. |
| 163826 | +** |
| 163827 | +** The second argument to this function, which may not be NULL, identifies |
| 163828 | +** a database in which to store the state of the RBU vacuum operation if |
| 163829 | +** it is suspended. The first time sqlite3rbu_vacuum() is called, to start |
| 163830 | +** an RBU vacuum operation, the state database should either not exist or |
| 163831 | +** be empty (contain no tables). If an RBU vacuum is suspended by calling |
| 163832 | +** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has |
| 163833 | +** returned SQLITE_DONE, the vacuum state is stored in the state database. |
| 163834 | +** The vacuum can be resumed by calling this function to open a new RBU |
| 163835 | +** handle specifying the same target and state databases. |
| 163836 | +** |
| 163837 | +** This function does not delete the state database after an RBU vacuum |
| 163838 | +** is completed, even if it created it. However, if the call to |
| 163839 | +** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents |
| 163840 | +** of the state tables within the state database are zeroed. This way, |
| 163841 | +** the next call to sqlite3rbu_vacuum() opens a handle that starts a |
| 163842 | +** new RBU vacuum operation. |
| 163843 | +** |
| 163844 | +** As with sqlite3rbu_open(), Zipvfs users should rever to the comment |
| 163845 | +** describing the sqlite3rbu_create_vfs() API function below for |
| 163846 | +** a description of the complications associated with using RBU with |
| 163847 | +** zipvfs databases. |
| 163848 | +*/ |
| 163849 | +SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum( |
| 163850 | + const char *zTarget, |
| 163851 | + const char *zState |
| 163852 | +); |
| 163853 | + |
| 163313 | 163854 | /* |
| 163314 | 163855 | ** Internally, each RBU connection uses a separate SQLite database |
| 163315 | 163856 | ** connection to access the target and rbu update databases. This |
| 163316 | 163857 | ** API allows the application direct access to these database handles. |
| 163317 | 163858 | ** |
| | @@ -163586,10 +164127,11 @@ |
| 163586 | 164127 | typedef struct rbu_file rbu_file; |
| 163587 | 164128 | typedef struct RbuUpdateStmt RbuUpdateStmt; |
| 163588 | 164129 | |
| 163589 | 164130 | #if !defined(SQLITE_AMALGAMATION) |
| 163590 | 164131 | typedef unsigned int u32; |
| 164132 | +typedef unsigned short u16; |
| 163591 | 164133 | typedef unsigned char u8; |
| 163592 | 164134 | typedef sqlite3_int64 i64; |
| 163593 | 164135 | #endif |
| 163594 | 164136 | |
| 163595 | 164137 | /* |
| | @@ -163598,10 +164140,12 @@ |
| 163598 | 164140 | ** format. |
| 163599 | 164141 | */ |
| 163600 | 164142 | #define WAL_LOCK_WRITE 0 |
| 163601 | 164143 | #define WAL_LOCK_CKPT 1 |
| 163602 | 164144 | #define WAL_LOCK_READ0 3 |
| 164145 | + |
| 164146 | +#define SQLITE_FCNTL_RBUCNT 5149216 |
| 163603 | 164147 | |
| 163604 | 164148 | /* |
| 163605 | 164149 | ** A structure to store values read from the rbu_state table in memory. |
| 163606 | 164150 | */ |
| 163607 | 164151 | struct RbuState { |
| | @@ -163777,10 +164321,14 @@ |
| 163777 | 164321 | int nFrameAlloc; /* Allocated size of aFrame[] array */ |
| 163778 | 164322 | RbuFrame *aFrame; |
| 163779 | 164323 | int pgsz; |
| 163780 | 164324 | u8 *aBuf; |
| 163781 | 164325 | i64 iWalCksum; |
| 164326 | + |
| 164327 | + /* Used in RBU vacuum mode only */ |
| 164328 | + int nRbu; /* Number of RBU VFS in the stack */ |
| 164329 | + rbu_file *pRbuFd; /* Fd for main db of dbRbu */ |
| 163782 | 164330 | }; |
| 163783 | 164331 | |
| 163784 | 164332 | /* |
| 163785 | 164333 | ** An rbu VFS is implemented using an instance of this structure. |
| 163786 | 164334 | */ |
| | @@ -163802,10 +164350,11 @@ |
| 163802 | 164350 | sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */ |
| 163803 | 164351 | |
| 163804 | 164352 | int openFlags; /* Flags this file was opened with */ |
| 163805 | 164353 | u32 iCookie; /* Cookie value for main db files */ |
| 163806 | 164354 | u8 iWriteVer; /* "write-version" value for main db files */ |
| 164355 | + u8 bNolock; /* True to fail EXCLUSIVE locks */ |
| 163807 | 164356 | |
| 163808 | 164357 | int nShm; /* Number of entries in apShm[] array */ |
| 163809 | 164358 | char **apShm; /* Array of mmap'd *-shm regions */ |
| 163810 | 164359 | char *zDel; /* Delete this when closing file */ |
| 163811 | 164360 | |
| | @@ -163812,10 +164361,15 @@ |
| 163812 | 164361 | const char *zWal; /* Wal filename for this main db file */ |
| 163813 | 164362 | rbu_file *pWalFd; /* Wal file descriptor for this main db */ |
| 163814 | 164363 | rbu_file *pMainNext; /* Next MAIN_DB file */ |
| 163815 | 164364 | }; |
| 163816 | 164365 | |
| 164366 | +/* |
| 164367 | +** True for an RBU vacuum handle, or false otherwise. |
| 164368 | +*/ |
| 164369 | +#define rbuIsVacuum(p) ((p)->zTarget==0) |
| 164370 | + |
| 163817 | 164371 | |
| 163818 | 164372 | /************************************************************************* |
| 163819 | 164373 | ** The following three functions, found below: |
| 163820 | 164374 | ** |
| 163821 | 164375 | ** rbuDeltaGetInt() |
| | @@ -164260,12 +164814,15 @@ |
| 164260 | 164814 | } |
| 164261 | 164815 | |
| 164262 | 164816 | |
| 164263 | 164817 | /* |
| 164264 | 164818 | ** The implementation of the rbu_target_name() SQL function. This function |
| 164265 | | -** accepts one argument - the name of a table in the RBU database. If the |
| 164266 | | -** table name matches the pattern: |
| 164819 | +** accepts one or two arguments. The first argument is the name of a table - |
| 164820 | +** the name of a table in the RBU database. The second, if it is present, is 1 |
| 164821 | +** for a view or 0 for a table. |
| 164822 | +** |
| 164823 | +** For a non-vacuum RBU handle, if the table name matches the pattern: |
| 164267 | 164824 | ** |
| 164268 | 164825 | ** data[0-9]_<name> |
| 164269 | 164826 | ** |
| 164270 | 164827 | ** where <name> is any sequence of 1 or more characters, <name> is returned. |
| 164271 | 164828 | ** Otherwise, if the only argument does not match the above pattern, an SQL |
| | @@ -164272,25 +164829,37 @@ |
| 164272 | 164829 | ** NULL is returned. |
| 164273 | 164830 | ** |
| 164274 | 164831 | ** "data_t1" -> "t1" |
| 164275 | 164832 | ** "data0123_t2" -> "t2" |
| 164276 | 164833 | ** "dataAB_t3" -> NULL |
| 164834 | +** |
| 164835 | +** For an rbu vacuum handle, a copy of the first argument is returned if |
| 164836 | +** the second argument is either missing or 0 (not a view). |
| 164277 | 164837 | */ |
| 164278 | 164838 | static void rbuTargetNameFunc( |
| 164279 | | - sqlite3_context *context, |
| 164839 | + sqlite3_context *pCtx, |
| 164280 | 164840 | int argc, |
| 164281 | 164841 | sqlite3_value **argv |
| 164282 | 164842 | ){ |
| 164843 | + sqlite3rbu *p = sqlite3_user_data(pCtx); |
| 164283 | 164844 | const char *zIn; |
| 164284 | | - assert( argc==1 ); |
| 164845 | + assert( argc==1 || argc==2 ); |
| 164285 | 164846 | |
| 164286 | 164847 | zIn = (const char*)sqlite3_value_text(argv[0]); |
| 164287 | | - if( zIn && strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){ |
| 164288 | | - int i; |
| 164289 | | - for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++); |
| 164290 | | - if( zIn[i]=='_' && zIn[i+1] ){ |
| 164291 | | - sqlite3_result_text(context, &zIn[i+1], -1, SQLITE_STATIC); |
| 164848 | + if( zIn ){ |
| 164849 | + if( rbuIsVacuum(p) ){ |
| 164850 | + if( argc==1 || 0==sqlite3_value_int(argv[1]) ){ |
| 164851 | + sqlite3_result_text(pCtx, zIn, -1, SQLITE_STATIC); |
| 164852 | + } |
| 164853 | + }else{ |
| 164854 | + if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){ |
| 164855 | + int i; |
| 164856 | + for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++); |
| 164857 | + if( zIn[i]=='_' && zIn[i+1] ){ |
| 164858 | + sqlite3_result_text(pCtx, &zIn[i+1], -1, SQLITE_STATIC); |
| 164859 | + } |
| 164860 | + } |
| 164292 | 164861 | } |
| 164293 | 164862 | } |
| 164294 | 164863 | } |
| 164295 | 164864 | |
| 164296 | 164865 | /* |
| | @@ -164304,11 +164873,12 @@ |
| 164304 | 164873 | static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){ |
| 164305 | 164874 | int rc; |
| 164306 | 164875 | memset(pIter, 0, sizeof(RbuObjIter)); |
| 164307 | 164876 | |
| 164308 | 164877 | rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg, |
| 164309 | | - "SELECT rbu_target_name(name) AS target, name FROM sqlite_master " |
| 164878 | + "SELECT rbu_target_name(name, type='view') AS target, name " |
| 164879 | + "FROM sqlite_master " |
| 164310 | 164880 | "WHERE type IN ('table', 'view') AND target IS NOT NULL " |
| 164311 | 164881 | "ORDER BY name" |
| 164312 | 164882 | ); |
| 164313 | 164883 | |
| 164314 | 164884 | if( rc==SQLITE_OK ){ |
| | @@ -164680,10 +165250,11 @@ |
| 164680 | 165250 | } |
| 164681 | 165251 | sqlite3_finalize(pStmt); |
| 164682 | 165252 | pStmt = 0; |
| 164683 | 165253 | |
| 164684 | 165254 | if( p->rc==SQLITE_OK |
| 165255 | + && rbuIsVacuum(p)==0 |
| 164685 | 165256 | && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) |
| 164686 | 165257 | ){ |
| 164687 | 165258 | p->rc = SQLITE_ERROR; |
| 164688 | 165259 | p->zErrmsg = sqlite3_mprintf( |
| 164689 | 165260 | "table %q %s rbu_rowid column", pIter->zDataTbl, |
| | @@ -164819,10 +165390,12 @@ |
| 164819 | 165390 | if( pIter->eType==RBU_PK_IPK ){ |
| 164820 | 165391 | int i; |
| 164821 | 165392 | for(i=0; pIter->abTblPk[i]==0; i++); |
| 164822 | 165393 | assert( i<pIter->nTblCol ); |
| 164823 | 165394 | zCol = pIter->azTblCol[i]; |
| 165395 | + }else if( rbuIsVacuum(p) ){ |
| 165396 | + zCol = "_rowid_"; |
| 164824 | 165397 | }else{ |
| 164825 | 165398 | zCol = "rbu_rowid"; |
| 164826 | 165399 | } |
| 164827 | 165400 | zType = "INTEGER"; |
| 164828 | 165401 | }else{ |
| | @@ -165359,20 +165932,29 @@ |
| 165359 | 165932 | sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind) |
| 165360 | 165933 | ); |
| 165361 | 165934 | } |
| 165362 | 165935 | |
| 165363 | 165936 | /* And to delete index entries */ |
| 165364 | | - if( p->rc==SQLITE_OK ){ |
| 165937 | + if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){ |
| 165365 | 165938 | p->rc = prepareFreeAndCollectError( |
| 165366 | 165939 | p->dbMain, &pIter->pDelete, &p->zErrmsg, |
| 165367 | 165940 | sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere) |
| 165368 | 165941 | ); |
| 165369 | 165942 | } |
| 165370 | 165943 | |
| 165371 | 165944 | /* Create the SELECT statement to read keys in sorted order */ |
| 165372 | 165945 | if( p->rc==SQLITE_OK ){ |
| 165373 | 165946 | char *zSql; |
| 165947 | + if( rbuIsVacuum(p) ){ |
| 165948 | + zSql = sqlite3_mprintf( |
| 165949 | + "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s", |
| 165950 | + zCollist, |
| 165951 | + pIter->zDataTbl, |
| 165952 | + zCollist, zLimit |
| 165953 | + ); |
| 165954 | + }else |
| 165955 | + |
| 165374 | 165956 | if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 165375 | 165957 | zSql = sqlite3_mprintf( |
| 165376 | 165958 | "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s", |
| 165377 | 165959 | zCollist, p->zStateDb, pIter->zDataTbl, |
| 165378 | 165960 | zCollist, zLimit |
| | @@ -165395,11 +165977,13 @@ |
| 165395 | 165977 | sqlite3_free(zImposterCols); |
| 165396 | 165978 | sqlite3_free(zImposterPK); |
| 165397 | 165979 | sqlite3_free(zWhere); |
| 165398 | 165980 | sqlite3_free(zBind); |
| 165399 | 165981 | }else{ |
| 165400 | | - int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE); |
| 165982 | + int bRbuRowid = (pIter->eType==RBU_PK_VTAB) |
| 165983 | + ||(pIter->eType==RBU_PK_NONE) |
| 165984 | + ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p)); |
| 165401 | 165985 | const char *zTbl = pIter->zTbl; /* Table this step applies to */ |
| 165402 | 165986 | const char *zWrite; /* Imposter table name */ |
| 165403 | 165987 | |
| 165404 | 165988 | char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid); |
| 165405 | 165989 | char *zWhere = rbuObjIterGetWhere(p, pIter); |
| | @@ -165422,20 +166006,22 @@ |
| 165422 | 166006 | zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings |
| 165423 | 166007 | ) |
| 165424 | 166008 | ); |
| 165425 | 166009 | } |
| 165426 | 166010 | |
| 165427 | | - /* Create the DELETE statement to write to the target PK b-tree */ |
| 165428 | | - if( p->rc==SQLITE_OK ){ |
| 166011 | + /* Create the DELETE statement to write to the target PK b-tree. |
| 166012 | + ** Because it only performs INSERT operations, this is not required for |
| 166013 | + ** an rbu vacuum handle. */ |
| 166014 | + if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){ |
| 165429 | 166015 | p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz, |
| 165430 | 166016 | sqlite3_mprintf( |
| 165431 | 166017 | "DELETE FROM \"%s%w\" WHERE %s", zWrite, zTbl, zWhere |
| 165432 | 166018 | ) |
| 165433 | 166019 | ); |
| 165434 | 166020 | } |
| 165435 | 166021 | |
| 165436 | | - if( pIter->abIndexed ){ |
| 166022 | + if( rbuIsVacuum(p)==0 && pIter->abIndexed ){ |
| 165437 | 166023 | const char *zRbuRowid = ""; |
| 165438 | 166024 | if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){ |
| 165439 | 166025 | zRbuRowid = ", rbu_rowid"; |
| 165440 | 166026 | } |
| 165441 | 166027 | |
| | @@ -165481,14 +166067,20 @@ |
| 165481 | 166067 | rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid); |
| 165482 | 166068 | } |
| 165483 | 166069 | |
| 165484 | 166070 | /* Create the SELECT statement to read keys from data_xxx */ |
| 165485 | 166071 | if( p->rc==SQLITE_OK ){ |
| 166072 | + const char *zRbuRowid = ""; |
| 166073 | + if( bRbuRowid ){ |
| 166074 | + zRbuRowid = rbuIsVacuum(p) ? ",_rowid_ " : ",rbu_rowid"; |
| 166075 | + } |
| 165486 | 166076 | p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, |
| 165487 | 166077 | sqlite3_mprintf( |
| 165488 | | - "SELECT %s, rbu_control%s FROM '%q'%s", |
| 165489 | | - zCollist, (bRbuRowid ? ", rbu_rowid" : ""), |
| 166078 | + "SELECT %s,%s rbu_control%s FROM '%q'%s", |
| 166079 | + zCollist, |
| 166080 | + (rbuIsVacuum(p) ? "0 AS " : ""), |
| 166081 | + zRbuRowid, |
| 165490 | 166082 | pIter->zDataTbl, zLimit |
| 165491 | 166083 | ) |
| 165492 | 166084 | ); |
| 165493 | 166085 | } |
| 165494 | 166086 | |
| | @@ -165579,44 +166171,231 @@ |
| 165579 | 166171 | } |
| 165580 | 166172 | |
| 165581 | 166173 | return p->rc; |
| 165582 | 166174 | } |
| 165583 | 166175 | |
| 165584 | | -static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){ |
| 166176 | +static sqlite3 *rbuOpenDbhandle( |
| 166177 | + sqlite3rbu *p, |
| 166178 | + const char *zName, |
| 166179 | + int bUseVfs |
| 166180 | +){ |
| 165585 | 166181 | sqlite3 *db = 0; |
| 165586 | 166182 | if( p->rc==SQLITE_OK ){ |
| 165587 | 166183 | const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI; |
| 165588 | | - p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName); |
| 166184 | + p->rc = sqlite3_open_v2(zName, &db, flags, bUseVfs ? p->zVfsName : 0); |
| 165589 | 166185 | if( p->rc ){ |
| 165590 | 166186 | p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db)); |
| 165591 | 166187 | sqlite3_close(db); |
| 165592 | 166188 | db = 0; |
| 165593 | 166189 | } |
| 165594 | 166190 | } |
| 165595 | 166191 | return db; |
| 165596 | 166192 | } |
| 166193 | + |
| 166194 | +/* |
| 166195 | +** Free an RbuState object allocated by rbuLoadState(). |
| 166196 | +*/ |
| 166197 | +static void rbuFreeState(RbuState *p){ |
| 166198 | + if( p ){ |
| 166199 | + sqlite3_free(p->zTbl); |
| 166200 | + sqlite3_free(p->zIdx); |
| 166201 | + sqlite3_free(p); |
| 166202 | + } |
| 166203 | +} |
| 166204 | + |
| 166205 | +/* |
| 166206 | +** Allocate an RbuState object and load the contents of the rbu_state |
| 166207 | +** table into it. Return a pointer to the new object. It is the |
| 166208 | +** responsibility of the caller to eventually free the object using |
| 166209 | +** sqlite3_free(). |
| 166210 | +** |
| 166211 | +** If an error occurs, leave an error code and message in the rbu handle |
| 166212 | +** and return NULL. |
| 166213 | +*/ |
| 166214 | +static RbuState *rbuLoadState(sqlite3rbu *p){ |
| 166215 | + RbuState *pRet = 0; |
| 166216 | + sqlite3_stmt *pStmt = 0; |
| 166217 | + int rc; |
| 166218 | + int rc2; |
| 166219 | + |
| 166220 | + pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState)); |
| 166221 | + if( pRet==0 ) return 0; |
| 166222 | + |
| 166223 | + rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, |
| 166224 | + sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb) |
| 166225 | + ); |
| 166226 | + while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 166227 | + switch( sqlite3_column_int(pStmt, 0) ){ |
| 166228 | + case RBU_STATE_STAGE: |
| 166229 | + pRet->eStage = sqlite3_column_int(pStmt, 1); |
| 166230 | + if( pRet->eStage!=RBU_STAGE_OAL |
| 166231 | + && pRet->eStage!=RBU_STAGE_MOVE |
| 166232 | + && pRet->eStage!=RBU_STAGE_CKPT |
| 166233 | + ){ |
| 166234 | + p->rc = SQLITE_CORRUPT; |
| 166235 | + } |
| 166236 | + break; |
| 166237 | + |
| 166238 | + case RBU_STATE_TBL: |
| 166239 | + pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); |
| 166240 | + break; |
| 166241 | + |
| 166242 | + case RBU_STATE_IDX: |
| 166243 | + pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); |
| 166244 | + break; |
| 166245 | + |
| 166246 | + case RBU_STATE_ROW: |
| 166247 | + pRet->nRow = sqlite3_column_int(pStmt, 1); |
| 166248 | + break; |
| 166249 | + |
| 166250 | + case RBU_STATE_PROGRESS: |
| 166251 | + pRet->nProgress = sqlite3_column_int64(pStmt, 1); |
| 166252 | + break; |
| 166253 | + |
| 166254 | + case RBU_STATE_CKPT: |
| 166255 | + pRet->iWalCksum = sqlite3_column_int64(pStmt, 1); |
| 166256 | + break; |
| 166257 | + |
| 166258 | + case RBU_STATE_COOKIE: |
| 166259 | + pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1); |
| 166260 | + break; |
| 166261 | + |
| 166262 | + case RBU_STATE_OALSZ: |
| 166263 | + pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1); |
| 166264 | + break; |
| 166265 | + |
| 166266 | + case RBU_STATE_PHASEONESTEP: |
| 166267 | + pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1); |
| 166268 | + break; |
| 166269 | + |
| 166270 | + default: |
| 166271 | + rc = SQLITE_CORRUPT; |
| 166272 | + break; |
| 166273 | + } |
| 166274 | + } |
| 166275 | + rc2 = sqlite3_finalize(pStmt); |
| 166276 | + if( rc==SQLITE_OK ) rc = rc2; |
| 166277 | + |
| 166278 | + p->rc = rc; |
| 166279 | + return pRet; |
| 166280 | +} |
| 166281 | + |
| 165597 | 166282 | |
| 165598 | 166283 | /* |
| 165599 | 166284 | ** Open the database handle and attach the RBU database as "rbu". If an |
| 165600 | 166285 | ** error occurs, leave an error code and message in the RBU handle. |
| 165601 | 166286 | */ |
| 165602 | 166287 | static void rbuOpenDatabase(sqlite3rbu *p){ |
| 165603 | 166288 | assert( p->rc==SQLITE_OK ); |
| 165604 | 166289 | assert( p->dbMain==0 && p->dbRbu==0 ); |
| 166290 | + assert( rbuIsVacuum(p) || p->zTarget!=0 ); |
| 165605 | 166291 | |
| 165606 | | - p->eStage = 0; |
| 165607 | | - p->dbMain = rbuOpenDbhandle(p, p->zTarget); |
| 165608 | | - p->dbRbu = rbuOpenDbhandle(p, p->zRbu); |
| 166292 | + /* Open the RBU database */ |
| 166293 | + p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1); |
| 166294 | + |
| 166295 | + if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){ |
| 166296 | + sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p); |
| 166297 | + } |
| 165609 | 166298 | |
| 165610 | 166299 | /* If using separate RBU and state databases, attach the state database to |
| 165611 | 166300 | ** the RBU db handle now. */ |
| 165612 | 166301 | if( p->zState ){ |
| 165613 | 166302 | rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState); |
| 165614 | 166303 | memcpy(p->zStateDb, "stat", 4); |
| 165615 | 166304 | }else{ |
| 165616 | 166305 | memcpy(p->zStateDb, "main", 4); |
| 165617 | 166306 | } |
| 166307 | + |
| 166308 | +#if 0 |
| 166309 | + if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){ |
| 166310 | + p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, 0); |
| 166311 | + } |
| 166312 | +#endif |
| 166313 | + |
| 166314 | + /* If it has not already been created, create the rbu_state table */ |
| 166315 | + rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb); |
| 166316 | + |
| 166317 | +#if 0 |
| 166318 | + if( rbuIsVacuum(p) ){ |
| 166319 | + if( p->rc==SQLITE_OK ){ |
| 166320 | + int rc2; |
| 166321 | + int bOk = 0; |
| 166322 | + sqlite3_stmt *pCnt = 0; |
| 166323 | + p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg, |
| 166324 | + "SELECT count(*) FROM stat.sqlite_master" |
| 166325 | + ); |
| 166326 | + if( p->rc==SQLITE_OK |
| 166327 | + && sqlite3_step(pCnt)==SQLITE_ROW |
| 166328 | + && 1==sqlite3_column_int(pCnt, 0) |
| 166329 | + ){ |
| 166330 | + bOk = 1; |
| 166331 | + } |
| 166332 | + rc2 = sqlite3_finalize(pCnt); |
| 166333 | + if( p->rc==SQLITE_OK ) p->rc = rc2; |
| 166334 | + |
| 166335 | + if( p->rc==SQLITE_OK && bOk==0 ){ |
| 166336 | + p->rc = SQLITE_ERROR; |
| 166337 | + p->zErrmsg = sqlite3_mprintf("invalid state database"); |
| 166338 | + } |
| 166339 | + |
| 166340 | + if( p->rc==SQLITE_OK ){ |
| 166341 | + p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0); |
| 166342 | + } |
| 166343 | + } |
| 166344 | + } |
| 166345 | +#endif |
| 166346 | + |
| 166347 | + if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){ |
| 166348 | + int bOpen = 0; |
| 166349 | + int rc; |
| 166350 | + p->nRbu = 0; |
| 166351 | + p->pRbuFd = 0; |
| 166352 | + rc = sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p); |
| 166353 | + if( rc!=SQLITE_NOTFOUND ) p->rc = rc; |
| 166354 | + if( p->eStage>=RBU_STAGE_MOVE ){ |
| 166355 | + bOpen = 1; |
| 166356 | + }else{ |
| 166357 | + RbuState *pState = rbuLoadState(p); |
| 166358 | + if( pState ){ |
| 166359 | + bOpen = (pState->eStage>RBU_STAGE_MOVE); |
| 166360 | + rbuFreeState(pState); |
| 166361 | + } |
| 166362 | + } |
| 166363 | + if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1); |
| 166364 | + } |
| 166365 | + |
| 166366 | + p->eStage = 0; |
| 166367 | + if( p->rc==SQLITE_OK && p->dbMain==0 ){ |
| 166368 | + if( !rbuIsVacuum(p) ){ |
| 166369 | + p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1); |
| 166370 | + }else if( p->pRbuFd->pWalFd ){ |
| 166371 | + p->rc = SQLITE_ERROR; |
| 166372 | + p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database"); |
| 166373 | + }else{ |
| 166374 | + char *zTarget; |
| 166375 | + char *zExtra = 0; |
| 166376 | + if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){ |
| 166377 | + zExtra = &p->zRbu[5]; |
| 166378 | + while( *zExtra ){ |
| 166379 | + if( *zExtra++=='?' ) break; |
| 166380 | + } |
| 166381 | + if( *zExtra=='\0' ) zExtra = 0; |
| 166382 | + } |
| 166383 | + |
| 166384 | + zTarget = sqlite3_mprintf("file:%s-vacuum?rbu_memory=1%s%s", |
| 166385 | + sqlite3_db_filename(p->dbRbu, "main"), |
| 166386 | + (zExtra==0 ? "" : "&"), (zExtra==0 ? "" : zExtra) |
| 166387 | + ); |
| 166388 | + |
| 166389 | + if( zTarget==0 ){ |
| 166390 | + p->rc = SQLITE_NOMEM; |
| 166391 | + return; |
| 166392 | + } |
| 166393 | + p->dbMain = rbuOpenDbhandle(p, zTarget, p->nRbu<=1); |
| 166394 | + sqlite3_free(zTarget); |
| 166395 | + } |
| 166396 | + } |
| 165618 | 166397 | |
| 165619 | 166398 | if( p->rc==SQLITE_OK ){ |
| 165620 | 166399 | p->rc = sqlite3_create_function(p->dbMain, |
| 165621 | 166400 | "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0 |
| 165622 | 166401 | ); |
| | @@ -165628,11 +166407,11 @@ |
| 165628 | 166407 | ); |
| 165629 | 166408 | } |
| 165630 | 166409 | |
| 165631 | 166410 | if( p->rc==SQLITE_OK ){ |
| 165632 | 166411 | p->rc = sqlite3_create_function(p->dbRbu, |
| 165633 | | - "rbu_target_name", 1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0 |
| 166412 | + "rbu_target_name", -1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0 |
| 165634 | 166413 | ); |
| 165635 | 166414 | } |
| 165636 | 166415 | |
| 165637 | 166416 | if( p->rc==SQLITE_OK ){ |
| 165638 | 166417 | p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p); |
| | @@ -165887,13 +166666,19 @@ |
| 165887 | 166666 | ** If an error occurs, leave an error code and error message in the rbu |
| 165888 | 166667 | ** handle. |
| 165889 | 166668 | */ |
| 165890 | 166669 | static void rbuMoveOalFile(sqlite3rbu *p){ |
| 165891 | 166670 | const char *zBase = sqlite3_db_filename(p->dbMain, "main"); |
| 166671 | + const char *zMove = zBase; |
| 166672 | + char *zOal; |
| 166673 | + char *zWal; |
| 165892 | 166674 | |
| 165893 | | - char *zWal = sqlite3_mprintf("%s-wal", zBase); |
| 165894 | | - char *zOal = sqlite3_mprintf("%s-oal", zBase); |
| 166675 | + if( rbuIsVacuum(p) ){ |
| 166676 | + zMove = sqlite3_db_filename(p->dbRbu, "main"); |
| 166677 | + } |
| 166678 | + zOal = sqlite3_mprintf("%s-oal", zMove); |
| 166679 | + zWal = sqlite3_mprintf("%s-wal", zMove); |
| 165895 | 166680 | |
| 165896 | 166681 | assert( p->eStage==RBU_STAGE_MOVE ); |
| 165897 | 166682 | assert( p->rc==SQLITE_OK && p->zErrmsg==0 ); |
| 165898 | 166683 | if( zWal==0 || zOal==0 ){ |
| 165899 | 166684 | p->rc = SQLITE_NOMEM; |
| | @@ -165910,12 +166695,12 @@ |
| 165910 | 166695 | rbuFileSuffix3(zBase, zWal); |
| 165911 | 166696 | rbuFileSuffix3(zBase, zOal); |
| 165912 | 166697 | |
| 165913 | 166698 | /* Re-open the databases. */ |
| 165914 | 166699 | rbuObjIterFinalize(&p->objiter); |
| 165915 | | - sqlite3_close(p->dbMain); |
| 165916 | 166700 | sqlite3_close(p->dbRbu); |
| 166701 | + sqlite3_close(p->dbMain); |
| 165917 | 166702 | p->dbMain = 0; |
| 165918 | 166703 | p->dbRbu = 0; |
| 165919 | 166704 | |
| 165920 | 166705 | #if defined(_WIN32_WCE) |
| 165921 | 166706 | { |
| | @@ -166073,23 +166858,28 @@ |
| 166073 | 166858 | |
| 166074 | 166859 | pVal = sqlite3_column_value(pIter->pSelect, i); |
| 166075 | 166860 | p->rc = sqlite3_bind_value(pWriter, i+1, pVal); |
| 166076 | 166861 | if( p->rc ) return; |
| 166077 | 166862 | } |
| 166078 | | - if( pIter->zIdx==0 |
| 166079 | | - && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE) |
| 166080 | | - ){ |
| 166081 | | - /* For a virtual table, or a table with no primary key, the |
| 166082 | | - ** SELECT statement is: |
| 166083 | | - ** |
| 166084 | | - ** SELECT <cols>, rbu_control, rbu_rowid FROM .... |
| 166085 | | - ** |
| 166086 | | - ** Hence column_value(pIter->nCol+1). |
| 166087 | | - */ |
| 166088 | | - assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid"); |
| 166089 | | - pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1); |
| 166090 | | - p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal); |
| 166863 | + if( pIter->zIdx==0 ){ |
| 166864 | + if( pIter->eType==RBU_PK_VTAB |
| 166865 | + || pIter->eType==RBU_PK_NONE |
| 166866 | + || (pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p)) |
| 166867 | + ){ |
| 166868 | + /* For a virtual table, or a table with no primary key, the |
| 166869 | + ** SELECT statement is: |
| 166870 | + ** |
| 166871 | + ** SELECT <cols>, rbu_control, rbu_rowid FROM .... |
| 166872 | + ** |
| 166873 | + ** Hence column_value(pIter->nCol+1). |
| 166874 | + */ |
| 166875 | + assertColumnName(pIter->pSelect, pIter->nCol+1, |
| 166876 | + rbuIsVacuum(p) ? "rowid" : "rbu_rowid" |
| 166877 | + ); |
| 166878 | + pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1); |
| 166879 | + p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal); |
| 166880 | + } |
| 166091 | 166881 | } |
| 166092 | 166882 | if( p->rc==SQLITE_OK ){ |
| 166093 | 166883 | sqlite3_step(pWriter); |
| 166094 | 166884 | p->rc = resetAndCollectError(pWriter, &p->zErrmsg); |
| 166095 | 166885 | } |
| | @@ -166164,17 +166954,22 @@ |
| 166164 | 166954 | return p->rc; |
| 166165 | 166955 | } |
| 166166 | 166956 | |
| 166167 | 166957 | /* |
| 166168 | 166958 | ** Increment the schema cookie of the main database opened by p->dbMain. |
| 166959 | +** |
| 166960 | +** Or, if this is an RBU vacuum, set the schema cookie of the main db |
| 166961 | +** opened by p->dbMain to one more than the schema cookie of the main |
| 166962 | +** db opened by p->dbRbu. |
| 166169 | 166963 | */ |
| 166170 | 166964 | static void rbuIncrSchemaCookie(sqlite3rbu *p){ |
| 166171 | 166965 | if( p->rc==SQLITE_OK ){ |
| 166966 | + sqlite3 *dbread = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain); |
| 166172 | 166967 | int iCookie = 1000000; |
| 166173 | 166968 | sqlite3_stmt *pStmt; |
| 166174 | 166969 | |
| 166175 | | - p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg, |
| 166970 | + p->rc = prepareAndCollectError(dbread, &pStmt, &p->zErrmsg, |
| 166176 | 166971 | "PRAGMA schema_version" |
| 166177 | 166972 | ); |
| 166178 | 166973 | if( p->rc==SQLITE_OK ){ |
| 166179 | 166974 | /* Coverage: it may be that this sqlite3_step() cannot fail. There |
| 166180 | 166975 | ** is already a transaction open, so the prepared statement cannot |
| | @@ -166198,10 +166993,11 @@ |
| 166198 | 166993 | ** are determined by inspecting the rbu handle passed as the first argument. |
| 166199 | 166994 | */ |
| 166200 | 166995 | static void rbuSaveState(sqlite3rbu *p, int eStage){ |
| 166201 | 166996 | if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){ |
| 166202 | 166997 | sqlite3_stmt *pInsert = 0; |
| 166998 | + rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd); |
| 166203 | 166999 | int rc; |
| 166204 | 167000 | |
| 166205 | 167001 | assert( p->zErrmsg==0 ); |
| 166206 | 167002 | rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg, |
| 166207 | 167003 | sqlite3_mprintf( |
| | @@ -166220,11 +167016,11 @@ |
| 166220 | 167016 | RBU_STATE_TBL, p->objiter.zTbl, |
| 166221 | 167017 | RBU_STATE_IDX, p->objiter.zIdx, |
| 166222 | 167018 | RBU_STATE_ROW, p->nStep, |
| 166223 | 167019 | RBU_STATE_PROGRESS, p->nProgress, |
| 166224 | 167020 | RBU_STATE_CKPT, p->iWalCksum, |
| 166225 | | - RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie, |
| 167021 | + RBU_STATE_COOKIE, (i64)pFd->iCookie, |
| 166226 | 167022 | RBU_STATE_OALSZ, p->iOalSz, |
| 166227 | 167023 | RBU_STATE_PHASEONESTEP, p->nPhaseOneStep |
| 166228 | 167024 | ) |
| 166229 | 167025 | ); |
| 166230 | 167026 | assert( pInsert==0 || rc==SQLITE_OK ); |
| | @@ -166235,26 +167031,121 @@ |
| 166235 | 167031 | } |
| 166236 | 167032 | if( rc!=SQLITE_OK ) p->rc = rc; |
| 166237 | 167033 | } |
| 166238 | 167034 | } |
| 166239 | 167035 | |
| 167036 | + |
| 167037 | +/* |
| 167038 | +** The second argument passed to this function is the name of a PRAGMA |
| 167039 | +** setting - "page_size", "auto_vacuum", "user_version" or "application_id". |
| 167040 | +** This function executes the following on sqlite3rbu.dbRbu: |
| 167041 | +** |
| 167042 | +** "PRAGMA main.$zPragma" |
| 167043 | +** |
| 167044 | +** where $zPragma is the string passed as the second argument, then |
| 167045 | +** on sqlite3rbu.dbMain: |
| 167046 | +** |
| 167047 | +** "PRAGMA main.$zPragma = $val" |
| 167048 | +** |
| 167049 | +** where $val is the value returned by the first PRAGMA invocation. |
| 167050 | +** |
| 167051 | +** In short, it copies the value of the specified PRAGMA setting from |
| 167052 | +** dbRbu to dbMain. |
| 167053 | +*/ |
| 167054 | +static void rbuCopyPragma(sqlite3rbu *p, const char *zPragma){ |
| 167055 | + if( p->rc==SQLITE_OK ){ |
| 167056 | + sqlite3_stmt *pPragma = 0; |
| 167057 | + p->rc = prepareFreeAndCollectError(p->dbRbu, &pPragma, &p->zErrmsg, |
| 167058 | + sqlite3_mprintf("PRAGMA main.%s", zPragma) |
| 167059 | + ); |
| 167060 | + if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pPragma) ){ |
| 167061 | + p->rc = rbuMPrintfExec(p, p->dbMain, "PRAGMA main.%s = %d", |
| 167062 | + zPragma, sqlite3_column_int(pPragma, 0) |
| 167063 | + ); |
| 167064 | + } |
| 167065 | + rbuFinalize(p, pPragma); |
| 167066 | + } |
| 167067 | +} |
| 167068 | + |
| 167069 | +/* |
| 167070 | +** The RBU handle passed as the only argument has just been opened and |
| 167071 | +** the state database is empty. If this RBU handle was opened for an |
| 167072 | +** RBU vacuum operation, create the schema in the target db. |
| 167073 | +*/ |
| 167074 | +static void rbuCreateTargetSchema(sqlite3rbu *p){ |
| 167075 | + sqlite3_stmt *pSql = 0; |
| 167076 | + sqlite3_stmt *pInsert = 0; |
| 167077 | + |
| 167078 | + assert( rbuIsVacuum(p) ); |
| 167079 | + p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg); |
| 167080 | + if( p->rc==SQLITE_OK ){ |
| 167081 | + p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg, |
| 167082 | + "SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0" |
| 167083 | + " AND name!='sqlite_sequence' " |
| 167084 | + " ORDER BY type DESC" |
| 167085 | + ); |
| 167086 | + } |
| 167087 | + |
| 167088 | + while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){ |
| 167089 | + const char *zSql = (const char*)sqlite3_column_text(pSql, 0); |
| 167090 | + p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg); |
| 167091 | + } |
| 167092 | + rbuFinalize(p, pSql); |
| 167093 | + if( p->rc!=SQLITE_OK ) return; |
| 167094 | + |
| 167095 | + if( p->rc==SQLITE_OK ){ |
| 167096 | + p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg, |
| 167097 | + "SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL" |
| 167098 | + ); |
| 167099 | + } |
| 167100 | + |
| 167101 | + if( p->rc==SQLITE_OK ){ |
| 167102 | + p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg, |
| 167103 | + "INSERT INTO sqlite_master VALUES(?,?,?,?,?)" |
| 167104 | + ); |
| 167105 | + } |
| 167106 | + |
| 167107 | + while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){ |
| 167108 | + int i; |
| 167109 | + for(i=0; i<5; i++){ |
| 167110 | + sqlite3_bind_value(pInsert, i+1, sqlite3_column_value(pSql, i)); |
| 167111 | + } |
| 167112 | + sqlite3_step(pInsert); |
| 167113 | + p->rc = sqlite3_reset(pInsert); |
| 167114 | + } |
| 167115 | + if( p->rc==SQLITE_OK ){ |
| 167116 | + p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=0",0,0,&p->zErrmsg); |
| 167117 | + } |
| 167118 | + |
| 167119 | + rbuFinalize(p, pSql); |
| 167120 | + rbuFinalize(p, pInsert); |
| 167121 | +} |
| 166240 | 167122 | |
| 166241 | 167123 | /* |
| 166242 | 167124 | ** Step the RBU object. |
| 166243 | 167125 | */ |
| 166244 | 167126 | SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){ |
| 166245 | 167127 | if( p ){ |
| 166246 | 167128 | switch( p->eStage ){ |
| 166247 | 167129 | case RBU_STAGE_OAL: { |
| 166248 | 167130 | RbuObjIter *pIter = &p->objiter; |
| 167131 | + |
| 167132 | + /* If this is an RBU vacuum operation and the state table was empty |
| 167133 | + ** when this handle was opened, create the target database schema. */ |
| 167134 | + if( rbuIsVacuum(p) && p->nProgress==0 && p->rc==SQLITE_OK ){ |
| 167135 | + rbuCreateTargetSchema(p); |
| 167136 | + rbuCopyPragma(p, "user_version"); |
| 167137 | + rbuCopyPragma(p, "application_id"); |
| 167138 | + } |
| 167139 | + |
| 166249 | 167140 | while( p->rc==SQLITE_OK && pIter->zTbl ){ |
| 166250 | 167141 | |
| 166251 | 167142 | if( pIter->bCleanup ){ |
| 166252 | 167143 | /* Clean up the rbu_tmp_xxx table for the previous table. It |
| 166253 | 167144 | ** cannot be dropped as there are currently active SQL statements. |
| 166254 | 167145 | ** But the contents can be deleted. */ |
| 166255 | | - if( pIter->abIndexed ){ |
| 167146 | + if( rbuIsVacuum(p)==0 && pIter->abIndexed ){ |
| 166256 | 167147 | rbuMPrintfExec(p, p->dbRbu, |
| 166257 | 167148 | "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl |
| 166258 | 167149 | ); |
| 166259 | 167150 | } |
| 166260 | 167151 | }else{ |
| | @@ -166337,98 +167228,10 @@ |
| 166337 | 167228 | }else{ |
| 166338 | 167229 | return SQLITE_NOMEM; |
| 166339 | 167230 | } |
| 166340 | 167231 | } |
| 166341 | 167232 | |
| 166342 | | -/* |
| 166343 | | -** Free an RbuState object allocated by rbuLoadState(). |
| 166344 | | -*/ |
| 166345 | | -static void rbuFreeState(RbuState *p){ |
| 166346 | | - if( p ){ |
| 166347 | | - sqlite3_free(p->zTbl); |
| 166348 | | - sqlite3_free(p->zIdx); |
| 166349 | | - sqlite3_free(p); |
| 166350 | | - } |
| 166351 | | -} |
| 166352 | | - |
| 166353 | | -/* |
| 166354 | | -** Allocate an RbuState object and load the contents of the rbu_state |
| 166355 | | -** table into it. Return a pointer to the new object. It is the |
| 166356 | | -** responsibility of the caller to eventually free the object using |
| 166357 | | -** sqlite3_free(). |
| 166358 | | -** |
| 166359 | | -** If an error occurs, leave an error code and message in the rbu handle |
| 166360 | | -** and return NULL. |
| 166361 | | -*/ |
| 166362 | | -static RbuState *rbuLoadState(sqlite3rbu *p){ |
| 166363 | | - RbuState *pRet = 0; |
| 166364 | | - sqlite3_stmt *pStmt = 0; |
| 166365 | | - int rc; |
| 166366 | | - int rc2; |
| 166367 | | - |
| 166368 | | - pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState)); |
| 166369 | | - if( pRet==0 ) return 0; |
| 166370 | | - |
| 166371 | | - rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg, |
| 166372 | | - sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb) |
| 166373 | | - ); |
| 166374 | | - while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ |
| 166375 | | - switch( sqlite3_column_int(pStmt, 0) ){ |
| 166376 | | - case RBU_STATE_STAGE: |
| 166377 | | - pRet->eStage = sqlite3_column_int(pStmt, 1); |
| 166378 | | - if( pRet->eStage!=RBU_STAGE_OAL |
| 166379 | | - && pRet->eStage!=RBU_STAGE_MOVE |
| 166380 | | - && pRet->eStage!=RBU_STAGE_CKPT |
| 166381 | | - ){ |
| 166382 | | - p->rc = SQLITE_CORRUPT; |
| 166383 | | - } |
| 166384 | | - break; |
| 166385 | | - |
| 166386 | | - case RBU_STATE_TBL: |
| 166387 | | - pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); |
| 166388 | | - break; |
| 166389 | | - |
| 166390 | | - case RBU_STATE_IDX: |
| 166391 | | - pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc); |
| 166392 | | - break; |
| 166393 | | - |
| 166394 | | - case RBU_STATE_ROW: |
| 166395 | | - pRet->nRow = sqlite3_column_int(pStmt, 1); |
| 166396 | | - break; |
| 166397 | | - |
| 166398 | | - case RBU_STATE_PROGRESS: |
| 166399 | | - pRet->nProgress = sqlite3_column_int64(pStmt, 1); |
| 166400 | | - break; |
| 166401 | | - |
| 166402 | | - case RBU_STATE_CKPT: |
| 166403 | | - pRet->iWalCksum = sqlite3_column_int64(pStmt, 1); |
| 166404 | | - break; |
| 166405 | | - |
| 166406 | | - case RBU_STATE_COOKIE: |
| 166407 | | - pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1); |
| 166408 | | - break; |
| 166409 | | - |
| 166410 | | - case RBU_STATE_OALSZ: |
| 166411 | | - pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1); |
| 166412 | | - break; |
| 166413 | | - |
| 166414 | | - case RBU_STATE_PHASEONESTEP: |
| 166415 | | - pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1); |
| 166416 | | - break; |
| 166417 | | - |
| 166418 | | - default: |
| 166419 | | - rc = SQLITE_CORRUPT; |
| 166420 | | - break; |
| 166421 | | - } |
| 166422 | | - } |
| 166423 | | - rc2 = sqlite3_finalize(pStmt); |
| 166424 | | - if( rc==SQLITE_OK ) rc = rc2; |
| 166425 | | - |
| 166426 | | - p->rc = rc; |
| 166427 | | - return pRet; |
| 166428 | | -} |
| 166429 | | - |
| 166430 | 167233 | /* |
| 166431 | 167234 | ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero |
| 166432 | 167235 | ** otherwise. Either or both argument may be NULL. Two NULL values are |
| 166433 | 167236 | ** considered equal, and NULL is considered distinct from all other values. |
| 166434 | 167237 | */ |
| | @@ -166614,20 +167417,18 @@ |
| 166614 | 167417 | } |
| 166615 | 167418 | } |
| 166616 | 167419 | } |
| 166617 | 167420 | } |
| 166618 | 167421 | |
| 166619 | | -/* |
| 166620 | | -** Open and return a new RBU handle. |
| 166621 | | -*/ |
| 166622 | | -SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open( |
| 167422 | + |
| 167423 | +static sqlite3rbu *openRbuHandle( |
| 166623 | 167424 | const char *zTarget, |
| 166624 | 167425 | const char *zRbu, |
| 166625 | 167426 | const char *zState |
| 166626 | 167427 | ){ |
| 166627 | 167428 | sqlite3rbu *p; |
| 166628 | | - size_t nTarget = strlen(zTarget); |
| 167429 | + size_t nTarget = zTarget ? strlen(zTarget) : 0; |
| 166629 | 167430 | size_t nRbu = strlen(zRbu); |
| 166630 | 167431 | size_t nState = zState ? strlen(zState) : 0; |
| 166631 | 167432 | size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1; |
| 166632 | 167433 | |
| 166633 | 167434 | p = (sqlite3rbu*)sqlite3_malloc64(nByte); |
| | @@ -166636,26 +167437,28 @@ |
| 166636 | 167437 | |
| 166637 | 167438 | /* Create the custom VFS. */ |
| 166638 | 167439 | memset(p, 0, sizeof(sqlite3rbu)); |
| 166639 | 167440 | rbuCreateVfs(p); |
| 166640 | 167441 | |
| 166641 | | - /* Open the target database */ |
| 167442 | + /* Open the target, RBU and state databases */ |
| 166642 | 167443 | if( p->rc==SQLITE_OK ){ |
| 166643 | | - p->zTarget = (char*)&p[1]; |
| 166644 | | - memcpy(p->zTarget, zTarget, nTarget+1); |
| 166645 | | - p->zRbu = &p->zTarget[nTarget+1]; |
| 167444 | + char *pCsr = (char*)&p[1]; |
| 167445 | + if( zTarget ){ |
| 167446 | + p->zTarget = pCsr; |
| 167447 | + memcpy(p->zTarget, zTarget, nTarget+1); |
| 167448 | + pCsr += nTarget+1; |
| 167449 | + } |
| 167450 | + p->zRbu = pCsr; |
| 166646 | 167451 | memcpy(p->zRbu, zRbu, nRbu+1); |
| 167452 | + pCsr += nRbu+1; |
| 166647 | 167453 | if( zState ){ |
| 166648 | | - p->zState = &p->zRbu[nRbu+1]; |
| 167454 | + p->zState = pCsr; |
| 166649 | 167455 | memcpy(p->zState, zState, nState+1); |
| 166650 | 167456 | } |
| 166651 | 167457 | rbuOpenDatabase(p); |
| 166652 | 167458 | } |
| 166653 | 167459 | |
| 166654 | | - /* If it has not already been created, create the rbu_state table */ |
| 166655 | | - rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb); |
| 166656 | | - |
| 166657 | 167460 | if( p->rc==SQLITE_OK ){ |
| 166658 | 167461 | pState = rbuLoadState(p); |
| 166659 | 167462 | assert( pState || p->rc!=SQLITE_OK ); |
| 166660 | 167463 | if( p->rc==SQLITE_OK ){ |
| 166661 | 167464 | |
| | @@ -166681,31 +167484,43 @@ |
| 166681 | 167484 | p->eStage = RBU_STAGE_CKPT; |
| 166682 | 167485 | p->nStep = 0; |
| 166683 | 167486 | } |
| 166684 | 167487 | } |
| 166685 | 167488 | |
| 166686 | | - if( p->rc==SQLITE_OK |
| 167489 | + if( p->rc==SQLITE_OK |
| 166687 | 167490 | && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE) |
| 166688 | | - && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie |
| 166689 | | - ){ |
| 166690 | | - /* At this point (pTargetFd->iCookie) contains the value of the |
| 166691 | | - ** change-counter cookie (the thing that gets incremented when a |
| 166692 | | - ** transaction is committed in rollback mode) currently stored on |
| 166693 | | - ** page 1 of the database file. */ |
| 166694 | | - p->rc = SQLITE_BUSY; |
| 166695 | | - p->zErrmsg = sqlite3_mprintf("database modified during rbu update"); |
| 167491 | + && pState->eStage!=0 |
| 167492 | + ){ |
| 167493 | + rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd); |
| 167494 | + if( pFd->iCookie!=pState->iCookie ){ |
| 167495 | + /* At this point (pTargetFd->iCookie) contains the value of the |
| 167496 | + ** change-counter cookie (the thing that gets incremented when a |
| 167497 | + ** transaction is committed in rollback mode) currently stored on |
| 167498 | + ** page 1 of the database file. */ |
| 167499 | + p->rc = SQLITE_BUSY; |
| 167500 | + p->zErrmsg = sqlite3_mprintf("database modified during rbu %s", |
| 167501 | + (rbuIsVacuum(p) ? "vacuum" : "update") |
| 167502 | + ); |
| 167503 | + } |
| 166696 | 167504 | } |
| 166697 | 167505 | |
| 166698 | 167506 | if( p->rc==SQLITE_OK ){ |
| 166699 | 167507 | if( p->eStage==RBU_STAGE_OAL ){ |
| 166700 | 167508 | sqlite3 *db = p->dbMain; |
| 167509 | + |
| 167510 | + if( pState->eStage==0 && rbuIsVacuum(p) ){ |
| 167511 | + rbuCopyPragma(p, "page_size"); |
| 167512 | + rbuCopyPragma(p, "auto_vacuum"); |
| 167513 | + } |
| 166701 | 167514 | |
| 166702 | 167515 | /* Open transactions both databases. The *-oal file is opened or |
| 166703 | 167516 | ** created at this point. */ |
| 166704 | | - p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); |
| 167517 | + if( p->rc==SQLITE_OK ){ |
| 167518 | + p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); |
| 167519 | + } |
| 166705 | 167520 | if( p->rc==SQLITE_OK ){ |
| 166706 | | - p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg); |
| 167521 | + p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, &p->zErrmsg); |
| 166707 | 167522 | } |
| 166708 | 167523 | |
| 166709 | 167524 | /* Check if the main database is a zipvfs db. If it is, set the upper |
| 166710 | 167525 | ** level pager to use "journal_mode=off". This prevents it from |
| 166711 | 167526 | ** generating a large journal using a temp file. */ |
| | @@ -166746,10 +167561,32 @@ |
| 166746 | 167561 | } |
| 166747 | 167562 | |
| 166748 | 167563 | return p; |
| 166749 | 167564 | } |
| 166750 | 167565 | |
| 167566 | +/* |
| 167567 | +** Open and return a new RBU handle. |
| 167568 | +*/ |
| 167569 | +SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open( |
| 167570 | + const char *zTarget, |
| 167571 | + const char *zRbu, |
| 167572 | + const char *zState |
| 167573 | +){ |
| 167574 | + /* TODO: Check that zTarget and zRbu are non-NULL */ |
| 167575 | + return openRbuHandle(zTarget, zRbu, zState); |
| 167576 | +} |
| 167577 | + |
| 167578 | +/* |
| 167579 | +** Open a handle to begin or resume an RBU VACUUM operation. |
| 167580 | +*/ |
| 167581 | +SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum( |
| 167582 | + const char *zTarget, |
| 167583 | + const char *zState |
| 167584 | +){ |
| 167585 | + /* TODO: Check that both arguments are non-NULL */ |
| 167586 | + return openRbuHandle(0, zTarget, zState); |
| 167587 | +} |
| 166751 | 167588 | |
| 166752 | 167589 | /* |
| 166753 | 167590 | ** Return the database handle used by pRbu. |
| 166754 | 167591 | */ |
| 166755 | 167592 | SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){ |
| | @@ -166766,11 +167603,11 @@ |
| 166766 | 167603 | ** then edit any error message string so as to remove all occurrences of |
| 166767 | 167604 | ** the pattern "rbu_imp_[0-9]*". |
| 166768 | 167605 | */ |
| 166769 | 167606 | static void rbuEditErrmsg(sqlite3rbu *p){ |
| 166770 | 167607 | if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){ |
| 166771 | | - int i; |
| 167608 | + unsigned int i; |
| 166772 | 167609 | size_t nErrmsg = strlen(p->zErrmsg); |
| 166773 | 167610 | for(i=0; i<(nErrmsg-8); i++){ |
| 166774 | 167611 | if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){ |
| 166775 | 167612 | int nDel = 8; |
| 166776 | 167613 | while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++; |
| | @@ -166799,14 +167636,24 @@ |
| 166799 | 167636 | p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg); |
| 166800 | 167637 | } |
| 166801 | 167638 | |
| 166802 | 167639 | /* Close any open statement handles. */ |
| 166803 | 167640 | rbuObjIterFinalize(&p->objiter); |
| 167641 | + |
| 167642 | + /* If this is an RBU vacuum handle and the vacuum has either finished |
| 167643 | + ** successfully or encountered an error, delete the contents of the |
| 167644 | + ** state table. This causes the next call to sqlite3rbu_vacuum() |
| 167645 | + ** specifying the current target and state databases to start a new |
| 167646 | + ** vacuum from scratch. */ |
| 167647 | + if( rbuIsVacuum(p) && p->rc!=SQLITE_OK && p->dbRbu ){ |
| 167648 | + int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0); |
| 167649 | + if( p->rc==SQLITE_DONE && rc2!=SQLITE_OK ) p->rc = rc2; |
| 167650 | + } |
| 166804 | 167651 | |
| 166805 | 167652 | /* Close the open database handle and VFS object. */ |
| 166806 | | - sqlite3_close(p->dbMain); |
| 166807 | 167653 | sqlite3_close(p->dbRbu); |
| 167654 | + sqlite3_close(p->dbMain); |
| 166808 | 167655 | rbuDeleteVfs(p); |
| 166809 | 167656 | sqlite3_free(p->aBuf); |
| 166810 | 167657 | sqlite3_free(p->aFrame); |
| 166811 | 167658 | |
| 166812 | 167659 | rbuEditErrmsg(p); |
| | @@ -167003,10 +167850,26 @@ |
| 167003 | 167850 | return ((u32)aBuf[0] << 24) |
| 167004 | 167851 | + ((u32)aBuf[1] << 16) |
| 167005 | 167852 | + ((u32)aBuf[2] << 8) |
| 167006 | 167853 | + ((u32)aBuf[3]); |
| 167007 | 167854 | } |
| 167855 | + |
| 167856 | +/* |
| 167857 | +** Write an unsigned 32-bit value in big-endian format to the supplied |
| 167858 | +** buffer. |
| 167859 | +*/ |
| 167860 | +static void rbuPutU32(u8 *aBuf, u32 iVal){ |
| 167861 | + aBuf[0] = (iVal >> 24) & 0xFF; |
| 167862 | + aBuf[1] = (iVal >> 16) & 0xFF; |
| 167863 | + aBuf[2] = (iVal >> 8) & 0xFF; |
| 167864 | + aBuf[3] = (iVal >> 0) & 0xFF; |
| 167865 | +} |
| 167866 | + |
| 167867 | +static void rbuPutU16(u8 *aBuf, u16 iVal){ |
| 167868 | + aBuf[0] = (iVal >> 8) & 0xFF; |
| 167869 | + aBuf[1] = (iVal >> 0) & 0xFF; |
| 167870 | +} |
| 167008 | 167871 | |
| 167009 | 167872 | /* |
| 167010 | 167873 | ** Read data from an rbuVfs-file. |
| 167011 | 167874 | */ |
| 167012 | 167875 | static int rbuVfsRead( |
| | @@ -167029,10 +167892,39 @@ |
| 167029 | 167892 | ){ |
| 167030 | 167893 | rc = SQLITE_OK; |
| 167031 | 167894 | memset(zBuf, 0, iAmt); |
| 167032 | 167895 | }else{ |
| 167033 | 167896 | rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst); |
| 167897 | +#if 1 |
| 167898 | + /* If this is being called to read the first page of the target |
| 167899 | + ** database as part of an rbu vacuum operation, synthesize the |
| 167900 | + ** contents of the first page if it does not yet exist. Otherwise, |
| 167901 | + ** SQLite will not check for a *-wal file. */ |
| 167902 | + if( pRbu && rbuIsVacuum(pRbu) |
| 167903 | + && rc==SQLITE_IOERR_SHORT_READ && iOfst==0 |
| 167904 | + && (p->openFlags & SQLITE_OPEN_MAIN_DB) |
| 167905 | + && pRbu->rc==SQLITE_OK |
| 167906 | + ){ |
| 167907 | + sqlite3_file *pFd = (sqlite3_file*)pRbu->pRbuFd; |
| 167908 | + rc = pFd->pMethods->xRead(pFd, zBuf, iAmt, iOfst); |
| 167909 | + if( rc==SQLITE_OK ){ |
| 167910 | + u8 *aBuf = (u8*)zBuf; |
| 167911 | + u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0; |
| 167912 | + rbuPutU32(&aBuf[52], iRoot); /* largest root page number */ |
| 167913 | + rbuPutU32(&aBuf[36], 0); /* number of free pages */ |
| 167914 | + rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */ |
| 167915 | + rbuPutU32(&aBuf[28], 1); /* size of db file in pages */ |
| 167916 | + rbuPutU32(&aBuf[24], pRbu->pRbuFd->iCookie+1); /* Change counter */ |
| 167917 | + |
| 167918 | + if( iAmt>100 ){ |
| 167919 | + memset(&aBuf[100], 0, iAmt-100); |
| 167920 | + rbuPutU16(&aBuf[105], iAmt & 0xFFFF); |
| 167921 | + aBuf[100] = 0x0D; |
| 167922 | + } |
| 167923 | + } |
| 167924 | + } |
| 167925 | +#endif |
| 167034 | 167926 | } |
| 167035 | 167927 | if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){ |
| 167036 | 167928 | /* These look like magic numbers. But they are stable, as they are part |
| 167037 | 167929 | ** of the definition of the SQLite file format, which may not change. */ |
| 167038 | 167930 | u8 *pBuf = (u8*)zBuf; |
| | @@ -167103,11 +167995,24 @@ |
| 167103 | 167995 | /* |
| 167104 | 167996 | ** Return the current file-size of an rbuVfs-file. |
| 167105 | 167997 | */ |
| 167106 | 167998 | static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ |
| 167107 | 167999 | rbu_file *p = (rbu_file *)pFile; |
| 167108 | | - return p->pReal->pMethods->xFileSize(p->pReal, pSize); |
| 168000 | + int rc; |
| 168001 | + rc = p->pReal->pMethods->xFileSize(p->pReal, pSize); |
| 168002 | + |
| 168003 | + /* If this is an RBU vacuum operation and this is the target database, |
| 168004 | + ** pretend that it has at least one page. Otherwise, SQLite will not |
| 168005 | + ** check for the existance of a *-wal file. rbuVfsRead() contains |
| 168006 | + ** similar logic. */ |
| 168007 | + if( rc==SQLITE_OK && *pSize==0 |
| 168008 | + && p->pRbu && rbuIsVacuum(p->pRbu) |
| 168009 | + && (p->openFlags & SQLITE_OPEN_MAIN_DB) |
| 168010 | + ){ |
| 168011 | + *pSize = 1024; |
| 168012 | + } |
| 168013 | + return rc; |
| 167109 | 168014 | } |
| 167110 | 168015 | |
| 167111 | 168016 | /* |
| 167112 | 168017 | ** Lock an rbuVfs-file. |
| 167113 | 168018 | */ |
| | @@ -167115,11 +168020,13 @@ |
| 167115 | 168020 | rbu_file *p = (rbu_file*)pFile; |
| 167116 | 168021 | sqlite3rbu *pRbu = p->pRbu; |
| 167117 | 168022 | int rc = SQLITE_OK; |
| 167118 | 168023 | |
| 167119 | 168024 | assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) ); |
| 167120 | | - if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){ |
| 168025 | + if( eLock==SQLITE_LOCK_EXCLUSIVE |
| 168026 | + && (p->bNolock || (pRbu && pRbu->eStage!=RBU_STAGE_DONE)) |
| 168027 | + ){ |
| 167121 | 168028 | /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this |
| 167122 | 168029 | ** prevents it from checkpointing the database from sqlite3_close(). */ |
| 167123 | 168030 | rc = SQLITE_BUSY; |
| 167124 | 168031 | }else{ |
| 167125 | 168032 | rc = p->pReal->pMethods->xLock(p->pReal, eLock); |
| | @@ -167177,10 +168084,16 @@ |
| 167177 | 168084 | if( p->pWalFd ) p->pWalFd->pRbu = pRbu; |
| 167178 | 168085 | rc = SQLITE_OK; |
| 167179 | 168086 | } |
| 167180 | 168087 | } |
| 167181 | 168088 | return rc; |
| 168089 | + } |
| 168090 | + else if( op==SQLITE_FCNTL_RBUCNT ){ |
| 168091 | + sqlite3rbu *pRbu = (sqlite3rbu*)pArg; |
| 168092 | + pRbu->nRbu++; |
| 168093 | + pRbu->pRbuFd = p; |
| 168094 | + p->bNolock = 1; |
| 167182 | 168095 | } |
| 167183 | 168096 | |
| 167184 | 168097 | rc = xControl(p->pReal, op, pArg); |
| 167185 | 168098 | if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){ |
| 167186 | 168099 | rbu_vfs *pRbuVfs = p->pRbuVfs; |
| | @@ -167340,10 +168253,37 @@ |
| 167340 | 168253 | sqlite3_mutex_enter(pRbuVfs->mutex); |
| 167341 | 168254 | for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){} |
| 167342 | 168255 | sqlite3_mutex_leave(pRbuVfs->mutex); |
| 167343 | 168256 | return pDb; |
| 167344 | 168257 | } |
| 168258 | + |
| 168259 | +/* |
| 168260 | +** A main database named zName has just been opened. The following |
| 168261 | +** function returns a pointer to a buffer owned by SQLite that contains |
| 168262 | +** the name of the *-wal file this db connection will use. SQLite |
| 168263 | +** happens to pass a pointer to this buffer when using xAccess() |
| 168264 | +** or xOpen() to operate on the *-wal file. |
| 168265 | +*/ |
| 168266 | +static const char *rbuMainToWal(const char *zName, int flags){ |
| 168267 | + int n = (int)strlen(zName); |
| 168268 | + const char *z = &zName[n]; |
| 168269 | + if( flags & SQLITE_OPEN_URI ){ |
| 168270 | + int odd = 0; |
| 168271 | + while( 1 ){ |
| 168272 | + if( z[0]==0 ){ |
| 168273 | + odd = 1 - odd; |
| 168274 | + if( odd && z[1]==0 ) break; |
| 168275 | + } |
| 168276 | + z++; |
| 168277 | + } |
| 168278 | + z += 2; |
| 168279 | + }else{ |
| 168280 | + while( *z==0 ) z++; |
| 168281 | + } |
| 168282 | + z += (n + 8 + 1); |
| 168283 | + return z; |
| 168284 | +} |
| 167345 | 168285 | |
| 167346 | 168286 | /* |
| 167347 | 168287 | ** Open an rbu file handle. |
| 167348 | 168288 | */ |
| 167349 | 168289 | static int rbuVfsOpen( |
| | @@ -167376,10 +168316,11 @@ |
| 167376 | 168316 | rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs; |
| 167377 | 168317 | sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs; |
| 167378 | 168318 | rbu_file *pFd = (rbu_file *)pFile; |
| 167379 | 168319 | int rc = SQLITE_OK; |
| 167380 | 168320 | const char *zOpen = zName; |
| 168321 | + int oflags = flags; |
| 167381 | 168322 | |
| 167382 | 168323 | memset(pFd, 0, sizeof(rbu_file)); |
| 167383 | 168324 | pFd->pReal = (sqlite3_file*)&pFd[1]; |
| 167384 | 168325 | pFd->pRbuVfs = pRbuVfs; |
| 167385 | 168326 | pFd->openFlags = flags; |
| | @@ -167388,40 +168329,31 @@ |
| 167388 | 168329 | /* A main database has just been opened. The following block sets |
| 167389 | 168330 | ** (pFd->zWal) to point to a buffer owned by SQLite that contains |
| 167390 | 168331 | ** the name of the *-wal file this db connection will use. SQLite |
| 167391 | 168332 | ** happens to pass a pointer to this buffer when using xAccess() |
| 167392 | 168333 | ** or xOpen() to operate on the *-wal file. */ |
| 167393 | | - int n = (int)strlen(zName); |
| 167394 | | - const char *z = &zName[n]; |
| 167395 | | - if( flags & SQLITE_OPEN_URI ){ |
| 167396 | | - int odd = 0; |
| 167397 | | - while( 1 ){ |
| 167398 | | - if( z[0]==0 ){ |
| 167399 | | - odd = 1 - odd; |
| 167400 | | - if( odd && z[1]==0 ) break; |
| 167401 | | - } |
| 167402 | | - z++; |
| 167403 | | - } |
| 167404 | | - z += 2; |
| 167405 | | - }else{ |
| 167406 | | - while( *z==0 ) z++; |
| 167407 | | - } |
| 167408 | | - z += (n + 8 + 1); |
| 167409 | | - pFd->zWal = z; |
| 168334 | + pFd->zWal = rbuMainToWal(zName, flags); |
| 167410 | 168335 | } |
| 167411 | 168336 | else if( flags & SQLITE_OPEN_WAL ){ |
| 167412 | 168337 | rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName); |
| 167413 | 168338 | if( pDb ){ |
| 167414 | 168339 | if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ |
| 167415 | 168340 | /* This call is to open a *-wal file. Intead, open the *-oal. This |
| 167416 | 168341 | ** code ensures that the string passed to xOpen() is terminated by a |
| 167417 | 168342 | ** pair of '\0' bytes in case the VFS attempts to extract a URI |
| 167418 | 168343 | ** parameter from it. */ |
| 167419 | | - size_t nCopy = strlen(zName); |
| 167420 | | - char *zCopy = sqlite3_malloc64(nCopy+2); |
| 168344 | + const char *zBase = zName; |
| 168345 | + size_t nCopy; |
| 168346 | + char *zCopy; |
| 168347 | + if( rbuIsVacuum(pDb->pRbu) ){ |
| 168348 | + zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main"); |
| 168349 | + zBase = rbuMainToWal(zBase, SQLITE_OPEN_URI); |
| 168350 | + } |
| 168351 | + nCopy = strlen(zBase); |
| 168352 | + zCopy = sqlite3_malloc64(nCopy+2); |
| 167421 | 168353 | if( zCopy ){ |
| 167422 | | - memcpy(zCopy, zName, nCopy); |
| 168354 | + memcpy(zCopy, zBase, nCopy); |
| 167423 | 168355 | zCopy[nCopy-3] = 'o'; |
| 167424 | 168356 | zCopy[nCopy] = '\0'; |
| 167425 | 168357 | zCopy[nCopy+1] = '\0'; |
| 167426 | 168358 | zOpen = (const char*)(pFd->zDel = zCopy); |
| 167427 | 168359 | }else{ |
| | @@ -167431,13 +168363,22 @@ |
| 167431 | 168363 | } |
| 167432 | 168364 | pDb->pWalFd = pFd; |
| 167433 | 168365 | } |
| 167434 | 168366 | } |
| 167435 | 168367 | } |
| 168368 | + |
| 168369 | + if( oflags & SQLITE_OPEN_MAIN_DB |
| 168370 | + && sqlite3_uri_boolean(zName, "rbu_memory", 0) |
| 168371 | + ){ |
| 168372 | + assert( oflags & SQLITE_OPEN_MAIN_DB ); |
| 168373 | + oflags = SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | |
| 168374 | + SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE; |
| 168375 | + zOpen = 0; |
| 168376 | + } |
| 167436 | 168377 | |
| 167437 | 168378 | if( rc==SQLITE_OK ){ |
| 167438 | | - rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, flags, pOutFlags); |
| 168379 | + rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags); |
| 167439 | 168380 | } |
| 167440 | 168381 | if( pFd->pReal->pMethods ){ |
| 167441 | 168382 | /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods |
| 167442 | 168383 | ** pointer and, if the file is a main database file, link it into the |
| 167443 | 168384 | ** mutex protected linked list of all such files. */ |
| | @@ -168678,23 +169619,22 @@ |
| 168678 | 169619 | */ |
| 168679 | 169620 | static int sessionVarintGet(u8 *aBuf, int *piVal){ |
| 168680 | 169621 | return getVarint32(aBuf, *piVal); |
| 168681 | 169622 | } |
| 168682 | 169623 | |
| 169624 | +/* Load an unaligned and unsigned 32-bit integer */ |
| 169625 | +#define SESSION_UINT32(x) (((u32)(x)[0]<<24)|((x)[1]<<16)|((x)[2]<<8)|(x)[3]) |
| 169626 | + |
| 168683 | 169627 | /* |
| 168684 | 169628 | ** Read a 64-bit big-endian integer value from buffer aRec[]. Return |
| 168685 | 169629 | ** the value read. |
| 168686 | 169630 | */ |
| 168687 | 169631 | static sqlite3_int64 sessionGetI64(u8 *aRec){ |
| 168688 | | - return (((sqlite3_int64)aRec[0]) << 56) |
| 168689 | | - + (((sqlite3_int64)aRec[1]) << 48) |
| 168690 | | - + (((sqlite3_int64)aRec[2]) << 40) |
| 168691 | | - + (((sqlite3_int64)aRec[3]) << 32) |
| 168692 | | - + (((sqlite3_int64)aRec[4]) << 24) |
| 168693 | | - + (((sqlite3_int64)aRec[5]) << 16) |
| 168694 | | - + (((sqlite3_int64)aRec[6]) << 8) |
| 168695 | | - + (((sqlite3_int64)aRec[7]) << 0); |
| 169632 | + u64 x = SESSION_UINT32(aRec); |
| 169633 | + u32 y = SESSION_UINT32(aRec+4); |
| 169634 | + x = (x<<32) + y; |
| 169635 | + return (sqlite3_int64)x; |
| 168696 | 169636 | } |
| 168697 | 169637 | |
| 168698 | 169638 | /* |
| 168699 | 169639 | ** Write a 64-bit big-endian integer value to the buffer aBuf[]. |
| 168700 | 169640 | */ |
| | @@ -168992,18 +169932,23 @@ |
| 168992 | 169932 | u8 *a1 = aLeft; /* Cursor to iterate through aLeft */ |
| 168993 | 169933 | u8 *a2 = aRight; /* Cursor to iterate through aRight */ |
| 168994 | 169934 | int iCol; /* Used to iterate through table columns */ |
| 168995 | 169935 | |
| 168996 | 169936 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 168997 | | - int n1 = sessionSerialLen(a1); |
| 168998 | | - int n2 = sessionSerialLen(a2); |
| 168999 | | - |
| 169000 | | - if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){ |
| 169001 | | - return 0; |
| 169002 | | - } |
| 169003 | | - if( pTab->abPK[iCol] || bLeftPkOnly==0 ) a1 += n1; |
| 169004 | | - if( pTab->abPK[iCol] || bRightPkOnly==0 ) a2 += n2; |
| 169937 | + if( pTab->abPK[iCol] ){ |
| 169938 | + int n1 = sessionSerialLen(a1); |
| 169939 | + int n2 = sessionSerialLen(a2); |
| 169940 | + |
| 169941 | + if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){ |
| 169942 | + return 0; |
| 169943 | + } |
| 169944 | + a1 += n1; |
| 169945 | + a2 += n2; |
| 169946 | + }else{ |
| 169947 | + if( bLeftPkOnly==0 ) a1 += sessionSerialLen(a1); |
| 169948 | + if( bRightPkOnly==0 ) a2 += sessionSerialLen(a2); |
| 169949 | + } |
| 169005 | 169950 | } |
| 169006 | 169951 | |
| 169007 | 169952 | return 1; |
| 169008 | 169953 | } |
| 169009 | 169954 | |
| | @@ -169335,13 +170280,13 @@ |
| 169335 | 170280 | int rc; |
| 169336 | 170281 | int nByte; |
| 169337 | 170282 | int nDbCol = 0; |
| 169338 | 170283 | int nThis; |
| 169339 | 170284 | int i; |
| 169340 | | - u8 *pAlloc; |
| 170285 | + u8 *pAlloc = 0; |
| 169341 | 170286 | char **azCol = 0; |
| 169342 | | - u8 *abPK; |
| 170287 | + u8 *abPK = 0; |
| 169343 | 170288 | |
| 169344 | 170289 | assert( pazCol && pabPK ); |
| 169345 | 170290 | |
| 169346 | 170291 | nThis = sqlite3Strlen30(zThis); |
| 169347 | 170292 | zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis); |
| | @@ -169993,13 +170938,13 @@ |
| 169993 | 170938 | for(pTab=pList; pTab; pTab=pNext){ |
| 169994 | 170939 | int i; |
| 169995 | 170940 | pNext = pTab->pNext; |
| 169996 | 170941 | for(i=0; i<pTab->nChange; i++){ |
| 169997 | 170942 | SessionChange *p; |
| 169998 | | - SessionChange *pNext; |
| 169999 | | - for(p=pTab->apChange[i]; p; p=pNext){ |
| 170000 | | - pNext = p->pNext; |
| 170943 | + SessionChange *pNextChange; |
| 170944 | + for(p=pTab->apChange[i]; p; p=pNextChange){ |
| 170945 | + pNextChange = p->pNext; |
| 170001 | 170946 | sqlite3_free(p); |
| 170002 | 170947 | } |
| 170003 | 170948 | } |
| 170004 | 170949 | sqlite3_free((char*)pTab->azCol); /* cast works around VC++ bug */ |
| 170005 | 170950 | sqlite3_free(pTab->apChange); |
| | @@ -171282,11 +172227,10 @@ |
| 171282 | 172227 | if( p->bPatchset && p->op==SQLITE_UPDATE ){ |
| 171283 | 172228 | /* If this is an UPDATE that is part of a patchset, then all PK and |
| 171284 | 172229 | ** modified fields are present in the new.* record. The old.* record |
| 171285 | 172230 | ** is currently completely empty. This block shifts the PK fields from |
| 171286 | 172231 | ** new.* to old.*, to accommodate the code that reads these arrays. */ |
| 171287 | | - int i; |
| 171288 | 172232 | for(i=0; i<p->nCol; i++){ |
| 171289 | 172233 | assert( p->apValue[i]==0 ); |
| 171290 | 172234 | assert( p->abPK[i]==0 || p->apValue[i+p->nCol] ); |
| 171291 | 172235 | if( p->abPK[i] ){ |
| 171292 | 172236 | p->apValue[i] = p->apValue[i+p->nCol]; |
| | @@ -172055,11 +172999,11 @@ |
| 172055 | 172999 | sqlite3_changeset_iter *pIter, /* Changeset iterator */ |
| 172056 | 173000 | int(*xConflict)(void *, int, sqlite3_changeset_iter*), |
| 172057 | 173001 | void *pCtx, /* First argument for conflict handler */ |
| 172058 | 173002 | int *pbReplace /* OUT: Set to true if PK row is found */ |
| 172059 | 173003 | ){ |
| 172060 | | - int res; /* Value returned by conflict handler */ |
| 173004 | + int res = 0; /* Value returned by conflict handler */ |
| 172061 | 173005 | int rc; |
| 172062 | 173006 | int nCol; |
| 172063 | 173007 | int op; |
| 172064 | 173008 | const char *zDummy; |
| 172065 | 173009 | |
| | @@ -175390,15 +176334,17 @@ |
| 175390 | 176334 | ** of the current query. Specifically, a query equivalent to: |
| 175391 | 176335 | ** |
| 175392 | 176336 | ** ... FROM ftstable WHERE ftstable MATCH $p ORDER BY rowid |
| 175393 | 176337 | ** |
| 175394 | 176338 | ** with $p set to a phrase equivalent to the phrase iPhrase of the |
| 175395 | | -** current query is executed. For each row visited, the callback function |
| 175396 | | -** passed as the fourth argument is invoked. The context and API objects |
| 175397 | | -** passed to the callback function may be used to access the properties of |
| 175398 | | -** each matched row. Invoking Api.xUserData() returns a copy of the pointer |
| 175399 | | -** passed as the third argument to pUserData. |
| 176339 | +** current query is executed. Any column filter that applies to |
| 176340 | +** phrase iPhrase of the current query is included in $p. For each |
| 176341 | +** row visited, the callback function passed as the fourth argument |
| 176342 | +** is invoked. The context and API objects passed to the callback |
| 176343 | +** function may be used to access the properties of each matched row. |
| 176344 | +** Invoking Api.xUserData() returns a copy of the pointer passed as |
| 176345 | +** the third argument to pUserData. |
| 175400 | 176346 | ** |
| 175401 | 176347 | ** If the callback function returns any value other than SQLITE_OK, the |
| 175402 | 176348 | ** query is abandoned and the xQueryPhrase function returns immediately. |
| 175403 | 176349 | ** If the returned value is SQLITE_DONE, xQueryPhrase returns SQLITE_OK. |
| 175404 | 176350 | ** Otherwise, the error code is propagated upwards. |
| | @@ -181429,10 +182375,21 @@ |
| 181429 | 182375 | } |
| 181430 | 182376 | if( rc==SQLITE_OK ){ |
| 181431 | 182377 | pNew->pRoot->pNear = (Fts5ExprNearset*)sqlite3Fts5MallocZero(&rc, |
| 181432 | 182378 | sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*)); |
| 181433 | 182379 | } |
| 182380 | + if( rc==SQLITE_OK ){ |
| 182381 | + Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset; |
| 182382 | + if( pColsetOrig ){ |
| 182383 | + int nByte = sizeof(Fts5Colset) + pColsetOrig->nCol * sizeof(int); |
| 182384 | + Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte); |
| 182385 | + if( pColset ){ |
| 182386 | + memcpy(pColset, pColsetOrig, nByte); |
| 182387 | + } |
| 182388 | + pNew->pRoot->pNear->pColset = pColset; |
| 182389 | + } |
| 182390 | + } |
| 181434 | 182391 | |
| 181435 | 182392 | for(i=0; rc==SQLITE_OK && i<pOrig->nTerm; i++){ |
| 181436 | 182393 | int tflags = 0; |
| 181437 | 182394 | Fts5ExprTerm *p; |
| 181438 | 182395 | for(p=&pOrig->aTerm[i]; p && rc==SQLITE_OK; p=p->pSynonym){ |
| | @@ -182777,15 +183734,15 @@ |
| 182777 | 183734 | assert( iCol>=p->iCol ); |
| 182778 | 183735 | if( iCol!=p->iCol ){ |
| 182779 | 183736 | if( pHash->eDetail==FTS5_DETAIL_FULL ){ |
| 182780 | 183737 | pPtr[p->nData++] = 0x01; |
| 182781 | 183738 | p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol); |
| 182782 | | - p->iCol = iCol; |
| 183739 | + p->iCol = (i16)iCol; |
| 182783 | 183740 | p->iPos = 0; |
| 182784 | 183741 | }else{ |
| 182785 | 183742 | bNew = 1; |
| 182786 | | - p->iCol = iPos = iCol; |
| 183743 | + p->iCol = (i16)(iPos = iCol); |
| 182787 | 183744 | } |
| 182788 | 183745 | } |
| 182789 | 183746 | |
| 182790 | 183747 | /* Append the new position offset, if necessary */ |
| 182791 | 183748 | if( bNew ){ |
| | @@ -186204,11 +187161,11 @@ |
| 186204 | 187161 | while( *aiCol<iPrev ){ |
| 186205 | 187162 | aiCol++; |
| 186206 | 187163 | if( aiCol==aiColEnd ) goto setoutputs_col_out; |
| 186207 | 187164 | } |
| 186208 | 187165 | if( *aiCol==iPrev ){ |
| 186209 | | - *aOut++ = (iPrev - iPrevOut) + 2; |
| 187166 | + *aOut++ = (u8)((iPrev - iPrevOut) + 2); |
| 186210 | 187167 | iPrevOut = iPrev; |
| 186211 | 187168 | } |
| 186212 | 187169 | } |
| 186213 | 187170 | |
| 186214 | 187171 | setoutputs_col_out: |
| | @@ -192037,11 +192994,11 @@ |
| 192037 | 192994 | int nArg, /* Number of args */ |
| 192038 | 192995 | sqlite3_value **apUnused /* Function arguments */ |
| 192039 | 192996 | ){ |
| 192040 | 192997 | assert( nArg==0 ); |
| 192041 | 192998 | UNUSED_PARAM2(nArg, apUnused); |
| 192042 | | - sqlite3_result_text(pCtx, "fts5: 2016-03-30 16:23:06 7cf0cab730e2d570c82dd789279ad6501ac598c8", -1, SQLITE_TRANSIENT); |
| 192999 | + sqlite3_result_text(pCtx, "fts5: 2016-05-18 10:57:30 fc49f556e48970561d7ab6a2f24fdd7d9eb81ff2", -1, SQLITE_TRANSIENT); |
| 192043 | 193000 | } |
| 192044 | 193001 | |
| 192045 | 193002 | static int fts5Init(sqlite3 *db){ |
| 192046 | 193003 | static const sqlite3_module fts5Mod = { |
| 192047 | 193004 | /* iVersion */ 2, |
| 192048 | 193005 | |