Fossil SCM
Update the built-in SQLite to version 3.17.0 beta1
Commit
8fe0fefb24e30b6f51836b4b6cf55e0ad441f368
Parent
8e659df6965e817…
2 files changed
+1332
-689
+55
-27
+1332
-689
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | -** version 3.16.2. By combining all the individual C code files into this | |
| 3 | +** version 3.17.0. By combining all the individual C code files into this | |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| @@ -208,10 +208,18 @@ | ||
| 208 | 208 | #ifdef __GNUC__ |
| 209 | 209 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 210 | 210 | #else |
| 211 | 211 | # define GCC_VERSION 0 |
| 212 | 212 | #endif |
| 213 | + | |
| 214 | +/* What version of CLANG is being used. 0 means CLANG is not being used */ | |
| 215 | +#if defined(__clang__) && !defined(_WIN32) | |
| 216 | +# define CLANG_VERSION \ | |
| 217 | + (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) | |
| 218 | +#else | |
| 219 | +# define CLANG_VERSION 0 | |
| 220 | +#endif | |
| 213 | 221 | |
| 214 | 222 | /* Needed for various definitions... */ |
| 215 | 223 | #if defined(__GNUC__) && !defined(_GNU_SOURCE) |
| 216 | 224 | # define _GNU_SOURCE |
| 217 | 225 | #endif |
| @@ -379,13 +387,13 @@ | ||
| 379 | 387 | ** |
| 380 | 388 | ** See also: [sqlite3_libversion()], |
| 381 | 389 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 382 | 390 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 383 | 391 | */ |
| 384 | -#define SQLITE_VERSION "3.16.2" | |
| 385 | -#define SQLITE_VERSION_NUMBER 3016002 | |
| 386 | -#define SQLITE_SOURCE_ID "2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209" | |
| 392 | +#define SQLITE_VERSION "3.17.0" | |
| 393 | +#define SQLITE_VERSION_NUMBER 3017000 | |
| 394 | +#define SQLITE_SOURCE_ID "2017-02-07 13:51:48 a136609c98ed3cc673c5a3c2578d49db3f2518d1" | |
| 387 | 395 | |
| 388 | 396 | /* |
| 389 | 397 | ** CAPI3REF: Run-Time Library Version Numbers |
| 390 | 398 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 391 | 399 | ** |
| @@ -517,11 +525,15 @@ | ||
| 517 | 525 | ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
| 518 | 526 | ** between 0 and +18446744073709551615 inclusive. |
| 519 | 527 | */ |
| 520 | 528 | #ifdef SQLITE_INT64_TYPE |
| 521 | 529 | typedef SQLITE_INT64_TYPE sqlite_int64; |
| 522 | - typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; | |
| 530 | +# ifdef SQLITE_UINT64_TYPE | |
| 531 | + typedef SQLITE_UINT64_TYPE sqlite_uint64; | |
| 532 | +# else | |
| 533 | + typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; | |
| 534 | +# endif | |
| 523 | 535 | #elif defined(_MSC_VER) || defined(__BORLANDC__) |
| 524 | 536 | typedef __int64 sqlite_int64; |
| 525 | 537 | typedef unsigned __int64 sqlite_uint64; |
| 526 | 538 | #else |
| 527 | 539 | typedef long long int sqlite_int64; |
| @@ -830,11 +842,11 @@ | ||
| 830 | 842 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 831 | 843 | ** after reboot following a crash or power loss, the only bytes in a |
| 832 | 844 | ** file that were written at the application level might have changed |
| 833 | 845 | ** and that adjacent bytes, even bytes within the same sector are |
| 834 | 846 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 835 | -** flag indicate that a file cannot be deleted when open. The | |
| 847 | +** flag indicates that a file cannot be deleted when open. The | |
| 836 | 848 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
| 837 | 849 | ** read-only media and cannot be changed even by processes with |
| 838 | 850 | ** elevated privileges. |
| 839 | 851 | */ |
| 840 | 852 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| @@ -980,10 +992,13 @@ | ||
| 980 | 992 | ** <li> [SQLITE_IOCAP_ATOMIC16K] |
| 981 | 993 | ** <li> [SQLITE_IOCAP_ATOMIC32K] |
| 982 | 994 | ** <li> [SQLITE_IOCAP_ATOMIC64K] |
| 983 | 995 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
| 984 | 996 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
| 997 | +** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] | |
| 998 | +** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] | |
| 999 | +** <li> [SQLITE_IOCAP_IMMUTABLE] | |
| 985 | 1000 | ** </ul> |
| 986 | 1001 | ** |
| 987 | 1002 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 988 | 1003 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 989 | 1004 | ** mean that writes of blocks that are nnn bytes in size and |
| @@ -5668,11 +5683,11 @@ | ||
| 5668 | 5683 | ** ^(The update hook is not invoked when internal system tables are |
| 5669 | 5684 | ** modified (i.e. sqlite_master and sqlite_sequence).)^ |
| 5670 | 5685 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
| 5671 | 5686 | ** |
| 5672 | 5687 | ** ^In the current implementation, the update hook |
| 5673 | -** is not invoked when duplication rows are deleted because of an | |
| 5688 | +** is not invoked when conflicting rows are deleted because of an | |
| 5674 | 5689 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
| 5675 | 5690 | ** invoked when rows are deleted using the [truncate optimization]. |
| 5676 | 5691 | ** The exceptions defined in this paragraph might change in a future |
| 5677 | 5692 | ** release of SQLite. |
| 5678 | 5693 | ** |
| @@ -6450,10 +6465,16 @@ | ||
| 6450 | 6465 | ** |
| 6451 | 6466 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 6452 | 6467 | ** [database connection] error code and message accessible via |
| 6453 | 6468 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 6454 | 6469 | ** |
| 6470 | +** A BLOB referenced by sqlite3_blob_open() may be read using the | |
| 6471 | +** [sqlite3_blob_read()] interface and modified by using | |
| 6472 | +** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a | |
| 6473 | +** different row of the same table using the [sqlite3_blob_reopen()] | |
| 6474 | +** interface. However, the column, table, or database of a [BLOB handle] | |
| 6475 | +** cannot be changed after the [BLOB handle] is opened. | |
| 6455 | 6476 | ** |
| 6456 | 6477 | ** ^(If the row that a BLOB handle points to is modified by an |
| 6457 | 6478 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 6458 | 6479 | ** then the BLOB handle is marked as "expired". |
| 6459 | 6480 | ** This is true if any column of the row is changed, even a column |
| @@ -6473,10 +6494,14 @@ | ||
| 6473 | 6494 | ** and the built-in [zeroblob] SQL function may be used to create a |
| 6474 | 6495 | ** zero-filled blob to read or write using the incremental-blob interface. |
| 6475 | 6496 | ** |
| 6476 | 6497 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 6477 | 6498 | ** be released by a call to [sqlite3_blob_close()]. |
| 6499 | +** | |
| 6500 | +** See also: [sqlite3_blob_close()], | |
| 6501 | +** [sqlite3_blob_reopen()], [sqlite3_blob_read()], | |
| 6502 | +** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. | |
| 6478 | 6503 | */ |
| 6479 | 6504 | SQLITE_API int sqlite3_blob_open( |
| 6480 | 6505 | sqlite3*, |
| 6481 | 6506 | const char *zDb, |
| 6482 | 6507 | const char *zTable, |
| @@ -6488,15 +6513,15 @@ | ||
| 6488 | 6513 | |
| 6489 | 6514 | /* |
| 6490 | 6515 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6491 | 6516 | ** METHOD: sqlite3_blob |
| 6492 | 6517 | ** |
| 6493 | -** ^This function is used to move an existing blob handle so that it points | |
| 6518 | +** ^This function is used to move an existing [BLOB handle] so that it points | |
| 6494 | 6519 | ** to a different row of the same database table. ^The new row is identified |
| 6495 | 6520 | ** by the rowid value passed as the second argument. Only the row can be |
| 6496 | 6521 | ** changed. ^The database, table and column on which the blob handle is open |
| 6497 | -** remain the same. Moving an existing blob handle to a new row can be | |
| 6522 | +** remain the same. Moving an existing [BLOB handle] to a new row is | |
| 6498 | 6523 | ** faster than closing the existing handle and opening a new one. |
| 6499 | 6524 | ** |
| 6500 | 6525 | ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
| 6501 | 6526 | ** it must exist and there must be either a blob or text value stored in |
| 6502 | 6527 | ** the nominated column.)^ ^If the new row is not present in the table, or if |
| @@ -8421,22 +8446,22 @@ | ||
| 8421 | 8446 | ** ^These interfaces are only available if SQLite is compiled using the |
| 8422 | 8447 | ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. |
| 8423 | 8448 | ** |
| 8424 | 8449 | ** ^The [sqlite3_preupdate_hook()] interface registers a callback function |
| 8425 | 8450 | ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation |
| 8426 | -** on a [rowid table]. | |
| 8451 | +** on a database table. | |
| 8427 | 8452 | ** ^At most one preupdate hook may be registered at a time on a single |
| 8428 | 8453 | ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides |
| 8429 | 8454 | ** the previous setting. |
| 8430 | 8455 | ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] |
| 8431 | 8456 | ** with a NULL pointer as the second parameter. |
| 8432 | 8457 | ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as |
| 8433 | 8458 | ** the first parameter to callbacks. |
| 8434 | 8459 | ** |
| 8435 | -** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate | |
| 8436 | -** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID] | |
| 8437 | -** tables. | |
| 8460 | +** ^The preupdate hook only fires for changes to real database tables; the | |
| 8461 | +** preupdate hook is not invoked for changes to [virtual tables] or to | |
| 8462 | +** system tables like sqlite_master or sqlite_stat1. | |
| 8438 | 8463 | ** |
| 8439 | 8464 | ** ^The second parameter to the preupdate callback is a pointer to |
| 8440 | 8465 | ** the [database connection] that registered the preupdate hook. |
| 8441 | 8466 | ** ^The third parameter to the preupdate callback is one of the constants |
| 8442 | 8467 | ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the |
| @@ -8446,16 +8471,20 @@ | ||
| 8446 | 8471 | ** will be "main" for the main database or "temp" for TEMP tables or |
| 8447 | 8472 | ** the name given after the AS keyword in the [ATTACH] statement for attached |
| 8448 | 8473 | ** databases.)^ |
| 8449 | 8474 | ** ^The fifth parameter to the preupdate callback is the name of the |
| 8450 | 8475 | ** table that is being modified. |
| 8451 | -** ^The sixth parameter to the preupdate callback is the initial [rowid] of the | |
| 8452 | -** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is | |
| 8453 | -** undefined for SQLITE_INSERT changes. | |
| 8454 | -** ^The seventh parameter to the preupdate callback is the final [rowid] of | |
| 8455 | -** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is | |
| 8456 | -** undefined for SQLITE_DELETE changes. | |
| 8476 | +** | |
| 8477 | +** For an UPDATE or DELETE operation on a [rowid table], the sixth | |
| 8478 | +** parameter passed to the preupdate callback is the initial [rowid] of the | |
| 8479 | +** row being modified or deleted. For an INSERT operation on a rowid table, | |
| 8480 | +** or any operation on a WITHOUT ROWID table, the value of the sixth | |
| 8481 | +** parameter is undefined. For an INSERT or UPDATE on a rowid table the | |
| 8482 | +** seventh parameter is the final rowid value of the row being inserted | |
| 8483 | +** or updated. The value of the seventh parameter passed to the callback | |
| 8484 | +** function is not defined for operations on WITHOUT ROWID tables, or for | |
| 8485 | +** INSERT operations on rowid tables. | |
| 8457 | 8486 | ** |
| 8458 | 8487 | ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], |
| 8459 | 8488 | ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces |
| 8460 | 8489 | ** provide additional information about a preupdate event. These routines |
| 8461 | 8490 | ** may only be called from within a preupdate callback. Invoking any of |
| @@ -9155,11 +9184,12 @@ | ||
| 9155 | 9184 | ** |
| 9156 | 9185 | ** <li> For each row (primary key) that exists in the to-table but not in |
| 9157 | 9186 | ** the from-table, a DELETE record is added to the session object. |
| 9158 | 9187 | ** |
| 9159 | 9188 | ** <li> For each row (primary key) that exists in both tables, but features |
| 9160 | -** different in each, an UPDATE record is added to the session. | |
| 9189 | +** different non-PK values in each, an UPDATE record is added to the | |
| 9190 | +** session. | |
| 9161 | 9191 | ** </ul> |
| 9162 | 9192 | ** |
| 9163 | 9193 | ** To clarify, if this function is called and then a changeset constructed |
| 9164 | 9194 | ** using [sqlite3session_changeset()], then after applying that changeset to |
| 9165 | 9195 | ** database zFrom the contents of the two compatible tables would be |
| @@ -9740,11 +9770,11 @@ | ||
| 9740 | 9770 | ** considered compatible if all of the following are true: |
| 9741 | 9771 | ** |
| 9742 | 9772 | ** <ul> |
| 9743 | 9773 | ** <li> The table has the same name as the name recorded in the |
| 9744 | 9774 | ** changeset, and |
| 9745 | -** <li> The table has the same number of columns as recorded in the | |
| 9775 | +** <li> The table has at least as many columns as recorded in the | |
| 9746 | 9776 | ** changeset, and |
| 9747 | 9777 | ** <li> The table has primary key columns in the same position as |
| 9748 | 9778 | ** recorded in the changeset. |
| 9749 | 9779 | ** </ul> |
| 9750 | 9780 | ** |
| @@ -9785,11 +9815,15 @@ | ||
| 9785 | 9815 | ** the changeset the row is deleted from the target database. |
| 9786 | 9816 | ** |
| 9787 | 9817 | ** If a row with matching primary key values is found, but one or more of |
| 9788 | 9818 | ** the non-primary key fields contains a value different from the original |
| 9789 | 9819 | ** row value stored in the changeset, the conflict-handler function is |
| 9790 | -** invoked with [SQLITE_CHANGESET_DATA] as the second argument. | |
| 9820 | +** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the | |
| 9821 | +** database table has more columns than are recorded in the changeset, | |
| 9822 | +** only the values of those non-primary key fields are compared against | |
| 9823 | +** the current database contents - any trailing database table columns | |
| 9824 | +** are ignored. | |
| 9791 | 9825 | ** |
| 9792 | 9826 | ** If no row with matching primary key values is found in the database, |
| 9793 | 9827 | ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] |
| 9794 | 9828 | ** passed as the second argument. |
| 9795 | 9829 | ** |
| @@ -9800,11 +9834,13 @@ | ||
| 9800 | 9834 | ** operation is attempted because an earlier call to the conflict handler |
| 9801 | 9835 | ** function returned [SQLITE_CHANGESET_REPLACE]. |
| 9802 | 9836 | ** |
| 9803 | 9837 | ** <dt>INSERT Changes<dd> |
| 9804 | 9838 | ** For each INSERT change, an attempt is made to insert the new row into |
| 9805 | -** the database. | |
| 9839 | +** the database. If the changeset row contains fewer fields than the | |
| 9840 | +** database table, the trailing fields are populated with their default | |
| 9841 | +** values. | |
| 9806 | 9842 | ** |
| 9807 | 9843 | ** If the attempt to insert the row fails because the database already |
| 9808 | 9844 | ** contains a row with the same primary key values, the conflict handler |
| 9809 | 9845 | ** function is invoked with the second argument set to |
| 9810 | 9846 | ** [SQLITE_CHANGESET_CONFLICT]. |
| @@ -9818,17 +9854,17 @@ | ||
| 9818 | 9854 | ** |
| 9819 | 9855 | ** <dt>UPDATE Changes<dd> |
| 9820 | 9856 | ** For each UPDATE change, this function checks if the target database |
| 9821 | 9857 | ** contains a row with the same primary key value (or values) as the |
| 9822 | 9858 | ** original row values stored in the changeset. If it does, and the values |
| 9823 | -** stored in all non-primary key columns also match the values stored in | |
| 9824 | -** the changeset the row is updated within the target database. | |
| 9859 | +** stored in all modified non-primary key columns also match the values | |
| 9860 | +** stored in the changeset the row is updated within the target database. | |
| 9825 | 9861 | ** |
| 9826 | 9862 | ** If a row with matching primary key values is found, but one or more of |
| 9827 | -** the non-primary key fields contains a value different from an original | |
| 9828 | -** row value stored in the changeset, the conflict-handler function is | |
| 9829 | -** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since | |
| 9863 | +** the modified non-primary key fields contains a value different from an | |
| 9864 | +** original row value stored in the changeset, the conflict-handler function | |
| 9865 | +** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since | |
| 9830 | 9866 | ** UPDATE changes only contain values for non-primary key fields that are |
| 9831 | 9867 | ** to be modified, only those fields need to match the original values to |
| 9832 | 9868 | ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. |
| 9833 | 9869 | ** |
| 9834 | 9870 | ** If no row with matching primary key values is found in the database, |
| @@ -11537,10 +11573,22 @@ | ||
| 11537 | 11573 | #include <stdlib.h> |
| 11538 | 11574 | #include <string.h> |
| 11539 | 11575 | #include <assert.h> |
| 11540 | 11576 | #include <stddef.h> |
| 11541 | 11577 | |
| 11578 | +/* | |
| 11579 | +** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY. | |
| 11580 | +** This allows better measurements of where memcpy() is used when running | |
| 11581 | +** cachegrind. But this macro version of memcpy() is very slow so it | |
| 11582 | +** should not be used in production. This is a performance measurement | |
| 11583 | +** hack only. | |
| 11584 | +*/ | |
| 11585 | +#ifdef SQLITE_INLINE_MEMCPY | |
| 11586 | +# define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\ | |
| 11587 | + int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);} | |
| 11588 | +#endif | |
| 11589 | + | |
| 11542 | 11590 | /* |
| 11543 | 11591 | ** If compiling for a processor that lacks floating point support, |
| 11544 | 11592 | ** substitute integer for floating-point |
| 11545 | 11593 | */ |
| 11546 | 11594 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| @@ -11621,13 +11669,16 @@ | ||
| 11621 | 11669 | /* |
| 11622 | 11670 | ** The default initial allocation for the pagecache when using separate |
| 11623 | 11671 | ** pagecaches for each database connection. A positive number is the |
| 11624 | 11672 | ** number of pages. A negative number N translations means that a buffer |
| 11625 | 11673 | ** of -1024*N bytes is allocated and used for as many pages as it will hold. |
| 11674 | +** | |
| 11675 | +** The default value of "20" was choosen to minimize the run-time of the | |
| 11676 | +** speedtest1 test program with options: --shrink-memory --reprepare | |
| 11626 | 11677 | */ |
| 11627 | 11678 | #ifndef SQLITE_DEFAULT_PCACHE_INITSZ |
| 11628 | -# define SQLITE_DEFAULT_PCACHE_INITSZ 100 | |
| 11679 | +# define SQLITE_DEFAULT_PCACHE_INITSZ 20 | |
| 11629 | 11680 | #endif |
| 11630 | 11681 | |
| 11631 | 11682 | /* |
| 11632 | 11683 | ** GCC does not define the offsetof() macro so we'll have to do it |
| 11633 | 11684 | ** ourselves. |
| @@ -12346,13 +12397,14 @@ | ||
| 12346 | 12397 | ); |
| 12347 | 12398 | SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*); |
| 12348 | 12399 | SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*); |
| 12349 | 12400 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags); |
| 12350 | 12401 | |
| 12351 | -/* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */ | |
| 12402 | +/* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */ | |
| 12352 | 12403 | #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */ |
| 12353 | 12404 | #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */ |
| 12405 | +#define BTREE_APPEND 0x08 /* Insert is likely an append */ | |
| 12354 | 12406 | |
| 12355 | 12407 | /* An instance of the BtreePayload object describes the content of a single |
| 12356 | 12408 | ** entry in either an index or table btree. |
| 12357 | 12409 | ** |
| 12358 | 12410 | ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain |
| @@ -12379,11 +12431,11 @@ | ||
| 12379 | 12431 | int nData; /* Size of pData. 0 if none. */ |
| 12380 | 12432 | int nZero; /* Extra zero data appended after pData,nData */ |
| 12381 | 12433 | }; |
| 12382 | 12434 | |
| 12383 | 12435 | SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload, |
| 12384 | - int bias, int seekResult); | |
| 12436 | + int flags, int seekResult); | |
| 12385 | 12437 | SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes); |
| 12386 | 12438 | SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| 12387 | 12439 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes); |
| 12388 | 12440 | SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); |
| 12389 | 12441 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes); |
| @@ -12512,12 +12564,11 @@ | ||
| 12512 | 12564 | ** as an instance of the following structure: |
| 12513 | 12565 | */ |
| 12514 | 12566 | struct VdbeOp { |
| 12515 | 12567 | u8 opcode; /* What operation to perform */ |
| 12516 | 12568 | signed char p4type; /* One of the P4_xxx constants for p4 */ |
| 12517 | - u8 notUsed1; | |
| 12518 | - u8 p5; /* Fifth parameter is an unsigned character */ | |
| 12569 | + u16 p5; /* Fifth parameter is an unsigned 16-bit integer */ | |
| 12519 | 12570 | int p1; /* First operand */ |
| 12520 | 12571 | int p2; /* Second parameter (often the jump destination) */ |
| 12521 | 12572 | int p3; /* The third parameter */ |
| 12522 | 12573 | union p4union { /* fourth parameter */ |
| 12523 | 12574 | int i; /* Integer value if p4type==P4_INT32 */ |
| @@ -12874,11 +12925,11 @@ | ||
| 12874 | 12925 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 12875 | 12926 | SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8); |
| 12876 | 12927 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 12877 | 12928 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 12878 | 12929 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 12879 | -SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); | |
| 12930 | +SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5); | |
| 12880 | 12931 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 12881 | 12932 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 12882 | 12933 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 12883 | 12934 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 12884 | 12935 | SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type); |
| @@ -13176,18 +13227,20 @@ | ||
| 13176 | 13227 | SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*); |
| 13177 | 13228 | SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 13178 | 13229 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 13179 | 13230 | SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 13180 | 13231 | SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 13181 | -SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager); | |
| 13232 | +# ifdef SQLITE_DIRECT_OVERFLOW_READ | |
| 13233 | +SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno); | |
| 13234 | +# endif | |
| 13182 | 13235 | # ifdef SQLITE_ENABLE_SNAPSHOT |
| 13183 | 13236 | SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot); |
| 13184 | 13237 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 13185 | 13238 | SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager); |
| 13186 | 13239 | # endif |
| 13187 | 13240 | #else |
| 13188 | -# define sqlite3PagerUseWal(x) 0 | |
| 13241 | +# define sqlite3PagerUseWal(x,y) 0 | |
| 13189 | 13242 | #endif |
| 13190 | 13243 | |
| 13191 | 13244 | #ifdef SQLITE_ENABLE_ZIPVFS |
| 13192 | 13245 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); |
| 13193 | 13246 | #endif |
| @@ -14007,10 +14060,11 @@ | ||
| 14007 | 14060 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| 14008 | 14061 | u8 suppressErr; /* Do not issue error messages if true */ |
| 14009 | 14062 | u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ |
| 14010 | 14063 | u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */ |
| 14011 | 14064 | u8 mTrace; /* zero or more SQLITE_TRACE flags */ |
| 14065 | + u8 skipBtreeMutex; /* True if no shared-cache backends */ | |
| 14012 | 14066 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 14013 | 14067 | u32 magic; /* Magic number for detect library misuse */ |
| 14014 | 14068 | int nChange; /* Value returned by sqlite3_changes() */ |
| 14015 | 14069 | int nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 14016 | 14070 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| @@ -14272,10 +14326,11 @@ | ||
| 14272 | 14326 | #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ |
| 14273 | 14327 | #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ |
| 14274 | 14328 | #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ |
| 14275 | 14329 | #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a |
| 14276 | 14330 | ** single query - might change over time */ |
| 14331 | +#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */ | |
| 14277 | 14332 | |
| 14278 | 14333 | /* |
| 14279 | 14334 | ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 14280 | 14335 | ** used to create the initializers for the FuncDef structures. |
| 14281 | 14336 | ** |
| @@ -15278,11 +15333,11 @@ | ||
| 15278 | 15333 | #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */ |
| 15279 | 15334 | #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */ |
| 15280 | 15335 | #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */ |
| 15281 | 15336 | #define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */ |
| 15282 | 15337 | #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */ |
| 15283 | - /* 0x1000 not currently used */ | |
| 15338 | +#define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */ | |
| 15284 | 15339 | /* 0x2000 not currently used */ |
| 15285 | 15340 | #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */ |
| 15286 | 15341 | /* 0x8000 not currently used */ |
| 15287 | 15342 | |
| 15288 | 15343 | /* Allowed return values from sqlite3WhereIsDistinct() |
| @@ -15739,25 +15794,23 @@ | ||
| 15739 | 15794 | ** OPFLAG_AUXDELETE == BTREE_AUXDELETE |
| 15740 | 15795 | */ |
| 15741 | 15796 | #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */ |
| 15742 | 15797 | /* Also used in P2 (not P5) of OP_Delete */ |
| 15743 | 15798 | #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ |
| 15744 | -#define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */ | |
| 15799 | +#define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */ | |
| 15745 | 15800 | #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ |
| 15746 | 15801 | #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ |
| 15747 | 15802 | #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ |
| 15748 | -#ifdef SQLITE_ENABLE_PREUPDATE_HOOK | |
| 15749 | 15803 | #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */ |
| 15750 | -#endif | |
| 15751 | 15804 | #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ |
| 15752 | 15805 | #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ |
| 15753 | 15806 | #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ |
| 15754 | 15807 | #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ |
| 15755 | 15808 | #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */ |
| 15756 | 15809 | #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ |
| 15757 | 15810 | #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ |
| 15758 | -#define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete: keep cursor position */ | |
| 15811 | +#define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */ | |
| 15759 | 15812 | #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */ |
| 15760 | 15813 | |
| 15761 | 15814 | /* |
| 15762 | 15815 | * Each trigger present in the database schema is stored as an instance of |
| 15763 | 15816 | * struct Trigger. |
| @@ -16414,11 +16467,11 @@ | ||
| 16414 | 16467 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*); |
| 16415 | 16468 | SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int); |
| 16416 | 16469 | SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); |
| 16417 | 16470 | SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int); |
| 16418 | 16471 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); |
| 16419 | -SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8); | |
| 16472 | +SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int); | |
| 16420 | 16473 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| 16421 | 16474 | SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int); |
| 16422 | 16475 | SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int); |
| 16423 | 16476 | SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); |
| 16424 | 16477 | #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ |
| @@ -16476,10 +16529,15 @@ | ||
| 16476 | 16529 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); |
| 16477 | 16530 | SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); |
| 16478 | 16531 | SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); |
| 16479 | 16532 | SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, |
| 16480 | 16533 | u8,u8,int,int*,int*); |
| 16534 | +#ifdef SQLITE_ENABLE_NULL_TRIM | |
| 16535 | +SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe*,Table*); | |
| 16536 | +#else | |
| 16537 | +# define sqlite3SetMakeRecordP5(A,B) | |
| 16538 | +#endif | |
| 16481 | 16539 | SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); |
| 16482 | 16540 | SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*); |
| 16483 | 16541 | SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int); |
| 16484 | 16542 | SQLITE_PRIVATE void sqlite3MultiWrite(Parse*); |
| 16485 | 16543 | SQLITE_PRIVATE void sqlite3MayAbort(Parse*); |
| @@ -16754,12 +16812,14 @@ | ||
| 16754 | 16812 | #endif |
| 16755 | 16813 | |
| 16756 | 16814 | /* |
| 16757 | 16815 | ** The interface to the LEMON-generated parser |
| 16758 | 16816 | */ |
| 16759 | -SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64)); | |
| 16760 | -SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*)); | |
| 16817 | +#ifndef SQLITE_AMALGAMATION | |
| 16818 | +SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64)); | |
| 16819 | +SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*)); | |
| 16820 | +#endif | |
| 16761 | 16821 | SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*); |
| 16762 | 16822 | #ifdef YYTRACKMAXSTACKDEPTH |
| 16763 | 16823 | SQLITE_PRIVATE int sqlite3ParserStackPeak(void*); |
| 16764 | 16824 | #endif |
| 16765 | 16825 | |
| @@ -16865,10 +16925,11 @@ | ||
| 16865 | 16925 | #define sqlite3FkActions(a,b,c,d,e,f) |
| 16866 | 16926 | #define sqlite3FkCheck(a,b,c,d,e,f) |
| 16867 | 16927 | #define sqlite3FkDropTable(a,b,c) |
| 16868 | 16928 | #define sqlite3FkOldmask(a,b) 0 |
| 16869 | 16929 | #define sqlite3FkRequired(a,b,c,d) 0 |
| 16930 | + #define sqlite3FkReferences(a) 0 | |
| 16870 | 16931 | #endif |
| 16871 | 16932 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 16872 | 16933 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*); |
| 16873 | 16934 | SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); |
| 16874 | 16935 | #else |
| @@ -17193,10 +17254,23 @@ | ||
| 17193 | 17254 | ** setting.) |
| 17194 | 17255 | */ |
| 17195 | 17256 | #ifndef SQLITE_STMTJRNL_SPILL |
| 17196 | 17257 | # define SQLITE_STMTJRNL_SPILL (64*1024) |
| 17197 | 17258 | #endif |
| 17259 | + | |
| 17260 | +/* | |
| 17261 | +** The default lookaside-configuration, the format "SZ,N". SZ is the | |
| 17262 | +** number of bytes in each lookaside slot (should be a multiple of 8) | |
| 17263 | +** and N is the number of slots. The lookaside-configuration can be | |
| 17264 | +** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE) | |
| 17265 | +** or at run-time for an individual database connection using | |
| 17266 | +** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE); | |
| 17267 | +*/ | |
| 17268 | +#ifndef SQLITE_DEFAULT_LOOKASIDE | |
| 17269 | +# define SQLITE_DEFAULT_LOOKASIDE 1200,100 | |
| 17270 | +#endif | |
| 17271 | + | |
| 17198 | 17272 | |
| 17199 | 17273 | /* |
| 17200 | 17274 | ** The following singleton contains the global configuration for |
| 17201 | 17275 | ** the SQLite library. |
| 17202 | 17276 | */ |
| @@ -17206,12 +17280,11 @@ | ||
| 17206 | 17280 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 17207 | 17281 | SQLITE_USE_URI, /* bOpenUri */ |
| 17208 | 17282 | SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ |
| 17209 | 17283 | 0x7ffffffe, /* mxStrlen */ |
| 17210 | 17284 | 0, /* neverCorrupt */ |
| 17211 | - 512, /* szLookaside */ | |
| 17212 | - 125, /* nLookaside */ | |
| 17285 | + SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */ | |
| 17213 | 17286 | SQLITE_STMTJRNL_SPILL, /* nStmtSpill */ |
| 17214 | 17287 | {0,0,0,0,0,0,0,0}, /* m */ |
| 17215 | 17288 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
| 17216 | 17289 | {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */ |
| 17217 | 17290 | (void*)0, /* pHeap */ |
| @@ -18219,10 +18292,11 @@ | ||
| 18219 | 18292 | int iNewReg; /* Register for new.* values */ |
| 18220 | 18293 | i64 iKey1; /* First key value passed to hook */ |
| 18221 | 18294 | i64 iKey2; /* Second key value passed to hook */ |
| 18222 | 18295 | Mem *aNew; /* Array of new.* values */ |
| 18223 | 18296 | Table *pTab; /* Schema object being upated */ |
| 18297 | + Index *pPk; /* PK index if pTab is WITHOUT ROWID */ | |
| 18224 | 18298 | }; |
| 18225 | 18299 | |
| 18226 | 18300 | /* |
| 18227 | 18301 | ** Function prototypes |
| 18228 | 18302 | */ |
| @@ -24283,39 +24357,38 @@ | ||
| 24283 | 24357 | |
| 24284 | 24358 | /* |
| 24285 | 24359 | ** Do a memory allocation with statistics and alarms. Assume the |
| 24286 | 24360 | ** lock is already held. |
| 24287 | 24361 | */ |
| 24288 | -static int mallocWithAlarm(int n, void **pp){ | |
| 24289 | - int nFull; | |
| 24362 | +static void mallocWithAlarm(int n, void **pp){ | |
| 24290 | 24363 | void *p; |
| 24364 | + int nFull = 0; | |
| 24291 | 24365 | assert( sqlite3_mutex_held(mem0.mutex) ); |
| 24292 | - nFull = sqlite3GlobalConfig.m.xRoundup(n); | |
| 24293 | 24366 | sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n); |
| 24294 | 24367 | if( mem0.alarmThreshold>0 ){ |
| 24295 | 24368 | sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 24369 | + nFull = sqlite3GlobalConfig.m.xRoundup(n); | |
| 24296 | 24370 | if( nUsed >= mem0.alarmThreshold - nFull ){ |
| 24297 | 24371 | mem0.nearlyFull = 1; |
| 24298 | 24372 | sqlite3MallocAlarm(nFull); |
| 24299 | 24373 | }else{ |
| 24300 | 24374 | mem0.nearlyFull = 0; |
| 24301 | 24375 | } |
| 24302 | 24376 | } |
| 24303 | - p = sqlite3GlobalConfig.m.xMalloc(nFull); | |
| 24377 | + p = sqlite3GlobalConfig.m.xMalloc(n); | |
| 24304 | 24378 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 24305 | 24379 | if( p==0 && mem0.alarmThreshold>0 ){ |
| 24306 | 24380 | sqlite3MallocAlarm(nFull); |
| 24307 | - p = sqlite3GlobalConfig.m.xMalloc(nFull); | |
| 24381 | + p = sqlite3GlobalConfig.m.xMalloc(n); | |
| 24308 | 24382 | } |
| 24309 | 24383 | #endif |
| 24310 | 24384 | if( p ){ |
| 24311 | 24385 | nFull = sqlite3MallocSize(p); |
| 24312 | 24386 | sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull); |
| 24313 | 24387 | sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1); |
| 24314 | 24388 | } |
| 24315 | 24389 | *pp = p; |
| 24316 | - return nFull; | |
| 24317 | 24390 | } |
| 24318 | 24391 | |
| 24319 | 24392 | /* |
| 24320 | 24393 | ** Allocate memory. This routine is like sqlite3_malloc() except that it |
| 24321 | 24394 | ** assumes the memory subsystem has already been initialized. |
| @@ -24951,11 +25024,10 @@ | ||
| 24951 | 25024 | |
| 24952 | 25025 | /* |
| 24953 | 25026 | ** Allowed values for et_info.flags |
| 24954 | 25027 | */ |
| 24955 | 25028 | #define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
| 24956 | -#define FLAG_INTERN 2 /* True if for internal use only */ | |
| 24957 | 25029 | #define FLAG_STRING 4 /* Allow infinity precision */ |
| 24958 | 25030 | |
| 24959 | 25031 | |
| 24960 | 25032 | /* |
| 24961 | 25033 | ** The following table is searched linearly, so it is good to put the |
| @@ -24985,15 +25057,14 @@ | ||
| 24985 | 25057 | { 'i', 10, 1, etRADIX, 0, 0 }, |
| 24986 | 25058 | { 'n', 0, 0, etSIZE, 0, 0 }, |
| 24987 | 25059 | { '%', 0, 0, etPERCENT, 0, 0 }, |
| 24988 | 25060 | { 'p', 16, 0, etPOINTER, 0, 1 }, |
| 24989 | 25061 | |
| 24990 | -/* All the rest have the FLAG_INTERN bit set and are thus for internal | |
| 24991 | -** use only */ | |
| 24992 | - { 'T', 0, 2, etTOKEN, 0, 0 }, | |
| 24993 | - { 'S', 0, 2, etSRCLIST, 0, 0 }, | |
| 24994 | - { 'r', 10, 3, etORDINAL, 0, 0 }, | |
| 25062 | + /* All the rest are undocumented and are for internal use only */ | |
| 25063 | + { 'T', 0, 0, etTOKEN, 0, 0 }, | |
| 25064 | + { 'S', 0, 0, etSRCLIST, 0, 0 }, | |
| 25065 | + { 'r', 10, 1, etORDINAL, 0, 0 }, | |
| 24995 | 25066 | }; |
| 24996 | 25067 | |
| 24997 | 25068 | /* |
| 24998 | 25069 | ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point |
| 24999 | 25070 | ** conversions will work. |
| @@ -25083,11 +25154,10 @@ | ||
| 25083 | 25154 | etByte flag_long; /* True if "l" flag is present */ |
| 25084 | 25155 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 25085 | 25156 | etByte done; /* Loop termination flag */ |
| 25086 | 25157 | etByte xtype = etINVALID; /* Conversion paradigm */ |
| 25087 | 25158 | u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ |
| 25088 | - u8 useIntern; /* Ok to use internal conversions (ex: %T) */ | |
| 25089 | 25159 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 25090 | 25160 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 25091 | 25161 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| 25092 | 25162 | const et_info *infop; /* Pointer to the appropriate info structure */ |
| 25093 | 25163 | char *zOut; /* Rendering buffer */ |
| @@ -25102,17 +25172,15 @@ | ||
| 25102 | 25172 | #endif |
| 25103 | 25173 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 25104 | 25174 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 25105 | 25175 | |
| 25106 | 25176 | bufpt = 0; |
| 25107 | - if( pAccum->printfFlags ){ | |
| 25108 | - if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ | |
| 25109 | - pArgList = va_arg(ap, PrintfArguments*); | |
| 25110 | - } | |
| 25111 | - useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL; | |
| 25177 | + if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ | |
| 25178 | + pArgList = va_arg(ap, PrintfArguments*); | |
| 25179 | + bArgList = 1; | |
| 25112 | 25180 | }else{ |
| 25113 | - bArgList = useIntern = 0; | |
| 25181 | + bArgList = 0; | |
| 25114 | 25182 | } |
| 25115 | 25183 | for(; (c=(*fmt))!=0; ++fmt){ |
| 25116 | 25184 | if( c!='%' ){ |
| 25117 | 25185 | bufpt = (char *)fmt; |
| 25118 | 25186 | #if HAVE_STRCHRNUL |
| @@ -25220,15 +25288,11 @@ | ||
| 25220 | 25288 | infop = &fmtinfo[0]; |
| 25221 | 25289 | xtype = etINVALID; |
| 25222 | 25290 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| 25223 | 25291 | if( c==fmtinfo[idx].fmttype ){ |
| 25224 | 25292 | infop = &fmtinfo[idx]; |
| 25225 | - if( useIntern || (infop->flags & FLAG_INTERN)==0 ){ | |
| 25226 | - xtype = infop->type; | |
| 25227 | - }else{ | |
| 25228 | - return; | |
| 25229 | - } | |
| 25293 | + xtype = infop->type; | |
| 25230 | 25294 | break; |
| 25231 | 25295 | } |
| 25232 | 25296 | } |
| 25233 | 25297 | |
| 25234 | 25298 | /* |
| @@ -25593,22 +25657,28 @@ | ||
| 25593 | 25657 | ** consume, not the length of the output... |
| 25594 | 25658 | ** if( precision>=0 && precision<length ) length = precision; */ |
| 25595 | 25659 | break; |
| 25596 | 25660 | } |
| 25597 | 25661 | case etTOKEN: { |
| 25598 | - Token *pToken = va_arg(ap, Token*); | |
| 25662 | + Token *pToken; | |
| 25663 | + if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; | |
| 25664 | + pToken = va_arg(ap, Token*); | |
| 25599 | 25665 | assert( bArgList==0 ); |
| 25600 | 25666 | if( pToken && pToken->n ){ |
| 25601 | 25667 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
| 25602 | 25668 | } |
| 25603 | 25669 | length = width = 0; |
| 25604 | 25670 | break; |
| 25605 | 25671 | } |
| 25606 | 25672 | case etSRCLIST: { |
| 25607 | - SrcList *pSrc = va_arg(ap, SrcList*); | |
| 25608 | - int k = va_arg(ap, int); | |
| 25609 | - struct SrcList_item *pItem = &pSrc->a[k]; | |
| 25673 | + SrcList *pSrc; | |
| 25674 | + int k; | |
| 25675 | + struct SrcList_item *pItem; | |
| 25676 | + if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; | |
| 25677 | + pSrc = va_arg(ap, SrcList*); | |
| 25678 | + k = va_arg(ap, int); | |
| 25679 | + pItem = &pSrc->a[k]; | |
| 25610 | 25680 | assert( bArgList==0 ); |
| 25611 | 25681 | assert( k>=0 && k<pSrc->nSrc ); |
| 25612 | 25682 | if( pItem->zDatabase ){ |
| 25613 | 25683 | sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); |
| 25614 | 25684 | sqlite3StrAccumAppend(pAccum, ".", 1); |
| @@ -25626,13 +25696,17 @@ | ||
| 25626 | 25696 | ** The text of the conversion is pointed to by "bufpt" and is |
| 25627 | 25697 | ** "length" characters long. The field width is "width". Do |
| 25628 | 25698 | ** the output. |
| 25629 | 25699 | */ |
| 25630 | 25700 | width -= length; |
| 25631 | - if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); | |
| 25632 | - sqlite3StrAccumAppend(pAccum, bufpt, length); | |
| 25633 | - if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); | |
| 25701 | + if( width>0 ){ | |
| 25702 | + if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); | |
| 25703 | + sqlite3StrAccumAppend(pAccum, bufpt, length); | |
| 25704 | + if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); | |
| 25705 | + }else{ | |
| 25706 | + sqlite3StrAccumAppend(pAccum, bufpt, length); | |
| 25707 | + } | |
| 25634 | 25708 | |
| 25635 | 25709 | if( zExtra ){ |
| 25636 | 25710 | sqlite3DbFree(pAccum->db, zExtra); |
| 25637 | 25711 | zExtra = 0; |
| 25638 | 25712 | } |
| @@ -28601,11 +28675,11 @@ | ||
| 28601 | 28675 | #if SQLITE_BYTEORDER==4321 |
| 28602 | 28676 | u32 x; |
| 28603 | 28677 | memcpy(&x,p,4); |
| 28604 | 28678 | return x; |
| 28605 | 28679 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28606 | - && defined(__GNUC__) && GCC_VERSION>=4003000 | |
| 28680 | + && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 28607 | 28681 | u32 x; |
| 28608 | 28682 | memcpy(&x,p,4); |
| 28609 | 28683 | return __builtin_bswap32(x); |
| 28610 | 28684 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28611 | 28685 | && defined(_MSC_VER) && _MSC_VER>=1300 |
| @@ -28619,11 +28693,11 @@ | ||
| 28619 | 28693 | } |
| 28620 | 28694 | SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){ |
| 28621 | 28695 | #if SQLITE_BYTEORDER==4321 |
| 28622 | 28696 | memcpy(p,&v,4); |
| 28623 | 28697 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28624 | - && defined(__GNUC__) && GCC_VERSION>=4003000 | |
| 28698 | + && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 28625 | 28699 | u32 x = __builtin_bswap32(v); |
| 28626 | 28700 | memcpy(p,&x,4); |
| 28627 | 28701 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28628 | 28702 | && defined(_MSC_VER) && _MSC_VER>=1300 |
| 28629 | 28703 | u32 x = _byteswap_ulong(v); |
| @@ -28739,10 +28813,14 @@ | ||
| 28739 | 28813 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 28740 | 28814 | ** Return 0 on success. Or if the operation would have resulted in an |
| 28741 | 28815 | ** overflow, leave *pA unchanged and return 1. |
| 28742 | 28816 | */ |
| 28743 | 28817 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| 28818 | +#if !defined(SQLITE_DISABLE_INTRINSIC) \ | |
| 28819 | + && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) | |
| 28820 | + return __builtin_add_overflow(*pA, iB, pA); | |
| 28821 | +#else | |
| 28744 | 28822 | i64 iA = *pA; |
| 28745 | 28823 | testcase( iA==0 ); testcase( iA==1 ); |
| 28746 | 28824 | testcase( iB==-1 ); testcase( iB==0 ); |
| 28747 | 28825 | if( iB>=0 ){ |
| 28748 | 28826 | testcase( iA>0 && LARGEST_INT64 - iA == iB ); |
| @@ -28753,23 +28831,33 @@ | ||
| 28753 | 28831 | testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); |
| 28754 | 28832 | if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; |
| 28755 | 28833 | } |
| 28756 | 28834 | *pA += iB; |
| 28757 | 28835 | return 0; |
| 28836 | +#endif | |
| 28758 | 28837 | } |
| 28759 | 28838 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 28839 | +#if !defined(SQLITE_DISABLE_INTRINSIC) \ | |
| 28840 | + && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) | |
| 28841 | + return __builtin_sub_overflow(*pA, iB, pA); | |
| 28842 | +#else | |
| 28760 | 28843 | testcase( iB==SMALLEST_INT64+1 ); |
| 28761 | 28844 | if( iB==SMALLEST_INT64 ){ |
| 28762 | 28845 | testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); |
| 28763 | 28846 | if( (*pA)>=0 ) return 1; |
| 28764 | 28847 | *pA -= iB; |
| 28765 | 28848 | return 0; |
| 28766 | 28849 | }else{ |
| 28767 | 28850 | return sqlite3AddInt64(pA, -iB); |
| 28768 | 28851 | } |
| 28852 | +#endif | |
| 28769 | 28853 | } |
| 28770 | 28854 | SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ |
| 28855 | +#if !defined(SQLITE_DISABLE_INTRINSIC) \ | |
| 28856 | + && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) | |
| 28857 | + return __builtin_mul_overflow(*pA, iB, pA); | |
| 28858 | +#else | |
| 28771 | 28859 | i64 iA = *pA; |
| 28772 | 28860 | if( iB>0 ){ |
| 28773 | 28861 | if( iA>LARGEST_INT64/iB ) return 1; |
| 28774 | 28862 | if( iA<SMALLEST_INT64/iB ) return 1; |
| 28775 | 28863 | }else if( iB<0 ){ |
| @@ -28781,10 +28869,11 @@ | ||
| 28781 | 28869 | if( -iA>LARGEST_INT64/-iB ) return 1; |
| 28782 | 28870 | } |
| 28783 | 28871 | } |
| 28784 | 28872 | *pA = iA*iB; |
| 28785 | 28873 | return 0; |
| 28874 | +#endif | |
| 28786 | 28875 | } |
| 28787 | 28876 | |
| 28788 | 28877 | /* |
| 28789 | 28878 | ** Compute the absolute value of a 32-bit signed integer, of possible. Or |
| 28790 | 28879 | ** if the integer has a value of -2147483648, return +2147483647 |
| @@ -47485,18 +47574,24 @@ | ||
| 47485 | 47574 | ** if( pPager->jfd->pMethods ){ ... |
| 47486 | 47575 | */ |
| 47487 | 47576 | #define isOpen(pFd) ((pFd)->pMethods!=0) |
| 47488 | 47577 | |
| 47489 | 47578 | /* |
| 47490 | -** Return true if this pager uses a write-ahead log instead of the usual | |
| 47491 | -** rollback journal. Otherwise false. | |
| 47579 | +** Return true if this pager uses a write-ahead log to read page pgno. | |
| 47580 | +** Return false if the pager reads pgno directly from the database. | |
| 47492 | 47581 | */ |
| 47582 | +#if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_DIRECT_OVERFLOW_READ) | |
| 47583 | +SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno pgno){ | |
| 47584 | + u32 iRead = 0; | |
| 47585 | + int rc; | |
| 47586 | + if( pPager->pWal==0 ) return 0; | |
| 47587 | + rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead); | |
| 47588 | + return rc || iRead; | |
| 47589 | +} | |
| 47590 | +#endif | |
| 47493 | 47591 | #ifndef SQLITE_OMIT_WAL |
| 47494 | -SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager){ | |
| 47495 | - return (pPager->pWal!=0); | |
| 47496 | -} | |
| 47497 | -# define pagerUseWal(x) sqlite3PagerUseWal(x) | |
| 47592 | +# define pagerUseWal(x) ((x)->pWal!=0) | |
| 47498 | 47593 | #else |
| 47499 | 47594 | # define pagerUseWal(x) 0 |
| 47500 | 47595 | # define pagerRollbackWal(x) 0 |
| 47501 | 47596 | # define pagerWalFrames(v,w,x,y) 0 |
| 47502 | 47597 | # define pagerOpenWalIfPresent(z) SQLITE_OK |
| @@ -58624,27 +58719,38 @@ | ||
| 58624 | 58719 | ** Enter the mutexes in accending order by BtShared pointer address |
| 58625 | 58720 | ** to avoid the possibility of deadlock when two threads with |
| 58626 | 58721 | ** two or more btrees in common both try to lock all their btrees |
| 58627 | 58722 | ** at the same instant. |
| 58628 | 58723 | */ |
| 58629 | -SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ | |
| 58724 | +static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){ | |
| 58630 | 58725 | int i; |
| 58726 | + int skipOk = 1; | |
| 58631 | 58727 | Btree *p; |
| 58632 | 58728 | assert( sqlite3_mutex_held(db->mutex) ); |
| 58633 | 58729 | for(i=0; i<db->nDb; i++){ |
| 58634 | 58730 | p = db->aDb[i].pBt; |
| 58635 | - if( p ) sqlite3BtreeEnter(p); | |
| 58731 | + if( p && p->sharable ){ | |
| 58732 | + sqlite3BtreeEnter(p); | |
| 58733 | + skipOk = 0; | |
| 58734 | + } | |
| 58636 | 58735 | } |
| 58736 | + db->skipBtreeMutex = skipOk; | |
| 58637 | 58737 | } |
| 58638 | -SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){ | |
| 58738 | +SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ | |
| 58739 | + if( db->skipBtreeMutex==0 ) btreeEnterAll(db); | |
| 58740 | +} | |
| 58741 | +static void SQLITE_NOINLINE btreeLeaveAll(sqlite3 *db){ | |
| 58639 | 58742 | int i; |
| 58640 | 58743 | Btree *p; |
| 58641 | 58744 | assert( sqlite3_mutex_held(db->mutex) ); |
| 58642 | 58745 | for(i=0; i<db->nDb; i++){ |
| 58643 | 58746 | p = db->aDb[i].pBt; |
| 58644 | 58747 | if( p ) sqlite3BtreeLeave(p); |
| 58645 | 58748 | } |
| 58749 | +} | |
| 58750 | +SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){ | |
| 58751 | + if( db->skipBtreeMutex==0 ) btreeLeaveAll(db); | |
| 58646 | 58752 | } |
| 58647 | 58753 | |
| 58648 | 58754 | #ifndef NDEBUG |
| 58649 | 58755 | /* |
| 58650 | 58756 | ** Return true if the current thread holds the database connection |
| @@ -62097,16 +62203,18 @@ | ||
| 62097 | 62203 | for(i=0; i<nCell; i++){ |
| 62098 | 62204 | u8 *pCell = findCell(pPage, i); |
| 62099 | 62205 | if( eType==PTRMAP_OVERFLOW1 ){ |
| 62100 | 62206 | CellInfo info; |
| 62101 | 62207 | pPage->xParseCell(pPage, pCell, &info); |
| 62102 | - if( info.nLocal<info.nPayload | |
| 62103 | - && pCell+info.nSize-1<=pPage->aData+pPage->maskPage | |
| 62104 | - && iFrom==get4byte(pCell+info.nSize-4) | |
| 62105 | - ){ | |
| 62106 | - put4byte(pCell+info.nSize-4, iTo); | |
| 62107 | - break; | |
| 62208 | + if( info.nLocal<info.nPayload ){ | |
| 62209 | + if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){ | |
| 62210 | + return SQLITE_CORRUPT_BKPT; | |
| 62211 | + } | |
| 62212 | + if( iFrom==get4byte(pCell+info.nSize-4) ){ | |
| 62213 | + put4byte(pCell+info.nSize-4, iTo); | |
| 62214 | + break; | |
| 62215 | + } | |
| 62108 | 62216 | } |
| 62109 | 62217 | }else{ |
| 62110 | 62218 | if( get4byte(pCell)==iFrom ){ |
| 62111 | 62219 | put4byte(pCell, iTo); |
| 62112 | 62220 | break; |
| @@ -62777,11 +62885,16 @@ | ||
| 62777 | 62885 | if( p && p->inTrans==TRANS_WRITE ){ |
| 62778 | 62886 | BtShared *pBt = p->pBt; |
| 62779 | 62887 | assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK ); |
| 62780 | 62888 | assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) ); |
| 62781 | 62889 | sqlite3BtreeEnter(p); |
| 62782 | - rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint); | |
| 62890 | + if( op==SAVEPOINT_ROLLBACK ){ | |
| 62891 | + rc = saveAllCursors(pBt, 0, 0); | |
| 62892 | + } | |
| 62893 | + if( rc==SQLITE_OK ){ | |
| 62894 | + rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint); | |
| 62895 | + } | |
| 62783 | 62896 | if( rc==SQLITE_OK ){ |
| 62784 | 62897 | if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){ |
| 62785 | 62898 | pBt->nPage = 0; |
| 62786 | 62899 | } |
| 62787 | 62900 | rc = newDatabase(pBt); |
| @@ -63163,25 +63276,24 @@ | ||
| 63163 | 63276 | ** for the entry that the pCur cursor is pointing to. The eOp |
| 63164 | 63277 | ** argument is interpreted as follows: |
| 63165 | 63278 | ** |
| 63166 | 63279 | ** 0: The operation is a read. Populate the overflow cache. |
| 63167 | 63280 | ** 1: The operation is a write. Populate the overflow cache. |
| 63168 | -** 2: The operation is a read. Do not populate the overflow cache. | |
| 63169 | 63281 | ** |
| 63170 | 63282 | ** A total of "amt" bytes are read or written beginning at "offset". |
| 63171 | 63283 | ** Data is read to or from the buffer pBuf. |
| 63172 | 63284 | ** |
| 63173 | 63285 | ** The content being read or written might appear on the main page |
| 63174 | 63286 | ** or be scattered out on multiple overflow pages. |
| 63175 | 63287 | ** |
| 63176 | -** If the current cursor entry uses one or more overflow pages and the | |
| 63177 | -** eOp argument is not 2, this function may allocate space for and lazily | |
| 63178 | -** populates the overflow page-list cache array (BtCursor.aOverflow). | |
| 63288 | +** If the current cursor entry uses one or more overflow pages | |
| 63289 | +** this function may allocate space for and lazily populate | |
| 63290 | +** the overflow page-list cache array (BtCursor.aOverflow). | |
| 63179 | 63291 | ** Subsequent calls use this cache to make seeking to the supplied offset |
| 63180 | 63292 | ** more efficient. |
| 63181 | 63293 | ** |
| 63182 | -** Once an overflow page-list cache has been allocated, it may be | |
| 63294 | +** Once an overflow page-list cache has been allocated, it must be | |
| 63183 | 63295 | ** invalidated if some other cursor writes to the same table, or if |
| 63184 | 63296 | ** the cursor is moved to a different row. Additionally, in auto-vacuum |
| 63185 | 63297 | ** mode, the following events may invalidate an overflow page-list cache. |
| 63186 | 63298 | ** |
| 63187 | 63299 | ** * An incremental vacuum, |
| @@ -63199,25 +63311,21 @@ | ||
| 63199 | 63311 | int rc = SQLITE_OK; |
| 63200 | 63312 | int iIdx = 0; |
| 63201 | 63313 | MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */ |
| 63202 | 63314 | BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */ |
| 63203 | 63315 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63204 | - unsigned char * const pBufStart = pBuf; | |
| 63205 | - int bEnd; /* True if reading to end of data */ | |
| 63316 | + unsigned char * const pBufStart = pBuf; /* Start of original out buffer */ | |
| 63206 | 63317 | #endif |
| 63207 | 63318 | |
| 63208 | 63319 | assert( pPage ); |
| 63320 | + assert( eOp==0 || eOp==1 ); | |
| 63209 | 63321 | assert( pCur->eState==CURSOR_VALID ); |
| 63210 | 63322 | assert( pCur->aiIdx[pCur->iPage]<pPage->nCell ); |
| 63211 | 63323 | assert( cursorHoldsMutex(pCur) ); |
| 63212 | - assert( eOp!=2 || offset==0 ); /* Always start from beginning for eOp==2 */ | |
| 63213 | 63324 | |
| 63214 | 63325 | getCellInfo(pCur); |
| 63215 | 63326 | aPayload = pCur->info.pPayload; |
| 63216 | -#ifdef SQLITE_DIRECT_OVERFLOW_READ | |
| 63217 | - bEnd = offset+amt==pCur->info.nPayload; | |
| 63218 | -#endif | |
| 63219 | 63327 | assert( offset+amt <= pCur->info.nPayload ); |
| 63220 | 63328 | |
| 63221 | 63329 | assert( aPayload > pPage->aData ); |
| 63222 | 63330 | if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){ |
| 63223 | 63331 | /* Trying to read or write past the end of the data is an error. The |
| @@ -63232,11 +63340,11 @@ | ||
| 63232 | 63340 | if( offset<pCur->info.nLocal ){ |
| 63233 | 63341 | int a = amt; |
| 63234 | 63342 | if( a+offset>pCur->info.nLocal ){ |
| 63235 | 63343 | a = pCur->info.nLocal - offset; |
| 63236 | 63344 | } |
| 63237 | - rc = copyPayload(&aPayload[offset], pBuf, a, (eOp & 0x01), pPage->pDbPage); | |
| 63345 | + rc = copyPayload(&aPayload[offset], pBuf, a, eOp, pPage->pDbPage); | |
| 63238 | 63346 | offset = 0; |
| 63239 | 63347 | pBuf += a; |
| 63240 | 63348 | amt -= a; |
| 63241 | 63349 | }else{ |
| 63242 | 63350 | offset -= pCur->info.nLocal; |
| @@ -63248,69 +63356,58 @@ | ||
| 63248 | 63356 | Pgno nextPage; |
| 63249 | 63357 | |
| 63250 | 63358 | nextPage = get4byte(&aPayload[pCur->info.nLocal]); |
| 63251 | 63359 | |
| 63252 | 63360 | /* If the BtCursor.aOverflow[] has not been allocated, allocate it now. |
| 63253 | - ** Except, do not allocate aOverflow[] for eOp==2. | |
| 63254 | 63361 | ** |
| 63255 | 63362 | ** The aOverflow[] array is sized at one entry for each overflow page |
| 63256 | 63363 | ** in the overflow chain. The page number of the first overflow page is |
| 63257 | 63364 | ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array |
| 63258 | 63365 | ** means "not yet known" (the cache is lazily populated). |
| 63259 | 63366 | */ |
| 63260 | - if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){ | |
| 63367 | + if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){ | |
| 63261 | 63368 | int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; |
| 63262 | 63369 | if( nOvfl>pCur->nOvflAlloc ){ |
| 63263 | 63370 | Pgno *aNew = (Pgno*)sqlite3Realloc( |
| 63264 | 63371 | pCur->aOverflow, nOvfl*2*sizeof(Pgno) |
| 63265 | 63372 | ); |
| 63266 | 63373 | if( aNew==0 ){ |
| 63267 | - rc = SQLITE_NOMEM_BKPT; | |
| 63374 | + return SQLITE_NOMEM_BKPT; | |
| 63268 | 63375 | }else{ |
| 63269 | 63376 | pCur->nOvflAlloc = nOvfl*2; |
| 63270 | 63377 | pCur->aOverflow = aNew; |
| 63271 | 63378 | } |
| 63272 | 63379 | } |
| 63273 | - if( rc==SQLITE_OK ){ | |
| 63274 | - memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno)); | |
| 63275 | - pCur->curFlags |= BTCF_ValidOvfl; | |
| 63380 | + memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno)); | |
| 63381 | + pCur->curFlags |= BTCF_ValidOvfl; | |
| 63382 | + }else{ | |
| 63383 | + /* If the overflow page-list cache has been allocated and the | |
| 63384 | + ** entry for the first required overflow page is valid, skip | |
| 63385 | + ** directly to it. | |
| 63386 | + */ | |
| 63387 | + if( pCur->aOverflow[offset/ovflSize] ){ | |
| 63388 | + iIdx = (offset/ovflSize); | |
| 63389 | + nextPage = pCur->aOverflow[iIdx]; | |
| 63390 | + offset = (offset%ovflSize); | |
| 63276 | 63391 | } |
| 63277 | 63392 | } |
| 63278 | 63393 | |
| 63279 | - /* If the overflow page-list cache has been allocated and the | |
| 63280 | - ** entry for the first required overflow page is valid, skip | |
| 63281 | - ** directly to it. | |
| 63282 | - */ | |
| 63283 | - if( (pCur->curFlags & BTCF_ValidOvfl)!=0 | |
| 63284 | - && pCur->aOverflow[offset/ovflSize] | |
| 63285 | - ){ | |
| 63286 | - iIdx = (offset/ovflSize); | |
| 63287 | - nextPage = pCur->aOverflow[iIdx]; | |
| 63288 | - offset = (offset%ovflSize); | |
| 63289 | - } | |
| 63290 | - | |
| 63291 | - for( ; rc==SQLITE_OK && amt>0 && nextPage; iIdx++){ | |
| 63292 | - | |
| 63394 | + assert( rc==SQLITE_OK && amt>0 ); | |
| 63395 | + while( nextPage ){ | |
| 63293 | 63396 | /* If required, populate the overflow page-list cache. */ |
| 63294 | - if( (pCur->curFlags & BTCF_ValidOvfl)!=0 ){ | |
| 63295 | - assert( pCur->aOverflow[iIdx]==0 | |
| 63296 | - || pCur->aOverflow[iIdx]==nextPage | |
| 63297 | - || CORRUPT_DB ); | |
| 63298 | - pCur->aOverflow[iIdx] = nextPage; | |
| 63299 | - } | |
| 63397 | + assert( pCur->aOverflow[iIdx]==0 | |
| 63398 | + || pCur->aOverflow[iIdx]==nextPage | |
| 63399 | + || CORRUPT_DB ); | |
| 63400 | + pCur->aOverflow[iIdx] = nextPage; | |
| 63300 | 63401 | |
| 63301 | 63402 | if( offset>=ovflSize ){ |
| 63302 | 63403 | /* The only reason to read this page is to obtain the page |
| 63303 | 63404 | ** number for the next page in the overflow chain. The page |
| 63304 | 63405 | ** data is not required. So first try to lookup the overflow |
| 63305 | 63406 | ** page-list cache, if any, then fall back to the getOverflowPage() |
| 63306 | 63407 | ** function. |
| 63307 | - ** | |
| 63308 | - ** Note that the aOverflow[] array must be allocated because eOp!=2 | |
| 63309 | - ** here. If eOp==2, then offset==0 and this branch is never taken. | |
| 63310 | 63408 | */ |
| 63311 | - assert( eOp!=2 ); | |
| 63312 | 63409 | assert( pCur->curFlags & BTCF_ValidOvfl ); |
| 63313 | 63410 | assert( pCur->pBtree->db==pBt->db ); |
| 63314 | 63411 | if( pCur->aOverflow[iIdx+1] ){ |
| 63315 | 63412 | nextPage = pCur->aOverflow[iIdx+1]; |
| 63316 | 63413 | }else{ |
| @@ -63320,11 +63417,11 @@ | ||
| 63320 | 63417 | }else{ |
| 63321 | 63418 | /* Need to read this page properly. It contains some of the |
| 63322 | 63419 | ** range of data that is being read (eOp==0) or written (eOp!=0). |
| 63323 | 63420 | */ |
| 63324 | 63421 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63325 | - sqlite3_file *fd; | |
| 63422 | + sqlite3_file *fd; /* File from which to do direct overflow read */ | |
| 63326 | 63423 | #endif |
| 63327 | 63424 | int a = amt; |
| 63328 | 63425 | if( a + offset > ovflSize ){ |
| 63329 | 63426 | a = ovflSize - offset; |
| 63330 | 63427 | } |
| @@ -63332,31 +63429,29 @@ | ||
| 63332 | 63429 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63333 | 63430 | /* If all the following are true: |
| 63334 | 63431 | ** |
| 63335 | 63432 | ** 1) this is a read operation, and |
| 63336 | 63433 | ** 2) data is required from the start of this overflow page, and |
| 63337 | - ** 3) the database is file-backed, and | |
| 63338 | - ** 4) there is no open write-transaction, and | |
| 63339 | - ** 5) the database is not a WAL database, | |
| 63340 | - ** 6) all data from the page is being read. | |
| 63341 | - ** 7) at least 4 bytes have already been read into the output buffer | |
| 63434 | + ** 3) there is no open write-transaction, and | |
| 63435 | + ** 4) the database is file-backed, and | |
| 63436 | + ** 5) the page is not in the WAL file | |
| 63437 | + ** 6) at least 4 bytes have already been read into the output buffer | |
| 63342 | 63438 | ** |
| 63343 | 63439 | ** then data can be read directly from the database file into the |
| 63344 | 63440 | ** output buffer, bypassing the page-cache altogether. This speeds |
| 63345 | 63441 | ** up loading large records that span many overflow pages. |
| 63346 | 63442 | */ |
| 63347 | - if( (eOp&0x01)==0 /* (1) */ | |
| 63443 | + if( eOp==0 /* (1) */ | |
| 63348 | 63444 | && offset==0 /* (2) */ |
| 63349 | - && (bEnd || a==ovflSize) /* (6) */ | |
| 63350 | - && pBt->inTransaction==TRANS_READ /* (4) */ | |
| 63351 | - && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */ | |
| 63352 | - && 0==sqlite3PagerUseWal(pBt->pPager) /* (5) */ | |
| 63353 | - && &pBuf[-4]>=pBufStart /* (7) */ | |
| 63445 | + && pBt->inTransaction==TRANS_READ /* (3) */ | |
| 63446 | + && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (4) */ | |
| 63447 | + && 0==sqlite3PagerUseWal(pBt->pPager, nextPage) /* (5) */ | |
| 63448 | + && &pBuf[-4]>=pBufStart /* (6) */ | |
| 63354 | 63449 | ){ |
| 63355 | 63450 | u8 aSave[4]; |
| 63356 | 63451 | u8 *aWrite = &pBuf[-4]; |
| 63357 | - assert( aWrite>=pBufStart ); /* hence (7) */ | |
| 63452 | + assert( aWrite>=pBufStart ); /* due to (6) */ | |
| 63358 | 63453 | memcpy(aSave, aWrite, 4); |
| 63359 | 63454 | rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1)); |
| 63360 | 63455 | nextPage = get4byte(aWrite); |
| 63361 | 63456 | memcpy(aWrite, aSave, 4); |
| 63362 | 63457 | }else |
| @@ -63363,28 +63458,31 @@ | ||
| 63363 | 63458 | #endif |
| 63364 | 63459 | |
| 63365 | 63460 | { |
| 63366 | 63461 | DbPage *pDbPage; |
| 63367 | 63462 | rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage, |
| 63368 | - ((eOp&0x01)==0 ? PAGER_GET_READONLY : 0) | |
| 63463 | + (eOp==0 ? PAGER_GET_READONLY : 0) | |
| 63369 | 63464 | ); |
| 63370 | 63465 | if( rc==SQLITE_OK ){ |
| 63371 | 63466 | aPayload = sqlite3PagerGetData(pDbPage); |
| 63372 | 63467 | nextPage = get4byte(aPayload); |
| 63373 | - rc = copyPayload(&aPayload[offset+4], pBuf, a, (eOp&0x01), pDbPage); | |
| 63468 | + rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage); | |
| 63374 | 63469 | sqlite3PagerUnref(pDbPage); |
| 63375 | 63470 | offset = 0; |
| 63376 | 63471 | } |
| 63377 | 63472 | } |
| 63378 | 63473 | amt -= a; |
| 63474 | + if( amt==0 ) return rc; | |
| 63379 | 63475 | pBuf += a; |
| 63380 | 63476 | } |
| 63477 | + if( rc ) break; | |
| 63478 | + iIdx++; | |
| 63381 | 63479 | } |
| 63382 | 63480 | } |
| 63383 | 63481 | |
| 63384 | 63482 | if( rc==SQLITE_OK && amt>0 ){ |
| 63385 | - return SQLITE_CORRUPT_BKPT; | |
| 63483 | + return SQLITE_CORRUPT_BKPT; /* Overflow chain ends prematurely */ | |
| 63386 | 63484 | } |
| 63387 | 63485 | return rc; |
| 63388 | 63486 | } |
| 63389 | 63487 | |
| 63390 | 63488 | /* |
| @@ -63409,25 +63507,38 @@ | ||
| 63409 | 63507 | assert( pCur->eState==CURSOR_VALID ); |
| 63410 | 63508 | assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] ); |
| 63411 | 63509 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 63412 | 63510 | return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); |
| 63413 | 63511 | } |
| 63512 | + | |
| 63513 | +/* | |
| 63514 | +** This variant of sqlite3BtreePayload() works even if the cursor has not | |
| 63515 | +** in the CURSOR_VALID state. It is only used by the sqlite3_blob_read() | |
| 63516 | +** interface. | |
| 63517 | +*/ | |
| 63414 | 63518 | #ifndef SQLITE_OMIT_INCRBLOB |
| 63415 | -SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ | |
| 63519 | +static SQLITE_NOINLINE int accessPayloadChecked( | |
| 63520 | + BtCursor *pCur, | |
| 63521 | + u32 offset, | |
| 63522 | + u32 amt, | |
| 63523 | + void *pBuf | |
| 63524 | +){ | |
| 63416 | 63525 | int rc; |
| 63417 | 63526 | if ( pCur->eState==CURSOR_INVALID ){ |
| 63418 | 63527 | return SQLITE_ABORT; |
| 63419 | 63528 | } |
| 63420 | 63529 | assert( cursorOwnsBtShared(pCur) ); |
| 63421 | - rc = restoreCursorPosition(pCur); | |
| 63422 | - if( rc==SQLITE_OK ){ | |
| 63423 | - assert( pCur->eState==CURSOR_VALID ); | |
| 63424 | - assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] ); | |
| 63425 | - assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); | |
| 63426 | - rc = accessPayload(pCur, offset, amt, pBuf, 0); | |
| 63427 | - } | |
| 63428 | - return rc; | |
| 63530 | + rc = btreeRestoreCursorPosition(pCur); | |
| 63531 | + return rc ? rc : accessPayload(pCur, offset, amt, pBuf, 0); | |
| 63532 | +} | |
| 63533 | +SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ | |
| 63534 | + if( pCur->eState==CURSOR_VALID ){ | |
| 63535 | + assert( cursorOwnsBtShared(pCur) ); | |
| 63536 | + return accessPayload(pCur, offset, amt, pBuf, 0); | |
| 63537 | + }else{ | |
| 63538 | + return accessPayloadChecked(pCur, offset, amt, pBuf); | |
| 63539 | + } | |
| 63429 | 63540 | } |
| 63430 | 63541 | #endif /* SQLITE_OMIT_INCRBLOB */ |
| 63431 | 63542 | |
| 63432 | 63543 | /* |
| 63433 | 63544 | ** Return a pointer to payload information from the entry that the |
| @@ -63829,13 +63940,30 @@ | ||
| 63829 | 63940 | ){ |
| 63830 | 63941 | if( pCur->info.nKey==intKey ){ |
| 63831 | 63942 | *pRes = 0; |
| 63832 | 63943 | return SQLITE_OK; |
| 63833 | 63944 | } |
| 63834 | - if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){ | |
| 63835 | - *pRes = -1; | |
| 63836 | - return SQLITE_OK; | |
| 63945 | + if( pCur->info.nKey<intKey ){ | |
| 63946 | + if( (pCur->curFlags & BTCF_AtLast)!=0 ){ | |
| 63947 | + *pRes = -1; | |
| 63948 | + return SQLITE_OK; | |
| 63949 | + } | |
| 63950 | + /* If the requested key is one more than the previous key, then | |
| 63951 | + ** try to get there using sqlite3BtreeNext() rather than a full | |
| 63952 | + ** binary search. This is an optimization only. The correct answer | |
| 63953 | + ** is still obtained without this ase, only a little more slowely */ | |
| 63954 | + if( pCur->info.nKey+1==intKey && !pCur->skipNext ){ | |
| 63955 | + *pRes = 0; | |
| 63956 | + rc = sqlite3BtreeNext(pCur, pRes); | |
| 63957 | + if( rc ) return rc; | |
| 63958 | + if( *pRes==0 ){ | |
| 63959 | + getCellInfo(pCur); | |
| 63960 | + if( pCur->info.nKey==intKey ){ | |
| 63961 | + return SQLITE_OK; | |
| 63962 | + } | |
| 63963 | + } | |
| 63964 | + } | |
| 63837 | 63965 | } |
| 63838 | 63966 | } |
| 63839 | 63967 | |
| 63840 | 63968 | if( pIdxKey ){ |
| 63841 | 63969 | xRecordCompare = sqlite3VdbeFindCompare(pIdxKey); |
| @@ -63967,11 +64095,12 @@ | ||
| 63967 | 64095 | if( pCellKey==0 ){ |
| 63968 | 64096 | rc = SQLITE_NOMEM_BKPT; |
| 63969 | 64097 | goto moveto_finish; |
| 63970 | 64098 | } |
| 63971 | 64099 | pCur->aiIdx[pCur->iPage] = (u16)idx; |
| 63972 | - rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2); | |
| 64100 | + rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0); | |
| 64101 | + pCur->curFlags &= ~BTCF_ValidOvfl; | |
| 63973 | 64102 | if( rc ){ |
| 63974 | 64103 | sqlite3_free(pCellKey); |
| 63975 | 64104 | goto moveto_finish; |
| 63976 | 64105 | } |
| 63977 | 64106 | c = xRecordCompare(nCell, pCellKey, pIdxKey); |
| @@ -66010,11 +66139,10 @@ | ||
| 66010 | 66139 | */ |
| 66011 | 66140 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 66012 | 66141 | for(i=0; i<nOld; i++){ |
| 66013 | 66142 | MemPage *p = apOld[i]; |
| 66014 | 66143 | szNew[i] = usableSpace - p->nFree; |
| 66015 | - if( szNew[i]<0 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; } | |
| 66016 | 66144 | for(j=0; j<p->nOverflow; j++){ |
| 66017 | 66145 | szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]); |
| 66018 | 66146 | } |
| 66019 | 66147 | cntNew[i] = cntOld[i]; |
| 66020 | 66148 | } |
| @@ -66689,11 +66817,11 @@ | ||
| 66689 | 66817 | ** to decode the key. |
| 66690 | 66818 | */ |
| 66691 | 66819 | SQLITE_PRIVATE int sqlite3BtreeInsert( |
| 66692 | 66820 | BtCursor *pCur, /* Insert data into the table of this cursor */ |
| 66693 | 66821 | const BtreePayload *pX, /* Content of the row to be inserted */ |
| 66694 | - int appendBias, /* True if this is likely an append */ | |
| 66822 | + int flags, /* True if this is likely an append */ | |
| 66695 | 66823 | int seekResult /* Result of prior MovetoUnpacked() call */ |
| 66696 | 66824 | ){ |
| 66697 | 66825 | int rc; |
| 66698 | 66826 | int loc = seekResult; /* -1: before desired location +1: after */ |
| 66699 | 66827 | int szNew = 0; |
| @@ -66701,10 +66829,12 @@ | ||
| 66701 | 66829 | MemPage *pPage; |
| 66702 | 66830 | Btree *p = pCur->pBtree; |
| 66703 | 66831 | BtShared *pBt = p->pBt; |
| 66704 | 66832 | unsigned char *oldCell; |
| 66705 | 66833 | unsigned char *newCell = 0; |
| 66834 | + | |
| 66835 | + assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND))==flags ); | |
| 66706 | 66836 | |
| 66707 | 66837 | if( pCur->eState==CURSOR_FAULT ){ |
| 66708 | 66838 | assert( pCur->skipNext!=SQLITE_OK ); |
| 66709 | 66839 | return pCur->skipNext; |
| 66710 | 66840 | } |
| @@ -66742,23 +66872,28 @@ | ||
| 66742 | 66872 | assert( pX->pKey==0 ); |
| 66743 | 66873 | /* If this is an insert into a table b-tree, invalidate any incrblob |
| 66744 | 66874 | ** cursors open on the row being replaced */ |
| 66745 | 66875 | invalidateIncrblobCursors(p, pX->nKey, 0); |
| 66746 | 66876 | |
| 66877 | + /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing | |
| 66878 | + ** to a row with the same key as the new entry being inserted. */ | |
| 66879 | + assert( (flags & BTREE_SAVEPOSITION)==0 || | |
| 66880 | + ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) ); | |
| 66881 | + | |
| 66747 | 66882 | /* If the cursor is currently on the last row and we are appending a |
| 66748 | 66883 | ** new row onto the end, set the "loc" to avoid an unnecessary |
| 66749 | 66884 | ** btreeMoveto() call */ |
| 66750 | 66885 | if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){ |
| 66751 | 66886 | loc = 0; |
| 66752 | 66887 | }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0 |
| 66753 | 66888 | && pCur->info.nKey==pX->nKey-1 ){ |
| 66754 | 66889 | loc = -1; |
| 66755 | 66890 | }else if( loc==0 ){ |
| 66756 | - rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc); | |
| 66891 | + rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc); | |
| 66757 | 66892 | if( rc ) return rc; |
| 66758 | 66893 | } |
| 66759 | - }else if( loc==0 ){ | |
| 66894 | + }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){ | |
| 66760 | 66895 | if( pX->nMem ){ |
| 66761 | 66896 | UnpackedRecord r; |
| 66762 | 66897 | r.pKeyInfo = pCur->pKeyInfo; |
| 66763 | 66898 | r.aMem = pX->aMem; |
| 66764 | 66899 | r.nField = pX->nMem; |
| @@ -66765,13 +66900,13 @@ | ||
| 66765 | 66900 | r.default_rc = 0; |
| 66766 | 66901 | r.errCode = 0; |
| 66767 | 66902 | r.r1 = 0; |
| 66768 | 66903 | r.r2 = 0; |
| 66769 | 66904 | r.eqSeen = 0; |
| 66770 | - rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc); | |
| 66905 | + rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc); | |
| 66771 | 66906 | }else{ |
| 66772 | - rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc); | |
| 66907 | + rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc); | |
| 66773 | 66908 | } |
| 66774 | 66909 | if( rc ) return rc; |
| 66775 | 66910 | } |
| 66776 | 66911 | assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) ); |
| 66777 | 66912 | |
| @@ -66855,10 +66990,24 @@ | ||
| 66855 | 66990 | ** fails. Internal data structure corruption will result otherwise. |
| 66856 | 66991 | ** Also, set the cursor state to invalid. This stops saveCursorPosition() |
| 66857 | 66992 | ** from trying to save the current position of the cursor. */ |
| 66858 | 66993 | pCur->apPage[pCur->iPage]->nOverflow = 0; |
| 66859 | 66994 | pCur->eState = CURSOR_INVALID; |
| 66995 | + if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){ | |
| 66996 | + rc = moveToRoot(pCur); | |
| 66997 | + if( pCur->pKeyInfo ){ | |
| 66998 | + assert( pCur->pKey==0 ); | |
| 66999 | + pCur->pKey = sqlite3Malloc( pX->nKey ); | |
| 67000 | + if( pCur->pKey==0 ){ | |
| 67001 | + rc = SQLITE_NOMEM; | |
| 67002 | + }else{ | |
| 67003 | + memcpy(pCur->pKey, pX->pKey, pX->nKey); | |
| 67004 | + } | |
| 67005 | + } | |
| 67006 | + pCur->eState = CURSOR_REQUIRESEEK; | |
| 67007 | + pCur->nKey = pX->nKey; | |
| 67008 | + } | |
| 66860 | 67009 | } |
| 66861 | 67010 | assert( pCur->apPage[pCur->iPage]->nOverflow==0 ); |
| 66862 | 67011 | |
| 66863 | 67012 | end_insert: |
| 66864 | 67013 | return rc; |
| @@ -71765,11 +71914,11 @@ | ||
| 71765 | 71914 | sqlite3VdbeGetOp(p,addr)->p2 = val; |
| 71766 | 71915 | } |
| 71767 | 71916 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){ |
| 71768 | 71917 | sqlite3VdbeGetOp(p,addr)->p3 = val; |
| 71769 | 71918 | } |
| 71770 | -SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){ | |
| 71919 | +SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){ | |
| 71771 | 71920 | assert( p->nOp>0 || p->db->mallocFailed ); |
| 71772 | 71921 | if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5; |
| 71773 | 71922 | } |
| 71774 | 71923 | |
| 71775 | 71924 | /* |
| @@ -73479,64 +73628,63 @@ | ||
| 73479 | 73628 | ** statement transaction is committed. |
| 73480 | 73629 | ** |
| 73481 | 73630 | ** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned. |
| 73482 | 73631 | ** Otherwise SQLITE_OK. |
| 73483 | 73632 | */ |
| 73484 | -SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){ | |
| 73633 | +static SQLITE_NOINLINE int vdbeCloseStatement(Vdbe *p, int eOp){ | |
| 73485 | 73634 | sqlite3 *const db = p->db; |
| 73486 | 73635 | int rc = SQLITE_OK; |
| 73487 | - | |
| 73488 | - /* If p->iStatement is greater than zero, then this Vdbe opened a | |
| 73489 | - ** statement transaction that should be closed here. The only exception | |
| 73490 | - ** is that an IO error may have occurred, causing an emergency rollback. | |
| 73491 | - ** In this case (db->nStatement==0), and there is nothing to do. | |
| 73492 | - */ | |
| 73493 | - if( db->nStatement && p->iStatement ){ | |
| 73494 | - int i; | |
| 73495 | - const int iSavepoint = p->iStatement-1; | |
| 73496 | - | |
| 73497 | - assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE); | |
| 73498 | - assert( db->nStatement>0 ); | |
| 73499 | - assert( p->iStatement==(db->nStatement+db->nSavepoint) ); | |
| 73500 | - | |
| 73501 | - for(i=0; i<db->nDb; i++){ | |
| 73502 | - int rc2 = SQLITE_OK; | |
| 73503 | - Btree *pBt = db->aDb[i].pBt; | |
| 73504 | - if( pBt ){ | |
| 73505 | - if( eOp==SAVEPOINT_ROLLBACK ){ | |
| 73506 | - rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint); | |
| 73507 | - } | |
| 73508 | - if( rc2==SQLITE_OK ){ | |
| 73509 | - rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint); | |
| 73510 | - } | |
| 73511 | - if( rc==SQLITE_OK ){ | |
| 73512 | - rc = rc2; | |
| 73513 | - } | |
| 73514 | - } | |
| 73515 | - } | |
| 73516 | - db->nStatement--; | |
| 73517 | - p->iStatement = 0; | |
| 73518 | - | |
| 73519 | - if( rc==SQLITE_OK ){ | |
| 73520 | - if( eOp==SAVEPOINT_ROLLBACK ){ | |
| 73521 | - rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint); | |
| 73522 | - } | |
| 73523 | - if( rc==SQLITE_OK ){ | |
| 73524 | - rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint); | |
| 73525 | - } | |
| 73526 | - } | |
| 73527 | - | |
| 73528 | - /* If the statement transaction is being rolled back, also restore the | |
| 73529 | - ** database handles deferred constraint counter to the value it had when | |
| 73530 | - ** the statement transaction was opened. */ | |
| 73531 | - if( eOp==SAVEPOINT_ROLLBACK ){ | |
| 73532 | - db->nDeferredCons = p->nStmtDefCons; | |
| 73533 | - db->nDeferredImmCons = p->nStmtDefImmCons; | |
| 73534 | - } | |
| 73535 | - } | |
| 73536 | - return rc; | |
| 73537 | -} | |
| 73636 | + int i; | |
| 73637 | + const int iSavepoint = p->iStatement-1; | |
| 73638 | + | |
| 73639 | + assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE); | |
| 73640 | + assert( db->nStatement>0 ); | |
| 73641 | + assert( p->iStatement==(db->nStatement+db->nSavepoint) ); | |
| 73642 | + | |
| 73643 | + for(i=0; i<db->nDb; i++){ | |
| 73644 | + int rc2 = SQLITE_OK; | |
| 73645 | + Btree *pBt = db->aDb[i].pBt; | |
| 73646 | + if( pBt ){ | |
| 73647 | + if( eOp==SAVEPOINT_ROLLBACK ){ | |
| 73648 | + rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint); | |
| 73649 | + } | |
| 73650 | + if( rc2==SQLITE_OK ){ | |
| 73651 | + rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint); | |
| 73652 | + } | |
| 73653 | + if( rc==SQLITE_OK ){ | |
| 73654 | + rc = rc2; | |
| 73655 | + } | |
| 73656 | + } | |
| 73657 | + } | |
| 73658 | + db->nStatement--; | |
| 73659 | + p->iStatement = 0; | |
| 73660 | + | |
| 73661 | + if( rc==SQLITE_OK ){ | |
| 73662 | + if( eOp==SAVEPOINT_ROLLBACK ){ | |
| 73663 | + rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint); | |
| 73664 | + } | |
| 73665 | + if( rc==SQLITE_OK ){ | |
| 73666 | + rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint); | |
| 73667 | + } | |
| 73668 | + } | |
| 73669 | + | |
| 73670 | + /* If the statement transaction is being rolled back, also restore the | |
| 73671 | + ** database handles deferred constraint counter to the value it had when | |
| 73672 | + ** the statement transaction was opened. */ | |
| 73673 | + if( eOp==SAVEPOINT_ROLLBACK ){ | |
| 73674 | + db->nDeferredCons = p->nStmtDefCons; | |
| 73675 | + db->nDeferredImmCons = p->nStmtDefImmCons; | |
| 73676 | + } | |
| 73677 | + return rc; | |
| 73678 | +} | |
| 73679 | +SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){ | |
| 73680 | + if( p->db->nStatement && p->iStatement ){ | |
| 73681 | + return vdbeCloseStatement(p, eOp); | |
| 73682 | + } | |
| 73683 | + return SQLITE_OK; | |
| 73684 | +} | |
| 73685 | + | |
| 73538 | 73686 | |
| 73539 | 73687 | /* |
| 73540 | 73688 | ** This function is called when a transaction opened by the database |
| 73541 | 73689 | ** handle associated with the VM passed as an argument is about to be |
| 73542 | 73690 | ** committed. If there are outstanding deferred foreign key constraint |
| @@ -75567,14 +75715,14 @@ | ||
| 75567 | 75715 | ** structure itself, using sqlite3DbFree(). |
| 75568 | 75716 | ** |
| 75569 | 75717 | ** This function is used to free UnpackedRecord structures allocated by |
| 75570 | 75718 | ** the vdbeUnpackRecord() function found in vdbeapi.c. |
| 75571 | 75719 | */ |
| 75572 | -static void vdbeFreeUnpacked(sqlite3 *db, UnpackedRecord *p){ | |
| 75720 | +static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){ | |
| 75573 | 75721 | if( p ){ |
| 75574 | 75722 | int i; |
| 75575 | - for(i=0; i<p->nField; i++){ | |
| 75723 | + for(i=0; i<nField; i++){ | |
| 75576 | 75724 | Mem *pMem = &p->aMem[i]; |
| 75577 | 75725 | if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem); |
| 75578 | 75726 | } |
| 75579 | 75727 | sqlite3DbFree(db, p); |
| 75580 | 75728 | } |
| @@ -75603,14 +75751,19 @@ | ||
| 75603 | 75751 | const char *zTbl = pTab->zName; |
| 75604 | 75752 | static const u8 fakeSortOrder = 0; |
| 75605 | 75753 | |
| 75606 | 75754 | assert( db->pPreUpdate==0 ); |
| 75607 | 75755 | memset(&preupdate, 0, sizeof(PreUpdate)); |
| 75608 | - if( op==SQLITE_UPDATE ){ | |
| 75609 | - iKey2 = v->aMem[iReg].u.i; | |
| 75756 | + if( HasRowid(pTab)==0 ){ | |
| 75757 | + iKey1 = iKey2 = 0; | |
| 75758 | + preupdate.pPk = sqlite3PrimaryKeyIndex(pTab); | |
| 75610 | 75759 | }else{ |
| 75611 | - iKey2 = iKey1; | |
| 75760 | + if( op==SQLITE_UPDATE ){ | |
| 75761 | + iKey2 = v->aMem[iReg].u.i; | |
| 75762 | + }else{ | |
| 75763 | + iKey2 = iKey1; | |
| 75764 | + } | |
| 75612 | 75765 | } |
| 75613 | 75766 | |
| 75614 | 75767 | assert( pCsr->nField==pTab->nCol |
| 75615 | 75768 | || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1) |
| 75616 | 75769 | ); |
| @@ -75629,12 +75782,12 @@ | ||
| 75629 | 75782 | |
| 75630 | 75783 | db->pPreUpdate = &preupdate; |
| 75631 | 75784 | db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2); |
| 75632 | 75785 | db->pPreUpdate = 0; |
| 75633 | 75786 | sqlite3DbFree(db, preupdate.aRecord); |
| 75634 | - vdbeFreeUnpacked(db, preupdate.pUnpacked); | |
| 75635 | - vdbeFreeUnpacked(db, preupdate.pNewUnpacked); | |
| 75787 | + vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked); | |
| 75788 | + vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked); | |
| 75636 | 75789 | if( preupdate.aNew ){ |
| 75637 | 75790 | int i; |
| 75638 | 75791 | for(i=0; i<pCsr->nField; i++){ |
| 75639 | 75792 | sqlite3VdbeMemRelease(&preupdate.aNew[i]); |
| 75640 | 75793 | } |
| @@ -77305,18 +77458,22 @@ | ||
| 77305 | 77458 | ** This function is called from within a pre-update callback to retrieve |
| 77306 | 77459 | ** a field of the row currently being updated or deleted. |
| 77307 | 77460 | */ |
| 77308 | 77461 | SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){ |
| 77309 | 77462 | PreUpdate *p = db->pPreUpdate; |
| 77463 | + Mem *pMem; | |
| 77310 | 77464 | int rc = SQLITE_OK; |
| 77311 | 77465 | |
| 77312 | 77466 | /* Test that this call is being made from within an SQLITE_DELETE or |
| 77313 | 77467 | ** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */ |
| 77314 | 77468 | if( !p || p->op==SQLITE_INSERT ){ |
| 77315 | 77469 | rc = SQLITE_MISUSE_BKPT; |
| 77316 | 77470 | goto preupdate_old_out; |
| 77317 | 77471 | } |
| 77472 | + if( p->pPk ){ | |
| 77473 | + iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx); | |
| 77474 | + } | |
| 77318 | 77475 | if( iIdx>=p->pCsr->nField || iIdx<0 ){ |
| 77319 | 77476 | rc = SQLITE_RANGE; |
| 77320 | 77477 | goto preupdate_old_out; |
| 77321 | 77478 | } |
| 77322 | 77479 | |
| @@ -77338,21 +77495,18 @@ | ||
| 77338 | 77495 | goto preupdate_old_out; |
| 77339 | 77496 | } |
| 77340 | 77497 | p->aRecord = aRec; |
| 77341 | 77498 | } |
| 77342 | 77499 | |
| 77343 | - if( iIdx>=p->pUnpacked->nField ){ | |
| 77500 | + pMem = *ppValue = &p->pUnpacked->aMem[iIdx]; | |
| 77501 | + if( iIdx==p->pTab->iPKey ){ | |
| 77502 | + sqlite3VdbeMemSetInt64(pMem, p->iKey1); | |
| 77503 | + }else if( iIdx>=p->pUnpacked->nField ){ | |
| 77344 | 77504 | *ppValue = (sqlite3_value *)columnNullValue(); |
| 77345 | - }else{ | |
| 77346 | - Mem *pMem = *ppValue = &p->pUnpacked->aMem[iIdx]; | |
| 77347 | - *ppValue = &p->pUnpacked->aMem[iIdx]; | |
| 77348 | - if( iIdx==p->pTab->iPKey ){ | |
| 77349 | - sqlite3VdbeMemSetInt64(pMem, p->iKey1); | |
| 77350 | - }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){ | |
| 77351 | - if( pMem->flags & MEM_Int ){ | |
| 77352 | - sqlite3VdbeMemRealify(pMem); | |
| 77353 | - } | |
| 77505 | + }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){ | |
| 77506 | + if( pMem->flags & MEM_Int ){ | |
| 77507 | + sqlite3VdbeMemRealify(pMem); | |
| 77354 | 77508 | } |
| 77355 | 77509 | } |
| 77356 | 77510 | |
| 77357 | 77511 | preupdate_old_out: |
| 77358 | 77512 | sqlite3Error(db, rc); |
| @@ -77401,10 +77555,13 @@ | ||
| 77401 | 77555 | |
| 77402 | 77556 | if( !p || p->op==SQLITE_DELETE ){ |
| 77403 | 77557 | rc = SQLITE_MISUSE_BKPT; |
| 77404 | 77558 | goto preupdate_new_out; |
| 77405 | 77559 | } |
| 77560 | + if( p->pPk && p->op!=SQLITE_UPDATE ){ | |
| 77561 | + iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx); | |
| 77562 | + } | |
| 77406 | 77563 | if( iIdx>=p->pCsr->nField || iIdx<0 ){ |
| 77407 | 77564 | rc = SQLITE_RANGE; |
| 77408 | 77565 | goto preupdate_new_out; |
| 77409 | 77566 | } |
| 77410 | 77567 | |
| @@ -77421,17 +77578,15 @@ | ||
| 77421 | 77578 | rc = SQLITE_NOMEM; |
| 77422 | 77579 | goto preupdate_new_out; |
| 77423 | 77580 | } |
| 77424 | 77581 | p->pNewUnpacked = pUnpack; |
| 77425 | 77582 | } |
| 77426 | - if( iIdx>=pUnpack->nField ){ | |
| 77583 | + pMem = &pUnpack->aMem[iIdx]; | |
| 77584 | + if( iIdx==p->pTab->iPKey ){ | |
| 77585 | + sqlite3VdbeMemSetInt64(pMem, p->iKey2); | |
| 77586 | + }else if( iIdx>=pUnpack->nField ){ | |
| 77427 | 77587 | pMem = (sqlite3_value *)columnNullValue(); |
| 77428 | - }else{ | |
| 77429 | - pMem = &pUnpack->aMem[iIdx]; | |
| 77430 | - if( iIdx==p->pTab->iPKey ){ | |
| 77431 | - sqlite3VdbeMemSetInt64(pMem, p->iKey2); | |
| 77432 | - } | |
| 77433 | 77588 | } |
| 77434 | 77589 | }else{ |
| 77435 | 77590 | /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required |
| 77436 | 77591 | ** value. Make a copy of the cell contents and return a pointer to it. |
| 77437 | 77592 | ** It is not safe to return a pointer to the memory cell itself as the |
| @@ -78404,12 +78559,10 @@ | ||
| 78404 | 78559 | Mem *aMem = p->aMem; /* Copy of p->aMem */ |
| 78405 | 78560 | Mem *pIn1 = 0; /* 1st input operand */ |
| 78406 | 78561 | Mem *pIn2 = 0; /* 2nd input operand */ |
| 78407 | 78562 | Mem *pIn3 = 0; /* 3rd input operand */ |
| 78408 | 78563 | Mem *pOut = 0; /* Output operand */ |
| 78409 | - int *aPermute = 0; /* Permutation of columns for OP_Compare */ | |
| 78410 | - i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ | |
| 78411 | 78564 | #ifdef VDBE_PROFILE |
| 78412 | 78565 | u64 start; /* CPU clock count at start of opcode */ |
| 78413 | 78566 | #endif |
| 78414 | 78567 | /*** INSERT STACK UNION HERE ***/ |
| 78415 | 78568 | |
| @@ -78420,11 +78573,10 @@ | ||
| 78420 | 78573 | ** sqlite3_column_text16() failed. */ |
| 78421 | 78574 | goto no_mem; |
| 78422 | 78575 | } |
| 78423 | 78576 | assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY ); |
| 78424 | 78577 | assert( p->bIsReader || p->readOnly!=0 ); |
| 78425 | - p->rc = SQLITE_OK; | |
| 78426 | 78578 | p->iCurrentTime = 0; |
| 78427 | 78579 | assert( p->explain==0 ); |
| 78428 | 78580 | p->pResultSet = 0; |
| 78429 | 78581 | db->busyHandler.nBusy = 0; |
| 78430 | 78582 | if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| @@ -78781,11 +78933,10 @@ | ||
| 78781 | 78933 | pFrame = p->pFrame; |
| 78782 | 78934 | p->pFrame = pFrame->pParent; |
| 78783 | 78935 | p->nFrame--; |
| 78784 | 78936 | sqlite3VdbeSetChanges(db, p->nChange); |
| 78785 | 78937 | pcx = sqlite3VdbeFrameRestore(pFrame); |
| 78786 | - lastRowid = db->lastRowid; | |
| 78787 | 78938 | if( pOp->p2==OE_Ignore ){ |
| 78788 | 78939 | /* Instruction pcx is the OP_Program that invoked the sub-program |
| 78789 | 78940 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 78790 | 78941 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 78791 | 78942 | ** an IGNORE exception. In this case jump to the address specified |
| @@ -79016,11 +79167,11 @@ | ||
| 79016 | 79167 | assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) ); |
| 79017 | 79168 | pVar = &p->aVar[pOp->p1 - 1]; |
| 79018 | 79169 | if( sqlite3VdbeMemTooBig(pVar) ){ |
| 79019 | 79170 | goto too_big; |
| 79020 | 79171 | } |
| 79021 | - pOut = out2Prerelease(p, pOp); | |
| 79172 | + pOut = &aMem[pOp->p2]; | |
| 79022 | 79173 | sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 79023 | 79174 | UPDATE_MAX_BLOBSIZE(pOut); |
| 79024 | 79175 | break; |
| 79025 | 79176 | } |
| 79026 | 79177 | |
| @@ -79503,13 +79654,11 @@ | ||
| 79503 | 79654 | REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]); |
| 79504 | 79655 | } |
| 79505 | 79656 | #endif |
| 79506 | 79657 | MemSetTypeFlag(pCtx->pOut, MEM_Null); |
| 79507 | 79658 | pCtx->fErrorOrAux = 0; |
| 79508 | - db->lastRowid = lastRowid; | |
| 79509 | 79659 | (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */ |
| 79510 | - lastRowid = db->lastRowid; /* Remember rowid changes made by xSFunc */ | |
| 79511 | 79660 | |
| 79512 | 79661 | /* If the function returned an error, throw an exception */ |
| 79513 | 79662 | if( pCtx->fErrorOrAux ){ |
| 79514 | 79663 | if( pCtx->isError ){ |
| 79515 | 79664 | sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| @@ -79961,12 +80110,12 @@ | ||
| 79961 | 80110 | } |
| 79962 | 80111 | |
| 79963 | 80112 | |
| 79964 | 80113 | /* Opcode: Permutation * * * P4 * |
| 79965 | 80114 | ** |
| 79966 | -** Set the permutation used by the OP_Compare operator to be the array | |
| 79967 | -** of integers in P4. | |
| 80115 | +** Set the permutation used by the OP_Compare operator in the next | |
| 80116 | +** instruction. The permutation is stored in the P4 operand. | |
| 79968 | 80117 | ** |
| 79969 | 80118 | ** The permutation is only valid until the next OP_Compare that has |
| 79970 | 80119 | ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should |
| 79971 | 80120 | ** occur immediately prior to the OP_Compare. |
| 79972 | 80121 | ** |
| @@ -79974,11 +80123,12 @@ | ||
| 79974 | 80123 | ** and does not become part of the permutation. |
| 79975 | 80124 | */ |
| 79976 | 80125 | case OP_Permutation: { |
| 79977 | 80126 | assert( pOp->p4type==P4_INTARRAY ); |
| 79978 | 80127 | assert( pOp->p4.ai ); |
| 79979 | - aPermute = pOp->p4.ai + 1; | |
| 80128 | + assert( pOp[1].opcode==OP_Compare ); | |
| 80129 | + assert( pOp[1].p5 & OPFLAG_PERMUTE ); | |
| 79980 | 80130 | break; |
| 79981 | 80131 | } |
| 79982 | 80132 | |
| 79983 | 80133 | /* Opcode: Compare P1 P2 P3 P4 P5 |
| 79984 | 80134 | ** Synopsis: r[P1@P3] <-> r[P2@P3] |
| @@ -80007,12 +80157,21 @@ | ||
| 80007 | 80157 | int p2; |
| 80008 | 80158 | const KeyInfo *pKeyInfo; |
| 80009 | 80159 | int idx; |
| 80010 | 80160 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 80011 | 80161 | int bRev; /* True for DESCENDING sort order */ |
| 80162 | + int *aPermute; /* The permutation */ | |
| 80012 | 80163 | |
| 80013 | - if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; | |
| 80164 | + if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){ | |
| 80165 | + aPermute = 0; | |
| 80166 | + }else{ | |
| 80167 | + assert( pOp>aOp ); | |
| 80168 | + assert( pOp[-1].opcode==OP_Permutation ); | |
| 80169 | + assert( pOp[-1].p4type==P4_INTARRAY ); | |
| 80170 | + aPermute = pOp[-1].p4.ai + 1; | |
| 80171 | + assert( aPermute!=0 ); | |
| 80172 | + } | |
| 80014 | 80173 | n = pOp->p3; |
| 80015 | 80174 | pKeyInfo = pOp->p4.pKeyInfo; |
| 80016 | 80175 | assert( n>0 ); |
| 80017 | 80176 | assert( pKeyInfo!=0 ); |
| 80018 | 80177 | p1 = pOp->p1; |
| @@ -80041,11 +80200,10 @@ | ||
| 80041 | 80200 | if( iCompare ){ |
| 80042 | 80201 | if( bRev ) iCompare = -iCompare; |
| 80043 | 80202 | break; |
| 80044 | 80203 | } |
| 80045 | 80204 | } |
| 80046 | - aPermute = 0; | |
| 80047 | 80205 | break; |
| 80048 | 80206 | } |
| 80049 | 80207 | |
| 80050 | 80208 | /* Opcode: Jump P1 P2 P3 * * |
| 80051 | 80209 | ** |
| @@ -80597,10 +80755,24 @@ | ||
| 80597 | 80755 | do{ |
| 80598 | 80756 | applyAffinity(pRec++, *(zAffinity++), encoding); |
| 80599 | 80757 | assert( zAffinity[0]==0 || pRec<=pLast ); |
| 80600 | 80758 | }while( zAffinity[0] ); |
| 80601 | 80759 | } |
| 80760 | + | |
| 80761 | +#ifdef SQLITE_ENABLE_NULL_TRIM | |
| 80762 | + /* NULLs can be safely trimmed from the end of the record, as long as | |
| 80763 | + ** as the schema format is 2 or more and none of the omitted columns | |
| 80764 | + ** have a non-NULL default value. Also, the record must be left with | |
| 80765 | + ** at least one field. If P5>0 then it will be one more than the | |
| 80766 | + ** index of the right-most column with a non-NULL default value */ | |
| 80767 | + if( pOp->p5 ){ | |
| 80768 | + while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){ | |
| 80769 | + pLast--; | |
| 80770 | + nField--; | |
| 80771 | + } | |
| 80772 | + } | |
| 80773 | +#endif | |
| 80602 | 80774 | |
| 80603 | 80775 | /* Loop through the elements that will make up the record to figure |
| 80604 | 80776 | ** out how much space is required for the new record. |
| 80605 | 80777 | */ |
| 80606 | 80778 | pRec = pLast; |
| @@ -82187,11 +82359,11 @@ | ||
| 82187 | 82359 | assert( memIsValid(pData) ); |
| 82188 | 82360 | pC = p->apCsr[pOp->p1]; |
| 82189 | 82361 | assert( pC!=0 ); |
| 82190 | 82362 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 82191 | 82363 | assert( pC->uc.pCursor!=0 ); |
| 82192 | - assert( pC->isTable ); | |
| 82364 | + assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable ); | |
| 82193 | 82365 | assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC ); |
| 82194 | 82366 | REGISTER_TRACE(pOp->p2, pData); |
| 82195 | 82367 | |
| 82196 | 82368 | if( pOp->opcode==OP_Insert ){ |
| 82197 | 82369 | pKey = &aMem[pOp->p3]; |
| @@ -82203,18 +82375,17 @@ | ||
| 82203 | 82375 | assert( pOp->opcode==OP_InsertInt ); |
| 82204 | 82376 | x.nKey = pOp->p3; |
| 82205 | 82377 | } |
| 82206 | 82378 | |
| 82207 | 82379 | if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){ |
| 82208 | - assert( pC->isTable ); | |
| 82209 | 82380 | assert( pC->iDb>=0 ); |
| 82210 | 82381 | zDb = db->aDb[pC->iDb].zDbSName; |
| 82211 | 82382 | pTab = pOp->p4.pTab; |
| 82212 | - assert( HasRowid(pTab) ); | |
| 82383 | + assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) ); | |
| 82213 | 82384 | op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); |
| 82214 | 82385 | }else{ |
| 82215 | - pTab = 0; /* Not needed. Silence a comiler warning. */ | |
| 82386 | + pTab = 0; /* Not needed. Silence a compiler warning. */ | |
| 82216 | 82387 | zDb = 0; /* Not needed. Silence a compiler warning. */ |
| 82217 | 82388 | } |
| 82218 | 82389 | |
| 82219 | 82390 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 82220 | 82391 | /* Invoke the pre-update hook, if any */ |
| @@ -82222,14 +82393,15 @@ | ||
| 82222 | 82393 | && pOp->p4type==P4_TABLE |
| 82223 | 82394 | && !(pOp->p5 & OPFLAG_ISUPDATE) |
| 82224 | 82395 | ){ |
| 82225 | 82396 | sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2); |
| 82226 | 82397 | } |
| 82398 | + if( pOp->p5 & OPFLAG_ISNOOP ) break; | |
| 82227 | 82399 | #endif |
| 82228 | 82400 | |
| 82229 | 82401 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 82230 | - if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = x.nKey; | |
| 82402 | + if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey; | |
| 82231 | 82403 | if( pData->flags & MEM_Null ){ |
| 82232 | 82404 | x.pData = 0; |
| 82233 | 82405 | x.nData = 0; |
| 82234 | 82406 | }else{ |
| 82235 | 82407 | assert( pData->flags & (MEM_Blob|MEM_Str) ); |
| @@ -82242,11 +82414,11 @@ | ||
| 82242 | 82414 | }else{ |
| 82243 | 82415 | x.nZero = 0; |
| 82244 | 82416 | } |
| 82245 | 82417 | x.pKey = 0; |
| 82246 | 82418 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, |
| 82247 | - (pOp->p5 & OPFLAG_APPEND)!=0, seekResult | |
| 82419 | + (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), seekResult | |
| 82248 | 82420 | ); |
| 82249 | 82421 | pC->deferredMoveto = 0; |
| 82250 | 82422 | pC->cacheStatus = CACHE_STALE; |
| 82251 | 82423 | |
| 82252 | 82424 | /* Invoke the update-hook if required. */ |
| @@ -82334,12 +82506,15 @@ | ||
| 82334 | 82506 | pTab = 0; /* Not needed. Silence a compiler warning. */ |
| 82335 | 82507 | } |
| 82336 | 82508 | |
| 82337 | 82509 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 82338 | 82510 | /* Invoke the pre-update-hook if required. */ |
| 82339 | - if( db->xPreUpdateCallback && pOp->p4.pTab && HasRowid(pTab) ){ | |
| 82340 | - assert( !(opflags & OPFLAG_ISUPDATE) || (aMem[pOp->p3].flags & MEM_Int) ); | |
| 82511 | + if( db->xPreUpdateCallback && pOp->p4.pTab ){ | |
| 82512 | + assert( !(opflags & OPFLAG_ISUPDATE) | |
| 82513 | + || HasRowid(pTab)==0 | |
| 82514 | + || (aMem[pOp->p3].flags & MEM_Int) | |
| 82515 | + ); | |
| 82341 | 82516 | sqlite3VdbePreUpdateHook(p, pC, |
| 82342 | 82517 | (opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE, |
| 82343 | 82518 | zDb, pTab, pC->movetoTarget, |
| 82344 | 82519 | pOp->p3 |
| 82345 | 82520 | ); |
| @@ -82453,11 +82628,11 @@ | ||
| 82453 | 82628 | if( rc ) goto abort_due_to_error; |
| 82454 | 82629 | p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE; |
| 82455 | 82630 | break; |
| 82456 | 82631 | } |
| 82457 | 82632 | |
| 82458 | -/* Opcode: RowData P1 P2 * * * | |
| 82633 | +/* Opcode: RowData P1 P2 P3 * * | |
| 82459 | 82634 | ** Synopsis: r[P2]=data |
| 82460 | 82635 | ** |
| 82461 | 82636 | ** Write into register P2 the complete row content for the row at |
| 82462 | 82637 | ** which cursor P1 is currently pointing. |
| 82463 | 82638 | ** There is no interpretation of the data. |
| @@ -82467,18 +82642,30 @@ | ||
| 82467 | 82642 | ** If cursor P1 is an index, then the content is the key of the row. |
| 82468 | 82643 | ** If cursor P2 is a table, then the content extracted is the data. |
| 82469 | 82644 | ** |
| 82470 | 82645 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 82471 | 82646 | ** of a real table, not a pseudo-table. |
| 82647 | +** | |
| 82648 | +** If P3!=0 then this opcode is allowed to make an ephermeral pointer | |
| 82649 | +** into the database page. That means that the content of the output | |
| 82650 | +** register will be invalidated as soon as the cursor moves - including | |
| 82651 | +** moves caused by other cursors that "save" the the current cursors | |
| 82652 | +** position in order that they can write to the same table. If P3==0 | |
| 82653 | +** then a copy of the data is made into memory. P3!=0 is faster, but | |
| 82654 | +** P3==0 is safer. | |
| 82655 | +** | |
| 82656 | +** If P3!=0 then the content of the P2 register is unsuitable for use | |
| 82657 | +** in OP_Result and any OP_Result will invalidate the P2 register content. | |
| 82658 | +** The P2 register content is invalidated by opcodes like OP_Function or | |
| 82659 | +** by any use of another cursor pointing to the same table. | |
| 82472 | 82660 | */ |
| 82473 | 82661 | case OP_RowData: { |
| 82474 | 82662 | VdbeCursor *pC; |
| 82475 | 82663 | BtCursor *pCrsr; |
| 82476 | 82664 | u32 n; |
| 82477 | 82665 | |
| 82478 | - pOut = &aMem[pOp->p2]; | |
| 82479 | - memAboutToChange(p, pOut); | |
| 82666 | + pOut = out2Prerelease(p, pOp); | |
| 82480 | 82667 | |
| 82481 | 82668 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 82482 | 82669 | pC = p->apCsr[pOp->p1]; |
| 82483 | 82670 | assert( pC!=0 ); |
| 82484 | 82671 | assert( pC->eCurType==CURTYPE_BTREE ); |
| @@ -82505,18 +82692,13 @@ | ||
| 82505 | 82692 | n = sqlite3BtreePayloadSize(pCrsr); |
| 82506 | 82693 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 82507 | 82694 | goto too_big; |
| 82508 | 82695 | } |
| 82509 | 82696 | testcase( n==0 ); |
| 82510 | - if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){ | |
| 82511 | - goto no_mem; | |
| 82512 | - } | |
| 82513 | - pOut->n = n; | |
| 82514 | - MemSetTypeFlag(pOut, MEM_Blob); | |
| 82515 | - rc = sqlite3BtreePayload(pCrsr, 0, n, pOut->z); | |
| 82697 | + rc = sqlite3VdbeMemFromBtree(pCrsr, 0, n, pOut); | |
| 82516 | 82698 | if( rc ) goto abort_due_to_error; |
| 82517 | - pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ | |
| 82699 | + if( !pOp->p3 ) Deephemeralize(pOut); | |
| 82518 | 82700 | UPDATE_MAX_BLOBSIZE(pOut); |
| 82519 | 82701 | REGISTER_TRACE(pOp->p2, pOut); |
| 82520 | 82702 | break; |
| 82521 | 82703 | } |
| 82522 | 82704 | |
| @@ -82900,11 +83082,11 @@ | ||
| 82900 | 83082 | x.nKey = pIn2->n; |
| 82901 | 83083 | x.pKey = pIn2->z; |
| 82902 | 83084 | x.aMem = aMem + pOp->p3; |
| 82903 | 83085 | x.nMem = (u16)pOp->p4.i; |
| 82904 | 83086 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, |
| 82905 | - (pOp->p5 & OPFLAG_APPEND)!=0, | |
| 83087 | + (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), | |
| 82906 | 83088 | ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 82907 | 83089 | ); |
| 82908 | 83090 | assert( pC->deferredMoveto==0 ); |
| 82909 | 83091 | pC->cacheStatus = CACHE_STALE; |
| 82910 | 83092 | } |
| @@ -83022,11 +83204,10 @@ | ||
| 83022 | 83204 | pTabCur->aAltMap = pOp->p4.ai; |
| 83023 | 83205 | pTabCur->pAltCursor = pC; |
| 83024 | 83206 | }else{ |
| 83025 | 83207 | pOut = out2Prerelease(p, pOp); |
| 83026 | 83208 | pOut->u.i = rowid; |
| 83027 | - pOut->flags = MEM_Int; | |
| 83028 | 83209 | } |
| 83029 | 83210 | }else{ |
| 83030 | 83211 | assert( pOp->opcode==OP_IdxRowid ); |
| 83031 | 83212 | sqlite3VdbeMemSetNull(&aMem[pOp->p2]); |
| 83032 | 83213 | } |
| @@ -83664,11 +83845,11 @@ | ||
| 83664 | 83845 | assert( (int)(pOp - aOp)==pFrame->pc ); |
| 83665 | 83846 | } |
| 83666 | 83847 | |
| 83667 | 83848 | p->nFrame++; |
| 83668 | 83849 | pFrame->pParent = p->pFrame; |
| 83669 | - pFrame->lastRowid = lastRowid; | |
| 83850 | + pFrame->lastRowid = db->lastRowid; | |
| 83670 | 83851 | pFrame->nChange = p->nChange; |
| 83671 | 83852 | pFrame->nDbChange = p->db->nChange; |
| 83672 | 83853 | assert( pFrame->pAuxData==0 ); |
| 83673 | 83854 | pFrame->pAuxData = p->pAuxData; |
| 83674 | 83855 | p->pAuxData = 0; |
| @@ -84605,11 +84786,11 @@ | ||
| 84605 | 84786 | rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); |
| 84606 | 84787 | db->vtabOnConflict = vtabOnConflict; |
| 84607 | 84788 | sqlite3VtabImportErrmsg(p, pVtab); |
| 84608 | 84789 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 84609 | 84790 | assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); |
| 84610 | - db->lastRowid = lastRowid = rowid; | |
| 84791 | + db->lastRowid = rowid; | |
| 84611 | 84792 | } |
| 84612 | 84793 | if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 84613 | 84794 | if( pOp->p5==OE_Ignore ){ |
| 84614 | 84795 | rc = SQLITE_OK; |
| 84615 | 84796 | }else{ |
| @@ -84841,11 +85022,10 @@ | ||
| 84841 | 85022 | |
| 84842 | 85023 | /* This is the only way out of this procedure. We have to |
| 84843 | 85024 | ** release the mutexes on btrees that were acquired at the |
| 84844 | 85025 | ** top. */ |
| 84845 | 85026 | vdbe_return: |
| 84846 | - db->lastRowid = lastRowid; | |
| 84847 | 85027 | testcase( nVmStep>0 ); |
| 84848 | 85028 | p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; |
| 84849 | 85029 | sqlite3VdbeLeave(p); |
| 84850 | 85030 | assert( rc!=SQLITE_OK || nExtraDelete==0 |
| 84851 | 85031 | || sqlite3_strlike("DELETE%",p->zSql,0)!=0 |
| @@ -84905,14 +85085,13 @@ | ||
| 84905 | 85085 | /* |
| 84906 | 85086 | ** Valid sqlite3_blob* handles point to Incrblob structures. |
| 84907 | 85087 | */ |
| 84908 | 85088 | typedef struct Incrblob Incrblob; |
| 84909 | 85089 | struct Incrblob { |
| 84910 | - int flags; /* Copy of "flags" passed to sqlite3_blob_open() */ | |
| 84911 | 85090 | int nByte; /* Size of open blob, in bytes */ |
| 84912 | 85091 | int iOffset; /* Byte offset of blob in cursor data */ |
| 84913 | - int iCol; /* Table column this handle is open on */ | |
| 85092 | + u16 iCol; /* Table column this handle is open on */ | |
| 84914 | 85093 | BtCursor *pCsr; /* Cursor pointing at blob row */ |
| 84915 | 85094 | sqlite3_stmt *pStmt; /* Statement holding cursor open */ |
| 84916 | 85095 | sqlite3 *db; /* The associated database */ |
| 84917 | 85096 | char *zDb; /* Database name */ |
| 84918 | 85097 | Table *pTab; /* Table object */ |
| @@ -84939,21 +85118,31 @@ | ||
| 84939 | 85118 | static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr){ |
| 84940 | 85119 | int rc; /* Error code */ |
| 84941 | 85120 | char *zErr = 0; /* Error message */ |
| 84942 | 85121 | Vdbe *v = (Vdbe *)p->pStmt; |
| 84943 | 85122 | |
| 84944 | - /* Set the value of the SQL statements only variable to integer iRow. | |
| 84945 | - ** This is done directly instead of using sqlite3_bind_int64() to avoid | |
| 84946 | - ** triggering asserts related to mutexes. | |
| 85123 | + /* Set the value of register r[1] in the SQL statement to integer iRow. | |
| 85124 | + ** This is done directly as a performance optimization | |
| 84947 | 85125 | */ |
| 84948 | - assert( v->aVar[0].flags&MEM_Int ); | |
| 84949 | - v->aVar[0].u.i = iRow; | |
| 85126 | + v->aMem[1].flags = MEM_Int; | |
| 85127 | + v->aMem[1].u.i = iRow; | |
| 84950 | 85128 | |
| 84951 | - rc = sqlite3_step(p->pStmt); | |
| 85129 | + /* If the statement has been run before (and is paused at the OP_ResultRow) | |
| 85130 | + ** then back it up to the point where it does the OP_SeekRowid. This could | |
| 85131 | + ** have been down with an extra OP_Goto, but simply setting the program | |
| 85132 | + ** counter is faster. */ | |
| 85133 | + if( v->pc>3 ){ | |
| 85134 | + v->pc = 3; | |
| 85135 | + rc = sqlite3VdbeExec(v); | |
| 85136 | + }else{ | |
| 85137 | + rc = sqlite3_step(p->pStmt); | |
| 85138 | + } | |
| 84952 | 85139 | if( rc==SQLITE_ROW ){ |
| 84953 | 85140 | VdbeCursor *pC = v->apCsr[0]; |
| 84954 | - u32 type = pC->aType[p->iCol]; | |
| 85141 | + u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0; | |
| 85142 | + testcase( pC->nHdrParsed==p->iCol ); | |
| 85143 | + testcase( pC->nHdrParsed==p->iCol+1 ); | |
| 84955 | 85144 | if( type<12 ){ |
| 84956 | 85145 | zErr = sqlite3MPrintf(p->db, "cannot open value of type %s", |
| 84957 | 85146 | type==0?"null": type==7?"real": "integer" |
| 84958 | 85147 | ); |
| 84959 | 85148 | rc = SQLITE_ERROR; |
| @@ -84994,11 +85183,11 @@ | ||
| 84994 | 85183 | sqlite3* db, /* The database connection */ |
| 84995 | 85184 | const char *zDb, /* The attached database containing the blob */ |
| 84996 | 85185 | const char *zTable, /* The table containing the blob */ |
| 84997 | 85186 | const char *zColumn, /* The column containing the blob */ |
| 84998 | 85187 | sqlite_int64 iRow, /* The row containing the glob */ |
| 84999 | - int flags, /* True -> read/write access, false -> read-only */ | |
| 85188 | + int wrFlag, /* True -> read/write access, false -> read-only */ | |
| 85000 | 85189 | sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */ |
| 85001 | 85190 | ){ |
| 85002 | 85191 | int nAttempt = 0; |
| 85003 | 85192 | int iCol; /* Index of zColumn in row-record */ |
| 85004 | 85193 | int rc = SQLITE_OK; |
| @@ -85016,11 +85205,11 @@ | ||
| 85016 | 85205 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 85017 | 85206 | if( !sqlite3SafetyCheckOk(db) || zTable==0 ){ |
| 85018 | 85207 | return SQLITE_MISUSE_BKPT; |
| 85019 | 85208 | } |
| 85020 | 85209 | #endif |
| 85021 | - flags = !!flags; /* flags = (flags ? 1 : 0); */ | |
| 85210 | + wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */ | |
| 85022 | 85211 | |
| 85023 | 85212 | sqlite3_mutex_enter(db->mutex); |
| 85024 | 85213 | |
| 85025 | 85214 | pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob)); |
| 85026 | 85215 | if( !pBlob ) goto blob_open_out; |
| @@ -85076,13 +85265,12 @@ | ||
| 85076 | 85265 | goto blob_open_out; |
| 85077 | 85266 | } |
| 85078 | 85267 | |
| 85079 | 85268 | /* If the value is being opened for writing, check that the |
| 85080 | 85269 | ** column is not indexed, and that it is not part of a foreign key. |
| 85081 | - ** It is against the rules to open a column to which either of these | |
| 85082 | - ** descriptions applies for writing. */ | |
| 85083 | - if( flags ){ | |
| 85270 | + */ | |
| 85271 | + if( wrFlag ){ | |
| 85084 | 85272 | const char *zFault = 0; |
| 85085 | 85273 | Index *pIdx; |
| 85086 | 85274 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 85087 | 85275 | if( db->flags&SQLITE_ForeignKeys ){ |
| 85088 | 85276 | /* Check that the column is not part of an FK child key definition. It |
| @@ -85139,22 +85327,21 @@ | ||
| 85139 | 85327 | */ |
| 85140 | 85328 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 85141 | 85329 | static const VdbeOpList openBlob[] = { |
| 85142 | 85330 | {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */ |
| 85143 | 85331 | {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */ |
| 85144 | - {OP_Variable, 1, 1, 0}, /* 2: Move ?1 into reg[1] */ | |
| 85145 | - {OP_NotExists, 0, 7, 1}, /* 3: Seek the cursor */ | |
| 85146 | - {OP_Column, 0, 0, 1}, /* 4 */ | |
| 85147 | - {OP_ResultRow, 1, 0, 0}, /* 5 */ | |
| 85148 | - {OP_Goto, 0, 2, 0}, /* 6 */ | |
| 85149 | - {OP_Halt, 0, 0, 0}, /* 7 */ | |
| 85332 | + /* blobSeekToRow() will initialize r[1] to the desired rowid */ | |
| 85333 | + {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */ | |
| 85334 | + {OP_Column, 0, 0, 1}, /* 3 */ | |
| 85335 | + {OP_ResultRow, 1, 0, 0}, /* 4 */ | |
| 85336 | + {OP_Halt, 0, 0, 0}, /* 5 */ | |
| 85150 | 85337 | }; |
| 85151 | 85338 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 85152 | 85339 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 85153 | 85340 | VdbeOp *aOp; |
| 85154 | 85341 | |
| 85155 | - sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags, | |
| 85342 | + sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag, | |
| 85156 | 85343 | pTab->pSchema->schema_cookie, |
| 85157 | 85344 | pTab->pSchema->iGeneration); |
| 85158 | 85345 | sqlite3VdbeChangeP5(v, 1); |
| 85159 | 85346 | aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); |
| 85160 | 85347 | |
| @@ -85167,19 +85354,19 @@ | ||
| 85167 | 85354 | #ifdef SQLITE_OMIT_SHARED_CACHE |
| 85168 | 85355 | aOp[0].opcode = OP_Noop; |
| 85169 | 85356 | #else |
| 85170 | 85357 | aOp[0].p1 = iDb; |
| 85171 | 85358 | aOp[0].p2 = pTab->tnum; |
| 85172 | - aOp[0].p3 = flags; | |
| 85359 | + aOp[0].p3 = wrFlag; | |
| 85173 | 85360 | sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); |
| 85174 | 85361 | } |
| 85175 | 85362 | if( db->mallocFailed==0 ){ |
| 85176 | 85363 | #endif |
| 85177 | 85364 | |
| 85178 | 85365 | /* Remove either the OP_OpenWrite or OpenRead. Set the P2 |
| 85179 | 85366 | ** parameter of the other to pTab->tnum. */ |
| 85180 | - if( flags ) aOp[1].opcode = OP_OpenWrite; | |
| 85367 | + if( wrFlag ) aOp[1].opcode = OP_OpenWrite; | |
| 85181 | 85368 | aOp[1].p2 = pTab->tnum; |
| 85182 | 85369 | aOp[1].p3 = iDb; |
| 85183 | 85370 | |
| 85184 | 85371 | /* Configure the number of columns. Configure the cursor to |
| 85185 | 85372 | ** think that the table has one more column than it really |
| @@ -85188,27 +85375,25 @@ | ||
| 85188 | 85375 | ** we can invoke OP_Column to fill in the vdbe cursors type |
| 85189 | 85376 | ** and offset cache without causing any IO. |
| 85190 | 85377 | */ |
| 85191 | 85378 | aOp[1].p4type = P4_INT32; |
| 85192 | 85379 | aOp[1].p4.i = pTab->nCol+1; |
| 85193 | - aOp[4].p2 = pTab->nCol; | |
| 85380 | + aOp[3].p2 = pTab->nCol; | |
| 85194 | 85381 | |
| 85195 | - pParse->nVar = 1; | |
| 85382 | + pParse->nVar = 0; | |
| 85196 | 85383 | pParse->nMem = 1; |
| 85197 | 85384 | pParse->nTab = 1; |
| 85198 | 85385 | sqlite3VdbeMakeReady(v, pParse); |
| 85199 | 85386 | } |
| 85200 | 85387 | } |
| 85201 | 85388 | |
| 85202 | - pBlob->flags = flags; | |
| 85203 | 85389 | pBlob->iCol = iCol; |
| 85204 | 85390 | pBlob->db = db; |
| 85205 | 85391 | sqlite3BtreeLeaveAll(db); |
| 85206 | 85392 | if( db->mallocFailed ){ |
| 85207 | 85393 | goto blob_open_out; |
| 85208 | 85394 | } |
| 85209 | - sqlite3_bind_int64(pBlob->pStmt, 1, iRow); | |
| 85210 | 85395 | rc = blobSeekToRow(pBlob, iRow, &zErr); |
| 85211 | 85396 | } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA ); |
| 85212 | 85397 | |
| 85213 | 85398 | blob_open_out: |
| 85214 | 85399 | if( rc==SQLITE_OK && db->mallocFailed==0 ){ |
| @@ -88741,12 +88926,10 @@ | ||
| 88741 | 88926 | ** This file contains routines used for walking the parser tree and |
| 88742 | 88927 | ** resolve all identifiers by associating them with a particular |
| 88743 | 88928 | ** table and column. |
| 88744 | 88929 | */ |
| 88745 | 88930 | /* #include "sqliteInt.h" */ |
| 88746 | -/* #include <stdlib.h> */ | |
| 88747 | -/* #include <string.h> */ | |
| 88748 | 88931 | |
| 88749 | 88932 | /* |
| 88750 | 88933 | ** Walk the expression tree pExpr and increase the aggregate function |
| 88751 | 88934 | ** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node. |
| 88752 | 88935 | ** This needs to occur when copying a TK_AGG_FUNCTION node from an |
| @@ -91237,21 +91420,27 @@ | ||
| 91237 | 91420 | int doAdd = 0; |
| 91238 | 91421 | if( z[0]=='?' ){ |
| 91239 | 91422 | /* Wildcard of the form "?nnn". Convert "nnn" to an integer and |
| 91240 | 91423 | ** use it as the variable number */ |
| 91241 | 91424 | i64 i; |
| 91242 | - int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8); | |
| 91243 | - x = (ynVar)i; | |
| 91425 | + int bOk; | |
| 91426 | + if( n==2 ){ /*OPTIMIZATION-IF-TRUE*/ | |
| 91427 | + i = z[1]-'0'; /* The common case of ?N for a single digit N */ | |
| 91428 | + bOk = 1; | |
| 91429 | + }else{ | |
| 91430 | + bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8); | |
| 91431 | + } | |
| 91244 | 91432 | testcase( i==0 ); |
| 91245 | 91433 | testcase( i==1 ); |
| 91246 | 91434 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 ); |
| 91247 | 91435 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ); |
| 91248 | 91436 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 91249 | 91437 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 91250 | 91438 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 91251 | 91439 | return; |
| 91252 | 91440 | } |
| 91441 | + x = (ynVar)i; | |
| 91253 | 91442 | if( x>pParse->nVar ){ |
| 91254 | 91443 | pParse->nVar = (int)x; |
| 91255 | 91444 | doAdd = 1; |
| 91256 | 91445 | }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){ |
| 91257 | 91446 | doAdd = 1; |
| @@ -91682,37 +91871,45 @@ | ||
| 91682 | 91871 | pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); |
| 91683 | 91872 | pNewItem->idx = pOldItem->idx; |
| 91684 | 91873 | } |
| 91685 | 91874 | return pNew; |
| 91686 | 91875 | } |
| 91687 | -SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){ | |
| 91688 | - Select *pNew, *pPrior; | |
| 91876 | +SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *pDup, int flags){ | |
| 91877 | + Select *pRet = 0; | |
| 91878 | + Select *pNext = 0; | |
| 91879 | + Select **pp = &pRet; | |
| 91880 | + Select *p; | |
| 91881 | + | |
| 91689 | 91882 | assert( db!=0 ); |
| 91690 | - if( p==0 ) return 0; | |
| 91691 | - pNew = sqlite3DbMallocRawNN(db, sizeof(*p) ); | |
| 91692 | - if( pNew==0 ) return 0; | |
| 91693 | - pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags); | |
| 91694 | - pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags); | |
| 91695 | - pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags); | |
| 91696 | - pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags); | |
| 91697 | - pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags); | |
| 91698 | - pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags); | |
| 91699 | - pNew->op = p->op; | |
| 91700 | - pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags); | |
| 91701 | - if( pPrior ) pPrior->pNext = pNew; | |
| 91702 | - pNew->pNext = 0; | |
| 91703 | - pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags); | |
| 91704 | - pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags); | |
| 91705 | - pNew->iLimit = 0; | |
| 91706 | - pNew->iOffset = 0; | |
| 91707 | - pNew->selFlags = p->selFlags & ~SF_UsesEphemeral; | |
| 91708 | - pNew->addrOpenEphm[0] = -1; | |
| 91709 | - pNew->addrOpenEphm[1] = -1; | |
| 91710 | - pNew->nSelectRow = p->nSelectRow; | |
| 91711 | - pNew->pWith = withDup(db, p->pWith); | |
| 91712 | - sqlite3SelectSetName(pNew, p->zSelName); | |
| 91713 | - return pNew; | |
| 91883 | + for(p=pDup; p; p=p->pPrior){ | |
| 91884 | + Select *pNew = sqlite3DbMallocRawNN(db, sizeof(*p) ); | |
| 91885 | + if( pNew==0 ) break; | |
| 91886 | + pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags); | |
| 91887 | + pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags); | |
| 91888 | + pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags); | |
| 91889 | + pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags); | |
| 91890 | + pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags); | |
| 91891 | + pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags); | |
| 91892 | + pNew->op = p->op; | |
| 91893 | + pNew->pNext = pNext; | |
| 91894 | + pNew->pPrior = 0; | |
| 91895 | + pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags); | |
| 91896 | + pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags); | |
| 91897 | + pNew->iLimit = 0; | |
| 91898 | + pNew->iOffset = 0; | |
| 91899 | + pNew->selFlags = p->selFlags & ~SF_UsesEphemeral; | |
| 91900 | + pNew->addrOpenEphm[0] = -1; | |
| 91901 | + pNew->addrOpenEphm[1] = -1; | |
| 91902 | + pNew->nSelectRow = p->nSelectRow; | |
| 91903 | + pNew->pWith = withDup(db, p->pWith); | |
| 91904 | + sqlite3SelectSetName(pNew, p->zSelName); | |
| 91905 | + *pp = pNew; | |
| 91906 | + pp = &pNew->pPrior; | |
| 91907 | + pNext = pNew; | |
| 91908 | + } | |
| 91909 | + | |
| 91910 | + return pRet; | |
| 91714 | 91911 | } |
| 91715 | 91912 | #else |
| 91716 | 91913 | SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){ |
| 91717 | 91914 | assert( p==0 ); |
| 91718 | 91915 | return 0; |
| @@ -91773,11 +91970,11 @@ | ||
| 91773 | 91970 | ** |
| 91774 | 91971 | ** (a,b,c) = (expr1,expr2,expr3) |
| 91775 | 91972 | ** Or: (a,b,c) = (SELECT x,y,z FROM ....) |
| 91776 | 91973 | ** |
| 91777 | 91974 | ** For each term of the vector assignment, append new entries to the |
| 91778 | -** expression list pList. In the case of a subquery on the LHS, append | |
| 91975 | +** expression list pList. In the case of a subquery on the RHS, append | |
| 91779 | 91976 | ** TK_SELECT_COLUMN expressions. |
| 91780 | 91977 | */ |
| 91781 | 91978 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector( |
| 91782 | 91979 | Parse *pParse, /* Parsing context */ |
| 91783 | 91980 | ExprList *pList, /* List to which to append. Might be NULL */ |
| @@ -93882,10 +94079,15 @@ | ||
| 93882 | 94079 | int i; /* Loop counter */ |
| 93883 | 94080 | sqlite3 *db = pParse->db; /* The database connection */ |
| 93884 | 94081 | u8 enc = ENC(db); /* The text encoding used by this database */ |
| 93885 | 94082 | CollSeq *pColl = 0; /* A collating sequence */ |
| 93886 | 94083 | |
| 94084 | + if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){ | |
| 94085 | + /* SQL functions can be expensive. So try to move constant functions | |
| 94086 | + ** out of the inner loop, even if that means an extra OP_Copy. */ | |
| 94087 | + return sqlite3ExprCodeAtInit(pParse, pExpr, -1); | |
| 94088 | + } | |
| 93887 | 94089 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 93888 | 94090 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 93889 | 94091 | pFarg = 0; |
| 93890 | 94092 | }else{ |
| 93891 | 94093 | pFarg = pExpr->x.pList; |
| @@ -93929,10 +94131,26 @@ | ||
| 93929 | 94131 | */ |
| 93930 | 94132 | if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){ |
| 93931 | 94133 | assert( nFarg>=1 ); |
| 93932 | 94134 | return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target); |
| 93933 | 94135 | } |
| 94136 | + | |
| 94137 | +#ifdef SQLITE_DEBUG | |
| 94138 | + /* The AFFINITY() function evaluates to a string that describes | |
| 94139 | + ** the type affinity of the argument. This is used for testing of | |
| 94140 | + ** the SQLite type logic. | |
| 94141 | + */ | |
| 94142 | + if( pDef->funcFlags & SQLITE_FUNC_AFFINITY ){ | |
| 94143 | + const char *azAff[] = { "blob", "text", "numeric", "integer", "real" }; | |
| 94144 | + char aff; | |
| 94145 | + assert( nFarg==1 ); | |
| 94146 | + aff = sqlite3ExprAffinity(pFarg->a[0].pExpr); | |
| 94147 | + sqlite3VdbeLoadString(v, target, | |
| 94148 | + aff ? azAff[aff-SQLITE_AFF_BLOB] : "none"); | |
| 94149 | + return target; | |
| 94150 | + } | |
| 94151 | +#endif | |
| 93934 | 94152 | |
| 93935 | 94153 | for(i=0; i<nFarg; i++){ |
| 93936 | 94154 | if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){ |
| 93937 | 94155 | testcase( i==31 ); |
| 93938 | 94156 | constMask |= MASKBIT32(i); |
| @@ -94246,28 +94464,44 @@ | ||
| 94246 | 94464 | return inReg; |
| 94247 | 94465 | } |
| 94248 | 94466 | |
| 94249 | 94467 | /* |
| 94250 | 94468 | ** Factor out the code of the given expression to initialization time. |
| 94469 | +** | |
| 94470 | +** If regDest>=0 then the result is always stored in that register and the | |
| 94471 | +** result is not reusable. If regDest<0 then this routine is free to | |
| 94472 | +** store the value whereever it wants. The register where the expression | |
| 94473 | +** is stored is returned. When regDest<0, two identical expressions will | |
| 94474 | +** code to the same register. | |
| 94251 | 94475 | */ |
| 94252 | -SQLITE_PRIVATE void sqlite3ExprCodeAtInit( | |
| 94476 | +SQLITE_PRIVATE int sqlite3ExprCodeAtInit( | |
| 94253 | 94477 | Parse *pParse, /* Parsing context */ |
| 94254 | 94478 | Expr *pExpr, /* The expression to code when the VDBE initializes */ |
| 94255 | - int regDest, /* Store the value in this register */ | |
| 94256 | - u8 reusable /* True if this expression is reusable */ | |
| 94479 | + int regDest /* Store the value in this register */ | |
| 94257 | 94480 | ){ |
| 94258 | 94481 | ExprList *p; |
| 94259 | 94482 | assert( ConstFactorOk(pParse) ); |
| 94260 | 94483 | p = pParse->pConstExpr; |
| 94484 | + if( regDest<0 && p ){ | |
| 94485 | + struct ExprList_item *pItem; | |
| 94486 | + int i; | |
| 94487 | + for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){ | |
| 94488 | + if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){ | |
| 94489 | + return pItem->u.iConstExprReg; | |
| 94490 | + } | |
| 94491 | + } | |
| 94492 | + } | |
| 94261 | 94493 | pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 94262 | 94494 | p = sqlite3ExprListAppend(pParse, p, pExpr); |
| 94263 | 94495 | if( p ){ |
| 94264 | 94496 | struct ExprList_item *pItem = &p->a[p->nExpr-1]; |
| 94497 | + pItem->reusable = regDest<0; | |
| 94498 | + if( regDest<0 ) regDest = ++pParse->nMem; | |
| 94265 | 94499 | pItem->u.iConstExprReg = regDest; |
| 94266 | - pItem->reusable = reusable; | |
| 94267 | 94500 | } |
| 94268 | 94501 | pParse->pConstExpr = p; |
| 94502 | + return regDest; | |
| 94269 | 94503 | } |
| 94270 | 94504 | |
| 94271 | 94505 | /* |
| 94272 | 94506 | ** Generate code to evaluate an expression and store the results |
| 94273 | 94507 | ** into a register. Return the register number where the results |
| @@ -94286,23 +94520,12 @@ | ||
| 94286 | 94520 | pExpr = sqlite3ExprSkipCollate(pExpr); |
| 94287 | 94521 | if( ConstFactorOk(pParse) |
| 94288 | 94522 | && pExpr->op!=TK_REGISTER |
| 94289 | 94523 | && sqlite3ExprIsConstantNotJoin(pExpr) |
| 94290 | 94524 | ){ |
| 94291 | - ExprList *p = pParse->pConstExpr; | |
| 94292 | - int i; | |
| 94293 | 94525 | *pReg = 0; |
| 94294 | - if( p ){ | |
| 94295 | - struct ExprList_item *pItem; | |
| 94296 | - for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){ | |
| 94297 | - if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){ | |
| 94298 | - return pItem->u.iConstExprReg; | |
| 94299 | - } | |
| 94300 | - } | |
| 94301 | - } | |
| 94302 | - r2 = ++pParse->nMem; | |
| 94303 | - sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1); | |
| 94526 | + r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1); | |
| 94304 | 94527 | }else{ |
| 94305 | 94528 | int r1 = sqlite3GetTempReg(pParse); |
| 94306 | 94529 | r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); |
| 94307 | 94530 | if( r2==r1 ){ |
| 94308 | 94531 | *pReg = r1; |
| @@ -94352,11 +94575,11 @@ | ||
| 94352 | 94575 | ** in register target. If the expression is constant, then this routine |
| 94353 | 94576 | ** might choose to code the expression at initialization time. |
| 94354 | 94577 | */ |
| 94355 | 94578 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){ |
| 94356 | 94579 | if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){ |
| 94357 | - sqlite3ExprCodeAtInit(pParse, pExpr, target, 0); | |
| 94580 | + sqlite3ExprCodeAtInit(pParse, pExpr, target); | |
| 94358 | 94581 | }else{ |
| 94359 | 94582 | sqlite3ExprCode(pParse, pExpr, target); |
| 94360 | 94583 | } |
| 94361 | 94584 | } |
| 94362 | 94585 | |
| @@ -94424,11 +94647,11 @@ | ||
| 94424 | 94647 | n--; |
| 94425 | 94648 | }else{ |
| 94426 | 94649 | sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i); |
| 94427 | 94650 | } |
| 94428 | 94651 | }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ |
| 94429 | - sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0); | |
| 94652 | + sqlite3ExprCodeAtInit(pParse, pExpr, target+i); | |
| 94430 | 94653 | }else{ |
| 94431 | 94654 | int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 94432 | 94655 | if( inReg!=target+i ){ |
| 94433 | 94656 | VdbeOp *pOp; |
| 94434 | 94657 | if( copyOp==OP_Copy |
| @@ -96968,10 +97191,16 @@ | ||
| 96968 | 97191 | ** used to query statistical information that has been gathered into |
| 96969 | 97192 | ** the Stat4Accum object by prior calls to stat_push(). The P parameter |
| 96970 | 97193 | ** has type BLOB but it is really just a pointer to the Stat4Accum object. |
| 96971 | 97194 | ** The content to returned is determined by the parameter J |
| 96972 | 97195 | ** which is one of the STAT_GET_xxxx values defined above. |
| 97196 | +** | |
| 97197 | +** The stat_get(P,J) function is not available to generic SQL. It is | |
| 97198 | +** inserted as part of a manually constructed bytecode program. (See | |
| 97199 | +** the callStatGet() routine below.) It is guaranteed that the P | |
| 97200 | +** parameter will always be a poiner to a Stat4Accum object, never a | |
| 97201 | +** NULL. | |
| 96973 | 97202 | ** |
| 96974 | 97203 | ** If neither STAT3 nor STAT4 are enabled, then J is always |
| 96975 | 97204 | ** STAT_GET_STAT1 and is hence omitted and this routine becomes |
| 96976 | 97205 | ** a one-parameter function, stat_get(P), that always returns the |
| 96977 | 97206 | ** stat1 table entry information. |
| @@ -97787,11 +98016,11 @@ | ||
| 97787 | 98016 | sumEq += aSample[i].anEq[iCol]; |
| 97788 | 98017 | nSum100 += 100; |
| 97789 | 98018 | } |
| 97790 | 98019 | } |
| 97791 | 98020 | |
| 97792 | - if( nDist100>nSum100 ){ | |
| 98021 | + if( nDist100>nSum100 && sumEq<nRow ){ | |
| 97793 | 98022 | avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100); |
| 97794 | 98023 | } |
| 97795 | 98024 | if( avgEq==0 ) avgEq = 1; |
| 97796 | 98025 | pIdx->aAvgEq[iCol] = avgEq; |
| 97797 | 98026 | } |
| @@ -98201,10 +98430,11 @@ | ||
| 98201 | 98430 | assert( pVfs ); |
| 98202 | 98431 | flags |= SQLITE_OPEN_MAIN_DB; |
| 98203 | 98432 | rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags); |
| 98204 | 98433 | sqlite3_free( zPath ); |
| 98205 | 98434 | db->nDb++; |
| 98435 | + db->skipBtreeMutex = 0; | |
| 98206 | 98436 | if( rc==SQLITE_CONSTRAINT ){ |
| 98207 | 98437 | rc = SQLITE_ERROR; |
| 98208 | 98438 | zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
| 98209 | 98439 | }else if( rc==SQLITE_OK ){ |
| 98210 | 98440 | Pager *pPager; |
| @@ -104365,16 +104595,12 @@ | ||
| 104365 | 104595 | } |
| 104366 | 104596 | }else |
| 104367 | 104597 | #endif |
| 104368 | 104598 | { |
| 104369 | 104599 | int count = (pParse->nested==0); /* True to count changes */ |
| 104370 | - int iIdxNoSeek = -1; | |
| 104371 | - if( bComplex==0 && aiCurOnePass[1]!=iDataCur ){ | |
| 104372 | - iIdxNoSeek = aiCurOnePass[1]; | |
| 104373 | - } | |
| 104374 | 104600 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 104375 | - iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek); | |
| 104601 | + iKey, nKey, count, OE_Default, eOnePass, aiCurOnePass[1]); | |
| 104376 | 104602 | } |
| 104377 | 104603 | |
| 104378 | 104604 | /* End of the loop over all rowids/primary-keys. */ |
| 104379 | 104605 | if( eOnePass!=ONEPASS_OFF ){ |
| 104380 | 104606 | sqlite3VdbeResolveLabel(v, addrBypass); |
| @@ -104450,19 +104676,21 @@ | ||
| 104450 | 104676 | ** then this function must seek iDataCur to the entry identified by iPk |
| 104451 | 104677 | ** and nPk before reading from it. |
| 104452 | 104678 | ** |
| 104453 | 104679 | ** If eMode is ONEPASS_MULTI, then this call is being made as part |
| 104454 | 104680 | ** of a ONEPASS delete that affects multiple rows. In this case, if |
| 104455 | -** iIdxNoSeek is a valid cursor number (>=0), then its position should | |
| 104456 | -** be preserved following the delete operation. Or, if iIdxNoSeek is not | |
| 104457 | -** a valid cursor number, the position of iDataCur should be preserved | |
| 104458 | -** instead. | |
| 104681 | +** iIdxNoSeek is a valid cursor number (>=0) and is not the same as | |
| 104682 | +** iDataCur, then its position should be preserved following the delete | |
| 104683 | +** operation. Or, if iIdxNoSeek is not a valid cursor number, the | |
| 104684 | +** position of iDataCur should be preserved instead. | |
| 104459 | 104685 | ** |
| 104460 | 104686 | ** iIdxNoSeek: |
| 104461 | -** If iIdxNoSeek is a valid cursor number (>=0), then it identifies an | |
| 104462 | -** index cursor (from within array of cursors starting at iIdxCur) that | |
| 104463 | -** already points to the index entry to be deleted. | |
| 104687 | +** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur, | |
| 104688 | +** then it identifies an index cursor (from within array of cursors | |
| 104689 | +** starting at iIdxCur) that already points to the index entry to be deleted. | |
| 104690 | +** Except, this optimization is disabled if there are BEFORE triggers since | |
| 104691 | +** the trigger body might have moved the cursor. | |
| 104464 | 104692 | */ |
| 104465 | 104693 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 104466 | 104694 | Parse *pParse, /* Parsing context */ |
| 104467 | 104695 | Table *pTab, /* Table containing the row to be deleted */ |
| 104468 | 104696 | Trigger *pTrigger, /* List of triggers to (potentially) fire */ |
| @@ -104529,17 +104757,22 @@ | ||
| 104529 | 104757 | TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel |
| 104530 | 104758 | ); |
| 104531 | 104759 | |
| 104532 | 104760 | /* If any BEFORE triggers were coded, then seek the cursor to the |
| 104533 | 104761 | ** row to be deleted again. It may be that the BEFORE triggers moved |
| 104534 | - ** the cursor or of already deleted the row that the cursor was | |
| 104762 | + ** the cursor or already deleted the row that the cursor was | |
| 104535 | 104763 | ** pointing to. |
| 104764 | + ** | |
| 104765 | + ** Also disable the iIdxNoSeek optimization since the BEFORE trigger | |
| 104766 | + ** may have moved that cursor. | |
| 104536 | 104767 | */ |
| 104537 | 104768 | if( addrStart<sqlite3VdbeCurrentAddr(v) ){ |
| 104538 | 104769 | sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 104539 | 104770 | VdbeCoverageIf(v, opSeek==OP_NotExists); |
| 104540 | 104771 | VdbeCoverageIf(v, opSeek==OP_NotFound); |
| 104772 | + testcase( iIdxNoSeek>=0 ); | |
| 104773 | + iIdxNoSeek = -1; | |
| 104541 | 104774 | } |
| 104542 | 104775 | |
| 104543 | 104776 | /* Do FK processing. This call checks that any FK constraints that |
| 104544 | 104777 | ** refer to this table (i.e. constraints attached to other tables) |
| 104545 | 104778 | ** are not violated by deleting this row. */ |
| @@ -104558,15 +104791,17 @@ | ||
| 104558 | 104791 | */ |
| 104559 | 104792 | if( pTab->pSelect==0 ){ |
| 104560 | 104793 | u8 p5 = 0; |
| 104561 | 104794 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); |
| 104562 | 104795 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 104563 | - sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE); | |
| 104796 | + if( pParse->nested==0 ){ | |
| 104797 | + sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE); | |
| 104798 | + } | |
| 104564 | 104799 | if( eMode!=ONEPASS_OFF ){ |
| 104565 | 104800 | sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE); |
| 104566 | 104801 | } |
| 104567 | - if( iIdxNoSeek>=0 ){ | |
| 104802 | + if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){ | |
| 104568 | 104803 | sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); |
| 104569 | 104804 | } |
| 104570 | 104805 | if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION; |
| 104571 | 104806 | sqlite3VdbeChangeP5(v, p5); |
| 104572 | 104807 | } |
| @@ -104716,10 +104951,14 @@ | ||
| 104716 | 104951 | ** opcode if it is present */ |
| 104717 | 104952 | sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity); |
| 104718 | 104953 | } |
| 104719 | 104954 | if( regOut ){ |
| 104720 | 104955 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 104956 | + if( pIdx->pTable->pSelect ){ | |
| 104957 | + const char *zAff = sqlite3IndexAffinityStr(pParse->db, pIdx); | |
| 104958 | + sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT); | |
| 104959 | + } | |
| 104721 | 104960 | } |
| 104722 | 104961 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 104723 | 104962 | return regBase; |
| 104724 | 104963 | } |
| 104725 | 104964 | |
| @@ -106512,10 +106751,13 @@ | ||
| 106512 | 106751 | DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 106513 | 106752 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 106514 | 106753 | FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106515 | 106754 | FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106516 | 106755 | FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106756 | +#ifdef SQLITE_DEBUG | |
| 106757 | + FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY), | |
| 106758 | +#endif | |
| 106517 | 106759 | FUNCTION(ltrim, 1, 1, 0, trimFunc ), |
| 106518 | 106760 | FUNCTION(ltrim, 2, 1, 0, trimFunc ), |
| 106519 | 106761 | FUNCTION(rtrim, 1, 2, 0, trimFunc ), |
| 106520 | 106762 | FUNCTION(rtrim, 2, 2, 0, trimFunc ), |
| 106521 | 106763 | FUNCTION(trim, 1, 3, 0, trimFunc ), |
| @@ -109667,11 +109909,11 @@ | ||
| 109667 | 109909 | if( db->flags&SQLITE_RecTriggers ){ |
| 109668 | 109910 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 109669 | 109911 | } |
| 109670 | 109912 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 109671 | 109913 | regR, nPkField, 0, OE_Replace, |
| 109672 | - (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), -1); | |
| 109914 | + (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur); | |
| 109673 | 109915 | seenReplace = 1; |
| 109674 | 109916 | break; |
| 109675 | 109917 | } |
| 109676 | 109918 | } |
| 109677 | 109919 | sqlite3VdbeResolveLabel(v, addrUniqueOk); |
| @@ -109683,10 +109925,29 @@ | ||
| 109683 | 109925 | } |
| 109684 | 109926 | |
| 109685 | 109927 | *pbMayReplace = seenReplace; |
| 109686 | 109928 | VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace)); |
| 109687 | 109929 | } |
| 109930 | + | |
| 109931 | +#ifdef SQLITE_ENABLE_NULL_TRIM | |
| 109932 | +/* | |
| 109933 | +** Change the P5 operand on the last opcode (which should be an OP_MakeRecord) | |
| 109934 | +** to be the number of columns in table pTab that must not be NULL-trimmed. | |
| 109935 | +** | |
| 109936 | +** Or if no columns of pTab may be NULL-trimmed, leave P5 at zero. | |
| 109937 | +*/ | |
| 109938 | +SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe *v, Table *pTab){ | |
| 109939 | + u16 i; | |
| 109940 | + | |
| 109941 | + /* Records with omitted columns are only allowed for schema format | |
| 109942 | + ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */ | |
| 109943 | + if( pTab->pSchema->file_format<2 ) return; | |
| 109944 | + | |
| 109945 | + for(i=pTab->nCol; i>1 && pTab->aCol[i-1].pDflt==0; i--){} | |
| 109946 | + sqlite3VdbeChangeP5(v, i); | |
| 109947 | +} | |
| 109948 | +#endif | |
| 109688 | 109949 | |
| 109689 | 109950 | /* |
| 109690 | 109951 | ** This routine generates code to finish the INSERT or UPDATE operation |
| 109691 | 109952 | ** that was started by a prior call to sqlite3GenerateConstraintChecks. |
| 109692 | 109953 | ** A consecutive range of registers starting at regNewData contains the |
| @@ -109700,11 +109961,11 @@ | ||
| 109700 | 109961 | Table *pTab, /* the table into which we are inserting */ |
| 109701 | 109962 | int iDataCur, /* Cursor of the canonical data source */ |
| 109702 | 109963 | int iIdxCur, /* First index cursor */ |
| 109703 | 109964 | int regNewData, /* Range of content */ |
| 109704 | 109965 | int *aRegIdx, /* Register used by each index. 0 for unused indices */ |
| 109705 | - int isUpdate, /* True for UPDATE, False for INSERT */ | |
| 109966 | + int update_flags, /* True for UPDATE, False for INSERT */ | |
| 109706 | 109967 | int appendBias, /* True if this is likely to be an append */ |
| 109707 | 109968 | int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */ |
| 109708 | 109969 | ){ |
| 109709 | 109970 | Vdbe *v; /* Prepared statements under construction */ |
| 109710 | 109971 | Index *pIdx; /* An index being inserted or updated */ |
| @@ -109711,10 +109972,15 @@ | ||
| 109711 | 109972 | u8 pik_flags; /* flag values passed to the btree insert */ |
| 109712 | 109973 | int regData; /* Content registers (after the rowid) */ |
| 109713 | 109974 | int regRec; /* Register holding assembled record for the table */ |
| 109714 | 109975 | int i; /* Loop counter */ |
| 109715 | 109976 | u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */ |
| 109977 | + | |
| 109978 | + assert( update_flags==0 | |
| 109979 | + || update_flags==OPFLAG_ISUPDATE | |
| 109980 | + || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION) | |
| 109981 | + ); | |
| 109716 | 109982 | |
| 109717 | 109983 | v = sqlite3GetVdbe(pParse); |
| 109718 | 109984 | assert( v!=0 ); |
| 109719 | 109985 | assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 109720 | 109986 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| @@ -109722,34 +109988,43 @@ | ||
| 109722 | 109988 | bAffinityDone = 1; |
| 109723 | 109989 | if( pIdx->pPartIdxWhere ){ |
| 109724 | 109990 | sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2); |
| 109725 | 109991 | VdbeCoverage(v); |
| 109726 | 109992 | } |
| 109727 | - sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i], | |
| 109728 | - aRegIdx[i]+1, | |
| 109729 | - pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn); | |
| 109730 | - pik_flags = 0; | |
| 109731 | - if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT; | |
| 109993 | + pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0); | |
| 109732 | 109994 | if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){ |
| 109733 | 109995 | assert( pParse->nested==0 ); |
| 109734 | 109996 | pik_flags |= OPFLAG_NCHANGE; |
| 109997 | + pik_flags |= (update_flags & OPFLAG_SAVEPOSITION); | |
| 109998 | +#ifdef SQLITE_ENABLE_PREUPDATE_HOOK | |
| 109999 | + if( update_flags==0 ){ | |
| 110000 | + sqlite3VdbeAddOp4(v, OP_InsertInt, | |
| 110001 | + iIdxCur+i, aRegIdx[i], 0, (char*)pTab, P4_TABLE | |
| 110002 | + ); | |
| 110003 | + sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP); | |
| 110004 | + } | |
| 110005 | +#endif | |
| 109735 | 110006 | } |
| 110007 | + sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i], | |
| 110008 | + aRegIdx[i]+1, | |
| 110009 | + pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn); | |
| 109736 | 110010 | sqlite3VdbeChangeP5(v, pik_flags); |
| 109737 | 110011 | } |
| 109738 | 110012 | if( !HasRowid(pTab) ) return; |
| 109739 | 110013 | regData = regNewData + 1; |
| 109740 | 110014 | regRec = sqlite3GetTempReg(pParse); |
| 109741 | 110015 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec); |
| 110016 | + sqlite3SetMakeRecordP5(v, pTab); | |
| 109742 | 110017 | if( !bAffinityDone ){ |
| 109743 | 110018 | sqlite3TableAffinity(v, pTab, 0); |
| 109744 | 110019 | sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol); |
| 109745 | 110020 | } |
| 109746 | 110021 | if( pParse->nested ){ |
| 109747 | 110022 | pik_flags = 0; |
| 109748 | 110023 | }else{ |
| 109749 | 110024 | pik_flags = OPFLAG_NCHANGE; |
| 109750 | - pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID); | |
| 110025 | + pik_flags |= (update_flags?update_flags:OPFLAG_LASTROWID); | |
| 109751 | 110026 | } |
| 109752 | 110027 | if( appendBias ){ |
| 109753 | 110028 | pik_flags |= OPFLAG_APPEND; |
| 109754 | 110029 | } |
| 109755 | 110030 | if( useSeekResult ){ |
| @@ -110154,11 +110429,11 @@ | ||
| 110154 | 110429 | addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); |
| 110155 | 110430 | }else{ |
| 110156 | 110431 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 110157 | 110432 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 110158 | 110433 | } |
| 110159 | - sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); | |
| 110434 | + sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); | |
| 110160 | 110435 | if( db->flags & SQLITE_Vacuum ){ |
| 110161 | 110436 | sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); |
| 110162 | 110437 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID| |
| 110163 | 110438 | OPFLAG_APPEND|OPFLAG_USESEEKRESULT; |
| 110164 | 110439 | }else{ |
| @@ -110186,11 +110461,11 @@ | ||
| 110186 | 110461 | sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest); |
| 110187 | 110462 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 110188 | 110463 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 110189 | 110464 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 110190 | 110465 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 110191 | - sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); | |
| 110466 | + sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); | |
| 110192 | 110467 | if( db->flags & SQLITE_Vacuum ){ |
| 110193 | 110468 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 110194 | 110469 | ** that the destination table is empty. If all indexed columns use |
| 110195 | 110470 | ** collation sequence BINARY, then it can also be assumed that the |
| 110196 | 110471 | ** index will be populated by inserting keys in strictly sorted |
| @@ -110971,11 +111246,10 @@ | ||
| 110971 | 111246 | #endif /* SQLITE3EXT_H */ |
| 110972 | 111247 | |
| 110973 | 111248 | /************** End of sqlite3ext.h ******************************************/ |
| 110974 | 111249 | /************** Continuing where we left off in loadext.c ********************/ |
| 110975 | 111250 | /* #include "sqliteInt.h" */ |
| 110976 | -/* #include <string.h> */ | |
| 110977 | 111251 | |
| 110978 | 111252 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 110979 | 111253 | /* |
| 110980 | 111254 | ** Some API routines are omitted when various features are |
| 110981 | 111255 | ** excluded from a build of SQLite. Substitute a NULL pointer |
| @@ -112635,11 +112909,11 @@ | ||
| 112635 | 112909 | |
| 112636 | 112910 | /* |
| 112637 | 112911 | ** Locate a pragma in the aPragmaName[] array. |
| 112638 | 112912 | */ |
| 112639 | 112913 | static const PragmaName *pragmaLocate(const char *zName){ |
| 112640 | - int upr, lwr, mid, rc; | |
| 112914 | + int upr, lwr, mid = 0, rc; | |
| 112641 | 112915 | lwr = 0; |
| 112642 | 112916 | upr = ArraySize(aPragmaName)-1; |
| 112643 | 112917 | while( lwr<=upr ){ |
| 112644 | 112918 | mid = (lwr+upr)/2; |
| 112645 | 112919 | rc = sqlite3_stricmp(zName, aPragmaName[mid].zName); |
| @@ -116149,10 +116423,11 @@ | ||
| 116149 | 116423 | v = pParse->pVdbe; |
| 116150 | 116424 | r1 = sqlite3GetTempReg(pParse); |
| 116151 | 116425 | sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v); |
| 116152 | 116426 | sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1); |
| 116153 | 116427 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N); |
| 116428 | + sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); | |
| 116154 | 116429 | sqlite3ReleaseTempReg(pParse, r1); |
| 116155 | 116430 | } |
| 116156 | 116431 | |
| 116157 | 116432 | /* |
| 116158 | 116433 | ** This routine generates the code for the inside of the inner loop |
| @@ -119677,11 +119952,19 @@ | ||
| 119677 | 119952 | assert( pTab->nTabRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 )); |
| 119678 | 119953 | |
| 119679 | 119954 | pCte->zCteErr = "circular reference: %s"; |
| 119680 | 119955 | pSavedWith = pParse->pWith; |
| 119681 | 119956 | pParse->pWith = pWith; |
| 119682 | - sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel); | |
| 119957 | + if( bMayRecursive ){ | |
| 119958 | + Select *pPrior = pSel->pPrior; | |
| 119959 | + assert( pPrior->pWith==0 ); | |
| 119960 | + pPrior->pWith = pSel->pWith; | |
| 119961 | + sqlite3WalkSelect(pWalker, pPrior); | |
| 119962 | + pPrior->pWith = 0; | |
| 119963 | + }else{ | |
| 119964 | + sqlite3WalkSelect(pWalker, pSel); | |
| 119965 | + } | |
| 119683 | 119966 | pParse->pWith = pWith; |
| 119684 | 119967 | |
| 119685 | 119968 | for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); |
| 119686 | 119969 | pEList = pLeft->pEList; |
| 119687 | 119970 | if( pCte->pCols ){ |
| @@ -119721,14 +120004,16 @@ | ||
| 119721 | 120004 | ** sqlite3SelectExpand() when walking a SELECT tree to resolve table |
| 119722 | 120005 | ** names and other FROM clause elements. |
| 119723 | 120006 | */ |
| 119724 | 120007 | static void selectPopWith(Walker *pWalker, Select *p){ |
| 119725 | 120008 | Parse *pParse = pWalker->pParse; |
| 119726 | - With *pWith = findRightmost(p)->pWith; | |
| 119727 | - if( pWith!=0 ){ | |
| 119728 | - assert( pParse->pWith==pWith ); | |
| 119729 | - pParse->pWith = pWith->pOuter; | |
| 120009 | + if( pParse->pWith && p->pPrior==0 ){ | |
| 120010 | + With *pWith = findRightmost(p)->pWith; | |
| 120011 | + if( pWith!=0 ){ | |
| 120012 | + assert( pParse->pWith==pWith ); | |
| 120013 | + pParse->pWith = pWith->pOuter; | |
| 120014 | + } | |
| 119730 | 120015 | } |
| 119731 | 120016 | } |
| 119732 | 120017 | #else |
| 119733 | 120018 | #define selectPopWith 0 |
| 119734 | 120019 | #endif |
| @@ -119774,12 +120059,12 @@ | ||
| 119774 | 120059 | if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){ |
| 119775 | 120060 | return WRC_Prune; |
| 119776 | 120061 | } |
| 119777 | 120062 | pTabList = p->pSrc; |
| 119778 | 120063 | pEList = p->pEList; |
| 119779 | - if( pWalker->xSelectCallback2==selectPopWith ){ | |
| 119780 | - sqlite3WithPush(pParse, findRightmost(p)->pWith, 0); | |
| 120064 | + if( p->pWith ){ | |
| 120065 | + sqlite3WithPush(pParse, p->pWith, 0); | |
| 119781 | 120066 | } |
| 119782 | 120067 | |
| 119783 | 120068 | /* Make sure cursor numbers have been assigned to all entries in |
| 119784 | 120069 | ** the FROM clause of the SELECT statement. |
| 119785 | 120070 | */ |
| @@ -120062,13 +120347,11 @@ | ||
| 120062 | 120347 | if( pParse->hasCompound ){ |
| 120063 | 120348 | w.xSelectCallback = convertCompoundSelectToSubquery; |
| 120064 | 120349 | sqlite3WalkSelect(&w, pSelect); |
| 120065 | 120350 | } |
| 120066 | 120351 | w.xSelectCallback = selectExpander; |
| 120067 | - if( (pSelect->selFlags & SF_MultiValue)==0 ){ | |
| 120068 | - w.xSelectCallback2 = selectPopWith; | |
| 120069 | - } | |
| 120352 | + w.xSelectCallback2 = selectPopWith; | |
| 120070 | 120353 | sqlite3WalkSelect(&w, pSelect); |
| 120071 | 120354 | } |
| 120072 | 120355 | |
| 120073 | 120356 | |
| 120074 | 120357 | #ifndef SQLITE_OMIT_SUBQUERY |
| @@ -121143,11 +121426,11 @@ | ||
| 121143 | 121426 | /* This case runs if the aggregate has no GROUP BY clause. The |
| 121144 | 121427 | ** processing is much simpler since there is only a single row |
| 121145 | 121428 | ** of output. |
| 121146 | 121429 | */ |
| 121147 | 121430 | resetAccumulator(pParse, &sAggInfo); |
| 121148 | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax,0,flag,0); | |
| 121431 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax, 0,flag,0); | |
| 121149 | 121432 | if( pWInfo==0 ){ |
| 121150 | 121433 | sqlite3ExprListDelete(db, pDel); |
| 121151 | 121434 | goto select_end; |
| 121152 | 121435 | } |
| 121153 | 121436 | updateAccumulator(pParse, &sAggInfo); |
| @@ -121232,12 +121515,10 @@ | ||
| 121232 | 121515 | ** |
| 121233 | 121516 | ** These routines are in a separate files so that they will not be linked |
| 121234 | 121517 | ** if they are not used. |
| 121235 | 121518 | */ |
| 121236 | 121519 | /* #include "sqliteInt.h" */ |
| 121237 | -/* #include <stdlib.h> */ | |
| 121238 | -/* #include <string.h> */ | |
| 121239 | 121520 | |
| 121240 | 121521 | #ifndef SQLITE_OMIT_GET_TABLE |
| 121241 | 121522 | |
| 121242 | 121523 | /* |
| 121243 | 121524 | ** This structure is used to pass data from sqlite3_get_table() through |
| @@ -122591,16 +122872,16 @@ | ||
| 122591 | 122872 | sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc, |
| 122592 | 122873 | pCol->affinity, &pValue); |
| 122593 | 122874 | if( pValue ){ |
| 122594 | 122875 | sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 122595 | 122876 | } |
| 122877 | + } | |
| 122596 | 122878 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 122597 | - if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ | |
| 122598 | - sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); | |
| 122599 | - } | |
| 122879 | + if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ | |
| 122880 | + sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); | |
| 122881 | + } | |
| 122600 | 122882 | #endif |
| 122601 | - } | |
| 122602 | 122883 | } |
| 122603 | 122884 | |
| 122604 | 122885 | /* |
| 122605 | 122886 | ** Process an UPDATE statement. |
| 122606 | 122887 | ** |
| @@ -122625,11 +122906,11 @@ | ||
| 122625 | 122906 | int nIdx; /* Number of indices that need updating */ |
| 122626 | 122907 | int iBaseCur; /* Base cursor number */ |
| 122627 | 122908 | int iDataCur; /* Cursor for the canonical data btree */ |
| 122628 | 122909 | int iIdxCur; /* Cursor for the first index */ |
| 122629 | 122910 | sqlite3 *db; /* The database structure */ |
| 122630 | - int *aRegIdx = 0; /* One register assigned to each index to be updated */ | |
| 122911 | + int *aRegIdx = 0; /* First register in array assigned to each index */ | |
| 122631 | 122912 | int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the |
| 122632 | 122913 | ** an expression for the i-th column of the table. |
| 122633 | 122914 | ** aXRef[i]==-1 if the i-th column is not changed. */ |
| 122634 | 122915 | u8 *aToOpen; /* 1 for tables and indices to be opened */ |
| 122635 | 122916 | u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */ |
| @@ -122637,14 +122918,15 @@ | ||
| 122637 | 122918 | u8 chngKey; /* Either chngPk or chngRowid */ |
| 122638 | 122919 | Expr *pRowidExpr = 0; /* Expression defining the new record number */ |
| 122639 | 122920 | AuthContext sContext; /* The authorization context */ |
| 122640 | 122921 | NameContext sNC; /* The name-context to resolve expressions in */ |
| 122641 | 122922 | int iDb; /* Database containing the table being updated */ |
| 122642 | - int okOnePass; /* True for one-pass algorithm without the FIFO */ | |
| 122923 | + int eOnePass; /* ONEPASS_XXX value from where.c */ | |
| 122643 | 122924 | int hasFK; /* True if foreign key processing is required */ |
| 122644 | 122925 | int labelBreak; /* Jump here to break out of UPDATE loop */ |
| 122645 | 122926 | int labelContinue; /* Jump here to continue next step of UPDATE loop */ |
| 122927 | + int flags; /* Flags for sqlite3WhereBegin() */ | |
| 122646 | 122928 | |
| 122647 | 122929 | #ifndef SQLITE_OMIT_TRIGGER |
| 122648 | 122930 | int isView; /* True when updating a view (INSTEAD OF trigger) */ |
| 122649 | 122931 | Trigger *pTrigger; /* List of triggers on pTab, if required */ |
| 122650 | 122932 | int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */ |
| @@ -122651,10 +122933,14 @@ | ||
| 122651 | 122933 | #endif |
| 122652 | 122934 | int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */ |
| 122653 | 122935 | int iEph = 0; /* Ephemeral table holding all primary key values */ |
| 122654 | 122936 | int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */ |
| 122655 | 122937 | int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */ |
| 122938 | + int addrOpen = 0; /* Address of OP_OpenEphemeral */ | |
| 122939 | + int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */ | |
| 122940 | + i16 nPk = 0; /* Number of components of the PRIMARY KEY */ | |
| 122941 | + int bReplace = 0; /* True if REPLACE conflict resolution might happen */ | |
| 122656 | 122942 | |
| 122657 | 122943 | /* Register Allocations */ |
| 122658 | 122944 | int regRowCount = 0; /* A count of rows changed */ |
| 122659 | 122945 | int regOldRowid = 0; /* The old rowid */ |
| 122660 | 122946 | int regNewRowid = 0; /* The new rowid */ |
| @@ -122810,17 +123096,27 @@ | ||
| 122810 | 123096 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 122811 | 123097 | i16 iIdxCol = pIdx->aiColumn[i]; |
| 122812 | 123098 | if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){ |
| 122813 | 123099 | reg = ++pParse->nMem; |
| 122814 | 123100 | pParse->nMem += pIdx->nColumn; |
| 123101 | + if( (onError==OE_Replace) | |
| 123102 | + || (onError==OE_Default && pIdx->onError==OE_Replace) | |
| 123103 | + ){ | |
| 123104 | + bReplace = 1; | |
| 123105 | + } | |
| 122815 | 123106 | break; |
| 122816 | 123107 | } |
| 122817 | 123108 | } |
| 122818 | 123109 | } |
| 122819 | 123110 | if( reg==0 ) aToOpen[j+1] = 0; |
| 122820 | 123111 | aRegIdx[j] = reg; |
| 122821 | 123112 | } |
| 123113 | + if( bReplace ){ | |
| 123114 | + /* If REPLACE conflict resolution might be invoked, open cursors on all | |
| 123115 | + ** indexes in case they are needed to delete records. */ | |
| 123116 | + memset(aToOpen, 1, nIdx+1); | |
| 123117 | + } | |
| 122822 | 123118 | |
| 122823 | 123119 | /* Begin generating code. */ |
| 122824 | 123120 | v = sqlite3GetVdbe(pParse); |
| 122825 | 123121 | if( v==0 ) goto update_cleanup; |
| 122826 | 123122 | if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); |
| @@ -122869,107 +123165,127 @@ | ||
| 122869 | 123165 | pWhere, onError); |
| 122870 | 123166 | goto update_cleanup; |
| 122871 | 123167 | } |
| 122872 | 123168 | #endif |
| 122873 | 123169 | |
| 122874 | - /* Begin the database scan | |
| 122875 | - */ | |
| 123170 | + /* Initialize the count of updated rows */ | |
| 123171 | + if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){ | |
| 123172 | + regRowCount = ++pParse->nMem; | |
| 123173 | + sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount); | |
| 123174 | + } | |
| 123175 | + | |
| 122876 | 123176 | if( HasRowid(pTab) ){ |
| 122877 | 123177 | sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid); |
| 122878 | - pWInfo = sqlite3WhereBegin( | |
| 122879 | - pParse, pTabList, pWhere, 0, 0, | |
| 122880 | - WHERE_ONEPASS_DESIRED | WHERE_SEEK_TABLE, iIdxCur | |
| 122881 | - ); | |
| 122882 | - if( pWInfo==0 ) goto update_cleanup; | |
| 122883 | - okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); | |
| 122884 | - | |
| 122885 | - /* Remember the rowid of every item to be updated. | |
| 122886 | - */ | |
| 122887 | - sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid); | |
| 122888 | - if( !okOnePass ){ | |
| 122889 | - sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid); | |
| 122890 | - } | |
| 122891 | - | |
| 122892 | - /* End the database scan loop. | |
| 122893 | - */ | |
| 122894 | - sqlite3WhereEnd(pWInfo); | |
| 122895 | 123178 | }else{ |
| 122896 | - int iPk; /* First of nPk memory cells holding PRIMARY KEY value */ | |
| 122897 | - i16 nPk; /* Number of components of the PRIMARY KEY */ | |
| 122898 | - int addrOpen; /* Address of the OpenEphemeral instruction */ | |
| 122899 | - | |
| 122900 | 123179 | assert( pPk!=0 ); |
| 122901 | 123180 | nPk = pPk->nKeyCol; |
| 122902 | 123181 | iPk = pParse->nMem+1; |
| 122903 | 123182 | pParse->nMem += nPk; |
| 122904 | 123183 | regKey = ++pParse->nMem; |
| 122905 | 123184 | iEph = pParse->nTab++; |
| 123185 | + | |
| 122906 | 123186 | sqlite3VdbeAddOp2(v, OP_Null, 0, iPk); |
| 122907 | 123187 | addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk); |
| 122908 | 123188 | sqlite3VdbeSetP4KeyInfo(pParse, pPk); |
| 122909 | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, | |
| 122910 | - WHERE_ONEPASS_DESIRED, iIdxCur); | |
| 122911 | - if( pWInfo==0 ) goto update_cleanup; | |
| 122912 | - okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); | |
| 123189 | + } | |
| 123190 | + | |
| 123191 | + /* Begin the database scan. | |
| 123192 | + ** | |
| 123193 | + ** Do not consider a single-pass strategy for a multi-row update if | |
| 123194 | + ** there are any triggers or foreign keys to process, or rows may | |
| 123195 | + ** be deleted as a result of REPLACE conflict handling. Any of these | |
| 123196 | + ** things might disturb a cursor being used to scan through the table | |
| 123197 | + ** or index, causing a single-pass approach to malfunction. */ | |
| 123198 | + flags = WHERE_ONEPASS_DESIRED|WHERE_SEEK_UNIQ_TABLE; | |
| 123199 | + if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){ | |
| 123200 | + flags |= WHERE_ONEPASS_MULTIROW; | |
| 123201 | + } | |
| 123202 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags, iIdxCur); | |
| 123203 | + if( pWInfo==0 ) goto update_cleanup; | |
| 123204 | + | |
| 123205 | + /* A one-pass strategy that might update more than one row may not | |
| 123206 | + ** be used if any column of the index used for the scan is being | |
| 123207 | + ** updated. Otherwise, if there is an index on "b", statements like | |
| 123208 | + ** the following could create an infinite loop: | |
| 123209 | + ** | |
| 123210 | + ** UPDATE t1 SET b=b+1 WHERE b>? | |
| 123211 | + ** | |
| 123212 | + ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI | |
| 123213 | + ** strategy that uses an index for which one or more columns are being | |
| 123214 | + ** updated. */ | |
| 123215 | + eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); | |
| 123216 | + if( eOnePass==ONEPASS_MULTI ){ | |
| 123217 | + int iCur = aiCurOnePass[1]; | |
| 123218 | + if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){ | |
| 123219 | + eOnePass = ONEPASS_OFF; | |
| 123220 | + } | |
| 123221 | + assert( iCur!=iDataCur || !HasRowid(pTab) ); | |
| 123222 | + } | |
| 123223 | + | |
| 123224 | + if( HasRowid(pTab) ){ | |
| 123225 | + /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF | |
| 123226 | + ** mode, write the rowid into the FIFO. In either of the one-pass modes, | |
| 123227 | + ** leave it in register regOldRowid. */ | |
| 123228 | + sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid); | |
| 123229 | + if( eOnePass==ONEPASS_OFF ){ | |
| 123230 | + sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid); | |
| 123231 | + } | |
| 123232 | + }else{ | |
| 123233 | + /* Read the PK of the current row into an array of registers. In | |
| 123234 | + ** ONEPASS_OFF mode, serialize the array into a record and store it in | |
| 123235 | + ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change | |
| 123236 | + ** the OP_OpenEphemeral instruction to a Noop (the ephemeral table | |
| 123237 | + ** is not required) and leave the PK fields in the array of registers. */ | |
| 122913 | 123238 | for(i=0; i<nPk; i++){ |
| 122914 | 123239 | assert( pPk->aiColumn[i]>=0 ); |
| 122915 | - sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i], | |
| 122916 | - iPk+i); | |
| 123240 | + sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur,pPk->aiColumn[i],iPk+i); | |
| 122917 | 123241 | } |
| 122918 | - if( okOnePass ){ | |
| 123242 | + if( eOnePass ){ | |
| 122919 | 123243 | sqlite3VdbeChangeToNoop(v, addrOpen); |
| 122920 | 123244 | nKey = nPk; |
| 122921 | 123245 | regKey = iPk; |
| 122922 | 123246 | }else{ |
| 122923 | 123247 | sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey, |
| 122924 | 123248 | sqlite3IndexAffinityStr(db, pPk), nPk); |
| 122925 | 123249 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk); |
| 122926 | 123250 | } |
| 122927 | - sqlite3WhereEnd(pWInfo); | |
| 122928 | 123251 | } |
| 122929 | 123252 | |
| 122930 | - /* Initialize the count of updated rows | |
| 122931 | - */ | |
| 122932 | - if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){ | |
| 122933 | - regRowCount = ++pParse->nMem; | |
| 122934 | - sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount); | |
| 123253 | + if( eOnePass!=ONEPASS_MULTI ){ | |
| 123254 | + sqlite3WhereEnd(pWInfo); | |
| 122935 | 123255 | } |
| 122936 | 123256 | |
| 122937 | 123257 | labelBreak = sqlite3VdbeMakeLabel(v); |
| 122938 | 123258 | if( !isView ){ |
| 122939 | - /* | |
| 122940 | - ** Open every index that needs updating. Note that if any | |
| 122941 | - ** index could potentially invoke a REPLACE conflict resolution | |
| 122942 | - ** action, then we need to open all indices because we might need | |
| 122943 | - ** to be deleting some records. | |
| 122944 | - */ | |
| 122945 | - if( onError==OE_Replace ){ | |
| 122946 | - memset(aToOpen, 1, nIdx+1); | |
| 122947 | - }else{ | |
| 122948 | - for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ | |
| 122949 | - if( pIdx->onError==OE_Replace ){ | |
| 122950 | - memset(aToOpen, 1, nIdx+1); | |
| 122951 | - break; | |
| 122952 | - } | |
| 122953 | - } | |
| 122954 | - } | |
| 122955 | - if( okOnePass ){ | |
| 123259 | + int addrOnce = 0; | |
| 123260 | + | |
| 123261 | + /* Open every index that needs updating. */ | |
| 123262 | + if( eOnePass!=ONEPASS_OFF ){ | |
| 122956 | 123263 | if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0; |
| 122957 | 123264 | if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0; |
| 122958 | 123265 | } |
| 123266 | + | |
| 123267 | + if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){ | |
| 123268 | + addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); | |
| 123269 | + } | |
| 122959 | 123270 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, aToOpen, |
| 122960 | 123271 | 0, 0); |
| 123272 | + if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce); | |
| 122961 | 123273 | } |
| 122962 | 123274 | |
| 122963 | 123275 | /* Top of the update loop */ |
| 122964 | - if( okOnePass ){ | |
| 122965 | - if( aToOpen[iDataCur-iBaseCur] && !isView ){ | |
| 123276 | + if( eOnePass!=ONEPASS_OFF ){ | |
| 123277 | + if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){ | |
| 122966 | 123278 | assert( pPk ); |
| 122967 | 123279 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey); |
| 122968 | 123280 | VdbeCoverageNeverTaken(v); |
| 122969 | 123281 | } |
| 122970 | - labelContinue = labelBreak; | |
| 123282 | + if( eOnePass==ONEPASS_SINGLE ){ | |
| 123283 | + labelContinue = labelBreak; | |
| 123284 | + }else{ | |
| 123285 | + labelContinue = sqlite3VdbeMakeLabel(v); | |
| 123286 | + } | |
| 122971 | 123287 | sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak); |
| 122972 | 123288 | VdbeCoverageIf(v, pPk==0); |
| 122973 | 123289 | VdbeCoverageIf(v, pPk!=0); |
| 122974 | 123290 | }else if( pPk ){ |
| 122975 | 123291 | labelContinue = sqlite3VdbeMakeLabel(v); |
| @@ -123090,11 +123406,10 @@ | ||
| 123090 | 123406 | } |
| 123091 | 123407 | } |
| 123092 | 123408 | |
| 123093 | 123409 | if( !isView ){ |
| 123094 | 123410 | int addr1 = 0; /* Address of jump instruction */ |
| 123095 | - int bReplace = 0; /* True if REPLACE conflict resolution might happen */ | |
| 123096 | 123411 | |
| 123097 | 123412 | /* Do constraint checks. */ |
| 123098 | 123413 | assert( regOldRowid>0 ); |
| 123099 | 123414 | sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur, |
| 123100 | 123415 | regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace, |
| @@ -123126,18 +123441,22 @@ | ||
| 123126 | 123441 | ** is the column index supplied by the user. |
| 123127 | 123442 | */ |
| 123128 | 123443 | assert( regNew==regNewRowid+1 ); |
| 123129 | 123444 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 123130 | 123445 | sqlite3VdbeAddOp3(v, OP_Delete, iDataCur, |
| 123131 | - OPFLAG_ISUPDATE | ((hasFK || chngKey || pPk!=0) ? 0 : OPFLAG_ISNOOP), | |
| 123446 | + OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP), | |
| 123132 | 123447 | regNewRowid |
| 123133 | 123448 | ); |
| 123449 | + if( eOnePass==ONEPASS_MULTI ){ | |
| 123450 | + assert( hasFK==0 && chngKey==0 ); | |
| 123451 | + sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION); | |
| 123452 | + } | |
| 123134 | 123453 | if( !pParse->nested ){ |
| 123135 | 123454 | sqlite3VdbeAppendP4(v, pTab, P4_TABLE); |
| 123136 | 123455 | } |
| 123137 | 123456 | #else |
| 123138 | - if( hasFK || chngKey || pPk!=0 ){ | |
| 123457 | + if( hasFK || chngKey ){ | |
| 123139 | 123458 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0); |
| 123140 | 123459 | } |
| 123141 | 123460 | #endif |
| 123142 | 123461 | if( bReplace || chngKey ){ |
| 123143 | 123462 | sqlite3VdbeJumpHere(v, addr1); |
| @@ -123146,12 +123465,15 @@ | ||
| 123146 | 123465 | if( hasFK ){ |
| 123147 | 123466 | sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey); |
| 123148 | 123467 | } |
| 123149 | 123468 | |
| 123150 | 123469 | /* Insert the new index entries and the new record. */ |
| 123151 | - sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur, | |
| 123152 | - regNewRowid, aRegIdx, 1, 0, 0); | |
| 123470 | + sqlite3CompleteInsertion( | |
| 123471 | + pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx, | |
| 123472 | + OPFLAG_ISUPDATE | (eOnePass==ONEPASS_MULTI ? OPFLAG_SAVEPOSITION : 0), | |
| 123473 | + 0, 0 | |
| 123474 | + ); | |
| 123153 | 123475 | |
| 123154 | 123476 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 123155 | 123477 | ** handle rows (possibly in other tables) that refer via a foreign key |
| 123156 | 123478 | ** to the row just updated. */ |
| 123157 | 123479 | if( hasFK ){ |
| @@ -123169,12 +123491,15 @@ | ||
| 123169 | 123491 | TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue); |
| 123170 | 123492 | |
| 123171 | 123493 | /* Repeat the above with the next record to be updated, until |
| 123172 | 123494 | ** all record selected by the WHERE clause have been updated. |
| 123173 | 123495 | */ |
| 123174 | - if( okOnePass ){ | |
| 123496 | + if( eOnePass==ONEPASS_SINGLE ){ | |
| 123175 | 123497 | /* Nothing to do at end-of-loop for a single-pass */ |
| 123498 | + }else if( eOnePass==ONEPASS_MULTI ){ | |
| 123499 | + sqlite3VdbeResolveLabel(v, labelContinue); | |
| 123500 | + sqlite3WhereEnd(pWInfo); | |
| 123176 | 123501 | }else if( pPk ){ |
| 123177 | 123502 | sqlite3VdbeResolveLabel(v, labelContinue); |
| 123178 | 123503 | sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v); |
| 123179 | 123504 | }else{ |
| 123180 | 123505 | sqlite3VdbeGoto(v, labelContinue); |
| @@ -127090,11 +127415,14 @@ | ||
| 127090 | 127415 | |
| 127091 | 127416 | /* Seek the table cursor, if required */ |
| 127092 | 127417 | if( omitTable ){ |
| 127093 | 127418 | /* pIdx is a covering index. No need to access the main table. */ |
| 127094 | 127419 | }else if( HasRowid(pIdx->pTable) ){ |
| 127095 | - if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0 ){ | |
| 127420 | + if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE) || ( | |
| 127421 | + (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE) | |
| 127422 | + && (pWInfo->eOnePass==ONEPASS_SINGLE) | |
| 127423 | + )){ | |
| 127096 | 127424 | iRowidReg = ++pParse->nMem; |
| 127097 | 127425 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); |
| 127098 | 127426 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 127099 | 127427 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg); |
| 127100 | 127428 | VdbeCoverage(v); |
| @@ -128454,10 +128782,11 @@ | ||
| 128454 | 128782 | int noCase = 0; /* uppercase equivalent to lowercase */ |
| 128455 | 128783 | int op; /* Top-level operator. pExpr->op */ |
| 128456 | 128784 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 128457 | 128785 | sqlite3 *db = pParse->db; /* Database connection */ |
| 128458 | 128786 | unsigned char eOp2; /* op2 value for LIKE/REGEXP/GLOB */ |
| 128787 | + int nLeft; /* Number of elements on left side vector */ | |
| 128459 | 128788 | |
| 128460 | 128789 | if( db->mallocFailed ){ |
| 128461 | 128790 | return; |
| 128462 | 128791 | } |
| 128463 | 128792 | pTerm = &pWC->a[idxTerm]; |
| @@ -128483,10 +128812,14 @@ | ||
| 128483 | 128812 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 128484 | 128813 | Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable); |
| 128485 | 128814 | prereqAll |= x; |
| 128486 | 128815 | extraRight = x-1; /* ON clause terms may not be used with an index |
| 128487 | 128816 | ** on left table of a LEFT JOIN. Ticket #3015 */ |
| 128817 | + if( (prereqAll>>1)>=x ){ | |
| 128818 | + sqlite3ErrorMsg(pParse, "ON clause references tables to its right"); | |
| 128819 | + return; | |
| 128820 | + } | |
| 128488 | 128821 | } |
| 128489 | 128822 | pTerm->prereqAll = prereqAll; |
| 128490 | 128823 | pTerm->leftCursor = -1; |
| 128491 | 128824 | pTerm->iParent = -1; |
| 128492 | 128825 | pTerm->eOperator = 0; |
| @@ -128725,17 +129058,16 @@ | ||
| 128725 | 129058 | ** |
| 128726 | 129059 | ** This is only required if at least one side of the comparison operation |
| 128727 | 129060 | ** is not a sub-select. */ |
| 128728 | 129061 | if( pWC->op==TK_AND |
| 128729 | 129062 | && (pExpr->op==TK_EQ || pExpr->op==TK_IS) |
| 128730 | - && sqlite3ExprIsVector(pExpr->pLeft) | |
| 129063 | + && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1 | |
| 129064 | + && sqlite3ExprVectorSize(pExpr->pRight)==nLeft | |
| 128731 | 129065 | && ( (pExpr->pLeft->flags & EP_xIsSelect)==0 |
| 128732 | - || (pExpr->pRight->flags & EP_xIsSelect)==0 | |
| 128733 | - )){ | |
| 128734 | - int nLeft = sqlite3ExprVectorSize(pExpr->pLeft); | |
| 129066 | + || (pExpr->pRight->flags & EP_xIsSelect)==0) | |
| 129067 | + ){ | |
| 128735 | 129068 | int i; |
| 128736 | - assert( nLeft==sqlite3ExprVectorSize(pExpr->pRight) ); | |
| 128737 | 129069 | for(i=0; i<nLeft; i++){ |
| 128738 | 129070 | int idxNew; |
| 128739 | 129071 | Expr *pNew; |
| 128740 | 129072 | Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i); |
| 128741 | 129073 | Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i); |
| @@ -133934,11 +134266,12 @@ | ||
| 133934 | 134266 | x = sqlite3ColumnOfIndex(pIdx, x); |
| 133935 | 134267 | if( x>=0 ){ |
| 133936 | 134268 | pOp->p2 = x; |
| 133937 | 134269 | pOp->p1 = pLevel->iIdxCur; |
| 133938 | 134270 | } |
| 133939 | - assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 ); | |
| 134271 | + assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 | |
| 134272 | + || pWInfo->eOnePass ); | |
| 133940 | 134273 | }else if( pOp->opcode==OP_Rowid ){ |
| 133941 | 134274 | pOp->p1 = pLevel->iIdxCur; |
| 133942 | 134275 | pOp->opcode = OP_IdxRowid; |
| 133943 | 134276 | } |
| 133944 | 134277 | } |
| @@ -133998,10 +134331,23 @@ | ||
| 133998 | 134331 | ** Indicate that sqlite3ParserFree() will never be called with a null |
| 133999 | 134332 | ** pointer. |
| 134000 | 134333 | */ |
| 134001 | 134334 | #define YYPARSEFREENEVERNULL 1 |
| 134002 | 134335 | |
| 134336 | +/* | |
| 134337 | +** In the amalgamation, the parse.c file generated by lemon and the | |
| 134338 | +** tokenize.c file are concatenated. In that case, sqlite3RunParser() | |
| 134339 | +** has access to the the size of the yyParser object and so the parser | |
| 134340 | +** engine can be allocated from stack. In that case, only the | |
| 134341 | +** sqlite3ParserInit() and sqlite3ParserFinalize() routines are invoked | |
| 134342 | +** and the sqlite3ParserAlloc() and sqlite3ParserFree() routines can be | |
| 134343 | +** omitted. | |
| 134344 | +*/ | |
| 134345 | +#ifdef SQLITE_AMALGAMATION | |
| 134346 | +# define sqlite3Parser_ENGINEALWAYSONSTACK 1 | |
| 134347 | +#endif | |
| 134348 | + | |
| 134003 | 134349 | /* |
| 134004 | 134350 | ** Alternative datatype for the argument to the malloc() routine passed |
| 134005 | 134351 | ** into sqlite3ParserAlloc(). The default is size_t. |
| 134006 | 134352 | */ |
| 134007 | 134353 | #define YYMALLOCARGTYPE u64 |
| @@ -135446,10 +135792,35 @@ | ||
| 135446 | 135792 | */ |
| 135447 | 135793 | #ifndef YYMALLOCARGTYPE |
| 135448 | 135794 | # define YYMALLOCARGTYPE size_t |
| 135449 | 135795 | #endif |
| 135450 | 135796 | |
| 135797 | +/* Initialize a new parser that has already been allocated. | |
| 135798 | +*/ | |
| 135799 | +SQLITE_PRIVATE void sqlite3ParserInit(void *yypParser){ | |
| 135800 | + yyParser *pParser = (yyParser*)yypParser; | |
| 135801 | +#ifdef YYTRACKMAXSTACKDEPTH | |
| 135802 | + pParser->yyhwm = 0; | |
| 135803 | +#endif | |
| 135804 | +#if YYSTACKDEPTH<=0 | |
| 135805 | + pParser->yytos = NULL; | |
| 135806 | + pParser->yystack = NULL; | |
| 135807 | + pParser->yystksz = 0; | |
| 135808 | + if( yyGrowStack(pParser) ){ | |
| 135809 | + pParser->yystack = &pParser->yystk0; | |
| 135810 | + pParser->yystksz = 1; | |
| 135811 | + } | |
| 135812 | +#endif | |
| 135813 | +#ifndef YYNOERRORRECOVERY | |
| 135814 | + pParser->yyerrcnt = -1; | |
| 135815 | +#endif | |
| 135816 | + pParser->yytos = pParser->yystack; | |
| 135817 | + pParser->yystack[0].stateno = 0; | |
| 135818 | + pParser->yystack[0].major = 0; | |
| 135819 | +} | |
| 135820 | + | |
| 135821 | +#ifndef sqlite3Parser_ENGINEALWAYSONSTACK | |
| 135451 | 135822 | /* |
| 135452 | 135823 | ** This function allocates a new parser. |
| 135453 | 135824 | ** The only argument is a pointer to a function which works like |
| 135454 | 135825 | ** malloc. |
| 135455 | 135826 | ** |
| @@ -135461,32 +135832,15 @@ | ||
| 135461 | 135832 | ** to sqlite3Parser and sqlite3ParserFree. |
| 135462 | 135833 | */ |
| 135463 | 135834 | SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ |
| 135464 | 135835 | yyParser *pParser; |
| 135465 | 135836 | pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); |
| 135466 | - if( pParser ){ | |
| 135467 | -#ifdef YYTRACKMAXSTACKDEPTH | |
| 135468 | - pParser->yyhwm = 0; | |
| 135469 | -#endif | |
| 135470 | -#if YYSTACKDEPTH<=0 | |
| 135471 | - pParser->yytos = NULL; | |
| 135472 | - pParser->yystack = NULL; | |
| 135473 | - pParser->yystksz = 0; | |
| 135474 | - if( yyGrowStack(pParser) ){ | |
| 135475 | - pParser->yystack = &pParser->yystk0; | |
| 135476 | - pParser->yystksz = 1; | |
| 135477 | - } | |
| 135478 | -#endif | |
| 135479 | -#ifndef YYNOERRORRECOVERY | |
| 135480 | - pParser->yyerrcnt = -1; | |
| 135481 | -#endif | |
| 135482 | - pParser->yytos = pParser->yystack; | |
| 135483 | - pParser->yystack[0].stateno = 0; | |
| 135484 | - pParser->yystack[0].major = 0; | |
| 135485 | - } | |
| 135837 | + if( pParser ) sqlite3ParserInit(pParser); | |
| 135486 | 135838 | return pParser; |
| 135487 | 135839 | } |
| 135840 | +#endif /* sqlite3Parser_ENGINEALWAYSONSTACK */ | |
| 135841 | + | |
| 135488 | 135842 | |
| 135489 | 135843 | /* The following function deletes the "minor type" or semantic value |
| 135490 | 135844 | ** associated with a symbol. The symbol can be either a terminal |
| 135491 | 135845 | ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is |
| 135492 | 135846 | ** a pointer to the value to be deleted. The code used to do the |
| @@ -135608,10 +135962,22 @@ | ||
| 135608 | 135962 | } |
| 135609 | 135963 | #endif |
| 135610 | 135964 | yy_destructor(pParser, yytos->major, &yytos->minor); |
| 135611 | 135965 | } |
| 135612 | 135966 | |
| 135967 | +/* | |
| 135968 | +** Clear all secondary memory allocations from the parser | |
| 135969 | +*/ | |
| 135970 | +SQLITE_PRIVATE void sqlite3ParserFinalize(void *p){ | |
| 135971 | + yyParser *pParser = (yyParser*)p; | |
| 135972 | + while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); | |
| 135973 | +#if YYSTACKDEPTH<=0 | |
| 135974 | + if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); | |
| 135975 | +#endif | |
| 135976 | +} | |
| 135977 | + | |
| 135978 | +#ifndef sqlite3Parser_ENGINEALWAYSONSTACK | |
| 135613 | 135979 | /* |
| 135614 | 135980 | ** Deallocate and destroy a parser. Destructors are called for |
| 135615 | 135981 | ** all stack elements before shutting the parser down. |
| 135616 | 135982 | ** |
| 135617 | 135983 | ** If the YYPARSEFREENEVERNULL macro exists (for example because it |
| @@ -135620,20 +135986,17 @@ | ||
| 135620 | 135986 | */ |
| 135621 | 135987 | SQLITE_PRIVATE void sqlite3ParserFree( |
| 135622 | 135988 | void *p, /* The parser to be deleted */ |
| 135623 | 135989 | void (*freeProc)(void*) /* Function used to reclaim memory */ |
| 135624 | 135990 | ){ |
| 135625 | - yyParser *pParser = (yyParser*)p; | |
| 135626 | 135991 | #ifndef YYPARSEFREENEVERNULL |
| 135627 | - if( pParser==0 ) return; | |
| 135628 | -#endif | |
| 135629 | - while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); | |
| 135630 | -#if YYSTACKDEPTH<=0 | |
| 135631 | - if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); | |
| 135632 | -#endif | |
| 135633 | - (*freeProc)((void*)pParser); | |
| 135634 | -} | |
| 135992 | + if( p==0 ) return; | |
| 135993 | +#endif | |
| 135994 | + sqlite3ParserFinalize(p); | |
| 135995 | + (*freeProc)(p); | |
| 135996 | +} | |
| 135997 | +#endif /* sqlite3Parser_ENGINEALWAYSONSTACK */ | |
| 135635 | 135998 | |
| 135636 | 135999 | /* |
| 135637 | 136000 | ** Return the peak depth of the stack for a parser. |
| 135638 | 136001 | */ |
| 135639 | 136002 | #ifdef YYTRACKMAXSTACKDEPTH |
| @@ -138483,10 +138846,13 @@ | ||
| 138483 | 138846 | void *pEngine; /* The LEMON-generated LALR(1) parser */ |
| 138484 | 138847 | int tokenType; /* type of the next token */ |
| 138485 | 138848 | int lastTokenParsed = -1; /* type of the previous token */ |
| 138486 | 138849 | sqlite3 *db = pParse->db; /* The database connection */ |
| 138487 | 138850 | int mxSqlLen; /* Max length of an SQL string */ |
| 138851 | +#ifdef sqlite3Parser_ENGINEALWAYSONSTACK | |
| 138852 | + unsigned char zSpace[sizeof(yyParser)]; /* Space for parser engine object */ | |
| 138853 | +#endif | |
| 138488 | 138854 | |
| 138489 | 138855 | assert( zSql!=0 ); |
| 138490 | 138856 | mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 138491 | 138857 | if( db->nVdbeActive==0 ){ |
| 138492 | 138858 | db->u1.isInterrupted = 0; |
| @@ -138494,15 +138860,20 @@ | ||
| 138494 | 138860 | pParse->rc = SQLITE_OK; |
| 138495 | 138861 | pParse->zTail = zSql; |
| 138496 | 138862 | i = 0; |
| 138497 | 138863 | assert( pzErrMsg!=0 ); |
| 138498 | 138864 | /* sqlite3ParserTrace(stdout, "parser: "); */ |
| 138865 | +#ifdef sqlite3Parser_ENGINEALWAYSONSTACK | |
| 138866 | + pEngine = zSpace; | |
| 138867 | + sqlite3ParserInit(pEngine); | |
| 138868 | +#else | |
| 138499 | 138869 | pEngine = sqlite3ParserAlloc(sqlite3Malloc); |
| 138500 | 138870 | if( pEngine==0 ){ |
| 138501 | 138871 | sqlite3OomFault(db); |
| 138502 | 138872 | return SQLITE_NOMEM_BKPT; |
| 138503 | 138873 | } |
| 138874 | +#endif | |
| 138504 | 138875 | assert( pParse->pNewTable==0 ); |
| 138505 | 138876 | assert( pParse->pNewTrigger==0 ); |
| 138506 | 138877 | assert( pParse->nVar==0 ); |
| 138507 | 138878 | assert( pParse->pVList==0 ); |
| 138508 | 138879 | while( 1 ){ |
| @@ -138550,11 +138921,15 @@ | ||
| 138550 | 138921 | sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK, |
| 138551 | 138922 | sqlite3ParserStackPeak(pEngine) |
| 138552 | 138923 | ); |
| 138553 | 138924 | sqlite3_mutex_leave(sqlite3MallocMutex()); |
| 138554 | 138925 | #endif /* YYDEBUG */ |
| 138926 | +#ifdef sqlite3Parser_ENGINEALWAYSONSTACK | |
| 138927 | + sqlite3ParserFinalize(pEngine); | |
| 138928 | +#else | |
| 138555 | 138929 | sqlite3ParserFree(pEngine, sqlite3_free); |
| 138930 | +#endif | |
| 138556 | 138931 | if( db->mallocFailed ){ |
| 138557 | 138932 | pParse->rc = SQLITE_NOMEM_BKPT; |
| 138558 | 138933 | } |
| 138559 | 138934 | if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){ |
| 138560 | 138935 | pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc)); |
| @@ -145675,13 +146050,13 @@ | ||
| 145675 | 146050 | p->nPendingData = 0; |
| 145676 | 146051 | p->azColumn = (char **)&p[1]; |
| 145677 | 146052 | p->pTokenizer = pTokenizer; |
| 145678 | 146053 | p->nMaxPendingData = FTS3_MAX_PENDING_DATA; |
| 145679 | 146054 | p->bHasDocsize = (isFts4 && bNoDocsize==0); |
| 145680 | - p->bHasStat = isFts4; | |
| 145681 | - p->bFts4 = isFts4; | |
| 145682 | - p->bDescIdx = bDescIdx; | |
| 146055 | + p->bHasStat = (u8)isFts4; | |
| 146056 | + p->bFts4 = (u8)isFts4; | |
| 146057 | + p->bDescIdx = (u8)bDescIdx; | |
| 145683 | 146058 | p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */ |
| 145684 | 146059 | p->zContentTbl = zContent; |
| 145685 | 146060 | p->zLanguageid = zLanguageid; |
| 145686 | 146061 | zContent = 0; |
| 145687 | 146062 | zLanguageid = 0; |
| @@ -147734,11 +148109,11 @@ | ||
| 147734 | 148109 | sqlite3_stmt *pStmt = 0; |
| 147735 | 148110 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 147736 | 148111 | if( rc==SQLITE_OK ){ |
| 147737 | 148112 | int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW); |
| 147738 | 148113 | rc = sqlite3_finalize(pStmt); |
| 147739 | - if( rc==SQLITE_OK ) p->bHasStat = bHasStat; | |
| 148114 | + if( rc==SQLITE_OK ) p->bHasStat = (u8)bHasStat; | |
| 147740 | 148115 | } |
| 147741 | 148116 | sqlite3_free(zSql); |
| 147742 | 148117 | }else{ |
| 147743 | 148118 | rc = SQLITE_NOMEM; |
| 147744 | 148119 | } |
| @@ -162638,28 +163013,33 @@ | ||
| 162638 | 163013 | struct Rtree { |
| 162639 | 163014 | sqlite3_vtab base; /* Base class. Must be first */ |
| 162640 | 163015 | sqlite3 *db; /* Host database connection */ |
| 162641 | 163016 | int iNodeSize; /* Size in bytes of each node in the node table */ |
| 162642 | 163017 | u8 nDim; /* Number of dimensions */ |
| 163018 | + u8 nDim2; /* Twice the number of dimensions */ | |
| 162643 | 163019 | u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */ |
| 162644 | 163020 | u8 nBytesPerCell; /* Bytes consumed per cell */ |
| 163021 | + u8 inWrTrans; /* True if inside write transaction */ | |
| 162645 | 163022 | int iDepth; /* Current depth of the r-tree structure */ |
| 162646 | 163023 | char *zDb; /* Name of database containing r-tree table */ |
| 162647 | 163024 | char *zName; /* Name of r-tree table */ |
| 162648 | - int nBusy; /* Current number of users of this structure */ | |
| 163025 | + u32 nBusy; /* Current number of users of this structure */ | |
| 162649 | 163026 | i64 nRowEst; /* Estimated number of rows in this table */ |
| 163027 | + u32 nCursor; /* Number of open cursors */ | |
| 162650 | 163028 | |
| 162651 | 163029 | /* List of nodes removed during a CondenseTree operation. List is |
| 162652 | 163030 | ** linked together via the pointer normally used for hash chains - |
| 162653 | 163031 | ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree |
| 162654 | 163032 | ** headed by the node (leaf nodes have RtreeNode.iNode==0). |
| 162655 | 163033 | */ |
| 162656 | 163034 | RtreeNode *pDeleted; |
| 162657 | 163035 | int iReinsertHeight; /* Height of sub-trees Reinsert() has run on */ |
| 163036 | + | |
| 163037 | + /* Blob I/O on xxx_node */ | |
| 163038 | + sqlite3_blob *pNodeBlob; | |
| 162658 | 163039 | |
| 162659 | 163040 | /* Statements to read/write/delete a record from xxx_node */ |
| 162660 | - sqlite3_stmt *pReadNode; | |
| 162661 | 163041 | sqlite3_stmt *pWriteNode; |
| 162662 | 163042 | sqlite3_stmt *pDeleteNode; |
| 162663 | 163043 | |
| 162664 | 163044 | /* Statements to read/write/delete a record from xxx_rowid */ |
| 162665 | 163045 | sqlite3_stmt *pReadRowid; |
| @@ -162884,26 +163264,110 @@ | ||
| 162884 | 163264 | #endif |
| 162885 | 163265 | #ifndef MIN |
| 162886 | 163266 | # define MIN(x,y) ((x) > (y) ? (y) : (x)) |
| 162887 | 163267 | #endif |
| 162888 | 163268 | |
| 163269 | +/* What version of GCC is being used. 0 means GCC is not being used */ | |
| 163270 | +#ifndef GCC_VERSION | |
| 163271 | +#ifdef __GNUC__ | |
| 163272 | +# define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) | |
| 163273 | +#else | |
| 163274 | +# define GCC_VERSION 0 | |
| 163275 | +#endif | |
| 163276 | +#endif | |
| 163277 | + | |
| 163278 | +/* What version of CLANG is being used. 0 means CLANG is not being used */ | |
| 163279 | +#ifndef CLANG_VERSION | |
| 163280 | +#if defined(__clang__) && !defined(_WIN32) | |
| 163281 | +# define CLANG_VERSION \ | |
| 163282 | + (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) | |
| 163283 | +#else | |
| 163284 | +# define CLANG_VERSION 0 | |
| 163285 | +#endif | |
| 163286 | +#endif | |
| 163287 | + | |
| 163288 | +/* The testcase() macro should already be defined in the amalgamation. If | |
| 163289 | +** it is not, make it a no-op. | |
| 163290 | +*/ | |
| 163291 | +#ifndef SQLITE_AMALGAMATION | |
| 163292 | +# define testcase(X) | |
| 163293 | +#endif | |
| 163294 | + | |
| 163295 | +/* | |
| 163296 | +** Macros to determine whether the machine is big or little endian, | |
| 163297 | +** and whether or not that determination is run-time or compile-time. | |
| 163298 | +** | |
| 163299 | +** For best performance, an attempt is made to guess at the byte-order | |
| 163300 | +** using C-preprocessor macros. If that is unsuccessful, or if | |
| 163301 | +** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined | |
| 163302 | +** at run-time. | |
| 163303 | +*/ | |
| 163304 | +#ifndef SQLITE_BYTEORDER | |
| 163305 | +#if (defined(i386) || defined(__i386__) || defined(_M_IX86) || \ | |
| 163306 | + defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ | |
| 163307 | + defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \ | |
| 163308 | + defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER) | |
| 163309 | +# define SQLITE_BYTEORDER 1234 | |
| 163310 | +#elif (defined(sparc) || defined(__ppc__)) \ | |
| 163311 | + && !defined(SQLITE_RUNTIME_BYTEORDER) | |
| 163312 | +# define SQLITE_BYTEORDER 4321 | |
| 163313 | +#else | |
| 163314 | +# define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */ | |
| 163315 | +#endif | |
| 163316 | +#endif | |
| 163317 | + | |
| 163318 | + | |
| 163319 | +/* What version of MSVC is being used. 0 means MSVC is not being used */ | |
| 163320 | +#ifndef MSVC_VERSION | |
| 163321 | +#if defined(_MSC_VER) | |
| 163322 | +# define MSVC_VERSION _MSC_VER | |
| 163323 | +#else | |
| 163324 | +# define MSVC_VERSION 0 | |
| 163325 | +#endif | |
| 163326 | +#endif | |
| 163327 | + | |
| 162889 | 163328 | /* |
| 162890 | 163329 | ** Functions to deserialize a 16 bit integer, 32 bit real number and |
| 162891 | 163330 | ** 64 bit integer. The deserialized value is returned. |
| 162892 | 163331 | */ |
| 162893 | 163332 | static int readInt16(u8 *p){ |
| 162894 | 163333 | return (p[0]<<8) + p[1]; |
| 162895 | 163334 | } |
| 162896 | 163335 | static void readCoord(u8 *p, RtreeCoord *pCoord){ |
| 163336 | + assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ | |
| 163337 | +#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 | |
| 163338 | + pCoord->u = _byteswap_ulong(*(u32*)p); | |
| 163339 | +#elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163340 | + pCoord->u = __builtin_bswap32(*(u32*)p); | |
| 163341 | +#elif SQLITE_BYTEORDER==1234 | |
| 163342 | + pCoord->u = ((pCoord->u>>24)&0xff)|((pCoord->u>>8)&0xff00)| | |
| 163343 | + ((pCoord->u&0xff)<<24)|((pCoord->u&0xff00)<<8); | |
| 163344 | +#elif SQLITE_BYTEORDER==4321 | |
| 163345 | + pCoord->u = *(u32*)p; | |
| 163346 | +#else | |
| 162897 | 163347 | pCoord->u = ( |
| 162898 | 163348 | (((u32)p[0]) << 24) + |
| 162899 | 163349 | (((u32)p[1]) << 16) + |
| 162900 | 163350 | (((u32)p[2]) << 8) + |
| 162901 | 163351 | (((u32)p[3]) << 0) |
| 162902 | 163352 | ); |
| 163353 | +#endif | |
| 162903 | 163354 | } |
| 162904 | 163355 | static i64 readInt64(u8 *p){ |
| 163356 | +#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 | |
| 163357 | + u64 x; | |
| 163358 | + memcpy(&x, p, 8); | |
| 163359 | + return (i64)_byteswap_uint64(x); | |
| 163360 | +#elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163361 | + u64 x; | |
| 163362 | + memcpy(&x, p, 8); | |
| 163363 | + return (i64)__builtin_bswap64(x); | |
| 163364 | +#elif SQLITE_BYTEORDER==4321 | |
| 163365 | + i64 x; | |
| 163366 | + memcpy(&x, p, 8); | |
| 163367 | + return x; | |
| 163368 | +#else | |
| 162905 | 163369 | return ( |
| 162906 | 163370 | (((i64)p[0]) << 56) + |
| 162907 | 163371 | (((i64)p[1]) << 48) + |
| 162908 | 163372 | (((i64)p[2]) << 40) + |
| 162909 | 163373 | (((i64)p[3]) << 32) + |
| @@ -162910,10 +163374,11 @@ | ||
| 162910 | 163374 | (((i64)p[4]) << 24) + |
| 162911 | 163375 | (((i64)p[5]) << 16) + |
| 162912 | 163376 | (((i64)p[6]) << 8) + |
| 162913 | 163377 | (((i64)p[7]) << 0) |
| 162914 | 163378 | ); |
| 163379 | +#endif | |
| 162915 | 163380 | } |
| 162916 | 163381 | |
| 162917 | 163382 | /* |
| 162918 | 163383 | ** Functions to serialize a 16 bit integer, 32 bit real number and |
| 162919 | 163384 | ** 64 bit integer. The value returned is the number of bytes written |
| @@ -162924,28 +163389,50 @@ | ||
| 162924 | 163389 | p[1] = (i>> 0)&0xFF; |
| 162925 | 163390 | return 2; |
| 162926 | 163391 | } |
| 162927 | 163392 | static int writeCoord(u8 *p, RtreeCoord *pCoord){ |
| 162928 | 163393 | u32 i; |
| 163394 | + assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ | |
| 162929 | 163395 | assert( sizeof(RtreeCoord)==4 ); |
| 162930 | 163396 | assert( sizeof(u32)==4 ); |
| 163397 | +#if SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163398 | + i = __builtin_bswap32(pCoord->u); | |
| 163399 | + memcpy(p, &i, 4); | |
| 163400 | +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 | |
| 163401 | + i = _byteswap_ulong(pCoord->u); | |
| 163402 | + memcpy(p, &i, 4); | |
| 163403 | +#elif SQLITE_BYTEORDER==4321 | |
| 163404 | + i = pCoord->u; | |
| 163405 | + memcpy(p, &i, 4); | |
| 163406 | +#else | |
| 162931 | 163407 | i = pCoord->u; |
| 162932 | 163408 | p[0] = (i>>24)&0xFF; |
| 162933 | 163409 | p[1] = (i>>16)&0xFF; |
| 162934 | 163410 | p[2] = (i>> 8)&0xFF; |
| 162935 | 163411 | p[3] = (i>> 0)&0xFF; |
| 163412 | +#endif | |
| 162936 | 163413 | return 4; |
| 162937 | 163414 | } |
| 162938 | 163415 | static int writeInt64(u8 *p, i64 i){ |
| 163416 | +#if SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163417 | + i = (i64)__builtin_bswap64((u64)i); | |
| 163418 | + memcpy(p, &i, 8); | |
| 163419 | +#elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 | |
| 163420 | + i = (i64)_byteswap_uint64((u64)i); | |
| 163421 | + memcpy(p, &i, 8); | |
| 163422 | +#elif SQLITE_BYTEORDER==4321 | |
| 163423 | + memcpy(p, &i, 8); | |
| 163424 | +#else | |
| 162939 | 163425 | p[0] = (i>>56)&0xFF; |
| 162940 | 163426 | p[1] = (i>>48)&0xFF; |
| 162941 | 163427 | p[2] = (i>>40)&0xFF; |
| 162942 | 163428 | p[3] = (i>>32)&0xFF; |
| 162943 | 163429 | p[4] = (i>>24)&0xFF; |
| 162944 | 163430 | p[5] = (i>>16)&0xFF; |
| 162945 | 163431 | p[6] = (i>> 8)&0xFF; |
| 162946 | 163432 | p[7] = (i>> 0)&0xFF; |
| 163433 | +#endif | |
| 162947 | 163434 | return 8; |
| 162948 | 163435 | } |
| 162949 | 163436 | |
| 162950 | 163437 | /* |
| 162951 | 163438 | ** Increment the reference count of node p. |
| @@ -163023,10 +163510,21 @@ | ||
| 163023 | 163510 | pNode->isDirty = 1; |
| 163024 | 163511 | nodeReference(pParent); |
| 163025 | 163512 | } |
| 163026 | 163513 | return pNode; |
| 163027 | 163514 | } |
| 163515 | + | |
| 163516 | +/* | |
| 163517 | +** Clear the Rtree.pNodeBlob object | |
| 163518 | +*/ | |
| 163519 | +static void nodeBlobReset(Rtree *pRtree){ | |
| 163520 | + if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){ | |
| 163521 | + sqlite3_blob *pBlob = pRtree->pNodeBlob; | |
| 163522 | + pRtree->pNodeBlob = 0; | |
| 163523 | + sqlite3_blob_close(pBlob); | |
| 163524 | + } | |
| 163525 | +} | |
| 163028 | 163526 | |
| 163029 | 163527 | /* |
| 163030 | 163528 | ** Obtain a reference to an r-tree node. |
| 163031 | 163529 | */ |
| 163032 | 163530 | static int nodeAcquire( |
| @@ -163033,13 +163531,12 @@ | ||
| 163033 | 163531 | Rtree *pRtree, /* R-tree structure */ |
| 163034 | 163532 | i64 iNode, /* Node number to load */ |
| 163035 | 163533 | RtreeNode *pParent, /* Either the parent node or NULL */ |
| 163036 | 163534 | RtreeNode **ppNode /* OUT: Acquired node */ |
| 163037 | 163535 | ){ |
| 163038 | - int rc; | |
| 163039 | - int rc2 = SQLITE_OK; | |
| 163040 | - RtreeNode *pNode; | |
| 163536 | + int rc = SQLITE_OK; | |
| 163537 | + RtreeNode *pNode = 0; | |
| 163041 | 163538 | |
| 163042 | 163539 | /* Check if the requested node is already in the hash table. If so, |
| 163043 | 163540 | ** increase its reference count and return it. |
| 163044 | 163541 | */ |
| 163045 | 163542 | if( (pNode = nodeHashLookup(pRtree, iNode)) ){ |
| @@ -163051,32 +163548,49 @@ | ||
| 163051 | 163548 | pNode->nRef++; |
| 163052 | 163549 | *ppNode = pNode; |
| 163053 | 163550 | return SQLITE_OK; |
| 163054 | 163551 | } |
| 163055 | 163552 | |
| 163056 | - sqlite3_bind_int64(pRtree->pReadNode, 1, iNode); | |
| 163057 | - rc = sqlite3_step(pRtree->pReadNode); | |
| 163058 | - if( rc==SQLITE_ROW ){ | |
| 163059 | - const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0); | |
| 163060 | - if( pRtree->iNodeSize==sqlite3_column_bytes(pRtree->pReadNode, 0) ){ | |
| 163061 | - pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize); | |
| 163062 | - if( !pNode ){ | |
| 163063 | - rc2 = SQLITE_NOMEM; | |
| 163064 | - }else{ | |
| 163065 | - pNode->pParent = pParent; | |
| 163066 | - pNode->zData = (u8 *)&pNode[1]; | |
| 163067 | - pNode->nRef = 1; | |
| 163068 | - pNode->iNode = iNode; | |
| 163069 | - pNode->isDirty = 0; | |
| 163070 | - pNode->pNext = 0; | |
| 163071 | - memcpy(pNode->zData, zBlob, pRtree->iNodeSize); | |
| 163072 | - nodeReference(pParent); | |
| 163073 | - } | |
| 163074 | - } | |
| 163075 | - } | |
| 163076 | - rc = sqlite3_reset(pRtree->pReadNode); | |
| 163077 | - if( rc==SQLITE_OK ) rc = rc2; | |
| 163553 | + if( pRtree->pNodeBlob ){ | |
| 163554 | + sqlite3_blob *pBlob = pRtree->pNodeBlob; | |
| 163555 | + pRtree->pNodeBlob = 0; | |
| 163556 | + rc = sqlite3_blob_reopen(pBlob, iNode); | |
| 163557 | + pRtree->pNodeBlob = pBlob; | |
| 163558 | + if( rc ){ | |
| 163559 | + nodeBlobReset(pRtree); | |
| 163560 | + if( rc==SQLITE_NOMEM ) return SQLITE_NOMEM; | |
| 163561 | + } | |
| 163562 | + } | |
| 163563 | + if( pRtree->pNodeBlob==0 ){ | |
| 163564 | + char *zTab = sqlite3_mprintf("%s_node", pRtree->zName); | |
| 163565 | + if( zTab==0 ) return SQLITE_NOMEM; | |
| 163566 | + rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, zTab, "data", iNode, 0, | |
| 163567 | + &pRtree->pNodeBlob); | |
| 163568 | + sqlite3_free(zTab); | |
| 163569 | + } | |
| 163570 | + if( rc ){ | |
| 163571 | + nodeBlobReset(pRtree); | |
| 163572 | + *ppNode = 0; | |
| 163573 | + /* If unable to open an sqlite3_blob on the desired row, that can only | |
| 163574 | + ** be because the shadow tables hold erroneous data. */ | |
| 163575 | + if( rc==SQLITE_ERROR ) rc = SQLITE_CORRUPT_VTAB; | |
| 163576 | + }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){ | |
| 163577 | + pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize); | |
| 163578 | + if( !pNode ){ | |
| 163579 | + rc = SQLITE_NOMEM; | |
| 163580 | + }else{ | |
| 163581 | + pNode->pParent = pParent; | |
| 163582 | + pNode->zData = (u8 *)&pNode[1]; | |
| 163583 | + pNode->nRef = 1; | |
| 163584 | + pNode->iNode = iNode; | |
| 163585 | + pNode->isDirty = 0; | |
| 163586 | + pNode->pNext = 0; | |
| 163587 | + rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData, | |
| 163588 | + pRtree->iNodeSize, 0); | |
| 163589 | + nodeReference(pParent); | |
| 163590 | + } | |
| 163591 | + } | |
| 163078 | 163592 | |
| 163079 | 163593 | /* If the root node was just loaded, set pRtree->iDepth to the height |
| 163080 | 163594 | ** of the r-tree structure. A height of zero means all data is stored on |
| 163081 | 163595 | ** the root node. A height of one means the children of the root node |
| 163082 | 163596 | ** are the leaves, and so on. If the depth as specified on the root node |
| @@ -163124,11 +163638,11 @@ | ||
| 163124 | 163638 | int iCell /* Index into pNode into which pCell is written */ |
| 163125 | 163639 | ){ |
| 163126 | 163640 | int ii; |
| 163127 | 163641 | u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell]; |
| 163128 | 163642 | p += writeInt64(p, pCell->iRowid); |
| 163129 | - for(ii=0; ii<(pRtree->nDim*2); ii++){ | |
| 163643 | + for(ii=0; ii<pRtree->nDim2; ii++){ | |
| 163130 | 163644 | p += writeCoord(p, &pCell->aCoord[ii]); |
| 163131 | 163645 | } |
| 163132 | 163646 | pNode->isDirty = 1; |
| 163133 | 163647 | } |
| 163134 | 163648 | |
| @@ -163258,17 +163772,20 @@ | ||
| 163258 | 163772 | int iCell, /* Index of the cell within the node */ |
| 163259 | 163773 | RtreeCell *pCell /* OUT: Write the cell contents here */ |
| 163260 | 163774 | ){ |
| 163261 | 163775 | u8 *pData; |
| 163262 | 163776 | RtreeCoord *pCoord; |
| 163263 | - int ii; | |
| 163777 | + int ii = 0; | |
| 163264 | 163778 | pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell); |
| 163265 | 163779 | pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell); |
| 163266 | 163780 | pCoord = pCell->aCoord; |
| 163267 | - for(ii=0; ii<pRtree->nDim*2; ii++){ | |
| 163268 | - readCoord(&pData[ii*4], &pCoord[ii]); | |
| 163269 | - } | |
| 163781 | + do{ | |
| 163782 | + readCoord(pData, &pCoord[ii]); | |
| 163783 | + readCoord(pData+4, &pCoord[ii+1]); | |
| 163784 | + pData += 8; | |
| 163785 | + ii += 2; | |
| 163786 | + }while( ii<pRtree->nDim2 ); | |
| 163270 | 163787 | } |
| 163271 | 163788 | |
| 163272 | 163789 | |
| 163273 | 163790 | /* Forward declaration for the function that does the work of |
| 163274 | 163791 | ** the virtual table module xCreate() and xConnect() methods. |
| @@ -163315,11 +163832,13 @@ | ||
| 163315 | 163832 | ** zero the structure is deleted. |
| 163316 | 163833 | */ |
| 163317 | 163834 | static void rtreeRelease(Rtree *pRtree){ |
| 163318 | 163835 | pRtree->nBusy--; |
| 163319 | 163836 | if( pRtree->nBusy==0 ){ |
| 163320 | - sqlite3_finalize(pRtree->pReadNode); | |
| 163837 | + pRtree->inWrTrans = 0; | |
| 163838 | + pRtree->nCursor = 0; | |
| 163839 | + nodeBlobReset(pRtree); | |
| 163321 | 163840 | sqlite3_finalize(pRtree->pWriteNode); |
| 163322 | 163841 | sqlite3_finalize(pRtree->pDeleteNode); |
| 163323 | 163842 | sqlite3_finalize(pRtree->pReadRowid); |
| 163324 | 163843 | sqlite3_finalize(pRtree->pWriteRowid); |
| 163325 | 163844 | sqlite3_finalize(pRtree->pDeleteRowid); |
| @@ -163353,10 +163872,11 @@ | ||
| 163353 | 163872 | pRtree->zDb, pRtree->zName |
| 163354 | 163873 | ); |
| 163355 | 163874 | if( !zCreate ){ |
| 163356 | 163875 | rc = SQLITE_NOMEM; |
| 163357 | 163876 | }else{ |
| 163877 | + nodeBlobReset(pRtree); | |
| 163358 | 163878 | rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0); |
| 163359 | 163879 | sqlite3_free(zCreate); |
| 163360 | 163880 | } |
| 163361 | 163881 | if( rc==SQLITE_OK ){ |
| 163362 | 163882 | rtreeRelease(pRtree); |
| @@ -163368,17 +163888,19 @@ | ||
| 163368 | 163888 | /* |
| 163369 | 163889 | ** Rtree virtual table module xOpen method. |
| 163370 | 163890 | */ |
| 163371 | 163891 | static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ |
| 163372 | 163892 | int rc = SQLITE_NOMEM; |
| 163893 | + Rtree *pRtree = (Rtree *)pVTab; | |
| 163373 | 163894 | RtreeCursor *pCsr; |
| 163374 | 163895 | |
| 163375 | 163896 | pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor)); |
| 163376 | 163897 | if( pCsr ){ |
| 163377 | 163898 | memset(pCsr, 0, sizeof(RtreeCursor)); |
| 163378 | 163899 | pCsr->base.pVtab = pVTab; |
| 163379 | 163900 | rc = SQLITE_OK; |
| 163901 | + pRtree->nCursor++; | |
| 163380 | 163902 | } |
| 163381 | 163903 | *ppCursor = (sqlite3_vtab_cursor *)pCsr; |
| 163382 | 163904 | |
| 163383 | 163905 | return rc; |
| 163384 | 163906 | } |
| @@ -163407,14 +163929,17 @@ | ||
| 163407 | 163929 | */ |
| 163408 | 163930 | static int rtreeClose(sqlite3_vtab_cursor *cur){ |
| 163409 | 163931 | Rtree *pRtree = (Rtree *)(cur->pVtab); |
| 163410 | 163932 | int ii; |
| 163411 | 163933 | RtreeCursor *pCsr = (RtreeCursor *)cur; |
| 163934 | + assert( pRtree->nCursor>0 ); | |
| 163412 | 163935 | freeCursorConstraints(pCsr); |
| 163413 | 163936 | sqlite3_free(pCsr->aPoint); |
| 163414 | 163937 | for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]); |
| 163415 | 163938 | sqlite3_free(pCsr); |
| 163939 | + pRtree->nCursor--; | |
| 163940 | + nodeBlobReset(pRtree); | |
| 163416 | 163941 | return SQLITE_OK; |
| 163417 | 163942 | } |
| 163418 | 163943 | |
| 163419 | 163944 | /* |
| 163420 | 163945 | ** Rtree virtual table module xEof method. |
| @@ -163433,27 +163958,34 @@ | ||
| 163433 | 163958 | ** endian platforms. The on-disk record stores integer coordinates if |
| 163434 | 163959 | ** eInt is true and it stores 32-bit floating point records if eInt is |
| 163435 | 163960 | ** false. a[] is the four bytes of the on-disk record to be decoded. |
| 163436 | 163961 | ** Store the results in "r". |
| 163437 | 163962 | ** |
| 163438 | -** There are three versions of this macro, one each for little-endian and | |
| 163439 | -** big-endian processors and a third generic implementation. The endian- | |
| 163440 | -** specific implementations are much faster and are preferred if the | |
| 163441 | -** processor endianness is known at compile-time. The SQLITE_BYTEORDER | |
| 163442 | -** macro is part of sqliteInt.h and hence the endian-specific | |
| 163443 | -** implementation will only be used if this module is compiled as part | |
| 163444 | -** of the amalgamation. | |
| 163963 | +** There are five versions of this macro. The last one is generic. The | |
| 163964 | +** other four are various architectures-specific optimizations. | |
| 163445 | 163965 | */ |
| 163446 | -#if defined(SQLITE_BYTEORDER) && SQLITE_BYTEORDER==1234 | |
| 163966 | +#if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 | |
| 163967 | +#define RTREE_DECODE_COORD(eInt, a, r) { \ | |
| 163968 | + RtreeCoord c; /* Coordinate decoded */ \ | |
| 163969 | + c.u = _byteswap_ulong(*(u32*)a); \ | |
| 163970 | + r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ | |
| 163971 | +} | |
| 163972 | +#elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) | |
| 163973 | +#define RTREE_DECODE_COORD(eInt, a, r) { \ | |
| 163974 | + RtreeCoord c; /* Coordinate decoded */ \ | |
| 163975 | + c.u = __builtin_bswap32(*(u32*)a); \ | |
| 163976 | + r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ | |
| 163977 | +} | |
| 163978 | +#elif SQLITE_BYTEORDER==1234 | |
| 163447 | 163979 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163448 | 163980 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163449 | 163981 | memcpy(&c.u,a,4); \ |
| 163450 | 163982 | c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \ |
| 163451 | 163983 | ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \ |
| 163452 | 163984 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163453 | 163985 | } |
| 163454 | -#elif defined(SQLITE_BYTEORDER) && SQLITE_BYTEORDER==4321 | |
| 163986 | +#elif SQLITE_BYTEORDER==4321 | |
| 163455 | 163987 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163456 | 163988 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163457 | 163989 | memcpy(&c.u,a,4); \ |
| 163458 | 163990 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163459 | 163991 | } |
| @@ -163476,30 +164008,58 @@ | ||
| 163476 | 164008 | u8 *pCellData, /* Raw cell content */ |
| 163477 | 164009 | RtreeSearchPoint *pSearch, /* Container of this cell */ |
| 163478 | 164010 | sqlite3_rtree_dbl *prScore, /* OUT: score for the cell */ |
| 163479 | 164011 | int *peWithin /* OUT: visibility of the cell */ |
| 163480 | 164012 | ){ |
| 163481 | - int i; /* Loop counter */ | |
| 163482 | 164013 | sqlite3_rtree_query_info *pInfo = pConstraint->pInfo; /* Callback info */ |
| 163483 | 164014 | int nCoord = pInfo->nCoord; /* No. of coordinates */ |
| 163484 | 164015 | int rc; /* Callback return code */ |
| 164016 | + RtreeCoord c; /* Translator union */ | |
| 163485 | 164017 | sqlite3_rtree_dbl aCoord[RTREE_MAX_DIMENSIONS*2]; /* Decoded coordinates */ |
| 163486 | 164018 | |
| 163487 | 164019 | assert( pConstraint->op==RTREE_MATCH || pConstraint->op==RTREE_QUERY ); |
| 163488 | 164020 | assert( nCoord==2 || nCoord==4 || nCoord==6 || nCoord==8 || nCoord==10 ); |
| 163489 | 164021 | |
| 163490 | 164022 | if( pConstraint->op==RTREE_QUERY && pSearch->iLevel==1 ){ |
| 163491 | 164023 | pInfo->iRowid = readInt64(pCellData); |
| 163492 | 164024 | } |
| 163493 | 164025 | pCellData += 8; |
| 163494 | - for(i=0; i<nCoord; i++, pCellData += 4){ | |
| 163495 | - RTREE_DECODE_COORD(eInt, pCellData, aCoord[i]); | |
| 164026 | +#ifndef SQLITE_RTREE_INT_ONLY | |
| 164027 | + if( eInt==0 ){ | |
| 164028 | + switch( nCoord ){ | |
| 164029 | + case 10: readCoord(pCellData+36, &c); aCoord[9] = c.f; | |
| 164030 | + readCoord(pCellData+32, &c); aCoord[8] = c.f; | |
| 164031 | + case 8: readCoord(pCellData+28, &c); aCoord[7] = c.f; | |
| 164032 | + readCoord(pCellData+24, &c); aCoord[6] = c.f; | |
| 164033 | + case 6: readCoord(pCellData+20, &c); aCoord[5] = c.f; | |
| 164034 | + readCoord(pCellData+16, &c); aCoord[4] = c.f; | |
| 164035 | + case 4: readCoord(pCellData+12, &c); aCoord[3] = c.f; | |
| 164036 | + readCoord(pCellData+8, &c); aCoord[2] = c.f; | |
| 164037 | + default: readCoord(pCellData+4, &c); aCoord[1] = c.f; | |
| 164038 | + readCoord(pCellData, &c); aCoord[0] = c.f; | |
| 164039 | + } | |
| 164040 | + }else | |
| 164041 | +#endif | |
| 164042 | + { | |
| 164043 | + switch( nCoord ){ | |
| 164044 | + case 10: readCoord(pCellData+36, &c); aCoord[9] = c.i; | |
| 164045 | + readCoord(pCellData+32, &c); aCoord[8] = c.i; | |
| 164046 | + case 8: readCoord(pCellData+28, &c); aCoord[7] = c.i; | |
| 164047 | + readCoord(pCellData+24, &c); aCoord[6] = c.i; | |
| 164048 | + case 6: readCoord(pCellData+20, &c); aCoord[5] = c.i; | |
| 164049 | + readCoord(pCellData+16, &c); aCoord[4] = c.i; | |
| 164050 | + case 4: readCoord(pCellData+12, &c); aCoord[3] = c.i; | |
| 164051 | + readCoord(pCellData+8, &c); aCoord[2] = c.i; | |
| 164052 | + default: readCoord(pCellData+4, &c); aCoord[1] = c.i; | |
| 164053 | + readCoord(pCellData, &c); aCoord[0] = c.i; | |
| 164054 | + } | |
| 163496 | 164055 | } |
| 163497 | 164056 | if( pConstraint->op==RTREE_MATCH ){ |
| 164057 | + int eWithin = 0; | |
| 163498 | 164058 | rc = pConstraint->u.xGeom((sqlite3_rtree_geometry*)pInfo, |
| 163499 | - nCoord, aCoord, &i); | |
| 163500 | - if( i==0 ) *peWithin = NOT_WITHIN; | |
| 164059 | + nCoord, aCoord, &eWithin); | |
| 164060 | + if( eWithin==0 ) *peWithin = NOT_WITHIN; | |
| 163501 | 164061 | *prScore = RTREE_ZERO; |
| 163502 | 164062 | }else{ |
| 163503 | 164063 | pInfo->aCoord = aCoord; |
| 163504 | 164064 | pInfo->iLevel = pSearch->iLevel - 1; |
| 163505 | 164065 | pInfo->rScore = pInfo->rParentScore = pSearch->rScore; |
| @@ -163531,10 +164091,11 @@ | ||
| 163531 | 164091 | */ |
| 163532 | 164092 | pCellData += 8 + 4*(p->iCoord&0xfe); |
| 163533 | 164093 | |
| 163534 | 164094 | assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE |
| 163535 | 164095 | || p->op==RTREE_GT || p->op==RTREE_EQ ); |
| 164096 | + assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */ | |
| 163536 | 164097 | switch( p->op ){ |
| 163537 | 164098 | case RTREE_LE: |
| 163538 | 164099 | case RTREE_LT: |
| 163539 | 164100 | case RTREE_EQ: |
| 163540 | 164101 | RTREE_DECODE_COORD(eInt, pCellData, val); |
| @@ -163571,10 +164132,11 @@ | ||
| 163571 | 164132 | RtreeDValue xN; /* Coordinate value converted to a double */ |
| 163572 | 164133 | |
| 163573 | 164134 | assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE |
| 163574 | 164135 | || p->op==RTREE_GT || p->op==RTREE_EQ ); |
| 163575 | 164136 | pCellData += 8 + p->iCoord*4; |
| 164137 | + assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */ | |
| 163576 | 164138 | RTREE_DECODE_COORD(eInt, pCellData, xN); |
| 163577 | 164139 | switch( p->op ){ |
| 163578 | 164140 | case RTREE_LE: if( xN <= p->u.rValue ) return; break; |
| 163579 | 164141 | case RTREE_LT: if( xN < p->u.rValue ) return; break; |
| 163580 | 164142 | case RTREE_GE: if( xN >= p->u.rValue ) return; break; |
| @@ -163639,11 +164201,11 @@ | ||
| 163639 | 164201 | if( pA->iLevel>pB->iLevel ) return +1; |
| 163640 | 164202 | return 0; |
| 163641 | 164203 | } |
| 163642 | 164204 | |
| 163643 | 164205 | /* |
| 163644 | -** Interchange to search points in a cursor. | |
| 164206 | +** Interchange two search points in a cursor. | |
| 163645 | 164207 | */ |
| 163646 | 164208 | static void rtreeSearchPointSwap(RtreeCursor *p, int i, int j){ |
| 163647 | 164209 | RtreeSearchPoint t = p->aPoint[i]; |
| 163648 | 164210 | assert( i<j ); |
| 163649 | 164211 | p->aPoint[i] = p->aPoint[j]; |
| @@ -163887,11 +164449,11 @@ | ||
| 163887 | 164449 | rtreeSearchPointPop(pCur); |
| 163888 | 164450 | } |
| 163889 | 164451 | if( rScore<RTREE_ZERO ) rScore = RTREE_ZERO; |
| 163890 | 164452 | p = rtreeSearchPointNew(pCur, rScore, x.iLevel); |
| 163891 | 164453 | if( p==0 ) return SQLITE_NOMEM; |
| 163892 | - p->eWithin = eWithin; | |
| 164454 | + p->eWithin = (u8)eWithin; | |
| 163893 | 164455 | p->id = x.id; |
| 163894 | 164456 | p->iCell = x.iCell; |
| 163895 | 164457 | RTREE_QUEUE_TRACE(pCur, "PUSH-S:"); |
| 163896 | 164458 | break; |
| 163897 | 164459 | } |
| @@ -163946,11 +164508,10 @@ | ||
| 163946 | 164508 | if( rc ) return rc; |
| 163947 | 164509 | if( p==0 ) return SQLITE_OK; |
| 163948 | 164510 | if( i==0 ){ |
| 163949 | 164511 | sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell)); |
| 163950 | 164512 | }else{ |
| 163951 | - if( rc ) return rc; | |
| 163952 | 164513 | nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c); |
| 163953 | 164514 | #ifndef SQLITE_RTREE_INT_ONLY |
| 163954 | 164515 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 163955 | 164516 | sqlite3_result_double(ctx, c.f); |
| 163956 | 164517 | }else |
| @@ -164075,11 +164636,11 @@ | ||
| 164075 | 164636 | assert( p!=0 ); /* Always returns pCsr->sPoint */ |
| 164076 | 164637 | pCsr->aNode[0] = pLeaf; |
| 164077 | 164638 | p->id = iNode; |
| 164078 | 164639 | p->eWithin = PARTLY_WITHIN; |
| 164079 | 164640 | rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell); |
| 164080 | - p->iCell = iCell; | |
| 164641 | + p->iCell = (u8)iCell; | |
| 164081 | 164642 | RTREE_QUEUE_TRACE(pCsr, "PUSH-F1:"); |
| 164082 | 164643 | }else{ |
| 164083 | 164644 | pCsr->atEOF = 1; |
| 164084 | 164645 | } |
| 164085 | 164646 | }else{ |
| @@ -164108,11 +164669,11 @@ | ||
| 164108 | 164669 | */ |
| 164109 | 164670 | rc = deserializeGeometry(argv[ii], p); |
| 164110 | 164671 | if( rc!=SQLITE_OK ){ |
| 164111 | 164672 | break; |
| 164112 | 164673 | } |
| 164113 | - p->pInfo->nCoord = pRtree->nDim*2; | |
| 164674 | + p->pInfo->nCoord = pRtree->nDim2; | |
| 164114 | 164675 | p->pInfo->anQueue = pCsr->anQueue; |
| 164115 | 164676 | p->pInfo->mxLevel = pRtree->iDepth + 1; |
| 164116 | 164677 | }else{ |
| 164117 | 164678 | #ifdef SQLITE_RTREE_INT_ONLY |
| 164118 | 164679 | p->u.rValue = sqlite3_value_int64(argv[ii]); |
| @@ -164123,11 +164684,11 @@ | ||
| 164123 | 164684 | } |
| 164124 | 164685 | } |
| 164125 | 164686 | } |
| 164126 | 164687 | if( rc==SQLITE_OK ){ |
| 164127 | 164688 | RtreeSearchPoint *pNew; |
| 164128 | - pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, pRtree->iDepth+1); | |
| 164689 | + pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1)); | |
| 164129 | 164690 | if( pNew==0 ) return SQLITE_NOMEM; |
| 164130 | 164691 | pNew->id = 1; |
| 164131 | 164692 | pNew->iCell = 0; |
| 164132 | 164693 | pNew->eWithin = PARTLY_WITHIN; |
| 164133 | 164694 | assert( pCsr->bPoint==1 ); |
| @@ -164141,23 +164702,10 @@ | ||
| 164141 | 164702 | nodeRelease(pRtree, pRoot); |
| 164142 | 164703 | rtreeRelease(pRtree); |
| 164143 | 164704 | return rc; |
| 164144 | 164705 | } |
| 164145 | 164706 | |
| 164146 | -/* | |
| 164147 | -** Set the pIdxInfo->estimatedRows variable to nRow. Unless this | |
| 164148 | -** extension is currently being used by a version of SQLite too old to | |
| 164149 | -** support estimatedRows. In that case this function is a no-op. | |
| 164150 | -*/ | |
| 164151 | -static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){ | |
| 164152 | -#if SQLITE_VERSION_NUMBER>=3008002 | |
| 164153 | - if( sqlite3_libversion_number()>=3008002 ){ | |
| 164154 | - pIdxInfo->estimatedRows = nRow; | |
| 164155 | - } | |
| 164156 | -#endif | |
| 164157 | -} | |
| 164158 | - | |
| 164159 | 164707 | /* |
| 164160 | 164708 | ** Rtree virtual table module xBestIndex method. There are three |
| 164161 | 164709 | ** table scan strategies to choose from (in order from most to |
| 164162 | 164710 | ** least desirable): |
| 164163 | 164711 | ** |
| @@ -164233,11 +164781,11 @@ | ||
| 164233 | 164781 | ** considered almost as quick as a direct rowid lookup (for which |
| 164234 | 164782 | ** sqlite uses an internal cost of 0.0). It is expected to return |
| 164235 | 164783 | ** a single row. |
| 164236 | 164784 | */ |
| 164237 | 164785 | pIdxInfo->estimatedCost = 30.0; |
| 164238 | - setEstimatedRows(pIdxInfo, 1); | |
| 164786 | + pIdxInfo->estimatedRows = 1; | |
| 164239 | 164787 | return SQLITE_OK; |
| 164240 | 164788 | } |
| 164241 | 164789 | |
| 164242 | 164790 | if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){ |
| 164243 | 164791 | u8 op; |
| @@ -164251,11 +164799,11 @@ | ||
| 164251 | 164799 | assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH ); |
| 164252 | 164800 | op = RTREE_MATCH; |
| 164253 | 164801 | break; |
| 164254 | 164802 | } |
| 164255 | 164803 | zIdxStr[iIdx++] = op; |
| 164256 | - zIdxStr[iIdx++] = p->iColumn - 1 + '0'; | |
| 164804 | + zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0'); | |
| 164257 | 164805 | pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2); |
| 164258 | 164806 | pIdxInfo->aConstraintUsage[ii].omit = 1; |
| 164259 | 164807 | } |
| 164260 | 164808 | } |
| 164261 | 164809 | |
| @@ -164265,55 +164813,75 @@ | ||
| 164265 | 164813 | return SQLITE_NOMEM; |
| 164266 | 164814 | } |
| 164267 | 164815 | |
| 164268 | 164816 | nRow = pRtree->nRowEst >> (iIdx/2); |
| 164269 | 164817 | pIdxInfo->estimatedCost = (double)6.0 * (double)nRow; |
| 164270 | - setEstimatedRows(pIdxInfo, nRow); | |
| 164818 | + pIdxInfo->estimatedRows = nRow; | |
| 164271 | 164819 | |
| 164272 | 164820 | return rc; |
| 164273 | 164821 | } |
| 164274 | 164822 | |
| 164275 | 164823 | /* |
| 164276 | 164824 | ** Return the N-dimensional volumn of the cell stored in *p. |
| 164277 | 164825 | */ |
| 164278 | 164826 | static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){ |
| 164279 | 164827 | RtreeDValue area = (RtreeDValue)1; |
| 164280 | - int ii; | |
| 164281 | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ | |
| 164282 | - area = (area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]))); | |
| 164828 | + assert( pRtree->nDim>=1 && pRtree->nDim<=5 ); | |
| 164829 | +#ifndef SQLITE_RTREE_INT_ONLY | |
| 164830 | + if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ | |
| 164831 | + switch( pRtree->nDim ){ | |
| 164832 | + case 5: area = p->aCoord[9].f - p->aCoord[8].f; | |
| 164833 | + case 4: area *= p->aCoord[7].f - p->aCoord[6].f; | |
| 164834 | + case 3: area *= p->aCoord[5].f - p->aCoord[4].f; | |
| 164835 | + case 2: area *= p->aCoord[3].f - p->aCoord[2].f; | |
| 164836 | + default: area *= p->aCoord[1].f - p->aCoord[0].f; | |
| 164837 | + } | |
| 164838 | + }else | |
| 164839 | +#endif | |
| 164840 | + { | |
| 164841 | + switch( pRtree->nDim ){ | |
| 164842 | + case 5: area = p->aCoord[9].i - p->aCoord[8].i; | |
| 164843 | + case 4: area *= p->aCoord[7].i - p->aCoord[6].i; | |
| 164844 | + case 3: area *= p->aCoord[5].i - p->aCoord[4].i; | |
| 164845 | + case 2: area *= p->aCoord[3].i - p->aCoord[2].i; | |
| 164846 | + default: area *= p->aCoord[1].i - p->aCoord[0].i; | |
| 164847 | + } | |
| 164283 | 164848 | } |
| 164284 | 164849 | return area; |
| 164285 | 164850 | } |
| 164286 | 164851 | |
| 164287 | 164852 | /* |
| 164288 | 164853 | ** Return the margin length of cell p. The margin length is the sum |
| 164289 | 164854 | ** of the objects size in each dimension. |
| 164290 | 164855 | */ |
| 164291 | 164856 | static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){ |
| 164292 | - RtreeDValue margin = (RtreeDValue)0; | |
| 164293 | - int ii; | |
| 164294 | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ | |
| 164857 | + RtreeDValue margin = 0; | |
| 164858 | + int ii = pRtree->nDim2 - 2; | |
| 164859 | + do{ | |
| 164295 | 164860 | margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])); |
| 164296 | - } | |
| 164861 | + ii -= 2; | |
| 164862 | + }while( ii>=0 ); | |
| 164297 | 164863 | return margin; |
| 164298 | 164864 | } |
| 164299 | 164865 | |
| 164300 | 164866 | /* |
| 164301 | 164867 | ** Store the union of cells p1 and p2 in p1. |
| 164302 | 164868 | */ |
| 164303 | 164869 | static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ |
| 164304 | - int ii; | |
| 164870 | + int ii = 0; | |
| 164305 | 164871 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 164306 | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ | |
| 164872 | + do{ | |
| 164307 | 164873 | p1->aCoord[ii].f = MIN(p1->aCoord[ii].f, p2->aCoord[ii].f); |
| 164308 | 164874 | p1->aCoord[ii+1].f = MAX(p1->aCoord[ii+1].f, p2->aCoord[ii+1].f); |
| 164309 | - } | |
| 164875 | + ii += 2; | |
| 164876 | + }while( ii<pRtree->nDim2 ); | |
| 164310 | 164877 | }else{ |
| 164311 | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ | |
| 164878 | + do{ | |
| 164312 | 164879 | p1->aCoord[ii].i = MIN(p1->aCoord[ii].i, p2->aCoord[ii].i); |
| 164313 | 164880 | p1->aCoord[ii+1].i = MAX(p1->aCoord[ii+1].i, p2->aCoord[ii+1].i); |
| 164314 | - } | |
| 164881 | + ii += 2; | |
| 164882 | + }while( ii<pRtree->nDim2 ); | |
| 164315 | 164883 | } |
| 164316 | 164884 | } |
| 164317 | 164885 | |
| 164318 | 164886 | /* |
| 164319 | 164887 | ** Return true if the area covered by p2 is a subset of the area covered |
| @@ -164320,11 +164888,11 @@ | ||
| 164320 | 164888 | ** by p1. False otherwise. |
| 164321 | 164889 | */ |
| 164322 | 164890 | static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ |
| 164323 | 164891 | int ii; |
| 164324 | 164892 | int isInt = (pRtree->eCoordType==RTREE_COORD_INT32); |
| 164325 | - for(ii=0; ii<(pRtree->nDim*2); ii+=2){ | |
| 164893 | + for(ii=0; ii<pRtree->nDim2; ii+=2){ | |
| 164326 | 164894 | RtreeCoord *a1 = &p1->aCoord[ii]; |
| 164327 | 164895 | RtreeCoord *a2 = &p2->aCoord[ii]; |
| 164328 | 164896 | if( (!isInt && (a2[0].f<a1[0].f || a2[1].f>a1[1].f)) |
| 164329 | 164897 | || ( isInt && (a2[0].i<a1[0].i || a2[1].i>a1[1].i)) |
| 164330 | 164898 | ){ |
| @@ -164355,11 +164923,11 @@ | ||
| 164355 | 164923 | int ii; |
| 164356 | 164924 | RtreeDValue overlap = RTREE_ZERO; |
| 164357 | 164925 | for(ii=0; ii<nCell; ii++){ |
| 164358 | 164926 | int jj; |
| 164359 | 164927 | RtreeDValue o = (RtreeDValue)1; |
| 164360 | - for(jj=0; jj<(pRtree->nDim*2); jj+=2){ | |
| 164928 | + for(jj=0; jj<pRtree->nDim2; jj+=2){ | |
| 164361 | 164929 | RtreeDValue x1, x2; |
| 164362 | 164930 | x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj])); |
| 164363 | 164931 | x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1])); |
| 164364 | 164932 | if( x2<x1 ){ |
| 164365 | 164933 | o = (RtreeDValue)0; |
| @@ -165411,11 +165979,11 @@ | ||
| 165411 | 165979 | ** with "column" that are interpreted as table constraints. |
| 165412 | 165980 | ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5)); |
| 165413 | 165981 | ** This problem was discovered after years of use, so we silently ignore |
| 165414 | 165982 | ** these kinds of misdeclared tables to avoid breaking any legacy. |
| 165415 | 165983 | */ |
| 165416 | - assert( nData<=(pRtree->nDim*2 + 3) ); | |
| 165984 | + assert( nData<=(pRtree->nDim2 + 3) ); | |
| 165417 | 165985 | |
| 165418 | 165986 | #ifndef SQLITE_RTREE_INT_ONLY |
| 165419 | 165987 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 165420 | 165988 | for(ii=0; ii<nData-4; ii+=2){ |
| 165421 | 165989 | cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]); |
| @@ -165500,10 +166068,31 @@ | ||
| 165500 | 166068 | |
| 165501 | 166069 | constraint: |
| 165502 | 166070 | rtreeRelease(pRtree); |
| 165503 | 166071 | return rc; |
| 165504 | 166072 | } |
| 166073 | + | |
| 166074 | +/* | |
| 166075 | +** Called when a transaction starts. | |
| 166076 | +*/ | |
| 166077 | +static int rtreeBeginTransaction(sqlite3_vtab *pVtab){ | |
| 166078 | + Rtree *pRtree = (Rtree *)pVtab; | |
| 166079 | + assert( pRtree->inWrTrans==0 ); | |
| 166080 | + pRtree->inWrTrans++; | |
| 166081 | + return SQLITE_OK; | |
| 166082 | +} | |
| 166083 | + | |
| 166084 | +/* | |
| 166085 | +** Called when a transaction completes (either by COMMIT or ROLLBACK). | |
| 166086 | +** The sqlite3_blob object should be released at this point. | |
| 166087 | +*/ | |
| 166088 | +static int rtreeEndTransaction(sqlite3_vtab *pVtab){ | |
| 166089 | + Rtree *pRtree = (Rtree *)pVtab; | |
| 166090 | + pRtree->inWrTrans = 0; | |
| 166091 | + nodeBlobReset(pRtree); | |
| 166092 | + return SQLITE_OK; | |
| 166093 | +} | |
| 165505 | 166094 | |
| 165506 | 166095 | /* |
| 165507 | 166096 | ** The xRename method for rtree module virtual tables. |
| 165508 | 166097 | */ |
| 165509 | 166098 | static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){ |
| @@ -165521,10 +166110,11 @@ | ||
| 165521 | 166110 | rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0); |
| 165522 | 166111 | sqlite3_free(zSql); |
| 165523 | 166112 | } |
| 165524 | 166113 | return rc; |
| 165525 | 166114 | } |
| 166115 | + | |
| 165526 | 166116 | |
| 165527 | 166117 | /* |
| 165528 | 166118 | ** This function populates the pRtree->nRowEst variable with an estimate |
| 165529 | 166119 | ** of the number of rows in the virtual table. If possible, this is based |
| 165530 | 166120 | ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST. |
| @@ -165581,19 +166171,19 @@ | ||
| 165581 | 166171 | rtreeNext, /* xNext - advance a cursor */ |
| 165582 | 166172 | rtreeEof, /* xEof */ |
| 165583 | 166173 | rtreeColumn, /* xColumn - read data */ |
| 165584 | 166174 | rtreeRowid, /* xRowid - read data */ |
| 165585 | 166175 | rtreeUpdate, /* xUpdate - write data */ |
| 165586 | - 0, /* xBegin - begin transaction */ | |
| 165587 | - 0, /* xSync - sync transaction */ | |
| 165588 | - 0, /* xCommit - commit transaction */ | |
| 165589 | - 0, /* xRollback - rollback transaction */ | |
| 166176 | + rtreeBeginTransaction, /* xBegin - begin transaction */ | |
| 166177 | + rtreeEndTransaction, /* xSync - sync transaction */ | |
| 166178 | + rtreeEndTransaction, /* xCommit - commit transaction */ | |
| 166179 | + rtreeEndTransaction, /* xRollback - rollback transaction */ | |
| 165590 | 166180 | 0, /* xFindFunction - function overloading */ |
| 165591 | 166181 | rtreeRename, /* xRename - rename the table */ |
| 165592 | 166182 | 0, /* xSavepoint */ |
| 165593 | 166183 | 0, /* xRelease */ |
| 165594 | - 0 /* xRollbackTo */ | |
| 166184 | + 0, /* xRollbackTo */ | |
| 165595 | 166185 | }; |
| 165596 | 166186 | |
| 165597 | 166187 | static int rtreeSqlInit( |
| 165598 | 166188 | Rtree *pRtree, |
| 165599 | 166189 | sqlite3 *db, |
| @@ -165601,14 +166191,13 @@ | ||
| 165601 | 166191 | const char *zPrefix, |
| 165602 | 166192 | int isCreate |
| 165603 | 166193 | ){ |
| 165604 | 166194 | int rc = SQLITE_OK; |
| 165605 | 166195 | |
| 165606 | - #define N_STATEMENT 9 | |
| 166196 | + #define N_STATEMENT 8 | |
| 165607 | 166197 | static const char *azSql[N_STATEMENT] = { |
| 165608 | - /* Read and write the xxx_node table */ | |
| 165609 | - "SELECT data FROM '%q'.'%q_node' WHERE nodeno = :1", | |
| 166198 | + /* Write the xxx_node table */ | |
| 165610 | 166199 | "INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(:1, :2)", |
| 165611 | 166200 | "DELETE FROM '%q'.'%q_node' WHERE nodeno = :1", |
| 165612 | 166201 | |
| 165613 | 166202 | /* Read and write the xxx_rowid table */ |
| 165614 | 166203 | "SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = :1", |
| @@ -165642,19 +166231,18 @@ | ||
| 165642 | 166231 | if( rc!=SQLITE_OK ){ |
| 165643 | 166232 | return rc; |
| 165644 | 166233 | } |
| 165645 | 166234 | } |
| 165646 | 166235 | |
| 165647 | - appStmt[0] = &pRtree->pReadNode; | |
| 165648 | - appStmt[1] = &pRtree->pWriteNode; | |
| 165649 | - appStmt[2] = &pRtree->pDeleteNode; | |
| 165650 | - appStmt[3] = &pRtree->pReadRowid; | |
| 165651 | - appStmt[4] = &pRtree->pWriteRowid; | |
| 165652 | - appStmt[5] = &pRtree->pDeleteRowid; | |
| 165653 | - appStmt[6] = &pRtree->pReadParent; | |
| 165654 | - appStmt[7] = &pRtree->pWriteParent; | |
| 165655 | - appStmt[8] = &pRtree->pDeleteParent; | |
| 166236 | + appStmt[0] = &pRtree->pWriteNode; | |
| 166237 | + appStmt[1] = &pRtree->pDeleteNode; | |
| 166238 | + appStmt[2] = &pRtree->pReadRowid; | |
| 166239 | + appStmt[3] = &pRtree->pWriteRowid; | |
| 166240 | + appStmt[4] = &pRtree->pDeleteRowid; | |
| 166241 | + appStmt[5] = &pRtree->pReadParent; | |
| 166242 | + appStmt[6] = &pRtree->pWriteParent; | |
| 166243 | + appStmt[7] = &pRtree->pDeleteParent; | |
| 165656 | 166244 | |
| 165657 | 166245 | rc = rtreeQueryStat1(db, pRtree); |
| 165658 | 166246 | for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){ |
| 165659 | 166247 | char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix); |
| 165660 | 166248 | if( zSql ){ |
| @@ -165788,13 +166376,14 @@ | ||
| 165788 | 166376 | memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2); |
| 165789 | 166377 | pRtree->nBusy = 1; |
| 165790 | 166378 | pRtree->base.pModule = &rtreeModule; |
| 165791 | 166379 | pRtree->zDb = (char *)&pRtree[1]; |
| 165792 | 166380 | pRtree->zName = &pRtree->zDb[nDb+1]; |
| 165793 | - pRtree->nDim = (argc-4)/2; | |
| 165794 | - pRtree->nBytesPerCell = 8 + pRtree->nDim*4*2; | |
| 165795 | - pRtree->eCoordType = eCoordType; | |
| 166381 | + pRtree->nDim = (u8)((argc-4)/2); | |
| 166382 | + pRtree->nDim2 = pRtree->nDim*2; | |
| 166383 | + pRtree->nBytesPerCell = 8 + pRtree->nDim2*4; | |
| 166384 | + pRtree->eCoordType = (u8)eCoordType; | |
| 165796 | 166385 | memcpy(pRtree->zDb, argv[1], nDb); |
| 165797 | 166386 | memcpy(pRtree->zName, argv[2], nName); |
| 165798 | 166387 | |
| 165799 | 166388 | /* Figure out the node size to use. */ |
| 165800 | 166389 | rc = getNodeSize(db, pRtree, isCreate, pzErr); |
| @@ -165863,11 +166452,12 @@ | ||
| 165863 | 166452 | int ii; |
| 165864 | 166453 | |
| 165865 | 166454 | UNUSED_PARAMETER(nArg); |
| 165866 | 166455 | memset(&node, 0, sizeof(RtreeNode)); |
| 165867 | 166456 | memset(&tree, 0, sizeof(Rtree)); |
| 165868 | - tree.nDim = sqlite3_value_int(apArg[0]); | |
| 166457 | + tree.nDim = (u8)sqlite3_value_int(apArg[0]); | |
| 166458 | + tree.nDim2 = tree.nDim*2; | |
| 165869 | 166459 | tree.nBytesPerCell = 8 + 8 * tree.nDim; |
| 165870 | 166460 | node.zData = (u8 *)sqlite3_value_blob(apArg[1]); |
| 165871 | 166461 | |
| 165872 | 166462 | for(ii=0; ii<NCELL(&node); ii++){ |
| 165873 | 166463 | char zCell[512]; |
| @@ -165876,11 +166466,11 @@ | ||
| 165876 | 166466 | int jj; |
| 165877 | 166467 | |
| 165878 | 166468 | nodeGetCell(&tree, &node, ii, &cell); |
| 165879 | 166469 | sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid); |
| 165880 | 166470 | nCell = (int)strlen(zCell); |
| 165881 | - for(jj=0; jj<tree.nDim*2; jj++){ | |
| 166471 | + for(jj=0; jj<tree.nDim2; jj++){ | |
| 165882 | 166472 | #ifndef SQLITE_RTREE_INT_ONLY |
| 165883 | 166473 | sqlite3_snprintf(512-nCell,&zCell[nCell], " %g", |
| 165884 | 166474 | (double)cell.aCoord[jj].f); |
| 165885 | 166475 | #else |
| 165886 | 166476 | sqlite3_snprintf(512-nCell,&zCell[nCell], " %d", |
| @@ -166584,42 +167174,40 @@ | ||
| 166584 | 167174 | |
| 166585 | 167175 | /* |
| 166586 | 167176 | ** Register the ICU extension functions with database db. |
| 166587 | 167177 | */ |
| 166588 | 167178 | SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){ |
| 166589 | - struct IcuScalar { | |
| 167179 | + static const struct IcuScalar { | |
| 166590 | 167180 | const char *zName; /* Function name */ |
| 166591 | - int nArg; /* Number of arguments */ | |
| 166592 | - int enc; /* Optimal text encoding */ | |
| 166593 | - void *pContext; /* sqlite3_user_data() context */ | |
| 167181 | + unsigned char nArg; /* Number of arguments */ | |
| 167182 | + unsigned short enc; /* Optimal text encoding */ | |
| 167183 | + unsigned char iContext; /* sqlite3_user_data() context */ | |
| 166594 | 167184 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**); |
| 166595 | 167185 | } scalars[] = { |
| 166596 | - {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc}, | |
| 166597 | - | |
| 166598 | - {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, | |
| 166599 | - {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, | |
| 166600 | - {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16}, | |
| 166601 | - {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16}, | |
| 166602 | - | |
| 166603 | - {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, | |
| 166604 | - {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, | |
| 166605 | - {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16}, | |
| 166606 | - {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16}, | |
| 166607 | - | |
| 166608 | - {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, | |
| 166609 | - {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, | |
| 166610 | - | |
| 166611 | - {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation}, | |
| 167186 | + {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation}, | |
| 167187 | + {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc}, | |
| 167188 | + {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, | |
| 167189 | + {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, | |
| 167190 | + {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, | |
| 167191 | + {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, | |
| 167192 | + {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, | |
| 167193 | + {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, | |
| 167194 | + {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, | |
| 167195 | + {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, | |
| 167196 | + {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, | |
| 167197 | + {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, | |
| 166612 | 167198 | }; |
| 166613 | - | |
| 166614 | 167199 | int rc = SQLITE_OK; |
| 166615 | 167200 | int i; |
| 166616 | 167201 | |
| 167202 | + | |
| 166617 | 167203 | for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){ |
| 166618 | - struct IcuScalar *p = &scalars[i]; | |
| 167204 | + const struct IcuScalar *p = &scalars[i]; | |
| 166619 | 167205 | rc = sqlite3_create_function( |
| 166620 | - db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0 | |
| 167206 | + db, p->zName, p->nArg, p->enc, | |
| 167207 | + p->iContext ? (void*)db : (void*)0, | |
| 167208 | + p->xFunc, 0, 0 | |
| 166621 | 167209 | ); |
| 166622 | 167210 | } |
| 166623 | 167211 | |
| 166624 | 167212 | return rc; |
| 166625 | 167213 | } |
| @@ -169823,11 +170411,11 @@ | ||
| 169823 | 170411 | |
| 169824 | 170412 | /* |
| 169825 | 170413 | ** Open the database handle and attach the RBU database as "rbu". If an |
| 169826 | 170414 | ** error occurs, leave an error code and message in the RBU handle. |
| 169827 | 170415 | */ |
| 169828 | -static void rbuOpenDatabase(sqlite3rbu *p){ | |
| 170416 | +static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){ | |
| 169829 | 170417 | assert( p->rc || (p->dbMain==0 && p->dbRbu==0) ); |
| 169830 | 170418 | assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 ); |
| 169831 | 170419 | |
| 169832 | 170420 | /* Open the RBU database */ |
| 169833 | 170421 | p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1); |
| @@ -169898,11 +170486,11 @@ | ||
| 169898 | 170486 | if( p->eStage>=RBU_STAGE_MOVE ){ |
| 169899 | 170487 | bOpen = 1; |
| 169900 | 170488 | }else{ |
| 169901 | 170489 | RbuState *pState = rbuLoadState(p); |
| 169902 | 170490 | if( pState ){ |
| 169903 | - bOpen = (pState->eStage>RBU_STAGE_MOVE); | |
| 170491 | + bOpen = (pState->eStage>=RBU_STAGE_MOVE); | |
| 169904 | 170492 | rbuFreeState(pState); |
| 169905 | 170493 | } |
| 169906 | 170494 | } |
| 169907 | 170495 | if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1); |
| 169908 | 170496 | } |
| @@ -169910,10 +170498,19 @@ | ||
| 169910 | 170498 | p->eStage = 0; |
| 169911 | 170499 | if( p->rc==SQLITE_OK && p->dbMain==0 ){ |
| 169912 | 170500 | if( !rbuIsVacuum(p) ){ |
| 169913 | 170501 | p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1); |
| 169914 | 170502 | }else if( p->pRbuFd->pWalFd ){ |
| 170503 | + if( pbRetry ){ | |
| 170504 | + p->pRbuFd->bNolock = 0; | |
| 170505 | + sqlite3_close(p->dbRbu); | |
| 170506 | + sqlite3_close(p->dbMain); | |
| 170507 | + p->dbMain = 0; | |
| 170508 | + p->dbRbu = 0; | |
| 170509 | + *pbRetry = 1; | |
| 170510 | + return; | |
| 170511 | + } | |
| 169915 | 170512 | p->rc = SQLITE_ERROR; |
| 169916 | 170513 | p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database"); |
| 169917 | 170514 | }else{ |
| 169918 | 170515 | char *zTarget; |
| 169919 | 170516 | char *zExtra = 0; |
| @@ -170090,20 +170687,22 @@ | ||
| 170090 | 170687 | p->eStage = RBU_STAGE_CAPTURE; |
| 170091 | 170688 | rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0); |
| 170092 | 170689 | if( rc2!=SQLITE_INTERNAL ) p->rc = rc2; |
| 170093 | 170690 | } |
| 170094 | 170691 | |
| 170095 | - if( p->rc==SQLITE_OK ){ | |
| 170692 | + if( p->rc==SQLITE_OK && p->nFrame>0 ){ | |
| 170096 | 170693 | p->eStage = RBU_STAGE_CKPT; |
| 170097 | 170694 | p->nStep = (pState ? pState->nRow : 0); |
| 170098 | 170695 | p->aBuf = rbuMalloc(p, p->pgsz); |
| 170099 | 170696 | p->iWalCksum = rbuShmChecksum(p); |
| 170100 | 170697 | } |
| 170101 | 170698 | |
| 170102 | - if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){ | |
| 170103 | - p->rc = SQLITE_DONE; | |
| 170104 | - p->eStage = RBU_STAGE_DONE; | |
| 170699 | + if( p->rc==SQLITE_OK ){ | |
| 170700 | + if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){ | |
| 170701 | + p->rc = SQLITE_DONE; | |
| 170702 | + p->eStage = RBU_STAGE_DONE; | |
| 170703 | + } | |
| 170105 | 170704 | } |
| 170106 | 170705 | } |
| 170107 | 170706 | |
| 170108 | 170707 | /* |
| 170109 | 170708 | ** Called when iAmt bytes are read from offset iOff of the wal file while |
| @@ -170272,11 +170871,11 @@ | ||
| 170272 | 170871 | #else |
| 170273 | 170872 | p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; |
| 170274 | 170873 | #endif |
| 170275 | 170874 | |
| 170276 | 170875 | if( p->rc==SQLITE_OK ){ |
| 170277 | - rbuOpenDatabase(p); | |
| 170876 | + rbuOpenDatabase(p, 0); | |
| 170278 | 170877 | rbuSetupCheckpoint(p, 0); |
| 170279 | 170878 | } |
| 170280 | 170879 | } |
| 170281 | 170880 | } |
| 170282 | 170881 | |
| @@ -170983,10 +171582,11 @@ | ||
| 170983 | 171582 | rbuCreateVfs(p); |
| 170984 | 171583 | |
| 170985 | 171584 | /* Open the target, RBU and state databases */ |
| 170986 | 171585 | if( p->rc==SQLITE_OK ){ |
| 170987 | 171586 | char *pCsr = (char*)&p[1]; |
| 171587 | + int bRetry = 0; | |
| 170988 | 171588 | if( zTarget ){ |
| 170989 | 171589 | p->zTarget = pCsr; |
| 170990 | 171590 | memcpy(p->zTarget, zTarget, nTarget+1); |
| 170991 | 171591 | pCsr += nTarget+1; |
| 170992 | 171592 | } |
| @@ -170994,11 +171594,22 @@ | ||
| 170994 | 171594 | memcpy(p->zRbu, zRbu, nRbu+1); |
| 170995 | 171595 | pCsr += nRbu+1; |
| 170996 | 171596 | if( zState ){ |
| 170997 | 171597 | p->zState = rbuMPrintf(p, "%s", zState); |
| 170998 | 171598 | } |
| 170999 | - rbuOpenDatabase(p); | |
| 171599 | + | |
| 171600 | + /* If the first attempt to open the database file fails and the bRetry | |
| 171601 | + ** flag it set, this means that the db was not opened because it seemed | |
| 171602 | + ** to be a wal-mode db. But, this may have happened due to an earlier | |
| 171603 | + ** RBU vacuum operation leaving an old wal file in the directory. | |
| 171604 | + ** If this is the case, it will have been checkpointed and deleted | |
| 171605 | + ** when the handle was closed and a second attempt to open the | |
| 171606 | + ** database may succeed. */ | |
| 171607 | + rbuOpenDatabase(p, &bRetry); | |
| 171608 | + if( bRetry ){ | |
| 171609 | + rbuOpenDatabase(p, 0); | |
| 171610 | + } | |
| 171000 | 171611 | } |
| 171001 | 171612 | |
| 171002 | 171613 | if( p->rc==SQLITE_OK ){ |
| 171003 | 171614 | pState = rbuLoadState(p); |
| 171004 | 171615 | assert( pState || p->rc!=SQLITE_OK ); |
| @@ -175957,11 +176568,11 @@ | ||
| 175957 | 176568 | sqlite3_value **ppValue /* OUT: Value from conflicting row */ |
| 175958 | 176569 | ){ |
| 175959 | 176570 | if( !pIter->pConflict ){ |
| 175960 | 176571 | return SQLITE_MISUSE; |
| 175961 | 176572 | } |
| 175962 | - if( iVal<0 || iVal>=sqlite3_column_count(pIter->pConflict) ){ | |
| 176573 | + if( iVal<0 || iVal>=pIter->nCol ){ | |
| 175963 | 176574 | return SQLITE_RANGE; |
| 175964 | 176575 | } |
| 175965 | 176576 | *ppValue = sqlite3_column_value(pIter->pConflict, iVal); |
| 175966 | 176577 | return SQLITE_OK; |
| 175967 | 176578 | } |
| @@ -176424,11 +177035,17 @@ | ||
| 176424 | 177035 | int i; |
| 176425 | 177036 | SessionBuffer buf = {0, 0, 0}; |
| 176426 | 177037 | |
| 176427 | 177038 | sessionAppendStr(&buf, "INSERT INTO main.", &rc); |
| 176428 | 177039 | sessionAppendIdent(&buf, zTab, &rc); |
| 176429 | - sessionAppendStr(&buf, " VALUES(?", &rc); | |
| 177040 | + sessionAppendStr(&buf, "(", &rc); | |
| 177041 | + for(i=0; i<p->nCol; i++){ | |
| 177042 | + if( i!=0 ) sessionAppendStr(&buf, ", ", &rc); | |
| 177043 | + sessionAppendIdent(&buf, p->azCol[i], &rc); | |
| 177044 | + } | |
| 177045 | + | |
| 177046 | + sessionAppendStr(&buf, ") VALUES(?", &rc); | |
| 176430 | 177047 | for(i=1; i<p->nCol; i++){ |
| 176431 | 177048 | sessionAppendStr(&buf, ", ?", &rc); |
| 176432 | 177049 | } |
| 176433 | 177050 | sessionAppendStr(&buf, ")", &rc); |
| 176434 | 177051 | |
| @@ -176970,42 +177587,51 @@ | ||
| 176970 | 177587 | break; |
| 176971 | 177588 | } |
| 176972 | 177589 | nTab = (int)strlen(zTab); |
| 176973 | 177590 | sApply.azCol = (const char **)zTab; |
| 176974 | 177591 | }else{ |
| 177592 | + int nMinCol = 0; | |
| 177593 | + int i; | |
| 177594 | + | |
| 176975 | 177595 | sqlite3changeset_pk(pIter, &abPK, 0); |
| 176976 | 177596 | rc = sessionTableInfo( |
| 176977 | 177597 | db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK |
| 176978 | 177598 | ); |
| 176979 | 177599 | if( rc!=SQLITE_OK ) break; |
| 177600 | + for(i=0; i<sApply.nCol; i++){ | |
| 177601 | + if( sApply.abPK[i] ) nMinCol = i+1; | |
| 177602 | + } | |
| 176980 | 177603 | |
| 176981 | 177604 | if( sApply.nCol==0 ){ |
| 176982 | 177605 | schemaMismatch = 1; |
| 176983 | 177606 | sqlite3_log(SQLITE_SCHEMA, |
| 176984 | 177607 | "sqlite3changeset_apply(): no such table: %s", zTab |
| 176985 | 177608 | ); |
| 176986 | 177609 | } |
| 176987 | - else if( sApply.nCol!=nCol ){ | |
| 177610 | + else if( sApply.nCol<nCol ){ | |
| 176988 | 177611 | schemaMismatch = 1; |
| 176989 | 177612 | sqlite3_log(SQLITE_SCHEMA, |
| 176990 | - "sqlite3changeset_apply(): table %s has %d columns, expected %d", | |
| 177613 | + "sqlite3changeset_apply(): table %s has %d columns, " | |
| 177614 | + "expected %d or more", | |
| 176991 | 177615 | zTab, sApply.nCol, nCol |
| 176992 | 177616 | ); |
| 176993 | 177617 | } |
| 176994 | - else if( memcmp(sApply.abPK, abPK, nCol)!=0 ){ | |
| 177618 | + else if( nCol<nMinCol || memcmp(sApply.abPK, abPK, nCol)!=0 ){ | |
| 176995 | 177619 | schemaMismatch = 1; |
| 176996 | 177620 | sqlite3_log(SQLITE_SCHEMA, "sqlite3changeset_apply(): " |
| 176997 | 177621 | "primary key mismatch for table %s", zTab |
| 176998 | 177622 | ); |
| 176999 | 177623 | } |
| 177000 | - else if( | |
| 177001 | - (rc = sessionSelectRow(db, zTab, &sApply)) | |
| 177002 | - || (rc = sessionUpdateRow(db, zTab, &sApply)) | |
| 177003 | - || (rc = sessionDeleteRow(db, zTab, &sApply)) | |
| 177004 | - || (rc = sessionInsertRow(db, zTab, &sApply)) | |
| 177005 | - ){ | |
| 177006 | - break; | |
| 177624 | + else{ | |
| 177625 | + sApply.nCol = nCol; | |
| 177626 | + if((rc = sessionSelectRow(db, zTab, &sApply)) | |
| 177627 | + || (rc = sessionUpdateRow(db, zTab, &sApply)) | |
| 177628 | + || (rc = sessionDeleteRow(db, zTab, &sApply)) | |
| 177629 | + || (rc = sessionInsertRow(db, zTab, &sApply)) | |
| 177630 | + ){ | |
| 177631 | + break; | |
| 177632 | + } | |
| 177007 | 177633 | } |
| 177008 | 177634 | nTab = sqlite3Strlen30(zTab); |
| 177009 | 177635 | } |
| 177010 | 177636 | } |
| 177011 | 177637 | |
| @@ -177593,11 +178219,11 @@ | ||
| 177593 | 178219 | ** a BLOB, but there is no support for JSONB in the current implementation. |
| 177594 | 178220 | ** This implementation parses JSON text at 250 MB/s, so it is hard to see |
| 177595 | 178221 | ** how JSONB might improve on that.) |
| 177596 | 178222 | */ |
| 177597 | 178223 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1) |
| 177598 | -#if !defined(_SQLITEINT_H_) | |
| 178224 | +#if !defined(SQLITEINT_H) | |
| 177599 | 178225 | /* #include "sqlite3ext.h" */ |
| 177600 | 178226 | #endif |
| 177601 | 178227 | SQLITE_EXTENSION_INIT1 |
| 177602 | 178228 | /* #include <assert.h> */ |
| 177603 | 178229 | /* #include <string.h> */ |
| @@ -181644,10 +182270,35 @@ | ||
| 181644 | 182270 | */ |
| 181645 | 182271 | #ifndef fts5YYMALLOCARGTYPE |
| 181646 | 182272 | # define fts5YYMALLOCARGTYPE size_t |
| 181647 | 182273 | #endif |
| 181648 | 182274 | |
| 182275 | +/* Initialize a new parser that has already been allocated. | |
| 182276 | +*/ | |
| 182277 | +static void sqlite3Fts5ParserInit(void *fts5yypParser){ | |
| 182278 | + fts5yyParser *pParser = (fts5yyParser*)fts5yypParser; | |
| 182279 | +#ifdef fts5YYTRACKMAXSTACKDEPTH | |
| 182280 | + pParser->fts5yyhwm = 0; | |
| 182281 | +#endif | |
| 182282 | +#if fts5YYSTACKDEPTH<=0 | |
| 182283 | + pParser->fts5yytos = NULL; | |
| 182284 | + pParser->fts5yystack = NULL; | |
| 182285 | + pParser->fts5yystksz = 0; | |
| 182286 | + if( fts5yyGrowStack(pParser) ){ | |
| 182287 | + pParser->fts5yystack = &pParser->fts5yystk0; | |
| 182288 | + pParser->fts5yystksz = 1; | |
| 182289 | + } | |
| 182290 | +#endif | |
| 182291 | +#ifndef fts5YYNOERRORRECOVERY | |
| 182292 | + pParser->fts5yyerrcnt = -1; | |
| 182293 | +#endif | |
| 182294 | + pParser->fts5yytos = pParser->fts5yystack; | |
| 182295 | + pParser->fts5yystack[0].stateno = 0; | |
| 182296 | + pParser->fts5yystack[0].major = 0; | |
| 182297 | +} | |
| 182298 | + | |
| 182299 | +#ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK | |
| 181649 | 182300 | /* |
| 181650 | 182301 | ** This function allocates a new parser. |
| 181651 | 182302 | ** The only argument is a pointer to a function which works like |
| 181652 | 182303 | ** malloc. |
| 181653 | 182304 | ** |
| @@ -181659,32 +182310,15 @@ | ||
| 181659 | 182310 | ** to sqlite3Fts5Parser and sqlite3Fts5ParserFree. |
| 181660 | 182311 | */ |
| 181661 | 182312 | static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(fts5YYMALLOCARGTYPE)){ |
| 181662 | 182313 | fts5yyParser *pParser; |
| 181663 | 182314 | pParser = (fts5yyParser*)(*mallocProc)( (fts5YYMALLOCARGTYPE)sizeof(fts5yyParser) ); |
| 181664 | - if( pParser ){ | |
| 181665 | -#ifdef fts5YYTRACKMAXSTACKDEPTH | |
| 181666 | - pParser->fts5yyhwm = 0; | |
| 181667 | -#endif | |
| 181668 | -#if fts5YYSTACKDEPTH<=0 | |
| 181669 | - pParser->fts5yytos = NULL; | |
| 181670 | - pParser->fts5yystack = NULL; | |
| 181671 | - pParser->fts5yystksz = 0; | |
| 181672 | - if( fts5yyGrowStack(pParser) ){ | |
| 181673 | - pParser->fts5yystack = &pParser->fts5yystk0; | |
| 181674 | - pParser->fts5yystksz = 1; | |
| 181675 | - } | |
| 181676 | -#endif | |
| 181677 | -#ifndef fts5YYNOERRORRECOVERY | |
| 181678 | - pParser->fts5yyerrcnt = -1; | |
| 181679 | -#endif | |
| 181680 | - pParser->fts5yytos = pParser->fts5yystack; | |
| 181681 | - pParser->fts5yystack[0].stateno = 0; | |
| 181682 | - pParser->fts5yystack[0].major = 0; | |
| 181683 | - } | |
| 182315 | + if( pParser ) sqlite3Fts5ParserInit(pParser); | |
| 181684 | 182316 | return pParser; |
| 181685 | 182317 | } |
| 182318 | +#endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */ | |
| 182319 | + | |
| 181686 | 182320 | |
| 181687 | 182321 | /* The following function deletes the "minor type" or semantic value |
| 181688 | 182322 | ** associated with a symbol. The symbol can be either a terminal |
| 181689 | 182323 | ** or nonterminal. "fts5yymajor" is the symbol code, and "fts5yypminor" is |
| 181690 | 182324 | ** a pointer to the value to be deleted. The code used to do the |
| @@ -181762,10 +182396,22 @@ | ||
| 181762 | 182396 | } |
| 181763 | 182397 | #endif |
| 181764 | 182398 | fts5yy_destructor(pParser, fts5yytos->major, &fts5yytos->minor); |
| 181765 | 182399 | } |
| 181766 | 182400 | |
| 182401 | +/* | |
| 182402 | +** Clear all secondary memory allocations from the parser | |
| 182403 | +*/ | |
| 182404 | +static void sqlite3Fts5ParserFinalize(void *p){ | |
| 182405 | + fts5yyParser *pParser = (fts5yyParser*)p; | |
| 182406 | + while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser); | |
| 182407 | +#if fts5YYSTACKDEPTH<=0 | |
| 182408 | + if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack); | |
| 182409 | +#endif | |
| 182410 | +} | |
| 182411 | + | |
| 182412 | +#ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK | |
| 181767 | 182413 | /* |
| 181768 | 182414 | ** Deallocate and destroy a parser. Destructors are called for |
| 181769 | 182415 | ** all stack elements before shutting the parser down. |
| 181770 | 182416 | ** |
| 181771 | 182417 | ** If the fts5YYPARSEFREENEVERNULL macro exists (for example because it |
| @@ -181774,20 +182420,17 @@ | ||
| 181774 | 182420 | */ |
| 181775 | 182421 | static void sqlite3Fts5ParserFree( |
| 181776 | 182422 | void *p, /* The parser to be deleted */ |
| 181777 | 182423 | void (*freeProc)(void*) /* Function used to reclaim memory */ |
| 181778 | 182424 | ){ |
| 181779 | - fts5yyParser *pParser = (fts5yyParser*)p; | |
| 181780 | 182425 | #ifndef fts5YYPARSEFREENEVERNULL |
| 181781 | - if( pParser==0 ) return; | |
| 181782 | -#endif | |
| 181783 | - while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser); | |
| 181784 | -#if fts5YYSTACKDEPTH<=0 | |
| 181785 | - if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack); | |
| 181786 | -#endif | |
| 181787 | - (*freeProc)((void*)pParser); | |
| 181788 | -} | |
| 182426 | + if( p==0 ) return; | |
| 182427 | +#endif | |
| 182428 | + sqlite3Fts5ParserFinalize(p); | |
| 182429 | + (*freeProc)(p); | |
| 182430 | +} | |
| 182431 | +#endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */ | |
| 181789 | 182432 | |
| 181790 | 182433 | /* |
| 181791 | 182434 | ** Return the peak depth of the stack for a parser. |
| 181792 | 182435 | */ |
| 181793 | 182436 | #ifdef fts5YYTRACKMAXSTACKDEPTH |
| @@ -186122,11 +186765,11 @@ | ||
| 186122 | 186765 | memset(&sCtx, 0, sizeof(TokenCtx)); |
| 186123 | 186766 | sCtx.pPhrase = pAppend; |
| 186124 | 186767 | |
| 186125 | 186768 | rc = fts5ParseStringFromToken(pToken, &z); |
| 186126 | 186769 | if( rc==SQLITE_OK ){ |
| 186127 | - int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_QUERY : 0); | |
| 186770 | + int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_PREFIX : 0); | |
| 186128 | 186771 | int n; |
| 186129 | 186772 | sqlite3Fts5Dequote(z); |
| 186130 | 186773 | n = (int)strlen(z); |
| 186131 | 186774 | rc = sqlite3Fts5Tokenize(pConfig, flags, z, n, &sCtx, fts5ParseTokenize); |
| 186132 | 186775 | } |
| @@ -196863,11 +197506,11 @@ | ||
| 196863 | 197506 | int nArg, /* Number of args */ |
| 196864 | 197507 | sqlite3_value **apUnused /* Function arguments */ |
| 196865 | 197508 | ){ |
| 196866 | 197509 | assert( nArg==0 ); |
| 196867 | 197510 | UNUSED_PARAM2(nArg, apUnused); |
| 196868 | - sqlite3_result_text(pCtx, "fts5: 2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209", -1, SQLITE_TRANSIENT); | |
| 197511 | + sqlite3_result_text(pCtx, "fts5: 2017-02-07 12:58:38 07fe6228208684d579c4f6c334c90eb6262a9233", -1, SQLITE_TRANSIENT); | |
| 196869 | 197512 | } |
| 196870 | 197513 | |
| 196871 | 197514 | static int fts5Init(sqlite3 *db){ |
| 196872 | 197515 | static const sqlite3_module fts5Mod = { |
| 196873 | 197516 | /* iVersion */ 2, |
| 196874 | 197517 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.16.2. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -208,10 +208,18 @@ | |
| 208 | #ifdef __GNUC__ |
| 209 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 210 | #else |
| 211 | # define GCC_VERSION 0 |
| 212 | #endif |
| 213 | |
| 214 | /* Needed for various definitions... */ |
| 215 | #if defined(__GNUC__) && !defined(_GNU_SOURCE) |
| 216 | # define _GNU_SOURCE |
| 217 | #endif |
| @@ -379,13 +387,13 @@ | |
| 379 | ** |
| 380 | ** See also: [sqlite3_libversion()], |
| 381 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 382 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 383 | */ |
| 384 | #define SQLITE_VERSION "3.16.2" |
| 385 | #define SQLITE_VERSION_NUMBER 3016002 |
| 386 | #define SQLITE_SOURCE_ID "2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209" |
| 387 | |
| 388 | /* |
| 389 | ** CAPI3REF: Run-Time Library Version Numbers |
| 390 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 391 | ** |
| @@ -517,11 +525,15 @@ | |
| 517 | ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
| 518 | ** between 0 and +18446744073709551615 inclusive. |
| 519 | */ |
| 520 | #ifdef SQLITE_INT64_TYPE |
| 521 | typedef SQLITE_INT64_TYPE sqlite_int64; |
| 522 | typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; |
| 523 | #elif defined(_MSC_VER) || defined(__BORLANDC__) |
| 524 | typedef __int64 sqlite_int64; |
| 525 | typedef unsigned __int64 sqlite_uint64; |
| 526 | #else |
| 527 | typedef long long int sqlite_int64; |
| @@ -830,11 +842,11 @@ | |
| 830 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 831 | ** after reboot following a crash or power loss, the only bytes in a |
| 832 | ** file that were written at the application level might have changed |
| 833 | ** and that adjacent bytes, even bytes within the same sector are |
| 834 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 835 | ** flag indicate that a file cannot be deleted when open. The |
| 836 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
| 837 | ** read-only media and cannot be changed even by processes with |
| 838 | ** elevated privileges. |
| 839 | */ |
| 840 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| @@ -980,10 +992,13 @@ | |
| 980 | ** <li> [SQLITE_IOCAP_ATOMIC16K] |
| 981 | ** <li> [SQLITE_IOCAP_ATOMIC32K] |
| 982 | ** <li> [SQLITE_IOCAP_ATOMIC64K] |
| 983 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
| 984 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
| 985 | ** </ul> |
| 986 | ** |
| 987 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 988 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 989 | ** mean that writes of blocks that are nnn bytes in size and |
| @@ -5668,11 +5683,11 @@ | |
| 5668 | ** ^(The update hook is not invoked when internal system tables are |
| 5669 | ** modified (i.e. sqlite_master and sqlite_sequence).)^ |
| 5670 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
| 5671 | ** |
| 5672 | ** ^In the current implementation, the update hook |
| 5673 | ** is not invoked when duplication rows are deleted because of an |
| 5674 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
| 5675 | ** invoked when rows are deleted using the [truncate optimization]. |
| 5676 | ** The exceptions defined in this paragraph might change in a future |
| 5677 | ** release of SQLite. |
| 5678 | ** |
| @@ -6450,10 +6465,16 @@ | |
| 6450 | ** |
| 6451 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 6452 | ** [database connection] error code and message accessible via |
| 6453 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 6454 | ** |
| 6455 | ** |
| 6456 | ** ^(If the row that a BLOB handle points to is modified by an |
| 6457 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 6458 | ** then the BLOB handle is marked as "expired". |
| 6459 | ** This is true if any column of the row is changed, even a column |
| @@ -6473,10 +6494,14 @@ | |
| 6473 | ** and the built-in [zeroblob] SQL function may be used to create a |
| 6474 | ** zero-filled blob to read or write using the incremental-blob interface. |
| 6475 | ** |
| 6476 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 6477 | ** be released by a call to [sqlite3_blob_close()]. |
| 6478 | */ |
| 6479 | SQLITE_API int sqlite3_blob_open( |
| 6480 | sqlite3*, |
| 6481 | const char *zDb, |
| 6482 | const char *zTable, |
| @@ -6488,15 +6513,15 @@ | |
| 6488 | |
| 6489 | /* |
| 6490 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6491 | ** METHOD: sqlite3_blob |
| 6492 | ** |
| 6493 | ** ^This function is used to move an existing blob handle so that it points |
| 6494 | ** to a different row of the same database table. ^The new row is identified |
| 6495 | ** by the rowid value passed as the second argument. Only the row can be |
| 6496 | ** changed. ^The database, table and column on which the blob handle is open |
| 6497 | ** remain the same. Moving an existing blob handle to a new row can be |
| 6498 | ** faster than closing the existing handle and opening a new one. |
| 6499 | ** |
| 6500 | ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
| 6501 | ** it must exist and there must be either a blob or text value stored in |
| 6502 | ** the nominated column.)^ ^If the new row is not present in the table, or if |
| @@ -8421,22 +8446,22 @@ | |
| 8421 | ** ^These interfaces are only available if SQLite is compiled using the |
| 8422 | ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. |
| 8423 | ** |
| 8424 | ** ^The [sqlite3_preupdate_hook()] interface registers a callback function |
| 8425 | ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation |
| 8426 | ** on a [rowid table]. |
| 8427 | ** ^At most one preupdate hook may be registered at a time on a single |
| 8428 | ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides |
| 8429 | ** the previous setting. |
| 8430 | ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] |
| 8431 | ** with a NULL pointer as the second parameter. |
| 8432 | ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as |
| 8433 | ** the first parameter to callbacks. |
| 8434 | ** |
| 8435 | ** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate |
| 8436 | ** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID] |
| 8437 | ** tables. |
| 8438 | ** |
| 8439 | ** ^The second parameter to the preupdate callback is a pointer to |
| 8440 | ** the [database connection] that registered the preupdate hook. |
| 8441 | ** ^The third parameter to the preupdate callback is one of the constants |
| 8442 | ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the |
| @@ -8446,16 +8471,20 @@ | |
| 8446 | ** will be "main" for the main database or "temp" for TEMP tables or |
| 8447 | ** the name given after the AS keyword in the [ATTACH] statement for attached |
| 8448 | ** databases.)^ |
| 8449 | ** ^The fifth parameter to the preupdate callback is the name of the |
| 8450 | ** table that is being modified. |
| 8451 | ** ^The sixth parameter to the preupdate callback is the initial [rowid] of the |
| 8452 | ** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is |
| 8453 | ** undefined for SQLITE_INSERT changes. |
| 8454 | ** ^The seventh parameter to the preupdate callback is the final [rowid] of |
| 8455 | ** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is |
| 8456 | ** undefined for SQLITE_DELETE changes. |
| 8457 | ** |
| 8458 | ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], |
| 8459 | ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces |
| 8460 | ** provide additional information about a preupdate event. These routines |
| 8461 | ** may only be called from within a preupdate callback. Invoking any of |
| @@ -9155,11 +9184,12 @@ | |
| 9155 | ** |
| 9156 | ** <li> For each row (primary key) that exists in the to-table but not in |
| 9157 | ** the from-table, a DELETE record is added to the session object. |
| 9158 | ** |
| 9159 | ** <li> For each row (primary key) that exists in both tables, but features |
| 9160 | ** different in each, an UPDATE record is added to the session. |
| 9161 | ** </ul> |
| 9162 | ** |
| 9163 | ** To clarify, if this function is called and then a changeset constructed |
| 9164 | ** using [sqlite3session_changeset()], then after applying that changeset to |
| 9165 | ** database zFrom the contents of the two compatible tables would be |
| @@ -9740,11 +9770,11 @@ | |
| 9740 | ** considered compatible if all of the following are true: |
| 9741 | ** |
| 9742 | ** <ul> |
| 9743 | ** <li> The table has the same name as the name recorded in the |
| 9744 | ** changeset, and |
| 9745 | ** <li> The table has the same number of columns as recorded in the |
| 9746 | ** changeset, and |
| 9747 | ** <li> The table has primary key columns in the same position as |
| 9748 | ** recorded in the changeset. |
| 9749 | ** </ul> |
| 9750 | ** |
| @@ -9785,11 +9815,15 @@ | |
| 9785 | ** the changeset the row is deleted from the target database. |
| 9786 | ** |
| 9787 | ** If a row with matching primary key values is found, but one or more of |
| 9788 | ** the non-primary key fields contains a value different from the original |
| 9789 | ** row value stored in the changeset, the conflict-handler function is |
| 9790 | ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. |
| 9791 | ** |
| 9792 | ** If no row with matching primary key values is found in the database, |
| 9793 | ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] |
| 9794 | ** passed as the second argument. |
| 9795 | ** |
| @@ -9800,11 +9834,13 @@ | |
| 9800 | ** operation is attempted because an earlier call to the conflict handler |
| 9801 | ** function returned [SQLITE_CHANGESET_REPLACE]. |
| 9802 | ** |
| 9803 | ** <dt>INSERT Changes<dd> |
| 9804 | ** For each INSERT change, an attempt is made to insert the new row into |
| 9805 | ** the database. |
| 9806 | ** |
| 9807 | ** If the attempt to insert the row fails because the database already |
| 9808 | ** contains a row with the same primary key values, the conflict handler |
| 9809 | ** function is invoked with the second argument set to |
| 9810 | ** [SQLITE_CHANGESET_CONFLICT]. |
| @@ -9818,17 +9854,17 @@ | |
| 9818 | ** |
| 9819 | ** <dt>UPDATE Changes<dd> |
| 9820 | ** For each UPDATE change, this function checks if the target database |
| 9821 | ** contains a row with the same primary key value (or values) as the |
| 9822 | ** original row values stored in the changeset. If it does, and the values |
| 9823 | ** stored in all non-primary key columns also match the values stored in |
| 9824 | ** the changeset the row is updated within the target database. |
| 9825 | ** |
| 9826 | ** If a row with matching primary key values is found, but one or more of |
| 9827 | ** the non-primary key fields contains a value different from an original |
| 9828 | ** row value stored in the changeset, the conflict-handler function is |
| 9829 | ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since |
| 9830 | ** UPDATE changes only contain values for non-primary key fields that are |
| 9831 | ** to be modified, only those fields need to match the original values to |
| 9832 | ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. |
| 9833 | ** |
| 9834 | ** If no row with matching primary key values is found in the database, |
| @@ -11537,10 +11573,22 @@ | |
| 11537 | #include <stdlib.h> |
| 11538 | #include <string.h> |
| 11539 | #include <assert.h> |
| 11540 | #include <stddef.h> |
| 11541 | |
| 11542 | /* |
| 11543 | ** If compiling for a processor that lacks floating point support, |
| 11544 | ** substitute integer for floating-point |
| 11545 | */ |
| 11546 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| @@ -11621,13 +11669,16 @@ | |
| 11621 | /* |
| 11622 | ** The default initial allocation for the pagecache when using separate |
| 11623 | ** pagecaches for each database connection. A positive number is the |
| 11624 | ** number of pages. A negative number N translations means that a buffer |
| 11625 | ** of -1024*N bytes is allocated and used for as many pages as it will hold. |
| 11626 | */ |
| 11627 | #ifndef SQLITE_DEFAULT_PCACHE_INITSZ |
| 11628 | # define SQLITE_DEFAULT_PCACHE_INITSZ 100 |
| 11629 | #endif |
| 11630 | |
| 11631 | /* |
| 11632 | ** GCC does not define the offsetof() macro so we'll have to do it |
| 11633 | ** ourselves. |
| @@ -12346,13 +12397,14 @@ | |
| 12346 | ); |
| 12347 | SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*); |
| 12348 | SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*); |
| 12349 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags); |
| 12350 | |
| 12351 | /* Allowed flags for the 2nd argument to sqlite3BtreeDelete() */ |
| 12352 | #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */ |
| 12353 | #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */ |
| 12354 | |
| 12355 | /* An instance of the BtreePayload object describes the content of a single |
| 12356 | ** entry in either an index or table btree. |
| 12357 | ** |
| 12358 | ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain |
| @@ -12379,11 +12431,11 @@ | |
| 12379 | int nData; /* Size of pData. 0 if none. */ |
| 12380 | int nZero; /* Extra zero data appended after pData,nData */ |
| 12381 | }; |
| 12382 | |
| 12383 | SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload, |
| 12384 | int bias, int seekResult); |
| 12385 | SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes); |
| 12386 | SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| 12387 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes); |
| 12388 | SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); |
| 12389 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes); |
| @@ -12512,12 +12564,11 @@ | |
| 12512 | ** as an instance of the following structure: |
| 12513 | */ |
| 12514 | struct VdbeOp { |
| 12515 | u8 opcode; /* What operation to perform */ |
| 12516 | signed char p4type; /* One of the P4_xxx constants for p4 */ |
| 12517 | u8 notUsed1; |
| 12518 | u8 p5; /* Fifth parameter is an unsigned character */ |
| 12519 | int p1; /* First operand */ |
| 12520 | int p2; /* Second parameter (often the jump destination) */ |
| 12521 | int p3; /* The third parameter */ |
| 12522 | union p4union { /* fourth parameter */ |
| 12523 | int i; /* Integer value if p4type==P4_INT32 */ |
| @@ -12874,11 +12925,11 @@ | |
| 12874 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 12875 | SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8); |
| 12876 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 12877 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 12878 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 12879 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 12880 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 12881 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 12882 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 12883 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 12884 | SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type); |
| @@ -13176,18 +13227,20 @@ | |
| 13176 | SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*); |
| 13177 | SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 13178 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 13179 | SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 13180 | SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 13181 | SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager); |
| 13182 | # ifdef SQLITE_ENABLE_SNAPSHOT |
| 13183 | SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot); |
| 13184 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 13185 | SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager); |
| 13186 | # endif |
| 13187 | #else |
| 13188 | # define sqlite3PagerUseWal(x) 0 |
| 13189 | #endif |
| 13190 | |
| 13191 | #ifdef SQLITE_ENABLE_ZIPVFS |
| 13192 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); |
| 13193 | #endif |
| @@ -14007,10 +14060,11 @@ | |
| 14007 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| 14008 | u8 suppressErr; /* Do not issue error messages if true */ |
| 14009 | u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ |
| 14010 | u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */ |
| 14011 | u8 mTrace; /* zero or more SQLITE_TRACE flags */ |
| 14012 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 14013 | u32 magic; /* Magic number for detect library misuse */ |
| 14014 | int nChange; /* Value returned by sqlite3_changes() */ |
| 14015 | int nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 14016 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| @@ -14272,10 +14326,11 @@ | |
| 14272 | #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ |
| 14273 | #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ |
| 14274 | #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ |
| 14275 | #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a |
| 14276 | ** single query - might change over time */ |
| 14277 | |
| 14278 | /* |
| 14279 | ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 14280 | ** used to create the initializers for the FuncDef structures. |
| 14281 | ** |
| @@ -15278,11 +15333,11 @@ | |
| 15278 | #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */ |
| 15279 | #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */ |
| 15280 | #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */ |
| 15281 | #define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */ |
| 15282 | #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */ |
| 15283 | /* 0x1000 not currently used */ |
| 15284 | /* 0x2000 not currently used */ |
| 15285 | #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */ |
| 15286 | /* 0x8000 not currently used */ |
| 15287 | |
| 15288 | /* Allowed return values from sqlite3WhereIsDistinct() |
| @@ -15739,25 +15794,23 @@ | |
| 15739 | ** OPFLAG_AUXDELETE == BTREE_AUXDELETE |
| 15740 | */ |
| 15741 | #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */ |
| 15742 | /* Also used in P2 (not P5) of OP_Delete */ |
| 15743 | #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ |
| 15744 | #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */ |
| 15745 | #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ |
| 15746 | #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ |
| 15747 | #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ |
| 15748 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 15749 | #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */ |
| 15750 | #endif |
| 15751 | #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ |
| 15752 | #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ |
| 15753 | #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ |
| 15754 | #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ |
| 15755 | #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */ |
| 15756 | #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ |
| 15757 | #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ |
| 15758 | #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete: keep cursor position */ |
| 15759 | #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */ |
| 15760 | |
| 15761 | /* |
| 15762 | * Each trigger present in the database schema is stored as an instance of |
| 15763 | * struct Trigger. |
| @@ -16414,11 +16467,11 @@ | |
| 16414 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*); |
| 16415 | SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int); |
| 16416 | SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); |
| 16417 | SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int); |
| 16418 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); |
| 16419 | SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8); |
| 16420 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| 16421 | SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int); |
| 16422 | SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int); |
| 16423 | SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); |
| 16424 | #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ |
| @@ -16476,10 +16529,15 @@ | |
| 16476 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); |
| 16477 | SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); |
| 16478 | SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); |
| 16479 | SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, |
| 16480 | u8,u8,int,int*,int*); |
| 16481 | SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); |
| 16482 | SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*); |
| 16483 | SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int); |
| 16484 | SQLITE_PRIVATE void sqlite3MultiWrite(Parse*); |
| 16485 | SQLITE_PRIVATE void sqlite3MayAbort(Parse*); |
| @@ -16754,12 +16812,14 @@ | |
| 16754 | #endif |
| 16755 | |
| 16756 | /* |
| 16757 | ** The interface to the LEMON-generated parser |
| 16758 | */ |
| 16759 | SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64)); |
| 16760 | SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*)); |
| 16761 | SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*); |
| 16762 | #ifdef YYTRACKMAXSTACKDEPTH |
| 16763 | SQLITE_PRIVATE int sqlite3ParserStackPeak(void*); |
| 16764 | #endif |
| 16765 | |
| @@ -16865,10 +16925,11 @@ | |
| 16865 | #define sqlite3FkActions(a,b,c,d,e,f) |
| 16866 | #define sqlite3FkCheck(a,b,c,d,e,f) |
| 16867 | #define sqlite3FkDropTable(a,b,c) |
| 16868 | #define sqlite3FkOldmask(a,b) 0 |
| 16869 | #define sqlite3FkRequired(a,b,c,d) 0 |
| 16870 | #endif |
| 16871 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 16872 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*); |
| 16873 | SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); |
| 16874 | #else |
| @@ -17193,10 +17254,23 @@ | |
| 17193 | ** setting.) |
| 17194 | */ |
| 17195 | #ifndef SQLITE_STMTJRNL_SPILL |
| 17196 | # define SQLITE_STMTJRNL_SPILL (64*1024) |
| 17197 | #endif |
| 17198 | |
| 17199 | /* |
| 17200 | ** The following singleton contains the global configuration for |
| 17201 | ** the SQLite library. |
| 17202 | */ |
| @@ -17206,12 +17280,11 @@ | |
| 17206 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 17207 | SQLITE_USE_URI, /* bOpenUri */ |
| 17208 | SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ |
| 17209 | 0x7ffffffe, /* mxStrlen */ |
| 17210 | 0, /* neverCorrupt */ |
| 17211 | 512, /* szLookaside */ |
| 17212 | 125, /* nLookaside */ |
| 17213 | SQLITE_STMTJRNL_SPILL, /* nStmtSpill */ |
| 17214 | {0,0,0,0,0,0,0,0}, /* m */ |
| 17215 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
| 17216 | {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */ |
| 17217 | (void*)0, /* pHeap */ |
| @@ -18219,10 +18292,11 @@ | |
| 18219 | int iNewReg; /* Register for new.* values */ |
| 18220 | i64 iKey1; /* First key value passed to hook */ |
| 18221 | i64 iKey2; /* Second key value passed to hook */ |
| 18222 | Mem *aNew; /* Array of new.* values */ |
| 18223 | Table *pTab; /* Schema object being upated */ |
| 18224 | }; |
| 18225 | |
| 18226 | /* |
| 18227 | ** Function prototypes |
| 18228 | */ |
| @@ -24283,39 +24357,38 @@ | |
| 24283 | |
| 24284 | /* |
| 24285 | ** Do a memory allocation with statistics and alarms. Assume the |
| 24286 | ** lock is already held. |
| 24287 | */ |
| 24288 | static int mallocWithAlarm(int n, void **pp){ |
| 24289 | int nFull; |
| 24290 | void *p; |
| 24291 | assert( sqlite3_mutex_held(mem0.mutex) ); |
| 24292 | nFull = sqlite3GlobalConfig.m.xRoundup(n); |
| 24293 | sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n); |
| 24294 | if( mem0.alarmThreshold>0 ){ |
| 24295 | sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 24296 | if( nUsed >= mem0.alarmThreshold - nFull ){ |
| 24297 | mem0.nearlyFull = 1; |
| 24298 | sqlite3MallocAlarm(nFull); |
| 24299 | }else{ |
| 24300 | mem0.nearlyFull = 0; |
| 24301 | } |
| 24302 | } |
| 24303 | p = sqlite3GlobalConfig.m.xMalloc(nFull); |
| 24304 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 24305 | if( p==0 && mem0.alarmThreshold>0 ){ |
| 24306 | sqlite3MallocAlarm(nFull); |
| 24307 | p = sqlite3GlobalConfig.m.xMalloc(nFull); |
| 24308 | } |
| 24309 | #endif |
| 24310 | if( p ){ |
| 24311 | nFull = sqlite3MallocSize(p); |
| 24312 | sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull); |
| 24313 | sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1); |
| 24314 | } |
| 24315 | *pp = p; |
| 24316 | return nFull; |
| 24317 | } |
| 24318 | |
| 24319 | /* |
| 24320 | ** Allocate memory. This routine is like sqlite3_malloc() except that it |
| 24321 | ** assumes the memory subsystem has already been initialized. |
| @@ -24951,11 +25024,10 @@ | |
| 24951 | |
| 24952 | /* |
| 24953 | ** Allowed values for et_info.flags |
| 24954 | */ |
| 24955 | #define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
| 24956 | #define FLAG_INTERN 2 /* True if for internal use only */ |
| 24957 | #define FLAG_STRING 4 /* Allow infinity precision */ |
| 24958 | |
| 24959 | |
| 24960 | /* |
| 24961 | ** The following table is searched linearly, so it is good to put the |
| @@ -24985,15 +25057,14 @@ | |
| 24985 | { 'i', 10, 1, etRADIX, 0, 0 }, |
| 24986 | { 'n', 0, 0, etSIZE, 0, 0 }, |
| 24987 | { '%', 0, 0, etPERCENT, 0, 0 }, |
| 24988 | { 'p', 16, 0, etPOINTER, 0, 1 }, |
| 24989 | |
| 24990 | /* All the rest have the FLAG_INTERN bit set and are thus for internal |
| 24991 | ** use only */ |
| 24992 | { 'T', 0, 2, etTOKEN, 0, 0 }, |
| 24993 | { 'S', 0, 2, etSRCLIST, 0, 0 }, |
| 24994 | { 'r', 10, 3, etORDINAL, 0, 0 }, |
| 24995 | }; |
| 24996 | |
| 24997 | /* |
| 24998 | ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point |
| 24999 | ** conversions will work. |
| @@ -25083,11 +25154,10 @@ | |
| 25083 | etByte flag_long; /* True if "l" flag is present */ |
| 25084 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 25085 | etByte done; /* Loop termination flag */ |
| 25086 | etByte xtype = etINVALID; /* Conversion paradigm */ |
| 25087 | u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ |
| 25088 | u8 useIntern; /* Ok to use internal conversions (ex: %T) */ |
| 25089 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 25090 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 25091 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| 25092 | const et_info *infop; /* Pointer to the appropriate info structure */ |
| 25093 | char *zOut; /* Rendering buffer */ |
| @@ -25102,17 +25172,15 @@ | |
| 25102 | #endif |
| 25103 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 25104 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 25105 | |
| 25106 | bufpt = 0; |
| 25107 | if( pAccum->printfFlags ){ |
| 25108 | if( (bArgList = (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ |
| 25109 | pArgList = va_arg(ap, PrintfArguments*); |
| 25110 | } |
| 25111 | useIntern = pAccum->printfFlags & SQLITE_PRINTF_INTERNAL; |
| 25112 | }else{ |
| 25113 | bArgList = useIntern = 0; |
| 25114 | } |
| 25115 | for(; (c=(*fmt))!=0; ++fmt){ |
| 25116 | if( c!='%' ){ |
| 25117 | bufpt = (char *)fmt; |
| 25118 | #if HAVE_STRCHRNUL |
| @@ -25220,15 +25288,11 @@ | |
| 25220 | infop = &fmtinfo[0]; |
| 25221 | xtype = etINVALID; |
| 25222 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| 25223 | if( c==fmtinfo[idx].fmttype ){ |
| 25224 | infop = &fmtinfo[idx]; |
| 25225 | if( useIntern || (infop->flags & FLAG_INTERN)==0 ){ |
| 25226 | xtype = infop->type; |
| 25227 | }else{ |
| 25228 | return; |
| 25229 | } |
| 25230 | break; |
| 25231 | } |
| 25232 | } |
| 25233 | |
| 25234 | /* |
| @@ -25593,22 +25657,28 @@ | |
| 25593 | ** consume, not the length of the output... |
| 25594 | ** if( precision>=0 && precision<length ) length = precision; */ |
| 25595 | break; |
| 25596 | } |
| 25597 | case etTOKEN: { |
| 25598 | Token *pToken = va_arg(ap, Token*); |
| 25599 | assert( bArgList==0 ); |
| 25600 | if( pToken && pToken->n ){ |
| 25601 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
| 25602 | } |
| 25603 | length = width = 0; |
| 25604 | break; |
| 25605 | } |
| 25606 | case etSRCLIST: { |
| 25607 | SrcList *pSrc = va_arg(ap, SrcList*); |
| 25608 | int k = va_arg(ap, int); |
| 25609 | struct SrcList_item *pItem = &pSrc->a[k]; |
| 25610 | assert( bArgList==0 ); |
| 25611 | assert( k>=0 && k<pSrc->nSrc ); |
| 25612 | if( pItem->zDatabase ){ |
| 25613 | sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); |
| 25614 | sqlite3StrAccumAppend(pAccum, ".", 1); |
| @@ -25626,13 +25696,17 @@ | |
| 25626 | ** The text of the conversion is pointed to by "bufpt" and is |
| 25627 | ** "length" characters long. The field width is "width". Do |
| 25628 | ** the output. |
| 25629 | */ |
| 25630 | width -= length; |
| 25631 | if( width>0 && !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); |
| 25632 | sqlite3StrAccumAppend(pAccum, bufpt, length); |
| 25633 | if( width>0 && flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); |
| 25634 | |
| 25635 | if( zExtra ){ |
| 25636 | sqlite3DbFree(pAccum->db, zExtra); |
| 25637 | zExtra = 0; |
| 25638 | } |
| @@ -28601,11 +28675,11 @@ | |
| 28601 | #if SQLITE_BYTEORDER==4321 |
| 28602 | u32 x; |
| 28603 | memcpy(&x,p,4); |
| 28604 | return x; |
| 28605 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28606 | && defined(__GNUC__) && GCC_VERSION>=4003000 |
| 28607 | u32 x; |
| 28608 | memcpy(&x,p,4); |
| 28609 | return __builtin_bswap32(x); |
| 28610 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28611 | && defined(_MSC_VER) && _MSC_VER>=1300 |
| @@ -28619,11 +28693,11 @@ | |
| 28619 | } |
| 28620 | SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){ |
| 28621 | #if SQLITE_BYTEORDER==4321 |
| 28622 | memcpy(p,&v,4); |
| 28623 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28624 | && defined(__GNUC__) && GCC_VERSION>=4003000 |
| 28625 | u32 x = __builtin_bswap32(v); |
| 28626 | memcpy(p,&x,4); |
| 28627 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28628 | && defined(_MSC_VER) && _MSC_VER>=1300 |
| 28629 | u32 x = _byteswap_ulong(v); |
| @@ -28739,10 +28813,14 @@ | |
| 28739 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 28740 | ** Return 0 on success. Or if the operation would have resulted in an |
| 28741 | ** overflow, leave *pA unchanged and return 1. |
| 28742 | */ |
| 28743 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| 28744 | i64 iA = *pA; |
| 28745 | testcase( iA==0 ); testcase( iA==1 ); |
| 28746 | testcase( iB==-1 ); testcase( iB==0 ); |
| 28747 | if( iB>=0 ){ |
| 28748 | testcase( iA>0 && LARGEST_INT64 - iA == iB ); |
| @@ -28753,23 +28831,33 @@ | |
| 28753 | testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); |
| 28754 | if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; |
| 28755 | } |
| 28756 | *pA += iB; |
| 28757 | return 0; |
| 28758 | } |
| 28759 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 28760 | testcase( iB==SMALLEST_INT64+1 ); |
| 28761 | if( iB==SMALLEST_INT64 ){ |
| 28762 | testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); |
| 28763 | if( (*pA)>=0 ) return 1; |
| 28764 | *pA -= iB; |
| 28765 | return 0; |
| 28766 | }else{ |
| 28767 | return sqlite3AddInt64(pA, -iB); |
| 28768 | } |
| 28769 | } |
| 28770 | SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ |
| 28771 | i64 iA = *pA; |
| 28772 | if( iB>0 ){ |
| 28773 | if( iA>LARGEST_INT64/iB ) return 1; |
| 28774 | if( iA<SMALLEST_INT64/iB ) return 1; |
| 28775 | }else if( iB<0 ){ |
| @@ -28781,10 +28869,11 @@ | |
| 28781 | if( -iA>LARGEST_INT64/-iB ) return 1; |
| 28782 | } |
| 28783 | } |
| 28784 | *pA = iA*iB; |
| 28785 | return 0; |
| 28786 | } |
| 28787 | |
| 28788 | /* |
| 28789 | ** Compute the absolute value of a 32-bit signed integer, of possible. Or |
| 28790 | ** if the integer has a value of -2147483648, return +2147483647 |
| @@ -47485,18 +47574,24 @@ | |
| 47485 | ** if( pPager->jfd->pMethods ){ ... |
| 47486 | */ |
| 47487 | #define isOpen(pFd) ((pFd)->pMethods!=0) |
| 47488 | |
| 47489 | /* |
| 47490 | ** Return true if this pager uses a write-ahead log instead of the usual |
| 47491 | ** rollback journal. Otherwise false. |
| 47492 | */ |
| 47493 | #ifndef SQLITE_OMIT_WAL |
| 47494 | SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager){ |
| 47495 | return (pPager->pWal!=0); |
| 47496 | } |
| 47497 | # define pagerUseWal(x) sqlite3PagerUseWal(x) |
| 47498 | #else |
| 47499 | # define pagerUseWal(x) 0 |
| 47500 | # define pagerRollbackWal(x) 0 |
| 47501 | # define pagerWalFrames(v,w,x,y) 0 |
| 47502 | # define pagerOpenWalIfPresent(z) SQLITE_OK |
| @@ -58624,27 +58719,38 @@ | |
| 58624 | ** Enter the mutexes in accending order by BtShared pointer address |
| 58625 | ** to avoid the possibility of deadlock when two threads with |
| 58626 | ** two or more btrees in common both try to lock all their btrees |
| 58627 | ** at the same instant. |
| 58628 | */ |
| 58629 | SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ |
| 58630 | int i; |
| 58631 | Btree *p; |
| 58632 | assert( sqlite3_mutex_held(db->mutex) ); |
| 58633 | for(i=0; i<db->nDb; i++){ |
| 58634 | p = db->aDb[i].pBt; |
| 58635 | if( p ) sqlite3BtreeEnter(p); |
| 58636 | } |
| 58637 | } |
| 58638 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){ |
| 58639 | int i; |
| 58640 | Btree *p; |
| 58641 | assert( sqlite3_mutex_held(db->mutex) ); |
| 58642 | for(i=0; i<db->nDb; i++){ |
| 58643 | p = db->aDb[i].pBt; |
| 58644 | if( p ) sqlite3BtreeLeave(p); |
| 58645 | } |
| 58646 | } |
| 58647 | |
| 58648 | #ifndef NDEBUG |
| 58649 | /* |
| 58650 | ** Return true if the current thread holds the database connection |
| @@ -62097,16 +62203,18 @@ | |
| 62097 | for(i=0; i<nCell; i++){ |
| 62098 | u8 *pCell = findCell(pPage, i); |
| 62099 | if( eType==PTRMAP_OVERFLOW1 ){ |
| 62100 | CellInfo info; |
| 62101 | pPage->xParseCell(pPage, pCell, &info); |
| 62102 | if( info.nLocal<info.nPayload |
| 62103 | && pCell+info.nSize-1<=pPage->aData+pPage->maskPage |
| 62104 | && iFrom==get4byte(pCell+info.nSize-4) |
| 62105 | ){ |
| 62106 | put4byte(pCell+info.nSize-4, iTo); |
| 62107 | break; |
| 62108 | } |
| 62109 | }else{ |
| 62110 | if( get4byte(pCell)==iFrom ){ |
| 62111 | put4byte(pCell, iTo); |
| 62112 | break; |
| @@ -62777,11 +62885,16 @@ | |
| 62777 | if( p && p->inTrans==TRANS_WRITE ){ |
| 62778 | BtShared *pBt = p->pBt; |
| 62779 | assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK ); |
| 62780 | assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) ); |
| 62781 | sqlite3BtreeEnter(p); |
| 62782 | rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint); |
| 62783 | if( rc==SQLITE_OK ){ |
| 62784 | if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){ |
| 62785 | pBt->nPage = 0; |
| 62786 | } |
| 62787 | rc = newDatabase(pBt); |
| @@ -63163,25 +63276,24 @@ | |
| 63163 | ** for the entry that the pCur cursor is pointing to. The eOp |
| 63164 | ** argument is interpreted as follows: |
| 63165 | ** |
| 63166 | ** 0: The operation is a read. Populate the overflow cache. |
| 63167 | ** 1: The operation is a write. Populate the overflow cache. |
| 63168 | ** 2: The operation is a read. Do not populate the overflow cache. |
| 63169 | ** |
| 63170 | ** A total of "amt" bytes are read or written beginning at "offset". |
| 63171 | ** Data is read to or from the buffer pBuf. |
| 63172 | ** |
| 63173 | ** The content being read or written might appear on the main page |
| 63174 | ** or be scattered out on multiple overflow pages. |
| 63175 | ** |
| 63176 | ** If the current cursor entry uses one or more overflow pages and the |
| 63177 | ** eOp argument is not 2, this function may allocate space for and lazily |
| 63178 | ** populates the overflow page-list cache array (BtCursor.aOverflow). |
| 63179 | ** Subsequent calls use this cache to make seeking to the supplied offset |
| 63180 | ** more efficient. |
| 63181 | ** |
| 63182 | ** Once an overflow page-list cache has been allocated, it may be |
| 63183 | ** invalidated if some other cursor writes to the same table, or if |
| 63184 | ** the cursor is moved to a different row. Additionally, in auto-vacuum |
| 63185 | ** mode, the following events may invalidate an overflow page-list cache. |
| 63186 | ** |
| 63187 | ** * An incremental vacuum, |
| @@ -63199,25 +63311,21 @@ | |
| 63199 | int rc = SQLITE_OK; |
| 63200 | int iIdx = 0; |
| 63201 | MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */ |
| 63202 | BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */ |
| 63203 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63204 | unsigned char * const pBufStart = pBuf; |
| 63205 | int bEnd; /* True if reading to end of data */ |
| 63206 | #endif |
| 63207 | |
| 63208 | assert( pPage ); |
| 63209 | assert( pCur->eState==CURSOR_VALID ); |
| 63210 | assert( pCur->aiIdx[pCur->iPage]<pPage->nCell ); |
| 63211 | assert( cursorHoldsMutex(pCur) ); |
| 63212 | assert( eOp!=2 || offset==0 ); /* Always start from beginning for eOp==2 */ |
| 63213 | |
| 63214 | getCellInfo(pCur); |
| 63215 | aPayload = pCur->info.pPayload; |
| 63216 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63217 | bEnd = offset+amt==pCur->info.nPayload; |
| 63218 | #endif |
| 63219 | assert( offset+amt <= pCur->info.nPayload ); |
| 63220 | |
| 63221 | assert( aPayload > pPage->aData ); |
| 63222 | if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){ |
| 63223 | /* Trying to read or write past the end of the data is an error. The |
| @@ -63232,11 +63340,11 @@ | |
| 63232 | if( offset<pCur->info.nLocal ){ |
| 63233 | int a = amt; |
| 63234 | if( a+offset>pCur->info.nLocal ){ |
| 63235 | a = pCur->info.nLocal - offset; |
| 63236 | } |
| 63237 | rc = copyPayload(&aPayload[offset], pBuf, a, (eOp & 0x01), pPage->pDbPage); |
| 63238 | offset = 0; |
| 63239 | pBuf += a; |
| 63240 | amt -= a; |
| 63241 | }else{ |
| 63242 | offset -= pCur->info.nLocal; |
| @@ -63248,69 +63356,58 @@ | |
| 63248 | Pgno nextPage; |
| 63249 | |
| 63250 | nextPage = get4byte(&aPayload[pCur->info.nLocal]); |
| 63251 | |
| 63252 | /* If the BtCursor.aOverflow[] has not been allocated, allocate it now. |
| 63253 | ** Except, do not allocate aOverflow[] for eOp==2. |
| 63254 | ** |
| 63255 | ** The aOverflow[] array is sized at one entry for each overflow page |
| 63256 | ** in the overflow chain. The page number of the first overflow page is |
| 63257 | ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array |
| 63258 | ** means "not yet known" (the cache is lazily populated). |
| 63259 | */ |
| 63260 | if( eOp!=2 && (pCur->curFlags & BTCF_ValidOvfl)==0 ){ |
| 63261 | int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; |
| 63262 | if( nOvfl>pCur->nOvflAlloc ){ |
| 63263 | Pgno *aNew = (Pgno*)sqlite3Realloc( |
| 63264 | pCur->aOverflow, nOvfl*2*sizeof(Pgno) |
| 63265 | ); |
| 63266 | if( aNew==0 ){ |
| 63267 | rc = SQLITE_NOMEM_BKPT; |
| 63268 | }else{ |
| 63269 | pCur->nOvflAlloc = nOvfl*2; |
| 63270 | pCur->aOverflow = aNew; |
| 63271 | } |
| 63272 | } |
| 63273 | if( rc==SQLITE_OK ){ |
| 63274 | memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno)); |
| 63275 | pCur->curFlags |= BTCF_ValidOvfl; |
| 63276 | } |
| 63277 | } |
| 63278 | |
| 63279 | /* If the overflow page-list cache has been allocated and the |
| 63280 | ** entry for the first required overflow page is valid, skip |
| 63281 | ** directly to it. |
| 63282 | */ |
| 63283 | if( (pCur->curFlags & BTCF_ValidOvfl)!=0 |
| 63284 | && pCur->aOverflow[offset/ovflSize] |
| 63285 | ){ |
| 63286 | iIdx = (offset/ovflSize); |
| 63287 | nextPage = pCur->aOverflow[iIdx]; |
| 63288 | offset = (offset%ovflSize); |
| 63289 | } |
| 63290 | |
| 63291 | for( ; rc==SQLITE_OK && amt>0 && nextPage; iIdx++){ |
| 63292 | |
| 63293 | /* If required, populate the overflow page-list cache. */ |
| 63294 | if( (pCur->curFlags & BTCF_ValidOvfl)!=0 ){ |
| 63295 | assert( pCur->aOverflow[iIdx]==0 |
| 63296 | || pCur->aOverflow[iIdx]==nextPage |
| 63297 | || CORRUPT_DB ); |
| 63298 | pCur->aOverflow[iIdx] = nextPage; |
| 63299 | } |
| 63300 | |
| 63301 | if( offset>=ovflSize ){ |
| 63302 | /* The only reason to read this page is to obtain the page |
| 63303 | ** number for the next page in the overflow chain. The page |
| 63304 | ** data is not required. So first try to lookup the overflow |
| 63305 | ** page-list cache, if any, then fall back to the getOverflowPage() |
| 63306 | ** function. |
| 63307 | ** |
| 63308 | ** Note that the aOverflow[] array must be allocated because eOp!=2 |
| 63309 | ** here. If eOp==2, then offset==0 and this branch is never taken. |
| 63310 | */ |
| 63311 | assert( eOp!=2 ); |
| 63312 | assert( pCur->curFlags & BTCF_ValidOvfl ); |
| 63313 | assert( pCur->pBtree->db==pBt->db ); |
| 63314 | if( pCur->aOverflow[iIdx+1] ){ |
| 63315 | nextPage = pCur->aOverflow[iIdx+1]; |
| 63316 | }else{ |
| @@ -63320,11 +63417,11 @@ | |
| 63320 | }else{ |
| 63321 | /* Need to read this page properly. It contains some of the |
| 63322 | ** range of data that is being read (eOp==0) or written (eOp!=0). |
| 63323 | */ |
| 63324 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63325 | sqlite3_file *fd; |
| 63326 | #endif |
| 63327 | int a = amt; |
| 63328 | if( a + offset > ovflSize ){ |
| 63329 | a = ovflSize - offset; |
| 63330 | } |
| @@ -63332,31 +63429,29 @@ | |
| 63332 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63333 | /* If all the following are true: |
| 63334 | ** |
| 63335 | ** 1) this is a read operation, and |
| 63336 | ** 2) data is required from the start of this overflow page, and |
| 63337 | ** 3) the database is file-backed, and |
| 63338 | ** 4) there is no open write-transaction, and |
| 63339 | ** 5) the database is not a WAL database, |
| 63340 | ** 6) all data from the page is being read. |
| 63341 | ** 7) at least 4 bytes have already been read into the output buffer |
| 63342 | ** |
| 63343 | ** then data can be read directly from the database file into the |
| 63344 | ** output buffer, bypassing the page-cache altogether. This speeds |
| 63345 | ** up loading large records that span many overflow pages. |
| 63346 | */ |
| 63347 | if( (eOp&0x01)==0 /* (1) */ |
| 63348 | && offset==0 /* (2) */ |
| 63349 | && (bEnd || a==ovflSize) /* (6) */ |
| 63350 | && pBt->inTransaction==TRANS_READ /* (4) */ |
| 63351 | && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (3) */ |
| 63352 | && 0==sqlite3PagerUseWal(pBt->pPager) /* (5) */ |
| 63353 | && &pBuf[-4]>=pBufStart /* (7) */ |
| 63354 | ){ |
| 63355 | u8 aSave[4]; |
| 63356 | u8 *aWrite = &pBuf[-4]; |
| 63357 | assert( aWrite>=pBufStart ); /* hence (7) */ |
| 63358 | memcpy(aSave, aWrite, 4); |
| 63359 | rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1)); |
| 63360 | nextPage = get4byte(aWrite); |
| 63361 | memcpy(aWrite, aSave, 4); |
| 63362 | }else |
| @@ -63363,28 +63458,31 @@ | |
| 63363 | #endif |
| 63364 | |
| 63365 | { |
| 63366 | DbPage *pDbPage; |
| 63367 | rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage, |
| 63368 | ((eOp&0x01)==0 ? PAGER_GET_READONLY : 0) |
| 63369 | ); |
| 63370 | if( rc==SQLITE_OK ){ |
| 63371 | aPayload = sqlite3PagerGetData(pDbPage); |
| 63372 | nextPage = get4byte(aPayload); |
| 63373 | rc = copyPayload(&aPayload[offset+4], pBuf, a, (eOp&0x01), pDbPage); |
| 63374 | sqlite3PagerUnref(pDbPage); |
| 63375 | offset = 0; |
| 63376 | } |
| 63377 | } |
| 63378 | amt -= a; |
| 63379 | pBuf += a; |
| 63380 | } |
| 63381 | } |
| 63382 | } |
| 63383 | |
| 63384 | if( rc==SQLITE_OK && amt>0 ){ |
| 63385 | return SQLITE_CORRUPT_BKPT; |
| 63386 | } |
| 63387 | return rc; |
| 63388 | } |
| 63389 | |
| 63390 | /* |
| @@ -63409,25 +63507,38 @@ | |
| 63409 | assert( pCur->eState==CURSOR_VALID ); |
| 63410 | assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] ); |
| 63411 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 63412 | return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); |
| 63413 | } |
| 63414 | #ifndef SQLITE_OMIT_INCRBLOB |
| 63415 | SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 63416 | int rc; |
| 63417 | if ( pCur->eState==CURSOR_INVALID ){ |
| 63418 | return SQLITE_ABORT; |
| 63419 | } |
| 63420 | assert( cursorOwnsBtShared(pCur) ); |
| 63421 | rc = restoreCursorPosition(pCur); |
| 63422 | if( rc==SQLITE_OK ){ |
| 63423 | assert( pCur->eState==CURSOR_VALID ); |
| 63424 | assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] ); |
| 63425 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 63426 | rc = accessPayload(pCur, offset, amt, pBuf, 0); |
| 63427 | } |
| 63428 | return rc; |
| 63429 | } |
| 63430 | #endif /* SQLITE_OMIT_INCRBLOB */ |
| 63431 | |
| 63432 | /* |
| 63433 | ** Return a pointer to payload information from the entry that the |
| @@ -63829,13 +63940,30 @@ | |
| 63829 | ){ |
| 63830 | if( pCur->info.nKey==intKey ){ |
| 63831 | *pRes = 0; |
| 63832 | return SQLITE_OK; |
| 63833 | } |
| 63834 | if( (pCur->curFlags & BTCF_AtLast)!=0 && pCur->info.nKey<intKey ){ |
| 63835 | *pRes = -1; |
| 63836 | return SQLITE_OK; |
| 63837 | } |
| 63838 | } |
| 63839 | |
| 63840 | if( pIdxKey ){ |
| 63841 | xRecordCompare = sqlite3VdbeFindCompare(pIdxKey); |
| @@ -63967,11 +64095,12 @@ | |
| 63967 | if( pCellKey==0 ){ |
| 63968 | rc = SQLITE_NOMEM_BKPT; |
| 63969 | goto moveto_finish; |
| 63970 | } |
| 63971 | pCur->aiIdx[pCur->iPage] = (u16)idx; |
| 63972 | rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 2); |
| 63973 | if( rc ){ |
| 63974 | sqlite3_free(pCellKey); |
| 63975 | goto moveto_finish; |
| 63976 | } |
| 63977 | c = xRecordCompare(nCell, pCellKey, pIdxKey); |
| @@ -66010,11 +66139,10 @@ | |
| 66010 | */ |
| 66011 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 66012 | for(i=0; i<nOld; i++){ |
| 66013 | MemPage *p = apOld[i]; |
| 66014 | szNew[i] = usableSpace - p->nFree; |
| 66015 | if( szNew[i]<0 ){ rc = SQLITE_CORRUPT_BKPT; goto balance_cleanup; } |
| 66016 | for(j=0; j<p->nOverflow; j++){ |
| 66017 | szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]); |
| 66018 | } |
| 66019 | cntNew[i] = cntOld[i]; |
| 66020 | } |
| @@ -66689,11 +66817,11 @@ | |
| 66689 | ** to decode the key. |
| 66690 | */ |
| 66691 | SQLITE_PRIVATE int sqlite3BtreeInsert( |
| 66692 | BtCursor *pCur, /* Insert data into the table of this cursor */ |
| 66693 | const BtreePayload *pX, /* Content of the row to be inserted */ |
| 66694 | int appendBias, /* True if this is likely an append */ |
| 66695 | int seekResult /* Result of prior MovetoUnpacked() call */ |
| 66696 | ){ |
| 66697 | int rc; |
| 66698 | int loc = seekResult; /* -1: before desired location +1: after */ |
| 66699 | int szNew = 0; |
| @@ -66701,10 +66829,12 @@ | |
| 66701 | MemPage *pPage; |
| 66702 | Btree *p = pCur->pBtree; |
| 66703 | BtShared *pBt = p->pBt; |
| 66704 | unsigned char *oldCell; |
| 66705 | unsigned char *newCell = 0; |
| 66706 | |
| 66707 | if( pCur->eState==CURSOR_FAULT ){ |
| 66708 | assert( pCur->skipNext!=SQLITE_OK ); |
| 66709 | return pCur->skipNext; |
| 66710 | } |
| @@ -66742,23 +66872,28 @@ | |
| 66742 | assert( pX->pKey==0 ); |
| 66743 | /* If this is an insert into a table b-tree, invalidate any incrblob |
| 66744 | ** cursors open on the row being replaced */ |
| 66745 | invalidateIncrblobCursors(p, pX->nKey, 0); |
| 66746 | |
| 66747 | /* If the cursor is currently on the last row and we are appending a |
| 66748 | ** new row onto the end, set the "loc" to avoid an unnecessary |
| 66749 | ** btreeMoveto() call */ |
| 66750 | if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){ |
| 66751 | loc = 0; |
| 66752 | }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0 |
| 66753 | && pCur->info.nKey==pX->nKey-1 ){ |
| 66754 | loc = -1; |
| 66755 | }else if( loc==0 ){ |
| 66756 | rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc); |
| 66757 | if( rc ) return rc; |
| 66758 | } |
| 66759 | }else if( loc==0 ){ |
| 66760 | if( pX->nMem ){ |
| 66761 | UnpackedRecord r; |
| 66762 | r.pKeyInfo = pCur->pKeyInfo; |
| 66763 | r.aMem = pX->aMem; |
| 66764 | r.nField = pX->nMem; |
| @@ -66765,13 +66900,13 @@ | |
| 66765 | r.default_rc = 0; |
| 66766 | r.errCode = 0; |
| 66767 | r.r1 = 0; |
| 66768 | r.r2 = 0; |
| 66769 | r.eqSeen = 0; |
| 66770 | rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc); |
| 66771 | }else{ |
| 66772 | rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc); |
| 66773 | } |
| 66774 | if( rc ) return rc; |
| 66775 | } |
| 66776 | assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) ); |
| 66777 | |
| @@ -66855,10 +66990,24 @@ | |
| 66855 | ** fails. Internal data structure corruption will result otherwise. |
| 66856 | ** Also, set the cursor state to invalid. This stops saveCursorPosition() |
| 66857 | ** from trying to save the current position of the cursor. */ |
| 66858 | pCur->apPage[pCur->iPage]->nOverflow = 0; |
| 66859 | pCur->eState = CURSOR_INVALID; |
| 66860 | } |
| 66861 | assert( pCur->apPage[pCur->iPage]->nOverflow==0 ); |
| 66862 | |
| 66863 | end_insert: |
| 66864 | return rc; |
| @@ -71765,11 +71914,11 @@ | |
| 71765 | sqlite3VdbeGetOp(p,addr)->p2 = val; |
| 71766 | } |
| 71767 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){ |
| 71768 | sqlite3VdbeGetOp(p,addr)->p3 = val; |
| 71769 | } |
| 71770 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u8 p5){ |
| 71771 | assert( p->nOp>0 || p->db->mallocFailed ); |
| 71772 | if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5; |
| 71773 | } |
| 71774 | |
| 71775 | /* |
| @@ -73479,64 +73628,63 @@ | |
| 73479 | ** statement transaction is committed. |
| 73480 | ** |
| 73481 | ** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned. |
| 73482 | ** Otherwise SQLITE_OK. |
| 73483 | */ |
| 73484 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){ |
| 73485 | sqlite3 *const db = p->db; |
| 73486 | int rc = SQLITE_OK; |
| 73487 | |
| 73488 | /* If p->iStatement is greater than zero, then this Vdbe opened a |
| 73489 | ** statement transaction that should be closed here. The only exception |
| 73490 | ** is that an IO error may have occurred, causing an emergency rollback. |
| 73491 | ** In this case (db->nStatement==0), and there is nothing to do. |
| 73492 | */ |
| 73493 | if( db->nStatement && p->iStatement ){ |
| 73494 | int i; |
| 73495 | const int iSavepoint = p->iStatement-1; |
| 73496 | |
| 73497 | assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE); |
| 73498 | assert( db->nStatement>0 ); |
| 73499 | assert( p->iStatement==(db->nStatement+db->nSavepoint) ); |
| 73500 | |
| 73501 | for(i=0; i<db->nDb; i++){ |
| 73502 | int rc2 = SQLITE_OK; |
| 73503 | Btree *pBt = db->aDb[i].pBt; |
| 73504 | if( pBt ){ |
| 73505 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| 73506 | rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint); |
| 73507 | } |
| 73508 | if( rc2==SQLITE_OK ){ |
| 73509 | rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint); |
| 73510 | } |
| 73511 | if( rc==SQLITE_OK ){ |
| 73512 | rc = rc2; |
| 73513 | } |
| 73514 | } |
| 73515 | } |
| 73516 | db->nStatement--; |
| 73517 | p->iStatement = 0; |
| 73518 | |
| 73519 | if( rc==SQLITE_OK ){ |
| 73520 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| 73521 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint); |
| 73522 | } |
| 73523 | if( rc==SQLITE_OK ){ |
| 73524 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint); |
| 73525 | } |
| 73526 | } |
| 73527 | |
| 73528 | /* If the statement transaction is being rolled back, also restore the |
| 73529 | ** database handles deferred constraint counter to the value it had when |
| 73530 | ** the statement transaction was opened. */ |
| 73531 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| 73532 | db->nDeferredCons = p->nStmtDefCons; |
| 73533 | db->nDeferredImmCons = p->nStmtDefImmCons; |
| 73534 | } |
| 73535 | } |
| 73536 | return rc; |
| 73537 | } |
| 73538 | |
| 73539 | /* |
| 73540 | ** This function is called when a transaction opened by the database |
| 73541 | ** handle associated with the VM passed as an argument is about to be |
| 73542 | ** committed. If there are outstanding deferred foreign key constraint |
| @@ -75567,14 +75715,14 @@ | |
| 75567 | ** structure itself, using sqlite3DbFree(). |
| 75568 | ** |
| 75569 | ** This function is used to free UnpackedRecord structures allocated by |
| 75570 | ** the vdbeUnpackRecord() function found in vdbeapi.c. |
| 75571 | */ |
| 75572 | static void vdbeFreeUnpacked(sqlite3 *db, UnpackedRecord *p){ |
| 75573 | if( p ){ |
| 75574 | int i; |
| 75575 | for(i=0; i<p->nField; i++){ |
| 75576 | Mem *pMem = &p->aMem[i]; |
| 75577 | if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem); |
| 75578 | } |
| 75579 | sqlite3DbFree(db, p); |
| 75580 | } |
| @@ -75603,14 +75751,19 @@ | |
| 75603 | const char *zTbl = pTab->zName; |
| 75604 | static const u8 fakeSortOrder = 0; |
| 75605 | |
| 75606 | assert( db->pPreUpdate==0 ); |
| 75607 | memset(&preupdate, 0, sizeof(PreUpdate)); |
| 75608 | if( op==SQLITE_UPDATE ){ |
| 75609 | iKey2 = v->aMem[iReg].u.i; |
| 75610 | }else{ |
| 75611 | iKey2 = iKey1; |
| 75612 | } |
| 75613 | |
| 75614 | assert( pCsr->nField==pTab->nCol |
| 75615 | || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1) |
| 75616 | ); |
| @@ -75629,12 +75782,12 @@ | |
| 75629 | |
| 75630 | db->pPreUpdate = &preupdate; |
| 75631 | db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2); |
| 75632 | db->pPreUpdate = 0; |
| 75633 | sqlite3DbFree(db, preupdate.aRecord); |
| 75634 | vdbeFreeUnpacked(db, preupdate.pUnpacked); |
| 75635 | vdbeFreeUnpacked(db, preupdate.pNewUnpacked); |
| 75636 | if( preupdate.aNew ){ |
| 75637 | int i; |
| 75638 | for(i=0; i<pCsr->nField; i++){ |
| 75639 | sqlite3VdbeMemRelease(&preupdate.aNew[i]); |
| 75640 | } |
| @@ -77305,18 +77458,22 @@ | |
| 77305 | ** This function is called from within a pre-update callback to retrieve |
| 77306 | ** a field of the row currently being updated or deleted. |
| 77307 | */ |
| 77308 | SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){ |
| 77309 | PreUpdate *p = db->pPreUpdate; |
| 77310 | int rc = SQLITE_OK; |
| 77311 | |
| 77312 | /* Test that this call is being made from within an SQLITE_DELETE or |
| 77313 | ** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */ |
| 77314 | if( !p || p->op==SQLITE_INSERT ){ |
| 77315 | rc = SQLITE_MISUSE_BKPT; |
| 77316 | goto preupdate_old_out; |
| 77317 | } |
| 77318 | if( iIdx>=p->pCsr->nField || iIdx<0 ){ |
| 77319 | rc = SQLITE_RANGE; |
| 77320 | goto preupdate_old_out; |
| 77321 | } |
| 77322 | |
| @@ -77338,21 +77495,18 @@ | |
| 77338 | goto preupdate_old_out; |
| 77339 | } |
| 77340 | p->aRecord = aRec; |
| 77341 | } |
| 77342 | |
| 77343 | if( iIdx>=p->pUnpacked->nField ){ |
| 77344 | *ppValue = (sqlite3_value *)columnNullValue(); |
| 77345 | }else{ |
| 77346 | Mem *pMem = *ppValue = &p->pUnpacked->aMem[iIdx]; |
| 77347 | *ppValue = &p->pUnpacked->aMem[iIdx]; |
| 77348 | if( iIdx==p->pTab->iPKey ){ |
| 77349 | sqlite3VdbeMemSetInt64(pMem, p->iKey1); |
| 77350 | }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){ |
| 77351 | if( pMem->flags & MEM_Int ){ |
| 77352 | sqlite3VdbeMemRealify(pMem); |
| 77353 | } |
| 77354 | } |
| 77355 | } |
| 77356 | |
| 77357 | preupdate_old_out: |
| 77358 | sqlite3Error(db, rc); |
| @@ -77401,10 +77555,13 @@ | |
| 77401 | |
| 77402 | if( !p || p->op==SQLITE_DELETE ){ |
| 77403 | rc = SQLITE_MISUSE_BKPT; |
| 77404 | goto preupdate_new_out; |
| 77405 | } |
| 77406 | if( iIdx>=p->pCsr->nField || iIdx<0 ){ |
| 77407 | rc = SQLITE_RANGE; |
| 77408 | goto preupdate_new_out; |
| 77409 | } |
| 77410 | |
| @@ -77421,17 +77578,15 @@ | |
| 77421 | rc = SQLITE_NOMEM; |
| 77422 | goto preupdate_new_out; |
| 77423 | } |
| 77424 | p->pNewUnpacked = pUnpack; |
| 77425 | } |
| 77426 | if( iIdx>=pUnpack->nField ){ |
| 77427 | pMem = (sqlite3_value *)columnNullValue(); |
| 77428 | }else{ |
| 77429 | pMem = &pUnpack->aMem[iIdx]; |
| 77430 | if( iIdx==p->pTab->iPKey ){ |
| 77431 | sqlite3VdbeMemSetInt64(pMem, p->iKey2); |
| 77432 | } |
| 77433 | } |
| 77434 | }else{ |
| 77435 | /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required |
| 77436 | ** value. Make a copy of the cell contents and return a pointer to it. |
| 77437 | ** It is not safe to return a pointer to the memory cell itself as the |
| @@ -78404,12 +78559,10 @@ | |
| 78404 | Mem *aMem = p->aMem; /* Copy of p->aMem */ |
| 78405 | Mem *pIn1 = 0; /* 1st input operand */ |
| 78406 | Mem *pIn2 = 0; /* 2nd input operand */ |
| 78407 | Mem *pIn3 = 0; /* 3rd input operand */ |
| 78408 | Mem *pOut = 0; /* Output operand */ |
| 78409 | int *aPermute = 0; /* Permutation of columns for OP_Compare */ |
| 78410 | i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ |
| 78411 | #ifdef VDBE_PROFILE |
| 78412 | u64 start; /* CPU clock count at start of opcode */ |
| 78413 | #endif |
| 78414 | /*** INSERT STACK UNION HERE ***/ |
| 78415 | |
| @@ -78420,11 +78573,10 @@ | |
| 78420 | ** sqlite3_column_text16() failed. */ |
| 78421 | goto no_mem; |
| 78422 | } |
| 78423 | assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY ); |
| 78424 | assert( p->bIsReader || p->readOnly!=0 ); |
| 78425 | p->rc = SQLITE_OK; |
| 78426 | p->iCurrentTime = 0; |
| 78427 | assert( p->explain==0 ); |
| 78428 | p->pResultSet = 0; |
| 78429 | db->busyHandler.nBusy = 0; |
| 78430 | if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| @@ -78781,11 +78933,10 @@ | |
| 78781 | pFrame = p->pFrame; |
| 78782 | p->pFrame = pFrame->pParent; |
| 78783 | p->nFrame--; |
| 78784 | sqlite3VdbeSetChanges(db, p->nChange); |
| 78785 | pcx = sqlite3VdbeFrameRestore(pFrame); |
| 78786 | lastRowid = db->lastRowid; |
| 78787 | if( pOp->p2==OE_Ignore ){ |
| 78788 | /* Instruction pcx is the OP_Program that invoked the sub-program |
| 78789 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 78790 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 78791 | ** an IGNORE exception. In this case jump to the address specified |
| @@ -79016,11 +79167,11 @@ | |
| 79016 | assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) ); |
| 79017 | pVar = &p->aVar[pOp->p1 - 1]; |
| 79018 | if( sqlite3VdbeMemTooBig(pVar) ){ |
| 79019 | goto too_big; |
| 79020 | } |
| 79021 | pOut = out2Prerelease(p, pOp); |
| 79022 | sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 79023 | UPDATE_MAX_BLOBSIZE(pOut); |
| 79024 | break; |
| 79025 | } |
| 79026 | |
| @@ -79503,13 +79654,11 @@ | |
| 79503 | REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]); |
| 79504 | } |
| 79505 | #endif |
| 79506 | MemSetTypeFlag(pCtx->pOut, MEM_Null); |
| 79507 | pCtx->fErrorOrAux = 0; |
| 79508 | db->lastRowid = lastRowid; |
| 79509 | (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */ |
| 79510 | lastRowid = db->lastRowid; /* Remember rowid changes made by xSFunc */ |
| 79511 | |
| 79512 | /* If the function returned an error, throw an exception */ |
| 79513 | if( pCtx->fErrorOrAux ){ |
| 79514 | if( pCtx->isError ){ |
| 79515 | sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| @@ -79961,12 +80110,12 @@ | |
| 79961 | } |
| 79962 | |
| 79963 | |
| 79964 | /* Opcode: Permutation * * * P4 * |
| 79965 | ** |
| 79966 | ** Set the permutation used by the OP_Compare operator to be the array |
| 79967 | ** of integers in P4. |
| 79968 | ** |
| 79969 | ** The permutation is only valid until the next OP_Compare that has |
| 79970 | ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should |
| 79971 | ** occur immediately prior to the OP_Compare. |
| 79972 | ** |
| @@ -79974,11 +80123,12 @@ | |
| 79974 | ** and does not become part of the permutation. |
| 79975 | */ |
| 79976 | case OP_Permutation: { |
| 79977 | assert( pOp->p4type==P4_INTARRAY ); |
| 79978 | assert( pOp->p4.ai ); |
| 79979 | aPermute = pOp->p4.ai + 1; |
| 79980 | break; |
| 79981 | } |
| 79982 | |
| 79983 | /* Opcode: Compare P1 P2 P3 P4 P5 |
| 79984 | ** Synopsis: r[P1@P3] <-> r[P2@P3] |
| @@ -80007,12 +80157,21 @@ | |
| 80007 | int p2; |
| 80008 | const KeyInfo *pKeyInfo; |
| 80009 | int idx; |
| 80010 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 80011 | int bRev; /* True for DESCENDING sort order */ |
| 80012 | |
| 80013 | if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; |
| 80014 | n = pOp->p3; |
| 80015 | pKeyInfo = pOp->p4.pKeyInfo; |
| 80016 | assert( n>0 ); |
| 80017 | assert( pKeyInfo!=0 ); |
| 80018 | p1 = pOp->p1; |
| @@ -80041,11 +80200,10 @@ | |
| 80041 | if( iCompare ){ |
| 80042 | if( bRev ) iCompare = -iCompare; |
| 80043 | break; |
| 80044 | } |
| 80045 | } |
| 80046 | aPermute = 0; |
| 80047 | break; |
| 80048 | } |
| 80049 | |
| 80050 | /* Opcode: Jump P1 P2 P3 * * |
| 80051 | ** |
| @@ -80597,10 +80755,24 @@ | |
| 80597 | do{ |
| 80598 | applyAffinity(pRec++, *(zAffinity++), encoding); |
| 80599 | assert( zAffinity[0]==0 || pRec<=pLast ); |
| 80600 | }while( zAffinity[0] ); |
| 80601 | } |
| 80602 | |
| 80603 | /* Loop through the elements that will make up the record to figure |
| 80604 | ** out how much space is required for the new record. |
| 80605 | */ |
| 80606 | pRec = pLast; |
| @@ -82187,11 +82359,11 @@ | |
| 82187 | assert( memIsValid(pData) ); |
| 82188 | pC = p->apCsr[pOp->p1]; |
| 82189 | assert( pC!=0 ); |
| 82190 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 82191 | assert( pC->uc.pCursor!=0 ); |
| 82192 | assert( pC->isTable ); |
| 82193 | assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC ); |
| 82194 | REGISTER_TRACE(pOp->p2, pData); |
| 82195 | |
| 82196 | if( pOp->opcode==OP_Insert ){ |
| 82197 | pKey = &aMem[pOp->p3]; |
| @@ -82203,18 +82375,17 @@ | |
| 82203 | assert( pOp->opcode==OP_InsertInt ); |
| 82204 | x.nKey = pOp->p3; |
| 82205 | } |
| 82206 | |
| 82207 | if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){ |
| 82208 | assert( pC->isTable ); |
| 82209 | assert( pC->iDb>=0 ); |
| 82210 | zDb = db->aDb[pC->iDb].zDbSName; |
| 82211 | pTab = pOp->p4.pTab; |
| 82212 | assert( HasRowid(pTab) ); |
| 82213 | op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); |
| 82214 | }else{ |
| 82215 | pTab = 0; /* Not needed. Silence a comiler warning. */ |
| 82216 | zDb = 0; /* Not needed. Silence a compiler warning. */ |
| 82217 | } |
| 82218 | |
| 82219 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 82220 | /* Invoke the pre-update hook, if any */ |
| @@ -82222,14 +82393,15 @@ | |
| 82222 | && pOp->p4type==P4_TABLE |
| 82223 | && !(pOp->p5 & OPFLAG_ISUPDATE) |
| 82224 | ){ |
| 82225 | sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2); |
| 82226 | } |
| 82227 | #endif |
| 82228 | |
| 82229 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 82230 | if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = x.nKey; |
| 82231 | if( pData->flags & MEM_Null ){ |
| 82232 | x.pData = 0; |
| 82233 | x.nData = 0; |
| 82234 | }else{ |
| 82235 | assert( pData->flags & (MEM_Blob|MEM_Str) ); |
| @@ -82242,11 +82414,11 @@ | |
| 82242 | }else{ |
| 82243 | x.nZero = 0; |
| 82244 | } |
| 82245 | x.pKey = 0; |
| 82246 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, |
| 82247 | (pOp->p5 & OPFLAG_APPEND)!=0, seekResult |
| 82248 | ); |
| 82249 | pC->deferredMoveto = 0; |
| 82250 | pC->cacheStatus = CACHE_STALE; |
| 82251 | |
| 82252 | /* Invoke the update-hook if required. */ |
| @@ -82334,12 +82506,15 @@ | |
| 82334 | pTab = 0; /* Not needed. Silence a compiler warning. */ |
| 82335 | } |
| 82336 | |
| 82337 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 82338 | /* Invoke the pre-update-hook if required. */ |
| 82339 | if( db->xPreUpdateCallback && pOp->p4.pTab && HasRowid(pTab) ){ |
| 82340 | assert( !(opflags & OPFLAG_ISUPDATE) || (aMem[pOp->p3].flags & MEM_Int) ); |
| 82341 | sqlite3VdbePreUpdateHook(p, pC, |
| 82342 | (opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE, |
| 82343 | zDb, pTab, pC->movetoTarget, |
| 82344 | pOp->p3 |
| 82345 | ); |
| @@ -82453,11 +82628,11 @@ | |
| 82453 | if( rc ) goto abort_due_to_error; |
| 82454 | p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE; |
| 82455 | break; |
| 82456 | } |
| 82457 | |
| 82458 | /* Opcode: RowData P1 P2 * * * |
| 82459 | ** Synopsis: r[P2]=data |
| 82460 | ** |
| 82461 | ** Write into register P2 the complete row content for the row at |
| 82462 | ** which cursor P1 is currently pointing. |
| 82463 | ** There is no interpretation of the data. |
| @@ -82467,18 +82642,30 @@ | |
| 82467 | ** If cursor P1 is an index, then the content is the key of the row. |
| 82468 | ** If cursor P2 is a table, then the content extracted is the data. |
| 82469 | ** |
| 82470 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 82471 | ** of a real table, not a pseudo-table. |
| 82472 | */ |
| 82473 | case OP_RowData: { |
| 82474 | VdbeCursor *pC; |
| 82475 | BtCursor *pCrsr; |
| 82476 | u32 n; |
| 82477 | |
| 82478 | pOut = &aMem[pOp->p2]; |
| 82479 | memAboutToChange(p, pOut); |
| 82480 | |
| 82481 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 82482 | pC = p->apCsr[pOp->p1]; |
| 82483 | assert( pC!=0 ); |
| 82484 | assert( pC->eCurType==CURTYPE_BTREE ); |
| @@ -82505,18 +82692,13 @@ | |
| 82505 | n = sqlite3BtreePayloadSize(pCrsr); |
| 82506 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 82507 | goto too_big; |
| 82508 | } |
| 82509 | testcase( n==0 ); |
| 82510 | if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){ |
| 82511 | goto no_mem; |
| 82512 | } |
| 82513 | pOut->n = n; |
| 82514 | MemSetTypeFlag(pOut, MEM_Blob); |
| 82515 | rc = sqlite3BtreePayload(pCrsr, 0, n, pOut->z); |
| 82516 | if( rc ) goto abort_due_to_error; |
| 82517 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ |
| 82518 | UPDATE_MAX_BLOBSIZE(pOut); |
| 82519 | REGISTER_TRACE(pOp->p2, pOut); |
| 82520 | break; |
| 82521 | } |
| 82522 | |
| @@ -82900,11 +83082,11 @@ | |
| 82900 | x.nKey = pIn2->n; |
| 82901 | x.pKey = pIn2->z; |
| 82902 | x.aMem = aMem + pOp->p3; |
| 82903 | x.nMem = (u16)pOp->p4.i; |
| 82904 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, |
| 82905 | (pOp->p5 & OPFLAG_APPEND)!=0, |
| 82906 | ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 82907 | ); |
| 82908 | assert( pC->deferredMoveto==0 ); |
| 82909 | pC->cacheStatus = CACHE_STALE; |
| 82910 | } |
| @@ -83022,11 +83204,10 @@ | |
| 83022 | pTabCur->aAltMap = pOp->p4.ai; |
| 83023 | pTabCur->pAltCursor = pC; |
| 83024 | }else{ |
| 83025 | pOut = out2Prerelease(p, pOp); |
| 83026 | pOut->u.i = rowid; |
| 83027 | pOut->flags = MEM_Int; |
| 83028 | } |
| 83029 | }else{ |
| 83030 | assert( pOp->opcode==OP_IdxRowid ); |
| 83031 | sqlite3VdbeMemSetNull(&aMem[pOp->p2]); |
| 83032 | } |
| @@ -83664,11 +83845,11 @@ | |
| 83664 | assert( (int)(pOp - aOp)==pFrame->pc ); |
| 83665 | } |
| 83666 | |
| 83667 | p->nFrame++; |
| 83668 | pFrame->pParent = p->pFrame; |
| 83669 | pFrame->lastRowid = lastRowid; |
| 83670 | pFrame->nChange = p->nChange; |
| 83671 | pFrame->nDbChange = p->db->nChange; |
| 83672 | assert( pFrame->pAuxData==0 ); |
| 83673 | pFrame->pAuxData = p->pAuxData; |
| 83674 | p->pAuxData = 0; |
| @@ -84605,11 +84786,11 @@ | |
| 84605 | rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); |
| 84606 | db->vtabOnConflict = vtabOnConflict; |
| 84607 | sqlite3VtabImportErrmsg(p, pVtab); |
| 84608 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 84609 | assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); |
| 84610 | db->lastRowid = lastRowid = rowid; |
| 84611 | } |
| 84612 | if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 84613 | if( pOp->p5==OE_Ignore ){ |
| 84614 | rc = SQLITE_OK; |
| 84615 | }else{ |
| @@ -84841,11 +85022,10 @@ | |
| 84841 | |
| 84842 | /* This is the only way out of this procedure. We have to |
| 84843 | ** release the mutexes on btrees that were acquired at the |
| 84844 | ** top. */ |
| 84845 | vdbe_return: |
| 84846 | db->lastRowid = lastRowid; |
| 84847 | testcase( nVmStep>0 ); |
| 84848 | p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; |
| 84849 | sqlite3VdbeLeave(p); |
| 84850 | assert( rc!=SQLITE_OK || nExtraDelete==0 |
| 84851 | || sqlite3_strlike("DELETE%",p->zSql,0)!=0 |
| @@ -84905,14 +85085,13 @@ | |
| 84905 | /* |
| 84906 | ** Valid sqlite3_blob* handles point to Incrblob structures. |
| 84907 | */ |
| 84908 | typedef struct Incrblob Incrblob; |
| 84909 | struct Incrblob { |
| 84910 | int flags; /* Copy of "flags" passed to sqlite3_blob_open() */ |
| 84911 | int nByte; /* Size of open blob, in bytes */ |
| 84912 | int iOffset; /* Byte offset of blob in cursor data */ |
| 84913 | int iCol; /* Table column this handle is open on */ |
| 84914 | BtCursor *pCsr; /* Cursor pointing at blob row */ |
| 84915 | sqlite3_stmt *pStmt; /* Statement holding cursor open */ |
| 84916 | sqlite3 *db; /* The associated database */ |
| 84917 | char *zDb; /* Database name */ |
| 84918 | Table *pTab; /* Table object */ |
| @@ -84939,21 +85118,31 @@ | |
| 84939 | static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr){ |
| 84940 | int rc; /* Error code */ |
| 84941 | char *zErr = 0; /* Error message */ |
| 84942 | Vdbe *v = (Vdbe *)p->pStmt; |
| 84943 | |
| 84944 | /* Set the value of the SQL statements only variable to integer iRow. |
| 84945 | ** This is done directly instead of using sqlite3_bind_int64() to avoid |
| 84946 | ** triggering asserts related to mutexes. |
| 84947 | */ |
| 84948 | assert( v->aVar[0].flags&MEM_Int ); |
| 84949 | v->aVar[0].u.i = iRow; |
| 84950 | |
| 84951 | rc = sqlite3_step(p->pStmt); |
| 84952 | if( rc==SQLITE_ROW ){ |
| 84953 | VdbeCursor *pC = v->apCsr[0]; |
| 84954 | u32 type = pC->aType[p->iCol]; |
| 84955 | if( type<12 ){ |
| 84956 | zErr = sqlite3MPrintf(p->db, "cannot open value of type %s", |
| 84957 | type==0?"null": type==7?"real": "integer" |
| 84958 | ); |
| 84959 | rc = SQLITE_ERROR; |
| @@ -84994,11 +85183,11 @@ | |
| 84994 | sqlite3* db, /* The database connection */ |
| 84995 | const char *zDb, /* The attached database containing the blob */ |
| 84996 | const char *zTable, /* The table containing the blob */ |
| 84997 | const char *zColumn, /* The column containing the blob */ |
| 84998 | sqlite_int64 iRow, /* The row containing the glob */ |
| 84999 | int flags, /* True -> read/write access, false -> read-only */ |
| 85000 | sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */ |
| 85001 | ){ |
| 85002 | int nAttempt = 0; |
| 85003 | int iCol; /* Index of zColumn in row-record */ |
| 85004 | int rc = SQLITE_OK; |
| @@ -85016,11 +85205,11 @@ | |
| 85016 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 85017 | if( !sqlite3SafetyCheckOk(db) || zTable==0 ){ |
| 85018 | return SQLITE_MISUSE_BKPT; |
| 85019 | } |
| 85020 | #endif |
| 85021 | flags = !!flags; /* flags = (flags ? 1 : 0); */ |
| 85022 | |
| 85023 | sqlite3_mutex_enter(db->mutex); |
| 85024 | |
| 85025 | pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob)); |
| 85026 | if( !pBlob ) goto blob_open_out; |
| @@ -85076,13 +85265,12 @@ | |
| 85076 | goto blob_open_out; |
| 85077 | } |
| 85078 | |
| 85079 | /* If the value is being opened for writing, check that the |
| 85080 | ** column is not indexed, and that it is not part of a foreign key. |
| 85081 | ** It is against the rules to open a column to which either of these |
| 85082 | ** descriptions applies for writing. */ |
| 85083 | if( flags ){ |
| 85084 | const char *zFault = 0; |
| 85085 | Index *pIdx; |
| 85086 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 85087 | if( db->flags&SQLITE_ForeignKeys ){ |
| 85088 | /* Check that the column is not part of an FK child key definition. It |
| @@ -85139,22 +85327,21 @@ | |
| 85139 | */ |
| 85140 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 85141 | static const VdbeOpList openBlob[] = { |
| 85142 | {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */ |
| 85143 | {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */ |
| 85144 | {OP_Variable, 1, 1, 0}, /* 2: Move ?1 into reg[1] */ |
| 85145 | {OP_NotExists, 0, 7, 1}, /* 3: Seek the cursor */ |
| 85146 | {OP_Column, 0, 0, 1}, /* 4 */ |
| 85147 | {OP_ResultRow, 1, 0, 0}, /* 5 */ |
| 85148 | {OP_Goto, 0, 2, 0}, /* 6 */ |
| 85149 | {OP_Halt, 0, 0, 0}, /* 7 */ |
| 85150 | }; |
| 85151 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 85152 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 85153 | VdbeOp *aOp; |
| 85154 | |
| 85155 | sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags, |
| 85156 | pTab->pSchema->schema_cookie, |
| 85157 | pTab->pSchema->iGeneration); |
| 85158 | sqlite3VdbeChangeP5(v, 1); |
| 85159 | aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); |
| 85160 | |
| @@ -85167,19 +85354,19 @@ | |
| 85167 | #ifdef SQLITE_OMIT_SHARED_CACHE |
| 85168 | aOp[0].opcode = OP_Noop; |
| 85169 | #else |
| 85170 | aOp[0].p1 = iDb; |
| 85171 | aOp[0].p2 = pTab->tnum; |
| 85172 | aOp[0].p3 = flags; |
| 85173 | sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); |
| 85174 | } |
| 85175 | if( db->mallocFailed==0 ){ |
| 85176 | #endif |
| 85177 | |
| 85178 | /* Remove either the OP_OpenWrite or OpenRead. Set the P2 |
| 85179 | ** parameter of the other to pTab->tnum. */ |
| 85180 | if( flags ) aOp[1].opcode = OP_OpenWrite; |
| 85181 | aOp[1].p2 = pTab->tnum; |
| 85182 | aOp[1].p3 = iDb; |
| 85183 | |
| 85184 | /* Configure the number of columns. Configure the cursor to |
| 85185 | ** think that the table has one more column than it really |
| @@ -85188,27 +85375,25 @@ | |
| 85188 | ** we can invoke OP_Column to fill in the vdbe cursors type |
| 85189 | ** and offset cache without causing any IO. |
| 85190 | */ |
| 85191 | aOp[1].p4type = P4_INT32; |
| 85192 | aOp[1].p4.i = pTab->nCol+1; |
| 85193 | aOp[4].p2 = pTab->nCol; |
| 85194 | |
| 85195 | pParse->nVar = 1; |
| 85196 | pParse->nMem = 1; |
| 85197 | pParse->nTab = 1; |
| 85198 | sqlite3VdbeMakeReady(v, pParse); |
| 85199 | } |
| 85200 | } |
| 85201 | |
| 85202 | pBlob->flags = flags; |
| 85203 | pBlob->iCol = iCol; |
| 85204 | pBlob->db = db; |
| 85205 | sqlite3BtreeLeaveAll(db); |
| 85206 | if( db->mallocFailed ){ |
| 85207 | goto blob_open_out; |
| 85208 | } |
| 85209 | sqlite3_bind_int64(pBlob->pStmt, 1, iRow); |
| 85210 | rc = blobSeekToRow(pBlob, iRow, &zErr); |
| 85211 | } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA ); |
| 85212 | |
| 85213 | blob_open_out: |
| 85214 | if( rc==SQLITE_OK && db->mallocFailed==0 ){ |
| @@ -88741,12 +88926,10 @@ | |
| 88741 | ** This file contains routines used for walking the parser tree and |
| 88742 | ** resolve all identifiers by associating them with a particular |
| 88743 | ** table and column. |
| 88744 | */ |
| 88745 | /* #include "sqliteInt.h" */ |
| 88746 | /* #include <stdlib.h> */ |
| 88747 | /* #include <string.h> */ |
| 88748 | |
| 88749 | /* |
| 88750 | ** Walk the expression tree pExpr and increase the aggregate function |
| 88751 | ** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node. |
| 88752 | ** This needs to occur when copying a TK_AGG_FUNCTION node from an |
| @@ -91237,21 +91420,27 @@ | |
| 91237 | int doAdd = 0; |
| 91238 | if( z[0]=='?' ){ |
| 91239 | /* Wildcard of the form "?nnn". Convert "nnn" to an integer and |
| 91240 | ** use it as the variable number */ |
| 91241 | i64 i; |
| 91242 | int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8); |
| 91243 | x = (ynVar)i; |
| 91244 | testcase( i==0 ); |
| 91245 | testcase( i==1 ); |
| 91246 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 ); |
| 91247 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ); |
| 91248 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 91249 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 91250 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 91251 | return; |
| 91252 | } |
| 91253 | if( x>pParse->nVar ){ |
| 91254 | pParse->nVar = (int)x; |
| 91255 | doAdd = 1; |
| 91256 | }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){ |
| 91257 | doAdd = 1; |
| @@ -91682,37 +91871,45 @@ | |
| 91682 | pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); |
| 91683 | pNewItem->idx = pOldItem->idx; |
| 91684 | } |
| 91685 | return pNew; |
| 91686 | } |
| 91687 | SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){ |
| 91688 | Select *pNew, *pPrior; |
| 91689 | assert( db!=0 ); |
| 91690 | if( p==0 ) return 0; |
| 91691 | pNew = sqlite3DbMallocRawNN(db, sizeof(*p) ); |
| 91692 | if( pNew==0 ) return 0; |
| 91693 | pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags); |
| 91694 | pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags); |
| 91695 | pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags); |
| 91696 | pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags); |
| 91697 | pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags); |
| 91698 | pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags); |
| 91699 | pNew->op = p->op; |
| 91700 | pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags); |
| 91701 | if( pPrior ) pPrior->pNext = pNew; |
| 91702 | pNew->pNext = 0; |
| 91703 | pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags); |
| 91704 | pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags); |
| 91705 | pNew->iLimit = 0; |
| 91706 | pNew->iOffset = 0; |
| 91707 | pNew->selFlags = p->selFlags & ~SF_UsesEphemeral; |
| 91708 | pNew->addrOpenEphm[0] = -1; |
| 91709 | pNew->addrOpenEphm[1] = -1; |
| 91710 | pNew->nSelectRow = p->nSelectRow; |
| 91711 | pNew->pWith = withDup(db, p->pWith); |
| 91712 | sqlite3SelectSetName(pNew, p->zSelName); |
| 91713 | return pNew; |
| 91714 | } |
| 91715 | #else |
| 91716 | SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){ |
| 91717 | assert( p==0 ); |
| 91718 | return 0; |
| @@ -91773,11 +91970,11 @@ | |
| 91773 | ** |
| 91774 | ** (a,b,c) = (expr1,expr2,expr3) |
| 91775 | ** Or: (a,b,c) = (SELECT x,y,z FROM ....) |
| 91776 | ** |
| 91777 | ** For each term of the vector assignment, append new entries to the |
| 91778 | ** expression list pList. In the case of a subquery on the LHS, append |
| 91779 | ** TK_SELECT_COLUMN expressions. |
| 91780 | */ |
| 91781 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector( |
| 91782 | Parse *pParse, /* Parsing context */ |
| 91783 | ExprList *pList, /* List to which to append. Might be NULL */ |
| @@ -93882,10 +94079,15 @@ | |
| 93882 | int i; /* Loop counter */ |
| 93883 | sqlite3 *db = pParse->db; /* The database connection */ |
| 93884 | u8 enc = ENC(db); /* The text encoding used by this database */ |
| 93885 | CollSeq *pColl = 0; /* A collating sequence */ |
| 93886 | |
| 93887 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 93888 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 93889 | pFarg = 0; |
| 93890 | }else{ |
| 93891 | pFarg = pExpr->x.pList; |
| @@ -93929,10 +94131,26 @@ | |
| 93929 | */ |
| 93930 | if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){ |
| 93931 | assert( nFarg>=1 ); |
| 93932 | return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target); |
| 93933 | } |
| 93934 | |
| 93935 | for(i=0; i<nFarg; i++){ |
| 93936 | if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){ |
| 93937 | testcase( i==31 ); |
| 93938 | constMask |= MASKBIT32(i); |
| @@ -94246,28 +94464,44 @@ | |
| 94246 | return inReg; |
| 94247 | } |
| 94248 | |
| 94249 | /* |
| 94250 | ** Factor out the code of the given expression to initialization time. |
| 94251 | */ |
| 94252 | SQLITE_PRIVATE void sqlite3ExprCodeAtInit( |
| 94253 | Parse *pParse, /* Parsing context */ |
| 94254 | Expr *pExpr, /* The expression to code when the VDBE initializes */ |
| 94255 | int regDest, /* Store the value in this register */ |
| 94256 | u8 reusable /* True if this expression is reusable */ |
| 94257 | ){ |
| 94258 | ExprList *p; |
| 94259 | assert( ConstFactorOk(pParse) ); |
| 94260 | p = pParse->pConstExpr; |
| 94261 | pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 94262 | p = sqlite3ExprListAppend(pParse, p, pExpr); |
| 94263 | if( p ){ |
| 94264 | struct ExprList_item *pItem = &p->a[p->nExpr-1]; |
| 94265 | pItem->u.iConstExprReg = regDest; |
| 94266 | pItem->reusable = reusable; |
| 94267 | } |
| 94268 | pParse->pConstExpr = p; |
| 94269 | } |
| 94270 | |
| 94271 | /* |
| 94272 | ** Generate code to evaluate an expression and store the results |
| 94273 | ** into a register. Return the register number where the results |
| @@ -94286,23 +94520,12 @@ | |
| 94286 | pExpr = sqlite3ExprSkipCollate(pExpr); |
| 94287 | if( ConstFactorOk(pParse) |
| 94288 | && pExpr->op!=TK_REGISTER |
| 94289 | && sqlite3ExprIsConstantNotJoin(pExpr) |
| 94290 | ){ |
| 94291 | ExprList *p = pParse->pConstExpr; |
| 94292 | int i; |
| 94293 | *pReg = 0; |
| 94294 | if( p ){ |
| 94295 | struct ExprList_item *pItem; |
| 94296 | for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){ |
| 94297 | if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){ |
| 94298 | return pItem->u.iConstExprReg; |
| 94299 | } |
| 94300 | } |
| 94301 | } |
| 94302 | r2 = ++pParse->nMem; |
| 94303 | sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1); |
| 94304 | }else{ |
| 94305 | int r1 = sqlite3GetTempReg(pParse); |
| 94306 | r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); |
| 94307 | if( r2==r1 ){ |
| 94308 | *pReg = r1; |
| @@ -94352,11 +94575,11 @@ | |
| 94352 | ** in register target. If the expression is constant, then this routine |
| 94353 | ** might choose to code the expression at initialization time. |
| 94354 | */ |
| 94355 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){ |
| 94356 | if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){ |
| 94357 | sqlite3ExprCodeAtInit(pParse, pExpr, target, 0); |
| 94358 | }else{ |
| 94359 | sqlite3ExprCode(pParse, pExpr, target); |
| 94360 | } |
| 94361 | } |
| 94362 | |
| @@ -94424,11 +94647,11 @@ | |
| 94424 | n--; |
| 94425 | }else{ |
| 94426 | sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i); |
| 94427 | } |
| 94428 | }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ |
| 94429 | sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0); |
| 94430 | }else{ |
| 94431 | int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 94432 | if( inReg!=target+i ){ |
| 94433 | VdbeOp *pOp; |
| 94434 | if( copyOp==OP_Copy |
| @@ -96968,10 +97191,16 @@ | |
| 96968 | ** used to query statistical information that has been gathered into |
| 96969 | ** the Stat4Accum object by prior calls to stat_push(). The P parameter |
| 96970 | ** has type BLOB but it is really just a pointer to the Stat4Accum object. |
| 96971 | ** The content to returned is determined by the parameter J |
| 96972 | ** which is one of the STAT_GET_xxxx values defined above. |
| 96973 | ** |
| 96974 | ** If neither STAT3 nor STAT4 are enabled, then J is always |
| 96975 | ** STAT_GET_STAT1 and is hence omitted and this routine becomes |
| 96976 | ** a one-parameter function, stat_get(P), that always returns the |
| 96977 | ** stat1 table entry information. |
| @@ -97787,11 +98016,11 @@ | |
| 97787 | sumEq += aSample[i].anEq[iCol]; |
| 97788 | nSum100 += 100; |
| 97789 | } |
| 97790 | } |
| 97791 | |
| 97792 | if( nDist100>nSum100 ){ |
| 97793 | avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100); |
| 97794 | } |
| 97795 | if( avgEq==0 ) avgEq = 1; |
| 97796 | pIdx->aAvgEq[iCol] = avgEq; |
| 97797 | } |
| @@ -98201,10 +98430,11 @@ | |
| 98201 | assert( pVfs ); |
| 98202 | flags |= SQLITE_OPEN_MAIN_DB; |
| 98203 | rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags); |
| 98204 | sqlite3_free( zPath ); |
| 98205 | db->nDb++; |
| 98206 | if( rc==SQLITE_CONSTRAINT ){ |
| 98207 | rc = SQLITE_ERROR; |
| 98208 | zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
| 98209 | }else if( rc==SQLITE_OK ){ |
| 98210 | Pager *pPager; |
| @@ -104365,16 +104595,12 @@ | |
| 104365 | } |
| 104366 | }else |
| 104367 | #endif |
| 104368 | { |
| 104369 | int count = (pParse->nested==0); /* True to count changes */ |
| 104370 | int iIdxNoSeek = -1; |
| 104371 | if( bComplex==0 && aiCurOnePass[1]!=iDataCur ){ |
| 104372 | iIdxNoSeek = aiCurOnePass[1]; |
| 104373 | } |
| 104374 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 104375 | iKey, nKey, count, OE_Default, eOnePass, iIdxNoSeek); |
| 104376 | } |
| 104377 | |
| 104378 | /* End of the loop over all rowids/primary-keys. */ |
| 104379 | if( eOnePass!=ONEPASS_OFF ){ |
| 104380 | sqlite3VdbeResolveLabel(v, addrBypass); |
| @@ -104450,19 +104676,21 @@ | |
| 104450 | ** then this function must seek iDataCur to the entry identified by iPk |
| 104451 | ** and nPk before reading from it. |
| 104452 | ** |
| 104453 | ** If eMode is ONEPASS_MULTI, then this call is being made as part |
| 104454 | ** of a ONEPASS delete that affects multiple rows. In this case, if |
| 104455 | ** iIdxNoSeek is a valid cursor number (>=0), then its position should |
| 104456 | ** be preserved following the delete operation. Or, if iIdxNoSeek is not |
| 104457 | ** a valid cursor number, the position of iDataCur should be preserved |
| 104458 | ** instead. |
| 104459 | ** |
| 104460 | ** iIdxNoSeek: |
| 104461 | ** If iIdxNoSeek is a valid cursor number (>=0), then it identifies an |
| 104462 | ** index cursor (from within array of cursors starting at iIdxCur) that |
| 104463 | ** already points to the index entry to be deleted. |
| 104464 | */ |
| 104465 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 104466 | Parse *pParse, /* Parsing context */ |
| 104467 | Table *pTab, /* Table containing the row to be deleted */ |
| 104468 | Trigger *pTrigger, /* List of triggers to (potentially) fire */ |
| @@ -104529,17 +104757,22 @@ | |
| 104529 | TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel |
| 104530 | ); |
| 104531 | |
| 104532 | /* If any BEFORE triggers were coded, then seek the cursor to the |
| 104533 | ** row to be deleted again. It may be that the BEFORE triggers moved |
| 104534 | ** the cursor or of already deleted the row that the cursor was |
| 104535 | ** pointing to. |
| 104536 | */ |
| 104537 | if( addrStart<sqlite3VdbeCurrentAddr(v) ){ |
| 104538 | sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 104539 | VdbeCoverageIf(v, opSeek==OP_NotExists); |
| 104540 | VdbeCoverageIf(v, opSeek==OP_NotFound); |
| 104541 | } |
| 104542 | |
| 104543 | /* Do FK processing. This call checks that any FK constraints that |
| 104544 | ** refer to this table (i.e. constraints attached to other tables) |
| 104545 | ** are not violated by deleting this row. */ |
| @@ -104558,15 +104791,17 @@ | |
| 104558 | */ |
| 104559 | if( pTab->pSelect==0 ){ |
| 104560 | u8 p5 = 0; |
| 104561 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); |
| 104562 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 104563 | sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE); |
| 104564 | if( eMode!=ONEPASS_OFF ){ |
| 104565 | sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE); |
| 104566 | } |
| 104567 | if( iIdxNoSeek>=0 ){ |
| 104568 | sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); |
| 104569 | } |
| 104570 | if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION; |
| 104571 | sqlite3VdbeChangeP5(v, p5); |
| 104572 | } |
| @@ -104716,10 +104951,14 @@ | |
| 104716 | ** opcode if it is present */ |
| 104717 | sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity); |
| 104718 | } |
| 104719 | if( regOut ){ |
| 104720 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 104721 | } |
| 104722 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 104723 | return regBase; |
| 104724 | } |
| 104725 | |
| @@ -106512,10 +106751,13 @@ | |
| 106512 | DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 106513 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 106514 | FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106515 | FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106516 | FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106517 | FUNCTION(ltrim, 1, 1, 0, trimFunc ), |
| 106518 | FUNCTION(ltrim, 2, 1, 0, trimFunc ), |
| 106519 | FUNCTION(rtrim, 1, 2, 0, trimFunc ), |
| 106520 | FUNCTION(rtrim, 2, 2, 0, trimFunc ), |
| 106521 | FUNCTION(trim, 1, 3, 0, trimFunc ), |
| @@ -109667,11 +109909,11 @@ | |
| 109667 | if( db->flags&SQLITE_RecTriggers ){ |
| 109668 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 109669 | } |
| 109670 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 109671 | regR, nPkField, 0, OE_Replace, |
| 109672 | (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), -1); |
| 109673 | seenReplace = 1; |
| 109674 | break; |
| 109675 | } |
| 109676 | } |
| 109677 | sqlite3VdbeResolveLabel(v, addrUniqueOk); |
| @@ -109683,10 +109925,29 @@ | |
| 109683 | } |
| 109684 | |
| 109685 | *pbMayReplace = seenReplace; |
| 109686 | VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace)); |
| 109687 | } |
| 109688 | |
| 109689 | /* |
| 109690 | ** This routine generates code to finish the INSERT or UPDATE operation |
| 109691 | ** that was started by a prior call to sqlite3GenerateConstraintChecks. |
| 109692 | ** A consecutive range of registers starting at regNewData contains the |
| @@ -109700,11 +109961,11 @@ | |
| 109700 | Table *pTab, /* the table into which we are inserting */ |
| 109701 | int iDataCur, /* Cursor of the canonical data source */ |
| 109702 | int iIdxCur, /* First index cursor */ |
| 109703 | int regNewData, /* Range of content */ |
| 109704 | int *aRegIdx, /* Register used by each index. 0 for unused indices */ |
| 109705 | int isUpdate, /* True for UPDATE, False for INSERT */ |
| 109706 | int appendBias, /* True if this is likely to be an append */ |
| 109707 | int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */ |
| 109708 | ){ |
| 109709 | Vdbe *v; /* Prepared statements under construction */ |
| 109710 | Index *pIdx; /* An index being inserted or updated */ |
| @@ -109711,10 +109972,15 @@ | |
| 109711 | u8 pik_flags; /* flag values passed to the btree insert */ |
| 109712 | int regData; /* Content registers (after the rowid) */ |
| 109713 | int regRec; /* Register holding assembled record for the table */ |
| 109714 | int i; /* Loop counter */ |
| 109715 | u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */ |
| 109716 | |
| 109717 | v = sqlite3GetVdbe(pParse); |
| 109718 | assert( v!=0 ); |
| 109719 | assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 109720 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| @@ -109722,34 +109988,43 @@ | |
| 109722 | bAffinityDone = 1; |
| 109723 | if( pIdx->pPartIdxWhere ){ |
| 109724 | sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2); |
| 109725 | VdbeCoverage(v); |
| 109726 | } |
| 109727 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i], |
| 109728 | aRegIdx[i]+1, |
| 109729 | pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn); |
| 109730 | pik_flags = 0; |
| 109731 | if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT; |
| 109732 | if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){ |
| 109733 | assert( pParse->nested==0 ); |
| 109734 | pik_flags |= OPFLAG_NCHANGE; |
| 109735 | } |
| 109736 | sqlite3VdbeChangeP5(v, pik_flags); |
| 109737 | } |
| 109738 | if( !HasRowid(pTab) ) return; |
| 109739 | regData = regNewData + 1; |
| 109740 | regRec = sqlite3GetTempReg(pParse); |
| 109741 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec); |
| 109742 | if( !bAffinityDone ){ |
| 109743 | sqlite3TableAffinity(v, pTab, 0); |
| 109744 | sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol); |
| 109745 | } |
| 109746 | if( pParse->nested ){ |
| 109747 | pik_flags = 0; |
| 109748 | }else{ |
| 109749 | pik_flags = OPFLAG_NCHANGE; |
| 109750 | pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID); |
| 109751 | } |
| 109752 | if( appendBias ){ |
| 109753 | pik_flags |= OPFLAG_APPEND; |
| 109754 | } |
| 109755 | if( useSeekResult ){ |
| @@ -110154,11 +110429,11 @@ | |
| 110154 | addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); |
| 110155 | }else{ |
| 110156 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 110157 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 110158 | } |
| 110159 | sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); |
| 110160 | if( db->flags & SQLITE_Vacuum ){ |
| 110161 | sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); |
| 110162 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID| |
| 110163 | OPFLAG_APPEND|OPFLAG_USESEEKRESULT; |
| 110164 | }else{ |
| @@ -110186,11 +110461,11 @@ | |
| 110186 | sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest); |
| 110187 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 110188 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 110189 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 110190 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 110191 | sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); |
| 110192 | if( db->flags & SQLITE_Vacuum ){ |
| 110193 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 110194 | ** that the destination table is empty. If all indexed columns use |
| 110195 | ** collation sequence BINARY, then it can also be assumed that the |
| 110196 | ** index will be populated by inserting keys in strictly sorted |
| @@ -110971,11 +111246,10 @@ | |
| 110971 | #endif /* SQLITE3EXT_H */ |
| 110972 | |
| 110973 | /************** End of sqlite3ext.h ******************************************/ |
| 110974 | /************** Continuing where we left off in loadext.c ********************/ |
| 110975 | /* #include "sqliteInt.h" */ |
| 110976 | /* #include <string.h> */ |
| 110977 | |
| 110978 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 110979 | /* |
| 110980 | ** Some API routines are omitted when various features are |
| 110981 | ** excluded from a build of SQLite. Substitute a NULL pointer |
| @@ -112635,11 +112909,11 @@ | |
| 112635 | |
| 112636 | /* |
| 112637 | ** Locate a pragma in the aPragmaName[] array. |
| 112638 | */ |
| 112639 | static const PragmaName *pragmaLocate(const char *zName){ |
| 112640 | int upr, lwr, mid, rc; |
| 112641 | lwr = 0; |
| 112642 | upr = ArraySize(aPragmaName)-1; |
| 112643 | while( lwr<=upr ){ |
| 112644 | mid = (lwr+upr)/2; |
| 112645 | rc = sqlite3_stricmp(zName, aPragmaName[mid].zName); |
| @@ -116149,10 +116423,11 @@ | |
| 116149 | v = pParse->pVdbe; |
| 116150 | r1 = sqlite3GetTempReg(pParse); |
| 116151 | sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v); |
| 116152 | sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1); |
| 116153 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N); |
| 116154 | sqlite3ReleaseTempReg(pParse, r1); |
| 116155 | } |
| 116156 | |
| 116157 | /* |
| 116158 | ** This routine generates the code for the inside of the inner loop |
| @@ -119677,11 +119952,19 @@ | |
| 119677 | assert( pTab->nTabRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 )); |
| 119678 | |
| 119679 | pCte->zCteErr = "circular reference: %s"; |
| 119680 | pSavedWith = pParse->pWith; |
| 119681 | pParse->pWith = pWith; |
| 119682 | sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel); |
| 119683 | pParse->pWith = pWith; |
| 119684 | |
| 119685 | for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); |
| 119686 | pEList = pLeft->pEList; |
| 119687 | if( pCte->pCols ){ |
| @@ -119721,14 +120004,16 @@ | |
| 119721 | ** sqlite3SelectExpand() when walking a SELECT tree to resolve table |
| 119722 | ** names and other FROM clause elements. |
| 119723 | */ |
| 119724 | static void selectPopWith(Walker *pWalker, Select *p){ |
| 119725 | Parse *pParse = pWalker->pParse; |
| 119726 | With *pWith = findRightmost(p)->pWith; |
| 119727 | if( pWith!=0 ){ |
| 119728 | assert( pParse->pWith==pWith ); |
| 119729 | pParse->pWith = pWith->pOuter; |
| 119730 | } |
| 119731 | } |
| 119732 | #else |
| 119733 | #define selectPopWith 0 |
| 119734 | #endif |
| @@ -119774,12 +120059,12 @@ | |
| 119774 | if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){ |
| 119775 | return WRC_Prune; |
| 119776 | } |
| 119777 | pTabList = p->pSrc; |
| 119778 | pEList = p->pEList; |
| 119779 | if( pWalker->xSelectCallback2==selectPopWith ){ |
| 119780 | sqlite3WithPush(pParse, findRightmost(p)->pWith, 0); |
| 119781 | } |
| 119782 | |
| 119783 | /* Make sure cursor numbers have been assigned to all entries in |
| 119784 | ** the FROM clause of the SELECT statement. |
| 119785 | */ |
| @@ -120062,13 +120347,11 @@ | |
| 120062 | if( pParse->hasCompound ){ |
| 120063 | w.xSelectCallback = convertCompoundSelectToSubquery; |
| 120064 | sqlite3WalkSelect(&w, pSelect); |
| 120065 | } |
| 120066 | w.xSelectCallback = selectExpander; |
| 120067 | if( (pSelect->selFlags & SF_MultiValue)==0 ){ |
| 120068 | w.xSelectCallback2 = selectPopWith; |
| 120069 | } |
| 120070 | sqlite3WalkSelect(&w, pSelect); |
| 120071 | } |
| 120072 | |
| 120073 | |
| 120074 | #ifndef SQLITE_OMIT_SUBQUERY |
| @@ -121143,11 +121426,11 @@ | |
| 121143 | /* This case runs if the aggregate has no GROUP BY clause. The |
| 121144 | ** processing is much simpler since there is only a single row |
| 121145 | ** of output. |
| 121146 | */ |
| 121147 | resetAccumulator(pParse, &sAggInfo); |
| 121148 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax,0,flag,0); |
| 121149 | if( pWInfo==0 ){ |
| 121150 | sqlite3ExprListDelete(db, pDel); |
| 121151 | goto select_end; |
| 121152 | } |
| 121153 | updateAccumulator(pParse, &sAggInfo); |
| @@ -121232,12 +121515,10 @@ | |
| 121232 | ** |
| 121233 | ** These routines are in a separate files so that they will not be linked |
| 121234 | ** if they are not used. |
| 121235 | */ |
| 121236 | /* #include "sqliteInt.h" */ |
| 121237 | /* #include <stdlib.h> */ |
| 121238 | /* #include <string.h> */ |
| 121239 | |
| 121240 | #ifndef SQLITE_OMIT_GET_TABLE |
| 121241 | |
| 121242 | /* |
| 121243 | ** This structure is used to pass data from sqlite3_get_table() through |
| @@ -122591,16 +122872,16 @@ | |
| 122591 | sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc, |
| 122592 | pCol->affinity, &pValue); |
| 122593 | if( pValue ){ |
| 122594 | sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 122595 | } |
| 122596 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 122597 | if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 122598 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 122599 | } |
| 122600 | #endif |
| 122601 | } |
| 122602 | } |
| 122603 | |
| 122604 | /* |
| 122605 | ** Process an UPDATE statement. |
| 122606 | ** |
| @@ -122625,11 +122906,11 @@ | |
| 122625 | int nIdx; /* Number of indices that need updating */ |
| 122626 | int iBaseCur; /* Base cursor number */ |
| 122627 | int iDataCur; /* Cursor for the canonical data btree */ |
| 122628 | int iIdxCur; /* Cursor for the first index */ |
| 122629 | sqlite3 *db; /* The database structure */ |
| 122630 | int *aRegIdx = 0; /* One register assigned to each index to be updated */ |
| 122631 | int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the |
| 122632 | ** an expression for the i-th column of the table. |
| 122633 | ** aXRef[i]==-1 if the i-th column is not changed. */ |
| 122634 | u8 *aToOpen; /* 1 for tables and indices to be opened */ |
| 122635 | u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */ |
| @@ -122637,14 +122918,15 @@ | |
| 122637 | u8 chngKey; /* Either chngPk or chngRowid */ |
| 122638 | Expr *pRowidExpr = 0; /* Expression defining the new record number */ |
| 122639 | AuthContext sContext; /* The authorization context */ |
| 122640 | NameContext sNC; /* The name-context to resolve expressions in */ |
| 122641 | int iDb; /* Database containing the table being updated */ |
| 122642 | int okOnePass; /* True for one-pass algorithm without the FIFO */ |
| 122643 | int hasFK; /* True if foreign key processing is required */ |
| 122644 | int labelBreak; /* Jump here to break out of UPDATE loop */ |
| 122645 | int labelContinue; /* Jump here to continue next step of UPDATE loop */ |
| 122646 | |
| 122647 | #ifndef SQLITE_OMIT_TRIGGER |
| 122648 | int isView; /* True when updating a view (INSTEAD OF trigger) */ |
| 122649 | Trigger *pTrigger; /* List of triggers on pTab, if required */ |
| 122650 | int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */ |
| @@ -122651,10 +122933,14 @@ | |
| 122651 | #endif |
| 122652 | int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */ |
| 122653 | int iEph = 0; /* Ephemeral table holding all primary key values */ |
| 122654 | int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */ |
| 122655 | int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */ |
| 122656 | |
| 122657 | /* Register Allocations */ |
| 122658 | int regRowCount = 0; /* A count of rows changed */ |
| 122659 | int regOldRowid = 0; /* The old rowid */ |
| 122660 | int regNewRowid = 0; /* The new rowid */ |
| @@ -122810,17 +123096,27 @@ | |
| 122810 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 122811 | i16 iIdxCol = pIdx->aiColumn[i]; |
| 122812 | if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){ |
| 122813 | reg = ++pParse->nMem; |
| 122814 | pParse->nMem += pIdx->nColumn; |
| 122815 | break; |
| 122816 | } |
| 122817 | } |
| 122818 | } |
| 122819 | if( reg==0 ) aToOpen[j+1] = 0; |
| 122820 | aRegIdx[j] = reg; |
| 122821 | } |
| 122822 | |
| 122823 | /* Begin generating code. */ |
| 122824 | v = sqlite3GetVdbe(pParse); |
| 122825 | if( v==0 ) goto update_cleanup; |
| 122826 | if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); |
| @@ -122869,107 +123165,127 @@ | |
| 122869 | pWhere, onError); |
| 122870 | goto update_cleanup; |
| 122871 | } |
| 122872 | #endif |
| 122873 | |
| 122874 | /* Begin the database scan |
| 122875 | */ |
| 122876 | if( HasRowid(pTab) ){ |
| 122877 | sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid); |
| 122878 | pWInfo = sqlite3WhereBegin( |
| 122879 | pParse, pTabList, pWhere, 0, 0, |
| 122880 | WHERE_ONEPASS_DESIRED | WHERE_SEEK_TABLE, iIdxCur |
| 122881 | ); |
| 122882 | if( pWInfo==0 ) goto update_cleanup; |
| 122883 | okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); |
| 122884 | |
| 122885 | /* Remember the rowid of every item to be updated. |
| 122886 | */ |
| 122887 | sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid); |
| 122888 | if( !okOnePass ){ |
| 122889 | sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid); |
| 122890 | } |
| 122891 | |
| 122892 | /* End the database scan loop. |
| 122893 | */ |
| 122894 | sqlite3WhereEnd(pWInfo); |
| 122895 | }else{ |
| 122896 | int iPk; /* First of nPk memory cells holding PRIMARY KEY value */ |
| 122897 | i16 nPk; /* Number of components of the PRIMARY KEY */ |
| 122898 | int addrOpen; /* Address of the OpenEphemeral instruction */ |
| 122899 | |
| 122900 | assert( pPk!=0 ); |
| 122901 | nPk = pPk->nKeyCol; |
| 122902 | iPk = pParse->nMem+1; |
| 122903 | pParse->nMem += nPk; |
| 122904 | regKey = ++pParse->nMem; |
| 122905 | iEph = pParse->nTab++; |
| 122906 | sqlite3VdbeAddOp2(v, OP_Null, 0, iPk); |
| 122907 | addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk); |
| 122908 | sqlite3VdbeSetP4KeyInfo(pParse, pPk); |
| 122909 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, |
| 122910 | WHERE_ONEPASS_DESIRED, iIdxCur); |
| 122911 | if( pWInfo==0 ) goto update_cleanup; |
| 122912 | okOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); |
| 122913 | for(i=0; i<nPk; i++){ |
| 122914 | assert( pPk->aiColumn[i]>=0 ); |
| 122915 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pPk->aiColumn[i], |
| 122916 | iPk+i); |
| 122917 | } |
| 122918 | if( okOnePass ){ |
| 122919 | sqlite3VdbeChangeToNoop(v, addrOpen); |
| 122920 | nKey = nPk; |
| 122921 | regKey = iPk; |
| 122922 | }else{ |
| 122923 | sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey, |
| 122924 | sqlite3IndexAffinityStr(db, pPk), nPk); |
| 122925 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk); |
| 122926 | } |
| 122927 | sqlite3WhereEnd(pWInfo); |
| 122928 | } |
| 122929 | |
| 122930 | /* Initialize the count of updated rows |
| 122931 | */ |
| 122932 | if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){ |
| 122933 | regRowCount = ++pParse->nMem; |
| 122934 | sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount); |
| 122935 | } |
| 122936 | |
| 122937 | labelBreak = sqlite3VdbeMakeLabel(v); |
| 122938 | if( !isView ){ |
| 122939 | /* |
| 122940 | ** Open every index that needs updating. Note that if any |
| 122941 | ** index could potentially invoke a REPLACE conflict resolution |
| 122942 | ** action, then we need to open all indices because we might need |
| 122943 | ** to be deleting some records. |
| 122944 | */ |
| 122945 | if( onError==OE_Replace ){ |
| 122946 | memset(aToOpen, 1, nIdx+1); |
| 122947 | }else{ |
| 122948 | for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){ |
| 122949 | if( pIdx->onError==OE_Replace ){ |
| 122950 | memset(aToOpen, 1, nIdx+1); |
| 122951 | break; |
| 122952 | } |
| 122953 | } |
| 122954 | } |
| 122955 | if( okOnePass ){ |
| 122956 | if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0; |
| 122957 | if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0; |
| 122958 | } |
| 122959 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, aToOpen, |
| 122960 | 0, 0); |
| 122961 | } |
| 122962 | |
| 122963 | /* Top of the update loop */ |
| 122964 | if( okOnePass ){ |
| 122965 | if( aToOpen[iDataCur-iBaseCur] && !isView ){ |
| 122966 | assert( pPk ); |
| 122967 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey); |
| 122968 | VdbeCoverageNeverTaken(v); |
| 122969 | } |
| 122970 | labelContinue = labelBreak; |
| 122971 | sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak); |
| 122972 | VdbeCoverageIf(v, pPk==0); |
| 122973 | VdbeCoverageIf(v, pPk!=0); |
| 122974 | }else if( pPk ){ |
| 122975 | labelContinue = sqlite3VdbeMakeLabel(v); |
| @@ -123090,11 +123406,10 @@ | |
| 123090 | } |
| 123091 | } |
| 123092 | |
| 123093 | if( !isView ){ |
| 123094 | int addr1 = 0; /* Address of jump instruction */ |
| 123095 | int bReplace = 0; /* True if REPLACE conflict resolution might happen */ |
| 123096 | |
| 123097 | /* Do constraint checks. */ |
| 123098 | assert( regOldRowid>0 ); |
| 123099 | sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur, |
| 123100 | regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace, |
| @@ -123126,18 +123441,22 @@ | |
| 123126 | ** is the column index supplied by the user. |
| 123127 | */ |
| 123128 | assert( regNew==regNewRowid+1 ); |
| 123129 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 123130 | sqlite3VdbeAddOp3(v, OP_Delete, iDataCur, |
| 123131 | OPFLAG_ISUPDATE | ((hasFK || chngKey || pPk!=0) ? 0 : OPFLAG_ISNOOP), |
| 123132 | regNewRowid |
| 123133 | ); |
| 123134 | if( !pParse->nested ){ |
| 123135 | sqlite3VdbeAppendP4(v, pTab, P4_TABLE); |
| 123136 | } |
| 123137 | #else |
| 123138 | if( hasFK || chngKey || pPk!=0 ){ |
| 123139 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0); |
| 123140 | } |
| 123141 | #endif |
| 123142 | if( bReplace || chngKey ){ |
| 123143 | sqlite3VdbeJumpHere(v, addr1); |
| @@ -123146,12 +123465,15 @@ | |
| 123146 | if( hasFK ){ |
| 123147 | sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey); |
| 123148 | } |
| 123149 | |
| 123150 | /* Insert the new index entries and the new record. */ |
| 123151 | sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur, |
| 123152 | regNewRowid, aRegIdx, 1, 0, 0); |
| 123153 | |
| 123154 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 123155 | ** handle rows (possibly in other tables) that refer via a foreign key |
| 123156 | ** to the row just updated. */ |
| 123157 | if( hasFK ){ |
| @@ -123169,12 +123491,15 @@ | |
| 123169 | TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue); |
| 123170 | |
| 123171 | /* Repeat the above with the next record to be updated, until |
| 123172 | ** all record selected by the WHERE clause have been updated. |
| 123173 | */ |
| 123174 | if( okOnePass ){ |
| 123175 | /* Nothing to do at end-of-loop for a single-pass */ |
| 123176 | }else if( pPk ){ |
| 123177 | sqlite3VdbeResolveLabel(v, labelContinue); |
| 123178 | sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v); |
| 123179 | }else{ |
| 123180 | sqlite3VdbeGoto(v, labelContinue); |
| @@ -127090,11 +127415,14 @@ | |
| 127090 | |
| 127091 | /* Seek the table cursor, if required */ |
| 127092 | if( omitTable ){ |
| 127093 | /* pIdx is a covering index. No need to access the main table. */ |
| 127094 | }else if( HasRowid(pIdx->pTable) ){ |
| 127095 | if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE)!=0 ){ |
| 127096 | iRowidReg = ++pParse->nMem; |
| 127097 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); |
| 127098 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 127099 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg); |
| 127100 | VdbeCoverage(v); |
| @@ -128454,10 +128782,11 @@ | |
| 128454 | int noCase = 0; /* uppercase equivalent to lowercase */ |
| 128455 | int op; /* Top-level operator. pExpr->op */ |
| 128456 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 128457 | sqlite3 *db = pParse->db; /* Database connection */ |
| 128458 | unsigned char eOp2; /* op2 value for LIKE/REGEXP/GLOB */ |
| 128459 | |
| 128460 | if( db->mallocFailed ){ |
| 128461 | return; |
| 128462 | } |
| 128463 | pTerm = &pWC->a[idxTerm]; |
| @@ -128483,10 +128812,14 @@ | |
| 128483 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 128484 | Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable); |
| 128485 | prereqAll |= x; |
| 128486 | extraRight = x-1; /* ON clause terms may not be used with an index |
| 128487 | ** on left table of a LEFT JOIN. Ticket #3015 */ |
| 128488 | } |
| 128489 | pTerm->prereqAll = prereqAll; |
| 128490 | pTerm->leftCursor = -1; |
| 128491 | pTerm->iParent = -1; |
| 128492 | pTerm->eOperator = 0; |
| @@ -128725,17 +129058,16 @@ | |
| 128725 | ** |
| 128726 | ** This is only required if at least one side of the comparison operation |
| 128727 | ** is not a sub-select. */ |
| 128728 | if( pWC->op==TK_AND |
| 128729 | && (pExpr->op==TK_EQ || pExpr->op==TK_IS) |
| 128730 | && sqlite3ExprIsVector(pExpr->pLeft) |
| 128731 | && ( (pExpr->pLeft->flags & EP_xIsSelect)==0 |
| 128732 | || (pExpr->pRight->flags & EP_xIsSelect)==0 |
| 128733 | )){ |
| 128734 | int nLeft = sqlite3ExprVectorSize(pExpr->pLeft); |
| 128735 | int i; |
| 128736 | assert( nLeft==sqlite3ExprVectorSize(pExpr->pRight) ); |
| 128737 | for(i=0; i<nLeft; i++){ |
| 128738 | int idxNew; |
| 128739 | Expr *pNew; |
| 128740 | Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i); |
| 128741 | Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i); |
| @@ -133934,11 +134266,12 @@ | |
| 133934 | x = sqlite3ColumnOfIndex(pIdx, x); |
| 133935 | if( x>=0 ){ |
| 133936 | pOp->p2 = x; |
| 133937 | pOp->p1 = pLevel->iIdxCur; |
| 133938 | } |
| 133939 | assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 ); |
| 133940 | }else if( pOp->opcode==OP_Rowid ){ |
| 133941 | pOp->p1 = pLevel->iIdxCur; |
| 133942 | pOp->opcode = OP_IdxRowid; |
| 133943 | } |
| 133944 | } |
| @@ -133998,10 +134331,23 @@ | |
| 133998 | ** Indicate that sqlite3ParserFree() will never be called with a null |
| 133999 | ** pointer. |
| 134000 | */ |
| 134001 | #define YYPARSEFREENEVERNULL 1 |
| 134002 | |
| 134003 | /* |
| 134004 | ** Alternative datatype for the argument to the malloc() routine passed |
| 134005 | ** into sqlite3ParserAlloc(). The default is size_t. |
| 134006 | */ |
| 134007 | #define YYMALLOCARGTYPE u64 |
| @@ -135446,10 +135792,35 @@ | |
| 135446 | */ |
| 135447 | #ifndef YYMALLOCARGTYPE |
| 135448 | # define YYMALLOCARGTYPE size_t |
| 135449 | #endif |
| 135450 | |
| 135451 | /* |
| 135452 | ** This function allocates a new parser. |
| 135453 | ** The only argument is a pointer to a function which works like |
| 135454 | ** malloc. |
| 135455 | ** |
| @@ -135461,32 +135832,15 @@ | |
| 135461 | ** to sqlite3Parser and sqlite3ParserFree. |
| 135462 | */ |
| 135463 | SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ |
| 135464 | yyParser *pParser; |
| 135465 | pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); |
| 135466 | if( pParser ){ |
| 135467 | #ifdef YYTRACKMAXSTACKDEPTH |
| 135468 | pParser->yyhwm = 0; |
| 135469 | #endif |
| 135470 | #if YYSTACKDEPTH<=0 |
| 135471 | pParser->yytos = NULL; |
| 135472 | pParser->yystack = NULL; |
| 135473 | pParser->yystksz = 0; |
| 135474 | if( yyGrowStack(pParser) ){ |
| 135475 | pParser->yystack = &pParser->yystk0; |
| 135476 | pParser->yystksz = 1; |
| 135477 | } |
| 135478 | #endif |
| 135479 | #ifndef YYNOERRORRECOVERY |
| 135480 | pParser->yyerrcnt = -1; |
| 135481 | #endif |
| 135482 | pParser->yytos = pParser->yystack; |
| 135483 | pParser->yystack[0].stateno = 0; |
| 135484 | pParser->yystack[0].major = 0; |
| 135485 | } |
| 135486 | return pParser; |
| 135487 | } |
| 135488 | |
| 135489 | /* The following function deletes the "minor type" or semantic value |
| 135490 | ** associated with a symbol. The symbol can be either a terminal |
| 135491 | ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is |
| 135492 | ** a pointer to the value to be deleted. The code used to do the |
| @@ -135608,10 +135962,22 @@ | |
| 135608 | } |
| 135609 | #endif |
| 135610 | yy_destructor(pParser, yytos->major, &yytos->minor); |
| 135611 | } |
| 135612 | |
| 135613 | /* |
| 135614 | ** Deallocate and destroy a parser. Destructors are called for |
| 135615 | ** all stack elements before shutting the parser down. |
| 135616 | ** |
| 135617 | ** If the YYPARSEFREENEVERNULL macro exists (for example because it |
| @@ -135620,20 +135986,17 @@ | |
| 135620 | */ |
| 135621 | SQLITE_PRIVATE void sqlite3ParserFree( |
| 135622 | void *p, /* The parser to be deleted */ |
| 135623 | void (*freeProc)(void*) /* Function used to reclaim memory */ |
| 135624 | ){ |
| 135625 | yyParser *pParser = (yyParser*)p; |
| 135626 | #ifndef YYPARSEFREENEVERNULL |
| 135627 | if( pParser==0 ) return; |
| 135628 | #endif |
| 135629 | while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); |
| 135630 | #if YYSTACKDEPTH<=0 |
| 135631 | if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); |
| 135632 | #endif |
| 135633 | (*freeProc)((void*)pParser); |
| 135634 | } |
| 135635 | |
| 135636 | /* |
| 135637 | ** Return the peak depth of the stack for a parser. |
| 135638 | */ |
| 135639 | #ifdef YYTRACKMAXSTACKDEPTH |
| @@ -138483,10 +138846,13 @@ | |
| 138483 | void *pEngine; /* The LEMON-generated LALR(1) parser */ |
| 138484 | int tokenType; /* type of the next token */ |
| 138485 | int lastTokenParsed = -1; /* type of the previous token */ |
| 138486 | sqlite3 *db = pParse->db; /* The database connection */ |
| 138487 | int mxSqlLen; /* Max length of an SQL string */ |
| 138488 | |
| 138489 | assert( zSql!=0 ); |
| 138490 | mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 138491 | if( db->nVdbeActive==0 ){ |
| 138492 | db->u1.isInterrupted = 0; |
| @@ -138494,15 +138860,20 @@ | |
| 138494 | pParse->rc = SQLITE_OK; |
| 138495 | pParse->zTail = zSql; |
| 138496 | i = 0; |
| 138497 | assert( pzErrMsg!=0 ); |
| 138498 | /* sqlite3ParserTrace(stdout, "parser: "); */ |
| 138499 | pEngine = sqlite3ParserAlloc(sqlite3Malloc); |
| 138500 | if( pEngine==0 ){ |
| 138501 | sqlite3OomFault(db); |
| 138502 | return SQLITE_NOMEM_BKPT; |
| 138503 | } |
| 138504 | assert( pParse->pNewTable==0 ); |
| 138505 | assert( pParse->pNewTrigger==0 ); |
| 138506 | assert( pParse->nVar==0 ); |
| 138507 | assert( pParse->pVList==0 ); |
| 138508 | while( 1 ){ |
| @@ -138550,11 +138921,15 @@ | |
| 138550 | sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK, |
| 138551 | sqlite3ParserStackPeak(pEngine) |
| 138552 | ); |
| 138553 | sqlite3_mutex_leave(sqlite3MallocMutex()); |
| 138554 | #endif /* YYDEBUG */ |
| 138555 | sqlite3ParserFree(pEngine, sqlite3_free); |
| 138556 | if( db->mallocFailed ){ |
| 138557 | pParse->rc = SQLITE_NOMEM_BKPT; |
| 138558 | } |
| 138559 | if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){ |
| 138560 | pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc)); |
| @@ -145675,13 +146050,13 @@ | |
| 145675 | p->nPendingData = 0; |
| 145676 | p->azColumn = (char **)&p[1]; |
| 145677 | p->pTokenizer = pTokenizer; |
| 145678 | p->nMaxPendingData = FTS3_MAX_PENDING_DATA; |
| 145679 | p->bHasDocsize = (isFts4 && bNoDocsize==0); |
| 145680 | p->bHasStat = isFts4; |
| 145681 | p->bFts4 = isFts4; |
| 145682 | p->bDescIdx = bDescIdx; |
| 145683 | p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */ |
| 145684 | p->zContentTbl = zContent; |
| 145685 | p->zLanguageid = zLanguageid; |
| 145686 | zContent = 0; |
| 145687 | zLanguageid = 0; |
| @@ -147734,11 +148109,11 @@ | |
| 147734 | sqlite3_stmt *pStmt = 0; |
| 147735 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 147736 | if( rc==SQLITE_OK ){ |
| 147737 | int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW); |
| 147738 | rc = sqlite3_finalize(pStmt); |
| 147739 | if( rc==SQLITE_OK ) p->bHasStat = bHasStat; |
| 147740 | } |
| 147741 | sqlite3_free(zSql); |
| 147742 | }else{ |
| 147743 | rc = SQLITE_NOMEM; |
| 147744 | } |
| @@ -162638,28 +163013,33 @@ | |
| 162638 | struct Rtree { |
| 162639 | sqlite3_vtab base; /* Base class. Must be first */ |
| 162640 | sqlite3 *db; /* Host database connection */ |
| 162641 | int iNodeSize; /* Size in bytes of each node in the node table */ |
| 162642 | u8 nDim; /* Number of dimensions */ |
| 162643 | u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */ |
| 162644 | u8 nBytesPerCell; /* Bytes consumed per cell */ |
| 162645 | int iDepth; /* Current depth of the r-tree structure */ |
| 162646 | char *zDb; /* Name of database containing r-tree table */ |
| 162647 | char *zName; /* Name of r-tree table */ |
| 162648 | int nBusy; /* Current number of users of this structure */ |
| 162649 | i64 nRowEst; /* Estimated number of rows in this table */ |
| 162650 | |
| 162651 | /* List of nodes removed during a CondenseTree operation. List is |
| 162652 | ** linked together via the pointer normally used for hash chains - |
| 162653 | ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree |
| 162654 | ** headed by the node (leaf nodes have RtreeNode.iNode==0). |
| 162655 | */ |
| 162656 | RtreeNode *pDeleted; |
| 162657 | int iReinsertHeight; /* Height of sub-trees Reinsert() has run on */ |
| 162658 | |
| 162659 | /* Statements to read/write/delete a record from xxx_node */ |
| 162660 | sqlite3_stmt *pReadNode; |
| 162661 | sqlite3_stmt *pWriteNode; |
| 162662 | sqlite3_stmt *pDeleteNode; |
| 162663 | |
| 162664 | /* Statements to read/write/delete a record from xxx_rowid */ |
| 162665 | sqlite3_stmt *pReadRowid; |
| @@ -162884,26 +163264,110 @@ | |
| 162884 | #endif |
| 162885 | #ifndef MIN |
| 162886 | # define MIN(x,y) ((x) > (y) ? (y) : (x)) |
| 162887 | #endif |
| 162888 | |
| 162889 | /* |
| 162890 | ** Functions to deserialize a 16 bit integer, 32 bit real number and |
| 162891 | ** 64 bit integer. The deserialized value is returned. |
| 162892 | */ |
| 162893 | static int readInt16(u8 *p){ |
| 162894 | return (p[0]<<8) + p[1]; |
| 162895 | } |
| 162896 | static void readCoord(u8 *p, RtreeCoord *pCoord){ |
| 162897 | pCoord->u = ( |
| 162898 | (((u32)p[0]) << 24) + |
| 162899 | (((u32)p[1]) << 16) + |
| 162900 | (((u32)p[2]) << 8) + |
| 162901 | (((u32)p[3]) << 0) |
| 162902 | ); |
| 162903 | } |
| 162904 | static i64 readInt64(u8 *p){ |
| 162905 | return ( |
| 162906 | (((i64)p[0]) << 56) + |
| 162907 | (((i64)p[1]) << 48) + |
| 162908 | (((i64)p[2]) << 40) + |
| 162909 | (((i64)p[3]) << 32) + |
| @@ -162910,10 +163374,11 @@ | |
| 162910 | (((i64)p[4]) << 24) + |
| 162911 | (((i64)p[5]) << 16) + |
| 162912 | (((i64)p[6]) << 8) + |
| 162913 | (((i64)p[7]) << 0) |
| 162914 | ); |
| 162915 | } |
| 162916 | |
| 162917 | /* |
| 162918 | ** Functions to serialize a 16 bit integer, 32 bit real number and |
| 162919 | ** 64 bit integer. The value returned is the number of bytes written |
| @@ -162924,28 +163389,50 @@ | |
| 162924 | p[1] = (i>> 0)&0xFF; |
| 162925 | return 2; |
| 162926 | } |
| 162927 | static int writeCoord(u8 *p, RtreeCoord *pCoord){ |
| 162928 | u32 i; |
| 162929 | assert( sizeof(RtreeCoord)==4 ); |
| 162930 | assert( sizeof(u32)==4 ); |
| 162931 | i = pCoord->u; |
| 162932 | p[0] = (i>>24)&0xFF; |
| 162933 | p[1] = (i>>16)&0xFF; |
| 162934 | p[2] = (i>> 8)&0xFF; |
| 162935 | p[3] = (i>> 0)&0xFF; |
| 162936 | return 4; |
| 162937 | } |
| 162938 | static int writeInt64(u8 *p, i64 i){ |
| 162939 | p[0] = (i>>56)&0xFF; |
| 162940 | p[1] = (i>>48)&0xFF; |
| 162941 | p[2] = (i>>40)&0xFF; |
| 162942 | p[3] = (i>>32)&0xFF; |
| 162943 | p[4] = (i>>24)&0xFF; |
| 162944 | p[5] = (i>>16)&0xFF; |
| 162945 | p[6] = (i>> 8)&0xFF; |
| 162946 | p[7] = (i>> 0)&0xFF; |
| 162947 | return 8; |
| 162948 | } |
| 162949 | |
| 162950 | /* |
| 162951 | ** Increment the reference count of node p. |
| @@ -163023,10 +163510,21 @@ | |
| 163023 | pNode->isDirty = 1; |
| 163024 | nodeReference(pParent); |
| 163025 | } |
| 163026 | return pNode; |
| 163027 | } |
| 163028 | |
| 163029 | /* |
| 163030 | ** Obtain a reference to an r-tree node. |
| 163031 | */ |
| 163032 | static int nodeAcquire( |
| @@ -163033,13 +163531,12 @@ | |
| 163033 | Rtree *pRtree, /* R-tree structure */ |
| 163034 | i64 iNode, /* Node number to load */ |
| 163035 | RtreeNode *pParent, /* Either the parent node or NULL */ |
| 163036 | RtreeNode **ppNode /* OUT: Acquired node */ |
| 163037 | ){ |
| 163038 | int rc; |
| 163039 | int rc2 = SQLITE_OK; |
| 163040 | RtreeNode *pNode; |
| 163041 | |
| 163042 | /* Check if the requested node is already in the hash table. If so, |
| 163043 | ** increase its reference count and return it. |
| 163044 | */ |
| 163045 | if( (pNode = nodeHashLookup(pRtree, iNode)) ){ |
| @@ -163051,32 +163548,49 @@ | |
| 163051 | pNode->nRef++; |
| 163052 | *ppNode = pNode; |
| 163053 | return SQLITE_OK; |
| 163054 | } |
| 163055 | |
| 163056 | sqlite3_bind_int64(pRtree->pReadNode, 1, iNode); |
| 163057 | rc = sqlite3_step(pRtree->pReadNode); |
| 163058 | if( rc==SQLITE_ROW ){ |
| 163059 | const u8 *zBlob = sqlite3_column_blob(pRtree->pReadNode, 0); |
| 163060 | if( pRtree->iNodeSize==sqlite3_column_bytes(pRtree->pReadNode, 0) ){ |
| 163061 | pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize); |
| 163062 | if( !pNode ){ |
| 163063 | rc2 = SQLITE_NOMEM; |
| 163064 | }else{ |
| 163065 | pNode->pParent = pParent; |
| 163066 | pNode->zData = (u8 *)&pNode[1]; |
| 163067 | pNode->nRef = 1; |
| 163068 | pNode->iNode = iNode; |
| 163069 | pNode->isDirty = 0; |
| 163070 | pNode->pNext = 0; |
| 163071 | memcpy(pNode->zData, zBlob, pRtree->iNodeSize); |
| 163072 | nodeReference(pParent); |
| 163073 | } |
| 163074 | } |
| 163075 | } |
| 163076 | rc = sqlite3_reset(pRtree->pReadNode); |
| 163077 | if( rc==SQLITE_OK ) rc = rc2; |
| 163078 | |
| 163079 | /* If the root node was just loaded, set pRtree->iDepth to the height |
| 163080 | ** of the r-tree structure. A height of zero means all data is stored on |
| 163081 | ** the root node. A height of one means the children of the root node |
| 163082 | ** are the leaves, and so on. If the depth as specified on the root node |
| @@ -163124,11 +163638,11 @@ | |
| 163124 | int iCell /* Index into pNode into which pCell is written */ |
| 163125 | ){ |
| 163126 | int ii; |
| 163127 | u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell]; |
| 163128 | p += writeInt64(p, pCell->iRowid); |
| 163129 | for(ii=0; ii<(pRtree->nDim*2); ii++){ |
| 163130 | p += writeCoord(p, &pCell->aCoord[ii]); |
| 163131 | } |
| 163132 | pNode->isDirty = 1; |
| 163133 | } |
| 163134 | |
| @@ -163258,17 +163772,20 @@ | |
| 163258 | int iCell, /* Index of the cell within the node */ |
| 163259 | RtreeCell *pCell /* OUT: Write the cell contents here */ |
| 163260 | ){ |
| 163261 | u8 *pData; |
| 163262 | RtreeCoord *pCoord; |
| 163263 | int ii; |
| 163264 | pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell); |
| 163265 | pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell); |
| 163266 | pCoord = pCell->aCoord; |
| 163267 | for(ii=0; ii<pRtree->nDim*2; ii++){ |
| 163268 | readCoord(&pData[ii*4], &pCoord[ii]); |
| 163269 | } |
| 163270 | } |
| 163271 | |
| 163272 | |
| 163273 | /* Forward declaration for the function that does the work of |
| 163274 | ** the virtual table module xCreate() and xConnect() methods. |
| @@ -163315,11 +163832,13 @@ | |
| 163315 | ** zero the structure is deleted. |
| 163316 | */ |
| 163317 | static void rtreeRelease(Rtree *pRtree){ |
| 163318 | pRtree->nBusy--; |
| 163319 | if( pRtree->nBusy==0 ){ |
| 163320 | sqlite3_finalize(pRtree->pReadNode); |
| 163321 | sqlite3_finalize(pRtree->pWriteNode); |
| 163322 | sqlite3_finalize(pRtree->pDeleteNode); |
| 163323 | sqlite3_finalize(pRtree->pReadRowid); |
| 163324 | sqlite3_finalize(pRtree->pWriteRowid); |
| 163325 | sqlite3_finalize(pRtree->pDeleteRowid); |
| @@ -163353,10 +163872,11 @@ | |
| 163353 | pRtree->zDb, pRtree->zName |
| 163354 | ); |
| 163355 | if( !zCreate ){ |
| 163356 | rc = SQLITE_NOMEM; |
| 163357 | }else{ |
| 163358 | rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0); |
| 163359 | sqlite3_free(zCreate); |
| 163360 | } |
| 163361 | if( rc==SQLITE_OK ){ |
| 163362 | rtreeRelease(pRtree); |
| @@ -163368,17 +163888,19 @@ | |
| 163368 | /* |
| 163369 | ** Rtree virtual table module xOpen method. |
| 163370 | */ |
| 163371 | static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ |
| 163372 | int rc = SQLITE_NOMEM; |
| 163373 | RtreeCursor *pCsr; |
| 163374 | |
| 163375 | pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor)); |
| 163376 | if( pCsr ){ |
| 163377 | memset(pCsr, 0, sizeof(RtreeCursor)); |
| 163378 | pCsr->base.pVtab = pVTab; |
| 163379 | rc = SQLITE_OK; |
| 163380 | } |
| 163381 | *ppCursor = (sqlite3_vtab_cursor *)pCsr; |
| 163382 | |
| 163383 | return rc; |
| 163384 | } |
| @@ -163407,14 +163929,17 @@ | |
| 163407 | */ |
| 163408 | static int rtreeClose(sqlite3_vtab_cursor *cur){ |
| 163409 | Rtree *pRtree = (Rtree *)(cur->pVtab); |
| 163410 | int ii; |
| 163411 | RtreeCursor *pCsr = (RtreeCursor *)cur; |
| 163412 | freeCursorConstraints(pCsr); |
| 163413 | sqlite3_free(pCsr->aPoint); |
| 163414 | for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]); |
| 163415 | sqlite3_free(pCsr); |
| 163416 | return SQLITE_OK; |
| 163417 | } |
| 163418 | |
| 163419 | /* |
| 163420 | ** Rtree virtual table module xEof method. |
| @@ -163433,27 +163958,34 @@ | |
| 163433 | ** endian platforms. The on-disk record stores integer coordinates if |
| 163434 | ** eInt is true and it stores 32-bit floating point records if eInt is |
| 163435 | ** false. a[] is the four bytes of the on-disk record to be decoded. |
| 163436 | ** Store the results in "r". |
| 163437 | ** |
| 163438 | ** There are three versions of this macro, one each for little-endian and |
| 163439 | ** big-endian processors and a third generic implementation. The endian- |
| 163440 | ** specific implementations are much faster and are preferred if the |
| 163441 | ** processor endianness is known at compile-time. The SQLITE_BYTEORDER |
| 163442 | ** macro is part of sqliteInt.h and hence the endian-specific |
| 163443 | ** implementation will only be used if this module is compiled as part |
| 163444 | ** of the amalgamation. |
| 163445 | */ |
| 163446 | #if defined(SQLITE_BYTEORDER) && SQLITE_BYTEORDER==1234 |
| 163447 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163448 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163449 | memcpy(&c.u,a,4); \ |
| 163450 | c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \ |
| 163451 | ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \ |
| 163452 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163453 | } |
| 163454 | #elif defined(SQLITE_BYTEORDER) && SQLITE_BYTEORDER==4321 |
| 163455 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163456 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163457 | memcpy(&c.u,a,4); \ |
| 163458 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163459 | } |
| @@ -163476,30 +164008,58 @@ | |
| 163476 | u8 *pCellData, /* Raw cell content */ |
| 163477 | RtreeSearchPoint *pSearch, /* Container of this cell */ |
| 163478 | sqlite3_rtree_dbl *prScore, /* OUT: score for the cell */ |
| 163479 | int *peWithin /* OUT: visibility of the cell */ |
| 163480 | ){ |
| 163481 | int i; /* Loop counter */ |
| 163482 | sqlite3_rtree_query_info *pInfo = pConstraint->pInfo; /* Callback info */ |
| 163483 | int nCoord = pInfo->nCoord; /* No. of coordinates */ |
| 163484 | int rc; /* Callback return code */ |
| 163485 | sqlite3_rtree_dbl aCoord[RTREE_MAX_DIMENSIONS*2]; /* Decoded coordinates */ |
| 163486 | |
| 163487 | assert( pConstraint->op==RTREE_MATCH || pConstraint->op==RTREE_QUERY ); |
| 163488 | assert( nCoord==2 || nCoord==4 || nCoord==6 || nCoord==8 || nCoord==10 ); |
| 163489 | |
| 163490 | if( pConstraint->op==RTREE_QUERY && pSearch->iLevel==1 ){ |
| 163491 | pInfo->iRowid = readInt64(pCellData); |
| 163492 | } |
| 163493 | pCellData += 8; |
| 163494 | for(i=0; i<nCoord; i++, pCellData += 4){ |
| 163495 | RTREE_DECODE_COORD(eInt, pCellData, aCoord[i]); |
| 163496 | } |
| 163497 | if( pConstraint->op==RTREE_MATCH ){ |
| 163498 | rc = pConstraint->u.xGeom((sqlite3_rtree_geometry*)pInfo, |
| 163499 | nCoord, aCoord, &i); |
| 163500 | if( i==0 ) *peWithin = NOT_WITHIN; |
| 163501 | *prScore = RTREE_ZERO; |
| 163502 | }else{ |
| 163503 | pInfo->aCoord = aCoord; |
| 163504 | pInfo->iLevel = pSearch->iLevel - 1; |
| 163505 | pInfo->rScore = pInfo->rParentScore = pSearch->rScore; |
| @@ -163531,10 +164091,11 @@ | |
| 163531 | */ |
| 163532 | pCellData += 8 + 4*(p->iCoord&0xfe); |
| 163533 | |
| 163534 | assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE |
| 163535 | || p->op==RTREE_GT || p->op==RTREE_EQ ); |
| 163536 | switch( p->op ){ |
| 163537 | case RTREE_LE: |
| 163538 | case RTREE_LT: |
| 163539 | case RTREE_EQ: |
| 163540 | RTREE_DECODE_COORD(eInt, pCellData, val); |
| @@ -163571,10 +164132,11 @@ | |
| 163571 | RtreeDValue xN; /* Coordinate value converted to a double */ |
| 163572 | |
| 163573 | assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE |
| 163574 | || p->op==RTREE_GT || p->op==RTREE_EQ ); |
| 163575 | pCellData += 8 + p->iCoord*4; |
| 163576 | RTREE_DECODE_COORD(eInt, pCellData, xN); |
| 163577 | switch( p->op ){ |
| 163578 | case RTREE_LE: if( xN <= p->u.rValue ) return; break; |
| 163579 | case RTREE_LT: if( xN < p->u.rValue ) return; break; |
| 163580 | case RTREE_GE: if( xN >= p->u.rValue ) return; break; |
| @@ -163639,11 +164201,11 @@ | |
| 163639 | if( pA->iLevel>pB->iLevel ) return +1; |
| 163640 | return 0; |
| 163641 | } |
| 163642 | |
| 163643 | /* |
| 163644 | ** Interchange to search points in a cursor. |
| 163645 | */ |
| 163646 | static void rtreeSearchPointSwap(RtreeCursor *p, int i, int j){ |
| 163647 | RtreeSearchPoint t = p->aPoint[i]; |
| 163648 | assert( i<j ); |
| 163649 | p->aPoint[i] = p->aPoint[j]; |
| @@ -163887,11 +164449,11 @@ | |
| 163887 | rtreeSearchPointPop(pCur); |
| 163888 | } |
| 163889 | if( rScore<RTREE_ZERO ) rScore = RTREE_ZERO; |
| 163890 | p = rtreeSearchPointNew(pCur, rScore, x.iLevel); |
| 163891 | if( p==0 ) return SQLITE_NOMEM; |
| 163892 | p->eWithin = eWithin; |
| 163893 | p->id = x.id; |
| 163894 | p->iCell = x.iCell; |
| 163895 | RTREE_QUEUE_TRACE(pCur, "PUSH-S:"); |
| 163896 | break; |
| 163897 | } |
| @@ -163946,11 +164508,10 @@ | |
| 163946 | if( rc ) return rc; |
| 163947 | if( p==0 ) return SQLITE_OK; |
| 163948 | if( i==0 ){ |
| 163949 | sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell)); |
| 163950 | }else{ |
| 163951 | if( rc ) return rc; |
| 163952 | nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c); |
| 163953 | #ifndef SQLITE_RTREE_INT_ONLY |
| 163954 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 163955 | sqlite3_result_double(ctx, c.f); |
| 163956 | }else |
| @@ -164075,11 +164636,11 @@ | |
| 164075 | assert( p!=0 ); /* Always returns pCsr->sPoint */ |
| 164076 | pCsr->aNode[0] = pLeaf; |
| 164077 | p->id = iNode; |
| 164078 | p->eWithin = PARTLY_WITHIN; |
| 164079 | rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell); |
| 164080 | p->iCell = iCell; |
| 164081 | RTREE_QUEUE_TRACE(pCsr, "PUSH-F1:"); |
| 164082 | }else{ |
| 164083 | pCsr->atEOF = 1; |
| 164084 | } |
| 164085 | }else{ |
| @@ -164108,11 +164669,11 @@ | |
| 164108 | */ |
| 164109 | rc = deserializeGeometry(argv[ii], p); |
| 164110 | if( rc!=SQLITE_OK ){ |
| 164111 | break; |
| 164112 | } |
| 164113 | p->pInfo->nCoord = pRtree->nDim*2; |
| 164114 | p->pInfo->anQueue = pCsr->anQueue; |
| 164115 | p->pInfo->mxLevel = pRtree->iDepth + 1; |
| 164116 | }else{ |
| 164117 | #ifdef SQLITE_RTREE_INT_ONLY |
| 164118 | p->u.rValue = sqlite3_value_int64(argv[ii]); |
| @@ -164123,11 +164684,11 @@ | |
| 164123 | } |
| 164124 | } |
| 164125 | } |
| 164126 | if( rc==SQLITE_OK ){ |
| 164127 | RtreeSearchPoint *pNew; |
| 164128 | pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, pRtree->iDepth+1); |
| 164129 | if( pNew==0 ) return SQLITE_NOMEM; |
| 164130 | pNew->id = 1; |
| 164131 | pNew->iCell = 0; |
| 164132 | pNew->eWithin = PARTLY_WITHIN; |
| 164133 | assert( pCsr->bPoint==1 ); |
| @@ -164141,23 +164702,10 @@ | |
| 164141 | nodeRelease(pRtree, pRoot); |
| 164142 | rtreeRelease(pRtree); |
| 164143 | return rc; |
| 164144 | } |
| 164145 | |
| 164146 | /* |
| 164147 | ** Set the pIdxInfo->estimatedRows variable to nRow. Unless this |
| 164148 | ** extension is currently being used by a version of SQLite too old to |
| 164149 | ** support estimatedRows. In that case this function is a no-op. |
| 164150 | */ |
| 164151 | static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){ |
| 164152 | #if SQLITE_VERSION_NUMBER>=3008002 |
| 164153 | if( sqlite3_libversion_number()>=3008002 ){ |
| 164154 | pIdxInfo->estimatedRows = nRow; |
| 164155 | } |
| 164156 | #endif |
| 164157 | } |
| 164158 | |
| 164159 | /* |
| 164160 | ** Rtree virtual table module xBestIndex method. There are three |
| 164161 | ** table scan strategies to choose from (in order from most to |
| 164162 | ** least desirable): |
| 164163 | ** |
| @@ -164233,11 +164781,11 @@ | |
| 164233 | ** considered almost as quick as a direct rowid lookup (for which |
| 164234 | ** sqlite uses an internal cost of 0.0). It is expected to return |
| 164235 | ** a single row. |
| 164236 | */ |
| 164237 | pIdxInfo->estimatedCost = 30.0; |
| 164238 | setEstimatedRows(pIdxInfo, 1); |
| 164239 | return SQLITE_OK; |
| 164240 | } |
| 164241 | |
| 164242 | if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){ |
| 164243 | u8 op; |
| @@ -164251,11 +164799,11 @@ | |
| 164251 | assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH ); |
| 164252 | op = RTREE_MATCH; |
| 164253 | break; |
| 164254 | } |
| 164255 | zIdxStr[iIdx++] = op; |
| 164256 | zIdxStr[iIdx++] = p->iColumn - 1 + '0'; |
| 164257 | pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2); |
| 164258 | pIdxInfo->aConstraintUsage[ii].omit = 1; |
| 164259 | } |
| 164260 | } |
| 164261 | |
| @@ -164265,55 +164813,75 @@ | |
| 164265 | return SQLITE_NOMEM; |
| 164266 | } |
| 164267 | |
| 164268 | nRow = pRtree->nRowEst >> (iIdx/2); |
| 164269 | pIdxInfo->estimatedCost = (double)6.0 * (double)nRow; |
| 164270 | setEstimatedRows(pIdxInfo, nRow); |
| 164271 | |
| 164272 | return rc; |
| 164273 | } |
| 164274 | |
| 164275 | /* |
| 164276 | ** Return the N-dimensional volumn of the cell stored in *p. |
| 164277 | */ |
| 164278 | static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){ |
| 164279 | RtreeDValue area = (RtreeDValue)1; |
| 164280 | int ii; |
| 164281 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 164282 | area = (area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]))); |
| 164283 | } |
| 164284 | return area; |
| 164285 | } |
| 164286 | |
| 164287 | /* |
| 164288 | ** Return the margin length of cell p. The margin length is the sum |
| 164289 | ** of the objects size in each dimension. |
| 164290 | */ |
| 164291 | static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){ |
| 164292 | RtreeDValue margin = (RtreeDValue)0; |
| 164293 | int ii; |
| 164294 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 164295 | margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])); |
| 164296 | } |
| 164297 | return margin; |
| 164298 | } |
| 164299 | |
| 164300 | /* |
| 164301 | ** Store the union of cells p1 and p2 in p1. |
| 164302 | */ |
| 164303 | static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ |
| 164304 | int ii; |
| 164305 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 164306 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 164307 | p1->aCoord[ii].f = MIN(p1->aCoord[ii].f, p2->aCoord[ii].f); |
| 164308 | p1->aCoord[ii+1].f = MAX(p1->aCoord[ii+1].f, p2->aCoord[ii+1].f); |
| 164309 | } |
| 164310 | }else{ |
| 164311 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 164312 | p1->aCoord[ii].i = MIN(p1->aCoord[ii].i, p2->aCoord[ii].i); |
| 164313 | p1->aCoord[ii+1].i = MAX(p1->aCoord[ii+1].i, p2->aCoord[ii+1].i); |
| 164314 | } |
| 164315 | } |
| 164316 | } |
| 164317 | |
| 164318 | /* |
| 164319 | ** Return true if the area covered by p2 is a subset of the area covered |
| @@ -164320,11 +164888,11 @@ | |
| 164320 | ** by p1. False otherwise. |
| 164321 | */ |
| 164322 | static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ |
| 164323 | int ii; |
| 164324 | int isInt = (pRtree->eCoordType==RTREE_COORD_INT32); |
| 164325 | for(ii=0; ii<(pRtree->nDim*2); ii+=2){ |
| 164326 | RtreeCoord *a1 = &p1->aCoord[ii]; |
| 164327 | RtreeCoord *a2 = &p2->aCoord[ii]; |
| 164328 | if( (!isInt && (a2[0].f<a1[0].f || a2[1].f>a1[1].f)) |
| 164329 | || ( isInt && (a2[0].i<a1[0].i || a2[1].i>a1[1].i)) |
| 164330 | ){ |
| @@ -164355,11 +164923,11 @@ | |
| 164355 | int ii; |
| 164356 | RtreeDValue overlap = RTREE_ZERO; |
| 164357 | for(ii=0; ii<nCell; ii++){ |
| 164358 | int jj; |
| 164359 | RtreeDValue o = (RtreeDValue)1; |
| 164360 | for(jj=0; jj<(pRtree->nDim*2); jj+=2){ |
| 164361 | RtreeDValue x1, x2; |
| 164362 | x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj])); |
| 164363 | x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1])); |
| 164364 | if( x2<x1 ){ |
| 164365 | o = (RtreeDValue)0; |
| @@ -165411,11 +165979,11 @@ | |
| 165411 | ** with "column" that are interpreted as table constraints. |
| 165412 | ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5)); |
| 165413 | ** This problem was discovered after years of use, so we silently ignore |
| 165414 | ** these kinds of misdeclared tables to avoid breaking any legacy. |
| 165415 | */ |
| 165416 | assert( nData<=(pRtree->nDim*2 + 3) ); |
| 165417 | |
| 165418 | #ifndef SQLITE_RTREE_INT_ONLY |
| 165419 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 165420 | for(ii=0; ii<nData-4; ii+=2){ |
| 165421 | cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]); |
| @@ -165500,10 +166068,31 @@ | |
| 165500 | |
| 165501 | constraint: |
| 165502 | rtreeRelease(pRtree); |
| 165503 | return rc; |
| 165504 | } |
| 165505 | |
| 165506 | /* |
| 165507 | ** The xRename method for rtree module virtual tables. |
| 165508 | */ |
| 165509 | static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){ |
| @@ -165521,10 +166110,11 @@ | |
| 165521 | rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0); |
| 165522 | sqlite3_free(zSql); |
| 165523 | } |
| 165524 | return rc; |
| 165525 | } |
| 165526 | |
| 165527 | /* |
| 165528 | ** This function populates the pRtree->nRowEst variable with an estimate |
| 165529 | ** of the number of rows in the virtual table. If possible, this is based |
| 165530 | ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST. |
| @@ -165581,19 +166171,19 @@ | |
| 165581 | rtreeNext, /* xNext - advance a cursor */ |
| 165582 | rtreeEof, /* xEof */ |
| 165583 | rtreeColumn, /* xColumn - read data */ |
| 165584 | rtreeRowid, /* xRowid - read data */ |
| 165585 | rtreeUpdate, /* xUpdate - write data */ |
| 165586 | 0, /* xBegin - begin transaction */ |
| 165587 | 0, /* xSync - sync transaction */ |
| 165588 | 0, /* xCommit - commit transaction */ |
| 165589 | 0, /* xRollback - rollback transaction */ |
| 165590 | 0, /* xFindFunction - function overloading */ |
| 165591 | rtreeRename, /* xRename - rename the table */ |
| 165592 | 0, /* xSavepoint */ |
| 165593 | 0, /* xRelease */ |
| 165594 | 0 /* xRollbackTo */ |
| 165595 | }; |
| 165596 | |
| 165597 | static int rtreeSqlInit( |
| 165598 | Rtree *pRtree, |
| 165599 | sqlite3 *db, |
| @@ -165601,14 +166191,13 @@ | |
| 165601 | const char *zPrefix, |
| 165602 | int isCreate |
| 165603 | ){ |
| 165604 | int rc = SQLITE_OK; |
| 165605 | |
| 165606 | #define N_STATEMENT 9 |
| 165607 | static const char *azSql[N_STATEMENT] = { |
| 165608 | /* Read and write the xxx_node table */ |
| 165609 | "SELECT data FROM '%q'.'%q_node' WHERE nodeno = :1", |
| 165610 | "INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(:1, :2)", |
| 165611 | "DELETE FROM '%q'.'%q_node' WHERE nodeno = :1", |
| 165612 | |
| 165613 | /* Read and write the xxx_rowid table */ |
| 165614 | "SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = :1", |
| @@ -165642,19 +166231,18 @@ | |
| 165642 | if( rc!=SQLITE_OK ){ |
| 165643 | return rc; |
| 165644 | } |
| 165645 | } |
| 165646 | |
| 165647 | appStmt[0] = &pRtree->pReadNode; |
| 165648 | appStmt[1] = &pRtree->pWriteNode; |
| 165649 | appStmt[2] = &pRtree->pDeleteNode; |
| 165650 | appStmt[3] = &pRtree->pReadRowid; |
| 165651 | appStmt[4] = &pRtree->pWriteRowid; |
| 165652 | appStmt[5] = &pRtree->pDeleteRowid; |
| 165653 | appStmt[6] = &pRtree->pReadParent; |
| 165654 | appStmt[7] = &pRtree->pWriteParent; |
| 165655 | appStmt[8] = &pRtree->pDeleteParent; |
| 165656 | |
| 165657 | rc = rtreeQueryStat1(db, pRtree); |
| 165658 | for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){ |
| 165659 | char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix); |
| 165660 | if( zSql ){ |
| @@ -165788,13 +166376,14 @@ | |
| 165788 | memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2); |
| 165789 | pRtree->nBusy = 1; |
| 165790 | pRtree->base.pModule = &rtreeModule; |
| 165791 | pRtree->zDb = (char *)&pRtree[1]; |
| 165792 | pRtree->zName = &pRtree->zDb[nDb+1]; |
| 165793 | pRtree->nDim = (argc-4)/2; |
| 165794 | pRtree->nBytesPerCell = 8 + pRtree->nDim*4*2; |
| 165795 | pRtree->eCoordType = eCoordType; |
| 165796 | memcpy(pRtree->zDb, argv[1], nDb); |
| 165797 | memcpy(pRtree->zName, argv[2], nName); |
| 165798 | |
| 165799 | /* Figure out the node size to use. */ |
| 165800 | rc = getNodeSize(db, pRtree, isCreate, pzErr); |
| @@ -165863,11 +166452,12 @@ | |
| 165863 | int ii; |
| 165864 | |
| 165865 | UNUSED_PARAMETER(nArg); |
| 165866 | memset(&node, 0, sizeof(RtreeNode)); |
| 165867 | memset(&tree, 0, sizeof(Rtree)); |
| 165868 | tree.nDim = sqlite3_value_int(apArg[0]); |
| 165869 | tree.nBytesPerCell = 8 + 8 * tree.nDim; |
| 165870 | node.zData = (u8 *)sqlite3_value_blob(apArg[1]); |
| 165871 | |
| 165872 | for(ii=0; ii<NCELL(&node); ii++){ |
| 165873 | char zCell[512]; |
| @@ -165876,11 +166466,11 @@ | |
| 165876 | int jj; |
| 165877 | |
| 165878 | nodeGetCell(&tree, &node, ii, &cell); |
| 165879 | sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid); |
| 165880 | nCell = (int)strlen(zCell); |
| 165881 | for(jj=0; jj<tree.nDim*2; jj++){ |
| 165882 | #ifndef SQLITE_RTREE_INT_ONLY |
| 165883 | sqlite3_snprintf(512-nCell,&zCell[nCell], " %g", |
| 165884 | (double)cell.aCoord[jj].f); |
| 165885 | #else |
| 165886 | sqlite3_snprintf(512-nCell,&zCell[nCell], " %d", |
| @@ -166584,42 +167174,40 @@ | |
| 166584 | |
| 166585 | /* |
| 166586 | ** Register the ICU extension functions with database db. |
| 166587 | */ |
| 166588 | SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){ |
| 166589 | struct IcuScalar { |
| 166590 | const char *zName; /* Function name */ |
| 166591 | int nArg; /* Number of arguments */ |
| 166592 | int enc; /* Optimal text encoding */ |
| 166593 | void *pContext; /* sqlite3_user_data() context */ |
| 166594 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**); |
| 166595 | } scalars[] = { |
| 166596 | {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc}, |
| 166597 | |
| 166598 | {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 166599 | {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 166600 | {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16}, |
| 166601 | {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16}, |
| 166602 | |
| 166603 | {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 166604 | {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 166605 | {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16}, |
| 166606 | {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16}, |
| 166607 | |
| 166608 | {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, |
| 166609 | {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, |
| 166610 | |
| 166611 | {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation}, |
| 166612 | }; |
| 166613 | |
| 166614 | int rc = SQLITE_OK; |
| 166615 | int i; |
| 166616 | |
| 166617 | for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){ |
| 166618 | struct IcuScalar *p = &scalars[i]; |
| 166619 | rc = sqlite3_create_function( |
| 166620 | db, p->zName, p->nArg, p->enc, p->pContext, p->xFunc, 0, 0 |
| 166621 | ); |
| 166622 | } |
| 166623 | |
| 166624 | return rc; |
| 166625 | } |
| @@ -169823,11 +170411,11 @@ | |
| 169823 | |
| 169824 | /* |
| 169825 | ** Open the database handle and attach the RBU database as "rbu". If an |
| 169826 | ** error occurs, leave an error code and message in the RBU handle. |
| 169827 | */ |
| 169828 | static void rbuOpenDatabase(sqlite3rbu *p){ |
| 169829 | assert( p->rc || (p->dbMain==0 && p->dbRbu==0) ); |
| 169830 | assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 ); |
| 169831 | |
| 169832 | /* Open the RBU database */ |
| 169833 | p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1); |
| @@ -169898,11 +170486,11 @@ | |
| 169898 | if( p->eStage>=RBU_STAGE_MOVE ){ |
| 169899 | bOpen = 1; |
| 169900 | }else{ |
| 169901 | RbuState *pState = rbuLoadState(p); |
| 169902 | if( pState ){ |
| 169903 | bOpen = (pState->eStage>RBU_STAGE_MOVE); |
| 169904 | rbuFreeState(pState); |
| 169905 | } |
| 169906 | } |
| 169907 | if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1); |
| 169908 | } |
| @@ -169910,10 +170498,19 @@ | |
| 169910 | p->eStage = 0; |
| 169911 | if( p->rc==SQLITE_OK && p->dbMain==0 ){ |
| 169912 | if( !rbuIsVacuum(p) ){ |
| 169913 | p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1); |
| 169914 | }else if( p->pRbuFd->pWalFd ){ |
| 169915 | p->rc = SQLITE_ERROR; |
| 169916 | p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database"); |
| 169917 | }else{ |
| 169918 | char *zTarget; |
| 169919 | char *zExtra = 0; |
| @@ -170090,20 +170687,22 @@ | |
| 170090 | p->eStage = RBU_STAGE_CAPTURE; |
| 170091 | rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0); |
| 170092 | if( rc2!=SQLITE_INTERNAL ) p->rc = rc2; |
| 170093 | } |
| 170094 | |
| 170095 | if( p->rc==SQLITE_OK ){ |
| 170096 | p->eStage = RBU_STAGE_CKPT; |
| 170097 | p->nStep = (pState ? pState->nRow : 0); |
| 170098 | p->aBuf = rbuMalloc(p, p->pgsz); |
| 170099 | p->iWalCksum = rbuShmChecksum(p); |
| 170100 | } |
| 170101 | |
| 170102 | if( p->rc==SQLITE_OK && pState && pState->iWalCksum!=p->iWalCksum ){ |
| 170103 | p->rc = SQLITE_DONE; |
| 170104 | p->eStage = RBU_STAGE_DONE; |
| 170105 | } |
| 170106 | } |
| 170107 | |
| 170108 | /* |
| 170109 | ** Called when iAmt bytes are read from offset iOff of the wal file while |
| @@ -170272,11 +170871,11 @@ | |
| 170272 | #else |
| 170273 | p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; |
| 170274 | #endif |
| 170275 | |
| 170276 | if( p->rc==SQLITE_OK ){ |
| 170277 | rbuOpenDatabase(p); |
| 170278 | rbuSetupCheckpoint(p, 0); |
| 170279 | } |
| 170280 | } |
| 170281 | } |
| 170282 | |
| @@ -170983,10 +171582,11 @@ | |
| 170983 | rbuCreateVfs(p); |
| 170984 | |
| 170985 | /* Open the target, RBU and state databases */ |
| 170986 | if( p->rc==SQLITE_OK ){ |
| 170987 | char *pCsr = (char*)&p[1]; |
| 170988 | if( zTarget ){ |
| 170989 | p->zTarget = pCsr; |
| 170990 | memcpy(p->zTarget, zTarget, nTarget+1); |
| 170991 | pCsr += nTarget+1; |
| 170992 | } |
| @@ -170994,11 +171594,22 @@ | |
| 170994 | memcpy(p->zRbu, zRbu, nRbu+1); |
| 170995 | pCsr += nRbu+1; |
| 170996 | if( zState ){ |
| 170997 | p->zState = rbuMPrintf(p, "%s", zState); |
| 170998 | } |
| 170999 | rbuOpenDatabase(p); |
| 171000 | } |
| 171001 | |
| 171002 | if( p->rc==SQLITE_OK ){ |
| 171003 | pState = rbuLoadState(p); |
| 171004 | assert( pState || p->rc!=SQLITE_OK ); |
| @@ -175957,11 +176568,11 @@ | |
| 175957 | sqlite3_value **ppValue /* OUT: Value from conflicting row */ |
| 175958 | ){ |
| 175959 | if( !pIter->pConflict ){ |
| 175960 | return SQLITE_MISUSE; |
| 175961 | } |
| 175962 | if( iVal<0 || iVal>=sqlite3_column_count(pIter->pConflict) ){ |
| 175963 | return SQLITE_RANGE; |
| 175964 | } |
| 175965 | *ppValue = sqlite3_column_value(pIter->pConflict, iVal); |
| 175966 | return SQLITE_OK; |
| 175967 | } |
| @@ -176424,11 +177035,17 @@ | |
| 176424 | int i; |
| 176425 | SessionBuffer buf = {0, 0, 0}; |
| 176426 | |
| 176427 | sessionAppendStr(&buf, "INSERT INTO main.", &rc); |
| 176428 | sessionAppendIdent(&buf, zTab, &rc); |
| 176429 | sessionAppendStr(&buf, " VALUES(?", &rc); |
| 176430 | for(i=1; i<p->nCol; i++){ |
| 176431 | sessionAppendStr(&buf, ", ?", &rc); |
| 176432 | } |
| 176433 | sessionAppendStr(&buf, ")", &rc); |
| 176434 | |
| @@ -176970,42 +177587,51 @@ | |
| 176970 | break; |
| 176971 | } |
| 176972 | nTab = (int)strlen(zTab); |
| 176973 | sApply.azCol = (const char **)zTab; |
| 176974 | }else{ |
| 176975 | sqlite3changeset_pk(pIter, &abPK, 0); |
| 176976 | rc = sessionTableInfo( |
| 176977 | db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK |
| 176978 | ); |
| 176979 | if( rc!=SQLITE_OK ) break; |
| 176980 | |
| 176981 | if( sApply.nCol==0 ){ |
| 176982 | schemaMismatch = 1; |
| 176983 | sqlite3_log(SQLITE_SCHEMA, |
| 176984 | "sqlite3changeset_apply(): no such table: %s", zTab |
| 176985 | ); |
| 176986 | } |
| 176987 | else if( sApply.nCol!=nCol ){ |
| 176988 | schemaMismatch = 1; |
| 176989 | sqlite3_log(SQLITE_SCHEMA, |
| 176990 | "sqlite3changeset_apply(): table %s has %d columns, expected %d", |
| 176991 | zTab, sApply.nCol, nCol |
| 176992 | ); |
| 176993 | } |
| 176994 | else if( memcmp(sApply.abPK, abPK, nCol)!=0 ){ |
| 176995 | schemaMismatch = 1; |
| 176996 | sqlite3_log(SQLITE_SCHEMA, "sqlite3changeset_apply(): " |
| 176997 | "primary key mismatch for table %s", zTab |
| 176998 | ); |
| 176999 | } |
| 177000 | else if( |
| 177001 | (rc = sessionSelectRow(db, zTab, &sApply)) |
| 177002 | || (rc = sessionUpdateRow(db, zTab, &sApply)) |
| 177003 | || (rc = sessionDeleteRow(db, zTab, &sApply)) |
| 177004 | || (rc = sessionInsertRow(db, zTab, &sApply)) |
| 177005 | ){ |
| 177006 | break; |
| 177007 | } |
| 177008 | nTab = sqlite3Strlen30(zTab); |
| 177009 | } |
| 177010 | } |
| 177011 | |
| @@ -177593,11 +178219,11 @@ | |
| 177593 | ** a BLOB, but there is no support for JSONB in the current implementation. |
| 177594 | ** This implementation parses JSON text at 250 MB/s, so it is hard to see |
| 177595 | ** how JSONB might improve on that.) |
| 177596 | */ |
| 177597 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1) |
| 177598 | #if !defined(_SQLITEINT_H_) |
| 177599 | /* #include "sqlite3ext.h" */ |
| 177600 | #endif |
| 177601 | SQLITE_EXTENSION_INIT1 |
| 177602 | /* #include <assert.h> */ |
| 177603 | /* #include <string.h> */ |
| @@ -181644,10 +182270,35 @@ | |
| 181644 | */ |
| 181645 | #ifndef fts5YYMALLOCARGTYPE |
| 181646 | # define fts5YYMALLOCARGTYPE size_t |
| 181647 | #endif |
| 181648 | |
| 181649 | /* |
| 181650 | ** This function allocates a new parser. |
| 181651 | ** The only argument is a pointer to a function which works like |
| 181652 | ** malloc. |
| 181653 | ** |
| @@ -181659,32 +182310,15 @@ | |
| 181659 | ** to sqlite3Fts5Parser and sqlite3Fts5ParserFree. |
| 181660 | */ |
| 181661 | static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(fts5YYMALLOCARGTYPE)){ |
| 181662 | fts5yyParser *pParser; |
| 181663 | pParser = (fts5yyParser*)(*mallocProc)( (fts5YYMALLOCARGTYPE)sizeof(fts5yyParser) ); |
| 181664 | if( pParser ){ |
| 181665 | #ifdef fts5YYTRACKMAXSTACKDEPTH |
| 181666 | pParser->fts5yyhwm = 0; |
| 181667 | #endif |
| 181668 | #if fts5YYSTACKDEPTH<=0 |
| 181669 | pParser->fts5yytos = NULL; |
| 181670 | pParser->fts5yystack = NULL; |
| 181671 | pParser->fts5yystksz = 0; |
| 181672 | if( fts5yyGrowStack(pParser) ){ |
| 181673 | pParser->fts5yystack = &pParser->fts5yystk0; |
| 181674 | pParser->fts5yystksz = 1; |
| 181675 | } |
| 181676 | #endif |
| 181677 | #ifndef fts5YYNOERRORRECOVERY |
| 181678 | pParser->fts5yyerrcnt = -1; |
| 181679 | #endif |
| 181680 | pParser->fts5yytos = pParser->fts5yystack; |
| 181681 | pParser->fts5yystack[0].stateno = 0; |
| 181682 | pParser->fts5yystack[0].major = 0; |
| 181683 | } |
| 181684 | return pParser; |
| 181685 | } |
| 181686 | |
| 181687 | /* The following function deletes the "minor type" or semantic value |
| 181688 | ** associated with a symbol. The symbol can be either a terminal |
| 181689 | ** or nonterminal. "fts5yymajor" is the symbol code, and "fts5yypminor" is |
| 181690 | ** a pointer to the value to be deleted. The code used to do the |
| @@ -181762,10 +182396,22 @@ | |
| 181762 | } |
| 181763 | #endif |
| 181764 | fts5yy_destructor(pParser, fts5yytos->major, &fts5yytos->minor); |
| 181765 | } |
| 181766 | |
| 181767 | /* |
| 181768 | ** Deallocate and destroy a parser. Destructors are called for |
| 181769 | ** all stack elements before shutting the parser down. |
| 181770 | ** |
| 181771 | ** If the fts5YYPARSEFREENEVERNULL macro exists (for example because it |
| @@ -181774,20 +182420,17 @@ | |
| 181774 | */ |
| 181775 | static void sqlite3Fts5ParserFree( |
| 181776 | void *p, /* The parser to be deleted */ |
| 181777 | void (*freeProc)(void*) /* Function used to reclaim memory */ |
| 181778 | ){ |
| 181779 | fts5yyParser *pParser = (fts5yyParser*)p; |
| 181780 | #ifndef fts5YYPARSEFREENEVERNULL |
| 181781 | if( pParser==0 ) return; |
| 181782 | #endif |
| 181783 | while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser); |
| 181784 | #if fts5YYSTACKDEPTH<=0 |
| 181785 | if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack); |
| 181786 | #endif |
| 181787 | (*freeProc)((void*)pParser); |
| 181788 | } |
| 181789 | |
| 181790 | /* |
| 181791 | ** Return the peak depth of the stack for a parser. |
| 181792 | */ |
| 181793 | #ifdef fts5YYTRACKMAXSTACKDEPTH |
| @@ -186122,11 +186765,11 @@ | |
| 186122 | memset(&sCtx, 0, sizeof(TokenCtx)); |
| 186123 | sCtx.pPhrase = pAppend; |
| 186124 | |
| 186125 | rc = fts5ParseStringFromToken(pToken, &z); |
| 186126 | if( rc==SQLITE_OK ){ |
| 186127 | int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_QUERY : 0); |
| 186128 | int n; |
| 186129 | sqlite3Fts5Dequote(z); |
| 186130 | n = (int)strlen(z); |
| 186131 | rc = sqlite3Fts5Tokenize(pConfig, flags, z, n, &sCtx, fts5ParseTokenize); |
| 186132 | } |
| @@ -196863,11 +197506,11 @@ | |
| 196863 | int nArg, /* Number of args */ |
| 196864 | sqlite3_value **apUnused /* Function arguments */ |
| 196865 | ){ |
| 196866 | assert( nArg==0 ); |
| 196867 | UNUSED_PARAM2(nArg, apUnused); |
| 196868 | sqlite3_result_text(pCtx, "fts5: 2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209", -1, SQLITE_TRANSIENT); |
| 196869 | } |
| 196870 | |
| 196871 | static int fts5Init(sqlite3 *db){ |
| 196872 | static const sqlite3_module fts5Mod = { |
| 196873 | /* iVersion */ 2, |
| 196874 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.17.0. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -208,10 +208,18 @@ | |
| 208 | #ifdef __GNUC__ |
| 209 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 210 | #else |
| 211 | # define GCC_VERSION 0 |
| 212 | #endif |
| 213 | |
| 214 | /* What version of CLANG is being used. 0 means CLANG is not being used */ |
| 215 | #if defined(__clang__) && !defined(_WIN32) |
| 216 | # define CLANG_VERSION \ |
| 217 | (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) |
| 218 | #else |
| 219 | # define CLANG_VERSION 0 |
| 220 | #endif |
| 221 | |
| 222 | /* Needed for various definitions... */ |
| 223 | #if defined(__GNUC__) && !defined(_GNU_SOURCE) |
| 224 | # define _GNU_SOURCE |
| 225 | #endif |
| @@ -379,13 +387,13 @@ | |
| 387 | ** |
| 388 | ** See also: [sqlite3_libversion()], |
| 389 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 390 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 391 | */ |
| 392 | #define SQLITE_VERSION "3.17.0" |
| 393 | #define SQLITE_VERSION_NUMBER 3017000 |
| 394 | #define SQLITE_SOURCE_ID "2017-02-07 13:51:48 a136609c98ed3cc673c5a3c2578d49db3f2518d1" |
| 395 | |
| 396 | /* |
| 397 | ** CAPI3REF: Run-Time Library Version Numbers |
| 398 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 399 | ** |
| @@ -517,11 +525,15 @@ | |
| 525 | ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
| 526 | ** between 0 and +18446744073709551615 inclusive. |
| 527 | */ |
| 528 | #ifdef SQLITE_INT64_TYPE |
| 529 | typedef SQLITE_INT64_TYPE sqlite_int64; |
| 530 | # ifdef SQLITE_UINT64_TYPE |
| 531 | typedef SQLITE_UINT64_TYPE sqlite_uint64; |
| 532 | # else |
| 533 | typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; |
| 534 | # endif |
| 535 | #elif defined(_MSC_VER) || defined(__BORLANDC__) |
| 536 | typedef __int64 sqlite_int64; |
| 537 | typedef unsigned __int64 sqlite_uint64; |
| 538 | #else |
| 539 | typedef long long int sqlite_int64; |
| @@ -830,11 +842,11 @@ | |
| 842 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 843 | ** after reboot following a crash or power loss, the only bytes in a |
| 844 | ** file that were written at the application level might have changed |
| 845 | ** and that adjacent bytes, even bytes within the same sector are |
| 846 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 847 | ** flag indicates that a file cannot be deleted when open. The |
| 848 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
| 849 | ** read-only media and cannot be changed even by processes with |
| 850 | ** elevated privileges. |
| 851 | */ |
| 852 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| @@ -980,10 +992,13 @@ | |
| 992 | ** <li> [SQLITE_IOCAP_ATOMIC16K] |
| 993 | ** <li> [SQLITE_IOCAP_ATOMIC32K] |
| 994 | ** <li> [SQLITE_IOCAP_ATOMIC64K] |
| 995 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
| 996 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
| 997 | ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] |
| 998 | ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] |
| 999 | ** <li> [SQLITE_IOCAP_IMMUTABLE] |
| 1000 | ** </ul> |
| 1001 | ** |
| 1002 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 1003 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 1004 | ** mean that writes of blocks that are nnn bytes in size and |
| @@ -5668,11 +5683,11 @@ | |
| 5683 | ** ^(The update hook is not invoked when internal system tables are |
| 5684 | ** modified (i.e. sqlite_master and sqlite_sequence).)^ |
| 5685 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
| 5686 | ** |
| 5687 | ** ^In the current implementation, the update hook |
| 5688 | ** is not invoked when conflicting rows are deleted because of an |
| 5689 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
| 5690 | ** invoked when rows are deleted using the [truncate optimization]. |
| 5691 | ** The exceptions defined in this paragraph might change in a future |
| 5692 | ** release of SQLite. |
| 5693 | ** |
| @@ -6450,10 +6465,16 @@ | |
| 6465 | ** |
| 6466 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 6467 | ** [database connection] error code and message accessible via |
| 6468 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 6469 | ** |
| 6470 | ** A BLOB referenced by sqlite3_blob_open() may be read using the |
| 6471 | ** [sqlite3_blob_read()] interface and modified by using |
| 6472 | ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a |
| 6473 | ** different row of the same table using the [sqlite3_blob_reopen()] |
| 6474 | ** interface. However, the column, table, or database of a [BLOB handle] |
| 6475 | ** cannot be changed after the [BLOB handle] is opened. |
| 6476 | ** |
| 6477 | ** ^(If the row that a BLOB handle points to is modified by an |
| 6478 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 6479 | ** then the BLOB handle is marked as "expired". |
| 6480 | ** This is true if any column of the row is changed, even a column |
| @@ -6473,10 +6494,14 @@ | |
| 6494 | ** and the built-in [zeroblob] SQL function may be used to create a |
| 6495 | ** zero-filled blob to read or write using the incremental-blob interface. |
| 6496 | ** |
| 6497 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 6498 | ** be released by a call to [sqlite3_blob_close()]. |
| 6499 | ** |
| 6500 | ** See also: [sqlite3_blob_close()], |
| 6501 | ** [sqlite3_blob_reopen()], [sqlite3_blob_read()], |
| 6502 | ** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. |
| 6503 | */ |
| 6504 | SQLITE_API int sqlite3_blob_open( |
| 6505 | sqlite3*, |
| 6506 | const char *zDb, |
| 6507 | const char *zTable, |
| @@ -6488,15 +6513,15 @@ | |
| 6513 | |
| 6514 | /* |
| 6515 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6516 | ** METHOD: sqlite3_blob |
| 6517 | ** |
| 6518 | ** ^This function is used to move an existing [BLOB handle] so that it points |
| 6519 | ** to a different row of the same database table. ^The new row is identified |
| 6520 | ** by the rowid value passed as the second argument. Only the row can be |
| 6521 | ** changed. ^The database, table and column on which the blob handle is open |
| 6522 | ** remain the same. Moving an existing [BLOB handle] to a new row is |
| 6523 | ** faster than closing the existing handle and opening a new one. |
| 6524 | ** |
| 6525 | ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
| 6526 | ** it must exist and there must be either a blob or text value stored in |
| 6527 | ** the nominated column.)^ ^If the new row is not present in the table, or if |
| @@ -8421,22 +8446,22 @@ | |
| 8446 | ** ^These interfaces are only available if SQLite is compiled using the |
| 8447 | ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. |
| 8448 | ** |
| 8449 | ** ^The [sqlite3_preupdate_hook()] interface registers a callback function |
| 8450 | ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation |
| 8451 | ** on a database table. |
| 8452 | ** ^At most one preupdate hook may be registered at a time on a single |
| 8453 | ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides |
| 8454 | ** the previous setting. |
| 8455 | ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] |
| 8456 | ** with a NULL pointer as the second parameter. |
| 8457 | ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as |
| 8458 | ** the first parameter to callbacks. |
| 8459 | ** |
| 8460 | ** ^The preupdate hook only fires for changes to real database tables; the |
| 8461 | ** preupdate hook is not invoked for changes to [virtual tables] or to |
| 8462 | ** system tables like sqlite_master or sqlite_stat1. |
| 8463 | ** |
| 8464 | ** ^The second parameter to the preupdate callback is a pointer to |
| 8465 | ** the [database connection] that registered the preupdate hook. |
| 8466 | ** ^The third parameter to the preupdate callback is one of the constants |
| 8467 | ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the |
| @@ -8446,16 +8471,20 @@ | |
| 8471 | ** will be "main" for the main database or "temp" for TEMP tables or |
| 8472 | ** the name given after the AS keyword in the [ATTACH] statement for attached |
| 8473 | ** databases.)^ |
| 8474 | ** ^The fifth parameter to the preupdate callback is the name of the |
| 8475 | ** table that is being modified. |
| 8476 | ** |
| 8477 | ** For an UPDATE or DELETE operation on a [rowid table], the sixth |
| 8478 | ** parameter passed to the preupdate callback is the initial [rowid] of the |
| 8479 | ** row being modified or deleted. For an INSERT operation on a rowid table, |
| 8480 | ** or any operation on a WITHOUT ROWID table, the value of the sixth |
| 8481 | ** parameter is undefined. For an INSERT or UPDATE on a rowid table the |
| 8482 | ** seventh parameter is the final rowid value of the row being inserted |
| 8483 | ** or updated. The value of the seventh parameter passed to the callback |
| 8484 | ** function is not defined for operations on WITHOUT ROWID tables, or for |
| 8485 | ** INSERT operations on rowid tables. |
| 8486 | ** |
| 8487 | ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], |
| 8488 | ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces |
| 8489 | ** provide additional information about a preupdate event. These routines |
| 8490 | ** may only be called from within a preupdate callback. Invoking any of |
| @@ -9155,11 +9184,12 @@ | |
| 9184 | ** |
| 9185 | ** <li> For each row (primary key) that exists in the to-table but not in |
| 9186 | ** the from-table, a DELETE record is added to the session object. |
| 9187 | ** |
| 9188 | ** <li> For each row (primary key) that exists in both tables, but features |
| 9189 | ** different non-PK values in each, an UPDATE record is added to the |
| 9190 | ** session. |
| 9191 | ** </ul> |
| 9192 | ** |
| 9193 | ** To clarify, if this function is called and then a changeset constructed |
| 9194 | ** using [sqlite3session_changeset()], then after applying that changeset to |
| 9195 | ** database zFrom the contents of the two compatible tables would be |
| @@ -9740,11 +9770,11 @@ | |
| 9770 | ** considered compatible if all of the following are true: |
| 9771 | ** |
| 9772 | ** <ul> |
| 9773 | ** <li> The table has the same name as the name recorded in the |
| 9774 | ** changeset, and |
| 9775 | ** <li> The table has at least as many columns as recorded in the |
| 9776 | ** changeset, and |
| 9777 | ** <li> The table has primary key columns in the same position as |
| 9778 | ** recorded in the changeset. |
| 9779 | ** </ul> |
| 9780 | ** |
| @@ -9785,11 +9815,15 @@ | |
| 9815 | ** the changeset the row is deleted from the target database. |
| 9816 | ** |
| 9817 | ** If a row with matching primary key values is found, but one or more of |
| 9818 | ** the non-primary key fields contains a value different from the original |
| 9819 | ** row value stored in the changeset, the conflict-handler function is |
| 9820 | ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the |
| 9821 | ** database table has more columns than are recorded in the changeset, |
| 9822 | ** only the values of those non-primary key fields are compared against |
| 9823 | ** the current database contents - any trailing database table columns |
| 9824 | ** are ignored. |
| 9825 | ** |
| 9826 | ** If no row with matching primary key values is found in the database, |
| 9827 | ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] |
| 9828 | ** passed as the second argument. |
| 9829 | ** |
| @@ -9800,11 +9834,13 @@ | |
| 9834 | ** operation is attempted because an earlier call to the conflict handler |
| 9835 | ** function returned [SQLITE_CHANGESET_REPLACE]. |
| 9836 | ** |
| 9837 | ** <dt>INSERT Changes<dd> |
| 9838 | ** For each INSERT change, an attempt is made to insert the new row into |
| 9839 | ** the database. If the changeset row contains fewer fields than the |
| 9840 | ** database table, the trailing fields are populated with their default |
| 9841 | ** values. |
| 9842 | ** |
| 9843 | ** If the attempt to insert the row fails because the database already |
| 9844 | ** contains a row with the same primary key values, the conflict handler |
| 9845 | ** function is invoked with the second argument set to |
| 9846 | ** [SQLITE_CHANGESET_CONFLICT]. |
| @@ -9818,17 +9854,17 @@ | |
| 9854 | ** |
| 9855 | ** <dt>UPDATE Changes<dd> |
| 9856 | ** For each UPDATE change, this function checks if the target database |
| 9857 | ** contains a row with the same primary key value (or values) as the |
| 9858 | ** original row values stored in the changeset. If it does, and the values |
| 9859 | ** stored in all modified non-primary key columns also match the values |
| 9860 | ** stored in the changeset the row is updated within the target database. |
| 9861 | ** |
| 9862 | ** If a row with matching primary key values is found, but one or more of |
| 9863 | ** the modified non-primary key fields contains a value different from an |
| 9864 | ** original row value stored in the changeset, the conflict-handler function |
| 9865 | ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since |
| 9866 | ** UPDATE changes only contain values for non-primary key fields that are |
| 9867 | ** to be modified, only those fields need to match the original values to |
| 9868 | ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. |
| 9869 | ** |
| 9870 | ** If no row with matching primary key values is found in the database, |
| @@ -11537,10 +11573,22 @@ | |
| 11573 | #include <stdlib.h> |
| 11574 | #include <string.h> |
| 11575 | #include <assert.h> |
| 11576 | #include <stddef.h> |
| 11577 | |
| 11578 | /* |
| 11579 | ** Use a macro to replace memcpy() if compiled with SQLITE_INLINE_MEMCPY. |
| 11580 | ** This allows better measurements of where memcpy() is used when running |
| 11581 | ** cachegrind. But this macro version of memcpy() is very slow so it |
| 11582 | ** should not be used in production. This is a performance measurement |
| 11583 | ** hack only. |
| 11584 | */ |
| 11585 | #ifdef SQLITE_INLINE_MEMCPY |
| 11586 | # define memcpy(D,S,N) {char*xxd=(char*)(D);const char*xxs=(const char*)(S);\ |
| 11587 | int xxn=(N);while(xxn-->0)*(xxd++)=*(xxs++);} |
| 11588 | #endif |
| 11589 | |
| 11590 | /* |
| 11591 | ** If compiling for a processor that lacks floating point support, |
| 11592 | ** substitute integer for floating-point |
| 11593 | */ |
| 11594 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| @@ -11621,13 +11669,16 @@ | |
| 11669 | /* |
| 11670 | ** The default initial allocation for the pagecache when using separate |
| 11671 | ** pagecaches for each database connection. A positive number is the |
| 11672 | ** number of pages. A negative number N translations means that a buffer |
| 11673 | ** of -1024*N bytes is allocated and used for as many pages as it will hold. |
| 11674 | ** |
| 11675 | ** The default value of "20" was choosen to minimize the run-time of the |
| 11676 | ** speedtest1 test program with options: --shrink-memory --reprepare |
| 11677 | */ |
| 11678 | #ifndef SQLITE_DEFAULT_PCACHE_INITSZ |
| 11679 | # define SQLITE_DEFAULT_PCACHE_INITSZ 20 |
| 11680 | #endif |
| 11681 | |
| 11682 | /* |
| 11683 | ** GCC does not define the offsetof() macro so we'll have to do it |
| 11684 | ** ourselves. |
| @@ -12346,13 +12397,14 @@ | |
| 12397 | ); |
| 12398 | SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor*); |
| 12399 | SQLITE_PRIVATE int sqlite3BtreeCursorRestore(BtCursor*, int*); |
| 12400 | SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags); |
| 12401 | |
| 12402 | /* Allowed flags for sqlite3BtreeDelete() and sqlite3BtreeInsert() */ |
| 12403 | #define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */ |
| 12404 | #define BTREE_AUXDELETE 0x04 /* not the primary delete operation */ |
| 12405 | #define BTREE_APPEND 0x08 /* Insert is likely an append */ |
| 12406 | |
| 12407 | /* An instance of the BtreePayload object describes the content of a single |
| 12408 | ** entry in either an index or table btree. |
| 12409 | ** |
| 12410 | ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain |
| @@ -12379,11 +12431,11 @@ | |
| 12431 | int nData; /* Size of pData. 0 if none. */ |
| 12432 | int nZero; /* Extra zero data appended after pData,nData */ |
| 12433 | }; |
| 12434 | |
| 12435 | SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload, |
| 12436 | int flags, int seekResult); |
| 12437 | SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes); |
| 12438 | SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| 12439 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes); |
| 12440 | SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); |
| 12441 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes); |
| @@ -12512,12 +12564,11 @@ | |
| 12564 | ** as an instance of the following structure: |
| 12565 | */ |
| 12566 | struct VdbeOp { |
| 12567 | u8 opcode; /* What operation to perform */ |
| 12568 | signed char p4type; /* One of the P4_xxx constants for p4 */ |
| 12569 | u16 p5; /* Fifth parameter is an unsigned 16-bit integer */ |
| 12570 | int p1; /* First operand */ |
| 12571 | int p2; /* Second parameter (often the jump destination) */ |
| 12572 | int p3; /* The third parameter */ |
| 12573 | union p4union { /* fourth parameter */ |
| 12574 | int i; /* Integer value if p4type==P4_INT32 */ |
| @@ -12874,11 +12925,11 @@ | |
| 12925 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*); |
| 12926 | SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8); |
| 12927 | SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1); |
| 12928 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 12929 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 12930 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u16 P5); |
| 12931 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 12932 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 12933 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 12934 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 12935 | SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type); |
| @@ -13176,18 +13227,20 @@ | |
| 13227 | SQLITE_PRIVATE int sqlite3PagerCheckpoint(Pager *pPager, sqlite3*, int, int*, int*); |
| 13228 | SQLITE_PRIVATE int sqlite3PagerWalSupported(Pager *pPager); |
| 13229 | SQLITE_PRIVATE int sqlite3PagerWalCallback(Pager *pPager); |
| 13230 | SQLITE_PRIVATE int sqlite3PagerOpenWal(Pager *pPager, int *pisOpen); |
| 13231 | SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 13232 | # ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 13233 | SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno); |
| 13234 | # endif |
| 13235 | # ifdef SQLITE_ENABLE_SNAPSHOT |
| 13236 | SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot); |
| 13237 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 13238 | SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager); |
| 13239 | # endif |
| 13240 | #else |
| 13241 | # define sqlite3PagerUseWal(x,y) 0 |
| 13242 | #endif |
| 13243 | |
| 13244 | #ifdef SQLITE_ENABLE_ZIPVFS |
| 13245 | SQLITE_PRIVATE int sqlite3PagerWalFramesize(Pager *pPager); |
| 13246 | #endif |
| @@ -14007,10 +14060,11 @@ | |
| 14060 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| 14061 | u8 suppressErr; /* Do not issue error messages if true */ |
| 14062 | u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ |
| 14063 | u8 isTransactionSavepoint; /* True if the outermost savepoint is a TS */ |
| 14064 | u8 mTrace; /* zero or more SQLITE_TRACE flags */ |
| 14065 | u8 skipBtreeMutex; /* True if no shared-cache backends */ |
| 14066 | int nextPagesize; /* Pagesize after VACUUM if >0 */ |
| 14067 | u32 magic; /* Magic number for detect library misuse */ |
| 14068 | int nChange; /* Value returned by sqlite3_changes() */ |
| 14069 | int nTotalChange; /* Value returned by sqlite3_total_changes() */ |
| 14070 | int aLimit[SQLITE_N_LIMIT]; /* Limits */ |
| @@ -14272,10 +14326,11 @@ | |
| 14326 | #define SQLITE_FUNC_UNLIKELY 0x0400 /* Built-in unlikely() function */ |
| 14327 | #define SQLITE_FUNC_CONSTANT 0x0800 /* Constant inputs give a constant output */ |
| 14328 | #define SQLITE_FUNC_MINMAX 0x1000 /* True for min() and max() aggregates */ |
| 14329 | #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a |
| 14330 | ** single query - might change over time */ |
| 14331 | #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */ |
| 14332 | |
| 14333 | /* |
| 14334 | ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 14335 | ** used to create the initializers for the FuncDef structures. |
| 14336 | ** |
| @@ -15278,11 +15333,11 @@ | |
| 15333 | #define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */ |
| 15334 | #define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */ |
| 15335 | #define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */ |
| 15336 | #define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */ |
| 15337 | #define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */ |
| 15338 | #define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */ |
| 15339 | /* 0x2000 not currently used */ |
| 15340 | #define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */ |
| 15341 | /* 0x8000 not currently used */ |
| 15342 | |
| 15343 | /* Allowed return values from sqlite3WhereIsDistinct() |
| @@ -15739,25 +15794,23 @@ | |
| 15794 | ** OPFLAG_AUXDELETE == BTREE_AUXDELETE |
| 15795 | */ |
| 15796 | #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */ |
| 15797 | /* Also used in P2 (not P5) of OP_Delete */ |
| 15798 | #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */ |
| 15799 | #define OPFLAG_LASTROWID 0x20 /* Set to update db->lastRowid */ |
| 15800 | #define OPFLAG_ISUPDATE 0x04 /* This OP_Insert is an sql UPDATE */ |
| 15801 | #define OPFLAG_APPEND 0x08 /* This is likely to be an append */ |
| 15802 | #define OPFLAG_USESEEKRESULT 0x10 /* Try to avoid a seek in BtreeInsert() */ |
| 15803 | #define OPFLAG_ISNOOP 0x40 /* OP_Delete does pre-update-hook only */ |
| 15804 | #define OPFLAG_LENGTHARG 0x40 /* OP_Column only used for length() */ |
| 15805 | #define OPFLAG_TYPEOFARG 0x80 /* OP_Column only used for typeof() */ |
| 15806 | #define OPFLAG_BULKCSR 0x01 /* OP_Open** used to open bulk cursor */ |
| 15807 | #define OPFLAG_SEEKEQ 0x02 /* OP_Open** cursor uses EQ seek only */ |
| 15808 | #define OPFLAG_FORDELETE 0x08 /* OP_Open should use BTREE_FORDELETE */ |
| 15809 | #define OPFLAG_P2ISREG 0x10 /* P2 to OP_Open** is a register number */ |
| 15810 | #define OPFLAG_PERMUTE 0x01 /* OP_Compare: use the permutation */ |
| 15811 | #define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */ |
| 15812 | #define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */ |
| 15813 | |
| 15814 | /* |
| 15815 | * Each trigger present in the database schema is stored as an instance of |
| 15816 | * struct Trigger. |
| @@ -16414,11 +16467,11 @@ | |
| 16467 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*); |
| 16468 | SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int); |
| 16469 | SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int); |
| 16470 | SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, Expr*, int); |
| 16471 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int); |
| 16472 | SQLITE_PRIVATE int sqlite3ExprCodeAtInit(Parse*, Expr*, int); |
| 16473 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| 16474 | SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int); |
| 16475 | SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int); |
| 16476 | SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8); |
| 16477 | #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ |
| @@ -16476,10 +16529,15 @@ | |
| 16529 | SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*, int); |
| 16530 | SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int); |
| 16531 | SQLITE_PRIVATE void sqlite3ResolvePartIdxLabel(Parse*,int); |
| 16532 | SQLITE_PRIVATE void sqlite3GenerateConstraintChecks(Parse*,Table*,int*,int,int,int,int, |
| 16533 | u8,u8,int,int*,int*); |
| 16534 | #ifdef SQLITE_ENABLE_NULL_TRIM |
| 16535 | SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe*,Table*); |
| 16536 | #else |
| 16537 | # define sqlite3SetMakeRecordP5(A,B) |
| 16538 | #endif |
| 16539 | SQLITE_PRIVATE void sqlite3CompleteInsertion(Parse*,Table*,int,int,int,int*,int,int,int); |
| 16540 | SQLITE_PRIVATE int sqlite3OpenTableAndIndices(Parse*, Table*, int, u8, int, u8*, int*, int*); |
| 16541 | SQLITE_PRIVATE void sqlite3BeginWriteOperation(Parse*, int, int); |
| 16542 | SQLITE_PRIVATE void sqlite3MultiWrite(Parse*); |
| 16543 | SQLITE_PRIVATE void sqlite3MayAbort(Parse*); |
| @@ -16754,12 +16812,14 @@ | |
| 16812 | #endif |
| 16813 | |
| 16814 | /* |
| 16815 | ** The interface to the LEMON-generated parser |
| 16816 | */ |
| 16817 | #ifndef SQLITE_AMALGAMATION |
| 16818 | SQLITE_PRIVATE void *sqlite3ParserAlloc(void*(*)(u64)); |
| 16819 | SQLITE_PRIVATE void sqlite3ParserFree(void*, void(*)(void*)); |
| 16820 | #endif |
| 16821 | SQLITE_PRIVATE void sqlite3Parser(void*, int, Token, Parse*); |
| 16822 | #ifdef YYTRACKMAXSTACKDEPTH |
| 16823 | SQLITE_PRIVATE int sqlite3ParserStackPeak(void*); |
| 16824 | #endif |
| 16825 | |
| @@ -16865,10 +16925,11 @@ | |
| 16925 | #define sqlite3FkActions(a,b,c,d,e,f) |
| 16926 | #define sqlite3FkCheck(a,b,c,d,e,f) |
| 16927 | #define sqlite3FkDropTable(a,b,c) |
| 16928 | #define sqlite3FkOldmask(a,b) 0 |
| 16929 | #define sqlite3FkRequired(a,b,c,d) 0 |
| 16930 | #define sqlite3FkReferences(a) 0 |
| 16931 | #endif |
| 16932 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 16933 | SQLITE_PRIVATE void sqlite3FkDelete(sqlite3 *, Table*); |
| 16934 | SQLITE_PRIVATE int sqlite3FkLocateIndex(Parse*,Table*,FKey*,Index**,int**); |
| 16935 | #else |
| @@ -17193,10 +17254,23 @@ | |
| 17254 | ** setting.) |
| 17255 | */ |
| 17256 | #ifndef SQLITE_STMTJRNL_SPILL |
| 17257 | # define SQLITE_STMTJRNL_SPILL (64*1024) |
| 17258 | #endif |
| 17259 | |
| 17260 | /* |
| 17261 | ** The default lookaside-configuration, the format "SZ,N". SZ is the |
| 17262 | ** number of bytes in each lookaside slot (should be a multiple of 8) |
| 17263 | ** and N is the number of slots. The lookaside-configuration can be |
| 17264 | ** changed as start-time using sqlite3_config(SQLITE_CONFIG_LOOKASIDE) |
| 17265 | ** or at run-time for an individual database connection using |
| 17266 | ** sqlite3_db_config(db, SQLITE_DBCONFIG_LOOKASIDE); |
| 17267 | */ |
| 17268 | #ifndef SQLITE_DEFAULT_LOOKASIDE |
| 17269 | # define SQLITE_DEFAULT_LOOKASIDE 1200,100 |
| 17270 | #endif |
| 17271 | |
| 17272 | |
| 17273 | /* |
| 17274 | ** The following singleton contains the global configuration for |
| 17275 | ** the SQLite library. |
| 17276 | */ |
| @@ -17206,12 +17280,11 @@ | |
| 17280 | SQLITE_THREADSAFE==1, /* bFullMutex */ |
| 17281 | SQLITE_USE_URI, /* bOpenUri */ |
| 17282 | SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */ |
| 17283 | 0x7ffffffe, /* mxStrlen */ |
| 17284 | 0, /* neverCorrupt */ |
| 17285 | SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */ |
| 17286 | SQLITE_STMTJRNL_SPILL, /* nStmtSpill */ |
| 17287 | {0,0,0,0,0,0,0,0}, /* m */ |
| 17288 | {0,0,0,0,0,0,0,0,0}, /* mutex */ |
| 17289 | {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */ |
| 17290 | (void*)0, /* pHeap */ |
| @@ -18219,10 +18292,11 @@ | |
| 18292 | int iNewReg; /* Register for new.* values */ |
| 18293 | i64 iKey1; /* First key value passed to hook */ |
| 18294 | i64 iKey2; /* Second key value passed to hook */ |
| 18295 | Mem *aNew; /* Array of new.* values */ |
| 18296 | Table *pTab; /* Schema object being upated */ |
| 18297 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 18298 | }; |
| 18299 | |
| 18300 | /* |
| 18301 | ** Function prototypes |
| 18302 | */ |
| @@ -24283,39 +24357,38 @@ | |
| 24357 | |
| 24358 | /* |
| 24359 | ** Do a memory allocation with statistics and alarms. Assume the |
| 24360 | ** lock is already held. |
| 24361 | */ |
| 24362 | static void mallocWithAlarm(int n, void **pp){ |
| 24363 | void *p; |
| 24364 | int nFull = 0; |
| 24365 | assert( sqlite3_mutex_held(mem0.mutex) ); |
| 24366 | sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n); |
| 24367 | if( mem0.alarmThreshold>0 ){ |
| 24368 | sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 24369 | nFull = sqlite3GlobalConfig.m.xRoundup(n); |
| 24370 | if( nUsed >= mem0.alarmThreshold - nFull ){ |
| 24371 | mem0.nearlyFull = 1; |
| 24372 | sqlite3MallocAlarm(nFull); |
| 24373 | }else{ |
| 24374 | mem0.nearlyFull = 0; |
| 24375 | } |
| 24376 | } |
| 24377 | p = sqlite3GlobalConfig.m.xMalloc(n); |
| 24378 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 24379 | if( p==0 && mem0.alarmThreshold>0 ){ |
| 24380 | sqlite3MallocAlarm(nFull); |
| 24381 | p = sqlite3GlobalConfig.m.xMalloc(n); |
| 24382 | } |
| 24383 | #endif |
| 24384 | if( p ){ |
| 24385 | nFull = sqlite3MallocSize(p); |
| 24386 | sqlite3StatusUp(SQLITE_STATUS_MEMORY_USED, nFull); |
| 24387 | sqlite3StatusUp(SQLITE_STATUS_MALLOC_COUNT, 1); |
| 24388 | } |
| 24389 | *pp = p; |
| 24390 | } |
| 24391 | |
| 24392 | /* |
| 24393 | ** Allocate memory. This routine is like sqlite3_malloc() except that it |
| 24394 | ** assumes the memory subsystem has already been initialized. |
| @@ -24951,11 +25024,10 @@ | |
| 25024 | |
| 25025 | /* |
| 25026 | ** Allowed values for et_info.flags |
| 25027 | */ |
| 25028 | #define FLAG_SIGNED 1 /* True if the value to convert is signed */ |
| 25029 | #define FLAG_STRING 4 /* Allow infinity precision */ |
| 25030 | |
| 25031 | |
| 25032 | /* |
| 25033 | ** The following table is searched linearly, so it is good to put the |
| @@ -24985,15 +25057,14 @@ | |
| 25057 | { 'i', 10, 1, etRADIX, 0, 0 }, |
| 25058 | { 'n', 0, 0, etSIZE, 0, 0 }, |
| 25059 | { '%', 0, 0, etPERCENT, 0, 0 }, |
| 25060 | { 'p', 16, 0, etPOINTER, 0, 1 }, |
| 25061 | |
| 25062 | /* All the rest are undocumented and are for internal use only */ |
| 25063 | { 'T', 0, 0, etTOKEN, 0, 0 }, |
| 25064 | { 'S', 0, 0, etSRCLIST, 0, 0 }, |
| 25065 | { 'r', 10, 1, etORDINAL, 0, 0 }, |
| 25066 | }; |
| 25067 | |
| 25068 | /* |
| 25069 | ** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point |
| 25070 | ** conversions will work. |
| @@ -25083,11 +25154,10 @@ | |
| 25154 | etByte flag_long; /* True if "l" flag is present */ |
| 25155 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 25156 | etByte done; /* Loop termination flag */ |
| 25157 | etByte xtype = etINVALID; /* Conversion paradigm */ |
| 25158 | u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ |
| 25159 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 25160 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 25161 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| 25162 | const et_info *infop; /* Pointer to the appropriate info structure */ |
| 25163 | char *zOut; /* Rendering buffer */ |
| @@ -25102,17 +25172,15 @@ | |
| 25172 | #endif |
| 25173 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 25174 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 25175 | |
| 25176 | bufpt = 0; |
| 25177 | if( (pAccum->printfFlags & SQLITE_PRINTF_SQLFUNC)!=0 ){ |
| 25178 | pArgList = va_arg(ap, PrintfArguments*); |
| 25179 | bArgList = 1; |
| 25180 | }else{ |
| 25181 | bArgList = 0; |
| 25182 | } |
| 25183 | for(; (c=(*fmt))!=0; ++fmt){ |
| 25184 | if( c!='%' ){ |
| 25185 | bufpt = (char *)fmt; |
| 25186 | #if HAVE_STRCHRNUL |
| @@ -25220,15 +25288,11 @@ | |
| 25288 | infop = &fmtinfo[0]; |
| 25289 | xtype = etINVALID; |
| 25290 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| 25291 | if( c==fmtinfo[idx].fmttype ){ |
| 25292 | infop = &fmtinfo[idx]; |
| 25293 | xtype = infop->type; |
| 25294 | break; |
| 25295 | } |
| 25296 | } |
| 25297 | |
| 25298 | /* |
| @@ -25593,22 +25657,28 @@ | |
| 25657 | ** consume, not the length of the output... |
| 25658 | ** if( precision>=0 && precision<length ) length = precision; */ |
| 25659 | break; |
| 25660 | } |
| 25661 | case etTOKEN: { |
| 25662 | Token *pToken; |
| 25663 | if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; |
| 25664 | pToken = va_arg(ap, Token*); |
| 25665 | assert( bArgList==0 ); |
| 25666 | if( pToken && pToken->n ){ |
| 25667 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
| 25668 | } |
| 25669 | length = width = 0; |
| 25670 | break; |
| 25671 | } |
| 25672 | case etSRCLIST: { |
| 25673 | SrcList *pSrc; |
| 25674 | int k; |
| 25675 | struct SrcList_item *pItem; |
| 25676 | if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return; |
| 25677 | pSrc = va_arg(ap, SrcList*); |
| 25678 | k = va_arg(ap, int); |
| 25679 | pItem = &pSrc->a[k]; |
| 25680 | assert( bArgList==0 ); |
| 25681 | assert( k>=0 && k<pSrc->nSrc ); |
| 25682 | if( pItem->zDatabase ){ |
| 25683 | sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); |
| 25684 | sqlite3StrAccumAppend(pAccum, ".", 1); |
| @@ -25626,13 +25696,17 @@ | |
| 25696 | ** The text of the conversion is pointed to by "bufpt" and is |
| 25697 | ** "length" characters long. The field width is "width". Do |
| 25698 | ** the output. |
| 25699 | */ |
| 25700 | width -= length; |
| 25701 | if( width>0 ){ |
| 25702 | if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); |
| 25703 | sqlite3StrAccumAppend(pAccum, bufpt, length); |
| 25704 | if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' '); |
| 25705 | }else{ |
| 25706 | sqlite3StrAccumAppend(pAccum, bufpt, length); |
| 25707 | } |
| 25708 | |
| 25709 | if( zExtra ){ |
| 25710 | sqlite3DbFree(pAccum->db, zExtra); |
| 25711 | zExtra = 0; |
| 25712 | } |
| @@ -28601,11 +28675,11 @@ | |
| 28675 | #if SQLITE_BYTEORDER==4321 |
| 28676 | u32 x; |
| 28677 | memcpy(&x,p,4); |
| 28678 | return x; |
| 28679 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28680 | && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 28681 | u32 x; |
| 28682 | memcpy(&x,p,4); |
| 28683 | return __builtin_bswap32(x); |
| 28684 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28685 | && defined(_MSC_VER) && _MSC_VER>=1300 |
| @@ -28619,11 +28693,11 @@ | |
| 28693 | } |
| 28694 | SQLITE_PRIVATE void sqlite3Put4byte(unsigned char *p, u32 v){ |
| 28695 | #if SQLITE_BYTEORDER==4321 |
| 28696 | memcpy(p,&v,4); |
| 28697 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28698 | && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 28699 | u32 x = __builtin_bswap32(v); |
| 28700 | memcpy(p,&x,4); |
| 28701 | #elif SQLITE_BYTEORDER==1234 && !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28702 | && defined(_MSC_VER) && _MSC_VER>=1300 |
| 28703 | u32 x = _byteswap_ulong(v); |
| @@ -28739,10 +28813,14 @@ | |
| 28813 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 28814 | ** Return 0 on success. Or if the operation would have resulted in an |
| 28815 | ** overflow, leave *pA unchanged and return 1. |
| 28816 | */ |
| 28817 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| 28818 | #if !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28819 | && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) |
| 28820 | return __builtin_add_overflow(*pA, iB, pA); |
| 28821 | #else |
| 28822 | i64 iA = *pA; |
| 28823 | testcase( iA==0 ); testcase( iA==1 ); |
| 28824 | testcase( iB==-1 ); testcase( iB==0 ); |
| 28825 | if( iB>=0 ){ |
| 28826 | testcase( iA>0 && LARGEST_INT64 - iA == iB ); |
| @@ -28753,23 +28831,33 @@ | |
| 28831 | testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 ); |
| 28832 | if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1; |
| 28833 | } |
| 28834 | *pA += iB; |
| 28835 | return 0; |
| 28836 | #endif |
| 28837 | } |
| 28838 | SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){ |
| 28839 | #if !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28840 | && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) |
| 28841 | return __builtin_sub_overflow(*pA, iB, pA); |
| 28842 | #else |
| 28843 | testcase( iB==SMALLEST_INT64+1 ); |
| 28844 | if( iB==SMALLEST_INT64 ){ |
| 28845 | testcase( (*pA)==(-1) ); testcase( (*pA)==0 ); |
| 28846 | if( (*pA)>=0 ) return 1; |
| 28847 | *pA -= iB; |
| 28848 | return 0; |
| 28849 | }else{ |
| 28850 | return sqlite3AddInt64(pA, -iB); |
| 28851 | } |
| 28852 | #endif |
| 28853 | } |
| 28854 | SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){ |
| 28855 | #if !defined(SQLITE_DISABLE_INTRINSIC) \ |
| 28856 | && (GCC_VERSION>=5004000 || CLANG_VERSION>=4000000) |
| 28857 | return __builtin_mul_overflow(*pA, iB, pA); |
| 28858 | #else |
| 28859 | i64 iA = *pA; |
| 28860 | if( iB>0 ){ |
| 28861 | if( iA>LARGEST_INT64/iB ) return 1; |
| 28862 | if( iA<SMALLEST_INT64/iB ) return 1; |
| 28863 | }else if( iB<0 ){ |
| @@ -28781,10 +28869,11 @@ | |
| 28869 | if( -iA>LARGEST_INT64/-iB ) return 1; |
| 28870 | } |
| 28871 | } |
| 28872 | *pA = iA*iB; |
| 28873 | return 0; |
| 28874 | #endif |
| 28875 | } |
| 28876 | |
| 28877 | /* |
| 28878 | ** Compute the absolute value of a 32-bit signed integer, of possible. Or |
| 28879 | ** if the integer has a value of -2147483648, return +2147483647 |
| @@ -47485,18 +47574,24 @@ | |
| 47574 | ** if( pPager->jfd->pMethods ){ ... |
| 47575 | */ |
| 47576 | #define isOpen(pFd) ((pFd)->pMethods!=0) |
| 47577 | |
| 47578 | /* |
| 47579 | ** Return true if this pager uses a write-ahead log to read page pgno. |
| 47580 | ** Return false if the pager reads pgno directly from the database. |
| 47581 | */ |
| 47582 | #if !defined(SQLITE_OMIT_WAL) && defined(SQLITE_DIRECT_OVERFLOW_READ) |
| 47583 | SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager, Pgno pgno){ |
| 47584 | u32 iRead = 0; |
| 47585 | int rc; |
| 47586 | if( pPager->pWal==0 ) return 0; |
| 47587 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead); |
| 47588 | return rc || iRead; |
| 47589 | } |
| 47590 | #endif |
| 47591 | #ifndef SQLITE_OMIT_WAL |
| 47592 | # define pagerUseWal(x) ((x)->pWal!=0) |
| 47593 | #else |
| 47594 | # define pagerUseWal(x) 0 |
| 47595 | # define pagerRollbackWal(x) 0 |
| 47596 | # define pagerWalFrames(v,w,x,y) 0 |
| 47597 | # define pagerOpenWalIfPresent(z) SQLITE_OK |
| @@ -58624,27 +58719,38 @@ | |
| 58719 | ** Enter the mutexes in accending order by BtShared pointer address |
| 58720 | ** to avoid the possibility of deadlock when two threads with |
| 58721 | ** two or more btrees in common both try to lock all their btrees |
| 58722 | ** at the same instant. |
| 58723 | */ |
| 58724 | static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){ |
| 58725 | int i; |
| 58726 | int skipOk = 1; |
| 58727 | Btree *p; |
| 58728 | assert( sqlite3_mutex_held(db->mutex) ); |
| 58729 | for(i=0; i<db->nDb; i++){ |
| 58730 | p = db->aDb[i].pBt; |
| 58731 | if( p && p->sharable ){ |
| 58732 | sqlite3BtreeEnter(p); |
| 58733 | skipOk = 0; |
| 58734 | } |
| 58735 | } |
| 58736 | db->skipBtreeMutex = skipOk; |
| 58737 | } |
| 58738 | SQLITE_PRIVATE void sqlite3BtreeEnterAll(sqlite3 *db){ |
| 58739 | if( db->skipBtreeMutex==0 ) btreeEnterAll(db); |
| 58740 | } |
| 58741 | static void SQLITE_NOINLINE btreeLeaveAll(sqlite3 *db){ |
| 58742 | int i; |
| 58743 | Btree *p; |
| 58744 | assert( sqlite3_mutex_held(db->mutex) ); |
| 58745 | for(i=0; i<db->nDb; i++){ |
| 58746 | p = db->aDb[i].pBt; |
| 58747 | if( p ) sqlite3BtreeLeave(p); |
| 58748 | } |
| 58749 | } |
| 58750 | SQLITE_PRIVATE void sqlite3BtreeLeaveAll(sqlite3 *db){ |
| 58751 | if( db->skipBtreeMutex==0 ) btreeLeaveAll(db); |
| 58752 | } |
| 58753 | |
| 58754 | #ifndef NDEBUG |
| 58755 | /* |
| 58756 | ** Return true if the current thread holds the database connection |
| @@ -62097,16 +62203,18 @@ | |
| 62203 | for(i=0; i<nCell; i++){ |
| 62204 | u8 *pCell = findCell(pPage, i); |
| 62205 | if( eType==PTRMAP_OVERFLOW1 ){ |
| 62206 | CellInfo info; |
| 62207 | pPage->xParseCell(pPage, pCell, &info); |
| 62208 | if( info.nLocal<info.nPayload ){ |
| 62209 | if( pCell+info.nSize > pPage->aData+pPage->pBt->usableSize ){ |
| 62210 | return SQLITE_CORRUPT_BKPT; |
| 62211 | } |
| 62212 | if( iFrom==get4byte(pCell+info.nSize-4) ){ |
| 62213 | put4byte(pCell+info.nSize-4, iTo); |
| 62214 | break; |
| 62215 | } |
| 62216 | } |
| 62217 | }else{ |
| 62218 | if( get4byte(pCell)==iFrom ){ |
| 62219 | put4byte(pCell, iTo); |
| 62220 | break; |
| @@ -62777,11 +62885,16 @@ | |
| 62885 | if( p && p->inTrans==TRANS_WRITE ){ |
| 62886 | BtShared *pBt = p->pBt; |
| 62887 | assert( op==SAVEPOINT_RELEASE || op==SAVEPOINT_ROLLBACK ); |
| 62888 | assert( iSavepoint>=0 || (iSavepoint==-1 && op==SAVEPOINT_ROLLBACK) ); |
| 62889 | sqlite3BtreeEnter(p); |
| 62890 | if( op==SAVEPOINT_ROLLBACK ){ |
| 62891 | rc = saveAllCursors(pBt, 0, 0); |
| 62892 | } |
| 62893 | if( rc==SQLITE_OK ){ |
| 62894 | rc = sqlite3PagerSavepoint(pBt->pPager, op, iSavepoint); |
| 62895 | } |
| 62896 | if( rc==SQLITE_OK ){ |
| 62897 | if( iSavepoint<0 && (pBt->btsFlags & BTS_INITIALLY_EMPTY)!=0 ){ |
| 62898 | pBt->nPage = 0; |
| 62899 | } |
| 62900 | rc = newDatabase(pBt); |
| @@ -63163,25 +63276,24 @@ | |
| 63276 | ** for the entry that the pCur cursor is pointing to. The eOp |
| 63277 | ** argument is interpreted as follows: |
| 63278 | ** |
| 63279 | ** 0: The operation is a read. Populate the overflow cache. |
| 63280 | ** 1: The operation is a write. Populate the overflow cache. |
| 63281 | ** |
| 63282 | ** A total of "amt" bytes are read or written beginning at "offset". |
| 63283 | ** Data is read to or from the buffer pBuf. |
| 63284 | ** |
| 63285 | ** The content being read or written might appear on the main page |
| 63286 | ** or be scattered out on multiple overflow pages. |
| 63287 | ** |
| 63288 | ** If the current cursor entry uses one or more overflow pages |
| 63289 | ** this function may allocate space for and lazily populate |
| 63290 | ** the overflow page-list cache array (BtCursor.aOverflow). |
| 63291 | ** Subsequent calls use this cache to make seeking to the supplied offset |
| 63292 | ** more efficient. |
| 63293 | ** |
| 63294 | ** Once an overflow page-list cache has been allocated, it must be |
| 63295 | ** invalidated if some other cursor writes to the same table, or if |
| 63296 | ** the cursor is moved to a different row. Additionally, in auto-vacuum |
| 63297 | ** mode, the following events may invalidate an overflow page-list cache. |
| 63298 | ** |
| 63299 | ** * An incremental vacuum, |
| @@ -63199,25 +63311,21 @@ | |
| 63311 | int rc = SQLITE_OK; |
| 63312 | int iIdx = 0; |
| 63313 | MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */ |
| 63314 | BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */ |
| 63315 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63316 | unsigned char * const pBufStart = pBuf; /* Start of original out buffer */ |
| 63317 | #endif |
| 63318 | |
| 63319 | assert( pPage ); |
| 63320 | assert( eOp==0 || eOp==1 ); |
| 63321 | assert( pCur->eState==CURSOR_VALID ); |
| 63322 | assert( pCur->aiIdx[pCur->iPage]<pPage->nCell ); |
| 63323 | assert( cursorHoldsMutex(pCur) ); |
| 63324 | |
| 63325 | getCellInfo(pCur); |
| 63326 | aPayload = pCur->info.pPayload; |
| 63327 | assert( offset+amt <= pCur->info.nPayload ); |
| 63328 | |
| 63329 | assert( aPayload > pPage->aData ); |
| 63330 | if( (uptr)(aPayload - pPage->aData) > (pBt->usableSize - pCur->info.nLocal) ){ |
| 63331 | /* Trying to read or write past the end of the data is an error. The |
| @@ -63232,11 +63340,11 @@ | |
| 63340 | if( offset<pCur->info.nLocal ){ |
| 63341 | int a = amt; |
| 63342 | if( a+offset>pCur->info.nLocal ){ |
| 63343 | a = pCur->info.nLocal - offset; |
| 63344 | } |
| 63345 | rc = copyPayload(&aPayload[offset], pBuf, a, eOp, pPage->pDbPage); |
| 63346 | offset = 0; |
| 63347 | pBuf += a; |
| 63348 | amt -= a; |
| 63349 | }else{ |
| 63350 | offset -= pCur->info.nLocal; |
| @@ -63248,69 +63356,58 @@ | |
| 63356 | Pgno nextPage; |
| 63357 | |
| 63358 | nextPage = get4byte(&aPayload[pCur->info.nLocal]); |
| 63359 | |
| 63360 | /* If the BtCursor.aOverflow[] has not been allocated, allocate it now. |
| 63361 | ** |
| 63362 | ** The aOverflow[] array is sized at one entry for each overflow page |
| 63363 | ** in the overflow chain. The page number of the first overflow page is |
| 63364 | ** stored in aOverflow[0], etc. A value of 0 in the aOverflow[] array |
| 63365 | ** means "not yet known" (the cache is lazily populated). |
| 63366 | */ |
| 63367 | if( (pCur->curFlags & BTCF_ValidOvfl)==0 ){ |
| 63368 | int nOvfl = (pCur->info.nPayload-pCur->info.nLocal+ovflSize-1)/ovflSize; |
| 63369 | if( nOvfl>pCur->nOvflAlloc ){ |
| 63370 | Pgno *aNew = (Pgno*)sqlite3Realloc( |
| 63371 | pCur->aOverflow, nOvfl*2*sizeof(Pgno) |
| 63372 | ); |
| 63373 | if( aNew==0 ){ |
| 63374 | return SQLITE_NOMEM_BKPT; |
| 63375 | }else{ |
| 63376 | pCur->nOvflAlloc = nOvfl*2; |
| 63377 | pCur->aOverflow = aNew; |
| 63378 | } |
| 63379 | } |
| 63380 | memset(pCur->aOverflow, 0, nOvfl*sizeof(Pgno)); |
| 63381 | pCur->curFlags |= BTCF_ValidOvfl; |
| 63382 | }else{ |
| 63383 | /* If the overflow page-list cache has been allocated and the |
| 63384 | ** entry for the first required overflow page is valid, skip |
| 63385 | ** directly to it. |
| 63386 | */ |
| 63387 | if( pCur->aOverflow[offset/ovflSize] ){ |
| 63388 | iIdx = (offset/ovflSize); |
| 63389 | nextPage = pCur->aOverflow[iIdx]; |
| 63390 | offset = (offset%ovflSize); |
| 63391 | } |
| 63392 | } |
| 63393 | |
| 63394 | assert( rc==SQLITE_OK && amt>0 ); |
| 63395 | while( nextPage ){ |
| 63396 | /* If required, populate the overflow page-list cache. */ |
| 63397 | assert( pCur->aOverflow[iIdx]==0 |
| 63398 | || pCur->aOverflow[iIdx]==nextPage |
| 63399 | || CORRUPT_DB ); |
| 63400 | pCur->aOverflow[iIdx] = nextPage; |
| 63401 | |
| 63402 | if( offset>=ovflSize ){ |
| 63403 | /* The only reason to read this page is to obtain the page |
| 63404 | ** number for the next page in the overflow chain. The page |
| 63405 | ** data is not required. So first try to lookup the overflow |
| 63406 | ** page-list cache, if any, then fall back to the getOverflowPage() |
| 63407 | ** function. |
| 63408 | */ |
| 63409 | assert( pCur->curFlags & BTCF_ValidOvfl ); |
| 63410 | assert( pCur->pBtree->db==pBt->db ); |
| 63411 | if( pCur->aOverflow[iIdx+1] ){ |
| 63412 | nextPage = pCur->aOverflow[iIdx+1]; |
| 63413 | }else{ |
| @@ -63320,11 +63417,11 @@ | |
| 63417 | }else{ |
| 63418 | /* Need to read this page properly. It contains some of the |
| 63419 | ** range of data that is being read (eOp==0) or written (eOp!=0). |
| 63420 | */ |
| 63421 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63422 | sqlite3_file *fd; /* File from which to do direct overflow read */ |
| 63423 | #endif |
| 63424 | int a = amt; |
| 63425 | if( a + offset > ovflSize ){ |
| 63426 | a = ovflSize - offset; |
| 63427 | } |
| @@ -63332,31 +63429,29 @@ | |
| 63429 | #ifdef SQLITE_DIRECT_OVERFLOW_READ |
| 63430 | /* If all the following are true: |
| 63431 | ** |
| 63432 | ** 1) this is a read operation, and |
| 63433 | ** 2) data is required from the start of this overflow page, and |
| 63434 | ** 3) there is no open write-transaction, and |
| 63435 | ** 4) the database is file-backed, and |
| 63436 | ** 5) the page is not in the WAL file |
| 63437 | ** 6) at least 4 bytes have already been read into the output buffer |
| 63438 | ** |
| 63439 | ** then data can be read directly from the database file into the |
| 63440 | ** output buffer, bypassing the page-cache altogether. This speeds |
| 63441 | ** up loading large records that span many overflow pages. |
| 63442 | */ |
| 63443 | if( eOp==0 /* (1) */ |
| 63444 | && offset==0 /* (2) */ |
| 63445 | && pBt->inTransaction==TRANS_READ /* (3) */ |
| 63446 | && (fd = sqlite3PagerFile(pBt->pPager))->pMethods /* (4) */ |
| 63447 | && 0==sqlite3PagerUseWal(pBt->pPager, nextPage) /* (5) */ |
| 63448 | && &pBuf[-4]>=pBufStart /* (6) */ |
| 63449 | ){ |
| 63450 | u8 aSave[4]; |
| 63451 | u8 *aWrite = &pBuf[-4]; |
| 63452 | assert( aWrite>=pBufStart ); /* due to (6) */ |
| 63453 | memcpy(aSave, aWrite, 4); |
| 63454 | rc = sqlite3OsRead(fd, aWrite, a+4, (i64)pBt->pageSize*(nextPage-1)); |
| 63455 | nextPage = get4byte(aWrite); |
| 63456 | memcpy(aWrite, aSave, 4); |
| 63457 | }else |
| @@ -63363,28 +63458,31 @@ | |
| 63458 | #endif |
| 63459 | |
| 63460 | { |
| 63461 | DbPage *pDbPage; |
| 63462 | rc = sqlite3PagerGet(pBt->pPager, nextPage, &pDbPage, |
| 63463 | (eOp==0 ? PAGER_GET_READONLY : 0) |
| 63464 | ); |
| 63465 | if( rc==SQLITE_OK ){ |
| 63466 | aPayload = sqlite3PagerGetData(pDbPage); |
| 63467 | nextPage = get4byte(aPayload); |
| 63468 | rc = copyPayload(&aPayload[offset+4], pBuf, a, eOp, pDbPage); |
| 63469 | sqlite3PagerUnref(pDbPage); |
| 63470 | offset = 0; |
| 63471 | } |
| 63472 | } |
| 63473 | amt -= a; |
| 63474 | if( amt==0 ) return rc; |
| 63475 | pBuf += a; |
| 63476 | } |
| 63477 | if( rc ) break; |
| 63478 | iIdx++; |
| 63479 | } |
| 63480 | } |
| 63481 | |
| 63482 | if( rc==SQLITE_OK && amt>0 ){ |
| 63483 | return SQLITE_CORRUPT_BKPT; /* Overflow chain ends prematurely */ |
| 63484 | } |
| 63485 | return rc; |
| 63486 | } |
| 63487 | |
| 63488 | /* |
| @@ -63409,25 +63507,38 @@ | |
| 63507 | assert( pCur->eState==CURSOR_VALID ); |
| 63508 | assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] ); |
| 63509 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 63510 | return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); |
| 63511 | } |
| 63512 | |
| 63513 | /* |
| 63514 | ** This variant of sqlite3BtreePayload() works even if the cursor has not |
| 63515 | ** in the CURSOR_VALID state. It is only used by the sqlite3_blob_read() |
| 63516 | ** interface. |
| 63517 | */ |
| 63518 | #ifndef SQLITE_OMIT_INCRBLOB |
| 63519 | static SQLITE_NOINLINE int accessPayloadChecked( |
| 63520 | BtCursor *pCur, |
| 63521 | u32 offset, |
| 63522 | u32 amt, |
| 63523 | void *pBuf |
| 63524 | ){ |
| 63525 | int rc; |
| 63526 | if ( pCur->eState==CURSOR_INVALID ){ |
| 63527 | return SQLITE_ABORT; |
| 63528 | } |
| 63529 | assert( cursorOwnsBtShared(pCur) ); |
| 63530 | rc = btreeRestoreCursorPosition(pCur); |
| 63531 | return rc ? rc : accessPayload(pCur, offset, amt, pBuf, 0); |
| 63532 | } |
| 63533 | SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 63534 | if( pCur->eState==CURSOR_VALID ){ |
| 63535 | assert( cursorOwnsBtShared(pCur) ); |
| 63536 | return accessPayload(pCur, offset, amt, pBuf, 0); |
| 63537 | }else{ |
| 63538 | return accessPayloadChecked(pCur, offset, amt, pBuf); |
| 63539 | } |
| 63540 | } |
| 63541 | #endif /* SQLITE_OMIT_INCRBLOB */ |
| 63542 | |
| 63543 | /* |
| 63544 | ** Return a pointer to payload information from the entry that the |
| @@ -63829,13 +63940,30 @@ | |
| 63940 | ){ |
| 63941 | if( pCur->info.nKey==intKey ){ |
| 63942 | *pRes = 0; |
| 63943 | return SQLITE_OK; |
| 63944 | } |
| 63945 | if( pCur->info.nKey<intKey ){ |
| 63946 | if( (pCur->curFlags & BTCF_AtLast)!=0 ){ |
| 63947 | *pRes = -1; |
| 63948 | return SQLITE_OK; |
| 63949 | } |
| 63950 | /* If the requested key is one more than the previous key, then |
| 63951 | ** try to get there using sqlite3BtreeNext() rather than a full |
| 63952 | ** binary search. This is an optimization only. The correct answer |
| 63953 | ** is still obtained without this ase, only a little more slowely */ |
| 63954 | if( pCur->info.nKey+1==intKey && !pCur->skipNext ){ |
| 63955 | *pRes = 0; |
| 63956 | rc = sqlite3BtreeNext(pCur, pRes); |
| 63957 | if( rc ) return rc; |
| 63958 | if( *pRes==0 ){ |
| 63959 | getCellInfo(pCur); |
| 63960 | if( pCur->info.nKey==intKey ){ |
| 63961 | return SQLITE_OK; |
| 63962 | } |
| 63963 | } |
| 63964 | } |
| 63965 | } |
| 63966 | } |
| 63967 | |
| 63968 | if( pIdxKey ){ |
| 63969 | xRecordCompare = sqlite3VdbeFindCompare(pIdxKey); |
| @@ -63967,11 +64095,12 @@ | |
| 64095 | if( pCellKey==0 ){ |
| 64096 | rc = SQLITE_NOMEM_BKPT; |
| 64097 | goto moveto_finish; |
| 64098 | } |
| 64099 | pCur->aiIdx[pCur->iPage] = (u16)idx; |
| 64100 | rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0); |
| 64101 | pCur->curFlags &= ~BTCF_ValidOvfl; |
| 64102 | if( rc ){ |
| 64103 | sqlite3_free(pCellKey); |
| 64104 | goto moveto_finish; |
| 64105 | } |
| 64106 | c = xRecordCompare(nCell, pCellKey, pIdxKey); |
| @@ -66010,11 +66139,10 @@ | |
| 66139 | */ |
| 66140 | usableSpace = pBt->usableSize - 12 + leafCorrection; |
| 66141 | for(i=0; i<nOld; i++){ |
| 66142 | MemPage *p = apOld[i]; |
| 66143 | szNew[i] = usableSpace - p->nFree; |
| 66144 | for(j=0; j<p->nOverflow; j++){ |
| 66145 | szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]); |
| 66146 | } |
| 66147 | cntNew[i] = cntOld[i]; |
| 66148 | } |
| @@ -66689,11 +66817,11 @@ | |
| 66817 | ** to decode the key. |
| 66818 | */ |
| 66819 | SQLITE_PRIVATE int sqlite3BtreeInsert( |
| 66820 | BtCursor *pCur, /* Insert data into the table of this cursor */ |
| 66821 | const BtreePayload *pX, /* Content of the row to be inserted */ |
| 66822 | int flags, /* True if this is likely an append */ |
| 66823 | int seekResult /* Result of prior MovetoUnpacked() call */ |
| 66824 | ){ |
| 66825 | int rc; |
| 66826 | int loc = seekResult; /* -1: before desired location +1: after */ |
| 66827 | int szNew = 0; |
| @@ -66701,10 +66829,12 @@ | |
| 66829 | MemPage *pPage; |
| 66830 | Btree *p = pCur->pBtree; |
| 66831 | BtShared *pBt = p->pBt; |
| 66832 | unsigned char *oldCell; |
| 66833 | unsigned char *newCell = 0; |
| 66834 | |
| 66835 | assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND))==flags ); |
| 66836 | |
| 66837 | if( pCur->eState==CURSOR_FAULT ){ |
| 66838 | assert( pCur->skipNext!=SQLITE_OK ); |
| 66839 | return pCur->skipNext; |
| 66840 | } |
| @@ -66742,23 +66872,28 @@ | |
| 66872 | assert( pX->pKey==0 ); |
| 66873 | /* If this is an insert into a table b-tree, invalidate any incrblob |
| 66874 | ** cursors open on the row being replaced */ |
| 66875 | invalidateIncrblobCursors(p, pX->nKey, 0); |
| 66876 | |
| 66877 | /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing |
| 66878 | ** to a row with the same key as the new entry being inserted. */ |
| 66879 | assert( (flags & BTREE_SAVEPOSITION)==0 || |
| 66880 | ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) ); |
| 66881 | |
| 66882 | /* If the cursor is currently on the last row and we are appending a |
| 66883 | ** new row onto the end, set the "loc" to avoid an unnecessary |
| 66884 | ** btreeMoveto() call */ |
| 66885 | if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){ |
| 66886 | loc = 0; |
| 66887 | }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0 |
| 66888 | && pCur->info.nKey==pX->nKey-1 ){ |
| 66889 | loc = -1; |
| 66890 | }else if( loc==0 ){ |
| 66891 | rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc); |
| 66892 | if( rc ) return rc; |
| 66893 | } |
| 66894 | }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){ |
| 66895 | if( pX->nMem ){ |
| 66896 | UnpackedRecord r; |
| 66897 | r.pKeyInfo = pCur->pKeyInfo; |
| 66898 | r.aMem = pX->aMem; |
| 66899 | r.nField = pX->nMem; |
| @@ -66765,13 +66900,13 @@ | |
| 66900 | r.default_rc = 0; |
| 66901 | r.errCode = 0; |
| 66902 | r.r1 = 0; |
| 66903 | r.r2 = 0; |
| 66904 | r.eqSeen = 0; |
| 66905 | rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc); |
| 66906 | }else{ |
| 66907 | rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc); |
| 66908 | } |
| 66909 | if( rc ) return rc; |
| 66910 | } |
| 66911 | assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) ); |
| 66912 | |
| @@ -66855,10 +66990,24 @@ | |
| 66990 | ** fails. Internal data structure corruption will result otherwise. |
| 66991 | ** Also, set the cursor state to invalid. This stops saveCursorPosition() |
| 66992 | ** from trying to save the current position of the cursor. */ |
| 66993 | pCur->apPage[pCur->iPage]->nOverflow = 0; |
| 66994 | pCur->eState = CURSOR_INVALID; |
| 66995 | if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){ |
| 66996 | rc = moveToRoot(pCur); |
| 66997 | if( pCur->pKeyInfo ){ |
| 66998 | assert( pCur->pKey==0 ); |
| 66999 | pCur->pKey = sqlite3Malloc( pX->nKey ); |
| 67000 | if( pCur->pKey==0 ){ |
| 67001 | rc = SQLITE_NOMEM; |
| 67002 | }else{ |
| 67003 | memcpy(pCur->pKey, pX->pKey, pX->nKey); |
| 67004 | } |
| 67005 | } |
| 67006 | pCur->eState = CURSOR_REQUIRESEEK; |
| 67007 | pCur->nKey = pX->nKey; |
| 67008 | } |
| 67009 | } |
| 67010 | assert( pCur->apPage[pCur->iPage]->nOverflow==0 ); |
| 67011 | |
| 67012 | end_insert: |
| 67013 | return rc; |
| @@ -71765,11 +71914,11 @@ | |
| 71914 | sqlite3VdbeGetOp(p,addr)->p2 = val; |
| 71915 | } |
| 71916 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe *p, u32 addr, int val){ |
| 71917 | sqlite3VdbeGetOp(p,addr)->p3 = val; |
| 71918 | } |
| 71919 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){ |
| 71920 | assert( p->nOp>0 || p->db->mallocFailed ); |
| 71921 | if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5; |
| 71922 | } |
| 71923 | |
| 71924 | /* |
| @@ -73479,64 +73628,63 @@ | |
| 73628 | ** statement transaction is committed. |
| 73629 | ** |
| 73630 | ** If an IO error occurs, an SQLITE_IOERR_XXX error code is returned. |
| 73631 | ** Otherwise SQLITE_OK. |
| 73632 | */ |
| 73633 | static SQLITE_NOINLINE int vdbeCloseStatement(Vdbe *p, int eOp){ |
| 73634 | sqlite3 *const db = p->db; |
| 73635 | int rc = SQLITE_OK; |
| 73636 | int i; |
| 73637 | const int iSavepoint = p->iStatement-1; |
| 73638 | |
| 73639 | assert( eOp==SAVEPOINT_ROLLBACK || eOp==SAVEPOINT_RELEASE); |
| 73640 | assert( db->nStatement>0 ); |
| 73641 | assert( p->iStatement==(db->nStatement+db->nSavepoint) ); |
| 73642 | |
| 73643 | for(i=0; i<db->nDb; i++){ |
| 73644 | int rc2 = SQLITE_OK; |
| 73645 | Btree *pBt = db->aDb[i].pBt; |
| 73646 | if( pBt ){ |
| 73647 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| 73648 | rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_ROLLBACK, iSavepoint); |
| 73649 | } |
| 73650 | if( rc2==SQLITE_OK ){ |
| 73651 | rc2 = sqlite3BtreeSavepoint(pBt, SAVEPOINT_RELEASE, iSavepoint); |
| 73652 | } |
| 73653 | if( rc==SQLITE_OK ){ |
| 73654 | rc = rc2; |
| 73655 | } |
| 73656 | } |
| 73657 | } |
| 73658 | db->nStatement--; |
| 73659 | p->iStatement = 0; |
| 73660 | |
| 73661 | if( rc==SQLITE_OK ){ |
| 73662 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| 73663 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_ROLLBACK, iSavepoint); |
| 73664 | } |
| 73665 | if( rc==SQLITE_OK ){ |
| 73666 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_RELEASE, iSavepoint); |
| 73667 | } |
| 73668 | } |
| 73669 | |
| 73670 | /* If the statement transaction is being rolled back, also restore the |
| 73671 | ** database handles deferred constraint counter to the value it had when |
| 73672 | ** the statement transaction was opened. */ |
| 73673 | if( eOp==SAVEPOINT_ROLLBACK ){ |
| 73674 | db->nDeferredCons = p->nStmtDefCons; |
| 73675 | db->nDeferredImmCons = p->nStmtDefImmCons; |
| 73676 | } |
| 73677 | return rc; |
| 73678 | } |
| 73679 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *p, int eOp){ |
| 73680 | if( p->db->nStatement && p->iStatement ){ |
| 73681 | return vdbeCloseStatement(p, eOp); |
| 73682 | } |
| 73683 | return SQLITE_OK; |
| 73684 | } |
| 73685 | |
| 73686 | |
| 73687 | /* |
| 73688 | ** This function is called when a transaction opened by the database |
| 73689 | ** handle associated with the VM passed as an argument is about to be |
| 73690 | ** committed. If there are outstanding deferred foreign key constraint |
| @@ -75567,14 +75715,14 @@ | |
| 75715 | ** structure itself, using sqlite3DbFree(). |
| 75716 | ** |
| 75717 | ** This function is used to free UnpackedRecord structures allocated by |
| 75718 | ** the vdbeUnpackRecord() function found in vdbeapi.c. |
| 75719 | */ |
| 75720 | static void vdbeFreeUnpacked(sqlite3 *db, int nField, UnpackedRecord *p){ |
| 75721 | if( p ){ |
| 75722 | int i; |
| 75723 | for(i=0; i<nField; i++){ |
| 75724 | Mem *pMem = &p->aMem[i]; |
| 75725 | if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem); |
| 75726 | } |
| 75727 | sqlite3DbFree(db, p); |
| 75728 | } |
| @@ -75603,14 +75751,19 @@ | |
| 75751 | const char *zTbl = pTab->zName; |
| 75752 | static const u8 fakeSortOrder = 0; |
| 75753 | |
| 75754 | assert( db->pPreUpdate==0 ); |
| 75755 | memset(&preupdate, 0, sizeof(PreUpdate)); |
| 75756 | if( HasRowid(pTab)==0 ){ |
| 75757 | iKey1 = iKey2 = 0; |
| 75758 | preupdate.pPk = sqlite3PrimaryKeyIndex(pTab); |
| 75759 | }else{ |
| 75760 | if( op==SQLITE_UPDATE ){ |
| 75761 | iKey2 = v->aMem[iReg].u.i; |
| 75762 | }else{ |
| 75763 | iKey2 = iKey1; |
| 75764 | } |
| 75765 | } |
| 75766 | |
| 75767 | assert( pCsr->nField==pTab->nCol |
| 75768 | || (pCsr->nField==pTab->nCol+1 && op==SQLITE_DELETE && iReg==-1) |
| 75769 | ); |
| @@ -75629,12 +75782,12 @@ | |
| 75782 | |
| 75783 | db->pPreUpdate = &preupdate; |
| 75784 | db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2); |
| 75785 | db->pPreUpdate = 0; |
| 75786 | sqlite3DbFree(db, preupdate.aRecord); |
| 75787 | vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked); |
| 75788 | vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked); |
| 75789 | if( preupdate.aNew ){ |
| 75790 | int i; |
| 75791 | for(i=0; i<pCsr->nField; i++){ |
| 75792 | sqlite3VdbeMemRelease(&preupdate.aNew[i]); |
| 75793 | } |
| @@ -77305,18 +77458,22 @@ | |
| 77458 | ** This function is called from within a pre-update callback to retrieve |
| 77459 | ** a field of the row currently being updated or deleted. |
| 77460 | */ |
| 77461 | SQLITE_API int sqlite3_preupdate_old(sqlite3 *db, int iIdx, sqlite3_value **ppValue){ |
| 77462 | PreUpdate *p = db->pPreUpdate; |
| 77463 | Mem *pMem; |
| 77464 | int rc = SQLITE_OK; |
| 77465 | |
| 77466 | /* Test that this call is being made from within an SQLITE_DELETE or |
| 77467 | ** SQLITE_UPDATE pre-update callback, and that iIdx is within range. */ |
| 77468 | if( !p || p->op==SQLITE_INSERT ){ |
| 77469 | rc = SQLITE_MISUSE_BKPT; |
| 77470 | goto preupdate_old_out; |
| 77471 | } |
| 77472 | if( p->pPk ){ |
| 77473 | iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx); |
| 77474 | } |
| 77475 | if( iIdx>=p->pCsr->nField || iIdx<0 ){ |
| 77476 | rc = SQLITE_RANGE; |
| 77477 | goto preupdate_old_out; |
| 77478 | } |
| 77479 | |
| @@ -77338,21 +77495,18 @@ | |
| 77495 | goto preupdate_old_out; |
| 77496 | } |
| 77497 | p->aRecord = aRec; |
| 77498 | } |
| 77499 | |
| 77500 | pMem = *ppValue = &p->pUnpacked->aMem[iIdx]; |
| 77501 | if( iIdx==p->pTab->iPKey ){ |
| 77502 | sqlite3VdbeMemSetInt64(pMem, p->iKey1); |
| 77503 | }else if( iIdx>=p->pUnpacked->nField ){ |
| 77504 | *ppValue = (sqlite3_value *)columnNullValue(); |
| 77505 | }else if( p->pTab->aCol[iIdx].affinity==SQLITE_AFF_REAL ){ |
| 77506 | if( pMem->flags & MEM_Int ){ |
| 77507 | sqlite3VdbeMemRealify(pMem); |
| 77508 | } |
| 77509 | } |
| 77510 | |
| 77511 | preupdate_old_out: |
| 77512 | sqlite3Error(db, rc); |
| @@ -77401,10 +77555,13 @@ | |
| 77555 | |
| 77556 | if( !p || p->op==SQLITE_DELETE ){ |
| 77557 | rc = SQLITE_MISUSE_BKPT; |
| 77558 | goto preupdate_new_out; |
| 77559 | } |
| 77560 | if( p->pPk && p->op!=SQLITE_UPDATE ){ |
| 77561 | iIdx = sqlite3ColumnOfIndex(p->pPk, iIdx); |
| 77562 | } |
| 77563 | if( iIdx>=p->pCsr->nField || iIdx<0 ){ |
| 77564 | rc = SQLITE_RANGE; |
| 77565 | goto preupdate_new_out; |
| 77566 | } |
| 77567 | |
| @@ -77421,17 +77578,15 @@ | |
| 77578 | rc = SQLITE_NOMEM; |
| 77579 | goto preupdate_new_out; |
| 77580 | } |
| 77581 | p->pNewUnpacked = pUnpack; |
| 77582 | } |
| 77583 | pMem = &pUnpack->aMem[iIdx]; |
| 77584 | if( iIdx==p->pTab->iPKey ){ |
| 77585 | sqlite3VdbeMemSetInt64(pMem, p->iKey2); |
| 77586 | }else if( iIdx>=pUnpack->nField ){ |
| 77587 | pMem = (sqlite3_value *)columnNullValue(); |
| 77588 | } |
| 77589 | }else{ |
| 77590 | /* For an UPDATE, memory cell (p->iNewReg+1+iIdx) contains the required |
| 77591 | ** value. Make a copy of the cell contents and return a pointer to it. |
| 77592 | ** It is not safe to return a pointer to the memory cell itself as the |
| @@ -78404,12 +78559,10 @@ | |
| 78559 | Mem *aMem = p->aMem; /* Copy of p->aMem */ |
| 78560 | Mem *pIn1 = 0; /* 1st input operand */ |
| 78561 | Mem *pIn2 = 0; /* 2nd input operand */ |
| 78562 | Mem *pIn3 = 0; /* 3rd input operand */ |
| 78563 | Mem *pOut = 0; /* Output operand */ |
| 78564 | #ifdef VDBE_PROFILE |
| 78565 | u64 start; /* CPU clock count at start of opcode */ |
| 78566 | #endif |
| 78567 | /*** INSERT STACK UNION HERE ***/ |
| 78568 | |
| @@ -78420,11 +78573,10 @@ | |
| 78573 | ** sqlite3_column_text16() failed. */ |
| 78574 | goto no_mem; |
| 78575 | } |
| 78576 | assert( p->rc==SQLITE_OK || (p->rc&0xff)==SQLITE_BUSY ); |
| 78577 | assert( p->bIsReader || p->readOnly!=0 ); |
| 78578 | p->iCurrentTime = 0; |
| 78579 | assert( p->explain==0 ); |
| 78580 | p->pResultSet = 0; |
| 78581 | db->busyHandler.nBusy = 0; |
| 78582 | if( db->u1.isInterrupted ) goto abort_due_to_interrupt; |
| @@ -78781,11 +78933,10 @@ | |
| 78933 | pFrame = p->pFrame; |
| 78934 | p->pFrame = pFrame->pParent; |
| 78935 | p->nFrame--; |
| 78936 | sqlite3VdbeSetChanges(db, p->nChange); |
| 78937 | pcx = sqlite3VdbeFrameRestore(pFrame); |
| 78938 | if( pOp->p2==OE_Ignore ){ |
| 78939 | /* Instruction pcx is the OP_Program that invoked the sub-program |
| 78940 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 78941 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 78942 | ** an IGNORE exception. In this case jump to the address specified |
| @@ -79016,11 +79167,11 @@ | |
| 79167 | assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) ); |
| 79168 | pVar = &p->aVar[pOp->p1 - 1]; |
| 79169 | if( sqlite3VdbeMemTooBig(pVar) ){ |
| 79170 | goto too_big; |
| 79171 | } |
| 79172 | pOut = &aMem[pOp->p2]; |
| 79173 | sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 79174 | UPDATE_MAX_BLOBSIZE(pOut); |
| 79175 | break; |
| 79176 | } |
| 79177 | |
| @@ -79503,13 +79654,11 @@ | |
| 79654 | REGISTER_TRACE(pOp->p2+i, pCtx->argv[i]); |
| 79655 | } |
| 79656 | #endif |
| 79657 | MemSetTypeFlag(pCtx->pOut, MEM_Null); |
| 79658 | pCtx->fErrorOrAux = 0; |
| 79659 | (*pCtx->pFunc->xSFunc)(pCtx, pCtx->argc, pCtx->argv);/* IMP: R-24505-23230 */ |
| 79660 | |
| 79661 | /* If the function returned an error, throw an exception */ |
| 79662 | if( pCtx->fErrorOrAux ){ |
| 79663 | if( pCtx->isError ){ |
| 79664 | sqlite3VdbeError(p, "%s", sqlite3_value_text(pCtx->pOut)); |
| @@ -79961,12 +80110,12 @@ | |
| 80110 | } |
| 80111 | |
| 80112 | |
| 80113 | /* Opcode: Permutation * * * P4 * |
| 80114 | ** |
| 80115 | ** Set the permutation used by the OP_Compare operator in the next |
| 80116 | ** instruction. The permutation is stored in the P4 operand. |
| 80117 | ** |
| 80118 | ** The permutation is only valid until the next OP_Compare that has |
| 80119 | ** the OPFLAG_PERMUTE bit set in P5. Typically the OP_Permutation should |
| 80120 | ** occur immediately prior to the OP_Compare. |
| 80121 | ** |
| @@ -79974,11 +80123,12 @@ | |
| 80123 | ** and does not become part of the permutation. |
| 80124 | */ |
| 80125 | case OP_Permutation: { |
| 80126 | assert( pOp->p4type==P4_INTARRAY ); |
| 80127 | assert( pOp->p4.ai ); |
| 80128 | assert( pOp[1].opcode==OP_Compare ); |
| 80129 | assert( pOp[1].p5 & OPFLAG_PERMUTE ); |
| 80130 | break; |
| 80131 | } |
| 80132 | |
| 80133 | /* Opcode: Compare P1 P2 P3 P4 P5 |
| 80134 | ** Synopsis: r[P1@P3] <-> r[P2@P3] |
| @@ -80007,12 +80157,21 @@ | |
| 80157 | int p2; |
| 80158 | const KeyInfo *pKeyInfo; |
| 80159 | int idx; |
| 80160 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 80161 | int bRev; /* True for DESCENDING sort order */ |
| 80162 | int *aPermute; /* The permutation */ |
| 80163 | |
| 80164 | if( (pOp->p5 & OPFLAG_PERMUTE)==0 ){ |
| 80165 | aPermute = 0; |
| 80166 | }else{ |
| 80167 | assert( pOp>aOp ); |
| 80168 | assert( pOp[-1].opcode==OP_Permutation ); |
| 80169 | assert( pOp[-1].p4type==P4_INTARRAY ); |
| 80170 | aPermute = pOp[-1].p4.ai + 1; |
| 80171 | assert( aPermute!=0 ); |
| 80172 | } |
| 80173 | n = pOp->p3; |
| 80174 | pKeyInfo = pOp->p4.pKeyInfo; |
| 80175 | assert( n>0 ); |
| 80176 | assert( pKeyInfo!=0 ); |
| 80177 | p1 = pOp->p1; |
| @@ -80041,11 +80200,10 @@ | |
| 80200 | if( iCompare ){ |
| 80201 | if( bRev ) iCompare = -iCompare; |
| 80202 | break; |
| 80203 | } |
| 80204 | } |
| 80205 | break; |
| 80206 | } |
| 80207 | |
| 80208 | /* Opcode: Jump P1 P2 P3 * * |
| 80209 | ** |
| @@ -80597,10 +80755,24 @@ | |
| 80755 | do{ |
| 80756 | applyAffinity(pRec++, *(zAffinity++), encoding); |
| 80757 | assert( zAffinity[0]==0 || pRec<=pLast ); |
| 80758 | }while( zAffinity[0] ); |
| 80759 | } |
| 80760 | |
| 80761 | #ifdef SQLITE_ENABLE_NULL_TRIM |
| 80762 | /* NULLs can be safely trimmed from the end of the record, as long as |
| 80763 | ** as the schema format is 2 or more and none of the omitted columns |
| 80764 | ** have a non-NULL default value. Also, the record must be left with |
| 80765 | ** at least one field. If P5>0 then it will be one more than the |
| 80766 | ** index of the right-most column with a non-NULL default value */ |
| 80767 | if( pOp->p5 ){ |
| 80768 | while( (pLast->flags & MEM_Null)!=0 && nField>pOp->p5 ){ |
| 80769 | pLast--; |
| 80770 | nField--; |
| 80771 | } |
| 80772 | } |
| 80773 | #endif |
| 80774 | |
| 80775 | /* Loop through the elements that will make up the record to figure |
| 80776 | ** out how much space is required for the new record. |
| 80777 | */ |
| 80778 | pRec = pLast; |
| @@ -82187,11 +82359,11 @@ | |
| 82359 | assert( memIsValid(pData) ); |
| 82360 | pC = p->apCsr[pOp->p1]; |
| 82361 | assert( pC!=0 ); |
| 82362 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 82363 | assert( pC->uc.pCursor!=0 ); |
| 82364 | assert( (pOp->p5 & OPFLAG_ISNOOP) || pC->isTable ); |
| 82365 | assert( pOp->p4type==P4_TABLE || pOp->p4type>=P4_STATIC ); |
| 82366 | REGISTER_TRACE(pOp->p2, pData); |
| 82367 | |
| 82368 | if( pOp->opcode==OP_Insert ){ |
| 82369 | pKey = &aMem[pOp->p3]; |
| @@ -82203,18 +82375,17 @@ | |
| 82375 | assert( pOp->opcode==OP_InsertInt ); |
| 82376 | x.nKey = pOp->p3; |
| 82377 | } |
| 82378 | |
| 82379 | if( pOp->p4type==P4_TABLE && HAS_UPDATE_HOOK(db) ){ |
| 82380 | assert( pC->iDb>=0 ); |
| 82381 | zDb = db->aDb[pC->iDb].zDbSName; |
| 82382 | pTab = pOp->p4.pTab; |
| 82383 | assert( (pOp->p5 & OPFLAG_ISNOOP) || HasRowid(pTab) ); |
| 82384 | op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); |
| 82385 | }else{ |
| 82386 | pTab = 0; /* Not needed. Silence a compiler warning. */ |
| 82387 | zDb = 0; /* Not needed. Silence a compiler warning. */ |
| 82388 | } |
| 82389 | |
| 82390 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 82391 | /* Invoke the pre-update hook, if any */ |
| @@ -82222,14 +82393,15 @@ | |
| 82393 | && pOp->p4type==P4_TABLE |
| 82394 | && !(pOp->p5 & OPFLAG_ISUPDATE) |
| 82395 | ){ |
| 82396 | sqlite3VdbePreUpdateHook(p, pC, SQLITE_INSERT, zDb, pTab, x.nKey, pOp->p2); |
| 82397 | } |
| 82398 | if( pOp->p5 & OPFLAG_ISNOOP ) break; |
| 82399 | #endif |
| 82400 | |
| 82401 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 82402 | if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey; |
| 82403 | if( pData->flags & MEM_Null ){ |
| 82404 | x.pData = 0; |
| 82405 | x.nData = 0; |
| 82406 | }else{ |
| 82407 | assert( pData->flags & (MEM_Blob|MEM_Str) ); |
| @@ -82242,11 +82414,11 @@ | |
| 82414 | }else{ |
| 82415 | x.nZero = 0; |
| 82416 | } |
| 82417 | x.pKey = 0; |
| 82418 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, |
| 82419 | (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), seekResult |
| 82420 | ); |
| 82421 | pC->deferredMoveto = 0; |
| 82422 | pC->cacheStatus = CACHE_STALE; |
| 82423 | |
| 82424 | /* Invoke the update-hook if required. */ |
| @@ -82334,12 +82506,15 @@ | |
| 82506 | pTab = 0; /* Not needed. Silence a compiler warning. */ |
| 82507 | } |
| 82508 | |
| 82509 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 82510 | /* Invoke the pre-update-hook if required. */ |
| 82511 | if( db->xPreUpdateCallback && pOp->p4.pTab ){ |
| 82512 | assert( !(opflags & OPFLAG_ISUPDATE) |
| 82513 | || HasRowid(pTab)==0 |
| 82514 | || (aMem[pOp->p3].flags & MEM_Int) |
| 82515 | ); |
| 82516 | sqlite3VdbePreUpdateHook(p, pC, |
| 82517 | (opflags & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_DELETE, |
| 82518 | zDb, pTab, pC->movetoTarget, |
| 82519 | pOp->p3 |
| 82520 | ); |
| @@ -82453,11 +82628,11 @@ | |
| 82628 | if( rc ) goto abort_due_to_error; |
| 82629 | p->apCsr[pOp->p3]->cacheStatus = CACHE_STALE; |
| 82630 | break; |
| 82631 | } |
| 82632 | |
| 82633 | /* Opcode: RowData P1 P2 P3 * * |
| 82634 | ** Synopsis: r[P2]=data |
| 82635 | ** |
| 82636 | ** Write into register P2 the complete row content for the row at |
| 82637 | ** which cursor P1 is currently pointing. |
| 82638 | ** There is no interpretation of the data. |
| @@ -82467,18 +82642,30 @@ | |
| 82642 | ** If cursor P1 is an index, then the content is the key of the row. |
| 82643 | ** If cursor P2 is a table, then the content extracted is the data. |
| 82644 | ** |
| 82645 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 82646 | ** of a real table, not a pseudo-table. |
| 82647 | ** |
| 82648 | ** If P3!=0 then this opcode is allowed to make an ephermeral pointer |
| 82649 | ** into the database page. That means that the content of the output |
| 82650 | ** register will be invalidated as soon as the cursor moves - including |
| 82651 | ** moves caused by other cursors that "save" the the current cursors |
| 82652 | ** position in order that they can write to the same table. If P3==0 |
| 82653 | ** then a copy of the data is made into memory. P3!=0 is faster, but |
| 82654 | ** P3==0 is safer. |
| 82655 | ** |
| 82656 | ** If P3!=0 then the content of the P2 register is unsuitable for use |
| 82657 | ** in OP_Result and any OP_Result will invalidate the P2 register content. |
| 82658 | ** The P2 register content is invalidated by opcodes like OP_Function or |
| 82659 | ** by any use of another cursor pointing to the same table. |
| 82660 | */ |
| 82661 | case OP_RowData: { |
| 82662 | VdbeCursor *pC; |
| 82663 | BtCursor *pCrsr; |
| 82664 | u32 n; |
| 82665 | |
| 82666 | pOut = out2Prerelease(p, pOp); |
| 82667 | |
| 82668 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 82669 | pC = p->apCsr[pOp->p1]; |
| 82670 | assert( pC!=0 ); |
| 82671 | assert( pC->eCurType==CURTYPE_BTREE ); |
| @@ -82505,18 +82692,13 @@ | |
| 82692 | n = sqlite3BtreePayloadSize(pCrsr); |
| 82693 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 82694 | goto too_big; |
| 82695 | } |
| 82696 | testcase( n==0 ); |
| 82697 | rc = sqlite3VdbeMemFromBtree(pCrsr, 0, n, pOut); |
| 82698 | if( rc ) goto abort_due_to_error; |
| 82699 | if( !pOp->p3 ) Deephemeralize(pOut); |
| 82700 | UPDATE_MAX_BLOBSIZE(pOut); |
| 82701 | REGISTER_TRACE(pOp->p2, pOut); |
| 82702 | break; |
| 82703 | } |
| 82704 | |
| @@ -82900,11 +83082,11 @@ | |
| 83082 | x.nKey = pIn2->n; |
| 83083 | x.pKey = pIn2->z; |
| 83084 | x.aMem = aMem + pOp->p3; |
| 83085 | x.nMem = (u16)pOp->p4.i; |
| 83086 | rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, |
| 83087 | (pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION)), |
| 83088 | ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 83089 | ); |
| 83090 | assert( pC->deferredMoveto==0 ); |
| 83091 | pC->cacheStatus = CACHE_STALE; |
| 83092 | } |
| @@ -83022,11 +83204,10 @@ | |
| 83204 | pTabCur->aAltMap = pOp->p4.ai; |
| 83205 | pTabCur->pAltCursor = pC; |
| 83206 | }else{ |
| 83207 | pOut = out2Prerelease(p, pOp); |
| 83208 | pOut->u.i = rowid; |
| 83209 | } |
| 83210 | }else{ |
| 83211 | assert( pOp->opcode==OP_IdxRowid ); |
| 83212 | sqlite3VdbeMemSetNull(&aMem[pOp->p2]); |
| 83213 | } |
| @@ -83664,11 +83845,11 @@ | |
| 83845 | assert( (int)(pOp - aOp)==pFrame->pc ); |
| 83846 | } |
| 83847 | |
| 83848 | p->nFrame++; |
| 83849 | pFrame->pParent = p->pFrame; |
| 83850 | pFrame->lastRowid = db->lastRowid; |
| 83851 | pFrame->nChange = p->nChange; |
| 83852 | pFrame->nDbChange = p->db->nChange; |
| 83853 | assert( pFrame->pAuxData==0 ); |
| 83854 | pFrame->pAuxData = p->pAuxData; |
| 83855 | p->pAuxData = 0; |
| @@ -84605,11 +84786,11 @@ | |
| 84786 | rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); |
| 84787 | db->vtabOnConflict = vtabOnConflict; |
| 84788 | sqlite3VtabImportErrmsg(p, pVtab); |
| 84789 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 84790 | assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); |
| 84791 | db->lastRowid = rowid; |
| 84792 | } |
| 84793 | if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 84794 | if( pOp->p5==OE_Ignore ){ |
| 84795 | rc = SQLITE_OK; |
| 84796 | }else{ |
| @@ -84841,11 +85022,10 @@ | |
| 85022 | |
| 85023 | /* This is the only way out of this procedure. We have to |
| 85024 | ** release the mutexes on btrees that were acquired at the |
| 85025 | ** top. */ |
| 85026 | vdbe_return: |
| 85027 | testcase( nVmStep>0 ); |
| 85028 | p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep; |
| 85029 | sqlite3VdbeLeave(p); |
| 85030 | assert( rc!=SQLITE_OK || nExtraDelete==0 |
| 85031 | || sqlite3_strlike("DELETE%",p->zSql,0)!=0 |
| @@ -84905,14 +85085,13 @@ | |
| 85085 | /* |
| 85086 | ** Valid sqlite3_blob* handles point to Incrblob structures. |
| 85087 | */ |
| 85088 | typedef struct Incrblob Incrblob; |
| 85089 | struct Incrblob { |
| 85090 | int nByte; /* Size of open blob, in bytes */ |
| 85091 | int iOffset; /* Byte offset of blob in cursor data */ |
| 85092 | u16 iCol; /* Table column this handle is open on */ |
| 85093 | BtCursor *pCsr; /* Cursor pointing at blob row */ |
| 85094 | sqlite3_stmt *pStmt; /* Statement holding cursor open */ |
| 85095 | sqlite3 *db; /* The associated database */ |
| 85096 | char *zDb; /* Database name */ |
| 85097 | Table *pTab; /* Table object */ |
| @@ -84939,21 +85118,31 @@ | |
| 85118 | static int blobSeekToRow(Incrblob *p, sqlite3_int64 iRow, char **pzErr){ |
| 85119 | int rc; /* Error code */ |
| 85120 | char *zErr = 0; /* Error message */ |
| 85121 | Vdbe *v = (Vdbe *)p->pStmt; |
| 85122 | |
| 85123 | /* Set the value of register r[1] in the SQL statement to integer iRow. |
| 85124 | ** This is done directly as a performance optimization |
| 85125 | */ |
| 85126 | v->aMem[1].flags = MEM_Int; |
| 85127 | v->aMem[1].u.i = iRow; |
| 85128 | |
| 85129 | /* If the statement has been run before (and is paused at the OP_ResultRow) |
| 85130 | ** then back it up to the point where it does the OP_SeekRowid. This could |
| 85131 | ** have been down with an extra OP_Goto, but simply setting the program |
| 85132 | ** counter is faster. */ |
| 85133 | if( v->pc>3 ){ |
| 85134 | v->pc = 3; |
| 85135 | rc = sqlite3VdbeExec(v); |
| 85136 | }else{ |
| 85137 | rc = sqlite3_step(p->pStmt); |
| 85138 | } |
| 85139 | if( rc==SQLITE_ROW ){ |
| 85140 | VdbeCursor *pC = v->apCsr[0]; |
| 85141 | u32 type = pC->nHdrParsed>p->iCol ? pC->aType[p->iCol] : 0; |
| 85142 | testcase( pC->nHdrParsed==p->iCol ); |
| 85143 | testcase( pC->nHdrParsed==p->iCol+1 ); |
| 85144 | if( type<12 ){ |
| 85145 | zErr = sqlite3MPrintf(p->db, "cannot open value of type %s", |
| 85146 | type==0?"null": type==7?"real": "integer" |
| 85147 | ); |
| 85148 | rc = SQLITE_ERROR; |
| @@ -84994,11 +85183,11 @@ | |
| 85183 | sqlite3* db, /* The database connection */ |
| 85184 | const char *zDb, /* The attached database containing the blob */ |
| 85185 | const char *zTable, /* The table containing the blob */ |
| 85186 | const char *zColumn, /* The column containing the blob */ |
| 85187 | sqlite_int64 iRow, /* The row containing the glob */ |
| 85188 | int wrFlag, /* True -> read/write access, false -> read-only */ |
| 85189 | sqlite3_blob **ppBlob /* Handle for accessing the blob returned here */ |
| 85190 | ){ |
| 85191 | int nAttempt = 0; |
| 85192 | int iCol; /* Index of zColumn in row-record */ |
| 85193 | int rc = SQLITE_OK; |
| @@ -85016,11 +85205,11 @@ | |
| 85205 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 85206 | if( !sqlite3SafetyCheckOk(db) || zTable==0 ){ |
| 85207 | return SQLITE_MISUSE_BKPT; |
| 85208 | } |
| 85209 | #endif |
| 85210 | wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */ |
| 85211 | |
| 85212 | sqlite3_mutex_enter(db->mutex); |
| 85213 | |
| 85214 | pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob)); |
| 85215 | if( !pBlob ) goto blob_open_out; |
| @@ -85076,13 +85265,12 @@ | |
| 85265 | goto blob_open_out; |
| 85266 | } |
| 85267 | |
| 85268 | /* If the value is being opened for writing, check that the |
| 85269 | ** column is not indexed, and that it is not part of a foreign key. |
| 85270 | */ |
| 85271 | if( wrFlag ){ |
| 85272 | const char *zFault = 0; |
| 85273 | Index *pIdx; |
| 85274 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 85275 | if( db->flags&SQLITE_ForeignKeys ){ |
| 85276 | /* Check that the column is not part of an FK child key definition. It |
| @@ -85139,22 +85327,21 @@ | |
| 85327 | */ |
| 85328 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 85329 | static const VdbeOpList openBlob[] = { |
| 85330 | {OP_TableLock, 0, 0, 0}, /* 0: Acquire a read or write lock */ |
| 85331 | {OP_OpenRead, 0, 0, 0}, /* 1: Open a cursor */ |
| 85332 | /* blobSeekToRow() will initialize r[1] to the desired rowid */ |
| 85333 | {OP_NotExists, 0, 5, 1}, /* 2: Seek the cursor to rowid=r[1] */ |
| 85334 | {OP_Column, 0, 0, 1}, /* 3 */ |
| 85335 | {OP_ResultRow, 1, 0, 0}, /* 4 */ |
| 85336 | {OP_Halt, 0, 0, 0}, /* 5 */ |
| 85337 | }; |
| 85338 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 85339 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 85340 | VdbeOp *aOp; |
| 85341 | |
| 85342 | sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag, |
| 85343 | pTab->pSchema->schema_cookie, |
| 85344 | pTab->pSchema->iGeneration); |
| 85345 | sqlite3VdbeChangeP5(v, 1); |
| 85346 | aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn); |
| 85347 | |
| @@ -85167,19 +85354,19 @@ | |
| 85354 | #ifdef SQLITE_OMIT_SHARED_CACHE |
| 85355 | aOp[0].opcode = OP_Noop; |
| 85356 | #else |
| 85357 | aOp[0].p1 = iDb; |
| 85358 | aOp[0].p2 = pTab->tnum; |
| 85359 | aOp[0].p3 = wrFlag; |
| 85360 | sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT); |
| 85361 | } |
| 85362 | if( db->mallocFailed==0 ){ |
| 85363 | #endif |
| 85364 | |
| 85365 | /* Remove either the OP_OpenWrite or OpenRead. Set the P2 |
| 85366 | ** parameter of the other to pTab->tnum. */ |
| 85367 | if( wrFlag ) aOp[1].opcode = OP_OpenWrite; |
| 85368 | aOp[1].p2 = pTab->tnum; |
| 85369 | aOp[1].p3 = iDb; |
| 85370 | |
| 85371 | /* Configure the number of columns. Configure the cursor to |
| 85372 | ** think that the table has one more column than it really |
| @@ -85188,27 +85375,25 @@ | |
| 85375 | ** we can invoke OP_Column to fill in the vdbe cursors type |
| 85376 | ** and offset cache without causing any IO. |
| 85377 | */ |
| 85378 | aOp[1].p4type = P4_INT32; |
| 85379 | aOp[1].p4.i = pTab->nCol+1; |
| 85380 | aOp[3].p2 = pTab->nCol; |
| 85381 | |
| 85382 | pParse->nVar = 0; |
| 85383 | pParse->nMem = 1; |
| 85384 | pParse->nTab = 1; |
| 85385 | sqlite3VdbeMakeReady(v, pParse); |
| 85386 | } |
| 85387 | } |
| 85388 | |
| 85389 | pBlob->iCol = iCol; |
| 85390 | pBlob->db = db; |
| 85391 | sqlite3BtreeLeaveAll(db); |
| 85392 | if( db->mallocFailed ){ |
| 85393 | goto blob_open_out; |
| 85394 | } |
| 85395 | rc = blobSeekToRow(pBlob, iRow, &zErr); |
| 85396 | } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA ); |
| 85397 | |
| 85398 | blob_open_out: |
| 85399 | if( rc==SQLITE_OK && db->mallocFailed==0 ){ |
| @@ -88741,12 +88926,10 @@ | |
| 88926 | ** This file contains routines used for walking the parser tree and |
| 88927 | ** resolve all identifiers by associating them with a particular |
| 88928 | ** table and column. |
| 88929 | */ |
| 88930 | /* #include "sqliteInt.h" */ |
| 88931 | |
| 88932 | /* |
| 88933 | ** Walk the expression tree pExpr and increase the aggregate function |
| 88934 | ** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node. |
| 88935 | ** This needs to occur when copying a TK_AGG_FUNCTION node from an |
| @@ -91237,21 +91420,27 @@ | |
| 91420 | int doAdd = 0; |
| 91421 | if( z[0]=='?' ){ |
| 91422 | /* Wildcard of the form "?nnn". Convert "nnn" to an integer and |
| 91423 | ** use it as the variable number */ |
| 91424 | i64 i; |
| 91425 | int bOk; |
| 91426 | if( n==2 ){ /*OPTIMIZATION-IF-TRUE*/ |
| 91427 | i = z[1]-'0'; /* The common case of ?N for a single digit N */ |
| 91428 | bOk = 1; |
| 91429 | }else{ |
| 91430 | bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8); |
| 91431 | } |
| 91432 | testcase( i==0 ); |
| 91433 | testcase( i==1 ); |
| 91434 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]-1 ); |
| 91435 | testcase( i==db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ); |
| 91436 | if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){ |
| 91437 | sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d", |
| 91438 | db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]); |
| 91439 | return; |
| 91440 | } |
| 91441 | x = (ynVar)i; |
| 91442 | if( x>pParse->nVar ){ |
| 91443 | pParse->nVar = (int)x; |
| 91444 | doAdd = 1; |
| 91445 | }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){ |
| 91446 | doAdd = 1; |
| @@ -91682,37 +91871,45 @@ | |
| 91871 | pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); |
| 91872 | pNewItem->idx = pOldItem->idx; |
| 91873 | } |
| 91874 | return pNew; |
| 91875 | } |
| 91876 | SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *pDup, int flags){ |
| 91877 | Select *pRet = 0; |
| 91878 | Select *pNext = 0; |
| 91879 | Select **pp = &pRet; |
| 91880 | Select *p; |
| 91881 | |
| 91882 | assert( db!=0 ); |
| 91883 | for(p=pDup; p; p=p->pPrior){ |
| 91884 | Select *pNew = sqlite3DbMallocRawNN(db, sizeof(*p) ); |
| 91885 | if( pNew==0 ) break; |
| 91886 | pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags); |
| 91887 | pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags); |
| 91888 | pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags); |
| 91889 | pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags); |
| 91890 | pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags); |
| 91891 | pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags); |
| 91892 | pNew->op = p->op; |
| 91893 | pNew->pNext = pNext; |
| 91894 | pNew->pPrior = 0; |
| 91895 | pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags); |
| 91896 | pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags); |
| 91897 | pNew->iLimit = 0; |
| 91898 | pNew->iOffset = 0; |
| 91899 | pNew->selFlags = p->selFlags & ~SF_UsesEphemeral; |
| 91900 | pNew->addrOpenEphm[0] = -1; |
| 91901 | pNew->addrOpenEphm[1] = -1; |
| 91902 | pNew->nSelectRow = p->nSelectRow; |
| 91903 | pNew->pWith = withDup(db, p->pWith); |
| 91904 | sqlite3SelectSetName(pNew, p->zSelName); |
| 91905 | *pp = pNew; |
| 91906 | pp = &pNew->pPrior; |
| 91907 | pNext = pNew; |
| 91908 | } |
| 91909 | |
| 91910 | return pRet; |
| 91911 | } |
| 91912 | #else |
| 91913 | SQLITE_PRIVATE Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){ |
| 91914 | assert( p==0 ); |
| 91915 | return 0; |
| @@ -91773,11 +91970,11 @@ | |
| 91970 | ** |
| 91971 | ** (a,b,c) = (expr1,expr2,expr3) |
| 91972 | ** Or: (a,b,c) = (SELECT x,y,z FROM ....) |
| 91973 | ** |
| 91974 | ** For each term of the vector assignment, append new entries to the |
| 91975 | ** expression list pList. In the case of a subquery on the RHS, append |
| 91976 | ** TK_SELECT_COLUMN expressions. |
| 91977 | */ |
| 91978 | SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector( |
| 91979 | Parse *pParse, /* Parsing context */ |
| 91980 | ExprList *pList, /* List to which to append. Might be NULL */ |
| @@ -93882,10 +94079,15 @@ | |
| 94079 | int i; /* Loop counter */ |
| 94080 | sqlite3 *db = pParse->db; /* The database connection */ |
| 94081 | u8 enc = ENC(db); /* The text encoding used by this database */ |
| 94082 | CollSeq *pColl = 0; /* A collating sequence */ |
| 94083 | |
| 94084 | if( ConstFactorOk(pParse) && sqlite3ExprIsConstantNotJoin(pExpr) ){ |
| 94085 | /* SQL functions can be expensive. So try to move constant functions |
| 94086 | ** out of the inner loop, even if that means an extra OP_Copy. */ |
| 94087 | return sqlite3ExprCodeAtInit(pParse, pExpr, -1); |
| 94088 | } |
| 94089 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 94090 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 94091 | pFarg = 0; |
| 94092 | }else{ |
| 94093 | pFarg = pExpr->x.pList; |
| @@ -93929,10 +94131,26 @@ | |
| 94131 | */ |
| 94132 | if( pDef->funcFlags & SQLITE_FUNC_UNLIKELY ){ |
| 94133 | assert( nFarg>=1 ); |
| 94134 | return sqlite3ExprCodeTarget(pParse, pFarg->a[0].pExpr, target); |
| 94135 | } |
| 94136 | |
| 94137 | #ifdef SQLITE_DEBUG |
| 94138 | /* The AFFINITY() function evaluates to a string that describes |
| 94139 | ** the type affinity of the argument. This is used for testing of |
| 94140 | ** the SQLite type logic. |
| 94141 | */ |
| 94142 | if( pDef->funcFlags & SQLITE_FUNC_AFFINITY ){ |
| 94143 | const char *azAff[] = { "blob", "text", "numeric", "integer", "real" }; |
| 94144 | char aff; |
| 94145 | assert( nFarg==1 ); |
| 94146 | aff = sqlite3ExprAffinity(pFarg->a[0].pExpr); |
| 94147 | sqlite3VdbeLoadString(v, target, |
| 94148 | aff ? azAff[aff-SQLITE_AFF_BLOB] : "none"); |
| 94149 | return target; |
| 94150 | } |
| 94151 | #endif |
| 94152 | |
| 94153 | for(i=0; i<nFarg; i++){ |
| 94154 | if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){ |
| 94155 | testcase( i==31 ); |
| 94156 | constMask |= MASKBIT32(i); |
| @@ -94246,28 +94464,44 @@ | |
| 94464 | return inReg; |
| 94465 | } |
| 94466 | |
| 94467 | /* |
| 94468 | ** Factor out the code of the given expression to initialization time. |
| 94469 | ** |
| 94470 | ** If regDest>=0 then the result is always stored in that register and the |
| 94471 | ** result is not reusable. If regDest<0 then this routine is free to |
| 94472 | ** store the value whereever it wants. The register where the expression |
| 94473 | ** is stored is returned. When regDest<0, two identical expressions will |
| 94474 | ** code to the same register. |
| 94475 | */ |
| 94476 | SQLITE_PRIVATE int sqlite3ExprCodeAtInit( |
| 94477 | Parse *pParse, /* Parsing context */ |
| 94478 | Expr *pExpr, /* The expression to code when the VDBE initializes */ |
| 94479 | int regDest /* Store the value in this register */ |
| 94480 | ){ |
| 94481 | ExprList *p; |
| 94482 | assert( ConstFactorOk(pParse) ); |
| 94483 | p = pParse->pConstExpr; |
| 94484 | if( regDest<0 && p ){ |
| 94485 | struct ExprList_item *pItem; |
| 94486 | int i; |
| 94487 | for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){ |
| 94488 | if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){ |
| 94489 | return pItem->u.iConstExprReg; |
| 94490 | } |
| 94491 | } |
| 94492 | } |
| 94493 | pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 94494 | p = sqlite3ExprListAppend(pParse, p, pExpr); |
| 94495 | if( p ){ |
| 94496 | struct ExprList_item *pItem = &p->a[p->nExpr-1]; |
| 94497 | pItem->reusable = regDest<0; |
| 94498 | if( regDest<0 ) regDest = ++pParse->nMem; |
| 94499 | pItem->u.iConstExprReg = regDest; |
| 94500 | } |
| 94501 | pParse->pConstExpr = p; |
| 94502 | return regDest; |
| 94503 | } |
| 94504 | |
| 94505 | /* |
| 94506 | ** Generate code to evaluate an expression and store the results |
| 94507 | ** into a register. Return the register number where the results |
| @@ -94286,23 +94520,12 @@ | |
| 94520 | pExpr = sqlite3ExprSkipCollate(pExpr); |
| 94521 | if( ConstFactorOk(pParse) |
| 94522 | && pExpr->op!=TK_REGISTER |
| 94523 | && sqlite3ExprIsConstantNotJoin(pExpr) |
| 94524 | ){ |
| 94525 | *pReg = 0; |
| 94526 | r2 = sqlite3ExprCodeAtInit(pParse, pExpr, -1); |
| 94527 | }else{ |
| 94528 | int r1 = sqlite3GetTempReg(pParse); |
| 94529 | r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); |
| 94530 | if( r2==r1 ){ |
| 94531 | *pReg = r1; |
| @@ -94352,11 +94575,11 @@ | |
| 94575 | ** in register target. If the expression is constant, then this routine |
| 94576 | ** might choose to code the expression at initialization time. |
| 94577 | */ |
| 94578 | SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){ |
| 94579 | if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){ |
| 94580 | sqlite3ExprCodeAtInit(pParse, pExpr, target); |
| 94581 | }else{ |
| 94582 | sqlite3ExprCode(pParse, pExpr, target); |
| 94583 | } |
| 94584 | } |
| 94585 | |
| @@ -94424,11 +94647,11 @@ | |
| 94647 | n--; |
| 94648 | }else{ |
| 94649 | sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i); |
| 94650 | } |
| 94651 | }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ |
| 94652 | sqlite3ExprCodeAtInit(pParse, pExpr, target+i); |
| 94653 | }else{ |
| 94654 | int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 94655 | if( inReg!=target+i ){ |
| 94656 | VdbeOp *pOp; |
| 94657 | if( copyOp==OP_Copy |
| @@ -96968,10 +97191,16 @@ | |
| 97191 | ** used to query statistical information that has been gathered into |
| 97192 | ** the Stat4Accum object by prior calls to stat_push(). The P parameter |
| 97193 | ** has type BLOB but it is really just a pointer to the Stat4Accum object. |
| 97194 | ** The content to returned is determined by the parameter J |
| 97195 | ** which is one of the STAT_GET_xxxx values defined above. |
| 97196 | ** |
| 97197 | ** The stat_get(P,J) function is not available to generic SQL. It is |
| 97198 | ** inserted as part of a manually constructed bytecode program. (See |
| 97199 | ** the callStatGet() routine below.) It is guaranteed that the P |
| 97200 | ** parameter will always be a poiner to a Stat4Accum object, never a |
| 97201 | ** NULL. |
| 97202 | ** |
| 97203 | ** If neither STAT3 nor STAT4 are enabled, then J is always |
| 97204 | ** STAT_GET_STAT1 and is hence omitted and this routine becomes |
| 97205 | ** a one-parameter function, stat_get(P), that always returns the |
| 97206 | ** stat1 table entry information. |
| @@ -97787,11 +98016,11 @@ | |
| 98016 | sumEq += aSample[i].anEq[iCol]; |
| 98017 | nSum100 += 100; |
| 98018 | } |
| 98019 | } |
| 98020 | |
| 98021 | if( nDist100>nSum100 && sumEq<nRow ){ |
| 98022 | avgEq = ((i64)100 * (nRow - sumEq))/(nDist100 - nSum100); |
| 98023 | } |
| 98024 | if( avgEq==0 ) avgEq = 1; |
| 98025 | pIdx->aAvgEq[iCol] = avgEq; |
| 98026 | } |
| @@ -98201,10 +98430,11 @@ | |
| 98430 | assert( pVfs ); |
| 98431 | flags |= SQLITE_OPEN_MAIN_DB; |
| 98432 | rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags); |
| 98433 | sqlite3_free( zPath ); |
| 98434 | db->nDb++; |
| 98435 | db->skipBtreeMutex = 0; |
| 98436 | if( rc==SQLITE_CONSTRAINT ){ |
| 98437 | rc = SQLITE_ERROR; |
| 98438 | zErrDyn = sqlite3MPrintf(db, "database is already attached"); |
| 98439 | }else if( rc==SQLITE_OK ){ |
| 98440 | Pager *pPager; |
| @@ -104365,16 +104595,12 @@ | |
| 104595 | } |
| 104596 | }else |
| 104597 | #endif |
| 104598 | { |
| 104599 | int count = (pParse->nested==0); /* True to count changes */ |
| 104600 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 104601 | iKey, nKey, count, OE_Default, eOnePass, aiCurOnePass[1]); |
| 104602 | } |
| 104603 | |
| 104604 | /* End of the loop over all rowids/primary-keys. */ |
| 104605 | if( eOnePass!=ONEPASS_OFF ){ |
| 104606 | sqlite3VdbeResolveLabel(v, addrBypass); |
| @@ -104450,19 +104676,21 @@ | |
| 104676 | ** then this function must seek iDataCur to the entry identified by iPk |
| 104677 | ** and nPk before reading from it. |
| 104678 | ** |
| 104679 | ** If eMode is ONEPASS_MULTI, then this call is being made as part |
| 104680 | ** of a ONEPASS delete that affects multiple rows. In this case, if |
| 104681 | ** iIdxNoSeek is a valid cursor number (>=0) and is not the same as |
| 104682 | ** iDataCur, then its position should be preserved following the delete |
| 104683 | ** operation. Or, if iIdxNoSeek is not a valid cursor number, the |
| 104684 | ** position of iDataCur should be preserved instead. |
| 104685 | ** |
| 104686 | ** iIdxNoSeek: |
| 104687 | ** If iIdxNoSeek is a valid cursor number (>=0) not equal to iDataCur, |
| 104688 | ** then it identifies an index cursor (from within array of cursors |
| 104689 | ** starting at iIdxCur) that already points to the index entry to be deleted. |
| 104690 | ** Except, this optimization is disabled if there are BEFORE triggers since |
| 104691 | ** the trigger body might have moved the cursor. |
| 104692 | */ |
| 104693 | SQLITE_PRIVATE void sqlite3GenerateRowDelete( |
| 104694 | Parse *pParse, /* Parsing context */ |
| 104695 | Table *pTab, /* Table containing the row to be deleted */ |
| 104696 | Trigger *pTrigger, /* List of triggers to (potentially) fire */ |
| @@ -104529,17 +104757,22 @@ | |
| 104757 | TK_DELETE, 0, TRIGGER_BEFORE, pTab, iOld, onconf, iLabel |
| 104758 | ); |
| 104759 | |
| 104760 | /* If any BEFORE triggers were coded, then seek the cursor to the |
| 104761 | ** row to be deleted again. It may be that the BEFORE triggers moved |
| 104762 | ** the cursor or already deleted the row that the cursor was |
| 104763 | ** pointing to. |
| 104764 | ** |
| 104765 | ** Also disable the iIdxNoSeek optimization since the BEFORE trigger |
| 104766 | ** may have moved that cursor. |
| 104767 | */ |
| 104768 | if( addrStart<sqlite3VdbeCurrentAddr(v) ){ |
| 104769 | sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk); |
| 104770 | VdbeCoverageIf(v, opSeek==OP_NotExists); |
| 104771 | VdbeCoverageIf(v, opSeek==OP_NotFound); |
| 104772 | testcase( iIdxNoSeek>=0 ); |
| 104773 | iIdxNoSeek = -1; |
| 104774 | } |
| 104775 | |
| 104776 | /* Do FK processing. This call checks that any FK constraints that |
| 104777 | ** refer to this table (i.e. constraints attached to other tables) |
| 104778 | ** are not violated by deleting this row. */ |
| @@ -104558,15 +104791,17 @@ | |
| 104791 | */ |
| 104792 | if( pTab->pSelect==0 ){ |
| 104793 | u8 p5 = 0; |
| 104794 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); |
| 104795 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 104796 | if( pParse->nested==0 ){ |
| 104797 | sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE); |
| 104798 | } |
| 104799 | if( eMode!=ONEPASS_OFF ){ |
| 104800 | sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE); |
| 104801 | } |
| 104802 | if( iIdxNoSeek>=0 && iIdxNoSeek!=iDataCur ){ |
| 104803 | sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); |
| 104804 | } |
| 104805 | if( eMode==ONEPASS_MULTI ) p5 |= OPFLAG_SAVEPOSITION; |
| 104806 | sqlite3VdbeChangeP5(v, p5); |
| 104807 | } |
| @@ -104716,10 +104951,14 @@ | |
| 104951 | ** opcode if it is present */ |
| 104952 | sqlite3VdbeDeletePriorOpcode(v, OP_RealAffinity); |
| 104953 | } |
| 104954 | if( regOut ){ |
| 104955 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 104956 | if( pIdx->pTable->pSelect ){ |
| 104957 | const char *zAff = sqlite3IndexAffinityStr(pParse->db, pIdx); |
| 104958 | sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT); |
| 104959 | } |
| 104960 | } |
| 104961 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 104962 | return regBase; |
| 104963 | } |
| 104964 | |
| @@ -106512,10 +106751,13 @@ | |
| 106751 | DFUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 106752 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 106753 | FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106754 | FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106755 | FUNCTION2(likely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 106756 | #ifdef SQLITE_DEBUG |
| 106757 | FUNCTION2(affinity, 1, 0, 0, noopFunc, SQLITE_FUNC_AFFINITY), |
| 106758 | #endif |
| 106759 | FUNCTION(ltrim, 1, 1, 0, trimFunc ), |
| 106760 | FUNCTION(ltrim, 2, 1, 0, trimFunc ), |
| 106761 | FUNCTION(rtrim, 1, 2, 0, trimFunc ), |
| 106762 | FUNCTION(rtrim, 2, 2, 0, trimFunc ), |
| 106763 | FUNCTION(trim, 1, 3, 0, trimFunc ), |
| @@ -109667,11 +109909,11 @@ | |
| 109909 | if( db->flags&SQLITE_RecTriggers ){ |
| 109910 | pTrigger = sqlite3TriggersExist(pParse, pTab, TK_DELETE, 0, 0); |
| 109911 | } |
| 109912 | sqlite3GenerateRowDelete(pParse, pTab, pTrigger, iDataCur, iIdxCur, |
| 109913 | regR, nPkField, 0, OE_Replace, |
| 109914 | (pIdx==pPk ? ONEPASS_SINGLE : ONEPASS_OFF), iThisCur); |
| 109915 | seenReplace = 1; |
| 109916 | break; |
| 109917 | } |
| 109918 | } |
| 109919 | sqlite3VdbeResolveLabel(v, addrUniqueOk); |
| @@ -109683,10 +109925,29 @@ | |
| 109925 | } |
| 109926 | |
| 109927 | *pbMayReplace = seenReplace; |
| 109928 | VdbeModuleComment((v, "END: GenCnstCks(%d)", seenReplace)); |
| 109929 | } |
| 109930 | |
| 109931 | #ifdef SQLITE_ENABLE_NULL_TRIM |
| 109932 | /* |
| 109933 | ** Change the P5 operand on the last opcode (which should be an OP_MakeRecord) |
| 109934 | ** to be the number of columns in table pTab that must not be NULL-trimmed. |
| 109935 | ** |
| 109936 | ** Or if no columns of pTab may be NULL-trimmed, leave P5 at zero. |
| 109937 | */ |
| 109938 | SQLITE_PRIVATE void sqlite3SetMakeRecordP5(Vdbe *v, Table *pTab){ |
| 109939 | u16 i; |
| 109940 | |
| 109941 | /* Records with omitted columns are only allowed for schema format |
| 109942 | ** version 2 and later (SQLite version 3.1.4, 2005-02-20). */ |
| 109943 | if( pTab->pSchema->file_format<2 ) return; |
| 109944 | |
| 109945 | for(i=pTab->nCol; i>1 && pTab->aCol[i-1].pDflt==0; i--){} |
| 109946 | sqlite3VdbeChangeP5(v, i); |
| 109947 | } |
| 109948 | #endif |
| 109949 | |
| 109950 | /* |
| 109951 | ** This routine generates code to finish the INSERT or UPDATE operation |
| 109952 | ** that was started by a prior call to sqlite3GenerateConstraintChecks. |
| 109953 | ** A consecutive range of registers starting at regNewData contains the |
| @@ -109700,11 +109961,11 @@ | |
| 109961 | Table *pTab, /* the table into which we are inserting */ |
| 109962 | int iDataCur, /* Cursor of the canonical data source */ |
| 109963 | int iIdxCur, /* First index cursor */ |
| 109964 | int regNewData, /* Range of content */ |
| 109965 | int *aRegIdx, /* Register used by each index. 0 for unused indices */ |
| 109966 | int update_flags, /* True for UPDATE, False for INSERT */ |
| 109967 | int appendBias, /* True if this is likely to be an append */ |
| 109968 | int useSeekResult /* True to set the USESEEKRESULT flag on OP_[Idx]Insert */ |
| 109969 | ){ |
| 109970 | Vdbe *v; /* Prepared statements under construction */ |
| 109971 | Index *pIdx; /* An index being inserted or updated */ |
| @@ -109711,10 +109972,15 @@ | |
| 109972 | u8 pik_flags; /* flag values passed to the btree insert */ |
| 109973 | int regData; /* Content registers (after the rowid) */ |
| 109974 | int regRec; /* Register holding assembled record for the table */ |
| 109975 | int i; /* Loop counter */ |
| 109976 | u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */ |
| 109977 | |
| 109978 | assert( update_flags==0 |
| 109979 | || update_flags==OPFLAG_ISUPDATE |
| 109980 | || update_flags==(OPFLAG_ISUPDATE|OPFLAG_SAVEPOSITION) |
| 109981 | ); |
| 109982 | |
| 109983 | v = sqlite3GetVdbe(pParse); |
| 109984 | assert( v!=0 ); |
| 109985 | assert( pTab->pSelect==0 ); /* This table is not a VIEW */ |
| 109986 | for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){ |
| @@ -109722,34 +109988,43 @@ | |
| 109988 | bAffinityDone = 1; |
| 109989 | if( pIdx->pPartIdxWhere ){ |
| 109990 | sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2); |
| 109991 | VdbeCoverage(v); |
| 109992 | } |
| 109993 | pik_flags = (useSeekResult ? OPFLAG_USESEEKRESULT : 0); |
| 109994 | if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){ |
| 109995 | assert( pParse->nested==0 ); |
| 109996 | pik_flags |= OPFLAG_NCHANGE; |
| 109997 | pik_flags |= (update_flags & OPFLAG_SAVEPOSITION); |
| 109998 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 109999 | if( update_flags==0 ){ |
| 110000 | sqlite3VdbeAddOp4(v, OP_InsertInt, |
| 110001 | iIdxCur+i, aRegIdx[i], 0, (char*)pTab, P4_TABLE |
| 110002 | ); |
| 110003 | sqlite3VdbeChangeP5(v, OPFLAG_ISNOOP); |
| 110004 | } |
| 110005 | #endif |
| 110006 | } |
| 110007 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i], |
| 110008 | aRegIdx[i]+1, |
| 110009 | pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn); |
| 110010 | sqlite3VdbeChangeP5(v, pik_flags); |
| 110011 | } |
| 110012 | if( !HasRowid(pTab) ) return; |
| 110013 | regData = regNewData + 1; |
| 110014 | regRec = sqlite3GetTempReg(pParse); |
| 110015 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec); |
| 110016 | sqlite3SetMakeRecordP5(v, pTab); |
| 110017 | if( !bAffinityDone ){ |
| 110018 | sqlite3TableAffinity(v, pTab, 0); |
| 110019 | sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol); |
| 110020 | } |
| 110021 | if( pParse->nested ){ |
| 110022 | pik_flags = 0; |
| 110023 | }else{ |
| 110024 | pik_flags = OPFLAG_NCHANGE; |
| 110025 | pik_flags |= (update_flags?update_flags:OPFLAG_LASTROWID); |
| 110026 | } |
| 110027 | if( appendBias ){ |
| 110028 | pik_flags |= OPFLAG_APPEND; |
| 110029 | } |
| 110030 | if( useSeekResult ){ |
| @@ -110154,11 +110429,11 @@ | |
| 110429 | addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid); |
| 110430 | }else{ |
| 110431 | addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid); |
| 110432 | assert( (pDest->tabFlags & TF_Autoincrement)==0 ); |
| 110433 | } |
| 110434 | sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); |
| 110435 | if( db->flags & SQLITE_Vacuum ){ |
| 110436 | sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1); |
| 110437 | insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID| |
| 110438 | OPFLAG_APPEND|OPFLAG_USESEEKRESULT; |
| 110439 | }else{ |
| @@ -110186,11 +110461,11 @@ | |
| 110461 | sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest); |
| 110462 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 110463 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 110464 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 110465 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 110466 | sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1); |
| 110467 | if( db->flags & SQLITE_Vacuum ){ |
| 110468 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 110469 | ** that the destination table is empty. If all indexed columns use |
| 110470 | ** collation sequence BINARY, then it can also be assumed that the |
| 110471 | ** index will be populated by inserting keys in strictly sorted |
| @@ -110971,11 +111246,10 @@ | |
| 111246 | #endif /* SQLITE3EXT_H */ |
| 111247 | |
| 111248 | /************** End of sqlite3ext.h ******************************************/ |
| 111249 | /************** Continuing where we left off in loadext.c ********************/ |
| 111250 | /* #include "sqliteInt.h" */ |
| 111251 | |
| 111252 | #ifndef SQLITE_OMIT_LOAD_EXTENSION |
| 111253 | /* |
| 111254 | ** Some API routines are omitted when various features are |
| 111255 | ** excluded from a build of SQLite. Substitute a NULL pointer |
| @@ -112635,11 +112909,11 @@ | |
| 112909 | |
| 112910 | /* |
| 112911 | ** Locate a pragma in the aPragmaName[] array. |
| 112912 | */ |
| 112913 | static const PragmaName *pragmaLocate(const char *zName){ |
| 112914 | int upr, lwr, mid = 0, rc; |
| 112915 | lwr = 0; |
| 112916 | upr = ArraySize(aPragmaName)-1; |
| 112917 | while( lwr<=upr ){ |
| 112918 | mid = (lwr+upr)/2; |
| 112919 | rc = sqlite3_stricmp(zName, aPragmaName[mid].zName); |
| @@ -116149,10 +116423,11 @@ | |
| 116423 | v = pParse->pVdbe; |
| 116424 | r1 = sqlite3GetTempReg(pParse); |
| 116425 | sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v); |
| 116426 | sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1); |
| 116427 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N); |
| 116428 | sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT); |
| 116429 | sqlite3ReleaseTempReg(pParse, r1); |
| 116430 | } |
| 116431 | |
| 116432 | /* |
| 116433 | ** This routine generates the code for the inside of the inner loop |
| @@ -119677,11 +119952,19 @@ | |
| 119952 | assert( pTab->nTabRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 )); |
| 119953 | |
| 119954 | pCte->zCteErr = "circular reference: %s"; |
| 119955 | pSavedWith = pParse->pWith; |
| 119956 | pParse->pWith = pWith; |
| 119957 | if( bMayRecursive ){ |
| 119958 | Select *pPrior = pSel->pPrior; |
| 119959 | assert( pPrior->pWith==0 ); |
| 119960 | pPrior->pWith = pSel->pWith; |
| 119961 | sqlite3WalkSelect(pWalker, pPrior); |
| 119962 | pPrior->pWith = 0; |
| 119963 | }else{ |
| 119964 | sqlite3WalkSelect(pWalker, pSel); |
| 119965 | } |
| 119966 | pParse->pWith = pWith; |
| 119967 | |
| 119968 | for(pLeft=pSel; pLeft->pPrior; pLeft=pLeft->pPrior); |
| 119969 | pEList = pLeft->pEList; |
| 119970 | if( pCte->pCols ){ |
| @@ -119721,14 +120004,16 @@ | |
| 120004 | ** sqlite3SelectExpand() when walking a SELECT tree to resolve table |
| 120005 | ** names and other FROM clause elements. |
| 120006 | */ |
| 120007 | static void selectPopWith(Walker *pWalker, Select *p){ |
| 120008 | Parse *pParse = pWalker->pParse; |
| 120009 | if( pParse->pWith && p->pPrior==0 ){ |
| 120010 | With *pWith = findRightmost(p)->pWith; |
| 120011 | if( pWith!=0 ){ |
| 120012 | assert( pParse->pWith==pWith ); |
| 120013 | pParse->pWith = pWith->pOuter; |
| 120014 | } |
| 120015 | } |
| 120016 | } |
| 120017 | #else |
| 120018 | #define selectPopWith 0 |
| 120019 | #endif |
| @@ -119774,12 +120059,12 @@ | |
| 120059 | if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){ |
| 120060 | return WRC_Prune; |
| 120061 | } |
| 120062 | pTabList = p->pSrc; |
| 120063 | pEList = p->pEList; |
| 120064 | if( p->pWith ){ |
| 120065 | sqlite3WithPush(pParse, p->pWith, 0); |
| 120066 | } |
| 120067 | |
| 120068 | /* Make sure cursor numbers have been assigned to all entries in |
| 120069 | ** the FROM clause of the SELECT statement. |
| 120070 | */ |
| @@ -120062,13 +120347,11 @@ | |
| 120347 | if( pParse->hasCompound ){ |
| 120348 | w.xSelectCallback = convertCompoundSelectToSubquery; |
| 120349 | sqlite3WalkSelect(&w, pSelect); |
| 120350 | } |
| 120351 | w.xSelectCallback = selectExpander; |
| 120352 | w.xSelectCallback2 = selectPopWith; |
| 120353 | sqlite3WalkSelect(&w, pSelect); |
| 120354 | } |
| 120355 | |
| 120356 | |
| 120357 | #ifndef SQLITE_OMIT_SUBQUERY |
| @@ -121143,11 +121426,11 @@ | |
| 121426 | /* This case runs if the aggregate has no GROUP BY clause. The |
| 121427 | ** processing is much simpler since there is only a single row |
| 121428 | ** of output. |
| 121429 | */ |
| 121430 | resetAccumulator(pParse, &sAggInfo); |
| 121431 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMax, 0,flag,0); |
| 121432 | if( pWInfo==0 ){ |
| 121433 | sqlite3ExprListDelete(db, pDel); |
| 121434 | goto select_end; |
| 121435 | } |
| 121436 | updateAccumulator(pParse, &sAggInfo); |
| @@ -121232,12 +121515,10 @@ | |
| 121515 | ** |
| 121516 | ** These routines are in a separate files so that they will not be linked |
| 121517 | ** if they are not used. |
| 121518 | */ |
| 121519 | /* #include "sqliteInt.h" */ |
| 121520 | |
| 121521 | #ifndef SQLITE_OMIT_GET_TABLE |
| 121522 | |
| 121523 | /* |
| 121524 | ** This structure is used to pass data from sqlite3_get_table() through |
| @@ -122591,16 +122872,16 @@ | |
| 122872 | sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc, |
| 122873 | pCol->affinity, &pValue); |
| 122874 | if( pValue ){ |
| 122875 | sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 122876 | } |
| 122877 | } |
| 122878 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 122879 | if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 122880 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 122881 | } |
| 122882 | #endif |
| 122883 | } |
| 122884 | |
| 122885 | /* |
| 122886 | ** Process an UPDATE statement. |
| 122887 | ** |
| @@ -122625,11 +122906,11 @@ | |
| 122906 | int nIdx; /* Number of indices that need updating */ |
| 122907 | int iBaseCur; /* Base cursor number */ |
| 122908 | int iDataCur; /* Cursor for the canonical data btree */ |
| 122909 | int iIdxCur; /* Cursor for the first index */ |
| 122910 | sqlite3 *db; /* The database structure */ |
| 122911 | int *aRegIdx = 0; /* First register in array assigned to each index */ |
| 122912 | int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the |
| 122913 | ** an expression for the i-th column of the table. |
| 122914 | ** aXRef[i]==-1 if the i-th column is not changed. */ |
| 122915 | u8 *aToOpen; /* 1 for tables and indices to be opened */ |
| 122916 | u8 chngPk; /* PRIMARY KEY changed in a WITHOUT ROWID table */ |
| @@ -122637,14 +122918,15 @@ | |
| 122918 | u8 chngKey; /* Either chngPk or chngRowid */ |
| 122919 | Expr *pRowidExpr = 0; /* Expression defining the new record number */ |
| 122920 | AuthContext sContext; /* The authorization context */ |
| 122921 | NameContext sNC; /* The name-context to resolve expressions in */ |
| 122922 | int iDb; /* Database containing the table being updated */ |
| 122923 | int eOnePass; /* ONEPASS_XXX value from where.c */ |
| 122924 | int hasFK; /* True if foreign key processing is required */ |
| 122925 | int labelBreak; /* Jump here to break out of UPDATE loop */ |
| 122926 | int labelContinue; /* Jump here to continue next step of UPDATE loop */ |
| 122927 | int flags; /* Flags for sqlite3WhereBegin() */ |
| 122928 | |
| 122929 | #ifndef SQLITE_OMIT_TRIGGER |
| 122930 | int isView; /* True when updating a view (INSTEAD OF trigger) */ |
| 122931 | Trigger *pTrigger; /* List of triggers on pTab, if required */ |
| 122932 | int tmask; /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */ |
| @@ -122651,10 +122933,14 @@ | |
| 122933 | #endif |
| 122934 | int newmask; /* Mask of NEW.* columns accessed by BEFORE triggers */ |
| 122935 | int iEph = 0; /* Ephemeral table holding all primary key values */ |
| 122936 | int nKey = 0; /* Number of elements in regKey for WITHOUT ROWID */ |
| 122937 | int aiCurOnePass[2]; /* The write cursors opened by WHERE_ONEPASS */ |
| 122938 | int addrOpen = 0; /* Address of OP_OpenEphemeral */ |
| 122939 | int iPk = 0; /* First of nPk cells holding PRIMARY KEY value */ |
| 122940 | i16 nPk = 0; /* Number of components of the PRIMARY KEY */ |
| 122941 | int bReplace = 0; /* True if REPLACE conflict resolution might happen */ |
| 122942 | |
| 122943 | /* Register Allocations */ |
| 122944 | int regRowCount = 0; /* A count of rows changed */ |
| 122945 | int regOldRowid = 0; /* The old rowid */ |
| 122946 | int regNewRowid = 0; /* The new rowid */ |
| @@ -122810,17 +123096,27 @@ | |
| 123096 | for(i=0; i<pIdx->nKeyCol; i++){ |
| 123097 | i16 iIdxCol = pIdx->aiColumn[i]; |
| 123098 | if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){ |
| 123099 | reg = ++pParse->nMem; |
| 123100 | pParse->nMem += pIdx->nColumn; |
| 123101 | if( (onError==OE_Replace) |
| 123102 | || (onError==OE_Default && pIdx->onError==OE_Replace) |
| 123103 | ){ |
| 123104 | bReplace = 1; |
| 123105 | } |
| 123106 | break; |
| 123107 | } |
| 123108 | } |
| 123109 | } |
| 123110 | if( reg==0 ) aToOpen[j+1] = 0; |
| 123111 | aRegIdx[j] = reg; |
| 123112 | } |
| 123113 | if( bReplace ){ |
| 123114 | /* If REPLACE conflict resolution might be invoked, open cursors on all |
| 123115 | ** indexes in case they are needed to delete records. */ |
| 123116 | memset(aToOpen, 1, nIdx+1); |
| 123117 | } |
| 123118 | |
| 123119 | /* Begin generating code. */ |
| 123120 | v = sqlite3GetVdbe(pParse); |
| 123121 | if( v==0 ) goto update_cleanup; |
| 123122 | if( pParse->nested==0 ) sqlite3VdbeCountChanges(v); |
| @@ -122869,107 +123165,127 @@ | |
| 123165 | pWhere, onError); |
| 123166 | goto update_cleanup; |
| 123167 | } |
| 123168 | #endif |
| 123169 | |
| 123170 | /* Initialize the count of updated rows */ |
| 123171 | if( (db->flags & SQLITE_CountRows) && !pParse->pTriggerTab ){ |
| 123172 | regRowCount = ++pParse->nMem; |
| 123173 | sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount); |
| 123174 | } |
| 123175 | |
| 123176 | if( HasRowid(pTab) ){ |
| 123177 | sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid); |
| 123178 | }else{ |
| 123179 | assert( pPk!=0 ); |
| 123180 | nPk = pPk->nKeyCol; |
| 123181 | iPk = pParse->nMem+1; |
| 123182 | pParse->nMem += nPk; |
| 123183 | regKey = ++pParse->nMem; |
| 123184 | iEph = pParse->nTab++; |
| 123185 | |
| 123186 | sqlite3VdbeAddOp2(v, OP_Null, 0, iPk); |
| 123187 | addrOpen = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iEph, nPk); |
| 123188 | sqlite3VdbeSetP4KeyInfo(pParse, pPk); |
| 123189 | } |
| 123190 | |
| 123191 | /* Begin the database scan. |
| 123192 | ** |
| 123193 | ** Do not consider a single-pass strategy for a multi-row update if |
| 123194 | ** there are any triggers or foreign keys to process, or rows may |
| 123195 | ** be deleted as a result of REPLACE conflict handling. Any of these |
| 123196 | ** things might disturb a cursor being used to scan through the table |
| 123197 | ** or index, causing a single-pass approach to malfunction. */ |
| 123198 | flags = WHERE_ONEPASS_DESIRED|WHERE_SEEK_UNIQ_TABLE; |
| 123199 | if( !pParse->nested && !pTrigger && !hasFK && !chngKey && !bReplace ){ |
| 123200 | flags |= WHERE_ONEPASS_MULTIROW; |
| 123201 | } |
| 123202 | pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0, 0, flags, iIdxCur); |
| 123203 | if( pWInfo==0 ) goto update_cleanup; |
| 123204 | |
| 123205 | /* A one-pass strategy that might update more than one row may not |
| 123206 | ** be used if any column of the index used for the scan is being |
| 123207 | ** updated. Otherwise, if there is an index on "b", statements like |
| 123208 | ** the following could create an infinite loop: |
| 123209 | ** |
| 123210 | ** UPDATE t1 SET b=b+1 WHERE b>? |
| 123211 | ** |
| 123212 | ** Fall back to ONEPASS_OFF if where.c has selected a ONEPASS_MULTI |
| 123213 | ** strategy that uses an index for which one or more columns are being |
| 123214 | ** updated. */ |
| 123215 | eOnePass = sqlite3WhereOkOnePass(pWInfo, aiCurOnePass); |
| 123216 | if( eOnePass==ONEPASS_MULTI ){ |
| 123217 | int iCur = aiCurOnePass[1]; |
| 123218 | if( iCur>=0 && iCur!=iDataCur && aToOpen[iCur-iBaseCur] ){ |
| 123219 | eOnePass = ONEPASS_OFF; |
| 123220 | } |
| 123221 | assert( iCur!=iDataCur || !HasRowid(pTab) ); |
| 123222 | } |
| 123223 | |
| 123224 | if( HasRowid(pTab) ){ |
| 123225 | /* Read the rowid of the current row of the WHERE scan. In ONEPASS_OFF |
| 123226 | ** mode, write the rowid into the FIFO. In either of the one-pass modes, |
| 123227 | ** leave it in register regOldRowid. */ |
| 123228 | sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regOldRowid); |
| 123229 | if( eOnePass==ONEPASS_OFF ){ |
| 123230 | sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid); |
| 123231 | } |
| 123232 | }else{ |
| 123233 | /* Read the PK of the current row into an array of registers. In |
| 123234 | ** ONEPASS_OFF mode, serialize the array into a record and store it in |
| 123235 | ** the ephemeral table. Or, in ONEPASS_SINGLE or MULTI mode, change |
| 123236 | ** the OP_OpenEphemeral instruction to a Noop (the ephemeral table |
| 123237 | ** is not required) and leave the PK fields in the array of registers. */ |
| 123238 | for(i=0; i<nPk; i++){ |
| 123239 | assert( pPk->aiColumn[i]>=0 ); |
| 123240 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur,pPk->aiColumn[i],iPk+i); |
| 123241 | } |
| 123242 | if( eOnePass ){ |
| 123243 | sqlite3VdbeChangeToNoop(v, addrOpen); |
| 123244 | nKey = nPk; |
| 123245 | regKey = iPk; |
| 123246 | }else{ |
| 123247 | sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey, |
| 123248 | sqlite3IndexAffinityStr(db, pPk), nPk); |
| 123249 | sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk); |
| 123250 | } |
| 123251 | } |
| 123252 | |
| 123253 | if( eOnePass!=ONEPASS_MULTI ){ |
| 123254 | sqlite3WhereEnd(pWInfo); |
| 123255 | } |
| 123256 | |
| 123257 | labelBreak = sqlite3VdbeMakeLabel(v); |
| 123258 | if( !isView ){ |
| 123259 | int addrOnce = 0; |
| 123260 | |
| 123261 | /* Open every index that needs updating. */ |
| 123262 | if( eOnePass!=ONEPASS_OFF ){ |
| 123263 | if( aiCurOnePass[0]>=0 ) aToOpen[aiCurOnePass[0]-iBaseCur] = 0; |
| 123264 | if( aiCurOnePass[1]>=0 ) aToOpen[aiCurOnePass[1]-iBaseCur] = 0; |
| 123265 | } |
| 123266 | |
| 123267 | if( eOnePass==ONEPASS_MULTI && (nIdx-(aiCurOnePass[1]>=0))>0 ){ |
| 123268 | addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); |
| 123269 | } |
| 123270 | sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, 0, iBaseCur, aToOpen, |
| 123271 | 0, 0); |
| 123272 | if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce); |
| 123273 | } |
| 123274 | |
| 123275 | /* Top of the update loop */ |
| 123276 | if( eOnePass!=ONEPASS_OFF ){ |
| 123277 | if( !isView && aiCurOnePass[0]!=iDataCur && aiCurOnePass[1]!=iDataCur ){ |
| 123278 | assert( pPk ); |
| 123279 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey); |
| 123280 | VdbeCoverageNeverTaken(v); |
| 123281 | } |
| 123282 | if( eOnePass==ONEPASS_SINGLE ){ |
| 123283 | labelContinue = labelBreak; |
| 123284 | }else{ |
| 123285 | labelContinue = sqlite3VdbeMakeLabel(v); |
| 123286 | } |
| 123287 | sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak); |
| 123288 | VdbeCoverageIf(v, pPk==0); |
| 123289 | VdbeCoverageIf(v, pPk!=0); |
| 123290 | }else if( pPk ){ |
| 123291 | labelContinue = sqlite3VdbeMakeLabel(v); |
| @@ -123090,11 +123406,10 @@ | |
| 123406 | } |
| 123407 | } |
| 123408 | |
| 123409 | if( !isView ){ |
| 123410 | int addr1 = 0; /* Address of jump instruction */ |
| 123411 | |
| 123412 | /* Do constraint checks. */ |
| 123413 | assert( regOldRowid>0 ); |
| 123414 | sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur, |
| 123415 | regNewRowid, regOldRowid, chngKey, onError, labelContinue, &bReplace, |
| @@ -123126,18 +123441,22 @@ | |
| 123441 | ** is the column index supplied by the user. |
| 123442 | */ |
| 123443 | assert( regNew==regNewRowid+1 ); |
| 123444 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| 123445 | sqlite3VdbeAddOp3(v, OP_Delete, iDataCur, |
| 123446 | OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP), |
| 123447 | regNewRowid |
| 123448 | ); |
| 123449 | if( eOnePass==ONEPASS_MULTI ){ |
| 123450 | assert( hasFK==0 && chngKey==0 ); |
| 123451 | sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION); |
| 123452 | } |
| 123453 | if( !pParse->nested ){ |
| 123454 | sqlite3VdbeAppendP4(v, pTab, P4_TABLE); |
| 123455 | } |
| 123456 | #else |
| 123457 | if( hasFK || chngKey ){ |
| 123458 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0); |
| 123459 | } |
| 123460 | #endif |
| 123461 | if( bReplace || chngKey ){ |
| 123462 | sqlite3VdbeJumpHere(v, addr1); |
| @@ -123146,12 +123465,15 @@ | |
| 123465 | if( hasFK ){ |
| 123466 | sqlite3FkCheck(pParse, pTab, 0, regNewRowid, aXRef, chngKey); |
| 123467 | } |
| 123468 | |
| 123469 | /* Insert the new index entries and the new record. */ |
| 123470 | sqlite3CompleteInsertion( |
| 123471 | pParse, pTab, iDataCur, iIdxCur, regNewRowid, aRegIdx, |
| 123472 | OPFLAG_ISUPDATE | (eOnePass==ONEPASS_MULTI ? OPFLAG_SAVEPOSITION : 0), |
| 123473 | 0, 0 |
| 123474 | ); |
| 123475 | |
| 123476 | /* Do any ON CASCADE, SET NULL or SET DEFAULT operations required to |
| 123477 | ** handle rows (possibly in other tables) that refer via a foreign key |
| 123478 | ** to the row just updated. */ |
| 123479 | if( hasFK ){ |
| @@ -123169,12 +123491,15 @@ | |
| 123491 | TRIGGER_AFTER, pTab, regOldRowid, onError, labelContinue); |
| 123492 | |
| 123493 | /* Repeat the above with the next record to be updated, until |
| 123494 | ** all record selected by the WHERE clause have been updated. |
| 123495 | */ |
| 123496 | if( eOnePass==ONEPASS_SINGLE ){ |
| 123497 | /* Nothing to do at end-of-loop for a single-pass */ |
| 123498 | }else if( eOnePass==ONEPASS_MULTI ){ |
| 123499 | sqlite3VdbeResolveLabel(v, labelContinue); |
| 123500 | sqlite3WhereEnd(pWInfo); |
| 123501 | }else if( pPk ){ |
| 123502 | sqlite3VdbeResolveLabel(v, labelContinue); |
| 123503 | sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v); |
| 123504 | }else{ |
| 123505 | sqlite3VdbeGoto(v, labelContinue); |
| @@ -127090,11 +127415,14 @@ | |
| 127415 | |
| 127416 | /* Seek the table cursor, if required */ |
| 127417 | if( omitTable ){ |
| 127418 | /* pIdx is a covering index. No need to access the main table. */ |
| 127419 | }else if( HasRowid(pIdx->pTable) ){ |
| 127420 | if( (pWInfo->wctrlFlags & WHERE_SEEK_TABLE) || ( |
| 127421 | (pWInfo->wctrlFlags & WHERE_SEEK_UNIQ_TABLE) |
| 127422 | && (pWInfo->eOnePass==ONEPASS_SINGLE) |
| 127423 | )){ |
| 127424 | iRowidReg = ++pParse->nMem; |
| 127425 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg); |
| 127426 | sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg); |
| 127427 | sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, iRowidReg); |
| 127428 | VdbeCoverage(v); |
| @@ -128454,10 +128782,11 @@ | |
| 128782 | int noCase = 0; /* uppercase equivalent to lowercase */ |
| 128783 | int op; /* Top-level operator. pExpr->op */ |
| 128784 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 128785 | sqlite3 *db = pParse->db; /* Database connection */ |
| 128786 | unsigned char eOp2; /* op2 value for LIKE/REGEXP/GLOB */ |
| 128787 | int nLeft; /* Number of elements on left side vector */ |
| 128788 | |
| 128789 | if( db->mallocFailed ){ |
| 128790 | return; |
| 128791 | } |
| 128792 | pTerm = &pWC->a[idxTerm]; |
| @@ -128483,10 +128812,14 @@ | |
| 128812 | if( ExprHasProperty(pExpr, EP_FromJoin) ){ |
| 128813 | Bitmask x = sqlite3WhereGetMask(pMaskSet, pExpr->iRightJoinTable); |
| 128814 | prereqAll |= x; |
| 128815 | extraRight = x-1; /* ON clause terms may not be used with an index |
| 128816 | ** on left table of a LEFT JOIN. Ticket #3015 */ |
| 128817 | if( (prereqAll>>1)>=x ){ |
| 128818 | sqlite3ErrorMsg(pParse, "ON clause references tables to its right"); |
| 128819 | return; |
| 128820 | } |
| 128821 | } |
| 128822 | pTerm->prereqAll = prereqAll; |
| 128823 | pTerm->leftCursor = -1; |
| 128824 | pTerm->iParent = -1; |
| 128825 | pTerm->eOperator = 0; |
| @@ -128725,17 +129058,16 @@ | |
| 129058 | ** |
| 129059 | ** This is only required if at least one side of the comparison operation |
| 129060 | ** is not a sub-select. */ |
| 129061 | if( pWC->op==TK_AND |
| 129062 | && (pExpr->op==TK_EQ || pExpr->op==TK_IS) |
| 129063 | && (nLeft = sqlite3ExprVectorSize(pExpr->pLeft))>1 |
| 129064 | && sqlite3ExprVectorSize(pExpr->pRight)==nLeft |
| 129065 | && ( (pExpr->pLeft->flags & EP_xIsSelect)==0 |
| 129066 | || (pExpr->pRight->flags & EP_xIsSelect)==0) |
| 129067 | ){ |
| 129068 | int i; |
| 129069 | for(i=0; i<nLeft; i++){ |
| 129070 | int idxNew; |
| 129071 | Expr *pNew; |
| 129072 | Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i); |
| 129073 | Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i); |
| @@ -133934,11 +134266,12 @@ | |
| 134266 | x = sqlite3ColumnOfIndex(pIdx, x); |
| 134267 | if( x>=0 ){ |
| 134268 | pOp->p2 = x; |
| 134269 | pOp->p1 = pLevel->iIdxCur; |
| 134270 | } |
| 134271 | assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0 |
| 134272 | || pWInfo->eOnePass ); |
| 134273 | }else if( pOp->opcode==OP_Rowid ){ |
| 134274 | pOp->p1 = pLevel->iIdxCur; |
| 134275 | pOp->opcode = OP_IdxRowid; |
| 134276 | } |
| 134277 | } |
| @@ -133998,10 +134331,23 @@ | |
| 134331 | ** Indicate that sqlite3ParserFree() will never be called with a null |
| 134332 | ** pointer. |
| 134333 | */ |
| 134334 | #define YYPARSEFREENEVERNULL 1 |
| 134335 | |
| 134336 | /* |
| 134337 | ** In the amalgamation, the parse.c file generated by lemon and the |
| 134338 | ** tokenize.c file are concatenated. In that case, sqlite3RunParser() |
| 134339 | ** has access to the the size of the yyParser object and so the parser |
| 134340 | ** engine can be allocated from stack. In that case, only the |
| 134341 | ** sqlite3ParserInit() and sqlite3ParserFinalize() routines are invoked |
| 134342 | ** and the sqlite3ParserAlloc() and sqlite3ParserFree() routines can be |
| 134343 | ** omitted. |
| 134344 | */ |
| 134345 | #ifdef SQLITE_AMALGAMATION |
| 134346 | # define sqlite3Parser_ENGINEALWAYSONSTACK 1 |
| 134347 | #endif |
| 134348 | |
| 134349 | /* |
| 134350 | ** Alternative datatype for the argument to the malloc() routine passed |
| 134351 | ** into sqlite3ParserAlloc(). The default is size_t. |
| 134352 | */ |
| 134353 | #define YYMALLOCARGTYPE u64 |
| @@ -135446,10 +135792,35 @@ | |
| 135792 | */ |
| 135793 | #ifndef YYMALLOCARGTYPE |
| 135794 | # define YYMALLOCARGTYPE size_t |
| 135795 | #endif |
| 135796 | |
| 135797 | /* Initialize a new parser that has already been allocated. |
| 135798 | */ |
| 135799 | SQLITE_PRIVATE void sqlite3ParserInit(void *yypParser){ |
| 135800 | yyParser *pParser = (yyParser*)yypParser; |
| 135801 | #ifdef YYTRACKMAXSTACKDEPTH |
| 135802 | pParser->yyhwm = 0; |
| 135803 | #endif |
| 135804 | #if YYSTACKDEPTH<=0 |
| 135805 | pParser->yytos = NULL; |
| 135806 | pParser->yystack = NULL; |
| 135807 | pParser->yystksz = 0; |
| 135808 | if( yyGrowStack(pParser) ){ |
| 135809 | pParser->yystack = &pParser->yystk0; |
| 135810 | pParser->yystksz = 1; |
| 135811 | } |
| 135812 | #endif |
| 135813 | #ifndef YYNOERRORRECOVERY |
| 135814 | pParser->yyerrcnt = -1; |
| 135815 | #endif |
| 135816 | pParser->yytos = pParser->yystack; |
| 135817 | pParser->yystack[0].stateno = 0; |
| 135818 | pParser->yystack[0].major = 0; |
| 135819 | } |
| 135820 | |
| 135821 | #ifndef sqlite3Parser_ENGINEALWAYSONSTACK |
| 135822 | /* |
| 135823 | ** This function allocates a new parser. |
| 135824 | ** The only argument is a pointer to a function which works like |
| 135825 | ** malloc. |
| 135826 | ** |
| @@ -135461,32 +135832,15 @@ | |
| 135832 | ** to sqlite3Parser and sqlite3ParserFree. |
| 135833 | */ |
| 135834 | SQLITE_PRIVATE void *sqlite3ParserAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ |
| 135835 | yyParser *pParser; |
| 135836 | pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); |
| 135837 | if( pParser ) sqlite3ParserInit(pParser); |
| 135838 | return pParser; |
| 135839 | } |
| 135840 | #endif /* sqlite3Parser_ENGINEALWAYSONSTACK */ |
| 135841 | |
| 135842 | |
| 135843 | /* The following function deletes the "minor type" or semantic value |
| 135844 | ** associated with a symbol. The symbol can be either a terminal |
| 135845 | ** or nonterminal. "yymajor" is the symbol code, and "yypminor" is |
| 135846 | ** a pointer to the value to be deleted. The code used to do the |
| @@ -135608,10 +135962,22 @@ | |
| 135962 | } |
| 135963 | #endif |
| 135964 | yy_destructor(pParser, yytos->major, &yytos->minor); |
| 135965 | } |
| 135966 | |
| 135967 | /* |
| 135968 | ** Clear all secondary memory allocations from the parser |
| 135969 | */ |
| 135970 | SQLITE_PRIVATE void sqlite3ParserFinalize(void *p){ |
| 135971 | yyParser *pParser = (yyParser*)p; |
| 135972 | while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser); |
| 135973 | #if YYSTACKDEPTH<=0 |
| 135974 | if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack); |
| 135975 | #endif |
| 135976 | } |
| 135977 | |
| 135978 | #ifndef sqlite3Parser_ENGINEALWAYSONSTACK |
| 135979 | /* |
| 135980 | ** Deallocate and destroy a parser. Destructors are called for |
| 135981 | ** all stack elements before shutting the parser down. |
| 135982 | ** |
| 135983 | ** If the YYPARSEFREENEVERNULL macro exists (for example because it |
| @@ -135620,20 +135986,17 @@ | |
| 135986 | */ |
| 135987 | SQLITE_PRIVATE void sqlite3ParserFree( |
| 135988 | void *p, /* The parser to be deleted */ |
| 135989 | void (*freeProc)(void*) /* Function used to reclaim memory */ |
| 135990 | ){ |
| 135991 | #ifndef YYPARSEFREENEVERNULL |
| 135992 | if( p==0 ) return; |
| 135993 | #endif |
| 135994 | sqlite3ParserFinalize(p); |
| 135995 | (*freeProc)(p); |
| 135996 | } |
| 135997 | #endif /* sqlite3Parser_ENGINEALWAYSONSTACK */ |
| 135998 | |
| 135999 | /* |
| 136000 | ** Return the peak depth of the stack for a parser. |
| 136001 | */ |
| 136002 | #ifdef YYTRACKMAXSTACKDEPTH |
| @@ -138483,10 +138846,13 @@ | |
| 138846 | void *pEngine; /* The LEMON-generated LALR(1) parser */ |
| 138847 | int tokenType; /* type of the next token */ |
| 138848 | int lastTokenParsed = -1; /* type of the previous token */ |
| 138849 | sqlite3 *db = pParse->db; /* The database connection */ |
| 138850 | int mxSqlLen; /* Max length of an SQL string */ |
| 138851 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 138852 | unsigned char zSpace[sizeof(yyParser)]; /* Space for parser engine object */ |
| 138853 | #endif |
| 138854 | |
| 138855 | assert( zSql!=0 ); |
| 138856 | mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 138857 | if( db->nVdbeActive==0 ){ |
| 138858 | db->u1.isInterrupted = 0; |
| @@ -138494,15 +138860,20 @@ | |
| 138860 | pParse->rc = SQLITE_OK; |
| 138861 | pParse->zTail = zSql; |
| 138862 | i = 0; |
| 138863 | assert( pzErrMsg!=0 ); |
| 138864 | /* sqlite3ParserTrace(stdout, "parser: "); */ |
| 138865 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 138866 | pEngine = zSpace; |
| 138867 | sqlite3ParserInit(pEngine); |
| 138868 | #else |
| 138869 | pEngine = sqlite3ParserAlloc(sqlite3Malloc); |
| 138870 | if( pEngine==0 ){ |
| 138871 | sqlite3OomFault(db); |
| 138872 | return SQLITE_NOMEM_BKPT; |
| 138873 | } |
| 138874 | #endif |
| 138875 | assert( pParse->pNewTable==0 ); |
| 138876 | assert( pParse->pNewTrigger==0 ); |
| 138877 | assert( pParse->nVar==0 ); |
| 138878 | assert( pParse->pVList==0 ); |
| 138879 | while( 1 ){ |
| @@ -138550,11 +138921,15 @@ | |
| 138921 | sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK, |
| 138922 | sqlite3ParserStackPeak(pEngine) |
| 138923 | ); |
| 138924 | sqlite3_mutex_leave(sqlite3MallocMutex()); |
| 138925 | #endif /* YYDEBUG */ |
| 138926 | #ifdef sqlite3Parser_ENGINEALWAYSONSTACK |
| 138927 | sqlite3ParserFinalize(pEngine); |
| 138928 | #else |
| 138929 | sqlite3ParserFree(pEngine, sqlite3_free); |
| 138930 | #endif |
| 138931 | if( db->mallocFailed ){ |
| 138932 | pParse->rc = SQLITE_NOMEM_BKPT; |
| 138933 | } |
| 138934 | if( pParse->rc!=SQLITE_OK && pParse->rc!=SQLITE_DONE && pParse->zErrMsg==0 ){ |
| 138935 | pParse->zErrMsg = sqlite3MPrintf(db, "%s", sqlite3ErrStr(pParse->rc)); |
| @@ -145675,13 +146050,13 @@ | |
| 146050 | p->nPendingData = 0; |
| 146051 | p->azColumn = (char **)&p[1]; |
| 146052 | p->pTokenizer = pTokenizer; |
| 146053 | p->nMaxPendingData = FTS3_MAX_PENDING_DATA; |
| 146054 | p->bHasDocsize = (isFts4 && bNoDocsize==0); |
| 146055 | p->bHasStat = (u8)isFts4; |
| 146056 | p->bFts4 = (u8)isFts4; |
| 146057 | p->bDescIdx = (u8)bDescIdx; |
| 146058 | p->nAutoincrmerge = 0xff; /* 0xff means setting unknown */ |
| 146059 | p->zContentTbl = zContent; |
| 146060 | p->zLanguageid = zLanguageid; |
| 146061 | zContent = 0; |
| 146062 | zLanguageid = 0; |
| @@ -147734,11 +148109,11 @@ | |
| 148109 | sqlite3_stmt *pStmt = 0; |
| 148110 | rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0); |
| 148111 | if( rc==SQLITE_OK ){ |
| 148112 | int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW); |
| 148113 | rc = sqlite3_finalize(pStmt); |
| 148114 | if( rc==SQLITE_OK ) p->bHasStat = (u8)bHasStat; |
| 148115 | } |
| 148116 | sqlite3_free(zSql); |
| 148117 | }else{ |
| 148118 | rc = SQLITE_NOMEM; |
| 148119 | } |
| @@ -162638,28 +163013,33 @@ | |
| 163013 | struct Rtree { |
| 163014 | sqlite3_vtab base; /* Base class. Must be first */ |
| 163015 | sqlite3 *db; /* Host database connection */ |
| 163016 | int iNodeSize; /* Size in bytes of each node in the node table */ |
| 163017 | u8 nDim; /* Number of dimensions */ |
| 163018 | u8 nDim2; /* Twice the number of dimensions */ |
| 163019 | u8 eCoordType; /* RTREE_COORD_REAL32 or RTREE_COORD_INT32 */ |
| 163020 | u8 nBytesPerCell; /* Bytes consumed per cell */ |
| 163021 | u8 inWrTrans; /* True if inside write transaction */ |
| 163022 | int iDepth; /* Current depth of the r-tree structure */ |
| 163023 | char *zDb; /* Name of database containing r-tree table */ |
| 163024 | char *zName; /* Name of r-tree table */ |
| 163025 | u32 nBusy; /* Current number of users of this structure */ |
| 163026 | i64 nRowEst; /* Estimated number of rows in this table */ |
| 163027 | u32 nCursor; /* Number of open cursors */ |
| 163028 | |
| 163029 | /* List of nodes removed during a CondenseTree operation. List is |
| 163030 | ** linked together via the pointer normally used for hash chains - |
| 163031 | ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree |
| 163032 | ** headed by the node (leaf nodes have RtreeNode.iNode==0). |
| 163033 | */ |
| 163034 | RtreeNode *pDeleted; |
| 163035 | int iReinsertHeight; /* Height of sub-trees Reinsert() has run on */ |
| 163036 | |
| 163037 | /* Blob I/O on xxx_node */ |
| 163038 | sqlite3_blob *pNodeBlob; |
| 163039 | |
| 163040 | /* Statements to read/write/delete a record from xxx_node */ |
| 163041 | sqlite3_stmt *pWriteNode; |
| 163042 | sqlite3_stmt *pDeleteNode; |
| 163043 | |
| 163044 | /* Statements to read/write/delete a record from xxx_rowid */ |
| 163045 | sqlite3_stmt *pReadRowid; |
| @@ -162884,26 +163264,110 @@ | |
| 163264 | #endif |
| 163265 | #ifndef MIN |
| 163266 | # define MIN(x,y) ((x) > (y) ? (y) : (x)) |
| 163267 | #endif |
| 163268 | |
| 163269 | /* What version of GCC is being used. 0 means GCC is not being used */ |
| 163270 | #ifndef GCC_VERSION |
| 163271 | #ifdef __GNUC__ |
| 163272 | # define GCC_VERSION (__GNUC__*1000000+__GNUC_MINOR__*1000+__GNUC_PATCHLEVEL__) |
| 163273 | #else |
| 163274 | # define GCC_VERSION 0 |
| 163275 | #endif |
| 163276 | #endif |
| 163277 | |
| 163278 | /* What version of CLANG is being used. 0 means CLANG is not being used */ |
| 163279 | #ifndef CLANG_VERSION |
| 163280 | #if defined(__clang__) && !defined(_WIN32) |
| 163281 | # define CLANG_VERSION \ |
| 163282 | (__clang_major__*1000000+__clang_minor__*1000+__clang_patchlevel__) |
| 163283 | #else |
| 163284 | # define CLANG_VERSION 0 |
| 163285 | #endif |
| 163286 | #endif |
| 163287 | |
| 163288 | /* The testcase() macro should already be defined in the amalgamation. If |
| 163289 | ** it is not, make it a no-op. |
| 163290 | */ |
| 163291 | #ifndef SQLITE_AMALGAMATION |
| 163292 | # define testcase(X) |
| 163293 | #endif |
| 163294 | |
| 163295 | /* |
| 163296 | ** Macros to determine whether the machine is big or little endian, |
| 163297 | ** and whether or not that determination is run-time or compile-time. |
| 163298 | ** |
| 163299 | ** For best performance, an attempt is made to guess at the byte-order |
| 163300 | ** using C-preprocessor macros. If that is unsuccessful, or if |
| 163301 | ** -DSQLITE_RUNTIME_BYTEORDER=1 is set, then byte-order is determined |
| 163302 | ** at run-time. |
| 163303 | */ |
| 163304 | #ifndef SQLITE_BYTEORDER |
| 163305 | #if (defined(i386) || defined(__i386__) || defined(_M_IX86) || \ |
| 163306 | defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || \ |
| 163307 | defined(_M_AMD64) || defined(_M_ARM) || defined(__x86) || \ |
| 163308 | defined(__arm__)) && !defined(SQLITE_RUNTIME_BYTEORDER) |
| 163309 | # define SQLITE_BYTEORDER 1234 |
| 163310 | #elif (defined(sparc) || defined(__ppc__)) \ |
| 163311 | && !defined(SQLITE_RUNTIME_BYTEORDER) |
| 163312 | # define SQLITE_BYTEORDER 4321 |
| 163313 | #else |
| 163314 | # define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */ |
| 163315 | #endif |
| 163316 | #endif |
| 163317 | |
| 163318 | |
| 163319 | /* What version of MSVC is being used. 0 means MSVC is not being used */ |
| 163320 | #ifndef MSVC_VERSION |
| 163321 | #if defined(_MSC_VER) |
| 163322 | # define MSVC_VERSION _MSC_VER |
| 163323 | #else |
| 163324 | # define MSVC_VERSION 0 |
| 163325 | #endif |
| 163326 | #endif |
| 163327 | |
| 163328 | /* |
| 163329 | ** Functions to deserialize a 16 bit integer, 32 bit real number and |
| 163330 | ** 64 bit integer. The deserialized value is returned. |
| 163331 | */ |
| 163332 | static int readInt16(u8 *p){ |
| 163333 | return (p[0]<<8) + p[1]; |
| 163334 | } |
| 163335 | static void readCoord(u8 *p, RtreeCoord *pCoord){ |
| 163336 | assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ |
| 163337 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163338 | pCoord->u = _byteswap_ulong(*(u32*)p); |
| 163339 | #elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163340 | pCoord->u = __builtin_bswap32(*(u32*)p); |
| 163341 | #elif SQLITE_BYTEORDER==1234 |
| 163342 | pCoord->u = ((pCoord->u>>24)&0xff)|((pCoord->u>>8)&0xff00)| |
| 163343 | ((pCoord->u&0xff)<<24)|((pCoord->u&0xff00)<<8); |
| 163344 | #elif SQLITE_BYTEORDER==4321 |
| 163345 | pCoord->u = *(u32*)p; |
| 163346 | #else |
| 163347 | pCoord->u = ( |
| 163348 | (((u32)p[0]) << 24) + |
| 163349 | (((u32)p[1]) << 16) + |
| 163350 | (((u32)p[2]) << 8) + |
| 163351 | (((u32)p[3]) << 0) |
| 163352 | ); |
| 163353 | #endif |
| 163354 | } |
| 163355 | static i64 readInt64(u8 *p){ |
| 163356 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163357 | u64 x; |
| 163358 | memcpy(&x, p, 8); |
| 163359 | return (i64)_byteswap_uint64(x); |
| 163360 | #elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163361 | u64 x; |
| 163362 | memcpy(&x, p, 8); |
| 163363 | return (i64)__builtin_bswap64(x); |
| 163364 | #elif SQLITE_BYTEORDER==4321 |
| 163365 | i64 x; |
| 163366 | memcpy(&x, p, 8); |
| 163367 | return x; |
| 163368 | #else |
| 163369 | return ( |
| 163370 | (((i64)p[0]) << 56) + |
| 163371 | (((i64)p[1]) << 48) + |
| 163372 | (((i64)p[2]) << 40) + |
| 163373 | (((i64)p[3]) << 32) + |
| @@ -162910,10 +163374,11 @@ | |
| 163374 | (((i64)p[4]) << 24) + |
| 163375 | (((i64)p[5]) << 16) + |
| 163376 | (((i64)p[6]) << 8) + |
| 163377 | (((i64)p[7]) << 0) |
| 163378 | ); |
| 163379 | #endif |
| 163380 | } |
| 163381 | |
| 163382 | /* |
| 163383 | ** Functions to serialize a 16 bit integer, 32 bit real number and |
| 163384 | ** 64 bit integer. The value returned is the number of bytes written |
| @@ -162924,28 +163389,50 @@ | |
| 163389 | p[1] = (i>> 0)&0xFF; |
| 163390 | return 2; |
| 163391 | } |
| 163392 | static int writeCoord(u8 *p, RtreeCoord *pCoord){ |
| 163393 | u32 i; |
| 163394 | assert( ((((char*)p) - (char*)0)&3)==0 ); /* p is always 4-byte aligned */ |
| 163395 | assert( sizeof(RtreeCoord)==4 ); |
| 163396 | assert( sizeof(u32)==4 ); |
| 163397 | #if SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163398 | i = __builtin_bswap32(pCoord->u); |
| 163399 | memcpy(p, &i, 4); |
| 163400 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163401 | i = _byteswap_ulong(pCoord->u); |
| 163402 | memcpy(p, &i, 4); |
| 163403 | #elif SQLITE_BYTEORDER==4321 |
| 163404 | i = pCoord->u; |
| 163405 | memcpy(p, &i, 4); |
| 163406 | #else |
| 163407 | i = pCoord->u; |
| 163408 | p[0] = (i>>24)&0xFF; |
| 163409 | p[1] = (i>>16)&0xFF; |
| 163410 | p[2] = (i>> 8)&0xFF; |
| 163411 | p[3] = (i>> 0)&0xFF; |
| 163412 | #endif |
| 163413 | return 4; |
| 163414 | } |
| 163415 | static int writeInt64(u8 *p, i64 i){ |
| 163416 | #if SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163417 | i = (i64)__builtin_bswap64((u64)i); |
| 163418 | memcpy(p, &i, 8); |
| 163419 | #elif SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163420 | i = (i64)_byteswap_uint64((u64)i); |
| 163421 | memcpy(p, &i, 8); |
| 163422 | #elif SQLITE_BYTEORDER==4321 |
| 163423 | memcpy(p, &i, 8); |
| 163424 | #else |
| 163425 | p[0] = (i>>56)&0xFF; |
| 163426 | p[1] = (i>>48)&0xFF; |
| 163427 | p[2] = (i>>40)&0xFF; |
| 163428 | p[3] = (i>>32)&0xFF; |
| 163429 | p[4] = (i>>24)&0xFF; |
| 163430 | p[5] = (i>>16)&0xFF; |
| 163431 | p[6] = (i>> 8)&0xFF; |
| 163432 | p[7] = (i>> 0)&0xFF; |
| 163433 | #endif |
| 163434 | return 8; |
| 163435 | } |
| 163436 | |
| 163437 | /* |
| 163438 | ** Increment the reference count of node p. |
| @@ -163023,10 +163510,21 @@ | |
| 163510 | pNode->isDirty = 1; |
| 163511 | nodeReference(pParent); |
| 163512 | } |
| 163513 | return pNode; |
| 163514 | } |
| 163515 | |
| 163516 | /* |
| 163517 | ** Clear the Rtree.pNodeBlob object |
| 163518 | */ |
| 163519 | static void nodeBlobReset(Rtree *pRtree){ |
| 163520 | if( pRtree->pNodeBlob && pRtree->inWrTrans==0 && pRtree->nCursor==0 ){ |
| 163521 | sqlite3_blob *pBlob = pRtree->pNodeBlob; |
| 163522 | pRtree->pNodeBlob = 0; |
| 163523 | sqlite3_blob_close(pBlob); |
| 163524 | } |
| 163525 | } |
| 163526 | |
| 163527 | /* |
| 163528 | ** Obtain a reference to an r-tree node. |
| 163529 | */ |
| 163530 | static int nodeAcquire( |
| @@ -163033,13 +163531,12 @@ | |
| 163531 | Rtree *pRtree, /* R-tree structure */ |
| 163532 | i64 iNode, /* Node number to load */ |
| 163533 | RtreeNode *pParent, /* Either the parent node or NULL */ |
| 163534 | RtreeNode **ppNode /* OUT: Acquired node */ |
| 163535 | ){ |
| 163536 | int rc = SQLITE_OK; |
| 163537 | RtreeNode *pNode = 0; |
| 163538 | |
| 163539 | /* Check if the requested node is already in the hash table. If so, |
| 163540 | ** increase its reference count and return it. |
| 163541 | */ |
| 163542 | if( (pNode = nodeHashLookup(pRtree, iNode)) ){ |
| @@ -163051,32 +163548,49 @@ | |
| 163548 | pNode->nRef++; |
| 163549 | *ppNode = pNode; |
| 163550 | return SQLITE_OK; |
| 163551 | } |
| 163552 | |
| 163553 | if( pRtree->pNodeBlob ){ |
| 163554 | sqlite3_blob *pBlob = pRtree->pNodeBlob; |
| 163555 | pRtree->pNodeBlob = 0; |
| 163556 | rc = sqlite3_blob_reopen(pBlob, iNode); |
| 163557 | pRtree->pNodeBlob = pBlob; |
| 163558 | if( rc ){ |
| 163559 | nodeBlobReset(pRtree); |
| 163560 | if( rc==SQLITE_NOMEM ) return SQLITE_NOMEM; |
| 163561 | } |
| 163562 | } |
| 163563 | if( pRtree->pNodeBlob==0 ){ |
| 163564 | char *zTab = sqlite3_mprintf("%s_node", pRtree->zName); |
| 163565 | if( zTab==0 ) return SQLITE_NOMEM; |
| 163566 | rc = sqlite3_blob_open(pRtree->db, pRtree->zDb, zTab, "data", iNode, 0, |
| 163567 | &pRtree->pNodeBlob); |
| 163568 | sqlite3_free(zTab); |
| 163569 | } |
| 163570 | if( rc ){ |
| 163571 | nodeBlobReset(pRtree); |
| 163572 | *ppNode = 0; |
| 163573 | /* If unable to open an sqlite3_blob on the desired row, that can only |
| 163574 | ** be because the shadow tables hold erroneous data. */ |
| 163575 | if( rc==SQLITE_ERROR ) rc = SQLITE_CORRUPT_VTAB; |
| 163576 | }else if( pRtree->iNodeSize==sqlite3_blob_bytes(pRtree->pNodeBlob) ){ |
| 163577 | pNode = (RtreeNode *)sqlite3_malloc(sizeof(RtreeNode)+pRtree->iNodeSize); |
| 163578 | if( !pNode ){ |
| 163579 | rc = SQLITE_NOMEM; |
| 163580 | }else{ |
| 163581 | pNode->pParent = pParent; |
| 163582 | pNode->zData = (u8 *)&pNode[1]; |
| 163583 | pNode->nRef = 1; |
| 163584 | pNode->iNode = iNode; |
| 163585 | pNode->isDirty = 0; |
| 163586 | pNode->pNext = 0; |
| 163587 | rc = sqlite3_blob_read(pRtree->pNodeBlob, pNode->zData, |
| 163588 | pRtree->iNodeSize, 0); |
| 163589 | nodeReference(pParent); |
| 163590 | } |
| 163591 | } |
| 163592 | |
| 163593 | /* If the root node was just loaded, set pRtree->iDepth to the height |
| 163594 | ** of the r-tree structure. A height of zero means all data is stored on |
| 163595 | ** the root node. A height of one means the children of the root node |
| 163596 | ** are the leaves, and so on. If the depth as specified on the root node |
| @@ -163124,11 +163638,11 @@ | |
| 163638 | int iCell /* Index into pNode into which pCell is written */ |
| 163639 | ){ |
| 163640 | int ii; |
| 163641 | u8 *p = &pNode->zData[4 + pRtree->nBytesPerCell*iCell]; |
| 163642 | p += writeInt64(p, pCell->iRowid); |
| 163643 | for(ii=0; ii<pRtree->nDim2; ii++){ |
| 163644 | p += writeCoord(p, &pCell->aCoord[ii]); |
| 163645 | } |
| 163646 | pNode->isDirty = 1; |
| 163647 | } |
| 163648 | |
| @@ -163258,17 +163772,20 @@ | |
| 163772 | int iCell, /* Index of the cell within the node */ |
| 163773 | RtreeCell *pCell /* OUT: Write the cell contents here */ |
| 163774 | ){ |
| 163775 | u8 *pData; |
| 163776 | RtreeCoord *pCoord; |
| 163777 | int ii = 0; |
| 163778 | pCell->iRowid = nodeGetRowid(pRtree, pNode, iCell); |
| 163779 | pData = pNode->zData + (12 + pRtree->nBytesPerCell*iCell); |
| 163780 | pCoord = pCell->aCoord; |
| 163781 | do{ |
| 163782 | readCoord(pData, &pCoord[ii]); |
| 163783 | readCoord(pData+4, &pCoord[ii+1]); |
| 163784 | pData += 8; |
| 163785 | ii += 2; |
| 163786 | }while( ii<pRtree->nDim2 ); |
| 163787 | } |
| 163788 | |
| 163789 | |
| 163790 | /* Forward declaration for the function that does the work of |
| 163791 | ** the virtual table module xCreate() and xConnect() methods. |
| @@ -163315,11 +163832,13 @@ | |
| 163832 | ** zero the structure is deleted. |
| 163833 | */ |
| 163834 | static void rtreeRelease(Rtree *pRtree){ |
| 163835 | pRtree->nBusy--; |
| 163836 | if( pRtree->nBusy==0 ){ |
| 163837 | pRtree->inWrTrans = 0; |
| 163838 | pRtree->nCursor = 0; |
| 163839 | nodeBlobReset(pRtree); |
| 163840 | sqlite3_finalize(pRtree->pWriteNode); |
| 163841 | sqlite3_finalize(pRtree->pDeleteNode); |
| 163842 | sqlite3_finalize(pRtree->pReadRowid); |
| 163843 | sqlite3_finalize(pRtree->pWriteRowid); |
| 163844 | sqlite3_finalize(pRtree->pDeleteRowid); |
| @@ -163353,10 +163872,11 @@ | |
| 163872 | pRtree->zDb, pRtree->zName |
| 163873 | ); |
| 163874 | if( !zCreate ){ |
| 163875 | rc = SQLITE_NOMEM; |
| 163876 | }else{ |
| 163877 | nodeBlobReset(pRtree); |
| 163878 | rc = sqlite3_exec(pRtree->db, zCreate, 0, 0, 0); |
| 163879 | sqlite3_free(zCreate); |
| 163880 | } |
| 163881 | if( rc==SQLITE_OK ){ |
| 163882 | rtreeRelease(pRtree); |
| @@ -163368,17 +163888,19 @@ | |
| 163888 | /* |
| 163889 | ** Rtree virtual table module xOpen method. |
| 163890 | */ |
| 163891 | static int rtreeOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){ |
| 163892 | int rc = SQLITE_NOMEM; |
| 163893 | Rtree *pRtree = (Rtree *)pVTab; |
| 163894 | RtreeCursor *pCsr; |
| 163895 | |
| 163896 | pCsr = (RtreeCursor *)sqlite3_malloc(sizeof(RtreeCursor)); |
| 163897 | if( pCsr ){ |
| 163898 | memset(pCsr, 0, sizeof(RtreeCursor)); |
| 163899 | pCsr->base.pVtab = pVTab; |
| 163900 | rc = SQLITE_OK; |
| 163901 | pRtree->nCursor++; |
| 163902 | } |
| 163903 | *ppCursor = (sqlite3_vtab_cursor *)pCsr; |
| 163904 | |
| 163905 | return rc; |
| 163906 | } |
| @@ -163407,14 +163929,17 @@ | |
| 163929 | */ |
| 163930 | static int rtreeClose(sqlite3_vtab_cursor *cur){ |
| 163931 | Rtree *pRtree = (Rtree *)(cur->pVtab); |
| 163932 | int ii; |
| 163933 | RtreeCursor *pCsr = (RtreeCursor *)cur; |
| 163934 | assert( pRtree->nCursor>0 ); |
| 163935 | freeCursorConstraints(pCsr); |
| 163936 | sqlite3_free(pCsr->aPoint); |
| 163937 | for(ii=0; ii<RTREE_CACHE_SZ; ii++) nodeRelease(pRtree, pCsr->aNode[ii]); |
| 163938 | sqlite3_free(pCsr); |
| 163939 | pRtree->nCursor--; |
| 163940 | nodeBlobReset(pRtree); |
| 163941 | return SQLITE_OK; |
| 163942 | } |
| 163943 | |
| 163944 | /* |
| 163945 | ** Rtree virtual table module xEof method. |
| @@ -163433,27 +163958,34 @@ | |
| 163958 | ** endian platforms. The on-disk record stores integer coordinates if |
| 163959 | ** eInt is true and it stores 32-bit floating point records if eInt is |
| 163960 | ** false. a[] is the four bytes of the on-disk record to be decoded. |
| 163961 | ** Store the results in "r". |
| 163962 | ** |
| 163963 | ** There are five versions of this macro. The last one is generic. The |
| 163964 | ** other four are various architectures-specific optimizations. |
| 163965 | */ |
| 163966 | #if SQLITE_BYTEORDER==1234 && MSVC_VERSION>=1300 |
| 163967 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163968 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163969 | c.u = _byteswap_ulong(*(u32*)a); \ |
| 163970 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163971 | } |
| 163972 | #elif SQLITE_BYTEORDER==1234 && (GCC_VERSION>=4003000 || CLANG_VERSION>=3000000) |
| 163973 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163974 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163975 | c.u = __builtin_bswap32(*(u32*)a); \ |
| 163976 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163977 | } |
| 163978 | #elif SQLITE_BYTEORDER==1234 |
| 163979 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163980 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163981 | memcpy(&c.u,a,4); \ |
| 163982 | c.u = ((c.u>>24)&0xff)|((c.u>>8)&0xff00)| \ |
| 163983 | ((c.u&0xff)<<24)|((c.u&0xff00)<<8); \ |
| 163984 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163985 | } |
| 163986 | #elif SQLITE_BYTEORDER==4321 |
| 163987 | #define RTREE_DECODE_COORD(eInt, a, r) { \ |
| 163988 | RtreeCoord c; /* Coordinate decoded */ \ |
| 163989 | memcpy(&c.u,a,4); \ |
| 163990 | r = eInt ? (sqlite3_rtree_dbl)c.i : (sqlite3_rtree_dbl)c.f; \ |
| 163991 | } |
| @@ -163476,30 +164008,58 @@ | |
| 164008 | u8 *pCellData, /* Raw cell content */ |
| 164009 | RtreeSearchPoint *pSearch, /* Container of this cell */ |
| 164010 | sqlite3_rtree_dbl *prScore, /* OUT: score for the cell */ |
| 164011 | int *peWithin /* OUT: visibility of the cell */ |
| 164012 | ){ |
| 164013 | sqlite3_rtree_query_info *pInfo = pConstraint->pInfo; /* Callback info */ |
| 164014 | int nCoord = pInfo->nCoord; /* No. of coordinates */ |
| 164015 | int rc; /* Callback return code */ |
| 164016 | RtreeCoord c; /* Translator union */ |
| 164017 | sqlite3_rtree_dbl aCoord[RTREE_MAX_DIMENSIONS*2]; /* Decoded coordinates */ |
| 164018 | |
| 164019 | assert( pConstraint->op==RTREE_MATCH || pConstraint->op==RTREE_QUERY ); |
| 164020 | assert( nCoord==2 || nCoord==4 || nCoord==6 || nCoord==8 || nCoord==10 ); |
| 164021 | |
| 164022 | if( pConstraint->op==RTREE_QUERY && pSearch->iLevel==1 ){ |
| 164023 | pInfo->iRowid = readInt64(pCellData); |
| 164024 | } |
| 164025 | pCellData += 8; |
| 164026 | #ifndef SQLITE_RTREE_INT_ONLY |
| 164027 | if( eInt==0 ){ |
| 164028 | switch( nCoord ){ |
| 164029 | case 10: readCoord(pCellData+36, &c); aCoord[9] = c.f; |
| 164030 | readCoord(pCellData+32, &c); aCoord[8] = c.f; |
| 164031 | case 8: readCoord(pCellData+28, &c); aCoord[7] = c.f; |
| 164032 | readCoord(pCellData+24, &c); aCoord[6] = c.f; |
| 164033 | case 6: readCoord(pCellData+20, &c); aCoord[5] = c.f; |
| 164034 | readCoord(pCellData+16, &c); aCoord[4] = c.f; |
| 164035 | case 4: readCoord(pCellData+12, &c); aCoord[3] = c.f; |
| 164036 | readCoord(pCellData+8, &c); aCoord[2] = c.f; |
| 164037 | default: readCoord(pCellData+4, &c); aCoord[1] = c.f; |
| 164038 | readCoord(pCellData, &c); aCoord[0] = c.f; |
| 164039 | } |
| 164040 | }else |
| 164041 | #endif |
| 164042 | { |
| 164043 | switch( nCoord ){ |
| 164044 | case 10: readCoord(pCellData+36, &c); aCoord[9] = c.i; |
| 164045 | readCoord(pCellData+32, &c); aCoord[8] = c.i; |
| 164046 | case 8: readCoord(pCellData+28, &c); aCoord[7] = c.i; |
| 164047 | readCoord(pCellData+24, &c); aCoord[6] = c.i; |
| 164048 | case 6: readCoord(pCellData+20, &c); aCoord[5] = c.i; |
| 164049 | readCoord(pCellData+16, &c); aCoord[4] = c.i; |
| 164050 | case 4: readCoord(pCellData+12, &c); aCoord[3] = c.i; |
| 164051 | readCoord(pCellData+8, &c); aCoord[2] = c.i; |
| 164052 | default: readCoord(pCellData+4, &c); aCoord[1] = c.i; |
| 164053 | readCoord(pCellData, &c); aCoord[0] = c.i; |
| 164054 | } |
| 164055 | } |
| 164056 | if( pConstraint->op==RTREE_MATCH ){ |
| 164057 | int eWithin = 0; |
| 164058 | rc = pConstraint->u.xGeom((sqlite3_rtree_geometry*)pInfo, |
| 164059 | nCoord, aCoord, &eWithin); |
| 164060 | if( eWithin==0 ) *peWithin = NOT_WITHIN; |
| 164061 | *prScore = RTREE_ZERO; |
| 164062 | }else{ |
| 164063 | pInfo->aCoord = aCoord; |
| 164064 | pInfo->iLevel = pSearch->iLevel - 1; |
| 164065 | pInfo->rScore = pInfo->rParentScore = pSearch->rScore; |
| @@ -163531,10 +164091,11 @@ | |
| 164091 | */ |
| 164092 | pCellData += 8 + 4*(p->iCoord&0xfe); |
| 164093 | |
| 164094 | assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE |
| 164095 | || p->op==RTREE_GT || p->op==RTREE_EQ ); |
| 164096 | assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */ |
| 164097 | switch( p->op ){ |
| 164098 | case RTREE_LE: |
| 164099 | case RTREE_LT: |
| 164100 | case RTREE_EQ: |
| 164101 | RTREE_DECODE_COORD(eInt, pCellData, val); |
| @@ -163571,10 +164132,11 @@ | |
| 164132 | RtreeDValue xN; /* Coordinate value converted to a double */ |
| 164133 | |
| 164134 | assert(p->op==RTREE_LE || p->op==RTREE_LT || p->op==RTREE_GE |
| 164135 | || p->op==RTREE_GT || p->op==RTREE_EQ ); |
| 164136 | pCellData += 8 + p->iCoord*4; |
| 164137 | assert( ((((char*)pCellData) - (char*)0)&3)==0 ); /* 4-byte aligned */ |
| 164138 | RTREE_DECODE_COORD(eInt, pCellData, xN); |
| 164139 | switch( p->op ){ |
| 164140 | case RTREE_LE: if( xN <= p->u.rValue ) return; break; |
| 164141 | case RTREE_LT: if( xN < p->u.rValue ) return; break; |
| 164142 | case RTREE_GE: if( xN >= p->u.rValue ) return; break; |
| @@ -163639,11 +164201,11 @@ | |
| 164201 | if( pA->iLevel>pB->iLevel ) return +1; |
| 164202 | return 0; |
| 164203 | } |
| 164204 | |
| 164205 | /* |
| 164206 | ** Interchange two search points in a cursor. |
| 164207 | */ |
| 164208 | static void rtreeSearchPointSwap(RtreeCursor *p, int i, int j){ |
| 164209 | RtreeSearchPoint t = p->aPoint[i]; |
| 164210 | assert( i<j ); |
| 164211 | p->aPoint[i] = p->aPoint[j]; |
| @@ -163887,11 +164449,11 @@ | |
| 164449 | rtreeSearchPointPop(pCur); |
| 164450 | } |
| 164451 | if( rScore<RTREE_ZERO ) rScore = RTREE_ZERO; |
| 164452 | p = rtreeSearchPointNew(pCur, rScore, x.iLevel); |
| 164453 | if( p==0 ) return SQLITE_NOMEM; |
| 164454 | p->eWithin = (u8)eWithin; |
| 164455 | p->id = x.id; |
| 164456 | p->iCell = x.iCell; |
| 164457 | RTREE_QUEUE_TRACE(pCur, "PUSH-S:"); |
| 164458 | break; |
| 164459 | } |
| @@ -163946,11 +164508,10 @@ | |
| 164508 | if( rc ) return rc; |
| 164509 | if( p==0 ) return SQLITE_OK; |
| 164510 | if( i==0 ){ |
| 164511 | sqlite3_result_int64(ctx, nodeGetRowid(pRtree, pNode, p->iCell)); |
| 164512 | }else{ |
| 164513 | nodeGetCoord(pRtree, pNode, p->iCell, i-1, &c); |
| 164514 | #ifndef SQLITE_RTREE_INT_ONLY |
| 164515 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 164516 | sqlite3_result_double(ctx, c.f); |
| 164517 | }else |
| @@ -164075,11 +164636,11 @@ | |
| 164636 | assert( p!=0 ); /* Always returns pCsr->sPoint */ |
| 164637 | pCsr->aNode[0] = pLeaf; |
| 164638 | p->id = iNode; |
| 164639 | p->eWithin = PARTLY_WITHIN; |
| 164640 | rc = nodeRowidIndex(pRtree, pLeaf, iRowid, &iCell); |
| 164641 | p->iCell = (u8)iCell; |
| 164642 | RTREE_QUEUE_TRACE(pCsr, "PUSH-F1:"); |
| 164643 | }else{ |
| 164644 | pCsr->atEOF = 1; |
| 164645 | } |
| 164646 | }else{ |
| @@ -164108,11 +164669,11 @@ | |
| 164669 | */ |
| 164670 | rc = deserializeGeometry(argv[ii], p); |
| 164671 | if( rc!=SQLITE_OK ){ |
| 164672 | break; |
| 164673 | } |
| 164674 | p->pInfo->nCoord = pRtree->nDim2; |
| 164675 | p->pInfo->anQueue = pCsr->anQueue; |
| 164676 | p->pInfo->mxLevel = pRtree->iDepth + 1; |
| 164677 | }else{ |
| 164678 | #ifdef SQLITE_RTREE_INT_ONLY |
| 164679 | p->u.rValue = sqlite3_value_int64(argv[ii]); |
| @@ -164123,11 +164684,11 @@ | |
| 164684 | } |
| 164685 | } |
| 164686 | } |
| 164687 | if( rc==SQLITE_OK ){ |
| 164688 | RtreeSearchPoint *pNew; |
| 164689 | pNew = rtreeSearchPointNew(pCsr, RTREE_ZERO, (u8)(pRtree->iDepth+1)); |
| 164690 | if( pNew==0 ) return SQLITE_NOMEM; |
| 164691 | pNew->id = 1; |
| 164692 | pNew->iCell = 0; |
| 164693 | pNew->eWithin = PARTLY_WITHIN; |
| 164694 | assert( pCsr->bPoint==1 ); |
| @@ -164141,23 +164702,10 @@ | |
| 164702 | nodeRelease(pRtree, pRoot); |
| 164703 | rtreeRelease(pRtree); |
| 164704 | return rc; |
| 164705 | } |
| 164706 | |
| 164707 | /* |
| 164708 | ** Rtree virtual table module xBestIndex method. There are three |
| 164709 | ** table scan strategies to choose from (in order from most to |
| 164710 | ** least desirable): |
| 164711 | ** |
| @@ -164233,11 +164781,11 @@ | |
| 164781 | ** considered almost as quick as a direct rowid lookup (for which |
| 164782 | ** sqlite uses an internal cost of 0.0). It is expected to return |
| 164783 | ** a single row. |
| 164784 | */ |
| 164785 | pIdxInfo->estimatedCost = 30.0; |
| 164786 | pIdxInfo->estimatedRows = 1; |
| 164787 | return SQLITE_OK; |
| 164788 | } |
| 164789 | |
| 164790 | if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){ |
| 164791 | u8 op; |
| @@ -164251,11 +164799,11 @@ | |
| 164799 | assert( p->op==SQLITE_INDEX_CONSTRAINT_MATCH ); |
| 164800 | op = RTREE_MATCH; |
| 164801 | break; |
| 164802 | } |
| 164803 | zIdxStr[iIdx++] = op; |
| 164804 | zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0'); |
| 164805 | pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2); |
| 164806 | pIdxInfo->aConstraintUsage[ii].omit = 1; |
| 164807 | } |
| 164808 | } |
| 164809 | |
| @@ -164265,55 +164813,75 @@ | |
| 164813 | return SQLITE_NOMEM; |
| 164814 | } |
| 164815 | |
| 164816 | nRow = pRtree->nRowEst >> (iIdx/2); |
| 164817 | pIdxInfo->estimatedCost = (double)6.0 * (double)nRow; |
| 164818 | pIdxInfo->estimatedRows = nRow; |
| 164819 | |
| 164820 | return rc; |
| 164821 | } |
| 164822 | |
| 164823 | /* |
| 164824 | ** Return the N-dimensional volumn of the cell stored in *p. |
| 164825 | */ |
| 164826 | static RtreeDValue cellArea(Rtree *pRtree, RtreeCell *p){ |
| 164827 | RtreeDValue area = (RtreeDValue)1; |
| 164828 | assert( pRtree->nDim>=1 && pRtree->nDim<=5 ); |
| 164829 | #ifndef SQLITE_RTREE_INT_ONLY |
| 164830 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 164831 | switch( pRtree->nDim ){ |
| 164832 | case 5: area = p->aCoord[9].f - p->aCoord[8].f; |
| 164833 | case 4: area *= p->aCoord[7].f - p->aCoord[6].f; |
| 164834 | case 3: area *= p->aCoord[5].f - p->aCoord[4].f; |
| 164835 | case 2: area *= p->aCoord[3].f - p->aCoord[2].f; |
| 164836 | default: area *= p->aCoord[1].f - p->aCoord[0].f; |
| 164837 | } |
| 164838 | }else |
| 164839 | #endif |
| 164840 | { |
| 164841 | switch( pRtree->nDim ){ |
| 164842 | case 5: area = p->aCoord[9].i - p->aCoord[8].i; |
| 164843 | case 4: area *= p->aCoord[7].i - p->aCoord[6].i; |
| 164844 | case 3: area *= p->aCoord[5].i - p->aCoord[4].i; |
| 164845 | case 2: area *= p->aCoord[3].i - p->aCoord[2].i; |
| 164846 | default: area *= p->aCoord[1].i - p->aCoord[0].i; |
| 164847 | } |
| 164848 | } |
| 164849 | return area; |
| 164850 | } |
| 164851 | |
| 164852 | /* |
| 164853 | ** Return the margin length of cell p. The margin length is the sum |
| 164854 | ** of the objects size in each dimension. |
| 164855 | */ |
| 164856 | static RtreeDValue cellMargin(Rtree *pRtree, RtreeCell *p){ |
| 164857 | RtreeDValue margin = 0; |
| 164858 | int ii = pRtree->nDim2 - 2; |
| 164859 | do{ |
| 164860 | margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])); |
| 164861 | ii -= 2; |
| 164862 | }while( ii>=0 ); |
| 164863 | return margin; |
| 164864 | } |
| 164865 | |
| 164866 | /* |
| 164867 | ** Store the union of cells p1 and p2 in p1. |
| 164868 | */ |
| 164869 | static void cellUnion(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ |
| 164870 | int ii = 0; |
| 164871 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 164872 | do{ |
| 164873 | p1->aCoord[ii].f = MIN(p1->aCoord[ii].f, p2->aCoord[ii].f); |
| 164874 | p1->aCoord[ii+1].f = MAX(p1->aCoord[ii+1].f, p2->aCoord[ii+1].f); |
| 164875 | ii += 2; |
| 164876 | }while( ii<pRtree->nDim2 ); |
| 164877 | }else{ |
| 164878 | do{ |
| 164879 | p1->aCoord[ii].i = MIN(p1->aCoord[ii].i, p2->aCoord[ii].i); |
| 164880 | p1->aCoord[ii+1].i = MAX(p1->aCoord[ii+1].i, p2->aCoord[ii+1].i); |
| 164881 | ii += 2; |
| 164882 | }while( ii<pRtree->nDim2 ); |
| 164883 | } |
| 164884 | } |
| 164885 | |
| 164886 | /* |
| 164887 | ** Return true if the area covered by p2 is a subset of the area covered |
| @@ -164320,11 +164888,11 @@ | |
| 164888 | ** by p1. False otherwise. |
| 164889 | */ |
| 164890 | static int cellContains(Rtree *pRtree, RtreeCell *p1, RtreeCell *p2){ |
| 164891 | int ii; |
| 164892 | int isInt = (pRtree->eCoordType==RTREE_COORD_INT32); |
| 164893 | for(ii=0; ii<pRtree->nDim2; ii+=2){ |
| 164894 | RtreeCoord *a1 = &p1->aCoord[ii]; |
| 164895 | RtreeCoord *a2 = &p2->aCoord[ii]; |
| 164896 | if( (!isInt && (a2[0].f<a1[0].f || a2[1].f>a1[1].f)) |
| 164897 | || ( isInt && (a2[0].i<a1[0].i || a2[1].i>a1[1].i)) |
| 164898 | ){ |
| @@ -164355,11 +164923,11 @@ | |
| 164923 | int ii; |
| 164924 | RtreeDValue overlap = RTREE_ZERO; |
| 164925 | for(ii=0; ii<nCell; ii++){ |
| 164926 | int jj; |
| 164927 | RtreeDValue o = (RtreeDValue)1; |
| 164928 | for(jj=0; jj<pRtree->nDim2; jj+=2){ |
| 164929 | RtreeDValue x1, x2; |
| 164930 | x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj])); |
| 164931 | x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1])); |
| 164932 | if( x2<x1 ){ |
| 164933 | o = (RtreeDValue)0; |
| @@ -165411,11 +165979,11 @@ | |
| 165979 | ** with "column" that are interpreted as table constraints. |
| 165980 | ** Example: CREATE VIRTUAL TABLE bad USING rtree(x,y,CHECK(y>5)); |
| 165981 | ** This problem was discovered after years of use, so we silently ignore |
| 165982 | ** these kinds of misdeclared tables to avoid breaking any legacy. |
| 165983 | */ |
| 165984 | assert( nData<=(pRtree->nDim2 + 3) ); |
| 165985 | |
| 165986 | #ifndef SQLITE_RTREE_INT_ONLY |
| 165987 | if( pRtree->eCoordType==RTREE_COORD_REAL32 ){ |
| 165988 | for(ii=0; ii<nData-4; ii+=2){ |
| 165989 | cell.aCoord[ii].f = rtreeValueDown(azData[ii+3]); |
| @@ -165500,10 +166068,31 @@ | |
| 166068 | |
| 166069 | constraint: |
| 166070 | rtreeRelease(pRtree); |
| 166071 | return rc; |
| 166072 | } |
| 166073 | |
| 166074 | /* |
| 166075 | ** Called when a transaction starts. |
| 166076 | */ |
| 166077 | static int rtreeBeginTransaction(sqlite3_vtab *pVtab){ |
| 166078 | Rtree *pRtree = (Rtree *)pVtab; |
| 166079 | assert( pRtree->inWrTrans==0 ); |
| 166080 | pRtree->inWrTrans++; |
| 166081 | return SQLITE_OK; |
| 166082 | } |
| 166083 | |
| 166084 | /* |
| 166085 | ** Called when a transaction completes (either by COMMIT or ROLLBACK). |
| 166086 | ** The sqlite3_blob object should be released at this point. |
| 166087 | */ |
| 166088 | static int rtreeEndTransaction(sqlite3_vtab *pVtab){ |
| 166089 | Rtree *pRtree = (Rtree *)pVtab; |
| 166090 | pRtree->inWrTrans = 0; |
| 166091 | nodeBlobReset(pRtree); |
| 166092 | return SQLITE_OK; |
| 166093 | } |
| 166094 | |
| 166095 | /* |
| 166096 | ** The xRename method for rtree module virtual tables. |
| 166097 | */ |
| 166098 | static int rtreeRename(sqlite3_vtab *pVtab, const char *zNewName){ |
| @@ -165521,10 +166110,11 @@ | |
| 166110 | rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0); |
| 166111 | sqlite3_free(zSql); |
| 166112 | } |
| 166113 | return rc; |
| 166114 | } |
| 166115 | |
| 166116 | |
| 166117 | /* |
| 166118 | ** This function populates the pRtree->nRowEst variable with an estimate |
| 166119 | ** of the number of rows in the virtual table. If possible, this is based |
| 166120 | ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST. |
| @@ -165581,19 +166171,19 @@ | |
| 166171 | rtreeNext, /* xNext - advance a cursor */ |
| 166172 | rtreeEof, /* xEof */ |
| 166173 | rtreeColumn, /* xColumn - read data */ |
| 166174 | rtreeRowid, /* xRowid - read data */ |
| 166175 | rtreeUpdate, /* xUpdate - write data */ |
| 166176 | rtreeBeginTransaction, /* xBegin - begin transaction */ |
| 166177 | rtreeEndTransaction, /* xSync - sync transaction */ |
| 166178 | rtreeEndTransaction, /* xCommit - commit transaction */ |
| 166179 | rtreeEndTransaction, /* xRollback - rollback transaction */ |
| 166180 | 0, /* xFindFunction - function overloading */ |
| 166181 | rtreeRename, /* xRename - rename the table */ |
| 166182 | 0, /* xSavepoint */ |
| 166183 | 0, /* xRelease */ |
| 166184 | 0, /* xRollbackTo */ |
| 166185 | }; |
| 166186 | |
| 166187 | static int rtreeSqlInit( |
| 166188 | Rtree *pRtree, |
| 166189 | sqlite3 *db, |
| @@ -165601,14 +166191,13 @@ | |
| 166191 | const char *zPrefix, |
| 166192 | int isCreate |
| 166193 | ){ |
| 166194 | int rc = SQLITE_OK; |
| 166195 | |
| 166196 | #define N_STATEMENT 8 |
| 166197 | static const char *azSql[N_STATEMENT] = { |
| 166198 | /* Write the xxx_node table */ |
| 166199 | "INSERT OR REPLACE INTO '%q'.'%q_node' VALUES(:1, :2)", |
| 166200 | "DELETE FROM '%q'.'%q_node' WHERE nodeno = :1", |
| 166201 | |
| 166202 | /* Read and write the xxx_rowid table */ |
| 166203 | "SELECT nodeno FROM '%q'.'%q_rowid' WHERE rowid = :1", |
| @@ -165642,19 +166231,18 @@ | |
| 166231 | if( rc!=SQLITE_OK ){ |
| 166232 | return rc; |
| 166233 | } |
| 166234 | } |
| 166235 | |
| 166236 | appStmt[0] = &pRtree->pWriteNode; |
| 166237 | appStmt[1] = &pRtree->pDeleteNode; |
| 166238 | appStmt[2] = &pRtree->pReadRowid; |
| 166239 | appStmt[3] = &pRtree->pWriteRowid; |
| 166240 | appStmt[4] = &pRtree->pDeleteRowid; |
| 166241 | appStmt[5] = &pRtree->pReadParent; |
| 166242 | appStmt[6] = &pRtree->pWriteParent; |
| 166243 | appStmt[7] = &pRtree->pDeleteParent; |
| 166244 | |
| 166245 | rc = rtreeQueryStat1(db, pRtree); |
| 166246 | for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){ |
| 166247 | char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix); |
| 166248 | if( zSql ){ |
| @@ -165788,13 +166376,14 @@ | |
| 166376 | memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2); |
| 166377 | pRtree->nBusy = 1; |
| 166378 | pRtree->base.pModule = &rtreeModule; |
| 166379 | pRtree->zDb = (char *)&pRtree[1]; |
| 166380 | pRtree->zName = &pRtree->zDb[nDb+1]; |
| 166381 | pRtree->nDim = (u8)((argc-4)/2); |
| 166382 | pRtree->nDim2 = pRtree->nDim*2; |
| 166383 | pRtree->nBytesPerCell = 8 + pRtree->nDim2*4; |
| 166384 | pRtree->eCoordType = (u8)eCoordType; |
| 166385 | memcpy(pRtree->zDb, argv[1], nDb); |
| 166386 | memcpy(pRtree->zName, argv[2], nName); |
| 166387 | |
| 166388 | /* Figure out the node size to use. */ |
| 166389 | rc = getNodeSize(db, pRtree, isCreate, pzErr); |
| @@ -165863,11 +166452,12 @@ | |
| 166452 | int ii; |
| 166453 | |
| 166454 | UNUSED_PARAMETER(nArg); |
| 166455 | memset(&node, 0, sizeof(RtreeNode)); |
| 166456 | memset(&tree, 0, sizeof(Rtree)); |
| 166457 | tree.nDim = (u8)sqlite3_value_int(apArg[0]); |
| 166458 | tree.nDim2 = tree.nDim*2; |
| 166459 | tree.nBytesPerCell = 8 + 8 * tree.nDim; |
| 166460 | node.zData = (u8 *)sqlite3_value_blob(apArg[1]); |
| 166461 | |
| 166462 | for(ii=0; ii<NCELL(&node); ii++){ |
| 166463 | char zCell[512]; |
| @@ -165876,11 +166466,11 @@ | |
| 166466 | int jj; |
| 166467 | |
| 166468 | nodeGetCell(&tree, &node, ii, &cell); |
| 166469 | sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid); |
| 166470 | nCell = (int)strlen(zCell); |
| 166471 | for(jj=0; jj<tree.nDim2; jj++){ |
| 166472 | #ifndef SQLITE_RTREE_INT_ONLY |
| 166473 | sqlite3_snprintf(512-nCell,&zCell[nCell], " %g", |
| 166474 | (double)cell.aCoord[jj].f); |
| 166475 | #else |
| 166476 | sqlite3_snprintf(512-nCell,&zCell[nCell], " %d", |
| @@ -166584,42 +167174,40 @@ | |
| 167174 | |
| 167175 | /* |
| 167176 | ** Register the ICU extension functions with database db. |
| 167177 | */ |
| 167178 | SQLITE_PRIVATE int sqlite3IcuInit(sqlite3 *db){ |
| 167179 | static const struct IcuScalar { |
| 167180 | const char *zName; /* Function name */ |
| 167181 | unsigned char nArg; /* Number of arguments */ |
| 167182 | unsigned short enc; /* Optimal text encoding */ |
| 167183 | unsigned char iContext; /* sqlite3_user_data() context */ |
| 167184 | void (*xFunc)(sqlite3_context*,int,sqlite3_value**); |
| 167185 | } scalars[] = { |
| 167186 | {"icu_load_collation", 2, SQLITE_UTF8, 1, icuLoadCollation}, |
| 167187 | {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc}, |
| 167188 | {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 167189 | {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 167190 | {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 167191 | {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 167192 | {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 167193 | {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16}, |
| 167194 | {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 167195 | {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 1, icuCaseFunc16}, |
| 167196 | {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, |
| 167197 | {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc}, |
| 167198 | }; |
| 167199 | int rc = SQLITE_OK; |
| 167200 | int i; |
| 167201 | |
| 167202 | |
| 167203 | for(i=0; rc==SQLITE_OK && i<(int)(sizeof(scalars)/sizeof(scalars[0])); i++){ |
| 167204 | const struct IcuScalar *p = &scalars[i]; |
| 167205 | rc = sqlite3_create_function( |
| 167206 | db, p->zName, p->nArg, p->enc, |
| 167207 | p->iContext ? (void*)db : (void*)0, |
| 167208 | p->xFunc, 0, 0 |
| 167209 | ); |
| 167210 | } |
| 167211 | |
| 167212 | return rc; |
| 167213 | } |
| @@ -169823,11 +170411,11 @@ | |
| 170411 | |
| 170412 | /* |
| 170413 | ** Open the database handle and attach the RBU database as "rbu". If an |
| 170414 | ** error occurs, leave an error code and message in the RBU handle. |
| 170415 | */ |
| 170416 | static void rbuOpenDatabase(sqlite3rbu *p, int *pbRetry){ |
| 170417 | assert( p->rc || (p->dbMain==0 && p->dbRbu==0) ); |
| 170418 | assert( p->rc || rbuIsVacuum(p) || p->zTarget!=0 ); |
| 170419 | |
| 170420 | /* Open the RBU database */ |
| 170421 | p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1); |
| @@ -169898,11 +170486,11 @@ | |
| 170486 | if( p->eStage>=RBU_STAGE_MOVE ){ |
| 170487 | bOpen = 1; |
| 170488 | }else{ |
| 170489 | RbuState *pState = rbuLoadState(p); |
| 170490 | if( pState ){ |
| 170491 | bOpen = (pState->eStage>=RBU_STAGE_MOVE); |
| 170492 | rbuFreeState(pState); |
| 170493 | } |
| 170494 | } |
| 170495 | if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1); |
| 170496 | } |
| @@ -169910,10 +170498,19 @@ | |
| 170498 | p->eStage = 0; |
| 170499 | if( p->rc==SQLITE_OK && p->dbMain==0 ){ |
| 170500 | if( !rbuIsVacuum(p) ){ |
| 170501 | p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1); |
| 170502 | }else if( p->pRbuFd->pWalFd ){ |
| 170503 | if( pbRetry ){ |
| 170504 | p->pRbuFd->bNolock = 0; |
| 170505 | sqlite3_close(p->dbRbu); |
| 170506 | sqlite3_close(p->dbMain); |
| 170507 | p->dbMain = 0; |
| 170508 | p->dbRbu = 0; |
| 170509 | *pbRetry = 1; |
| 170510 | return; |
| 170511 | } |
| 170512 | p->rc = SQLITE_ERROR; |
| 170513 | p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database"); |
| 170514 | }else{ |
| 170515 | char *zTarget; |
| 170516 | char *zExtra = 0; |
| @@ -170090,20 +170687,22 @@ | |
| 170687 | p->eStage = RBU_STAGE_CAPTURE; |
| 170688 | rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0); |
| 170689 | if( rc2!=SQLITE_INTERNAL ) p->rc = rc2; |
| 170690 | } |
| 170691 | |
| 170692 | if( p->rc==SQLITE_OK && p->nFrame>0 ){ |
| 170693 | p->eStage = RBU_STAGE_CKPT; |
| 170694 | p->nStep = (pState ? pState->nRow : 0); |
| 170695 | p->aBuf = rbuMalloc(p, p->pgsz); |
| 170696 | p->iWalCksum = rbuShmChecksum(p); |
| 170697 | } |
| 170698 | |
| 170699 | if( p->rc==SQLITE_OK ){ |
| 170700 | if( p->nFrame==0 || (pState && pState->iWalCksum!=p->iWalCksum) ){ |
| 170701 | p->rc = SQLITE_DONE; |
| 170702 | p->eStage = RBU_STAGE_DONE; |
| 170703 | } |
| 170704 | } |
| 170705 | } |
| 170706 | |
| 170707 | /* |
| 170708 | ** Called when iAmt bytes are read from offset iOff of the wal file while |
| @@ -170272,11 +170871,11 @@ | |
| 170871 | #else |
| 170872 | p->rc = rename(zOal, zWal) ? SQLITE_IOERR : SQLITE_OK; |
| 170873 | #endif |
| 170874 | |
| 170875 | if( p->rc==SQLITE_OK ){ |
| 170876 | rbuOpenDatabase(p, 0); |
| 170877 | rbuSetupCheckpoint(p, 0); |
| 170878 | } |
| 170879 | } |
| 170880 | } |
| 170881 | |
| @@ -170983,10 +171582,11 @@ | |
| 171582 | rbuCreateVfs(p); |
| 171583 | |
| 171584 | /* Open the target, RBU and state databases */ |
| 171585 | if( p->rc==SQLITE_OK ){ |
| 171586 | char *pCsr = (char*)&p[1]; |
| 171587 | int bRetry = 0; |
| 171588 | if( zTarget ){ |
| 171589 | p->zTarget = pCsr; |
| 171590 | memcpy(p->zTarget, zTarget, nTarget+1); |
| 171591 | pCsr += nTarget+1; |
| 171592 | } |
| @@ -170994,11 +171594,22 @@ | |
| 171594 | memcpy(p->zRbu, zRbu, nRbu+1); |
| 171595 | pCsr += nRbu+1; |
| 171596 | if( zState ){ |
| 171597 | p->zState = rbuMPrintf(p, "%s", zState); |
| 171598 | } |
| 171599 | |
| 171600 | /* If the first attempt to open the database file fails and the bRetry |
| 171601 | ** flag it set, this means that the db was not opened because it seemed |
| 171602 | ** to be a wal-mode db. But, this may have happened due to an earlier |
| 171603 | ** RBU vacuum operation leaving an old wal file in the directory. |
| 171604 | ** If this is the case, it will have been checkpointed and deleted |
| 171605 | ** when the handle was closed and a second attempt to open the |
| 171606 | ** database may succeed. */ |
| 171607 | rbuOpenDatabase(p, &bRetry); |
| 171608 | if( bRetry ){ |
| 171609 | rbuOpenDatabase(p, 0); |
| 171610 | } |
| 171611 | } |
| 171612 | |
| 171613 | if( p->rc==SQLITE_OK ){ |
| 171614 | pState = rbuLoadState(p); |
| 171615 | assert( pState || p->rc!=SQLITE_OK ); |
| @@ -175957,11 +176568,11 @@ | |
| 176568 | sqlite3_value **ppValue /* OUT: Value from conflicting row */ |
| 176569 | ){ |
| 176570 | if( !pIter->pConflict ){ |
| 176571 | return SQLITE_MISUSE; |
| 176572 | } |
| 176573 | if( iVal<0 || iVal>=pIter->nCol ){ |
| 176574 | return SQLITE_RANGE; |
| 176575 | } |
| 176576 | *ppValue = sqlite3_column_value(pIter->pConflict, iVal); |
| 176577 | return SQLITE_OK; |
| 176578 | } |
| @@ -176424,11 +177035,17 @@ | |
| 177035 | int i; |
| 177036 | SessionBuffer buf = {0, 0, 0}; |
| 177037 | |
| 177038 | sessionAppendStr(&buf, "INSERT INTO main.", &rc); |
| 177039 | sessionAppendIdent(&buf, zTab, &rc); |
| 177040 | sessionAppendStr(&buf, "(", &rc); |
| 177041 | for(i=0; i<p->nCol; i++){ |
| 177042 | if( i!=0 ) sessionAppendStr(&buf, ", ", &rc); |
| 177043 | sessionAppendIdent(&buf, p->azCol[i], &rc); |
| 177044 | } |
| 177045 | |
| 177046 | sessionAppendStr(&buf, ") VALUES(?", &rc); |
| 177047 | for(i=1; i<p->nCol; i++){ |
| 177048 | sessionAppendStr(&buf, ", ?", &rc); |
| 177049 | } |
| 177050 | sessionAppendStr(&buf, ")", &rc); |
| 177051 | |
| @@ -176970,42 +177587,51 @@ | |
| 177587 | break; |
| 177588 | } |
| 177589 | nTab = (int)strlen(zTab); |
| 177590 | sApply.azCol = (const char **)zTab; |
| 177591 | }else{ |
| 177592 | int nMinCol = 0; |
| 177593 | int i; |
| 177594 | |
| 177595 | sqlite3changeset_pk(pIter, &abPK, 0); |
| 177596 | rc = sessionTableInfo( |
| 177597 | db, "main", zNew, &sApply.nCol, &zTab, &sApply.azCol, &sApply.abPK |
| 177598 | ); |
| 177599 | if( rc!=SQLITE_OK ) break; |
| 177600 | for(i=0; i<sApply.nCol; i++){ |
| 177601 | if( sApply.abPK[i] ) nMinCol = i+1; |
| 177602 | } |
| 177603 | |
| 177604 | if( sApply.nCol==0 ){ |
| 177605 | schemaMismatch = 1; |
| 177606 | sqlite3_log(SQLITE_SCHEMA, |
| 177607 | "sqlite3changeset_apply(): no such table: %s", zTab |
| 177608 | ); |
| 177609 | } |
| 177610 | else if( sApply.nCol<nCol ){ |
| 177611 | schemaMismatch = 1; |
| 177612 | sqlite3_log(SQLITE_SCHEMA, |
| 177613 | "sqlite3changeset_apply(): table %s has %d columns, " |
| 177614 | "expected %d or more", |
| 177615 | zTab, sApply.nCol, nCol |
| 177616 | ); |
| 177617 | } |
| 177618 | else if( nCol<nMinCol || memcmp(sApply.abPK, abPK, nCol)!=0 ){ |
| 177619 | schemaMismatch = 1; |
| 177620 | sqlite3_log(SQLITE_SCHEMA, "sqlite3changeset_apply(): " |
| 177621 | "primary key mismatch for table %s", zTab |
| 177622 | ); |
| 177623 | } |
| 177624 | else{ |
| 177625 | sApply.nCol = nCol; |
| 177626 | if((rc = sessionSelectRow(db, zTab, &sApply)) |
| 177627 | || (rc = sessionUpdateRow(db, zTab, &sApply)) |
| 177628 | || (rc = sessionDeleteRow(db, zTab, &sApply)) |
| 177629 | || (rc = sessionInsertRow(db, zTab, &sApply)) |
| 177630 | ){ |
| 177631 | break; |
| 177632 | } |
| 177633 | } |
| 177634 | nTab = sqlite3Strlen30(zTab); |
| 177635 | } |
| 177636 | } |
| 177637 | |
| @@ -177593,11 +178219,11 @@ | |
| 178219 | ** a BLOB, but there is no support for JSONB in the current implementation. |
| 178220 | ** This implementation parses JSON text at 250 MB/s, so it is hard to see |
| 178221 | ** how JSONB might improve on that.) |
| 178222 | */ |
| 178223 | #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_JSON1) |
| 178224 | #if !defined(SQLITEINT_H) |
| 178225 | /* #include "sqlite3ext.h" */ |
| 178226 | #endif |
| 178227 | SQLITE_EXTENSION_INIT1 |
| 178228 | /* #include <assert.h> */ |
| 178229 | /* #include <string.h> */ |
| @@ -181644,10 +182270,35 @@ | |
| 182270 | */ |
| 182271 | #ifndef fts5YYMALLOCARGTYPE |
| 182272 | # define fts5YYMALLOCARGTYPE size_t |
| 182273 | #endif |
| 182274 | |
| 182275 | /* Initialize a new parser that has already been allocated. |
| 182276 | */ |
| 182277 | static void sqlite3Fts5ParserInit(void *fts5yypParser){ |
| 182278 | fts5yyParser *pParser = (fts5yyParser*)fts5yypParser; |
| 182279 | #ifdef fts5YYTRACKMAXSTACKDEPTH |
| 182280 | pParser->fts5yyhwm = 0; |
| 182281 | #endif |
| 182282 | #if fts5YYSTACKDEPTH<=0 |
| 182283 | pParser->fts5yytos = NULL; |
| 182284 | pParser->fts5yystack = NULL; |
| 182285 | pParser->fts5yystksz = 0; |
| 182286 | if( fts5yyGrowStack(pParser) ){ |
| 182287 | pParser->fts5yystack = &pParser->fts5yystk0; |
| 182288 | pParser->fts5yystksz = 1; |
| 182289 | } |
| 182290 | #endif |
| 182291 | #ifndef fts5YYNOERRORRECOVERY |
| 182292 | pParser->fts5yyerrcnt = -1; |
| 182293 | #endif |
| 182294 | pParser->fts5yytos = pParser->fts5yystack; |
| 182295 | pParser->fts5yystack[0].stateno = 0; |
| 182296 | pParser->fts5yystack[0].major = 0; |
| 182297 | } |
| 182298 | |
| 182299 | #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK |
| 182300 | /* |
| 182301 | ** This function allocates a new parser. |
| 182302 | ** The only argument is a pointer to a function which works like |
| 182303 | ** malloc. |
| 182304 | ** |
| @@ -181659,32 +182310,15 @@ | |
| 182310 | ** to sqlite3Fts5Parser and sqlite3Fts5ParserFree. |
| 182311 | */ |
| 182312 | static void *sqlite3Fts5ParserAlloc(void *(*mallocProc)(fts5YYMALLOCARGTYPE)){ |
| 182313 | fts5yyParser *pParser; |
| 182314 | pParser = (fts5yyParser*)(*mallocProc)( (fts5YYMALLOCARGTYPE)sizeof(fts5yyParser) ); |
| 182315 | if( pParser ) sqlite3Fts5ParserInit(pParser); |
| 182316 | return pParser; |
| 182317 | } |
| 182318 | #endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */ |
| 182319 | |
| 182320 | |
| 182321 | /* The following function deletes the "minor type" or semantic value |
| 182322 | ** associated with a symbol. The symbol can be either a terminal |
| 182323 | ** or nonterminal. "fts5yymajor" is the symbol code, and "fts5yypminor" is |
| 182324 | ** a pointer to the value to be deleted. The code used to do the |
| @@ -181762,10 +182396,22 @@ | |
| 182396 | } |
| 182397 | #endif |
| 182398 | fts5yy_destructor(pParser, fts5yytos->major, &fts5yytos->minor); |
| 182399 | } |
| 182400 | |
| 182401 | /* |
| 182402 | ** Clear all secondary memory allocations from the parser |
| 182403 | */ |
| 182404 | static void sqlite3Fts5ParserFinalize(void *p){ |
| 182405 | fts5yyParser *pParser = (fts5yyParser*)p; |
| 182406 | while( pParser->fts5yytos>pParser->fts5yystack ) fts5yy_pop_parser_stack(pParser); |
| 182407 | #if fts5YYSTACKDEPTH<=0 |
| 182408 | if( pParser->fts5yystack!=&pParser->fts5yystk0 ) free(pParser->fts5yystack); |
| 182409 | #endif |
| 182410 | } |
| 182411 | |
| 182412 | #ifndef sqlite3Fts5Parser_ENGINEALWAYSONSTACK |
| 182413 | /* |
| 182414 | ** Deallocate and destroy a parser. Destructors are called for |
| 182415 | ** all stack elements before shutting the parser down. |
| 182416 | ** |
| 182417 | ** If the fts5YYPARSEFREENEVERNULL macro exists (for example because it |
| @@ -181774,20 +182420,17 @@ | |
| 182420 | */ |
| 182421 | static void sqlite3Fts5ParserFree( |
| 182422 | void *p, /* The parser to be deleted */ |
| 182423 | void (*freeProc)(void*) /* Function used to reclaim memory */ |
| 182424 | ){ |
| 182425 | #ifndef fts5YYPARSEFREENEVERNULL |
| 182426 | if( p==0 ) return; |
| 182427 | #endif |
| 182428 | sqlite3Fts5ParserFinalize(p); |
| 182429 | (*freeProc)(p); |
| 182430 | } |
| 182431 | #endif /* sqlite3Fts5Parser_ENGINEALWAYSONSTACK */ |
| 182432 | |
| 182433 | /* |
| 182434 | ** Return the peak depth of the stack for a parser. |
| 182435 | */ |
| 182436 | #ifdef fts5YYTRACKMAXSTACKDEPTH |
| @@ -186122,11 +186765,11 @@ | |
| 186765 | memset(&sCtx, 0, sizeof(TokenCtx)); |
| 186766 | sCtx.pPhrase = pAppend; |
| 186767 | |
| 186768 | rc = fts5ParseStringFromToken(pToken, &z); |
| 186769 | if( rc==SQLITE_OK ){ |
| 186770 | int flags = FTS5_TOKENIZE_QUERY | (bPrefix ? FTS5_TOKENIZE_PREFIX : 0); |
| 186771 | int n; |
| 186772 | sqlite3Fts5Dequote(z); |
| 186773 | n = (int)strlen(z); |
| 186774 | rc = sqlite3Fts5Tokenize(pConfig, flags, z, n, &sCtx, fts5ParseTokenize); |
| 186775 | } |
| @@ -196863,11 +197506,11 @@ | |
| 197506 | int nArg, /* Number of args */ |
| 197507 | sqlite3_value **apUnused /* Function arguments */ |
| 197508 | ){ |
| 197509 | assert( nArg==0 ); |
| 197510 | UNUSED_PARAM2(nArg, apUnused); |
| 197511 | sqlite3_result_text(pCtx, "fts5: 2017-02-07 12:58:38 07fe6228208684d579c4f6c334c90eb6262a9233", -1, SQLITE_TRANSIENT); |
| 197512 | } |
| 197513 | |
| 197514 | static int fts5Init(sqlite3 *db){ |
| 197515 | static const sqlite3_module fts5Mod = { |
| 197516 | /* iVersion */ 2, |
| 197517 |
+55
-27
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -119,13 +119,13 @@ | ||
| 119 | 119 | ** |
| 120 | 120 | ** See also: [sqlite3_libversion()], |
| 121 | 121 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 122 | 122 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 123 | 123 | */ |
| 124 | -#define SQLITE_VERSION "3.16.2" | |
| 125 | -#define SQLITE_VERSION_NUMBER 3016002 | |
| 126 | -#define SQLITE_SOURCE_ID "2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209" | |
| 124 | +#define SQLITE_VERSION "3.17.0" | |
| 125 | +#define SQLITE_VERSION_NUMBER 3017000 | |
| 126 | +#define SQLITE_SOURCE_ID "2017-02-07 13:51:48 a136609c98ed3cc673c5a3c2578d49db3f2518d1" | |
| 127 | 127 | |
| 128 | 128 | /* |
| 129 | 129 | ** CAPI3REF: Run-Time Library Version Numbers |
| 130 | 130 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 131 | 131 | ** |
| @@ -257,11 +257,15 @@ | ||
| 257 | 257 | ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
| 258 | 258 | ** between 0 and +18446744073709551615 inclusive. |
| 259 | 259 | */ |
| 260 | 260 | #ifdef SQLITE_INT64_TYPE |
| 261 | 261 | typedef SQLITE_INT64_TYPE sqlite_int64; |
| 262 | - typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; | |
| 262 | +# ifdef SQLITE_UINT64_TYPE | |
| 263 | + typedef SQLITE_UINT64_TYPE sqlite_uint64; | |
| 264 | +# else | |
| 265 | + typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; | |
| 266 | +# endif | |
| 263 | 267 | #elif defined(_MSC_VER) || defined(__BORLANDC__) |
| 264 | 268 | typedef __int64 sqlite_int64; |
| 265 | 269 | typedef unsigned __int64 sqlite_uint64; |
| 266 | 270 | #else |
| 267 | 271 | typedef long long int sqlite_int64; |
| @@ -570,11 +574,11 @@ | ||
| 570 | 574 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 571 | 575 | ** after reboot following a crash or power loss, the only bytes in a |
| 572 | 576 | ** file that were written at the application level might have changed |
| 573 | 577 | ** and that adjacent bytes, even bytes within the same sector are |
| 574 | 578 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 575 | -** flag indicate that a file cannot be deleted when open. The | |
| 579 | +** flag indicates that a file cannot be deleted when open. The | |
| 576 | 580 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
| 577 | 581 | ** read-only media and cannot be changed even by processes with |
| 578 | 582 | ** elevated privileges. |
| 579 | 583 | */ |
| 580 | 584 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| @@ -720,10 +724,13 @@ | ||
| 720 | 724 | ** <li> [SQLITE_IOCAP_ATOMIC16K] |
| 721 | 725 | ** <li> [SQLITE_IOCAP_ATOMIC32K] |
| 722 | 726 | ** <li> [SQLITE_IOCAP_ATOMIC64K] |
| 723 | 727 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
| 724 | 728 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
| 729 | +** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] | |
| 730 | +** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] | |
| 731 | +** <li> [SQLITE_IOCAP_IMMUTABLE] | |
| 725 | 732 | ** </ul> |
| 726 | 733 | ** |
| 727 | 734 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 728 | 735 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 729 | 736 | ** mean that writes of blocks that are nnn bytes in size and |
| @@ -5408,11 +5415,11 @@ | ||
| 5408 | 5415 | ** ^(The update hook is not invoked when internal system tables are |
| 5409 | 5416 | ** modified (i.e. sqlite_master and sqlite_sequence).)^ |
| 5410 | 5417 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
| 5411 | 5418 | ** |
| 5412 | 5419 | ** ^In the current implementation, the update hook |
| 5413 | -** is not invoked when duplication rows are deleted because of an | |
| 5420 | +** is not invoked when conflicting rows are deleted because of an | |
| 5414 | 5421 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
| 5415 | 5422 | ** invoked when rows are deleted using the [truncate optimization]. |
| 5416 | 5423 | ** The exceptions defined in this paragraph might change in a future |
| 5417 | 5424 | ** release of SQLite. |
| 5418 | 5425 | ** |
| @@ -6190,10 +6197,16 @@ | ||
| 6190 | 6197 | ** |
| 6191 | 6198 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 6192 | 6199 | ** [database connection] error code and message accessible via |
| 6193 | 6200 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 6194 | 6201 | ** |
| 6202 | +** A BLOB referenced by sqlite3_blob_open() may be read using the | |
| 6203 | +** [sqlite3_blob_read()] interface and modified by using | |
| 6204 | +** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a | |
| 6205 | +** different row of the same table using the [sqlite3_blob_reopen()] | |
| 6206 | +** interface. However, the column, table, or database of a [BLOB handle] | |
| 6207 | +** cannot be changed after the [BLOB handle] is opened. | |
| 6195 | 6208 | ** |
| 6196 | 6209 | ** ^(If the row that a BLOB handle points to is modified by an |
| 6197 | 6210 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 6198 | 6211 | ** then the BLOB handle is marked as "expired". |
| 6199 | 6212 | ** This is true if any column of the row is changed, even a column |
| @@ -6213,10 +6226,14 @@ | ||
| 6213 | 6226 | ** and the built-in [zeroblob] SQL function may be used to create a |
| 6214 | 6227 | ** zero-filled blob to read or write using the incremental-blob interface. |
| 6215 | 6228 | ** |
| 6216 | 6229 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 6217 | 6230 | ** be released by a call to [sqlite3_blob_close()]. |
| 6231 | +** | |
| 6232 | +** See also: [sqlite3_blob_close()], | |
| 6233 | +** [sqlite3_blob_reopen()], [sqlite3_blob_read()], | |
| 6234 | +** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. | |
| 6218 | 6235 | */ |
| 6219 | 6236 | SQLITE_API int sqlite3_blob_open( |
| 6220 | 6237 | sqlite3*, |
| 6221 | 6238 | const char *zDb, |
| 6222 | 6239 | const char *zTable, |
| @@ -6228,15 +6245,15 @@ | ||
| 6228 | 6245 | |
| 6229 | 6246 | /* |
| 6230 | 6247 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6231 | 6248 | ** METHOD: sqlite3_blob |
| 6232 | 6249 | ** |
| 6233 | -** ^This function is used to move an existing blob handle so that it points | |
| 6250 | +** ^This function is used to move an existing [BLOB handle] so that it points | |
| 6234 | 6251 | ** to a different row of the same database table. ^The new row is identified |
| 6235 | 6252 | ** by the rowid value passed as the second argument. Only the row can be |
| 6236 | 6253 | ** changed. ^The database, table and column on which the blob handle is open |
| 6237 | -** remain the same. Moving an existing blob handle to a new row can be | |
| 6254 | +** remain the same. Moving an existing [BLOB handle] to a new row is | |
| 6238 | 6255 | ** faster than closing the existing handle and opening a new one. |
| 6239 | 6256 | ** |
| 6240 | 6257 | ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
| 6241 | 6258 | ** it must exist and there must be either a blob or text value stored in |
| 6242 | 6259 | ** the nominated column.)^ ^If the new row is not present in the table, or if |
| @@ -8161,22 +8178,22 @@ | ||
| 8161 | 8178 | ** ^These interfaces are only available if SQLite is compiled using the |
| 8162 | 8179 | ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. |
| 8163 | 8180 | ** |
| 8164 | 8181 | ** ^The [sqlite3_preupdate_hook()] interface registers a callback function |
| 8165 | 8182 | ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation |
| 8166 | -** on a [rowid table]. | |
| 8183 | +** on a database table. | |
| 8167 | 8184 | ** ^At most one preupdate hook may be registered at a time on a single |
| 8168 | 8185 | ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides |
| 8169 | 8186 | ** the previous setting. |
| 8170 | 8187 | ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] |
| 8171 | 8188 | ** with a NULL pointer as the second parameter. |
| 8172 | 8189 | ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as |
| 8173 | 8190 | ** the first parameter to callbacks. |
| 8174 | 8191 | ** |
| 8175 | -** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate | |
| 8176 | -** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID] | |
| 8177 | -** tables. | |
| 8192 | +** ^The preupdate hook only fires for changes to real database tables; the | |
| 8193 | +** preupdate hook is not invoked for changes to [virtual tables] or to | |
| 8194 | +** system tables like sqlite_master or sqlite_stat1. | |
| 8178 | 8195 | ** |
| 8179 | 8196 | ** ^The second parameter to the preupdate callback is a pointer to |
| 8180 | 8197 | ** the [database connection] that registered the preupdate hook. |
| 8181 | 8198 | ** ^The third parameter to the preupdate callback is one of the constants |
| 8182 | 8199 | ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the |
| @@ -8186,16 +8203,20 @@ | ||
| 8186 | 8203 | ** will be "main" for the main database or "temp" for TEMP tables or |
| 8187 | 8204 | ** the name given after the AS keyword in the [ATTACH] statement for attached |
| 8188 | 8205 | ** databases.)^ |
| 8189 | 8206 | ** ^The fifth parameter to the preupdate callback is the name of the |
| 8190 | 8207 | ** table that is being modified. |
| 8191 | -** ^The sixth parameter to the preupdate callback is the initial [rowid] of the | |
| 8192 | -** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is | |
| 8193 | -** undefined for SQLITE_INSERT changes. | |
| 8194 | -** ^The seventh parameter to the preupdate callback is the final [rowid] of | |
| 8195 | -** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is | |
| 8196 | -** undefined for SQLITE_DELETE changes. | |
| 8208 | +** | |
| 8209 | +** For an UPDATE or DELETE operation on a [rowid table], the sixth | |
| 8210 | +** parameter passed to the preupdate callback is the initial [rowid] of the | |
| 8211 | +** row being modified or deleted. For an INSERT operation on a rowid table, | |
| 8212 | +** or any operation on a WITHOUT ROWID table, the value of the sixth | |
| 8213 | +** parameter is undefined. For an INSERT or UPDATE on a rowid table the | |
| 8214 | +** seventh parameter is the final rowid value of the row being inserted | |
| 8215 | +** or updated. The value of the seventh parameter passed to the callback | |
| 8216 | +** function is not defined for operations on WITHOUT ROWID tables, or for | |
| 8217 | +** INSERT operations on rowid tables. | |
| 8197 | 8218 | ** |
| 8198 | 8219 | ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], |
| 8199 | 8220 | ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces |
| 8200 | 8221 | ** provide additional information about a preupdate event. These routines |
| 8201 | 8222 | ** may only be called from within a preupdate callback. Invoking any of |
| @@ -8895,11 +8916,12 @@ | ||
| 8895 | 8916 | ** |
| 8896 | 8917 | ** <li> For each row (primary key) that exists in the to-table but not in |
| 8897 | 8918 | ** the from-table, a DELETE record is added to the session object. |
| 8898 | 8919 | ** |
| 8899 | 8920 | ** <li> For each row (primary key) that exists in both tables, but features |
| 8900 | -** different in each, an UPDATE record is added to the session. | |
| 8921 | +** different non-PK values in each, an UPDATE record is added to the | |
| 8922 | +** session. | |
| 8901 | 8923 | ** </ul> |
| 8902 | 8924 | ** |
| 8903 | 8925 | ** To clarify, if this function is called and then a changeset constructed |
| 8904 | 8926 | ** using [sqlite3session_changeset()], then after applying that changeset to |
| 8905 | 8927 | ** database zFrom the contents of the two compatible tables would be |
| @@ -9480,11 +9502,11 @@ | ||
| 9480 | 9502 | ** considered compatible if all of the following are true: |
| 9481 | 9503 | ** |
| 9482 | 9504 | ** <ul> |
| 9483 | 9505 | ** <li> The table has the same name as the name recorded in the |
| 9484 | 9506 | ** changeset, and |
| 9485 | -** <li> The table has the same number of columns as recorded in the | |
| 9507 | +** <li> The table has at least as many columns as recorded in the | |
| 9486 | 9508 | ** changeset, and |
| 9487 | 9509 | ** <li> The table has primary key columns in the same position as |
| 9488 | 9510 | ** recorded in the changeset. |
| 9489 | 9511 | ** </ul> |
| 9490 | 9512 | ** |
| @@ -9525,11 +9547,15 @@ | ||
| 9525 | 9547 | ** the changeset the row is deleted from the target database. |
| 9526 | 9548 | ** |
| 9527 | 9549 | ** If a row with matching primary key values is found, but one or more of |
| 9528 | 9550 | ** the non-primary key fields contains a value different from the original |
| 9529 | 9551 | ** row value stored in the changeset, the conflict-handler function is |
| 9530 | -** invoked with [SQLITE_CHANGESET_DATA] as the second argument. | |
| 9552 | +** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the | |
| 9553 | +** database table has more columns than are recorded in the changeset, | |
| 9554 | +** only the values of those non-primary key fields are compared against | |
| 9555 | +** the current database contents - any trailing database table columns | |
| 9556 | +** are ignored. | |
| 9531 | 9557 | ** |
| 9532 | 9558 | ** If no row with matching primary key values is found in the database, |
| 9533 | 9559 | ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] |
| 9534 | 9560 | ** passed as the second argument. |
| 9535 | 9561 | ** |
| @@ -9540,11 +9566,13 @@ | ||
| 9540 | 9566 | ** operation is attempted because an earlier call to the conflict handler |
| 9541 | 9567 | ** function returned [SQLITE_CHANGESET_REPLACE]. |
| 9542 | 9568 | ** |
| 9543 | 9569 | ** <dt>INSERT Changes<dd> |
| 9544 | 9570 | ** For each INSERT change, an attempt is made to insert the new row into |
| 9545 | -** the database. | |
| 9571 | +** the database. If the changeset row contains fewer fields than the | |
| 9572 | +** database table, the trailing fields are populated with their default | |
| 9573 | +** values. | |
| 9546 | 9574 | ** |
| 9547 | 9575 | ** If the attempt to insert the row fails because the database already |
| 9548 | 9576 | ** contains a row with the same primary key values, the conflict handler |
| 9549 | 9577 | ** function is invoked with the second argument set to |
| 9550 | 9578 | ** [SQLITE_CHANGESET_CONFLICT]. |
| @@ -9558,17 +9586,17 @@ | ||
| 9558 | 9586 | ** |
| 9559 | 9587 | ** <dt>UPDATE Changes<dd> |
| 9560 | 9588 | ** For each UPDATE change, this function checks if the target database |
| 9561 | 9589 | ** contains a row with the same primary key value (or values) as the |
| 9562 | 9590 | ** original row values stored in the changeset. If it does, and the values |
| 9563 | -** stored in all non-primary key columns also match the values stored in | |
| 9564 | -** the changeset the row is updated within the target database. | |
| 9591 | +** stored in all modified non-primary key columns also match the values | |
| 9592 | +** stored in the changeset the row is updated within the target database. | |
| 9565 | 9593 | ** |
| 9566 | 9594 | ** If a row with matching primary key values is found, but one or more of |
| 9567 | -** the non-primary key fields contains a value different from an original | |
| 9568 | -** row value stored in the changeset, the conflict-handler function is | |
| 9569 | -** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since | |
| 9595 | +** the modified non-primary key fields contains a value different from an | |
| 9596 | +** original row value stored in the changeset, the conflict-handler function | |
| 9597 | +** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since | |
| 9570 | 9598 | ** UPDATE changes only contain values for non-primary key fields that are |
| 9571 | 9599 | ** to be modified, only those fields need to match the original values to |
| 9572 | 9600 | ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. |
| 9573 | 9601 | ** |
| 9574 | 9602 | ** If no row with matching primary key values is found in the database, |
| 9575 | 9603 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -119,13 +119,13 @@ | |
| 119 | ** |
| 120 | ** See also: [sqlite3_libversion()], |
| 121 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 122 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 123 | */ |
| 124 | #define SQLITE_VERSION "3.16.2" |
| 125 | #define SQLITE_VERSION_NUMBER 3016002 |
| 126 | #define SQLITE_SOURCE_ID "2017-01-06 16:32:41 a65a62893ca8319e89e48b8a38cf8a59c69a8209" |
| 127 | |
| 128 | /* |
| 129 | ** CAPI3REF: Run-Time Library Version Numbers |
| 130 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 131 | ** |
| @@ -257,11 +257,15 @@ | |
| 257 | ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
| 258 | ** between 0 and +18446744073709551615 inclusive. |
| 259 | */ |
| 260 | #ifdef SQLITE_INT64_TYPE |
| 261 | typedef SQLITE_INT64_TYPE sqlite_int64; |
| 262 | typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; |
| 263 | #elif defined(_MSC_VER) || defined(__BORLANDC__) |
| 264 | typedef __int64 sqlite_int64; |
| 265 | typedef unsigned __int64 sqlite_uint64; |
| 266 | #else |
| 267 | typedef long long int sqlite_int64; |
| @@ -570,11 +574,11 @@ | |
| 570 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 571 | ** after reboot following a crash or power loss, the only bytes in a |
| 572 | ** file that were written at the application level might have changed |
| 573 | ** and that adjacent bytes, even bytes within the same sector are |
| 574 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 575 | ** flag indicate that a file cannot be deleted when open. The |
| 576 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
| 577 | ** read-only media and cannot be changed even by processes with |
| 578 | ** elevated privileges. |
| 579 | */ |
| 580 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| @@ -720,10 +724,13 @@ | |
| 720 | ** <li> [SQLITE_IOCAP_ATOMIC16K] |
| 721 | ** <li> [SQLITE_IOCAP_ATOMIC32K] |
| 722 | ** <li> [SQLITE_IOCAP_ATOMIC64K] |
| 723 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
| 724 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
| 725 | ** </ul> |
| 726 | ** |
| 727 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 728 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 729 | ** mean that writes of blocks that are nnn bytes in size and |
| @@ -5408,11 +5415,11 @@ | |
| 5408 | ** ^(The update hook is not invoked when internal system tables are |
| 5409 | ** modified (i.e. sqlite_master and sqlite_sequence).)^ |
| 5410 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
| 5411 | ** |
| 5412 | ** ^In the current implementation, the update hook |
| 5413 | ** is not invoked when duplication rows are deleted because of an |
| 5414 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
| 5415 | ** invoked when rows are deleted using the [truncate optimization]. |
| 5416 | ** The exceptions defined in this paragraph might change in a future |
| 5417 | ** release of SQLite. |
| 5418 | ** |
| @@ -6190,10 +6197,16 @@ | |
| 6190 | ** |
| 6191 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 6192 | ** [database connection] error code and message accessible via |
| 6193 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 6194 | ** |
| 6195 | ** |
| 6196 | ** ^(If the row that a BLOB handle points to is modified by an |
| 6197 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 6198 | ** then the BLOB handle is marked as "expired". |
| 6199 | ** This is true if any column of the row is changed, even a column |
| @@ -6213,10 +6226,14 @@ | |
| 6213 | ** and the built-in [zeroblob] SQL function may be used to create a |
| 6214 | ** zero-filled blob to read or write using the incremental-blob interface. |
| 6215 | ** |
| 6216 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 6217 | ** be released by a call to [sqlite3_blob_close()]. |
| 6218 | */ |
| 6219 | SQLITE_API int sqlite3_blob_open( |
| 6220 | sqlite3*, |
| 6221 | const char *zDb, |
| 6222 | const char *zTable, |
| @@ -6228,15 +6245,15 @@ | |
| 6228 | |
| 6229 | /* |
| 6230 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6231 | ** METHOD: sqlite3_blob |
| 6232 | ** |
| 6233 | ** ^This function is used to move an existing blob handle so that it points |
| 6234 | ** to a different row of the same database table. ^The new row is identified |
| 6235 | ** by the rowid value passed as the second argument. Only the row can be |
| 6236 | ** changed. ^The database, table and column on which the blob handle is open |
| 6237 | ** remain the same. Moving an existing blob handle to a new row can be |
| 6238 | ** faster than closing the existing handle and opening a new one. |
| 6239 | ** |
| 6240 | ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
| 6241 | ** it must exist and there must be either a blob or text value stored in |
| 6242 | ** the nominated column.)^ ^If the new row is not present in the table, or if |
| @@ -8161,22 +8178,22 @@ | |
| 8161 | ** ^These interfaces are only available if SQLite is compiled using the |
| 8162 | ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. |
| 8163 | ** |
| 8164 | ** ^The [sqlite3_preupdate_hook()] interface registers a callback function |
| 8165 | ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation |
| 8166 | ** on a [rowid table]. |
| 8167 | ** ^At most one preupdate hook may be registered at a time on a single |
| 8168 | ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides |
| 8169 | ** the previous setting. |
| 8170 | ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] |
| 8171 | ** with a NULL pointer as the second parameter. |
| 8172 | ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as |
| 8173 | ** the first parameter to callbacks. |
| 8174 | ** |
| 8175 | ** ^The preupdate hook only fires for changes to [rowid tables]; the preupdate |
| 8176 | ** hook is not invoked for changes to [virtual tables] or [WITHOUT ROWID] |
| 8177 | ** tables. |
| 8178 | ** |
| 8179 | ** ^The second parameter to the preupdate callback is a pointer to |
| 8180 | ** the [database connection] that registered the preupdate hook. |
| 8181 | ** ^The third parameter to the preupdate callback is one of the constants |
| 8182 | ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the |
| @@ -8186,16 +8203,20 @@ | |
| 8186 | ** will be "main" for the main database or "temp" for TEMP tables or |
| 8187 | ** the name given after the AS keyword in the [ATTACH] statement for attached |
| 8188 | ** databases.)^ |
| 8189 | ** ^The fifth parameter to the preupdate callback is the name of the |
| 8190 | ** table that is being modified. |
| 8191 | ** ^The sixth parameter to the preupdate callback is the initial [rowid] of the |
| 8192 | ** row being changes for SQLITE_UPDATE and SQLITE_DELETE changes and is |
| 8193 | ** undefined for SQLITE_INSERT changes. |
| 8194 | ** ^The seventh parameter to the preupdate callback is the final [rowid] of |
| 8195 | ** the row being changed for SQLITE_UPDATE and SQLITE_INSERT changes and is |
| 8196 | ** undefined for SQLITE_DELETE changes. |
| 8197 | ** |
| 8198 | ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], |
| 8199 | ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces |
| 8200 | ** provide additional information about a preupdate event. These routines |
| 8201 | ** may only be called from within a preupdate callback. Invoking any of |
| @@ -8895,11 +8916,12 @@ | |
| 8895 | ** |
| 8896 | ** <li> For each row (primary key) that exists in the to-table but not in |
| 8897 | ** the from-table, a DELETE record is added to the session object. |
| 8898 | ** |
| 8899 | ** <li> For each row (primary key) that exists in both tables, but features |
| 8900 | ** different in each, an UPDATE record is added to the session. |
| 8901 | ** </ul> |
| 8902 | ** |
| 8903 | ** To clarify, if this function is called and then a changeset constructed |
| 8904 | ** using [sqlite3session_changeset()], then after applying that changeset to |
| 8905 | ** database zFrom the contents of the two compatible tables would be |
| @@ -9480,11 +9502,11 @@ | |
| 9480 | ** considered compatible if all of the following are true: |
| 9481 | ** |
| 9482 | ** <ul> |
| 9483 | ** <li> The table has the same name as the name recorded in the |
| 9484 | ** changeset, and |
| 9485 | ** <li> The table has the same number of columns as recorded in the |
| 9486 | ** changeset, and |
| 9487 | ** <li> The table has primary key columns in the same position as |
| 9488 | ** recorded in the changeset. |
| 9489 | ** </ul> |
| 9490 | ** |
| @@ -9525,11 +9547,15 @@ | |
| 9525 | ** the changeset the row is deleted from the target database. |
| 9526 | ** |
| 9527 | ** If a row with matching primary key values is found, but one or more of |
| 9528 | ** the non-primary key fields contains a value different from the original |
| 9529 | ** row value stored in the changeset, the conflict-handler function is |
| 9530 | ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. |
| 9531 | ** |
| 9532 | ** If no row with matching primary key values is found in the database, |
| 9533 | ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] |
| 9534 | ** passed as the second argument. |
| 9535 | ** |
| @@ -9540,11 +9566,13 @@ | |
| 9540 | ** operation is attempted because an earlier call to the conflict handler |
| 9541 | ** function returned [SQLITE_CHANGESET_REPLACE]. |
| 9542 | ** |
| 9543 | ** <dt>INSERT Changes<dd> |
| 9544 | ** For each INSERT change, an attempt is made to insert the new row into |
| 9545 | ** the database. |
| 9546 | ** |
| 9547 | ** If the attempt to insert the row fails because the database already |
| 9548 | ** contains a row with the same primary key values, the conflict handler |
| 9549 | ** function is invoked with the second argument set to |
| 9550 | ** [SQLITE_CHANGESET_CONFLICT]. |
| @@ -9558,17 +9586,17 @@ | |
| 9558 | ** |
| 9559 | ** <dt>UPDATE Changes<dd> |
| 9560 | ** For each UPDATE change, this function checks if the target database |
| 9561 | ** contains a row with the same primary key value (or values) as the |
| 9562 | ** original row values stored in the changeset. If it does, and the values |
| 9563 | ** stored in all non-primary key columns also match the values stored in |
| 9564 | ** the changeset the row is updated within the target database. |
| 9565 | ** |
| 9566 | ** If a row with matching primary key values is found, but one or more of |
| 9567 | ** the non-primary key fields contains a value different from an original |
| 9568 | ** row value stored in the changeset, the conflict-handler function is |
| 9569 | ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since |
| 9570 | ** UPDATE changes only contain values for non-primary key fields that are |
| 9571 | ** to be modified, only those fields need to match the original values to |
| 9572 | ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. |
| 9573 | ** |
| 9574 | ** If no row with matching primary key values is found in the database, |
| 9575 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -119,13 +119,13 @@ | |
| 119 | ** |
| 120 | ** See also: [sqlite3_libversion()], |
| 121 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 122 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 123 | */ |
| 124 | #define SQLITE_VERSION "3.17.0" |
| 125 | #define SQLITE_VERSION_NUMBER 3017000 |
| 126 | #define SQLITE_SOURCE_ID "2017-02-07 13:51:48 a136609c98ed3cc673c5a3c2578d49db3f2518d1" |
| 127 | |
| 128 | /* |
| 129 | ** CAPI3REF: Run-Time Library Version Numbers |
| 130 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 131 | ** |
| @@ -257,11 +257,15 @@ | |
| 257 | ** sqlite3_uint64 and sqlite_uint64 types can store integer values |
| 258 | ** between 0 and +18446744073709551615 inclusive. |
| 259 | */ |
| 260 | #ifdef SQLITE_INT64_TYPE |
| 261 | typedef SQLITE_INT64_TYPE sqlite_int64; |
| 262 | # ifdef SQLITE_UINT64_TYPE |
| 263 | typedef SQLITE_UINT64_TYPE sqlite_uint64; |
| 264 | # else |
| 265 | typedef unsigned SQLITE_INT64_TYPE sqlite_uint64; |
| 266 | # endif |
| 267 | #elif defined(_MSC_VER) || defined(__BORLANDC__) |
| 268 | typedef __int64 sqlite_int64; |
| 269 | typedef unsigned __int64 sqlite_uint64; |
| 270 | #else |
| 271 | typedef long long int sqlite_int64; |
| @@ -570,11 +574,11 @@ | |
| 574 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 575 | ** after reboot following a crash or power loss, the only bytes in a |
| 576 | ** file that were written at the application level might have changed |
| 577 | ** and that adjacent bytes, even bytes within the same sector are |
| 578 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 579 | ** flag indicates that a file cannot be deleted when open. The |
| 580 | ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on |
| 581 | ** read-only media and cannot be changed even by processes with |
| 582 | ** elevated privileges. |
| 583 | */ |
| 584 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| @@ -720,10 +724,13 @@ | |
| 724 | ** <li> [SQLITE_IOCAP_ATOMIC16K] |
| 725 | ** <li> [SQLITE_IOCAP_ATOMIC32K] |
| 726 | ** <li> [SQLITE_IOCAP_ATOMIC64K] |
| 727 | ** <li> [SQLITE_IOCAP_SAFE_APPEND] |
| 728 | ** <li> [SQLITE_IOCAP_SEQUENTIAL] |
| 729 | ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN] |
| 730 | ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE] |
| 731 | ** <li> [SQLITE_IOCAP_IMMUTABLE] |
| 732 | ** </ul> |
| 733 | ** |
| 734 | ** The SQLITE_IOCAP_ATOMIC property means that all writes of |
| 735 | ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values |
| 736 | ** mean that writes of blocks that are nnn bytes in size and |
| @@ -5408,11 +5415,11 @@ | |
| 5415 | ** ^(The update hook is not invoked when internal system tables are |
| 5416 | ** modified (i.e. sqlite_master and sqlite_sequence).)^ |
| 5417 | ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified. |
| 5418 | ** |
| 5419 | ** ^In the current implementation, the update hook |
| 5420 | ** is not invoked when conflicting rows are deleted because of an |
| 5421 | ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook |
| 5422 | ** invoked when rows are deleted using the [truncate optimization]. |
| 5423 | ** The exceptions defined in this paragraph might change in a future |
| 5424 | ** release of SQLite. |
| 5425 | ** |
| @@ -6190,10 +6197,16 @@ | |
| 6197 | ** |
| 6198 | ** ^Unless it returns SQLITE_MISUSE, this function sets the |
| 6199 | ** [database connection] error code and message accessible via |
| 6200 | ** [sqlite3_errcode()] and [sqlite3_errmsg()] and related functions. |
| 6201 | ** |
| 6202 | ** A BLOB referenced by sqlite3_blob_open() may be read using the |
| 6203 | ** [sqlite3_blob_read()] interface and modified by using |
| 6204 | ** [sqlite3_blob_write()]. The [BLOB handle] can be moved to a |
| 6205 | ** different row of the same table using the [sqlite3_blob_reopen()] |
| 6206 | ** interface. However, the column, table, or database of a [BLOB handle] |
| 6207 | ** cannot be changed after the [BLOB handle] is opened. |
| 6208 | ** |
| 6209 | ** ^(If the row that a BLOB handle points to is modified by an |
| 6210 | ** [UPDATE], [DELETE], or by [ON CONFLICT] side-effects |
| 6211 | ** then the BLOB handle is marked as "expired". |
| 6212 | ** This is true if any column of the row is changed, even a column |
| @@ -6213,10 +6226,14 @@ | |
| 6226 | ** and the built-in [zeroblob] SQL function may be used to create a |
| 6227 | ** zero-filled blob to read or write using the incremental-blob interface. |
| 6228 | ** |
| 6229 | ** To avoid a resource leak, every open [BLOB handle] should eventually |
| 6230 | ** be released by a call to [sqlite3_blob_close()]. |
| 6231 | ** |
| 6232 | ** See also: [sqlite3_blob_close()], |
| 6233 | ** [sqlite3_blob_reopen()], [sqlite3_blob_read()], |
| 6234 | ** [sqlite3_blob_bytes()], [sqlite3_blob_write()]. |
| 6235 | */ |
| 6236 | SQLITE_API int sqlite3_blob_open( |
| 6237 | sqlite3*, |
| 6238 | const char *zDb, |
| 6239 | const char *zTable, |
| @@ -6228,15 +6245,15 @@ | |
| 6245 | |
| 6246 | /* |
| 6247 | ** CAPI3REF: Move a BLOB Handle to a New Row |
| 6248 | ** METHOD: sqlite3_blob |
| 6249 | ** |
| 6250 | ** ^This function is used to move an existing [BLOB handle] so that it points |
| 6251 | ** to a different row of the same database table. ^The new row is identified |
| 6252 | ** by the rowid value passed as the second argument. Only the row can be |
| 6253 | ** changed. ^The database, table and column on which the blob handle is open |
| 6254 | ** remain the same. Moving an existing [BLOB handle] to a new row is |
| 6255 | ** faster than closing the existing handle and opening a new one. |
| 6256 | ** |
| 6257 | ** ^(The new row must meet the same criteria as for [sqlite3_blob_open()] - |
| 6258 | ** it must exist and there must be either a blob or text value stored in |
| 6259 | ** the nominated column.)^ ^If the new row is not present in the table, or if |
| @@ -8161,22 +8178,22 @@ | |
| 8178 | ** ^These interfaces are only available if SQLite is compiled using the |
| 8179 | ** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option. |
| 8180 | ** |
| 8181 | ** ^The [sqlite3_preupdate_hook()] interface registers a callback function |
| 8182 | ** that is invoked prior to each [INSERT], [UPDATE], and [DELETE] operation |
| 8183 | ** on a database table. |
| 8184 | ** ^At most one preupdate hook may be registered at a time on a single |
| 8185 | ** [database connection]; each call to [sqlite3_preupdate_hook()] overrides |
| 8186 | ** the previous setting. |
| 8187 | ** ^The preupdate hook is disabled by invoking [sqlite3_preupdate_hook()] |
| 8188 | ** with a NULL pointer as the second parameter. |
| 8189 | ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as |
| 8190 | ** the first parameter to callbacks. |
| 8191 | ** |
| 8192 | ** ^The preupdate hook only fires for changes to real database tables; the |
| 8193 | ** preupdate hook is not invoked for changes to [virtual tables] or to |
| 8194 | ** system tables like sqlite_master or sqlite_stat1. |
| 8195 | ** |
| 8196 | ** ^The second parameter to the preupdate callback is a pointer to |
| 8197 | ** the [database connection] that registered the preupdate hook. |
| 8198 | ** ^The third parameter to the preupdate callback is one of the constants |
| 8199 | ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the |
| @@ -8186,16 +8203,20 @@ | |
| 8203 | ** will be "main" for the main database or "temp" for TEMP tables or |
| 8204 | ** the name given after the AS keyword in the [ATTACH] statement for attached |
| 8205 | ** databases.)^ |
| 8206 | ** ^The fifth parameter to the preupdate callback is the name of the |
| 8207 | ** table that is being modified. |
| 8208 | ** |
| 8209 | ** For an UPDATE or DELETE operation on a [rowid table], the sixth |
| 8210 | ** parameter passed to the preupdate callback is the initial [rowid] of the |
| 8211 | ** row being modified or deleted. For an INSERT operation on a rowid table, |
| 8212 | ** or any operation on a WITHOUT ROWID table, the value of the sixth |
| 8213 | ** parameter is undefined. For an INSERT or UPDATE on a rowid table the |
| 8214 | ** seventh parameter is the final rowid value of the row being inserted |
| 8215 | ** or updated. The value of the seventh parameter passed to the callback |
| 8216 | ** function is not defined for operations on WITHOUT ROWID tables, or for |
| 8217 | ** INSERT operations on rowid tables. |
| 8218 | ** |
| 8219 | ** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()], |
| 8220 | ** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces |
| 8221 | ** provide additional information about a preupdate event. These routines |
| 8222 | ** may only be called from within a preupdate callback. Invoking any of |
| @@ -8895,11 +8916,12 @@ | |
| 8916 | ** |
| 8917 | ** <li> For each row (primary key) that exists in the to-table but not in |
| 8918 | ** the from-table, a DELETE record is added to the session object. |
| 8919 | ** |
| 8920 | ** <li> For each row (primary key) that exists in both tables, but features |
| 8921 | ** different non-PK values in each, an UPDATE record is added to the |
| 8922 | ** session. |
| 8923 | ** </ul> |
| 8924 | ** |
| 8925 | ** To clarify, if this function is called and then a changeset constructed |
| 8926 | ** using [sqlite3session_changeset()], then after applying that changeset to |
| 8927 | ** database zFrom the contents of the two compatible tables would be |
| @@ -9480,11 +9502,11 @@ | |
| 9502 | ** considered compatible if all of the following are true: |
| 9503 | ** |
| 9504 | ** <ul> |
| 9505 | ** <li> The table has the same name as the name recorded in the |
| 9506 | ** changeset, and |
| 9507 | ** <li> The table has at least as many columns as recorded in the |
| 9508 | ** changeset, and |
| 9509 | ** <li> The table has primary key columns in the same position as |
| 9510 | ** recorded in the changeset. |
| 9511 | ** </ul> |
| 9512 | ** |
| @@ -9525,11 +9547,15 @@ | |
| 9547 | ** the changeset the row is deleted from the target database. |
| 9548 | ** |
| 9549 | ** If a row with matching primary key values is found, but one or more of |
| 9550 | ** the non-primary key fields contains a value different from the original |
| 9551 | ** row value stored in the changeset, the conflict-handler function is |
| 9552 | ** invoked with [SQLITE_CHANGESET_DATA] as the second argument. If the |
| 9553 | ** database table has more columns than are recorded in the changeset, |
| 9554 | ** only the values of those non-primary key fields are compared against |
| 9555 | ** the current database contents - any trailing database table columns |
| 9556 | ** are ignored. |
| 9557 | ** |
| 9558 | ** If no row with matching primary key values is found in the database, |
| 9559 | ** the conflict-handler function is invoked with [SQLITE_CHANGESET_NOTFOUND] |
| 9560 | ** passed as the second argument. |
| 9561 | ** |
| @@ -9540,11 +9566,13 @@ | |
| 9566 | ** operation is attempted because an earlier call to the conflict handler |
| 9567 | ** function returned [SQLITE_CHANGESET_REPLACE]. |
| 9568 | ** |
| 9569 | ** <dt>INSERT Changes<dd> |
| 9570 | ** For each INSERT change, an attempt is made to insert the new row into |
| 9571 | ** the database. If the changeset row contains fewer fields than the |
| 9572 | ** database table, the trailing fields are populated with their default |
| 9573 | ** values. |
| 9574 | ** |
| 9575 | ** If the attempt to insert the row fails because the database already |
| 9576 | ** contains a row with the same primary key values, the conflict handler |
| 9577 | ** function is invoked with the second argument set to |
| 9578 | ** [SQLITE_CHANGESET_CONFLICT]. |
| @@ -9558,17 +9586,17 @@ | |
| 9586 | ** |
| 9587 | ** <dt>UPDATE Changes<dd> |
| 9588 | ** For each UPDATE change, this function checks if the target database |
| 9589 | ** contains a row with the same primary key value (or values) as the |
| 9590 | ** original row values stored in the changeset. If it does, and the values |
| 9591 | ** stored in all modified non-primary key columns also match the values |
| 9592 | ** stored in the changeset the row is updated within the target database. |
| 9593 | ** |
| 9594 | ** If a row with matching primary key values is found, but one or more of |
| 9595 | ** the modified non-primary key fields contains a value different from an |
| 9596 | ** original row value stored in the changeset, the conflict-handler function |
| 9597 | ** is invoked with [SQLITE_CHANGESET_DATA] as the second argument. Since |
| 9598 | ** UPDATE changes only contain values for non-primary key fields that are |
| 9599 | ** to be modified, only those fields need to match the original values to |
| 9600 | ** avoid the SQLITE_CHANGESET_DATA conflict-handler callback. |
| 9601 | ** |
| 9602 | ** If no row with matching primary key values is found in the database, |
| 9603 |