| | @@ -1165,11 +1165,11 @@ |
| 1165 | 1165 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1166 | 1166 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1167 | 1167 | */ |
| 1168 | 1168 | #define SQLITE_VERSION "3.31.0" |
| 1169 | 1169 | #define SQLITE_VERSION_NUMBER 3031000 |
| 1170 | | -#define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68" |
| 1170 | +#define SQLITE_SOURCE_ID "2020-01-20 14:42:09 63d886f4ce3c770498b8bdad45b04143a3f63197d81793bde107450aba4a9c87" |
| 1171 | 1171 | |
| 1172 | 1172 | /* |
| 1173 | 1173 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1174 | 1174 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1175 | 1175 | ** |
| | @@ -2151,10 +2151,16 @@ |
| 2151 | 2151 | ** a single attached database that occur due to other database connections, |
| 2152 | 2152 | ** but omits changes implemented by the database connection on which it is |
| 2153 | 2153 | ** called. This file control is the only mechanism to detect changes that |
| 2154 | 2154 | ** happen either internally or externally and that are associated with |
| 2155 | 2155 | ** a particular attached database. |
| 2156 | +** |
| 2157 | +** <li>[[SQLITE_FCNTL_CKPT_DONE]] |
| 2158 | +** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint |
| 2159 | +** in wal mode after the client has finished copying pages from the wal |
| 2160 | +** file to the database file, but before the *-shm file is updated to |
| 2161 | +** record the fact that the pages have been checkpointed. |
| 2156 | 2162 | ** </ul> |
| 2157 | 2163 | */ |
| 2158 | 2164 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 2159 | 2165 | #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2 |
| 2160 | 2166 | #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3 |
| | @@ -2188,10 +2194,11 @@ |
| 2188 | 2194 | #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32 |
| 2189 | 2195 | #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33 |
| 2190 | 2196 | #define SQLITE_FCNTL_LOCK_TIMEOUT 34 |
| 2191 | 2197 | #define SQLITE_FCNTL_DATA_VERSION 35 |
| 2192 | 2198 | #define SQLITE_FCNTL_SIZE_LIMIT 36 |
| 2199 | +#define SQLITE_FCNTL_CKPT_DONE 37 |
| 2193 | 2200 | |
| 2194 | 2201 | /* deprecated names */ |
| 2195 | 2202 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 2196 | 2203 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 2197 | 2204 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| | @@ -3307,25 +3314,27 @@ |
| 3307 | 3314 | ** compile-time option. |
| 3308 | 3315 | ** </dd> |
| 3309 | 3316 | ** |
| 3310 | 3317 | ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]] |
| 3311 | 3318 | ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td> |
| 3312 | | -** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells the SQLite to |
| 3313 | | -** assume that database schemas are untainted by malicious content. |
| 3319 | +** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to |
| 3320 | +** assume that database schemas (the contents of the [sqlite_master] tables) |
| 3321 | +** are untainted by malicious content. |
| 3314 | 3322 | ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite |
| 3315 | 3323 | ** takes additional defensive steps to protect the application from harm |
| 3316 | | -** including, but not limited to, the following: |
| 3324 | +** including: |
| 3317 | 3325 | ** <ul> |
| 3318 | 3326 | ** <li> Prohibit the use of SQL functions inside triggers, views, |
| 3319 | | -** CHECK constraints, DEFAULT VALUEs, index definitions, and/or |
| 3320 | | -** generated columns unless those functions are tagged |
| 3321 | | -** with [SQLITE_INNOCUOUS]. |
| 3322 | | -** <li> Pohibit the use of virtual tables inside of triggers and/or views |
| 3327 | +** CHECK constraints, DEFAULT clauses, expression indexes, |
| 3328 | +** partial indexes, or generated columns |
| 3329 | +** unless those functions are tagged with [SQLITE_INNOCUOUS]. |
| 3330 | +** <li> Prohibit the use of virtual tables inside of triggers or views |
| 3323 | 3331 | ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS]. |
| 3324 | 3332 | ** </ul> |
| 3325 | 3333 | ** This setting defaults to "on" for legacy compatibility, however |
| 3326 | | -** all applications are advised to turn it off if possible. |
| 3334 | +** all applications are advised to turn it off if possible. This setting |
| 3335 | +** can also be controlled using the [PRAGMA trusted_schema] statement. |
| 3327 | 3336 | ** </dd> |
| 3328 | 3337 | ** |
| 3329 | 3338 | ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]] |
| 3330 | 3339 | ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td> |
| 3331 | 3340 | ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates |
| | @@ -3834,11 +3843,11 @@ |
| 3834 | 3843 | /* |
| 3835 | 3844 | ** CAPI3REF: Memory Allocation Subsystem |
| 3836 | 3845 | ** |
| 3837 | 3846 | ** The SQLite core uses these three routines for all of its own |
| 3838 | 3847 | ** internal memory allocation needs. "Core" in the previous sentence |
| 3839 | | -** does not include operating-system specific VFS implementation. The |
| 3848 | +** does not include operating-system specific [VFS] implementation. The |
| 3840 | 3849 | ** Windows VFS uses native malloc() and free() for some operations. |
| 3841 | 3850 | ** |
| 3842 | 3851 | ** ^The sqlite3_malloc() routine returns a pointer to a block |
| 3843 | 3852 | ** of memory at least N bytes in length, where N is the parameter. |
| 3844 | 3853 | ** ^If sqlite3_malloc() is unable to obtain sufficient free |
| | @@ -4317,14 +4326,12 @@ |
| 4317 | 4326 | ** passing it to [sqlite3_close()] when it is no longer required. |
| 4318 | 4327 | ** |
| 4319 | 4328 | ** The sqlite3_open_v2() interface works like sqlite3_open() |
| 4320 | 4329 | ** except that it accepts two additional parameters for additional control |
| 4321 | 4330 | ** over the new database connection. ^(The flags parameter to |
| 4322 | | -** sqlite3_open_v2() can take one of |
| 4323 | | -** the following three values, optionally combined with the |
| 4324 | | -** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE], |
| 4325 | | -** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^ |
| 4331 | +** sqlite3_open_v2() must include, at a minimum, one of the following |
| 4332 | +** three flag combinations:)^ |
| 4326 | 4333 | ** |
| 4327 | 4334 | ** <dl> |
| 4328 | 4335 | ** ^(<dt>[SQLITE_OPEN_READONLY]</dt> |
| 4329 | 4336 | ** <dd>The database is opened in read-only mode. If the database does not |
| 4330 | 4337 | ** already exist, an error is returned.</dd>)^ |
| | @@ -4337,28 +4344,56 @@ |
| 4337 | 4344 | ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt> |
| 4338 | 4345 | ** <dd>The database is opened for reading and writing, and is created if |
| 4339 | 4346 | ** it does not already exist. This is the behavior that is always used for |
| 4340 | 4347 | ** sqlite3_open() and sqlite3_open16().</dd>)^ |
| 4341 | 4348 | ** </dl> |
| 4349 | +** |
| 4350 | +** In addition to the required flags, the following optional flags are |
| 4351 | +** also supported: |
| 4352 | +** |
| 4353 | +** <dl> |
| 4354 | +** ^(<dt>[SQLITE_OPEN_URI]</dt> |
| 4355 | +** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^ |
| 4356 | +** |
| 4357 | +** ^(<dt>[SQLITE_OPEN_MEMORY]</dt> |
| 4358 | +** <dd>The database will be opened as an in-memory database. The database |
| 4359 | +** is named by the "filename" argument for the purposes of cache-sharing, |
| 4360 | +** if shared cache mode is enabled, but the "filename" is otherwise ignored. |
| 4361 | +** </dd>)^ |
| 4362 | +** |
| 4363 | +** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt> |
| 4364 | +** <dd>The new database connection will use the "multi-thread" |
| 4365 | +** [threading mode].)^ This means that separate threads are allowed |
| 4366 | +** to use SQLite at the same time, as long as each thread is using |
| 4367 | +** a different [database connection]. |
| 4368 | +** |
| 4369 | +** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt> |
| 4370 | +** <dd>The new database connection will use the "serialized" |
| 4371 | +** [threading mode].)^ This means the multiple threads can safely |
| 4372 | +** attempt to use the same database connection at the same time. |
| 4373 | +** (Mutexes will block any actual concurrency, but in this mode |
| 4374 | +** there is no harm in trying.) |
| 4375 | +** |
| 4376 | +** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt> |
| 4377 | +** <dd>The database is opened [shared cache] enabled, overriding |
| 4378 | +** the default shared cache setting provided by |
| 4379 | +** [sqlite3_enable_shared_cache()].)^ |
| 4380 | +** |
| 4381 | +** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt> |
| 4382 | +** <dd>The database is opened [shared cache] disabled, overriding |
| 4383 | +** the default shared cache setting provided by |
| 4384 | +** [sqlite3_enable_shared_cache()].)^ |
| 4385 | +** |
| 4386 | +** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt> |
| 4387 | +** <dd>The database filename is not allowed to be a symbolic link</dd> |
| 4388 | +** </dl>)^ |
| 4342 | 4389 | ** |
| 4343 | 4390 | ** If the 3rd parameter to sqlite3_open_v2() is not one of the |
| 4344 | | -** combinations shown above optionally combined with other |
| 4391 | +** required combinations shown above optionally combined with other |
| 4345 | 4392 | ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits] |
| 4346 | 4393 | ** then the behavior is undefined. |
| 4347 | 4394 | ** |
| 4348 | | -** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection |
| 4349 | | -** opens in the multi-thread [threading mode] as long as the single-thread |
| 4350 | | -** mode has not been set at compile-time or start-time. ^If the |
| 4351 | | -** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens |
| 4352 | | -** in the serialized [threading mode] unless single-thread was |
| 4353 | | -** previously selected at compile-time or start-time. |
| 4354 | | -** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be |
| 4355 | | -** eligible to use [shared cache mode], regardless of whether or not shared |
| 4356 | | -** cache is enabled using [sqlite3_enable_shared_cache()]. ^The |
| 4357 | | -** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not |
| 4358 | | -** participate in [shared cache mode] even if it is enabled. |
| 4359 | | -** |
| 4360 | 4395 | ** ^The fourth parameter to sqlite3_open_v2() is the name of the |
| 4361 | 4396 | ** [sqlite3_vfs] object that defines the operating system interface that |
| 4362 | 4397 | ** the new database connection should use. ^If the fourth parameter is |
| 4363 | 4398 | ** a NULL pointer then the default [sqlite3_vfs] object is used. |
| 4364 | 4399 | ** |
| | @@ -4534,18 +4569,17 @@ |
| 4534 | 4569 | ); |
| 4535 | 4570 | |
| 4536 | 4571 | /* |
| 4537 | 4572 | ** CAPI3REF: Obtain Values For URI Parameters |
| 4538 | 4573 | ** |
| 4539 | | -** These are utility routines, useful to VFS implementations, that check |
| 4540 | | -** to see if a database file was a URI that contained a specific query |
| 4574 | +** These are utility routines, useful to [VFS|custom VFS implementations], |
| 4575 | +** that check if a database file was a URI that contained a specific query |
| 4541 | 4576 | ** parameter, and if so obtains the value of that query parameter. |
| 4542 | 4577 | ** |
| 4543 | 4578 | ** If F is the database filename pointer passed into the xOpen() method of |
| 4544 | | -** a VFS implementation when the flags parameter to xOpen() has one or |
| 4545 | | -** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and |
| 4546 | | -** P is the name of the query parameter, then |
| 4579 | +** a VFS implementation or it is the return value of [sqlite3_db_filename()] |
| 4580 | +** and if P is the name of the query parameter, then |
| 4547 | 4581 | ** sqlite3_uri_parameter(F,P) returns the value of the P |
| 4548 | 4582 | ** parameter if it exists or a NULL pointer if P does not appear as a |
| 4549 | 4583 | ** query parameter on F. If P is a query parameter of F and it |
| 4550 | 4584 | ** has no explicit value, then sqlite3_uri_parameter(F,P) returns |
| 4551 | 4585 | ** a pointer to an empty string. |
| | @@ -4563,22 +4597,69 @@ |
| 4563 | 4597 | ** |
| 4564 | 4598 | ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a |
| 4565 | 4599 | ** 64-bit signed integer and returns that integer, or D if P does not |
| 4566 | 4600 | ** exist. If the value of P is something other than an integer, then |
| 4567 | 4601 | ** zero is returned. |
| 4602 | +** |
| 4603 | +** The sqlite3_uri_key(F,N) returns a pointer to the name (not |
| 4604 | +** the value) of the N-th query parameter for filename F, or a NULL |
| 4605 | +** pointer if N is less than zero or greater than the number of query |
| 4606 | +** parameters minus 1. The N value is zero-based so N should be 0 to obtain |
| 4607 | +** the name of the first query parameter, 1 for the second parameter, and |
| 4608 | +** so forth. |
| 4568 | 4609 | ** |
| 4569 | 4610 | ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and |
| 4570 | 4611 | ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and |
| 4571 | | -** is not a database file pathname pointer that SQLite passed into the xOpen |
| 4572 | | -** VFS method, then the behavior of this routine is undefined and probably |
| 4573 | | -** undesirable. |
| 4612 | +** is not a database file pathname pointer that the SQLite core passed |
| 4613 | +** into the xOpen VFS method, then the behavior of this routine is undefined |
| 4614 | +** and probably undesirable. |
| 4615 | +** |
| 4616 | +** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F |
| 4617 | +** parameter can also be the name of a rollback journal file or WAL file |
| 4618 | +** in addition to the main database file. Prior to version 3.31.0, these |
| 4619 | +** routines would only work if F was the name of the main database file. |
| 4620 | +** When the F parameter is the name of the rollback journal or WAL file, |
| 4621 | +** it has access to all the same query parameters as were found on the |
| 4622 | +** main database file. |
| 4574 | 4623 | ** |
| 4575 | 4624 | ** See the [URI filename] documentation for additional information. |
| 4576 | 4625 | */ |
| 4577 | 4626 | SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam); |
| 4578 | 4627 | SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault); |
| 4579 | 4628 | SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); |
| 4629 | +SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N); |
| 4630 | + |
| 4631 | +/* |
| 4632 | +** CAPI3REF: Translate filenames |
| 4633 | +** |
| 4634 | +** These routines are available to [VFS|custom VFS implementations] for |
| 4635 | +** translating filenames between the main database file, the journal file, |
| 4636 | +** and the WAL file. |
| 4637 | +** |
| 4638 | +** If F is the name of an sqlite database file, journal file, or WAL file |
| 4639 | +** passed by the SQLite core into the VFS, then sqlite3_filename_database(F) |
| 4640 | +** returns the name of the corresponding database file. |
| 4641 | +** |
| 4642 | +** If F is the name of an sqlite database file, journal file, or WAL file |
| 4643 | +** passed by the SQLite core into the VFS, or if F is a database filename |
| 4644 | +** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F) |
| 4645 | +** returns the name of the corresponding rollback journal file. |
| 4646 | +** |
| 4647 | +** If F is the name of an sqlite database file, journal file, or WAL file |
| 4648 | +** that was passed by the SQLite core into the VFS, or if F is a database |
| 4649 | +** filename obtained from [sqlite3_db_filename()], then |
| 4650 | +** sqlite3_filename_wal(F) returns the name of the corresponding |
| 4651 | +** WAL file. |
| 4652 | +** |
| 4653 | +** In all of the above, if F is not the name of a database, journal or WAL |
| 4654 | +** filename passed into the VFS from the SQLite core and F is not the |
| 4655 | +** return value from [sqlite3_db_filename()], then the result is |
| 4656 | +** undefined and is likely a memory access violation. |
| 4657 | +*/ |
| 4658 | +SQLITE_API const char *sqlite3_filename_database(const char*); |
| 4659 | +SQLITE_API const char *sqlite3_filename_journal(const char*); |
| 4660 | +SQLITE_API const char *sqlite3_filename_wal(const char*); |
| 4580 | 4661 | |
| 4581 | 4662 | |
| 4582 | 4663 | /* |
| 4583 | 4664 | ** CAPI3REF: Error Codes And Messages |
| 4584 | 4665 | ** METHOD: sqlite3 |
| | @@ -5877,12 +5958,10 @@ |
| 5877 | 5958 | SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt); |
| 5878 | 5959 | |
| 5879 | 5960 | /* |
| 5880 | 5961 | ** CAPI3REF: Create Or Redefine SQL Functions |
| 5881 | 5962 | ** KEYWORDS: {function creation routines} |
| 5882 | | -** KEYWORDS: {application-defined SQL function} |
| 5883 | | -** KEYWORDS: {application-defined SQL functions} |
| 5884 | 5963 | ** METHOD: sqlite3 |
| 5885 | 5964 | ** |
| 5886 | 5965 | ** ^These functions (collectively known as "function creation routines") |
| 5887 | 5966 | ** are used to add SQL functions or aggregates or to redefine the behavior |
| 5888 | 5967 | ** of existing SQL functions or aggregates. The only differences between |
| | @@ -5934,13 +6013,24 @@ |
| 5934 | 6013 | ** perform additional optimizations on deterministic functions, so use |
| 5935 | 6014 | ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. |
| 5936 | 6015 | ** |
| 5937 | 6016 | ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY] |
| 5938 | 6017 | ** flag, which if present prevents the function from being invoked from |
| 5939 | | -** within VIEWs or TRIGGERs. For security reasons, the [SQLITE_DIRECTONLY] |
| 5940 | | -** flag is recommended for any application-defined SQL function that has |
| 5941 | | -** side-effects. |
| 6018 | +** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions, |
| 6019 | +** index expressions, or the WHERE clause of partial indexes. |
| 6020 | +** |
| 6021 | +** <span style="background-color:#ffff90;"> |
| 6022 | +** For best security, the [SQLITE_DIRECTONLY] flag is recommended for |
| 6023 | +** all application-defined SQL functions that do not need to be |
| 6024 | +** used inside of triggers, view, CHECK constraints, or other elements of |
| 6025 | +** the database schema. This flags is especially recommended for SQL |
| 6026 | +** functions that have side effects or reveal internal application state. |
| 6027 | +** Without this flag, an attacker might be able to modify the schema of |
| 6028 | +** a database file to include invocations of the function with parameters |
| 6029 | +** chosen by the attacker, which the application will then execute when |
| 6030 | +** the database file is opened and read. |
| 6031 | +** </span> |
| 5942 | 6032 | ** |
| 5943 | 6033 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 5944 | 6034 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 5945 | 6035 | ** |
| 5946 | 6036 | ** ^The sixth, seventh and eighth parameters passed to the three |
| | @@ -6055,46 +6145,66 @@ |
| 6055 | 6145 | ** These constants may be ORed together with the |
| 6056 | 6146 | ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument |
| 6057 | 6147 | ** to [sqlite3_create_function()], [sqlite3_create_function16()], or |
| 6058 | 6148 | ** [sqlite3_create_function_v2()]. |
| 6059 | 6149 | ** |
| 6150 | +** <dl> |
| 6151 | +** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd> |
| 6060 | 6152 | ** The SQLITE_DETERMINISTIC flag means that the new function always gives |
| 6061 | 6153 | ** the same output when the input parameters are the same. |
| 6062 | 6154 | ** The [abs|abs() function] is deterministic, for example, but |
| 6063 | 6155 | ** [randomblob|randomblob()] is not. Functions must |
| 6064 | 6156 | ** be deterministic in order to be used in certain contexts such as |
| 6065 | | -** [CHECK constraints] or [generated columns]. SQLite might also optimize |
| 6066 | | -** deterministic functions by factoring them out of inner loops. |
| 6157 | +** with the WHERE clause of [partial indexes] or in [generated columns]. |
| 6158 | +** SQLite might also optimize deterministic functions by factoring them |
| 6159 | +** out of inner loops. |
| 6160 | +** </dd> |
| 6161 | +** |
| 6162 | +** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd> |
| 6163 | +** The SQLITE_DIRECTONLY flag means that the function may only be invoked |
| 6164 | +** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in |
| 6165 | +** schema structures such as [CHECK constraints], [DEFAULT clauses], |
| 6166 | +** [expression indexes], [partial indexes], or [generated columns]. |
| 6167 | +** The SQLITE_DIRECTONLY flags is a security feature which is recommended |
| 6168 | +** for all [application-defined SQL functions], and especially for functions |
| 6169 | +** that have side-effects or that could potentially leak sensitive |
| 6170 | +** information. |
| 6171 | +** </dd> |
| 6067 | 6172 | ** |
| 6068 | | -** The SQLITE_INNOCUOUS flag means that the new function is unlikely |
| 6173 | +** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd> |
| 6174 | +** The SQLITE_INNOCUOUS flag means that the function is unlikely |
| 6069 | 6175 | ** to cause problems even if misused. An innocuous function should have |
| 6070 | | -** no side effects and consume few resources. The [abs|abs() function] |
| 6071 | | -** is an example of an innocuous function. |
| 6176 | +** no side effects and should not depend on any values other than its |
| 6177 | +** input parameters. The [abs|abs() function] is an example of an |
| 6178 | +** innocuous function. |
| 6072 | 6179 | ** The [load_extension() SQL function] is not innocuous because of its |
| 6073 | | -** side effects. Some heightened security settings |
| 6074 | | -** ([SQLITE_DBCONFIG_UNSAFE_FUNC_IN_VIEW]) |
| 6075 | | -** disable the use of SQLlfunctions inside views and triggers unless |
| 6180 | +** side effects. |
| 6181 | +** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not |
| 6182 | +** exactly the same. The [random|random() function] is an example of a |
| 6183 | +** function that is innocuous but not deterministic. |
| 6184 | +** <p>Some heightened security settings |
| 6185 | +** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF]) |
| 6186 | +** disable the use of SQL functions inside views and triggers and in |
| 6187 | +** schema structures such as [CHECK constraints], [DEFAULT clauses], |
| 6188 | +** [expression indexes], [partial indexes], and [generated columns] unless |
| 6076 | 6189 | ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions |
| 6077 | 6190 | ** are innocuous. Developers are advised to avoid using the |
| 6078 | 6191 | ** SQLITE_INNOCUOUS flag for application-defined functions unless the |
| 6079 | | -** function is specifically intended for use inside of views and triggers. |
| 6080 | | -** |
| 6081 | | -** The SQLITE_DIRECTONLY flag means that the function may only be invoked |
| 6082 | | -** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is |
| 6083 | | -** a security feature which is recommended for all |
| 6084 | | -** [application-defined SQL functions] that have side-effects. This flag |
| 6085 | | -** prevents an attacker from adding triggers and views to a schema then |
| 6086 | | -** tricking a high-privilege application into causing unintended side-effects |
| 6087 | | -** while performing ordinary queries. |
| 6088 | | -** |
| 6192 | +** function has been carefully audited and found to be free of potentially |
| 6193 | +** security-adverse side-effects and information-leaks. |
| 6194 | +** </dd> |
| 6195 | +** |
| 6196 | +** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd> |
| 6089 | 6197 | ** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call |
| 6090 | 6198 | ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments. |
| 6091 | 6199 | ** Specifying this flag makes no difference for scalar or aggregate user |
| 6092 | 6200 | ** functions. However, if it is not specified for a user-defined window |
| 6093 | 6201 | ** function, then any sub-types belonging to arguments passed to the window |
| 6094 | 6202 | ** function may be discarded before the window function is called (i.e. |
| 6095 | 6203 | ** sqlite3_value_subtype() will always return 0). |
| 6204 | +** </dd> |
| 6205 | +** </dl> |
| 6096 | 6206 | */ |
| 6097 | 6207 | #define SQLITE_DETERMINISTIC 0x000000800 |
| 6098 | 6208 | #define SQLITE_DIRECTONLY 0x000080000 |
| 6099 | 6209 | #define SQLITE_SUBTYPE 0x000100000 |
| 6100 | 6210 | #define SQLITE_INNOCUOUS 0x000200000 |
| | @@ -7006,10 +7116,21 @@ |
| 7006 | 7116 | ** |
| 7007 | 7117 | ** ^The filename returned by this function is the output of the |
| 7008 | 7118 | ** xFullPathname method of the [VFS]. ^In other words, the filename |
| 7009 | 7119 | ** will be an absolute pathname, even if the filename used |
| 7010 | 7120 | ** to open the database originally was a URI or relative pathname. |
| 7121 | +** |
| 7122 | +** If the filename pointer returned by this routine is not NULL, then it |
| 7123 | +** can be used as the filename input parameter to these routines: |
| 7124 | +** <ul> |
| 7125 | +** <li> [sqlite3_uri_parameter()] |
| 7126 | +** <li> [sqlite3_uri_boolean()] |
| 7127 | +** <li> [sqlite3_uri_int64()] |
| 7128 | +** <li> [sqlite3_filename_database()] |
| 7129 | +** <li> [sqlite3_filename_journal()] |
| 7130 | +** <li> [sqlite3_filename_wal()] |
| 7131 | +** </ul> |
| 7011 | 7132 | */ |
| 7012 | 7133 | SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName); |
| 7013 | 7134 | |
| 7014 | 7135 | /* |
| 7015 | 7136 | ** CAPI3REF: Determine if a database is read-only |
| | @@ -9974,10 +10095,18 @@ |
| 9974 | 10095 | ** silently replace the appropriate rows within the xUpdate callback and |
| 9975 | 10096 | ** return SQLITE_OK. Or, if this is not possible, it may return |
| 9976 | 10097 | ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT |
| 9977 | 10098 | ** constraint handling. |
| 9978 | 10099 | ** </dd> |
| 10100 | +** |
| 10101 | +** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 10102 | +** <dd>Calls of the form |
| 10103 | +** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 10104 | +** the [xConnect] or [xCreate] methods of a [virtual table] implmentation |
| 10105 | +** prohibits that virtual table from being used from within triggers and |
| 10106 | +** views. |
| 10107 | +** </dd> |
| 9979 | 10108 | ** |
| 9980 | 10109 | ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt> |
| 9981 | 10110 | ** <dd>Calls of the form |
| 9982 | 10111 | ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the |
| 9983 | 10112 | ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation |
| | @@ -9985,18 +10114,10 @@ |
| 9985 | 10114 | ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the |
| 9986 | 10115 | ** virtual table can do no serious harm even if it is controlled by a |
| 9987 | 10116 | ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS |
| 9988 | 10117 | ** flag unless absolutely necessary. |
| 9989 | 10118 | ** </dd> |
| 9990 | | -** |
| 9991 | | -** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt> |
| 9992 | | -** <dd>Calls of the form |
| 9993 | | -** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the |
| 9994 | | -** the [xConnect] or [xCreate] methods of a [virtual table] implmentation |
| 9995 | | -** prohibits that virtual table from being used from within triggers and |
| 9996 | | -** views. |
| 9997 | | -** </dd> |
| 9998 | 10119 | ** </dl> |
| 9999 | 10120 | */ |
| 10000 | 10121 | #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1 |
| 10001 | 10122 | #define SQLITE_VTAB_INNOCUOUS 2 |
| 10002 | 10123 | #define SQLITE_VTAB_DIRECTONLY 3 |
| | @@ -15718,11 +15839,11 @@ |
| 15718 | 15839 | SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*); |
| 15719 | 15840 | #ifdef SQLITE_DEBUG |
| 15720 | 15841 | SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*); |
| 15721 | 15842 | #endif |
| 15722 | 15843 | SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*); |
| 15723 | | -SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int); |
| 15844 | +SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager*, int); |
| 15724 | 15845 | SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*); |
| 15725 | 15846 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*); |
| 15726 | 15847 | SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*); |
| 15727 | 15848 | SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*); |
| 15728 | 15849 | SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*); |
| | @@ -19254,13 +19375,10 @@ |
| 19254 | 19375 | SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*); |
| 19255 | 19376 | SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*); |
| 19256 | 19377 | SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*); |
| 19257 | 19378 | SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*); |
| 19258 | 19379 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); |
| 19259 | | -#ifdef SQLITE_DEBUG |
| 19260 | | -SQLITE_PRIVATE int sqlite3UriCount(const char*); |
| 19261 | | -#endif |
| 19262 | 19380 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 19263 | 19381 | sqlite3_vfs**,char**,char **); |
| 19264 | 19382 | #ifdef SQLITE_HAS_CODEC |
| 19265 | 19383 | SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*); |
| 19266 | 19384 | #else |
| | @@ -22090,11 +22208,11 @@ |
| 22090 | 22208 | */ |
| 22091 | 22209 | if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){ |
| 22092 | 22210 | r = p->s*1000.0 + 210866760000000.0; |
| 22093 | 22211 | if( r>=0.0 && r<464269060800000.0 ){ |
| 22094 | 22212 | clearYMD_HMS_TZ(p); |
| 22095 | | - p->iJD = (sqlite3_int64)r; |
| 22213 | + p->iJD = (sqlite3_int64)(r + 0.5); |
| 22096 | 22214 | p->validJD = 1; |
| 22097 | 22215 | p->rawS = 0; |
| 22098 | 22216 | rc = 0; |
| 22099 | 22217 | } |
| 22100 | 22218 | } |
| | @@ -30871,11 +30989,13 @@ |
| 30871 | 30989 | ** strings, and stuff like that. |
| 30872 | 30990 | ** |
| 30873 | 30991 | */ |
| 30874 | 30992 | /* #include "sqliteInt.h" */ |
| 30875 | 30993 | /* #include <stdarg.h> */ |
| 30994 | +#ifndef SQLITE_OMIT_FLOATING_POINT |
| 30876 | 30995 | #include <math.h> |
| 30996 | +#endif |
| 30877 | 30997 | |
| 30878 | 30998 | /* |
| 30879 | 30999 | ** Routine needed to support the testcase() macro. |
| 30880 | 31000 | */ |
| 30881 | 31001 | #ifdef SQLITE_COVERAGE_TEST |
| | @@ -56105,57 +56225,92 @@ |
| 56105 | 56225 | ** Pager object (sizeof(Pager) bytes) |
| 56106 | 56226 | ** PCache object (sqlite3PcacheSize() bytes) |
| 56107 | 56227 | ** Database file handle (pVfs->szOsFile bytes) |
| 56108 | 56228 | ** Sub-journal file handle (journalFileSize bytes) |
| 56109 | 56229 | ** Main journal file handle (journalFileSize bytes) |
| 56230 | + ** \0\1\0 journal prefix (3 bytes) |
| 56231 | + ** Journal filename (nPathname+8+1 bytes) |
| 56232 | + ** \2\0 WAL prefix (2 bytes) |
| 56233 | + ** WAL filename (nPathname+4+1 bytes) |
| 56234 | + ** \3\0 database prefix (2 bytes) |
| 56110 | 56235 | ** Database file name (nPathname+1 bytes) |
| 56111 | | - ** Journal file name (nPathname+8+1 bytes) |
| 56236 | + ** URI query parameters (nUriByte bytes) |
| 56237 | + ** \0\0 terminator (2 bytes) |
| 56112 | 56238 | */ |
| 56113 | 56239 | pPtr = (u8 *)sqlite3MallocZero( |
| 56114 | | - ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 56115 | | - ROUND8(pcacheSize) + /* PCache object */ |
| 56116 | | - ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 56117 | | - journalFileSize * 2 + /* The two journal files */ |
| 56118 | | - nPathname + 1 + nUriByte + /* zFilename */ |
| 56119 | | - nPathname + 8 + 2 /* zJournal */ |
| 56240 | + ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 56241 | + ROUND8(pcacheSize) + /* PCache object */ |
| 56242 | + ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 56243 | + journalFileSize * 2 + /* The two journal files */ |
| 56244 | + 3 + /* Journal prefix */ |
| 56245 | + nPathname + 8 + 1 + /* Journal filename */ |
| 56120 | 56246 | #ifndef SQLITE_OMIT_WAL |
| 56121 | | - + nPathname + 4 + 2 /* zWal */ |
| 56247 | + 2 + /* WAL prefix */ |
| 56248 | + nPathname + 4 + 1 + /* WAL filename */ |
| 56122 | 56249 | #endif |
| 56250 | + 2 + /* Database prefix */ |
| 56251 | + nPathname + 1 + /* database filename */ |
| 56252 | + nUriByte + /* query parameters */ |
| 56253 | + 2 /* Terminator */ |
| 56123 | 56254 | ); |
| 56124 | 56255 | assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) ); |
| 56125 | 56256 | if( !pPtr ){ |
| 56126 | 56257 | sqlite3DbFree(0, zPathname); |
| 56127 | 56258 | return SQLITE_NOMEM_BKPT; |
| 56128 | 56259 | } |
| 56129 | | - pPager = (Pager*)(pPtr); |
| 56130 | | - pPager->pPCache = (PCache*)(pPtr += ROUND8(sizeof(*pPager))); |
| 56131 | | - pPager->fd = (sqlite3_file*)(pPtr += ROUND8(pcacheSize)); |
| 56132 | | - pPager->sjfd = (sqlite3_file*)(pPtr += ROUND8(pVfs->szOsFile)); |
| 56133 | | - pPager->jfd = (sqlite3_file*)(pPtr += journalFileSize); |
| 56134 | | - pPager->zFilename = (char*)(pPtr += journalFileSize); |
| 56260 | + pPager = (Pager*)pPtr; pPtr += ROUND8(sizeof(*pPager)); |
| 56261 | + pPager->pPCache = (PCache*)pPtr; pPtr += ROUND8(pcacheSize); |
| 56262 | + pPager->fd = (sqlite3_file*)pPtr; pPtr += ROUND8(pVfs->szOsFile); |
| 56263 | + pPager->sjfd = (sqlite3_file*)pPtr; pPtr += journalFileSize; |
| 56264 | + pPager->jfd = (sqlite3_file*)pPtr; pPtr += journalFileSize; |
| 56135 | 56265 | assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) ); |
| 56136 | 56266 | |
| 56137 | | - /* Fill in the Pager.zFilename and Pager.zJournal buffers, if required. */ |
| 56138 | | - if( zPathname ){ |
| 56139 | | - assert( nPathname>0 ); |
| 56140 | | - memcpy(pPager->zFilename, zPathname, nPathname); |
| 56141 | | - if( nUri ) memcpy(&pPager->zFilename[nPathname+1], zUri, nUriByte); |
| 56142 | | - pPager->zJournal = (char*)(pPtr += nPathname + 1 + nUriByte); |
| 56143 | | - memcpy(pPager->zJournal, zPathname, nPathname); |
| 56144 | | - memcpy(&pPager->zJournal[nPathname], "-journal", 8); |
| 56145 | | - sqlite3FileSuffix3(pPager->zFilename, pPager->zJournal); |
| 56267 | + |
| 56268 | + /* Fill in Pager.zJournal */ |
| 56269 | + pPtr[1] = '\001'; pPtr += 3; |
| 56270 | + if( nPathname>0 ){ |
| 56271 | + pPager->zJournal = (char*)pPtr; |
| 56272 | + memcpy(pPtr, zPathname, nPathname); pPtr += nPathname; |
| 56273 | + memcpy(pPtr, "-journal",8); pPtr += 8 + 1; |
| 56274 | +#ifdef SQLITE_ENABLE_8_3_NAMES |
| 56275 | + sqlite3FileSuffix3(zFilename,pPager->zJournal); |
| 56276 | + pPtr = (u8*)(pPager->zJournal + sqlite3Strlen30(pPager->zJournal)+1); |
| 56277 | +#endif |
| 56278 | + }else{ |
| 56279 | + pPager->zJournal = 0; |
| 56280 | + pPtr++; |
| 56281 | + } |
| 56282 | + |
| 56146 | 56283 | #ifndef SQLITE_OMIT_WAL |
| 56147 | | - pPager->zWal = (char*)(pPtr += nPathname + 8 + 2); |
| 56148 | | - memcpy(pPager->zWal, zPathname, nPathname); |
| 56149 | | - memcpy(&pPager->zWal[nPathname], "-wal", 4); |
| 56150 | | - sqlite3FileSuffix3(pPager->zFilename, pPager->zWal); |
| 56151 | | - assert( sqlite3UriCount(pPager->zWal)==0 ); |
| 56284 | + /* Fill in Pager.zWal */ |
| 56285 | + pPtr[0] = '\002'; pPtr[1] = 0; pPtr += 2; |
| 56286 | + if( nPathname>0 ){ |
| 56287 | + pPager->zWal = (char*)pPtr; |
| 56288 | + memcpy(pPtr, zPathname, nPathname); pPtr += nPathname; |
| 56289 | + memcpy(pPtr, "-wal", 4); pPtr += 4 + 1; |
| 56290 | +#ifdef SQLITE_ENABLE_8_3_NAMES |
| 56291 | + sqlite3FileSuffix3(zFilename, pPager->zWal); |
| 56292 | + pPtr = (u8*)(pPager->zWal + sqlite3Strlen30(pPager->zWal)+1); |
| 56152 | 56293 | #endif |
| 56153 | | - assert( sqlite3UriCount(pPager->zFilename)==nUri ); |
| 56154 | | - assert( sqlite3UriCount(pPager->zJournal)==0 ); |
| 56155 | | - sqlite3DbFree(0, zPathname); |
| 56294 | + }else{ |
| 56295 | + pPager->zWal = 0; |
| 56296 | + pPtr++; |
| 56156 | 56297 | } |
| 56298 | +#endif |
| 56299 | + |
| 56300 | + /* Fill in the Pager.zFilename and pPager.zQueryParam fields */ |
| 56301 | + pPtr[0] = '\003'; pPtr[1] = 0; pPtr += 2; |
| 56302 | + pPager->zFilename = (char*)pPtr; |
| 56303 | + if( nPathname>0 ){ |
| 56304 | + memcpy(pPtr, zPathname, nPathname); pPtr += nPathname + 1; |
| 56305 | + if( zUri ){ |
| 56306 | + memcpy(pPtr, zUri, nUriByte); /* pPtr += nUriByte; // not needed */ |
| 56307 | + } |
| 56308 | + /* Double-zero terminator implied by the sqlite3MallocZero */ |
| 56309 | + } |
| 56310 | + |
| 56311 | + if( nPathname ) sqlite3DbFree(0, zPathname); |
| 56157 | 56312 | pPager->pVfs = pVfs; |
| 56158 | 56313 | pPager->vfsFlags = vfsFlags; |
| 56159 | 56314 | |
| 56160 | 56315 | /* Open the pager file. |
| 56161 | 56316 | */ |
| | @@ -56200,13 +56355,13 @@ |
| 56200 | 56355 | } |
| 56201 | 56356 | } |
| 56202 | 56357 | } |
| 56203 | 56358 | #endif |
| 56204 | 56359 | } |
| 56205 | | - pPager->noLock = sqlite3_uri_boolean(zFilename, "nolock", 0); |
| 56360 | + pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0); |
| 56206 | 56361 | if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0 |
| 56207 | | - || sqlite3_uri_boolean(zFilename, "immutable", 0) ){ |
| 56362 | + || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){ |
| 56208 | 56363 | vfsFlags |= SQLITE_OPEN_READONLY; |
| 56209 | 56364 | goto act_like_temp_file; |
| 56210 | 56365 | } |
| 56211 | 56366 | } |
| 56212 | 56367 | }else{ |
| | @@ -58265,13 +58420,17 @@ |
| 58265 | 58420 | ** nullIfMemDb is true. This routine is called with nullIfMemDb==1 when |
| 58266 | 58421 | ** used to report the filename to the user, for compatibility with legacy |
| 58267 | 58422 | ** behavior. But when the Btree needs to know the filename for matching to |
| 58268 | 58423 | ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can |
| 58269 | 58424 | ** participate in shared-cache. |
| 58425 | +** |
| 58426 | +** The return value to this routine is always safe to use with |
| 58427 | +** sqlite3_uri_parameter() and sqlite3_filename_database() and friends. |
| 58270 | 58428 | */ |
| 58271 | | -SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager, int nullIfMemDb){ |
| 58272 | | - return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename; |
| 58429 | +SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager *pPager, int nullIfMemDb){ |
| 58430 | + static const char zFake[] = { 0x00, 0x01, 0x00, 0x00, 0x00 }; |
| 58431 | + return (nullIfMemDb && pPager->memDb) ? &zFake[3] : pPager->zFilename; |
| 58273 | 58432 | } |
| 58274 | 58433 | |
| 58275 | 58434 | /* |
| 58276 | 58435 | ** Return the VFS structure for the pager. |
| 58277 | 58436 | */ |
| | @@ -58921,10 +59080,12 @@ |
| 58921 | 59080 | if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK); |
| 58922 | 59081 | } |
| 58923 | 59082 | } |
| 58924 | 59083 | return rc; |
| 58925 | 59084 | } |
| 59085 | + |
| 59086 | + |
| 58926 | 59087 | |
| 58927 | 59088 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 58928 | 59089 | /* |
| 58929 | 59090 | ** If this is a WAL database, obtain a snapshot handle for the snapshot |
| 58930 | 59091 | ** currently open. Otherwise, return an error. |
| | @@ -60931,10 +61092,14 @@ |
| 60931 | 61092 | rc = sqlite3OsTruncate(pWal->pDbFd, szDb); |
| 60932 | 61093 | if( rc==SQLITE_OK ){ |
| 60933 | 61094 | rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags)); |
| 60934 | 61095 | } |
| 60935 | 61096 | } |
| 61097 | + if( rc==SQLITE_OK ){ |
| 61098 | + rc = sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0); |
| 61099 | + if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 61100 | + } |
| 60936 | 61101 | if( rc==SQLITE_OK ){ |
| 60937 | 61102 | pInfo->nBackfill = mxSafeFrame; |
| 60938 | 61103 | } |
| 60939 | 61104 | } |
| 60940 | 61105 | |
| | @@ -65639,11 +65804,11 @@ |
| 65639 | 65804 | if( data[iPtr+1]==0 && data[iPtr]==0 ){ |
| 65640 | 65805 | iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */ |
| 65641 | 65806 | }else{ |
| 65642 | 65807 | while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){ |
| 65643 | 65808 | if( iFreeBlk<iPtr+4 ){ |
| 65644 | | - if( ALWAYS(iFreeBlk==0) ) break; |
| 65809 | + if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */ |
| 65645 | 65810 | return SQLITE_CORRUPT_PAGE(pPage); |
| 65646 | 65811 | } |
| 65647 | 65812 | iPtr = iFreeBlk; |
| 65648 | 65813 | } |
| 65649 | 65814 | if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */ |
| | @@ -76798,11 +76963,15 @@ |
| 76798 | 76963 | ){ |
| 76799 | 76964 | sqlite3VdbeMemNumerify(pVal); |
| 76800 | 76965 | if( pVal->flags & MEM_Real ){ |
| 76801 | 76966 | pVal->u.r = -pVal->u.r; |
| 76802 | 76967 | }else if( pVal->u.i==SMALLEST_INT64 ){ |
| 76968 | +#ifndef SQLITE_OMIT_FLOATING_POINT |
| 76803 | 76969 | pVal->u.r = -(double)SMALLEST_INT64; |
| 76970 | +#else |
| 76971 | + pVal->u.r = LARGEST_INT64; |
| 76972 | +#endif |
| 76804 | 76973 | MemSetTypeFlag(pVal, MEM_Real); |
| 76805 | 76974 | }else{ |
| 76806 | 76975 | pVal->u.i = -pVal->u.i; |
| 76807 | 76976 | } |
| 76808 | 76977 | sqlite3ValueApplyAffinity(pVal, affinity, enc); |
| | @@ -78351,18 +78520,20 @@ |
| 78351 | 78520 | ){ |
| 78352 | 78521 | if( N==0 ) return; |
| 78353 | 78522 | assert( pParse->pVdbe ); |
| 78354 | 78523 | assert( iFirst>=1 ); |
| 78355 | 78524 | assert( iFirst+N-1<=pParse->nMem ); |
| 78356 | | - while( N>0 && (mask&1)!=0 ){ |
| 78357 | | - mask >>= 1; |
| 78358 | | - iFirst++; |
| 78359 | | - N--; |
| 78360 | | - } |
| 78361 | | - while( N>0 && N<=32 && (mask & MASKBIT32(N-1))!=0 ){ |
| 78362 | | - mask &= ~MASKBIT32(N-1); |
| 78363 | | - N--; |
| 78525 | + if( N<=31 && mask!=0 ){ |
| 78526 | + while( N>0 && (mask&1)!=0 ){ |
| 78527 | + mask >>= 1; |
| 78528 | + iFirst++; |
| 78529 | + N--; |
| 78530 | + } |
| 78531 | + while( N>0 && N<=32 && (mask & MASKBIT32(N-1))!=0 ){ |
| 78532 | + mask &= ~MASKBIT32(N-1); |
| 78533 | + N--; |
| 78534 | + } |
| 78364 | 78535 | } |
| 78365 | 78536 | if( N>0 ){ |
| 78366 | 78537 | sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask); |
| 78367 | 78538 | if( bUndefine ) sqlite3VdbeChangeP5(pParse->pVdbe, 1); |
| 78368 | 78539 | } |
| | @@ -85085,11 +85256,11 @@ |
| 85085 | 85256 | if( f & MEM_Zero ){ |
| 85086 | 85257 | sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero); |
| 85087 | 85258 | } |
| 85088 | 85259 | }else if( f & MEM_Str ){ |
| 85089 | 85260 | int j; |
| 85090 | | - int c; |
| 85261 | + u8 c; |
| 85091 | 85262 | if( f & MEM_Dyn ){ |
| 85092 | 85263 | c = 'z'; |
| 85093 | 85264 | assert( (f & (MEM_Static|MEM_Ephem))==0 ); |
| 85094 | 85265 | }else if( f & MEM_Static ){ |
| 85095 | 85266 | c = 't'; |
| | @@ -85100,11 +85271,11 @@ |
| 85100 | 85271 | }else{ |
| 85101 | 85272 | c = 's'; |
| 85102 | 85273 | } |
| 85103 | 85274 | sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n); |
| 85104 | 85275 | for(j=0; j<25 && j<pMem->n; j++){ |
| 85105 | | - u8 c = pMem->z[j]; |
| 85276 | + c = pMem->z[j]; |
| 85106 | 85277 | sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.'); |
| 85107 | 85278 | } |
| 85108 | 85279 | sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]); |
| 85109 | 85280 | } |
| 85110 | 85281 | } |
| | @@ -88577,19 +88748,17 @@ |
| 88577 | 88748 | SQLITE_OPEN_DELETEONCLOSE | |
| 88578 | 88749 | SQLITE_OPEN_TRANSIENT_DB; |
| 88579 | 88750 | assert( pOp->p1>=0 ); |
| 88580 | 88751 | assert( pOp->p2>=0 ); |
| 88581 | 88752 | pCx = p->apCsr[pOp->p1]; |
| 88582 | | - if( pCx ){ |
| 88753 | + if( pCx && pCx->pBtx ){ |
| 88583 | 88754 | /* If the ephermeral table is already open, erase all existing content |
| 88584 | 88755 | ** so that the table is empty again, rather than creating a new table. */ |
| 88585 | 88756 | assert( pCx->isEphemeral ); |
| 88586 | 88757 | pCx->seqCount = 0; |
| 88587 | 88758 | pCx->cacheStatus = CACHE_STALE; |
| 88588 | | - if( pCx->pBtx ){ |
| 88589 | | - rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0); |
| 88590 | | - } |
| 88759 | + rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0); |
| 88591 | 88760 | }else{ |
| 88592 | 88761 | pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE); |
| 88593 | 88762 | if( pCx==0 ) goto no_mem; |
| 88594 | 88763 | pCx->isEphemeral = 1; |
| 88595 | 88764 | rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx, |
| | @@ -97441,15 +97610,18 @@ |
| 97441 | 97610 | ** constant because they are constant for the duration of one query. |
| 97442 | 97611 | ** This allows them to be factored out of inner loops. */ |
| 97443 | 97612 | ExprSetProperty(pExpr,EP_ConstFunc); |
| 97444 | 97613 | } |
| 97445 | 97614 | if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){ |
| 97446 | | - /* Date/time functions that use 'now', and other functions like |
| 97615 | + /* Clearly non-deterministic functions like random(), but also |
| 97616 | + ** date/time functions that use 'now', and other functions like |
| 97447 | 97617 | ** sqlite_version() that might change over time cannot be used |
| 97448 | | - ** in an index. */ |
| 97618 | + ** in an index or generated column. Curiously, they can be used |
| 97619 | + ** in a CHECK constraint. SQLServer, MySQL, and PostgreSQL all |
| 97620 | + ** all this. */ |
| 97449 | 97621 | sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions", |
| 97450 | | - NC_SelfRef, 0); |
| 97622 | + NC_IdxExpr|NC_PartIdx|NC_GenCol, 0); |
| 97451 | 97623 | }else{ |
| 97452 | 97624 | assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */ |
| 97453 | 97625 | pExpr->op2 = pNC->ncFlags & NC_SelfRef; |
| 97454 | 97626 | if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL); |
| 97455 | 97627 | } |
| | @@ -111196,12 +111368,12 @@ |
| 111196 | 111368 | if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){ |
| 111197 | 111369 | /* If there are errors in resolving the expression, change the |
| 111198 | 111370 | ** expression to a NULL. This prevents code generators that operate |
| 111199 | 111371 | ** on the expression from inserting extra parts into the expression |
| 111200 | 111372 | ** tree that have been allocated from lookaside memory, which is |
| 111201 | | - ** illegal in a schema and will lead to errors heap corruption when |
| 111202 | | - ** the database connection closes. */ |
| 111373 | + ** illegal in a schema and will lead to errors or heap corruption |
| 111374 | + ** when the database connection closes. */ |
| 111203 | 111375 | sqlite3ExprDelete(db, pX); |
| 111204 | 111376 | p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0); |
| 111205 | 111377 | } |
| 111206 | 111378 | }else{ |
| 111207 | 111379 | nNG++; |
| | @@ -115463,11 +115635,13 @@ |
| 115463 | 115635 | ** time functions, are implemented separately.) |
| 115464 | 115636 | */ |
| 115465 | 115637 | /* #include "sqliteInt.h" */ |
| 115466 | 115638 | /* #include <stdlib.h> */ |
| 115467 | 115639 | /* #include <assert.h> */ |
| 115640 | +#ifndef SQLITE_OMIT_FLOATING_POINT |
| 115468 | 115641 | /* #include <math.h> */ |
| 115642 | +#endif |
| 115469 | 115643 | /* #include "vdbeInt.h" */ |
| 115470 | 115644 | |
| 115471 | 115645 | /* |
| 115472 | 115646 | ** Return the collating function associated with a function. |
| 115473 | 115647 | */ |
| | @@ -120572,17 +120746,19 @@ |
| 120572 | 120746 | ** pass is sufficient */ |
| 120573 | 120747 | break; |
| 120574 | 120748 | } |
| 120575 | 120749 | if( b2ndPass ) break; /* Never need more than 2 passes */ |
| 120576 | 120750 | b2ndPass = 1; |
| 120751 | +#ifndef SQLITE_OMIT_GENERATED_COLUMNS |
| 120577 | 120752 | if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){ |
| 120578 | 120753 | /* If any NOT NULL ON CONFLICT REPLACE constraints fired on the |
| 120579 | 120754 | ** first pass, recomputed values for all generated columns, as |
| 120580 | 120755 | ** those values might depend on columns affected by the REPLACE. |
| 120581 | 120756 | */ |
| 120582 | 120757 | sqlite3ComputeGeneratedColumns(pParse, regNewData+1, pTab); |
| 120583 | 120758 | } |
| 120759 | +#endif |
| 120584 | 120760 | } /* end of 2-pass loop */ |
| 120585 | 120761 | } /* end if( has-not-null-constraints ) */ |
| 120586 | 120762 | |
| 120587 | 120763 | /* Test all CHECK constraints |
| 120588 | 120764 | */ |
| | @@ -122287,11 +122463,16 @@ |
| 122287 | 122463 | /* Version 3.28.0 and later */ |
| 122288 | 122464 | int (*stmt_isexplain)(sqlite3_stmt*); |
| 122289 | 122465 | int (*value_frombind)(sqlite3_value*); |
| 122290 | 122466 | /* Version 3.30.0 and later */ |
| 122291 | 122467 | int (*drop_modules)(sqlite3*,const char**); |
| 122468 | + /* Version 3.31.0 and later */ |
| 122292 | 122469 | sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64); |
| 122470 | + const char *(*uri_key)(const char*,int); |
| 122471 | + const char *(*filename_database)(const char*); |
| 122472 | + const char *(*filename_journal)(const char*); |
| 122473 | + const char *(*filename_wal)(const char*); |
| 122293 | 122474 | }; |
| 122294 | 122475 | |
| 122295 | 122476 | /* |
| 122296 | 122477 | ** This is the function signature used for all extension entry points. It |
| 122297 | 122478 | ** is also defined in the file "loadext.c". |
| | @@ -122582,11 +122763,16 @@ |
| 122582 | 122763 | /* Version 3.28.0 and later */ |
| 122583 | 122764 | #define sqlite3_stmt_isexplain sqlite3_api->isexplain |
| 122584 | 122765 | #define sqlite3_value_frombind sqlite3_api->frombind |
| 122585 | 122766 | /* Version 3.30.0 and later */ |
| 122586 | 122767 | #define sqlite3_drop_modules sqlite3_api->drop_modules |
| 122768 | +/* Version 3.31.0 andn later */ |
| 122587 | 122769 | #define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64 |
| 122770 | +#define sqlite3_uri_key sqlite3_api->uri_key |
| 122771 | +#define sqlite3_filename_database sqlite3_api->filename_database |
| 122772 | +#define sqlite3_filename_journal sqlite3_api->filename_journal |
| 122773 | +#define sqlite3_filename_wal sqlite3_api->filename_wal |
| 122588 | 122774 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 122589 | 122775 | |
| 122590 | 122776 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 122591 | 122777 | /* This case when the file really is being compiled as a loadable |
| 122592 | 122778 | ** extension */ |
| | @@ -123057,10 +123243,14 @@ |
| 123057 | 123243 | #else |
| 123058 | 123244 | 0, |
| 123059 | 123245 | #endif |
| 123060 | 123246 | /* Version 3.31.0 and later */ |
| 123061 | 123247 | sqlite3_hard_heap_limit64, |
| 123248 | + sqlite3_uri_key, |
| 123249 | + sqlite3_filename_database, |
| 123250 | + sqlite3_filename_journal, |
| 123251 | + sqlite3_filename_wal, |
| 123062 | 123252 | }; |
| 123063 | 123253 | |
| 123064 | 123254 | /* |
| 123065 | 123255 | ** Attempt to load an SQLite extension library contained in the file |
| 123066 | 123256 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| | @@ -125937,14 +126127,21 @@ |
| 125937 | 126127 | /* Only change the value of sqlite.enc if the database handle is not |
| 125938 | 126128 | ** initialized. If the main database exists, the new sqlite.enc value |
| 125939 | 126129 | ** will be overwritten when the schema is next loaded. If it does not |
| 125940 | 126130 | ** already exists, it will be created to use the new encoding value. |
| 125941 | 126131 | */ |
| 125942 | | - if( |
| 125943 | | - !(DbHasProperty(db, 0, DB_SchemaLoaded)) || |
| 125944 | | - DbHasProperty(db, 0, DB_Empty) |
| 125945 | | - ){ |
| 126132 | + int canChangeEnc = 1; /* True if allowed to change the encoding */ |
| 126133 | + int i; /* For looping over all attached databases */ |
| 126134 | + for(i=0; i<db->nDb; i++){ |
| 126135 | + if( db->aDb[i].pBt!=0 |
| 126136 | + && DbHasProperty(db,i,DB_SchemaLoaded) |
| 126137 | + && !DbHasProperty(db,i,DB_Empty) |
| 126138 | + ){ |
| 126139 | + canChangeEnc = 0; |
| 126140 | + } |
| 126141 | + } |
| 126142 | + if( canChangeEnc ){ |
| 125946 | 126143 | for(pEnc=&encnames[0]; pEnc->zName; pEnc++){ |
| 125947 | 126144 | if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){ |
| 125948 | 126145 | SCHEMA_ENC(db) = ENC(db) = |
| 125949 | 126146 | pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE; |
| 125950 | 126147 | break; |
| | @@ -130138,11 +130335,13 @@ |
| 130138 | 130335 | assert( p->selFlags & SF_MultiValue ); |
| 130139 | 130336 | do{ |
| 130140 | 130337 | assert( p->selFlags & SF_Values ); |
| 130141 | 130338 | assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) ); |
| 130142 | 130339 | assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr ); |
| 130340 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 130143 | 130341 | if( p->pWin ) return -1; |
| 130342 | +#endif |
| 130144 | 130343 | if( p->pPrior==0 ) break; |
| 130145 | 130344 | assert( p->pPrior->pNext==p ); |
| 130146 | 130345 | p = p->pPrior; |
| 130147 | 130346 | nRow += bShowAll; |
| 130148 | 130347 | }while(1); |
| | @@ -131501,11 +131700,13 @@ |
| 131501 | 131700 | assert( pSub->pSrc!=0 ); |
| 131502 | 131701 | assert( pSub->pEList->nExpr==pSub1->pEList->nExpr ); |
| 131503 | 131702 | if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */ |
| 131504 | 131703 | || (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */ |
| 131505 | 131704 | || pSub1->pSrc->nSrc<1 /* (17c) */ |
| 131705 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 131506 | 131706 | || pSub1->pWin /* (17e) */ |
| 131707 | +#endif |
| 131507 | 131708 | ){ |
| 131508 | 131709 | return 0; |
| 131509 | 131710 | } |
| 131510 | 131711 | testcase( pSub1->pSrc->nSrc>1 ); |
| 131511 | 131712 | } |
| | @@ -131875,11 +132076,15 @@ |
| 131875 | 132076 | */ |
| 131876 | 132077 | static int propagateConstantExprRewrite(Walker *pWalker, Expr *pExpr){ |
| 131877 | 132078 | int i; |
| 131878 | 132079 | WhereConst *pConst; |
| 131879 | 132080 | if( pExpr->op!=TK_COLUMN ) return WRC_Continue; |
| 131880 | | - if( ExprHasProperty(pExpr, EP_FixedCol) ) return WRC_Continue; |
| 132081 | + if( ExprHasProperty(pExpr, EP_FixedCol|EP_FromJoin) ){ |
| 132082 | + testcase( ExprHasProperty(pExpr, EP_FixedCol) ); |
| 132083 | + testcase( ExprHasProperty(pExpr, EP_FromJoin) ); |
| 132084 | + return WRC_Continue; |
| 132085 | + } |
| 131881 | 132086 | pConst = pWalker->u.pConst; |
| 131882 | 132087 | for(i=0; i<pConst->nConst; i++){ |
| 131883 | 132088 | Expr *pColumn = pConst->apExpr[i*2]; |
| 131884 | 132089 | if( pColumn==pExpr ) continue; |
| 131885 | 132090 | if( pColumn->iTable!=pExpr->iTable ) continue; |
| | @@ -132604,11 +132809,11 @@ |
| 132604 | 132809 | } |
| 132605 | 132810 | pTab->nTabRef++; |
| 132606 | 132811 | if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){ |
| 132607 | 132812 | return WRC_Abort; |
| 132608 | 132813 | } |
| 132609 | | -#if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE) |
| 132814 | +#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_VIRTUALTABLE) |
| 132610 | 132815 | if( IsVirtual(pTab) || pTab->pSelect ){ |
| 132611 | 132816 | i16 nCol; |
| 132612 | 132817 | u8 eCodeOrig = pWalker->eCode; |
| 132613 | 132818 | if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort; |
| 132614 | 132819 | assert( pFrom->pSelect==0 ); |
| | @@ -133756,11 +133961,13 @@ |
| 133756 | 133961 | ** written the query must use a temp-table for at least one of the ORDER |
| 133757 | 133962 | ** BY and DISTINCT, and an index or separate temp-table for the other. |
| 133758 | 133963 | */ |
| 133759 | 133964 | if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct |
| 133760 | 133965 | && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0 |
| 133966 | +#ifndef SQLITE_OMIT_WINDOWFUNC |
| 133761 | 133967 | && p->pWin==0 |
| 133968 | +#endif |
| 133762 | 133969 | ){ |
| 133763 | 133970 | p->selFlags &= ~SF_Distinct; |
| 133764 | 133971 | pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0); |
| 133765 | 133972 | p->selFlags |= SF_Aggregate; |
| 133766 | 133973 | /* Notice that even thought SF_Distinct has been cleared from p->selFlags, |
| | @@ -139191,26 +139398,26 @@ |
| 139191 | 139398 | }; |
| 139192 | 139399 | |
| 139193 | 139400 | /* |
| 139194 | 139401 | ** Allowed values of WhereTerm.wtFlags |
| 139195 | 139402 | */ |
| 139196 | | -#define TERM_DYNAMIC 0x01 /* Need to call sqlite3ExprDelete(db, pExpr) */ |
| 139197 | | -#define TERM_VIRTUAL 0x02 /* Added by the optimizer. Do not code */ |
| 139198 | | -#define TERM_CODED 0x04 /* This term is already coded */ |
| 139199 | | -#define TERM_COPIED 0x08 /* Has a child */ |
| 139200 | | -#define TERM_ORINFO 0x10 /* Need to free the WhereTerm.u.pOrInfo object */ |
| 139201 | | -#define TERM_ANDINFO 0x20 /* Need to free the WhereTerm.u.pAndInfo obj */ |
| 139202 | | -#define TERM_OR_OK 0x40 /* Used during OR-clause processing */ |
| 139403 | +#define TERM_DYNAMIC 0x0001 /* Need to call sqlite3ExprDelete(db, pExpr) */ |
| 139404 | +#define TERM_VIRTUAL 0x0002 /* Added by the optimizer. Do not code */ |
| 139405 | +#define TERM_CODED 0x0004 /* This term is already coded */ |
| 139406 | +#define TERM_COPIED 0x0008 /* Has a child */ |
| 139407 | +#define TERM_ORINFO 0x0010 /* Need to free the WhereTerm.u.pOrInfo object */ |
| 139408 | +#define TERM_ANDINFO 0x0020 /* Need to free the WhereTerm.u.pAndInfo obj */ |
| 139409 | +#define TERM_OR_OK 0x0040 /* Used during OR-clause processing */ |
| 139203 | 139410 | #ifdef SQLITE_ENABLE_STAT4 |
| 139204 | | -# define TERM_VNULL 0x80 /* Manufactured x>NULL or x<=NULL term */ |
| 139411 | +# define TERM_VNULL 0x0080 /* Manufactured x>NULL or x<=NULL term */ |
| 139205 | 139412 | #else |
| 139206 | | -# define TERM_VNULL 0x00 /* Disabled if not using stat4 */ |
| 139413 | +# define TERM_VNULL 0x0000 /* Disabled if not using stat4 */ |
| 139207 | 139414 | #endif |
| 139208 | | -#define TERM_LIKEOPT 0x100 /* Virtual terms from the LIKE optimization */ |
| 139209 | | -#define TERM_LIKECOND 0x200 /* Conditionally this LIKE operator term */ |
| 139210 | | -#define TERM_LIKE 0x400 /* The original LIKE operator */ |
| 139211 | | -#define TERM_IS 0x800 /* Term.pExpr is an IS operator */ |
| 139415 | +#define TERM_LIKEOPT 0x0100 /* Virtual terms from the LIKE optimization */ |
| 139416 | +#define TERM_LIKECOND 0x0200 /* Conditionally this LIKE operator term */ |
| 139417 | +#define TERM_LIKE 0x0400 /* The original LIKE operator */ |
| 139418 | +#define TERM_IS 0x0800 /* Term.pExpr is an IS operator */ |
| 139212 | 139419 | #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */ |
| 139213 | 139420 | |
| 139214 | 139421 | /* |
| 139215 | 139422 | ** An instance of the WhereScan object is used as an iterator for locating |
| 139216 | 139423 | ** terms in the WHERE clause that are useful to the query planner. |
| | @@ -141660,13 +141867,13 @@ |
| 141660 | 141867 | WhereTerm *pOrTerm = &pOrWc->a[ii]; |
| 141661 | 141868 | if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){ |
| 141662 | 141869 | WhereInfo *pSubWInfo; /* Info for single OR-term scan */ |
| 141663 | 141870 | Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */ |
| 141664 | 141871 | int jmp1 = 0; /* Address of jump operation */ |
| 141665 | | - assert( (pTabItem[0].fg.jointype & JT_LEFT)==0 |
| 141666 | | - || ExprHasProperty(pOrExpr, EP_FromJoin) |
| 141667 | | - ); |
| 141872 | + testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0 |
| 141873 | + && !ExprHasProperty(pOrExpr, EP_FromJoin) |
| 141874 | + ); /* See TH3 vtab25.400 and ticket 614b25314c766238 */ |
| 141668 | 141875 | if( pAndExpr ){ |
| 141669 | 141876 | pAndExpr->pLeft = pOrExpr; |
| 141670 | 141877 | pOrExpr = pAndExpr; |
| 141671 | 141878 | } |
| 141672 | 141879 | /* Loop through table entries that match term pOrTerm. */ |
| | @@ -148498,18 +148705,18 @@ |
| 148498 | 148705 | ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3); |
| 148499 | 148706 | ** |
| 148500 | 148707 | ** then table t2 can be omitted from the following: |
| 148501 | 148708 | ** |
| 148502 | 148709 | ** SELECT v1, v3 FROM t1 |
| 148503 | | - ** LEFT JOIN t2 USING (t1.ipk=t2.ipk) |
| 148504 | | - ** LEFT JOIN t3 USING (t1.ipk=t3.ipk) |
| 148710 | + ** LEFT JOIN t2 ON (t1.ipk=t2.ipk) |
| 148711 | + ** LEFT JOIN t3 ON (t1.ipk=t3.ipk) |
| 148505 | 148712 | ** |
| 148506 | 148713 | ** or from: |
| 148507 | 148714 | ** |
| 148508 | 148715 | ** SELECT DISTINCT v1, v3 FROM t1 |
| 148509 | 148716 | ** LEFT JOIN t2 |
| 148510 | | - ** LEFT JOIN t3 USING (t1.ipk=t3.ipk) |
| 148717 | + ** LEFT JOIN t3 ON (t1.ipk=t3.ipk) |
| 148511 | 148718 | */ |
| 148512 | 148719 | notReady = ~(Bitmask)0; |
| 148513 | 148720 | if( pWInfo->nLevel>=2 |
| 148514 | 148721 | && pResultSet!=0 /* guarantees condition (1) above */ |
| 148515 | 148722 | && OptimizationEnabled(db, SQLITE_OmitNoopJoin) |
| | @@ -162726,10 +162933,11 @@ |
| 162726 | 162933 | ** xRandomness method on the primary VFS. |
| 162727 | 162934 | ** |
| 162728 | 162935 | ** This test-control also resets the PRNG so that the new seed will |
| 162729 | 162936 | ** be used for the next call to sqlite3_randomness(). |
| 162730 | 162937 | */ |
| 162938 | +#ifndef SQLITE_OMIT_WSD |
| 162731 | 162939 | case SQLITE_TESTCTRL_PRNG_SEED: { |
| 162732 | 162940 | int x = va_arg(ap, int); |
| 162733 | 162941 | int y; |
| 162734 | 162942 | sqlite3 *db = va_arg(ap, sqlite3*); |
| 162735 | 162943 | assert( db==0 || db->aDb[0].pSchema!=0 ); |
| | @@ -162736,10 +162944,11 @@ |
| 162736 | 162944 | if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; } |
| 162737 | 162945 | sqlite3Config.iPrngSeed = x; |
| 162738 | 162946 | sqlite3_randomness(0,0); |
| 162739 | 162947 | break; |
| 162740 | 162948 | } |
| 162949 | +#endif |
| 162741 | 162950 | |
| 162742 | 162951 | /* |
| 162743 | 162952 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| 162744 | 162953 | ** |
| 162745 | 162954 | ** Run a test against a Bitvec object of size. The program argument |
| | @@ -163063,29 +163272,10 @@ |
| 163063 | 163272 | va_end(ap); |
| 163064 | 163273 | #endif /* SQLITE_UNTESTABLE */ |
| 163065 | 163274 | return rc; |
| 163066 | 163275 | } |
| 163067 | 163276 | |
| 163068 | | -#ifdef SQLITE_DEBUG |
| 163069 | | -/* |
| 163070 | | -** This routine appears inside assert() statements only. |
| 163071 | | -** |
| 163072 | | -** Return the number of URI parameters that follow the filename. |
| 163073 | | -*/ |
| 163074 | | -SQLITE_PRIVATE int sqlite3UriCount(const char *z){ |
| 163075 | | - int n = 0; |
| 163076 | | - if( z==0 ) return 0; |
| 163077 | | - z += strlen(z)+1; |
| 163078 | | - while( z[0] ){ |
| 163079 | | - z += strlen(z)+1; |
| 163080 | | - z += strlen(z)+1; |
| 163081 | | - n++; |
| 163082 | | - } |
| 163083 | | - return n; |
| 163084 | | -} |
| 163085 | | -#endif /* SQLITE_DEBUG */ |
| 163086 | | - |
| 163087 | 163277 | /* |
| 163088 | 163278 | ** This is a utility routine, useful to VFS implementations, that checks |
| 163089 | 163279 | ** to see if a database file was a URI that contained a specific query |
| 163090 | 163280 | ** parameter, and if so obtains the value of the query parameter. |
| 163091 | 163281 | ** |
| | @@ -163104,10 +163294,23 @@ |
| 163104 | 163294 | if( x==0 ) return zFilename; |
| 163105 | 163295 | zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163106 | 163296 | } |
| 163107 | 163297 | return 0; |
| 163108 | 163298 | } |
| 163299 | + |
| 163300 | +/* |
| 163301 | +** Return a pointer to the name of Nth query parameter of the filename. |
| 163302 | +*/ |
| 163303 | +SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N){ |
| 163304 | + if( zFilename==0 || N<0 ) return 0; |
| 163305 | + zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163306 | + while( zFilename[0] && (N--)>0 ){ |
| 163307 | + zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163308 | + zFilename += sqlite3Strlen30(zFilename) + 1; |
| 163309 | + } |
| 163310 | + return zFilename[0] ? zFilename : 0; |
| 163311 | +} |
| 163109 | 163312 | |
| 163110 | 163313 | /* |
| 163111 | 163314 | ** Return a boolean value for a query parameter. |
| 163112 | 163315 | */ |
| 163113 | 163316 | SQLITE_API int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){ |
| | @@ -163129,10 +163332,50 @@ |
| 163129 | 163332 | if( z && sqlite3DecOrHexToI64(z, &v)==0 ){ |
| 163130 | 163333 | bDflt = v; |
| 163131 | 163334 | } |
| 163132 | 163335 | return bDflt; |
| 163133 | 163336 | } |
| 163337 | + |
| 163338 | +/* |
| 163339 | +** The Pager stores the Journal filename, WAL filename, and Database filename |
| 163340 | +** consecutively in memory, in that order, with prefixes \000\001\000, |
| 163341 | +** \002\000, and \003\000, in that order. Thus the three names look like query |
| 163342 | +** parameters if you start at the first prefix. |
| 163343 | +** |
| 163344 | +** This routine backs up a filename to the start of the first prefix. |
| 163345 | +** |
| 163346 | +** This only works if the filenamed passed in was obtained from the Pager. |
| 163347 | +*/ |
| 163348 | +static const char *startOfNameList(const char *zName){ |
| 163349 | + while( zName[0]!='\001' || zName[1]!=0 ){ |
| 163350 | + zName -= 3; |
| 163351 | + while( zName[0]!='\000' ){ zName--; } |
| 163352 | + zName++; |
| 163353 | + } |
| 163354 | + return zName-1; |
| 163355 | +} |
| 163356 | + |
| 163357 | +/* |
| 163358 | +** Translate a filename that was handed to a VFS routine into the corresponding |
| 163359 | +** database, journal, or WAL file. |
| 163360 | +** |
| 163361 | +** It is an error to pass this routine a filename string that was not |
| 163362 | +** passed into the VFS from the SQLite core. Doing so is similar to |
| 163363 | +** passing free() a pointer that was not obtained from malloc() - it is |
| 163364 | +** an error that we cannot easily detect but that will likely cause memory |
| 163365 | +** corruption. |
| 163366 | +*/ |
| 163367 | +SQLITE_API const char *sqlite3_filename_database(const char *zFilename){ |
| 163368 | + return sqlite3_uri_parameter(zFilename - 3, "\003"); |
| 163369 | +} |
| 163370 | +SQLITE_API const char *sqlite3_filename_journal(const char *zFilename){ |
| 163371 | + const char *z = sqlite3_uri_parameter(startOfNameList(zFilename), "\001"); |
| 163372 | + return ALWAYS(z) && z[0] ? z : 0; |
| 163373 | +} |
| 163374 | +SQLITE_API const char *sqlite3_filename_wal(const char *zFilename){ |
| 163375 | + return sqlite3_uri_parameter(startOfNameList(zFilename), "\002"); |
| 163376 | +} |
| 163134 | 163377 | |
| 163135 | 163378 | /* |
| 163136 | 163379 | ** Return the Btree pointer identified by zDbName. Return NULL if not found. |
| 163137 | 163380 | */ |
| 163138 | 163381 | SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){ |
| | @@ -198461,37 +198704,10 @@ |
| 198461 | 198704 | rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag); |
| 198462 | 198705 | } |
| 198463 | 198706 | return rc; |
| 198464 | 198707 | } |
| 198465 | 198708 | |
| 198466 | | -/* |
| 198467 | | -** A main database named zName has just been opened. The following |
| 198468 | | -** function returns a pointer to a buffer owned by SQLite that contains |
| 198469 | | -** the name of the *-wal file this db connection will use. SQLite |
| 198470 | | -** happens to pass a pointer to this buffer when using xAccess() |
| 198471 | | -** or xOpen() to operate on the *-wal file. |
| 198472 | | -*/ |
| 198473 | | -static const char *rbuMainToWal(const char *zName, int flags){ |
| 198474 | | - int n = (int)strlen(zName); |
| 198475 | | - const char *z = &zName[n]; |
| 198476 | | - if( flags & SQLITE_OPEN_URI ){ |
| 198477 | | - int odd = 0; |
| 198478 | | - while( 1 ){ |
| 198479 | | - if( z[0]==0 ){ |
| 198480 | | - odd = 1 - odd; |
| 198481 | | - if( odd && z[1]==0 ) break; |
| 198482 | | - } |
| 198483 | | - z++; |
| 198484 | | - } |
| 198485 | | - z += 2; |
| 198486 | | - }else{ |
| 198487 | | - while( *z==0 ) z++; |
| 198488 | | - } |
| 198489 | | - z += (n + 8 + 2); |
| 198490 | | - return z; |
| 198491 | | -} |
| 198492 | | - |
| 198493 | 198709 | /* |
| 198494 | 198710 | ** Open an rbu file handle. |
| 198495 | 198711 | */ |
| 198496 | 198712 | static int rbuVfsOpen( |
| 198497 | 198713 | sqlite3_vfs *pVfs, |
| | @@ -198536,11 +198752,11 @@ |
| 198536 | 198752 | /* A main database has just been opened. The following block sets |
| 198537 | 198753 | ** (pFd->zWal) to point to a buffer owned by SQLite that contains |
| 198538 | 198754 | ** the name of the *-wal file this db connection will use. SQLite |
| 198539 | 198755 | ** happens to pass a pointer to this buffer when using xAccess() |
| 198540 | 198756 | ** or xOpen() to operate on the *-wal file. */ |
| 198541 | | - pFd->zWal = rbuMainToWal(zName, flags); |
| 198757 | + pFd->zWal = sqlite3_filename_wal(zName); |
| 198542 | 198758 | } |
| 198543 | 198759 | else if( flags & SQLITE_OPEN_WAL ){ |
| 198544 | 198760 | rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0); |
| 198545 | 198761 | if( pDb ){ |
| 198546 | 198762 | if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){ |
| | @@ -198551,11 +198767,11 @@ |
| 198551 | 198767 | const char *zBase = zName; |
| 198552 | 198768 | size_t nCopy; |
| 198553 | 198769 | char *zCopy; |
| 198554 | 198770 | if( rbuIsVacuum(pDb->pRbu) ){ |
| 198555 | 198771 | zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main"); |
| 198556 | | - zBase = rbuMainToWal(zBase, SQLITE_OPEN_URI); |
| 198772 | + zBase = sqlite3_filename_wal(zBase); |
| 198557 | 198773 | } |
| 198558 | 198774 | nCopy = strlen(zBase); |
| 198559 | 198775 | zCopy = sqlite3_malloc64(nCopy+2); |
| 198560 | 198776 | if( zCopy ){ |
| 198561 | 198777 | memcpy(zCopy, zBase, nCopy); |
| | @@ -223413,11 +223629,11 @@ |
| 223413 | 223629 | int nArg, /* Number of args */ |
| 223414 | 223630 | sqlite3_value **apUnused /* Function arguments */ |
| 223415 | 223631 | ){ |
| 223416 | 223632 | assert( nArg==0 ); |
| 223417 | 223633 | UNUSED_PARAM2(nArg, apUnused); |
| 223418 | | - sqlite3_result_text(pCtx, "fts5: 2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68", -1, SQLITE_TRANSIENT); |
| 223634 | + sqlite3_result_text(pCtx, "fts5: 2020-01-20 14:42:09 63d886f4ce3c770498b8bdad45b04143a3f63197d81793bde107450aba4a9c87", -1, SQLITE_TRANSIENT); |
| 223419 | 223635 | } |
| 223420 | 223636 | |
| 223421 | 223637 | /* |
| 223422 | 223638 | ** Return true if zName is the extension on one of the shadow tables used |
| 223423 | 223639 | ** by this module. |
| | @@ -228186,12 +228402,12 @@ |
| 228186 | 228402 | } |
| 228187 | 228403 | #endif /* SQLITE_CORE */ |
| 228188 | 228404 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 228189 | 228405 | |
| 228190 | 228406 | /************** End of stmt.c ************************************************/ |
| 228191 | | -#if __LINE__!=228191 |
| 228407 | +#if __LINE__!=228407 |
| 228192 | 228408 | #undef SQLITE_SOURCE_ID |
| 228193 | | -#define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0falt2" |
| 228409 | +#define SQLITE_SOURCE_ID "2020-01-20 14:42:09 63d886f4ce3c770498b8bdad45b04143a3f63197d81793bde107450aba4aalt2" |
| 228194 | 228410 | #endif |
| 228195 | 228411 | /* Return the source-id for this library */ |
| 228196 | 228412 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 228197 | 228413 | /************************** End of sqlite3.c ******************************/ |
| 228198 | 228414 | |