Fossil SCM
Update the built-in SQLite to the latest trunk version that fixes a harmless compiler warning.
Commit
f8a29b2e208dddd5feab9d536ce01227eb5a58c2d805a2b089e4b9e10e2215b9
Parent
37dfb4c8d67aa86…
2 files changed
+641
-320
+35
-20
+641
-320
| --- extsrc/sqlite3.c | ||
| +++ extsrc/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.42.0. By combining all the individual C code files into this | |
| 3 | +** version $VERSION. 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. |
| @@ -14,10 +14,13 @@ | ||
| 14 | 14 | ** the text of this file. Search for "Begin file sqlite3.h" to find the start |
| 15 | 15 | ** of the embedded sqlite3.h header file.) Additional code files may be needed |
| 16 | 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | +** | |
| 20 | +** The content in this amalgamation comes from Fossil check-in | |
| 21 | +** ec4ab327decd6a5ee5e6a53f1489e17e0cd. | |
| 19 | 22 | */ |
| 20 | 23 | #define SQLITE_CORE 1 |
| 21 | 24 | #define SQLITE_AMALGAMATION 1 |
| 22 | 25 | #ifndef SQLITE_PRIVATE |
| 23 | 26 | # define SQLITE_PRIVATE static |
| @@ -48,15 +51,15 @@ | ||
| 48 | 51 | ** NO_TEST - The branches on this line are not |
| 49 | 52 | ** measured by branch coverage. This is |
| 50 | 53 | ** used on lines of code that actually |
| 51 | 54 | ** implement parts of coverage testing. |
| 52 | 55 | ** |
| 53 | -** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false | |
| 56 | +** OPTIMIZATION-IF-TRUE - This branch is allowed to always be false | |
| 54 | 57 | ** and the correct answer is still obtained, |
| 55 | 58 | ** though perhaps more slowly. |
| 56 | 59 | ** |
| 57 | -** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true | |
| 60 | +** OPTIMIZATION-IF-FALSE - This branch is allowed to always be true | |
| 58 | 61 | ** and the correct answer is still obtained, |
| 59 | 62 | ** though perhaps more slowly. |
| 60 | 63 | ** |
| 61 | 64 | ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread |
| 62 | 65 | ** that would be harmless and undetectable |
| @@ -454,13 +457,13 @@ | ||
| 454 | 457 | ** |
| 455 | 458 | ** See also: [sqlite3_libversion()], |
| 456 | 459 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 457 | 460 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 458 | 461 | */ |
| 459 | -#define SQLITE_VERSION "3.42.0" | |
| 460 | -#define SQLITE_VERSION_NUMBER 3042000 | |
| 461 | -#define SQLITE_SOURCE_ID "2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0" | |
| 462 | +#define SQLITE_VERSION "3.43.0" | |
| 463 | +#define SQLITE_VERSION_NUMBER 3043000 | |
| 464 | +#define SQLITE_SOURCE_ID "2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9" | |
| 462 | 465 | |
| 463 | 466 | /* |
| 464 | 467 | ** CAPI3REF: Run-Time Library Version Numbers |
| 465 | 468 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 466 | 469 | ** |
| @@ -1498,11 +1501,11 @@ | ||
| 1498 | 1501 | ** the database is not a wal-mode db, or if there is no such connection in any |
| 1499 | 1502 | ** other process. This opcode cannot be used to detect transactions opened |
| 1500 | 1503 | ** by clients within the current process, only within other processes. |
| 1501 | 1504 | ** |
| 1502 | 1505 | ** <li>[[SQLITE_FCNTL_CKSM_FILE]] |
| 1503 | -** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the | |
| 1506 | +** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the | |
| 1504 | 1507 | ** [checksum VFS shim] only. |
| 1505 | 1508 | ** |
| 1506 | 1509 | ** <li>[[SQLITE_FCNTL_RESET_CACHE]] |
| 1507 | 1510 | ** If there is currently no transaction open on the database, and the |
| 1508 | 1511 | ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control |
| @@ -2762,11 +2765,11 @@ | ||
| 2762 | 2765 | ** 3.0.0. |
| 2763 | 2766 | ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on, |
| 2764 | 2767 | ** the [VACUUM] command will fail with an obscure error when attempting to |
| 2765 | 2768 | ** process a table with generated columns and a descending index. This is |
| 2766 | 2769 | ** not considered a bug since SQLite versions 3.3.0 and earlier do not support |
| 2767 | -** either generated columns or decending indexes. | |
| 2770 | +** either generated columns or descending indexes. | |
| 2768 | 2771 | ** </dd> |
| 2769 | 2772 | ** |
| 2770 | 2773 | ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]] |
| 2771 | 2774 | ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt> |
| 2772 | 2775 | ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in |
| @@ -3043,10 +3046,11 @@ | ||
| 3043 | 3046 | ** SQL statements is a no-op and has no effect on SQL statements |
| 3044 | 3047 | ** that are started after the sqlite3_interrupt() call returns. |
| 3045 | 3048 | ** |
| 3046 | 3049 | ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether |
| 3047 | 3050 | ** or not an interrupt is currently in effect for [database connection] D. |
| 3051 | +** It returns 1 if an interrupt is currently in effect, or 0 otherwise. | |
| 3048 | 3052 | */ |
| 3049 | 3053 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 3050 | 3054 | SQLITE_API int sqlite3_is_interrupted(sqlite3*); |
| 3051 | 3055 | |
| 3052 | 3056 | /* |
| @@ -3696,12 +3700,14 @@ | ||
| 3696 | 3700 | ** and context pointer P. ^If the X callback is |
| 3697 | 3701 | ** NULL or if the M mask is zero, then tracing is disabled. The |
| 3698 | 3702 | ** M argument should be the bitwise OR-ed combination of |
| 3699 | 3703 | ** zero or more [SQLITE_TRACE] constants. |
| 3700 | 3704 | ** |
| 3701 | -** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides | |
| 3702 | -** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2(). | |
| 3705 | +** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P) | |
| 3706 | +** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or | |
| 3707 | +** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each | |
| 3708 | +** database connection may have at most one trace callback. | |
| 3703 | 3709 | ** |
| 3704 | 3710 | ** ^The X callback is invoked whenever any of the events identified by |
| 3705 | 3711 | ** mask M occur. ^The integer return value from the callback is currently |
| 3706 | 3712 | ** ignored, though this may change in future releases. Callback |
| 3707 | 3713 | ** implementations should return zero to ensure future compatibility. |
| @@ -4066,11 +4072,11 @@ | ||
| 4066 | 4072 | ** |
| 4067 | 4073 | ** The first parameter to these interfaces (hereafter referred to |
| 4068 | 4074 | ** as F) must be one of: |
| 4069 | 4075 | ** <ul> |
| 4070 | 4076 | ** <li> A database filename pointer created by the SQLite core and |
| 4071 | -** passed into the xOpen() method of a VFS implemention, or | |
| 4077 | +** passed into the xOpen() method of a VFS implementation, or | |
| 4072 | 4078 | ** <li> A filename obtained from [sqlite3_db_filename()], or |
| 4073 | 4079 | ** <li> A new filename constructed using [sqlite3_create_filename()]. |
| 4074 | 4080 | ** </ul> |
| 4075 | 4081 | ** If the F parameter is not one of the above, then the behavior is |
| 4076 | 4082 | ** undefined and probably undesirable. Older versions of SQLite were |
| @@ -4179,11 +4185,11 @@ | ||
| 4179 | 4185 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); |
| 4180 | 4186 | |
| 4181 | 4187 | /* |
| 4182 | 4188 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 4183 | 4189 | ** |
| 4184 | -** These interfces are provided for use by [VFS shim] implementations and | |
| 4190 | +** These interfaces are provided for use by [VFS shim] implementations and | |
| 4185 | 4191 | ** are not useful outside of that context. |
| 4186 | 4192 | ** |
| 4187 | 4193 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 4188 | 4194 | ** database filename D with corresponding journal file J and WAL file W and |
| 4189 | 4195 | ** with N URI parameters key/values pairs in the array P. The result from |
| @@ -4889,11 +4895,11 @@ | ||
| 4889 | 4895 | ** These three options exist: |
| 4890 | 4896 | ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished |
| 4891 | 4897 | ** with it may be passed. ^It is called to dispose of the BLOB or string even |
| 4892 | 4898 | ** if the call to the bind API fails, except the destructor is not called if |
| 4893 | 4899 | ** the third parameter is a NULL pointer or the fourth parameter is negative. |
| 4894 | -** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that | |
| 4900 | +** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that | |
| 4895 | 4901 | ** the application remains responsible for disposing of the object. ^In this |
| 4896 | 4902 | ** case, the object and the provided pointer to it must remain valid until |
| 4897 | 4903 | ** either the prepared statement is finalized or the same SQL parameter is |
| 4898 | 4904 | ** bound to something else, whichever occurs sooner. |
| 4899 | 4905 | ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
| @@ -5568,18 +5574,30 @@ | ||
| 5568 | 5574 | ** Use [sqlite3_clear_bindings()] to reset the bindings. |
| 5569 | 5575 | ** |
| 5570 | 5576 | ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
| 5571 | 5577 | ** back to the beginning of its program. |
| 5572 | 5578 | ** |
| 5573 | -** ^If the most recent call to [sqlite3_step(S)] for the | |
| 5574 | -** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], | |
| 5575 | -** or if [sqlite3_step(S)] has never before been called on S, | |
| 5576 | -** then [sqlite3_reset(S)] returns [SQLITE_OK]. | |
| 5579 | +** ^The return code from [sqlite3_reset(S)] indicates whether or not | |
| 5580 | +** the previous evaluation of prepared statement S completed successfully. | |
| 5581 | +** ^If [sqlite3_step(S)] has never before been called on S or if | |
| 5582 | +** [sqlite3_step(S)] has not been called since the previous call | |
| 5583 | +** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return | |
| 5584 | +** [SQLITE_OK]. | |
| 5577 | 5585 | ** |
| 5578 | 5586 | ** ^If the most recent call to [sqlite3_step(S)] for the |
| 5579 | 5587 | ** [prepared statement] S indicated an error, then |
| 5580 | 5588 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
| 5589 | +** ^The [sqlite3_reset(S)] interface might also return an [error code] | |
| 5590 | +** if there were no prior errors but the process of resetting | |
| 5591 | +** the prepared statement caused a new error. ^For example, if an | |
| 5592 | +** [INSERT] statement with a [RETURNING] clause is only stepped one time, | |
| 5593 | +** that one call to [sqlite3_step(S)] might return SQLITE_ROW but | |
| 5594 | +** the overall statement might still fail and the [sqlite3_reset(S)] call | |
| 5595 | +** might return SQLITE_BUSY if locking constraints prevent the | |
| 5596 | +** database change from committing. Therefore, it is important that | |
| 5597 | +** applications check the return code from [sqlite3_reset(S)] even if | |
| 5598 | +** no prior call to [sqlite3_step(S)] indicated a problem. | |
| 5581 | 5599 | ** |
| 5582 | 5600 | ** ^The [sqlite3_reset(S)] interface does not change the values |
| 5583 | 5601 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
| 5584 | 5602 | */ |
| 5585 | 5603 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| @@ -5792,11 +5810,11 @@ | ||
| 5792 | 5810 | ** <p> |
| 5793 | 5811 | ** The SQLITE_DIRECTONLY flag is recommended for any |
| 5794 | 5812 | ** [application-defined SQL function] |
| 5795 | 5813 | ** that has side-effects or that could potentially leak sensitive information. |
| 5796 | 5814 | ** This will prevent attacks in which an application is tricked |
| 5797 | -** into using a database file that has had its schema surreptiously | |
| 5815 | +** into using a database file that has had its schema surreptitiously | |
| 5798 | 5816 | ** modified to invoke the application-defined function in ways that are |
| 5799 | 5817 | ** harmful. |
| 5800 | 5818 | ** <p> |
| 5801 | 5819 | ** Some people say it is good practice to set SQLITE_DIRECTONLY on all |
| 5802 | 5820 | ** [application-defined SQL functions], regardless of whether or not they |
| @@ -9501,12 +9519,12 @@ | ||
| 9501 | 9519 | ** ^(There may be at most one unlock-notify callback registered by a |
| 9502 | 9520 | ** blocked connection. If sqlite3_unlock_notify() is called when the |
| 9503 | 9521 | ** blocked connection already has a registered unlock-notify callback, |
| 9504 | 9522 | ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is |
| 9505 | 9523 | ** called with a NULL pointer as its second argument, then any existing |
| 9506 | -** unlock-notify callback is canceled. ^The blocked connections | |
| 9507 | -** unlock-notify callback may also be canceled by closing the blocked | |
| 9524 | +** unlock-notify callback is cancelled. ^The blocked connections | |
| 9525 | +** unlock-notify callback may also be cancelled by closing the blocked | |
| 9508 | 9526 | ** connection using [sqlite3_close()]. |
| 9509 | 9527 | ** |
| 9510 | 9528 | ** The unlock-notify callback is not reentrant. If an application invokes |
| 9511 | 9529 | ** any sqlite3_xxx API functions from within an unlock-notify callback, a |
| 9512 | 9530 | ** crash or deadlock may be the result. |
| @@ -9925,11 +9943,11 @@ | ||
| 9925 | 9943 | ** </dd> |
| 9926 | 9944 | ** |
| 9927 | 9945 | ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 9928 | 9946 | ** <dd>Calls of the form |
| 9929 | 9947 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 9930 | -** the [xConnect] or [xCreate] methods of a [virtual table] implmentation | |
| 9948 | +** the [xConnect] or [xCreate] methods of a [virtual table] implementation | |
| 9931 | 9949 | ** prohibits that virtual table from being used from within triggers and |
| 9932 | 9950 | ** views. |
| 9933 | 9951 | ** </dd> |
| 9934 | 9952 | ** |
| 9935 | 9953 | ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| @@ -10115,11 +10133,11 @@ | ||
| 10115 | 10133 | ** ^(A constraint on a virtual table of the form |
| 10116 | 10134 | ** "[IN operator|column IN (...)]" is |
| 10117 | 10135 | ** communicated to the xBestIndex method as a |
| 10118 | 10136 | ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use |
| 10119 | 10137 | ** this constraint, it must set the corresponding |
| 10120 | -** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under | |
| 10138 | +** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under | |
| 10121 | 10139 | ** the usual mode of handling IN operators, SQLite generates [bytecode] |
| 10122 | 10140 | ** that invokes the [xFilter|xFilter() method] once for each value |
| 10123 | 10141 | ** on the right-hand side of the IN operator.)^ Thus the virtual table |
| 10124 | 10142 | ** only sees a single value from the right-hand side of the IN operator |
| 10125 | 10143 | ** at a time. |
| @@ -10544,11 +10562,11 @@ | ||
| 10544 | 10562 | ** triggers; and so forth. |
| 10545 | 10563 | ** |
| 10546 | 10564 | ** When the [sqlite3_blob_write()] API is used to update a blob column, |
| 10547 | 10565 | ** the pre-update hook is invoked with SQLITE_DELETE. This is because the |
| 10548 | 10566 | ** in this case the new values are not available. In this case, when a |
| 10549 | -** callback made with op==SQLITE_DELETE is actuall a write using the | |
| 10567 | +** callback made with op==SQLITE_DELETE is actually a write using the | |
| 10550 | 10568 | ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns |
| 10551 | 10569 | ** the index of the column being written. In other cases, where the |
| 10552 | 10570 | ** pre-update hook is being invoked for some other reason, including a |
| 10553 | 10571 | ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1. |
| 10554 | 10572 | ** |
| @@ -13468,11 +13486,11 @@ | ||
| 13468 | 13486 | ** The maximum number of terms in a compound SELECT statement. |
| 13469 | 13487 | ** The code generator for compound SELECT statements does one |
| 13470 | 13488 | ** level of recursion for each term. A stack overflow can result |
| 13471 | 13489 | ** if the number of terms is too large. In practice, most SQL |
| 13472 | 13490 | ** never has more than 3 or 4 terms. Use a value of 0 to disable |
| 13473 | -** any limit on the number of terms in a compount SELECT. | |
| 13491 | +** any limit on the number of terms in a compound SELECT. | |
| 13474 | 13492 | */ |
| 13475 | 13493 | #ifndef SQLITE_MAX_COMPOUND_SELECT |
| 13476 | 13494 | # define SQLITE_MAX_COMPOUND_SELECT 500 |
| 13477 | 13495 | #endif |
| 13478 | 13496 | |
| @@ -14806,11 +14824,11 @@ | ||
| 14806 | 14824 | }; |
| 14807 | 14825 | |
| 14808 | 14826 | /* |
| 14809 | 14827 | ** Name of table that holds the database schema. |
| 14810 | 14828 | ** |
| 14811 | -** The PREFERRED names are used whereever possible. But LEGACY is also | |
| 14829 | +** The PREFERRED names are used wherever possible. But LEGACY is also | |
| 14812 | 14830 | ** used for backwards compatibility. |
| 14813 | 14831 | ** |
| 14814 | 14832 | ** 1. Queries can use either the PREFERRED or the LEGACY names |
| 14815 | 14833 | ** 2. The sqlite3_set_authorizer() callback uses the LEGACY name |
| 14816 | 14834 | ** 3. The PRAGMA table_list statement uses the PREFERRED name |
| @@ -16575,11 +16593,11 @@ | ||
| 16575 | 16593 | |
| 16576 | 16594 | /* |
| 16577 | 16595 | ** The VdbeCoverage macros are used to set a coverage testing point |
| 16578 | 16596 | ** for VDBE branch instructions. The coverage testing points are line |
| 16579 | 16597 | ** numbers in the sqlite3.c source file. VDBE branch coverage testing |
| 16580 | -** only works with an amalagmation build. That's ok since a VDBE branch | |
| 16598 | +** only works with an amalgamation build. That's ok since a VDBE branch | |
| 16581 | 16599 | ** coverage build designed for testing the test suite only. No application |
| 16582 | 16600 | ** should ever ship with VDBE branch coverage measuring turned on. |
| 16583 | 16601 | ** |
| 16584 | 16602 | ** VdbeCoverage(v) // Mark the previously coded instruction |
| 16585 | 16603 | ** // as a branch |
| @@ -16593,21 +16611,21 @@ | ||
| 16593 | 16611 | ** VdbeCoverageNeverNull(v) // Previous three-way branch is only |
| 16594 | 16612 | ** // taken on the first two ways. The |
| 16595 | 16613 | ** // NULL option is not possible |
| 16596 | 16614 | ** |
| 16597 | 16615 | ** VdbeCoverageEqNe(v) // Previous OP_Jump is only interested |
| 16598 | -** // in distingishing equal and not-equal. | |
| 16616 | +** // in distinguishing equal and not-equal. | |
| 16599 | 16617 | ** |
| 16600 | 16618 | ** Every VDBE branch operation must be tagged with one of the macros above. |
| 16601 | 16619 | ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and |
| 16602 | 16620 | ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch() |
| 16603 | 16621 | ** routine in vdbe.c, alerting the developer to the missed tag. |
| 16604 | 16622 | ** |
| 16605 | 16623 | ** During testing, the test application will invoke |
| 16606 | 16624 | ** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback |
| 16607 | 16625 | ** routine that is invoked as each bytecode branch is taken. The callback |
| 16608 | -** contains the sqlite3.c source line number ov the VdbeCoverage macro and | |
| 16626 | +** contains the sqlite3.c source line number of the VdbeCoverage macro and | |
| 16609 | 16627 | ** flags to indicate whether or not the branch was taken. The test application |
| 16610 | 16628 | ** is responsible for keeping track of this and reporting byte-code branches |
| 16611 | 16629 | ** that are never taken. |
| 16612 | 16630 | ** |
| 16613 | 16631 | ** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the |
| @@ -16942,11 +16960,11 @@ | ||
| 16942 | 16960 | #endif |
| 16943 | 16961 | |
| 16944 | 16962 | /* |
| 16945 | 16963 | ** Default synchronous levels. |
| 16946 | 16964 | ** |
| 16947 | -** Note that (for historcal reasons) the PAGER_SYNCHRONOUS_* macros differ | |
| 16965 | +** Note that (for historical reasons) the PAGER_SYNCHRONOUS_* macros differ | |
| 16948 | 16966 | ** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1. |
| 16949 | 16967 | ** |
| 16950 | 16968 | ** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS |
| 16951 | 16969 | ** OFF 1 0 |
| 16952 | 16970 | ** NORMAL 2 1 |
| @@ -16981,11 +16999,11 @@ | ||
| 16981 | 16999 | |
| 16982 | 17000 | /* |
| 16983 | 17001 | ** An instance of the following structure stores a database schema. |
| 16984 | 17002 | ** |
| 16985 | 17003 | ** Most Schema objects are associated with a Btree. The exception is |
| 16986 | -** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing. | |
| 17004 | +** the Schema for the TEMP database (sqlite3.aDb[1]) which is free-standing. | |
| 16987 | 17005 | ** In shared cache mode, a single Schema object can be shared by multiple |
| 16988 | 17006 | ** Btrees that refer to the same underlying BtShared object. |
| 16989 | 17007 | ** |
| 16990 | 17008 | ** Schema objects are automatically deallocated when the last Btree that |
| 16991 | 17009 | ** references them is destroyed. The TEMP Schema is manually freed by |
| @@ -17092,11 +17110,11 @@ | ||
| 17092 | 17110 | u32 nSlot; /* Number of lookaside slots allocated */ |
| 17093 | 17111 | u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ |
| 17094 | 17112 | LookasideSlot *pInit; /* List of buffers not previously used */ |
| 17095 | 17113 | LookasideSlot *pFree; /* List of available buffers */ |
| 17096 | 17114 | #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 17097 | - LookasideSlot *pSmallInit; /* List of small buffers not prediously used */ | |
| 17115 | + LookasideSlot *pSmallInit; /* List of small buffers not previously used */ | |
| 17098 | 17116 | LookasideSlot *pSmallFree; /* List of available small buffers */ |
| 17099 | 17117 | void *pMiddle; /* First byte past end of full-size buffers and |
| 17100 | 17118 | ** the first byte of LOOKASIDE_SMALL buffers */ |
| 17101 | 17119 | #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 17102 | 17120 | void *pStart; /* First byte of available memory space */ |
| @@ -17109,11 +17127,11 @@ | ||
| 17109 | 17127 | |
| 17110 | 17128 | #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0 |
| 17111 | 17129 | #define EnableLookaside db->lookaside.bDisable--;\ |
| 17112 | 17130 | db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue |
| 17113 | 17131 | |
| 17114 | -/* Size of the smaller allocations in two-size lookside */ | |
| 17132 | +/* Size of the smaller allocations in two-size lookaside */ | |
| 17115 | 17133 | #ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 17116 | 17134 | # define LOOKASIDE_SMALL 0 |
| 17117 | 17135 | #else |
| 17118 | 17136 | # define LOOKASIDE_SMALL 128 |
| 17119 | 17137 | #endif |
| @@ -17537,11 +17555,11 @@ | ||
| 17537 | 17555 | ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!! |
| 17538 | 17556 | ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API |
| 17539 | 17557 | ** |
| 17540 | 17558 | ** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the |
| 17541 | 17559 | ** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is |
| 17542 | -** used internally and if set means tha the function has side effects. | |
| 17560 | +** used internally and if set means that the function has side effects. | |
| 17543 | 17561 | ** SQLITE_INNOCUOUS is used by application code and means "not unsafe". |
| 17544 | 17562 | ** See multiple instances of tag-20230109-1. |
| 17545 | 17563 | */ |
| 17546 | 17564 | #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ |
| 17547 | 17565 | #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ |
| @@ -18127,11 +18145,11 @@ | ||
| 18127 | 18145 | ** to its default value. CASCADE means that a DELETE or UPDATE of the |
| 18128 | 18146 | ** referenced table row is propagated into the row that holds the |
| 18129 | 18147 | ** foreign key. |
| 18130 | 18148 | ** |
| 18131 | 18149 | ** The OE_Default value is a place holder that means to use whatever |
| 18132 | -** conflict resolution algorthm is required from context. | |
| 18150 | +** conflict resolution algorithm is required from context. | |
| 18133 | 18151 | ** |
| 18134 | 18152 | ** The following symbolic values are used to record which type |
| 18135 | 18153 | ** of conflict resolution action to take. |
| 18136 | 18154 | */ |
| 18137 | 18155 | #define OE_None 0 /* There is no constraint to check */ |
| @@ -18541,11 +18559,11 @@ | ||
| 18541 | 18559 | #endif |
| 18542 | 18560 | int iTable; /* TK_COLUMN: cursor number of table holding column |
| 18543 | 18561 | ** TK_REGISTER: register number |
| 18544 | 18562 | ** TK_TRIGGER: 1 -> new, 0 -> old |
| 18545 | 18563 | ** EP_Unlikely: 134217728 times likelihood |
| 18546 | - ** TK_IN: ephemerial table holding RHS | |
| 18564 | + ** TK_IN: ephemeral table holding RHS | |
| 18547 | 18565 | ** TK_SELECT_COLUMN: Number of columns on the LHS |
| 18548 | 18566 | ** TK_SELECT: 1st register of result vector */ |
| 18549 | 18567 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 18550 | 18568 | ** TK_VARIABLE: variable number (always >= 1). |
| 18551 | 18569 | ** TK_SELECT_COLUMN: column of the result vector */ |
| @@ -18811,11 +18829,11 @@ | ||
| 18811 | 18829 | unsigned fromDDL :1; /* Comes from sqlite_schema */ |
| 18812 | 18830 | unsigned isCte :1; /* This is a CTE */ |
| 18813 | 18831 | unsigned notCte :1; /* This item may not match a CTE */ |
| 18814 | 18832 | unsigned isUsing :1; /* u3.pUsing is valid */ |
| 18815 | 18833 | unsigned isOn :1; /* u3.pOn was once valid and non-NULL */ |
| 18816 | - unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */ | |
| 18834 | + unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */ | |
| 18817 | 18835 | unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */ |
| 18818 | 18836 | } fg; |
| 18819 | 18837 | int iCursor; /* The VDBE cursor number used to access this table */ |
| 18820 | 18838 | union { |
| 18821 | 18839 | Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */ |
| @@ -19657,11 +19675,11 @@ | ||
| 19657 | 19675 | #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ |
| 19658 | 19676 | |
| 19659 | 19677 | /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled |
| 19660 | 19678 | ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning |
| 19661 | 19679 | ** parameters are for temporary use during development, to help find |
| 19662 | -** optimial values for parameters in the query planner. The should not | |
| 19680 | +** optimal values for parameters in the query planner. The should not | |
| 19663 | 19681 | ** be used on trunk check-ins. They are a temporary mechanism available |
| 19664 | 19682 | ** for transient development builds only. |
| 19665 | 19683 | ** |
| 19666 | 19684 | ** Tuning parameters are numbered starting with 1. |
| 19667 | 19685 | */ |
| @@ -19769,10 +19787,11 @@ | ||
| 19769 | 19787 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 19770 | 19788 | int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 19771 | 19789 | void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ |
| 19772 | 19790 | int walkerDepth; /* Number of subqueries */ |
| 19773 | 19791 | u16 eCode; /* A small processing code */ |
| 19792 | + u16 mWFlags; /* Use-dependent flags */ | |
| 19774 | 19793 | union { /* Extra data for callback */ |
| 19775 | 19794 | NameContext *pNC; /* Naming context */ |
| 19776 | 19795 | int n; /* A counter */ |
| 19777 | 19796 | int iCur; /* A cursor number */ |
| 19778 | 19797 | SrcList *pSrcList; /* FROM clause */ |
| @@ -20479,11 +20498,11 @@ | ||
| 20479 | 20498 | SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, const Token*); |
| 20480 | 20499 | SQLITE_PRIVATE int sqlite3ExprCompare(const Parse*,const Expr*,const Expr*, int); |
| 20481 | 20500 | SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*,Expr*,int); |
| 20482 | 20501 | SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList*,const ExprList*, int); |
| 20483 | 20502 | SQLITE_PRIVATE int sqlite3ExprImpliesExpr(const Parse*,const Expr*,const Expr*, int); |
| 20484 | -SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int); | |
| 20503 | +SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int,int); | |
| 20485 | 20504 | SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*); |
| 20486 | 20505 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 20487 | 20506 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 20488 | 20507 | SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| 20489 | 20508 | SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*); |
| @@ -23042,11 +23061,11 @@ | ||
| 23042 | 23061 | int iNewReg; /* Register for new.* values */ |
| 23043 | 23062 | int iBlobWrite; /* Value returned by preupdate_blobwrite() */ |
| 23044 | 23063 | i64 iKey1; /* First key value passed to hook */ |
| 23045 | 23064 | i64 iKey2; /* Second key value passed to hook */ |
| 23046 | 23065 | Mem *aNew; /* Array of new.* values */ |
| 23047 | - Table *pTab; /* Schema object being upated */ | |
| 23066 | + Table *pTab; /* Schema object being updated */ | |
| 23048 | 23067 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 23049 | 23068 | }; |
| 23050 | 23069 | |
| 23051 | 23070 | /* |
| 23052 | 23071 | ** An instance of this object is used to pass an vector of values into |
| @@ -24258,10 +24277,29 @@ | ||
| 24258 | 24277 | { 4, "hour", 1.2897e+11, 3600.0 }, |
| 24259 | 24278 | { 3, "day", 5373485.0, 86400.0 }, |
| 24260 | 24279 | { 5, "month", 176546.0, 2592000.0 }, |
| 24261 | 24280 | { 4, "year", 14713.0, 31536000.0 }, |
| 24262 | 24281 | }; |
| 24282 | + | |
| 24283 | +/* | |
| 24284 | +** If the DateTime p is raw number, try to figure out if it is | |
| 24285 | +** a julian day number of a unix timestamp. Set the p value | |
| 24286 | +** appropriately. | |
| 24287 | +*/ | |
| 24288 | +static void autoAdjustDate(DateTime *p){ | |
| 24289 | + if( !p->rawS || p->validJD ){ | |
| 24290 | + p->rawS = 0; | |
| 24291 | + }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */ | |
| 24292 | + && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */ | |
| 24293 | + ){ | |
| 24294 | + double r = p->s*1000.0 + 210866760000000.0; | |
| 24295 | + clearYMD_HMS_TZ(p); | |
| 24296 | + p->iJD = (sqlite3_int64)(r + 0.5); | |
| 24297 | + p->validJD = 1; | |
| 24298 | + p->rawS = 0; | |
| 24299 | + } | |
| 24300 | +} | |
| 24263 | 24301 | |
| 24264 | 24302 | /* |
| 24265 | 24303 | ** Process a modifier to a date-time stamp. The modifiers are |
| 24266 | 24304 | ** as follows: |
| 24267 | 24305 | ** |
| @@ -24302,23 +24340,12 @@ | ||
| 24302 | 24340 | ** If rawS is available, then interpret as a julian day number, or |
| 24303 | 24341 | ** a unix timestamp, depending on its magnitude. |
| 24304 | 24342 | */ |
| 24305 | 24343 | if( sqlite3_stricmp(z, "auto")==0 ){ |
| 24306 | 24344 | if( idx>1 ) return 1; /* IMP: R-33611-57934 */ |
| 24307 | - if( !p->rawS || p->validJD ){ | |
| 24308 | - rc = 0; | |
| 24309 | - p->rawS = 0; | |
| 24310 | - }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */ | |
| 24311 | - && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */ | |
| 24312 | - ){ | |
| 24313 | - r = p->s*1000.0 + 210866760000000.0; | |
| 24314 | - clearYMD_HMS_TZ(p); | |
| 24315 | - p->iJD = (sqlite3_int64)(r + 0.5); | |
| 24316 | - p->validJD = 1; | |
| 24317 | - p->rawS = 0; | |
| 24318 | - rc = 0; | |
| 24319 | - } | |
| 24345 | + autoAdjustDate(p); | |
| 24346 | + rc = 0; | |
| 24320 | 24347 | } |
| 24321 | 24348 | break; |
| 24322 | 24349 | } |
| 24323 | 24350 | case 'j': { |
| 24324 | 24351 | /* |
| @@ -24480,22 +24507,68 @@ | ||
| 24480 | 24507 | case '7': |
| 24481 | 24508 | case '8': |
| 24482 | 24509 | case '9': { |
| 24483 | 24510 | double rRounder; |
| 24484 | 24511 | int i; |
| 24485 | - for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){} | |
| 24512 | + int Y,M,D,h,m,x; | |
| 24513 | + const char *z2 = z; | |
| 24514 | + for(n=1; z[n]; n++){ | |
| 24515 | + if( z[n]==':' ) break; | |
| 24516 | + if( sqlite3Isspace(z[n]) ) break; | |
| 24517 | + if( z[n]=='-' && n==5 && getDigits(&z[1], "40f", &Y)==1 ) break; | |
| 24518 | + } | |
| 24486 | 24519 | if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){ |
| 24487 | 24520 | rc = 1; |
| 24488 | 24521 | break; |
| 24489 | 24522 | } |
| 24490 | - if( z[n]==':' ){ | |
| 24523 | + if( z[n]=='-' ){ | |
| 24524 | + /* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the | |
| 24525 | + ** specified number of years, months, and days. MM is limited to | |
| 24526 | + ** the range 0-11 and DD is limited to 0-30. | |
| 24527 | + */ | |
| 24528 | + if( z[0]!='+' && z[0]!='-' ) break; /* Must start with +/- */ | |
| 24529 | + if( NEVER(n!=5) ) break; /* Must be 4-digit YYYY */ | |
| 24530 | + if( getDigits(&z[1], "40f-20a-20d", &Y, &M, &D)!=3 ) break; | |
| 24531 | + if( M>=12 ) break; /* M range 0..11 */ | |
| 24532 | + if( D>=31 ) break; /* D range 0..30 */ | |
| 24533 | + computeYMD_HMS(p); | |
| 24534 | + p->validJD = 0; | |
| 24535 | + if( z[0]=='-' ){ | |
| 24536 | + p->Y -= Y; | |
| 24537 | + p->M -= M; | |
| 24538 | + D = -D; | |
| 24539 | + }else{ | |
| 24540 | + p->Y += Y; | |
| 24541 | + p->M += M; | |
| 24542 | + } | |
| 24543 | + x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; | |
| 24544 | + p->Y += x; | |
| 24545 | + p->M -= x*12; | |
| 24546 | + computeJD(p); | |
| 24547 | + p->validHMS = 0; | |
| 24548 | + p->validYMD = 0; | |
| 24549 | + p->iJD += (i64)D*86400000; | |
| 24550 | + if( z[11]==0 ){ | |
| 24551 | + rc = 0; | |
| 24552 | + break; | |
| 24553 | + } | |
| 24554 | + if( sqlite3Isspace(z[11]) | |
| 24555 | + && getDigits(&z[12], "20c:20e", &h, &m)==2 | |
| 24556 | + ){ | |
| 24557 | + z2 = &z[12]; | |
| 24558 | + n = 2; | |
| 24559 | + }else{ | |
| 24560 | + break; | |
| 24561 | + } | |
| 24562 | + } | |
| 24563 | + if( z2[n]==':' ){ | |
| 24491 | 24564 | /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the |
| 24492 | 24565 | ** specified number of hours, minutes, seconds, and fractional seconds |
| 24493 | 24566 | ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be |
| 24494 | 24567 | ** omitted. |
| 24495 | 24568 | */ |
| 24496 | - const char *z2 = z; | |
| 24569 | + | |
| 24497 | 24570 | DateTime tx; |
| 24498 | 24571 | sqlite3_int64 day; |
| 24499 | 24572 | if( !sqlite3Isdigit(*z2) ) z2++; |
| 24500 | 24573 | memset(&tx, 0, sizeof(tx)); |
| 24501 | 24574 | if( parseHhMmSs(z2, &tx) ) break; |
| @@ -24526,11 +24599,10 @@ | ||
| 24526 | 24599 | && sqlite3_strnicmp(aXformType[i].zName, z, n)==0 |
| 24527 | 24600 | && r>-aXformType[i].rLimit && r<aXformType[i].rLimit |
| 24528 | 24601 | ){ |
| 24529 | 24602 | switch( i ){ |
| 24530 | 24603 | case 4: { /* Special processing to add months */ |
| 24531 | - int x; | |
| 24532 | 24604 | assert( strcmp(aXformType[i].zName,"month")==0 ); |
| 24533 | 24605 | computeYMD_HMS(p); |
| 24534 | 24606 | p->M += (int)r; |
| 24535 | 24607 | x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; |
| 24536 | 24608 | p->Y += x; |
| @@ -24803,11 +24875,11 @@ | ||
| 24803 | 24875 | ** %J ** julian day number |
| 24804 | 24876 | ** %m month 01-12 |
| 24805 | 24877 | ** %M minute 00-59 |
| 24806 | 24878 | ** %s seconds since 1970-01-01 |
| 24807 | 24879 | ** %S seconds 00-59 |
| 24808 | -** %w day of week 0-6 sunday==0 | |
| 24880 | +** %w day of week 0-6 Sunday==0 | |
| 24809 | 24881 | ** %W week of year 00-53 |
| 24810 | 24882 | ** %Y year 0000-9999 |
| 24811 | 24883 | ** %% % |
| 24812 | 24884 | */ |
| 24813 | 24885 | static void strftimeFunc( |
| @@ -24942,10 +25014,120 @@ | ||
| 24942 | 25014 | sqlite3_value **NotUsed2 |
| 24943 | 25015 | ){ |
| 24944 | 25016 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 24945 | 25017 | dateFunc(context, 0, 0); |
| 24946 | 25018 | } |
| 25019 | + | |
| 25020 | +/* | |
| 25021 | +** timediff(DATE1, DATE2) | |
| 25022 | +** | |
| 25023 | +** Return the amount of time that must be added to DATE2 in order to | |
| 25024 | +** convert it into DATE2. The time difference format is: | |
| 25025 | +** | |
| 25026 | +** +YYYY-MM-DD HH:MM:SS.SSS | |
| 25027 | +** | |
| 25028 | +** The initial "+" becomes "-" if DATE1 occurs before DATE2. For | |
| 25029 | +** date/time values A and B, the following invariant should hold: | |
| 25030 | +** | |
| 25031 | +** datetime(A) == (datetime(B, timediff(A,B)) | |
| 25032 | +** | |
| 25033 | +** Both DATE arguments must be either a julian day number, or an | |
| 25034 | +** ISO-8601 string. The unix timestamps are not supported by this | |
| 25035 | +** routine. | |
| 25036 | +*/ | |
| 25037 | +static void timediffFunc( | |
| 25038 | + sqlite3_context *context, | |
| 25039 | + int argc, | |
| 25040 | + sqlite3_value **argv | |
| 25041 | +){ | |
| 25042 | + char sign; | |
| 25043 | + int Y, M; | |
| 25044 | + DateTime d1, d2; | |
| 25045 | + sqlite3_str sRes; | |
| 25046 | + if( isDate(context, 1, argv, &d1) ) return; | |
| 25047 | + if( isDate(context, 1, &argv[1], &d2) ) return; | |
| 25048 | + computeYMD_HMS(&d1); | |
| 25049 | + computeYMD_HMS(&d2); | |
| 25050 | + if( d1.iJD>=d2.iJD ){ | |
| 25051 | + sign = '+'; | |
| 25052 | + Y = d1.Y - d2.Y; | |
| 25053 | + if( Y ){ | |
| 25054 | + d2.Y = d1.Y; | |
| 25055 | + d2.validJD = 0; | |
| 25056 | + computeJD(&d2); | |
| 25057 | + } | |
| 25058 | + M = d1.M - d2.M; | |
| 25059 | + if( M<0 ){ | |
| 25060 | + Y--; | |
| 25061 | + M += 12; | |
| 25062 | + } | |
| 25063 | + if( M!=0 ){ | |
| 25064 | + d2.M = d1.M; | |
| 25065 | + d2.validJD = 0; | |
| 25066 | + computeJD(&d2); | |
| 25067 | + } | |
| 25068 | + if( d1.iJD<d2.iJD ){ | |
| 25069 | + M--; | |
| 25070 | + if( M<0 ){ | |
| 25071 | + M = 11; | |
| 25072 | + Y--; | |
| 25073 | + } | |
| 25074 | + d2.M--; | |
| 25075 | + if( d2.M<1 ){ | |
| 25076 | + d2.M = 12; | |
| 25077 | + d2.Y--; | |
| 25078 | + } | |
| 25079 | + d2.validJD = 0; | |
| 25080 | + computeJD(&d2); | |
| 25081 | + } | |
| 25082 | + d1.iJD -= d2.iJD; | |
| 25083 | + d1.iJD += 148699540800000; | |
| 25084 | + }else{ | |
| 25085 | + sign = '-'; | |
| 25086 | + Y = d2.Y - d1.Y; | |
| 25087 | + if( Y ){ | |
| 25088 | + d2.Y = d1.Y; | |
| 25089 | + d2.validJD = 0; | |
| 25090 | + computeJD(&d2); | |
| 25091 | + } | |
| 25092 | + M = d2.M - d1.M; | |
| 25093 | + if( M<0 ){ | |
| 25094 | + Y--; | |
| 25095 | + M += 12; | |
| 25096 | + } | |
| 25097 | + if( M!=0 ){ | |
| 25098 | + d2.M = d1.M; | |
| 25099 | + d2.validJD = 0; | |
| 25100 | + computeJD(&d2); | |
| 25101 | + } | |
| 25102 | + if( d1.iJD>d2.iJD ){ | |
| 25103 | + M--; | |
| 25104 | + if( M<0 ){ | |
| 25105 | + M = 11; | |
| 25106 | + Y--; | |
| 25107 | + } | |
| 25108 | + d2.M++; | |
| 25109 | + if( d2.M>12 ){ | |
| 25110 | + d2.M = 1; | |
| 25111 | + d2.Y++; | |
| 25112 | + } | |
| 25113 | + d2.validJD = 0; | |
| 25114 | + computeJD(&d2); | |
| 25115 | + } | |
| 25116 | + d1.iJD = d2.iJD - d1.iJD; | |
| 25117 | + d1.iJD += 148699540800000; | |
| 25118 | + } | |
| 25119 | + d1.validYMD = 0; | |
| 25120 | + d1.validHMS = 0; | |
| 25121 | + d1.validTZ = 0; | |
| 25122 | + computeYMD_HMS(&d1); | |
| 25123 | + sqlite3StrAccumInit(&sRes, 0, 0, 0, 100); | |
| 25124 | + sqlite3_str_appendf(&sRes, "%c%04d-%02d-%02d %02d:%02d:%06.3f", | |
| 25125 | + sign, Y, M, d1.D-1, d1.h, d1.m, d1.s); | |
| 25126 | + sqlite3ResultStrAccum(context, &sRes); | |
| 25127 | +} | |
| 25128 | + | |
| 24947 | 25129 | |
| 24948 | 25130 | /* |
| 24949 | 25131 | ** current_timestamp() |
| 24950 | 25132 | ** |
| 24951 | 25133 | ** This function returns the same value as datetime('now'). |
| @@ -25017,10 +25199,11 @@ | ||
| 25017 | 25199 | PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ), |
| 25018 | 25200 | PURE_DATE(date, -1, 0, 0, dateFunc ), |
| 25019 | 25201 | PURE_DATE(time, -1, 0, 0, timeFunc ), |
| 25020 | 25202 | PURE_DATE(datetime, -1, 0, 0, datetimeFunc ), |
| 25021 | 25203 | PURE_DATE(strftime, -1, 0, 0, strftimeFunc ), |
| 25204 | + PURE_DATE(timediff, 2, 0, 0, timediffFunc ), | |
| 25022 | 25205 | DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), |
| 25023 | 25206 | DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc), |
| 25024 | 25207 | DFUNCTION(current_date, 0, 0, 0, cdateFunc ), |
| 25025 | 25208 | #else |
| 25026 | 25209 | STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc), |
| @@ -25170,11 +25353,11 @@ | ||
| 25170 | 25353 | && op!=SQLITE_FCNTL_CKPT_START |
| 25171 | 25354 | ){ |
| 25172 | 25355 | /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite |
| 25173 | 25356 | ** is using a regular VFS, it is called after the corresponding |
| 25174 | 25357 | ** transaction has been committed. Injecting a fault at this point |
| 25175 | - ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM | |
| 25358 | + ** confuses the test scripts - the COMMIT command returns SQLITE_NOMEM | |
| 25176 | 25359 | ** but the transaction is committed anyway. |
| 25177 | 25360 | ** |
| 25178 | 25361 | ** The core must call OsFileControl() though, not OsFileControlHint(), |
| 25179 | 25362 | ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably |
| 25180 | 25363 | ** means the commit really has failed and an error should be returned |
| @@ -25791,11 +25974,11 @@ | ||
| 25791 | 25974 | /* |
| 25792 | 25975 | ** Like free() but works for allocations obtained from sqlite3MemMalloc() |
| 25793 | 25976 | ** or sqlite3MemRealloc(). |
| 25794 | 25977 | ** |
| 25795 | 25978 | ** For this low-level routine, we already know that pPrior!=0 since |
| 25796 | -** cases where pPrior==0 will have been intecepted and dealt with | |
| 25979 | +** cases where pPrior==0 will have been intercepted and dealt with | |
| 25797 | 25980 | ** by higher-level routines. |
| 25798 | 25981 | */ |
| 25799 | 25982 | static void sqlite3MemFree(void *pPrior){ |
| 25800 | 25983 | #ifdef SQLITE_MALLOCSIZE |
| 25801 | 25984 | SQLITE_FREE(pPrior); |
| @@ -25879,11 +26062,11 @@ | ||
| 25879 | 26062 | size_t len; |
| 25880 | 26063 | if( _sqliteZone_ ){ |
| 25881 | 26064 | return SQLITE_OK; |
| 25882 | 26065 | } |
| 25883 | 26066 | len = sizeof(cpuCount); |
| 25884 | - /* One usually wants to use hw.acctivecpu for MT decisions, but not here */ | |
| 26067 | + /* One usually wants to use hw.activecpu for MT decisions, but not here */ | |
| 25885 | 26068 | sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); |
| 25886 | 26069 | if( cpuCount>1 ){ |
| 25887 | 26070 | /* defer MT decisions to system malloc */ |
| 25888 | 26071 | _sqliteZone_ = malloc_default_zone(); |
| 25889 | 26072 | }else{ |
| @@ -28346,11 +28529,11 @@ | ||
| 28346 | 28529 | |
| 28347 | 28530 | #include <pthread.h> |
| 28348 | 28531 | |
| 28349 | 28532 | /* |
| 28350 | 28533 | ** The sqlite3_mutex.id, sqlite3_mutex.nRef, and sqlite3_mutex.owner fields |
| 28351 | -** are necessary under two condidtions: (1) Debug builds and (2) using | |
| 28534 | +** are necessary under two conditions: (1) Debug builds and (2) using | |
| 28352 | 28535 | ** home-grown mutexes. Encapsulate these conditions into a single #define. |
| 28353 | 28536 | */ |
| 28354 | 28537 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HOMEGROWN_RECURSIVE_MUTEX) |
| 28355 | 28538 | # define SQLITE_MUTEX_NREF 1 |
| 28356 | 28539 | #else |
| @@ -28847,11 +29030,11 @@ | ||
| 28847 | 29030 | */ |
| 28848 | 29031 | struct sqlite3_mutex { |
| 28849 | 29032 | CRITICAL_SECTION mutex; /* Mutex controlling the lock */ |
| 28850 | 29033 | int id; /* Mutex type */ |
| 28851 | 29034 | #ifdef SQLITE_DEBUG |
| 28852 | - volatile int nRef; /* Number of enterances */ | |
| 29035 | + volatile int nRef; /* Number of entrances */ | |
| 28853 | 29036 | volatile DWORD owner; /* Thread holding this mutex */ |
| 28854 | 29037 | volatile LONG trace; /* True to trace changes */ |
| 28855 | 29038 | #endif |
| 28856 | 29039 | }; |
| 28857 | 29040 | |
| @@ -32228,11 +32411,12 @@ | ||
| 32228 | 32411 | const char *azOp[] = { |
| 32229 | 32412 | "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" |
| 32230 | 32413 | }; |
| 32231 | 32414 | assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); |
| 32232 | 32415 | assert( pExpr->pRight ); |
| 32233 | - assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE ); | |
| 32416 | + assert( sqlite3ExprSkipCollateAndLikely(pExpr->pRight)->op | |
| 32417 | + == TK_TRUEFALSE ); | |
| 32234 | 32418 | x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); |
| 32235 | 32419 | zUniOp = azOp[x]; |
| 32236 | 32420 | break; |
| 32237 | 32421 | } |
| 32238 | 32422 | |
| @@ -33887,11 +34071,11 @@ | ||
| 33887 | 34071 | #endif |
| 33888 | 34072 | |
| 33889 | 34073 | /* |
| 33890 | 34074 | ** Calls to sqlite3FaultSim() are used to simulate a failure during testing, |
| 33891 | 34075 | ** or to bypass normal error detection during testing in order to let |
| 33892 | -** execute proceed futher downstream. | |
| 34076 | +** execute proceed further downstream. | |
| 33893 | 34077 | ** |
| 33894 | 34078 | ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The |
| 33895 | 34079 | ** sqlite3FaultSim() function only returns non-zero during testing. |
| 33896 | 34080 | ** |
| 33897 | 34081 | ** During testing, if the test harness has set a fault-sim callback using |
| @@ -34498,11 +34682,11 @@ | ||
| 34498 | 34682 | } |
| 34499 | 34683 | |
| 34500 | 34684 | /* store the result */ |
| 34501 | 34685 | *pResult = result; |
| 34502 | 34686 | |
| 34503 | - /* return true if number and no extra non-whitespace chracters after */ | |
| 34687 | + /* return true if number and no extra non-whitespace characters after */ | |
| 34504 | 34688 | if( z==zEnd && nDigit>0 && eValid && eType>0 ){ |
| 34505 | 34689 | return eType; |
| 34506 | 34690 | }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){ |
| 34507 | 34691 | return -1; |
| 34508 | 34692 | }else{ |
| @@ -34634,11 +34818,11 @@ | ||
| 34634 | 34818 | testcase( i==20*incr ); |
| 34635 | 34819 | if( u>LARGEST_INT64 ){ |
| 34636 | 34820 | /* This test and assignment is needed only to suppress UB warnings |
| 34637 | 34821 | ** from clang and -fsanitize=undefined. This test and assignment make |
| 34638 | 34822 | ** the code a little larger and slower, and no harm comes from omitting |
| 34639 | - ** them, but we must appaise the undefined-behavior pharisees. */ | |
| 34823 | + ** them, but we must appease the undefined-behavior pharisees. */ | |
| 34640 | 34824 | *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64; |
| 34641 | 34825 | }else if( neg ){ |
| 34642 | 34826 | *pNum = -(i64)u; |
| 34643 | 34827 | }else{ |
| 34644 | 34828 | *pNum = (i64)u; |
| @@ -35319,11 +35503,11 @@ | ||
| 35319 | 35503 | return 1; |
| 35320 | 35504 | } |
| 35321 | 35505 | } |
| 35322 | 35506 | |
| 35323 | 35507 | /* |
| 35324 | -** Attempt to add, substract, or multiply the 64-bit signed value iB against | |
| 35508 | +** Attempt to add, subtract, or multiply the 64-bit signed value iB against | |
| 35325 | 35509 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 35326 | 35510 | ** Return 0 on success. Or if the operation would have resulted in an |
| 35327 | 35511 | ** overflow, leave *pA unchanged and return 1. |
| 35328 | 35512 | */ |
| 35329 | 35513 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| @@ -35632,11 +35816,11 @@ | ||
| 35632 | 35816 | */ |
| 35633 | 35817 | #ifndef SQLITE_HWTIME_H |
| 35634 | 35818 | #define SQLITE_HWTIME_H |
| 35635 | 35819 | |
| 35636 | 35820 | /* |
| 35637 | -** The following routine only works on pentium-class (or newer) processors. | |
| 35821 | +** The following routine only works on Pentium-class (or newer) processors. | |
| 35638 | 35822 | ** It uses the RDTSC opcode to read the cycle count value out of the |
| 35639 | 35823 | ** processor and returns that value. This can be used for high-res |
| 35640 | 35824 | ** profiling. |
| 35641 | 35825 | */ |
| 35642 | 35826 | #if !defined(__STRICT_ANSI__) && \ |
| @@ -35804,11 +35988,11 @@ | ||
| 35804 | 35988 | pH->first = pNew; |
| 35805 | 35989 | } |
| 35806 | 35990 | } |
| 35807 | 35991 | |
| 35808 | 35992 | |
| 35809 | -/* Resize the hash table so that it cantains "new_size" buckets. | |
| 35993 | +/* Resize the hash table so that it contains "new_size" buckets. | |
| 35810 | 35994 | ** |
| 35811 | 35995 | ** The hash table might fail to resize if sqlite3_malloc() fails or |
| 35812 | 35996 | ** if the new size is the same as the prior size. |
| 35813 | 35997 | ** Return TRUE if the resize occurs and false if not. |
| 35814 | 35998 | */ |
| @@ -37190,11 +37374,11 @@ | ||
| 37190 | 37374 | ** skip locking all together. |
| 37191 | 37375 | ** |
| 37192 | 37376 | ** This source file is organized into divisions where the logic for various |
| 37193 | 37377 | ** subfunctions is contained within the appropriate division. PLEASE |
| 37194 | 37378 | ** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed |
| 37195 | -** in the correct division and should be clearly labeled. | |
| 37379 | +** in the correct division and should be clearly labelled. | |
| 37196 | 37380 | ** |
| 37197 | 37381 | ** The layout of divisions is as follows: |
| 37198 | 37382 | ** |
| 37199 | 37383 | ** * General-purpose declarations and utility functions. |
| 37200 | 37384 | ** * Unique file ID logic used by VxWorks. |
| @@ -37777,11 +37961,11 @@ | ||
| 37777 | 37961 | #endif |
| 37778 | 37962 | } |
| 37779 | 37963 | |
| 37780 | 37964 | /* |
| 37781 | 37965 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| 37782 | -** "unix" VFSes. Return SQLITE_OK opon successfully updating the | |
| 37966 | +** "unix" VFSes. Return SQLITE_OK upon successfully updating the | |
| 37783 | 37967 | ** system call pointer, or SQLITE_NOTFOUND if there is no configurable |
| 37784 | 37968 | ** system call named zName. |
| 37785 | 37969 | */ |
| 37786 | 37970 | static int unixSetSystemCall( |
| 37787 | 37971 | sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ |
| @@ -38299,11 +38483,11 @@ | ||
| 38299 | 38483 | ** But wait: there are yet more problems with POSIX advisory locks. |
| 38300 | 38484 | ** |
| 38301 | 38485 | ** If you close a file descriptor that points to a file that has locks, |
| 38302 | 38486 | ** all locks on that file that are owned by the current process are |
| 38303 | 38487 | ** released. To work around this problem, each unixInodeInfo object |
| 38304 | -** maintains a count of the number of pending locks on tha inode. | |
| 38488 | +** maintains a count of the number of pending locks on the inode. | |
| 38305 | 38489 | ** When an attempt is made to close an unixFile, if there are |
| 38306 | 38490 | ** other unixFile open on the same inode that are holding locks, the call |
| 38307 | 38491 | ** to close() the file descriptor is deferred until all of the locks clear. |
| 38308 | 38492 | ** The unixInodeInfo structure keeps a list of file descriptors that need to |
| 38309 | 38493 | ** be closed and that list is walked (and cleared) when the last lock |
| @@ -38313,11 +38497,11 @@ | ||
| 38313 | 38497 | ** |
| 38314 | 38498 | ** Many older versions of linux use the LinuxThreads library which is |
| 38315 | 38499 | ** not posix compliant. Under LinuxThreads, a lock created by thread |
| 38316 | 38500 | ** A cannot be modified or overridden by a different thread B. |
| 38317 | 38501 | ** Only thread A can modify the lock. Locking behavior is correct |
| 38318 | -** if the appliation uses the newer Native Posix Thread Library (NPTL) | |
| 38502 | +** if the application uses the newer Native Posix Thread Library (NPTL) | |
| 38319 | 38503 | ** on linux - with NPTL a lock created by thread A can override locks |
| 38320 | 38504 | ** in thread B. But there is no way to know at compile-time which |
| 38321 | 38505 | ** threading library is being used. So there is no way to know at |
| 38322 | 38506 | ** compile-time whether or not thread A can override locks on thread B. |
| 38323 | 38507 | ** One has to do a run-time check to discover the behavior of the |
| @@ -38515,11 +38699,11 @@ | ||
| 38515 | 38699 | static void storeLastErrno(unixFile *pFile, int error){ |
| 38516 | 38700 | pFile->lastErrno = error; |
| 38517 | 38701 | } |
| 38518 | 38702 | |
| 38519 | 38703 | /* |
| 38520 | -** Close all file descriptors accumuated in the unixInodeInfo->pUnused list. | |
| 38704 | +** Close all file descriptors accumulated in the unixInodeInfo->pUnused list. | |
| 38521 | 38705 | */ |
| 38522 | 38706 | static void closePendingFds(unixFile *pFile){ |
| 38523 | 38707 | unixInodeInfo *pInode = pFile->pInode; |
| 38524 | 38708 | UnixUnusedFd *p; |
| 38525 | 38709 | UnixUnusedFd *pNext; |
| @@ -38878,19 +39062,19 @@ | ||
| 38878 | 39062 | ** lock primitives (called read-locks and write-locks below, to avoid |
| 38879 | 39063 | ** confusion with SQLite lock names). The algorithms are complicated |
| 38880 | 39064 | ** slightly in order to be compatible with Windows95 systems simultaneously |
| 38881 | 39065 | ** accessing the same database file, in case that is ever required. |
| 38882 | 39066 | ** |
| 38883 | - ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved | |
| 39067 | + ** Symbols defined in os.h identify the 'pending byte' and the 'reserved | |
| 38884 | 39068 | ** byte', each single bytes at well known offsets, and the 'shared byte |
| 38885 | 39069 | ** range', a range of 510 bytes at a well known offset. |
| 38886 | 39070 | ** |
| 38887 | 39071 | ** To obtain a SHARED lock, a read-lock is obtained on the 'pending |
| 38888 | 39072 | ** byte'. If this is successful, 'shared byte range' is read-locked |
| 38889 | 39073 | ** and the lock on the 'pending byte' released. (Legacy note: When |
| 38890 | 39074 | ** SQLite was first developed, Windows95 systems were still very common, |
| 38891 | - ** and Widnows95 lacks a shared-lock capability. So on Windows95, a | |
| 39075 | + ** and Windows95 lacks a shared-lock capability. So on Windows95, a | |
| 38892 | 39076 | ** single randomly selected by from the 'shared byte range' is locked. |
| 38893 | 39077 | ** Windows95 is now pretty much extinct, but this work-around for the |
| 38894 | 39078 | ** lack of shared-locks on Windows95 lives on, for backwards |
| 38895 | 39079 | ** compatibility.) |
| 38896 | 39080 | ** |
| @@ -38907,11 +39091,11 @@ | ||
| 38907 | 39091 | ** If a process that holds a RESERVED lock requests an EXCLUSIVE, then |
| 38908 | 39092 | ** a PENDING lock is obtained first. A PENDING lock is implemented by |
| 38909 | 39093 | ** obtaining a write-lock on the 'pending byte'. This ensures that no new |
| 38910 | 39094 | ** SHARED locks can be obtained, but existing SHARED locks are allowed to |
| 38911 | 39095 | ** persist. If the call to this function fails to obtain the EXCLUSIVE |
| 38912 | - ** lock in this case, it holds the PENDING lock intead. The client may | |
| 39096 | + ** lock in this case, it holds the PENDING lock instead. The client may | |
| 38913 | 39097 | ** then re-attempt the EXCLUSIVE lock later on, after existing SHARED |
| 38914 | 39098 | ** locks have cleared. |
| 38915 | 39099 | */ |
| 38916 | 39100 | int rc = SQLITE_OK; |
| 38917 | 39101 | unixFile *pFile = (unixFile*)id; |
| @@ -38935,11 +39119,11 @@ | ||
| 38935 | 39119 | return SQLITE_OK; |
| 38936 | 39120 | } |
| 38937 | 39121 | |
| 38938 | 39122 | /* Make sure the locking sequence is correct. |
| 38939 | 39123 | ** (1) We never move from unlocked to anything higher than shared lock. |
| 38940 | - ** (2) SQLite never explicitly requests a pendig lock. | |
| 39124 | + ** (2) SQLite never explicitly requests a pending lock. | |
| 38941 | 39125 | ** (3) A shared lock is always held when a reserve lock is requested. |
| 38942 | 39126 | */ |
| 38943 | 39127 | assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); |
| 38944 | 39128 | assert( eFileLock!=PENDING_LOCK ); |
| 38945 | 39129 | assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK ); |
| @@ -40153,11 +40337,11 @@ | ||
| 40153 | 40337 | return SQLITE_OK; |
| 40154 | 40338 | } |
| 40155 | 40339 | |
| 40156 | 40340 | /* Make sure the locking sequence is correct |
| 40157 | 40341 | ** (1) We never move from unlocked to anything higher than shared lock. |
| 40158 | - ** (2) SQLite never explicitly requests a pendig lock. | |
| 40342 | + ** (2) SQLite never explicitly requests a pending lock. | |
| 40159 | 40343 | ** (3) A shared lock is always held when a reserve lock is requested. |
| 40160 | 40344 | */ |
| 40161 | 40345 | assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); |
| 40162 | 40346 | assert( eFileLock!=PENDING_LOCK ); |
| 40163 | 40347 | assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK ); |
| @@ -40269,11 +40453,11 @@ | ||
| 40269 | 40453 | ** reestablish the shared lock if we can't get the afpUnlock |
| 40270 | 40454 | */ |
| 40271 | 40455 | if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST + |
| 40272 | 40456 | pInode->sharedByte, 1, 0)) ){ |
| 40273 | 40457 | int failed2 = SQLITE_OK; |
| 40274 | - /* now attemmpt to get the exclusive lock range */ | |
| 40458 | + /* now attempt to get the exclusive lock range */ | |
| 40275 | 40459 | failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST, |
| 40276 | 40460 | SHARED_SIZE, 1); |
| 40277 | 40461 | if( failed && (failed2 = afpSetLock(context->dbPath, pFile, |
| 40278 | 40462 | SHARED_FIRST + pInode->sharedByte, 1, 1)) ){ |
| 40279 | 40463 | /* Can't reestablish the shared lock. Sqlite can't deal, this is |
| @@ -40564,11 +40748,11 @@ | ||
| 40564 | 40748 | || offset+amt<=PENDING_BYTE |
| 40565 | 40749 | ); |
| 40566 | 40750 | #endif |
| 40567 | 40751 | |
| 40568 | 40752 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 40569 | - /* Deal with as much of this read request as possible by transfering | |
| 40753 | + /* Deal with as much of this read request as possible by transferring | |
| 40570 | 40754 | ** data from the memory mapping using memcpy(). */ |
| 40571 | 40755 | if( offset<pFile->mmapSize ){ |
| 40572 | 40756 | if( offset+amt <= pFile->mmapSize ){ |
| 40573 | 40757 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
| 40574 | 40758 | return SQLITE_OK; |
| @@ -40716,11 +40900,11 @@ | ||
| 40716 | 40900 | } |
| 40717 | 40901 | } |
| 40718 | 40902 | #endif |
| 40719 | 40903 | |
| 40720 | 40904 | #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 |
| 40721 | - /* Deal with as much of this write request as possible by transfering | |
| 40905 | + /* Deal with as much of this write request as possible by transferring | |
| 40722 | 40906 | ** data from the memory mapping using memcpy(). */ |
| 40723 | 40907 | if( offset<pFile->mmapSize ){ |
| 40724 | 40908 | if( offset+amt <= pFile->mmapSize ){ |
| 40725 | 40909 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); |
| 40726 | 40910 | return SQLITE_OK; |
| @@ -40838,11 +41022,11 @@ | ||
| 40838 | 41022 | #endif |
| 40839 | 41023 | |
| 40840 | 41024 | /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a |
| 40841 | 41025 | ** no-op. But go ahead and call fstat() to validate the file |
| 40842 | 41026 | ** descriptor as we need a method to provoke a failure during |
| 40843 | - ** coverate testing. | |
| 41027 | + ** coverage testing. | |
| 40844 | 41028 | */ |
| 40845 | 41029 | #ifdef SQLITE_NO_SYNC |
| 40846 | 41030 | { |
| 40847 | 41031 | struct stat buf; |
| 40848 | 41032 | rc = osFstat(fd, &buf); |
| @@ -46478,11 +46662,11 @@ | ||
| 46478 | 46662 | |
| 46479 | 46663 | }; /* End of the overrideable system calls */ |
| 46480 | 46664 | |
| 46481 | 46665 | /* |
| 46482 | 46666 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| 46483 | -** "win32" VFSes. Return SQLITE_OK opon successfully updating the | |
| 46667 | +** "win32" VFSes. Return SQLITE_OK upon successfully updating the | |
| 46484 | 46668 | ** system call pointer, or SQLITE_NOTFOUND if there is no configurable |
| 46485 | 46669 | ** system call named zName. |
| 46486 | 46670 | */ |
| 46487 | 46671 | static int winSetSystemCall( |
| 46488 | 46672 | sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ |
| @@ -48058,11 +48242,11 @@ | ||
| 48058 | 48242 | OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 48059 | 48243 | "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
| 48060 | 48244 | pFile->h, pBuf, amt, offset, pFile->locktype)); |
| 48061 | 48245 | |
| 48062 | 48246 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 48063 | - /* Deal with as much of this read request as possible by transfering | |
| 48247 | + /* Deal with as much of this read request as possible by transferring | |
| 48064 | 48248 | ** data from the memory mapping using memcpy(). */ |
| 48065 | 48249 | if( offset<pFile->mmapSize ){ |
| 48066 | 48250 | if( offset+amt <= pFile->mmapSize ){ |
| 48067 | 48251 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
| 48068 | 48252 | OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| @@ -48136,11 +48320,11 @@ | ||
| 48136 | 48320 | OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 48137 | 48321 | "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
| 48138 | 48322 | pFile->h, pBuf, amt, offset, pFile->locktype)); |
| 48139 | 48323 | |
| 48140 | 48324 | #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 |
| 48141 | - /* Deal with as much of this write request as possible by transfering | |
| 48325 | + /* Deal with as much of this write request as possible by transferring | |
| 48142 | 48326 | ** data from the memory mapping using memcpy(). */ |
| 48143 | 48327 | if( offset<pFile->mmapSize ){ |
| 48144 | 48328 | if( offset+amt <= pFile->mmapSize ){ |
| 48145 | 48329 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); |
| 48146 | 48330 | OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| @@ -48246,11 +48430,11 @@ | ||
| 48246 | 48430 | ** |
| 48247 | 48431 | ** The only feasible work-around is to defer the truncation until after |
| 48248 | 48432 | ** all references to memory-mapped content are closed. That is doable, |
| 48249 | 48433 | ** but involves adding a few branches in the common write code path which |
| 48250 | 48434 | ** could slow down normal operations slightly. Hence, we have decided for |
| 48251 | - ** now to simply make trancations a no-op if there are pending reads. We | |
| 48435 | + ** now to simply make transactions a no-op if there are pending reads. We | |
| 48252 | 48436 | ** can maybe revisit this decision in the future. |
| 48253 | 48437 | */ |
| 48254 | 48438 | return SQLITE_OK; |
| 48255 | 48439 | } |
| 48256 | 48440 | #endif |
| @@ -48305,11 +48489,11 @@ | ||
| 48305 | 48489 | } |
| 48306 | 48490 | |
| 48307 | 48491 | #ifdef SQLITE_TEST |
| 48308 | 48492 | /* |
| 48309 | 48493 | ** Count the number of fullsyncs and normal syncs. This is used to test |
| 48310 | -** that syncs and fullsyncs are occuring at the right times. | |
| 48494 | +** that syncs and fullsyncs are occurring at the right times. | |
| 48311 | 48495 | */ |
| 48312 | 48496 | SQLITE_API int sqlite3_sync_count = 0; |
| 48313 | 48497 | SQLITE_API int sqlite3_fullsync_count = 0; |
| 48314 | 48498 | #endif |
| 48315 | 48499 | |
| @@ -52643,11 +52827,11 @@ | ||
| 52643 | 52827 | return SQLITE_OK; |
| 52644 | 52828 | } |
| 52645 | 52829 | h = BITVEC_HASH(i++); |
| 52646 | 52830 | /* if there wasn't a hash collision, and this doesn't */ |
| 52647 | 52831 | /* completely fill the hash, then just add it without */ |
| 52648 | - /* worring about sub-dividing and re-hashing. */ | |
| 52832 | + /* worrying about sub-dividing and re-hashing. */ | |
| 52649 | 52833 | if( !p->u.aHash[h] ){ |
| 52650 | 52834 | if (p->nSet<(BITVEC_NINT-1)) { |
| 52651 | 52835 | goto bitvec_set_end; |
| 52652 | 52836 | } else { |
| 52653 | 52837 | goto bitvec_set_rehash; |
| @@ -53140,11 +53324,11 @@ | ||
| 53140 | 53324 | /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the |
| 53141 | 53325 | ** suggested cache size is set to N. */ |
| 53142 | 53326 | return p->szCache; |
| 53143 | 53327 | }else{ |
| 53144 | 53328 | i64 n; |
| 53145 | - /* IMPLEMANTATION-OF: R-59858-46238 If the argument N is negative, then the | |
| 53329 | + /* IMPLEMENTATION-OF: R-59858-46238 If the argument N is negative, then the | |
| 53146 | 53330 | ** number of cache pages is adjusted to be a number of pages that would |
| 53147 | 53331 | ** use approximately abs(N*1024) bytes of memory based on the current |
| 53148 | 53332 | ** page size. */ |
| 53149 | 53333 | n = ((-1024*(i64)p->szCache)/(p->szPage+p->szExtra)); |
| 53150 | 53334 | if( n>1000000000 ) n = 1000000000; |
| @@ -53628,11 +53812,11 @@ | ||
| 53628 | 53812 | } |
| 53629 | 53813 | return result.pDirty; |
| 53630 | 53814 | } |
| 53631 | 53815 | |
| 53632 | 53816 | /* |
| 53633 | -** Sort the list of pages in accending order by pgno. Pages are | |
| 53817 | +** Sort the list of pages in ascending order by pgno. Pages are | |
| 53634 | 53818 | ** connected by pDirty pointers. The pDirtyPrev pointers are |
| 53635 | 53819 | ** corrupted by this sort. |
| 53636 | 53820 | ** |
| 53637 | 53821 | ** Since there cannot be more than 2^31 distinct pages in a database, |
| 53638 | 53822 | ** there cannot be more than 31 buckets required by the merge sorter. |
| @@ -53868,11 +54052,11 @@ | ||
| 53868 | 54052 | ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N). |
| 53869 | 54053 | ** |
| 53870 | 54054 | ** If N is positive, then N pages worth of memory are allocated using a single |
| 53871 | 54055 | ** sqlite3Malloc() call and that memory is used for the first N pages allocated. |
| 53872 | 54056 | ** Or if N is negative, then -1024*N bytes of memory are allocated and used |
| 53873 | -** for as many pages as can be accomodated. | |
| 54057 | +** for as many pages as can be accommodated. | |
| 53874 | 54058 | ** |
| 53875 | 54059 | ** Only one of (2) or (3) can be used. Once the memory available to (2) or |
| 53876 | 54060 | ** (3) is exhausted, subsequent allocations fail over to the general-purpose |
| 53877 | 54061 | ** memory allocator (1). |
| 53878 | 54062 | ** |
| @@ -53902,11 +54086,11 @@ | ||
| 53902 | 54086 | ** but causes a 2-byte gap in the structure for most architectures (since |
| 53903 | 54087 | ** pointers must be either 4 or 8-byte aligned). As this structure is located |
| 53904 | 54088 | ** in memory directly after the associated page data, if the database is |
| 53905 | 54089 | ** corrupt, code at the b-tree layer may overread the page buffer and |
| 53906 | 54090 | ** read part of this structure before the corruption is detected. This |
| 53907 | -** can cause a valgrind error if the unitialized gap is accessed. Using u16 | |
| 54091 | +** can cause a valgrind error if the uninitialized gap is accessed. Using u16 | |
| 53908 | 54092 | ** ensures there is no such gap, and therefore no bytes of uninitialized |
| 53909 | 54093 | ** memory in the structure. |
| 53910 | 54094 | ** |
| 53911 | 54095 | ** The pLruNext and pLruPrev pointers form a double-linked circular list |
| 53912 | 54096 | ** of all pages that are unpinned. The PGroup.lru element (which should be |
| @@ -55122,11 +55306,11 @@ | ||
| 55122 | 55306 | ** until DESTROY. |
| 55123 | 55307 | ** |
| 55124 | 55308 | ** The TEST primitive includes a "batch" number. The TEST primitive |
| 55125 | 55309 | ** will only see elements that were inserted before the last change |
| 55126 | 55310 | ** in the batch number. In other words, if an INSERT occurs between |
| 55127 | -** two TESTs where the TESTs have the same batch nubmer, then the | |
| 55311 | +** two TESTs where the TESTs have the same batch number, then the | |
| 55128 | 55312 | ** value added by the INSERT will not be visible to the second TEST. |
| 55129 | 55313 | ** The initial batch number is zero, so if the very first TEST contains |
| 55130 | 55314 | ** a non-zero batch number, it will see all prior INSERTs. |
| 55131 | 55315 | ** |
| 55132 | 55316 | ** No INSERTs may occurs after a SMALLEST. An assertion will fail if |
| @@ -56045,11 +56229,11 @@ | ||
| 56045 | 56229 | ** Once it has entered the ERROR state, any attempt to use the pager |
| 56046 | 56230 | ** to read or write data returns an error. Eventually, once all |
| 56047 | 56231 | ** outstanding transactions have been abandoned, the pager is able to |
| 56048 | 56232 | ** transition back to OPEN state, discarding the contents of the |
| 56049 | 56233 | ** page-cache and any other in-memory state at the same time. Everything |
| 56050 | -** is reloaded from disk (and, if necessary, hot-journal rollback peformed) | |
| 56234 | +** is reloaded from disk (and, if necessary, hot-journal rollback performed) | |
| 56051 | 56235 | ** when a read-transaction is next opened on the pager (transitioning |
| 56052 | 56236 | ** the pager into READER state). At that point the system has recovered |
| 56053 | 56237 | ** from the error. |
| 56054 | 56238 | ** |
| 56055 | 56239 | ** Specifically, the pager jumps into the ERROR state if: |
| @@ -57418,11 +57602,11 @@ | ||
| 57418 | 57602 | ** + N bytes: super-journal filename in utf-8. |
| 57419 | 57603 | ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). |
| 57420 | 57604 | ** + 4 bytes: super-journal name checksum. |
| 57421 | 57605 | ** + 8 bytes: aJournalMagic[]. |
| 57422 | 57606 | ** |
| 57423 | -** The super-journal page checksum is the sum of the bytes in thesuper-journal | |
| 57607 | +** The super-journal page checksum is the sum of the bytes in the super-journal | |
| 57424 | 57608 | ** name, where each byte is interpreted as a signed 8-bit integer. |
| 57425 | 57609 | ** |
| 57426 | 57610 | ** If zSuper is a NULL pointer (occurs for a single database transaction), |
| 57427 | 57611 | ** this call is a no-op. |
| 57428 | 57612 | */ |
| @@ -57471,11 +57655,11 @@ | ||
| 57471 | 57655 | ){ |
| 57472 | 57656 | return rc; |
| 57473 | 57657 | } |
| 57474 | 57658 | pPager->journalOff += (nSuper+20); |
| 57475 | 57659 | |
| 57476 | - /* If the pager is in peristent-journal mode, then the physical | |
| 57660 | + /* If the pager is in persistent-journal mode, then the physical | |
| 57477 | 57661 | ** journal-file may extend past the end of the super-journal name |
| 57478 | 57662 | ** and 8 bytes of magic data just written to the file. This is |
| 57479 | 57663 | ** dangerous because the code to rollback a hot-journal file |
| 57480 | 57664 | ** will not be able to find the super-journal name to determine |
| 57481 | 57665 | ** whether or not the journal is hot. |
| @@ -57641,11 +57825,11 @@ | ||
| 57641 | 57825 | pPager->setSuper = 0; |
| 57642 | 57826 | } |
| 57643 | 57827 | |
| 57644 | 57828 | /* |
| 57645 | 57829 | ** This function is called whenever an IOERR or FULL error that requires |
| 57646 | -** the pager to transition into the ERROR state may ahve occurred. | |
| 57830 | +** the pager to transition into the ERROR state may have occurred. | |
| 57647 | 57831 | ** The first argument is a pointer to the pager structure, the second |
| 57648 | 57832 | ** the error-code about to be returned by a pager API function. The |
| 57649 | 57833 | ** value returned is a copy of the second argument to this function. |
| 57650 | 57834 | ** |
| 57651 | 57835 | ** If the second argument is SQLITE_FULL, SQLITE_IOERR or one of the |
| @@ -57916,11 +58100,11 @@ | ||
| 57916 | 58100 | pager_unlock(pPager); |
| 57917 | 58101 | } |
| 57918 | 58102 | |
| 57919 | 58103 | /* |
| 57920 | 58104 | ** Parameter aData must point to a buffer of pPager->pageSize bytes |
| 57921 | -** of data. Compute and return a checksum based ont the contents of the | |
| 58105 | +** of data. Compute and return a checksum based on the contents of the | |
| 57922 | 58106 | ** page of data and the current value of pPager->cksumInit. |
| 57923 | 58107 | ** |
| 57924 | 58108 | ** This is not a real checksum. It is really just the sum of the |
| 57925 | 58109 | ** random initial value (pPager->cksumInit) and every 200th byte |
| 57926 | 58110 | ** of the page data, starting with byte offset (pPager->pageSize%200). |
| @@ -58882,11 +59066,11 @@ | ||
| 58882 | 59066 | PgHdr *p; /* For looping over pages */ |
| 58883 | 59067 | |
| 58884 | 59068 | assert( pPager->pWal ); |
| 58885 | 59069 | assert( pList ); |
| 58886 | 59070 | #ifdef SQLITE_DEBUG |
| 58887 | - /* Verify that the page list is in accending order */ | |
| 59071 | + /* Verify that the page list is in ascending order */ | |
| 58888 | 59072 | for(p=pList; p && p->pDirty; p=p->pDirty){ |
| 58889 | 59073 | assert( p->pgno < p->pDirty->pgno ); |
| 58890 | 59074 | } |
| 58891 | 59075 | #endif |
| 58892 | 59076 | |
| @@ -59013,11 +59197,11 @@ | ||
| 59013 | 59197 | } |
| 59014 | 59198 | |
| 59015 | 59199 | #ifndef SQLITE_OMIT_WAL |
| 59016 | 59200 | /* |
| 59017 | 59201 | ** Check if the *-wal file that corresponds to the database opened by pPager |
| 59018 | -** exists if the database is not empy, or verify that the *-wal file does | |
| 59202 | +** exists if the database is not empty, or verify that the *-wal file does | |
| 59019 | 59203 | ** not exist (by deleting it) if the database file is empty. |
| 59020 | 59204 | ** |
| 59021 | 59205 | ** If the database is not empty and the *-wal file exists, open the pager |
| 59022 | 59206 | ** in WAL mode. If the database is empty or if no *-wal file exists and |
| 59023 | 59207 | ** if no error occurs, make sure Pager.journalMode is not set to |
| @@ -60765,11 +60949,11 @@ | ||
| 60765 | 60949 | return SQLITE_OK; |
| 60766 | 60950 | } |
| 60767 | 60951 | |
| 60768 | 60952 | /* |
| 60769 | 60953 | ** Return the sqlite3_file for the main database given the name |
| 60770 | -** of the corresonding WAL or Journal name as passed into | |
| 60954 | +** of the corresponding WAL or Journal name as passed into | |
| 60771 | 60955 | ** xOpen. |
| 60772 | 60956 | */ |
| 60773 | 60957 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char *zName){ |
| 60774 | 60958 | Pager *pPager; |
| 60775 | 60959 | while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){ |
| @@ -63050,11 +63234,11 @@ | ||
| 63050 | 63234 | |
| 63051 | 63235 | /* Change the journal mode. */ |
| 63052 | 63236 | assert( pPager->eState!=PAGER_ERROR ); |
| 63053 | 63237 | pPager->journalMode = (u8)eMode; |
| 63054 | 63238 | |
| 63055 | - /* When transistioning from TRUNCATE or PERSIST to any other journal | |
| 63239 | + /* When transitioning from TRUNCATE or PERSIST to any other journal | |
| 63056 | 63240 | ** mode except WAL, unless the pager is in locking_mode=exclusive mode, |
| 63057 | 63241 | ** delete the journal file. |
| 63058 | 63242 | */ |
| 63059 | 63243 | assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 ); |
| 63060 | 63244 | assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 ); |
| @@ -63768,11 +63952,11 @@ | ||
| 63768 | 63952 | ** of available reader locks and should be at least 3. The default |
| 63769 | 63953 | ** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5. |
| 63770 | 63954 | ** |
| 63771 | 63955 | ** Technically, the various VFSes are free to implement these locks however |
| 63772 | 63956 | ** they see fit. However, compatibility is encouraged so that VFSes can |
| 63773 | -** interoperate. The standard implemention used on both unix and windows | |
| 63957 | +** interoperate. The standard implementation used on both unix and windows | |
| 63774 | 63958 | ** is for the index number to indicate a byte offset into the |
| 63775 | 63959 | ** WalCkptInfo.aLock[] array in the wal-index header. In other words, all |
| 63776 | 63960 | ** locks are on the shm file. The WALINDEX_LOCK_OFFSET constant (which |
| 63777 | 63961 | ** should be 120) is the location in the shm file for the first locking |
| 63778 | 63962 | ** byte. |
| @@ -63844,11 +64028,11 @@ | ||
| 63844 | 64028 | ** There is one entry in aReadMark[] for each reader lock. If a reader |
| 63845 | 64029 | ** holds read-lock K, then the value in aReadMark[K] is no greater than |
| 63846 | 64030 | ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff) |
| 63847 | 64031 | ** for any aReadMark[] means that entry is unused. aReadMark[0] is |
| 63848 | 64032 | ** a special case; its value is never used and it exists as a place-holder |
| 63849 | -** to avoid having to offset aReadMark[] indexs by one. Readers holding | |
| 64033 | +** to avoid having to offset aReadMark[] indexes by one. Readers holding | |
| 63850 | 64034 | ** WAL_READ_LOCK(0) always ignore the entire WAL and read all content |
| 63851 | 64035 | ** directly from the database. |
| 63852 | 64036 | ** |
| 63853 | 64037 | ** The value of aReadMark[K] may only be changed by a thread that |
| 63854 | 64038 | ** is holding an exclusive lock on WAL_READ_LOCK(K). Thus, the value of |
| @@ -64374,19 +64558,19 @@ | ||
| 64374 | 64558 | */ |
| 64375 | 64559 | if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){ |
| 64376 | 64560 | return 0; |
| 64377 | 64561 | } |
| 64378 | 64562 | |
| 64379 | - /* A frame is only valid if the page number is creater than zero. | |
| 64563 | + /* A frame is only valid if the page number is greater than zero. | |
| 64380 | 64564 | */ |
| 64381 | 64565 | pgno = sqlite3Get4byte(&aFrame[0]); |
| 64382 | 64566 | if( pgno==0 ){ |
| 64383 | 64567 | return 0; |
| 64384 | 64568 | } |
| 64385 | 64569 | |
| 64386 | 64570 | /* A frame is only valid if a checksum of the WAL header, |
| 64387 | - ** all prior frams, the first 16 bytes of this frame-header, | |
| 64571 | + ** all prior frames, the first 16 bytes of this frame-header, | |
| 64388 | 64572 | ** and the frame-data matches the checksum in the last 8 |
| 64389 | 64573 | ** bytes of this frame-header. |
| 64390 | 64574 | */ |
| 64391 | 64575 | nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN); |
| 64392 | 64576 | walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum); |
| @@ -65076,11 +65260,11 @@ | ||
| 65076 | 65260 | } |
| 65077 | 65261 | return rc; |
| 65078 | 65262 | } |
| 65079 | 65263 | |
| 65080 | 65264 | /* |
| 65081 | -** Change the size to which the WAL file is trucated on each reset. | |
| 65265 | +** Change the size to which the WAL file is truncated on each reset. | |
| 65082 | 65266 | */ |
| 65083 | 65267 | SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){ |
| 65084 | 65268 | if( pWal ) pWal->mxWalSize = iLimit; |
| 65085 | 65269 | } |
| 65086 | 65270 | |
| @@ -65775,11 +65959,11 @@ | ||
| 65775 | 65959 | sqlite3OsFileControlHint( |
| 65776 | 65960 | pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist |
| 65777 | 65961 | ); |
| 65778 | 65962 | if( bPersist!=1 ){ |
| 65779 | 65963 | /* Try to delete the WAL file if the checkpoint completed and |
| 65780 | - ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal | |
| 65964 | + ** fsynced (rc==SQLITE_OK) and if we are not in persistent-wal | |
| 65781 | 65965 | ** mode (!bPersist) */ |
| 65782 | 65966 | isDelete = 1; |
| 65783 | 65967 | }else if( pWal->mxWalSize>=0 ){ |
| 65784 | 65968 | /* Try to truncate the WAL file to zero bytes if the checkpoint |
| 65785 | 65969 | ** completed and fsynced (rc==SQLITE_OK) and we are in persistent |
| @@ -65842,11 +66026,11 @@ | ||
| 65842 | 66026 | ** Memory barriers are used to prevent the compiler or the hardware from |
| 65843 | 66027 | ** reordering the reads and writes. TSAN and similar tools can sometimes |
| 65844 | 66028 | ** give false-positive warnings about these accesses because the tools do not |
| 65845 | 66029 | ** account for the double-read and the memory barrier. The use of mutexes |
| 65846 | 66030 | ** here would be problematic as the memory being accessed is potentially |
| 65847 | - ** shared among multiple processes and not all mutex implementions work | |
| 66031 | + ** shared among multiple processes and not all mutex implementations work | |
| 65848 | 66032 | ** reliably in that environment. |
| 65849 | 66033 | */ |
| 65850 | 66034 | aHdr = walIndexHdr(pWal); |
| 65851 | 66035 | memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */ |
| 65852 | 66036 | walShmBarrier(pWal); |
| @@ -67947,11 +68131,11 @@ | ||
| 67947 | 68131 | /* |
| 67948 | 68132 | ** An instance of this object stores information about each a single database |
| 67949 | 68133 | ** page that has been loaded into memory. The information in this object |
| 67950 | 68134 | ** is derived from the raw on-disk page content. |
| 67951 | 68135 | ** |
| 67952 | -** As each database page is loaded into memory, the pager allocats an | |
| 68136 | +** As each database page is loaded into memory, the pager allocates an | |
| 67953 | 68137 | ** instance of this object and zeros the first 8 bytes. (This is the |
| 67954 | 68138 | ** "extra" information associated with each page of the pager.) |
| 67955 | 68139 | ** |
| 67956 | 68140 | ** Access to all fields of this structure is controlled by the mutex |
| 67957 | 68141 | ** stored in MemPage.pBt->mutex. |
| @@ -68403,11 +68587,11 @@ | ||
| 68403 | 68587 | #define get4byte sqlite3Get4byte |
| 68404 | 68588 | #define put4byte sqlite3Put4byte |
| 68405 | 68589 | |
| 68406 | 68590 | /* |
| 68407 | 68591 | ** get2byteAligned(), unlike get2byte(), requires that its argument point to a |
| 68408 | -** two-byte aligned address. get2bytea() is only used for accessing the | |
| 68592 | +** two-byte aligned address. get2byteAligned() is only used for accessing the | |
| 68409 | 68593 | ** cell addresses in a btree header. |
| 68410 | 68594 | */ |
| 68411 | 68595 | #if SQLITE_BYTEORDER==4321 |
| 68412 | 68596 | # define get2byteAligned(x) (*(u16*)(x)) |
| 68413 | 68597 | #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000 |
| @@ -68580,11 +68764,11 @@ | ||
| 68580 | 68764 | ** against all schemas and we do not want those schemas being |
| 68581 | 68765 | ** reset out from under us. |
| 68582 | 68766 | ** |
| 68583 | 68767 | ** There is a corresponding leave-all procedures. |
| 68584 | 68768 | ** |
| 68585 | -** Enter the mutexes in accending order by BtShared pointer address | |
| 68769 | +** Enter the mutexes in ascending order by BtShared pointer address | |
| 68586 | 68770 | ** to avoid the possibility of deadlock when two threads with |
| 68587 | 68771 | ** two or more btrees in common both try to lock all their btrees |
| 68588 | 68772 | ** at the same instant. |
| 68589 | 68773 | */ |
| 68590 | 68774 | static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){ |
| @@ -68712,10 +68896,11 @@ | ||
| 68712 | 68896 | |
| 68713 | 68897 | #endif /* ifndef SQLITE_OMIT_SHARED_CACHE */ |
| 68714 | 68898 | |
| 68715 | 68899 | /************** End of btmutex.c *********************************************/ |
| 68716 | 68900 | /************** Begin file btree.c *******************************************/ |
| 68901 | + | |
| 68717 | 68902 | /* |
| 68718 | 68903 | ** 2004 April 6 |
| 68719 | 68904 | ** |
| 68720 | 68905 | ** The author disclaims copyright to this source code. In place of |
| 68721 | 68906 | ** a legal notice, here is a blessing: |
| @@ -70348,11 +70533,11 @@ | ||
| 70348 | 70533 | cbrk = usableSize; |
| 70349 | 70534 | iCellLast = usableSize - 4; |
| 70350 | 70535 | iCellStart = get2byte(&data[hdr+5]); |
| 70351 | 70536 | if( nCell>0 ){ |
| 70352 | 70537 | temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 70353 | - memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart); | |
| 70538 | + memcpy(temp, data, usableSize); | |
| 70354 | 70539 | src = temp; |
| 70355 | 70540 | for(i=0; i<nCell; i++){ |
| 70356 | 70541 | u8 *pAddr; /* The i-th cell pointer */ |
| 70357 | 70542 | pAddr = &data[cellOffset + i*2]; |
| 70358 | 70543 | pc = get2byte(pAddr); |
| @@ -70572,11 +70757,11 @@ | ||
| 70572 | 70757 | ** |
| 70573 | 70758 | ** Adjacent freeblocks are coalesced. |
| 70574 | 70759 | ** |
| 70575 | 70760 | ** Even though the freeblock list was checked by btreeComputeFreeSpace(), |
| 70576 | 70761 | ** that routine will not detect overlap between cells or freeblocks. Nor |
| 70577 | -** does it detect cells or freeblocks that encrouch into the reserved bytes | |
| 70762 | +** does it detect cells or freeblocks that encroach into the reserved bytes | |
| 70578 | 70763 | ** at the end of the page. So do additional corruption checks inside this |
| 70579 | 70764 | ** routine and return SQLITE_CORRUPT if any problems are found. |
| 70580 | 70765 | */ |
| 70581 | 70766 | static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ |
| 70582 | 70767 | u16 iPtr; /* Address of ptr to next freeblock */ |
| @@ -71175,11 +71360,11 @@ | ||
| 71175 | 71360 | /* pPage might not be a btree page; it might be an overflow page |
| 71176 | 71361 | ** or ptrmap page or a free page. In those cases, the following |
| 71177 | 71362 | ** call to btreeInitPage() will likely return SQLITE_CORRUPT. |
| 71178 | 71363 | ** But no harm is done by this. And it is very important that |
| 71179 | 71364 | ** btreeInitPage() be called on every btree page so we make |
| 71180 | - ** the call for every page that comes in for re-initing. */ | |
| 71365 | + ** the call for every page that comes in for re-initializing. */ | |
| 71181 | 71366 | btreeInitPage(pPage); |
| 71182 | 71367 | } |
| 71183 | 71368 | } |
| 71184 | 71369 | } |
| 71185 | 71370 | |
| @@ -71570,11 +71755,11 @@ | ||
| 71570 | 71755 | ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes |
| 71571 | 71756 | ** by the various routines that manipulate binary cells. Which |
| 71572 | 71757 | ** can mean that fillInCell() only initializes the first 2 or 3 |
| 71573 | 71758 | ** bytes of pTmpSpace, but that the first 4 bytes are copied from |
| 71574 | 71759 | ** it into a database page. This is not actually a problem, but it |
| 71575 | - ** does cause a valgrind error when the 1 or 2 bytes of unitialized | |
| 71760 | + ** does cause a valgrind error when the 1 or 2 bytes of uninitialized | |
| 71576 | 71761 | ** data is passed to system call write(). So to avoid this error, |
| 71577 | 71762 | ** zero the first 4 bytes of temp space here. |
| 71578 | 71763 | ** |
| 71579 | 71764 | ** Also: Provide four bytes of initialized space before the |
| 71580 | 71765 | ** beginning of pTmpSpace as an area available to prepend the |
| @@ -71805,11 +71990,11 @@ | ||
| 71805 | 71990 | return n; |
| 71806 | 71991 | } |
| 71807 | 71992 | |
| 71808 | 71993 | /* |
| 71809 | 71994 | ** Return the number of bytes of space at the end of every page that |
| 71810 | -** are intentually left unused. This is the "reserved" space that is | |
| 71995 | +** are intentionally left unused. This is the "reserved" space that is | |
| 71811 | 71996 | ** sometimes used by extensions. |
| 71812 | 71997 | ** |
| 71813 | 71998 | ** The value returned is the larger of the current reserve size and |
| 71814 | 71999 | ** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES. |
| 71815 | 72000 | ** The amount of reserve can only grow - never shrink. |
| @@ -72052,11 +72237,10 @@ | ||
| 72052 | 72237 | || pageSize>SQLITE_MAX_PAGE_SIZE |
| 72053 | 72238 | || pageSize<=256 |
| 72054 | 72239 | ){ |
| 72055 | 72240 | goto page1_init_failed; |
| 72056 | 72241 | } |
| 72057 | - pBt->btsFlags |= BTS_PAGESIZE_FIXED; | |
| 72058 | 72242 | assert( (pageSize & 7)==0 ); |
| 72059 | 72243 | /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte |
| 72060 | 72244 | ** integer at offset 20 is the number of bytes of space at the end of |
| 72061 | 72245 | ** each page to reserve for extensions. |
| 72062 | 72246 | ** |
| @@ -72072,10 +72256,11 @@ | ||
| 72072 | 72256 | ** again with the correct page-size. |
| 72073 | 72257 | */ |
| 72074 | 72258 | releasePageOne(pPage1); |
| 72075 | 72259 | pBt->usableSize = usableSize; |
| 72076 | 72260 | pBt->pageSize = pageSize; |
| 72261 | + pBt->btsFlags |= BTS_PAGESIZE_FIXED; | |
| 72077 | 72262 | freeTempSpace(pBt); |
| 72078 | 72263 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, |
| 72079 | 72264 | pageSize-usableSize); |
| 72080 | 72265 | return rc; |
| 72081 | 72266 | } |
| @@ -72091,10 +72276,11 @@ | ||
| 72091 | 72276 | ** be less than 480. In other words, if the page size is 512, then the |
| 72092 | 72277 | ** reserved space size cannot exceed 32. */ |
| 72093 | 72278 | if( usableSize<480 ){ |
| 72094 | 72279 | goto page1_init_failed; |
| 72095 | 72280 | } |
| 72281 | + pBt->btsFlags |= BTS_PAGESIZE_FIXED; | |
| 72096 | 72282 | pBt->pageSize = pageSize; |
| 72097 | 72283 | pBt->usableSize = usableSize; |
| 72098 | 72284 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 72099 | 72285 | pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0); |
| 72100 | 72286 | pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0); |
| @@ -72269,11 +72455,15 @@ | ||
| 72269 | 72455 | ** One or the other of the two processes must give way or there can be |
| 72270 | 72456 | ** no progress. By returning SQLITE_BUSY and not invoking the busy callback |
| 72271 | 72457 | ** when A already has a read lock, we encourage A to give up and let B |
| 72272 | 72458 | ** proceed. |
| 72273 | 72459 | */ |
| 72274 | -SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ | |
| 72460 | +static SQLITE_NOINLINE int btreeBeginTrans( | |
| 72461 | + Btree *p, /* The btree in which to start the transaction */ | |
| 72462 | + int wrflag, /* True to start a write transaction */ | |
| 72463 | + int *pSchemaVersion /* Put schema version number here, if not NULL */ | |
| 72464 | +){ | |
| 72275 | 72465 | BtShared *pBt = p->pBt; |
| 72276 | 72466 | Pager *pPager = pBt->pPager; |
| 72277 | 72467 | int rc = SQLITE_OK; |
| 72278 | 72468 | |
| 72279 | 72469 | sqlite3BtreeEnter(p); |
| @@ -72440,10 +72630,32 @@ | ||
| 72440 | 72630 | } |
| 72441 | 72631 | |
| 72442 | 72632 | btreeIntegrity(p); |
| 72443 | 72633 | sqlite3BtreeLeave(p); |
| 72444 | 72634 | return rc; |
| 72635 | +} | |
| 72636 | +SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ | |
| 72637 | + BtShared *pBt; | |
| 72638 | + if( p->sharable | |
| 72639 | + || p->inTrans==TRANS_NONE | |
| 72640 | + || (p->inTrans==TRANS_READ && wrflag!=0) | |
| 72641 | + ){ | |
| 72642 | + return btreeBeginTrans(p,wrflag,pSchemaVersion); | |
| 72643 | + } | |
| 72644 | + pBt = p->pBt; | |
| 72645 | + if( pSchemaVersion ){ | |
| 72646 | + *pSchemaVersion = get4byte(&pBt->pPage1->aData[40]); | |
| 72647 | + } | |
| 72648 | + if( wrflag ){ | |
| 72649 | + /* This call makes sure that the pager has the correct number of | |
| 72650 | + ** open savepoints. If the second parameter is greater than 0 and | |
| 72651 | + ** the sub-journal is not already open, then it will be opened here. | |
| 72652 | + */ | |
| 72653 | + return sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint); | |
| 72654 | + }else{ | |
| 72655 | + return SQLITE_OK; | |
| 72656 | + } | |
| 72445 | 72657 | } |
| 72446 | 72658 | |
| 72447 | 72659 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 72448 | 72660 | |
| 72449 | 72661 | /* |
| @@ -73574,11 +73786,11 @@ | ||
| 73574 | 73786 | ** |
| 73575 | 73787 | ** This is an optimization. Everything will still work if this |
| 73576 | 73788 | ** routine always returns 2147483647 (which is the largest record |
| 73577 | 73789 | ** that SQLite can handle) or more. But returning a smaller value might |
| 73578 | 73790 | ** prevent large memory allocations when trying to interpret a |
| 73579 | -** corrupt datrabase. | |
| 73791 | +** corrupt database. | |
| 73580 | 73792 | ** |
| 73581 | 73793 | ** The current implementation merely returns the size of the underlying |
| 73582 | 73794 | ** database file. |
| 73583 | 73795 | */ |
| 73584 | 73796 | SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){ |
| @@ -74374,11 +74586,11 @@ | ||
| 74374 | 74586 | return SQLITE_OK; |
| 74375 | 74587 | } |
| 74376 | 74588 | /* If the requested key is one more than the previous key, then |
| 74377 | 74589 | ** try to get there using sqlite3BtreeNext() rather than a full |
| 74378 | 74590 | ** binary search. This is an optimization only. The correct answer |
| 74379 | - ** is still obtained without this case, only a little more slowely */ | |
| 74591 | + ** is still obtained without this case, only a little more slowly. */ | |
| 74380 | 74592 | if( pCur->info.nKey+1==intKey ){ |
| 74381 | 74593 | *pRes = 0; |
| 74382 | 74594 | rc = sqlite3BtreeNext(pCur, 0); |
| 74383 | 74595 | if( rc==SQLITE_OK ){ |
| 74384 | 74596 | getCellInfo(pCur); |
| @@ -75557,11 +75769,11 @@ | ||
| 75557 | 75769 | return SQLITE_OK; |
| 75558 | 75770 | } |
| 75559 | 75771 | |
| 75560 | 75772 | /* Call xParseCell to compute the size of a cell. If the cell contains |
| 75561 | 75773 | ** overflow, then invoke cellClearOverflow to clear out that overflow. |
| 75562 | -** STore the result code (SQLITE_OK or some error code) in rc. | |
| 75774 | +** Store the result code (SQLITE_OK or some error code) in rc. | |
| 75563 | 75775 | ** |
| 75564 | 75776 | ** Implemented as macro to force inlining for performance. |
| 75565 | 75777 | */ |
| 75566 | 75778 | #define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \ |
| 75567 | 75779 | pPage->xParseCell(pPage, pCell, &sInfo); \ |
| @@ -76236,11 +76448,11 @@ | ||
| 76236 | 76448 | ** before returning. |
| 76237 | 76449 | ** |
| 76238 | 76450 | ** Finally, argument pBegin points to the byte immediately following the |
| 76239 | 76451 | ** end of the space required by this page for the cell-pointer area (for |
| 76240 | 76452 | ** all cells - not just those inserted by the current call). If the content |
| 76241 | -** area must be extended to before this point in order to accomodate all | |
| 76453 | +** area must be extended to before this point in order to accommodate all | |
| 76242 | 76454 | ** cells in apCell[], then the cells do not fit and non-zero is returned. |
| 76243 | 76455 | */ |
| 76244 | 76456 | static int pageInsertArray( |
| 76245 | 76457 | MemPage *pPg, /* Page to add cells to */ |
| 76246 | 76458 | u8 *pBegin, /* End of cell-pointer array */ |
| @@ -76551,11 +76763,11 @@ | ||
| 76551 | 76763 | |
| 76552 | 76764 | /* If this is an auto-vacuum database, update the pointer map |
| 76553 | 76765 | ** with entries for the new page, and any pointer from the |
| 76554 | 76766 | ** cell on the page to an overflow page. If either of these |
| 76555 | 76767 | ** operations fails, the return code is set, but the contents |
| 76556 | - ** of the parent page are still manipulated by thh code below. | |
| 76768 | + ** of the parent page are still manipulated by the code below. | |
| 76557 | 76769 | ** That is Ok, at this point the parent page is guaranteed to |
| 76558 | 76770 | ** be marked as dirty. Returning an error code will cause a |
| 76559 | 76771 | ** rollback, undoing any changes made to the parent page. |
| 76560 | 76772 | */ |
| 76561 | 76773 | if( ISAUTOVACUUM(pBt) ){ |
| @@ -77141,11 +77353,11 @@ | ||
| 77141 | 77353 | rc = SQLITE_CORRUPT_BKPT; |
| 77142 | 77354 | goto balance_cleanup; |
| 77143 | 77355 | } |
| 77144 | 77356 | } |
| 77145 | 77357 | |
| 77146 | - /* Sanity check: For a non-corrupt database file one of the follwing | |
| 77358 | + /* Sanity check: For a non-corrupt database file one of the following | |
| 77147 | 77359 | ** must be true: |
| 77148 | 77360 | ** (1) We found one or more cells (cntNew[0])>0), or |
| 77149 | 77361 | ** (2) pPage is a virtual root page. A virtual root page is when |
| 77150 | 77362 | ** the real root page is page 1 and we are the only child of |
| 77151 | 77363 | ** that page. |
| @@ -77758,11 +77970,11 @@ | ||
| 77758 | 77970 | int iOffset, /* Offset of first byte to write */ |
| 77759 | 77971 | int iAmt /* Number of bytes to be written */ |
| 77760 | 77972 | ){ |
| 77761 | 77973 | int nData = pX->nData - iOffset; |
| 77762 | 77974 | if( nData<=0 ){ |
| 77763 | - /* Overwritting with zeros */ | |
| 77975 | + /* Overwriting with zeros */ | |
| 77764 | 77976 | int i; |
| 77765 | 77977 | for(i=0; i<iAmt && pDest[i]==0; i++){} |
| 77766 | 77978 | if( i<iAmt ){ |
| 77767 | 77979 | int rc = sqlite3PagerWrite(pPage->pDbPage); |
| 77768 | 77980 | if( rc ) return rc; |
| @@ -77794,11 +78006,11 @@ | ||
| 77794 | 78006 | ** Overwrite the cell that cursor pCur is pointing to with fresh content |
| 77795 | 78007 | ** contained in pX. In this variant, pCur is pointing to an overflow |
| 77796 | 78008 | ** cell. |
| 77797 | 78009 | */ |
| 77798 | 78010 | static SQLITE_NOINLINE int btreeOverwriteOverflowCell( |
| 77799 | - BtCursor *pCur, /* Cursor pointing to cell to ovewrite */ | |
| 78011 | + BtCursor *pCur, /* Cursor pointing to cell to overwrite */ | |
| 77800 | 78012 | const BtreePayload *pX /* Content to write into the cell */ |
| 77801 | 78013 | ){ |
| 77802 | 78014 | int iOffset; /* Next byte of pX->pData to write */ |
| 77803 | 78015 | int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */ |
| 77804 | 78016 | int rc; /* Return code */ |
| @@ -78541,11 +78753,11 @@ | ||
| 78541 | 78753 | static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ |
| 78542 | 78754 | BtShared *pBt = p->pBt; |
| 78543 | 78755 | MemPage *pRoot; |
| 78544 | 78756 | Pgno pgnoRoot; |
| 78545 | 78757 | int rc; |
| 78546 | - int ptfFlags; /* Page-type flage for the root page of new table */ | |
| 78758 | + int ptfFlags; /* Page-type flags for the root page of new table */ | |
| 78547 | 78759 | |
| 78548 | 78760 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 78549 | 78761 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 78550 | 78762 | assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 78551 | 78763 | |
| @@ -79376,11 +79588,11 @@ | ||
| 79376 | 79588 | pBt = pCheck->pBt; |
| 79377 | 79589 | usableSize = pBt->usableSize; |
| 79378 | 79590 | if( iPage==0 ) return 0; |
| 79379 | 79591 | if( checkRef(pCheck, iPage) ) return 0; |
| 79380 | 79592 | pCheck->zPfx = "Tree %u page %u: "; |
| 79381 | - pCheck->v0 = pCheck->v1 = iPage; | |
| 79593 | + pCheck->v1 = iPage; | |
| 79382 | 79594 | if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){ |
| 79383 | 79595 | checkAppendMsg(pCheck, |
| 79384 | 79596 | "unable to get the page. error code=%d", rc); |
| 79385 | 79597 | goto end_of_check; |
| 79386 | 79598 | } |
| @@ -79713,10 +79925,11 @@ | ||
| 79713 | 79925 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 79714 | 79926 | if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){ |
| 79715 | 79927 | checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0); |
| 79716 | 79928 | } |
| 79717 | 79929 | #endif |
| 79930 | + sCheck.v0 = aRoot[i]; | |
| 79718 | 79931 | checkTreePage(&sCheck, aRoot[i], ¬Used, LARGEST_INT64); |
| 79719 | 79932 | } |
| 79720 | 79933 | pBt->db->flags = savedDbFlags; |
| 79721 | 79934 | |
| 79722 | 79935 | /* Make sure every page in the file is referenced |
| @@ -82256,10 +82469,11 @@ | ||
| 82256 | 82469 | if( pRec==0 ) return 0; |
| 82257 | 82470 | p->ppRec[0] = pRec; |
| 82258 | 82471 | } |
| 82259 | 82472 | |
| 82260 | 82473 | pRec->nField = p->iVal+1; |
| 82474 | + sqlite3VdbeMemSetNull(&pRec->aMem[p->iVal]); | |
| 82261 | 82475 | return &pRec->aMem[p->iVal]; |
| 82262 | 82476 | } |
| 82263 | 82477 | #else |
| 82264 | 82478 | UNUSED_PARAMETER(p); |
| 82265 | 82479 | #endif /* defined(SQLITE_ENABLE_STAT4) */ |
| @@ -83652,11 +83866,11 @@ | ||
| 83652 | 83866 | assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */ |
| 83653 | 83867 | p->readOnly = 1; |
| 83654 | 83868 | p->bIsReader = 0; |
| 83655 | 83869 | pOp = &p->aOp[p->nOp-1]; |
| 83656 | 83870 | assert( p->aOp[0].opcode==OP_Init ); |
| 83657 | - while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){ | |
| 83871 | + while( 1 /* Loop terminates when it reaches the OP_Init opcode */ ){ | |
| 83658 | 83872 | /* Only JUMP opcodes and the short list of special opcodes in the switch |
| 83659 | 83873 | ** below need to be considered. The mkopcodeh.tcl generator script groups |
| 83660 | 83874 | ** all these opcodes together near the front of the opcode list. Skip |
| 83661 | 83875 | ** any opcode that does not need processing by virtual of the fact that |
| 83662 | 83876 | ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization. |
| @@ -84106,11 +84320,11 @@ | ||
| 84106 | 84320 | } |
| 84107 | 84321 | |
| 84108 | 84322 | |
| 84109 | 84323 | /* |
| 84110 | 84324 | ** If the input FuncDef structure is ephemeral, then free it. If |
| 84111 | -** the FuncDef is not ephermal, then do nothing. | |
| 84325 | +** the FuncDef is not ephemeral, then do nothing. | |
| 84112 | 84326 | */ |
| 84113 | 84327 | static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){ |
| 84114 | 84328 | assert( db!=0 ); |
| 84115 | 84329 | if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){ |
| 84116 | 84330 | sqlite3DbNNFreeNN(db, pDef); |
| @@ -87057,10 +87271,19 @@ | ||
| 87057 | 87271 | ** sqlite3VdbeSerialTypeLen() in the common case. |
| 87058 | 87272 | */ |
| 87059 | 87273 | if( d1+(u64)serial_type1+2>(u64)nKey1 |
| 87060 | 87274 | && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)>(u64)nKey1 |
| 87061 | 87275 | ){ |
| 87276 | + if( serial_type1>=1 | |
| 87277 | + && serial_type1<=7 | |
| 87278 | + && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)<=(u64)nKey1+8 | |
| 87279 | + && CORRUPT_DB | |
| 87280 | + ){ | |
| 87281 | + return 1; /* corrupt record not detected by | |
| 87282 | + ** sqlite3VdbeRecordCompareWithSkip(). Return true | |
| 87283 | + ** to avoid firing the assert() */ | |
| 87284 | + } | |
| 87062 | 87285 | break; |
| 87063 | 87286 | } |
| 87064 | 87287 | |
| 87065 | 87288 | /* Extract the values to be compared. |
| 87066 | 87289 | */ |
| @@ -87500,11 +87723,11 @@ | ||
| 87500 | 87723 | serial_type = aKey1[idx1]; |
| 87501 | 87724 | if( serial_type>=10 ){ |
| 87502 | 87725 | /* Serial types 12 or greater are strings and blobs (greater than |
| 87503 | 87726 | ** numbers). Types 10 and 11 are currently "reserved for future |
| 87504 | 87727 | ** use", so it doesn't really matter what the results of comparing |
| 87505 | - ** them to numberic values are. */ | |
| 87728 | + ** them to numeric values are. */ | |
| 87506 | 87729 | rc = serial_type==10 ? -1 : +1; |
| 87507 | 87730 | }else if( serial_type==0 ){ |
| 87508 | 87731 | rc = -1; |
| 87509 | 87732 | }else{ |
| 87510 | 87733 | sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); |
| @@ -89129,11 +89352,11 @@ | ||
| 89129 | 89352 | |
| 89130 | 89353 | /* |
| 89131 | 89354 | ** The destructor function for a ValueList object. This needs to be |
| 89132 | 89355 | ** a separate function, unknowable to the application, to ensure that |
| 89133 | 89356 | ** calls to sqlite3_vtab_in_first()/sqlite3_vtab_in_next() that are not |
| 89134 | -** preceeded by activation of IN processing via sqlite3_vtab_int() do not | |
| 89357 | +** preceded by activation of IN processing via sqlite3_vtab_int() do not | |
| 89135 | 89358 | ** try to access a fake ValueList object inserted by a hostile extension. |
| 89136 | 89359 | */ |
| 89137 | 89360 | SQLITE_PRIVATE void sqlite3VdbeValueListFree(void *pToDelete){ |
| 89138 | 89361 | sqlite3_free(pToDelete); |
| 89139 | 89362 | } |
| @@ -89458,11 +89681,11 @@ | ||
| 89458 | 89681 | ** sqlite3_column_text() |
| 89459 | 89682 | ** sqlite3_column_text16() |
| 89460 | 89683 | ** sqlite3_column_real() |
| 89461 | 89684 | ** sqlite3_column_bytes() |
| 89462 | 89685 | ** sqlite3_column_bytes16() |
| 89463 | -** sqiite3_column_blob() | |
| 89686 | +** sqlite3_column_blob() | |
| 89464 | 89687 | */ |
| 89465 | 89688 | static void columnMallocFailure(sqlite3_stmt *pStmt) |
| 89466 | 89689 | { |
| 89467 | 89690 | /* If malloc() failed during an encoding conversion within an |
| 89468 | 89691 | ** sqlite3_column_XXX API, then set the return code of the statement to |
| @@ -89693,11 +89916,11 @@ | ||
| 89693 | 89916 | ** Routines used to attach values to wildcards in a compiled SQL statement. |
| 89694 | 89917 | */ |
| 89695 | 89918 | /* |
| 89696 | 89919 | ** Unbind the value bound to variable i in virtual machine p. This is the |
| 89697 | 89920 | ** the same as binding a NULL value to the column. If the "i" parameter is |
| 89698 | -** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK. | |
| 89921 | +** out of range, then SQLITE_RANGE is returned. Otherwise SQLITE_OK. | |
| 89699 | 89922 | ** |
| 89700 | 89923 | ** A successful evaluation of this routine acquires the mutex on p. |
| 89701 | 89924 | ** the mutex is released if any kind of error occurs. |
| 89702 | 89925 | ** |
| 89703 | 89926 | ** The error code stored in database p->db is overwritten with the return |
| @@ -91669,12 +91892,12 @@ | ||
| 91669 | 91892 | ** to the current line should be indented for EXPLAIN output. |
| 91670 | 91893 | */ |
| 91671 | 91894 | case OP_Goto: { /* jump */ |
| 91672 | 91895 | |
| 91673 | 91896 | #ifdef SQLITE_DEBUG |
| 91674 | - /* In debuggging mode, when the p5 flags is set on an OP_Goto, that | |
| 91675 | - ** means we should really jump back to the preceeding OP_ReleaseReg | |
| 91897 | + /* In debugging mode, when the p5 flags is set on an OP_Goto, that | |
| 91898 | + ** means we should really jump back to the preceding OP_ReleaseReg | |
| 91676 | 91899 | ** instruction. */ |
| 91677 | 91900 | if( pOp->p5 ){ |
| 91678 | 91901 | assert( pOp->p2 < (int)(pOp - aOp) ); |
| 91679 | 91902 | assert( pOp->p2 > 1 ); |
| 91680 | 91903 | pOp = &aOp[pOp->p2 - 2]; |
| @@ -91878,11 +92101,11 @@ | ||
| 91878 | 92101 | ** If P4 is not null then it is an error message string. |
| 91879 | 92102 | ** |
| 91880 | 92103 | ** P5 is a value between 0 and 4, inclusive, that modifies the P4 string. |
| 91881 | 92104 | ** |
| 91882 | 92105 | ** 0: (no change) |
| 91883 | -** 1: NOT NULL contraint failed: P4 | |
| 92106 | +** 1: NOT NULL constraint failed: P4 | |
| 91884 | 92107 | ** 2: UNIQUE constraint failed: P4 |
| 91885 | 92108 | ** 3: CHECK constraint failed: P4 |
| 91886 | 92109 | ** 4: FOREIGN KEY constraint failed: P4 |
| 91887 | 92110 | ** |
| 91888 | 92111 | ** If P5 is not zero and P4 is NULL, then everything after the ":" is |
| @@ -95105,11 +95328,11 @@ | ||
| 95105 | 95328 | aMem[pOp->p3].n = 0; |
| 95106 | 95329 | aMem[pOp->p3].z = ""; |
| 95107 | 95330 | } |
| 95108 | 95331 | pCx = p->apCsr[pOp->p1]; |
| 95109 | 95332 | if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){ |
| 95110 | - /* If the ephermeral table is already open and has no duplicates from | |
| 95333 | + /* If the ephemeral table is already open and has no duplicates from | |
| 95111 | 95334 | ** OP_OpenDup, then erase all existing content so that the table is |
| 95112 | 95335 | ** empty again, rather than creating a new table. */ |
| 95113 | 95336 | assert( pCx->isEphemeral ); |
| 95114 | 95337 | pCx->seqCount = 0; |
| 95115 | 95338 | pCx->cacheStatus = CACHE_STALE; |
| @@ -95596,19 +95819,19 @@ | ||
| 95596 | 95819 | ** The This.P5 parameter is a flag that indicates what to do if the |
| 95597 | 95820 | ** cursor ends up pointing at a valid row that is past the target |
| 95598 | 95821 | ** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If |
| 95599 | 95822 | ** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0 |
| 95600 | 95823 | ** case occurs when there are no inequality constraints to the right of |
| 95601 | -** the IN constraing. The jump to SeekGE.P2 ends the loop. The P5!=0 case | |
| 95824 | +** the IN constraint. The jump to SeekGE.P2 ends the loop. The P5!=0 case | |
| 95602 | 95825 | ** occurs when there are inequality constraints to the right of the IN |
| 95603 | 95826 | ** operator. In that case, the This.P2 will point either directly to or |
| 95604 | 95827 | ** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for |
| 95605 | 95828 | ** loop terminate. |
| 95606 | 95829 | ** |
| 95607 | 95830 | ** Possible outcomes from this opcode:<ol> |
| 95608 | 95831 | ** |
| 95609 | -** <li> If the cursor is initally not pointed to any valid row, then | |
| 95832 | +** <li> If the cursor is initially not pointed to any valid row, then | |
| 95610 | 95833 | ** fall through into the subsequent OP_SeekGE opcode. |
| 95611 | 95834 | ** |
| 95612 | 95835 | ** <li> If the cursor is left pointing to a row that is before the target |
| 95613 | 95836 | ** row, even after making as many as This.P1 calls to |
| 95614 | 95837 | ** sqlite3BtreeNext(), then also fall through into OP_SeekGE. |
| @@ -98277,11 +98500,11 @@ | ||
| 98277 | 98500 | #endif |
| 98278 | 98501 | |
| 98279 | 98502 | /* If this function is inside of a trigger, the register array in aMem[] |
| 98280 | 98503 | ** might change from one evaluation to the next. The next block of code |
| 98281 | 98504 | ** checks to see if the register array has changed, and if so it |
| 98282 | - ** reinitializes the relavant parts of the sqlite3_context object */ | |
| 98505 | + ** reinitializes the relevant parts of the sqlite3_context object */ | |
| 98283 | 98506 | if( pCtx->pMem != pMem ){ |
| 98284 | 98507 | pCtx->pMem = pMem; |
| 98285 | 98508 | for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; |
| 98286 | 98509 | } |
| 98287 | 98510 | |
| @@ -99155,11 +99378,11 @@ | ||
| 99155 | 99378 | ** invocation of this opcode. |
| 99156 | 99379 | ** |
| 99157 | 99380 | ** This opcode works exactly like OP_Function. The only difference is in |
| 99158 | 99381 | ** its name. This opcode is used in places where the function must be |
| 99159 | 99382 | ** purely non-deterministic. Some built-in date/time functions can be |
| 99160 | -** either determinitic of non-deterministic, depending on their arguments. | |
| 99383 | +** either deterministic of non-deterministic, depending on their arguments. | |
| 99161 | 99384 | ** When those function are used in a non-deterministic way, they will check |
| 99162 | 99385 | ** to see if they were called using OP_PureFunc instead of OP_Function, and |
| 99163 | 99386 | ** if they were, they throw an error. |
| 99164 | 99387 | ** |
| 99165 | 99388 | ** See also: AggStep, AggFinal, Function |
| @@ -99173,11 +99396,11 @@ | ||
| 99173 | 99396 | pCtx = pOp->p4.pCtx; |
| 99174 | 99397 | |
| 99175 | 99398 | /* If this function is inside of a trigger, the register array in aMem[] |
| 99176 | 99399 | ** might change from one evaluation to the next. The next block of code |
| 99177 | 99400 | ** checks to see if the register array has changed, and if so it |
| 99178 | - ** reinitializes the relavant parts of the sqlite3_context object */ | |
| 99401 | + ** reinitializes the relevant parts of the sqlite3_context object */ | |
| 99179 | 99402 | pOut = &aMem[pOp->p3]; |
| 99180 | 99403 | if( pCtx->pOut != pOut ){ |
| 99181 | 99404 | pCtx->pVdbe = p; |
| 99182 | 99405 | pCtx->pOut = pOut; |
| 99183 | 99406 | pCtx->enc = encoding; |
| @@ -99249,11 +99472,11 @@ | ||
| 99249 | 99472 | registerTrace(ii, &aMem[ii]); |
| 99250 | 99473 | } |
| 99251 | 99474 | printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); |
| 99252 | 99475 | } |
| 99253 | 99476 | #endif |
| 99254 | - h %= pIn1->n; | |
| 99477 | + h %= (pIn1->n*8); | |
| 99255 | 99478 | pIn1->z[h/8] |= 1<<(h&7); |
| 99256 | 99479 | break; |
| 99257 | 99480 | } |
| 99258 | 99481 | |
| 99259 | 99482 | /* Opcode: Filter P1 P2 P3 P4 * |
| @@ -99285,11 +99508,11 @@ | ||
| 99285 | 99508 | registerTrace(ii, &aMem[ii]); |
| 99286 | 99509 | } |
| 99287 | 99510 | printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); |
| 99288 | 99511 | } |
| 99289 | 99512 | #endif |
| 99290 | - h %= pIn1->n; | |
| 99513 | + h %= (pIn1->n*8); | |
| 99291 | 99514 | if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){ |
| 99292 | 99515 | VdbeBranchTaken(1, 2); |
| 99293 | 99516 | p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++; |
| 99294 | 99517 | goto jump_to_p2; |
| 99295 | 99518 | }else{ |
| @@ -99537,11 +99760,11 @@ | ||
| 99537 | 99760 | if( opProperty & OPFLG_OUT3 ){ |
| 99538 | 99761 | registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); |
| 99539 | 99762 | } |
| 99540 | 99763 | if( opProperty==0xff ){ |
| 99541 | 99764 | /* Never happens. This code exists to avoid a harmless linkage |
| 99542 | - ** warning aboud sqlite3VdbeRegisterDump() being defined but not | |
| 99765 | + ** warning about sqlite3VdbeRegisterDump() being defined but not | |
| 99543 | 99766 | ** used. */ |
| 99544 | 99767 | sqlite3VdbeRegisterDump(p); |
| 99545 | 99768 | } |
| 99546 | 99769 | } |
| 99547 | 99770 | #endif /* SQLITE_DEBUG */ |
| @@ -100255,11 +100478,11 @@ | ||
| 100255 | 100478 | ** merging two or more level-0 PMAs together creates a level-1 PMA. |
| 100256 | 100479 | ** |
| 100257 | 100480 | ** The threshold for the amount of main memory to use before flushing |
| 100258 | 100481 | ** records to a PMA is roughly the same as the limit configured for the |
| 100259 | 100482 | ** page-cache of the main database. Specifically, the threshold is set to |
| 100260 | -** the value returned by "PRAGMA main.page_size" multipled by | |
| 100483 | +** the value returned by "PRAGMA main.page_size" multiplied by | |
| 100261 | 100484 | ** that returned by "PRAGMA main.cache_size", in bytes. |
| 100262 | 100485 | ** |
| 100263 | 100486 | ** If the sorter is running in single-threaded mode, then all PMAs generated |
| 100264 | 100487 | ** are appended to a single temporary file. Or, if the sorter is running in |
| 100265 | 100488 | ** multi-threaded mode then up to (N+1) temporary files may be opened, where |
| @@ -100278,11 +100501,11 @@ | ||
| 100278 | 100501 | ** final PMA. So at this point the data is stored in some number of sorted |
| 100279 | 100502 | ** PMAs within temporary files on disk. |
| 100280 | 100503 | ** |
| 100281 | 100504 | ** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the |
| 100282 | 100505 | ** sorter is running in single-threaded mode, then these PMAs are merged |
| 100283 | -** incrementally as keys are retreived from the sorter by the VDBE. The | |
| 100506 | +** incrementally as keys are retrieved from the sorter by the VDBE. The | |
| 100284 | 100507 | ** MergeEngine object, described in further detail below, performs this |
| 100285 | 100508 | ** merge. |
| 100286 | 100509 | ** |
| 100287 | 100510 | ** Or, if running in multi-threaded mode, then a background thread is |
| 100288 | 100511 | ** launched to merge the existing PMAs. Once the background thread has |
| @@ -100441,11 +100664,11 @@ | ||
| 100441 | 100664 | ** single-threaded operation, there is exactly one instance of this object |
| 100442 | 100665 | ** and for multi-threaded operation there are two or more instances. |
| 100443 | 100666 | ** |
| 100444 | 100667 | ** Essentially, this structure contains all those fields of the VdbeSorter |
| 100445 | 100668 | ** structure for which each thread requires a separate instance. For example, |
| 100446 | -** each thread requries its own UnpackedRecord object to unpack records in | |
| 100669 | +** each thread requeries its own UnpackedRecord object to unpack records in | |
| 100447 | 100670 | ** as part of comparison operations. |
| 100448 | 100671 | ** |
| 100449 | 100672 | ** Before a background thread is launched, variable bDone is set to 0. Then, |
| 100450 | 100673 | ** right before it exits, the thread itself sets bDone to 1. This is used for |
| 100451 | 100674 | ** two purposes: |
| @@ -100513,11 +100736,11 @@ | ||
| 100513 | 100736 | /* |
| 100514 | 100737 | ** An instance of the following object is used to read records out of a |
| 100515 | 100738 | ** PMA, in sorted order. The next key to be read is cached in nKey/aKey. |
| 100516 | 100739 | ** aKey might point into aMap or into aBuffer. If neither of those locations |
| 100517 | 100740 | ** contain a contiguous representation of the key, then aAlloc is allocated |
| 100518 | -** and the key is copied into aAlloc and aKey is made to poitn to aAlloc. | |
| 100741 | +** and the key is copied into aAlloc and aKey is made to point to aAlloc. | |
| 100519 | 100742 | ** |
| 100520 | 100743 | ** pFd==0 at EOF. |
| 100521 | 100744 | */ |
| 100522 | 100745 | struct PmaReader { |
| 100523 | 100746 | i64 iReadOff; /* Current read offset */ |
| @@ -101884,11 +102107,11 @@ | ||
| 101884 | 102107 | ** records to disk. If the sorter is running in multi-threaded mode, |
| 101885 | 102108 | ** round-robin between the first (pSorter->nTask-1) tasks. Except, if |
| 101886 | 102109 | ** the background thread from a sub-tasks previous turn is still running, |
| 101887 | 102110 | ** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy, |
| 101888 | 102111 | ** fall back to using the final sub-task. The first (pSorter->nTask-1) |
| 101889 | - ** sub-tasks are prefered as they use background threads - the final | |
| 102112 | + ** sub-tasks are preferred as they use background threads - the final | |
| 101890 | 102113 | ** sub-task uses the main thread. */ |
| 101891 | 102114 | for(i=0; i<nWorker; i++){ |
| 101892 | 102115 | int iTest = (pSorter->iPrev + i + 1) % nWorker; |
| 101893 | 102116 | pTask = &pSorter->aTask[iTest]; |
| 101894 | 102117 | if( pTask->bDone ){ |
| @@ -102368,11 +102591,11 @@ | ||
| 102368 | 102591 | /* eMode is always INCRINIT_NORMAL in single-threaded mode */ |
| 102369 | 102592 | assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL ); |
| 102370 | 102593 | |
| 102371 | 102594 | rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); |
| 102372 | 102595 | |
| 102373 | - /* Set up the required files for pIncr. A multi-theaded IncrMerge object | |
| 102596 | + /* Set up the required files for pIncr. A multi-threaded IncrMerge object | |
| 102374 | 102597 | ** requires two temp files to itself, whereas a single-threaded object |
| 102375 | 102598 | ** only requires a region of pTask->file2. */ |
| 102376 | 102599 | if( rc==SQLITE_OK ){ |
| 102377 | 102600 | int mxSz = pIncr->mxSz; |
| 102378 | 102601 | #if SQLITE_MAX_WORKER_THREADS>0 |
| @@ -104033,11 +104256,11 @@ | ||
| 104033 | 104256 | }while( p!=0 ); |
| 104034 | 104257 | return WRC_Continue; |
| 104035 | 104258 | } |
| 104036 | 104259 | |
| 104037 | 104260 | /* Increase the walkerDepth when entering a subquery, and |
| 104038 | -** descrease when leaving the subquery. | |
| 104261 | +** decrease when leaving the subquery. | |
| 104039 | 104262 | */ |
| 104040 | 104263 | SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *pWalker, Select *pSelect){ |
| 104041 | 104264 | UNUSED_PARAMETER(pSelect); |
| 104042 | 104265 | pWalker->walkerDepth++; |
| 104043 | 104266 | return WRC_Continue; |
| @@ -105767,11 +105990,11 @@ | ||
| 105767 | 105990 | if( sqlite3ResolveExprNames(pNC, pE) ){ |
| 105768 | 105991 | return 1; |
| 105769 | 105992 | } |
| 105770 | 105993 | for(j=0; j<pSelect->pEList->nExpr; j++){ |
| 105771 | 105994 | if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){ |
| 105772 | - /* Since this expresion is being changed into a reference | |
| 105995 | + /* Since this expression is being changed into a reference | |
| 105773 | 105996 | ** to an identical expression in the result set, remove all Window |
| 105774 | 105997 | ** objects belonging to the expression from the Select.pWin list. */ |
| 105775 | 105998 | windowRemoveExprFromSelect(pSelect, pE); |
| 105776 | 105999 | pItem->u.x.iOrderByCol = j+1; |
| 105777 | 106000 | } |
| @@ -106154,11 +106377,11 @@ | ||
| 106154 | 106377 | return WRC_Continue; |
| 106155 | 106378 | } |
| 106156 | 106379 | |
| 106157 | 106380 | /* |
| 106158 | 106381 | ** Resolve all names in all expressions of a SELECT and in all |
| 106159 | -** decendents of the SELECT, including compounds off of p->pPrior, | |
| 106382 | +** descendants of the SELECT, including compounds off of p->pPrior, | |
| 106160 | 106383 | ** subqueries in expressions, and subqueries used as FROM clause |
| 106161 | 106384 | ** terms. |
| 106162 | 106385 | ** |
| 106163 | 106386 | ** See sqlite3ResolveExprNames() for a description of the kinds of |
| 106164 | 106387 | ** transformations that occur. |
| @@ -106304,10 +106527,11 @@ | ||
| 106304 | 106527 | } |
| 106305 | 106528 | #endif |
| 106306 | 106529 | if( op==TK_SELECT_COLUMN ){ |
| 106307 | 106530 | assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) ); |
| 106308 | 106531 | assert( pExpr->iColumn < pExpr->iTable ); |
| 106532 | + assert( pExpr->iColumn >= 0 ); | |
| 106309 | 106533 | assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr ); |
| 106310 | 106534 | return sqlite3ExprAffinity( |
| 106311 | 106535 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| 106312 | 106536 | ); |
| 106313 | 106537 | } |
| @@ -106540,11 +106764,11 @@ | ||
| 106540 | 106764 | } |
| 106541 | 106765 | |
| 106542 | 106766 | /* |
| 106543 | 106767 | ** Return the collation sequence for the expression pExpr. If |
| 106544 | 106768 | ** there is no defined collating sequence, return a pointer to the |
| 106545 | -** defautl collation sequence. | |
| 106769 | +** default collation sequence. | |
| 106546 | 106770 | ** |
| 106547 | 106771 | ** See also: sqlite3ExprCollSeq() |
| 106548 | 106772 | ** |
| 106549 | 106773 | ** The sqlite3ExprCollSeq() routine works the same except that it |
| 106550 | 106774 | ** returns NULL if there is no defined collation. |
| @@ -106670,11 +106894,11 @@ | ||
| 106670 | 106894 | } |
| 106671 | 106895 | } |
| 106672 | 106896 | return pColl; |
| 106673 | 106897 | } |
| 106674 | 106898 | |
| 106675 | -/* Expresssion p is a comparison operator. Return a collation sequence | |
| 106899 | +/* Expression p is a comparison operator. Return a collation sequence | |
| 106676 | 106900 | ** appropriate for the comparison operator. |
| 106677 | 106901 | ** |
| 106678 | 106902 | ** This is normally just a wrapper around sqlite3BinaryCompareCollSeq(). |
| 106679 | 106903 | ** However, if the OP_Commuted flag is set, then the order of the operands |
| 106680 | 106904 | ** is reversed in the sqlite3BinaryCompareCollSeq() call so that the |
| @@ -107586,11 +107810,11 @@ | ||
| 107586 | 107810 | } |
| 107587 | 107811 | |
| 107588 | 107812 | /* |
| 107589 | 107813 | ** Arrange to cause pExpr to be deleted when the pParse is deleted. |
| 107590 | 107814 | ** This is similar to sqlite3ExprDelete() except that the delete is |
| 107591 | -** deferred untilthe pParse is deleted. | |
| 107815 | +** deferred until the pParse is deleted. | |
| 107592 | 107816 | ** |
| 107593 | 107817 | ** The pExpr might be deleted immediately on an OOM error. |
| 107594 | 107818 | ** |
| 107595 | 107819 | ** The deferred delete is (currently) implemented by adding the |
| 107596 | 107820 | ** pExpr to the pParse->pConstExpr list with a register number of 0. |
| @@ -108428,11 +108652,11 @@ | ||
| 108428 | 108652 | /* |
| 108429 | 108653 | ** The argument must be a TK_TRUEFALSE Expr node. Return 1 if it is TRUE |
| 108430 | 108654 | ** and 0 if it is FALSE. |
| 108431 | 108655 | */ |
| 108432 | 108656 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){ |
| 108433 | - pExpr = sqlite3ExprSkipCollate((Expr*)pExpr); | |
| 108657 | + pExpr = sqlite3ExprSkipCollateAndLikely((Expr*)pExpr); | |
| 108434 | 108658 | assert( pExpr->op==TK_TRUEFALSE ); |
| 108435 | 108659 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 108436 | 108660 | assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0 |
| 108437 | 108661 | || sqlite3StrICmp(pExpr->u.zToken,"false")==0 ); |
| 108438 | 108662 | return pExpr->u.zToken[4]==0; |
| @@ -109021,11 +109245,11 @@ | ||
| 109021 | 109245 | ** |
| 109022 | 109246 | ** IN_INDEX_ROWID - The cursor was opened on a database table. |
| 109023 | 109247 | ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index. |
| 109024 | 109248 | ** IN_INDEX_INDEX_DESC - The cursor was opened on a descending index. |
| 109025 | 109249 | ** IN_INDEX_EPH - The cursor was opened on a specially created and |
| 109026 | -** populated epheremal table. | |
| 109250 | +** populated ephemeral table. | |
| 109027 | 109251 | ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be |
| 109028 | 109252 | ** implemented as a sequence of comparisons. |
| 109029 | 109253 | ** |
| 109030 | 109254 | ** An existing b-tree might be used if the RHS expression pX is a simple |
| 109031 | 109255 | ** subquery such as: |
| @@ -109034,11 +109258,11 @@ | ||
| 109034 | 109258 | ** |
| 109035 | 109259 | ** If the RHS of the IN operator is a list or a more complex subquery, then |
| 109036 | 109260 | ** an ephemeral table might need to be generated from the RHS and then |
| 109037 | 109261 | ** pX->iTable made to point to the ephemeral table instead of an |
| 109038 | 109262 | ** existing table. In this case, the creation and initialization of the |
| 109039 | -** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag | |
| 109263 | +** ephemeral table might be put inside of a subroutine, the EP_Subrtn flag | |
| 109040 | 109264 | ** will be set on pX and the pX->y.sub fields will be set to show where |
| 109041 | 109265 | ** the subroutine is coded. |
| 109042 | 109266 | ** |
| 109043 | 109267 | ** The inFlags parameter must contain, at a minimum, one of the bits |
| 109044 | 109268 | ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains |
| @@ -109046,16 +109270,16 @@ | ||
| 109046 | 109270 | ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will |
| 109047 | 109271 | ** be used to loop over all values of the RHS of the IN operator. |
| 109048 | 109272 | ** |
| 109049 | 109273 | ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate |
| 109050 | 109274 | ** through the set members) then the b-tree must not contain duplicates. |
| 109051 | -** An epheremal table will be created unless the selected columns are guaranteed | |
| 109275 | +** An ephemeral table will be created unless the selected columns are guaranteed | |
| 109052 | 109276 | ** to be unique - either because it is an INTEGER PRIMARY KEY or due to |
| 109053 | 109277 | ** a UNIQUE constraint or index. |
| 109054 | 109278 | ** |
| 109055 | 109279 | ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used |
| 109056 | -** for fast set membership tests) then an epheremal table must | |
| 109280 | +** for fast set membership tests) then an ephemeral table must | |
| 109057 | 109281 | ** be used unless <columns> is a single INTEGER PRIMARY KEY column or an |
| 109058 | 109282 | ** index can be found with the specified <columns> as its left-most. |
| 109059 | 109283 | ** |
| 109060 | 109284 | ** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and |
| 109061 | 109285 | ** if the RHS of the IN operator is a list (not a subquery) then this |
| @@ -109384,11 +109608,11 @@ | ||
| 109384 | 109608 | ** |
| 109385 | 109609 | ** x IN (4,5,11) -- IN operator with list on right-hand side |
| 109386 | 109610 | ** x IN (SELECT a FROM b) -- IN operator with subquery on the right |
| 109387 | 109611 | ** |
| 109388 | 109612 | ** The pExpr parameter is the IN operator. The cursor number for the |
| 109389 | -** constructed ephermeral table is returned. The first time the ephemeral | |
| 109613 | +** constructed ephemeral table is returned. The first time the ephemeral | |
| 109390 | 109614 | ** table is computed, the cursor number is also stored in pExpr->iTable, |
| 109391 | 109615 | ** however the cursor number returned might not be the same, as it might |
| 109392 | 109616 | ** have been duplicated using OP_OpenDup. |
| 109393 | 109617 | ** |
| 109394 | 109618 | ** If the LHS expression ("x" in the examples) is a column value, or |
| @@ -110231,11 +110455,11 @@ | ||
| 110231 | 110455 | ExprClearProperty(p, EP_Skip); |
| 110232 | 110456 | } |
| 110233 | 110457 | |
| 110234 | 110458 | /* |
| 110235 | 110459 | ** Evaluate an expression (either a vector or a scalar expression) and store |
| 110236 | -** the result in continguous temporary registers. Return the index of | |
| 110460 | +** the result in contiguous temporary registers. Return the index of | |
| 110237 | 110461 | ** the first register used to store the result. |
| 110238 | 110462 | ** |
| 110239 | 110463 | ** If the returned result register is a temporary scalar, then also write |
| 110240 | 110464 | ** that register number into *piFreeable. If the returned result register |
| 110241 | 110465 | ** is not a temporary or if the expression is a vector set *piFreeable |
| @@ -110271,11 +110495,11 @@ | ||
| 110271 | 110495 | ** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5) |
| 110272 | 110496 | ** so that a subsequent copy will not be merged into this one. |
| 110273 | 110497 | */ |
| 110274 | 110498 | static void setDoNotMergeFlagOnCopy(Vdbe *v){ |
| 110275 | 110499 | if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){ |
| 110276 | - sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */ | |
| 110500 | + sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergeable */ | |
| 110277 | 110501 | } |
| 110278 | 110502 | } |
| 110279 | 110503 | |
| 110280 | 110504 | /* |
| 110281 | 110505 | ** Generate code to implement special SQL functions that are implemented |
| @@ -110361,17 +110585,17 @@ | ||
| 110361 | 110585 | target); |
| 110362 | 110586 | break; |
| 110363 | 110587 | } |
| 110364 | 110588 | |
| 110365 | 110589 | case INLINEFUNC_implies_nonnull_row: { |
| 110366 | - /* REsult of sqlite3ExprImpliesNonNullRow() */ | |
| 110590 | + /* Result of sqlite3ExprImpliesNonNullRow() */ | |
| 110367 | 110591 | Expr *pA1; |
| 110368 | 110592 | assert( nFarg==2 ); |
| 110369 | 110593 | pA1 = pFarg->a[1].pExpr; |
| 110370 | 110594 | if( pA1->op==TK_COLUMN ){ |
| 110371 | 110595 | sqlite3VdbeAddOp2(v, OP_Integer, |
| 110372 | - sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable), | |
| 110596 | + sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable,1), | |
| 110373 | 110597 | target); |
| 110374 | 110598 | }else{ |
| 110375 | 110599 | sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| 110376 | 110600 | } |
| 110377 | 110601 | break; |
| @@ -110543,11 +110767,11 @@ | ||
| 110543 | 110767 | int iTab = pExpr->iTable; |
| 110544 | 110768 | int iReg; |
| 110545 | 110769 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| 110546 | 110770 | /* This COLUMN expression is really a constant due to WHERE clause |
| 110547 | 110771 | ** constraints, and that constant is coded by the pExpr->pLeft |
| 110548 | - ** expresssion. However, make sure the constant has the correct | |
| 110772 | + ** expression. However, make sure the constant has the correct | |
| 110549 | 110773 | ** datatype by applying the Affinity of the table column to the |
| 110550 | 110774 | ** constant. |
| 110551 | 110775 | */ |
| 110552 | 110776 | int aff; |
| 110553 | 110777 | iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); |
| @@ -111272,11 +111496,11 @@ | ||
| 111272 | 111496 | ** once. If no functions are involved, then factor the code out and put it at |
| 111273 | 111497 | ** the end of the prepared statement in the initialization section. |
| 111274 | 111498 | ** |
| 111275 | 111499 | ** If regDest>=0 then the result is always stored in that register and the |
| 111276 | 111500 | ** result is not reusable. If regDest<0 then this routine is free to |
| 111277 | -** store the value whereever it wants. The register where the expression | |
| 111501 | +** store the value wherever it wants. The register where the expression | |
| 111278 | 111502 | ** is stored is returned. When regDest<0, two identical expressions might |
| 111279 | 111503 | ** code to the same register, if they do not contain function calls and hence |
| 111280 | 111504 | ** are factored out into the initialization section at the end of the |
| 111281 | 111505 | ** prepared statement. |
| 111282 | 111506 | */ |
| @@ -112190,11 +112414,11 @@ | ||
| 112190 | 112414 | ** pE1: x>0 pE2: x==5 Result: false |
| 112191 | 112415 | ** pE1: x=21 pE2: x=21 OR y=43 Result: true |
| 112192 | 112416 | ** pE1: x!=123 pE2: x IS NOT NULL Result: true |
| 112193 | 112417 | ** pE1: x!=?1 pE2: x IS NOT NULL Result: true |
| 112194 | 112418 | ** pE1: x IS NULL pE2: x IS NOT NULL Result: false |
| 112195 | -** pE1: x IS ?2 pE2: x IS NOT NULL Reuslt: false | |
| 112419 | +** pE1: x IS ?2 pE2: x IS NOT NULL Result: false | |
| 112196 | 112420 | ** |
| 112197 | 112421 | ** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has |
| 112198 | 112422 | ** Expr.iTable<0 then assume a table number given by iTab. |
| 112199 | 112423 | ** |
| 112200 | 112424 | ** If pParse is not NULL, then the values of bound variables in pE1 are |
| @@ -112226,68 +112450,108 @@ | ||
| 112226 | 112450 | ){ |
| 112227 | 112451 | return 1; |
| 112228 | 112452 | } |
| 112229 | 112453 | return 0; |
| 112230 | 112454 | } |
| 112455 | + | |
| 112456 | +/* This is a helper function to impliesNotNullRow(). In this routine, | |
| 112457 | +** set pWalker->eCode to one only if *both* of the input expressions | |
| 112458 | +** separately have the implies-not-null-row property. | |
| 112459 | +*/ | |
| 112460 | +static void bothImplyNotNullRow(Walker *pWalker, Expr *pE1, Expr *pE2){ | |
| 112461 | + if( pWalker->eCode==0 ){ | |
| 112462 | + sqlite3WalkExpr(pWalker, pE1); | |
| 112463 | + if( pWalker->eCode ){ | |
| 112464 | + pWalker->eCode = 0; | |
| 112465 | + sqlite3WalkExpr(pWalker, pE2); | |
| 112466 | + } | |
| 112467 | + } | |
| 112468 | +} | |
| 112231 | 112469 | |
| 112232 | 112470 | /* |
| 112233 | 112471 | ** This is the Expr node callback for sqlite3ExprImpliesNonNullRow(). |
| 112234 | 112472 | ** If the expression node requires that the table at pWalker->iCur |
| 112235 | 112473 | ** have one or more non-NULL column, then set pWalker->eCode to 1 and abort. |
| 112474 | +** | |
| 112475 | +** pWalker->mWFlags is non-zero if this inquiry is being undertaking on | |
| 112476 | +** behalf of a RIGHT JOIN (or FULL JOIN). That makes a difference when | |
| 112477 | +** evaluating terms in the ON clause of an inner join. | |
| 112236 | 112478 | ** |
| 112237 | 112479 | ** This routine controls an optimization. False positives (setting |
| 112238 | 112480 | ** pWalker->eCode to 1 when it should not be) are deadly, but false-negatives |
| 112239 | 112481 | ** (never setting pWalker->eCode) is a harmless missed optimization. |
| 112240 | 112482 | */ |
| 112241 | 112483 | static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){ |
| 112242 | 112484 | testcase( pExpr->op==TK_AGG_COLUMN ); |
| 112243 | 112485 | testcase( pExpr->op==TK_AGG_FUNCTION ); |
| 112244 | 112486 | if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune; |
| 112487 | + if( ExprHasProperty(pExpr, EP_InnerON) && pWalker->mWFlags ){ | |
| 112488 | + /* If iCur is used in an inner-join ON clause to the left of a | |
| 112489 | + ** RIGHT JOIN, that does *not* mean that the table must be non-null. | |
| 112490 | + ** But it is difficult to check for that condition precisely. | |
| 112491 | + ** To keep things simple, any use of iCur from any inner-join is | |
| 112492 | + ** ignored while attempting to simplify a RIGHT JOIN. */ | |
| 112493 | + return WRC_Prune; | |
| 112494 | + } | |
| 112245 | 112495 | switch( pExpr->op ){ |
| 112246 | 112496 | case TK_ISNOT: |
| 112247 | 112497 | case TK_ISNULL: |
| 112248 | 112498 | case TK_NOTNULL: |
| 112249 | 112499 | case TK_IS: |
| 112250 | - case TK_OR: | |
| 112251 | 112500 | case TK_VECTOR: |
| 112252 | - case TK_CASE: | |
| 112253 | - case TK_IN: | |
| 112254 | 112501 | case TK_FUNCTION: |
| 112255 | 112502 | case TK_TRUTH: |
| 112503 | + case TK_CASE: | |
| 112256 | 112504 | testcase( pExpr->op==TK_ISNOT ); |
| 112257 | 112505 | testcase( pExpr->op==TK_ISNULL ); |
| 112258 | 112506 | testcase( pExpr->op==TK_NOTNULL ); |
| 112259 | 112507 | testcase( pExpr->op==TK_IS ); |
| 112260 | - testcase( pExpr->op==TK_OR ); | |
| 112261 | 112508 | testcase( pExpr->op==TK_VECTOR ); |
| 112262 | - testcase( pExpr->op==TK_CASE ); | |
| 112263 | - testcase( pExpr->op==TK_IN ); | |
| 112264 | 112509 | testcase( pExpr->op==TK_FUNCTION ); |
| 112265 | 112510 | testcase( pExpr->op==TK_TRUTH ); |
| 112511 | + testcase( pExpr->op==TK_CASE ); | |
| 112266 | 112512 | return WRC_Prune; |
| 112513 | + | |
| 112267 | 112514 | case TK_COLUMN: |
| 112268 | 112515 | if( pWalker->u.iCur==pExpr->iTable ){ |
| 112269 | 112516 | pWalker->eCode = 1; |
| 112270 | 112517 | return WRC_Abort; |
| 112271 | 112518 | } |
| 112272 | 112519 | return WRC_Prune; |
| 112273 | 112520 | |
| 112521 | + case TK_OR: | |
| 112274 | 112522 | case TK_AND: |
| 112275 | - if( pWalker->eCode==0 ){ | |
| 112523 | + /* Both sides of an AND or OR must separately imply non-null-row. | |
| 112524 | + ** Consider these cases: | |
| 112525 | + ** 1. NOT (x AND y) | |
| 112526 | + ** 2. x OR y | |
| 112527 | + ** If only one of x or y is non-null-row, then the overall expression | |
| 112528 | + ** can be true if the other arm is false (case 1) or true (case 2). | |
| 112529 | + */ | |
| 112530 | + testcase( pExpr->op==TK_OR ); | |
| 112531 | + testcase( pExpr->op==TK_AND ); | |
| 112532 | + bothImplyNotNullRow(pWalker, pExpr->pLeft, pExpr->pRight); | |
| 112533 | + return WRC_Prune; | |
| 112534 | + | |
| 112535 | + case TK_IN: | |
| 112536 | + /* Beware of "x NOT IN ()" and "x NOT IN (SELECT 1 WHERE false)", | |
| 112537 | + ** both of which can be true. But apart from these cases, if | |
| 112538 | + ** the left-hand side of the IN is NULL then the IN itself will be | |
| 112539 | + ** NULL. */ | |
| 112540 | + if( ExprUseXList(pExpr) && ALWAYS(pExpr->x.pList->nExpr>0) ){ | |
| 112276 | 112541 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 112277 | - if( pWalker->eCode ){ | |
| 112278 | - pWalker->eCode = 0; | |
| 112279 | - sqlite3WalkExpr(pWalker, pExpr->pRight); | |
| 112280 | - } | |
| 112281 | 112542 | } |
| 112282 | 112543 | return WRC_Prune; |
| 112283 | 112544 | |
| 112284 | 112545 | case TK_BETWEEN: |
| 112285 | - if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){ | |
| 112286 | - assert( pWalker->eCode ); | |
| 112287 | - return WRC_Abort; | |
| 112288 | - } | |
| 112546 | + /* In "x NOT BETWEEN y AND z" either x must be non-null-row or else | |
| 112547 | + ** both y and z must be non-null row */ | |
| 112548 | + assert( ExprUseXList(pExpr) ); | |
| 112549 | + assert( pExpr->x.pList->nExpr==2 ); | |
| 112550 | + sqlite3WalkExpr(pWalker, pExpr->pLeft); | |
| 112551 | + bothImplyNotNullRow(pWalker, pExpr->x.pList->a[0].pExpr, | |
| 112552 | + pExpr->x.pList->a[1].pExpr); | |
| 112289 | 112553 | return WRC_Prune; |
| 112290 | 112554 | |
| 112291 | 112555 | /* Virtual tables are allowed to use constraints like x=NULL. So |
| 112292 | 112556 | ** a term of the form x=y does not prove that y is not null if x |
| 112293 | 112557 | ** is the column of a virtual table */ |
| @@ -112345,26 +112609,27 @@ | ||
| 112345 | 112609 | ** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE |
| 112346 | 112610 | ** clause requires that some column of the right table of the LEFT JOIN |
| 112347 | 112611 | ** be non-NULL, then the LEFT JOIN can be safely converted into an |
| 112348 | 112612 | ** ordinary join. |
| 112349 | 112613 | */ |
| 112350 | -SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){ | |
| 112614 | +SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab, int isRJ){ | |
| 112351 | 112615 | Walker w; |
| 112352 | 112616 | p = sqlite3ExprSkipCollateAndLikely(p); |
| 112353 | 112617 | if( p==0 ) return 0; |
| 112354 | 112618 | if( p->op==TK_NOTNULL ){ |
| 112355 | 112619 | p = p->pLeft; |
| 112356 | 112620 | }else{ |
| 112357 | 112621 | while( p->op==TK_AND ){ |
| 112358 | - if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1; | |
| 112622 | + if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab, isRJ) ) return 1; | |
| 112359 | 112623 | p = p->pRight; |
| 112360 | 112624 | } |
| 112361 | 112625 | } |
| 112362 | 112626 | w.xExprCallback = impliesNotNullRow; |
| 112363 | 112627 | w.xSelectCallback = 0; |
| 112364 | 112628 | w.xSelectCallback2 = 0; |
| 112365 | 112629 | w.eCode = 0; |
| 112630 | + w.mWFlags = isRJ!=0; | |
| 112366 | 112631 | w.u.iCur = iTab; |
| 112367 | 112632 | sqlite3WalkExpr(&w, p); |
| 112368 | 112633 | return w.eCode; |
| 112369 | 112634 | } |
| 112370 | 112635 | |
| @@ -112421,11 +112686,11 @@ | ||
| 112421 | 112686 | sqlite3WalkExpr(&w, pExpr); |
| 112422 | 112687 | return !w.eCode; |
| 112423 | 112688 | } |
| 112424 | 112689 | |
| 112425 | 112690 | |
| 112426 | -/* Structure used to pass information throught the Walker in order to | |
| 112691 | +/* Structure used to pass information throughout the Walker in order to | |
| 112427 | 112692 | ** implement sqlite3ReferencesSrcList(). |
| 112428 | 112693 | */ |
| 112429 | 112694 | struct RefSrcList { |
| 112430 | 112695 | sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */ |
| 112431 | 112696 | SrcList *pRef; /* Looking for references to these tables */ |
| @@ -112637,11 +112902,11 @@ | ||
| 112637 | 112902 | /* |
| 112638 | 112903 | ** Search the AggInfo object for an aCol[] entry that has iTable and iColumn. |
| 112639 | 112904 | ** Return the index in aCol[] of the entry that describes that column. |
| 112640 | 112905 | ** |
| 112641 | 112906 | ** If no prior entry is found, create a new one and return -1. The |
| 112642 | -** new column will have an idex of pAggInfo->nColumn-1. | |
| 112907 | +** new column will have an index of pAggInfo->nColumn-1. | |
| 112643 | 112908 | */ |
| 112644 | 112909 | static void findOrCreateAggInfoColumn( |
| 112645 | 112910 | Parse *pParse, /* Parsing context */ |
| 112646 | 112911 | AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */ |
| 112647 | 112912 | Expr *pExpr /* Expr describing the column to find or insert */ |
| @@ -112650,10 +112915,11 @@ | ||
| 112650 | 112915 | int k; |
| 112651 | 112916 | |
| 112652 | 112917 | assert( pAggInfo->iFirstReg==0 ); |
| 112653 | 112918 | pCol = pAggInfo->aCol; |
| 112654 | 112919 | for(k=0; k<pAggInfo->nColumn; k++, pCol++){ |
| 112920 | + if( pCol->pCExpr==pExpr ) return; | |
| 112655 | 112921 | if( pCol->iTable==pExpr->iTable |
| 112656 | 112922 | && pCol->iColumn==pExpr->iColumn |
| 112657 | 112923 | && pExpr->op!=TK_IF_NULL_ROW |
| 112658 | 112924 | ){ |
| 112659 | 112925 | goto fix_up_expr; |
| @@ -114035,11 +114301,11 @@ | ||
| 114035 | 114301 | |
| 114036 | 114302 | return pBest; |
| 114037 | 114303 | } |
| 114038 | 114304 | |
| 114039 | 114305 | /* |
| 114040 | -** An error occured while parsing or otherwise processing a database | |
| 114306 | +** An error occurred while parsing or otherwise processing a database | |
| 114041 | 114307 | ** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an |
| 114042 | 114308 | ** ALTER TABLE RENAME COLUMN program. The error message emitted by the |
| 114043 | 114309 | ** sub-routine is currently stored in pParse->zErrMsg. This function |
| 114044 | 114310 | ** adds context to the error message and then stores it in pCtx. |
| 114045 | 114311 | */ |
| @@ -117141,18 +117407,19 @@ | ||
| 117141 | 117407 | pSample = &pIdx->aSample[pIdx->nSample]; |
| 117142 | 117408 | decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0); |
| 117143 | 117409 | decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0); |
| 117144 | 117410 | decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0); |
| 117145 | 117411 | |
| 117146 | - /* Take a copy of the sample. Add two 0x00 bytes the end of the buffer. | |
| 117412 | + /* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer. | |
| 117147 | 117413 | ** This is in case the sample record is corrupted. In that case, the |
| 117148 | 117414 | ** sqlite3VdbeRecordCompare() may read up to two varints past the |
| 117149 | 117415 | ** end of the allocated buffer before it realizes it is dealing with |
| 117150 | - ** a corrupt record. Adding the two 0x00 bytes prevents this from causing | |
| 117416 | + ** a corrupt record. Or it might try to read a large integer from the | |
| 117417 | + ** buffer. In any case, eight 0x00 bytes prevents this from causing | |
| 117151 | 117418 | ** a buffer overread. */ |
| 117152 | 117419 | pSample->n = sqlite3_column_bytes(pStmt, 4); |
| 117153 | - pSample->p = sqlite3DbMallocZero(db, pSample->n + 2); | |
| 117420 | + pSample->p = sqlite3DbMallocZero(db, pSample->n + 8); | |
| 117154 | 117421 | if( pSample->p==0 ){ |
| 117155 | 117422 | sqlite3_finalize(pStmt); |
| 117156 | 117423 | return SQLITE_NOMEM_BKPT; |
| 117157 | 117424 | } |
| 117158 | 117425 | if( pSample->n ){ |
| @@ -118106,11 +118373,11 @@ | ||
| 118106 | 118373 | const char *zArg3 |
| 118107 | 118374 | ){ |
| 118108 | 118375 | sqlite3 *db = pParse->db; |
| 118109 | 118376 | int rc; |
| 118110 | 118377 | |
| 118111 | - /* Don't do any authorization checks if the database is initialising | |
| 118378 | + /* Don't do any authorization checks if the database is initializing | |
| 118112 | 118379 | ** or if the parser is being invoked from within sqlite3_declare_vtab. |
| 118113 | 118380 | */ |
| 118114 | 118381 | assert( !IN_RENAME_OBJECT || db->xAuth==0 ); |
| 118115 | 118382 | if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){ |
| 118116 | 118383 | return SQLITE_OK; |
| @@ -118928,11 +119195,11 @@ | ||
| 118928 | 119195 | pCol->colFlags |= COLFLAG_HASCOLL; |
| 118929 | 119196 | } |
| 118930 | 119197 | } |
| 118931 | 119198 | |
| 118932 | 119199 | /* |
| 118933 | -** Return the collating squence name for a column | |
| 119200 | +** Return the collating sequence name for a column | |
| 118934 | 119201 | */ |
| 118935 | 119202 | SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){ |
| 118936 | 119203 | const char *z; |
| 118937 | 119204 | if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0; |
| 118938 | 119205 | z = pCol->zCnName; |
| @@ -119686,11 +119953,11 @@ | ||
| 119686 | 119953 | sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName); |
| 119687 | 119954 | return; |
| 119688 | 119955 | } |
| 119689 | 119956 | if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName); |
| 119690 | 119957 | |
| 119691 | - /* Because keywords GENERATE ALWAYS can be converted into indentifiers | |
| 119958 | + /* Because keywords GENERATE ALWAYS can be converted into identifiers | |
| 119692 | 119959 | ** by the parser, we can sometimes end up with a typename that ends |
| 119693 | 119960 | ** with "generated always". Check for this case and omit the surplus |
| 119694 | 119961 | ** text. */ |
| 119695 | 119962 | if( sType.n>=16 |
| 119696 | 119963 | && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0 |
| @@ -119907,11 +120174,11 @@ | ||
| 119907 | 120174 | */ |
| 119908 | 120175 | SQLITE_PRIVATE void sqlite3AddDefaultValue( |
| 119909 | 120176 | Parse *pParse, /* Parsing context */ |
| 119910 | 120177 | Expr *pExpr, /* The parsed expression of the default value */ |
| 119911 | 120178 | const char *zStart, /* Start of the default value text */ |
| 119912 | - const char *zEnd /* First character past end of defaut value text */ | |
| 120179 | + const char *zEnd /* First character past end of default value text */ | |
| 119913 | 120180 | ){ |
| 119914 | 120181 | Table *p; |
| 119915 | 120182 | Column *pCol; |
| 119916 | 120183 | sqlite3 *db = pParse->db; |
| 119917 | 120184 | p = pParse->pNewTable; |
| @@ -120255,11 +120522,11 @@ | ||
| 120255 | 120522 | ** which to write into the output buffer. This function copies the |
| 120256 | 120523 | ** nul-terminated string pointed to by the third parameter, zSignedIdent, |
| 120257 | 120524 | ** to the specified offset in the buffer and updates *pIdx to refer |
| 120258 | 120525 | ** to the first byte after the last byte written before returning. |
| 120259 | 120526 | ** |
| 120260 | -** If the string zSignedIdent consists entirely of alpha-numeric | |
| 120527 | +** If the string zSignedIdent consists entirely of alphanumeric | |
| 120261 | 120528 | ** characters, does not begin with a digit and is not an SQL keyword, |
| 120262 | 120529 | ** then it is copied to the output buffer exactly as it is. Otherwise, |
| 120263 | 120530 | ** it is quoted using double-quotes. |
| 120264 | 120531 | */ |
| 120265 | 120532 | static void identPut(char *z, int *pIdx, char *zSignedIdent){ |
| @@ -120407,11 +120674,11 @@ | ||
| 120407 | 120674 | int i; |
| 120408 | 120675 | const Column *aCol = pIdx->pTable->aCol; |
| 120409 | 120676 | for(i=0; i<pIdx->nColumn; i++){ |
| 120410 | 120677 | i16 x = pIdx->aiColumn[i]; |
| 120411 | 120678 | assert( x<pIdx->pTable->nCol ); |
| 120412 | - wIndex += x<0 ? 1 : aCol[pIdx->aiColumn[i]].szEst; | |
| 120679 | + wIndex += x<0 ? 1 : aCol[x].szEst; | |
| 120413 | 120680 | } |
| 120414 | 120681 | pIdx->szIdxRow = sqlite3LogEst(wIndex*4); |
| 120415 | 120682 | } |
| 120416 | 120683 | |
| 120417 | 120684 | /* Return true if column number x is any of the first nCol entries of aiCol[]. |
| @@ -122145,11 +122412,11 @@ | ||
| 122145 | 122412 | assert( pName && pName->z ); |
| 122146 | 122413 | |
| 122147 | 122414 | #ifndef SQLITE_OMIT_TEMPDB |
| 122148 | 122415 | /* If the index name was unqualified, check if the table |
| 122149 | 122416 | ** is a temp table. If so, set the database to 1. Do not do this |
| 122150 | - ** if initialising a database schema. | |
| 122417 | + ** if initializing a database schema. | |
| 122151 | 122418 | */ |
| 122152 | 122419 | if( !db->init.busy ){ |
| 122153 | 122420 | pTab = sqlite3SrcListLookup(pParse, pTblName); |
| 122154 | 122421 | if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){ |
| 122155 | 122422 | iDb = 1; |
| @@ -123802,11 +124069,11 @@ | ||
| 123802 | 124069 | sqlite3DbFree(db, pCte); |
| 123803 | 124070 | } |
| 123804 | 124071 | |
| 123805 | 124072 | /* |
| 123806 | 124073 | ** This routine is invoked once per CTE by the parser while parsing a |
| 123807 | -** WITH clause. The CTE described by teh third argument is added to | |
| 124074 | +** WITH clause. The CTE described by the third argument is added to | |
| 123808 | 124075 | ** the WITH clause of the second argument. If the second argument is |
| 123809 | 124076 | ** NULL, then a new WITH argument is created. |
| 123810 | 124077 | */ |
| 123811 | 124078 | SQLITE_PRIVATE With *sqlite3WithAdd( |
| 123812 | 124079 | Parse *pParse, /* Parsing context */ |
| @@ -124446,10 +124713,11 @@ | ||
| 124446 | 124713 | Table *pTab; |
| 124447 | 124714 | assert( pItem && pSrc->nSrc>=1 ); |
| 124448 | 124715 | pTab = sqlite3LocateTableItem(pParse, 0, pItem); |
| 124449 | 124716 | sqlite3DeleteTable(pParse->db, pItem->pTab); |
| 124450 | 124717 | pItem->pTab = pTab; |
| 124718 | + pItem->fg.notCte = 1; | |
| 124451 | 124719 | if( pTab ){ |
| 124452 | 124720 | pTab->nTabRef++; |
| 124453 | 124721 | if( pItem->fg.isIndexedBy && sqlite3IndexedByLookup(pParse, pItem) ){ |
| 124454 | 124722 | pTab = 0; |
| 124455 | 124723 | } |
| @@ -124598,11 +124866,11 @@ | ||
| 124598 | 124866 | char *zStmtType /* Either DELETE or UPDATE. For err msgs. */ |
| 124599 | 124867 | ){ |
| 124600 | 124868 | sqlite3 *db = pParse->db; |
| 124601 | 124869 | Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */ |
| 124602 | 124870 | Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */ |
| 124603 | - ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */ | |
| 124871 | + ExprList *pEList = NULL; /* Expression list containing only pSelectRowid*/ | |
| 124604 | 124872 | SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */ |
| 124605 | 124873 | Select *pSelect = NULL; /* Complete SELECT tree */ |
| 124606 | 124874 | Table *pTab; |
| 124607 | 124875 | |
| 124608 | 124876 | /* Check that there isn't an ORDER BY without a LIMIT clause. |
| @@ -124636,18 +124904,24 @@ | ||
| 124636 | 124904 | pEList = sqlite3ExprListAppend( |
| 124637 | 124905 | pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0) |
| 124638 | 124906 | ); |
| 124639 | 124907 | }else{ |
| 124640 | 124908 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 124909 | + assert( pPk!=0 ); | |
| 124910 | + assert( pPk->nKeyCol>=1 ); | |
| 124641 | 124911 | if( pPk->nKeyCol==1 ){ |
| 124642 | - const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName; | |
| 124912 | + const char *zName; | |
| 124913 | + assert( pPk->aiColumn[0]>=0 && pPk->aiColumn[0]<pTab->nCol ); | |
| 124914 | + zName = pTab->aCol[pPk->aiColumn[0]].zCnName; | |
| 124643 | 124915 | pLhs = sqlite3Expr(db, TK_ID, zName); |
| 124644 | 124916 | pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName)); |
| 124645 | 124917 | }else{ |
| 124646 | 124918 | int i; |
| 124647 | 124919 | for(i=0; i<pPk->nKeyCol; i++){ |
| 124648 | - Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName); | |
| 124920 | + Expr *p; | |
| 124921 | + assert( pPk->aiColumn[i]>=0 && pPk->aiColumn[i]<pTab->nCol ); | |
| 124922 | + p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName); | |
| 124649 | 124923 | pEList = sqlite3ExprListAppend(pParse, pEList, p); |
| 124650 | 124924 | } |
| 124651 | 124925 | pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 124652 | 124926 | if( pLhs ){ |
| 124653 | 124927 | pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0); |
| @@ -124672,11 +124946,11 @@ | ||
| 124672 | 124946 | /* generate the SELECT expression tree. */ |
| 124673 | 124947 | pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0, |
| 124674 | 124948 | pOrderBy,0,pLimit |
| 124675 | 124949 | ); |
| 124676 | 124950 | |
| 124677 | - /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */ | |
| 124951 | + /* now generate the new WHERE rowid IN clause for the DELETE/UPDATE */ | |
| 124678 | 124952 | pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0); |
| 124679 | 124953 | sqlite3PExprAddSelect(pParse, pInClause, pSelect); |
| 124680 | 124954 | return pInClause; |
| 124681 | 124955 | } |
| 124682 | 124956 | #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */ |
| @@ -126057,11 +126331,11 @@ | ||
| 126057 | 126331 | u8 noCase; /* true to ignore case differences */ |
| 126058 | 126332 | }; |
| 126059 | 126333 | |
| 126060 | 126334 | /* |
| 126061 | 126335 | ** For LIKE and GLOB matching on EBCDIC machines, assume that every |
| 126062 | -** character is exactly one byte in size. Also, provde the Utf8Read() | |
| 126336 | +** character is exactly one byte in size. Also, provide the Utf8Read() | |
| 126063 | 126337 | ** macro for fast reading of the next character in the common case where |
| 126064 | 126338 | ** the next character is ASCII. |
| 126065 | 126339 | */ |
| 126066 | 126340 | #if defined(SQLITE_EBCDIC) |
| 126067 | 126341 | # define sqlite3Utf8Read(A) (*((*A)++)) |
| @@ -126290,11 +126564,11 @@ | ||
| 126290 | 126564 | #endif |
| 126291 | 126565 | |
| 126292 | 126566 | |
| 126293 | 126567 | /* |
| 126294 | 126568 | ** Implementation of the like() SQL function. This function implements |
| 126295 | -** the build-in LIKE operator. The first argument to the function is the | |
| 126569 | +** the built-in LIKE operator. The first argument to the function is the | |
| 126296 | 126570 | ** pattern and the second argument is the string. So, the SQL statements: |
| 126297 | 126571 | ** |
| 126298 | 126572 | ** A LIKE B |
| 126299 | 126573 | ** |
| 126300 | 126574 | ** is implemented as like(B,A). |
| @@ -126676,11 +126950,11 @@ | ||
| 126676 | 126950 | ** two arguments. In both cases the first argument is interpreted as text |
| 126677 | 126951 | ** a text value containing a set of pairs of hexadecimal digits which are |
| 126678 | 126952 | ** decoded and returned as a blob. |
| 126679 | 126953 | ** |
| 126680 | 126954 | ** If there is only a single argument, then it must consist only of an |
| 126681 | -** even number of hexadeximal digits. Otherwise, return NULL. | |
| 126955 | +** even number of hexadecimal digits. Otherwise, return NULL. | |
| 126682 | 126956 | ** |
| 126683 | 126957 | ** Or, if there is a second argument, then any character that appears in |
| 126684 | 126958 | ** the second argument is also allowed to appear between pairs of hexadecimal |
| 126685 | 126959 | ** digits in the first argument. If any other character appears in the |
| 126686 | 126960 | ** first argument, or if one of the allowed characters appears between |
| @@ -127376,11 +127650,11 @@ | ||
| 127376 | 127650 | assert( argc==1 || argc==2 ); |
| 127377 | 127651 | (void)argc; /* Suppress unused parameter warning */ |
| 127378 | 127652 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 127379 | 127653 | pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC)); |
| 127380 | 127654 | /* pGCC is always non-NULL since groupConcatStep() will have always |
| 127381 | - ** run frist to initialize it */ | |
| 127655 | + ** run first to initialize it */ | |
| 127382 | 127656 | if( ALWAYS(pGCC) ){ |
| 127383 | 127657 | int nVS; |
| 127384 | 127658 | /* Must call sqlite3_value_text() to convert the argument into text prior |
| 127385 | 127659 | ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */ |
| 127386 | 127660 | (void)sqlite3_value_text(argv[0]); |
| @@ -129579,11 +129853,11 @@ | ||
| 129579 | 129853 | ** 'E' REAL |
| 129580 | 129854 | ** |
| 129581 | 129855 | ** For STRICT tables: |
| 129582 | 129856 | ** ------------------ |
| 129583 | 129857 | ** |
| 129584 | -** Generate an appropropriate OP_TypeCheck opcode that will verify the | |
| 129858 | +** Generate an appropriate OP_TypeCheck opcode that will verify the | |
| 129585 | 129859 | ** datatypes against the column definitions in pTab. If iReg==0, that |
| 129586 | 129860 | ** means an OP_MakeRecord opcode has already been generated and should be |
| 129587 | 129861 | ** the last opcode generated. The new OP_TypeCheck needs to be inserted |
| 129588 | 129862 | ** before the OP_MakeRecord. The new OP_TypeCheck should use the same |
| 129589 | 129863 | ** register set as the OP_MakeRecord. If iReg>0 then register iReg is |
| @@ -130871,11 +131145,11 @@ | ||
| 130871 | 131145 | #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */ |
| 130872 | 131146 | |
| 130873 | 131147 | /* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn(). |
| 130874 | 131148 | * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this |
| 130875 | 131149 | ** expression node references any of the |
| 130876 | -** columns that are being modifed by an UPDATE statement. | |
| 131150 | +** columns that are being modified by an UPDATE statement. | |
| 130877 | 131151 | */ |
| 130878 | 131152 | static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr){ |
| 130879 | 131153 | if( pExpr->op==TK_COLUMN ){ |
| 130880 | 131154 | assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 ); |
| 130881 | 131155 | if( pExpr->iColumn>=0 ){ |
| @@ -131094,11 +131368,11 @@ | ||
| 131094 | 131368 | int ignoreDest, /* Jump to this label on an OE_Ignore resolution */ |
| 131095 | 131369 | int *pbMayReplace, /* OUT: Set to true if constraint may cause a replace */ |
| 131096 | 131370 | int *aiChng, /* column i is unchanged if aiChng[i]<0 */ |
| 131097 | 131371 | Upsert *pUpsert /* ON CONFLICT clauses, if any. NULL otherwise */ |
| 131098 | 131372 | ){ |
| 131099 | - Vdbe *v; /* VDBE under constrution */ | |
| 131373 | + Vdbe *v; /* VDBE under construction */ | |
| 131100 | 131374 | Index *pIdx; /* Pointer to one of the indices */ |
| 131101 | 131375 | Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */ |
| 131102 | 131376 | sqlite3 *db; /* Database connection */ |
| 131103 | 131377 | int i; /* loop counter */ |
| 131104 | 131378 | int ix; /* Index loop counter */ |
| @@ -131577,11 +131851,11 @@ | ||
| 131577 | 131851 | */ |
| 131578 | 131852 | for(pIdx = indexIteratorFirst(&sIdxIter, &ix); |
| 131579 | 131853 | pIdx; |
| 131580 | 131854 | pIdx = indexIteratorNext(&sIdxIter, &ix) |
| 131581 | 131855 | ){ |
| 131582 | - int regIdx; /* Range of registers hold conent for pIdx */ | |
| 131856 | + int regIdx; /* Range of registers holding content for pIdx */ | |
| 131583 | 131857 | int regR; /* Range of registers holding conflicting PK */ |
| 131584 | 131858 | int iThisCur; /* Cursor for this UNIQUE index */ |
| 131585 | 131859 | int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */ |
| 131586 | 131860 | int addrConflictCk; /* First opcode in the conflict check logic */ |
| 131587 | 131861 | |
| @@ -132393,11 +132667,11 @@ | ||
| 132393 | 132667 | if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){ |
| 132394 | 132668 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 132395 | 132669 | } |
| 132396 | 132670 | #endif |
| 132397 | 132671 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 132398 | - /* Disallow the transfer optimization if the destination table constains | |
| 132672 | + /* Disallow the transfer optimization if the destination table contains | |
| 132399 | 132673 | ** any foreign key constraints. This is more restrictive than necessary. |
| 132400 | 132674 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 132401 | 132675 | ** command, and the VACUUM command disables foreign key constraints. So |
| 132402 | 132676 | ** the extra complication to make this rule less restrictive is probably |
| 132403 | 132677 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| @@ -134026,10 +134300,14 @@ | ||
| 134026 | 134300 | ** |
| 134027 | 134301 | ** Later (2023-03-25): Save an extra 6 bytes for the filename suffix. |
| 134028 | 134302 | ** See https://sqlite.org/forum/forumpost/24083b579d. |
| 134029 | 134303 | */ |
| 134030 | 134304 | if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found; |
| 134305 | + | |
| 134306 | + /* Do not allow sqlite3_load_extension() to link to a copy of the | |
| 134307 | + ** running application, by passing in an empty filename. */ | |
| 134308 | + if( nMsg==0 ) goto extension_not_found; | |
| 134031 | 134309 | |
| 134032 | 134310 | handle = sqlite3OsDlOpen(pVfs, zFile); |
| 134033 | 134311 | #if SQLITE_OS_UNIX || SQLITE_OS_WIN |
| 134034 | 134312 | for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){ |
| 134035 | 134313 | char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]); |
| @@ -135859,11 +136137,11 @@ | ||
| 135859 | 136137 | ** PRAGMA cache_spill=BOOLEAN |
| 135860 | 136138 | ** PRAGMA [schema.]cache_spill=N |
| 135861 | 136139 | ** |
| 135862 | 136140 | ** The first form reports the current local setting for the |
| 135863 | 136141 | ** page cache spill size. The second form turns cache spill on |
| 135864 | - ** or off. When turnning cache spill on, the size is set to the | |
| 136142 | + ** or off. When turning cache spill on, the size is set to the | |
| 135865 | 136143 | ** current cache_size. The third form sets a spill size that |
| 135866 | 136144 | ** may be different form the cache size. |
| 135867 | 136145 | ** If N is positive then that is the |
| 135868 | 136146 | ** number of pages in the cache. If N is negative, then the |
| 135869 | 136147 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| @@ -136637,13 +136915,13 @@ | ||
| 136637 | 136915 | ** Verify the integrity of the database. |
| 136638 | 136916 | ** |
| 136639 | 136917 | ** The "quick_check" is reduced version of |
| 136640 | 136918 | ** integrity_check designed to detect most database corruption |
| 136641 | 136919 | ** without the overhead of cross-checking indexes. Quick_check |
| 136642 | - ** is linear time wherease integrity_check is O(NlogN). | |
| 136920 | + ** is linear time whereas integrity_check is O(NlogN). | |
| 136643 | 136921 | ** |
| 136644 | - ** The maximum nubmer of errors is 100 by default. A different default | |
| 136922 | + ** The maximum number of errors is 100 by default. A different default | |
| 136645 | 136923 | ** can be specified using a numeric parameter N. |
| 136646 | 136924 | ** |
| 136647 | 136925 | ** Or, the parameter N can be the name of a table. In that case, only |
| 136648 | 136926 | ** the one table named is verified. The freelist is only verified if |
| 136649 | 136927 | ** the named table is "sqlite_schema" (or one of its aliases). |
| @@ -137397,11 +137675,11 @@ | ||
| 137397 | 137675 | int iTabCur; /* Cursor for a table whose size needs checking */ |
| 137398 | 137676 | HashElem *k; /* Loop over tables of a schema */ |
| 137399 | 137677 | Schema *pSchema; /* The current schema */ |
| 137400 | 137678 | Table *pTab; /* A table in the schema */ |
| 137401 | 137679 | Index *pIdx; /* An index of the table */ |
| 137402 | - LogEst szThreshold; /* Size threshold above which reanalysis is needd */ | |
| 137680 | + LogEst szThreshold; /* Size threshold above which reanalysis needed */ | |
| 137403 | 137681 | char *zSubSql; /* SQL statement for the OP_SqlExec opcode */ |
| 137404 | 137682 | u32 opMask; /* Mask of operations to perform */ |
| 137405 | 137683 | |
| 137406 | 137684 | if( zRight ){ |
| 137407 | 137685 | opMask = (u32)sqlite3Atoi(zRight); |
| @@ -138523,11 +138801,11 @@ | ||
| 138523 | 138801 | ** Add a new cleanup operation to a Parser. The cleanup should happen when |
| 138524 | 138802 | ** the parser object is destroyed. But, beware: the cleanup might happen |
| 138525 | 138803 | ** immediately. |
| 138526 | 138804 | ** |
| 138527 | 138805 | ** Use this mechanism for uncommon cleanups. There is a higher setup |
| 138528 | -** cost for this mechansim (an extra malloc), so it should not be used | |
| 138806 | +** cost for this mechanism (an extra malloc), so it should not be used | |
| 138529 | 138807 | ** for common cleanups that happen on most calls. But for less |
| 138530 | 138808 | ** common cleanups, we save a single NULL-pointer comparison in |
| 138531 | 138809 | ** sqlite3ParseObjectReset(), which reduces the total CPU cycle count. |
| 138532 | 138810 | ** |
| 138533 | 138811 | ** If a memory allocation error occurs, then the cleanup happens immediately. |
| @@ -139225,11 +139503,11 @@ | ||
| 139225 | 139503 | ** NATURAL RIGHT OUTER JT_NATURAL|JT_RIGHT|JT_OUTER |
| 139226 | 139504 | ** NATURAL FULL - JT_NATURAL|JT_LEFT|JT_RIGHT |
| 139227 | 139505 | ** NATURAL FULL OUTER JT_NATRUAL|JT_LEFT|JT_RIGHT |
| 139228 | 139506 | ** |
| 139229 | 139507 | ** To preserve historical compatibly, SQLite also accepts a variety |
| 139230 | -** of other non-standard and in many cases non-sensical join types. | |
| 139508 | +** of other non-standard and in many cases nonsensical join types. | |
| 139231 | 139509 | ** This routine makes as much sense at it can from the nonsense join |
| 139232 | 139510 | ** type and returns a result. Examples of accepted nonsense join types |
| 139233 | 139511 | ** include but are not limited to: |
| 139234 | 139512 | ** |
| 139235 | 139513 | ** INNER CROSS JOIN -> same as JOIN |
| @@ -139496,11 +139774,11 @@ | ||
| 139496 | 139774 | u32 joinType; |
| 139497 | 139775 | |
| 139498 | 139776 | if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue; |
| 139499 | 139777 | joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON; |
| 139500 | 139778 | |
| 139501 | - /* If this is a NATURAL join, synthesize an approprate USING clause | |
| 139779 | + /* If this is a NATURAL join, synthesize an appropriate USING clause | |
| 139502 | 139780 | ** to specify which columns should be joined. |
| 139503 | 139781 | */ |
| 139504 | 139782 | if( pRight->fg.jointype & JT_NATURAL ){ |
| 139505 | 139783 | IdList *pUsing = 0; |
| 139506 | 139784 | if( pRight->fg.isUsing || pRight->u3.pOn ){ |
| @@ -139712,11 +139990,11 @@ | ||
| 139712 | 139990 | ** (2) All output columns are included in the sort record. In that |
| 139713 | 139991 | ** case regData==regOrigData. |
| 139714 | 139992 | ** (3) Some output columns are omitted from the sort record due to |
| 139715 | 139993 | ** the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the |
| 139716 | 139994 | ** SQLITE_ECEL_OMITREF optimization, or due to the |
| 139717 | - ** SortCtx.pDeferredRowLoad optimiation. In any of these cases | |
| 139995 | + ** SortCtx.pDeferredRowLoad optimization. In any of these cases | |
| 139718 | 139996 | ** regOrigData is 0 to prevent this routine from trying to copy |
| 139719 | 139997 | ** values that might not yet exist. |
| 139720 | 139998 | */ |
| 139721 | 139999 | assert( nData==1 || regData==regOrigData || regOrigData==0 ); |
| 139722 | 140000 | |
| @@ -139768,11 +140046,11 @@ | ||
| 139768 | 140046 | memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */ |
| 139769 | 140047 | sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO); |
| 139770 | 140048 | testcase( pKI->nAllField > pKI->nKeyField+2 ); |
| 139771 | 140049 | pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat, |
| 139772 | 140050 | pKI->nAllField-pKI->nKeyField-1); |
| 139773 | - pOp = 0; /* Ensure pOp not used after sqltie3VdbeAddOp3() */ | |
| 140051 | + pOp = 0; /* Ensure pOp not used after sqlite3VdbeAddOp3() */ | |
| 139774 | 140052 | addrJmp = sqlite3VdbeCurrentAddr(v); |
| 139775 | 140053 | sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v); |
| 139776 | 140054 | pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse); |
| 139777 | 140055 | pSort->regReturn = ++pParse->nMem; |
| 139778 | 140056 | sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut); |
| @@ -139862,11 +140140,11 @@ | ||
| 139862 | 140140 | ** the ephemeral cursor and proceed. |
| 139863 | 140141 | ** |
| 139864 | 140142 | ** The returned value in this case is a copy of parameter iTab. |
| 139865 | 140143 | ** |
| 139866 | 140144 | ** WHERE_DISTINCT_ORDERED: |
| 139867 | -** In this case rows are being delivered sorted order. The ephermal | |
| 140145 | +** In this case rows are being delivered sorted order. The ephemeral | |
| 139868 | 140146 | ** table is not required. Instead, the current set of values |
| 139869 | 140147 | ** is compared against previous row. If they match, the new row |
| 139870 | 140148 | ** is not distinct and control jumps to VM address addrRepeat. Otherwise, |
| 139871 | 140149 | ** the VM program proceeds with processing the new row. |
| 139872 | 140150 | ** |
| @@ -141287,11 +141565,11 @@ | ||
| 141287 | 141565 | /* |
| 141288 | 141566 | ** pTab is a transient Table object that represents a subquery of some |
| 141289 | 141567 | ** kind (maybe a parenthesized subquery in the FROM clause of a larger |
| 141290 | 141568 | ** query, or a VIEW, or a CTE). This routine computes type information |
| 141291 | 141569 | ** for that Table object based on the Select object that implements the |
| 141292 | -** subquery. For the purposes of this routine, "type infomation" means: | |
| 141570 | +** subquery. For the purposes of this routine, "type information" means: | |
| 141293 | 141571 | ** |
| 141294 | 141572 | ** * The datatype name, as it might appear in a CREATE TABLE statement |
| 141295 | 141573 | ** * Which collating sequence to use for the column |
| 141296 | 141574 | ** * The affinity of the column |
| 141297 | 141575 | */ |
| @@ -141616,11 +141894,11 @@ | ||
| 141616 | 141894 | int iCurrent = 0; /* The Current table */ |
| 141617 | 141895 | int regCurrent; /* Register holding Current table */ |
| 141618 | 141896 | int iQueue; /* The Queue table */ |
| 141619 | 141897 | int iDistinct = 0; /* To ensure unique results if UNION */ |
| 141620 | 141898 | int eDest = SRT_Fifo; /* How to write to Queue */ |
| 141621 | - SelectDest destQueue; /* SelectDest targetting the Queue table */ | |
| 141899 | + SelectDest destQueue; /* SelectDest targeting the Queue table */ | |
| 141622 | 141900 | int i; /* Loop counter */ |
| 141623 | 141901 | int rc; /* Result code */ |
| 141624 | 141902 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| 141625 | 141903 | Expr *pLimit; /* Saved LIMIT and OFFSET */ |
| 141626 | 141904 | int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */ |
| @@ -142216,11 +142494,11 @@ | ||
| 142216 | 142494 | } |
| 142217 | 142495 | } |
| 142218 | 142496 | |
| 142219 | 142497 | /* |
| 142220 | 142498 | ** Code an output subroutine for a coroutine implementation of a |
| 142221 | -** SELECT statment. | |
| 142499 | +** SELECT statement. | |
| 142222 | 142500 | ** |
| 142223 | 142501 | ** The data to be output is contained in pIn->iSdst. There are |
| 142224 | 142502 | ** pIn->nSdst columns to be output. pDest is where the output should |
| 142225 | 142503 | ** be sent. |
| 142226 | 142504 | ** |
| @@ -142438,11 +142716,11 @@ | ||
| 142438 | 142716 | ** Jump AltB, AeqB, AgtB |
| 142439 | 142717 | ** End: ... |
| 142440 | 142718 | ** |
| 142441 | 142719 | ** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not |
| 142442 | 142720 | ** actually called using Gosub and they do not Return. EofA and EofB loop |
| 142443 | -** until all data is exhausted then jump to the "end" labe. AltB, AeqB, | |
| 142721 | +** until all data is exhausted then jump to the "end" label. AltB, AeqB, | |
| 142444 | 142722 | ** and AgtB jump to either L2 or to one of EofA or EofB. |
| 142445 | 142723 | */ |
| 142446 | 142724 | #ifndef SQLITE_OMIT_COMPOUND_SELECT |
| 142447 | 142725 | static int multiSelectOrderBy( |
| 142448 | 142726 | Parse *pParse, /* Parsing context */ |
| @@ -142475,11 +142753,11 @@ | ||
| 142475 | 142753 | int regPrev; /* A range of registers to hold previous output */ |
| 142476 | 142754 | int savedLimit; /* Saved value of p->iLimit */ |
| 142477 | 142755 | int savedOffset; /* Saved value of p->iOffset */ |
| 142478 | 142756 | int labelCmpr; /* Label for the start of the merge algorithm */ |
| 142479 | 142757 | int labelEnd; /* Label for the end of the overall SELECT stmt */ |
| 142480 | - int addr1; /* Jump instructions that get retargetted */ | |
| 142758 | + int addr1; /* Jump instructions that get retargeted */ | |
| 142481 | 142759 | int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */ |
| 142482 | 142760 | KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */ |
| 142483 | 142761 | KeyInfo *pKeyMerge; /* Comparison information for merging rows */ |
| 142484 | 142762 | sqlite3 *db; /* Database connection */ |
| 142485 | 142763 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| @@ -142844,15 +143122,18 @@ | ||
| 142844 | 143122 | pExpr->op = TK_NULL; |
| 142845 | 143123 | }else |
| 142846 | 143124 | #endif |
| 142847 | 143125 | { |
| 142848 | 143126 | Expr *pNew; |
| 142849 | - int iColumn = pExpr->iColumn; | |
| 142850 | - Expr *pCopy = pSubst->pEList->a[iColumn].pExpr; | |
| 143127 | + int iColumn; | |
| 143128 | + Expr *pCopy; | |
| 142851 | 143129 | Expr ifNullRow; |
| 143130 | + iColumn = pExpr->iColumn; | |
| 143131 | + assert( iColumn>=0 ); | |
| 142852 | 143132 | assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr ); |
| 142853 | 143133 | assert( pExpr->pRight==0 ); |
| 143134 | + pCopy = pSubst->pEList->a[iColumn].pExpr; | |
| 142854 | 143135 | if( sqlite3ExprIsVector(pCopy) ){ |
| 142855 | 143136 | sqlite3VectorErrorMsg(pSubst->pParse, pCopy); |
| 142856 | 143137 | }else{ |
| 142857 | 143138 | sqlite3 *db = pSubst->pParse->db; |
| 142858 | 143139 | if( pSubst->isOuterJoin |
| @@ -143197,11 +143478,11 @@ | ||
| 143197 | 143478 | ** (8) If the subquery uses LIMIT then the outer query may not be a join. |
| 143198 | 143479 | ** |
| 143199 | 143480 | ** (9) If the subquery uses LIMIT then the outer query may not be aggregate. |
| 143200 | 143481 | ** |
| 143201 | 143482 | ** (**) Restriction (10) was removed from the code on 2005-02-05 but we |
| 143202 | -** accidently carried the comment forward until 2014-09-15. Original | |
| 143483 | +** accidentally carried the comment forward until 2014-09-15. Original | |
| 143203 | 143484 | ** constraint: "If the subquery is aggregate then the outer query |
| 143204 | 143485 | ** may not use LIMIT." |
| 143205 | 143486 | ** |
| 143206 | 143487 | ** (11) The subquery and the outer query may not both have ORDER BY clauses. |
| 143207 | 143488 | ** |
| @@ -143471,11 +143752,11 @@ | ||
| 143471 | 143752 | pParse->zAuthContext = pSubitem->zName; |
| 143472 | 143753 | TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0); |
| 143473 | 143754 | testcase( i==SQLITE_DENY ); |
| 143474 | 143755 | pParse->zAuthContext = zSavedAuthContext; |
| 143475 | 143756 | |
| 143476 | - /* Delete the transient structures associated with thesubquery */ | |
| 143757 | + /* Delete the transient structures associated with the subquery */ | |
| 143477 | 143758 | pSub1 = pSubitem->pSelect; |
| 143478 | 143759 | sqlite3DbFree(db, pSubitem->zDatabase); |
| 143479 | 143760 | sqlite3DbFree(db, pSubitem->zName); |
| 143480 | 143761 | sqlite3DbFree(db, pSubitem->zAlias); |
| 143481 | 143762 | pSubitem->zDatabase = 0; |
| @@ -143653,11 +143934,11 @@ | ||
| 143653 | 143934 | if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){ |
| 143654 | 143935 | /* At this point, any non-zero iOrderByCol values indicate that the |
| 143655 | 143936 | ** ORDER BY column expression is identical to the iOrderByCol'th |
| 143656 | 143937 | ** expression returned by SELECT statement pSub. Since these values |
| 143657 | 143938 | ** do not necessarily correspond to columns in SELECT statement pParent, |
| 143658 | - ** zero them before transfering the ORDER BY clause. | |
| 143939 | + ** zero them before transferring the ORDER BY clause. | |
| 143659 | 143940 | ** |
| 143660 | 143941 | ** Not doing this may cause an error if a subsequent call to this |
| 143661 | 143942 | ** function attempts to flatten a compound sub-query into pParent |
| 143662 | 143943 | ** (the only way this can happen is if the compound sub-query is |
| 143663 | 143944 | ** currently part of pSub->pSrc). See ticket [d11a6e908f]. */ |
| @@ -143713,12 +143994,11 @@ | ||
| 143713 | 143994 | for(i=0; i<nSubSrc; i++){ |
| 143714 | 143995 | recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]); |
| 143715 | 143996 | } |
| 143716 | 143997 | } |
| 143717 | 143998 | |
| 143718 | - /* Finially, delete what is left of the subquery and return | |
| 143719 | - ** success. | |
| 143999 | + /* Finally, delete what is left of the subquery and return success. | |
| 143720 | 144000 | */ |
| 143721 | 144001 | sqlite3AggInfoPersistWalkerInit(&w, pParse); |
| 143722 | 144002 | sqlite3WalkSelect(&w,pSub1); |
| 143723 | 144003 | sqlite3SelectDelete(db, pSub1); |
| 143724 | 144004 | |
| @@ -143749,11 +144029,11 @@ | ||
| 143749 | 144029 | Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */ |
| 143750 | 144030 | }; |
| 143751 | 144031 | |
| 143752 | 144032 | /* |
| 143753 | 144033 | ** Add a new entry to the pConst object. Except, do not add duplicate |
| 143754 | -** pColumn entires. Also, do not add if doing so would not be appropriate. | |
| 144034 | +** pColumn entries. Also, do not add if doing so would not be appropriate. | |
| 143755 | 144035 | ** |
| 143756 | 144036 | ** The caller guarantees the pColumn is a column and pValue is a constant. |
| 143757 | 144037 | ** This routine has to do some additional checks before completing the |
| 143758 | 144038 | ** insert. |
| 143759 | 144039 | */ |
| @@ -143935,11 +144215,11 @@ | ||
| 143935 | 144215 | ** INSERT INTO t1 VALUES(123,'0123'); |
| 143936 | 144216 | ** SELECT * FROM t1 WHERE a=123 AND b=a; |
| 143937 | 144217 | ** SELECT * FROM t1 WHERE a=123 AND b=123; |
| 143938 | 144218 | ** |
| 143939 | 144219 | ** The two SELECT statements above should return different answers. b=a |
| 143940 | -** is alway true because the comparison uses numeric affinity, but b=123 | |
| 144220 | +** is always true because the comparison uses numeric affinity, but b=123 | |
| 143941 | 144221 | ** is false because it uses text affinity and '0123' is not the same as '123'. |
| 143942 | 144222 | ** To work around this, the expression tree is not actually changed from |
| 143943 | 144223 | ** "b=a" to "b=123" but rather the "a" in "b=a" is tagged with EP_FixedCol |
| 143944 | 144224 | ** and the "123" value is hung off of the pLeft pointer. Code generator |
| 143945 | 144225 | ** routines know to generate the constant "123" instead of looking up the |
| @@ -144019,11 +144299,11 @@ | ||
| 144019 | 144299 | ** this may change the results of the window functions. |
| 144020 | 144300 | ** |
| 144021 | 144301 | ** At the time this function is called it is guaranteed that |
| 144022 | 144302 | ** |
| 144023 | 144303 | ** * the sub-query uses only one distinct window frame, and |
| 144024 | -** * that the window frame has a PARTITION BY clase. | |
| 144304 | +** * that the window frame has a PARTITION BY clause. | |
| 144025 | 144305 | */ |
| 144026 | 144306 | static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){ |
| 144027 | 144307 | assert( pSubq->pWin->pPartition ); |
| 144028 | 144308 | assert( (pSubq->selFlags & SF_MultiPart)==0 ); |
| 144029 | 144309 | assert( pSubq->pPrior==0 ); |
| @@ -145527,11 +145807,11 @@ | ||
| 145527 | 145807 | assert( pExpr->iAgg>=0 ); |
| 145528 | 145808 | pCol = &pAggInfo->aCol[pExpr->iAgg]; |
| 145529 | 145809 | pExpr->op = TK_AGG_COLUMN; |
| 145530 | 145810 | pExpr->iTable = pCol->iTable; |
| 145531 | 145811 | pExpr->iColumn = pCol->iColumn; |
| 145532 | - ExprClearProperty(pExpr, EP_Skip|EP_Collate); | |
| 145812 | + ExprClearProperty(pExpr, EP_Skip|EP_Collate|EP_Unlikely); | |
| 145533 | 145813 | return WRC_Prune; |
| 145534 | 145814 | } |
| 145535 | 145815 | |
| 145536 | 145816 | /* |
| 145537 | 145817 | ** Convert every pAggInfo->aFunc[].pExpr such that any node within |
| @@ -145558,11 +145838,11 @@ | ||
| 145558 | 145838 | ** to calling this routine: |
| 145559 | 145839 | ** |
| 145560 | 145840 | ** * The aCol[] and aFunc[] arrays may be modified |
| 145561 | 145841 | ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used |
| 145562 | 145842 | ** |
| 145563 | -** After clling this routine: | |
| 145843 | +** After calling this routine: | |
| 145564 | 145844 | ** |
| 145565 | 145845 | ** * The aCol[] and aFunc[] arrays are fixed |
| 145566 | 145846 | ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may be used |
| 145567 | 145847 | ** |
| 145568 | 145848 | */ |
| @@ -146212,26 +146492,63 @@ | ||
| 146212 | 146492 | /* The expander should have already created transient Table objects |
| 146213 | 146493 | ** even for FROM clause elements such as subqueries that do not correspond |
| 146214 | 146494 | ** to a real table */ |
| 146215 | 146495 | assert( pTab!=0 ); |
| 146216 | 146496 | |
| 146217 | - /* Convert LEFT JOIN into JOIN if there are terms of the right table | |
| 146218 | - ** of the LEFT JOIN used in the WHERE clause. | |
| 146497 | + /* Try to simplify joins: | |
| 146498 | + ** | |
| 146499 | + ** LEFT JOIN -> JOIN | |
| 146500 | + ** RIGHT JOIN -> JOIN | |
| 146501 | + ** FULL JOIN -> RIGHT JOIN | |
| 146502 | + ** | |
| 146503 | + ** If terms of the i-th table are used in the WHERE clause in such a | |
| 146504 | + ** way that the i-th table cannot be the NULL row of a join, then | |
| 146505 | + ** perform the appropriate simplification. This is called | |
| 146506 | + ** "OUTER JOIN strength reduction" in the SQLite documentation. | |
| 146219 | 146507 | */ |
| 146220 | - if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==JT_LEFT | |
| 146221 | - && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor) | |
| 146508 | + if( (pItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 | |
| 146509 | + && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor, | |
| 146510 | + pItem->fg.jointype & JT_LTORJ) | |
| 146222 | 146511 | && OptimizationEnabled(db, SQLITE_SimplifyJoin) |
| 146223 | 146512 | ){ |
| 146224 | - TREETRACE(0x1000,pParse,p, | |
| 146225 | - ("LEFT-JOIN simplifies to JOIN on term %d\n",i)); | |
| 146226 | - pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER); | |
| 146513 | + if( pItem->fg.jointype & JT_LEFT ){ | |
| 146514 | + if( pItem->fg.jointype & JT_RIGHT ){ | |
| 146515 | + TREETRACE(0x1000,pParse,p, | |
| 146516 | + ("FULL-JOIN simplifies to RIGHT-JOIN on term %d\n",i)); | |
| 146517 | + pItem->fg.jointype &= ~JT_LEFT; | |
| 146518 | + }else{ | |
| 146519 | + TREETRACE(0x1000,pParse,p, | |
| 146520 | + ("LEFT-JOIN simplifies to JOIN on term %d\n",i)); | |
| 146521 | + pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER); | |
| 146522 | + } | |
| 146523 | + } | |
| 146524 | + if( pItem->fg.jointype & JT_LTORJ ){ | |
| 146525 | + for(j=i+1; j<pTabList->nSrc; j++){ | |
| 146526 | + SrcItem *pI2 = &pTabList->a[j]; | |
| 146527 | + if( pI2->fg.jointype & JT_RIGHT ){ | |
| 146528 | + if( pI2->fg.jointype & JT_LEFT ){ | |
| 146529 | + TREETRACE(0x1000,pParse,p, | |
| 146530 | + ("FULL-JOIN simplifies to LEFT-JOIN on term %d\n",j)); | |
| 146531 | + pI2->fg.jointype &= ~JT_RIGHT; | |
| 146532 | + }else{ | |
| 146533 | + TREETRACE(0x1000,pParse,p, | |
| 146534 | + ("RIGHT-JOIN simplifies to JOIN on term %d\n",j)); | |
| 146535 | + pI2->fg.jointype &= ~(JT_RIGHT|JT_OUTER); | |
| 146536 | + } | |
| 146537 | + } | |
| 146538 | + } | |
| 146539 | + for(j=pTabList->nSrc-1; j>=i; j--){ | |
| 146540 | + pTabList->a[j].fg.jointype &= ~JT_LTORJ; | |
| 146541 | + if( pTabList->a[j].fg.jointype & JT_RIGHT ) break; | |
| 146542 | + } | |
| 146543 | + } | |
| 146227 | 146544 | assert( pItem->iCursor>=0 ); |
| 146228 | 146545 | unsetJoinExpr(p->pWhere, pItem->iCursor, |
| 146229 | 146546 | pTabList->a[0].fg.jointype & JT_LTORJ); |
| 146230 | 146547 | } |
| 146231 | 146548 | |
| 146232 | - /* No futher action if this term of the FROM clause is not a subquery */ | |
| 146549 | + /* No further action if this term of the FROM clause is not a subquery */ | |
| 146233 | 146550 | if( pSub==0 ) continue; |
| 146234 | 146551 | |
| 146235 | 146552 | /* Catch mismatch in the declared columns of a view and the number of |
| 146236 | 146553 | ** columns in the SELECT on the RHS */ |
| 146237 | 146554 | if( pTab->nCol!=pSub->pEList->nExpr ){ |
| @@ -146481,11 +146798,11 @@ | ||
| 146481 | 146798 | sqlite3VdbeJumpHere(v, addrTop-1); |
| 146482 | 146799 | sqlite3ClearTempRegCache(pParse); |
| 146483 | 146800 | }else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){ |
| 146484 | 146801 | /* This is a CTE for which materialization code has already been |
| 146485 | 146802 | ** generated. Invoke the subroutine to compute the materialization, |
| 146486 | - ** the make the pItem->iCursor be a copy of the ephemerial table that | |
| 146803 | + ** the make the pItem->iCursor be a copy of the ephemeral table that | |
| 146487 | 146804 | ** holds the result of the materialization. */ |
| 146488 | 146805 | CteUse *pCteUse = pItem->u2.pCteUse; |
| 146489 | 146806 | sqlite3VdbeAddOp2(v, OP_Gosub, pCteUse->regRtn, pCteUse->addrM9e); |
| 146490 | 146807 | if( pItem->iCursor!=pCteUse->iCur ){ |
| 146491 | 146808 | sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur); |
| @@ -146864,11 +147181,11 @@ | ||
| 146864 | 147181 | /* Processing for aggregates with GROUP BY is very different and |
| 146865 | 147182 | ** much more complex than aggregates without a GROUP BY. |
| 146866 | 147183 | */ |
| 146867 | 147184 | if( pGroupBy ){ |
| 146868 | 147185 | KeyInfo *pKeyInfo; /* Keying information for the group by clause */ |
| 146869 | - int addr1; /* A-vs-B comparision jump */ | |
| 147186 | + int addr1; /* A-vs-B comparison jump */ | |
| 146870 | 147187 | int addrOutputRow; /* Start of subroutine that outputs a result row */ |
| 146871 | 147188 | int regOutputRow; /* Return address register for output subroutine */ |
| 146872 | 147189 | int addrSetAbort; /* Set the abort flag and return */ |
| 146873 | 147190 | int addrTopOfLoop; /* Top of the input loop */ |
| 146874 | 147191 | int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */ |
| @@ -149244,11 +149561,11 @@ | ||
| 149244 | 149561 | pSrc = sqlite3SrcListDup(db, pTabList, 0); |
| 149245 | 149562 | pWhere2 = sqlite3ExprDup(db, pWhere, 0); |
| 149246 | 149563 | |
| 149247 | 149564 | assert( pTabList->nSrc>1 ); |
| 149248 | 149565 | if( pSrc ){ |
| 149249 | - pSrc->a[0].fg.notCte = 1; | |
| 149566 | + assert( pSrc->a[0].fg.notCte ); | |
| 149250 | 149567 | pSrc->a[0].iCursor = -1; |
| 149251 | 149568 | pSrc->a[0].pTab->nTabRef--; |
| 149252 | 149569 | pSrc->a[0].pTab = 0; |
| 149253 | 149570 | } |
| 149254 | 149571 | if( pPk ){ |
| @@ -150231,11 +150548,11 @@ | ||
| 150231 | 150548 | const char *pVTab = (const char*)sqlite3GetVTable(db, pTab); |
| 150232 | 150549 | WhereInfo *pWInfo = 0; |
| 150233 | 150550 | int nArg = 2 + pTab->nCol; /* Number of arguments to VUpdate */ |
| 150234 | 150551 | int regArg; /* First register in VUpdate arg array */ |
| 150235 | 150552 | int regRec; /* Register in which to assemble record */ |
| 150236 | - int regRowid; /* Register for ephem table rowid */ | |
| 150553 | + int regRowid; /* Register for ephemeral table rowid */ | |
| 150237 | 150554 | int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */ |
| 150238 | 150555 | int aDummy[2]; /* Unused arg for sqlite3WhereOkOnePass() */ |
| 150239 | 150556 | int eOnePass; /* True to use onepass strategy */ |
| 150240 | 150557 | int addr; /* Address of OP_OpenEphemeral */ |
| 150241 | 150558 | |
| @@ -150352,11 +150669,11 @@ | ||
| 150352 | 150669 | /* End the virtual table scan */ |
| 150353 | 150670 | if( pSrc->nSrc==1 ){ |
| 150354 | 150671 | sqlite3WhereEnd(pWInfo); |
| 150355 | 150672 | } |
| 150356 | 150673 | |
| 150357 | - /* Begin scannning through the ephemeral table. */ | |
| 150674 | + /* Begin scanning through the ephemeral table. */ | |
| 150358 | 150675 | addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v); |
| 150359 | 150676 | |
| 150360 | 150677 | /* Extract arguments from the current row of the ephemeral table and |
| 150361 | 150678 | ** invoke the VUpdate method. */ |
| 150362 | 150679 | for(i=0; i<nArg; i++){ |
| @@ -150909,11 +151226,11 @@ | ||
| 150909 | 151226 | ** can be set to 'off' for this file, as it is not recovered if a crash |
| 150910 | 151227 | ** occurs anyway. The integrity of the database is maintained by a |
| 150911 | 151228 | ** (possibly synchronous) transaction opened on the main database before |
| 150912 | 151229 | ** sqlite3BtreeCopyFile() is called. |
| 150913 | 151230 | ** |
| 150914 | - ** An optimisation would be to use a non-journaled pager. | |
| 151231 | + ** An optimization would be to use a non-journaled pager. | |
| 150915 | 151232 | ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but |
| 150916 | 151233 | ** that actually made the VACUUM run slower. Very little journalling |
| 150917 | 151234 | ** actually occurs when doing a vacuum since the vacuum_db is initially |
| 150918 | 151235 | ** empty. Only the journal header is written. Apparently it takes more |
| 150919 | 151236 | ** time to parse and run the PRAGMA to turn journalling off than it does |
| @@ -151598,11 +151915,11 @@ | ||
| 151598 | 151915 | /* A slot for the record has already been allocated in the |
| 151599 | 151916 | ** schema table. We just need to update that slot with all |
| 151600 | 151917 | ** the information we've collected. |
| 151601 | 151918 | ** |
| 151602 | 151919 | ** The VM register number pParse->regRowid holds the rowid of an |
| 151603 | - ** entry in the sqlite_schema table tht was created for this vtab | |
| 151920 | + ** entry in the sqlite_schema table that was created for this vtab | |
| 151604 | 151921 | ** by sqlite3StartTable(). |
| 151605 | 151922 | */ |
| 151606 | 151923 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 151607 | 151924 | sqlite3NestedParse(pParse, |
| 151608 | 151925 | "UPDATE %Q." LEGACY_SCHEMA_TABLE " " |
| @@ -152342,11 +152659,11 @@ | ||
| 152342 | 152659 | ** exists when this routine returns or if an attempt to create it failed |
| 152343 | 152660 | ** and an error message was left in pParse. |
| 152344 | 152661 | ** |
| 152345 | 152662 | ** An eponymous virtual table instance is one that is named after its |
| 152346 | 152663 | ** module, and more importantly, does not require a CREATE VIRTUAL TABLE |
| 152347 | -** statement in order to come into existance. Eponymous virtual table | |
| 152664 | +** statement in order to come into existence. Eponymous virtual table | |
| 152348 | 152665 | ** instances always exist. They cannot be DROP-ed. |
| 152349 | 152666 | ** |
| 152350 | 152667 | ** Any virtual table module for which xConnect and xCreate are the same |
| 152351 | 152668 | ** method can have an eponymous virtual table instance. |
| 152352 | 152669 | */ |
| @@ -152533,11 +152850,11 @@ | ||
| 152533 | 152850 | typedef struct WhereMemBlock WhereMemBlock; |
| 152534 | 152851 | typedef struct WhereRightJoin WhereRightJoin; |
| 152535 | 152852 | |
| 152536 | 152853 | /* |
| 152537 | 152854 | ** This object is a header on a block of allocated memory that will be |
| 152538 | -** automatically freed when its WInfo oject is destructed. | |
| 152855 | +** automatically freed when its WInfo object is destructed. | |
| 152539 | 152856 | */ |
| 152540 | 152857 | struct WhereMemBlock { |
| 152541 | 152858 | WhereMemBlock *pNext; /* Next block in the chain */ |
| 152542 | 152859 | u64 sz; /* Bytes of space */ |
| 152543 | 152860 | }; |
| @@ -152594,11 +152911,11 @@ | ||
| 152594 | 152911 | int nIn; /* Number of entries in aInLoop[] */ |
| 152595 | 152912 | struct InLoop { |
| 152596 | 152913 | int iCur; /* The VDBE cursor used by this IN operator */ |
| 152597 | 152914 | int addrInTop; /* Top of the IN loop */ |
| 152598 | 152915 | int iBase; /* Base register of multi-key index record */ |
| 152599 | - int nPrefix; /* Number of prior entires in the key */ | |
| 152916 | + int nPrefix; /* Number of prior entries in the key */ | |
| 152600 | 152917 | u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */ |
| 152601 | 152918 | } *aInLoop; /* Information about each nested IN operator */ |
| 152602 | 152919 | } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ |
| 152603 | 152920 | Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */ |
| 152604 | 152921 | } u; |
| @@ -152844,11 +153161,11 @@ | ||
| 152844 | 153161 | u8 op; /* Split operator. TK_AND or TK_OR */ |
| 152845 | 153162 | u8 hasOr; /* True if any a[].eOperator is WO_OR */ |
| 152846 | 153163 | int nTerm; /* Number of terms */ |
| 152847 | 153164 | int nSlot; /* Number of entries in a[] */ |
| 152848 | 153165 | int nBase; /* Number of terms through the last non-Virtual */ |
| 152849 | - WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */ | |
| 153166 | + WhereTerm *a; /* Each a[] describes a term of the WHERE clause */ | |
| 152850 | 153167 | #if defined(SQLITE_SMALL_STACK) |
| 152851 | 153168 | WhereTerm aStatic[1]; /* Initial static space for a[] */ |
| 152852 | 153169 | #else |
| 152853 | 153170 | WhereTerm aStatic[8]; /* Initial static space for a[] */ |
| 152854 | 153171 | #endif |
| @@ -153929,11 +154246,11 @@ | ||
| 153929 | 154246 | assert( pIdx!=0 ); |
| 153930 | 154247 | |
| 153931 | 154248 | /* Figure out how many memory cells we will need then allocate them. |
| 153932 | 154249 | */ |
| 153933 | 154250 | regBase = pParse->nMem + 1; |
| 153934 | - nReg = pLoop->u.btree.nEq + nExtraReg; | |
| 154251 | + nReg = nEq + nExtraReg; | |
| 153935 | 154252 | pParse->nMem += nReg; |
| 153936 | 154253 | |
| 153937 | 154254 | zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx)); |
| 153938 | 154255 | assert( zAff!=0 || pParse->db->mallocFailed ); |
| 153939 | 154256 | |
| @@ -153976,13 +154293,10 @@ | ||
| 153976 | 154293 | regBase = r1; |
| 153977 | 154294 | }else{ |
| 153978 | 154295 | sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j); |
| 153979 | 154296 | } |
| 153980 | 154297 | } |
| 153981 | - } | |
| 153982 | - for(j=nSkip; j<nEq; j++){ | |
| 153983 | - pTerm = pLoop->aLTerm[j]; | |
| 153984 | 154298 | if( pTerm->eOperator & WO_IN ){ |
| 153985 | 154299 | if( pTerm->pExpr->flags & EP_xIsSelect ){ |
| 153986 | 154300 | /* No affinity ever needs to be (or should be) applied to a value |
| 153987 | 154301 | ** from the RHS of an "? IN (SELECT ...)" expression. The |
| 153988 | 154302 | ** sqlite3FindInIndex() routine has already ensured that the |
| @@ -154121,11 +154435,11 @@ | ||
| 154121 | 154435 | ** the specified column into the new register, and |
| 154122 | 154436 | ** |
| 154123 | 154437 | ** 2) transform the expression node to a TK_REGISTER node that reads |
| 154124 | 154438 | ** from the newly populated register. |
| 154125 | 154439 | ** |
| 154126 | -** Also, if the node is a TK_COLUMN that does access the table idenified | |
| 154440 | +** Also, if the node is a TK_COLUMN that does access the table identified | |
| 154127 | 154441 | ** by pCCurHint.iTabCur, and an index is being used (which we will |
| 154128 | 154442 | ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into |
| 154129 | 154443 | ** an access of the index rather than the original table. |
| 154130 | 154444 | */ |
| 154131 | 154445 | static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){ |
| @@ -154739,11 +155053,11 @@ | ||
| 154739 | 155053 | /* TK_LT */ OP_SeekLT, |
| 154740 | 155054 | /* TK_GE */ OP_SeekGE |
| 154741 | 155055 | }; |
| 154742 | 155056 | assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */ |
| 154743 | 155057 | assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */ |
| 154744 | - assert( TK_GE==TK_GT+3 ); /* ... is correcct. */ | |
| 155058 | + assert( TK_GE==TK_GT+3 ); /* ... is correct. */ | |
| 154745 | 155059 | |
| 154746 | 155060 | assert( (pStart->wtFlags & TERM_VNULL)==0 ); |
| 154747 | 155061 | testcase( pStart->wtFlags & TERM_VIRTUAL ); |
| 154748 | 155062 | pX = pStart->pExpr; |
| 154749 | 155063 | assert( pX!=0 ); |
| @@ -155919,11 +156233,11 @@ | ||
| 155919 | 156233 | ************************************************************************* |
| 155920 | 156234 | ** This module contains C code that generates VDBE code used to process |
| 155921 | 156235 | ** the WHERE clause of SQL statements. |
| 155922 | 156236 | ** |
| 155923 | 156237 | ** This file was originally part of where.c but was split out to improve |
| 155924 | -** readability and editabiliity. This file contains utility routines for | |
| 156238 | +** readability and editability. This file contains utility routines for | |
| 155925 | 156239 | ** analyzing Expr objects in the WHERE clause. |
| 155926 | 156240 | */ |
| 155927 | 156241 | /* #include "sqliteInt.h" */ |
| 155928 | 156242 | /* #include "whereInt.h" */ |
| 155929 | 156243 | |
| @@ -156708,11 +157022,11 @@ | ||
| 156708 | 157022 | } |
| 156709 | 157023 | if( (chngToIN & sqlite3WhereGetMask(&pWInfo->sMaskSet, |
| 156710 | 157024 | pOrTerm->leftCursor))==0 ){ |
| 156711 | 157025 | /* This term must be of the form t1.a==t2.b where t2 is in the |
| 156712 | 157026 | ** chngToIN set but t1 is not. This term will be either preceded |
| 156713 | - ** or follwed by an inverted copy (t2.b==t1.a). Skip this term | |
| 157027 | + ** or followed by an inverted copy (t2.b==t1.a). Skip this term | |
| 156714 | 157028 | ** and use its inversion. */ |
| 156715 | 157029 | testcase( pOrTerm->wtFlags & TERM_COPIED ); |
| 156716 | 157030 | testcase( pOrTerm->wtFlags & TERM_VIRTUAL ); |
| 156717 | 157031 | assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) ); |
| 156718 | 157032 | continue; |
| @@ -156970,12 +157284,12 @@ | ||
| 156970 | 157284 | ){ |
| 156971 | 157285 | WhereInfo *pWInfo = pWC->pWInfo; /* WHERE clause processing context */ |
| 156972 | 157286 | WhereTerm *pTerm; /* The term to be analyzed */ |
| 156973 | 157287 | WhereMaskSet *pMaskSet; /* Set of table index masks */ |
| 156974 | 157288 | Expr *pExpr; /* The expression to be analyzed */ |
| 156975 | - Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */ | |
| 156976 | - Bitmask prereqAll; /* Prerequesites of pExpr */ | |
| 157289 | + Bitmask prereqLeft; /* Prerequisites of the pExpr->pLeft */ | |
| 157290 | + Bitmask prereqAll; /* Prerequisites of pExpr */ | |
| 156977 | 157291 | Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */ |
| 156978 | 157292 | Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */ |
| 156979 | 157293 | int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */ |
| 156980 | 157294 | int noCase = 0; /* uppercase equivalent to lowercase */ |
| 156981 | 157295 | int op; /* Top-level operator. pExpr->op */ |
| @@ -159532,11 +159846,11 @@ | ||
| 159532 | 159846 | ** SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?; |
| 159533 | 159847 | ** |
| 159534 | 159848 | ** Value pLoop->nOut is currently set to the estimated number of rows |
| 159535 | 159849 | ** visited for scanning (a=? AND b=?). This function reduces that estimate |
| 159536 | 159850 | ** by some factor to account for the (c BETWEEN ? AND ?) expression based |
| 159537 | -** on the stat4 data for the index. this scan will be peformed multiple | |
| 159851 | +** on the stat4 data for the index. this scan will be performed multiple | |
| 159538 | 159852 | ** times (once for each (a,b) combination that matches a=?) is dealt with |
| 159539 | 159853 | ** by the caller. |
| 159540 | 159854 | ** |
| 159541 | 159855 | ** It does this by scanning through all stat4 samples, comparing values |
| 159542 | 159856 | ** extracted from pLower and pUpper with the corresponding column in each |
| @@ -160287,11 +160601,11 @@ | ||
| 160287 | 160601 | /* whereLoopAddBtree() always generates and inserts the automatic index |
| 160288 | 160602 | ** case first. Hence compatible candidate WhereLoops never have a larger |
| 160289 | 160603 | ** rSetup. Call this SETUP-INVARIANT */ |
| 160290 | 160604 | assert( p->rSetup>=pTemplate->rSetup ); |
| 160291 | 160605 | |
| 160292 | - /* Any loop using an appliation-defined index (or PRIMARY KEY or | |
| 160606 | + /* Any loop using an application-defined index (or PRIMARY KEY or | |
| 160293 | 160607 | ** UNIQUE constraint) with one or more == constraints is better |
| 160294 | 160608 | ** than an automatic index. Unless it is a skip-scan. */ |
| 160295 | 160609 | if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 |
| 160296 | 160610 | && (pTemplate->nSkip)==0 |
| 160297 | 160611 | && (pTemplate->wsFlags & WHERE_INDEXED)!=0 |
| @@ -160432,11 +160746,11 @@ | ||
| 160432 | 160746 | whereLoopInit(p); |
| 160433 | 160747 | p->pNextLoop = 0; |
| 160434 | 160748 | }else{ |
| 160435 | 160749 | /* We will be overwriting WhereLoop p[]. But before we do, first |
| 160436 | 160750 | ** go through the rest of the list and delete any other entries besides |
| 160437 | - ** p[] that are also supplated by pTemplate */ | |
| 160751 | + ** p[] that are also supplanted by pTemplate */ | |
| 160438 | 160752 | WhereLoop **ppTail = &p->pNextLoop; |
| 160439 | 160753 | WhereLoop *pToDel; |
| 160440 | 160754 | while( *ppTail ){ |
| 160441 | 160755 | ppTail = whereLoopFindLesser(ppTail, pTemplate); |
| 160442 | 160756 | if( ppTail==0 ) break; |
| @@ -160632,11 +160946,11 @@ | ||
| 160632 | 160946 | } |
| 160633 | 160947 | return i; |
| 160634 | 160948 | } |
| 160635 | 160949 | |
| 160636 | 160950 | /* |
| 160637 | -** Adjust the cost C by the costMult facter T. This only occurs if | |
| 160951 | +** Adjust the cost C by the costMult factor T. This only occurs if | |
| 160638 | 160952 | ** compiled with -DSQLITE_ENABLE_COSTMULT |
| 160639 | 160953 | */ |
| 160640 | 160954 | #ifdef SQLITE_ENABLE_COSTMULT |
| 160641 | 160955 | # define ApplyCostMultiplier(C,T) C += T |
| 160642 | 160956 | #else |
| @@ -160659,11 +160973,11 @@ | ||
| 160659 | 160973 | WhereLoopBuilder *pBuilder, /* The WhereLoop factory */ |
| 160660 | 160974 | SrcItem *pSrc, /* FROM clause term being analyzed */ |
| 160661 | 160975 | Index *pProbe, /* An index on pSrc */ |
| 160662 | 160976 | LogEst nInMul /* log(Number of iterations due to IN) */ |
| 160663 | 160977 | ){ |
| 160664 | - WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyse context */ | |
| 160978 | + WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyze context */ | |
| 160665 | 160979 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 160666 | 160980 | sqlite3 *db = pParse->db; /* Database connection malloc context */ |
| 160667 | 160981 | WhereLoop *pNew; /* Template WhereLoop under construction */ |
| 160668 | 160982 | WhereTerm *pTerm; /* A WhereTerm under consideration */ |
| 160669 | 160983 | int opMask; /* Valid operators for constraints */ |
| @@ -160969,11 +161283,11 @@ | ||
| 160969 | 161283 | ** seek only. Then, if this is a non-covering index, add the cost of |
| 160970 | 161284 | ** visiting the rows in the main table. */ |
| 160971 | 161285 | assert( pSrc->pTab->szTabRow>0 ); |
| 160972 | 161286 | if( pProbe->idxType==SQLITE_IDXTYPE_IPK ){ |
| 160973 | 161287 | /* The pProbe->szIdxRow is low for an IPK table since the interior |
| 160974 | - ** pages are small. Thuse szIdxRow gives a good estimate of seek cost. | |
| 161288 | + ** pages are small. Thus szIdxRow gives a good estimate of seek cost. | |
| 160975 | 161289 | ** But the leaf pages are full-size, so pProbe->szIdxRow would badly |
| 160976 | 161290 | ** under-estimate the scanning cost. */ |
| 160977 | 161291 | rCostIdx = pNew->nOut + 16; |
| 160978 | 161292 | }else{ |
| 160979 | 161293 | rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow; |
| @@ -161314,11 +161628,11 @@ | ||
| 161314 | 161628 | ** performance of using an index is far better than the worst-case performance |
| 161315 | 161629 | ** of a full table scan. |
| 161316 | 161630 | */ |
| 161317 | 161631 | static int whereLoopAddBtree( |
| 161318 | 161632 | WhereLoopBuilder *pBuilder, /* WHERE clause information */ |
| 161319 | - Bitmask mPrereq /* Extra prerequesites for using this table */ | |
| 161633 | + Bitmask mPrereq /* Extra prerequisites for using this table */ | |
| 161320 | 161634 | ){ |
| 161321 | 161635 | WhereInfo *pWInfo; /* WHERE analysis context */ |
| 161322 | 161636 | Index *pProbe; /* An index we are evaluating */ |
| 161323 | 161637 | Index sPk; /* A fake index object for the primary key */ |
| 161324 | 161638 | LogEst aiRowEstPk[2]; /* The aiRowLogEst[] value for the sPk index */ |
| @@ -161821,11 +162135,11 @@ | ||
| 161821 | 162135 | ** This routine depends on there being a HiddenIndexInfo structure immediately |
| 161822 | 162136 | ** following the sqlite3_index_info structure. |
| 161823 | 162137 | ** |
| 161824 | 162138 | ** Return a pointer to the collation name: |
| 161825 | 162139 | ** |
| 161826 | -** 1. If there is an explicit COLLATE operator on the constaint, return it. | |
| 162140 | +** 1. If there is an explicit COLLATE operator on the constraint, return it. | |
| 161827 | 162141 | ** |
| 161828 | 162142 | ** 2. Else, if the column has an alternative collation, return that. |
| 161829 | 162143 | ** |
| 161830 | 162144 | ** 3. Otherwise, return "BINARY". |
| 161831 | 162145 | */ |
| @@ -162885,11 +163199,11 @@ | ||
| 162885 | 163199 | aSortCost[isOrdered] = whereSortingCost( |
| 162886 | 163200 | pWInfo, nRowEst, nOrderBy, isOrdered |
| 162887 | 163201 | ); |
| 162888 | 163202 | } |
| 162889 | 163203 | /* TUNING: Add a small extra penalty (3) to sorting as an |
| 162890 | - ** extra encouragment to the query planner to select a plan | |
| 163204 | + ** extra encouragement to the query planner to select a plan | |
| 162891 | 163205 | ** where the rows emerge in the correct order without any sorting |
| 162892 | 163206 | ** required. */ |
| 162893 | 163207 | rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 3; |
| 162894 | 163208 | |
| 162895 | 163209 | WHERETRACE(0x002, |
| @@ -163593,11 +163907,11 @@ | ||
| 163593 | 163907 | ** inner loops (or around the "..." if the test occurs within the inner- |
| 163594 | 163908 | ** most loop) |
| 163595 | 163909 | ** |
| 163596 | 163910 | ** OUTER JOINS |
| 163597 | 163911 | ** |
| 163598 | -** An outer join of tables t1 and t2 is conceptally coded as follows: | |
| 163912 | +** An outer join of tables t1 and t2 is conceptually coded as follows: | |
| 163599 | 163913 | ** |
| 163600 | 163914 | ** foreach row1 in t1 do |
| 163601 | 163915 | ** flag = 0 |
| 163602 | 163916 | ** foreach row2 in t2 do |
| 163603 | 163917 | ** start: |
| @@ -163748,11 +164062,11 @@ | ||
| 163748 | 164062 | }else{ |
| 163749 | 164063 | /* Assign a bit from the bitmask to every term in the FROM clause. |
| 163750 | 164064 | ** |
| 163751 | 164065 | ** The N-th term of the FROM clause is assigned a bitmask of 1<<N. |
| 163752 | 164066 | ** |
| 163753 | - ** The rule of the previous sentence ensures thta if X is the bitmask for | |
| 164067 | + ** The rule of the previous sentence ensures that if X is the bitmask for | |
| 163754 | 164068 | ** a table T, then X-1 is the bitmask for all other tables to the left of T. |
| 163755 | 164069 | ** Knowing the bitmask for all tables to the left of a left join is |
| 163756 | 164070 | ** important. Ticket #3015. |
| 163757 | 164071 | ** |
| 163758 | 164072 | ** Note that bitmasks are created for all pTabList->nSrc tables in |
| @@ -164729,11 +165043,11 @@ | ||
| 164729 | 165043 | ** last_value(expr) |
| 164730 | 165044 | ** nth_value(expr, N) |
| 164731 | 165045 | ** |
| 164732 | 165046 | ** These are the same built-in window functions supported by Postgres. |
| 164733 | 165047 | ** Although the behaviour of aggregate window functions (functions that |
| 164734 | -** can be used as either aggregates or window funtions) allows them to | |
| 165048 | +** can be used as either aggregates or window functions) allows them to | |
| 164735 | 165049 | ** be implemented using an API, built-in window functions are much more |
| 164736 | 165050 | ** esoteric. Additionally, some window functions (e.g. nth_value()) |
| 164737 | 165051 | ** may only be implemented by caching the entire partition in memory. |
| 164738 | 165052 | ** As such, some built-in window functions use the same API as aggregate |
| 164739 | 165053 | ** window functions and some are implemented directly using VDBE |
| @@ -165259,11 +165573,11 @@ | ||
| 165259 | 165573 | ** linked list of WINDOW definitions for the current SELECT statement. |
| 165260 | 165574 | ** Argument pFunc is the function definition just resolved and pWin |
| 165261 | 165575 | ** is the Window object representing the associated OVER clause. This |
| 165262 | 165576 | ** function updates the contents of pWin as follows: |
| 165263 | 165577 | ** |
| 165264 | -** * If the OVER clause refered to a named window (as in "max(x) OVER win"), | |
| 165578 | +** * If the OVER clause referred to a named window (as in "max(x) OVER win"), | |
| 165265 | 165579 | ** search list pList for a matching WINDOW definition, and update pWin |
| 165266 | 165580 | ** accordingly. If no such WINDOW clause can be found, leave an error |
| 165267 | 165581 | ** in pParse. |
| 165268 | 165582 | ** |
| 165269 | 165583 | ** * If the function is a built-in window function that requires the |
| @@ -165880,11 +166194,11 @@ | ||
| 165880 | 166194 | } |
| 165881 | 166195 | return pWin; |
| 165882 | 166196 | } |
| 165883 | 166197 | |
| 165884 | 166198 | /* |
| 165885 | -** Window *pWin has just been created from a WINDOW clause. Tokne pBase | |
| 166199 | +** Window *pWin has just been created from a WINDOW clause. Token pBase | |
| 165886 | 166200 | ** is the base window. Earlier windows from the same WINDOW clause are |
| 165887 | 166201 | ** stored in the linked list starting at pWin->pNextWin. This function |
| 165888 | 166202 | ** either updates *pWin according to the base specification, or else |
| 165889 | 166203 | ** leaves an error in pParse. |
| 165890 | 166204 | */ |
| @@ -166186,11 +166500,11 @@ | ||
| 166186 | 166500 | ** start,current,end |
| 166187 | 166501 | ** Consider a window-frame similar to the following: |
| 166188 | 166502 | ** |
| 166189 | 166503 | ** (ORDER BY a, b GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING) |
| 166190 | 166504 | ** |
| 166191 | -** The windows functions implmentation caches the input rows in a temp | |
| 166505 | +** The windows functions implementation caches the input rows in a temp | |
| 166192 | 166506 | ** table, sorted by "a, b" (it actually populates the cache lazily, and |
| 166193 | 166507 | ** aggressively removes rows once they are no longer required, but that's |
| 166194 | 166508 | ** a mere detail). It keeps three cursors open on the temp table. One |
| 166195 | 166509 | ** (current) that points to the next row to return to the query engine |
| 166196 | 166510 | ** once its window function values have been calculated. Another (end) |
| @@ -167195,11 +167509,11 @@ | ||
| 167195 | 167509 | ** RETURN_ROW |
| 167196 | 167510 | ** } |
| 167197 | 167511 | ** |
| 167198 | 167512 | ** For the most part, the patterns above are adapted to support UNBOUNDED by |
| 167199 | 167513 | ** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and |
| 167200 | -** CURRENT ROW by assuming that it is equivilent to "0 PRECEDING/FOLLOWING". | |
| 167514 | +** CURRENT ROW by assuming that it is equivalent to "0 PRECEDING/FOLLOWING". | |
| 167201 | 167515 | ** This is optimized of course - branches that will never be taken and |
| 167202 | 167516 | ** conditions that are always true are omitted from the VM code. The only |
| 167203 | 167517 | ** exceptional case is: |
| 167204 | 167518 | ** |
| 167205 | 167519 | ** ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING |
| @@ -167474,11 +167788,11 @@ | ||
| 167474 | 167788 | s.eDelete = WINDOW_AGGINVERSE; |
| 167475 | 167789 | break; |
| 167476 | 167790 | } |
| 167477 | 167791 | |
| 167478 | 167792 | /* Allocate registers for the array of values from the sub-query, the |
| 167479 | - ** samve values in record form, and the rowid used to insert said record | |
| 167793 | + ** same values in record form, and the rowid used to insert said record | |
| 167480 | 167794 | ** into the ephemeral table. */ |
| 167481 | 167795 | regNew = pParse->nMem+1; |
| 167482 | 167796 | pParse->nMem += nInput; |
| 167483 | 167797 | regRecord = ++pParse->nMem; |
| 167484 | 167798 | s.regRowid = ++pParse->nMem; |
| @@ -167715,11 +168029,12 @@ | ||
| 167715 | 168029 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 167716 | 168030 | |
| 167717 | 168031 | /************** End of window.c **********************************************/ |
| 167718 | 168032 | /************** Begin file parse.c *******************************************/ |
| 167719 | 168033 | /* This file is automatically generated by Lemon from input grammar |
| 167720 | -** source file "parse.y". */ | |
| 168034 | +** source file "parse.y". | |
| 168035 | +*/ | |
| 167721 | 168036 | /* |
| 167722 | 168037 | ** 2001-09-15 |
| 167723 | 168038 | ** |
| 167724 | 168039 | ** The author disclaims copyright to this source code. In place of |
| 167725 | 168040 | ** a legal notice, here is a blessing: |
| @@ -167732,11 +168047,11 @@ | ||
| 167732 | 168047 | ** This file contains SQLite's SQL parser. |
| 167733 | 168048 | ** |
| 167734 | 168049 | ** The canonical source code to this file ("parse.y") is a Lemon grammar |
| 167735 | 168050 | ** file that specifies the input grammar and actions to take while parsing. |
| 167736 | 168051 | ** That input file is processed by Lemon to generate a C-language |
| 167737 | -** implementation of a parser for the given grammer. You might be reading | |
| 168052 | +** implementation of a parser for the given grammar. You might be reading | |
| 167738 | 168053 | ** this comment as part of the translated C-code. Edits should be made |
| 167739 | 168054 | ** to the original parse.y sources. |
| 167740 | 168055 | */ |
| 167741 | 168056 | |
| 167742 | 168057 | /* #include "sqliteInt.h" */ |
| @@ -174928,16 +175243,10 @@ | ||
| 174928 | 175243 | |
| 174929 | 175244 | /* |
| 174930 | 175245 | ** Forward declarations of external module initializer functions |
| 174931 | 175246 | ** for modules that need them. |
| 174932 | 175247 | */ |
| 174933 | -#ifdef SQLITE_ENABLE_FTS1 | |
| 174934 | -SQLITE_PRIVATE int sqlite3Fts1Init(sqlite3*); | |
| 174935 | -#endif | |
| 174936 | -#ifdef SQLITE_ENABLE_FTS2 | |
| 174937 | -SQLITE_PRIVATE int sqlite3Fts2Init(sqlite3*); | |
| 174938 | -#endif | |
| 174939 | 175248 | #ifdef SQLITE_ENABLE_FTS5 |
| 174940 | 175249 | SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*); |
| 174941 | 175250 | #endif |
| 174942 | 175251 | #ifdef SQLITE_ENABLE_STMTVTAB |
| 174943 | 175252 | SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3*); |
| @@ -174946,16 +175255,10 @@ | ||
| 174946 | 175255 | /* |
| 174947 | 175256 | ** An array of pointers to extension initializer functions for |
| 174948 | 175257 | ** built-in extensions. |
| 174949 | 175258 | */ |
| 174950 | 175259 | static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = { |
| 174951 | -#ifdef SQLITE_ENABLE_FTS1 | |
| 174952 | - sqlite3Fts1Init, | |
| 174953 | -#endif | |
| 174954 | -#ifdef SQLITE_ENABLE_FTS2 | |
| 174955 | - sqlite3Fts2Init, | |
| 174956 | -#endif | |
| 174957 | 175260 | #ifdef SQLITE_ENABLE_FTS3 |
| 174958 | 175261 | sqlite3Fts3Init, |
| 174959 | 175262 | #endif |
| 174960 | 175263 | #ifdef SQLITE_ENABLE_FTS5 |
| 174961 | 175264 | sqlite3Fts5Init, |
| @@ -178204,11 +178507,11 @@ | ||
| 178204 | 178507 | ** 2 on off |
| 178205 | 178508 | ** 1 off on |
| 178206 | 178509 | ** 0 off off |
| 178207 | 178510 | ** |
| 178208 | 178511 | ** Legacy behavior is 3 (double-quoted string literals are allowed anywhere) |
| 178209 | -** and so that is the default. But developers are encouranged to use | |
| 178512 | +** and so that is the default. But developers are encouraged to use | |
| 178210 | 178513 | ** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible. |
| 178211 | 178514 | */ |
| 178212 | 178515 | #if !defined(SQLITE_DQS) |
| 178213 | 178516 | # define SQLITE_DQS 3 |
| 178214 | 178517 | #endif |
| @@ -178739,11 +179042,11 @@ | ||
| 178739 | 179042 | goto error_out; |
| 178740 | 179043 | } |
| 178741 | 179044 | |
| 178742 | 179045 | /* Find the column for which info is requested */ |
| 178743 | 179046 | if( zColumnName==0 ){ |
| 178744 | - /* Query for existance of table only */ | |
| 179047 | + /* Query for existence of table only */ | |
| 178745 | 179048 | }else{ |
| 178746 | 179049 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 178747 | 179050 | pCol = &pTab->aCol[iCol]; |
| 178748 | 179051 | if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){ |
| 178749 | 179052 | break; |
| @@ -179179,11 +179482,11 @@ | ||
| 179179 | 179482 | ** |
| 179180 | 179483 | ** Set or clear a flag that indicates that the database file is always well- |
| 179181 | 179484 | ** formed and never corrupt. This flag is clear by default, indicating that |
| 179182 | 179485 | ** database files might have arbitrary corruption. Setting the flag during |
| 179183 | 179486 | ** testing causes certain assert() statements in the code to be activated |
| 179184 | - ** that demonstrat invariants on well-formed database files. | |
| 179487 | + ** that demonstrate invariants on well-formed database files. | |
| 179185 | 179488 | */ |
| 179186 | 179489 | case SQLITE_TESTCTRL_NEVER_CORRUPT: { |
| 179187 | 179490 | sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int); |
| 179188 | 179491 | break; |
| 179189 | 179492 | } |
| @@ -179333,11 +179636,11 @@ | ||
| 179333 | 179636 | ** |
| 179334 | 179637 | ** "ptr" is a pointer to a u32. |
| 179335 | 179638 | ** |
| 179336 | 179639 | ** op==0 Store the current sqlite3TreeTrace in *ptr |
| 179337 | 179640 | ** op==1 Set sqlite3TreeTrace to the value *ptr |
| 179338 | - ** op==3 Store the current sqlite3WhereTrace in *ptr | |
| 179641 | + ** op==2 Store the current sqlite3WhereTrace in *ptr | |
| 179339 | 179642 | ** op==3 Set sqlite3WhereTrace to the value *ptr |
| 179340 | 179643 | */ |
| 179341 | 179644 | case SQLITE_TESTCTRL_TRACEFLAGS: { |
| 179342 | 179645 | int opTrace = va_arg(ap, int); |
| 179343 | 179646 | u32 *ptr = va_arg(ap, u32*); |
| @@ -179669,11 +179972,11 @@ | ||
| 179669 | 179972 | #endif /* SQLITE_OMIT_WAL */ |
| 179670 | 179973 | return rc; |
| 179671 | 179974 | } |
| 179672 | 179975 | |
| 179673 | 179976 | /* |
| 179674 | -** Open a read-transaction on the snapshot idendified by pSnapshot. | |
| 179977 | +** Open a read-transaction on the snapshot identified by pSnapshot. | |
| 179675 | 179978 | */ |
| 179676 | 179979 | SQLITE_API int sqlite3_snapshot_open( |
| 179677 | 179980 | sqlite3 *db, |
| 179678 | 179981 | const char *zDb, |
| 179679 | 179982 | sqlite3_snapshot *pSnapshot |
| @@ -195704,10 +196007,11 @@ | ||
| 195704 | 196007 | memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING); |
| 195705 | 196008 | } |
| 195706 | 196009 | |
| 195707 | 196010 | for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){ |
| 195708 | 196011 | NodeReader reader; |
| 196012 | + memset(&reader, 0, sizeof(reader)); | |
| 195709 | 196013 | pNode = &pWriter->aNodeWriter[i]; |
| 195710 | 196014 | |
| 195711 | 196015 | if( pNode->block.a){ |
| 195712 | 196016 | rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n); |
| 195713 | 196017 | while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader); |
| @@ -200348,11 +200652,11 @@ | ||
| 200348 | 200652 | } |
| 200349 | 200653 | } |
| 200350 | 200654 | } |
| 200351 | 200655 | |
| 200352 | 200656 | /* |
| 200353 | -** Return a JsonNode and all its descendents as a JSON string. | |
| 200657 | +** Return a JsonNode and all its descendants as a JSON string. | |
| 200354 | 200658 | */ |
| 200355 | 200659 | static void jsonReturnJson( |
| 200356 | 200660 | JsonNode *pNode, /* Node to return */ |
| 200357 | 200661 | sqlite3_context *pCtx, /* Return value for this function */ |
| 200358 | 200662 | sqlite3_value **aReplace /* Array of replacement values */ |
| @@ -202420,11 +202724,11 @@ | ||
| 202420 | 202724 | UNUSED_PARAMETER(argc); |
| 202421 | 202725 | UNUSED_PARAMETER(argv); |
| 202422 | 202726 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 202423 | 202727 | #ifdef NEVER |
| 202424 | 202728 | /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will |
| 202425 | - ** always have been called to initalize it */ | |
| 202729 | + ** always have been called to initialize it */ | |
| 202426 | 202730 | if( NEVER(!pStr) ) return; |
| 202427 | 202731 | #endif |
| 202428 | 202732 | z = pStr->zBuf; |
| 202429 | 202733 | for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){ |
| 202430 | 202734 | if( c=='"' ){ |
| @@ -205011,11 +205315,24 @@ | ||
| 205011 | 205315 | break; |
| 205012 | 205316 | } |
| 205013 | 205317 | p->pInfo->nCoord = pRtree->nDim2; |
| 205014 | 205318 | p->pInfo->anQueue = pCsr->anQueue; |
| 205015 | 205319 | p->pInfo->mxLevel = pRtree->iDepth + 1; |
| 205016 | - }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ | |
| 205320 | + }else if( eType==SQLITE_INTEGER ){ | |
| 205321 | + sqlite3_int64 iVal = sqlite3_value_int64(argv[ii]); | |
| 205322 | +#ifdef SQLITE_RTREE_INT_ONLY | |
| 205323 | + p->u.rValue = iVal; | |
| 205324 | +#else | |
| 205325 | + p->u.rValue = (double)iVal; | |
| 205326 | + if( iVal>=((sqlite3_int64)1)<<48 | |
| 205327 | + || -iVal>=((sqlite3_int64)1)<<48 | |
| 205328 | + ){ | |
| 205329 | + if( p->op==RTREE_LT ) p->op = RTREE_LE; | |
| 205330 | + if( p->op==RTREE_GT ) p->op = RTREE_GE; | |
| 205331 | + } | |
| 205332 | +#endif | |
| 205333 | + }else if( eType==SQLITE_FLOAT ){ | |
| 205017 | 205334 | #ifdef SQLITE_RTREE_INT_ONLY |
| 205018 | 205335 | p->u.rValue = sqlite3_value_int64(argv[ii]); |
| 205019 | 205336 | #else |
| 205020 | 205337 | p->u.rValue = sqlite3_value_double(argv[ii]); |
| 205021 | 205338 | #endif |
| @@ -205142,24 +205459,25 @@ | ||
| 205142 | 205459 | if( p->usable |
| 205143 | 205460 | && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2) |
| 205144 | 205461 | || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) |
| 205145 | 205462 | ){ |
| 205146 | 205463 | u8 op; |
| 205464 | + u8 doOmit = 1; | |
| 205147 | 205465 | switch( p->op ){ |
| 205148 | - case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break; | |
| 205149 | - case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break; | |
| 205466 | + case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; doOmit = 0; break; | |
| 205467 | + case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; doOmit = 0; break; | |
| 205150 | 205468 | case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break; |
| 205151 | - case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break; | |
| 205469 | + case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; doOmit = 0; break; | |
| 205152 | 205470 | case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break; |
| 205153 | 205471 | case SQLITE_INDEX_CONSTRAINT_MATCH: op = RTREE_MATCH; break; |
| 205154 | 205472 | default: op = 0; break; |
| 205155 | 205473 | } |
| 205156 | 205474 | if( op ){ |
| 205157 | 205475 | zIdxStr[iIdx++] = op; |
| 205158 | 205476 | zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0'); |
| 205159 | 205477 | pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2); |
| 205160 | - pIdxInfo->aConstraintUsage[ii].omit = 1; | |
| 205478 | + pIdxInfo->aConstraintUsage[ii].omit = doOmit; | |
| 205161 | 205479 | } |
| 205162 | 205480 | } |
| 205163 | 205481 | } |
| 205164 | 205482 | |
| 205165 | 205483 | pIdxInfo->idxNum = 2; |
| @@ -225250,11 +225568,12 @@ | ||
| 225250 | 225568 | #define FTS5_COMMA 13 |
| 225251 | 225569 | #define FTS5_PLUS 14 |
| 225252 | 225570 | #define FTS5_STAR 15 |
| 225253 | 225571 | |
| 225254 | 225572 | /* This file is automatically generated by Lemon from input grammar |
| 225255 | -** source file "fts5parse.y". */ | |
| 225573 | +** source file "fts5parse.y". | |
| 225574 | +*/ | |
| 225256 | 225575 | /* |
| 225257 | 225576 | ** 2000-05-29 |
| 225258 | 225577 | ** |
| 225259 | 225578 | ** The author disclaims copyright to this source code. In place of |
| 225260 | 225579 | ** a legal notice, here is a blessing: |
| @@ -237173,11 +237492,11 @@ | ||
| 237173 | 237492 | if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty)); |
| 237174 | 237493 | fts5DataRelease(pLeaf); |
| 237175 | 237494 | pLeaf = 0; |
| 237176 | 237495 | }else if( bDetailNone ){ |
| 237177 | 237496 | break; |
| 237178 | - }else if( iNext>=pLeaf->szLeaf || iNext<4 ){ | |
| 237497 | + }else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){ | |
| 237179 | 237498 | p->rc = FTS5_CORRUPT; |
| 237180 | 237499 | break; |
| 237181 | 237500 | }else{ |
| 237182 | 237501 | int nShift = iNext - 4; |
| 237183 | 237502 | int nPg; |
| @@ -237377,11 +237696,13 @@ | ||
| 237377 | 237696 | }else{ |
| 237378 | 237697 | if( iKey!=1 ){ |
| 237379 | 237698 | iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix); |
| 237380 | 237699 | } |
| 237381 | 237700 | iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix); |
| 237382 | - if( nPrefix2>nPrefix ){ | |
| 237701 | + if( nPrefix2>pSeg->term.n ){ | |
| 237702 | + p->rc = FTS5_CORRUPT; | |
| 237703 | + }else if( nPrefix2>nPrefix ){ | |
| 237383 | 237704 | memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix); |
| 237384 | 237705 | iOff += (nPrefix2-nPrefix); |
| 237385 | 237706 | } |
| 237386 | 237707 | memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2); |
| 237387 | 237708 | iOff += nSuffix2; |
| @@ -242633,11 +242954,11 @@ | ||
| 242633 | 242954 | int nArg, /* Number of args */ |
| 242634 | 242955 | sqlite3_value **apUnused /* Function arguments */ |
| 242635 | 242956 | ){ |
| 242636 | 242957 | assert( nArg==0 ); |
| 242637 | 242958 | UNUSED_PARAM2(nArg, apUnused); |
| 242638 | - sqlite3_result_text(pCtx, "fts5: 2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0", -1, SQLITE_TRANSIENT); | |
| 242959 | + sqlite3_result_text(pCtx, "fts5: 2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9", -1, SQLITE_TRANSIENT); | |
| 242639 | 242960 | } |
| 242640 | 242961 | |
| 242641 | 242962 | /* |
| 242642 | 242963 | ** Return true if zName is the extension on one of the shadow tables used |
| 242643 | 242964 | ** by this module. |
| 242644 | 242965 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.42.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. |
| @@ -14,10 +14,13 @@ | |
| 14 | ** the text of this file. Search for "Begin file sqlite3.h" to find the start |
| 15 | ** of the embedded sqlite3.h header file.) Additional code files may be needed |
| 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | */ |
| 20 | #define SQLITE_CORE 1 |
| 21 | #define SQLITE_AMALGAMATION 1 |
| 22 | #ifndef SQLITE_PRIVATE |
| 23 | # define SQLITE_PRIVATE static |
| @@ -48,15 +51,15 @@ | |
| 48 | ** NO_TEST - The branches on this line are not |
| 49 | ** measured by branch coverage. This is |
| 50 | ** used on lines of code that actually |
| 51 | ** implement parts of coverage testing. |
| 52 | ** |
| 53 | ** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false |
| 54 | ** and the correct answer is still obtained, |
| 55 | ** though perhaps more slowly. |
| 56 | ** |
| 57 | ** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true |
| 58 | ** and the correct answer is still obtained, |
| 59 | ** though perhaps more slowly. |
| 60 | ** |
| 61 | ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread |
| 62 | ** that would be harmless and undetectable |
| @@ -454,13 +457,13 @@ | |
| 454 | ** |
| 455 | ** See also: [sqlite3_libversion()], |
| 456 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 457 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 458 | */ |
| 459 | #define SQLITE_VERSION "3.42.0" |
| 460 | #define SQLITE_VERSION_NUMBER 3042000 |
| 461 | #define SQLITE_SOURCE_ID "2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0" |
| 462 | |
| 463 | /* |
| 464 | ** CAPI3REF: Run-Time Library Version Numbers |
| 465 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 466 | ** |
| @@ -1498,11 +1501,11 @@ | |
| 1498 | ** the database is not a wal-mode db, or if there is no such connection in any |
| 1499 | ** other process. This opcode cannot be used to detect transactions opened |
| 1500 | ** by clients within the current process, only within other processes. |
| 1501 | ** |
| 1502 | ** <li>[[SQLITE_FCNTL_CKSM_FILE]] |
| 1503 | ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the |
| 1504 | ** [checksum VFS shim] only. |
| 1505 | ** |
| 1506 | ** <li>[[SQLITE_FCNTL_RESET_CACHE]] |
| 1507 | ** If there is currently no transaction open on the database, and the |
| 1508 | ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control |
| @@ -2762,11 +2765,11 @@ | |
| 2762 | ** 3.0.0. |
| 2763 | ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on, |
| 2764 | ** the [VACUUM] command will fail with an obscure error when attempting to |
| 2765 | ** process a table with generated columns and a descending index. This is |
| 2766 | ** not considered a bug since SQLite versions 3.3.0 and earlier do not support |
| 2767 | ** either generated columns or decending indexes. |
| 2768 | ** </dd> |
| 2769 | ** |
| 2770 | ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]] |
| 2771 | ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt> |
| 2772 | ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in |
| @@ -3043,10 +3046,11 @@ | |
| 3043 | ** SQL statements is a no-op and has no effect on SQL statements |
| 3044 | ** that are started after the sqlite3_interrupt() call returns. |
| 3045 | ** |
| 3046 | ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether |
| 3047 | ** or not an interrupt is currently in effect for [database connection] D. |
| 3048 | */ |
| 3049 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 3050 | SQLITE_API int sqlite3_is_interrupted(sqlite3*); |
| 3051 | |
| 3052 | /* |
| @@ -3696,12 +3700,14 @@ | |
| 3696 | ** and context pointer P. ^If the X callback is |
| 3697 | ** NULL or if the M mask is zero, then tracing is disabled. The |
| 3698 | ** M argument should be the bitwise OR-ed combination of |
| 3699 | ** zero or more [SQLITE_TRACE] constants. |
| 3700 | ** |
| 3701 | ** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides |
| 3702 | ** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2(). |
| 3703 | ** |
| 3704 | ** ^The X callback is invoked whenever any of the events identified by |
| 3705 | ** mask M occur. ^The integer return value from the callback is currently |
| 3706 | ** ignored, though this may change in future releases. Callback |
| 3707 | ** implementations should return zero to ensure future compatibility. |
| @@ -4066,11 +4072,11 @@ | |
| 4066 | ** |
| 4067 | ** The first parameter to these interfaces (hereafter referred to |
| 4068 | ** as F) must be one of: |
| 4069 | ** <ul> |
| 4070 | ** <li> A database filename pointer created by the SQLite core and |
| 4071 | ** passed into the xOpen() method of a VFS implemention, or |
| 4072 | ** <li> A filename obtained from [sqlite3_db_filename()], or |
| 4073 | ** <li> A new filename constructed using [sqlite3_create_filename()]. |
| 4074 | ** </ul> |
| 4075 | ** If the F parameter is not one of the above, then the behavior is |
| 4076 | ** undefined and probably undesirable. Older versions of SQLite were |
| @@ -4179,11 +4185,11 @@ | |
| 4179 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); |
| 4180 | |
| 4181 | /* |
| 4182 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 4183 | ** |
| 4184 | ** These interfces are provided for use by [VFS shim] implementations and |
| 4185 | ** are not useful outside of that context. |
| 4186 | ** |
| 4187 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 4188 | ** database filename D with corresponding journal file J and WAL file W and |
| 4189 | ** with N URI parameters key/values pairs in the array P. The result from |
| @@ -4889,11 +4895,11 @@ | |
| 4889 | ** These three options exist: |
| 4890 | ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished |
| 4891 | ** with it may be passed. ^It is called to dispose of the BLOB or string even |
| 4892 | ** if the call to the bind API fails, except the destructor is not called if |
| 4893 | ** the third parameter is a NULL pointer or the fourth parameter is negative. |
| 4894 | ** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that |
| 4895 | ** the application remains responsible for disposing of the object. ^In this |
| 4896 | ** case, the object and the provided pointer to it must remain valid until |
| 4897 | ** either the prepared statement is finalized or the same SQL parameter is |
| 4898 | ** bound to something else, whichever occurs sooner. |
| 4899 | ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
| @@ -5568,18 +5574,30 @@ | |
| 5568 | ** Use [sqlite3_clear_bindings()] to reset the bindings. |
| 5569 | ** |
| 5570 | ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
| 5571 | ** back to the beginning of its program. |
| 5572 | ** |
| 5573 | ** ^If the most recent call to [sqlite3_step(S)] for the |
| 5574 | ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], |
| 5575 | ** or if [sqlite3_step(S)] has never before been called on S, |
| 5576 | ** then [sqlite3_reset(S)] returns [SQLITE_OK]. |
| 5577 | ** |
| 5578 | ** ^If the most recent call to [sqlite3_step(S)] for the |
| 5579 | ** [prepared statement] S indicated an error, then |
| 5580 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
| 5581 | ** |
| 5582 | ** ^The [sqlite3_reset(S)] interface does not change the values |
| 5583 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
| 5584 | */ |
| 5585 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| @@ -5792,11 +5810,11 @@ | |
| 5792 | ** <p> |
| 5793 | ** The SQLITE_DIRECTONLY flag is recommended for any |
| 5794 | ** [application-defined SQL function] |
| 5795 | ** that has side-effects or that could potentially leak sensitive information. |
| 5796 | ** This will prevent attacks in which an application is tricked |
| 5797 | ** into using a database file that has had its schema surreptiously |
| 5798 | ** modified to invoke the application-defined function in ways that are |
| 5799 | ** harmful. |
| 5800 | ** <p> |
| 5801 | ** Some people say it is good practice to set SQLITE_DIRECTONLY on all |
| 5802 | ** [application-defined SQL functions], regardless of whether or not they |
| @@ -9501,12 +9519,12 @@ | |
| 9501 | ** ^(There may be at most one unlock-notify callback registered by a |
| 9502 | ** blocked connection. If sqlite3_unlock_notify() is called when the |
| 9503 | ** blocked connection already has a registered unlock-notify callback, |
| 9504 | ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is |
| 9505 | ** called with a NULL pointer as its second argument, then any existing |
| 9506 | ** unlock-notify callback is canceled. ^The blocked connections |
| 9507 | ** unlock-notify callback may also be canceled by closing the blocked |
| 9508 | ** connection using [sqlite3_close()]. |
| 9509 | ** |
| 9510 | ** The unlock-notify callback is not reentrant. If an application invokes |
| 9511 | ** any sqlite3_xxx API functions from within an unlock-notify callback, a |
| 9512 | ** crash or deadlock may be the result. |
| @@ -9925,11 +9943,11 @@ | |
| 9925 | ** </dd> |
| 9926 | ** |
| 9927 | ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 9928 | ** <dd>Calls of the form |
| 9929 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 9930 | ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation |
| 9931 | ** prohibits that virtual table from being used from within triggers and |
| 9932 | ** views. |
| 9933 | ** </dd> |
| 9934 | ** |
| 9935 | ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| @@ -10115,11 +10133,11 @@ | |
| 10115 | ** ^(A constraint on a virtual table of the form |
| 10116 | ** "[IN operator|column IN (...)]" is |
| 10117 | ** communicated to the xBestIndex method as a |
| 10118 | ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use |
| 10119 | ** this constraint, it must set the corresponding |
| 10120 | ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under |
| 10121 | ** the usual mode of handling IN operators, SQLite generates [bytecode] |
| 10122 | ** that invokes the [xFilter|xFilter() method] once for each value |
| 10123 | ** on the right-hand side of the IN operator.)^ Thus the virtual table |
| 10124 | ** only sees a single value from the right-hand side of the IN operator |
| 10125 | ** at a time. |
| @@ -10544,11 +10562,11 @@ | |
| 10544 | ** triggers; and so forth. |
| 10545 | ** |
| 10546 | ** When the [sqlite3_blob_write()] API is used to update a blob column, |
| 10547 | ** the pre-update hook is invoked with SQLITE_DELETE. This is because the |
| 10548 | ** in this case the new values are not available. In this case, when a |
| 10549 | ** callback made with op==SQLITE_DELETE is actuall a write using the |
| 10550 | ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns |
| 10551 | ** the index of the column being written. In other cases, where the |
| 10552 | ** pre-update hook is being invoked for some other reason, including a |
| 10553 | ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1. |
| 10554 | ** |
| @@ -13468,11 +13486,11 @@ | |
| 13468 | ** The maximum number of terms in a compound SELECT statement. |
| 13469 | ** The code generator for compound SELECT statements does one |
| 13470 | ** level of recursion for each term. A stack overflow can result |
| 13471 | ** if the number of terms is too large. In practice, most SQL |
| 13472 | ** never has more than 3 or 4 terms. Use a value of 0 to disable |
| 13473 | ** any limit on the number of terms in a compount SELECT. |
| 13474 | */ |
| 13475 | #ifndef SQLITE_MAX_COMPOUND_SELECT |
| 13476 | # define SQLITE_MAX_COMPOUND_SELECT 500 |
| 13477 | #endif |
| 13478 | |
| @@ -14806,11 +14824,11 @@ | |
| 14806 | }; |
| 14807 | |
| 14808 | /* |
| 14809 | ** Name of table that holds the database schema. |
| 14810 | ** |
| 14811 | ** The PREFERRED names are used whereever possible. But LEGACY is also |
| 14812 | ** used for backwards compatibility. |
| 14813 | ** |
| 14814 | ** 1. Queries can use either the PREFERRED or the LEGACY names |
| 14815 | ** 2. The sqlite3_set_authorizer() callback uses the LEGACY name |
| 14816 | ** 3. The PRAGMA table_list statement uses the PREFERRED name |
| @@ -16575,11 +16593,11 @@ | |
| 16575 | |
| 16576 | /* |
| 16577 | ** The VdbeCoverage macros are used to set a coverage testing point |
| 16578 | ** for VDBE branch instructions. The coverage testing points are line |
| 16579 | ** numbers in the sqlite3.c source file. VDBE branch coverage testing |
| 16580 | ** only works with an amalagmation build. That's ok since a VDBE branch |
| 16581 | ** coverage build designed for testing the test suite only. No application |
| 16582 | ** should ever ship with VDBE branch coverage measuring turned on. |
| 16583 | ** |
| 16584 | ** VdbeCoverage(v) // Mark the previously coded instruction |
| 16585 | ** // as a branch |
| @@ -16593,21 +16611,21 @@ | |
| 16593 | ** VdbeCoverageNeverNull(v) // Previous three-way branch is only |
| 16594 | ** // taken on the first two ways. The |
| 16595 | ** // NULL option is not possible |
| 16596 | ** |
| 16597 | ** VdbeCoverageEqNe(v) // Previous OP_Jump is only interested |
| 16598 | ** // in distingishing equal and not-equal. |
| 16599 | ** |
| 16600 | ** Every VDBE branch operation must be tagged with one of the macros above. |
| 16601 | ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and |
| 16602 | ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch() |
| 16603 | ** routine in vdbe.c, alerting the developer to the missed tag. |
| 16604 | ** |
| 16605 | ** During testing, the test application will invoke |
| 16606 | ** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback |
| 16607 | ** routine that is invoked as each bytecode branch is taken. The callback |
| 16608 | ** contains the sqlite3.c source line number ov the VdbeCoverage macro and |
| 16609 | ** flags to indicate whether or not the branch was taken. The test application |
| 16610 | ** is responsible for keeping track of this and reporting byte-code branches |
| 16611 | ** that are never taken. |
| 16612 | ** |
| 16613 | ** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the |
| @@ -16942,11 +16960,11 @@ | |
| 16942 | #endif |
| 16943 | |
| 16944 | /* |
| 16945 | ** Default synchronous levels. |
| 16946 | ** |
| 16947 | ** Note that (for historcal reasons) the PAGER_SYNCHRONOUS_* macros differ |
| 16948 | ** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1. |
| 16949 | ** |
| 16950 | ** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS |
| 16951 | ** OFF 1 0 |
| 16952 | ** NORMAL 2 1 |
| @@ -16981,11 +16999,11 @@ | |
| 16981 | |
| 16982 | /* |
| 16983 | ** An instance of the following structure stores a database schema. |
| 16984 | ** |
| 16985 | ** Most Schema objects are associated with a Btree. The exception is |
| 16986 | ** the Schema for the TEMP databaes (sqlite3.aDb[1]) which is free-standing. |
| 16987 | ** In shared cache mode, a single Schema object can be shared by multiple |
| 16988 | ** Btrees that refer to the same underlying BtShared object. |
| 16989 | ** |
| 16990 | ** Schema objects are automatically deallocated when the last Btree that |
| 16991 | ** references them is destroyed. The TEMP Schema is manually freed by |
| @@ -17092,11 +17110,11 @@ | |
| 17092 | u32 nSlot; /* Number of lookaside slots allocated */ |
| 17093 | u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ |
| 17094 | LookasideSlot *pInit; /* List of buffers not previously used */ |
| 17095 | LookasideSlot *pFree; /* List of available buffers */ |
| 17096 | #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 17097 | LookasideSlot *pSmallInit; /* List of small buffers not prediously used */ |
| 17098 | LookasideSlot *pSmallFree; /* List of available small buffers */ |
| 17099 | void *pMiddle; /* First byte past end of full-size buffers and |
| 17100 | ** the first byte of LOOKASIDE_SMALL buffers */ |
| 17101 | #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 17102 | void *pStart; /* First byte of available memory space */ |
| @@ -17109,11 +17127,11 @@ | |
| 17109 | |
| 17110 | #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0 |
| 17111 | #define EnableLookaside db->lookaside.bDisable--;\ |
| 17112 | db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue |
| 17113 | |
| 17114 | /* Size of the smaller allocations in two-size lookside */ |
| 17115 | #ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 17116 | # define LOOKASIDE_SMALL 0 |
| 17117 | #else |
| 17118 | # define LOOKASIDE_SMALL 128 |
| 17119 | #endif |
| @@ -17537,11 +17555,11 @@ | |
| 17537 | ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!! |
| 17538 | ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API |
| 17539 | ** |
| 17540 | ** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the |
| 17541 | ** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is |
| 17542 | ** used internally and if set means tha the function has side effects. |
| 17543 | ** SQLITE_INNOCUOUS is used by application code and means "not unsafe". |
| 17544 | ** See multiple instances of tag-20230109-1. |
| 17545 | */ |
| 17546 | #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ |
| 17547 | #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ |
| @@ -18127,11 +18145,11 @@ | |
| 18127 | ** to its default value. CASCADE means that a DELETE or UPDATE of the |
| 18128 | ** referenced table row is propagated into the row that holds the |
| 18129 | ** foreign key. |
| 18130 | ** |
| 18131 | ** The OE_Default value is a place holder that means to use whatever |
| 18132 | ** conflict resolution algorthm is required from context. |
| 18133 | ** |
| 18134 | ** The following symbolic values are used to record which type |
| 18135 | ** of conflict resolution action to take. |
| 18136 | */ |
| 18137 | #define OE_None 0 /* There is no constraint to check */ |
| @@ -18541,11 +18559,11 @@ | |
| 18541 | #endif |
| 18542 | int iTable; /* TK_COLUMN: cursor number of table holding column |
| 18543 | ** TK_REGISTER: register number |
| 18544 | ** TK_TRIGGER: 1 -> new, 0 -> old |
| 18545 | ** EP_Unlikely: 134217728 times likelihood |
| 18546 | ** TK_IN: ephemerial table holding RHS |
| 18547 | ** TK_SELECT_COLUMN: Number of columns on the LHS |
| 18548 | ** TK_SELECT: 1st register of result vector */ |
| 18549 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 18550 | ** TK_VARIABLE: variable number (always >= 1). |
| 18551 | ** TK_SELECT_COLUMN: column of the result vector */ |
| @@ -18811,11 +18829,11 @@ | |
| 18811 | unsigned fromDDL :1; /* Comes from sqlite_schema */ |
| 18812 | unsigned isCte :1; /* This is a CTE */ |
| 18813 | unsigned notCte :1; /* This item may not match a CTE */ |
| 18814 | unsigned isUsing :1; /* u3.pUsing is valid */ |
| 18815 | unsigned isOn :1; /* u3.pOn was once valid and non-NULL */ |
| 18816 | unsigned isSynthUsing :1; /* u3.pUsing is synthensized from NATURAL */ |
| 18817 | unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */ |
| 18818 | } fg; |
| 18819 | int iCursor; /* The VDBE cursor number used to access this table */ |
| 18820 | union { |
| 18821 | Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */ |
| @@ -19657,11 +19675,11 @@ | |
| 19657 | #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ |
| 19658 | |
| 19659 | /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled |
| 19660 | ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning |
| 19661 | ** parameters are for temporary use during development, to help find |
| 19662 | ** optimial values for parameters in the query planner. The should not |
| 19663 | ** be used on trunk check-ins. They are a temporary mechanism available |
| 19664 | ** for transient development builds only. |
| 19665 | ** |
| 19666 | ** Tuning parameters are numbered starting with 1. |
| 19667 | */ |
| @@ -19769,10 +19787,11 @@ | |
| 19769 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 19770 | int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 19771 | void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ |
| 19772 | int walkerDepth; /* Number of subqueries */ |
| 19773 | u16 eCode; /* A small processing code */ |
| 19774 | union { /* Extra data for callback */ |
| 19775 | NameContext *pNC; /* Naming context */ |
| 19776 | int n; /* A counter */ |
| 19777 | int iCur; /* A cursor number */ |
| 19778 | SrcList *pSrcList; /* FROM clause */ |
| @@ -20479,11 +20498,11 @@ | |
| 20479 | SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, const Token*); |
| 20480 | SQLITE_PRIVATE int sqlite3ExprCompare(const Parse*,const Expr*,const Expr*, int); |
| 20481 | SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*,Expr*,int); |
| 20482 | SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList*,const ExprList*, int); |
| 20483 | SQLITE_PRIVATE int sqlite3ExprImpliesExpr(const Parse*,const Expr*,const Expr*, int); |
| 20484 | SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int); |
| 20485 | SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*); |
| 20486 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 20487 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 20488 | SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| 20489 | SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*); |
| @@ -23042,11 +23061,11 @@ | |
| 23042 | int iNewReg; /* Register for new.* values */ |
| 23043 | int iBlobWrite; /* Value returned by preupdate_blobwrite() */ |
| 23044 | i64 iKey1; /* First key value passed to hook */ |
| 23045 | i64 iKey2; /* Second key value passed to hook */ |
| 23046 | Mem *aNew; /* Array of new.* values */ |
| 23047 | Table *pTab; /* Schema object being upated */ |
| 23048 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 23049 | }; |
| 23050 | |
| 23051 | /* |
| 23052 | ** An instance of this object is used to pass an vector of values into |
| @@ -24258,10 +24277,29 @@ | |
| 24258 | { 4, "hour", 1.2897e+11, 3600.0 }, |
| 24259 | { 3, "day", 5373485.0, 86400.0 }, |
| 24260 | { 5, "month", 176546.0, 2592000.0 }, |
| 24261 | { 4, "year", 14713.0, 31536000.0 }, |
| 24262 | }; |
| 24263 | |
| 24264 | /* |
| 24265 | ** Process a modifier to a date-time stamp. The modifiers are |
| 24266 | ** as follows: |
| 24267 | ** |
| @@ -24302,23 +24340,12 @@ | |
| 24302 | ** If rawS is available, then interpret as a julian day number, or |
| 24303 | ** a unix timestamp, depending on its magnitude. |
| 24304 | */ |
| 24305 | if( sqlite3_stricmp(z, "auto")==0 ){ |
| 24306 | if( idx>1 ) return 1; /* IMP: R-33611-57934 */ |
| 24307 | if( !p->rawS || p->validJD ){ |
| 24308 | rc = 0; |
| 24309 | p->rawS = 0; |
| 24310 | }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */ |
| 24311 | && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */ |
| 24312 | ){ |
| 24313 | r = p->s*1000.0 + 210866760000000.0; |
| 24314 | clearYMD_HMS_TZ(p); |
| 24315 | p->iJD = (sqlite3_int64)(r + 0.5); |
| 24316 | p->validJD = 1; |
| 24317 | p->rawS = 0; |
| 24318 | rc = 0; |
| 24319 | } |
| 24320 | } |
| 24321 | break; |
| 24322 | } |
| 24323 | case 'j': { |
| 24324 | /* |
| @@ -24480,22 +24507,68 @@ | |
| 24480 | case '7': |
| 24481 | case '8': |
| 24482 | case '9': { |
| 24483 | double rRounder; |
| 24484 | int i; |
| 24485 | for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){} |
| 24486 | if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){ |
| 24487 | rc = 1; |
| 24488 | break; |
| 24489 | } |
| 24490 | if( z[n]==':' ){ |
| 24491 | /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the |
| 24492 | ** specified number of hours, minutes, seconds, and fractional seconds |
| 24493 | ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be |
| 24494 | ** omitted. |
| 24495 | */ |
| 24496 | const char *z2 = z; |
| 24497 | DateTime tx; |
| 24498 | sqlite3_int64 day; |
| 24499 | if( !sqlite3Isdigit(*z2) ) z2++; |
| 24500 | memset(&tx, 0, sizeof(tx)); |
| 24501 | if( parseHhMmSs(z2, &tx) ) break; |
| @@ -24526,11 +24599,10 @@ | |
| 24526 | && sqlite3_strnicmp(aXformType[i].zName, z, n)==0 |
| 24527 | && r>-aXformType[i].rLimit && r<aXformType[i].rLimit |
| 24528 | ){ |
| 24529 | switch( i ){ |
| 24530 | case 4: { /* Special processing to add months */ |
| 24531 | int x; |
| 24532 | assert( strcmp(aXformType[i].zName,"month")==0 ); |
| 24533 | computeYMD_HMS(p); |
| 24534 | p->M += (int)r; |
| 24535 | x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; |
| 24536 | p->Y += x; |
| @@ -24803,11 +24875,11 @@ | |
| 24803 | ** %J ** julian day number |
| 24804 | ** %m month 01-12 |
| 24805 | ** %M minute 00-59 |
| 24806 | ** %s seconds since 1970-01-01 |
| 24807 | ** %S seconds 00-59 |
| 24808 | ** %w day of week 0-6 sunday==0 |
| 24809 | ** %W week of year 00-53 |
| 24810 | ** %Y year 0000-9999 |
| 24811 | ** %% % |
| 24812 | */ |
| 24813 | static void strftimeFunc( |
| @@ -24942,10 +25014,120 @@ | |
| 24942 | sqlite3_value **NotUsed2 |
| 24943 | ){ |
| 24944 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 24945 | dateFunc(context, 0, 0); |
| 24946 | } |
| 24947 | |
| 24948 | /* |
| 24949 | ** current_timestamp() |
| 24950 | ** |
| 24951 | ** This function returns the same value as datetime('now'). |
| @@ -25017,10 +25199,11 @@ | |
| 25017 | PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ), |
| 25018 | PURE_DATE(date, -1, 0, 0, dateFunc ), |
| 25019 | PURE_DATE(time, -1, 0, 0, timeFunc ), |
| 25020 | PURE_DATE(datetime, -1, 0, 0, datetimeFunc ), |
| 25021 | PURE_DATE(strftime, -1, 0, 0, strftimeFunc ), |
| 25022 | DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), |
| 25023 | DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc), |
| 25024 | DFUNCTION(current_date, 0, 0, 0, cdateFunc ), |
| 25025 | #else |
| 25026 | STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc), |
| @@ -25170,11 +25353,11 @@ | |
| 25170 | && op!=SQLITE_FCNTL_CKPT_START |
| 25171 | ){ |
| 25172 | /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite |
| 25173 | ** is using a regular VFS, it is called after the corresponding |
| 25174 | ** transaction has been committed. Injecting a fault at this point |
| 25175 | ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM |
| 25176 | ** but the transaction is committed anyway. |
| 25177 | ** |
| 25178 | ** The core must call OsFileControl() though, not OsFileControlHint(), |
| 25179 | ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably |
| 25180 | ** means the commit really has failed and an error should be returned |
| @@ -25791,11 +25974,11 @@ | |
| 25791 | /* |
| 25792 | ** Like free() but works for allocations obtained from sqlite3MemMalloc() |
| 25793 | ** or sqlite3MemRealloc(). |
| 25794 | ** |
| 25795 | ** For this low-level routine, we already know that pPrior!=0 since |
| 25796 | ** cases where pPrior==0 will have been intecepted and dealt with |
| 25797 | ** by higher-level routines. |
| 25798 | */ |
| 25799 | static void sqlite3MemFree(void *pPrior){ |
| 25800 | #ifdef SQLITE_MALLOCSIZE |
| 25801 | SQLITE_FREE(pPrior); |
| @@ -25879,11 +26062,11 @@ | |
| 25879 | size_t len; |
| 25880 | if( _sqliteZone_ ){ |
| 25881 | return SQLITE_OK; |
| 25882 | } |
| 25883 | len = sizeof(cpuCount); |
| 25884 | /* One usually wants to use hw.acctivecpu for MT decisions, but not here */ |
| 25885 | sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); |
| 25886 | if( cpuCount>1 ){ |
| 25887 | /* defer MT decisions to system malloc */ |
| 25888 | _sqliteZone_ = malloc_default_zone(); |
| 25889 | }else{ |
| @@ -28346,11 +28529,11 @@ | |
| 28346 | |
| 28347 | #include <pthread.h> |
| 28348 | |
| 28349 | /* |
| 28350 | ** The sqlite3_mutex.id, sqlite3_mutex.nRef, and sqlite3_mutex.owner fields |
| 28351 | ** are necessary under two condidtions: (1) Debug builds and (2) using |
| 28352 | ** home-grown mutexes. Encapsulate these conditions into a single #define. |
| 28353 | */ |
| 28354 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HOMEGROWN_RECURSIVE_MUTEX) |
| 28355 | # define SQLITE_MUTEX_NREF 1 |
| 28356 | #else |
| @@ -28847,11 +29030,11 @@ | |
| 28847 | */ |
| 28848 | struct sqlite3_mutex { |
| 28849 | CRITICAL_SECTION mutex; /* Mutex controlling the lock */ |
| 28850 | int id; /* Mutex type */ |
| 28851 | #ifdef SQLITE_DEBUG |
| 28852 | volatile int nRef; /* Number of enterances */ |
| 28853 | volatile DWORD owner; /* Thread holding this mutex */ |
| 28854 | volatile LONG trace; /* True to trace changes */ |
| 28855 | #endif |
| 28856 | }; |
| 28857 | |
| @@ -32228,11 +32411,12 @@ | |
| 32228 | const char *azOp[] = { |
| 32229 | "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" |
| 32230 | }; |
| 32231 | assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); |
| 32232 | assert( pExpr->pRight ); |
| 32233 | assert( sqlite3ExprSkipCollate(pExpr->pRight)->op==TK_TRUEFALSE ); |
| 32234 | x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); |
| 32235 | zUniOp = azOp[x]; |
| 32236 | break; |
| 32237 | } |
| 32238 | |
| @@ -33887,11 +34071,11 @@ | |
| 33887 | #endif |
| 33888 | |
| 33889 | /* |
| 33890 | ** Calls to sqlite3FaultSim() are used to simulate a failure during testing, |
| 33891 | ** or to bypass normal error detection during testing in order to let |
| 33892 | ** execute proceed futher downstream. |
| 33893 | ** |
| 33894 | ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The |
| 33895 | ** sqlite3FaultSim() function only returns non-zero during testing. |
| 33896 | ** |
| 33897 | ** During testing, if the test harness has set a fault-sim callback using |
| @@ -34498,11 +34682,11 @@ | |
| 34498 | } |
| 34499 | |
| 34500 | /* store the result */ |
| 34501 | *pResult = result; |
| 34502 | |
| 34503 | /* return true if number and no extra non-whitespace chracters after */ |
| 34504 | if( z==zEnd && nDigit>0 && eValid && eType>0 ){ |
| 34505 | return eType; |
| 34506 | }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){ |
| 34507 | return -1; |
| 34508 | }else{ |
| @@ -34634,11 +34818,11 @@ | |
| 34634 | testcase( i==20*incr ); |
| 34635 | if( u>LARGEST_INT64 ){ |
| 34636 | /* This test and assignment is needed only to suppress UB warnings |
| 34637 | ** from clang and -fsanitize=undefined. This test and assignment make |
| 34638 | ** the code a little larger and slower, and no harm comes from omitting |
| 34639 | ** them, but we must appaise the undefined-behavior pharisees. */ |
| 34640 | *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64; |
| 34641 | }else if( neg ){ |
| 34642 | *pNum = -(i64)u; |
| 34643 | }else{ |
| 34644 | *pNum = (i64)u; |
| @@ -35319,11 +35503,11 @@ | |
| 35319 | return 1; |
| 35320 | } |
| 35321 | } |
| 35322 | |
| 35323 | /* |
| 35324 | ** Attempt to add, substract, or multiply the 64-bit signed value iB against |
| 35325 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 35326 | ** Return 0 on success. Or if the operation would have resulted in an |
| 35327 | ** overflow, leave *pA unchanged and return 1. |
| 35328 | */ |
| 35329 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| @@ -35632,11 +35816,11 @@ | |
| 35632 | */ |
| 35633 | #ifndef SQLITE_HWTIME_H |
| 35634 | #define SQLITE_HWTIME_H |
| 35635 | |
| 35636 | /* |
| 35637 | ** The following routine only works on pentium-class (or newer) processors. |
| 35638 | ** It uses the RDTSC opcode to read the cycle count value out of the |
| 35639 | ** processor and returns that value. This can be used for high-res |
| 35640 | ** profiling. |
| 35641 | */ |
| 35642 | #if !defined(__STRICT_ANSI__) && \ |
| @@ -35804,11 +35988,11 @@ | |
| 35804 | pH->first = pNew; |
| 35805 | } |
| 35806 | } |
| 35807 | |
| 35808 | |
| 35809 | /* Resize the hash table so that it cantains "new_size" buckets. |
| 35810 | ** |
| 35811 | ** The hash table might fail to resize if sqlite3_malloc() fails or |
| 35812 | ** if the new size is the same as the prior size. |
| 35813 | ** Return TRUE if the resize occurs and false if not. |
| 35814 | */ |
| @@ -37190,11 +37374,11 @@ | |
| 37190 | ** skip locking all together. |
| 37191 | ** |
| 37192 | ** This source file is organized into divisions where the logic for various |
| 37193 | ** subfunctions is contained within the appropriate division. PLEASE |
| 37194 | ** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed |
| 37195 | ** in the correct division and should be clearly labeled. |
| 37196 | ** |
| 37197 | ** The layout of divisions is as follows: |
| 37198 | ** |
| 37199 | ** * General-purpose declarations and utility functions. |
| 37200 | ** * Unique file ID logic used by VxWorks. |
| @@ -37777,11 +37961,11 @@ | |
| 37777 | #endif |
| 37778 | } |
| 37779 | |
| 37780 | /* |
| 37781 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| 37782 | ** "unix" VFSes. Return SQLITE_OK opon successfully updating the |
| 37783 | ** system call pointer, or SQLITE_NOTFOUND if there is no configurable |
| 37784 | ** system call named zName. |
| 37785 | */ |
| 37786 | static int unixSetSystemCall( |
| 37787 | sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ |
| @@ -38299,11 +38483,11 @@ | |
| 38299 | ** But wait: there are yet more problems with POSIX advisory locks. |
| 38300 | ** |
| 38301 | ** If you close a file descriptor that points to a file that has locks, |
| 38302 | ** all locks on that file that are owned by the current process are |
| 38303 | ** released. To work around this problem, each unixInodeInfo object |
| 38304 | ** maintains a count of the number of pending locks on tha inode. |
| 38305 | ** When an attempt is made to close an unixFile, if there are |
| 38306 | ** other unixFile open on the same inode that are holding locks, the call |
| 38307 | ** to close() the file descriptor is deferred until all of the locks clear. |
| 38308 | ** The unixInodeInfo structure keeps a list of file descriptors that need to |
| 38309 | ** be closed and that list is walked (and cleared) when the last lock |
| @@ -38313,11 +38497,11 @@ | |
| 38313 | ** |
| 38314 | ** Many older versions of linux use the LinuxThreads library which is |
| 38315 | ** not posix compliant. Under LinuxThreads, a lock created by thread |
| 38316 | ** A cannot be modified or overridden by a different thread B. |
| 38317 | ** Only thread A can modify the lock. Locking behavior is correct |
| 38318 | ** if the appliation uses the newer Native Posix Thread Library (NPTL) |
| 38319 | ** on linux - with NPTL a lock created by thread A can override locks |
| 38320 | ** in thread B. But there is no way to know at compile-time which |
| 38321 | ** threading library is being used. So there is no way to know at |
| 38322 | ** compile-time whether or not thread A can override locks on thread B. |
| 38323 | ** One has to do a run-time check to discover the behavior of the |
| @@ -38515,11 +38699,11 @@ | |
| 38515 | static void storeLastErrno(unixFile *pFile, int error){ |
| 38516 | pFile->lastErrno = error; |
| 38517 | } |
| 38518 | |
| 38519 | /* |
| 38520 | ** Close all file descriptors accumuated in the unixInodeInfo->pUnused list. |
| 38521 | */ |
| 38522 | static void closePendingFds(unixFile *pFile){ |
| 38523 | unixInodeInfo *pInode = pFile->pInode; |
| 38524 | UnixUnusedFd *p; |
| 38525 | UnixUnusedFd *pNext; |
| @@ -38878,19 +39062,19 @@ | |
| 38878 | ** lock primitives (called read-locks and write-locks below, to avoid |
| 38879 | ** confusion with SQLite lock names). The algorithms are complicated |
| 38880 | ** slightly in order to be compatible with Windows95 systems simultaneously |
| 38881 | ** accessing the same database file, in case that is ever required. |
| 38882 | ** |
| 38883 | ** Symbols defined in os.h indentify the 'pending byte' and the 'reserved |
| 38884 | ** byte', each single bytes at well known offsets, and the 'shared byte |
| 38885 | ** range', a range of 510 bytes at a well known offset. |
| 38886 | ** |
| 38887 | ** To obtain a SHARED lock, a read-lock is obtained on the 'pending |
| 38888 | ** byte'. If this is successful, 'shared byte range' is read-locked |
| 38889 | ** and the lock on the 'pending byte' released. (Legacy note: When |
| 38890 | ** SQLite was first developed, Windows95 systems were still very common, |
| 38891 | ** and Widnows95 lacks a shared-lock capability. So on Windows95, a |
| 38892 | ** single randomly selected by from the 'shared byte range' is locked. |
| 38893 | ** Windows95 is now pretty much extinct, but this work-around for the |
| 38894 | ** lack of shared-locks on Windows95 lives on, for backwards |
| 38895 | ** compatibility.) |
| 38896 | ** |
| @@ -38907,11 +39091,11 @@ | |
| 38907 | ** If a process that holds a RESERVED lock requests an EXCLUSIVE, then |
| 38908 | ** a PENDING lock is obtained first. A PENDING lock is implemented by |
| 38909 | ** obtaining a write-lock on the 'pending byte'. This ensures that no new |
| 38910 | ** SHARED locks can be obtained, but existing SHARED locks are allowed to |
| 38911 | ** persist. If the call to this function fails to obtain the EXCLUSIVE |
| 38912 | ** lock in this case, it holds the PENDING lock intead. The client may |
| 38913 | ** then re-attempt the EXCLUSIVE lock later on, after existing SHARED |
| 38914 | ** locks have cleared. |
| 38915 | */ |
| 38916 | int rc = SQLITE_OK; |
| 38917 | unixFile *pFile = (unixFile*)id; |
| @@ -38935,11 +39119,11 @@ | |
| 38935 | return SQLITE_OK; |
| 38936 | } |
| 38937 | |
| 38938 | /* Make sure the locking sequence is correct. |
| 38939 | ** (1) We never move from unlocked to anything higher than shared lock. |
| 38940 | ** (2) SQLite never explicitly requests a pendig lock. |
| 38941 | ** (3) A shared lock is always held when a reserve lock is requested. |
| 38942 | */ |
| 38943 | assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); |
| 38944 | assert( eFileLock!=PENDING_LOCK ); |
| 38945 | assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK ); |
| @@ -40153,11 +40337,11 @@ | |
| 40153 | return SQLITE_OK; |
| 40154 | } |
| 40155 | |
| 40156 | /* Make sure the locking sequence is correct |
| 40157 | ** (1) We never move from unlocked to anything higher than shared lock. |
| 40158 | ** (2) SQLite never explicitly requests a pendig lock. |
| 40159 | ** (3) A shared lock is always held when a reserve lock is requested. |
| 40160 | */ |
| 40161 | assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); |
| 40162 | assert( eFileLock!=PENDING_LOCK ); |
| 40163 | assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK ); |
| @@ -40269,11 +40453,11 @@ | |
| 40269 | ** reestablish the shared lock if we can't get the afpUnlock |
| 40270 | */ |
| 40271 | if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST + |
| 40272 | pInode->sharedByte, 1, 0)) ){ |
| 40273 | int failed2 = SQLITE_OK; |
| 40274 | /* now attemmpt to get the exclusive lock range */ |
| 40275 | failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST, |
| 40276 | SHARED_SIZE, 1); |
| 40277 | if( failed && (failed2 = afpSetLock(context->dbPath, pFile, |
| 40278 | SHARED_FIRST + pInode->sharedByte, 1, 1)) ){ |
| 40279 | /* Can't reestablish the shared lock. Sqlite can't deal, this is |
| @@ -40564,11 +40748,11 @@ | |
| 40564 | || offset+amt<=PENDING_BYTE |
| 40565 | ); |
| 40566 | #endif |
| 40567 | |
| 40568 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 40569 | /* Deal with as much of this read request as possible by transfering |
| 40570 | ** data from the memory mapping using memcpy(). */ |
| 40571 | if( offset<pFile->mmapSize ){ |
| 40572 | if( offset+amt <= pFile->mmapSize ){ |
| 40573 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
| 40574 | return SQLITE_OK; |
| @@ -40716,11 +40900,11 @@ | |
| 40716 | } |
| 40717 | } |
| 40718 | #endif |
| 40719 | |
| 40720 | #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 |
| 40721 | /* Deal with as much of this write request as possible by transfering |
| 40722 | ** data from the memory mapping using memcpy(). */ |
| 40723 | if( offset<pFile->mmapSize ){ |
| 40724 | if( offset+amt <= pFile->mmapSize ){ |
| 40725 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); |
| 40726 | return SQLITE_OK; |
| @@ -40838,11 +41022,11 @@ | |
| 40838 | #endif |
| 40839 | |
| 40840 | /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a |
| 40841 | ** no-op. But go ahead and call fstat() to validate the file |
| 40842 | ** descriptor as we need a method to provoke a failure during |
| 40843 | ** coverate testing. |
| 40844 | */ |
| 40845 | #ifdef SQLITE_NO_SYNC |
| 40846 | { |
| 40847 | struct stat buf; |
| 40848 | rc = osFstat(fd, &buf); |
| @@ -46478,11 +46662,11 @@ | |
| 46478 | |
| 46479 | }; /* End of the overrideable system calls */ |
| 46480 | |
| 46481 | /* |
| 46482 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| 46483 | ** "win32" VFSes. Return SQLITE_OK opon successfully updating the |
| 46484 | ** system call pointer, or SQLITE_NOTFOUND if there is no configurable |
| 46485 | ** system call named zName. |
| 46486 | */ |
| 46487 | static int winSetSystemCall( |
| 46488 | sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ |
| @@ -48058,11 +48242,11 @@ | |
| 48058 | OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 48059 | "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
| 48060 | pFile->h, pBuf, amt, offset, pFile->locktype)); |
| 48061 | |
| 48062 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 48063 | /* Deal with as much of this read request as possible by transfering |
| 48064 | ** data from the memory mapping using memcpy(). */ |
| 48065 | if( offset<pFile->mmapSize ){ |
| 48066 | if( offset+amt <= pFile->mmapSize ){ |
| 48067 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
| 48068 | OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| @@ -48136,11 +48320,11 @@ | |
| 48136 | OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 48137 | "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
| 48138 | pFile->h, pBuf, amt, offset, pFile->locktype)); |
| 48139 | |
| 48140 | #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 |
| 48141 | /* Deal with as much of this write request as possible by transfering |
| 48142 | ** data from the memory mapping using memcpy(). */ |
| 48143 | if( offset<pFile->mmapSize ){ |
| 48144 | if( offset+amt <= pFile->mmapSize ){ |
| 48145 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); |
| 48146 | OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| @@ -48246,11 +48430,11 @@ | |
| 48246 | ** |
| 48247 | ** The only feasible work-around is to defer the truncation until after |
| 48248 | ** all references to memory-mapped content are closed. That is doable, |
| 48249 | ** but involves adding a few branches in the common write code path which |
| 48250 | ** could slow down normal operations slightly. Hence, we have decided for |
| 48251 | ** now to simply make trancations a no-op if there are pending reads. We |
| 48252 | ** can maybe revisit this decision in the future. |
| 48253 | */ |
| 48254 | return SQLITE_OK; |
| 48255 | } |
| 48256 | #endif |
| @@ -48305,11 +48489,11 @@ | |
| 48305 | } |
| 48306 | |
| 48307 | #ifdef SQLITE_TEST |
| 48308 | /* |
| 48309 | ** Count the number of fullsyncs and normal syncs. This is used to test |
| 48310 | ** that syncs and fullsyncs are occuring at the right times. |
| 48311 | */ |
| 48312 | SQLITE_API int sqlite3_sync_count = 0; |
| 48313 | SQLITE_API int sqlite3_fullsync_count = 0; |
| 48314 | #endif |
| 48315 | |
| @@ -52643,11 +52827,11 @@ | |
| 52643 | return SQLITE_OK; |
| 52644 | } |
| 52645 | h = BITVEC_HASH(i++); |
| 52646 | /* if there wasn't a hash collision, and this doesn't */ |
| 52647 | /* completely fill the hash, then just add it without */ |
| 52648 | /* worring about sub-dividing and re-hashing. */ |
| 52649 | if( !p->u.aHash[h] ){ |
| 52650 | if (p->nSet<(BITVEC_NINT-1)) { |
| 52651 | goto bitvec_set_end; |
| 52652 | } else { |
| 52653 | goto bitvec_set_rehash; |
| @@ -53140,11 +53324,11 @@ | |
| 53140 | /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the |
| 53141 | ** suggested cache size is set to N. */ |
| 53142 | return p->szCache; |
| 53143 | }else{ |
| 53144 | i64 n; |
| 53145 | /* IMPLEMANTATION-OF: R-59858-46238 If the argument N is negative, then the |
| 53146 | ** number of cache pages is adjusted to be a number of pages that would |
| 53147 | ** use approximately abs(N*1024) bytes of memory based on the current |
| 53148 | ** page size. */ |
| 53149 | n = ((-1024*(i64)p->szCache)/(p->szPage+p->szExtra)); |
| 53150 | if( n>1000000000 ) n = 1000000000; |
| @@ -53628,11 +53812,11 @@ | |
| 53628 | } |
| 53629 | return result.pDirty; |
| 53630 | } |
| 53631 | |
| 53632 | /* |
| 53633 | ** Sort the list of pages in accending order by pgno. Pages are |
| 53634 | ** connected by pDirty pointers. The pDirtyPrev pointers are |
| 53635 | ** corrupted by this sort. |
| 53636 | ** |
| 53637 | ** Since there cannot be more than 2^31 distinct pages in a database, |
| 53638 | ** there cannot be more than 31 buckets required by the merge sorter. |
| @@ -53868,11 +54052,11 @@ | |
| 53868 | ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N). |
| 53869 | ** |
| 53870 | ** If N is positive, then N pages worth of memory are allocated using a single |
| 53871 | ** sqlite3Malloc() call and that memory is used for the first N pages allocated. |
| 53872 | ** Or if N is negative, then -1024*N bytes of memory are allocated and used |
| 53873 | ** for as many pages as can be accomodated. |
| 53874 | ** |
| 53875 | ** Only one of (2) or (3) can be used. Once the memory available to (2) or |
| 53876 | ** (3) is exhausted, subsequent allocations fail over to the general-purpose |
| 53877 | ** memory allocator (1). |
| 53878 | ** |
| @@ -53902,11 +54086,11 @@ | |
| 53902 | ** but causes a 2-byte gap in the structure for most architectures (since |
| 53903 | ** pointers must be either 4 or 8-byte aligned). As this structure is located |
| 53904 | ** in memory directly after the associated page data, if the database is |
| 53905 | ** corrupt, code at the b-tree layer may overread the page buffer and |
| 53906 | ** read part of this structure before the corruption is detected. This |
| 53907 | ** can cause a valgrind error if the unitialized gap is accessed. Using u16 |
| 53908 | ** ensures there is no such gap, and therefore no bytes of uninitialized |
| 53909 | ** memory in the structure. |
| 53910 | ** |
| 53911 | ** The pLruNext and pLruPrev pointers form a double-linked circular list |
| 53912 | ** of all pages that are unpinned. The PGroup.lru element (which should be |
| @@ -55122,11 +55306,11 @@ | |
| 55122 | ** until DESTROY. |
| 55123 | ** |
| 55124 | ** The TEST primitive includes a "batch" number. The TEST primitive |
| 55125 | ** will only see elements that were inserted before the last change |
| 55126 | ** in the batch number. In other words, if an INSERT occurs between |
| 55127 | ** two TESTs where the TESTs have the same batch nubmer, then the |
| 55128 | ** value added by the INSERT will not be visible to the second TEST. |
| 55129 | ** The initial batch number is zero, so if the very first TEST contains |
| 55130 | ** a non-zero batch number, it will see all prior INSERTs. |
| 55131 | ** |
| 55132 | ** No INSERTs may occurs after a SMALLEST. An assertion will fail if |
| @@ -56045,11 +56229,11 @@ | |
| 56045 | ** Once it has entered the ERROR state, any attempt to use the pager |
| 56046 | ** to read or write data returns an error. Eventually, once all |
| 56047 | ** outstanding transactions have been abandoned, the pager is able to |
| 56048 | ** transition back to OPEN state, discarding the contents of the |
| 56049 | ** page-cache and any other in-memory state at the same time. Everything |
| 56050 | ** is reloaded from disk (and, if necessary, hot-journal rollback peformed) |
| 56051 | ** when a read-transaction is next opened on the pager (transitioning |
| 56052 | ** the pager into READER state). At that point the system has recovered |
| 56053 | ** from the error. |
| 56054 | ** |
| 56055 | ** Specifically, the pager jumps into the ERROR state if: |
| @@ -57418,11 +57602,11 @@ | |
| 57418 | ** + N bytes: super-journal filename in utf-8. |
| 57419 | ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). |
| 57420 | ** + 4 bytes: super-journal name checksum. |
| 57421 | ** + 8 bytes: aJournalMagic[]. |
| 57422 | ** |
| 57423 | ** The super-journal page checksum is the sum of the bytes in thesuper-journal |
| 57424 | ** name, where each byte is interpreted as a signed 8-bit integer. |
| 57425 | ** |
| 57426 | ** If zSuper is a NULL pointer (occurs for a single database transaction), |
| 57427 | ** this call is a no-op. |
| 57428 | */ |
| @@ -57471,11 +57655,11 @@ | |
| 57471 | ){ |
| 57472 | return rc; |
| 57473 | } |
| 57474 | pPager->journalOff += (nSuper+20); |
| 57475 | |
| 57476 | /* If the pager is in peristent-journal mode, then the physical |
| 57477 | ** journal-file may extend past the end of the super-journal name |
| 57478 | ** and 8 bytes of magic data just written to the file. This is |
| 57479 | ** dangerous because the code to rollback a hot-journal file |
| 57480 | ** will not be able to find the super-journal name to determine |
| 57481 | ** whether or not the journal is hot. |
| @@ -57641,11 +57825,11 @@ | |
| 57641 | pPager->setSuper = 0; |
| 57642 | } |
| 57643 | |
| 57644 | /* |
| 57645 | ** This function is called whenever an IOERR or FULL error that requires |
| 57646 | ** the pager to transition into the ERROR state may ahve occurred. |
| 57647 | ** The first argument is a pointer to the pager structure, the second |
| 57648 | ** the error-code about to be returned by a pager API function. The |
| 57649 | ** value returned is a copy of the second argument to this function. |
| 57650 | ** |
| 57651 | ** If the second argument is SQLITE_FULL, SQLITE_IOERR or one of the |
| @@ -57916,11 +58100,11 @@ | |
| 57916 | pager_unlock(pPager); |
| 57917 | } |
| 57918 | |
| 57919 | /* |
| 57920 | ** Parameter aData must point to a buffer of pPager->pageSize bytes |
| 57921 | ** of data. Compute and return a checksum based ont the contents of the |
| 57922 | ** page of data and the current value of pPager->cksumInit. |
| 57923 | ** |
| 57924 | ** This is not a real checksum. It is really just the sum of the |
| 57925 | ** random initial value (pPager->cksumInit) and every 200th byte |
| 57926 | ** of the page data, starting with byte offset (pPager->pageSize%200). |
| @@ -58882,11 +59066,11 @@ | |
| 58882 | PgHdr *p; /* For looping over pages */ |
| 58883 | |
| 58884 | assert( pPager->pWal ); |
| 58885 | assert( pList ); |
| 58886 | #ifdef SQLITE_DEBUG |
| 58887 | /* Verify that the page list is in accending order */ |
| 58888 | for(p=pList; p && p->pDirty; p=p->pDirty){ |
| 58889 | assert( p->pgno < p->pDirty->pgno ); |
| 58890 | } |
| 58891 | #endif |
| 58892 | |
| @@ -59013,11 +59197,11 @@ | |
| 59013 | } |
| 59014 | |
| 59015 | #ifndef SQLITE_OMIT_WAL |
| 59016 | /* |
| 59017 | ** Check if the *-wal file that corresponds to the database opened by pPager |
| 59018 | ** exists if the database is not empy, or verify that the *-wal file does |
| 59019 | ** not exist (by deleting it) if the database file is empty. |
| 59020 | ** |
| 59021 | ** If the database is not empty and the *-wal file exists, open the pager |
| 59022 | ** in WAL mode. If the database is empty or if no *-wal file exists and |
| 59023 | ** if no error occurs, make sure Pager.journalMode is not set to |
| @@ -60765,11 +60949,11 @@ | |
| 60765 | return SQLITE_OK; |
| 60766 | } |
| 60767 | |
| 60768 | /* |
| 60769 | ** Return the sqlite3_file for the main database given the name |
| 60770 | ** of the corresonding WAL or Journal name as passed into |
| 60771 | ** xOpen. |
| 60772 | */ |
| 60773 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char *zName){ |
| 60774 | Pager *pPager; |
| 60775 | while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){ |
| @@ -63050,11 +63234,11 @@ | |
| 63050 | |
| 63051 | /* Change the journal mode. */ |
| 63052 | assert( pPager->eState!=PAGER_ERROR ); |
| 63053 | pPager->journalMode = (u8)eMode; |
| 63054 | |
| 63055 | /* When transistioning from TRUNCATE or PERSIST to any other journal |
| 63056 | ** mode except WAL, unless the pager is in locking_mode=exclusive mode, |
| 63057 | ** delete the journal file. |
| 63058 | */ |
| 63059 | assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 ); |
| 63060 | assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 ); |
| @@ -63768,11 +63952,11 @@ | |
| 63768 | ** of available reader locks and should be at least 3. The default |
| 63769 | ** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5. |
| 63770 | ** |
| 63771 | ** Technically, the various VFSes are free to implement these locks however |
| 63772 | ** they see fit. However, compatibility is encouraged so that VFSes can |
| 63773 | ** interoperate. The standard implemention used on both unix and windows |
| 63774 | ** is for the index number to indicate a byte offset into the |
| 63775 | ** WalCkptInfo.aLock[] array in the wal-index header. In other words, all |
| 63776 | ** locks are on the shm file. The WALINDEX_LOCK_OFFSET constant (which |
| 63777 | ** should be 120) is the location in the shm file for the first locking |
| 63778 | ** byte. |
| @@ -63844,11 +64028,11 @@ | |
| 63844 | ** There is one entry in aReadMark[] for each reader lock. If a reader |
| 63845 | ** holds read-lock K, then the value in aReadMark[K] is no greater than |
| 63846 | ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff) |
| 63847 | ** for any aReadMark[] means that entry is unused. aReadMark[0] is |
| 63848 | ** a special case; its value is never used and it exists as a place-holder |
| 63849 | ** to avoid having to offset aReadMark[] indexs by one. Readers holding |
| 63850 | ** WAL_READ_LOCK(0) always ignore the entire WAL and read all content |
| 63851 | ** directly from the database. |
| 63852 | ** |
| 63853 | ** The value of aReadMark[K] may only be changed by a thread that |
| 63854 | ** is holding an exclusive lock on WAL_READ_LOCK(K). Thus, the value of |
| @@ -64374,19 +64558,19 @@ | |
| 64374 | */ |
| 64375 | if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){ |
| 64376 | return 0; |
| 64377 | } |
| 64378 | |
| 64379 | /* A frame is only valid if the page number is creater than zero. |
| 64380 | */ |
| 64381 | pgno = sqlite3Get4byte(&aFrame[0]); |
| 64382 | if( pgno==0 ){ |
| 64383 | return 0; |
| 64384 | } |
| 64385 | |
| 64386 | /* A frame is only valid if a checksum of the WAL header, |
| 64387 | ** all prior frams, the first 16 bytes of this frame-header, |
| 64388 | ** and the frame-data matches the checksum in the last 8 |
| 64389 | ** bytes of this frame-header. |
| 64390 | */ |
| 64391 | nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN); |
| 64392 | walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum); |
| @@ -65076,11 +65260,11 @@ | |
| 65076 | } |
| 65077 | return rc; |
| 65078 | } |
| 65079 | |
| 65080 | /* |
| 65081 | ** Change the size to which the WAL file is trucated on each reset. |
| 65082 | */ |
| 65083 | SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){ |
| 65084 | if( pWal ) pWal->mxWalSize = iLimit; |
| 65085 | } |
| 65086 | |
| @@ -65775,11 +65959,11 @@ | |
| 65775 | sqlite3OsFileControlHint( |
| 65776 | pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist |
| 65777 | ); |
| 65778 | if( bPersist!=1 ){ |
| 65779 | /* Try to delete the WAL file if the checkpoint completed and |
| 65780 | ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal |
| 65781 | ** mode (!bPersist) */ |
| 65782 | isDelete = 1; |
| 65783 | }else if( pWal->mxWalSize>=0 ){ |
| 65784 | /* Try to truncate the WAL file to zero bytes if the checkpoint |
| 65785 | ** completed and fsynced (rc==SQLITE_OK) and we are in persistent |
| @@ -65842,11 +66026,11 @@ | |
| 65842 | ** Memory barriers are used to prevent the compiler or the hardware from |
| 65843 | ** reordering the reads and writes. TSAN and similar tools can sometimes |
| 65844 | ** give false-positive warnings about these accesses because the tools do not |
| 65845 | ** account for the double-read and the memory barrier. The use of mutexes |
| 65846 | ** here would be problematic as the memory being accessed is potentially |
| 65847 | ** shared among multiple processes and not all mutex implementions work |
| 65848 | ** reliably in that environment. |
| 65849 | */ |
| 65850 | aHdr = walIndexHdr(pWal); |
| 65851 | memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */ |
| 65852 | walShmBarrier(pWal); |
| @@ -67947,11 +68131,11 @@ | |
| 67947 | /* |
| 67948 | ** An instance of this object stores information about each a single database |
| 67949 | ** page that has been loaded into memory. The information in this object |
| 67950 | ** is derived from the raw on-disk page content. |
| 67951 | ** |
| 67952 | ** As each database page is loaded into memory, the pager allocats an |
| 67953 | ** instance of this object and zeros the first 8 bytes. (This is the |
| 67954 | ** "extra" information associated with each page of the pager.) |
| 67955 | ** |
| 67956 | ** Access to all fields of this structure is controlled by the mutex |
| 67957 | ** stored in MemPage.pBt->mutex. |
| @@ -68403,11 +68587,11 @@ | |
| 68403 | #define get4byte sqlite3Get4byte |
| 68404 | #define put4byte sqlite3Put4byte |
| 68405 | |
| 68406 | /* |
| 68407 | ** get2byteAligned(), unlike get2byte(), requires that its argument point to a |
| 68408 | ** two-byte aligned address. get2bytea() is only used for accessing the |
| 68409 | ** cell addresses in a btree header. |
| 68410 | */ |
| 68411 | #if SQLITE_BYTEORDER==4321 |
| 68412 | # define get2byteAligned(x) (*(u16*)(x)) |
| 68413 | #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000 |
| @@ -68580,11 +68764,11 @@ | |
| 68580 | ** against all schemas and we do not want those schemas being |
| 68581 | ** reset out from under us. |
| 68582 | ** |
| 68583 | ** There is a corresponding leave-all procedures. |
| 68584 | ** |
| 68585 | ** Enter the mutexes in accending order by BtShared pointer address |
| 68586 | ** to avoid the possibility of deadlock when two threads with |
| 68587 | ** two or more btrees in common both try to lock all their btrees |
| 68588 | ** at the same instant. |
| 68589 | */ |
| 68590 | static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){ |
| @@ -68712,10 +68896,11 @@ | |
| 68712 | |
| 68713 | #endif /* ifndef SQLITE_OMIT_SHARED_CACHE */ |
| 68714 | |
| 68715 | /************** End of btmutex.c *********************************************/ |
| 68716 | /************** Begin file btree.c *******************************************/ |
| 68717 | /* |
| 68718 | ** 2004 April 6 |
| 68719 | ** |
| 68720 | ** The author disclaims copyright to this source code. In place of |
| 68721 | ** a legal notice, here is a blessing: |
| @@ -70348,11 +70533,11 @@ | |
| 70348 | cbrk = usableSize; |
| 70349 | iCellLast = usableSize - 4; |
| 70350 | iCellStart = get2byte(&data[hdr+5]); |
| 70351 | if( nCell>0 ){ |
| 70352 | temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 70353 | memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart); |
| 70354 | src = temp; |
| 70355 | for(i=0; i<nCell; i++){ |
| 70356 | u8 *pAddr; /* The i-th cell pointer */ |
| 70357 | pAddr = &data[cellOffset + i*2]; |
| 70358 | pc = get2byte(pAddr); |
| @@ -70572,11 +70757,11 @@ | |
| 70572 | ** |
| 70573 | ** Adjacent freeblocks are coalesced. |
| 70574 | ** |
| 70575 | ** Even though the freeblock list was checked by btreeComputeFreeSpace(), |
| 70576 | ** that routine will not detect overlap between cells or freeblocks. Nor |
| 70577 | ** does it detect cells or freeblocks that encrouch into the reserved bytes |
| 70578 | ** at the end of the page. So do additional corruption checks inside this |
| 70579 | ** routine and return SQLITE_CORRUPT if any problems are found. |
| 70580 | */ |
| 70581 | static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ |
| 70582 | u16 iPtr; /* Address of ptr to next freeblock */ |
| @@ -71175,11 +71360,11 @@ | |
| 71175 | /* pPage might not be a btree page; it might be an overflow page |
| 71176 | ** or ptrmap page or a free page. In those cases, the following |
| 71177 | ** call to btreeInitPage() will likely return SQLITE_CORRUPT. |
| 71178 | ** But no harm is done by this. And it is very important that |
| 71179 | ** btreeInitPage() be called on every btree page so we make |
| 71180 | ** the call for every page that comes in for re-initing. */ |
| 71181 | btreeInitPage(pPage); |
| 71182 | } |
| 71183 | } |
| 71184 | } |
| 71185 | |
| @@ -71570,11 +71755,11 @@ | |
| 71570 | ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes |
| 71571 | ** by the various routines that manipulate binary cells. Which |
| 71572 | ** can mean that fillInCell() only initializes the first 2 or 3 |
| 71573 | ** bytes of pTmpSpace, but that the first 4 bytes are copied from |
| 71574 | ** it into a database page. This is not actually a problem, but it |
| 71575 | ** does cause a valgrind error when the 1 or 2 bytes of unitialized |
| 71576 | ** data is passed to system call write(). So to avoid this error, |
| 71577 | ** zero the first 4 bytes of temp space here. |
| 71578 | ** |
| 71579 | ** Also: Provide four bytes of initialized space before the |
| 71580 | ** beginning of pTmpSpace as an area available to prepend the |
| @@ -71805,11 +71990,11 @@ | |
| 71805 | return n; |
| 71806 | } |
| 71807 | |
| 71808 | /* |
| 71809 | ** Return the number of bytes of space at the end of every page that |
| 71810 | ** are intentually left unused. This is the "reserved" space that is |
| 71811 | ** sometimes used by extensions. |
| 71812 | ** |
| 71813 | ** The value returned is the larger of the current reserve size and |
| 71814 | ** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES. |
| 71815 | ** The amount of reserve can only grow - never shrink. |
| @@ -72052,11 +72237,10 @@ | |
| 72052 | || pageSize>SQLITE_MAX_PAGE_SIZE |
| 72053 | || pageSize<=256 |
| 72054 | ){ |
| 72055 | goto page1_init_failed; |
| 72056 | } |
| 72057 | pBt->btsFlags |= BTS_PAGESIZE_FIXED; |
| 72058 | assert( (pageSize & 7)==0 ); |
| 72059 | /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte |
| 72060 | ** integer at offset 20 is the number of bytes of space at the end of |
| 72061 | ** each page to reserve for extensions. |
| 72062 | ** |
| @@ -72072,10 +72256,11 @@ | |
| 72072 | ** again with the correct page-size. |
| 72073 | */ |
| 72074 | releasePageOne(pPage1); |
| 72075 | pBt->usableSize = usableSize; |
| 72076 | pBt->pageSize = pageSize; |
| 72077 | freeTempSpace(pBt); |
| 72078 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, |
| 72079 | pageSize-usableSize); |
| 72080 | return rc; |
| 72081 | } |
| @@ -72091,10 +72276,11 @@ | |
| 72091 | ** be less than 480. In other words, if the page size is 512, then the |
| 72092 | ** reserved space size cannot exceed 32. */ |
| 72093 | if( usableSize<480 ){ |
| 72094 | goto page1_init_failed; |
| 72095 | } |
| 72096 | pBt->pageSize = pageSize; |
| 72097 | pBt->usableSize = usableSize; |
| 72098 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 72099 | pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0); |
| 72100 | pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0); |
| @@ -72269,11 +72455,15 @@ | |
| 72269 | ** One or the other of the two processes must give way or there can be |
| 72270 | ** no progress. By returning SQLITE_BUSY and not invoking the busy callback |
| 72271 | ** when A already has a read lock, we encourage A to give up and let B |
| 72272 | ** proceed. |
| 72273 | */ |
| 72274 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ |
| 72275 | BtShared *pBt = p->pBt; |
| 72276 | Pager *pPager = pBt->pPager; |
| 72277 | int rc = SQLITE_OK; |
| 72278 | |
| 72279 | sqlite3BtreeEnter(p); |
| @@ -72440,10 +72630,32 @@ | |
| 72440 | } |
| 72441 | |
| 72442 | btreeIntegrity(p); |
| 72443 | sqlite3BtreeLeave(p); |
| 72444 | return rc; |
| 72445 | } |
| 72446 | |
| 72447 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 72448 | |
| 72449 | /* |
| @@ -73574,11 +73786,11 @@ | |
| 73574 | ** |
| 73575 | ** This is an optimization. Everything will still work if this |
| 73576 | ** routine always returns 2147483647 (which is the largest record |
| 73577 | ** that SQLite can handle) or more. But returning a smaller value might |
| 73578 | ** prevent large memory allocations when trying to interpret a |
| 73579 | ** corrupt datrabase. |
| 73580 | ** |
| 73581 | ** The current implementation merely returns the size of the underlying |
| 73582 | ** database file. |
| 73583 | */ |
| 73584 | SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){ |
| @@ -74374,11 +74586,11 @@ | |
| 74374 | return SQLITE_OK; |
| 74375 | } |
| 74376 | /* If the requested key is one more than the previous key, then |
| 74377 | ** try to get there using sqlite3BtreeNext() rather than a full |
| 74378 | ** binary search. This is an optimization only. The correct answer |
| 74379 | ** is still obtained without this case, only a little more slowely */ |
| 74380 | if( pCur->info.nKey+1==intKey ){ |
| 74381 | *pRes = 0; |
| 74382 | rc = sqlite3BtreeNext(pCur, 0); |
| 74383 | if( rc==SQLITE_OK ){ |
| 74384 | getCellInfo(pCur); |
| @@ -75557,11 +75769,11 @@ | |
| 75557 | return SQLITE_OK; |
| 75558 | } |
| 75559 | |
| 75560 | /* Call xParseCell to compute the size of a cell. If the cell contains |
| 75561 | ** overflow, then invoke cellClearOverflow to clear out that overflow. |
| 75562 | ** STore the result code (SQLITE_OK or some error code) in rc. |
| 75563 | ** |
| 75564 | ** Implemented as macro to force inlining for performance. |
| 75565 | */ |
| 75566 | #define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \ |
| 75567 | pPage->xParseCell(pPage, pCell, &sInfo); \ |
| @@ -76236,11 +76448,11 @@ | |
| 76236 | ** before returning. |
| 76237 | ** |
| 76238 | ** Finally, argument pBegin points to the byte immediately following the |
| 76239 | ** end of the space required by this page for the cell-pointer area (for |
| 76240 | ** all cells - not just those inserted by the current call). If the content |
| 76241 | ** area must be extended to before this point in order to accomodate all |
| 76242 | ** cells in apCell[], then the cells do not fit and non-zero is returned. |
| 76243 | */ |
| 76244 | static int pageInsertArray( |
| 76245 | MemPage *pPg, /* Page to add cells to */ |
| 76246 | u8 *pBegin, /* End of cell-pointer array */ |
| @@ -76551,11 +76763,11 @@ | |
| 76551 | |
| 76552 | /* If this is an auto-vacuum database, update the pointer map |
| 76553 | ** with entries for the new page, and any pointer from the |
| 76554 | ** cell on the page to an overflow page. If either of these |
| 76555 | ** operations fails, the return code is set, but the contents |
| 76556 | ** of the parent page are still manipulated by thh code below. |
| 76557 | ** That is Ok, at this point the parent page is guaranteed to |
| 76558 | ** be marked as dirty. Returning an error code will cause a |
| 76559 | ** rollback, undoing any changes made to the parent page. |
| 76560 | */ |
| 76561 | if( ISAUTOVACUUM(pBt) ){ |
| @@ -77141,11 +77353,11 @@ | |
| 77141 | rc = SQLITE_CORRUPT_BKPT; |
| 77142 | goto balance_cleanup; |
| 77143 | } |
| 77144 | } |
| 77145 | |
| 77146 | /* Sanity check: For a non-corrupt database file one of the follwing |
| 77147 | ** must be true: |
| 77148 | ** (1) We found one or more cells (cntNew[0])>0), or |
| 77149 | ** (2) pPage is a virtual root page. A virtual root page is when |
| 77150 | ** the real root page is page 1 and we are the only child of |
| 77151 | ** that page. |
| @@ -77758,11 +77970,11 @@ | |
| 77758 | int iOffset, /* Offset of first byte to write */ |
| 77759 | int iAmt /* Number of bytes to be written */ |
| 77760 | ){ |
| 77761 | int nData = pX->nData - iOffset; |
| 77762 | if( nData<=0 ){ |
| 77763 | /* Overwritting with zeros */ |
| 77764 | int i; |
| 77765 | for(i=0; i<iAmt && pDest[i]==0; i++){} |
| 77766 | if( i<iAmt ){ |
| 77767 | int rc = sqlite3PagerWrite(pPage->pDbPage); |
| 77768 | if( rc ) return rc; |
| @@ -77794,11 +78006,11 @@ | |
| 77794 | ** Overwrite the cell that cursor pCur is pointing to with fresh content |
| 77795 | ** contained in pX. In this variant, pCur is pointing to an overflow |
| 77796 | ** cell. |
| 77797 | */ |
| 77798 | static SQLITE_NOINLINE int btreeOverwriteOverflowCell( |
| 77799 | BtCursor *pCur, /* Cursor pointing to cell to ovewrite */ |
| 77800 | const BtreePayload *pX /* Content to write into the cell */ |
| 77801 | ){ |
| 77802 | int iOffset; /* Next byte of pX->pData to write */ |
| 77803 | int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */ |
| 77804 | int rc; /* Return code */ |
| @@ -78541,11 +78753,11 @@ | |
| 78541 | static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ |
| 78542 | BtShared *pBt = p->pBt; |
| 78543 | MemPage *pRoot; |
| 78544 | Pgno pgnoRoot; |
| 78545 | int rc; |
| 78546 | int ptfFlags; /* Page-type flage for the root page of new table */ |
| 78547 | |
| 78548 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 78549 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 78550 | assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 78551 | |
| @@ -79376,11 +79588,11 @@ | |
| 79376 | pBt = pCheck->pBt; |
| 79377 | usableSize = pBt->usableSize; |
| 79378 | if( iPage==0 ) return 0; |
| 79379 | if( checkRef(pCheck, iPage) ) return 0; |
| 79380 | pCheck->zPfx = "Tree %u page %u: "; |
| 79381 | pCheck->v0 = pCheck->v1 = iPage; |
| 79382 | if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){ |
| 79383 | checkAppendMsg(pCheck, |
| 79384 | "unable to get the page. error code=%d", rc); |
| 79385 | goto end_of_check; |
| 79386 | } |
| @@ -79713,10 +79925,11 @@ | |
| 79713 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 79714 | if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){ |
| 79715 | checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0); |
| 79716 | } |
| 79717 | #endif |
| 79718 | checkTreePage(&sCheck, aRoot[i], ¬Used, LARGEST_INT64); |
| 79719 | } |
| 79720 | pBt->db->flags = savedDbFlags; |
| 79721 | |
| 79722 | /* Make sure every page in the file is referenced |
| @@ -82256,10 +82469,11 @@ | |
| 82256 | if( pRec==0 ) return 0; |
| 82257 | p->ppRec[0] = pRec; |
| 82258 | } |
| 82259 | |
| 82260 | pRec->nField = p->iVal+1; |
| 82261 | return &pRec->aMem[p->iVal]; |
| 82262 | } |
| 82263 | #else |
| 82264 | UNUSED_PARAMETER(p); |
| 82265 | #endif /* defined(SQLITE_ENABLE_STAT4) */ |
| @@ -83652,11 +83866,11 @@ | |
| 83652 | assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */ |
| 83653 | p->readOnly = 1; |
| 83654 | p->bIsReader = 0; |
| 83655 | pOp = &p->aOp[p->nOp-1]; |
| 83656 | assert( p->aOp[0].opcode==OP_Init ); |
| 83657 | while( 1 /* Loop termates when it reaches the OP_Init opcode */ ){ |
| 83658 | /* Only JUMP opcodes and the short list of special opcodes in the switch |
| 83659 | ** below need to be considered. The mkopcodeh.tcl generator script groups |
| 83660 | ** all these opcodes together near the front of the opcode list. Skip |
| 83661 | ** any opcode that does not need processing by virtual of the fact that |
| 83662 | ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization. |
| @@ -84106,11 +84320,11 @@ | |
| 84106 | } |
| 84107 | |
| 84108 | |
| 84109 | /* |
| 84110 | ** If the input FuncDef structure is ephemeral, then free it. If |
| 84111 | ** the FuncDef is not ephermal, then do nothing. |
| 84112 | */ |
| 84113 | static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){ |
| 84114 | assert( db!=0 ); |
| 84115 | if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){ |
| 84116 | sqlite3DbNNFreeNN(db, pDef); |
| @@ -87057,10 +87271,19 @@ | |
| 87057 | ** sqlite3VdbeSerialTypeLen() in the common case. |
| 87058 | */ |
| 87059 | if( d1+(u64)serial_type1+2>(u64)nKey1 |
| 87060 | && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)>(u64)nKey1 |
| 87061 | ){ |
| 87062 | break; |
| 87063 | } |
| 87064 | |
| 87065 | /* Extract the values to be compared. |
| 87066 | */ |
| @@ -87500,11 +87723,11 @@ | |
| 87500 | serial_type = aKey1[idx1]; |
| 87501 | if( serial_type>=10 ){ |
| 87502 | /* Serial types 12 or greater are strings and blobs (greater than |
| 87503 | ** numbers). Types 10 and 11 are currently "reserved for future |
| 87504 | ** use", so it doesn't really matter what the results of comparing |
| 87505 | ** them to numberic values are. */ |
| 87506 | rc = serial_type==10 ? -1 : +1; |
| 87507 | }else if( serial_type==0 ){ |
| 87508 | rc = -1; |
| 87509 | }else{ |
| 87510 | sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); |
| @@ -89129,11 +89352,11 @@ | |
| 89129 | |
| 89130 | /* |
| 89131 | ** The destructor function for a ValueList object. This needs to be |
| 89132 | ** a separate function, unknowable to the application, to ensure that |
| 89133 | ** calls to sqlite3_vtab_in_first()/sqlite3_vtab_in_next() that are not |
| 89134 | ** preceeded by activation of IN processing via sqlite3_vtab_int() do not |
| 89135 | ** try to access a fake ValueList object inserted by a hostile extension. |
| 89136 | */ |
| 89137 | SQLITE_PRIVATE void sqlite3VdbeValueListFree(void *pToDelete){ |
| 89138 | sqlite3_free(pToDelete); |
| 89139 | } |
| @@ -89458,11 +89681,11 @@ | |
| 89458 | ** sqlite3_column_text() |
| 89459 | ** sqlite3_column_text16() |
| 89460 | ** sqlite3_column_real() |
| 89461 | ** sqlite3_column_bytes() |
| 89462 | ** sqlite3_column_bytes16() |
| 89463 | ** sqiite3_column_blob() |
| 89464 | */ |
| 89465 | static void columnMallocFailure(sqlite3_stmt *pStmt) |
| 89466 | { |
| 89467 | /* If malloc() failed during an encoding conversion within an |
| 89468 | ** sqlite3_column_XXX API, then set the return code of the statement to |
| @@ -89693,11 +89916,11 @@ | |
| 89693 | ** Routines used to attach values to wildcards in a compiled SQL statement. |
| 89694 | */ |
| 89695 | /* |
| 89696 | ** Unbind the value bound to variable i in virtual machine p. This is the |
| 89697 | ** the same as binding a NULL value to the column. If the "i" parameter is |
| 89698 | ** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK. |
| 89699 | ** |
| 89700 | ** A successful evaluation of this routine acquires the mutex on p. |
| 89701 | ** the mutex is released if any kind of error occurs. |
| 89702 | ** |
| 89703 | ** The error code stored in database p->db is overwritten with the return |
| @@ -91669,12 +91892,12 @@ | |
| 91669 | ** to the current line should be indented for EXPLAIN output. |
| 91670 | */ |
| 91671 | case OP_Goto: { /* jump */ |
| 91672 | |
| 91673 | #ifdef SQLITE_DEBUG |
| 91674 | /* In debuggging mode, when the p5 flags is set on an OP_Goto, that |
| 91675 | ** means we should really jump back to the preceeding OP_ReleaseReg |
| 91676 | ** instruction. */ |
| 91677 | if( pOp->p5 ){ |
| 91678 | assert( pOp->p2 < (int)(pOp - aOp) ); |
| 91679 | assert( pOp->p2 > 1 ); |
| 91680 | pOp = &aOp[pOp->p2 - 2]; |
| @@ -91878,11 +92101,11 @@ | |
| 91878 | ** If P4 is not null then it is an error message string. |
| 91879 | ** |
| 91880 | ** P5 is a value between 0 and 4, inclusive, that modifies the P4 string. |
| 91881 | ** |
| 91882 | ** 0: (no change) |
| 91883 | ** 1: NOT NULL contraint failed: P4 |
| 91884 | ** 2: UNIQUE constraint failed: P4 |
| 91885 | ** 3: CHECK constraint failed: P4 |
| 91886 | ** 4: FOREIGN KEY constraint failed: P4 |
| 91887 | ** |
| 91888 | ** If P5 is not zero and P4 is NULL, then everything after the ":" is |
| @@ -95105,11 +95328,11 @@ | |
| 95105 | aMem[pOp->p3].n = 0; |
| 95106 | aMem[pOp->p3].z = ""; |
| 95107 | } |
| 95108 | pCx = p->apCsr[pOp->p1]; |
| 95109 | if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){ |
| 95110 | /* If the ephermeral table is already open and has no duplicates from |
| 95111 | ** OP_OpenDup, then erase all existing content so that the table is |
| 95112 | ** empty again, rather than creating a new table. */ |
| 95113 | assert( pCx->isEphemeral ); |
| 95114 | pCx->seqCount = 0; |
| 95115 | pCx->cacheStatus = CACHE_STALE; |
| @@ -95596,19 +95819,19 @@ | |
| 95596 | ** The This.P5 parameter is a flag that indicates what to do if the |
| 95597 | ** cursor ends up pointing at a valid row that is past the target |
| 95598 | ** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If |
| 95599 | ** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0 |
| 95600 | ** case occurs when there are no inequality constraints to the right of |
| 95601 | ** the IN constraing. The jump to SeekGE.P2 ends the loop. The P5!=0 case |
| 95602 | ** occurs when there are inequality constraints to the right of the IN |
| 95603 | ** operator. In that case, the This.P2 will point either directly to or |
| 95604 | ** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for |
| 95605 | ** loop terminate. |
| 95606 | ** |
| 95607 | ** Possible outcomes from this opcode:<ol> |
| 95608 | ** |
| 95609 | ** <li> If the cursor is initally not pointed to any valid row, then |
| 95610 | ** fall through into the subsequent OP_SeekGE opcode. |
| 95611 | ** |
| 95612 | ** <li> If the cursor is left pointing to a row that is before the target |
| 95613 | ** row, even after making as many as This.P1 calls to |
| 95614 | ** sqlite3BtreeNext(), then also fall through into OP_SeekGE. |
| @@ -98277,11 +98500,11 @@ | |
| 98277 | #endif |
| 98278 | |
| 98279 | /* If this function is inside of a trigger, the register array in aMem[] |
| 98280 | ** might change from one evaluation to the next. The next block of code |
| 98281 | ** checks to see if the register array has changed, and if so it |
| 98282 | ** reinitializes the relavant parts of the sqlite3_context object */ |
| 98283 | if( pCtx->pMem != pMem ){ |
| 98284 | pCtx->pMem = pMem; |
| 98285 | for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; |
| 98286 | } |
| 98287 | |
| @@ -99155,11 +99378,11 @@ | |
| 99155 | ** invocation of this opcode. |
| 99156 | ** |
| 99157 | ** This opcode works exactly like OP_Function. The only difference is in |
| 99158 | ** its name. This opcode is used in places where the function must be |
| 99159 | ** purely non-deterministic. Some built-in date/time functions can be |
| 99160 | ** either determinitic of non-deterministic, depending on their arguments. |
| 99161 | ** When those function are used in a non-deterministic way, they will check |
| 99162 | ** to see if they were called using OP_PureFunc instead of OP_Function, and |
| 99163 | ** if they were, they throw an error. |
| 99164 | ** |
| 99165 | ** See also: AggStep, AggFinal, Function |
| @@ -99173,11 +99396,11 @@ | |
| 99173 | pCtx = pOp->p4.pCtx; |
| 99174 | |
| 99175 | /* If this function is inside of a trigger, the register array in aMem[] |
| 99176 | ** might change from one evaluation to the next. The next block of code |
| 99177 | ** checks to see if the register array has changed, and if so it |
| 99178 | ** reinitializes the relavant parts of the sqlite3_context object */ |
| 99179 | pOut = &aMem[pOp->p3]; |
| 99180 | if( pCtx->pOut != pOut ){ |
| 99181 | pCtx->pVdbe = p; |
| 99182 | pCtx->pOut = pOut; |
| 99183 | pCtx->enc = encoding; |
| @@ -99249,11 +99472,11 @@ | |
| 99249 | registerTrace(ii, &aMem[ii]); |
| 99250 | } |
| 99251 | printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); |
| 99252 | } |
| 99253 | #endif |
| 99254 | h %= pIn1->n; |
| 99255 | pIn1->z[h/8] |= 1<<(h&7); |
| 99256 | break; |
| 99257 | } |
| 99258 | |
| 99259 | /* Opcode: Filter P1 P2 P3 P4 * |
| @@ -99285,11 +99508,11 @@ | |
| 99285 | registerTrace(ii, &aMem[ii]); |
| 99286 | } |
| 99287 | printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); |
| 99288 | } |
| 99289 | #endif |
| 99290 | h %= pIn1->n; |
| 99291 | if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){ |
| 99292 | VdbeBranchTaken(1, 2); |
| 99293 | p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++; |
| 99294 | goto jump_to_p2; |
| 99295 | }else{ |
| @@ -99537,11 +99760,11 @@ | |
| 99537 | if( opProperty & OPFLG_OUT3 ){ |
| 99538 | registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); |
| 99539 | } |
| 99540 | if( opProperty==0xff ){ |
| 99541 | /* Never happens. This code exists to avoid a harmless linkage |
| 99542 | ** warning aboud sqlite3VdbeRegisterDump() being defined but not |
| 99543 | ** used. */ |
| 99544 | sqlite3VdbeRegisterDump(p); |
| 99545 | } |
| 99546 | } |
| 99547 | #endif /* SQLITE_DEBUG */ |
| @@ -100255,11 +100478,11 @@ | |
| 100255 | ** merging two or more level-0 PMAs together creates a level-1 PMA. |
| 100256 | ** |
| 100257 | ** The threshold for the amount of main memory to use before flushing |
| 100258 | ** records to a PMA is roughly the same as the limit configured for the |
| 100259 | ** page-cache of the main database. Specifically, the threshold is set to |
| 100260 | ** the value returned by "PRAGMA main.page_size" multipled by |
| 100261 | ** that returned by "PRAGMA main.cache_size", in bytes. |
| 100262 | ** |
| 100263 | ** If the sorter is running in single-threaded mode, then all PMAs generated |
| 100264 | ** are appended to a single temporary file. Or, if the sorter is running in |
| 100265 | ** multi-threaded mode then up to (N+1) temporary files may be opened, where |
| @@ -100278,11 +100501,11 @@ | |
| 100278 | ** final PMA. So at this point the data is stored in some number of sorted |
| 100279 | ** PMAs within temporary files on disk. |
| 100280 | ** |
| 100281 | ** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the |
| 100282 | ** sorter is running in single-threaded mode, then these PMAs are merged |
| 100283 | ** incrementally as keys are retreived from the sorter by the VDBE. The |
| 100284 | ** MergeEngine object, described in further detail below, performs this |
| 100285 | ** merge. |
| 100286 | ** |
| 100287 | ** Or, if running in multi-threaded mode, then a background thread is |
| 100288 | ** launched to merge the existing PMAs. Once the background thread has |
| @@ -100441,11 +100664,11 @@ | |
| 100441 | ** single-threaded operation, there is exactly one instance of this object |
| 100442 | ** and for multi-threaded operation there are two or more instances. |
| 100443 | ** |
| 100444 | ** Essentially, this structure contains all those fields of the VdbeSorter |
| 100445 | ** structure for which each thread requires a separate instance. For example, |
| 100446 | ** each thread requries its own UnpackedRecord object to unpack records in |
| 100447 | ** as part of comparison operations. |
| 100448 | ** |
| 100449 | ** Before a background thread is launched, variable bDone is set to 0. Then, |
| 100450 | ** right before it exits, the thread itself sets bDone to 1. This is used for |
| 100451 | ** two purposes: |
| @@ -100513,11 +100736,11 @@ | |
| 100513 | /* |
| 100514 | ** An instance of the following object is used to read records out of a |
| 100515 | ** PMA, in sorted order. The next key to be read is cached in nKey/aKey. |
| 100516 | ** aKey might point into aMap or into aBuffer. If neither of those locations |
| 100517 | ** contain a contiguous representation of the key, then aAlloc is allocated |
| 100518 | ** and the key is copied into aAlloc and aKey is made to poitn to aAlloc. |
| 100519 | ** |
| 100520 | ** pFd==0 at EOF. |
| 100521 | */ |
| 100522 | struct PmaReader { |
| 100523 | i64 iReadOff; /* Current read offset */ |
| @@ -101884,11 +102107,11 @@ | |
| 101884 | ** records to disk. If the sorter is running in multi-threaded mode, |
| 101885 | ** round-robin between the first (pSorter->nTask-1) tasks. Except, if |
| 101886 | ** the background thread from a sub-tasks previous turn is still running, |
| 101887 | ** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy, |
| 101888 | ** fall back to using the final sub-task. The first (pSorter->nTask-1) |
| 101889 | ** sub-tasks are prefered as they use background threads - the final |
| 101890 | ** sub-task uses the main thread. */ |
| 101891 | for(i=0; i<nWorker; i++){ |
| 101892 | int iTest = (pSorter->iPrev + i + 1) % nWorker; |
| 101893 | pTask = &pSorter->aTask[iTest]; |
| 101894 | if( pTask->bDone ){ |
| @@ -102368,11 +102591,11 @@ | |
| 102368 | /* eMode is always INCRINIT_NORMAL in single-threaded mode */ |
| 102369 | assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL ); |
| 102370 | |
| 102371 | rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); |
| 102372 | |
| 102373 | /* Set up the required files for pIncr. A multi-theaded IncrMerge object |
| 102374 | ** requires two temp files to itself, whereas a single-threaded object |
| 102375 | ** only requires a region of pTask->file2. */ |
| 102376 | if( rc==SQLITE_OK ){ |
| 102377 | int mxSz = pIncr->mxSz; |
| 102378 | #if SQLITE_MAX_WORKER_THREADS>0 |
| @@ -104033,11 +104256,11 @@ | |
| 104033 | }while( p!=0 ); |
| 104034 | return WRC_Continue; |
| 104035 | } |
| 104036 | |
| 104037 | /* Increase the walkerDepth when entering a subquery, and |
| 104038 | ** descrease when leaving the subquery. |
| 104039 | */ |
| 104040 | SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *pWalker, Select *pSelect){ |
| 104041 | UNUSED_PARAMETER(pSelect); |
| 104042 | pWalker->walkerDepth++; |
| 104043 | return WRC_Continue; |
| @@ -105767,11 +105990,11 @@ | |
| 105767 | if( sqlite3ResolveExprNames(pNC, pE) ){ |
| 105768 | return 1; |
| 105769 | } |
| 105770 | for(j=0; j<pSelect->pEList->nExpr; j++){ |
| 105771 | if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){ |
| 105772 | /* Since this expresion is being changed into a reference |
| 105773 | ** to an identical expression in the result set, remove all Window |
| 105774 | ** objects belonging to the expression from the Select.pWin list. */ |
| 105775 | windowRemoveExprFromSelect(pSelect, pE); |
| 105776 | pItem->u.x.iOrderByCol = j+1; |
| 105777 | } |
| @@ -106154,11 +106377,11 @@ | |
| 106154 | return WRC_Continue; |
| 106155 | } |
| 106156 | |
| 106157 | /* |
| 106158 | ** Resolve all names in all expressions of a SELECT and in all |
| 106159 | ** decendents of the SELECT, including compounds off of p->pPrior, |
| 106160 | ** subqueries in expressions, and subqueries used as FROM clause |
| 106161 | ** terms. |
| 106162 | ** |
| 106163 | ** See sqlite3ResolveExprNames() for a description of the kinds of |
| 106164 | ** transformations that occur. |
| @@ -106304,10 +106527,11 @@ | |
| 106304 | } |
| 106305 | #endif |
| 106306 | if( op==TK_SELECT_COLUMN ){ |
| 106307 | assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) ); |
| 106308 | assert( pExpr->iColumn < pExpr->iTable ); |
| 106309 | assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr ); |
| 106310 | return sqlite3ExprAffinity( |
| 106311 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| 106312 | ); |
| 106313 | } |
| @@ -106540,11 +106764,11 @@ | |
| 106540 | } |
| 106541 | |
| 106542 | /* |
| 106543 | ** Return the collation sequence for the expression pExpr. If |
| 106544 | ** there is no defined collating sequence, return a pointer to the |
| 106545 | ** defautl collation sequence. |
| 106546 | ** |
| 106547 | ** See also: sqlite3ExprCollSeq() |
| 106548 | ** |
| 106549 | ** The sqlite3ExprCollSeq() routine works the same except that it |
| 106550 | ** returns NULL if there is no defined collation. |
| @@ -106670,11 +106894,11 @@ | |
| 106670 | } |
| 106671 | } |
| 106672 | return pColl; |
| 106673 | } |
| 106674 | |
| 106675 | /* Expresssion p is a comparison operator. Return a collation sequence |
| 106676 | ** appropriate for the comparison operator. |
| 106677 | ** |
| 106678 | ** This is normally just a wrapper around sqlite3BinaryCompareCollSeq(). |
| 106679 | ** However, if the OP_Commuted flag is set, then the order of the operands |
| 106680 | ** is reversed in the sqlite3BinaryCompareCollSeq() call so that the |
| @@ -107586,11 +107810,11 @@ | |
| 107586 | } |
| 107587 | |
| 107588 | /* |
| 107589 | ** Arrange to cause pExpr to be deleted when the pParse is deleted. |
| 107590 | ** This is similar to sqlite3ExprDelete() except that the delete is |
| 107591 | ** deferred untilthe pParse is deleted. |
| 107592 | ** |
| 107593 | ** The pExpr might be deleted immediately on an OOM error. |
| 107594 | ** |
| 107595 | ** The deferred delete is (currently) implemented by adding the |
| 107596 | ** pExpr to the pParse->pConstExpr list with a register number of 0. |
| @@ -108428,11 +108652,11 @@ | |
| 108428 | /* |
| 108429 | ** The argument must be a TK_TRUEFALSE Expr node. Return 1 if it is TRUE |
| 108430 | ** and 0 if it is FALSE. |
| 108431 | */ |
| 108432 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){ |
| 108433 | pExpr = sqlite3ExprSkipCollate((Expr*)pExpr); |
| 108434 | assert( pExpr->op==TK_TRUEFALSE ); |
| 108435 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 108436 | assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0 |
| 108437 | || sqlite3StrICmp(pExpr->u.zToken,"false")==0 ); |
| 108438 | return pExpr->u.zToken[4]==0; |
| @@ -109021,11 +109245,11 @@ | |
| 109021 | ** |
| 109022 | ** IN_INDEX_ROWID - The cursor was opened on a database table. |
| 109023 | ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index. |
| 109024 | ** IN_INDEX_INDEX_DESC - The cursor was opened on a descending index. |
| 109025 | ** IN_INDEX_EPH - The cursor was opened on a specially created and |
| 109026 | ** populated epheremal table. |
| 109027 | ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be |
| 109028 | ** implemented as a sequence of comparisons. |
| 109029 | ** |
| 109030 | ** An existing b-tree might be used if the RHS expression pX is a simple |
| 109031 | ** subquery such as: |
| @@ -109034,11 +109258,11 @@ | |
| 109034 | ** |
| 109035 | ** If the RHS of the IN operator is a list or a more complex subquery, then |
| 109036 | ** an ephemeral table might need to be generated from the RHS and then |
| 109037 | ** pX->iTable made to point to the ephemeral table instead of an |
| 109038 | ** existing table. In this case, the creation and initialization of the |
| 109039 | ** ephmeral table might be put inside of a subroutine, the EP_Subrtn flag |
| 109040 | ** will be set on pX and the pX->y.sub fields will be set to show where |
| 109041 | ** the subroutine is coded. |
| 109042 | ** |
| 109043 | ** The inFlags parameter must contain, at a minimum, one of the bits |
| 109044 | ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains |
| @@ -109046,16 +109270,16 @@ | |
| 109046 | ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will |
| 109047 | ** be used to loop over all values of the RHS of the IN operator. |
| 109048 | ** |
| 109049 | ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate |
| 109050 | ** through the set members) then the b-tree must not contain duplicates. |
| 109051 | ** An epheremal table will be created unless the selected columns are guaranteed |
| 109052 | ** to be unique - either because it is an INTEGER PRIMARY KEY or due to |
| 109053 | ** a UNIQUE constraint or index. |
| 109054 | ** |
| 109055 | ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used |
| 109056 | ** for fast set membership tests) then an epheremal table must |
| 109057 | ** be used unless <columns> is a single INTEGER PRIMARY KEY column or an |
| 109058 | ** index can be found with the specified <columns> as its left-most. |
| 109059 | ** |
| 109060 | ** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and |
| 109061 | ** if the RHS of the IN operator is a list (not a subquery) then this |
| @@ -109384,11 +109608,11 @@ | |
| 109384 | ** |
| 109385 | ** x IN (4,5,11) -- IN operator with list on right-hand side |
| 109386 | ** x IN (SELECT a FROM b) -- IN operator with subquery on the right |
| 109387 | ** |
| 109388 | ** The pExpr parameter is the IN operator. The cursor number for the |
| 109389 | ** constructed ephermeral table is returned. The first time the ephemeral |
| 109390 | ** table is computed, the cursor number is also stored in pExpr->iTable, |
| 109391 | ** however the cursor number returned might not be the same, as it might |
| 109392 | ** have been duplicated using OP_OpenDup. |
| 109393 | ** |
| 109394 | ** If the LHS expression ("x" in the examples) is a column value, or |
| @@ -110231,11 +110455,11 @@ | |
| 110231 | ExprClearProperty(p, EP_Skip); |
| 110232 | } |
| 110233 | |
| 110234 | /* |
| 110235 | ** Evaluate an expression (either a vector or a scalar expression) and store |
| 110236 | ** the result in continguous temporary registers. Return the index of |
| 110237 | ** the first register used to store the result. |
| 110238 | ** |
| 110239 | ** If the returned result register is a temporary scalar, then also write |
| 110240 | ** that register number into *piFreeable. If the returned result register |
| 110241 | ** is not a temporary or if the expression is a vector set *piFreeable |
| @@ -110271,11 +110495,11 @@ | |
| 110271 | ** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5) |
| 110272 | ** so that a subsequent copy will not be merged into this one. |
| 110273 | */ |
| 110274 | static void setDoNotMergeFlagOnCopy(Vdbe *v){ |
| 110275 | if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){ |
| 110276 | sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergable */ |
| 110277 | } |
| 110278 | } |
| 110279 | |
| 110280 | /* |
| 110281 | ** Generate code to implement special SQL functions that are implemented |
| @@ -110361,17 +110585,17 @@ | |
| 110361 | target); |
| 110362 | break; |
| 110363 | } |
| 110364 | |
| 110365 | case INLINEFUNC_implies_nonnull_row: { |
| 110366 | /* REsult of sqlite3ExprImpliesNonNullRow() */ |
| 110367 | Expr *pA1; |
| 110368 | assert( nFarg==2 ); |
| 110369 | pA1 = pFarg->a[1].pExpr; |
| 110370 | if( pA1->op==TK_COLUMN ){ |
| 110371 | sqlite3VdbeAddOp2(v, OP_Integer, |
| 110372 | sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable), |
| 110373 | target); |
| 110374 | }else{ |
| 110375 | sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| 110376 | } |
| 110377 | break; |
| @@ -110543,11 +110767,11 @@ | |
| 110543 | int iTab = pExpr->iTable; |
| 110544 | int iReg; |
| 110545 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| 110546 | /* This COLUMN expression is really a constant due to WHERE clause |
| 110547 | ** constraints, and that constant is coded by the pExpr->pLeft |
| 110548 | ** expresssion. However, make sure the constant has the correct |
| 110549 | ** datatype by applying the Affinity of the table column to the |
| 110550 | ** constant. |
| 110551 | */ |
| 110552 | int aff; |
| 110553 | iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); |
| @@ -111272,11 +111496,11 @@ | |
| 111272 | ** once. If no functions are involved, then factor the code out and put it at |
| 111273 | ** the end of the prepared statement in the initialization section. |
| 111274 | ** |
| 111275 | ** If regDest>=0 then the result is always stored in that register and the |
| 111276 | ** result is not reusable. If regDest<0 then this routine is free to |
| 111277 | ** store the value whereever it wants. The register where the expression |
| 111278 | ** is stored is returned. When regDest<0, two identical expressions might |
| 111279 | ** code to the same register, if they do not contain function calls and hence |
| 111280 | ** are factored out into the initialization section at the end of the |
| 111281 | ** prepared statement. |
| 111282 | */ |
| @@ -112190,11 +112414,11 @@ | |
| 112190 | ** pE1: x>0 pE2: x==5 Result: false |
| 112191 | ** pE1: x=21 pE2: x=21 OR y=43 Result: true |
| 112192 | ** pE1: x!=123 pE2: x IS NOT NULL Result: true |
| 112193 | ** pE1: x!=?1 pE2: x IS NOT NULL Result: true |
| 112194 | ** pE1: x IS NULL pE2: x IS NOT NULL Result: false |
| 112195 | ** pE1: x IS ?2 pE2: x IS NOT NULL Reuslt: false |
| 112196 | ** |
| 112197 | ** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has |
| 112198 | ** Expr.iTable<0 then assume a table number given by iTab. |
| 112199 | ** |
| 112200 | ** If pParse is not NULL, then the values of bound variables in pE1 are |
| @@ -112226,68 +112450,108 @@ | |
| 112226 | ){ |
| 112227 | return 1; |
| 112228 | } |
| 112229 | return 0; |
| 112230 | } |
| 112231 | |
| 112232 | /* |
| 112233 | ** This is the Expr node callback for sqlite3ExprImpliesNonNullRow(). |
| 112234 | ** If the expression node requires that the table at pWalker->iCur |
| 112235 | ** have one or more non-NULL column, then set pWalker->eCode to 1 and abort. |
| 112236 | ** |
| 112237 | ** This routine controls an optimization. False positives (setting |
| 112238 | ** pWalker->eCode to 1 when it should not be) are deadly, but false-negatives |
| 112239 | ** (never setting pWalker->eCode) is a harmless missed optimization. |
| 112240 | */ |
| 112241 | static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){ |
| 112242 | testcase( pExpr->op==TK_AGG_COLUMN ); |
| 112243 | testcase( pExpr->op==TK_AGG_FUNCTION ); |
| 112244 | if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune; |
| 112245 | switch( pExpr->op ){ |
| 112246 | case TK_ISNOT: |
| 112247 | case TK_ISNULL: |
| 112248 | case TK_NOTNULL: |
| 112249 | case TK_IS: |
| 112250 | case TK_OR: |
| 112251 | case TK_VECTOR: |
| 112252 | case TK_CASE: |
| 112253 | case TK_IN: |
| 112254 | case TK_FUNCTION: |
| 112255 | case TK_TRUTH: |
| 112256 | testcase( pExpr->op==TK_ISNOT ); |
| 112257 | testcase( pExpr->op==TK_ISNULL ); |
| 112258 | testcase( pExpr->op==TK_NOTNULL ); |
| 112259 | testcase( pExpr->op==TK_IS ); |
| 112260 | testcase( pExpr->op==TK_OR ); |
| 112261 | testcase( pExpr->op==TK_VECTOR ); |
| 112262 | testcase( pExpr->op==TK_CASE ); |
| 112263 | testcase( pExpr->op==TK_IN ); |
| 112264 | testcase( pExpr->op==TK_FUNCTION ); |
| 112265 | testcase( pExpr->op==TK_TRUTH ); |
| 112266 | return WRC_Prune; |
| 112267 | case TK_COLUMN: |
| 112268 | if( pWalker->u.iCur==pExpr->iTable ){ |
| 112269 | pWalker->eCode = 1; |
| 112270 | return WRC_Abort; |
| 112271 | } |
| 112272 | return WRC_Prune; |
| 112273 | |
| 112274 | case TK_AND: |
| 112275 | if( pWalker->eCode==0 ){ |
| 112276 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 112277 | if( pWalker->eCode ){ |
| 112278 | pWalker->eCode = 0; |
| 112279 | sqlite3WalkExpr(pWalker, pExpr->pRight); |
| 112280 | } |
| 112281 | } |
| 112282 | return WRC_Prune; |
| 112283 | |
| 112284 | case TK_BETWEEN: |
| 112285 | if( sqlite3WalkExpr(pWalker, pExpr->pLeft)==WRC_Abort ){ |
| 112286 | assert( pWalker->eCode ); |
| 112287 | return WRC_Abort; |
| 112288 | } |
| 112289 | return WRC_Prune; |
| 112290 | |
| 112291 | /* Virtual tables are allowed to use constraints like x=NULL. So |
| 112292 | ** a term of the form x=y does not prove that y is not null if x |
| 112293 | ** is the column of a virtual table */ |
| @@ -112345,26 +112609,27 @@ | |
| 112345 | ** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE |
| 112346 | ** clause requires that some column of the right table of the LEFT JOIN |
| 112347 | ** be non-NULL, then the LEFT JOIN can be safely converted into an |
| 112348 | ** ordinary join. |
| 112349 | */ |
| 112350 | SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){ |
| 112351 | Walker w; |
| 112352 | p = sqlite3ExprSkipCollateAndLikely(p); |
| 112353 | if( p==0 ) return 0; |
| 112354 | if( p->op==TK_NOTNULL ){ |
| 112355 | p = p->pLeft; |
| 112356 | }else{ |
| 112357 | while( p->op==TK_AND ){ |
| 112358 | if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1; |
| 112359 | p = p->pRight; |
| 112360 | } |
| 112361 | } |
| 112362 | w.xExprCallback = impliesNotNullRow; |
| 112363 | w.xSelectCallback = 0; |
| 112364 | w.xSelectCallback2 = 0; |
| 112365 | w.eCode = 0; |
| 112366 | w.u.iCur = iTab; |
| 112367 | sqlite3WalkExpr(&w, p); |
| 112368 | return w.eCode; |
| 112369 | } |
| 112370 | |
| @@ -112421,11 +112686,11 @@ | |
| 112421 | sqlite3WalkExpr(&w, pExpr); |
| 112422 | return !w.eCode; |
| 112423 | } |
| 112424 | |
| 112425 | |
| 112426 | /* Structure used to pass information throught the Walker in order to |
| 112427 | ** implement sqlite3ReferencesSrcList(). |
| 112428 | */ |
| 112429 | struct RefSrcList { |
| 112430 | sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */ |
| 112431 | SrcList *pRef; /* Looking for references to these tables */ |
| @@ -112637,11 +112902,11 @@ | |
| 112637 | /* |
| 112638 | ** Search the AggInfo object for an aCol[] entry that has iTable and iColumn. |
| 112639 | ** Return the index in aCol[] of the entry that describes that column. |
| 112640 | ** |
| 112641 | ** If no prior entry is found, create a new one and return -1. The |
| 112642 | ** new column will have an idex of pAggInfo->nColumn-1. |
| 112643 | */ |
| 112644 | static void findOrCreateAggInfoColumn( |
| 112645 | Parse *pParse, /* Parsing context */ |
| 112646 | AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */ |
| 112647 | Expr *pExpr /* Expr describing the column to find or insert */ |
| @@ -112650,10 +112915,11 @@ | |
| 112650 | int k; |
| 112651 | |
| 112652 | assert( pAggInfo->iFirstReg==0 ); |
| 112653 | pCol = pAggInfo->aCol; |
| 112654 | for(k=0; k<pAggInfo->nColumn; k++, pCol++){ |
| 112655 | if( pCol->iTable==pExpr->iTable |
| 112656 | && pCol->iColumn==pExpr->iColumn |
| 112657 | && pExpr->op!=TK_IF_NULL_ROW |
| 112658 | ){ |
| 112659 | goto fix_up_expr; |
| @@ -114035,11 +114301,11 @@ | |
| 114035 | |
| 114036 | return pBest; |
| 114037 | } |
| 114038 | |
| 114039 | /* |
| 114040 | ** An error occured while parsing or otherwise processing a database |
| 114041 | ** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an |
| 114042 | ** ALTER TABLE RENAME COLUMN program. The error message emitted by the |
| 114043 | ** sub-routine is currently stored in pParse->zErrMsg. This function |
| 114044 | ** adds context to the error message and then stores it in pCtx. |
| 114045 | */ |
| @@ -117141,18 +117407,19 @@ | |
| 117141 | pSample = &pIdx->aSample[pIdx->nSample]; |
| 117142 | decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0); |
| 117143 | decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0); |
| 117144 | decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0); |
| 117145 | |
| 117146 | /* Take a copy of the sample. Add two 0x00 bytes the end of the buffer. |
| 117147 | ** This is in case the sample record is corrupted. In that case, the |
| 117148 | ** sqlite3VdbeRecordCompare() may read up to two varints past the |
| 117149 | ** end of the allocated buffer before it realizes it is dealing with |
| 117150 | ** a corrupt record. Adding the two 0x00 bytes prevents this from causing |
| 117151 | ** a buffer overread. */ |
| 117152 | pSample->n = sqlite3_column_bytes(pStmt, 4); |
| 117153 | pSample->p = sqlite3DbMallocZero(db, pSample->n + 2); |
| 117154 | if( pSample->p==0 ){ |
| 117155 | sqlite3_finalize(pStmt); |
| 117156 | return SQLITE_NOMEM_BKPT; |
| 117157 | } |
| 117158 | if( pSample->n ){ |
| @@ -118106,11 +118373,11 @@ | |
| 118106 | const char *zArg3 |
| 118107 | ){ |
| 118108 | sqlite3 *db = pParse->db; |
| 118109 | int rc; |
| 118110 | |
| 118111 | /* Don't do any authorization checks if the database is initialising |
| 118112 | ** or if the parser is being invoked from within sqlite3_declare_vtab. |
| 118113 | */ |
| 118114 | assert( !IN_RENAME_OBJECT || db->xAuth==0 ); |
| 118115 | if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){ |
| 118116 | return SQLITE_OK; |
| @@ -118928,11 +119195,11 @@ | |
| 118928 | pCol->colFlags |= COLFLAG_HASCOLL; |
| 118929 | } |
| 118930 | } |
| 118931 | |
| 118932 | /* |
| 118933 | ** Return the collating squence name for a column |
| 118934 | */ |
| 118935 | SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){ |
| 118936 | const char *z; |
| 118937 | if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0; |
| 118938 | z = pCol->zCnName; |
| @@ -119686,11 +119953,11 @@ | |
| 119686 | sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName); |
| 119687 | return; |
| 119688 | } |
| 119689 | if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName); |
| 119690 | |
| 119691 | /* Because keywords GENERATE ALWAYS can be converted into indentifiers |
| 119692 | ** by the parser, we can sometimes end up with a typename that ends |
| 119693 | ** with "generated always". Check for this case and omit the surplus |
| 119694 | ** text. */ |
| 119695 | if( sType.n>=16 |
| 119696 | && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0 |
| @@ -119907,11 +120174,11 @@ | |
| 119907 | */ |
| 119908 | SQLITE_PRIVATE void sqlite3AddDefaultValue( |
| 119909 | Parse *pParse, /* Parsing context */ |
| 119910 | Expr *pExpr, /* The parsed expression of the default value */ |
| 119911 | const char *zStart, /* Start of the default value text */ |
| 119912 | const char *zEnd /* First character past end of defaut value text */ |
| 119913 | ){ |
| 119914 | Table *p; |
| 119915 | Column *pCol; |
| 119916 | sqlite3 *db = pParse->db; |
| 119917 | p = pParse->pNewTable; |
| @@ -120255,11 +120522,11 @@ | |
| 120255 | ** which to write into the output buffer. This function copies the |
| 120256 | ** nul-terminated string pointed to by the third parameter, zSignedIdent, |
| 120257 | ** to the specified offset in the buffer and updates *pIdx to refer |
| 120258 | ** to the first byte after the last byte written before returning. |
| 120259 | ** |
| 120260 | ** If the string zSignedIdent consists entirely of alpha-numeric |
| 120261 | ** characters, does not begin with a digit and is not an SQL keyword, |
| 120262 | ** then it is copied to the output buffer exactly as it is. Otherwise, |
| 120263 | ** it is quoted using double-quotes. |
| 120264 | */ |
| 120265 | static void identPut(char *z, int *pIdx, char *zSignedIdent){ |
| @@ -120407,11 +120674,11 @@ | |
| 120407 | int i; |
| 120408 | const Column *aCol = pIdx->pTable->aCol; |
| 120409 | for(i=0; i<pIdx->nColumn; i++){ |
| 120410 | i16 x = pIdx->aiColumn[i]; |
| 120411 | assert( x<pIdx->pTable->nCol ); |
| 120412 | wIndex += x<0 ? 1 : aCol[pIdx->aiColumn[i]].szEst; |
| 120413 | } |
| 120414 | pIdx->szIdxRow = sqlite3LogEst(wIndex*4); |
| 120415 | } |
| 120416 | |
| 120417 | /* Return true if column number x is any of the first nCol entries of aiCol[]. |
| @@ -122145,11 +122412,11 @@ | |
| 122145 | assert( pName && pName->z ); |
| 122146 | |
| 122147 | #ifndef SQLITE_OMIT_TEMPDB |
| 122148 | /* If the index name was unqualified, check if the table |
| 122149 | ** is a temp table. If so, set the database to 1. Do not do this |
| 122150 | ** if initialising a database schema. |
| 122151 | */ |
| 122152 | if( !db->init.busy ){ |
| 122153 | pTab = sqlite3SrcListLookup(pParse, pTblName); |
| 122154 | if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){ |
| 122155 | iDb = 1; |
| @@ -123802,11 +124069,11 @@ | |
| 123802 | sqlite3DbFree(db, pCte); |
| 123803 | } |
| 123804 | |
| 123805 | /* |
| 123806 | ** This routine is invoked once per CTE by the parser while parsing a |
| 123807 | ** WITH clause. The CTE described by teh third argument is added to |
| 123808 | ** the WITH clause of the second argument. If the second argument is |
| 123809 | ** NULL, then a new WITH argument is created. |
| 123810 | */ |
| 123811 | SQLITE_PRIVATE With *sqlite3WithAdd( |
| 123812 | Parse *pParse, /* Parsing context */ |
| @@ -124446,10 +124713,11 @@ | |
| 124446 | Table *pTab; |
| 124447 | assert( pItem && pSrc->nSrc>=1 ); |
| 124448 | pTab = sqlite3LocateTableItem(pParse, 0, pItem); |
| 124449 | sqlite3DeleteTable(pParse->db, pItem->pTab); |
| 124450 | pItem->pTab = pTab; |
| 124451 | if( pTab ){ |
| 124452 | pTab->nTabRef++; |
| 124453 | if( pItem->fg.isIndexedBy && sqlite3IndexedByLookup(pParse, pItem) ){ |
| 124454 | pTab = 0; |
| 124455 | } |
| @@ -124598,11 +124866,11 @@ | |
| 124598 | char *zStmtType /* Either DELETE or UPDATE. For err msgs. */ |
| 124599 | ){ |
| 124600 | sqlite3 *db = pParse->db; |
| 124601 | Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */ |
| 124602 | Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */ |
| 124603 | ExprList *pEList = NULL; /* Expression list contaning only pSelectRowid */ |
| 124604 | SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */ |
| 124605 | Select *pSelect = NULL; /* Complete SELECT tree */ |
| 124606 | Table *pTab; |
| 124607 | |
| 124608 | /* Check that there isn't an ORDER BY without a LIMIT clause. |
| @@ -124636,18 +124904,24 @@ | |
| 124636 | pEList = sqlite3ExprListAppend( |
| 124637 | pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0) |
| 124638 | ); |
| 124639 | }else{ |
| 124640 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 124641 | if( pPk->nKeyCol==1 ){ |
| 124642 | const char *zName = pTab->aCol[pPk->aiColumn[0]].zCnName; |
| 124643 | pLhs = sqlite3Expr(db, TK_ID, zName); |
| 124644 | pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName)); |
| 124645 | }else{ |
| 124646 | int i; |
| 124647 | for(i=0; i<pPk->nKeyCol; i++){ |
| 124648 | Expr *p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName); |
| 124649 | pEList = sqlite3ExprListAppend(pParse, pEList, p); |
| 124650 | } |
| 124651 | pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 124652 | if( pLhs ){ |
| 124653 | pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0); |
| @@ -124672,11 +124946,11 @@ | |
| 124672 | /* generate the SELECT expression tree. */ |
| 124673 | pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0, |
| 124674 | pOrderBy,0,pLimit |
| 124675 | ); |
| 124676 | |
| 124677 | /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */ |
| 124678 | pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0); |
| 124679 | sqlite3PExprAddSelect(pParse, pInClause, pSelect); |
| 124680 | return pInClause; |
| 124681 | } |
| 124682 | #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */ |
| @@ -126057,11 +126331,11 @@ | |
| 126057 | u8 noCase; /* true to ignore case differences */ |
| 126058 | }; |
| 126059 | |
| 126060 | /* |
| 126061 | ** For LIKE and GLOB matching on EBCDIC machines, assume that every |
| 126062 | ** character is exactly one byte in size. Also, provde the Utf8Read() |
| 126063 | ** macro for fast reading of the next character in the common case where |
| 126064 | ** the next character is ASCII. |
| 126065 | */ |
| 126066 | #if defined(SQLITE_EBCDIC) |
| 126067 | # define sqlite3Utf8Read(A) (*((*A)++)) |
| @@ -126290,11 +126564,11 @@ | |
| 126290 | #endif |
| 126291 | |
| 126292 | |
| 126293 | /* |
| 126294 | ** Implementation of the like() SQL function. This function implements |
| 126295 | ** the build-in LIKE operator. The first argument to the function is the |
| 126296 | ** pattern and the second argument is the string. So, the SQL statements: |
| 126297 | ** |
| 126298 | ** A LIKE B |
| 126299 | ** |
| 126300 | ** is implemented as like(B,A). |
| @@ -126676,11 +126950,11 @@ | |
| 126676 | ** two arguments. In both cases the first argument is interpreted as text |
| 126677 | ** a text value containing a set of pairs of hexadecimal digits which are |
| 126678 | ** decoded and returned as a blob. |
| 126679 | ** |
| 126680 | ** If there is only a single argument, then it must consist only of an |
| 126681 | ** even number of hexadeximal digits. Otherwise, return NULL. |
| 126682 | ** |
| 126683 | ** Or, if there is a second argument, then any character that appears in |
| 126684 | ** the second argument is also allowed to appear between pairs of hexadecimal |
| 126685 | ** digits in the first argument. If any other character appears in the |
| 126686 | ** first argument, or if one of the allowed characters appears between |
| @@ -127376,11 +127650,11 @@ | |
| 127376 | assert( argc==1 || argc==2 ); |
| 127377 | (void)argc; /* Suppress unused parameter warning */ |
| 127378 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 127379 | pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC)); |
| 127380 | /* pGCC is always non-NULL since groupConcatStep() will have always |
| 127381 | ** run frist to initialize it */ |
| 127382 | if( ALWAYS(pGCC) ){ |
| 127383 | int nVS; |
| 127384 | /* Must call sqlite3_value_text() to convert the argument into text prior |
| 127385 | ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */ |
| 127386 | (void)sqlite3_value_text(argv[0]); |
| @@ -129579,11 +129853,11 @@ | |
| 129579 | ** 'E' REAL |
| 129580 | ** |
| 129581 | ** For STRICT tables: |
| 129582 | ** ------------------ |
| 129583 | ** |
| 129584 | ** Generate an appropropriate OP_TypeCheck opcode that will verify the |
| 129585 | ** datatypes against the column definitions in pTab. If iReg==0, that |
| 129586 | ** means an OP_MakeRecord opcode has already been generated and should be |
| 129587 | ** the last opcode generated. The new OP_TypeCheck needs to be inserted |
| 129588 | ** before the OP_MakeRecord. The new OP_TypeCheck should use the same |
| 129589 | ** register set as the OP_MakeRecord. If iReg>0 then register iReg is |
| @@ -130871,11 +131145,11 @@ | |
| 130871 | #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */ |
| 130872 | |
| 130873 | /* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn(). |
| 130874 | * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this |
| 130875 | ** expression node references any of the |
| 130876 | ** columns that are being modifed by an UPDATE statement. |
| 130877 | */ |
| 130878 | static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr){ |
| 130879 | if( pExpr->op==TK_COLUMN ){ |
| 130880 | assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 ); |
| 130881 | if( pExpr->iColumn>=0 ){ |
| @@ -131094,11 +131368,11 @@ | |
| 131094 | int ignoreDest, /* Jump to this label on an OE_Ignore resolution */ |
| 131095 | int *pbMayReplace, /* OUT: Set to true if constraint may cause a replace */ |
| 131096 | int *aiChng, /* column i is unchanged if aiChng[i]<0 */ |
| 131097 | Upsert *pUpsert /* ON CONFLICT clauses, if any. NULL otherwise */ |
| 131098 | ){ |
| 131099 | Vdbe *v; /* VDBE under constrution */ |
| 131100 | Index *pIdx; /* Pointer to one of the indices */ |
| 131101 | Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */ |
| 131102 | sqlite3 *db; /* Database connection */ |
| 131103 | int i; /* loop counter */ |
| 131104 | int ix; /* Index loop counter */ |
| @@ -131577,11 +131851,11 @@ | |
| 131577 | */ |
| 131578 | for(pIdx = indexIteratorFirst(&sIdxIter, &ix); |
| 131579 | pIdx; |
| 131580 | pIdx = indexIteratorNext(&sIdxIter, &ix) |
| 131581 | ){ |
| 131582 | int regIdx; /* Range of registers hold conent for pIdx */ |
| 131583 | int regR; /* Range of registers holding conflicting PK */ |
| 131584 | int iThisCur; /* Cursor for this UNIQUE index */ |
| 131585 | int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */ |
| 131586 | int addrConflictCk; /* First opcode in the conflict check logic */ |
| 131587 | |
| @@ -132393,11 +132667,11 @@ | |
| 132393 | if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){ |
| 132394 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 132395 | } |
| 132396 | #endif |
| 132397 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 132398 | /* Disallow the transfer optimization if the destination table constains |
| 132399 | ** any foreign key constraints. This is more restrictive than necessary. |
| 132400 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 132401 | ** command, and the VACUUM command disables foreign key constraints. So |
| 132402 | ** the extra complication to make this rule less restrictive is probably |
| 132403 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| @@ -134026,10 +134300,14 @@ | |
| 134026 | ** |
| 134027 | ** Later (2023-03-25): Save an extra 6 bytes for the filename suffix. |
| 134028 | ** See https://sqlite.org/forum/forumpost/24083b579d. |
| 134029 | */ |
| 134030 | if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found; |
| 134031 | |
| 134032 | handle = sqlite3OsDlOpen(pVfs, zFile); |
| 134033 | #if SQLITE_OS_UNIX || SQLITE_OS_WIN |
| 134034 | for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){ |
| 134035 | char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]); |
| @@ -135859,11 +136137,11 @@ | |
| 135859 | ** PRAGMA cache_spill=BOOLEAN |
| 135860 | ** PRAGMA [schema.]cache_spill=N |
| 135861 | ** |
| 135862 | ** The first form reports the current local setting for the |
| 135863 | ** page cache spill size. The second form turns cache spill on |
| 135864 | ** or off. When turnning cache spill on, the size is set to the |
| 135865 | ** current cache_size. The third form sets a spill size that |
| 135866 | ** may be different form the cache size. |
| 135867 | ** If N is positive then that is the |
| 135868 | ** number of pages in the cache. If N is negative, then the |
| 135869 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| @@ -136637,13 +136915,13 @@ | |
| 136637 | ** Verify the integrity of the database. |
| 136638 | ** |
| 136639 | ** The "quick_check" is reduced version of |
| 136640 | ** integrity_check designed to detect most database corruption |
| 136641 | ** without the overhead of cross-checking indexes. Quick_check |
| 136642 | ** is linear time wherease integrity_check is O(NlogN). |
| 136643 | ** |
| 136644 | ** The maximum nubmer of errors is 100 by default. A different default |
| 136645 | ** can be specified using a numeric parameter N. |
| 136646 | ** |
| 136647 | ** Or, the parameter N can be the name of a table. In that case, only |
| 136648 | ** the one table named is verified. The freelist is only verified if |
| 136649 | ** the named table is "sqlite_schema" (or one of its aliases). |
| @@ -137397,11 +137675,11 @@ | |
| 137397 | int iTabCur; /* Cursor for a table whose size needs checking */ |
| 137398 | HashElem *k; /* Loop over tables of a schema */ |
| 137399 | Schema *pSchema; /* The current schema */ |
| 137400 | Table *pTab; /* A table in the schema */ |
| 137401 | Index *pIdx; /* An index of the table */ |
| 137402 | LogEst szThreshold; /* Size threshold above which reanalysis is needd */ |
| 137403 | char *zSubSql; /* SQL statement for the OP_SqlExec opcode */ |
| 137404 | u32 opMask; /* Mask of operations to perform */ |
| 137405 | |
| 137406 | if( zRight ){ |
| 137407 | opMask = (u32)sqlite3Atoi(zRight); |
| @@ -138523,11 +138801,11 @@ | |
| 138523 | ** Add a new cleanup operation to a Parser. The cleanup should happen when |
| 138524 | ** the parser object is destroyed. But, beware: the cleanup might happen |
| 138525 | ** immediately. |
| 138526 | ** |
| 138527 | ** Use this mechanism for uncommon cleanups. There is a higher setup |
| 138528 | ** cost for this mechansim (an extra malloc), so it should not be used |
| 138529 | ** for common cleanups that happen on most calls. But for less |
| 138530 | ** common cleanups, we save a single NULL-pointer comparison in |
| 138531 | ** sqlite3ParseObjectReset(), which reduces the total CPU cycle count. |
| 138532 | ** |
| 138533 | ** If a memory allocation error occurs, then the cleanup happens immediately. |
| @@ -139225,11 +139503,11 @@ | |
| 139225 | ** NATURAL RIGHT OUTER JT_NATURAL|JT_RIGHT|JT_OUTER |
| 139226 | ** NATURAL FULL - JT_NATURAL|JT_LEFT|JT_RIGHT |
| 139227 | ** NATURAL FULL OUTER JT_NATRUAL|JT_LEFT|JT_RIGHT |
| 139228 | ** |
| 139229 | ** To preserve historical compatibly, SQLite also accepts a variety |
| 139230 | ** of other non-standard and in many cases non-sensical join types. |
| 139231 | ** This routine makes as much sense at it can from the nonsense join |
| 139232 | ** type and returns a result. Examples of accepted nonsense join types |
| 139233 | ** include but are not limited to: |
| 139234 | ** |
| 139235 | ** INNER CROSS JOIN -> same as JOIN |
| @@ -139496,11 +139774,11 @@ | |
| 139496 | u32 joinType; |
| 139497 | |
| 139498 | if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue; |
| 139499 | joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON; |
| 139500 | |
| 139501 | /* If this is a NATURAL join, synthesize an approprate USING clause |
| 139502 | ** to specify which columns should be joined. |
| 139503 | */ |
| 139504 | if( pRight->fg.jointype & JT_NATURAL ){ |
| 139505 | IdList *pUsing = 0; |
| 139506 | if( pRight->fg.isUsing || pRight->u3.pOn ){ |
| @@ -139712,11 +139990,11 @@ | |
| 139712 | ** (2) All output columns are included in the sort record. In that |
| 139713 | ** case regData==regOrigData. |
| 139714 | ** (3) Some output columns are omitted from the sort record due to |
| 139715 | ** the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the |
| 139716 | ** SQLITE_ECEL_OMITREF optimization, or due to the |
| 139717 | ** SortCtx.pDeferredRowLoad optimiation. In any of these cases |
| 139718 | ** regOrigData is 0 to prevent this routine from trying to copy |
| 139719 | ** values that might not yet exist. |
| 139720 | */ |
| 139721 | assert( nData==1 || regData==regOrigData || regOrigData==0 ); |
| 139722 | |
| @@ -139768,11 +140046,11 @@ | |
| 139768 | memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */ |
| 139769 | sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO); |
| 139770 | testcase( pKI->nAllField > pKI->nKeyField+2 ); |
| 139771 | pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat, |
| 139772 | pKI->nAllField-pKI->nKeyField-1); |
| 139773 | pOp = 0; /* Ensure pOp not used after sqltie3VdbeAddOp3() */ |
| 139774 | addrJmp = sqlite3VdbeCurrentAddr(v); |
| 139775 | sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v); |
| 139776 | pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse); |
| 139777 | pSort->regReturn = ++pParse->nMem; |
| 139778 | sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut); |
| @@ -139862,11 +140140,11 @@ | |
| 139862 | ** the ephemeral cursor and proceed. |
| 139863 | ** |
| 139864 | ** The returned value in this case is a copy of parameter iTab. |
| 139865 | ** |
| 139866 | ** WHERE_DISTINCT_ORDERED: |
| 139867 | ** In this case rows are being delivered sorted order. The ephermal |
| 139868 | ** table is not required. Instead, the current set of values |
| 139869 | ** is compared against previous row. If they match, the new row |
| 139870 | ** is not distinct and control jumps to VM address addrRepeat. Otherwise, |
| 139871 | ** the VM program proceeds with processing the new row. |
| 139872 | ** |
| @@ -141287,11 +141565,11 @@ | |
| 141287 | /* |
| 141288 | ** pTab is a transient Table object that represents a subquery of some |
| 141289 | ** kind (maybe a parenthesized subquery in the FROM clause of a larger |
| 141290 | ** query, or a VIEW, or a CTE). This routine computes type information |
| 141291 | ** for that Table object based on the Select object that implements the |
| 141292 | ** subquery. For the purposes of this routine, "type infomation" means: |
| 141293 | ** |
| 141294 | ** * The datatype name, as it might appear in a CREATE TABLE statement |
| 141295 | ** * Which collating sequence to use for the column |
| 141296 | ** * The affinity of the column |
| 141297 | */ |
| @@ -141616,11 +141894,11 @@ | |
| 141616 | int iCurrent = 0; /* The Current table */ |
| 141617 | int regCurrent; /* Register holding Current table */ |
| 141618 | int iQueue; /* The Queue table */ |
| 141619 | int iDistinct = 0; /* To ensure unique results if UNION */ |
| 141620 | int eDest = SRT_Fifo; /* How to write to Queue */ |
| 141621 | SelectDest destQueue; /* SelectDest targetting the Queue table */ |
| 141622 | int i; /* Loop counter */ |
| 141623 | int rc; /* Result code */ |
| 141624 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| 141625 | Expr *pLimit; /* Saved LIMIT and OFFSET */ |
| 141626 | int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */ |
| @@ -142216,11 +142494,11 @@ | |
| 142216 | } |
| 142217 | } |
| 142218 | |
| 142219 | /* |
| 142220 | ** Code an output subroutine for a coroutine implementation of a |
| 142221 | ** SELECT statment. |
| 142222 | ** |
| 142223 | ** The data to be output is contained in pIn->iSdst. There are |
| 142224 | ** pIn->nSdst columns to be output. pDest is where the output should |
| 142225 | ** be sent. |
| 142226 | ** |
| @@ -142438,11 +142716,11 @@ | |
| 142438 | ** Jump AltB, AeqB, AgtB |
| 142439 | ** End: ... |
| 142440 | ** |
| 142441 | ** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not |
| 142442 | ** actually called using Gosub and they do not Return. EofA and EofB loop |
| 142443 | ** until all data is exhausted then jump to the "end" labe. AltB, AeqB, |
| 142444 | ** and AgtB jump to either L2 or to one of EofA or EofB. |
| 142445 | */ |
| 142446 | #ifndef SQLITE_OMIT_COMPOUND_SELECT |
| 142447 | static int multiSelectOrderBy( |
| 142448 | Parse *pParse, /* Parsing context */ |
| @@ -142475,11 +142753,11 @@ | |
| 142475 | int regPrev; /* A range of registers to hold previous output */ |
| 142476 | int savedLimit; /* Saved value of p->iLimit */ |
| 142477 | int savedOffset; /* Saved value of p->iOffset */ |
| 142478 | int labelCmpr; /* Label for the start of the merge algorithm */ |
| 142479 | int labelEnd; /* Label for the end of the overall SELECT stmt */ |
| 142480 | int addr1; /* Jump instructions that get retargetted */ |
| 142481 | int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */ |
| 142482 | KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */ |
| 142483 | KeyInfo *pKeyMerge; /* Comparison information for merging rows */ |
| 142484 | sqlite3 *db; /* Database connection */ |
| 142485 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| @@ -142844,15 +143122,18 @@ | |
| 142844 | pExpr->op = TK_NULL; |
| 142845 | }else |
| 142846 | #endif |
| 142847 | { |
| 142848 | Expr *pNew; |
| 142849 | int iColumn = pExpr->iColumn; |
| 142850 | Expr *pCopy = pSubst->pEList->a[iColumn].pExpr; |
| 142851 | Expr ifNullRow; |
| 142852 | assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr ); |
| 142853 | assert( pExpr->pRight==0 ); |
| 142854 | if( sqlite3ExprIsVector(pCopy) ){ |
| 142855 | sqlite3VectorErrorMsg(pSubst->pParse, pCopy); |
| 142856 | }else{ |
| 142857 | sqlite3 *db = pSubst->pParse->db; |
| 142858 | if( pSubst->isOuterJoin |
| @@ -143197,11 +143478,11 @@ | |
| 143197 | ** (8) If the subquery uses LIMIT then the outer query may not be a join. |
| 143198 | ** |
| 143199 | ** (9) If the subquery uses LIMIT then the outer query may not be aggregate. |
| 143200 | ** |
| 143201 | ** (**) Restriction (10) was removed from the code on 2005-02-05 but we |
| 143202 | ** accidently carried the comment forward until 2014-09-15. Original |
| 143203 | ** constraint: "If the subquery is aggregate then the outer query |
| 143204 | ** may not use LIMIT." |
| 143205 | ** |
| 143206 | ** (11) The subquery and the outer query may not both have ORDER BY clauses. |
| 143207 | ** |
| @@ -143471,11 +143752,11 @@ | |
| 143471 | pParse->zAuthContext = pSubitem->zName; |
| 143472 | TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0); |
| 143473 | testcase( i==SQLITE_DENY ); |
| 143474 | pParse->zAuthContext = zSavedAuthContext; |
| 143475 | |
| 143476 | /* Delete the transient structures associated with thesubquery */ |
| 143477 | pSub1 = pSubitem->pSelect; |
| 143478 | sqlite3DbFree(db, pSubitem->zDatabase); |
| 143479 | sqlite3DbFree(db, pSubitem->zName); |
| 143480 | sqlite3DbFree(db, pSubitem->zAlias); |
| 143481 | pSubitem->zDatabase = 0; |
| @@ -143653,11 +143934,11 @@ | |
| 143653 | if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){ |
| 143654 | /* At this point, any non-zero iOrderByCol values indicate that the |
| 143655 | ** ORDER BY column expression is identical to the iOrderByCol'th |
| 143656 | ** expression returned by SELECT statement pSub. Since these values |
| 143657 | ** do not necessarily correspond to columns in SELECT statement pParent, |
| 143658 | ** zero them before transfering the ORDER BY clause. |
| 143659 | ** |
| 143660 | ** Not doing this may cause an error if a subsequent call to this |
| 143661 | ** function attempts to flatten a compound sub-query into pParent |
| 143662 | ** (the only way this can happen is if the compound sub-query is |
| 143663 | ** currently part of pSub->pSrc). See ticket [d11a6e908f]. */ |
| @@ -143713,12 +143994,11 @@ | |
| 143713 | for(i=0; i<nSubSrc; i++){ |
| 143714 | recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]); |
| 143715 | } |
| 143716 | } |
| 143717 | |
| 143718 | /* Finially, delete what is left of the subquery and return |
| 143719 | ** success. |
| 143720 | */ |
| 143721 | sqlite3AggInfoPersistWalkerInit(&w, pParse); |
| 143722 | sqlite3WalkSelect(&w,pSub1); |
| 143723 | sqlite3SelectDelete(db, pSub1); |
| 143724 | |
| @@ -143749,11 +144029,11 @@ | |
| 143749 | Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */ |
| 143750 | }; |
| 143751 | |
| 143752 | /* |
| 143753 | ** Add a new entry to the pConst object. Except, do not add duplicate |
| 143754 | ** pColumn entires. Also, do not add if doing so would not be appropriate. |
| 143755 | ** |
| 143756 | ** The caller guarantees the pColumn is a column and pValue is a constant. |
| 143757 | ** This routine has to do some additional checks before completing the |
| 143758 | ** insert. |
| 143759 | */ |
| @@ -143935,11 +144215,11 @@ | |
| 143935 | ** INSERT INTO t1 VALUES(123,'0123'); |
| 143936 | ** SELECT * FROM t1 WHERE a=123 AND b=a; |
| 143937 | ** SELECT * FROM t1 WHERE a=123 AND b=123; |
| 143938 | ** |
| 143939 | ** The two SELECT statements above should return different answers. b=a |
| 143940 | ** is alway true because the comparison uses numeric affinity, but b=123 |
| 143941 | ** is false because it uses text affinity and '0123' is not the same as '123'. |
| 143942 | ** To work around this, the expression tree is not actually changed from |
| 143943 | ** "b=a" to "b=123" but rather the "a" in "b=a" is tagged with EP_FixedCol |
| 143944 | ** and the "123" value is hung off of the pLeft pointer. Code generator |
| 143945 | ** routines know to generate the constant "123" instead of looking up the |
| @@ -144019,11 +144299,11 @@ | |
| 144019 | ** this may change the results of the window functions. |
| 144020 | ** |
| 144021 | ** At the time this function is called it is guaranteed that |
| 144022 | ** |
| 144023 | ** * the sub-query uses only one distinct window frame, and |
| 144024 | ** * that the window frame has a PARTITION BY clase. |
| 144025 | */ |
| 144026 | static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){ |
| 144027 | assert( pSubq->pWin->pPartition ); |
| 144028 | assert( (pSubq->selFlags & SF_MultiPart)==0 ); |
| 144029 | assert( pSubq->pPrior==0 ); |
| @@ -145527,11 +145807,11 @@ | |
| 145527 | assert( pExpr->iAgg>=0 ); |
| 145528 | pCol = &pAggInfo->aCol[pExpr->iAgg]; |
| 145529 | pExpr->op = TK_AGG_COLUMN; |
| 145530 | pExpr->iTable = pCol->iTable; |
| 145531 | pExpr->iColumn = pCol->iColumn; |
| 145532 | ExprClearProperty(pExpr, EP_Skip|EP_Collate); |
| 145533 | return WRC_Prune; |
| 145534 | } |
| 145535 | |
| 145536 | /* |
| 145537 | ** Convert every pAggInfo->aFunc[].pExpr such that any node within |
| @@ -145558,11 +145838,11 @@ | |
| 145558 | ** to calling this routine: |
| 145559 | ** |
| 145560 | ** * The aCol[] and aFunc[] arrays may be modified |
| 145561 | ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used |
| 145562 | ** |
| 145563 | ** After clling this routine: |
| 145564 | ** |
| 145565 | ** * The aCol[] and aFunc[] arrays are fixed |
| 145566 | ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may be used |
| 145567 | ** |
| 145568 | */ |
| @@ -146212,26 +146492,63 @@ | |
| 146212 | /* The expander should have already created transient Table objects |
| 146213 | ** even for FROM clause elements such as subqueries that do not correspond |
| 146214 | ** to a real table */ |
| 146215 | assert( pTab!=0 ); |
| 146216 | |
| 146217 | /* Convert LEFT JOIN into JOIN if there are terms of the right table |
| 146218 | ** of the LEFT JOIN used in the WHERE clause. |
| 146219 | */ |
| 146220 | if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))==JT_LEFT |
| 146221 | && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor) |
| 146222 | && OptimizationEnabled(db, SQLITE_SimplifyJoin) |
| 146223 | ){ |
| 146224 | TREETRACE(0x1000,pParse,p, |
| 146225 | ("LEFT-JOIN simplifies to JOIN on term %d\n",i)); |
| 146226 | pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER); |
| 146227 | assert( pItem->iCursor>=0 ); |
| 146228 | unsetJoinExpr(p->pWhere, pItem->iCursor, |
| 146229 | pTabList->a[0].fg.jointype & JT_LTORJ); |
| 146230 | } |
| 146231 | |
| 146232 | /* No futher action if this term of the FROM clause is not a subquery */ |
| 146233 | if( pSub==0 ) continue; |
| 146234 | |
| 146235 | /* Catch mismatch in the declared columns of a view and the number of |
| 146236 | ** columns in the SELECT on the RHS */ |
| 146237 | if( pTab->nCol!=pSub->pEList->nExpr ){ |
| @@ -146481,11 +146798,11 @@ | |
| 146481 | sqlite3VdbeJumpHere(v, addrTop-1); |
| 146482 | sqlite3ClearTempRegCache(pParse); |
| 146483 | }else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){ |
| 146484 | /* This is a CTE for which materialization code has already been |
| 146485 | ** generated. Invoke the subroutine to compute the materialization, |
| 146486 | ** the make the pItem->iCursor be a copy of the ephemerial table that |
| 146487 | ** holds the result of the materialization. */ |
| 146488 | CteUse *pCteUse = pItem->u2.pCteUse; |
| 146489 | sqlite3VdbeAddOp2(v, OP_Gosub, pCteUse->regRtn, pCteUse->addrM9e); |
| 146490 | if( pItem->iCursor!=pCteUse->iCur ){ |
| 146491 | sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur); |
| @@ -146864,11 +147181,11 @@ | |
| 146864 | /* Processing for aggregates with GROUP BY is very different and |
| 146865 | ** much more complex than aggregates without a GROUP BY. |
| 146866 | */ |
| 146867 | if( pGroupBy ){ |
| 146868 | KeyInfo *pKeyInfo; /* Keying information for the group by clause */ |
| 146869 | int addr1; /* A-vs-B comparision jump */ |
| 146870 | int addrOutputRow; /* Start of subroutine that outputs a result row */ |
| 146871 | int regOutputRow; /* Return address register for output subroutine */ |
| 146872 | int addrSetAbort; /* Set the abort flag and return */ |
| 146873 | int addrTopOfLoop; /* Top of the input loop */ |
| 146874 | int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */ |
| @@ -149244,11 +149561,11 @@ | |
| 149244 | pSrc = sqlite3SrcListDup(db, pTabList, 0); |
| 149245 | pWhere2 = sqlite3ExprDup(db, pWhere, 0); |
| 149246 | |
| 149247 | assert( pTabList->nSrc>1 ); |
| 149248 | if( pSrc ){ |
| 149249 | pSrc->a[0].fg.notCte = 1; |
| 149250 | pSrc->a[0].iCursor = -1; |
| 149251 | pSrc->a[0].pTab->nTabRef--; |
| 149252 | pSrc->a[0].pTab = 0; |
| 149253 | } |
| 149254 | if( pPk ){ |
| @@ -150231,11 +150548,11 @@ | |
| 150231 | const char *pVTab = (const char*)sqlite3GetVTable(db, pTab); |
| 150232 | WhereInfo *pWInfo = 0; |
| 150233 | int nArg = 2 + pTab->nCol; /* Number of arguments to VUpdate */ |
| 150234 | int regArg; /* First register in VUpdate arg array */ |
| 150235 | int regRec; /* Register in which to assemble record */ |
| 150236 | int regRowid; /* Register for ephem table rowid */ |
| 150237 | int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */ |
| 150238 | int aDummy[2]; /* Unused arg for sqlite3WhereOkOnePass() */ |
| 150239 | int eOnePass; /* True to use onepass strategy */ |
| 150240 | int addr; /* Address of OP_OpenEphemeral */ |
| 150241 | |
| @@ -150352,11 +150669,11 @@ | |
| 150352 | /* End the virtual table scan */ |
| 150353 | if( pSrc->nSrc==1 ){ |
| 150354 | sqlite3WhereEnd(pWInfo); |
| 150355 | } |
| 150356 | |
| 150357 | /* Begin scannning through the ephemeral table. */ |
| 150358 | addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v); |
| 150359 | |
| 150360 | /* Extract arguments from the current row of the ephemeral table and |
| 150361 | ** invoke the VUpdate method. */ |
| 150362 | for(i=0; i<nArg; i++){ |
| @@ -150909,11 +151226,11 @@ | |
| 150909 | ** can be set to 'off' for this file, as it is not recovered if a crash |
| 150910 | ** occurs anyway. The integrity of the database is maintained by a |
| 150911 | ** (possibly synchronous) transaction opened on the main database before |
| 150912 | ** sqlite3BtreeCopyFile() is called. |
| 150913 | ** |
| 150914 | ** An optimisation would be to use a non-journaled pager. |
| 150915 | ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but |
| 150916 | ** that actually made the VACUUM run slower. Very little journalling |
| 150917 | ** actually occurs when doing a vacuum since the vacuum_db is initially |
| 150918 | ** empty. Only the journal header is written. Apparently it takes more |
| 150919 | ** time to parse and run the PRAGMA to turn journalling off than it does |
| @@ -151598,11 +151915,11 @@ | |
| 151598 | /* A slot for the record has already been allocated in the |
| 151599 | ** schema table. We just need to update that slot with all |
| 151600 | ** the information we've collected. |
| 151601 | ** |
| 151602 | ** The VM register number pParse->regRowid holds the rowid of an |
| 151603 | ** entry in the sqlite_schema table tht was created for this vtab |
| 151604 | ** by sqlite3StartTable(). |
| 151605 | */ |
| 151606 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 151607 | sqlite3NestedParse(pParse, |
| 151608 | "UPDATE %Q." LEGACY_SCHEMA_TABLE " " |
| @@ -152342,11 +152659,11 @@ | |
| 152342 | ** exists when this routine returns or if an attempt to create it failed |
| 152343 | ** and an error message was left in pParse. |
| 152344 | ** |
| 152345 | ** An eponymous virtual table instance is one that is named after its |
| 152346 | ** module, and more importantly, does not require a CREATE VIRTUAL TABLE |
| 152347 | ** statement in order to come into existance. Eponymous virtual table |
| 152348 | ** instances always exist. They cannot be DROP-ed. |
| 152349 | ** |
| 152350 | ** Any virtual table module for which xConnect and xCreate are the same |
| 152351 | ** method can have an eponymous virtual table instance. |
| 152352 | */ |
| @@ -152533,11 +152850,11 @@ | |
| 152533 | typedef struct WhereMemBlock WhereMemBlock; |
| 152534 | typedef struct WhereRightJoin WhereRightJoin; |
| 152535 | |
| 152536 | /* |
| 152537 | ** This object is a header on a block of allocated memory that will be |
| 152538 | ** automatically freed when its WInfo oject is destructed. |
| 152539 | */ |
| 152540 | struct WhereMemBlock { |
| 152541 | WhereMemBlock *pNext; /* Next block in the chain */ |
| 152542 | u64 sz; /* Bytes of space */ |
| 152543 | }; |
| @@ -152594,11 +152911,11 @@ | |
| 152594 | int nIn; /* Number of entries in aInLoop[] */ |
| 152595 | struct InLoop { |
| 152596 | int iCur; /* The VDBE cursor used by this IN operator */ |
| 152597 | int addrInTop; /* Top of the IN loop */ |
| 152598 | int iBase; /* Base register of multi-key index record */ |
| 152599 | int nPrefix; /* Number of prior entires in the key */ |
| 152600 | u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */ |
| 152601 | } *aInLoop; /* Information about each nested IN operator */ |
| 152602 | } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ |
| 152603 | Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */ |
| 152604 | } u; |
| @@ -152844,11 +153161,11 @@ | |
| 152844 | u8 op; /* Split operator. TK_AND or TK_OR */ |
| 152845 | u8 hasOr; /* True if any a[].eOperator is WO_OR */ |
| 152846 | int nTerm; /* Number of terms */ |
| 152847 | int nSlot; /* Number of entries in a[] */ |
| 152848 | int nBase; /* Number of terms through the last non-Virtual */ |
| 152849 | WhereTerm *a; /* Each a[] describes a term of the WHERE cluase */ |
| 152850 | #if defined(SQLITE_SMALL_STACK) |
| 152851 | WhereTerm aStatic[1]; /* Initial static space for a[] */ |
| 152852 | #else |
| 152853 | WhereTerm aStatic[8]; /* Initial static space for a[] */ |
| 152854 | #endif |
| @@ -153929,11 +154246,11 @@ | |
| 153929 | assert( pIdx!=0 ); |
| 153930 | |
| 153931 | /* Figure out how many memory cells we will need then allocate them. |
| 153932 | */ |
| 153933 | regBase = pParse->nMem + 1; |
| 153934 | nReg = pLoop->u.btree.nEq + nExtraReg; |
| 153935 | pParse->nMem += nReg; |
| 153936 | |
| 153937 | zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx)); |
| 153938 | assert( zAff!=0 || pParse->db->mallocFailed ); |
| 153939 | |
| @@ -153976,13 +154293,10 @@ | |
| 153976 | regBase = r1; |
| 153977 | }else{ |
| 153978 | sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j); |
| 153979 | } |
| 153980 | } |
| 153981 | } |
| 153982 | for(j=nSkip; j<nEq; j++){ |
| 153983 | pTerm = pLoop->aLTerm[j]; |
| 153984 | if( pTerm->eOperator & WO_IN ){ |
| 153985 | if( pTerm->pExpr->flags & EP_xIsSelect ){ |
| 153986 | /* No affinity ever needs to be (or should be) applied to a value |
| 153987 | ** from the RHS of an "? IN (SELECT ...)" expression. The |
| 153988 | ** sqlite3FindInIndex() routine has already ensured that the |
| @@ -154121,11 +154435,11 @@ | |
| 154121 | ** the specified column into the new register, and |
| 154122 | ** |
| 154123 | ** 2) transform the expression node to a TK_REGISTER node that reads |
| 154124 | ** from the newly populated register. |
| 154125 | ** |
| 154126 | ** Also, if the node is a TK_COLUMN that does access the table idenified |
| 154127 | ** by pCCurHint.iTabCur, and an index is being used (which we will |
| 154128 | ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into |
| 154129 | ** an access of the index rather than the original table. |
| 154130 | */ |
| 154131 | static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){ |
| @@ -154739,11 +155053,11 @@ | |
| 154739 | /* TK_LT */ OP_SeekLT, |
| 154740 | /* TK_GE */ OP_SeekGE |
| 154741 | }; |
| 154742 | assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */ |
| 154743 | assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */ |
| 154744 | assert( TK_GE==TK_GT+3 ); /* ... is correcct. */ |
| 154745 | |
| 154746 | assert( (pStart->wtFlags & TERM_VNULL)==0 ); |
| 154747 | testcase( pStart->wtFlags & TERM_VIRTUAL ); |
| 154748 | pX = pStart->pExpr; |
| 154749 | assert( pX!=0 ); |
| @@ -155919,11 +156233,11 @@ | |
| 155919 | ************************************************************************* |
| 155920 | ** This module contains C code that generates VDBE code used to process |
| 155921 | ** the WHERE clause of SQL statements. |
| 155922 | ** |
| 155923 | ** This file was originally part of where.c but was split out to improve |
| 155924 | ** readability and editabiliity. This file contains utility routines for |
| 155925 | ** analyzing Expr objects in the WHERE clause. |
| 155926 | */ |
| 155927 | /* #include "sqliteInt.h" */ |
| 155928 | /* #include "whereInt.h" */ |
| 155929 | |
| @@ -156708,11 +157022,11 @@ | |
| 156708 | } |
| 156709 | if( (chngToIN & sqlite3WhereGetMask(&pWInfo->sMaskSet, |
| 156710 | pOrTerm->leftCursor))==0 ){ |
| 156711 | /* This term must be of the form t1.a==t2.b where t2 is in the |
| 156712 | ** chngToIN set but t1 is not. This term will be either preceded |
| 156713 | ** or follwed by an inverted copy (t2.b==t1.a). Skip this term |
| 156714 | ** and use its inversion. */ |
| 156715 | testcase( pOrTerm->wtFlags & TERM_COPIED ); |
| 156716 | testcase( pOrTerm->wtFlags & TERM_VIRTUAL ); |
| 156717 | assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) ); |
| 156718 | continue; |
| @@ -156970,12 +157284,12 @@ | |
| 156970 | ){ |
| 156971 | WhereInfo *pWInfo = pWC->pWInfo; /* WHERE clause processing context */ |
| 156972 | WhereTerm *pTerm; /* The term to be analyzed */ |
| 156973 | WhereMaskSet *pMaskSet; /* Set of table index masks */ |
| 156974 | Expr *pExpr; /* The expression to be analyzed */ |
| 156975 | Bitmask prereqLeft; /* Prerequesites of the pExpr->pLeft */ |
| 156976 | Bitmask prereqAll; /* Prerequesites of pExpr */ |
| 156977 | Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */ |
| 156978 | Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */ |
| 156979 | int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */ |
| 156980 | int noCase = 0; /* uppercase equivalent to lowercase */ |
| 156981 | int op; /* Top-level operator. pExpr->op */ |
| @@ -159532,11 +159846,11 @@ | |
| 159532 | ** SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?; |
| 159533 | ** |
| 159534 | ** Value pLoop->nOut is currently set to the estimated number of rows |
| 159535 | ** visited for scanning (a=? AND b=?). This function reduces that estimate |
| 159536 | ** by some factor to account for the (c BETWEEN ? AND ?) expression based |
| 159537 | ** on the stat4 data for the index. this scan will be peformed multiple |
| 159538 | ** times (once for each (a,b) combination that matches a=?) is dealt with |
| 159539 | ** by the caller. |
| 159540 | ** |
| 159541 | ** It does this by scanning through all stat4 samples, comparing values |
| 159542 | ** extracted from pLower and pUpper with the corresponding column in each |
| @@ -160287,11 +160601,11 @@ | |
| 160287 | /* whereLoopAddBtree() always generates and inserts the automatic index |
| 160288 | ** case first. Hence compatible candidate WhereLoops never have a larger |
| 160289 | ** rSetup. Call this SETUP-INVARIANT */ |
| 160290 | assert( p->rSetup>=pTemplate->rSetup ); |
| 160291 | |
| 160292 | /* Any loop using an appliation-defined index (or PRIMARY KEY or |
| 160293 | ** UNIQUE constraint) with one or more == constraints is better |
| 160294 | ** than an automatic index. Unless it is a skip-scan. */ |
| 160295 | if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 |
| 160296 | && (pTemplate->nSkip)==0 |
| 160297 | && (pTemplate->wsFlags & WHERE_INDEXED)!=0 |
| @@ -160432,11 +160746,11 @@ | |
| 160432 | whereLoopInit(p); |
| 160433 | p->pNextLoop = 0; |
| 160434 | }else{ |
| 160435 | /* We will be overwriting WhereLoop p[]. But before we do, first |
| 160436 | ** go through the rest of the list and delete any other entries besides |
| 160437 | ** p[] that are also supplated by pTemplate */ |
| 160438 | WhereLoop **ppTail = &p->pNextLoop; |
| 160439 | WhereLoop *pToDel; |
| 160440 | while( *ppTail ){ |
| 160441 | ppTail = whereLoopFindLesser(ppTail, pTemplate); |
| 160442 | if( ppTail==0 ) break; |
| @@ -160632,11 +160946,11 @@ | |
| 160632 | } |
| 160633 | return i; |
| 160634 | } |
| 160635 | |
| 160636 | /* |
| 160637 | ** Adjust the cost C by the costMult facter T. This only occurs if |
| 160638 | ** compiled with -DSQLITE_ENABLE_COSTMULT |
| 160639 | */ |
| 160640 | #ifdef SQLITE_ENABLE_COSTMULT |
| 160641 | # define ApplyCostMultiplier(C,T) C += T |
| 160642 | #else |
| @@ -160659,11 +160973,11 @@ | |
| 160659 | WhereLoopBuilder *pBuilder, /* The WhereLoop factory */ |
| 160660 | SrcItem *pSrc, /* FROM clause term being analyzed */ |
| 160661 | Index *pProbe, /* An index on pSrc */ |
| 160662 | LogEst nInMul /* log(Number of iterations due to IN) */ |
| 160663 | ){ |
| 160664 | WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyse context */ |
| 160665 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 160666 | sqlite3 *db = pParse->db; /* Database connection malloc context */ |
| 160667 | WhereLoop *pNew; /* Template WhereLoop under construction */ |
| 160668 | WhereTerm *pTerm; /* A WhereTerm under consideration */ |
| 160669 | int opMask; /* Valid operators for constraints */ |
| @@ -160969,11 +161283,11 @@ | |
| 160969 | ** seek only. Then, if this is a non-covering index, add the cost of |
| 160970 | ** visiting the rows in the main table. */ |
| 160971 | assert( pSrc->pTab->szTabRow>0 ); |
| 160972 | if( pProbe->idxType==SQLITE_IDXTYPE_IPK ){ |
| 160973 | /* The pProbe->szIdxRow is low for an IPK table since the interior |
| 160974 | ** pages are small. Thuse szIdxRow gives a good estimate of seek cost. |
| 160975 | ** But the leaf pages are full-size, so pProbe->szIdxRow would badly |
| 160976 | ** under-estimate the scanning cost. */ |
| 160977 | rCostIdx = pNew->nOut + 16; |
| 160978 | }else{ |
| 160979 | rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow; |
| @@ -161314,11 +161628,11 @@ | |
| 161314 | ** performance of using an index is far better than the worst-case performance |
| 161315 | ** of a full table scan. |
| 161316 | */ |
| 161317 | static int whereLoopAddBtree( |
| 161318 | WhereLoopBuilder *pBuilder, /* WHERE clause information */ |
| 161319 | Bitmask mPrereq /* Extra prerequesites for using this table */ |
| 161320 | ){ |
| 161321 | WhereInfo *pWInfo; /* WHERE analysis context */ |
| 161322 | Index *pProbe; /* An index we are evaluating */ |
| 161323 | Index sPk; /* A fake index object for the primary key */ |
| 161324 | LogEst aiRowEstPk[2]; /* The aiRowLogEst[] value for the sPk index */ |
| @@ -161821,11 +162135,11 @@ | |
| 161821 | ** This routine depends on there being a HiddenIndexInfo structure immediately |
| 161822 | ** following the sqlite3_index_info structure. |
| 161823 | ** |
| 161824 | ** Return a pointer to the collation name: |
| 161825 | ** |
| 161826 | ** 1. If there is an explicit COLLATE operator on the constaint, return it. |
| 161827 | ** |
| 161828 | ** 2. Else, if the column has an alternative collation, return that. |
| 161829 | ** |
| 161830 | ** 3. Otherwise, return "BINARY". |
| 161831 | */ |
| @@ -162885,11 +163199,11 @@ | |
| 162885 | aSortCost[isOrdered] = whereSortingCost( |
| 162886 | pWInfo, nRowEst, nOrderBy, isOrdered |
| 162887 | ); |
| 162888 | } |
| 162889 | /* TUNING: Add a small extra penalty (3) to sorting as an |
| 162890 | ** extra encouragment to the query planner to select a plan |
| 162891 | ** where the rows emerge in the correct order without any sorting |
| 162892 | ** required. */ |
| 162893 | rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 3; |
| 162894 | |
| 162895 | WHERETRACE(0x002, |
| @@ -163593,11 +163907,11 @@ | |
| 163593 | ** inner loops (or around the "..." if the test occurs within the inner- |
| 163594 | ** most loop) |
| 163595 | ** |
| 163596 | ** OUTER JOINS |
| 163597 | ** |
| 163598 | ** An outer join of tables t1 and t2 is conceptally coded as follows: |
| 163599 | ** |
| 163600 | ** foreach row1 in t1 do |
| 163601 | ** flag = 0 |
| 163602 | ** foreach row2 in t2 do |
| 163603 | ** start: |
| @@ -163748,11 +164062,11 @@ | |
| 163748 | }else{ |
| 163749 | /* Assign a bit from the bitmask to every term in the FROM clause. |
| 163750 | ** |
| 163751 | ** The N-th term of the FROM clause is assigned a bitmask of 1<<N. |
| 163752 | ** |
| 163753 | ** The rule of the previous sentence ensures thta if X is the bitmask for |
| 163754 | ** a table T, then X-1 is the bitmask for all other tables to the left of T. |
| 163755 | ** Knowing the bitmask for all tables to the left of a left join is |
| 163756 | ** important. Ticket #3015. |
| 163757 | ** |
| 163758 | ** Note that bitmasks are created for all pTabList->nSrc tables in |
| @@ -164729,11 +165043,11 @@ | |
| 164729 | ** last_value(expr) |
| 164730 | ** nth_value(expr, N) |
| 164731 | ** |
| 164732 | ** These are the same built-in window functions supported by Postgres. |
| 164733 | ** Although the behaviour of aggregate window functions (functions that |
| 164734 | ** can be used as either aggregates or window funtions) allows them to |
| 164735 | ** be implemented using an API, built-in window functions are much more |
| 164736 | ** esoteric. Additionally, some window functions (e.g. nth_value()) |
| 164737 | ** may only be implemented by caching the entire partition in memory. |
| 164738 | ** As such, some built-in window functions use the same API as aggregate |
| 164739 | ** window functions and some are implemented directly using VDBE |
| @@ -165259,11 +165573,11 @@ | |
| 165259 | ** linked list of WINDOW definitions for the current SELECT statement. |
| 165260 | ** Argument pFunc is the function definition just resolved and pWin |
| 165261 | ** is the Window object representing the associated OVER clause. This |
| 165262 | ** function updates the contents of pWin as follows: |
| 165263 | ** |
| 165264 | ** * If the OVER clause refered to a named window (as in "max(x) OVER win"), |
| 165265 | ** search list pList for a matching WINDOW definition, and update pWin |
| 165266 | ** accordingly. If no such WINDOW clause can be found, leave an error |
| 165267 | ** in pParse. |
| 165268 | ** |
| 165269 | ** * If the function is a built-in window function that requires the |
| @@ -165880,11 +166194,11 @@ | |
| 165880 | } |
| 165881 | return pWin; |
| 165882 | } |
| 165883 | |
| 165884 | /* |
| 165885 | ** Window *pWin has just been created from a WINDOW clause. Tokne pBase |
| 165886 | ** is the base window. Earlier windows from the same WINDOW clause are |
| 165887 | ** stored in the linked list starting at pWin->pNextWin. This function |
| 165888 | ** either updates *pWin according to the base specification, or else |
| 165889 | ** leaves an error in pParse. |
| 165890 | */ |
| @@ -166186,11 +166500,11 @@ | |
| 166186 | ** start,current,end |
| 166187 | ** Consider a window-frame similar to the following: |
| 166188 | ** |
| 166189 | ** (ORDER BY a, b GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING) |
| 166190 | ** |
| 166191 | ** The windows functions implmentation caches the input rows in a temp |
| 166192 | ** table, sorted by "a, b" (it actually populates the cache lazily, and |
| 166193 | ** aggressively removes rows once they are no longer required, but that's |
| 166194 | ** a mere detail). It keeps three cursors open on the temp table. One |
| 166195 | ** (current) that points to the next row to return to the query engine |
| 166196 | ** once its window function values have been calculated. Another (end) |
| @@ -167195,11 +167509,11 @@ | |
| 167195 | ** RETURN_ROW |
| 167196 | ** } |
| 167197 | ** |
| 167198 | ** For the most part, the patterns above are adapted to support UNBOUNDED by |
| 167199 | ** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and |
| 167200 | ** CURRENT ROW by assuming that it is equivilent to "0 PRECEDING/FOLLOWING". |
| 167201 | ** This is optimized of course - branches that will never be taken and |
| 167202 | ** conditions that are always true are omitted from the VM code. The only |
| 167203 | ** exceptional case is: |
| 167204 | ** |
| 167205 | ** ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING |
| @@ -167474,11 +167788,11 @@ | |
| 167474 | s.eDelete = WINDOW_AGGINVERSE; |
| 167475 | break; |
| 167476 | } |
| 167477 | |
| 167478 | /* Allocate registers for the array of values from the sub-query, the |
| 167479 | ** samve values in record form, and the rowid used to insert said record |
| 167480 | ** into the ephemeral table. */ |
| 167481 | regNew = pParse->nMem+1; |
| 167482 | pParse->nMem += nInput; |
| 167483 | regRecord = ++pParse->nMem; |
| 167484 | s.regRowid = ++pParse->nMem; |
| @@ -167715,11 +168029,12 @@ | |
| 167715 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 167716 | |
| 167717 | /************** End of window.c **********************************************/ |
| 167718 | /************** Begin file parse.c *******************************************/ |
| 167719 | /* This file is automatically generated by Lemon from input grammar |
| 167720 | ** source file "parse.y". */ |
| 167721 | /* |
| 167722 | ** 2001-09-15 |
| 167723 | ** |
| 167724 | ** The author disclaims copyright to this source code. In place of |
| 167725 | ** a legal notice, here is a blessing: |
| @@ -167732,11 +168047,11 @@ | |
| 167732 | ** This file contains SQLite's SQL parser. |
| 167733 | ** |
| 167734 | ** The canonical source code to this file ("parse.y") is a Lemon grammar |
| 167735 | ** file that specifies the input grammar and actions to take while parsing. |
| 167736 | ** That input file is processed by Lemon to generate a C-language |
| 167737 | ** implementation of a parser for the given grammer. You might be reading |
| 167738 | ** this comment as part of the translated C-code. Edits should be made |
| 167739 | ** to the original parse.y sources. |
| 167740 | */ |
| 167741 | |
| 167742 | /* #include "sqliteInt.h" */ |
| @@ -174928,16 +175243,10 @@ | |
| 174928 | |
| 174929 | /* |
| 174930 | ** Forward declarations of external module initializer functions |
| 174931 | ** for modules that need them. |
| 174932 | */ |
| 174933 | #ifdef SQLITE_ENABLE_FTS1 |
| 174934 | SQLITE_PRIVATE int sqlite3Fts1Init(sqlite3*); |
| 174935 | #endif |
| 174936 | #ifdef SQLITE_ENABLE_FTS2 |
| 174937 | SQLITE_PRIVATE int sqlite3Fts2Init(sqlite3*); |
| 174938 | #endif |
| 174939 | #ifdef SQLITE_ENABLE_FTS5 |
| 174940 | SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*); |
| 174941 | #endif |
| 174942 | #ifdef SQLITE_ENABLE_STMTVTAB |
| 174943 | SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3*); |
| @@ -174946,16 +175255,10 @@ | |
| 174946 | /* |
| 174947 | ** An array of pointers to extension initializer functions for |
| 174948 | ** built-in extensions. |
| 174949 | */ |
| 174950 | static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = { |
| 174951 | #ifdef SQLITE_ENABLE_FTS1 |
| 174952 | sqlite3Fts1Init, |
| 174953 | #endif |
| 174954 | #ifdef SQLITE_ENABLE_FTS2 |
| 174955 | sqlite3Fts2Init, |
| 174956 | #endif |
| 174957 | #ifdef SQLITE_ENABLE_FTS3 |
| 174958 | sqlite3Fts3Init, |
| 174959 | #endif |
| 174960 | #ifdef SQLITE_ENABLE_FTS5 |
| 174961 | sqlite3Fts5Init, |
| @@ -178204,11 +178507,11 @@ | |
| 178204 | ** 2 on off |
| 178205 | ** 1 off on |
| 178206 | ** 0 off off |
| 178207 | ** |
| 178208 | ** Legacy behavior is 3 (double-quoted string literals are allowed anywhere) |
| 178209 | ** and so that is the default. But developers are encouranged to use |
| 178210 | ** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible. |
| 178211 | */ |
| 178212 | #if !defined(SQLITE_DQS) |
| 178213 | # define SQLITE_DQS 3 |
| 178214 | #endif |
| @@ -178739,11 +179042,11 @@ | |
| 178739 | goto error_out; |
| 178740 | } |
| 178741 | |
| 178742 | /* Find the column for which info is requested */ |
| 178743 | if( zColumnName==0 ){ |
| 178744 | /* Query for existance of table only */ |
| 178745 | }else{ |
| 178746 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 178747 | pCol = &pTab->aCol[iCol]; |
| 178748 | if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){ |
| 178749 | break; |
| @@ -179179,11 +179482,11 @@ | |
| 179179 | ** |
| 179180 | ** Set or clear a flag that indicates that the database file is always well- |
| 179181 | ** formed and never corrupt. This flag is clear by default, indicating that |
| 179182 | ** database files might have arbitrary corruption. Setting the flag during |
| 179183 | ** testing causes certain assert() statements in the code to be activated |
| 179184 | ** that demonstrat invariants on well-formed database files. |
| 179185 | */ |
| 179186 | case SQLITE_TESTCTRL_NEVER_CORRUPT: { |
| 179187 | sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int); |
| 179188 | break; |
| 179189 | } |
| @@ -179333,11 +179636,11 @@ | |
| 179333 | ** |
| 179334 | ** "ptr" is a pointer to a u32. |
| 179335 | ** |
| 179336 | ** op==0 Store the current sqlite3TreeTrace in *ptr |
| 179337 | ** op==1 Set sqlite3TreeTrace to the value *ptr |
| 179338 | ** op==3 Store the current sqlite3WhereTrace in *ptr |
| 179339 | ** op==3 Set sqlite3WhereTrace to the value *ptr |
| 179340 | */ |
| 179341 | case SQLITE_TESTCTRL_TRACEFLAGS: { |
| 179342 | int opTrace = va_arg(ap, int); |
| 179343 | u32 *ptr = va_arg(ap, u32*); |
| @@ -179669,11 +179972,11 @@ | |
| 179669 | #endif /* SQLITE_OMIT_WAL */ |
| 179670 | return rc; |
| 179671 | } |
| 179672 | |
| 179673 | /* |
| 179674 | ** Open a read-transaction on the snapshot idendified by pSnapshot. |
| 179675 | */ |
| 179676 | SQLITE_API int sqlite3_snapshot_open( |
| 179677 | sqlite3 *db, |
| 179678 | const char *zDb, |
| 179679 | sqlite3_snapshot *pSnapshot |
| @@ -195704,10 +196007,11 @@ | |
| 195704 | memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING); |
| 195705 | } |
| 195706 | |
| 195707 | for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){ |
| 195708 | NodeReader reader; |
| 195709 | pNode = &pWriter->aNodeWriter[i]; |
| 195710 | |
| 195711 | if( pNode->block.a){ |
| 195712 | rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n); |
| 195713 | while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader); |
| @@ -200348,11 +200652,11 @@ | |
| 200348 | } |
| 200349 | } |
| 200350 | } |
| 200351 | |
| 200352 | /* |
| 200353 | ** Return a JsonNode and all its descendents as a JSON string. |
| 200354 | */ |
| 200355 | static void jsonReturnJson( |
| 200356 | JsonNode *pNode, /* Node to return */ |
| 200357 | sqlite3_context *pCtx, /* Return value for this function */ |
| 200358 | sqlite3_value **aReplace /* Array of replacement values */ |
| @@ -202420,11 +202724,11 @@ | |
| 202420 | UNUSED_PARAMETER(argc); |
| 202421 | UNUSED_PARAMETER(argv); |
| 202422 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 202423 | #ifdef NEVER |
| 202424 | /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will |
| 202425 | ** always have been called to initalize it */ |
| 202426 | if( NEVER(!pStr) ) return; |
| 202427 | #endif |
| 202428 | z = pStr->zBuf; |
| 202429 | for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){ |
| 202430 | if( c=='"' ){ |
| @@ -205011,11 +205315,24 @@ | |
| 205011 | break; |
| 205012 | } |
| 205013 | p->pInfo->nCoord = pRtree->nDim2; |
| 205014 | p->pInfo->anQueue = pCsr->anQueue; |
| 205015 | p->pInfo->mxLevel = pRtree->iDepth + 1; |
| 205016 | }else if( eType==SQLITE_INTEGER || eType==SQLITE_FLOAT ){ |
| 205017 | #ifdef SQLITE_RTREE_INT_ONLY |
| 205018 | p->u.rValue = sqlite3_value_int64(argv[ii]); |
| 205019 | #else |
| 205020 | p->u.rValue = sqlite3_value_double(argv[ii]); |
| 205021 | #endif |
| @@ -205142,24 +205459,25 @@ | |
| 205142 | if( p->usable |
| 205143 | && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2) |
| 205144 | || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) |
| 205145 | ){ |
| 205146 | u8 op; |
| 205147 | switch( p->op ){ |
| 205148 | case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break; |
| 205149 | case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break; |
| 205150 | case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break; |
| 205151 | case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; break; |
| 205152 | case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break; |
| 205153 | case SQLITE_INDEX_CONSTRAINT_MATCH: op = RTREE_MATCH; break; |
| 205154 | default: op = 0; break; |
| 205155 | } |
| 205156 | if( op ){ |
| 205157 | zIdxStr[iIdx++] = op; |
| 205158 | zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0'); |
| 205159 | pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2); |
| 205160 | pIdxInfo->aConstraintUsage[ii].omit = 1; |
| 205161 | } |
| 205162 | } |
| 205163 | } |
| 205164 | |
| 205165 | pIdxInfo->idxNum = 2; |
| @@ -225250,11 +225568,12 @@ | |
| 225250 | #define FTS5_COMMA 13 |
| 225251 | #define FTS5_PLUS 14 |
| 225252 | #define FTS5_STAR 15 |
| 225253 | |
| 225254 | /* This file is automatically generated by Lemon from input grammar |
| 225255 | ** source file "fts5parse.y". */ |
| 225256 | /* |
| 225257 | ** 2000-05-29 |
| 225258 | ** |
| 225259 | ** The author disclaims copyright to this source code. In place of |
| 225260 | ** a legal notice, here is a blessing: |
| @@ -237173,11 +237492,11 @@ | |
| 237173 | if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty)); |
| 237174 | fts5DataRelease(pLeaf); |
| 237175 | pLeaf = 0; |
| 237176 | }else if( bDetailNone ){ |
| 237177 | break; |
| 237178 | }else if( iNext>=pLeaf->szLeaf || iNext<4 ){ |
| 237179 | p->rc = FTS5_CORRUPT; |
| 237180 | break; |
| 237181 | }else{ |
| 237182 | int nShift = iNext - 4; |
| 237183 | int nPg; |
| @@ -237377,11 +237696,13 @@ | |
| 237377 | }else{ |
| 237378 | if( iKey!=1 ){ |
| 237379 | iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix); |
| 237380 | } |
| 237381 | iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix); |
| 237382 | if( nPrefix2>nPrefix ){ |
| 237383 | memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix); |
| 237384 | iOff += (nPrefix2-nPrefix); |
| 237385 | } |
| 237386 | memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2); |
| 237387 | iOff += nSuffix2; |
| @@ -242633,11 +242954,11 @@ | |
| 242633 | int nArg, /* Number of args */ |
| 242634 | sqlite3_value **apUnused /* Function arguments */ |
| 242635 | ){ |
| 242636 | assert( nArg==0 ); |
| 242637 | UNUSED_PARAM2(nArg, apUnused); |
| 242638 | sqlite3_result_text(pCtx, "fts5: 2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0", -1, SQLITE_TRANSIENT); |
| 242639 | } |
| 242640 | |
| 242641 | /* |
| 242642 | ** Return true if zName is the extension on one of the shadow tables used |
| 242643 | ** by this module. |
| 242644 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version $VERSION. 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. |
| @@ -14,10 +14,13 @@ | |
| 14 | ** the text of this file. Search for "Begin file sqlite3.h" to find the start |
| 15 | ** of the embedded sqlite3.h header file.) Additional code files may be needed |
| 16 | ** if you want a wrapper to interface SQLite with your choice of programming |
| 17 | ** language. The code for the "sqlite3" command-line shell is also in a |
| 18 | ** separate file. This file contains only code for the core SQLite library. |
| 19 | ** |
| 20 | ** The content in this amalgamation comes from Fossil check-in |
| 21 | ** ec4ab327decd6a5ee5e6a53f1489e17e0cd. |
| 22 | */ |
| 23 | #define SQLITE_CORE 1 |
| 24 | #define SQLITE_AMALGAMATION 1 |
| 25 | #ifndef SQLITE_PRIVATE |
| 26 | # define SQLITE_PRIVATE static |
| @@ -48,15 +51,15 @@ | |
| 51 | ** NO_TEST - The branches on this line are not |
| 52 | ** measured by branch coverage. This is |
| 53 | ** used on lines of code that actually |
| 54 | ** implement parts of coverage testing. |
| 55 | ** |
| 56 | ** OPTIMIZATION-IF-TRUE - This branch is allowed to always be false |
| 57 | ** and the correct answer is still obtained, |
| 58 | ** though perhaps more slowly. |
| 59 | ** |
| 60 | ** OPTIMIZATION-IF-FALSE - This branch is allowed to always be true |
| 61 | ** and the correct answer is still obtained, |
| 62 | ** though perhaps more slowly. |
| 63 | ** |
| 64 | ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread |
| 65 | ** that would be harmless and undetectable |
| @@ -454,13 +457,13 @@ | |
| 457 | ** |
| 458 | ** See also: [sqlite3_libversion()], |
| 459 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 460 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 461 | */ |
| 462 | #define SQLITE_VERSION "3.43.0" |
| 463 | #define SQLITE_VERSION_NUMBER 3043000 |
| 464 | #define SQLITE_SOURCE_ID "2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9" |
| 465 | |
| 466 | /* |
| 467 | ** CAPI3REF: Run-Time Library Version Numbers |
| 468 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 469 | ** |
| @@ -1498,11 +1501,11 @@ | |
| 1501 | ** the database is not a wal-mode db, or if there is no such connection in any |
| 1502 | ** other process. This opcode cannot be used to detect transactions opened |
| 1503 | ** by clients within the current process, only within other processes. |
| 1504 | ** |
| 1505 | ** <li>[[SQLITE_FCNTL_CKSM_FILE]] |
| 1506 | ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the |
| 1507 | ** [checksum VFS shim] only. |
| 1508 | ** |
| 1509 | ** <li>[[SQLITE_FCNTL_RESET_CACHE]] |
| 1510 | ** If there is currently no transaction open on the database, and the |
| 1511 | ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control |
| @@ -2762,11 +2765,11 @@ | |
| 2765 | ** 3.0.0. |
| 2766 | ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on, |
| 2767 | ** the [VACUUM] command will fail with an obscure error when attempting to |
| 2768 | ** process a table with generated columns and a descending index. This is |
| 2769 | ** not considered a bug since SQLite versions 3.3.0 and earlier do not support |
| 2770 | ** either generated columns or descending indexes. |
| 2771 | ** </dd> |
| 2772 | ** |
| 2773 | ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]] |
| 2774 | ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt> |
| 2775 | ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in |
| @@ -3043,10 +3046,11 @@ | |
| 3046 | ** SQL statements is a no-op and has no effect on SQL statements |
| 3047 | ** that are started after the sqlite3_interrupt() call returns. |
| 3048 | ** |
| 3049 | ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether |
| 3050 | ** or not an interrupt is currently in effect for [database connection] D. |
| 3051 | ** It returns 1 if an interrupt is currently in effect, or 0 otherwise. |
| 3052 | */ |
| 3053 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 3054 | SQLITE_API int sqlite3_is_interrupted(sqlite3*); |
| 3055 | |
| 3056 | /* |
| @@ -3696,12 +3700,14 @@ | |
| 3700 | ** and context pointer P. ^If the X callback is |
| 3701 | ** NULL or if the M mask is zero, then tracing is disabled. The |
| 3702 | ** M argument should be the bitwise OR-ed combination of |
| 3703 | ** zero or more [SQLITE_TRACE] constants. |
| 3704 | ** |
| 3705 | ** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P) |
| 3706 | ** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or |
| 3707 | ** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each |
| 3708 | ** database connection may have at most one trace callback. |
| 3709 | ** |
| 3710 | ** ^The X callback is invoked whenever any of the events identified by |
| 3711 | ** mask M occur. ^The integer return value from the callback is currently |
| 3712 | ** ignored, though this may change in future releases. Callback |
| 3713 | ** implementations should return zero to ensure future compatibility. |
| @@ -4066,11 +4072,11 @@ | |
| 4072 | ** |
| 4073 | ** The first parameter to these interfaces (hereafter referred to |
| 4074 | ** as F) must be one of: |
| 4075 | ** <ul> |
| 4076 | ** <li> A database filename pointer created by the SQLite core and |
| 4077 | ** passed into the xOpen() method of a VFS implementation, or |
| 4078 | ** <li> A filename obtained from [sqlite3_db_filename()], or |
| 4079 | ** <li> A new filename constructed using [sqlite3_create_filename()]. |
| 4080 | ** </ul> |
| 4081 | ** If the F parameter is not one of the above, then the behavior is |
| 4082 | ** undefined and probably undesirable. Older versions of SQLite were |
| @@ -4179,11 +4185,11 @@ | |
| 4185 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); |
| 4186 | |
| 4187 | /* |
| 4188 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 4189 | ** |
| 4190 | ** These interfaces are provided for use by [VFS shim] implementations and |
| 4191 | ** are not useful outside of that context. |
| 4192 | ** |
| 4193 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 4194 | ** database filename D with corresponding journal file J and WAL file W and |
| 4195 | ** with N URI parameters key/values pairs in the array P. The result from |
| @@ -4889,11 +4895,11 @@ | |
| 4895 | ** These three options exist: |
| 4896 | ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished |
| 4897 | ** with it may be passed. ^It is called to dispose of the BLOB or string even |
| 4898 | ** if the call to the bind API fails, except the destructor is not called if |
| 4899 | ** the third parameter is a NULL pointer or the fourth parameter is negative. |
| 4900 | ** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that |
| 4901 | ** the application remains responsible for disposing of the object. ^In this |
| 4902 | ** case, the object and the provided pointer to it must remain valid until |
| 4903 | ** either the prepared statement is finalized or the same SQL parameter is |
| 4904 | ** bound to something else, whichever occurs sooner. |
| 4905 | ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
| @@ -5568,18 +5574,30 @@ | |
| 5574 | ** Use [sqlite3_clear_bindings()] to reset the bindings. |
| 5575 | ** |
| 5576 | ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
| 5577 | ** back to the beginning of its program. |
| 5578 | ** |
| 5579 | ** ^The return code from [sqlite3_reset(S)] indicates whether or not |
| 5580 | ** the previous evaluation of prepared statement S completed successfully. |
| 5581 | ** ^If [sqlite3_step(S)] has never before been called on S or if |
| 5582 | ** [sqlite3_step(S)] has not been called since the previous call |
| 5583 | ** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return |
| 5584 | ** [SQLITE_OK]. |
| 5585 | ** |
| 5586 | ** ^If the most recent call to [sqlite3_step(S)] for the |
| 5587 | ** [prepared statement] S indicated an error, then |
| 5588 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
| 5589 | ** ^The [sqlite3_reset(S)] interface might also return an [error code] |
| 5590 | ** if there were no prior errors but the process of resetting |
| 5591 | ** the prepared statement caused a new error. ^For example, if an |
| 5592 | ** [INSERT] statement with a [RETURNING] clause is only stepped one time, |
| 5593 | ** that one call to [sqlite3_step(S)] might return SQLITE_ROW but |
| 5594 | ** the overall statement might still fail and the [sqlite3_reset(S)] call |
| 5595 | ** might return SQLITE_BUSY if locking constraints prevent the |
| 5596 | ** database change from committing. Therefore, it is important that |
| 5597 | ** applications check the return code from [sqlite3_reset(S)] even if |
| 5598 | ** no prior call to [sqlite3_step(S)] indicated a problem. |
| 5599 | ** |
| 5600 | ** ^The [sqlite3_reset(S)] interface does not change the values |
| 5601 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
| 5602 | */ |
| 5603 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| @@ -5792,11 +5810,11 @@ | |
| 5810 | ** <p> |
| 5811 | ** The SQLITE_DIRECTONLY flag is recommended for any |
| 5812 | ** [application-defined SQL function] |
| 5813 | ** that has side-effects or that could potentially leak sensitive information. |
| 5814 | ** This will prevent attacks in which an application is tricked |
| 5815 | ** into using a database file that has had its schema surreptitiously |
| 5816 | ** modified to invoke the application-defined function in ways that are |
| 5817 | ** harmful. |
| 5818 | ** <p> |
| 5819 | ** Some people say it is good practice to set SQLITE_DIRECTONLY on all |
| 5820 | ** [application-defined SQL functions], regardless of whether or not they |
| @@ -9501,12 +9519,12 @@ | |
| 9519 | ** ^(There may be at most one unlock-notify callback registered by a |
| 9520 | ** blocked connection. If sqlite3_unlock_notify() is called when the |
| 9521 | ** blocked connection already has a registered unlock-notify callback, |
| 9522 | ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is |
| 9523 | ** called with a NULL pointer as its second argument, then any existing |
| 9524 | ** unlock-notify callback is cancelled. ^The blocked connections |
| 9525 | ** unlock-notify callback may also be cancelled by closing the blocked |
| 9526 | ** connection using [sqlite3_close()]. |
| 9527 | ** |
| 9528 | ** The unlock-notify callback is not reentrant. If an application invokes |
| 9529 | ** any sqlite3_xxx API functions from within an unlock-notify callback, a |
| 9530 | ** crash or deadlock may be the result. |
| @@ -9925,11 +9943,11 @@ | |
| 9943 | ** </dd> |
| 9944 | ** |
| 9945 | ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 9946 | ** <dd>Calls of the form |
| 9947 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 9948 | ** the [xConnect] or [xCreate] methods of a [virtual table] implementation |
| 9949 | ** prohibits that virtual table from being used from within triggers and |
| 9950 | ** views. |
| 9951 | ** </dd> |
| 9952 | ** |
| 9953 | ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| @@ -10115,11 +10133,11 @@ | |
| 10133 | ** ^(A constraint on a virtual table of the form |
| 10134 | ** "[IN operator|column IN (...)]" is |
| 10135 | ** communicated to the xBestIndex method as a |
| 10136 | ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use |
| 10137 | ** this constraint, it must set the corresponding |
| 10138 | ** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under |
| 10139 | ** the usual mode of handling IN operators, SQLite generates [bytecode] |
| 10140 | ** that invokes the [xFilter|xFilter() method] once for each value |
| 10141 | ** on the right-hand side of the IN operator.)^ Thus the virtual table |
| 10142 | ** only sees a single value from the right-hand side of the IN operator |
| 10143 | ** at a time. |
| @@ -10544,11 +10562,11 @@ | |
| 10562 | ** triggers; and so forth. |
| 10563 | ** |
| 10564 | ** When the [sqlite3_blob_write()] API is used to update a blob column, |
| 10565 | ** the pre-update hook is invoked with SQLITE_DELETE. This is because the |
| 10566 | ** in this case the new values are not available. In this case, when a |
| 10567 | ** callback made with op==SQLITE_DELETE is actually a write using the |
| 10568 | ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns |
| 10569 | ** the index of the column being written. In other cases, where the |
| 10570 | ** pre-update hook is being invoked for some other reason, including a |
| 10571 | ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1. |
| 10572 | ** |
| @@ -13468,11 +13486,11 @@ | |
| 13486 | ** The maximum number of terms in a compound SELECT statement. |
| 13487 | ** The code generator for compound SELECT statements does one |
| 13488 | ** level of recursion for each term. A stack overflow can result |
| 13489 | ** if the number of terms is too large. In practice, most SQL |
| 13490 | ** never has more than 3 or 4 terms. Use a value of 0 to disable |
| 13491 | ** any limit on the number of terms in a compound SELECT. |
| 13492 | */ |
| 13493 | #ifndef SQLITE_MAX_COMPOUND_SELECT |
| 13494 | # define SQLITE_MAX_COMPOUND_SELECT 500 |
| 13495 | #endif |
| 13496 | |
| @@ -14806,11 +14824,11 @@ | |
| 14824 | }; |
| 14825 | |
| 14826 | /* |
| 14827 | ** Name of table that holds the database schema. |
| 14828 | ** |
| 14829 | ** The PREFERRED names are used wherever possible. But LEGACY is also |
| 14830 | ** used for backwards compatibility. |
| 14831 | ** |
| 14832 | ** 1. Queries can use either the PREFERRED or the LEGACY names |
| 14833 | ** 2. The sqlite3_set_authorizer() callback uses the LEGACY name |
| 14834 | ** 3. The PRAGMA table_list statement uses the PREFERRED name |
| @@ -16575,11 +16593,11 @@ | |
| 16593 | |
| 16594 | /* |
| 16595 | ** The VdbeCoverage macros are used to set a coverage testing point |
| 16596 | ** for VDBE branch instructions. The coverage testing points are line |
| 16597 | ** numbers in the sqlite3.c source file. VDBE branch coverage testing |
| 16598 | ** only works with an amalgamation build. That's ok since a VDBE branch |
| 16599 | ** coverage build designed for testing the test suite only. No application |
| 16600 | ** should ever ship with VDBE branch coverage measuring turned on. |
| 16601 | ** |
| 16602 | ** VdbeCoverage(v) // Mark the previously coded instruction |
| 16603 | ** // as a branch |
| @@ -16593,21 +16611,21 @@ | |
| 16611 | ** VdbeCoverageNeverNull(v) // Previous three-way branch is only |
| 16612 | ** // taken on the first two ways. The |
| 16613 | ** // NULL option is not possible |
| 16614 | ** |
| 16615 | ** VdbeCoverageEqNe(v) // Previous OP_Jump is only interested |
| 16616 | ** // in distinguishing equal and not-equal. |
| 16617 | ** |
| 16618 | ** Every VDBE branch operation must be tagged with one of the macros above. |
| 16619 | ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and |
| 16620 | ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch() |
| 16621 | ** routine in vdbe.c, alerting the developer to the missed tag. |
| 16622 | ** |
| 16623 | ** During testing, the test application will invoke |
| 16624 | ** sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE,...) to set a callback |
| 16625 | ** routine that is invoked as each bytecode branch is taken. The callback |
| 16626 | ** contains the sqlite3.c source line number of the VdbeCoverage macro and |
| 16627 | ** flags to indicate whether or not the branch was taken. The test application |
| 16628 | ** is responsible for keeping track of this and reporting byte-code branches |
| 16629 | ** that are never taken. |
| 16630 | ** |
| 16631 | ** See the VdbeBranchTaken() macro and vdbeTakeBranch() function in the |
| @@ -16942,11 +16960,11 @@ | |
| 16960 | #endif |
| 16961 | |
| 16962 | /* |
| 16963 | ** Default synchronous levels. |
| 16964 | ** |
| 16965 | ** Note that (for historical reasons) the PAGER_SYNCHRONOUS_* macros differ |
| 16966 | ** from the SQLITE_DEFAULT_SYNCHRONOUS value by 1. |
| 16967 | ** |
| 16968 | ** PAGER_SYNCHRONOUS DEFAULT_SYNCHRONOUS |
| 16969 | ** OFF 1 0 |
| 16970 | ** NORMAL 2 1 |
| @@ -16981,11 +16999,11 @@ | |
| 16999 | |
| 17000 | /* |
| 17001 | ** An instance of the following structure stores a database schema. |
| 17002 | ** |
| 17003 | ** Most Schema objects are associated with a Btree. The exception is |
| 17004 | ** the Schema for the TEMP database (sqlite3.aDb[1]) which is free-standing. |
| 17005 | ** In shared cache mode, a single Schema object can be shared by multiple |
| 17006 | ** Btrees that refer to the same underlying BtShared object. |
| 17007 | ** |
| 17008 | ** Schema objects are automatically deallocated when the last Btree that |
| 17009 | ** references them is destroyed. The TEMP Schema is manually freed by |
| @@ -17092,11 +17110,11 @@ | |
| 17110 | u32 nSlot; /* Number of lookaside slots allocated */ |
| 17111 | u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */ |
| 17112 | LookasideSlot *pInit; /* List of buffers not previously used */ |
| 17113 | LookasideSlot *pFree; /* List of available buffers */ |
| 17114 | #ifndef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 17115 | LookasideSlot *pSmallInit; /* List of small buffers not previously used */ |
| 17116 | LookasideSlot *pSmallFree; /* List of available small buffers */ |
| 17117 | void *pMiddle; /* First byte past end of full-size buffers and |
| 17118 | ** the first byte of LOOKASIDE_SMALL buffers */ |
| 17119 | #endif /* SQLITE_OMIT_TWOSIZE_LOOKASIDE */ |
| 17120 | void *pStart; /* First byte of available memory space */ |
| @@ -17109,11 +17127,11 @@ | |
| 17127 | |
| 17128 | #define DisableLookaside db->lookaside.bDisable++;db->lookaside.sz=0 |
| 17129 | #define EnableLookaside db->lookaside.bDisable--;\ |
| 17130 | db->lookaside.sz=db->lookaside.bDisable?0:db->lookaside.szTrue |
| 17131 | |
| 17132 | /* Size of the smaller allocations in two-size lookaside */ |
| 17133 | #ifdef SQLITE_OMIT_TWOSIZE_LOOKASIDE |
| 17134 | # define LOOKASIDE_SMALL 0 |
| 17135 | #else |
| 17136 | # define LOOKASIDE_SMALL 128 |
| 17137 | #endif |
| @@ -17537,11 +17555,11 @@ | |
| 17555 | ** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!! |
| 17556 | ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API |
| 17557 | ** |
| 17558 | ** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the |
| 17559 | ** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is |
| 17560 | ** used internally and if set means that the function has side effects. |
| 17561 | ** SQLITE_INNOCUOUS is used by application code and means "not unsafe". |
| 17562 | ** See multiple instances of tag-20230109-1. |
| 17563 | */ |
| 17564 | #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */ |
| 17565 | #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */ |
| @@ -18127,11 +18145,11 @@ | |
| 18145 | ** to its default value. CASCADE means that a DELETE or UPDATE of the |
| 18146 | ** referenced table row is propagated into the row that holds the |
| 18147 | ** foreign key. |
| 18148 | ** |
| 18149 | ** The OE_Default value is a place holder that means to use whatever |
| 18150 | ** conflict resolution algorithm is required from context. |
| 18151 | ** |
| 18152 | ** The following symbolic values are used to record which type |
| 18153 | ** of conflict resolution action to take. |
| 18154 | */ |
| 18155 | #define OE_None 0 /* There is no constraint to check */ |
| @@ -18541,11 +18559,11 @@ | |
| 18559 | #endif |
| 18560 | int iTable; /* TK_COLUMN: cursor number of table holding column |
| 18561 | ** TK_REGISTER: register number |
| 18562 | ** TK_TRIGGER: 1 -> new, 0 -> old |
| 18563 | ** EP_Unlikely: 134217728 times likelihood |
| 18564 | ** TK_IN: ephemeral table holding RHS |
| 18565 | ** TK_SELECT_COLUMN: Number of columns on the LHS |
| 18566 | ** TK_SELECT: 1st register of result vector */ |
| 18567 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 18568 | ** TK_VARIABLE: variable number (always >= 1). |
| 18569 | ** TK_SELECT_COLUMN: column of the result vector */ |
| @@ -18811,11 +18829,11 @@ | |
| 18829 | unsigned fromDDL :1; /* Comes from sqlite_schema */ |
| 18830 | unsigned isCte :1; /* This is a CTE */ |
| 18831 | unsigned notCte :1; /* This item may not match a CTE */ |
| 18832 | unsigned isUsing :1; /* u3.pUsing is valid */ |
| 18833 | unsigned isOn :1; /* u3.pOn was once valid and non-NULL */ |
| 18834 | unsigned isSynthUsing :1; /* u3.pUsing is synthesized from NATURAL */ |
| 18835 | unsigned isNestedFrom :1; /* pSelect is a SF_NestedFrom subquery */ |
| 18836 | } fg; |
| 18837 | int iCursor; /* The VDBE cursor number used to access this table */ |
| 18838 | union { |
| 18839 | Expr *pOn; /* fg.isUsing==0 => The ON clause of a join */ |
| @@ -19657,11 +19675,11 @@ | |
| 19675 | #define INITFLAG_AlterAdd 0x0003 /* Reparse after an ADD COLUMN */ |
| 19676 | |
| 19677 | /* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled |
| 19678 | ** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning |
| 19679 | ** parameters are for temporary use during development, to help find |
| 19680 | ** optimal values for parameters in the query planner. The should not |
| 19681 | ** be used on trunk check-ins. They are a temporary mechanism available |
| 19682 | ** for transient development builds only. |
| 19683 | ** |
| 19684 | ** Tuning parameters are numbered starting with 1. |
| 19685 | */ |
| @@ -19769,10 +19787,11 @@ | |
| 19787 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 19788 | int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 19789 | void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */ |
| 19790 | int walkerDepth; /* Number of subqueries */ |
| 19791 | u16 eCode; /* A small processing code */ |
| 19792 | u16 mWFlags; /* Use-dependent flags */ |
| 19793 | union { /* Extra data for callback */ |
| 19794 | NameContext *pNC; /* Naming context */ |
| 19795 | int n; /* A counter */ |
| 19796 | int iCur; /* A cursor number */ |
| 19797 | SrcList *pSrcList; /* FROM clause */ |
| @@ -20479,11 +20498,11 @@ | |
| 20498 | SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, const Token*); |
| 20499 | SQLITE_PRIVATE int sqlite3ExprCompare(const Parse*,const Expr*,const Expr*, int); |
| 20500 | SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*,Expr*,int); |
| 20501 | SQLITE_PRIVATE int sqlite3ExprListCompare(const ExprList*,const ExprList*, int); |
| 20502 | SQLITE_PRIVATE int sqlite3ExprImpliesExpr(const Parse*,const Expr*,const Expr*, int); |
| 20503 | SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int,int); |
| 20504 | SQLITE_PRIVATE void sqlite3AggInfoPersistWalkerInit(Walker*,Parse*); |
| 20505 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 20506 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 20507 | SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| 20508 | SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse*, Expr*, SrcList*); |
| @@ -23042,11 +23061,11 @@ | |
| 23061 | int iNewReg; /* Register for new.* values */ |
| 23062 | int iBlobWrite; /* Value returned by preupdate_blobwrite() */ |
| 23063 | i64 iKey1; /* First key value passed to hook */ |
| 23064 | i64 iKey2; /* Second key value passed to hook */ |
| 23065 | Mem *aNew; /* Array of new.* values */ |
| 23066 | Table *pTab; /* Schema object being updated */ |
| 23067 | Index *pPk; /* PK index if pTab is WITHOUT ROWID */ |
| 23068 | }; |
| 23069 | |
| 23070 | /* |
| 23071 | ** An instance of this object is used to pass an vector of values into |
| @@ -24258,10 +24277,29 @@ | |
| 24277 | { 4, "hour", 1.2897e+11, 3600.0 }, |
| 24278 | { 3, "day", 5373485.0, 86400.0 }, |
| 24279 | { 5, "month", 176546.0, 2592000.0 }, |
| 24280 | { 4, "year", 14713.0, 31536000.0 }, |
| 24281 | }; |
| 24282 | |
| 24283 | /* |
| 24284 | ** If the DateTime p is raw number, try to figure out if it is |
| 24285 | ** a julian day number of a unix timestamp. Set the p value |
| 24286 | ** appropriately. |
| 24287 | */ |
| 24288 | static void autoAdjustDate(DateTime *p){ |
| 24289 | if( !p->rawS || p->validJD ){ |
| 24290 | p->rawS = 0; |
| 24291 | }else if( p->s>=-21086676*(i64)10000 /* -4713-11-24 12:00:00 */ |
| 24292 | && p->s<=(25340230*(i64)10000)+799 /* 9999-12-31 23:59:59 */ |
| 24293 | ){ |
| 24294 | double r = p->s*1000.0 + 210866760000000.0; |
| 24295 | clearYMD_HMS_TZ(p); |
| 24296 | p->iJD = (sqlite3_int64)(r + 0.5); |
| 24297 | p->validJD = 1; |
| 24298 | p->rawS = 0; |
| 24299 | } |
| 24300 | } |
| 24301 | |
| 24302 | /* |
| 24303 | ** Process a modifier to a date-time stamp. The modifiers are |
| 24304 | ** as follows: |
| 24305 | ** |
| @@ -24302,23 +24340,12 @@ | |
| 24340 | ** If rawS is available, then interpret as a julian day number, or |
| 24341 | ** a unix timestamp, depending on its magnitude. |
| 24342 | */ |
| 24343 | if( sqlite3_stricmp(z, "auto")==0 ){ |
| 24344 | if( idx>1 ) return 1; /* IMP: R-33611-57934 */ |
| 24345 | autoAdjustDate(p); |
| 24346 | rc = 0; |
| 24347 | } |
| 24348 | break; |
| 24349 | } |
| 24350 | case 'j': { |
| 24351 | /* |
| @@ -24480,22 +24507,68 @@ | |
| 24507 | case '7': |
| 24508 | case '8': |
| 24509 | case '9': { |
| 24510 | double rRounder; |
| 24511 | int i; |
| 24512 | int Y,M,D,h,m,x; |
| 24513 | const char *z2 = z; |
| 24514 | for(n=1; z[n]; n++){ |
| 24515 | if( z[n]==':' ) break; |
| 24516 | if( sqlite3Isspace(z[n]) ) break; |
| 24517 | if( z[n]=='-' && n==5 && getDigits(&z[1], "40f", &Y)==1 ) break; |
| 24518 | } |
| 24519 | if( sqlite3AtoF(z, &r, n, SQLITE_UTF8)<=0 ){ |
| 24520 | rc = 1; |
| 24521 | break; |
| 24522 | } |
| 24523 | if( z[n]=='-' ){ |
| 24524 | /* A modifier of the form (+|-)YYYY-MM-DD adds or subtracts the |
| 24525 | ** specified number of years, months, and days. MM is limited to |
| 24526 | ** the range 0-11 and DD is limited to 0-30. |
| 24527 | */ |
| 24528 | if( z[0]!='+' && z[0]!='-' ) break; /* Must start with +/- */ |
| 24529 | if( NEVER(n!=5) ) break; /* Must be 4-digit YYYY */ |
| 24530 | if( getDigits(&z[1], "40f-20a-20d", &Y, &M, &D)!=3 ) break; |
| 24531 | if( M>=12 ) break; /* M range 0..11 */ |
| 24532 | if( D>=31 ) break; /* D range 0..30 */ |
| 24533 | computeYMD_HMS(p); |
| 24534 | p->validJD = 0; |
| 24535 | if( z[0]=='-' ){ |
| 24536 | p->Y -= Y; |
| 24537 | p->M -= M; |
| 24538 | D = -D; |
| 24539 | }else{ |
| 24540 | p->Y += Y; |
| 24541 | p->M += M; |
| 24542 | } |
| 24543 | x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; |
| 24544 | p->Y += x; |
| 24545 | p->M -= x*12; |
| 24546 | computeJD(p); |
| 24547 | p->validHMS = 0; |
| 24548 | p->validYMD = 0; |
| 24549 | p->iJD += (i64)D*86400000; |
| 24550 | if( z[11]==0 ){ |
| 24551 | rc = 0; |
| 24552 | break; |
| 24553 | } |
| 24554 | if( sqlite3Isspace(z[11]) |
| 24555 | && getDigits(&z[12], "20c:20e", &h, &m)==2 |
| 24556 | ){ |
| 24557 | z2 = &z[12]; |
| 24558 | n = 2; |
| 24559 | }else{ |
| 24560 | break; |
| 24561 | } |
| 24562 | } |
| 24563 | if( z2[n]==':' ){ |
| 24564 | /* A modifier of the form (+|-)HH:MM:SS.FFF adds (or subtracts) the |
| 24565 | ** specified number of hours, minutes, seconds, and fractional seconds |
| 24566 | ** to the time. The ".FFF" may be omitted. The ":SS.FFF" may be |
| 24567 | ** omitted. |
| 24568 | */ |
| 24569 | |
| 24570 | DateTime tx; |
| 24571 | sqlite3_int64 day; |
| 24572 | if( !sqlite3Isdigit(*z2) ) z2++; |
| 24573 | memset(&tx, 0, sizeof(tx)); |
| 24574 | if( parseHhMmSs(z2, &tx) ) break; |
| @@ -24526,11 +24599,10 @@ | |
| 24599 | && sqlite3_strnicmp(aXformType[i].zName, z, n)==0 |
| 24600 | && r>-aXformType[i].rLimit && r<aXformType[i].rLimit |
| 24601 | ){ |
| 24602 | switch( i ){ |
| 24603 | case 4: { /* Special processing to add months */ |
| 24604 | assert( strcmp(aXformType[i].zName,"month")==0 ); |
| 24605 | computeYMD_HMS(p); |
| 24606 | p->M += (int)r; |
| 24607 | x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; |
| 24608 | p->Y += x; |
| @@ -24803,11 +24875,11 @@ | |
| 24875 | ** %J ** julian day number |
| 24876 | ** %m month 01-12 |
| 24877 | ** %M minute 00-59 |
| 24878 | ** %s seconds since 1970-01-01 |
| 24879 | ** %S seconds 00-59 |
| 24880 | ** %w day of week 0-6 Sunday==0 |
| 24881 | ** %W week of year 00-53 |
| 24882 | ** %Y year 0000-9999 |
| 24883 | ** %% % |
| 24884 | */ |
| 24885 | static void strftimeFunc( |
| @@ -24942,10 +25014,120 @@ | |
| 25014 | sqlite3_value **NotUsed2 |
| 25015 | ){ |
| 25016 | UNUSED_PARAMETER2(NotUsed, NotUsed2); |
| 25017 | dateFunc(context, 0, 0); |
| 25018 | } |
| 25019 | |
| 25020 | /* |
| 25021 | ** timediff(DATE1, DATE2) |
| 25022 | ** |
| 25023 | ** Return the amount of time that must be added to DATE2 in order to |
| 25024 | ** convert it into DATE2. The time difference format is: |
| 25025 | ** |
| 25026 | ** +YYYY-MM-DD HH:MM:SS.SSS |
| 25027 | ** |
| 25028 | ** The initial "+" becomes "-" if DATE1 occurs before DATE2. For |
| 25029 | ** date/time values A and B, the following invariant should hold: |
| 25030 | ** |
| 25031 | ** datetime(A) == (datetime(B, timediff(A,B)) |
| 25032 | ** |
| 25033 | ** Both DATE arguments must be either a julian day number, or an |
| 25034 | ** ISO-8601 string. The unix timestamps are not supported by this |
| 25035 | ** routine. |
| 25036 | */ |
| 25037 | static void timediffFunc( |
| 25038 | sqlite3_context *context, |
| 25039 | int argc, |
| 25040 | sqlite3_value **argv |
| 25041 | ){ |
| 25042 | char sign; |
| 25043 | int Y, M; |
| 25044 | DateTime d1, d2; |
| 25045 | sqlite3_str sRes; |
| 25046 | if( isDate(context, 1, argv, &d1) ) return; |
| 25047 | if( isDate(context, 1, &argv[1], &d2) ) return; |
| 25048 | computeYMD_HMS(&d1); |
| 25049 | computeYMD_HMS(&d2); |
| 25050 | if( d1.iJD>=d2.iJD ){ |
| 25051 | sign = '+'; |
| 25052 | Y = d1.Y - d2.Y; |
| 25053 | if( Y ){ |
| 25054 | d2.Y = d1.Y; |
| 25055 | d2.validJD = 0; |
| 25056 | computeJD(&d2); |
| 25057 | } |
| 25058 | M = d1.M - d2.M; |
| 25059 | if( M<0 ){ |
| 25060 | Y--; |
| 25061 | M += 12; |
| 25062 | } |
| 25063 | if( M!=0 ){ |
| 25064 | d2.M = d1.M; |
| 25065 | d2.validJD = 0; |
| 25066 | computeJD(&d2); |
| 25067 | } |
| 25068 | if( d1.iJD<d2.iJD ){ |
| 25069 | M--; |
| 25070 | if( M<0 ){ |
| 25071 | M = 11; |
| 25072 | Y--; |
| 25073 | } |
| 25074 | d2.M--; |
| 25075 | if( d2.M<1 ){ |
| 25076 | d2.M = 12; |
| 25077 | d2.Y--; |
| 25078 | } |
| 25079 | d2.validJD = 0; |
| 25080 | computeJD(&d2); |
| 25081 | } |
| 25082 | d1.iJD -= d2.iJD; |
| 25083 | d1.iJD += 148699540800000; |
| 25084 | }else{ |
| 25085 | sign = '-'; |
| 25086 | Y = d2.Y - d1.Y; |
| 25087 | if( Y ){ |
| 25088 | d2.Y = d1.Y; |
| 25089 | d2.validJD = 0; |
| 25090 | computeJD(&d2); |
| 25091 | } |
| 25092 | M = d2.M - d1.M; |
| 25093 | if( M<0 ){ |
| 25094 | Y--; |
| 25095 | M += 12; |
| 25096 | } |
| 25097 | if( M!=0 ){ |
| 25098 | d2.M = d1.M; |
| 25099 | d2.validJD = 0; |
| 25100 | computeJD(&d2); |
| 25101 | } |
| 25102 | if( d1.iJD>d2.iJD ){ |
| 25103 | M--; |
| 25104 | if( M<0 ){ |
| 25105 | M = 11; |
| 25106 | Y--; |
| 25107 | } |
| 25108 | d2.M++; |
| 25109 | if( d2.M>12 ){ |
| 25110 | d2.M = 1; |
| 25111 | d2.Y++; |
| 25112 | } |
| 25113 | d2.validJD = 0; |
| 25114 | computeJD(&d2); |
| 25115 | } |
| 25116 | d1.iJD = d2.iJD - d1.iJD; |
| 25117 | d1.iJD += 148699540800000; |
| 25118 | } |
| 25119 | d1.validYMD = 0; |
| 25120 | d1.validHMS = 0; |
| 25121 | d1.validTZ = 0; |
| 25122 | computeYMD_HMS(&d1); |
| 25123 | sqlite3StrAccumInit(&sRes, 0, 0, 0, 100); |
| 25124 | sqlite3_str_appendf(&sRes, "%c%04d-%02d-%02d %02d:%02d:%06.3f", |
| 25125 | sign, Y, M, d1.D-1, d1.h, d1.m, d1.s); |
| 25126 | sqlite3ResultStrAccum(context, &sRes); |
| 25127 | } |
| 25128 | |
| 25129 | |
| 25130 | /* |
| 25131 | ** current_timestamp() |
| 25132 | ** |
| 25133 | ** This function returns the same value as datetime('now'). |
| @@ -25017,10 +25199,11 @@ | |
| 25199 | PURE_DATE(unixepoch, -1, 0, 0, unixepochFunc ), |
| 25200 | PURE_DATE(date, -1, 0, 0, dateFunc ), |
| 25201 | PURE_DATE(time, -1, 0, 0, timeFunc ), |
| 25202 | PURE_DATE(datetime, -1, 0, 0, datetimeFunc ), |
| 25203 | PURE_DATE(strftime, -1, 0, 0, strftimeFunc ), |
| 25204 | PURE_DATE(timediff, 2, 0, 0, timediffFunc ), |
| 25205 | DFUNCTION(current_time, 0, 0, 0, ctimeFunc ), |
| 25206 | DFUNCTION(current_timestamp, 0, 0, 0, ctimestampFunc), |
| 25207 | DFUNCTION(current_date, 0, 0, 0, cdateFunc ), |
| 25208 | #else |
| 25209 | STR_FUNCTION(current_time, 0, "%H:%M:%S", 0, currentTimeFunc), |
| @@ -25170,11 +25353,11 @@ | |
| 25353 | && op!=SQLITE_FCNTL_CKPT_START |
| 25354 | ){ |
| 25355 | /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite |
| 25356 | ** is using a regular VFS, it is called after the corresponding |
| 25357 | ** transaction has been committed. Injecting a fault at this point |
| 25358 | ** confuses the test scripts - the COMMIT command returns SQLITE_NOMEM |
| 25359 | ** but the transaction is committed anyway. |
| 25360 | ** |
| 25361 | ** The core must call OsFileControl() though, not OsFileControlHint(), |
| 25362 | ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably |
| 25363 | ** means the commit really has failed and an error should be returned |
| @@ -25791,11 +25974,11 @@ | |
| 25974 | /* |
| 25975 | ** Like free() but works for allocations obtained from sqlite3MemMalloc() |
| 25976 | ** or sqlite3MemRealloc(). |
| 25977 | ** |
| 25978 | ** For this low-level routine, we already know that pPrior!=0 since |
| 25979 | ** cases where pPrior==0 will have been intercepted and dealt with |
| 25980 | ** by higher-level routines. |
| 25981 | */ |
| 25982 | static void sqlite3MemFree(void *pPrior){ |
| 25983 | #ifdef SQLITE_MALLOCSIZE |
| 25984 | SQLITE_FREE(pPrior); |
| @@ -25879,11 +26062,11 @@ | |
| 26062 | size_t len; |
| 26063 | if( _sqliteZone_ ){ |
| 26064 | return SQLITE_OK; |
| 26065 | } |
| 26066 | len = sizeof(cpuCount); |
| 26067 | /* One usually wants to use hw.activecpu for MT decisions, but not here */ |
| 26068 | sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0); |
| 26069 | if( cpuCount>1 ){ |
| 26070 | /* defer MT decisions to system malloc */ |
| 26071 | _sqliteZone_ = malloc_default_zone(); |
| 26072 | }else{ |
| @@ -28346,11 +28529,11 @@ | |
| 28529 | |
| 28530 | #include <pthread.h> |
| 28531 | |
| 28532 | /* |
| 28533 | ** The sqlite3_mutex.id, sqlite3_mutex.nRef, and sqlite3_mutex.owner fields |
| 28534 | ** are necessary under two conditions: (1) Debug builds and (2) using |
| 28535 | ** home-grown mutexes. Encapsulate these conditions into a single #define. |
| 28536 | */ |
| 28537 | #if defined(SQLITE_DEBUG) || defined(SQLITE_HOMEGROWN_RECURSIVE_MUTEX) |
| 28538 | # define SQLITE_MUTEX_NREF 1 |
| 28539 | #else |
| @@ -28847,11 +29030,11 @@ | |
| 29030 | */ |
| 29031 | struct sqlite3_mutex { |
| 29032 | CRITICAL_SECTION mutex; /* Mutex controlling the lock */ |
| 29033 | int id; /* Mutex type */ |
| 29034 | #ifdef SQLITE_DEBUG |
| 29035 | volatile int nRef; /* Number of entrances */ |
| 29036 | volatile DWORD owner; /* Thread holding this mutex */ |
| 29037 | volatile LONG trace; /* True to trace changes */ |
| 29038 | #endif |
| 29039 | }; |
| 29040 | |
| @@ -32228,11 +32411,12 @@ | |
| 32411 | const char *azOp[] = { |
| 32412 | "IS-FALSE", "IS-TRUE", "IS-NOT-FALSE", "IS-NOT-TRUE" |
| 32413 | }; |
| 32414 | assert( pExpr->op2==TK_IS || pExpr->op2==TK_ISNOT ); |
| 32415 | assert( pExpr->pRight ); |
| 32416 | assert( sqlite3ExprSkipCollateAndLikely(pExpr->pRight)->op |
| 32417 | == TK_TRUEFALSE ); |
| 32418 | x = (pExpr->op2==TK_ISNOT)*2 + sqlite3ExprTruthValue(pExpr->pRight); |
| 32419 | zUniOp = azOp[x]; |
| 32420 | break; |
| 32421 | } |
| 32422 | |
| @@ -33887,11 +34071,11 @@ | |
| 34071 | #endif |
| 34072 | |
| 34073 | /* |
| 34074 | ** Calls to sqlite3FaultSim() are used to simulate a failure during testing, |
| 34075 | ** or to bypass normal error detection during testing in order to let |
| 34076 | ** execute proceed further downstream. |
| 34077 | ** |
| 34078 | ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The |
| 34079 | ** sqlite3FaultSim() function only returns non-zero during testing. |
| 34080 | ** |
| 34081 | ** During testing, if the test harness has set a fault-sim callback using |
| @@ -34498,11 +34682,11 @@ | |
| 34682 | } |
| 34683 | |
| 34684 | /* store the result */ |
| 34685 | *pResult = result; |
| 34686 | |
| 34687 | /* return true if number and no extra non-whitespace characters after */ |
| 34688 | if( z==zEnd && nDigit>0 && eValid && eType>0 ){ |
| 34689 | return eType; |
| 34690 | }else if( eType>=2 && (eType==3 || eValid) && nDigit>0 ){ |
| 34691 | return -1; |
| 34692 | }else{ |
| @@ -34634,11 +34818,11 @@ | |
| 34818 | testcase( i==20*incr ); |
| 34819 | if( u>LARGEST_INT64 ){ |
| 34820 | /* This test and assignment is needed only to suppress UB warnings |
| 34821 | ** from clang and -fsanitize=undefined. This test and assignment make |
| 34822 | ** the code a little larger and slower, and no harm comes from omitting |
| 34823 | ** them, but we must appease the undefined-behavior pharisees. */ |
| 34824 | *pNum = neg ? SMALLEST_INT64 : LARGEST_INT64; |
| 34825 | }else if( neg ){ |
| 34826 | *pNum = -(i64)u; |
| 34827 | }else{ |
| 34828 | *pNum = (i64)u; |
| @@ -35319,11 +35503,11 @@ | |
| 35503 | return 1; |
| 35504 | } |
| 35505 | } |
| 35506 | |
| 35507 | /* |
| 35508 | ** Attempt to add, subtract, or multiply the 64-bit signed value iB against |
| 35509 | ** the other 64-bit signed integer at *pA and store the result in *pA. |
| 35510 | ** Return 0 on success. Or if the operation would have resulted in an |
| 35511 | ** overflow, leave *pA unchanged and return 1. |
| 35512 | */ |
| 35513 | SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){ |
| @@ -35632,11 +35816,11 @@ | |
| 35816 | */ |
| 35817 | #ifndef SQLITE_HWTIME_H |
| 35818 | #define SQLITE_HWTIME_H |
| 35819 | |
| 35820 | /* |
| 35821 | ** The following routine only works on Pentium-class (or newer) processors. |
| 35822 | ** It uses the RDTSC opcode to read the cycle count value out of the |
| 35823 | ** processor and returns that value. This can be used for high-res |
| 35824 | ** profiling. |
| 35825 | */ |
| 35826 | #if !defined(__STRICT_ANSI__) && \ |
| @@ -35804,11 +35988,11 @@ | |
| 35988 | pH->first = pNew; |
| 35989 | } |
| 35990 | } |
| 35991 | |
| 35992 | |
| 35993 | /* Resize the hash table so that it contains "new_size" buckets. |
| 35994 | ** |
| 35995 | ** The hash table might fail to resize if sqlite3_malloc() fails or |
| 35996 | ** if the new size is the same as the prior size. |
| 35997 | ** Return TRUE if the resize occurs and false if not. |
| 35998 | */ |
| @@ -37190,11 +37374,11 @@ | |
| 37374 | ** skip locking all together. |
| 37375 | ** |
| 37376 | ** This source file is organized into divisions where the logic for various |
| 37377 | ** subfunctions is contained within the appropriate division. PLEASE |
| 37378 | ** KEEP THE STRUCTURE OF THIS FILE INTACT. New code should be placed |
| 37379 | ** in the correct division and should be clearly labelled. |
| 37380 | ** |
| 37381 | ** The layout of divisions is as follows: |
| 37382 | ** |
| 37383 | ** * General-purpose declarations and utility functions. |
| 37384 | ** * Unique file ID logic used by VxWorks. |
| @@ -37777,11 +37961,11 @@ | |
| 37961 | #endif |
| 37962 | } |
| 37963 | |
| 37964 | /* |
| 37965 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| 37966 | ** "unix" VFSes. Return SQLITE_OK upon successfully updating the |
| 37967 | ** system call pointer, or SQLITE_NOTFOUND if there is no configurable |
| 37968 | ** system call named zName. |
| 37969 | */ |
| 37970 | static int unixSetSystemCall( |
| 37971 | sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ |
| @@ -38299,11 +38483,11 @@ | |
| 38483 | ** But wait: there are yet more problems with POSIX advisory locks. |
| 38484 | ** |
| 38485 | ** If you close a file descriptor that points to a file that has locks, |
| 38486 | ** all locks on that file that are owned by the current process are |
| 38487 | ** released. To work around this problem, each unixInodeInfo object |
| 38488 | ** maintains a count of the number of pending locks on the inode. |
| 38489 | ** When an attempt is made to close an unixFile, if there are |
| 38490 | ** other unixFile open on the same inode that are holding locks, the call |
| 38491 | ** to close() the file descriptor is deferred until all of the locks clear. |
| 38492 | ** The unixInodeInfo structure keeps a list of file descriptors that need to |
| 38493 | ** be closed and that list is walked (and cleared) when the last lock |
| @@ -38313,11 +38497,11 @@ | |
| 38497 | ** |
| 38498 | ** Many older versions of linux use the LinuxThreads library which is |
| 38499 | ** not posix compliant. Under LinuxThreads, a lock created by thread |
| 38500 | ** A cannot be modified or overridden by a different thread B. |
| 38501 | ** Only thread A can modify the lock. Locking behavior is correct |
| 38502 | ** if the application uses the newer Native Posix Thread Library (NPTL) |
| 38503 | ** on linux - with NPTL a lock created by thread A can override locks |
| 38504 | ** in thread B. But there is no way to know at compile-time which |
| 38505 | ** threading library is being used. So there is no way to know at |
| 38506 | ** compile-time whether or not thread A can override locks on thread B. |
| 38507 | ** One has to do a run-time check to discover the behavior of the |
| @@ -38515,11 +38699,11 @@ | |
| 38699 | static void storeLastErrno(unixFile *pFile, int error){ |
| 38700 | pFile->lastErrno = error; |
| 38701 | } |
| 38702 | |
| 38703 | /* |
| 38704 | ** Close all file descriptors accumulated in the unixInodeInfo->pUnused list. |
| 38705 | */ |
| 38706 | static void closePendingFds(unixFile *pFile){ |
| 38707 | unixInodeInfo *pInode = pFile->pInode; |
| 38708 | UnixUnusedFd *p; |
| 38709 | UnixUnusedFd *pNext; |
| @@ -38878,19 +39062,19 @@ | |
| 39062 | ** lock primitives (called read-locks and write-locks below, to avoid |
| 39063 | ** confusion with SQLite lock names). The algorithms are complicated |
| 39064 | ** slightly in order to be compatible with Windows95 systems simultaneously |
| 39065 | ** accessing the same database file, in case that is ever required. |
| 39066 | ** |
| 39067 | ** Symbols defined in os.h identify the 'pending byte' and the 'reserved |
| 39068 | ** byte', each single bytes at well known offsets, and the 'shared byte |
| 39069 | ** range', a range of 510 bytes at a well known offset. |
| 39070 | ** |
| 39071 | ** To obtain a SHARED lock, a read-lock is obtained on the 'pending |
| 39072 | ** byte'. If this is successful, 'shared byte range' is read-locked |
| 39073 | ** and the lock on the 'pending byte' released. (Legacy note: When |
| 39074 | ** SQLite was first developed, Windows95 systems were still very common, |
| 39075 | ** and Windows95 lacks a shared-lock capability. So on Windows95, a |
| 39076 | ** single randomly selected by from the 'shared byte range' is locked. |
| 39077 | ** Windows95 is now pretty much extinct, but this work-around for the |
| 39078 | ** lack of shared-locks on Windows95 lives on, for backwards |
| 39079 | ** compatibility.) |
| 39080 | ** |
| @@ -38907,11 +39091,11 @@ | |
| 39091 | ** If a process that holds a RESERVED lock requests an EXCLUSIVE, then |
| 39092 | ** a PENDING lock is obtained first. A PENDING lock is implemented by |
| 39093 | ** obtaining a write-lock on the 'pending byte'. This ensures that no new |
| 39094 | ** SHARED locks can be obtained, but existing SHARED locks are allowed to |
| 39095 | ** persist. If the call to this function fails to obtain the EXCLUSIVE |
| 39096 | ** lock in this case, it holds the PENDING lock instead. The client may |
| 39097 | ** then re-attempt the EXCLUSIVE lock later on, after existing SHARED |
| 39098 | ** locks have cleared. |
| 39099 | */ |
| 39100 | int rc = SQLITE_OK; |
| 39101 | unixFile *pFile = (unixFile*)id; |
| @@ -38935,11 +39119,11 @@ | |
| 39119 | return SQLITE_OK; |
| 39120 | } |
| 39121 | |
| 39122 | /* Make sure the locking sequence is correct. |
| 39123 | ** (1) We never move from unlocked to anything higher than shared lock. |
| 39124 | ** (2) SQLite never explicitly requests a pending lock. |
| 39125 | ** (3) A shared lock is always held when a reserve lock is requested. |
| 39126 | */ |
| 39127 | assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); |
| 39128 | assert( eFileLock!=PENDING_LOCK ); |
| 39129 | assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK ); |
| @@ -40153,11 +40337,11 @@ | |
| 40337 | return SQLITE_OK; |
| 40338 | } |
| 40339 | |
| 40340 | /* Make sure the locking sequence is correct |
| 40341 | ** (1) We never move from unlocked to anything higher than shared lock. |
| 40342 | ** (2) SQLite never explicitly requests a pending lock. |
| 40343 | ** (3) A shared lock is always held when a reserve lock is requested. |
| 40344 | */ |
| 40345 | assert( pFile->eFileLock!=NO_LOCK || eFileLock==SHARED_LOCK ); |
| 40346 | assert( eFileLock!=PENDING_LOCK ); |
| 40347 | assert( eFileLock!=RESERVED_LOCK || pFile->eFileLock==SHARED_LOCK ); |
| @@ -40269,11 +40453,11 @@ | |
| 40453 | ** reestablish the shared lock if we can't get the afpUnlock |
| 40454 | */ |
| 40455 | if( !(failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST + |
| 40456 | pInode->sharedByte, 1, 0)) ){ |
| 40457 | int failed2 = SQLITE_OK; |
| 40458 | /* now attempt to get the exclusive lock range */ |
| 40459 | failed = afpSetLock(context->dbPath, pFile, SHARED_FIRST, |
| 40460 | SHARED_SIZE, 1); |
| 40461 | if( failed && (failed2 = afpSetLock(context->dbPath, pFile, |
| 40462 | SHARED_FIRST + pInode->sharedByte, 1, 1)) ){ |
| 40463 | /* Can't reestablish the shared lock. Sqlite can't deal, this is |
| @@ -40564,11 +40748,11 @@ | |
| 40748 | || offset+amt<=PENDING_BYTE |
| 40749 | ); |
| 40750 | #endif |
| 40751 | |
| 40752 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 40753 | /* Deal with as much of this read request as possible by transferring |
| 40754 | ** data from the memory mapping using memcpy(). */ |
| 40755 | if( offset<pFile->mmapSize ){ |
| 40756 | if( offset+amt <= pFile->mmapSize ){ |
| 40757 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
| 40758 | return SQLITE_OK; |
| @@ -40716,11 +40900,11 @@ | |
| 40900 | } |
| 40901 | } |
| 40902 | #endif |
| 40903 | |
| 40904 | #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 |
| 40905 | /* Deal with as much of this write request as possible by transferring |
| 40906 | ** data from the memory mapping using memcpy(). */ |
| 40907 | if( offset<pFile->mmapSize ){ |
| 40908 | if( offset+amt <= pFile->mmapSize ){ |
| 40909 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); |
| 40910 | return SQLITE_OK; |
| @@ -40838,11 +41022,11 @@ | |
| 41022 | #endif |
| 41023 | |
| 41024 | /* If we compiled with the SQLITE_NO_SYNC flag, then syncing is a |
| 41025 | ** no-op. But go ahead and call fstat() to validate the file |
| 41026 | ** descriptor as we need a method to provoke a failure during |
| 41027 | ** coverage testing. |
| 41028 | */ |
| 41029 | #ifdef SQLITE_NO_SYNC |
| 41030 | { |
| 41031 | struct stat buf; |
| 41032 | rc = osFstat(fd, &buf); |
| @@ -46478,11 +46662,11 @@ | |
| 46662 | |
| 46663 | }; /* End of the overrideable system calls */ |
| 46664 | |
| 46665 | /* |
| 46666 | ** This is the xSetSystemCall() method of sqlite3_vfs for all of the |
| 46667 | ** "win32" VFSes. Return SQLITE_OK upon successfully updating the |
| 46668 | ** system call pointer, or SQLITE_NOTFOUND if there is no configurable |
| 46669 | ** system call named zName. |
| 46670 | */ |
| 46671 | static int winSetSystemCall( |
| 46672 | sqlite3_vfs *pNotUsed, /* The VFS pointer. Not used */ |
| @@ -48058,11 +48242,11 @@ | |
| 48242 | OSTRACE(("READ pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 48243 | "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
| 48244 | pFile->h, pBuf, amt, offset, pFile->locktype)); |
| 48245 | |
| 48246 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 48247 | /* Deal with as much of this read request as possible by transferring |
| 48248 | ** data from the memory mapping using memcpy(). */ |
| 48249 | if( offset<pFile->mmapSize ){ |
| 48250 | if( offset+amt <= pFile->mmapSize ){ |
| 48251 | memcpy(pBuf, &((u8 *)(pFile->pMapRegion))[offset], amt); |
| 48252 | OSTRACE(("READ-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| @@ -48136,11 +48320,11 @@ | |
| 48320 | OSTRACE(("WRITE pid=%lu, pFile=%p, file=%p, buffer=%p, amount=%d, " |
| 48321 | "offset=%lld, lock=%d\n", osGetCurrentProcessId(), pFile, |
| 48322 | pFile->h, pBuf, amt, offset, pFile->locktype)); |
| 48323 | |
| 48324 | #if defined(SQLITE_MMAP_READWRITE) && SQLITE_MAX_MMAP_SIZE>0 |
| 48325 | /* Deal with as much of this write request as possible by transferring |
| 48326 | ** data from the memory mapping using memcpy(). */ |
| 48327 | if( offset<pFile->mmapSize ){ |
| 48328 | if( offset+amt <= pFile->mmapSize ){ |
| 48329 | memcpy(&((u8 *)(pFile->pMapRegion))[offset], pBuf, amt); |
| 48330 | OSTRACE(("WRITE-MMAP pid=%lu, pFile=%p, file=%p, rc=SQLITE_OK\n", |
| @@ -48246,11 +48430,11 @@ | |
| 48430 | ** |
| 48431 | ** The only feasible work-around is to defer the truncation until after |
| 48432 | ** all references to memory-mapped content are closed. That is doable, |
| 48433 | ** but involves adding a few branches in the common write code path which |
| 48434 | ** could slow down normal operations slightly. Hence, we have decided for |
| 48435 | ** now to simply make transactions a no-op if there are pending reads. We |
| 48436 | ** can maybe revisit this decision in the future. |
| 48437 | */ |
| 48438 | return SQLITE_OK; |
| 48439 | } |
| 48440 | #endif |
| @@ -48305,11 +48489,11 @@ | |
| 48489 | } |
| 48490 | |
| 48491 | #ifdef SQLITE_TEST |
| 48492 | /* |
| 48493 | ** Count the number of fullsyncs and normal syncs. This is used to test |
| 48494 | ** that syncs and fullsyncs are occurring at the right times. |
| 48495 | */ |
| 48496 | SQLITE_API int sqlite3_sync_count = 0; |
| 48497 | SQLITE_API int sqlite3_fullsync_count = 0; |
| 48498 | #endif |
| 48499 | |
| @@ -52643,11 +52827,11 @@ | |
| 52827 | return SQLITE_OK; |
| 52828 | } |
| 52829 | h = BITVEC_HASH(i++); |
| 52830 | /* if there wasn't a hash collision, and this doesn't */ |
| 52831 | /* completely fill the hash, then just add it without */ |
| 52832 | /* worrying about sub-dividing and re-hashing. */ |
| 52833 | if( !p->u.aHash[h] ){ |
| 52834 | if (p->nSet<(BITVEC_NINT-1)) { |
| 52835 | goto bitvec_set_end; |
| 52836 | } else { |
| 52837 | goto bitvec_set_rehash; |
| @@ -53140,11 +53324,11 @@ | |
| 53324 | /* IMPLEMENTATION-OF: R-42059-47211 If the argument N is positive then the |
| 53325 | ** suggested cache size is set to N. */ |
| 53326 | return p->szCache; |
| 53327 | }else{ |
| 53328 | i64 n; |
| 53329 | /* IMPLEMENTATION-OF: R-59858-46238 If the argument N is negative, then the |
| 53330 | ** number of cache pages is adjusted to be a number of pages that would |
| 53331 | ** use approximately abs(N*1024) bytes of memory based on the current |
| 53332 | ** page size. */ |
| 53333 | n = ((-1024*(i64)p->szCache)/(p->szPage+p->szExtra)); |
| 53334 | if( n>1000000000 ) n = 1000000000; |
| @@ -53628,11 +53812,11 @@ | |
| 53812 | } |
| 53813 | return result.pDirty; |
| 53814 | } |
| 53815 | |
| 53816 | /* |
| 53817 | ** Sort the list of pages in ascending order by pgno. Pages are |
| 53818 | ** connected by pDirty pointers. The pDirtyPrev pointers are |
| 53819 | ** corrupted by this sort. |
| 53820 | ** |
| 53821 | ** Since there cannot be more than 2^31 distinct pages in a database, |
| 53822 | ** there cannot be more than 31 buckets required by the merge sorter. |
| @@ -53868,11 +54052,11 @@ | |
| 54052 | ** sqlite3_config(SQLITE_CONFIG_PAGECACHE, (void*)0, 0, N). |
| 54053 | ** |
| 54054 | ** If N is positive, then N pages worth of memory are allocated using a single |
| 54055 | ** sqlite3Malloc() call and that memory is used for the first N pages allocated. |
| 54056 | ** Or if N is negative, then -1024*N bytes of memory are allocated and used |
| 54057 | ** for as many pages as can be accommodated. |
| 54058 | ** |
| 54059 | ** Only one of (2) or (3) can be used. Once the memory available to (2) or |
| 54060 | ** (3) is exhausted, subsequent allocations fail over to the general-purpose |
| 54061 | ** memory allocator (1). |
| 54062 | ** |
| @@ -53902,11 +54086,11 @@ | |
| 54086 | ** but causes a 2-byte gap in the structure for most architectures (since |
| 54087 | ** pointers must be either 4 or 8-byte aligned). As this structure is located |
| 54088 | ** in memory directly after the associated page data, if the database is |
| 54089 | ** corrupt, code at the b-tree layer may overread the page buffer and |
| 54090 | ** read part of this structure before the corruption is detected. This |
| 54091 | ** can cause a valgrind error if the uninitialized gap is accessed. Using u16 |
| 54092 | ** ensures there is no such gap, and therefore no bytes of uninitialized |
| 54093 | ** memory in the structure. |
| 54094 | ** |
| 54095 | ** The pLruNext and pLruPrev pointers form a double-linked circular list |
| 54096 | ** of all pages that are unpinned. The PGroup.lru element (which should be |
| @@ -55122,11 +55306,11 @@ | |
| 55306 | ** until DESTROY. |
| 55307 | ** |
| 55308 | ** The TEST primitive includes a "batch" number. The TEST primitive |
| 55309 | ** will only see elements that were inserted before the last change |
| 55310 | ** in the batch number. In other words, if an INSERT occurs between |
| 55311 | ** two TESTs where the TESTs have the same batch number, then the |
| 55312 | ** value added by the INSERT will not be visible to the second TEST. |
| 55313 | ** The initial batch number is zero, so if the very first TEST contains |
| 55314 | ** a non-zero batch number, it will see all prior INSERTs. |
| 55315 | ** |
| 55316 | ** No INSERTs may occurs after a SMALLEST. An assertion will fail if |
| @@ -56045,11 +56229,11 @@ | |
| 56229 | ** Once it has entered the ERROR state, any attempt to use the pager |
| 56230 | ** to read or write data returns an error. Eventually, once all |
| 56231 | ** outstanding transactions have been abandoned, the pager is able to |
| 56232 | ** transition back to OPEN state, discarding the contents of the |
| 56233 | ** page-cache and any other in-memory state at the same time. Everything |
| 56234 | ** is reloaded from disk (and, if necessary, hot-journal rollback performed) |
| 56235 | ** when a read-transaction is next opened on the pager (transitioning |
| 56236 | ** the pager into READER state). At that point the system has recovered |
| 56237 | ** from the error. |
| 56238 | ** |
| 56239 | ** Specifically, the pager jumps into the ERROR state if: |
| @@ -57418,11 +57602,11 @@ | |
| 57602 | ** + N bytes: super-journal filename in utf-8. |
| 57603 | ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). |
| 57604 | ** + 4 bytes: super-journal name checksum. |
| 57605 | ** + 8 bytes: aJournalMagic[]. |
| 57606 | ** |
| 57607 | ** The super-journal page checksum is the sum of the bytes in the super-journal |
| 57608 | ** name, where each byte is interpreted as a signed 8-bit integer. |
| 57609 | ** |
| 57610 | ** If zSuper is a NULL pointer (occurs for a single database transaction), |
| 57611 | ** this call is a no-op. |
| 57612 | */ |
| @@ -57471,11 +57655,11 @@ | |
| 57655 | ){ |
| 57656 | return rc; |
| 57657 | } |
| 57658 | pPager->journalOff += (nSuper+20); |
| 57659 | |
| 57660 | /* If the pager is in persistent-journal mode, then the physical |
| 57661 | ** journal-file may extend past the end of the super-journal name |
| 57662 | ** and 8 bytes of magic data just written to the file. This is |
| 57663 | ** dangerous because the code to rollback a hot-journal file |
| 57664 | ** will not be able to find the super-journal name to determine |
| 57665 | ** whether or not the journal is hot. |
| @@ -57641,11 +57825,11 @@ | |
| 57825 | pPager->setSuper = 0; |
| 57826 | } |
| 57827 | |
| 57828 | /* |
| 57829 | ** This function is called whenever an IOERR or FULL error that requires |
| 57830 | ** the pager to transition into the ERROR state may have occurred. |
| 57831 | ** The first argument is a pointer to the pager structure, the second |
| 57832 | ** the error-code about to be returned by a pager API function. The |
| 57833 | ** value returned is a copy of the second argument to this function. |
| 57834 | ** |
| 57835 | ** If the second argument is SQLITE_FULL, SQLITE_IOERR or one of the |
| @@ -57916,11 +58100,11 @@ | |
| 58100 | pager_unlock(pPager); |
| 58101 | } |
| 58102 | |
| 58103 | /* |
| 58104 | ** Parameter aData must point to a buffer of pPager->pageSize bytes |
| 58105 | ** of data. Compute and return a checksum based on the contents of the |
| 58106 | ** page of data and the current value of pPager->cksumInit. |
| 58107 | ** |
| 58108 | ** This is not a real checksum. It is really just the sum of the |
| 58109 | ** random initial value (pPager->cksumInit) and every 200th byte |
| 58110 | ** of the page data, starting with byte offset (pPager->pageSize%200). |
| @@ -58882,11 +59066,11 @@ | |
| 59066 | PgHdr *p; /* For looping over pages */ |
| 59067 | |
| 59068 | assert( pPager->pWal ); |
| 59069 | assert( pList ); |
| 59070 | #ifdef SQLITE_DEBUG |
| 59071 | /* Verify that the page list is in ascending order */ |
| 59072 | for(p=pList; p && p->pDirty; p=p->pDirty){ |
| 59073 | assert( p->pgno < p->pDirty->pgno ); |
| 59074 | } |
| 59075 | #endif |
| 59076 | |
| @@ -59013,11 +59197,11 @@ | |
| 59197 | } |
| 59198 | |
| 59199 | #ifndef SQLITE_OMIT_WAL |
| 59200 | /* |
| 59201 | ** Check if the *-wal file that corresponds to the database opened by pPager |
| 59202 | ** exists if the database is not empty, or verify that the *-wal file does |
| 59203 | ** not exist (by deleting it) if the database file is empty. |
| 59204 | ** |
| 59205 | ** If the database is not empty and the *-wal file exists, open the pager |
| 59206 | ** in WAL mode. If the database is empty or if no *-wal file exists and |
| 59207 | ** if no error occurs, make sure Pager.journalMode is not set to |
| @@ -60765,11 +60949,11 @@ | |
| 60949 | return SQLITE_OK; |
| 60950 | } |
| 60951 | |
| 60952 | /* |
| 60953 | ** Return the sqlite3_file for the main database given the name |
| 60954 | ** of the corresponding WAL or Journal name as passed into |
| 60955 | ** xOpen. |
| 60956 | */ |
| 60957 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char *zName){ |
| 60958 | Pager *pPager; |
| 60959 | while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){ |
| @@ -63050,11 +63234,11 @@ | |
| 63234 | |
| 63235 | /* Change the journal mode. */ |
| 63236 | assert( pPager->eState!=PAGER_ERROR ); |
| 63237 | pPager->journalMode = (u8)eMode; |
| 63238 | |
| 63239 | /* When transitioning from TRUNCATE or PERSIST to any other journal |
| 63240 | ** mode except WAL, unless the pager is in locking_mode=exclusive mode, |
| 63241 | ** delete the journal file. |
| 63242 | */ |
| 63243 | assert( (PAGER_JOURNALMODE_TRUNCATE & 5)==1 ); |
| 63244 | assert( (PAGER_JOURNALMODE_PERSIST & 5)==1 ); |
| @@ -63768,11 +63952,11 @@ | |
| 63952 | ** of available reader locks and should be at least 3. The default |
| 63953 | ** is SQLITE_SHM_NLOCK==8 and WAL_NREADER==5. |
| 63954 | ** |
| 63955 | ** Technically, the various VFSes are free to implement these locks however |
| 63956 | ** they see fit. However, compatibility is encouraged so that VFSes can |
| 63957 | ** interoperate. The standard implementation used on both unix and windows |
| 63958 | ** is for the index number to indicate a byte offset into the |
| 63959 | ** WalCkptInfo.aLock[] array in the wal-index header. In other words, all |
| 63960 | ** locks are on the shm file. The WALINDEX_LOCK_OFFSET constant (which |
| 63961 | ** should be 120) is the location in the shm file for the first locking |
| 63962 | ** byte. |
| @@ -63844,11 +64028,11 @@ | |
| 64028 | ** There is one entry in aReadMark[] for each reader lock. If a reader |
| 64029 | ** holds read-lock K, then the value in aReadMark[K] is no greater than |
| 64030 | ** the mxFrame for that reader. The value READMARK_NOT_USED (0xffffffff) |
| 64031 | ** for any aReadMark[] means that entry is unused. aReadMark[0] is |
| 64032 | ** a special case; its value is never used and it exists as a place-holder |
| 64033 | ** to avoid having to offset aReadMark[] indexes by one. Readers holding |
| 64034 | ** WAL_READ_LOCK(0) always ignore the entire WAL and read all content |
| 64035 | ** directly from the database. |
| 64036 | ** |
| 64037 | ** The value of aReadMark[K] may only be changed by a thread that |
| 64038 | ** is holding an exclusive lock on WAL_READ_LOCK(K). Thus, the value of |
| @@ -64374,19 +64558,19 @@ | |
| 64558 | */ |
| 64559 | if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){ |
| 64560 | return 0; |
| 64561 | } |
| 64562 | |
| 64563 | /* A frame is only valid if the page number is greater than zero. |
| 64564 | */ |
| 64565 | pgno = sqlite3Get4byte(&aFrame[0]); |
| 64566 | if( pgno==0 ){ |
| 64567 | return 0; |
| 64568 | } |
| 64569 | |
| 64570 | /* A frame is only valid if a checksum of the WAL header, |
| 64571 | ** all prior frames, the first 16 bytes of this frame-header, |
| 64572 | ** and the frame-data matches the checksum in the last 8 |
| 64573 | ** bytes of this frame-header. |
| 64574 | */ |
| 64575 | nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN); |
| 64576 | walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum); |
| @@ -65076,11 +65260,11 @@ | |
| 65260 | } |
| 65261 | return rc; |
| 65262 | } |
| 65263 | |
| 65264 | /* |
| 65265 | ** Change the size to which the WAL file is truncated on each reset. |
| 65266 | */ |
| 65267 | SQLITE_PRIVATE void sqlite3WalLimit(Wal *pWal, i64 iLimit){ |
| 65268 | if( pWal ) pWal->mxWalSize = iLimit; |
| 65269 | } |
| 65270 | |
| @@ -65775,11 +65959,11 @@ | |
| 65959 | sqlite3OsFileControlHint( |
| 65960 | pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist |
| 65961 | ); |
| 65962 | if( bPersist!=1 ){ |
| 65963 | /* Try to delete the WAL file if the checkpoint completed and |
| 65964 | ** fsynced (rc==SQLITE_OK) and if we are not in persistent-wal |
| 65965 | ** mode (!bPersist) */ |
| 65966 | isDelete = 1; |
| 65967 | }else if( pWal->mxWalSize>=0 ){ |
| 65968 | /* Try to truncate the WAL file to zero bytes if the checkpoint |
| 65969 | ** completed and fsynced (rc==SQLITE_OK) and we are in persistent |
| @@ -65842,11 +66026,11 @@ | |
| 66026 | ** Memory barriers are used to prevent the compiler or the hardware from |
| 66027 | ** reordering the reads and writes. TSAN and similar tools can sometimes |
| 66028 | ** give false-positive warnings about these accesses because the tools do not |
| 66029 | ** account for the double-read and the memory barrier. The use of mutexes |
| 66030 | ** here would be problematic as the memory being accessed is potentially |
| 66031 | ** shared among multiple processes and not all mutex implementations work |
| 66032 | ** reliably in that environment. |
| 66033 | */ |
| 66034 | aHdr = walIndexHdr(pWal); |
| 66035 | memcpy(&h1, (void *)&aHdr[0], sizeof(h1)); /* Possible TSAN false-positive */ |
| 66036 | walShmBarrier(pWal); |
| @@ -67947,11 +68131,11 @@ | |
| 68131 | /* |
| 68132 | ** An instance of this object stores information about each a single database |
| 68133 | ** page that has been loaded into memory. The information in this object |
| 68134 | ** is derived from the raw on-disk page content. |
| 68135 | ** |
| 68136 | ** As each database page is loaded into memory, the pager allocates an |
| 68137 | ** instance of this object and zeros the first 8 bytes. (This is the |
| 68138 | ** "extra" information associated with each page of the pager.) |
| 68139 | ** |
| 68140 | ** Access to all fields of this structure is controlled by the mutex |
| 68141 | ** stored in MemPage.pBt->mutex. |
| @@ -68403,11 +68587,11 @@ | |
| 68587 | #define get4byte sqlite3Get4byte |
| 68588 | #define put4byte sqlite3Put4byte |
| 68589 | |
| 68590 | /* |
| 68591 | ** get2byteAligned(), unlike get2byte(), requires that its argument point to a |
| 68592 | ** two-byte aligned address. get2byteAligned() is only used for accessing the |
| 68593 | ** cell addresses in a btree header. |
| 68594 | */ |
| 68595 | #if SQLITE_BYTEORDER==4321 |
| 68596 | # define get2byteAligned(x) (*(u16*)(x)) |
| 68597 | #elif SQLITE_BYTEORDER==1234 && GCC_VERSION>=4008000 |
| @@ -68580,11 +68764,11 @@ | |
| 68764 | ** against all schemas and we do not want those schemas being |
| 68765 | ** reset out from under us. |
| 68766 | ** |
| 68767 | ** There is a corresponding leave-all procedures. |
| 68768 | ** |
| 68769 | ** Enter the mutexes in ascending order by BtShared pointer address |
| 68770 | ** to avoid the possibility of deadlock when two threads with |
| 68771 | ** two or more btrees in common both try to lock all their btrees |
| 68772 | ** at the same instant. |
| 68773 | */ |
| 68774 | static void SQLITE_NOINLINE btreeEnterAll(sqlite3 *db){ |
| @@ -68712,10 +68896,11 @@ | |
| 68896 | |
| 68897 | #endif /* ifndef SQLITE_OMIT_SHARED_CACHE */ |
| 68898 | |
| 68899 | /************** End of btmutex.c *********************************************/ |
| 68900 | /************** Begin file btree.c *******************************************/ |
| 68901 | |
| 68902 | /* |
| 68903 | ** 2004 April 6 |
| 68904 | ** |
| 68905 | ** The author disclaims copyright to this source code. In place of |
| 68906 | ** a legal notice, here is a blessing: |
| @@ -70348,11 +70533,11 @@ | |
| 70533 | cbrk = usableSize; |
| 70534 | iCellLast = usableSize - 4; |
| 70535 | iCellStart = get2byte(&data[hdr+5]); |
| 70536 | if( nCell>0 ){ |
| 70537 | temp = sqlite3PagerTempSpace(pPage->pBt->pPager); |
| 70538 | memcpy(temp, data, usableSize); |
| 70539 | src = temp; |
| 70540 | for(i=0; i<nCell; i++){ |
| 70541 | u8 *pAddr; /* The i-th cell pointer */ |
| 70542 | pAddr = &data[cellOffset + i*2]; |
| 70543 | pc = get2byte(pAddr); |
| @@ -70572,11 +70757,11 @@ | |
| 70757 | ** |
| 70758 | ** Adjacent freeblocks are coalesced. |
| 70759 | ** |
| 70760 | ** Even though the freeblock list was checked by btreeComputeFreeSpace(), |
| 70761 | ** that routine will not detect overlap between cells or freeblocks. Nor |
| 70762 | ** does it detect cells or freeblocks that encroach into the reserved bytes |
| 70763 | ** at the end of the page. So do additional corruption checks inside this |
| 70764 | ** routine and return SQLITE_CORRUPT if any problems are found. |
| 70765 | */ |
| 70766 | static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){ |
| 70767 | u16 iPtr; /* Address of ptr to next freeblock */ |
| @@ -71175,11 +71360,11 @@ | |
| 71360 | /* pPage might not be a btree page; it might be an overflow page |
| 71361 | ** or ptrmap page or a free page. In those cases, the following |
| 71362 | ** call to btreeInitPage() will likely return SQLITE_CORRUPT. |
| 71363 | ** But no harm is done by this. And it is very important that |
| 71364 | ** btreeInitPage() be called on every btree page so we make |
| 71365 | ** the call for every page that comes in for re-initializing. */ |
| 71366 | btreeInitPage(pPage); |
| 71367 | } |
| 71368 | } |
| 71369 | } |
| 71370 | |
| @@ -71570,11 +71755,11 @@ | |
| 71755 | ** a cell is less than 4 bytes in size, it is rounded up to 4 bytes |
| 71756 | ** by the various routines that manipulate binary cells. Which |
| 71757 | ** can mean that fillInCell() only initializes the first 2 or 3 |
| 71758 | ** bytes of pTmpSpace, but that the first 4 bytes are copied from |
| 71759 | ** it into a database page. This is not actually a problem, but it |
| 71760 | ** does cause a valgrind error when the 1 or 2 bytes of uninitialized |
| 71761 | ** data is passed to system call write(). So to avoid this error, |
| 71762 | ** zero the first 4 bytes of temp space here. |
| 71763 | ** |
| 71764 | ** Also: Provide four bytes of initialized space before the |
| 71765 | ** beginning of pTmpSpace as an area available to prepend the |
| @@ -71805,11 +71990,11 @@ | |
| 71990 | return n; |
| 71991 | } |
| 71992 | |
| 71993 | /* |
| 71994 | ** Return the number of bytes of space at the end of every page that |
| 71995 | ** are intentionally left unused. This is the "reserved" space that is |
| 71996 | ** sometimes used by extensions. |
| 71997 | ** |
| 71998 | ** The value returned is the larger of the current reserve size and |
| 71999 | ** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES. |
| 72000 | ** The amount of reserve can only grow - never shrink. |
| @@ -72052,11 +72237,10 @@ | |
| 72237 | || pageSize>SQLITE_MAX_PAGE_SIZE |
| 72238 | || pageSize<=256 |
| 72239 | ){ |
| 72240 | goto page1_init_failed; |
| 72241 | } |
| 72242 | assert( (pageSize & 7)==0 ); |
| 72243 | /* EVIDENCE-OF: R-59310-51205 The "reserved space" size in the 1-byte |
| 72244 | ** integer at offset 20 is the number of bytes of space at the end of |
| 72245 | ** each page to reserve for extensions. |
| 72246 | ** |
| @@ -72072,10 +72256,11 @@ | |
| 72256 | ** again with the correct page-size. |
| 72257 | */ |
| 72258 | releasePageOne(pPage1); |
| 72259 | pBt->usableSize = usableSize; |
| 72260 | pBt->pageSize = pageSize; |
| 72261 | pBt->btsFlags |= BTS_PAGESIZE_FIXED; |
| 72262 | freeTempSpace(pBt); |
| 72263 | rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize, |
| 72264 | pageSize-usableSize); |
| 72265 | return rc; |
| 72266 | } |
| @@ -72091,10 +72276,11 @@ | |
| 72276 | ** be less than 480. In other words, if the page size is 512, then the |
| 72277 | ** reserved space size cannot exceed 32. */ |
| 72278 | if( usableSize<480 ){ |
| 72279 | goto page1_init_failed; |
| 72280 | } |
| 72281 | pBt->btsFlags |= BTS_PAGESIZE_FIXED; |
| 72282 | pBt->pageSize = pageSize; |
| 72283 | pBt->usableSize = usableSize; |
| 72284 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 72285 | pBt->autoVacuum = (get4byte(&page1[36 + 4*4])?1:0); |
| 72286 | pBt->incrVacuum = (get4byte(&page1[36 + 7*4])?1:0); |
| @@ -72269,11 +72455,15 @@ | |
| 72455 | ** One or the other of the two processes must give way or there can be |
| 72456 | ** no progress. By returning SQLITE_BUSY and not invoking the busy callback |
| 72457 | ** when A already has a read lock, we encourage A to give up and let B |
| 72458 | ** proceed. |
| 72459 | */ |
| 72460 | static SQLITE_NOINLINE int btreeBeginTrans( |
| 72461 | Btree *p, /* The btree in which to start the transaction */ |
| 72462 | int wrflag, /* True to start a write transaction */ |
| 72463 | int *pSchemaVersion /* Put schema version number here, if not NULL */ |
| 72464 | ){ |
| 72465 | BtShared *pBt = p->pBt; |
| 72466 | Pager *pPager = pBt->pPager; |
| 72467 | int rc = SQLITE_OK; |
| 72468 | |
| 72469 | sqlite3BtreeEnter(p); |
| @@ -72440,10 +72630,32 @@ | |
| 72630 | } |
| 72631 | |
| 72632 | btreeIntegrity(p); |
| 72633 | sqlite3BtreeLeave(p); |
| 72634 | return rc; |
| 72635 | } |
| 72636 | SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree *p, int wrflag, int *pSchemaVersion){ |
| 72637 | BtShared *pBt; |
| 72638 | if( p->sharable |
| 72639 | || p->inTrans==TRANS_NONE |
| 72640 | || (p->inTrans==TRANS_READ && wrflag!=0) |
| 72641 | ){ |
| 72642 | return btreeBeginTrans(p,wrflag,pSchemaVersion); |
| 72643 | } |
| 72644 | pBt = p->pBt; |
| 72645 | if( pSchemaVersion ){ |
| 72646 | *pSchemaVersion = get4byte(&pBt->pPage1->aData[40]); |
| 72647 | } |
| 72648 | if( wrflag ){ |
| 72649 | /* This call makes sure that the pager has the correct number of |
| 72650 | ** open savepoints. If the second parameter is greater than 0 and |
| 72651 | ** the sub-journal is not already open, then it will be opened here. |
| 72652 | */ |
| 72653 | return sqlite3PagerOpenSavepoint(pBt->pPager, p->db->nSavepoint); |
| 72654 | }else{ |
| 72655 | return SQLITE_OK; |
| 72656 | } |
| 72657 | } |
| 72658 | |
| 72659 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 72660 | |
| 72661 | /* |
| @@ -73574,11 +73786,11 @@ | |
| 73786 | ** |
| 73787 | ** This is an optimization. Everything will still work if this |
| 73788 | ** routine always returns 2147483647 (which is the largest record |
| 73789 | ** that SQLite can handle) or more. But returning a smaller value might |
| 73790 | ** prevent large memory allocations when trying to interpret a |
| 73791 | ** corrupt database. |
| 73792 | ** |
| 73793 | ** The current implementation merely returns the size of the underlying |
| 73794 | ** database file. |
| 73795 | */ |
| 73796 | SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){ |
| @@ -74374,11 +74586,11 @@ | |
| 74586 | return SQLITE_OK; |
| 74587 | } |
| 74588 | /* If the requested key is one more than the previous key, then |
| 74589 | ** try to get there using sqlite3BtreeNext() rather than a full |
| 74590 | ** binary search. This is an optimization only. The correct answer |
| 74591 | ** is still obtained without this case, only a little more slowly. */ |
| 74592 | if( pCur->info.nKey+1==intKey ){ |
| 74593 | *pRes = 0; |
| 74594 | rc = sqlite3BtreeNext(pCur, 0); |
| 74595 | if( rc==SQLITE_OK ){ |
| 74596 | getCellInfo(pCur); |
| @@ -75557,11 +75769,11 @@ | |
| 75769 | return SQLITE_OK; |
| 75770 | } |
| 75771 | |
| 75772 | /* Call xParseCell to compute the size of a cell. If the cell contains |
| 75773 | ** overflow, then invoke cellClearOverflow to clear out that overflow. |
| 75774 | ** Store the result code (SQLITE_OK or some error code) in rc. |
| 75775 | ** |
| 75776 | ** Implemented as macro to force inlining for performance. |
| 75777 | */ |
| 75778 | #define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \ |
| 75779 | pPage->xParseCell(pPage, pCell, &sInfo); \ |
| @@ -76236,11 +76448,11 @@ | |
| 76448 | ** before returning. |
| 76449 | ** |
| 76450 | ** Finally, argument pBegin points to the byte immediately following the |
| 76451 | ** end of the space required by this page for the cell-pointer area (for |
| 76452 | ** all cells - not just those inserted by the current call). If the content |
| 76453 | ** area must be extended to before this point in order to accommodate all |
| 76454 | ** cells in apCell[], then the cells do not fit and non-zero is returned. |
| 76455 | */ |
| 76456 | static int pageInsertArray( |
| 76457 | MemPage *pPg, /* Page to add cells to */ |
| 76458 | u8 *pBegin, /* End of cell-pointer array */ |
| @@ -76551,11 +76763,11 @@ | |
| 76763 | |
| 76764 | /* If this is an auto-vacuum database, update the pointer map |
| 76765 | ** with entries for the new page, and any pointer from the |
| 76766 | ** cell on the page to an overflow page. If either of these |
| 76767 | ** operations fails, the return code is set, but the contents |
| 76768 | ** of the parent page are still manipulated by the code below. |
| 76769 | ** That is Ok, at this point the parent page is guaranteed to |
| 76770 | ** be marked as dirty. Returning an error code will cause a |
| 76771 | ** rollback, undoing any changes made to the parent page. |
| 76772 | */ |
| 76773 | if( ISAUTOVACUUM(pBt) ){ |
| @@ -77141,11 +77353,11 @@ | |
| 77353 | rc = SQLITE_CORRUPT_BKPT; |
| 77354 | goto balance_cleanup; |
| 77355 | } |
| 77356 | } |
| 77357 | |
| 77358 | /* Sanity check: For a non-corrupt database file one of the following |
| 77359 | ** must be true: |
| 77360 | ** (1) We found one or more cells (cntNew[0])>0), or |
| 77361 | ** (2) pPage is a virtual root page. A virtual root page is when |
| 77362 | ** the real root page is page 1 and we are the only child of |
| 77363 | ** that page. |
| @@ -77758,11 +77970,11 @@ | |
| 77970 | int iOffset, /* Offset of first byte to write */ |
| 77971 | int iAmt /* Number of bytes to be written */ |
| 77972 | ){ |
| 77973 | int nData = pX->nData - iOffset; |
| 77974 | if( nData<=0 ){ |
| 77975 | /* Overwriting with zeros */ |
| 77976 | int i; |
| 77977 | for(i=0; i<iAmt && pDest[i]==0; i++){} |
| 77978 | if( i<iAmt ){ |
| 77979 | int rc = sqlite3PagerWrite(pPage->pDbPage); |
| 77980 | if( rc ) return rc; |
| @@ -77794,11 +78006,11 @@ | |
| 78006 | ** Overwrite the cell that cursor pCur is pointing to with fresh content |
| 78007 | ** contained in pX. In this variant, pCur is pointing to an overflow |
| 78008 | ** cell. |
| 78009 | */ |
| 78010 | static SQLITE_NOINLINE int btreeOverwriteOverflowCell( |
| 78011 | BtCursor *pCur, /* Cursor pointing to cell to overwrite */ |
| 78012 | const BtreePayload *pX /* Content to write into the cell */ |
| 78013 | ){ |
| 78014 | int iOffset; /* Next byte of pX->pData to write */ |
| 78015 | int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */ |
| 78016 | int rc; /* Return code */ |
| @@ -78541,11 +78753,11 @@ | |
| 78753 | static int btreeCreateTable(Btree *p, Pgno *piTable, int createTabFlags){ |
| 78754 | BtShared *pBt = p->pBt; |
| 78755 | MemPage *pRoot; |
| 78756 | Pgno pgnoRoot; |
| 78757 | int rc; |
| 78758 | int ptfFlags; /* Page-type flags for the root page of new table */ |
| 78759 | |
| 78760 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 78761 | assert( pBt->inTransaction==TRANS_WRITE ); |
| 78762 | assert( (pBt->btsFlags & BTS_READ_ONLY)==0 ); |
| 78763 | |
| @@ -79376,11 +79588,11 @@ | |
| 79588 | pBt = pCheck->pBt; |
| 79589 | usableSize = pBt->usableSize; |
| 79590 | if( iPage==0 ) return 0; |
| 79591 | if( checkRef(pCheck, iPage) ) return 0; |
| 79592 | pCheck->zPfx = "Tree %u page %u: "; |
| 79593 | pCheck->v1 = iPage; |
| 79594 | if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){ |
| 79595 | checkAppendMsg(pCheck, |
| 79596 | "unable to get the page. error code=%d", rc); |
| 79597 | goto end_of_check; |
| 79598 | } |
| @@ -79713,10 +79925,11 @@ | |
| 79925 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 79926 | if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){ |
| 79927 | checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0); |
| 79928 | } |
| 79929 | #endif |
| 79930 | sCheck.v0 = aRoot[i]; |
| 79931 | checkTreePage(&sCheck, aRoot[i], ¬Used, LARGEST_INT64); |
| 79932 | } |
| 79933 | pBt->db->flags = savedDbFlags; |
| 79934 | |
| 79935 | /* Make sure every page in the file is referenced |
| @@ -82256,10 +82469,11 @@ | |
| 82469 | if( pRec==0 ) return 0; |
| 82470 | p->ppRec[0] = pRec; |
| 82471 | } |
| 82472 | |
| 82473 | pRec->nField = p->iVal+1; |
| 82474 | sqlite3VdbeMemSetNull(&pRec->aMem[p->iVal]); |
| 82475 | return &pRec->aMem[p->iVal]; |
| 82476 | } |
| 82477 | #else |
| 82478 | UNUSED_PARAMETER(p); |
| 82479 | #endif /* defined(SQLITE_ENABLE_STAT4) */ |
| @@ -83652,11 +83866,11 @@ | |
| 83866 | assert( pParse->db->mallocFailed==0 ); /* tag-20230419-1 */ |
| 83867 | p->readOnly = 1; |
| 83868 | p->bIsReader = 0; |
| 83869 | pOp = &p->aOp[p->nOp-1]; |
| 83870 | assert( p->aOp[0].opcode==OP_Init ); |
| 83871 | while( 1 /* Loop terminates when it reaches the OP_Init opcode */ ){ |
| 83872 | /* Only JUMP opcodes and the short list of special opcodes in the switch |
| 83873 | ** below need to be considered. The mkopcodeh.tcl generator script groups |
| 83874 | ** all these opcodes together near the front of the opcode list. Skip |
| 83875 | ** any opcode that does not need processing by virtual of the fact that |
| 83876 | ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization. |
| @@ -84106,11 +84320,11 @@ | |
| 84320 | } |
| 84321 | |
| 84322 | |
| 84323 | /* |
| 84324 | ** If the input FuncDef structure is ephemeral, then free it. If |
| 84325 | ** the FuncDef is not ephemeral, then do nothing. |
| 84326 | */ |
| 84327 | static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){ |
| 84328 | assert( db!=0 ); |
| 84329 | if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){ |
| 84330 | sqlite3DbNNFreeNN(db, pDef); |
| @@ -87057,10 +87271,19 @@ | |
| 87271 | ** sqlite3VdbeSerialTypeLen() in the common case. |
| 87272 | */ |
| 87273 | if( d1+(u64)serial_type1+2>(u64)nKey1 |
| 87274 | && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)>(u64)nKey1 |
| 87275 | ){ |
| 87276 | if( serial_type1>=1 |
| 87277 | && serial_type1<=7 |
| 87278 | && d1+(u64)sqlite3VdbeSerialTypeLen(serial_type1)<=(u64)nKey1+8 |
| 87279 | && CORRUPT_DB |
| 87280 | ){ |
| 87281 | return 1; /* corrupt record not detected by |
| 87282 | ** sqlite3VdbeRecordCompareWithSkip(). Return true |
| 87283 | ** to avoid firing the assert() */ |
| 87284 | } |
| 87285 | break; |
| 87286 | } |
| 87287 | |
| 87288 | /* Extract the values to be compared. |
| 87289 | */ |
| @@ -87500,11 +87723,11 @@ | |
| 87723 | serial_type = aKey1[idx1]; |
| 87724 | if( serial_type>=10 ){ |
| 87725 | /* Serial types 12 or greater are strings and blobs (greater than |
| 87726 | ** numbers). Types 10 and 11 are currently "reserved for future |
| 87727 | ** use", so it doesn't really matter what the results of comparing |
| 87728 | ** them to numeric values are. */ |
| 87729 | rc = serial_type==10 ? -1 : +1; |
| 87730 | }else if( serial_type==0 ){ |
| 87731 | rc = -1; |
| 87732 | }else{ |
| 87733 | sqlite3VdbeSerialGet(&aKey1[d1], serial_type, &mem1); |
| @@ -89129,11 +89352,11 @@ | |
| 89352 | |
| 89353 | /* |
| 89354 | ** The destructor function for a ValueList object. This needs to be |
| 89355 | ** a separate function, unknowable to the application, to ensure that |
| 89356 | ** calls to sqlite3_vtab_in_first()/sqlite3_vtab_in_next() that are not |
| 89357 | ** preceded by activation of IN processing via sqlite3_vtab_int() do not |
| 89358 | ** try to access a fake ValueList object inserted by a hostile extension. |
| 89359 | */ |
| 89360 | SQLITE_PRIVATE void sqlite3VdbeValueListFree(void *pToDelete){ |
| 89361 | sqlite3_free(pToDelete); |
| 89362 | } |
| @@ -89458,11 +89681,11 @@ | |
| 89681 | ** sqlite3_column_text() |
| 89682 | ** sqlite3_column_text16() |
| 89683 | ** sqlite3_column_real() |
| 89684 | ** sqlite3_column_bytes() |
| 89685 | ** sqlite3_column_bytes16() |
| 89686 | ** sqlite3_column_blob() |
| 89687 | */ |
| 89688 | static void columnMallocFailure(sqlite3_stmt *pStmt) |
| 89689 | { |
| 89690 | /* If malloc() failed during an encoding conversion within an |
| 89691 | ** sqlite3_column_XXX API, then set the return code of the statement to |
| @@ -89693,11 +89916,11 @@ | |
| 89916 | ** Routines used to attach values to wildcards in a compiled SQL statement. |
| 89917 | */ |
| 89918 | /* |
| 89919 | ** Unbind the value bound to variable i in virtual machine p. This is the |
| 89920 | ** the same as binding a NULL value to the column. If the "i" parameter is |
| 89921 | ** out of range, then SQLITE_RANGE is returned. Otherwise SQLITE_OK. |
| 89922 | ** |
| 89923 | ** A successful evaluation of this routine acquires the mutex on p. |
| 89924 | ** the mutex is released if any kind of error occurs. |
| 89925 | ** |
| 89926 | ** The error code stored in database p->db is overwritten with the return |
| @@ -91669,12 +91892,12 @@ | |
| 91892 | ** to the current line should be indented for EXPLAIN output. |
| 91893 | */ |
| 91894 | case OP_Goto: { /* jump */ |
| 91895 | |
| 91896 | #ifdef SQLITE_DEBUG |
| 91897 | /* In debugging mode, when the p5 flags is set on an OP_Goto, that |
| 91898 | ** means we should really jump back to the preceding OP_ReleaseReg |
| 91899 | ** instruction. */ |
| 91900 | if( pOp->p5 ){ |
| 91901 | assert( pOp->p2 < (int)(pOp - aOp) ); |
| 91902 | assert( pOp->p2 > 1 ); |
| 91903 | pOp = &aOp[pOp->p2 - 2]; |
| @@ -91878,11 +92101,11 @@ | |
| 92101 | ** If P4 is not null then it is an error message string. |
| 92102 | ** |
| 92103 | ** P5 is a value between 0 and 4, inclusive, that modifies the P4 string. |
| 92104 | ** |
| 92105 | ** 0: (no change) |
| 92106 | ** 1: NOT NULL constraint failed: P4 |
| 92107 | ** 2: UNIQUE constraint failed: P4 |
| 92108 | ** 3: CHECK constraint failed: P4 |
| 92109 | ** 4: FOREIGN KEY constraint failed: P4 |
| 92110 | ** |
| 92111 | ** If P5 is not zero and P4 is NULL, then everything after the ":" is |
| @@ -95105,11 +95328,11 @@ | |
| 95328 | aMem[pOp->p3].n = 0; |
| 95329 | aMem[pOp->p3].z = ""; |
| 95330 | } |
| 95331 | pCx = p->apCsr[pOp->p1]; |
| 95332 | if( pCx && !pCx->noReuse && ALWAYS(pOp->p2<=pCx->nField) ){ |
| 95333 | /* If the ephemeral table is already open and has no duplicates from |
| 95334 | ** OP_OpenDup, then erase all existing content so that the table is |
| 95335 | ** empty again, rather than creating a new table. */ |
| 95336 | assert( pCx->isEphemeral ); |
| 95337 | pCx->seqCount = 0; |
| 95338 | pCx->cacheStatus = CACHE_STALE; |
| @@ -95596,19 +95819,19 @@ | |
| 95819 | ** The This.P5 parameter is a flag that indicates what to do if the |
| 95820 | ** cursor ends up pointing at a valid row that is past the target |
| 95821 | ** row. If This.P5 is false (0) then a jump is made to SeekGE.P2. If |
| 95822 | ** This.P5 is true (non-zero) then a jump is made to This.P2. The P5==0 |
| 95823 | ** case occurs when there are no inequality constraints to the right of |
| 95824 | ** the IN constraint. The jump to SeekGE.P2 ends the loop. The P5!=0 case |
| 95825 | ** occurs when there are inequality constraints to the right of the IN |
| 95826 | ** operator. In that case, the This.P2 will point either directly to or |
| 95827 | ** to setup code prior to the OP_IdxGT or OP_IdxGE opcode that checks for |
| 95828 | ** loop terminate. |
| 95829 | ** |
| 95830 | ** Possible outcomes from this opcode:<ol> |
| 95831 | ** |
| 95832 | ** <li> If the cursor is initially not pointed to any valid row, then |
| 95833 | ** fall through into the subsequent OP_SeekGE opcode. |
| 95834 | ** |
| 95835 | ** <li> If the cursor is left pointing to a row that is before the target |
| 95836 | ** row, even after making as many as This.P1 calls to |
| 95837 | ** sqlite3BtreeNext(), then also fall through into OP_SeekGE. |
| @@ -98277,11 +98500,11 @@ | |
| 98500 | #endif |
| 98501 | |
| 98502 | /* If this function is inside of a trigger, the register array in aMem[] |
| 98503 | ** might change from one evaluation to the next. The next block of code |
| 98504 | ** checks to see if the register array has changed, and if so it |
| 98505 | ** reinitializes the relevant parts of the sqlite3_context object */ |
| 98506 | if( pCtx->pMem != pMem ){ |
| 98507 | pCtx->pMem = pMem; |
| 98508 | for(i=pCtx->argc-1; i>=0; i--) pCtx->argv[i] = &aMem[pOp->p2+i]; |
| 98509 | } |
| 98510 | |
| @@ -99155,11 +99378,11 @@ | |
| 99378 | ** invocation of this opcode. |
| 99379 | ** |
| 99380 | ** This opcode works exactly like OP_Function. The only difference is in |
| 99381 | ** its name. This opcode is used in places where the function must be |
| 99382 | ** purely non-deterministic. Some built-in date/time functions can be |
| 99383 | ** either deterministic of non-deterministic, depending on their arguments. |
| 99384 | ** When those function are used in a non-deterministic way, they will check |
| 99385 | ** to see if they were called using OP_PureFunc instead of OP_Function, and |
| 99386 | ** if they were, they throw an error. |
| 99387 | ** |
| 99388 | ** See also: AggStep, AggFinal, Function |
| @@ -99173,11 +99396,11 @@ | |
| 99396 | pCtx = pOp->p4.pCtx; |
| 99397 | |
| 99398 | /* If this function is inside of a trigger, the register array in aMem[] |
| 99399 | ** might change from one evaluation to the next. The next block of code |
| 99400 | ** checks to see if the register array has changed, and if so it |
| 99401 | ** reinitializes the relevant parts of the sqlite3_context object */ |
| 99402 | pOut = &aMem[pOp->p3]; |
| 99403 | if( pCtx->pOut != pOut ){ |
| 99404 | pCtx->pVdbe = p; |
| 99405 | pCtx->pOut = pOut; |
| 99406 | pCtx->enc = encoding; |
| @@ -99249,11 +99472,11 @@ | |
| 99472 | registerTrace(ii, &aMem[ii]); |
| 99473 | } |
| 99474 | printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); |
| 99475 | } |
| 99476 | #endif |
| 99477 | h %= (pIn1->n*8); |
| 99478 | pIn1->z[h/8] |= 1<<(h&7); |
| 99479 | break; |
| 99480 | } |
| 99481 | |
| 99482 | /* Opcode: Filter P1 P2 P3 P4 * |
| @@ -99285,11 +99508,11 @@ | |
| 99508 | registerTrace(ii, &aMem[ii]); |
| 99509 | } |
| 99510 | printf("hash: %llu modulo %d -> %u\n", h, pIn1->n, (int)(h%pIn1->n)); |
| 99511 | } |
| 99512 | #endif |
| 99513 | h %= (pIn1->n*8); |
| 99514 | if( (pIn1->z[h/8] & (1<<(h&7)))==0 ){ |
| 99515 | VdbeBranchTaken(1, 2); |
| 99516 | p->aCounter[SQLITE_STMTSTATUS_FILTER_HIT]++; |
| 99517 | goto jump_to_p2; |
| 99518 | }else{ |
| @@ -99537,11 +99760,11 @@ | |
| 99760 | if( opProperty & OPFLG_OUT3 ){ |
| 99761 | registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]); |
| 99762 | } |
| 99763 | if( opProperty==0xff ){ |
| 99764 | /* Never happens. This code exists to avoid a harmless linkage |
| 99765 | ** warning about sqlite3VdbeRegisterDump() being defined but not |
| 99766 | ** used. */ |
| 99767 | sqlite3VdbeRegisterDump(p); |
| 99768 | } |
| 99769 | } |
| 99770 | #endif /* SQLITE_DEBUG */ |
| @@ -100255,11 +100478,11 @@ | |
| 100478 | ** merging two or more level-0 PMAs together creates a level-1 PMA. |
| 100479 | ** |
| 100480 | ** The threshold for the amount of main memory to use before flushing |
| 100481 | ** records to a PMA is roughly the same as the limit configured for the |
| 100482 | ** page-cache of the main database. Specifically, the threshold is set to |
| 100483 | ** the value returned by "PRAGMA main.page_size" multiplied by |
| 100484 | ** that returned by "PRAGMA main.cache_size", in bytes. |
| 100485 | ** |
| 100486 | ** If the sorter is running in single-threaded mode, then all PMAs generated |
| 100487 | ** are appended to a single temporary file. Or, if the sorter is running in |
| 100488 | ** multi-threaded mode then up to (N+1) temporary files may be opened, where |
| @@ -100278,11 +100501,11 @@ | |
| 100501 | ** final PMA. So at this point the data is stored in some number of sorted |
| 100502 | ** PMAs within temporary files on disk. |
| 100503 | ** |
| 100504 | ** If there are fewer than SORTER_MAX_MERGE_COUNT PMAs in total and the |
| 100505 | ** sorter is running in single-threaded mode, then these PMAs are merged |
| 100506 | ** incrementally as keys are retrieved from the sorter by the VDBE. The |
| 100507 | ** MergeEngine object, described in further detail below, performs this |
| 100508 | ** merge. |
| 100509 | ** |
| 100510 | ** Or, if running in multi-threaded mode, then a background thread is |
| 100511 | ** launched to merge the existing PMAs. Once the background thread has |
| @@ -100441,11 +100664,11 @@ | |
| 100664 | ** single-threaded operation, there is exactly one instance of this object |
| 100665 | ** and for multi-threaded operation there are two or more instances. |
| 100666 | ** |
| 100667 | ** Essentially, this structure contains all those fields of the VdbeSorter |
| 100668 | ** structure for which each thread requires a separate instance. For example, |
| 100669 | ** each thread requeries its own UnpackedRecord object to unpack records in |
| 100670 | ** as part of comparison operations. |
| 100671 | ** |
| 100672 | ** Before a background thread is launched, variable bDone is set to 0. Then, |
| 100673 | ** right before it exits, the thread itself sets bDone to 1. This is used for |
| 100674 | ** two purposes: |
| @@ -100513,11 +100736,11 @@ | |
| 100736 | /* |
| 100737 | ** An instance of the following object is used to read records out of a |
| 100738 | ** PMA, in sorted order. The next key to be read is cached in nKey/aKey. |
| 100739 | ** aKey might point into aMap or into aBuffer. If neither of those locations |
| 100740 | ** contain a contiguous representation of the key, then aAlloc is allocated |
| 100741 | ** and the key is copied into aAlloc and aKey is made to point to aAlloc. |
| 100742 | ** |
| 100743 | ** pFd==0 at EOF. |
| 100744 | */ |
| 100745 | struct PmaReader { |
| 100746 | i64 iReadOff; /* Current read offset */ |
| @@ -101884,11 +102107,11 @@ | |
| 102107 | ** records to disk. If the sorter is running in multi-threaded mode, |
| 102108 | ** round-robin between the first (pSorter->nTask-1) tasks. Except, if |
| 102109 | ** the background thread from a sub-tasks previous turn is still running, |
| 102110 | ** skip it. If the first (pSorter->nTask-1) sub-tasks are all still busy, |
| 102111 | ** fall back to using the final sub-task. The first (pSorter->nTask-1) |
| 102112 | ** sub-tasks are preferred as they use background threads - the final |
| 102113 | ** sub-task uses the main thread. */ |
| 102114 | for(i=0; i<nWorker; i++){ |
| 102115 | int iTest = (pSorter->iPrev + i + 1) % nWorker; |
| 102116 | pTask = &pSorter->aTask[iTest]; |
| 102117 | if( pTask->bDone ){ |
| @@ -102368,11 +102591,11 @@ | |
| 102591 | /* eMode is always INCRINIT_NORMAL in single-threaded mode */ |
| 102592 | assert( SQLITE_MAX_WORKER_THREADS>0 || eMode==INCRINIT_NORMAL ); |
| 102593 | |
| 102594 | rc = vdbeMergeEngineInit(pTask, pIncr->pMerger, eMode); |
| 102595 | |
| 102596 | /* Set up the required files for pIncr. A multi-threaded IncrMerge object |
| 102597 | ** requires two temp files to itself, whereas a single-threaded object |
| 102598 | ** only requires a region of pTask->file2. */ |
| 102599 | if( rc==SQLITE_OK ){ |
| 102600 | int mxSz = pIncr->mxSz; |
| 102601 | #if SQLITE_MAX_WORKER_THREADS>0 |
| @@ -104033,11 +104256,11 @@ | |
| 104256 | }while( p!=0 ); |
| 104257 | return WRC_Continue; |
| 104258 | } |
| 104259 | |
| 104260 | /* Increase the walkerDepth when entering a subquery, and |
| 104261 | ** decrease when leaving the subquery. |
| 104262 | */ |
| 104263 | SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker *pWalker, Select *pSelect){ |
| 104264 | UNUSED_PARAMETER(pSelect); |
| 104265 | pWalker->walkerDepth++; |
| 104266 | return WRC_Continue; |
| @@ -105767,11 +105990,11 @@ | |
| 105990 | if( sqlite3ResolveExprNames(pNC, pE) ){ |
| 105991 | return 1; |
| 105992 | } |
| 105993 | for(j=0; j<pSelect->pEList->nExpr; j++){ |
| 105994 | if( sqlite3ExprCompare(0, pE, pSelect->pEList->a[j].pExpr, -1)==0 ){ |
| 105995 | /* Since this expression is being changed into a reference |
| 105996 | ** to an identical expression in the result set, remove all Window |
| 105997 | ** objects belonging to the expression from the Select.pWin list. */ |
| 105998 | windowRemoveExprFromSelect(pSelect, pE); |
| 105999 | pItem->u.x.iOrderByCol = j+1; |
| 106000 | } |
| @@ -106154,11 +106377,11 @@ | |
| 106377 | return WRC_Continue; |
| 106378 | } |
| 106379 | |
| 106380 | /* |
| 106381 | ** Resolve all names in all expressions of a SELECT and in all |
| 106382 | ** descendants of the SELECT, including compounds off of p->pPrior, |
| 106383 | ** subqueries in expressions, and subqueries used as FROM clause |
| 106384 | ** terms. |
| 106385 | ** |
| 106386 | ** See sqlite3ResolveExprNames() for a description of the kinds of |
| 106387 | ** transformations that occur. |
| @@ -106304,10 +106527,11 @@ | |
| 106527 | } |
| 106528 | #endif |
| 106529 | if( op==TK_SELECT_COLUMN ){ |
| 106530 | assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) ); |
| 106531 | assert( pExpr->iColumn < pExpr->iTable ); |
| 106532 | assert( pExpr->iColumn >= 0 ); |
| 106533 | assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr ); |
| 106534 | return sqlite3ExprAffinity( |
| 106535 | pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr |
| 106536 | ); |
| 106537 | } |
| @@ -106540,11 +106764,11 @@ | |
| 106764 | } |
| 106765 | |
| 106766 | /* |
| 106767 | ** Return the collation sequence for the expression pExpr. If |
| 106768 | ** there is no defined collating sequence, return a pointer to the |
| 106769 | ** default collation sequence. |
| 106770 | ** |
| 106771 | ** See also: sqlite3ExprCollSeq() |
| 106772 | ** |
| 106773 | ** The sqlite3ExprCollSeq() routine works the same except that it |
| 106774 | ** returns NULL if there is no defined collation. |
| @@ -106670,11 +106894,11 @@ | |
| 106894 | } |
| 106895 | } |
| 106896 | return pColl; |
| 106897 | } |
| 106898 | |
| 106899 | /* Expression p is a comparison operator. Return a collation sequence |
| 106900 | ** appropriate for the comparison operator. |
| 106901 | ** |
| 106902 | ** This is normally just a wrapper around sqlite3BinaryCompareCollSeq(). |
| 106903 | ** However, if the OP_Commuted flag is set, then the order of the operands |
| 106904 | ** is reversed in the sqlite3BinaryCompareCollSeq() call so that the |
| @@ -107586,11 +107810,11 @@ | |
| 107810 | } |
| 107811 | |
| 107812 | /* |
| 107813 | ** Arrange to cause pExpr to be deleted when the pParse is deleted. |
| 107814 | ** This is similar to sqlite3ExprDelete() except that the delete is |
| 107815 | ** deferred until the pParse is deleted. |
| 107816 | ** |
| 107817 | ** The pExpr might be deleted immediately on an OOM error. |
| 107818 | ** |
| 107819 | ** The deferred delete is (currently) implemented by adding the |
| 107820 | ** pExpr to the pParse->pConstExpr list with a register number of 0. |
| @@ -108428,11 +108652,11 @@ | |
| 108652 | /* |
| 108653 | ** The argument must be a TK_TRUEFALSE Expr node. Return 1 if it is TRUE |
| 108654 | ** and 0 if it is FALSE. |
| 108655 | */ |
| 108656 | SQLITE_PRIVATE int sqlite3ExprTruthValue(const Expr *pExpr){ |
| 108657 | pExpr = sqlite3ExprSkipCollateAndLikely((Expr*)pExpr); |
| 108658 | assert( pExpr->op==TK_TRUEFALSE ); |
| 108659 | assert( !ExprHasProperty(pExpr, EP_IntValue) ); |
| 108660 | assert( sqlite3StrICmp(pExpr->u.zToken,"true")==0 |
| 108661 | || sqlite3StrICmp(pExpr->u.zToken,"false")==0 ); |
| 108662 | return pExpr->u.zToken[4]==0; |
| @@ -109021,11 +109245,11 @@ | |
| 109245 | ** |
| 109246 | ** IN_INDEX_ROWID - The cursor was opened on a database table. |
| 109247 | ** IN_INDEX_INDEX_ASC - The cursor was opened on an ascending index. |
| 109248 | ** IN_INDEX_INDEX_DESC - The cursor was opened on a descending index. |
| 109249 | ** IN_INDEX_EPH - The cursor was opened on a specially created and |
| 109250 | ** populated ephemeral table. |
| 109251 | ** IN_INDEX_NOOP - No cursor was allocated. The IN operator must be |
| 109252 | ** implemented as a sequence of comparisons. |
| 109253 | ** |
| 109254 | ** An existing b-tree might be used if the RHS expression pX is a simple |
| 109255 | ** subquery such as: |
| @@ -109034,11 +109258,11 @@ | |
| 109258 | ** |
| 109259 | ** If the RHS of the IN operator is a list or a more complex subquery, then |
| 109260 | ** an ephemeral table might need to be generated from the RHS and then |
| 109261 | ** pX->iTable made to point to the ephemeral table instead of an |
| 109262 | ** existing table. In this case, the creation and initialization of the |
| 109263 | ** ephemeral table might be put inside of a subroutine, the EP_Subrtn flag |
| 109264 | ** will be set on pX and the pX->y.sub fields will be set to show where |
| 109265 | ** the subroutine is coded. |
| 109266 | ** |
| 109267 | ** The inFlags parameter must contain, at a minimum, one of the bits |
| 109268 | ** IN_INDEX_MEMBERSHIP or IN_INDEX_LOOP but not both. If inFlags contains |
| @@ -109046,16 +109270,16 @@ | |
| 109270 | ** membership test. When the IN_INDEX_LOOP bit is set, the IN index will |
| 109271 | ** be used to loop over all values of the RHS of the IN operator. |
| 109272 | ** |
| 109273 | ** When IN_INDEX_LOOP is used (and the b-tree will be used to iterate |
| 109274 | ** through the set members) then the b-tree must not contain duplicates. |
| 109275 | ** An ephemeral table will be created unless the selected columns are guaranteed |
| 109276 | ** to be unique - either because it is an INTEGER PRIMARY KEY or due to |
| 109277 | ** a UNIQUE constraint or index. |
| 109278 | ** |
| 109279 | ** When IN_INDEX_MEMBERSHIP is used (and the b-tree will be used |
| 109280 | ** for fast set membership tests) then an ephemeral table must |
| 109281 | ** be used unless <columns> is a single INTEGER PRIMARY KEY column or an |
| 109282 | ** index can be found with the specified <columns> as its left-most. |
| 109283 | ** |
| 109284 | ** If the IN_INDEX_NOOP_OK and IN_INDEX_MEMBERSHIP are both set and |
| 109285 | ** if the RHS of the IN operator is a list (not a subquery) then this |
| @@ -109384,11 +109608,11 @@ | |
| 109608 | ** |
| 109609 | ** x IN (4,5,11) -- IN operator with list on right-hand side |
| 109610 | ** x IN (SELECT a FROM b) -- IN operator with subquery on the right |
| 109611 | ** |
| 109612 | ** The pExpr parameter is the IN operator. The cursor number for the |
| 109613 | ** constructed ephemeral table is returned. The first time the ephemeral |
| 109614 | ** table is computed, the cursor number is also stored in pExpr->iTable, |
| 109615 | ** however the cursor number returned might not be the same, as it might |
| 109616 | ** have been duplicated using OP_OpenDup. |
| 109617 | ** |
| 109618 | ** If the LHS expression ("x" in the examples) is a column value, or |
| @@ -110231,11 +110455,11 @@ | |
| 110455 | ExprClearProperty(p, EP_Skip); |
| 110456 | } |
| 110457 | |
| 110458 | /* |
| 110459 | ** Evaluate an expression (either a vector or a scalar expression) and store |
| 110460 | ** the result in contiguous temporary registers. Return the index of |
| 110461 | ** the first register used to store the result. |
| 110462 | ** |
| 110463 | ** If the returned result register is a temporary scalar, then also write |
| 110464 | ** that register number into *piFreeable. If the returned result register |
| 110465 | ** is not a temporary or if the expression is a vector set *piFreeable |
| @@ -110271,11 +110495,11 @@ | |
| 110495 | ** If the last opcode is a OP_Copy, then set the do-not-merge flag (p5) |
| 110496 | ** so that a subsequent copy will not be merged into this one. |
| 110497 | */ |
| 110498 | static void setDoNotMergeFlagOnCopy(Vdbe *v){ |
| 110499 | if( sqlite3VdbeGetLastOp(v)->opcode==OP_Copy ){ |
| 110500 | sqlite3VdbeChangeP5(v, 1); /* Tag trailing OP_Copy as not mergeable */ |
| 110501 | } |
| 110502 | } |
| 110503 | |
| 110504 | /* |
| 110505 | ** Generate code to implement special SQL functions that are implemented |
| @@ -110361,17 +110585,17 @@ | |
| 110585 | target); |
| 110586 | break; |
| 110587 | } |
| 110588 | |
| 110589 | case INLINEFUNC_implies_nonnull_row: { |
| 110590 | /* Result of sqlite3ExprImpliesNonNullRow() */ |
| 110591 | Expr *pA1; |
| 110592 | assert( nFarg==2 ); |
| 110593 | pA1 = pFarg->a[1].pExpr; |
| 110594 | if( pA1->op==TK_COLUMN ){ |
| 110595 | sqlite3VdbeAddOp2(v, OP_Integer, |
| 110596 | sqlite3ExprImpliesNonNullRow(pFarg->a[0].pExpr,pA1->iTable,1), |
| 110597 | target); |
| 110598 | }else{ |
| 110599 | sqlite3VdbeAddOp2(v, OP_Null, 0, target); |
| 110600 | } |
| 110601 | break; |
| @@ -110543,11 +110767,11 @@ | |
| 110767 | int iTab = pExpr->iTable; |
| 110768 | int iReg; |
| 110769 | if( ExprHasProperty(pExpr, EP_FixedCol) ){ |
| 110770 | /* This COLUMN expression is really a constant due to WHERE clause |
| 110771 | ** constraints, and that constant is coded by the pExpr->pLeft |
| 110772 | ** expression. However, make sure the constant has the correct |
| 110773 | ** datatype by applying the Affinity of the table column to the |
| 110774 | ** constant. |
| 110775 | */ |
| 110776 | int aff; |
| 110777 | iReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft,target); |
| @@ -111272,11 +111496,11 @@ | |
| 111496 | ** once. If no functions are involved, then factor the code out and put it at |
| 111497 | ** the end of the prepared statement in the initialization section. |
| 111498 | ** |
| 111499 | ** If regDest>=0 then the result is always stored in that register and the |
| 111500 | ** result is not reusable. If regDest<0 then this routine is free to |
| 111501 | ** store the value wherever it wants. The register where the expression |
| 111502 | ** is stored is returned. When regDest<0, two identical expressions might |
| 111503 | ** code to the same register, if they do not contain function calls and hence |
| 111504 | ** are factored out into the initialization section at the end of the |
| 111505 | ** prepared statement. |
| 111506 | */ |
| @@ -112190,11 +112414,11 @@ | |
| 112414 | ** pE1: x>0 pE2: x==5 Result: false |
| 112415 | ** pE1: x=21 pE2: x=21 OR y=43 Result: true |
| 112416 | ** pE1: x!=123 pE2: x IS NOT NULL Result: true |
| 112417 | ** pE1: x!=?1 pE2: x IS NOT NULL Result: true |
| 112418 | ** pE1: x IS NULL pE2: x IS NOT NULL Result: false |
| 112419 | ** pE1: x IS ?2 pE2: x IS NOT NULL Result: false |
| 112420 | ** |
| 112421 | ** When comparing TK_COLUMN nodes between pE1 and pE2, if pE2 has |
| 112422 | ** Expr.iTable<0 then assume a table number given by iTab. |
| 112423 | ** |
| 112424 | ** If pParse is not NULL, then the values of bound variables in pE1 are |
| @@ -112226,68 +112450,108 @@ | |
| 112450 | ){ |
| 112451 | return 1; |
| 112452 | } |
| 112453 | return 0; |
| 112454 | } |
| 112455 | |
| 112456 | /* This is a helper function to impliesNotNullRow(). In this routine, |
| 112457 | ** set pWalker->eCode to one only if *both* of the input expressions |
| 112458 | ** separately have the implies-not-null-row property. |
| 112459 | */ |
| 112460 | static void bothImplyNotNullRow(Walker *pWalker, Expr *pE1, Expr *pE2){ |
| 112461 | if( pWalker->eCode==0 ){ |
| 112462 | sqlite3WalkExpr(pWalker, pE1); |
| 112463 | if( pWalker->eCode ){ |
| 112464 | pWalker->eCode = 0; |
| 112465 | sqlite3WalkExpr(pWalker, pE2); |
| 112466 | } |
| 112467 | } |
| 112468 | } |
| 112469 | |
| 112470 | /* |
| 112471 | ** This is the Expr node callback for sqlite3ExprImpliesNonNullRow(). |
| 112472 | ** If the expression node requires that the table at pWalker->iCur |
| 112473 | ** have one or more non-NULL column, then set pWalker->eCode to 1 and abort. |
| 112474 | ** |
| 112475 | ** pWalker->mWFlags is non-zero if this inquiry is being undertaking on |
| 112476 | ** behalf of a RIGHT JOIN (or FULL JOIN). That makes a difference when |
| 112477 | ** evaluating terms in the ON clause of an inner join. |
| 112478 | ** |
| 112479 | ** This routine controls an optimization. False positives (setting |
| 112480 | ** pWalker->eCode to 1 when it should not be) are deadly, but false-negatives |
| 112481 | ** (never setting pWalker->eCode) is a harmless missed optimization. |
| 112482 | */ |
| 112483 | static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){ |
| 112484 | testcase( pExpr->op==TK_AGG_COLUMN ); |
| 112485 | testcase( pExpr->op==TK_AGG_FUNCTION ); |
| 112486 | if( ExprHasProperty(pExpr, EP_OuterON) ) return WRC_Prune; |
| 112487 | if( ExprHasProperty(pExpr, EP_InnerON) && pWalker->mWFlags ){ |
| 112488 | /* If iCur is used in an inner-join ON clause to the left of a |
| 112489 | ** RIGHT JOIN, that does *not* mean that the table must be non-null. |
| 112490 | ** But it is difficult to check for that condition precisely. |
| 112491 | ** To keep things simple, any use of iCur from any inner-join is |
| 112492 | ** ignored while attempting to simplify a RIGHT JOIN. */ |
| 112493 | return WRC_Prune; |
| 112494 | } |
| 112495 | switch( pExpr->op ){ |
| 112496 | case TK_ISNOT: |
| 112497 | case TK_ISNULL: |
| 112498 | case TK_NOTNULL: |
| 112499 | case TK_IS: |
| 112500 | case TK_VECTOR: |
| 112501 | case TK_FUNCTION: |
| 112502 | case TK_TRUTH: |
| 112503 | case TK_CASE: |
| 112504 | testcase( pExpr->op==TK_ISNOT ); |
| 112505 | testcase( pExpr->op==TK_ISNULL ); |
| 112506 | testcase( pExpr->op==TK_NOTNULL ); |
| 112507 | testcase( pExpr->op==TK_IS ); |
| 112508 | testcase( pExpr->op==TK_VECTOR ); |
| 112509 | testcase( pExpr->op==TK_FUNCTION ); |
| 112510 | testcase( pExpr->op==TK_TRUTH ); |
| 112511 | testcase( pExpr->op==TK_CASE ); |
| 112512 | return WRC_Prune; |
| 112513 | |
| 112514 | case TK_COLUMN: |
| 112515 | if( pWalker->u.iCur==pExpr->iTable ){ |
| 112516 | pWalker->eCode = 1; |
| 112517 | return WRC_Abort; |
| 112518 | } |
| 112519 | return WRC_Prune; |
| 112520 | |
| 112521 | case TK_OR: |
| 112522 | case TK_AND: |
| 112523 | /* Both sides of an AND or OR must separately imply non-null-row. |
| 112524 | ** Consider these cases: |
| 112525 | ** 1. NOT (x AND y) |
| 112526 | ** 2. x OR y |
| 112527 | ** If only one of x or y is non-null-row, then the overall expression |
| 112528 | ** can be true if the other arm is false (case 1) or true (case 2). |
| 112529 | */ |
| 112530 | testcase( pExpr->op==TK_OR ); |
| 112531 | testcase( pExpr->op==TK_AND ); |
| 112532 | bothImplyNotNullRow(pWalker, pExpr->pLeft, pExpr->pRight); |
| 112533 | return WRC_Prune; |
| 112534 | |
| 112535 | case TK_IN: |
| 112536 | /* Beware of "x NOT IN ()" and "x NOT IN (SELECT 1 WHERE false)", |
| 112537 | ** both of which can be true. But apart from these cases, if |
| 112538 | ** the left-hand side of the IN is NULL then the IN itself will be |
| 112539 | ** NULL. */ |
| 112540 | if( ExprUseXList(pExpr) && ALWAYS(pExpr->x.pList->nExpr>0) ){ |
| 112541 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 112542 | } |
| 112543 | return WRC_Prune; |
| 112544 | |
| 112545 | case TK_BETWEEN: |
| 112546 | /* In "x NOT BETWEEN y AND z" either x must be non-null-row or else |
| 112547 | ** both y and z must be non-null row */ |
| 112548 | assert( ExprUseXList(pExpr) ); |
| 112549 | assert( pExpr->x.pList->nExpr==2 ); |
| 112550 | sqlite3WalkExpr(pWalker, pExpr->pLeft); |
| 112551 | bothImplyNotNullRow(pWalker, pExpr->x.pList->a[0].pExpr, |
| 112552 | pExpr->x.pList->a[1].pExpr); |
| 112553 | return WRC_Prune; |
| 112554 | |
| 112555 | /* Virtual tables are allowed to use constraints like x=NULL. So |
| 112556 | ** a term of the form x=y does not prove that y is not null if x |
| 112557 | ** is the column of a virtual table */ |
| @@ -112345,26 +112609,27 @@ | |
| 112609 | ** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE |
| 112610 | ** clause requires that some column of the right table of the LEFT JOIN |
| 112611 | ** be non-NULL, then the LEFT JOIN can be safely converted into an |
| 112612 | ** ordinary join. |
| 112613 | */ |
| 112614 | SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab, int isRJ){ |
| 112615 | Walker w; |
| 112616 | p = sqlite3ExprSkipCollateAndLikely(p); |
| 112617 | if( p==0 ) return 0; |
| 112618 | if( p->op==TK_NOTNULL ){ |
| 112619 | p = p->pLeft; |
| 112620 | }else{ |
| 112621 | while( p->op==TK_AND ){ |
| 112622 | if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab, isRJ) ) return 1; |
| 112623 | p = p->pRight; |
| 112624 | } |
| 112625 | } |
| 112626 | w.xExprCallback = impliesNotNullRow; |
| 112627 | w.xSelectCallback = 0; |
| 112628 | w.xSelectCallback2 = 0; |
| 112629 | w.eCode = 0; |
| 112630 | w.mWFlags = isRJ!=0; |
| 112631 | w.u.iCur = iTab; |
| 112632 | sqlite3WalkExpr(&w, p); |
| 112633 | return w.eCode; |
| 112634 | } |
| 112635 | |
| @@ -112421,11 +112686,11 @@ | |
| 112686 | sqlite3WalkExpr(&w, pExpr); |
| 112687 | return !w.eCode; |
| 112688 | } |
| 112689 | |
| 112690 | |
| 112691 | /* Structure used to pass information throughout the Walker in order to |
| 112692 | ** implement sqlite3ReferencesSrcList(). |
| 112693 | */ |
| 112694 | struct RefSrcList { |
| 112695 | sqlite3 *db; /* Database connection used for sqlite3DbRealloc() */ |
| 112696 | SrcList *pRef; /* Looking for references to these tables */ |
| @@ -112637,11 +112902,11 @@ | |
| 112902 | /* |
| 112903 | ** Search the AggInfo object for an aCol[] entry that has iTable and iColumn. |
| 112904 | ** Return the index in aCol[] of the entry that describes that column. |
| 112905 | ** |
| 112906 | ** If no prior entry is found, create a new one and return -1. The |
| 112907 | ** new column will have an index of pAggInfo->nColumn-1. |
| 112908 | */ |
| 112909 | static void findOrCreateAggInfoColumn( |
| 112910 | Parse *pParse, /* Parsing context */ |
| 112911 | AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */ |
| 112912 | Expr *pExpr /* Expr describing the column to find or insert */ |
| @@ -112650,10 +112915,11 @@ | |
| 112915 | int k; |
| 112916 | |
| 112917 | assert( pAggInfo->iFirstReg==0 ); |
| 112918 | pCol = pAggInfo->aCol; |
| 112919 | for(k=0; k<pAggInfo->nColumn; k++, pCol++){ |
| 112920 | if( pCol->pCExpr==pExpr ) return; |
| 112921 | if( pCol->iTable==pExpr->iTable |
| 112922 | && pCol->iColumn==pExpr->iColumn |
| 112923 | && pExpr->op!=TK_IF_NULL_ROW |
| 112924 | ){ |
| 112925 | goto fix_up_expr; |
| @@ -114035,11 +114301,11 @@ | |
| 114301 | |
| 114302 | return pBest; |
| 114303 | } |
| 114304 | |
| 114305 | /* |
| 114306 | ** An error occurred while parsing or otherwise processing a database |
| 114307 | ** object (either pParse->pNewTable, pNewIndex or pNewTrigger) as part of an |
| 114308 | ** ALTER TABLE RENAME COLUMN program. The error message emitted by the |
| 114309 | ** sub-routine is currently stored in pParse->zErrMsg. This function |
| 114310 | ** adds context to the error message and then stores it in pCtx. |
| 114311 | */ |
| @@ -117141,18 +117407,19 @@ | |
| 117407 | pSample = &pIdx->aSample[pIdx->nSample]; |
| 117408 | decodeIntArray((char*)sqlite3_column_text(pStmt,1),nCol,pSample->anEq,0,0); |
| 117409 | decodeIntArray((char*)sqlite3_column_text(pStmt,2),nCol,pSample->anLt,0,0); |
| 117410 | decodeIntArray((char*)sqlite3_column_text(pStmt,3),nCol,pSample->anDLt,0,0); |
| 117411 | |
| 117412 | /* Take a copy of the sample. Add 8 extra 0x00 bytes the end of the buffer. |
| 117413 | ** This is in case the sample record is corrupted. In that case, the |
| 117414 | ** sqlite3VdbeRecordCompare() may read up to two varints past the |
| 117415 | ** end of the allocated buffer before it realizes it is dealing with |
| 117416 | ** a corrupt record. Or it might try to read a large integer from the |
| 117417 | ** buffer. In any case, eight 0x00 bytes prevents this from causing |
| 117418 | ** a buffer overread. */ |
| 117419 | pSample->n = sqlite3_column_bytes(pStmt, 4); |
| 117420 | pSample->p = sqlite3DbMallocZero(db, pSample->n + 8); |
| 117421 | if( pSample->p==0 ){ |
| 117422 | sqlite3_finalize(pStmt); |
| 117423 | return SQLITE_NOMEM_BKPT; |
| 117424 | } |
| 117425 | if( pSample->n ){ |
| @@ -118106,11 +118373,11 @@ | |
| 118373 | const char *zArg3 |
| 118374 | ){ |
| 118375 | sqlite3 *db = pParse->db; |
| 118376 | int rc; |
| 118377 | |
| 118378 | /* Don't do any authorization checks if the database is initializing |
| 118379 | ** or if the parser is being invoked from within sqlite3_declare_vtab. |
| 118380 | */ |
| 118381 | assert( !IN_RENAME_OBJECT || db->xAuth==0 ); |
| 118382 | if( db->xAuth==0 || db->init.busy || IN_SPECIAL_PARSE ){ |
| 118383 | return SQLITE_OK; |
| @@ -118928,11 +119195,11 @@ | |
| 119195 | pCol->colFlags |= COLFLAG_HASCOLL; |
| 119196 | } |
| 119197 | } |
| 119198 | |
| 119199 | /* |
| 119200 | ** Return the collating sequence name for a column |
| 119201 | */ |
| 119202 | SQLITE_PRIVATE const char *sqlite3ColumnColl(Column *pCol){ |
| 119203 | const char *z; |
| 119204 | if( (pCol->colFlags & COLFLAG_HASCOLL)==0 ) return 0; |
| 119205 | z = pCol->zCnName; |
| @@ -119686,11 +119953,11 @@ | |
| 119953 | sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName); |
| 119954 | return; |
| 119955 | } |
| 119956 | if( !IN_RENAME_OBJECT ) sqlite3DequoteToken(&sName); |
| 119957 | |
| 119958 | /* Because keywords GENERATE ALWAYS can be converted into identifiers |
| 119959 | ** by the parser, we can sometimes end up with a typename that ends |
| 119960 | ** with "generated always". Check for this case and omit the surplus |
| 119961 | ** text. */ |
| 119962 | if( sType.n>=16 |
| 119963 | && sqlite3_strnicmp(sType.z+(sType.n-6),"always",6)==0 |
| @@ -119907,11 +120174,11 @@ | |
| 120174 | */ |
| 120175 | SQLITE_PRIVATE void sqlite3AddDefaultValue( |
| 120176 | Parse *pParse, /* Parsing context */ |
| 120177 | Expr *pExpr, /* The parsed expression of the default value */ |
| 120178 | const char *zStart, /* Start of the default value text */ |
| 120179 | const char *zEnd /* First character past end of default value text */ |
| 120180 | ){ |
| 120181 | Table *p; |
| 120182 | Column *pCol; |
| 120183 | sqlite3 *db = pParse->db; |
| 120184 | p = pParse->pNewTable; |
| @@ -120255,11 +120522,11 @@ | |
| 120522 | ** which to write into the output buffer. This function copies the |
| 120523 | ** nul-terminated string pointed to by the third parameter, zSignedIdent, |
| 120524 | ** to the specified offset in the buffer and updates *pIdx to refer |
| 120525 | ** to the first byte after the last byte written before returning. |
| 120526 | ** |
| 120527 | ** If the string zSignedIdent consists entirely of alphanumeric |
| 120528 | ** characters, does not begin with a digit and is not an SQL keyword, |
| 120529 | ** then it is copied to the output buffer exactly as it is. Otherwise, |
| 120530 | ** it is quoted using double-quotes. |
| 120531 | */ |
| 120532 | static void identPut(char *z, int *pIdx, char *zSignedIdent){ |
| @@ -120407,11 +120674,11 @@ | |
| 120674 | int i; |
| 120675 | const Column *aCol = pIdx->pTable->aCol; |
| 120676 | for(i=0; i<pIdx->nColumn; i++){ |
| 120677 | i16 x = pIdx->aiColumn[i]; |
| 120678 | assert( x<pIdx->pTable->nCol ); |
| 120679 | wIndex += x<0 ? 1 : aCol[x].szEst; |
| 120680 | } |
| 120681 | pIdx->szIdxRow = sqlite3LogEst(wIndex*4); |
| 120682 | } |
| 120683 | |
| 120684 | /* Return true if column number x is any of the first nCol entries of aiCol[]. |
| @@ -122145,11 +122412,11 @@ | |
| 122412 | assert( pName && pName->z ); |
| 122413 | |
| 122414 | #ifndef SQLITE_OMIT_TEMPDB |
| 122415 | /* If the index name was unqualified, check if the table |
| 122416 | ** is a temp table. If so, set the database to 1. Do not do this |
| 122417 | ** if initializing a database schema. |
| 122418 | */ |
| 122419 | if( !db->init.busy ){ |
| 122420 | pTab = sqlite3SrcListLookup(pParse, pTblName); |
| 122421 | if( pName2->n==0 && pTab && pTab->pSchema==db->aDb[1].pSchema ){ |
| 122422 | iDb = 1; |
| @@ -123802,11 +124069,11 @@ | |
| 124069 | sqlite3DbFree(db, pCte); |
| 124070 | } |
| 124071 | |
| 124072 | /* |
| 124073 | ** This routine is invoked once per CTE by the parser while parsing a |
| 124074 | ** WITH clause. The CTE described by the third argument is added to |
| 124075 | ** the WITH clause of the second argument. If the second argument is |
| 124076 | ** NULL, then a new WITH argument is created. |
| 124077 | */ |
| 124078 | SQLITE_PRIVATE With *sqlite3WithAdd( |
| 124079 | Parse *pParse, /* Parsing context */ |
| @@ -124446,10 +124713,11 @@ | |
| 124713 | Table *pTab; |
| 124714 | assert( pItem && pSrc->nSrc>=1 ); |
| 124715 | pTab = sqlite3LocateTableItem(pParse, 0, pItem); |
| 124716 | sqlite3DeleteTable(pParse->db, pItem->pTab); |
| 124717 | pItem->pTab = pTab; |
| 124718 | pItem->fg.notCte = 1; |
| 124719 | if( pTab ){ |
| 124720 | pTab->nTabRef++; |
| 124721 | if( pItem->fg.isIndexedBy && sqlite3IndexedByLookup(pParse, pItem) ){ |
| 124722 | pTab = 0; |
| 124723 | } |
| @@ -124598,11 +124866,11 @@ | |
| 124866 | char *zStmtType /* Either DELETE or UPDATE. For err msgs. */ |
| 124867 | ){ |
| 124868 | sqlite3 *db = pParse->db; |
| 124869 | Expr *pLhs = NULL; /* LHS of IN(SELECT...) operator */ |
| 124870 | Expr *pInClause = NULL; /* WHERE rowid IN ( select ) */ |
| 124871 | ExprList *pEList = NULL; /* Expression list containing only pSelectRowid*/ |
| 124872 | SrcList *pSelectSrc = NULL; /* SELECT rowid FROM x ... (dup of pSrc) */ |
| 124873 | Select *pSelect = NULL; /* Complete SELECT tree */ |
| 124874 | Table *pTab; |
| 124875 | |
| 124876 | /* Check that there isn't an ORDER BY without a LIMIT clause. |
| @@ -124636,18 +124904,24 @@ | |
| 124904 | pEList = sqlite3ExprListAppend( |
| 124905 | pParse, 0, sqlite3PExpr(pParse, TK_ROW, 0, 0) |
| 124906 | ); |
| 124907 | }else{ |
| 124908 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 124909 | assert( pPk!=0 ); |
| 124910 | assert( pPk->nKeyCol>=1 ); |
| 124911 | if( pPk->nKeyCol==1 ){ |
| 124912 | const char *zName; |
| 124913 | assert( pPk->aiColumn[0]>=0 && pPk->aiColumn[0]<pTab->nCol ); |
| 124914 | zName = pTab->aCol[pPk->aiColumn[0]].zCnName; |
| 124915 | pLhs = sqlite3Expr(db, TK_ID, zName); |
| 124916 | pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db, TK_ID, zName)); |
| 124917 | }else{ |
| 124918 | int i; |
| 124919 | for(i=0; i<pPk->nKeyCol; i++){ |
| 124920 | Expr *p; |
| 124921 | assert( pPk->aiColumn[i]>=0 && pPk->aiColumn[i]<pTab->nCol ); |
| 124922 | p = sqlite3Expr(db, TK_ID, pTab->aCol[pPk->aiColumn[i]].zCnName); |
| 124923 | pEList = sqlite3ExprListAppend(pParse, pEList, p); |
| 124924 | } |
| 124925 | pLhs = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 124926 | if( pLhs ){ |
| 124927 | pLhs->x.pList = sqlite3ExprListDup(db, pEList, 0); |
| @@ -124672,11 +124946,11 @@ | |
| 124946 | /* generate the SELECT expression tree. */ |
| 124947 | pSelect = sqlite3SelectNew(pParse, pEList, pSelectSrc, pWhere, 0 ,0, |
| 124948 | pOrderBy,0,pLimit |
| 124949 | ); |
| 124950 | |
| 124951 | /* now generate the new WHERE rowid IN clause for the DELETE/UPDATE */ |
| 124952 | pInClause = sqlite3PExpr(pParse, TK_IN, pLhs, 0); |
| 124953 | sqlite3PExprAddSelect(pParse, pInClause, pSelect); |
| 124954 | return pInClause; |
| 124955 | } |
| 124956 | #endif /* defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) */ |
| @@ -126057,11 +126331,11 @@ | |
| 126331 | u8 noCase; /* true to ignore case differences */ |
| 126332 | }; |
| 126333 | |
| 126334 | /* |
| 126335 | ** For LIKE and GLOB matching on EBCDIC machines, assume that every |
| 126336 | ** character is exactly one byte in size. Also, provide the Utf8Read() |
| 126337 | ** macro for fast reading of the next character in the common case where |
| 126338 | ** the next character is ASCII. |
| 126339 | */ |
| 126340 | #if defined(SQLITE_EBCDIC) |
| 126341 | # define sqlite3Utf8Read(A) (*((*A)++)) |
| @@ -126290,11 +126564,11 @@ | |
| 126564 | #endif |
| 126565 | |
| 126566 | |
| 126567 | /* |
| 126568 | ** Implementation of the like() SQL function. This function implements |
| 126569 | ** the built-in LIKE operator. The first argument to the function is the |
| 126570 | ** pattern and the second argument is the string. So, the SQL statements: |
| 126571 | ** |
| 126572 | ** A LIKE B |
| 126573 | ** |
| 126574 | ** is implemented as like(B,A). |
| @@ -126676,11 +126950,11 @@ | |
| 126950 | ** two arguments. In both cases the first argument is interpreted as text |
| 126951 | ** a text value containing a set of pairs of hexadecimal digits which are |
| 126952 | ** decoded and returned as a blob. |
| 126953 | ** |
| 126954 | ** If there is only a single argument, then it must consist only of an |
| 126955 | ** even number of hexadecimal digits. Otherwise, return NULL. |
| 126956 | ** |
| 126957 | ** Or, if there is a second argument, then any character that appears in |
| 126958 | ** the second argument is also allowed to appear between pairs of hexadecimal |
| 126959 | ** digits in the first argument. If any other character appears in the |
| 126960 | ** first argument, or if one of the allowed characters appears between |
| @@ -127376,11 +127650,11 @@ | |
| 127650 | assert( argc==1 || argc==2 ); |
| 127651 | (void)argc; /* Suppress unused parameter warning */ |
| 127652 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 127653 | pGCC = (GroupConcatCtx*)sqlite3_aggregate_context(context, sizeof(*pGCC)); |
| 127654 | /* pGCC is always non-NULL since groupConcatStep() will have always |
| 127655 | ** run first to initialize it */ |
| 127656 | if( ALWAYS(pGCC) ){ |
| 127657 | int nVS; |
| 127658 | /* Must call sqlite3_value_text() to convert the argument into text prior |
| 127659 | ** to invoking sqlite3_value_bytes(), in case the text encoding is UTF16 */ |
| 127660 | (void)sqlite3_value_text(argv[0]); |
| @@ -129579,11 +129853,11 @@ | |
| 129853 | ** 'E' REAL |
| 129854 | ** |
| 129855 | ** For STRICT tables: |
| 129856 | ** ------------------ |
| 129857 | ** |
| 129858 | ** Generate an appropriate OP_TypeCheck opcode that will verify the |
| 129859 | ** datatypes against the column definitions in pTab. If iReg==0, that |
| 129860 | ** means an OP_MakeRecord opcode has already been generated and should be |
| 129861 | ** the last opcode generated. The new OP_TypeCheck needs to be inserted |
| 129862 | ** before the OP_MakeRecord. The new OP_TypeCheck should use the same |
| 129863 | ** register set as the OP_MakeRecord. If iReg>0 then register iReg is |
| @@ -130871,11 +131145,11 @@ | |
| 131145 | #define CKCNSTRNT_ROWID 0x02 /* CHECK constraint references the ROWID */ |
| 131146 | |
| 131147 | /* This is the Walker callback from sqlite3ExprReferencesUpdatedColumn(). |
| 131148 | * Set bit 0x01 of pWalker->eCode if pWalker->eCode to 0 and if this |
| 131149 | ** expression node references any of the |
| 131150 | ** columns that are being modified by an UPDATE statement. |
| 131151 | */ |
| 131152 | static int checkConstraintExprNode(Walker *pWalker, Expr *pExpr){ |
| 131153 | if( pExpr->op==TK_COLUMN ){ |
| 131154 | assert( pExpr->iColumn>=0 || pExpr->iColumn==-1 ); |
| 131155 | if( pExpr->iColumn>=0 ){ |
| @@ -131094,11 +131368,11 @@ | |
| 131368 | int ignoreDest, /* Jump to this label on an OE_Ignore resolution */ |
| 131369 | int *pbMayReplace, /* OUT: Set to true if constraint may cause a replace */ |
| 131370 | int *aiChng, /* column i is unchanged if aiChng[i]<0 */ |
| 131371 | Upsert *pUpsert /* ON CONFLICT clauses, if any. NULL otherwise */ |
| 131372 | ){ |
| 131373 | Vdbe *v; /* VDBE under construction */ |
| 131374 | Index *pIdx; /* Pointer to one of the indices */ |
| 131375 | Index *pPk = 0; /* The PRIMARY KEY index for WITHOUT ROWID tables */ |
| 131376 | sqlite3 *db; /* Database connection */ |
| 131377 | int i; /* loop counter */ |
| 131378 | int ix; /* Index loop counter */ |
| @@ -131577,11 +131851,11 @@ | |
| 131851 | */ |
| 131852 | for(pIdx = indexIteratorFirst(&sIdxIter, &ix); |
| 131853 | pIdx; |
| 131854 | pIdx = indexIteratorNext(&sIdxIter, &ix) |
| 131855 | ){ |
| 131856 | int regIdx; /* Range of registers holding content for pIdx */ |
| 131857 | int regR; /* Range of registers holding conflicting PK */ |
| 131858 | int iThisCur; /* Cursor for this UNIQUE index */ |
| 131859 | int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */ |
| 131860 | int addrConflictCk; /* First opcode in the conflict check logic */ |
| 131861 | |
| @@ -132393,11 +132667,11 @@ | |
| 132667 | if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){ |
| 132668 | return 0; /* Tables have different CHECK constraints. Ticket #2252 */ |
| 132669 | } |
| 132670 | #endif |
| 132671 | #ifndef SQLITE_OMIT_FOREIGN_KEY |
| 132672 | /* Disallow the transfer optimization if the destination table contains |
| 132673 | ** any foreign key constraints. This is more restrictive than necessary. |
| 132674 | ** But the main beneficiary of the transfer optimization is the VACUUM |
| 132675 | ** command, and the VACUUM command disables foreign key constraints. So |
| 132676 | ** the extra complication to make this rule less restrictive is probably |
| 132677 | ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] |
| @@ -134026,10 +134300,14 @@ | |
| 134300 | ** |
| 134301 | ** Later (2023-03-25): Save an extra 6 bytes for the filename suffix. |
| 134302 | ** See https://sqlite.org/forum/forumpost/24083b579d. |
| 134303 | */ |
| 134304 | if( nMsg>SQLITE_MAX_PATHLEN ) goto extension_not_found; |
| 134305 | |
| 134306 | /* Do not allow sqlite3_load_extension() to link to a copy of the |
| 134307 | ** running application, by passing in an empty filename. */ |
| 134308 | if( nMsg==0 ) goto extension_not_found; |
| 134309 | |
| 134310 | handle = sqlite3OsDlOpen(pVfs, zFile); |
| 134311 | #if SQLITE_OS_UNIX || SQLITE_OS_WIN |
| 134312 | for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){ |
| 134313 | char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]); |
| @@ -135859,11 +136137,11 @@ | |
| 136137 | ** PRAGMA cache_spill=BOOLEAN |
| 136138 | ** PRAGMA [schema.]cache_spill=N |
| 136139 | ** |
| 136140 | ** The first form reports the current local setting for the |
| 136141 | ** page cache spill size. The second form turns cache spill on |
| 136142 | ** or off. When turning cache spill on, the size is set to the |
| 136143 | ** current cache_size. The third form sets a spill size that |
| 136144 | ** may be different form the cache size. |
| 136145 | ** If N is positive then that is the |
| 136146 | ** number of pages in the cache. If N is negative, then the |
| 136147 | ** number of pages is adjusted so that the cache uses -N kibibytes |
| @@ -136637,13 +136915,13 @@ | |
| 136915 | ** Verify the integrity of the database. |
| 136916 | ** |
| 136917 | ** The "quick_check" is reduced version of |
| 136918 | ** integrity_check designed to detect most database corruption |
| 136919 | ** without the overhead of cross-checking indexes. Quick_check |
| 136920 | ** is linear time whereas integrity_check is O(NlogN). |
| 136921 | ** |
| 136922 | ** The maximum number of errors is 100 by default. A different default |
| 136923 | ** can be specified using a numeric parameter N. |
| 136924 | ** |
| 136925 | ** Or, the parameter N can be the name of a table. In that case, only |
| 136926 | ** the one table named is verified. The freelist is only verified if |
| 136927 | ** the named table is "sqlite_schema" (or one of its aliases). |
| @@ -137397,11 +137675,11 @@ | |
| 137675 | int iTabCur; /* Cursor for a table whose size needs checking */ |
| 137676 | HashElem *k; /* Loop over tables of a schema */ |
| 137677 | Schema *pSchema; /* The current schema */ |
| 137678 | Table *pTab; /* A table in the schema */ |
| 137679 | Index *pIdx; /* An index of the table */ |
| 137680 | LogEst szThreshold; /* Size threshold above which reanalysis needed */ |
| 137681 | char *zSubSql; /* SQL statement for the OP_SqlExec opcode */ |
| 137682 | u32 opMask; /* Mask of operations to perform */ |
| 137683 | |
| 137684 | if( zRight ){ |
| 137685 | opMask = (u32)sqlite3Atoi(zRight); |
| @@ -138523,11 +138801,11 @@ | |
| 138801 | ** Add a new cleanup operation to a Parser. The cleanup should happen when |
| 138802 | ** the parser object is destroyed. But, beware: the cleanup might happen |
| 138803 | ** immediately. |
| 138804 | ** |
| 138805 | ** Use this mechanism for uncommon cleanups. There is a higher setup |
| 138806 | ** cost for this mechanism (an extra malloc), so it should not be used |
| 138807 | ** for common cleanups that happen on most calls. But for less |
| 138808 | ** common cleanups, we save a single NULL-pointer comparison in |
| 138809 | ** sqlite3ParseObjectReset(), which reduces the total CPU cycle count. |
| 138810 | ** |
| 138811 | ** If a memory allocation error occurs, then the cleanup happens immediately. |
| @@ -139225,11 +139503,11 @@ | |
| 139503 | ** NATURAL RIGHT OUTER JT_NATURAL|JT_RIGHT|JT_OUTER |
| 139504 | ** NATURAL FULL - JT_NATURAL|JT_LEFT|JT_RIGHT |
| 139505 | ** NATURAL FULL OUTER JT_NATRUAL|JT_LEFT|JT_RIGHT |
| 139506 | ** |
| 139507 | ** To preserve historical compatibly, SQLite also accepts a variety |
| 139508 | ** of other non-standard and in many cases nonsensical join types. |
| 139509 | ** This routine makes as much sense at it can from the nonsense join |
| 139510 | ** type and returns a result. Examples of accepted nonsense join types |
| 139511 | ** include but are not limited to: |
| 139512 | ** |
| 139513 | ** INNER CROSS JOIN -> same as JOIN |
| @@ -139496,11 +139774,11 @@ | |
| 139774 | u32 joinType; |
| 139775 | |
| 139776 | if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue; |
| 139777 | joinType = (pRight->fg.jointype & JT_OUTER)!=0 ? EP_OuterON : EP_InnerON; |
| 139778 | |
| 139779 | /* If this is a NATURAL join, synthesize an appropriate USING clause |
| 139780 | ** to specify which columns should be joined. |
| 139781 | */ |
| 139782 | if( pRight->fg.jointype & JT_NATURAL ){ |
| 139783 | IdList *pUsing = 0; |
| 139784 | if( pRight->fg.isUsing || pRight->u3.pOn ){ |
| @@ -139712,11 +139990,11 @@ | |
| 139990 | ** (2) All output columns are included in the sort record. In that |
| 139991 | ** case regData==regOrigData. |
| 139992 | ** (3) Some output columns are omitted from the sort record due to |
| 139993 | ** the SQLITE_ENABLE_SORTER_REFERENCES optimization, or due to the |
| 139994 | ** SQLITE_ECEL_OMITREF optimization, or due to the |
| 139995 | ** SortCtx.pDeferredRowLoad optimization. In any of these cases |
| 139996 | ** regOrigData is 0 to prevent this routine from trying to copy |
| 139997 | ** values that might not yet exist. |
| 139998 | */ |
| 139999 | assert( nData==1 || regData==regOrigData || regOrigData==0 ); |
| 140000 | |
| @@ -139768,11 +140046,11 @@ | |
| 140046 | memset(pKI->aSortFlags, 0, pKI->nKeyField); /* Makes OP_Jump testable */ |
| 140047 | sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO); |
| 140048 | testcase( pKI->nAllField > pKI->nKeyField+2 ); |
| 140049 | pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat, |
| 140050 | pKI->nAllField-pKI->nKeyField-1); |
| 140051 | pOp = 0; /* Ensure pOp not used after sqlite3VdbeAddOp3() */ |
| 140052 | addrJmp = sqlite3VdbeCurrentAddr(v); |
| 140053 | sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v); |
| 140054 | pSort->labelBkOut = sqlite3VdbeMakeLabel(pParse); |
| 140055 | pSort->regReturn = ++pParse->nMem; |
| 140056 | sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut); |
| @@ -139862,11 +140140,11 @@ | |
| 140140 | ** the ephemeral cursor and proceed. |
| 140141 | ** |
| 140142 | ** The returned value in this case is a copy of parameter iTab. |
| 140143 | ** |
| 140144 | ** WHERE_DISTINCT_ORDERED: |
| 140145 | ** In this case rows are being delivered sorted order. The ephemeral |
| 140146 | ** table is not required. Instead, the current set of values |
| 140147 | ** is compared against previous row. If they match, the new row |
| 140148 | ** is not distinct and control jumps to VM address addrRepeat. Otherwise, |
| 140149 | ** the VM program proceeds with processing the new row. |
| 140150 | ** |
| @@ -141287,11 +141565,11 @@ | |
| 141565 | /* |
| 141566 | ** pTab is a transient Table object that represents a subquery of some |
| 141567 | ** kind (maybe a parenthesized subquery in the FROM clause of a larger |
| 141568 | ** query, or a VIEW, or a CTE). This routine computes type information |
| 141569 | ** for that Table object based on the Select object that implements the |
| 141570 | ** subquery. For the purposes of this routine, "type information" means: |
| 141571 | ** |
| 141572 | ** * The datatype name, as it might appear in a CREATE TABLE statement |
| 141573 | ** * Which collating sequence to use for the column |
| 141574 | ** * The affinity of the column |
| 141575 | */ |
| @@ -141616,11 +141894,11 @@ | |
| 141894 | int iCurrent = 0; /* The Current table */ |
| 141895 | int regCurrent; /* Register holding Current table */ |
| 141896 | int iQueue; /* The Queue table */ |
| 141897 | int iDistinct = 0; /* To ensure unique results if UNION */ |
| 141898 | int eDest = SRT_Fifo; /* How to write to Queue */ |
| 141899 | SelectDest destQueue; /* SelectDest targeting the Queue table */ |
| 141900 | int i; /* Loop counter */ |
| 141901 | int rc; /* Result code */ |
| 141902 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| 141903 | Expr *pLimit; /* Saved LIMIT and OFFSET */ |
| 141904 | int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */ |
| @@ -142216,11 +142494,11 @@ | |
| 142494 | } |
| 142495 | } |
| 142496 | |
| 142497 | /* |
| 142498 | ** Code an output subroutine for a coroutine implementation of a |
| 142499 | ** SELECT statement. |
| 142500 | ** |
| 142501 | ** The data to be output is contained in pIn->iSdst. There are |
| 142502 | ** pIn->nSdst columns to be output. pDest is where the output should |
| 142503 | ** be sent. |
| 142504 | ** |
| @@ -142438,11 +142716,11 @@ | |
| 142716 | ** Jump AltB, AeqB, AgtB |
| 142717 | ** End: ... |
| 142718 | ** |
| 142719 | ** We call AltB, AeqB, AgtB, EofA, and EofB "subroutines" but they are not |
| 142720 | ** actually called using Gosub and they do not Return. EofA and EofB loop |
| 142721 | ** until all data is exhausted then jump to the "end" label. AltB, AeqB, |
| 142722 | ** and AgtB jump to either L2 or to one of EofA or EofB. |
| 142723 | */ |
| 142724 | #ifndef SQLITE_OMIT_COMPOUND_SELECT |
| 142725 | static int multiSelectOrderBy( |
| 142726 | Parse *pParse, /* Parsing context */ |
| @@ -142475,11 +142753,11 @@ | |
| 142753 | int regPrev; /* A range of registers to hold previous output */ |
| 142754 | int savedLimit; /* Saved value of p->iLimit */ |
| 142755 | int savedOffset; /* Saved value of p->iOffset */ |
| 142756 | int labelCmpr; /* Label for the start of the merge algorithm */ |
| 142757 | int labelEnd; /* Label for the end of the overall SELECT stmt */ |
| 142758 | int addr1; /* Jump instructions that get retargeted */ |
| 142759 | int op; /* One of TK_ALL, TK_UNION, TK_EXCEPT, TK_INTERSECT */ |
| 142760 | KeyInfo *pKeyDup = 0; /* Comparison information for duplicate removal */ |
| 142761 | KeyInfo *pKeyMerge; /* Comparison information for merging rows */ |
| 142762 | sqlite3 *db; /* Database connection */ |
| 142763 | ExprList *pOrderBy; /* The ORDER BY clause */ |
| @@ -142844,15 +143122,18 @@ | |
| 143122 | pExpr->op = TK_NULL; |
| 143123 | }else |
| 143124 | #endif |
| 143125 | { |
| 143126 | Expr *pNew; |
| 143127 | int iColumn; |
| 143128 | Expr *pCopy; |
| 143129 | Expr ifNullRow; |
| 143130 | iColumn = pExpr->iColumn; |
| 143131 | assert( iColumn>=0 ); |
| 143132 | assert( pSubst->pEList!=0 && iColumn<pSubst->pEList->nExpr ); |
| 143133 | assert( pExpr->pRight==0 ); |
| 143134 | pCopy = pSubst->pEList->a[iColumn].pExpr; |
| 143135 | if( sqlite3ExprIsVector(pCopy) ){ |
| 143136 | sqlite3VectorErrorMsg(pSubst->pParse, pCopy); |
| 143137 | }else{ |
| 143138 | sqlite3 *db = pSubst->pParse->db; |
| 143139 | if( pSubst->isOuterJoin |
| @@ -143197,11 +143478,11 @@ | |
| 143478 | ** (8) If the subquery uses LIMIT then the outer query may not be a join. |
| 143479 | ** |
| 143480 | ** (9) If the subquery uses LIMIT then the outer query may not be aggregate. |
| 143481 | ** |
| 143482 | ** (**) Restriction (10) was removed from the code on 2005-02-05 but we |
| 143483 | ** accidentally carried the comment forward until 2014-09-15. Original |
| 143484 | ** constraint: "If the subquery is aggregate then the outer query |
| 143485 | ** may not use LIMIT." |
| 143486 | ** |
| 143487 | ** (11) The subquery and the outer query may not both have ORDER BY clauses. |
| 143488 | ** |
| @@ -143471,11 +143752,11 @@ | |
| 143752 | pParse->zAuthContext = pSubitem->zName; |
| 143753 | TESTONLY(i =) sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0); |
| 143754 | testcase( i==SQLITE_DENY ); |
| 143755 | pParse->zAuthContext = zSavedAuthContext; |
| 143756 | |
| 143757 | /* Delete the transient structures associated with the subquery */ |
| 143758 | pSub1 = pSubitem->pSelect; |
| 143759 | sqlite3DbFree(db, pSubitem->zDatabase); |
| 143760 | sqlite3DbFree(db, pSubitem->zName); |
| 143761 | sqlite3DbFree(db, pSubitem->zAlias); |
| 143762 | pSubitem->zDatabase = 0; |
| @@ -143653,11 +143934,11 @@ | |
| 143934 | if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){ |
| 143935 | /* At this point, any non-zero iOrderByCol values indicate that the |
| 143936 | ** ORDER BY column expression is identical to the iOrderByCol'th |
| 143937 | ** expression returned by SELECT statement pSub. Since these values |
| 143938 | ** do not necessarily correspond to columns in SELECT statement pParent, |
| 143939 | ** zero them before transferring the ORDER BY clause. |
| 143940 | ** |
| 143941 | ** Not doing this may cause an error if a subsequent call to this |
| 143942 | ** function attempts to flatten a compound sub-query into pParent |
| 143943 | ** (the only way this can happen is if the compound sub-query is |
| 143944 | ** currently part of pSub->pSrc). See ticket [d11a6e908f]. */ |
| @@ -143713,12 +143994,11 @@ | |
| 143994 | for(i=0; i<nSubSrc; i++){ |
| 143995 | recomputeColumnsUsed(pParent, &pSrc->a[i+iFrom]); |
| 143996 | } |
| 143997 | } |
| 143998 | |
| 143999 | /* Finally, delete what is left of the subquery and return success. |
| 144000 | */ |
| 144001 | sqlite3AggInfoPersistWalkerInit(&w, pParse); |
| 144002 | sqlite3WalkSelect(&w,pSub1); |
| 144003 | sqlite3SelectDelete(db, pSub1); |
| 144004 | |
| @@ -143749,11 +144029,11 @@ | |
| 144029 | Expr **apExpr; /* [i*2] is COLUMN and [i*2+1] is VALUE */ |
| 144030 | }; |
| 144031 | |
| 144032 | /* |
| 144033 | ** Add a new entry to the pConst object. Except, do not add duplicate |
| 144034 | ** pColumn entries. Also, do not add if doing so would not be appropriate. |
| 144035 | ** |
| 144036 | ** The caller guarantees the pColumn is a column and pValue is a constant. |
| 144037 | ** This routine has to do some additional checks before completing the |
| 144038 | ** insert. |
| 144039 | */ |
| @@ -143935,11 +144215,11 @@ | |
| 144215 | ** INSERT INTO t1 VALUES(123,'0123'); |
| 144216 | ** SELECT * FROM t1 WHERE a=123 AND b=a; |
| 144217 | ** SELECT * FROM t1 WHERE a=123 AND b=123; |
| 144218 | ** |
| 144219 | ** The two SELECT statements above should return different answers. b=a |
| 144220 | ** is always true because the comparison uses numeric affinity, but b=123 |
| 144221 | ** is false because it uses text affinity and '0123' is not the same as '123'. |
| 144222 | ** To work around this, the expression tree is not actually changed from |
| 144223 | ** "b=a" to "b=123" but rather the "a" in "b=a" is tagged with EP_FixedCol |
| 144224 | ** and the "123" value is hung off of the pLeft pointer. Code generator |
| 144225 | ** routines know to generate the constant "123" instead of looking up the |
| @@ -144019,11 +144299,11 @@ | |
| 144299 | ** this may change the results of the window functions. |
| 144300 | ** |
| 144301 | ** At the time this function is called it is guaranteed that |
| 144302 | ** |
| 144303 | ** * the sub-query uses only one distinct window frame, and |
| 144304 | ** * that the window frame has a PARTITION BY clause. |
| 144305 | */ |
| 144306 | static int pushDownWindowCheck(Parse *pParse, Select *pSubq, Expr *pExpr){ |
| 144307 | assert( pSubq->pWin->pPartition ); |
| 144308 | assert( (pSubq->selFlags & SF_MultiPart)==0 ); |
| 144309 | assert( pSubq->pPrior==0 ); |
| @@ -145527,11 +145807,11 @@ | |
| 145807 | assert( pExpr->iAgg>=0 ); |
| 145808 | pCol = &pAggInfo->aCol[pExpr->iAgg]; |
| 145809 | pExpr->op = TK_AGG_COLUMN; |
| 145810 | pExpr->iTable = pCol->iTable; |
| 145811 | pExpr->iColumn = pCol->iColumn; |
| 145812 | ExprClearProperty(pExpr, EP_Skip|EP_Collate|EP_Unlikely); |
| 145813 | return WRC_Prune; |
| 145814 | } |
| 145815 | |
| 145816 | /* |
| 145817 | ** Convert every pAggInfo->aFunc[].pExpr such that any node within |
| @@ -145558,11 +145838,11 @@ | |
| 145838 | ** to calling this routine: |
| 145839 | ** |
| 145840 | ** * The aCol[] and aFunc[] arrays may be modified |
| 145841 | ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may not be used |
| 145842 | ** |
| 145843 | ** After calling this routine: |
| 145844 | ** |
| 145845 | ** * The aCol[] and aFunc[] arrays are fixed |
| 145846 | ** * The AggInfoColumnReg() and AggInfoFuncReg() macros may be used |
| 145847 | ** |
| 145848 | */ |
| @@ -146212,26 +146492,63 @@ | |
| 146492 | /* The expander should have already created transient Table objects |
| 146493 | ** even for FROM clause elements such as subqueries that do not correspond |
| 146494 | ** to a real table */ |
| 146495 | assert( pTab!=0 ); |
| 146496 | |
| 146497 | /* Try to simplify joins: |
| 146498 | ** |
| 146499 | ** LEFT JOIN -> JOIN |
| 146500 | ** RIGHT JOIN -> JOIN |
| 146501 | ** FULL JOIN -> RIGHT JOIN |
| 146502 | ** |
| 146503 | ** If terms of the i-th table are used in the WHERE clause in such a |
| 146504 | ** way that the i-th table cannot be the NULL row of a join, then |
| 146505 | ** perform the appropriate simplification. This is called |
| 146506 | ** "OUTER JOIN strength reduction" in the SQLite documentation. |
| 146507 | */ |
| 146508 | if( (pItem->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 |
| 146509 | && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor, |
| 146510 | pItem->fg.jointype & JT_LTORJ) |
| 146511 | && OptimizationEnabled(db, SQLITE_SimplifyJoin) |
| 146512 | ){ |
| 146513 | if( pItem->fg.jointype & JT_LEFT ){ |
| 146514 | if( pItem->fg.jointype & JT_RIGHT ){ |
| 146515 | TREETRACE(0x1000,pParse,p, |
| 146516 | ("FULL-JOIN simplifies to RIGHT-JOIN on term %d\n",i)); |
| 146517 | pItem->fg.jointype &= ~JT_LEFT; |
| 146518 | }else{ |
| 146519 | TREETRACE(0x1000,pParse,p, |
| 146520 | ("LEFT-JOIN simplifies to JOIN on term %d\n",i)); |
| 146521 | pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER); |
| 146522 | } |
| 146523 | } |
| 146524 | if( pItem->fg.jointype & JT_LTORJ ){ |
| 146525 | for(j=i+1; j<pTabList->nSrc; j++){ |
| 146526 | SrcItem *pI2 = &pTabList->a[j]; |
| 146527 | if( pI2->fg.jointype & JT_RIGHT ){ |
| 146528 | if( pI2->fg.jointype & JT_LEFT ){ |
| 146529 | TREETRACE(0x1000,pParse,p, |
| 146530 | ("FULL-JOIN simplifies to LEFT-JOIN on term %d\n",j)); |
| 146531 | pI2->fg.jointype &= ~JT_RIGHT; |
| 146532 | }else{ |
| 146533 | TREETRACE(0x1000,pParse,p, |
| 146534 | ("RIGHT-JOIN simplifies to JOIN on term %d\n",j)); |
| 146535 | pI2->fg.jointype &= ~(JT_RIGHT|JT_OUTER); |
| 146536 | } |
| 146537 | } |
| 146538 | } |
| 146539 | for(j=pTabList->nSrc-1; j>=i; j--){ |
| 146540 | pTabList->a[j].fg.jointype &= ~JT_LTORJ; |
| 146541 | if( pTabList->a[j].fg.jointype & JT_RIGHT ) break; |
| 146542 | } |
| 146543 | } |
| 146544 | assert( pItem->iCursor>=0 ); |
| 146545 | unsetJoinExpr(p->pWhere, pItem->iCursor, |
| 146546 | pTabList->a[0].fg.jointype & JT_LTORJ); |
| 146547 | } |
| 146548 | |
| 146549 | /* No further action if this term of the FROM clause is not a subquery */ |
| 146550 | if( pSub==0 ) continue; |
| 146551 | |
| 146552 | /* Catch mismatch in the declared columns of a view and the number of |
| 146553 | ** columns in the SELECT on the RHS */ |
| 146554 | if( pTab->nCol!=pSub->pEList->nExpr ){ |
| @@ -146481,11 +146798,11 @@ | |
| 146798 | sqlite3VdbeJumpHere(v, addrTop-1); |
| 146799 | sqlite3ClearTempRegCache(pParse); |
| 146800 | }else if( pItem->fg.isCte && pItem->u2.pCteUse->addrM9e>0 ){ |
| 146801 | /* This is a CTE for which materialization code has already been |
| 146802 | ** generated. Invoke the subroutine to compute the materialization, |
| 146803 | ** the make the pItem->iCursor be a copy of the ephemeral table that |
| 146804 | ** holds the result of the materialization. */ |
| 146805 | CteUse *pCteUse = pItem->u2.pCteUse; |
| 146806 | sqlite3VdbeAddOp2(v, OP_Gosub, pCteUse->regRtn, pCteUse->addrM9e); |
| 146807 | if( pItem->iCursor!=pCteUse->iCur ){ |
| 146808 | sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur); |
| @@ -146864,11 +147181,11 @@ | |
| 147181 | /* Processing for aggregates with GROUP BY is very different and |
| 147182 | ** much more complex than aggregates without a GROUP BY. |
| 147183 | */ |
| 147184 | if( pGroupBy ){ |
| 147185 | KeyInfo *pKeyInfo; /* Keying information for the group by clause */ |
| 147186 | int addr1; /* A-vs-B comparison jump */ |
| 147187 | int addrOutputRow; /* Start of subroutine that outputs a result row */ |
| 147188 | int regOutputRow; /* Return address register for output subroutine */ |
| 147189 | int addrSetAbort; /* Set the abort flag and return */ |
| 147190 | int addrTopOfLoop; /* Top of the input loop */ |
| 147191 | int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */ |
| @@ -149244,11 +149561,11 @@ | |
| 149561 | pSrc = sqlite3SrcListDup(db, pTabList, 0); |
| 149562 | pWhere2 = sqlite3ExprDup(db, pWhere, 0); |
| 149563 | |
| 149564 | assert( pTabList->nSrc>1 ); |
| 149565 | if( pSrc ){ |
| 149566 | assert( pSrc->a[0].fg.notCte ); |
| 149567 | pSrc->a[0].iCursor = -1; |
| 149568 | pSrc->a[0].pTab->nTabRef--; |
| 149569 | pSrc->a[0].pTab = 0; |
| 149570 | } |
| 149571 | if( pPk ){ |
| @@ -150231,11 +150548,11 @@ | |
| 150548 | const char *pVTab = (const char*)sqlite3GetVTable(db, pTab); |
| 150549 | WhereInfo *pWInfo = 0; |
| 150550 | int nArg = 2 + pTab->nCol; /* Number of arguments to VUpdate */ |
| 150551 | int regArg; /* First register in VUpdate arg array */ |
| 150552 | int regRec; /* Register in which to assemble record */ |
| 150553 | int regRowid; /* Register for ephemeral table rowid */ |
| 150554 | int iCsr = pSrc->a[0].iCursor; /* Cursor used for virtual table scan */ |
| 150555 | int aDummy[2]; /* Unused arg for sqlite3WhereOkOnePass() */ |
| 150556 | int eOnePass; /* True to use onepass strategy */ |
| 150557 | int addr; /* Address of OP_OpenEphemeral */ |
| 150558 | |
| @@ -150352,11 +150669,11 @@ | |
| 150669 | /* End the virtual table scan */ |
| 150670 | if( pSrc->nSrc==1 ){ |
| 150671 | sqlite3WhereEnd(pWInfo); |
| 150672 | } |
| 150673 | |
| 150674 | /* Begin scanning through the ephemeral table. */ |
| 150675 | addr = sqlite3VdbeAddOp1(v, OP_Rewind, ephemTab); VdbeCoverage(v); |
| 150676 | |
| 150677 | /* Extract arguments from the current row of the ephemeral table and |
| 150678 | ** invoke the VUpdate method. */ |
| 150679 | for(i=0; i<nArg; i++){ |
| @@ -150909,11 +151226,11 @@ | |
| 151226 | ** can be set to 'off' for this file, as it is not recovered if a crash |
| 151227 | ** occurs anyway. The integrity of the database is maintained by a |
| 151228 | ** (possibly synchronous) transaction opened on the main database before |
| 151229 | ** sqlite3BtreeCopyFile() is called. |
| 151230 | ** |
| 151231 | ** An optimization would be to use a non-journaled pager. |
| 151232 | ** (Later:) I tried setting "PRAGMA vacuum_db.journal_mode=OFF" but |
| 151233 | ** that actually made the VACUUM run slower. Very little journalling |
| 151234 | ** actually occurs when doing a vacuum since the vacuum_db is initially |
| 151235 | ** empty. Only the journal header is written. Apparently it takes more |
| 151236 | ** time to parse and run the PRAGMA to turn journalling off than it does |
| @@ -151598,11 +151915,11 @@ | |
| 151915 | /* A slot for the record has already been allocated in the |
| 151916 | ** schema table. We just need to update that slot with all |
| 151917 | ** the information we've collected. |
| 151918 | ** |
| 151919 | ** The VM register number pParse->regRowid holds the rowid of an |
| 151920 | ** entry in the sqlite_schema table that was created for this vtab |
| 151921 | ** by sqlite3StartTable(). |
| 151922 | */ |
| 151923 | iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 151924 | sqlite3NestedParse(pParse, |
| 151925 | "UPDATE %Q." LEGACY_SCHEMA_TABLE " " |
| @@ -152342,11 +152659,11 @@ | |
| 152659 | ** exists when this routine returns or if an attempt to create it failed |
| 152660 | ** and an error message was left in pParse. |
| 152661 | ** |
| 152662 | ** An eponymous virtual table instance is one that is named after its |
| 152663 | ** module, and more importantly, does not require a CREATE VIRTUAL TABLE |
| 152664 | ** statement in order to come into existence. Eponymous virtual table |
| 152665 | ** instances always exist. They cannot be DROP-ed. |
| 152666 | ** |
| 152667 | ** Any virtual table module for which xConnect and xCreate are the same |
| 152668 | ** method can have an eponymous virtual table instance. |
| 152669 | */ |
| @@ -152533,11 +152850,11 @@ | |
| 152850 | typedef struct WhereMemBlock WhereMemBlock; |
| 152851 | typedef struct WhereRightJoin WhereRightJoin; |
| 152852 | |
| 152853 | /* |
| 152854 | ** This object is a header on a block of allocated memory that will be |
| 152855 | ** automatically freed when its WInfo object is destructed. |
| 152856 | */ |
| 152857 | struct WhereMemBlock { |
| 152858 | WhereMemBlock *pNext; /* Next block in the chain */ |
| 152859 | u64 sz; /* Bytes of space */ |
| 152860 | }; |
| @@ -152594,11 +152911,11 @@ | |
| 152911 | int nIn; /* Number of entries in aInLoop[] */ |
| 152912 | struct InLoop { |
| 152913 | int iCur; /* The VDBE cursor used by this IN operator */ |
| 152914 | int addrInTop; /* Top of the IN loop */ |
| 152915 | int iBase; /* Base register of multi-key index record */ |
| 152916 | int nPrefix; /* Number of prior entries in the key */ |
| 152917 | u8 eEndLoopOp; /* IN Loop terminator. OP_Next or OP_Prev */ |
| 152918 | } *aInLoop; /* Information about each nested IN operator */ |
| 152919 | } in; /* Used when pWLoop->wsFlags&WHERE_IN_ABLE */ |
| 152920 | Index *pCoveringIdx; /* Possible covering index for WHERE_MULTI_OR */ |
| 152921 | } u; |
| @@ -152844,11 +153161,11 @@ | |
| 153161 | u8 op; /* Split operator. TK_AND or TK_OR */ |
| 153162 | u8 hasOr; /* True if any a[].eOperator is WO_OR */ |
| 153163 | int nTerm; /* Number of terms */ |
| 153164 | int nSlot; /* Number of entries in a[] */ |
| 153165 | int nBase; /* Number of terms through the last non-Virtual */ |
| 153166 | WhereTerm *a; /* Each a[] describes a term of the WHERE clause */ |
| 153167 | #if defined(SQLITE_SMALL_STACK) |
| 153168 | WhereTerm aStatic[1]; /* Initial static space for a[] */ |
| 153169 | #else |
| 153170 | WhereTerm aStatic[8]; /* Initial static space for a[] */ |
| 153171 | #endif |
| @@ -153929,11 +154246,11 @@ | |
| 154246 | assert( pIdx!=0 ); |
| 154247 | |
| 154248 | /* Figure out how many memory cells we will need then allocate them. |
| 154249 | */ |
| 154250 | regBase = pParse->nMem + 1; |
| 154251 | nReg = nEq + nExtraReg; |
| 154252 | pParse->nMem += nReg; |
| 154253 | |
| 154254 | zAff = sqlite3DbStrDup(pParse->db,sqlite3IndexAffinityStr(pParse->db,pIdx)); |
| 154255 | assert( zAff!=0 || pParse->db->mallocFailed ); |
| 154256 | |
| @@ -153976,13 +154293,10 @@ | |
| 154293 | regBase = r1; |
| 154294 | }else{ |
| 154295 | sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j); |
| 154296 | } |
| 154297 | } |
| 154298 | if( pTerm->eOperator & WO_IN ){ |
| 154299 | if( pTerm->pExpr->flags & EP_xIsSelect ){ |
| 154300 | /* No affinity ever needs to be (or should be) applied to a value |
| 154301 | ** from the RHS of an "? IN (SELECT ...)" expression. The |
| 154302 | ** sqlite3FindInIndex() routine has already ensured that the |
| @@ -154121,11 +154435,11 @@ | |
| 154435 | ** the specified column into the new register, and |
| 154436 | ** |
| 154437 | ** 2) transform the expression node to a TK_REGISTER node that reads |
| 154438 | ** from the newly populated register. |
| 154439 | ** |
| 154440 | ** Also, if the node is a TK_COLUMN that does access the table identified |
| 154441 | ** by pCCurHint.iTabCur, and an index is being used (which we will |
| 154442 | ** know because CCurHint.pIdx!=0) then transform the TK_COLUMN into |
| 154443 | ** an access of the index rather than the original table. |
| 154444 | */ |
| 154445 | static int codeCursorHintFixExpr(Walker *pWalker, Expr *pExpr){ |
| @@ -154739,11 +155053,11 @@ | |
| 155053 | /* TK_LT */ OP_SeekLT, |
| 155054 | /* TK_GE */ OP_SeekGE |
| 155055 | }; |
| 155056 | assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */ |
| 155057 | assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */ |
| 155058 | assert( TK_GE==TK_GT+3 ); /* ... is correct. */ |
| 155059 | |
| 155060 | assert( (pStart->wtFlags & TERM_VNULL)==0 ); |
| 155061 | testcase( pStart->wtFlags & TERM_VIRTUAL ); |
| 155062 | pX = pStart->pExpr; |
| 155063 | assert( pX!=0 ); |
| @@ -155919,11 +156233,11 @@ | |
| 156233 | ************************************************************************* |
| 156234 | ** This module contains C code that generates VDBE code used to process |
| 156235 | ** the WHERE clause of SQL statements. |
| 156236 | ** |
| 156237 | ** This file was originally part of where.c but was split out to improve |
| 156238 | ** readability and editability. This file contains utility routines for |
| 156239 | ** analyzing Expr objects in the WHERE clause. |
| 156240 | */ |
| 156241 | /* #include "sqliteInt.h" */ |
| 156242 | /* #include "whereInt.h" */ |
| 156243 | |
| @@ -156708,11 +157022,11 @@ | |
| 157022 | } |
| 157023 | if( (chngToIN & sqlite3WhereGetMask(&pWInfo->sMaskSet, |
| 157024 | pOrTerm->leftCursor))==0 ){ |
| 157025 | /* This term must be of the form t1.a==t2.b where t2 is in the |
| 157026 | ** chngToIN set but t1 is not. This term will be either preceded |
| 157027 | ** or followed by an inverted copy (t2.b==t1.a). Skip this term |
| 157028 | ** and use its inversion. */ |
| 157029 | testcase( pOrTerm->wtFlags & TERM_COPIED ); |
| 157030 | testcase( pOrTerm->wtFlags & TERM_VIRTUAL ); |
| 157031 | assert( pOrTerm->wtFlags & (TERM_COPIED|TERM_VIRTUAL) ); |
| 157032 | continue; |
| @@ -156970,12 +157284,12 @@ | |
| 157284 | ){ |
| 157285 | WhereInfo *pWInfo = pWC->pWInfo; /* WHERE clause processing context */ |
| 157286 | WhereTerm *pTerm; /* The term to be analyzed */ |
| 157287 | WhereMaskSet *pMaskSet; /* Set of table index masks */ |
| 157288 | Expr *pExpr; /* The expression to be analyzed */ |
| 157289 | Bitmask prereqLeft; /* Prerequisites of the pExpr->pLeft */ |
| 157290 | Bitmask prereqAll; /* Prerequisites of pExpr */ |
| 157291 | Bitmask extraRight = 0; /* Extra dependencies on LEFT JOIN */ |
| 157292 | Expr *pStr1 = 0; /* RHS of LIKE/GLOB operator */ |
| 157293 | int isComplete = 0; /* RHS of LIKE/GLOB ends with wildcard */ |
| 157294 | int noCase = 0; /* uppercase equivalent to lowercase */ |
| 157295 | int op; /* Top-level operator. pExpr->op */ |
| @@ -159532,11 +159846,11 @@ | |
| 159846 | ** SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?; |
| 159847 | ** |
| 159848 | ** Value pLoop->nOut is currently set to the estimated number of rows |
| 159849 | ** visited for scanning (a=? AND b=?). This function reduces that estimate |
| 159850 | ** by some factor to account for the (c BETWEEN ? AND ?) expression based |
| 159851 | ** on the stat4 data for the index. this scan will be performed multiple |
| 159852 | ** times (once for each (a,b) combination that matches a=?) is dealt with |
| 159853 | ** by the caller. |
| 159854 | ** |
| 159855 | ** It does this by scanning through all stat4 samples, comparing values |
| 159856 | ** extracted from pLower and pUpper with the corresponding column in each |
| @@ -160287,11 +160601,11 @@ | |
| 160601 | /* whereLoopAddBtree() always generates and inserts the automatic index |
| 160602 | ** case first. Hence compatible candidate WhereLoops never have a larger |
| 160603 | ** rSetup. Call this SETUP-INVARIANT */ |
| 160604 | assert( p->rSetup>=pTemplate->rSetup ); |
| 160605 | |
| 160606 | /* Any loop using an application-defined index (or PRIMARY KEY or |
| 160607 | ** UNIQUE constraint) with one or more == constraints is better |
| 160608 | ** than an automatic index. Unless it is a skip-scan. */ |
| 160609 | if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 |
| 160610 | && (pTemplate->nSkip)==0 |
| 160611 | && (pTemplate->wsFlags & WHERE_INDEXED)!=0 |
| @@ -160432,11 +160746,11 @@ | |
| 160746 | whereLoopInit(p); |
| 160747 | p->pNextLoop = 0; |
| 160748 | }else{ |
| 160749 | /* We will be overwriting WhereLoop p[]. But before we do, first |
| 160750 | ** go through the rest of the list and delete any other entries besides |
| 160751 | ** p[] that are also supplanted by pTemplate */ |
| 160752 | WhereLoop **ppTail = &p->pNextLoop; |
| 160753 | WhereLoop *pToDel; |
| 160754 | while( *ppTail ){ |
| 160755 | ppTail = whereLoopFindLesser(ppTail, pTemplate); |
| 160756 | if( ppTail==0 ) break; |
| @@ -160632,11 +160946,11 @@ | |
| 160946 | } |
| 160947 | return i; |
| 160948 | } |
| 160949 | |
| 160950 | /* |
| 160951 | ** Adjust the cost C by the costMult factor T. This only occurs if |
| 160952 | ** compiled with -DSQLITE_ENABLE_COSTMULT |
| 160953 | */ |
| 160954 | #ifdef SQLITE_ENABLE_COSTMULT |
| 160955 | # define ApplyCostMultiplier(C,T) C += T |
| 160956 | #else |
| @@ -160659,11 +160973,11 @@ | |
| 160973 | WhereLoopBuilder *pBuilder, /* The WhereLoop factory */ |
| 160974 | SrcItem *pSrc, /* FROM clause term being analyzed */ |
| 160975 | Index *pProbe, /* An index on pSrc */ |
| 160976 | LogEst nInMul /* log(Number of iterations due to IN) */ |
| 160977 | ){ |
| 160978 | WhereInfo *pWInfo = pBuilder->pWInfo; /* WHERE analyze context */ |
| 160979 | Parse *pParse = pWInfo->pParse; /* Parsing context */ |
| 160980 | sqlite3 *db = pParse->db; /* Database connection malloc context */ |
| 160981 | WhereLoop *pNew; /* Template WhereLoop under construction */ |
| 160982 | WhereTerm *pTerm; /* A WhereTerm under consideration */ |
| 160983 | int opMask; /* Valid operators for constraints */ |
| @@ -160969,11 +161283,11 @@ | |
| 161283 | ** seek only. Then, if this is a non-covering index, add the cost of |
| 161284 | ** visiting the rows in the main table. */ |
| 161285 | assert( pSrc->pTab->szTabRow>0 ); |
| 161286 | if( pProbe->idxType==SQLITE_IDXTYPE_IPK ){ |
| 161287 | /* The pProbe->szIdxRow is low for an IPK table since the interior |
| 161288 | ** pages are small. Thus szIdxRow gives a good estimate of seek cost. |
| 161289 | ** But the leaf pages are full-size, so pProbe->szIdxRow would badly |
| 161290 | ** under-estimate the scanning cost. */ |
| 161291 | rCostIdx = pNew->nOut + 16; |
| 161292 | }else{ |
| 161293 | rCostIdx = pNew->nOut + 1 + (15*pProbe->szIdxRow)/pSrc->pTab->szTabRow; |
| @@ -161314,11 +161628,11 @@ | |
| 161628 | ** performance of using an index is far better than the worst-case performance |
| 161629 | ** of a full table scan. |
| 161630 | */ |
| 161631 | static int whereLoopAddBtree( |
| 161632 | WhereLoopBuilder *pBuilder, /* WHERE clause information */ |
| 161633 | Bitmask mPrereq /* Extra prerequisites for using this table */ |
| 161634 | ){ |
| 161635 | WhereInfo *pWInfo; /* WHERE analysis context */ |
| 161636 | Index *pProbe; /* An index we are evaluating */ |
| 161637 | Index sPk; /* A fake index object for the primary key */ |
| 161638 | LogEst aiRowEstPk[2]; /* The aiRowLogEst[] value for the sPk index */ |
| @@ -161821,11 +162135,11 @@ | |
| 162135 | ** This routine depends on there being a HiddenIndexInfo structure immediately |
| 162136 | ** following the sqlite3_index_info structure. |
| 162137 | ** |
| 162138 | ** Return a pointer to the collation name: |
| 162139 | ** |
| 162140 | ** 1. If there is an explicit COLLATE operator on the constraint, return it. |
| 162141 | ** |
| 162142 | ** 2. Else, if the column has an alternative collation, return that. |
| 162143 | ** |
| 162144 | ** 3. Otherwise, return "BINARY". |
| 162145 | */ |
| @@ -162885,11 +163199,11 @@ | |
| 163199 | aSortCost[isOrdered] = whereSortingCost( |
| 163200 | pWInfo, nRowEst, nOrderBy, isOrdered |
| 163201 | ); |
| 163202 | } |
| 163203 | /* TUNING: Add a small extra penalty (3) to sorting as an |
| 163204 | ** extra encouragement to the query planner to select a plan |
| 163205 | ** where the rows emerge in the correct order without any sorting |
| 163206 | ** required. */ |
| 163207 | rCost = sqlite3LogEstAdd(rUnsorted, aSortCost[isOrdered]) + 3; |
| 163208 | |
| 163209 | WHERETRACE(0x002, |
| @@ -163593,11 +163907,11 @@ | |
| 163907 | ** inner loops (or around the "..." if the test occurs within the inner- |
| 163908 | ** most loop) |
| 163909 | ** |
| 163910 | ** OUTER JOINS |
| 163911 | ** |
| 163912 | ** An outer join of tables t1 and t2 is conceptually coded as follows: |
| 163913 | ** |
| 163914 | ** foreach row1 in t1 do |
| 163915 | ** flag = 0 |
| 163916 | ** foreach row2 in t2 do |
| 163917 | ** start: |
| @@ -163748,11 +164062,11 @@ | |
| 164062 | }else{ |
| 164063 | /* Assign a bit from the bitmask to every term in the FROM clause. |
| 164064 | ** |
| 164065 | ** The N-th term of the FROM clause is assigned a bitmask of 1<<N. |
| 164066 | ** |
| 164067 | ** The rule of the previous sentence ensures that if X is the bitmask for |
| 164068 | ** a table T, then X-1 is the bitmask for all other tables to the left of T. |
| 164069 | ** Knowing the bitmask for all tables to the left of a left join is |
| 164070 | ** important. Ticket #3015. |
| 164071 | ** |
| 164072 | ** Note that bitmasks are created for all pTabList->nSrc tables in |
| @@ -164729,11 +165043,11 @@ | |
| 165043 | ** last_value(expr) |
| 165044 | ** nth_value(expr, N) |
| 165045 | ** |
| 165046 | ** These are the same built-in window functions supported by Postgres. |
| 165047 | ** Although the behaviour of aggregate window functions (functions that |
| 165048 | ** can be used as either aggregates or window functions) allows them to |
| 165049 | ** be implemented using an API, built-in window functions are much more |
| 165050 | ** esoteric. Additionally, some window functions (e.g. nth_value()) |
| 165051 | ** may only be implemented by caching the entire partition in memory. |
| 165052 | ** As such, some built-in window functions use the same API as aggregate |
| 165053 | ** window functions and some are implemented directly using VDBE |
| @@ -165259,11 +165573,11 @@ | |
| 165573 | ** linked list of WINDOW definitions for the current SELECT statement. |
| 165574 | ** Argument pFunc is the function definition just resolved and pWin |
| 165575 | ** is the Window object representing the associated OVER clause. This |
| 165576 | ** function updates the contents of pWin as follows: |
| 165577 | ** |
| 165578 | ** * If the OVER clause referred to a named window (as in "max(x) OVER win"), |
| 165579 | ** search list pList for a matching WINDOW definition, and update pWin |
| 165580 | ** accordingly. If no such WINDOW clause can be found, leave an error |
| 165581 | ** in pParse. |
| 165582 | ** |
| 165583 | ** * If the function is a built-in window function that requires the |
| @@ -165880,11 +166194,11 @@ | |
| 166194 | } |
| 166195 | return pWin; |
| 166196 | } |
| 166197 | |
| 166198 | /* |
| 166199 | ** Window *pWin has just been created from a WINDOW clause. Token pBase |
| 166200 | ** is the base window. Earlier windows from the same WINDOW clause are |
| 166201 | ** stored in the linked list starting at pWin->pNextWin. This function |
| 166202 | ** either updates *pWin according to the base specification, or else |
| 166203 | ** leaves an error in pParse. |
| 166204 | */ |
| @@ -166186,11 +166500,11 @@ | |
| 166500 | ** start,current,end |
| 166501 | ** Consider a window-frame similar to the following: |
| 166502 | ** |
| 166503 | ** (ORDER BY a, b GROUPS BETWEEN 2 PRECEDING AND 2 FOLLOWING) |
| 166504 | ** |
| 166505 | ** The windows functions implementation caches the input rows in a temp |
| 166506 | ** table, sorted by "a, b" (it actually populates the cache lazily, and |
| 166507 | ** aggressively removes rows once they are no longer required, but that's |
| 166508 | ** a mere detail). It keeps three cursors open on the temp table. One |
| 166509 | ** (current) that points to the next row to return to the query engine |
| 166510 | ** once its window function values have been calculated. Another (end) |
| @@ -167195,11 +167509,11 @@ | |
| 167509 | ** RETURN_ROW |
| 167510 | ** } |
| 167511 | ** |
| 167512 | ** For the most part, the patterns above are adapted to support UNBOUNDED by |
| 167513 | ** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and |
| 167514 | ** CURRENT ROW by assuming that it is equivalent to "0 PRECEDING/FOLLOWING". |
| 167515 | ** This is optimized of course - branches that will never be taken and |
| 167516 | ** conditions that are always true are omitted from the VM code. The only |
| 167517 | ** exceptional case is: |
| 167518 | ** |
| 167519 | ** ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING |
| @@ -167474,11 +167788,11 @@ | |
| 167788 | s.eDelete = WINDOW_AGGINVERSE; |
| 167789 | break; |
| 167790 | } |
| 167791 | |
| 167792 | /* Allocate registers for the array of values from the sub-query, the |
| 167793 | ** same values in record form, and the rowid used to insert said record |
| 167794 | ** into the ephemeral table. */ |
| 167795 | regNew = pParse->nMem+1; |
| 167796 | pParse->nMem += nInput; |
| 167797 | regRecord = ++pParse->nMem; |
| 167798 | s.regRowid = ++pParse->nMem; |
| @@ -167715,11 +168029,12 @@ | |
| 168029 | #endif /* SQLITE_OMIT_WINDOWFUNC */ |
| 168030 | |
| 168031 | /************** End of window.c **********************************************/ |
| 168032 | /************** Begin file parse.c *******************************************/ |
| 168033 | /* This file is automatically generated by Lemon from input grammar |
| 168034 | ** source file "parse.y". |
| 168035 | */ |
| 168036 | /* |
| 168037 | ** 2001-09-15 |
| 168038 | ** |
| 168039 | ** The author disclaims copyright to this source code. In place of |
| 168040 | ** a legal notice, here is a blessing: |
| @@ -167732,11 +168047,11 @@ | |
| 168047 | ** This file contains SQLite's SQL parser. |
| 168048 | ** |
| 168049 | ** The canonical source code to this file ("parse.y") is a Lemon grammar |
| 168050 | ** file that specifies the input grammar and actions to take while parsing. |
| 168051 | ** That input file is processed by Lemon to generate a C-language |
| 168052 | ** implementation of a parser for the given grammar. You might be reading |
| 168053 | ** this comment as part of the translated C-code. Edits should be made |
| 168054 | ** to the original parse.y sources. |
| 168055 | */ |
| 168056 | |
| 168057 | /* #include "sqliteInt.h" */ |
| @@ -174928,16 +175243,10 @@ | |
| 175243 | |
| 175244 | /* |
| 175245 | ** Forward declarations of external module initializer functions |
| 175246 | ** for modules that need them. |
| 175247 | */ |
| 175248 | #ifdef SQLITE_ENABLE_FTS5 |
| 175249 | SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*); |
| 175250 | #endif |
| 175251 | #ifdef SQLITE_ENABLE_STMTVTAB |
| 175252 | SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3*); |
| @@ -174946,16 +175255,10 @@ | |
| 175255 | /* |
| 175256 | ** An array of pointers to extension initializer functions for |
| 175257 | ** built-in extensions. |
| 175258 | */ |
| 175259 | static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = { |
| 175260 | #ifdef SQLITE_ENABLE_FTS3 |
| 175261 | sqlite3Fts3Init, |
| 175262 | #endif |
| 175263 | #ifdef SQLITE_ENABLE_FTS5 |
| 175264 | sqlite3Fts5Init, |
| @@ -178204,11 +178507,11 @@ | |
| 178507 | ** 2 on off |
| 178508 | ** 1 off on |
| 178509 | ** 0 off off |
| 178510 | ** |
| 178511 | ** Legacy behavior is 3 (double-quoted string literals are allowed anywhere) |
| 178512 | ** and so that is the default. But developers are encouraged to use |
| 178513 | ** -DSQLITE_DQS=0 (best) or -DSQLITE_DQS=1 (second choice) if possible. |
| 178514 | */ |
| 178515 | #if !defined(SQLITE_DQS) |
| 178516 | # define SQLITE_DQS 3 |
| 178517 | #endif |
| @@ -178739,11 +179042,11 @@ | |
| 179042 | goto error_out; |
| 179043 | } |
| 179044 | |
| 179045 | /* Find the column for which info is requested */ |
| 179046 | if( zColumnName==0 ){ |
| 179047 | /* Query for existence of table only */ |
| 179048 | }else{ |
| 179049 | for(iCol=0; iCol<pTab->nCol; iCol++){ |
| 179050 | pCol = &pTab->aCol[iCol]; |
| 179051 | if( 0==sqlite3StrICmp(pCol->zCnName, zColumnName) ){ |
| 179052 | break; |
| @@ -179179,11 +179482,11 @@ | |
| 179482 | ** |
| 179483 | ** Set or clear a flag that indicates that the database file is always well- |
| 179484 | ** formed and never corrupt. This flag is clear by default, indicating that |
| 179485 | ** database files might have arbitrary corruption. Setting the flag during |
| 179486 | ** testing causes certain assert() statements in the code to be activated |
| 179487 | ** that demonstrate invariants on well-formed database files. |
| 179488 | */ |
| 179489 | case SQLITE_TESTCTRL_NEVER_CORRUPT: { |
| 179490 | sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int); |
| 179491 | break; |
| 179492 | } |
| @@ -179333,11 +179636,11 @@ | |
| 179636 | ** |
| 179637 | ** "ptr" is a pointer to a u32. |
| 179638 | ** |
| 179639 | ** op==0 Store the current sqlite3TreeTrace in *ptr |
| 179640 | ** op==1 Set sqlite3TreeTrace to the value *ptr |
| 179641 | ** op==2 Store the current sqlite3WhereTrace in *ptr |
| 179642 | ** op==3 Set sqlite3WhereTrace to the value *ptr |
| 179643 | */ |
| 179644 | case SQLITE_TESTCTRL_TRACEFLAGS: { |
| 179645 | int opTrace = va_arg(ap, int); |
| 179646 | u32 *ptr = va_arg(ap, u32*); |
| @@ -179669,11 +179972,11 @@ | |
| 179972 | #endif /* SQLITE_OMIT_WAL */ |
| 179973 | return rc; |
| 179974 | } |
| 179975 | |
| 179976 | /* |
| 179977 | ** Open a read-transaction on the snapshot identified by pSnapshot. |
| 179978 | */ |
| 179979 | SQLITE_API int sqlite3_snapshot_open( |
| 179980 | sqlite3 *db, |
| 179981 | const char *zDb, |
| 179982 | sqlite3_snapshot *pSnapshot |
| @@ -195704,10 +196007,11 @@ | |
| 196007 | memset(&pNode->block.a[nRoot], 0, FTS3_NODE_PADDING); |
| 196008 | } |
| 196009 | |
| 196010 | for(i=nHeight; i>=0 && rc==SQLITE_OK; i--){ |
| 196011 | NodeReader reader; |
| 196012 | memset(&reader, 0, sizeof(reader)); |
| 196013 | pNode = &pWriter->aNodeWriter[i]; |
| 196014 | |
| 196015 | if( pNode->block.a){ |
| 196016 | rc = nodeReaderInit(&reader, pNode->block.a, pNode->block.n); |
| 196017 | while( reader.aNode && rc==SQLITE_OK ) rc = nodeReaderNext(&reader); |
| @@ -200348,11 +200652,11 @@ | |
| 200652 | } |
| 200653 | } |
| 200654 | } |
| 200655 | |
| 200656 | /* |
| 200657 | ** Return a JsonNode and all its descendants as a JSON string. |
| 200658 | */ |
| 200659 | static void jsonReturnJson( |
| 200660 | JsonNode *pNode, /* Node to return */ |
| 200661 | sqlite3_context *pCtx, /* Return value for this function */ |
| 200662 | sqlite3_value **aReplace /* Array of replacement values */ |
| @@ -202420,11 +202724,11 @@ | |
| 202724 | UNUSED_PARAMETER(argc); |
| 202725 | UNUSED_PARAMETER(argv); |
| 202726 | pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0); |
| 202727 | #ifdef NEVER |
| 202728 | /* pStr is always non-NULL since jsonArrayStep() or jsonObjectStep() will |
| 202729 | ** always have been called to initialize it */ |
| 202730 | if( NEVER(!pStr) ) return; |
| 202731 | #endif |
| 202732 | z = pStr->zBuf; |
| 202733 | for(i=1; i<pStr->nUsed && ((c = z[i])!=',' || inStr || nNest); i++){ |
| 202734 | if( c=='"' ){ |
| @@ -205011,11 +205315,24 @@ | |
| 205315 | break; |
| 205316 | } |
| 205317 | p->pInfo->nCoord = pRtree->nDim2; |
| 205318 | p->pInfo->anQueue = pCsr->anQueue; |
| 205319 | p->pInfo->mxLevel = pRtree->iDepth + 1; |
| 205320 | }else if( eType==SQLITE_INTEGER ){ |
| 205321 | sqlite3_int64 iVal = sqlite3_value_int64(argv[ii]); |
| 205322 | #ifdef SQLITE_RTREE_INT_ONLY |
| 205323 | p->u.rValue = iVal; |
| 205324 | #else |
| 205325 | p->u.rValue = (double)iVal; |
| 205326 | if( iVal>=((sqlite3_int64)1)<<48 |
| 205327 | || -iVal>=((sqlite3_int64)1)<<48 |
| 205328 | ){ |
| 205329 | if( p->op==RTREE_LT ) p->op = RTREE_LE; |
| 205330 | if( p->op==RTREE_GT ) p->op = RTREE_GE; |
| 205331 | } |
| 205332 | #endif |
| 205333 | }else if( eType==SQLITE_FLOAT ){ |
| 205334 | #ifdef SQLITE_RTREE_INT_ONLY |
| 205335 | p->u.rValue = sqlite3_value_int64(argv[ii]); |
| 205336 | #else |
| 205337 | p->u.rValue = sqlite3_value_double(argv[ii]); |
| 205338 | #endif |
| @@ -205142,24 +205459,25 @@ | |
| 205459 | if( p->usable |
| 205460 | && ((p->iColumn>0 && p->iColumn<=pRtree->nDim2) |
| 205461 | || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) |
| 205462 | ){ |
| 205463 | u8 op; |
| 205464 | u8 doOmit = 1; |
| 205465 | switch( p->op ){ |
| 205466 | case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; doOmit = 0; break; |
| 205467 | case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; doOmit = 0; break; |
| 205468 | case SQLITE_INDEX_CONSTRAINT_LE: op = RTREE_LE; break; |
| 205469 | case SQLITE_INDEX_CONSTRAINT_LT: op = RTREE_LT; doOmit = 0; break; |
| 205470 | case SQLITE_INDEX_CONSTRAINT_GE: op = RTREE_GE; break; |
| 205471 | case SQLITE_INDEX_CONSTRAINT_MATCH: op = RTREE_MATCH; break; |
| 205472 | default: op = 0; break; |
| 205473 | } |
| 205474 | if( op ){ |
| 205475 | zIdxStr[iIdx++] = op; |
| 205476 | zIdxStr[iIdx++] = (char)(p->iColumn - 1 + '0'); |
| 205477 | pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2); |
| 205478 | pIdxInfo->aConstraintUsage[ii].omit = doOmit; |
| 205479 | } |
| 205480 | } |
| 205481 | } |
| 205482 | |
| 205483 | pIdxInfo->idxNum = 2; |
| @@ -225250,11 +225568,12 @@ | |
| 225568 | #define FTS5_COMMA 13 |
| 225569 | #define FTS5_PLUS 14 |
| 225570 | #define FTS5_STAR 15 |
| 225571 | |
| 225572 | /* This file is automatically generated by Lemon from input grammar |
| 225573 | ** source file "fts5parse.y". |
| 225574 | */ |
| 225575 | /* |
| 225576 | ** 2000-05-29 |
| 225577 | ** |
| 225578 | ** The author disclaims copyright to this source code. In place of |
| 225579 | ** a legal notice, here is a blessing: |
| @@ -237173,11 +237492,11 @@ | |
| 237492 | if( bDetailNone==0 ) fts5DataWrite(p, iRowid, aEmpty, sizeof(aEmpty)); |
| 237493 | fts5DataRelease(pLeaf); |
| 237494 | pLeaf = 0; |
| 237495 | }else if( bDetailNone ){ |
| 237496 | break; |
| 237497 | }else if( iNext>=pLeaf->szLeaf || pLeaf->nn<pLeaf->szLeaf || iNext<4 ){ |
| 237498 | p->rc = FTS5_CORRUPT; |
| 237499 | break; |
| 237500 | }else{ |
| 237501 | int nShift = iNext - 4; |
| 237502 | int nPg; |
| @@ -237377,11 +237696,13 @@ | |
| 237696 | }else{ |
| 237697 | if( iKey!=1 ){ |
| 237698 | iOff += sqlite3Fts5PutVarint(&aPg[iOff], nPrefix); |
| 237699 | } |
| 237700 | iOff += sqlite3Fts5PutVarint(&aPg[iOff], nSuffix); |
| 237701 | if( nPrefix2>pSeg->term.n ){ |
| 237702 | p->rc = FTS5_CORRUPT; |
| 237703 | }else if( nPrefix2>nPrefix ){ |
| 237704 | memcpy(&aPg[iOff], &pSeg->term.p[nPrefix], nPrefix2-nPrefix); |
| 237705 | iOff += (nPrefix2-nPrefix); |
| 237706 | } |
| 237707 | memmove(&aPg[iOff], &aPg[iNextOff], nSuffix2); |
| 237708 | iOff += nSuffix2; |
| @@ -242633,11 +242954,11 @@ | |
| 242954 | int nArg, /* Number of args */ |
| 242955 | sqlite3_value **apUnused /* Function arguments */ |
| 242956 | ){ |
| 242957 | assert( nArg==0 ); |
| 242958 | UNUSED_PARAM2(nArg, apUnused); |
| 242959 | sqlite3_result_text(pCtx, "fts5: 2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9", -1, SQLITE_TRANSIENT); |
| 242960 | } |
| 242961 | |
| 242962 | /* |
| 242963 | ** Return true if zName is the extension on one of the shadow tables used |
| 242964 | ** by this module. |
| 242965 |
+35
-20
| --- extsrc/sqlite3.h | ||
| +++ extsrc/sqlite3.h | ||
| @@ -144,13 +144,13 @@ | ||
| 144 | 144 | ** |
| 145 | 145 | ** See also: [sqlite3_libversion()], |
| 146 | 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | 148 | */ |
| 149 | -#define SQLITE_VERSION "3.42.0" | |
| 150 | -#define SQLITE_VERSION_NUMBER 3042000 | |
| 151 | -#define SQLITE_SOURCE_ID "2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0" | |
| 149 | +#define SQLITE_VERSION "3.43.0" | |
| 150 | +#define SQLITE_VERSION_NUMBER 3043000 | |
| 151 | +#define SQLITE_SOURCE_ID "2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9" | |
| 152 | 152 | |
| 153 | 153 | /* |
| 154 | 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | 156 | ** |
| @@ -1188,11 +1188,11 @@ | ||
| 1188 | 1188 | ** the database is not a wal-mode db, or if there is no such connection in any |
| 1189 | 1189 | ** other process. This opcode cannot be used to detect transactions opened |
| 1190 | 1190 | ** by clients within the current process, only within other processes. |
| 1191 | 1191 | ** |
| 1192 | 1192 | ** <li>[[SQLITE_FCNTL_CKSM_FILE]] |
| 1193 | -** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the | |
| 1193 | +** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the | |
| 1194 | 1194 | ** [checksum VFS shim] only. |
| 1195 | 1195 | ** |
| 1196 | 1196 | ** <li>[[SQLITE_FCNTL_RESET_CACHE]] |
| 1197 | 1197 | ** If there is currently no transaction open on the database, and the |
| 1198 | 1198 | ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control |
| @@ -2452,11 +2452,11 @@ | ||
| 2452 | 2452 | ** 3.0.0. |
| 2453 | 2453 | ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on, |
| 2454 | 2454 | ** the [VACUUM] command will fail with an obscure error when attempting to |
| 2455 | 2455 | ** process a table with generated columns and a descending index. This is |
| 2456 | 2456 | ** not considered a bug since SQLite versions 3.3.0 and earlier do not support |
| 2457 | -** either generated columns or decending indexes. | |
| 2457 | +** either generated columns or descending indexes. | |
| 2458 | 2458 | ** </dd> |
| 2459 | 2459 | ** |
| 2460 | 2460 | ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]] |
| 2461 | 2461 | ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt> |
| 2462 | 2462 | ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in |
| @@ -2733,10 +2733,11 @@ | ||
| 2733 | 2733 | ** SQL statements is a no-op and has no effect on SQL statements |
| 2734 | 2734 | ** that are started after the sqlite3_interrupt() call returns. |
| 2735 | 2735 | ** |
| 2736 | 2736 | ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether |
| 2737 | 2737 | ** or not an interrupt is currently in effect for [database connection] D. |
| 2738 | +** It returns 1 if an interrupt is currently in effect, or 0 otherwise. | |
| 2738 | 2739 | */ |
| 2739 | 2740 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 2740 | 2741 | SQLITE_API int sqlite3_is_interrupted(sqlite3*); |
| 2741 | 2742 | |
| 2742 | 2743 | /* |
| @@ -3386,12 +3387,14 @@ | ||
| 3386 | 3387 | ** and context pointer P. ^If the X callback is |
| 3387 | 3388 | ** NULL or if the M mask is zero, then tracing is disabled. The |
| 3388 | 3389 | ** M argument should be the bitwise OR-ed combination of |
| 3389 | 3390 | ** zero or more [SQLITE_TRACE] constants. |
| 3390 | 3391 | ** |
| 3391 | -** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides | |
| 3392 | -** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2(). | |
| 3392 | +** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P) | |
| 3393 | +** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or | |
| 3394 | +** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each | |
| 3395 | +** database connection may have at most one trace callback. | |
| 3393 | 3396 | ** |
| 3394 | 3397 | ** ^The X callback is invoked whenever any of the events identified by |
| 3395 | 3398 | ** mask M occur. ^The integer return value from the callback is currently |
| 3396 | 3399 | ** ignored, though this may change in future releases. Callback |
| 3397 | 3400 | ** implementations should return zero to ensure future compatibility. |
| @@ -3756,11 +3759,11 @@ | ||
| 3756 | 3759 | ** |
| 3757 | 3760 | ** The first parameter to these interfaces (hereafter referred to |
| 3758 | 3761 | ** as F) must be one of: |
| 3759 | 3762 | ** <ul> |
| 3760 | 3763 | ** <li> A database filename pointer created by the SQLite core and |
| 3761 | -** passed into the xOpen() method of a VFS implemention, or | |
| 3764 | +** passed into the xOpen() method of a VFS implementation, or | |
| 3762 | 3765 | ** <li> A filename obtained from [sqlite3_db_filename()], or |
| 3763 | 3766 | ** <li> A new filename constructed using [sqlite3_create_filename()]. |
| 3764 | 3767 | ** </ul> |
| 3765 | 3768 | ** If the F parameter is not one of the above, then the behavior is |
| 3766 | 3769 | ** undefined and probably undesirable. Older versions of SQLite were |
| @@ -3869,11 +3872,11 @@ | ||
| 3869 | 3872 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); |
| 3870 | 3873 | |
| 3871 | 3874 | /* |
| 3872 | 3875 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 3873 | 3876 | ** |
| 3874 | -** These interfces are provided for use by [VFS shim] implementations and | |
| 3877 | +** These interfaces are provided for use by [VFS shim] implementations and | |
| 3875 | 3878 | ** are not useful outside of that context. |
| 3876 | 3879 | ** |
| 3877 | 3880 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 3878 | 3881 | ** database filename D with corresponding journal file J and WAL file W and |
| 3879 | 3882 | ** with N URI parameters key/values pairs in the array P. The result from |
| @@ -4579,11 +4582,11 @@ | ||
| 4579 | 4582 | ** These three options exist: |
| 4580 | 4583 | ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished |
| 4581 | 4584 | ** with it may be passed. ^It is called to dispose of the BLOB or string even |
| 4582 | 4585 | ** if the call to the bind API fails, except the destructor is not called if |
| 4583 | 4586 | ** the third parameter is a NULL pointer or the fourth parameter is negative. |
| 4584 | -** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that | |
| 4587 | +** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that | |
| 4585 | 4588 | ** the application remains responsible for disposing of the object. ^In this |
| 4586 | 4589 | ** case, the object and the provided pointer to it must remain valid until |
| 4587 | 4590 | ** either the prepared statement is finalized or the same SQL parameter is |
| 4588 | 4591 | ** bound to something else, whichever occurs sooner. |
| 4589 | 4592 | ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
| @@ -5258,18 +5261,30 @@ | ||
| 5258 | 5261 | ** Use [sqlite3_clear_bindings()] to reset the bindings. |
| 5259 | 5262 | ** |
| 5260 | 5263 | ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
| 5261 | 5264 | ** back to the beginning of its program. |
| 5262 | 5265 | ** |
| 5263 | -** ^If the most recent call to [sqlite3_step(S)] for the | |
| 5264 | -** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], | |
| 5265 | -** or if [sqlite3_step(S)] has never before been called on S, | |
| 5266 | -** then [sqlite3_reset(S)] returns [SQLITE_OK]. | |
| 5266 | +** ^The return code from [sqlite3_reset(S)] indicates whether or not | |
| 5267 | +** the previous evaluation of prepared statement S completed successfully. | |
| 5268 | +** ^If [sqlite3_step(S)] has never before been called on S or if | |
| 5269 | +** [sqlite3_step(S)] has not been called since the previous call | |
| 5270 | +** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return | |
| 5271 | +** [SQLITE_OK]. | |
| 5267 | 5272 | ** |
| 5268 | 5273 | ** ^If the most recent call to [sqlite3_step(S)] for the |
| 5269 | 5274 | ** [prepared statement] S indicated an error, then |
| 5270 | 5275 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
| 5276 | +** ^The [sqlite3_reset(S)] interface might also return an [error code] | |
| 5277 | +** if there were no prior errors but the process of resetting | |
| 5278 | +** the prepared statement caused a new error. ^For example, if an | |
| 5279 | +** [INSERT] statement with a [RETURNING] clause is only stepped one time, | |
| 5280 | +** that one call to [sqlite3_step(S)] might return SQLITE_ROW but | |
| 5281 | +** the overall statement might still fail and the [sqlite3_reset(S)] call | |
| 5282 | +** might return SQLITE_BUSY if locking constraints prevent the | |
| 5283 | +** database change from committing. Therefore, it is important that | |
| 5284 | +** applications check the return code from [sqlite3_reset(S)] even if | |
| 5285 | +** no prior call to [sqlite3_step(S)] indicated a problem. | |
| 5271 | 5286 | ** |
| 5272 | 5287 | ** ^The [sqlite3_reset(S)] interface does not change the values |
| 5273 | 5288 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
| 5274 | 5289 | */ |
| 5275 | 5290 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| @@ -5482,11 +5497,11 @@ | ||
| 5482 | 5497 | ** <p> |
| 5483 | 5498 | ** The SQLITE_DIRECTONLY flag is recommended for any |
| 5484 | 5499 | ** [application-defined SQL function] |
| 5485 | 5500 | ** that has side-effects or that could potentially leak sensitive information. |
| 5486 | 5501 | ** This will prevent attacks in which an application is tricked |
| 5487 | -** into using a database file that has had its schema surreptiously | |
| 5502 | +** into using a database file that has had its schema surreptitiously | |
| 5488 | 5503 | ** modified to invoke the application-defined function in ways that are |
| 5489 | 5504 | ** harmful. |
| 5490 | 5505 | ** <p> |
| 5491 | 5506 | ** Some people say it is good practice to set SQLITE_DIRECTONLY on all |
| 5492 | 5507 | ** [application-defined SQL functions], regardless of whether or not they |
| @@ -9191,12 +9206,12 @@ | ||
| 9191 | 9206 | ** ^(There may be at most one unlock-notify callback registered by a |
| 9192 | 9207 | ** blocked connection. If sqlite3_unlock_notify() is called when the |
| 9193 | 9208 | ** blocked connection already has a registered unlock-notify callback, |
| 9194 | 9209 | ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is |
| 9195 | 9210 | ** called with a NULL pointer as its second argument, then any existing |
| 9196 | -** unlock-notify callback is canceled. ^The blocked connections | |
| 9197 | -** unlock-notify callback may also be canceled by closing the blocked | |
| 9211 | +** unlock-notify callback is cancelled. ^The blocked connections | |
| 9212 | +** unlock-notify callback may also be cancelled by closing the blocked | |
| 9198 | 9213 | ** connection using [sqlite3_close()]. |
| 9199 | 9214 | ** |
| 9200 | 9215 | ** The unlock-notify callback is not reentrant. If an application invokes |
| 9201 | 9216 | ** any sqlite3_xxx API functions from within an unlock-notify callback, a |
| 9202 | 9217 | ** crash or deadlock may be the result. |
| @@ -9615,11 +9630,11 @@ | ||
| 9615 | 9630 | ** </dd> |
| 9616 | 9631 | ** |
| 9617 | 9632 | ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 9618 | 9633 | ** <dd>Calls of the form |
| 9619 | 9634 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 9620 | -** the [xConnect] or [xCreate] methods of a [virtual table] implmentation | |
| 9635 | +** the [xConnect] or [xCreate] methods of a [virtual table] implementation | |
| 9621 | 9636 | ** prohibits that virtual table from being used from within triggers and |
| 9622 | 9637 | ** views. |
| 9623 | 9638 | ** </dd> |
| 9624 | 9639 | ** |
| 9625 | 9640 | ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| @@ -9805,11 +9820,11 @@ | ||
| 9805 | 9820 | ** ^(A constraint on a virtual table of the form |
| 9806 | 9821 | ** "[IN operator|column IN (...)]" is |
| 9807 | 9822 | ** communicated to the xBestIndex method as a |
| 9808 | 9823 | ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use |
| 9809 | 9824 | ** this constraint, it must set the corresponding |
| 9810 | -** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under | |
| 9825 | +** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under | |
| 9811 | 9826 | ** the usual mode of handling IN operators, SQLite generates [bytecode] |
| 9812 | 9827 | ** that invokes the [xFilter|xFilter() method] once for each value |
| 9813 | 9828 | ** on the right-hand side of the IN operator.)^ Thus the virtual table |
| 9814 | 9829 | ** only sees a single value from the right-hand side of the IN operator |
| 9815 | 9830 | ** at a time. |
| @@ -10234,11 +10249,11 @@ | ||
| 10234 | 10249 | ** triggers; and so forth. |
| 10235 | 10250 | ** |
| 10236 | 10251 | ** When the [sqlite3_blob_write()] API is used to update a blob column, |
| 10237 | 10252 | ** the pre-update hook is invoked with SQLITE_DELETE. This is because the |
| 10238 | 10253 | ** in this case the new values are not available. In this case, when a |
| 10239 | -** callback made with op==SQLITE_DELETE is actuall a write using the | |
| 10254 | +** callback made with op==SQLITE_DELETE is actually a write using the | |
| 10240 | 10255 | ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns |
| 10241 | 10256 | ** the index of the column being written. In other cases, where the |
| 10242 | 10257 | ** pre-update hook is being invoked for some other reason, including a |
| 10243 | 10258 | ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1. |
| 10244 | 10259 | ** |
| 10245 | 10260 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -144,13 +144,13 @@ | |
| 144 | ** |
| 145 | ** See also: [sqlite3_libversion()], |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.42.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3042000 |
| 151 | #define SQLITE_SOURCE_ID "2023-05-16 12:36:15 831d0fb2836b71c9bc51067c49fee4b8f18047814f2ff22d817d25195cf350b0" |
| 152 | |
| 153 | /* |
| 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | ** |
| @@ -1188,11 +1188,11 @@ | |
| 1188 | ** the database is not a wal-mode db, or if there is no such connection in any |
| 1189 | ** other process. This opcode cannot be used to detect transactions opened |
| 1190 | ** by clients within the current process, only within other processes. |
| 1191 | ** |
| 1192 | ** <li>[[SQLITE_FCNTL_CKSM_FILE]] |
| 1193 | ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the |
| 1194 | ** [checksum VFS shim] only. |
| 1195 | ** |
| 1196 | ** <li>[[SQLITE_FCNTL_RESET_CACHE]] |
| 1197 | ** If there is currently no transaction open on the database, and the |
| 1198 | ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control |
| @@ -2452,11 +2452,11 @@ | |
| 2452 | ** 3.0.0. |
| 2453 | ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on, |
| 2454 | ** the [VACUUM] command will fail with an obscure error when attempting to |
| 2455 | ** process a table with generated columns and a descending index. This is |
| 2456 | ** not considered a bug since SQLite versions 3.3.0 and earlier do not support |
| 2457 | ** either generated columns or decending indexes. |
| 2458 | ** </dd> |
| 2459 | ** |
| 2460 | ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]] |
| 2461 | ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt> |
| 2462 | ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in |
| @@ -2733,10 +2733,11 @@ | |
| 2733 | ** SQL statements is a no-op and has no effect on SQL statements |
| 2734 | ** that are started after the sqlite3_interrupt() call returns. |
| 2735 | ** |
| 2736 | ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether |
| 2737 | ** or not an interrupt is currently in effect for [database connection] D. |
| 2738 | */ |
| 2739 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 2740 | SQLITE_API int sqlite3_is_interrupted(sqlite3*); |
| 2741 | |
| 2742 | /* |
| @@ -3386,12 +3387,14 @@ | |
| 3386 | ** and context pointer P. ^If the X callback is |
| 3387 | ** NULL or if the M mask is zero, then tracing is disabled. The |
| 3388 | ** M argument should be the bitwise OR-ed combination of |
| 3389 | ** zero or more [SQLITE_TRACE] constants. |
| 3390 | ** |
| 3391 | ** ^Each call to either sqlite3_trace() or sqlite3_trace_v2() overrides |
| 3392 | ** (cancels) any prior calls to sqlite3_trace() or sqlite3_trace_v2(). |
| 3393 | ** |
| 3394 | ** ^The X callback is invoked whenever any of the events identified by |
| 3395 | ** mask M occur. ^The integer return value from the callback is currently |
| 3396 | ** ignored, though this may change in future releases. Callback |
| 3397 | ** implementations should return zero to ensure future compatibility. |
| @@ -3756,11 +3759,11 @@ | |
| 3756 | ** |
| 3757 | ** The first parameter to these interfaces (hereafter referred to |
| 3758 | ** as F) must be one of: |
| 3759 | ** <ul> |
| 3760 | ** <li> A database filename pointer created by the SQLite core and |
| 3761 | ** passed into the xOpen() method of a VFS implemention, or |
| 3762 | ** <li> A filename obtained from [sqlite3_db_filename()], or |
| 3763 | ** <li> A new filename constructed using [sqlite3_create_filename()]. |
| 3764 | ** </ul> |
| 3765 | ** If the F parameter is not one of the above, then the behavior is |
| 3766 | ** undefined and probably undesirable. Older versions of SQLite were |
| @@ -3869,11 +3872,11 @@ | |
| 3869 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); |
| 3870 | |
| 3871 | /* |
| 3872 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 3873 | ** |
| 3874 | ** These interfces are provided for use by [VFS shim] implementations and |
| 3875 | ** are not useful outside of that context. |
| 3876 | ** |
| 3877 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 3878 | ** database filename D with corresponding journal file J and WAL file W and |
| 3879 | ** with N URI parameters key/values pairs in the array P. The result from |
| @@ -4579,11 +4582,11 @@ | |
| 4579 | ** These three options exist: |
| 4580 | ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished |
| 4581 | ** with it may be passed. ^It is called to dispose of the BLOB or string even |
| 4582 | ** if the call to the bind API fails, except the destructor is not called if |
| 4583 | ** the third parameter is a NULL pointer or the fourth parameter is negative. |
| 4584 | ** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that |
| 4585 | ** the application remains responsible for disposing of the object. ^In this |
| 4586 | ** case, the object and the provided pointer to it must remain valid until |
| 4587 | ** either the prepared statement is finalized or the same SQL parameter is |
| 4588 | ** bound to something else, whichever occurs sooner. |
| 4589 | ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
| @@ -5258,18 +5261,30 @@ | |
| 5258 | ** Use [sqlite3_clear_bindings()] to reset the bindings. |
| 5259 | ** |
| 5260 | ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
| 5261 | ** back to the beginning of its program. |
| 5262 | ** |
| 5263 | ** ^If the most recent call to [sqlite3_step(S)] for the |
| 5264 | ** [prepared statement] S returned [SQLITE_ROW] or [SQLITE_DONE], |
| 5265 | ** or if [sqlite3_step(S)] has never before been called on S, |
| 5266 | ** then [sqlite3_reset(S)] returns [SQLITE_OK]. |
| 5267 | ** |
| 5268 | ** ^If the most recent call to [sqlite3_step(S)] for the |
| 5269 | ** [prepared statement] S indicated an error, then |
| 5270 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
| 5271 | ** |
| 5272 | ** ^The [sqlite3_reset(S)] interface does not change the values |
| 5273 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
| 5274 | */ |
| 5275 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| @@ -5482,11 +5497,11 @@ | |
| 5482 | ** <p> |
| 5483 | ** The SQLITE_DIRECTONLY flag is recommended for any |
| 5484 | ** [application-defined SQL function] |
| 5485 | ** that has side-effects or that could potentially leak sensitive information. |
| 5486 | ** This will prevent attacks in which an application is tricked |
| 5487 | ** into using a database file that has had its schema surreptiously |
| 5488 | ** modified to invoke the application-defined function in ways that are |
| 5489 | ** harmful. |
| 5490 | ** <p> |
| 5491 | ** Some people say it is good practice to set SQLITE_DIRECTONLY on all |
| 5492 | ** [application-defined SQL functions], regardless of whether or not they |
| @@ -9191,12 +9206,12 @@ | |
| 9191 | ** ^(There may be at most one unlock-notify callback registered by a |
| 9192 | ** blocked connection. If sqlite3_unlock_notify() is called when the |
| 9193 | ** blocked connection already has a registered unlock-notify callback, |
| 9194 | ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is |
| 9195 | ** called with a NULL pointer as its second argument, then any existing |
| 9196 | ** unlock-notify callback is canceled. ^The blocked connections |
| 9197 | ** unlock-notify callback may also be canceled by closing the blocked |
| 9198 | ** connection using [sqlite3_close()]. |
| 9199 | ** |
| 9200 | ** The unlock-notify callback is not reentrant. If an application invokes |
| 9201 | ** any sqlite3_xxx API functions from within an unlock-notify callback, a |
| 9202 | ** crash or deadlock may be the result. |
| @@ -9615,11 +9630,11 @@ | |
| 9615 | ** </dd> |
| 9616 | ** |
| 9617 | ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 9618 | ** <dd>Calls of the form |
| 9619 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 9620 | ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation |
| 9621 | ** prohibits that virtual table from being used from within triggers and |
| 9622 | ** views. |
| 9623 | ** </dd> |
| 9624 | ** |
| 9625 | ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| @@ -9805,11 +9820,11 @@ | |
| 9805 | ** ^(A constraint on a virtual table of the form |
| 9806 | ** "[IN operator|column IN (...)]" is |
| 9807 | ** communicated to the xBestIndex method as a |
| 9808 | ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use |
| 9809 | ** this constraint, it must set the corresponding |
| 9810 | ** aConstraintUsage[].argvIndex to a postive integer. ^(Then, under |
| 9811 | ** the usual mode of handling IN operators, SQLite generates [bytecode] |
| 9812 | ** that invokes the [xFilter|xFilter() method] once for each value |
| 9813 | ** on the right-hand side of the IN operator.)^ Thus the virtual table |
| 9814 | ** only sees a single value from the right-hand side of the IN operator |
| 9815 | ** at a time. |
| @@ -10234,11 +10249,11 @@ | |
| 10234 | ** triggers; and so forth. |
| 10235 | ** |
| 10236 | ** When the [sqlite3_blob_write()] API is used to update a blob column, |
| 10237 | ** the pre-update hook is invoked with SQLITE_DELETE. This is because the |
| 10238 | ** in this case the new values are not available. In this case, when a |
| 10239 | ** callback made with op==SQLITE_DELETE is actuall a write using the |
| 10240 | ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns |
| 10241 | ** the index of the column being written. In other cases, where the |
| 10242 | ** pre-update hook is being invoked for some other reason, including a |
| 10243 | ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1. |
| 10244 | ** |
| 10245 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -144,13 +144,13 @@ | |
| 144 | ** |
| 145 | ** See also: [sqlite3_libversion()], |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.43.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3043000 |
| 151 | #define SQLITE_SOURCE_ID "2023-06-12 18:22:34 7ec4ab327decd6a5ee5e6a53f1489e17e0cdbb297945f9acc532b47d052eb7a9" |
| 152 | |
| 153 | /* |
| 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | ** |
| @@ -1188,11 +1188,11 @@ | |
| 1188 | ** the database is not a wal-mode db, or if there is no such connection in any |
| 1189 | ** other process. This opcode cannot be used to detect transactions opened |
| 1190 | ** by clients within the current process, only within other processes. |
| 1191 | ** |
| 1192 | ** <li>[[SQLITE_FCNTL_CKSM_FILE]] |
| 1193 | ** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use internally by the |
| 1194 | ** [checksum VFS shim] only. |
| 1195 | ** |
| 1196 | ** <li>[[SQLITE_FCNTL_RESET_CACHE]] |
| 1197 | ** If there is currently no transaction open on the database, and the |
| 1198 | ** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control |
| @@ -2452,11 +2452,11 @@ | |
| 2452 | ** 3.0.0. |
| 2453 | ** <p>Note that when the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT setting is on, |
| 2454 | ** the [VACUUM] command will fail with an obscure error when attempting to |
| 2455 | ** process a table with generated columns and a descending index. This is |
| 2456 | ** not considered a bug since SQLite versions 3.3.0 and earlier do not support |
| 2457 | ** either generated columns or descending indexes. |
| 2458 | ** </dd> |
| 2459 | ** |
| 2460 | ** [[SQLITE_DBCONFIG_STMT_SCANSTATUS]] |
| 2461 | ** <dt>SQLITE_DBCONFIG_STMT_SCANSTATUS</dt> |
| 2462 | ** <dd>The SQLITE_DBCONFIG_STMT_SCANSTATUS option is only useful in |
| @@ -2733,10 +2733,11 @@ | |
| 2733 | ** SQL statements is a no-op and has no effect on SQL statements |
| 2734 | ** that are started after the sqlite3_interrupt() call returns. |
| 2735 | ** |
| 2736 | ** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether |
| 2737 | ** or not an interrupt is currently in effect for [database connection] D. |
| 2738 | ** It returns 1 if an interrupt is currently in effect, or 0 otherwise. |
| 2739 | */ |
| 2740 | SQLITE_API void sqlite3_interrupt(sqlite3*); |
| 2741 | SQLITE_API int sqlite3_is_interrupted(sqlite3*); |
| 2742 | |
| 2743 | /* |
| @@ -3386,12 +3387,14 @@ | |
| 3387 | ** and context pointer P. ^If the X callback is |
| 3388 | ** NULL or if the M mask is zero, then tracing is disabled. The |
| 3389 | ** M argument should be the bitwise OR-ed combination of |
| 3390 | ** zero or more [SQLITE_TRACE] constants. |
| 3391 | ** |
| 3392 | ** ^Each call to either sqlite3_trace(D,X,P) or sqlite3_trace_v2(D,M,X,P) |
| 3393 | ** overrides (cancels) all prior calls to sqlite3_trace(D,X,P) or |
| 3394 | ** sqlite3_trace_v2(D,M,X,P) for the [database connection] D. Each |
| 3395 | ** database connection may have at most one trace callback. |
| 3396 | ** |
| 3397 | ** ^The X callback is invoked whenever any of the events identified by |
| 3398 | ** mask M occur. ^The integer return value from the callback is currently |
| 3399 | ** ignored, though this may change in future releases. Callback |
| 3400 | ** implementations should return zero to ensure future compatibility. |
| @@ -3756,11 +3759,11 @@ | |
| 3759 | ** |
| 3760 | ** The first parameter to these interfaces (hereafter referred to |
| 3761 | ** as F) must be one of: |
| 3762 | ** <ul> |
| 3763 | ** <li> A database filename pointer created by the SQLite core and |
| 3764 | ** passed into the xOpen() method of a VFS implementation, or |
| 3765 | ** <li> A filename obtained from [sqlite3_db_filename()], or |
| 3766 | ** <li> A new filename constructed using [sqlite3_create_filename()]. |
| 3767 | ** </ul> |
| 3768 | ** If the F parameter is not one of the above, then the behavior is |
| 3769 | ** undefined and probably undesirable. Older versions of SQLite were |
| @@ -3869,11 +3872,11 @@ | |
| 3872 | SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); |
| 3873 | |
| 3874 | /* |
| 3875 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 3876 | ** |
| 3877 | ** These interfaces are provided for use by [VFS shim] implementations and |
| 3878 | ** are not useful outside of that context. |
| 3879 | ** |
| 3880 | ** The sqlite3_create_filename(D,J,W,N,P) allocates memory to hold a version of |
| 3881 | ** database filename D with corresponding journal file J and WAL file W and |
| 3882 | ** with N URI parameters key/values pairs in the array P. The result from |
| @@ -4579,11 +4582,11 @@ | |
| 4582 | ** These three options exist: |
| 4583 | ** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished |
| 4584 | ** with it may be passed. ^It is called to dispose of the BLOB or string even |
| 4585 | ** if the call to the bind API fails, except the destructor is not called if |
| 4586 | ** the third parameter is a NULL pointer or the fourth parameter is negative. |
| 4587 | ** ^ (2) The special constant, [SQLITE_STATIC], may be passed to indicate that |
| 4588 | ** the application remains responsible for disposing of the object. ^In this |
| 4589 | ** case, the object and the provided pointer to it must remain valid until |
| 4590 | ** either the prepared statement is finalized or the same SQL parameter is |
| 4591 | ** bound to something else, whichever occurs sooner. |
| 4592 | ** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the |
| @@ -5258,18 +5261,30 @@ | |
| 5261 | ** Use [sqlite3_clear_bindings()] to reset the bindings. |
| 5262 | ** |
| 5263 | ** ^The [sqlite3_reset(S)] interface resets the [prepared statement] S |
| 5264 | ** back to the beginning of its program. |
| 5265 | ** |
| 5266 | ** ^The return code from [sqlite3_reset(S)] indicates whether or not |
| 5267 | ** the previous evaluation of prepared statement S completed successfully. |
| 5268 | ** ^If [sqlite3_step(S)] has never before been called on S or if |
| 5269 | ** [sqlite3_step(S)] has not been called since the previous call |
| 5270 | ** to [sqlite3_reset(S)], then [sqlite3_reset(S)] will return |
| 5271 | ** [SQLITE_OK]. |
| 5272 | ** |
| 5273 | ** ^If the most recent call to [sqlite3_step(S)] for the |
| 5274 | ** [prepared statement] S indicated an error, then |
| 5275 | ** [sqlite3_reset(S)] returns an appropriate [error code]. |
| 5276 | ** ^The [sqlite3_reset(S)] interface might also return an [error code] |
| 5277 | ** if there were no prior errors but the process of resetting |
| 5278 | ** the prepared statement caused a new error. ^For example, if an |
| 5279 | ** [INSERT] statement with a [RETURNING] clause is only stepped one time, |
| 5280 | ** that one call to [sqlite3_step(S)] might return SQLITE_ROW but |
| 5281 | ** the overall statement might still fail and the [sqlite3_reset(S)] call |
| 5282 | ** might return SQLITE_BUSY if locking constraints prevent the |
| 5283 | ** database change from committing. Therefore, it is important that |
| 5284 | ** applications check the return code from [sqlite3_reset(S)] even if |
| 5285 | ** no prior call to [sqlite3_step(S)] indicated a problem. |
| 5286 | ** |
| 5287 | ** ^The [sqlite3_reset(S)] interface does not change the values |
| 5288 | ** of any [sqlite3_bind_blob|bindings] on the [prepared statement] S. |
| 5289 | */ |
| 5290 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| @@ -5482,11 +5497,11 @@ | |
| 5497 | ** <p> |
| 5498 | ** The SQLITE_DIRECTONLY flag is recommended for any |
| 5499 | ** [application-defined SQL function] |
| 5500 | ** that has side-effects or that could potentially leak sensitive information. |
| 5501 | ** This will prevent attacks in which an application is tricked |
| 5502 | ** into using a database file that has had its schema surreptitiously |
| 5503 | ** modified to invoke the application-defined function in ways that are |
| 5504 | ** harmful. |
| 5505 | ** <p> |
| 5506 | ** Some people say it is good practice to set SQLITE_DIRECTONLY on all |
| 5507 | ** [application-defined SQL functions], regardless of whether or not they |
| @@ -9191,12 +9206,12 @@ | |
| 9206 | ** ^(There may be at most one unlock-notify callback registered by a |
| 9207 | ** blocked connection. If sqlite3_unlock_notify() is called when the |
| 9208 | ** blocked connection already has a registered unlock-notify callback, |
| 9209 | ** then the new callback replaces the old.)^ ^If sqlite3_unlock_notify() is |
| 9210 | ** called with a NULL pointer as its second argument, then any existing |
| 9211 | ** unlock-notify callback is cancelled. ^The blocked connections |
| 9212 | ** unlock-notify callback may also be cancelled by closing the blocked |
| 9213 | ** connection using [sqlite3_close()]. |
| 9214 | ** |
| 9215 | ** The unlock-notify callback is not reentrant. If an application invokes |
| 9216 | ** any sqlite3_xxx API functions from within an unlock-notify callback, a |
| 9217 | ** crash or deadlock may be the result. |
| @@ -9615,11 +9630,11 @@ | |
| 9630 | ** </dd> |
| 9631 | ** |
| 9632 | ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 9633 | ** <dd>Calls of the form |
| 9634 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 9635 | ** the [xConnect] or [xCreate] methods of a [virtual table] implementation |
| 9636 | ** prohibits that virtual table from being used from within triggers and |
| 9637 | ** views. |
| 9638 | ** </dd> |
| 9639 | ** |
| 9640 | ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| @@ -9805,11 +9820,11 @@ | |
| 9820 | ** ^(A constraint on a virtual table of the form |
| 9821 | ** "[IN operator|column IN (...)]" is |
| 9822 | ** communicated to the xBestIndex method as a |
| 9823 | ** [SQLITE_INDEX_CONSTRAINT_EQ] constraint.)^ If xBestIndex wants to use |
| 9824 | ** this constraint, it must set the corresponding |
| 9825 | ** aConstraintUsage[].argvIndex to a positive integer. ^(Then, under |
| 9826 | ** the usual mode of handling IN operators, SQLite generates [bytecode] |
| 9827 | ** that invokes the [xFilter|xFilter() method] once for each value |
| 9828 | ** on the right-hand side of the IN operator.)^ Thus the virtual table |
| 9829 | ** only sees a single value from the right-hand side of the IN operator |
| 9830 | ** at a time. |
| @@ -10234,11 +10249,11 @@ | |
| 10249 | ** triggers; and so forth. |
| 10250 | ** |
| 10251 | ** When the [sqlite3_blob_write()] API is used to update a blob column, |
| 10252 | ** the pre-update hook is invoked with SQLITE_DELETE. This is because the |
| 10253 | ** in this case the new values are not available. In this case, when a |
| 10254 | ** callback made with op==SQLITE_DELETE is actually a write using the |
| 10255 | ** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns |
| 10256 | ** the index of the column being written. In other cases, where the |
| 10257 | ** pre-update hook is being invoked for some other reason, including a |
| 10258 | ** regular DELETE, sqlite3_preupdate_blobwrite() returns -1. |
| 10259 | ** |
| 10260 |