Fossil SCM

Update the built-in SQLite to the second beta for 3.31.0, for SQLite testing.

drh 2020-01-20 20:29 trunk
Commit f4e7ca02da2f9bfaea0c7e1fdea9667ba2ecc38b8bef4ef39e88439963bc613e
3 files changed +6 -2 +418 -202 +187 -66
+6 -2
--- src/shell.c
+++ src/shell.c
@@ -5524,14 +5524,14 @@
55245524
unusable = 1;
55255525
}else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
55265526
idx = i;
55275527
}
55285528
}
5529
+ pIdxInfo->estimatedCost = 1000.0;
55295530
if( idx>=0 ){
55305531
pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
55315532
pIdxInfo->aConstraintUsage[idx].omit = 1;
5532
- pIdxInfo->estimatedCost = 1000.0;
55335533
pIdxInfo->idxNum = 1;
55345534
}else if( unusable ){
55355535
return SQLITE_CONSTRAINT;
55365536
}
55375537
return SQLITE_OK;
@@ -11324,19 +11324,23 @@
1132411324
}
1132511325
1132611326
/* Create the TEMP table used to store parameter bindings */
1132711327
static void bind_table_init(ShellState *p){
1132811328
int wrSchema = 0;
11329
+ int defensiveMode = 0;
11330
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
11331
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
1132911332
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
1133011333
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
1133111334
sqlite3_exec(p->db,
1133211335
"CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
1133311336
" key TEXT PRIMARY KEY,\n"
1133411337
" value ANY\n"
1133511338
") WITHOUT ROWID;",
1133611339
0, 0, 0);
1133711340
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
11341
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
1133811342
}
1133911343
1134011344
/*
1134111345
** Bind parameters on a prepared statement.
1134211346
**
@@ -13485,11 +13489,11 @@
1348513489
static unsigned int get4byteInt(unsigned char *a){
1348613490
return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
1348713491
}
1348813492
1348913493
/*
13490
-** Implementation of the ".info" command.
13494
+** Implementation of the ".dbinfo" command.
1349113495
**
1349213496
** Return 1 on error, 2 to exit, and 0 otherwise.
1349313497
*/
1349413498
static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
1349513499
static const struct { const char *zName; int ofst; } aField[] = {
1349613500
--- src/shell.c
+++ src/shell.c
@@ -5524,14 +5524,14 @@
5524 unusable = 1;
5525 }else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
5526 idx = i;
5527 }
5528 }
 
5529 if( idx>=0 ){
5530 pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
5531 pIdxInfo->aConstraintUsage[idx].omit = 1;
5532 pIdxInfo->estimatedCost = 1000.0;
5533 pIdxInfo->idxNum = 1;
5534 }else if( unusable ){
5535 return SQLITE_CONSTRAINT;
5536 }
5537 return SQLITE_OK;
@@ -11324,19 +11324,23 @@
11324 }
11325
11326 /* Create the TEMP table used to store parameter bindings */
11327 static void bind_table_init(ShellState *p){
11328 int wrSchema = 0;
 
 
 
11329 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
11330 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
11331 sqlite3_exec(p->db,
11332 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
11333 " key TEXT PRIMARY KEY,\n"
11334 " value ANY\n"
11335 ") WITHOUT ROWID;",
11336 0, 0, 0);
11337 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
 
11338 }
11339
11340 /*
11341 ** Bind parameters on a prepared statement.
11342 **
@@ -13485,11 +13489,11 @@
13485 static unsigned int get4byteInt(unsigned char *a){
13486 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
13487 }
13488
13489 /*
13490 ** Implementation of the ".info" command.
13491 **
13492 ** Return 1 on error, 2 to exit, and 0 otherwise.
13493 */
13494 static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
13495 static const struct { const char *zName; int ofst; } aField[] = {
13496
--- src/shell.c
+++ src/shell.c
@@ -5524,14 +5524,14 @@
5524 unusable = 1;
5525 }else if( pCons->op==SQLITE_INDEX_CONSTRAINT_EQ ){
5526 idx = i;
5527 }
5528 }
5529 pIdxInfo->estimatedCost = 1000.0;
5530 if( idx>=0 ){
5531 pIdxInfo->aConstraintUsage[idx].argvIndex = 1;
5532 pIdxInfo->aConstraintUsage[idx].omit = 1;
 
5533 pIdxInfo->idxNum = 1;
5534 }else if( unusable ){
5535 return SQLITE_CONSTRAINT;
5536 }
5537 return SQLITE_OK;
@@ -11324,19 +11324,23 @@
11324 }
11325
11326 /* Create the TEMP table used to store parameter bindings */
11327 static void bind_table_init(ShellState *p){
11328 int wrSchema = 0;
11329 int defensiveMode = 0;
11330 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
11331 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
11332 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
11333 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
11334 sqlite3_exec(p->db,
11335 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
11336 " key TEXT PRIMARY KEY,\n"
11337 " value ANY\n"
11338 ") WITHOUT ROWID;",
11339 0, 0, 0);
11340 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
11341 sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
11342 }
11343
11344 /*
11345 ** Bind parameters on a prepared statement.
11346 **
@@ -13485,11 +13489,11 @@
13489 static unsigned int get4byteInt(unsigned char *a){
13490 return (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
13491 }
13492
13493 /*
13494 ** Implementation of the ".dbinfo" command.
13495 **
13496 ** Return 1 on error, 2 to exit, and 0 otherwise.
13497 */
13498 static int shell_dbinfo_command(ShellState *p, int nArg, char **azArg){
13499 static const struct { const char *zName; int ofst; } aField[] = {
13500
+418 -202
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
11651165
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11661166
** [sqlite_version()] and [sqlite_source_id()].
11671167
*/
11681168
#define SQLITE_VERSION "3.31.0"
11691169
#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"
11711171
11721172
/*
11731173
** CAPI3REF: Run-Time Library Version Numbers
11741174
** KEYWORDS: sqlite3_version sqlite3_sourceid
11751175
**
@@ -2151,10 +2151,16 @@
21512151
** a single attached database that occur due to other database connections,
21522152
** but omits changes implemented by the database connection on which it is
21532153
** called. This file control is the only mechanism to detect changes that
21542154
** happen either internally or externally and that are associated with
21552155
** 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.
21562162
** </ul>
21572163
*/
21582164
#define SQLITE_FCNTL_LOCKSTATE 1
21592165
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
21602166
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -2188,10 +2194,11 @@
21882194
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
21892195
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
21902196
#define SQLITE_FCNTL_LOCK_TIMEOUT 34
21912197
#define SQLITE_FCNTL_DATA_VERSION 35
21922198
#define SQLITE_FCNTL_SIZE_LIMIT 36
2199
+#define SQLITE_FCNTL_CKPT_DONE 37
21932200
21942201
/* deprecated names */
21952202
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
21962203
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
21972204
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3307,25 +3314,27 @@
33073314
** compile-time option.
33083315
** </dd>
33093316
**
33103317
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
33113318
** <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.
33143322
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
33153323
** takes additional defensive steps to protect the application from harm
3316
-** including, but not limited to, the following:
3324
+** including:
33173325
** <ul>
33183326
** <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
33233331
** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
33243332
** </ul>
33253333
** 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.
33273336
** </dd>
33283337
**
33293338
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
33303339
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
33313340
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
@@ -3834,11 +3843,11 @@
38343843
/*
38353844
** CAPI3REF: Memory Allocation Subsystem
38363845
**
38373846
** The SQLite core uses these three routines for all of its own
38383847
** 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
38403849
** Windows VFS uses native malloc() and free() for some operations.
38413850
**
38423851
** ^The sqlite3_malloc() routine returns a pointer to a block
38433852
** of memory at least N bytes in length, where N is the parameter.
38443853
** ^If sqlite3_malloc() is unable to obtain sufficient free
@@ -4317,14 +4326,12 @@
43174326
** passing it to [sqlite3_close()] when it is no longer required.
43184327
**
43194328
** The sqlite3_open_v2() interface works like sqlite3_open()
43204329
** except that it accepts two additional parameters for additional control
43214330
** 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:)^
43264333
**
43274334
** <dl>
43284335
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
43294336
** <dd>The database is opened in read-only mode. If the database does not
43304337
** already exist, an error is returned.</dd>)^
@@ -4337,28 +4344,56 @@
43374344
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
43384345
** <dd>The database is opened for reading and writing, and is created if
43394346
** it does not already exist. This is the behavior that is always used for
43404347
** sqlite3_open() and sqlite3_open16().</dd>)^
43414348
** </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>)^
43424389
**
43434390
** 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
43454392
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
43464393
** then the behavior is undefined.
43474394
**
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
-**
43604395
** ^The fourth parameter to sqlite3_open_v2() is the name of the
43614396
** [sqlite3_vfs] object that defines the operating system interface that
43624397
** the new database connection should use. ^If the fourth parameter is
43634398
** a NULL pointer then the default [sqlite3_vfs] object is used.
43644399
**
@@ -4534,18 +4569,17 @@
45344569
);
45354570
45364571
/*
45374572
** CAPI3REF: Obtain Values For URI Parameters
45384573
**
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
45414576
** parameter, and if so obtains the value of that query parameter.
45424577
**
45434578
** 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
45474581
** sqlite3_uri_parameter(F,P) returns the value of the P
45484582
** parameter if it exists or a NULL pointer if P does not appear as a
45494583
** query parameter on F. If P is a query parameter of F and it
45504584
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
45514585
** a pointer to an empty string.
@@ -4563,22 +4597,69 @@
45634597
**
45644598
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
45654599
** 64-bit signed integer and returns that integer, or D if P does not
45664600
** exist. If the value of P is something other than an integer, then
45674601
** 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.
45684609
**
45694610
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
45704611
** 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.
45744623
**
45754624
** See the [URI filename] documentation for additional information.
45764625
*/
45774626
SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
45784627
SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
45794628
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*);
45804661
45814662
45824663
/*
45834664
** CAPI3REF: Error Codes And Messages
45844665
** METHOD: sqlite3
@@ -5877,12 +5958,10 @@
58775958
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
58785959
58795960
/*
58805961
** CAPI3REF: Create Or Redefine SQL Functions
58815962
** KEYWORDS: {function creation routines}
5882
-** KEYWORDS: {application-defined SQL function}
5883
-** KEYWORDS: {application-defined SQL functions}
58845963
** METHOD: sqlite3
58855964
**
58865965
** ^These functions (collectively known as "function creation routines")
58875966
** are used to add SQL functions or aggregates or to redefine the behavior
58885967
** of existing SQL functions or aggregates. The only differences between
@@ -5934,13 +6013,24 @@
59346013
** perform additional optimizations on deterministic functions, so use
59356014
** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
59366015
**
59376016
** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
59386017
** 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>
59426032
**
59436033
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
59446034
** function can gain access to this pointer using [sqlite3_user_data()].)^
59456035
**
59466036
** ^The sixth, seventh and eighth parameters passed to the three
@@ -6055,46 +6145,66 @@
60556145
** These constants may be ORed together with the
60566146
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
60576147
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
60586148
** [sqlite3_create_function_v2()].
60596149
**
6150
+** <dl>
6151
+** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
60606152
** The SQLITE_DETERMINISTIC flag means that the new function always gives
60616153
** the same output when the input parameters are the same.
60626154
** The [abs|abs() function] is deterministic, for example, but
60636155
** [randomblob|randomblob()] is not. Functions must
60646156
** 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>
60676172
**
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
60696175
** 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.
60726179
** 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
60766189
** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
60776190
** are innocuous. Developers are advised to avoid using the
60786191
** 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>
60896197
** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
60906198
** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
60916199
** Specifying this flag makes no difference for scalar or aggregate user
60926200
** functions. However, if it is not specified for a user-defined window
60936201
** function, then any sub-types belonging to arguments passed to the window
60946202
** function may be discarded before the window function is called (i.e.
60956203
** sqlite3_value_subtype() will always return 0).
6204
+** </dd>
6205
+** </dl>
60966206
*/
60976207
#define SQLITE_DETERMINISTIC 0x000000800
60986208
#define SQLITE_DIRECTONLY 0x000080000
60996209
#define SQLITE_SUBTYPE 0x000100000
61006210
#define SQLITE_INNOCUOUS 0x000200000
@@ -7006,10 +7116,21 @@
70067116
**
70077117
** ^The filename returned by this function is the output of the
70087118
** xFullPathname method of the [VFS]. ^In other words, the filename
70097119
** will be an absolute pathname, even if the filename used
70107120
** 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>
70117132
*/
70127133
SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
70137134
70147135
/*
70157136
** CAPI3REF: Determine if a database is read-only
@@ -9974,10 +10095,18 @@
997410095
** silently replace the appropriate rows within the xUpdate callback and
997510096
** return SQLITE_OK. Or, if this is not possible, it may return
997610097
** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
997710098
** constraint handling.
997810099
** </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>
997910108
**
998010109
** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
998110110
** <dd>Calls of the form
998210111
** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
998310112
** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
@@ -9985,18 +10114,10 @@
998510114
** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
998610115
** virtual table can do no serious harm even if it is controlled by a
998710116
** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
998810117
** flag unless absolutely necessary.
998910118
** </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>
999810119
** </dl>
999910120
*/
1000010121
#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
1000110122
#define SQLITE_VTAB_INNOCUOUS 2
1000210123
#define SQLITE_VTAB_DIRECTONLY 3
@@ -15718,11 +15839,11 @@
1571815839
SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
1571915840
#ifdef SQLITE_DEBUG
1572015841
SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
1572115842
#endif
1572215843
SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
15723
-SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
15844
+SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager*, int);
1572415845
SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
1572515846
SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
1572615847
SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
1572715848
SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
1572815849
SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
@@ -19254,13 +19375,10 @@
1925419375
SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
1925519376
SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
1925619377
SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
1925719378
SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*);
1925819379
SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
19259
-#ifdef SQLITE_DEBUG
19260
-SQLITE_PRIVATE int sqlite3UriCount(const char*);
19261
-#endif
1926219380
SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
1926319381
sqlite3_vfs**,char**,char **);
1926419382
#ifdef SQLITE_HAS_CODEC
1926519383
SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*);
1926619384
#else
@@ -22090,11 +22208,11 @@
2209022208
*/
2209122209
if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
2209222210
r = p->s*1000.0 + 210866760000000.0;
2209322211
if( r>=0.0 && r<464269060800000.0 ){
2209422212
clearYMD_HMS_TZ(p);
22095
- p->iJD = (sqlite3_int64)r;
22213
+ p->iJD = (sqlite3_int64)(r + 0.5);
2209622214
p->validJD = 1;
2209722215
p->rawS = 0;
2209822216
rc = 0;
2209922217
}
2210022218
}
@@ -30871,11 +30989,13 @@
3087130989
** strings, and stuff like that.
3087230990
**
3087330991
*/
3087430992
/* #include "sqliteInt.h" */
3087530993
/* #include <stdarg.h> */
30994
+#ifndef SQLITE_OMIT_FLOATING_POINT
3087630995
#include <math.h>
30996
+#endif
3087730997
3087830998
/*
3087930999
** Routine needed to support the testcase() macro.
3088031000
*/
3088131001
#ifdef SQLITE_COVERAGE_TEST
@@ -56105,57 +56225,92 @@
5610556225
** Pager object (sizeof(Pager) bytes)
5610656226
** PCache object (sqlite3PcacheSize() bytes)
5610756227
** Database file handle (pVfs->szOsFile bytes)
5610856228
** Sub-journal file handle (journalFileSize bytes)
5610956229
** 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)
5611056235
** 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)
5611256238
*/
5611356239
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 */
5612056246
#ifndef SQLITE_OMIT_WAL
56121
- + nPathname + 4 + 2 /* zWal */
56247
+ 2 + /* WAL prefix */
56248
+ nPathname + 4 + 1 + /* WAL filename */
5612256249
#endif
56250
+ 2 + /* Database prefix */
56251
+ nPathname + 1 + /* database filename */
56252
+ nUriByte + /* query parameters */
56253
+ 2 /* Terminator */
5612356254
);
5612456255
assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
5612556256
if( !pPtr ){
5612656257
sqlite3DbFree(0, zPathname);
5612756258
return SQLITE_NOMEM_BKPT;
5612856259
}
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;
5613556265
assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
5613656266
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
+
5614656283
#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);
5615256293
#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++;
5615656297
}
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);
5615756312
pPager->pVfs = pVfs;
5615856313
pPager->vfsFlags = vfsFlags;
5615956314
5616056315
/* Open the pager file.
5616156316
*/
@@ -56200,13 +56355,13 @@
5620056355
}
5620156356
}
5620256357
}
5620356358
#endif
5620456359
}
56205
- pPager->noLock = sqlite3_uri_boolean(zFilename, "nolock", 0);
56360
+ pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
5620656361
if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
56207
- || sqlite3_uri_boolean(zFilename, "immutable", 0) ){
56362
+ || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){
5620856363
vfsFlags |= SQLITE_OPEN_READONLY;
5620956364
goto act_like_temp_file;
5621056365
}
5621156366
}
5621256367
}else{
@@ -58265,13 +58420,17 @@
5826558420
** nullIfMemDb is true. This routine is called with nullIfMemDb==1 when
5826658421
** used to report the filename to the user, for compatibility with legacy
5826758422
** behavior. But when the Btree needs to know the filename for matching to
5826858423
** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
5826958424
** 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.
5827058428
*/
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;
5827358432
}
5827458433
5827558434
/*
5827658435
** Return the VFS structure for the pager.
5827758436
*/
@@ -58921,10 +59080,12 @@
5892159080
if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
5892259081
}
5892359082
}
5892459083
return rc;
5892559084
}
59085
+
59086
+
5892659087
5892759088
#ifdef SQLITE_ENABLE_SNAPSHOT
5892859089
/*
5892959090
** If this is a WAL database, obtain a snapshot handle for the snapshot
5893059091
** currently open. Otherwise, return an error.
@@ -60931,10 +61092,14 @@
6093161092
rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
6093261093
if( rc==SQLITE_OK ){
6093361094
rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
6093461095
}
6093561096
}
61097
+ if( rc==SQLITE_OK ){
61098
+ rc = sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0);
61099
+ if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
61100
+ }
6093661101
if( rc==SQLITE_OK ){
6093761102
pInfo->nBackfill = mxSafeFrame;
6093861103
}
6093961104
}
6094061105
@@ -65639,11 +65804,11 @@
6563965804
if( data[iPtr+1]==0 && data[iPtr]==0 ){
6564065805
iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
6564165806
}else{
6564265807
while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
6564365808
if( iFreeBlk<iPtr+4 ){
65644
- if( ALWAYS(iFreeBlk==0) ) break;
65809
+ if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
6564565810
return SQLITE_CORRUPT_PAGE(pPage);
6564665811
}
6564765812
iPtr = iFreeBlk;
6564865813
}
6564965814
if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
@@ -76798,11 +76963,15 @@
7679876963
){
7679976964
sqlite3VdbeMemNumerify(pVal);
7680076965
if( pVal->flags & MEM_Real ){
7680176966
pVal->u.r = -pVal->u.r;
7680276967
}else if( pVal->u.i==SMALLEST_INT64 ){
76968
+#ifndef SQLITE_OMIT_FLOATING_POINT
7680376969
pVal->u.r = -(double)SMALLEST_INT64;
76970
+#else
76971
+ pVal->u.r = LARGEST_INT64;
76972
+#endif
7680476973
MemSetTypeFlag(pVal, MEM_Real);
7680576974
}else{
7680676975
pVal->u.i = -pVal->u.i;
7680776976
}
7680876977
sqlite3ValueApplyAffinity(pVal, affinity, enc);
@@ -78351,18 +78520,20 @@
7835178520
){
7835278521
if( N==0 ) return;
7835378522
assert( pParse->pVdbe );
7835478523
assert( iFirst>=1 );
7835578524
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
+ }
7836478535
}
7836578536
if( N>0 ){
7836678537
sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask);
7836778538
if( bUndefine ) sqlite3VdbeChangeP5(pParse->pVdbe, 1);
7836878539
}
@@ -85085,11 +85256,11 @@
8508585256
if( f & MEM_Zero ){
8508685257
sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero);
8508785258
}
8508885259
}else if( f & MEM_Str ){
8508985260
int j;
85090
- int c;
85261
+ u8 c;
8509185262
if( f & MEM_Dyn ){
8509285263
c = 'z';
8509385264
assert( (f & (MEM_Static|MEM_Ephem))==0 );
8509485265
}else if( f & MEM_Static ){
8509585266
c = 't';
@@ -85100,11 +85271,11 @@
8510085271
}else{
8510185272
c = 's';
8510285273
}
8510385274
sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n);
8510485275
for(j=0; j<25 && j<pMem->n; j++){
85105
- u8 c = pMem->z[j];
85276
+ c = pMem->z[j];
8510685277
sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
8510785278
}
8510885279
sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]);
8510985280
}
8511085281
}
@@ -88577,19 +88748,17 @@
8857788748
SQLITE_OPEN_DELETEONCLOSE |
8857888749
SQLITE_OPEN_TRANSIENT_DB;
8857988750
assert( pOp->p1>=0 );
8858088751
assert( pOp->p2>=0 );
8858188752
pCx = p->apCsr[pOp->p1];
88582
- if( pCx ){
88753
+ if( pCx && pCx->pBtx ){
8858388754
/* If the ephermeral table is already open, erase all existing content
8858488755
** so that the table is empty again, rather than creating a new table. */
8858588756
assert( pCx->isEphemeral );
8858688757
pCx->seqCount = 0;
8858788758
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);
8859188760
}else{
8859288761
pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
8859388762
if( pCx==0 ) goto no_mem;
8859488763
pCx->isEphemeral = 1;
8859588764
rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
@@ -97441,15 +97610,18 @@
9744197610
** constant because they are constant for the duration of one query.
9744297611
** This allows them to be factored out of inner loops. */
9744397612
ExprSetProperty(pExpr,EP_ConstFunc);
9744497613
}
9744597614
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
9744797617
** 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. */
9744997621
sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
97450
- NC_SelfRef, 0);
97622
+ NC_IdxExpr|NC_PartIdx|NC_GenCol, 0);
9745197623
}else{
9745297624
assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
9745397625
pExpr->op2 = pNC->ncFlags & NC_SelfRef;
9745497626
if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
9745597627
}
@@ -111196,12 +111368,12 @@
111196111368
if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
111197111369
/* If there are errors in resolving the expression, change the
111198111370
** expression to a NULL. This prevents code generators that operate
111199111371
** on the expression from inserting extra parts into the expression
111200111372
** 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. */
111203111375
sqlite3ExprDelete(db, pX);
111204111376
p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
111205111377
}
111206111378
}else{
111207111379
nNG++;
@@ -115463,11 +115635,13 @@
115463115635
** time functions, are implemented separately.)
115464115636
*/
115465115637
/* #include "sqliteInt.h" */
115466115638
/* #include <stdlib.h> */
115467115639
/* #include <assert.h> */
115640
+#ifndef SQLITE_OMIT_FLOATING_POINT
115468115641
/* #include <math.h> */
115642
+#endif
115469115643
/* #include "vdbeInt.h" */
115470115644
115471115645
/*
115472115646
** Return the collating function associated with a function.
115473115647
*/
@@ -120572,17 +120746,19 @@
120572120746
** pass is sufficient */
120573120747
break;
120574120748
}
120575120749
if( b2ndPass ) break; /* Never need more than 2 passes */
120576120750
b2ndPass = 1;
120751
+#ifndef SQLITE_OMIT_GENERATED_COLUMNS
120577120752
if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
120578120753
/* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
120579120754
** first pass, recomputed values for all generated columns, as
120580120755
** those values might depend on columns affected by the REPLACE.
120581120756
*/
120582120757
sqlite3ComputeGeneratedColumns(pParse, regNewData+1, pTab);
120583120758
}
120759
+#endif
120584120760
} /* end of 2-pass loop */
120585120761
} /* end if( has-not-null-constraints ) */
120586120762
120587120763
/* Test all CHECK constraints
120588120764
*/
@@ -122287,11 +122463,16 @@
122287122463
/* Version 3.28.0 and later */
122288122464
int (*stmt_isexplain)(sqlite3_stmt*);
122289122465
int (*value_frombind)(sqlite3_value*);
122290122466
/* Version 3.30.0 and later */
122291122467
int (*drop_modules)(sqlite3*,const char**);
122468
+ /* Version 3.31.0 and later */
122292122469
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*);
122293122474
};
122294122475
122295122476
/*
122296122477
** This is the function signature used for all extension entry points. It
122297122478
** is also defined in the file "loadext.c".
@@ -122582,11 +122763,16 @@
122582122763
/* Version 3.28.0 and later */
122583122764
#define sqlite3_stmt_isexplain sqlite3_api->isexplain
122584122765
#define sqlite3_value_frombind sqlite3_api->frombind
122585122766
/* Version 3.30.0 and later */
122586122767
#define sqlite3_drop_modules sqlite3_api->drop_modules
122768
+/* Version 3.31.0 andn later */
122587122769
#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
122588122774
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
122589122775
122590122776
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
122591122777
/* This case when the file really is being compiled as a loadable
122592122778
** extension */
@@ -123057,10 +123243,14 @@
123057123243
#else
123058123244
0,
123059123245
#endif
123060123246
/* Version 3.31.0 and later */
123061123247
sqlite3_hard_heap_limit64,
123248
+ sqlite3_uri_key,
123249
+ sqlite3_filename_database,
123250
+ sqlite3_filename_journal,
123251
+ sqlite3_filename_wal,
123062123252
};
123063123253
123064123254
/*
123065123255
** Attempt to load an SQLite extension library contained in the file
123066123256
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -125937,14 +126127,21 @@
125937126127
/* Only change the value of sqlite.enc if the database handle is not
125938126128
** initialized. If the main database exists, the new sqlite.enc value
125939126129
** will be overwritten when the schema is next loaded. If it does not
125940126130
** already exists, it will be created to use the new encoding value.
125941126131
*/
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 ){
125946126143
for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
125947126144
if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
125948126145
SCHEMA_ENC(db) = ENC(db) =
125949126146
pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
125950126147
break;
@@ -130138,11 +130335,13 @@
130138130335
assert( p->selFlags & SF_MultiValue );
130139130336
do{
130140130337
assert( p->selFlags & SF_Values );
130141130338
assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
130142130339
assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
130340
+#ifndef SQLITE_OMIT_WINDOWFUNC
130143130341
if( p->pWin ) return -1;
130342
+#endif
130144130343
if( p->pPrior==0 ) break;
130145130344
assert( p->pPrior->pNext==p );
130146130345
p = p->pPrior;
130147130346
nRow += bShowAll;
130148130347
}while(1);
@@ -131501,11 +131700,13 @@
131501131700
assert( pSub->pSrc!=0 );
131502131701
assert( pSub->pEList->nExpr==pSub1->pEList->nExpr );
131503131702
if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
131504131703
|| (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */
131505131704
|| pSub1->pSrc->nSrc<1 /* (17c) */
131705
+#ifndef SQLITE_OMIT_WINDOWFUNC
131506131706
|| pSub1->pWin /* (17e) */
131707
+#endif
131507131708
){
131508131709
return 0;
131509131710
}
131510131711
testcase( pSub1->pSrc->nSrc>1 );
131511131712
}
@@ -131875,11 +132076,15 @@
131875132076
*/
131876132077
static int propagateConstantExprRewrite(Walker *pWalker, Expr *pExpr){
131877132078
int i;
131878132079
WhereConst *pConst;
131879132080
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
+ }
131881132086
pConst = pWalker->u.pConst;
131882132087
for(i=0; i<pConst->nConst; i++){
131883132088
Expr *pColumn = pConst->apExpr[i*2];
131884132089
if( pColumn==pExpr ) continue;
131885132090
if( pColumn->iTable!=pExpr->iTable ) continue;
@@ -132604,11 +132809,11 @@
132604132809
}
132605132810
pTab->nTabRef++;
132606132811
if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
132607132812
return WRC_Abort;
132608132813
}
132609
-#if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
132814
+#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_VIRTUALTABLE)
132610132815
if( IsVirtual(pTab) || pTab->pSelect ){
132611132816
i16 nCol;
132612132817
u8 eCodeOrig = pWalker->eCode;
132613132818
if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
132614132819
assert( pFrom->pSelect==0 );
@@ -133756,11 +133961,13 @@
133756133961
** written the query must use a temp-table for at least one of the ORDER
133757133962
** BY and DISTINCT, and an index or separate temp-table for the other.
133758133963
*/
133759133964
if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
133760133965
&& sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
133966
+#ifndef SQLITE_OMIT_WINDOWFUNC
133761133967
&& p->pWin==0
133968
+#endif
133762133969
){
133763133970
p->selFlags &= ~SF_Distinct;
133764133971
pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
133765133972
p->selFlags |= SF_Aggregate;
133766133973
/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
@@ -139191,26 +139398,26 @@
139191139398
};
139192139399
139193139400
/*
139194139401
** Allowed values of WhereTerm.wtFlags
139195139402
*/
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 */
139203139410
#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 */
139205139412
#else
139206
-# define TERM_VNULL 0x00 /* Disabled if not using stat4 */
139413
+# define TERM_VNULL 0x0000 /* Disabled if not using stat4 */
139207139414
#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 */
139212139419
#define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */
139213139420
139214139421
/*
139215139422
** An instance of the WhereScan object is used as an iterator for locating
139216139423
** terms in the WHERE clause that are useful to the query planner.
@@ -141660,13 +141867,13 @@
141660141867
WhereTerm *pOrTerm = &pOrWc->a[ii];
141661141868
if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
141662141869
WhereInfo *pSubWInfo; /* Info for single OR-term scan */
141663141870
Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
141664141871
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 */
141668141875
if( pAndExpr ){
141669141876
pAndExpr->pLeft = pOrExpr;
141670141877
pOrExpr = pAndExpr;
141671141878
}
141672141879
/* Loop through table entries that match term pOrTerm. */
@@ -148498,18 +148705,18 @@
148498148705
** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3);
148499148706
**
148500148707
** then table t2 can be omitted from the following:
148501148708
**
148502148709
** 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)
148505148712
**
148506148713
** or from:
148507148714
**
148508148715
** SELECT DISTINCT v1, v3 FROM t1
148509148716
** LEFT JOIN t2
148510
- ** LEFT JOIN t3 USING (t1.ipk=t3.ipk)
148717
+ ** LEFT JOIN t3 ON (t1.ipk=t3.ipk)
148511148718
*/
148512148719
notReady = ~(Bitmask)0;
148513148720
if( pWInfo->nLevel>=2
148514148721
&& pResultSet!=0 /* guarantees condition (1) above */
148515148722
&& OptimizationEnabled(db, SQLITE_OmitNoopJoin)
@@ -162726,10 +162933,11 @@
162726162933
** xRandomness method on the primary VFS.
162727162934
**
162728162935
** This test-control also resets the PRNG so that the new seed will
162729162936
** be used for the next call to sqlite3_randomness().
162730162937
*/
162938
+#ifndef SQLITE_OMIT_WSD
162731162939
case SQLITE_TESTCTRL_PRNG_SEED: {
162732162940
int x = va_arg(ap, int);
162733162941
int y;
162734162942
sqlite3 *db = va_arg(ap, sqlite3*);
162735162943
assert( db==0 || db->aDb[0].pSchema!=0 );
@@ -162736,10 +162944,11 @@
162736162944
if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; }
162737162945
sqlite3Config.iPrngSeed = x;
162738162946
sqlite3_randomness(0,0);
162739162947
break;
162740162948
}
162949
+#endif
162741162950
162742162951
/*
162743162952
** sqlite3_test_control(BITVEC_TEST, size, program)
162744162953
**
162745162954
** Run a test against a Bitvec object of size. The program argument
@@ -163063,29 +163272,10 @@
163063163272
va_end(ap);
163064163273
#endif /* SQLITE_UNTESTABLE */
163065163274
return rc;
163066163275
}
163067163276
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
-
163087163277
/*
163088163278
** This is a utility routine, useful to VFS implementations, that checks
163089163279
** to see if a database file was a URI that contained a specific query
163090163280
** parameter, and if so obtains the value of the query parameter.
163091163281
**
@@ -163104,10 +163294,23 @@
163104163294
if( x==0 ) return zFilename;
163105163295
zFilename += sqlite3Strlen30(zFilename) + 1;
163106163296
}
163107163297
return 0;
163108163298
}
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
+}
163109163312
163110163313
/*
163111163314
** Return a boolean value for a query parameter.
163112163315
*/
163113163316
SQLITE_API int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){
@@ -163129,10 +163332,50 @@
163129163332
if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
163130163333
bDflt = v;
163131163334
}
163132163335
return bDflt;
163133163336
}
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
+}
163134163377
163135163378
/*
163136163379
** Return the Btree pointer identified by zDbName. Return NULL if not found.
163137163380
*/
163138163381
SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
@@ -198461,37 +198704,10 @@
198461198704
rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag);
198462198705
}
198463198706
return rc;
198464198707
}
198465198708
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
-
198493198709
/*
198494198710
** Open an rbu file handle.
198495198711
*/
198496198712
static int rbuVfsOpen(
198497198713
sqlite3_vfs *pVfs,
@@ -198536,11 +198752,11 @@
198536198752
/* A main database has just been opened. The following block sets
198537198753
** (pFd->zWal) to point to a buffer owned by SQLite that contains
198538198754
** the name of the *-wal file this db connection will use. SQLite
198539198755
** happens to pass a pointer to this buffer when using xAccess()
198540198756
** or xOpen() to operate on the *-wal file. */
198541
- pFd->zWal = rbuMainToWal(zName, flags);
198757
+ pFd->zWal = sqlite3_filename_wal(zName);
198542198758
}
198543198759
else if( flags & SQLITE_OPEN_WAL ){
198544198760
rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
198545198761
if( pDb ){
198546198762
if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
@@ -198551,11 +198767,11 @@
198551198767
const char *zBase = zName;
198552198768
size_t nCopy;
198553198769
char *zCopy;
198554198770
if( rbuIsVacuum(pDb->pRbu) ){
198555198771
zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
198556
- zBase = rbuMainToWal(zBase, SQLITE_OPEN_URI);
198772
+ zBase = sqlite3_filename_wal(zBase);
198557198773
}
198558198774
nCopy = strlen(zBase);
198559198775
zCopy = sqlite3_malloc64(nCopy+2);
198560198776
if( zCopy ){
198561198777
memcpy(zCopy, zBase, nCopy);
@@ -223413,11 +223629,11 @@
223413223629
int nArg, /* Number of args */
223414223630
sqlite3_value **apUnused /* Function arguments */
223415223631
){
223416223632
assert( nArg==0 );
223417223633
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);
223419223635
}
223420223636
223421223637
/*
223422223638
** Return true if zName is the extension on one of the shadow tables used
223423223639
** by this module.
@@ -228186,12 +228402,12 @@
228186228402
}
228187228403
#endif /* SQLITE_CORE */
228188228404
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
228189228405
228190228406
/************** End of stmt.c ************************************************/
228191
-#if __LINE__!=228191
228407
+#if __LINE__!=228407
228192228408
#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"
228194228410
#endif
228195228411
/* Return the source-id for this library */
228196228412
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
228197228413
/************************** End of sqlite3.c ******************************/
228198228414
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
1165 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1166 ** [sqlite_version()] and [sqlite_source_id()].
1167 */
1168 #define SQLITE_VERSION "3.31.0"
1169 #define SQLITE_VERSION_NUMBER 3031000
1170 #define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68"
1171
1172 /*
1173 ** CAPI3REF: Run-Time Library Version Numbers
1174 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1175 **
@@ -2151,10 +2151,16 @@
2151 ** a single attached database that occur due to other database connections,
2152 ** but omits changes implemented by the database connection on which it is
2153 ** called. This file control is the only mechanism to detect changes that
2154 ** happen either internally or externally and that are associated with
2155 ** a particular attached database.
 
 
 
 
 
 
2156 ** </ul>
2157 */
2158 #define SQLITE_FCNTL_LOCKSTATE 1
2159 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
2160 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -2188,10 +2194,11 @@
2188 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
2189 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
2190 #define SQLITE_FCNTL_LOCK_TIMEOUT 34
2191 #define SQLITE_FCNTL_DATA_VERSION 35
2192 #define SQLITE_FCNTL_SIZE_LIMIT 36
 
2193
2194 /* deprecated names */
2195 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2196 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2197 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3307,25 +3314,27 @@
3307 ** compile-time option.
3308 ** </dd>
3309 **
3310 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
3311 ** <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.
 
3314 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
3315 ** takes additional defensive steps to protect the application from harm
3316 ** including, but not limited to, the following:
3317 ** <ul>
3318 ** <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
3323 ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
3324 ** </ul>
3325 ** This setting defaults to "on" for legacy compatibility, however
3326 ** all applications are advised to turn it off if possible.
 
3327 ** </dd>
3328 **
3329 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
3330 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
3331 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
@@ -3834,11 +3843,11 @@
3834 /*
3835 ** CAPI3REF: Memory Allocation Subsystem
3836 **
3837 ** The SQLite core uses these three routines for all of its own
3838 ** internal memory allocation needs. "Core" in the previous sentence
3839 ** does not include operating-system specific VFS implementation. The
3840 ** Windows VFS uses native malloc() and free() for some operations.
3841 **
3842 ** ^The sqlite3_malloc() routine returns a pointer to a block
3843 ** of memory at least N bytes in length, where N is the parameter.
3844 ** ^If sqlite3_malloc() is unable to obtain sufficient free
@@ -4317,14 +4326,12 @@
4317 ** passing it to [sqlite3_close()] when it is no longer required.
4318 **
4319 ** The sqlite3_open_v2() interface works like sqlite3_open()
4320 ** except that it accepts two additional parameters for additional control
4321 ** 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:)^
4326 **
4327 ** <dl>
4328 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
4329 ** <dd>The database is opened in read-only mode. If the database does not
4330 ** already exist, an error is returned.</dd>)^
@@ -4337,28 +4344,56 @@
4337 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
4338 ** <dd>The database is opened for reading and writing, and is created if
4339 ** it does not already exist. This is the behavior that is always used for
4340 ** sqlite3_open() and sqlite3_open16().</dd>)^
4341 ** </dl>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4342 **
4343 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
4344 ** combinations shown above optionally combined with other
4345 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
4346 ** then the behavior is undefined.
4347 **
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 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
4361 ** [sqlite3_vfs] object that defines the operating system interface that
4362 ** the new database connection should use. ^If the fourth parameter is
4363 ** a NULL pointer then the default [sqlite3_vfs] object is used.
4364 **
@@ -4534,18 +4569,17 @@
4534 );
4535
4536 /*
4537 ** CAPI3REF: Obtain Values For URI Parameters
4538 **
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
4541 ** parameter, and if so obtains the value of that query parameter.
4542 **
4543 ** 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
4547 ** sqlite3_uri_parameter(F,P) returns the value of the P
4548 ** parameter if it exists or a NULL pointer if P does not appear as a
4549 ** query parameter on F. If P is a query parameter of F and it
4550 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
4551 ** a pointer to an empty string.
@@ -4563,22 +4597,69 @@
4563 **
4564 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4565 ** 64-bit signed integer and returns that integer, or D if P does not
4566 ** exist. If the value of P is something other than an integer, then
4567 ** zero is returned.
 
 
 
 
 
 
 
4568 **
4569 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
4570 ** 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.
 
 
 
 
 
 
 
 
4574 **
4575 ** See the [URI filename] documentation for additional information.
4576 */
4577 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
4578 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
4579 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4580
4581
4582 /*
4583 ** CAPI3REF: Error Codes And Messages
4584 ** METHOD: sqlite3
@@ -5877,12 +5958,10 @@
5877 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
5878
5879 /*
5880 ** CAPI3REF: Create Or Redefine SQL Functions
5881 ** KEYWORDS: {function creation routines}
5882 ** KEYWORDS: {application-defined SQL function}
5883 ** KEYWORDS: {application-defined SQL functions}
5884 ** METHOD: sqlite3
5885 **
5886 ** ^These functions (collectively known as "function creation routines")
5887 ** are used to add SQL functions or aggregates or to redefine the behavior
5888 ** of existing SQL functions or aggregates. The only differences between
@@ -5934,13 +6013,24 @@
5934 ** perform additional optimizations on deterministic functions, so use
5935 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
5936 **
5937 ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
5938 ** 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.
 
 
 
 
 
 
 
 
 
 
 
5942 **
5943 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
5944 ** function can gain access to this pointer using [sqlite3_user_data()].)^
5945 **
5946 ** ^The sixth, seventh and eighth parameters passed to the three
@@ -6055,46 +6145,66 @@
6055 ** These constants may be ORed together with the
6056 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
6057 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
6058 ** [sqlite3_create_function_v2()].
6059 **
 
 
6060 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
6061 ** the same output when the input parameters are the same.
6062 ** The [abs|abs() function] is deterministic, for example, but
6063 ** [randomblob|randomblob()] is not. Functions must
6064 ** 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.
 
 
 
 
 
 
 
 
 
 
 
 
 
6067 **
6068 ** The SQLITE_INNOCUOUS flag means that the new function is unlikely
 
6069 ** 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.
 
6072 ** 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
 
 
 
 
 
 
6076 ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
6077 ** are innocuous. Developers are advised to avoid using the
6078 ** 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 **
6089 ** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
6090 ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
6091 ** Specifying this flag makes no difference for scalar or aggregate user
6092 ** functions. However, if it is not specified for a user-defined window
6093 ** function, then any sub-types belonging to arguments passed to the window
6094 ** function may be discarded before the window function is called (i.e.
6095 ** sqlite3_value_subtype() will always return 0).
 
 
6096 */
6097 #define SQLITE_DETERMINISTIC 0x000000800
6098 #define SQLITE_DIRECTONLY 0x000080000
6099 #define SQLITE_SUBTYPE 0x000100000
6100 #define SQLITE_INNOCUOUS 0x000200000
@@ -7006,10 +7116,21 @@
7006 **
7007 ** ^The filename returned by this function is the output of the
7008 ** xFullPathname method of the [VFS]. ^In other words, the filename
7009 ** will be an absolute pathname, even if the filename used
7010 ** to open the database originally was a URI or relative pathname.
 
 
 
 
 
 
 
 
 
 
 
7011 */
7012 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
7013
7014 /*
7015 ** CAPI3REF: Determine if a database is read-only
@@ -9974,10 +10095,18 @@
9974 ** silently replace the appropriate rows within the xUpdate callback and
9975 ** return SQLITE_OK. Or, if this is not possible, it may return
9976 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
9977 ** constraint handling.
9978 ** </dd>
 
 
 
 
 
 
 
 
9979 **
9980 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
9981 ** <dd>Calls of the form
9982 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
9983 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
@@ -9985,18 +10114,10 @@
9985 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
9986 ** virtual table can do no serious harm even if it is controlled by a
9987 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
9988 ** flag unless absolutely necessary.
9989 ** </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 ** </dl>
9999 */
10000 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
10001 #define SQLITE_VTAB_INNOCUOUS 2
10002 #define SQLITE_VTAB_DIRECTONLY 3
@@ -15718,11 +15839,11 @@
15718 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
15719 #ifdef SQLITE_DEBUG
15720 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
15721 #endif
15722 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
15723 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager*, int);
15724 SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
15725 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
15726 SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
15727 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
15728 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
@@ -19254,13 +19375,10 @@
19254 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
19255 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
19256 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
19257 SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*);
19258 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
19259 #ifdef SQLITE_DEBUG
19260 SQLITE_PRIVATE int sqlite3UriCount(const char*);
19261 #endif
19262 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
19263 sqlite3_vfs**,char**,char **);
19264 #ifdef SQLITE_HAS_CODEC
19265 SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*);
19266 #else
@@ -22090,11 +22208,11 @@
22090 */
22091 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
22092 r = p->s*1000.0 + 210866760000000.0;
22093 if( r>=0.0 && r<464269060800000.0 ){
22094 clearYMD_HMS_TZ(p);
22095 p->iJD = (sqlite3_int64)r;
22096 p->validJD = 1;
22097 p->rawS = 0;
22098 rc = 0;
22099 }
22100 }
@@ -30871,11 +30989,13 @@
30871 ** strings, and stuff like that.
30872 **
30873 */
30874 /* #include "sqliteInt.h" */
30875 /* #include <stdarg.h> */
 
30876 #include <math.h>
 
30877
30878 /*
30879 ** Routine needed to support the testcase() macro.
30880 */
30881 #ifdef SQLITE_COVERAGE_TEST
@@ -56105,57 +56225,92 @@
56105 ** Pager object (sizeof(Pager) bytes)
56106 ** PCache object (sqlite3PcacheSize() bytes)
56107 ** Database file handle (pVfs->szOsFile bytes)
56108 ** Sub-journal file handle (journalFileSize bytes)
56109 ** Main journal file handle (journalFileSize bytes)
 
 
 
 
 
56110 ** Database file name (nPathname+1 bytes)
56111 ** Journal file name (nPathname+8+1 bytes)
 
56112 */
56113 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 */
56120 #ifndef SQLITE_OMIT_WAL
56121 + nPathname + 4 + 2 /* zWal */
 
56122 #endif
 
 
 
 
56123 );
56124 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
56125 if( !pPtr ){
56126 sqlite3DbFree(0, zPathname);
56127 return SQLITE_NOMEM_BKPT;
56128 }
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);
56135 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
56136
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);
 
 
 
 
 
 
 
56146 #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 );
 
 
 
 
56152 #endif
56153 assert( sqlite3UriCount(pPager->zFilename)==nUri );
56154 assert( sqlite3UriCount(pPager->zJournal)==0 );
56155 sqlite3DbFree(0, zPathname);
56156 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56157 pPager->pVfs = pVfs;
56158 pPager->vfsFlags = vfsFlags;
56159
56160 /* Open the pager file.
56161 */
@@ -56200,13 +56355,13 @@
56200 }
56201 }
56202 }
56203 #endif
56204 }
56205 pPager->noLock = sqlite3_uri_boolean(zFilename, "nolock", 0);
56206 if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
56207 || sqlite3_uri_boolean(zFilename, "immutable", 0) ){
56208 vfsFlags |= SQLITE_OPEN_READONLY;
56209 goto act_like_temp_file;
56210 }
56211 }
56212 }else{
@@ -58265,13 +58420,17 @@
58265 ** nullIfMemDb is true. This routine is called with nullIfMemDb==1 when
58266 ** used to report the filename to the user, for compatibility with legacy
58267 ** behavior. But when the Btree needs to know the filename for matching to
58268 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
58269 ** participate in shared-cache.
 
 
 
58270 */
58271 SQLITE_PRIVATE const char *sqlite3PagerFilename(Pager *pPager, int nullIfMemDb){
58272 return (nullIfMemDb && pPager->memDb) ? "" : pPager->zFilename;
 
58273 }
58274
58275 /*
58276 ** Return the VFS structure for the pager.
58277 */
@@ -58921,10 +59080,12 @@
58921 if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
58922 }
58923 }
58924 return rc;
58925 }
 
 
58926
58927 #ifdef SQLITE_ENABLE_SNAPSHOT
58928 /*
58929 ** If this is a WAL database, obtain a snapshot handle for the snapshot
58930 ** currently open. Otherwise, return an error.
@@ -60931,10 +61092,14 @@
60931 rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
60932 if( rc==SQLITE_OK ){
60933 rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
60934 }
60935 }
 
 
 
 
60936 if( rc==SQLITE_OK ){
60937 pInfo->nBackfill = mxSafeFrame;
60938 }
60939 }
60940
@@ -65639,11 +65804,11 @@
65639 if( data[iPtr+1]==0 && data[iPtr]==0 ){
65640 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
65641 }else{
65642 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
65643 if( iFreeBlk<iPtr+4 ){
65644 if( ALWAYS(iFreeBlk==0) ) break;
65645 return SQLITE_CORRUPT_PAGE(pPage);
65646 }
65647 iPtr = iFreeBlk;
65648 }
65649 if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
@@ -76798,11 +76963,15 @@
76798 ){
76799 sqlite3VdbeMemNumerify(pVal);
76800 if( pVal->flags & MEM_Real ){
76801 pVal->u.r = -pVal->u.r;
76802 }else if( pVal->u.i==SMALLEST_INT64 ){
 
76803 pVal->u.r = -(double)SMALLEST_INT64;
 
 
 
76804 MemSetTypeFlag(pVal, MEM_Real);
76805 }else{
76806 pVal->u.i = -pVal->u.i;
76807 }
76808 sqlite3ValueApplyAffinity(pVal, affinity, enc);
@@ -78351,18 +78520,20 @@
78351 ){
78352 if( N==0 ) return;
78353 assert( pParse->pVdbe );
78354 assert( iFirst>=1 );
78355 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--;
 
 
78364 }
78365 if( N>0 ){
78366 sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask);
78367 if( bUndefine ) sqlite3VdbeChangeP5(pParse->pVdbe, 1);
78368 }
@@ -85085,11 +85256,11 @@
85085 if( f & MEM_Zero ){
85086 sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero);
85087 }
85088 }else if( f & MEM_Str ){
85089 int j;
85090 int c;
85091 if( f & MEM_Dyn ){
85092 c = 'z';
85093 assert( (f & (MEM_Static|MEM_Ephem))==0 );
85094 }else if( f & MEM_Static ){
85095 c = 't';
@@ -85100,11 +85271,11 @@
85100 }else{
85101 c = 's';
85102 }
85103 sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n);
85104 for(j=0; j<25 && j<pMem->n; j++){
85105 u8 c = pMem->z[j];
85106 sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
85107 }
85108 sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]);
85109 }
85110 }
@@ -88577,19 +88748,17 @@
88577 SQLITE_OPEN_DELETEONCLOSE |
88578 SQLITE_OPEN_TRANSIENT_DB;
88579 assert( pOp->p1>=0 );
88580 assert( pOp->p2>=0 );
88581 pCx = p->apCsr[pOp->p1];
88582 if( pCx ){
88583 /* If the ephermeral table is already open, erase all existing content
88584 ** so that the table is empty again, rather than creating a new table. */
88585 assert( pCx->isEphemeral );
88586 pCx->seqCount = 0;
88587 pCx->cacheStatus = CACHE_STALE;
88588 if( pCx->pBtx ){
88589 rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
88590 }
88591 }else{
88592 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
88593 if( pCx==0 ) goto no_mem;
88594 pCx->isEphemeral = 1;
88595 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
@@ -97441,15 +97610,18 @@
97441 ** constant because they are constant for the duration of one query.
97442 ** This allows them to be factored out of inner loops. */
97443 ExprSetProperty(pExpr,EP_ConstFunc);
97444 }
97445 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
97446 /* Date/time functions that use 'now', and other functions like
 
97447 ** sqlite_version() that might change over time cannot be used
97448 ** in an index. */
 
 
97449 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
97450 NC_SelfRef, 0);
97451 }else{
97452 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
97453 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
97454 if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
97455 }
@@ -111196,12 +111368,12 @@
111196 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
111197 /* If there are errors in resolving the expression, change the
111198 ** expression to a NULL. This prevents code generators that operate
111199 ** on the expression from inserting extra parts into the expression
111200 ** 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. */
111203 sqlite3ExprDelete(db, pX);
111204 p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
111205 }
111206 }else{
111207 nNG++;
@@ -115463,11 +115635,13 @@
115463 ** time functions, are implemented separately.)
115464 */
115465 /* #include "sqliteInt.h" */
115466 /* #include <stdlib.h> */
115467 /* #include <assert.h> */
 
115468 /* #include <math.h> */
 
115469 /* #include "vdbeInt.h" */
115470
115471 /*
115472 ** Return the collating function associated with a function.
115473 */
@@ -120572,17 +120746,19 @@
120572 ** pass is sufficient */
120573 break;
120574 }
120575 if( b2ndPass ) break; /* Never need more than 2 passes */
120576 b2ndPass = 1;
 
120577 if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
120578 /* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
120579 ** first pass, recomputed values for all generated columns, as
120580 ** those values might depend on columns affected by the REPLACE.
120581 */
120582 sqlite3ComputeGeneratedColumns(pParse, regNewData+1, pTab);
120583 }
 
120584 } /* end of 2-pass loop */
120585 } /* end if( has-not-null-constraints ) */
120586
120587 /* Test all CHECK constraints
120588 */
@@ -122287,11 +122463,16 @@
122287 /* Version 3.28.0 and later */
122288 int (*stmt_isexplain)(sqlite3_stmt*);
122289 int (*value_frombind)(sqlite3_value*);
122290 /* Version 3.30.0 and later */
122291 int (*drop_modules)(sqlite3*,const char**);
 
122292 sqlite3_int64 (*hard_heap_limit64)(sqlite3_int64);
 
 
 
 
122293 };
122294
122295 /*
122296 ** This is the function signature used for all extension entry points. It
122297 ** is also defined in the file "loadext.c".
@@ -122582,11 +122763,16 @@
122582 /* Version 3.28.0 and later */
122583 #define sqlite3_stmt_isexplain sqlite3_api->isexplain
122584 #define sqlite3_value_frombind sqlite3_api->frombind
122585 /* Version 3.30.0 and later */
122586 #define sqlite3_drop_modules sqlite3_api->drop_modules
 
122587 #define sqlite3_hard_heap_limit64 sqlite3_api->hard_heap_limit64
 
 
 
 
122588 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
122589
122590 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
122591 /* This case when the file really is being compiled as a loadable
122592 ** extension */
@@ -123057,10 +123243,14 @@
123057 #else
123058 0,
123059 #endif
123060 /* Version 3.31.0 and later */
123061 sqlite3_hard_heap_limit64,
 
 
 
 
123062 };
123063
123064 /*
123065 ** Attempt to load an SQLite extension library contained in the file
123066 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -125937,14 +126127,21 @@
125937 /* Only change the value of sqlite.enc if the database handle is not
125938 ** initialized. If the main database exists, the new sqlite.enc value
125939 ** will be overwritten when the schema is next loaded. If it does not
125940 ** already exists, it will be created to use the new encoding value.
125941 */
125942 if(
125943 !(DbHasProperty(db, 0, DB_SchemaLoaded)) ||
125944 DbHasProperty(db, 0, DB_Empty)
125945 ){
 
 
 
 
 
 
 
125946 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
125947 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
125948 SCHEMA_ENC(db) = ENC(db) =
125949 pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
125950 break;
@@ -130138,11 +130335,13 @@
130138 assert( p->selFlags & SF_MultiValue );
130139 do{
130140 assert( p->selFlags & SF_Values );
130141 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
130142 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
 
130143 if( p->pWin ) return -1;
 
130144 if( p->pPrior==0 ) break;
130145 assert( p->pPrior->pNext==p );
130146 p = p->pPrior;
130147 nRow += bShowAll;
130148 }while(1);
@@ -131501,11 +131700,13 @@
131501 assert( pSub->pSrc!=0 );
131502 assert( pSub->pEList->nExpr==pSub1->pEList->nExpr );
131503 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
131504 || (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */
131505 || pSub1->pSrc->nSrc<1 /* (17c) */
 
131506 || pSub1->pWin /* (17e) */
 
131507 ){
131508 return 0;
131509 }
131510 testcase( pSub1->pSrc->nSrc>1 );
131511 }
@@ -131875,11 +132076,15 @@
131875 */
131876 static int propagateConstantExprRewrite(Walker *pWalker, Expr *pExpr){
131877 int i;
131878 WhereConst *pConst;
131879 if( pExpr->op!=TK_COLUMN ) return WRC_Continue;
131880 if( ExprHasProperty(pExpr, EP_FixedCol) ) return WRC_Continue;
 
 
 
 
131881 pConst = pWalker->u.pConst;
131882 for(i=0; i<pConst->nConst; i++){
131883 Expr *pColumn = pConst->apExpr[i*2];
131884 if( pColumn==pExpr ) continue;
131885 if( pColumn->iTable!=pExpr->iTable ) continue;
@@ -132604,11 +132809,11 @@
132604 }
132605 pTab->nTabRef++;
132606 if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
132607 return WRC_Abort;
132608 }
132609 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
132610 if( IsVirtual(pTab) || pTab->pSelect ){
132611 i16 nCol;
132612 u8 eCodeOrig = pWalker->eCode;
132613 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
132614 assert( pFrom->pSelect==0 );
@@ -133756,11 +133961,13 @@
133756 ** written the query must use a temp-table for at least one of the ORDER
133757 ** BY and DISTINCT, and an index or separate temp-table for the other.
133758 */
133759 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
133760 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
 
133761 && p->pWin==0
 
133762 ){
133763 p->selFlags &= ~SF_Distinct;
133764 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
133765 p->selFlags |= SF_Aggregate;
133766 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
@@ -139191,26 +139398,26 @@
139191 };
139192
139193 /*
139194 ** Allowed values of WhereTerm.wtFlags
139195 */
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 */
139203 #ifdef SQLITE_ENABLE_STAT4
139204 # define TERM_VNULL 0x80 /* Manufactured x>NULL or x<=NULL term */
139205 #else
139206 # define TERM_VNULL 0x00 /* Disabled if not using stat4 */
139207 #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 */
139212 #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */
139213
139214 /*
139215 ** An instance of the WhereScan object is used as an iterator for locating
139216 ** terms in the WHERE clause that are useful to the query planner.
@@ -141660,13 +141867,13 @@
141660 WhereTerm *pOrTerm = &pOrWc->a[ii];
141661 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
141662 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
141663 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
141664 int jmp1 = 0; /* Address of jump operation */
141665 assert( (pTabItem[0].fg.jointype & JT_LEFT)==0
141666 || ExprHasProperty(pOrExpr, EP_FromJoin)
141667 );
141668 if( pAndExpr ){
141669 pAndExpr->pLeft = pOrExpr;
141670 pOrExpr = pAndExpr;
141671 }
141672 /* Loop through table entries that match term pOrTerm. */
@@ -148498,18 +148705,18 @@
148498 ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3);
148499 **
148500 ** then table t2 can be omitted from the following:
148501 **
148502 ** SELECT v1, v3 FROM t1
148503 ** LEFT JOIN t2 USING (t1.ipk=t2.ipk)
148504 ** LEFT JOIN t3 USING (t1.ipk=t3.ipk)
148505 **
148506 ** or from:
148507 **
148508 ** SELECT DISTINCT v1, v3 FROM t1
148509 ** LEFT JOIN t2
148510 ** LEFT JOIN t3 USING (t1.ipk=t3.ipk)
148511 */
148512 notReady = ~(Bitmask)0;
148513 if( pWInfo->nLevel>=2
148514 && pResultSet!=0 /* guarantees condition (1) above */
148515 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
@@ -162726,10 +162933,11 @@
162726 ** xRandomness method on the primary VFS.
162727 **
162728 ** This test-control also resets the PRNG so that the new seed will
162729 ** be used for the next call to sqlite3_randomness().
162730 */
 
162731 case SQLITE_TESTCTRL_PRNG_SEED: {
162732 int x = va_arg(ap, int);
162733 int y;
162734 sqlite3 *db = va_arg(ap, sqlite3*);
162735 assert( db==0 || db->aDb[0].pSchema!=0 );
@@ -162736,10 +162944,11 @@
162736 if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; }
162737 sqlite3Config.iPrngSeed = x;
162738 sqlite3_randomness(0,0);
162739 break;
162740 }
 
162741
162742 /*
162743 ** sqlite3_test_control(BITVEC_TEST, size, program)
162744 **
162745 ** Run a test against a Bitvec object of size. The program argument
@@ -163063,29 +163272,10 @@
163063 va_end(ap);
163064 #endif /* SQLITE_UNTESTABLE */
163065 return rc;
163066 }
163067
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 /*
163088 ** This is a utility routine, useful to VFS implementations, that checks
163089 ** to see if a database file was a URI that contained a specific query
163090 ** parameter, and if so obtains the value of the query parameter.
163091 **
@@ -163104,10 +163294,23 @@
163104 if( x==0 ) return zFilename;
163105 zFilename += sqlite3Strlen30(zFilename) + 1;
163106 }
163107 return 0;
163108 }
 
 
 
 
 
 
 
 
 
 
 
 
 
163109
163110 /*
163111 ** Return a boolean value for a query parameter.
163112 */
163113 SQLITE_API int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){
@@ -163129,10 +163332,50 @@
163129 if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
163130 bDflt = v;
163131 }
163132 return bDflt;
163133 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163134
163135 /*
163136 ** Return the Btree pointer identified by zDbName. Return NULL if not found.
163137 */
163138 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
@@ -198461,37 +198704,10 @@
198461 rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag);
198462 }
198463 return rc;
198464 }
198465
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 /*
198494 ** Open an rbu file handle.
198495 */
198496 static int rbuVfsOpen(
198497 sqlite3_vfs *pVfs,
@@ -198536,11 +198752,11 @@
198536 /* A main database has just been opened. The following block sets
198537 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
198538 ** the name of the *-wal file this db connection will use. SQLite
198539 ** happens to pass a pointer to this buffer when using xAccess()
198540 ** or xOpen() to operate on the *-wal file. */
198541 pFd->zWal = rbuMainToWal(zName, flags);
198542 }
198543 else if( flags & SQLITE_OPEN_WAL ){
198544 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
198545 if( pDb ){
198546 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
@@ -198551,11 +198767,11 @@
198551 const char *zBase = zName;
198552 size_t nCopy;
198553 char *zCopy;
198554 if( rbuIsVacuum(pDb->pRbu) ){
198555 zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
198556 zBase = rbuMainToWal(zBase, SQLITE_OPEN_URI);
198557 }
198558 nCopy = strlen(zBase);
198559 zCopy = sqlite3_malloc64(nCopy+2);
198560 if( zCopy ){
198561 memcpy(zCopy, zBase, nCopy);
@@ -223413,11 +223629,11 @@
223413 int nArg, /* Number of args */
223414 sqlite3_value **apUnused /* Function arguments */
223415 ){
223416 assert( nArg==0 );
223417 UNUSED_PARAM2(nArg, apUnused);
223418 sqlite3_result_text(pCtx, "fts5: 2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68", -1, SQLITE_TRANSIENT);
223419 }
223420
223421 /*
223422 ** Return true if zName is the extension on one of the shadow tables used
223423 ** by this module.
@@ -228186,12 +228402,12 @@
228186 }
228187 #endif /* SQLITE_CORE */
228188 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
228189
228190 /************** End of stmt.c ************************************************/
228191 #if __LINE__!=228191
228192 #undef SQLITE_SOURCE_ID
228193 #define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0falt2"
228194 #endif
228195 /* Return the source-id for this library */
228196 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
228197 /************************** End of sqlite3.c ******************************/
228198
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1165,11 +1165,11 @@
1165 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1166 ** [sqlite_version()] and [sqlite_source_id()].
1167 */
1168 #define SQLITE_VERSION "3.31.0"
1169 #define SQLITE_VERSION_NUMBER 3031000
1170 #define SQLITE_SOURCE_ID "2020-01-20 14:42:09 63d886f4ce3c770498b8bdad45b04143a3f63197d81793bde107450aba4a9c87"
1171
1172 /*
1173 ** CAPI3REF: Run-Time Library Version Numbers
1174 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1175 **
@@ -2151,10 +2151,16 @@
2151 ** a single attached database that occur due to other database connections,
2152 ** but omits changes implemented by the database connection on which it is
2153 ** called. This file control is the only mechanism to detect changes that
2154 ** happen either internally or externally and that are associated with
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.
2162 ** </ul>
2163 */
2164 #define SQLITE_FCNTL_LOCKSTATE 1
2165 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
2166 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -2188,10 +2194,11 @@
2194 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
2195 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
2196 #define SQLITE_FCNTL_LOCK_TIMEOUT 34
2197 #define SQLITE_FCNTL_DATA_VERSION 35
2198 #define SQLITE_FCNTL_SIZE_LIMIT 36
2199 #define SQLITE_FCNTL_CKPT_DONE 37
2200
2201 /* deprecated names */
2202 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2203 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2204 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -3307,25 +3314,27 @@
3314 ** compile-time option.
3315 ** </dd>
3316 **
3317 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
3318 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
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.
3322 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
3323 ** takes additional defensive steps to protect the application from harm
3324 ** including:
3325 ** <ul>
3326 ** <li> Prohibit the use of SQL functions inside triggers, 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
3331 ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
3332 ** </ul>
3333 ** This setting defaults to "on" for legacy compatibility, however
3334 ** all applications are advised to turn it off if possible. This setting
3335 ** can also be controlled using the [PRAGMA trusted_schema] statement.
3336 ** </dd>
3337 **
3338 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
3339 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
3340 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
@@ -3834,11 +3843,11 @@
3843 /*
3844 ** CAPI3REF: Memory Allocation Subsystem
3845 **
3846 ** The SQLite core uses these three routines for all of its own
3847 ** internal memory allocation needs. "Core" in the previous sentence
3848 ** does not include operating-system specific [VFS] implementation. The
3849 ** Windows VFS uses native malloc() and free() for some operations.
3850 **
3851 ** ^The sqlite3_malloc() routine returns a pointer to a block
3852 ** of memory at least N bytes in length, where N is the parameter.
3853 ** ^If sqlite3_malloc() is unable to obtain sufficient free
@@ -4317,14 +4326,12 @@
4326 ** passing it to [sqlite3_close()] when it is no longer required.
4327 **
4328 ** The sqlite3_open_v2() interface works like sqlite3_open()
4329 ** except that it accepts two additional parameters for additional control
4330 ** over the new database connection. ^(The flags parameter to
4331 ** sqlite3_open_v2() must include, at a minimum, one of the following
4332 ** three flag combinations:)^
 
 
4333 **
4334 ** <dl>
4335 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
4336 ** <dd>The database is opened in read-only mode. If the database does not
4337 ** already exist, an error is returned.</dd>)^
@@ -4337,28 +4344,56 @@
4344 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
4345 ** <dd>The database is opened for reading and writing, and is created if
4346 ** it does not already exist. This is the behavior that is always used for
4347 ** sqlite3_open() and sqlite3_open16().</dd>)^
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>)^
4389 **
4390 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
4391 ** required combinations shown above optionally combined with other
4392 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
4393 ** then the behavior is undefined.
4394 **
 
 
 
 
 
 
 
 
 
 
 
 
4395 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
4396 ** [sqlite3_vfs] object that defines the operating system interface that
4397 ** the new database connection should use. ^If the fourth parameter is
4398 ** a NULL pointer then the default [sqlite3_vfs] object is used.
4399 **
@@ -4534,18 +4569,17 @@
4569 );
4570
4571 /*
4572 ** CAPI3REF: Obtain Values For URI Parameters
4573 **
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
4576 ** parameter, and if so obtains the value of that query parameter.
4577 **
4578 ** If F is the database filename pointer passed into the xOpen() method of
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
 
4581 ** sqlite3_uri_parameter(F,P) returns the value of the P
4582 ** parameter if it exists or a NULL pointer if P does not appear as a
4583 ** query parameter on F. If P is a query parameter of F and it
4584 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
4585 ** a pointer to an empty string.
@@ -4563,22 +4597,69 @@
4597 **
4598 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
4599 ** 64-bit signed integer and returns that integer, or D if P does not
4600 ** exist. If the value of P is something other than an integer, then
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.
4609 **
4610 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
4611 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
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.
4623 **
4624 ** See the [URI filename] documentation for additional information.
4625 */
4626 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
4627 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
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*);
4661
4662
4663 /*
4664 ** CAPI3REF: Error Codes And Messages
4665 ** METHOD: sqlite3
@@ -5877,12 +5958,10 @@
5958 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
5959
5960 /*
5961 ** CAPI3REF: Create Or Redefine SQL Functions
5962 ** KEYWORDS: {function creation routines}
 
 
5963 ** METHOD: sqlite3
5964 **
5965 ** ^These functions (collectively known as "function creation routines")
5966 ** are used to add SQL functions or aggregates or to redefine the behavior
5967 ** of existing SQL functions or aggregates. The only differences between
@@ -5934,13 +6013,24 @@
6013 ** perform additional optimizations on deterministic functions, so use
6014 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
6015 **
6016 ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
6017 ** flag, which if present prevents the function from being invoked from
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>
6032 **
6033 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
6034 ** function can gain access to this pointer using [sqlite3_user_data()].)^
6035 **
6036 ** ^The sixth, seventh and eighth parameters passed to the three
@@ -6055,46 +6145,66 @@
6145 ** These constants may be ORed together with the
6146 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
6147 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
6148 ** [sqlite3_create_function_v2()].
6149 **
6150 ** <dl>
6151 ** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
6152 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
6153 ** the same output when the input parameters are the same.
6154 ** The [abs|abs() function] is deterministic, for example, but
6155 ** [randomblob|randomblob()] is not. Functions must
6156 ** be deterministic in order to be used in certain contexts such as
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>
6172 **
6173 ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
6174 ** The SQLITE_INNOCUOUS flag means that the function is unlikely
6175 ** to cause problems even if misused. An innocuous function should have
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.
6179 ** The [load_extension() SQL function] is not innocuous because of its
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
6189 ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
6190 ** are innocuous. Developers are advised to avoid using the
6191 ** SQLITE_INNOCUOUS flag for application-defined functions unless the
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>
 
 
 
 
 
6197 ** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
6198 ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
6199 ** Specifying this flag makes no difference for scalar or aggregate user
6200 ** functions. However, if it is not specified for a user-defined window
6201 ** function, then any sub-types belonging to arguments passed to the window
6202 ** function may be discarded before the window function is called (i.e.
6203 ** sqlite3_value_subtype() will always return 0).
6204 ** </dd>
6205 ** </dl>
6206 */
6207 #define SQLITE_DETERMINISTIC 0x000000800
6208 #define SQLITE_DIRECTONLY 0x000080000
6209 #define SQLITE_SUBTYPE 0x000100000
6210 #define SQLITE_INNOCUOUS 0x000200000
@@ -7006,10 +7116,21 @@
7116 **
7117 ** ^The filename returned by this function is the output of the
7118 ** xFullPathname method of the [VFS]. ^In other words, the filename
7119 ** will be an absolute pathname, even if the filename used
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>
7132 */
7133 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
7134
7135 /*
7136 ** CAPI3REF: Determine if a database is read-only
@@ -9974,10 +10095,18 @@
10095 ** silently replace the appropriate rows within the xUpdate callback and
10096 ** return SQLITE_OK. Or, if this is not possible, it may return
10097 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
10098 ** constraint handling.
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>
10108 **
10109 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
10110 ** <dd>Calls of the form
10111 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
10112 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
@@ -9985,18 +10114,10 @@
10114 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
10115 ** virtual table can do no serious harm even if it is controlled by a
10116 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
10117 ** flag unless absolutely necessary.
10118 ** </dd>
 
 
 
 
 
 
 
 
10119 ** </dl>
10120 */
10121 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
10122 #define SQLITE_VTAB_INNOCUOUS 2
10123 #define SQLITE_VTAB_DIRECTONLY 3
@@ -15718,11 +15839,11 @@
15839 SQLITE_PRIVATE u32 sqlite3PagerDataVersion(Pager*);
15840 #ifdef SQLITE_DEBUG
15841 SQLITE_PRIVATE int sqlite3PagerRefcount(Pager*);
15842 #endif
15843 SQLITE_PRIVATE int sqlite3PagerMemUsed(Pager*);
15844 SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager*, int);
15845 SQLITE_PRIVATE sqlite3_vfs *sqlite3PagerVfs(Pager*);
15846 SQLITE_PRIVATE sqlite3_file *sqlite3PagerFile(Pager*);
15847 SQLITE_PRIVATE sqlite3_file *sqlite3PagerJrnlFile(Pager*);
15848 SQLITE_PRIVATE const char *sqlite3PagerJournalname(Pager*);
15849 SQLITE_PRIVATE void *sqlite3PagerTempSpace(Pager*);
@@ -19254,13 +19375,10 @@
19375 SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
19376 SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
19377 SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
19378 SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*);
19379 SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
 
 
 
19380 SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
19381 sqlite3_vfs**,char**,char **);
19382 #ifdef SQLITE_HAS_CODEC
19383 SQLITE_PRIVATE int sqlite3CodecQueryParameters(sqlite3*,const char*,const char*);
19384 #else
@@ -22090,11 +22208,11 @@
22208 */
22209 if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){
22210 r = p->s*1000.0 + 210866760000000.0;
22211 if( r>=0.0 && r<464269060800000.0 ){
22212 clearYMD_HMS_TZ(p);
22213 p->iJD = (sqlite3_int64)(r + 0.5);
22214 p->validJD = 1;
22215 p->rawS = 0;
22216 rc = 0;
22217 }
22218 }
@@ -30871,11 +30989,13 @@
30989 ** strings, and stuff like that.
30990 **
30991 */
30992 /* #include "sqliteInt.h" */
30993 /* #include <stdarg.h> */
30994 #ifndef SQLITE_OMIT_FLOATING_POINT
30995 #include <math.h>
30996 #endif
30997
30998 /*
30999 ** Routine needed to support the testcase() macro.
31000 */
31001 #ifdef SQLITE_COVERAGE_TEST
@@ -56105,57 +56225,92 @@
56225 ** Pager object (sizeof(Pager) bytes)
56226 ** PCache object (sqlite3PcacheSize() bytes)
56227 ** Database file handle (pVfs->szOsFile bytes)
56228 ** Sub-journal file handle (journalFileSize bytes)
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)
56235 ** Database file name (nPathname+1 bytes)
56236 ** URI query parameters (nUriByte bytes)
56237 ** \0\0 terminator (2 bytes)
56238 */
56239 pPtr = (u8 *)sqlite3MallocZero(
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 */
56246 #ifndef SQLITE_OMIT_WAL
56247 2 + /* WAL prefix */
56248 nPathname + 4 + 1 + /* WAL filename */
56249 #endif
56250 2 + /* Database prefix */
56251 nPathname + 1 + /* database filename */
56252 nUriByte + /* query parameters */
56253 2 /* Terminator */
56254 );
56255 assert( EIGHT_BYTE_ALIGNMENT(SQLITE_INT_TO_PTR(journalFileSize)) );
56256 if( !pPtr ){
56257 sqlite3DbFree(0, zPathname);
56258 return SQLITE_NOMEM_BKPT;
56259 }
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;
 
56265 assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) );
56266
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
56283 #ifndef SQLITE_OMIT_WAL
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);
56293 #endif
56294 }else{
56295 pPager->zWal = 0;
56296 pPtr++;
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);
56312 pPager->pVfs = pVfs;
56313 pPager->vfsFlags = vfsFlags;
56314
56315 /* Open the pager file.
56316 */
@@ -56200,13 +56355,13 @@
56355 }
56356 }
56357 }
56358 #endif
56359 }
56360 pPager->noLock = sqlite3_uri_boolean(pPager->zFilename, "nolock", 0);
56361 if( (iDc & SQLITE_IOCAP_IMMUTABLE)!=0
56362 || sqlite3_uri_boolean(pPager->zFilename, "immutable", 0) ){
56363 vfsFlags |= SQLITE_OPEN_READONLY;
56364 goto act_like_temp_file;
56365 }
56366 }
56367 }else{
@@ -58265,13 +58420,17 @@
58420 ** nullIfMemDb is true. This routine is called with nullIfMemDb==1 when
58421 ** used to report the filename to the user, for compatibility with legacy
58422 ** behavior. But when the Btree needs to know the filename for matching to
58423 ** shared cache, it uses nullIfMemDb==0 so that in-memory databases can
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.
58428 */
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;
58432 }
58433
58434 /*
58435 ** Return the VFS structure for the pager.
58436 */
@@ -58921,10 +59080,12 @@
59080 if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
59081 }
59082 }
59083 return rc;
59084 }
59085
59086
59087
59088 #ifdef SQLITE_ENABLE_SNAPSHOT
59089 /*
59090 ** If this is a WAL database, obtain a snapshot handle for the snapshot
59091 ** currently open. Otherwise, return an error.
@@ -60931,10 +61092,14 @@
61092 rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
61093 if( rc==SQLITE_OK ){
61094 rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
61095 }
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 }
61101 if( rc==SQLITE_OK ){
61102 pInfo->nBackfill = mxSafeFrame;
61103 }
61104 }
61105
@@ -65639,11 +65804,11 @@
65804 if( data[iPtr+1]==0 && data[iPtr]==0 ){
65805 iFreeBlk = 0; /* Shortcut for the case when the freelist is empty */
65806 }else{
65807 while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
65808 if( iFreeBlk<iPtr+4 ){
65809 if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
65810 return SQLITE_CORRUPT_PAGE(pPage);
65811 }
65812 iPtr = iFreeBlk;
65813 }
65814 if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
@@ -76798,11 +76963,15 @@
76963 ){
76964 sqlite3VdbeMemNumerify(pVal);
76965 if( pVal->flags & MEM_Real ){
76966 pVal->u.r = -pVal->u.r;
76967 }else if( pVal->u.i==SMALLEST_INT64 ){
76968 #ifndef SQLITE_OMIT_FLOATING_POINT
76969 pVal->u.r = -(double)SMALLEST_INT64;
76970 #else
76971 pVal->u.r = LARGEST_INT64;
76972 #endif
76973 MemSetTypeFlag(pVal, MEM_Real);
76974 }else{
76975 pVal->u.i = -pVal->u.i;
76976 }
76977 sqlite3ValueApplyAffinity(pVal, affinity, enc);
@@ -78351,18 +78520,20 @@
78520 ){
78521 if( N==0 ) return;
78522 assert( pParse->pVdbe );
78523 assert( iFirst>=1 );
78524 assert( iFirst+N-1<=pParse->nMem );
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 }
78535 }
78536 if( N>0 ){
78537 sqlite3VdbeAddOp3(pParse->pVdbe, OP_ReleaseReg, iFirst, N, *(int*)&mask);
78538 if( bUndefine ) sqlite3VdbeChangeP5(pParse->pVdbe, 1);
78539 }
@@ -85085,11 +85256,11 @@
85256 if( f & MEM_Zero ){
85257 sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero);
85258 }
85259 }else if( f & MEM_Str ){
85260 int j;
85261 u8 c;
85262 if( f & MEM_Dyn ){
85263 c = 'z';
85264 assert( (f & (MEM_Static|MEM_Ephem))==0 );
85265 }else if( f & MEM_Static ){
85266 c = 't';
@@ -85100,11 +85271,11 @@
85271 }else{
85272 c = 's';
85273 }
85274 sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n);
85275 for(j=0; j<25 && j<pMem->n; j++){
85276 c = pMem->z[j];
85277 sqlite3_str_appendchar(pStr, 1, (c>=0x20&&c<=0x7f) ? c : '.');
85278 }
85279 sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]);
85280 }
85281 }
@@ -88577,19 +88748,17 @@
88748 SQLITE_OPEN_DELETEONCLOSE |
88749 SQLITE_OPEN_TRANSIENT_DB;
88750 assert( pOp->p1>=0 );
88751 assert( pOp->p2>=0 );
88752 pCx = p->apCsr[pOp->p1];
88753 if( pCx && pCx->pBtx ){
88754 /* If the ephermeral table is already open, erase all existing content
88755 ** so that the table is empty again, rather than creating a new table. */
88756 assert( pCx->isEphemeral );
88757 pCx->seqCount = 0;
88758 pCx->cacheStatus = CACHE_STALE;
88759 rc = sqlite3BtreeClearTable(pCx->pBtx, pCx->pgnoRoot, 0);
 
 
88760 }else{
88761 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
88762 if( pCx==0 ) goto no_mem;
88763 pCx->isEphemeral = 1;
88764 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
@@ -97441,15 +97610,18 @@
97610 ** constant because they are constant for the duration of one query.
97611 ** This allows them to be factored out of inner loops. */
97612 ExprSetProperty(pExpr,EP_ConstFunc);
97613 }
97614 if( (pDef->funcFlags & SQLITE_FUNC_CONSTANT)==0 ){
97615 /* Clearly non-deterministic functions like random(), but also
97616 ** date/time functions that use 'now', and other functions like
97617 ** sqlite_version() that might change over time cannot be used
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. */
97621 sqlite3ResolveNotValid(pParse, pNC, "non-deterministic functions",
97622 NC_IdxExpr|NC_PartIdx|NC_GenCol, 0);
97623 }else{
97624 assert( (NC_SelfRef & 0xff)==NC_SelfRef ); /* Must fit in 8 bits */
97625 pExpr->op2 = pNC->ncFlags & NC_SelfRef;
97626 if( pNC->ncFlags & NC_FromDDL ) ExprSetProperty(pExpr, EP_FromDDL);
97627 }
@@ -111196,12 +111368,12 @@
111368 if( sqlite3ResolveSelfReference(pParse, p, NC_GenCol, pX, 0) ){
111369 /* If there are errors in resolving the expression, change the
111370 ** expression to a NULL. This prevents code generators that operate
111371 ** on the expression from inserting extra parts into the expression
111372 ** tree that have been allocated from lookaside memory, which is
111373 ** illegal in a schema and will lead to errors or heap corruption
111374 ** when the database connection closes. */
111375 sqlite3ExprDelete(db, pX);
111376 p->aCol[ii].pDflt = sqlite3ExprAlloc(db, TK_NULL, 0, 0);
111377 }
111378 }else{
111379 nNG++;
@@ -115463,11 +115635,13 @@
115635 ** time functions, are implemented separately.)
115636 */
115637 /* #include "sqliteInt.h" */
115638 /* #include <stdlib.h> */
115639 /* #include <assert.h> */
115640 #ifndef SQLITE_OMIT_FLOATING_POINT
115641 /* #include <math.h> */
115642 #endif
115643 /* #include "vdbeInt.h" */
115644
115645 /*
115646 ** Return the collating function associated with a function.
115647 */
@@ -120572,17 +120746,19 @@
120746 ** pass is sufficient */
120747 break;
120748 }
120749 if( b2ndPass ) break; /* Never need more than 2 passes */
120750 b2ndPass = 1;
120751 #ifndef SQLITE_OMIT_GENERATED_COLUMNS
120752 if( nSeenReplace>0 && (pTab->tabFlags & TF_HasGenerated)!=0 ){
120753 /* If any NOT NULL ON CONFLICT REPLACE constraints fired on the
120754 ** first pass, recomputed values for all generated columns, as
120755 ** those values might depend on columns affected by the REPLACE.
120756 */
120757 sqlite3ComputeGeneratedColumns(pParse, regNewData+1, pTab);
120758 }
120759 #endif
120760 } /* end of 2-pass loop */
120761 } /* end if( has-not-null-constraints ) */
120762
120763 /* Test all CHECK constraints
120764 */
@@ -122287,11 +122463,16 @@
122463 /* Version 3.28.0 and later */
122464 int (*stmt_isexplain)(sqlite3_stmt*);
122465 int (*value_frombind)(sqlite3_value*);
122466 /* Version 3.30.0 and later */
122467 int (*drop_modules)(sqlite3*,const char**);
122468 /* Version 3.31.0 and later */
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*);
122474 };
122475
122476 /*
122477 ** This is the function signature used for all extension entry points. It
122478 ** is also defined in the file "loadext.c".
@@ -122582,11 +122763,16 @@
122763 /* Version 3.28.0 and later */
122764 #define sqlite3_stmt_isexplain sqlite3_api->isexplain
122765 #define sqlite3_value_frombind sqlite3_api->frombind
122766 /* Version 3.30.0 and later */
122767 #define sqlite3_drop_modules sqlite3_api->drop_modules
122768 /* Version 3.31.0 andn later */
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
122774 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
122775
122776 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
122777 /* This case when the file really is being compiled as a loadable
122778 ** extension */
@@ -123057,10 +123243,14 @@
123243 #else
123244 0,
123245 #endif
123246 /* Version 3.31.0 and later */
123247 sqlite3_hard_heap_limit64,
123248 sqlite3_uri_key,
123249 sqlite3_filename_database,
123250 sqlite3_filename_journal,
123251 sqlite3_filename_wal,
123252 };
123253
123254 /*
123255 ** Attempt to load an SQLite extension library contained in the file
123256 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -125937,14 +126127,21 @@
126127 /* Only change the value of sqlite.enc if the database handle is not
126128 ** initialized. If the main database exists, the new sqlite.enc value
126129 ** will be overwritten when the schema is next loaded. If it does not
126130 ** already exists, it will be created to use the new encoding value.
126131 */
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 ){
126143 for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
126144 if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
126145 SCHEMA_ENC(db) = ENC(db) =
126146 pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
126147 break;
@@ -130138,11 +130335,13 @@
130335 assert( p->selFlags & SF_MultiValue );
130336 do{
130337 assert( p->selFlags & SF_Values );
130338 assert( p->op==TK_ALL || (p->op==TK_SELECT && p->pPrior==0) );
130339 assert( p->pNext==0 || p->pEList->nExpr==p->pNext->pEList->nExpr );
130340 #ifndef SQLITE_OMIT_WINDOWFUNC
130341 if( p->pWin ) return -1;
130342 #endif
130343 if( p->pPrior==0 ) break;
130344 assert( p->pPrior->pNext==p );
130345 p = p->pPrior;
130346 nRow += bShowAll;
130347 }while(1);
@@ -131501,11 +131700,13 @@
131700 assert( pSub->pSrc!=0 );
131701 assert( pSub->pEList->nExpr==pSub1->pEList->nExpr );
131702 if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0 /* (17b) */
131703 || (pSub1->pPrior && pSub1->op!=TK_ALL) /* (17a) */
131704 || pSub1->pSrc->nSrc<1 /* (17c) */
131705 #ifndef SQLITE_OMIT_WINDOWFUNC
131706 || pSub1->pWin /* (17e) */
131707 #endif
131708 ){
131709 return 0;
131710 }
131711 testcase( pSub1->pSrc->nSrc>1 );
131712 }
@@ -131875,11 +132076,15 @@
132076 */
132077 static int propagateConstantExprRewrite(Walker *pWalker, Expr *pExpr){
132078 int i;
132079 WhereConst *pConst;
132080 if( pExpr->op!=TK_COLUMN ) 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 }
132086 pConst = pWalker->u.pConst;
132087 for(i=0; i<pConst->nConst; i++){
132088 Expr *pColumn = pConst->apExpr[i*2];
132089 if( pColumn==pExpr ) continue;
132090 if( pColumn->iTable!=pExpr->iTable ) continue;
@@ -132604,11 +132809,11 @@
132809 }
132810 pTab->nTabRef++;
132811 if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
132812 return WRC_Abort;
132813 }
132814 #if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_VIRTUALTABLE)
132815 if( IsVirtual(pTab) || pTab->pSelect ){
132816 i16 nCol;
132817 u8 eCodeOrig = pWalker->eCode;
132818 if( sqlite3ViewGetColumnNames(pParse, pTab) ) return WRC_Abort;
132819 assert( pFrom->pSelect==0 );
@@ -133756,11 +133961,13 @@
133961 ** written the query must use a temp-table for at least one of the ORDER
133962 ** BY and DISTINCT, and an index or separate temp-table for the other.
133963 */
133964 if( (p->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct
133965 && sqlite3ExprListCompare(sSort.pOrderBy, pEList, -1)==0
133966 #ifndef SQLITE_OMIT_WINDOWFUNC
133967 && p->pWin==0
133968 #endif
133969 ){
133970 p->selFlags &= ~SF_Distinct;
133971 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
133972 p->selFlags |= SF_Aggregate;
133973 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
@@ -139191,26 +139398,26 @@
139398 };
139399
139400 /*
139401 ** Allowed values of WhereTerm.wtFlags
139402 */
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 */
139410 #ifdef SQLITE_ENABLE_STAT4
139411 # define TERM_VNULL 0x0080 /* Manufactured x>NULL or x<=NULL term */
139412 #else
139413 # define TERM_VNULL 0x0000 /* Disabled if not using stat4 */
139414 #endif
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 */
139419 #define TERM_VARSELECT 0x1000 /* Term.pExpr contains a correlated sub-query */
139420
139421 /*
139422 ** An instance of the WhereScan object is used as an iterator for locating
139423 ** terms in the WHERE clause that are useful to the query planner.
@@ -141660,13 +141867,13 @@
141867 WhereTerm *pOrTerm = &pOrWc->a[ii];
141868 if( pOrTerm->leftCursor==iCur || (pOrTerm->eOperator & WO_AND)!=0 ){
141869 WhereInfo *pSubWInfo; /* Info for single OR-term scan */
141870 Expr *pOrExpr = pOrTerm->pExpr; /* Current OR clause term */
141871 int jmp1 = 0; /* Address of jump operation */
141872 testcase( (pTabItem[0].fg.jointype & JT_LEFT)!=0
141873 && !ExprHasProperty(pOrExpr, EP_FromJoin)
141874 ); /* See TH3 vtab25.400 and ticket 614b25314c766238 */
141875 if( pAndExpr ){
141876 pAndExpr->pLeft = pOrExpr;
141877 pOrExpr = pAndExpr;
141878 }
141879 /* Loop through table entries that match term pOrTerm. */
@@ -148498,18 +148705,18 @@
148705 ** CREATE TABLE t3(ipk INTEGER PRIMARY KEY, v3);
148706 **
148707 ** then table t2 can be omitted from the following:
148708 **
148709 ** SELECT v1, v3 FROM t1
148710 ** LEFT JOIN t2 ON (t1.ipk=t2.ipk)
148711 ** LEFT JOIN t3 ON (t1.ipk=t3.ipk)
148712 **
148713 ** or from:
148714 **
148715 ** SELECT DISTINCT v1, v3 FROM t1
148716 ** LEFT JOIN t2
148717 ** LEFT JOIN t3 ON (t1.ipk=t3.ipk)
148718 */
148719 notReady = ~(Bitmask)0;
148720 if( pWInfo->nLevel>=2
148721 && pResultSet!=0 /* guarantees condition (1) above */
148722 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
@@ -162726,10 +162933,11 @@
162933 ** xRandomness method on the primary VFS.
162934 **
162935 ** This test-control also resets the PRNG so that the new seed will
162936 ** be used for the next call to sqlite3_randomness().
162937 */
162938 #ifndef SQLITE_OMIT_WSD
162939 case SQLITE_TESTCTRL_PRNG_SEED: {
162940 int x = va_arg(ap, int);
162941 int y;
162942 sqlite3 *db = va_arg(ap, sqlite3*);
162943 assert( db==0 || db->aDb[0].pSchema!=0 );
@@ -162736,10 +162944,11 @@
162944 if( db && (y = db->aDb[0].pSchema->schema_cookie)!=0 ){ x = y; }
162945 sqlite3Config.iPrngSeed = x;
162946 sqlite3_randomness(0,0);
162947 break;
162948 }
162949 #endif
162950
162951 /*
162952 ** sqlite3_test_control(BITVEC_TEST, size, program)
162953 **
162954 ** Run a test against a Bitvec object of size. The program argument
@@ -163063,29 +163272,10 @@
163272 va_end(ap);
163273 #endif /* SQLITE_UNTESTABLE */
163274 return rc;
163275 }
163276
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163277 /*
163278 ** This is a utility routine, useful to VFS implementations, that checks
163279 ** to see if a database file was a URI that contained a specific query
163280 ** parameter, and if so obtains the value of the query parameter.
163281 **
@@ -163104,10 +163294,23 @@
163294 if( x==0 ) return zFilename;
163295 zFilename += sqlite3Strlen30(zFilename) + 1;
163296 }
163297 return 0;
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 }
163312
163313 /*
163314 ** Return a boolean value for a query parameter.
163315 */
163316 SQLITE_API int sqlite3_uri_boolean(const char *zFilename, const char *zParam, int bDflt){
@@ -163129,10 +163332,50 @@
163332 if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
163333 bDflt = v;
163334 }
163335 return bDflt;
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 }
163377
163378 /*
163379 ** Return the Btree pointer identified by zDbName. Return NULL if not found.
163380 */
163381 SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3 *db, const char *zDbName){
@@ -198461,37 +198704,10 @@
198704 rc = p->pReal->pMethods->xShmUnmap(p->pReal, delFlag);
198705 }
198706 return rc;
198707 }
198708
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198709 /*
198710 ** Open an rbu file handle.
198711 */
198712 static int rbuVfsOpen(
198713 sqlite3_vfs *pVfs,
@@ -198536,11 +198752,11 @@
198752 /* A main database has just been opened. The following block sets
198753 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
198754 ** the name of the *-wal file this db connection will use. SQLite
198755 ** happens to pass a pointer to this buffer when using xAccess()
198756 ** or xOpen() to operate on the *-wal file. */
198757 pFd->zWal = sqlite3_filename_wal(zName);
198758 }
198759 else if( flags & SQLITE_OPEN_WAL ){
198760 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName, 0);
198761 if( pDb ){
198762 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
@@ -198551,11 +198767,11 @@
198767 const char *zBase = zName;
198768 size_t nCopy;
198769 char *zCopy;
198770 if( rbuIsVacuum(pDb->pRbu) ){
198771 zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
198772 zBase = sqlite3_filename_wal(zBase);
198773 }
198774 nCopy = strlen(zBase);
198775 zCopy = sqlite3_malloc64(nCopy+2);
198776 if( zCopy ){
198777 memcpy(zCopy, zBase, nCopy);
@@ -223413,11 +223629,11 @@
223629 int nArg, /* Number of args */
223630 sqlite3_value **apUnused /* Function arguments */
223631 ){
223632 assert( nArg==0 );
223633 UNUSED_PARAM2(nArg, apUnused);
223634 sqlite3_result_text(pCtx, "fts5: 2020-01-20 14:42:09 63d886f4ce3c770498b8bdad45b04143a3f63197d81793bde107450aba4a9c87", -1, SQLITE_TRANSIENT);
223635 }
223636
223637 /*
223638 ** Return true if zName is the extension on one of the shadow tables used
223639 ** by this module.
@@ -228186,12 +228402,12 @@
228402 }
228403 #endif /* SQLITE_CORE */
228404 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
228405
228406 /************** End of stmt.c ************************************************/
228407 #if __LINE__!=228407
228408 #undef SQLITE_SOURCE_ID
228409 #define SQLITE_SOURCE_ID "2020-01-20 14:42:09 63d886f4ce3c770498b8bdad45b04143a3f63197d81793bde107450aba4aalt2"
228410 #endif
228411 /* Return the source-id for this library */
228412 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
228413 /************************** End of sqlite3.c ******************************/
228414
+187 -66
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.31.0"
127127
#define SQLITE_VERSION_NUMBER 3031000
128
-#define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68"
128
+#define SQLITE_SOURCE_ID "2020-01-20 14:42:09 63d886f4ce3c770498b8bdad45b04143a3f63197d81793bde107450aba4a9c87"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -1109,10 +1109,16 @@
11091109
** a single attached database that occur due to other database connections,
11101110
** but omits changes implemented by the database connection on which it is
11111111
** called. This file control is the only mechanism to detect changes that
11121112
** happen either internally or externally and that are associated with
11131113
** a particular attached database.
1114
+**
1115
+** <li>[[SQLITE_FCNTL_CKPT_DONE]]
1116
+** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
1117
+** in wal mode after the client has finished copying pages from the wal
1118
+** file to the database file, but before the *-shm file is updated to
1119
+** record the fact that the pages have been checkpointed.
11141120
** </ul>
11151121
*/
11161122
#define SQLITE_FCNTL_LOCKSTATE 1
11171123
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
11181124
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1146,10 +1152,11 @@
11461152
#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
11471153
#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
11481154
#define SQLITE_FCNTL_LOCK_TIMEOUT 34
11491155
#define SQLITE_FCNTL_DATA_VERSION 35
11501156
#define SQLITE_FCNTL_SIZE_LIMIT 36
1157
+#define SQLITE_FCNTL_CKPT_DONE 37
11511158
11521159
/* deprecated names */
11531160
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
11541161
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
11551162
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2265,25 +2272,27 @@
22652272
** compile-time option.
22662273
** </dd>
22672274
**
22682275
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
22692276
** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2270
-** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells the SQLite to
2271
-** assume that database schemas are untainted by malicious content.
2277
+** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2278
+** assume that database schemas (the contents of the [sqlite_master] tables)
2279
+** are untainted by malicious content.
22722280
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
22732281
** takes additional defensive steps to protect the application from harm
2274
-** including, but not limited to, the following:
2282
+** including:
22752283
** <ul>
22762284
** <li> Prohibit the use of SQL functions inside triggers, views,
2277
-** CHECK constraints, DEFAULT VALUEs, index definitions, and/or
2278
-** generated columns unless those functions are tagged
2279
-** with [SQLITE_INNOCUOUS].
2280
-** <li> Pohibit the use of virtual tables inside of triggers and/or views
2285
+** CHECK constraints, DEFAULT clauses, expression indexes,
2286
+** partial indexes, or generated columns
2287
+** unless those functions are tagged with [SQLITE_INNOCUOUS].
2288
+** <li> Prohibit the use of virtual tables inside of triggers or views
22812289
** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
22822290
** </ul>
22832291
** This setting defaults to "on" for legacy compatibility, however
2284
-** all applications are advised to turn it off if possible.
2292
+** all applications are advised to turn it off if possible. This setting
2293
+** can also be controlled using the [PRAGMA trusted_schema] statement.
22852294
** </dd>
22862295
**
22872296
** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
22882297
** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
22892298
** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
@@ -2792,11 +2801,11 @@
27922801
/*
27932802
** CAPI3REF: Memory Allocation Subsystem
27942803
**
27952804
** The SQLite core uses these three routines for all of its own
27962805
** internal memory allocation needs. "Core" in the previous sentence
2797
-** does not include operating-system specific VFS implementation. The
2806
+** does not include operating-system specific [VFS] implementation. The
27982807
** Windows VFS uses native malloc() and free() for some operations.
27992808
**
28002809
** ^The sqlite3_malloc() routine returns a pointer to a block
28012810
** of memory at least N bytes in length, where N is the parameter.
28022811
** ^If sqlite3_malloc() is unable to obtain sufficient free
@@ -3275,14 +3284,12 @@
32753284
** passing it to [sqlite3_close()] when it is no longer required.
32763285
**
32773286
** The sqlite3_open_v2() interface works like sqlite3_open()
32783287
** except that it accepts two additional parameters for additional control
32793288
** over the new database connection. ^(The flags parameter to
3280
-** sqlite3_open_v2() can take one of
3281
-** the following three values, optionally combined with the
3282
-** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
3283
-** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
3289
+** sqlite3_open_v2() must include, at a minimum, one of the following
3290
+** three flag combinations:)^
32843291
**
32853292
** <dl>
32863293
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
32873294
** <dd>The database is opened in read-only mode. If the database does not
32883295
** already exist, an error is returned.</dd>)^
@@ -3295,28 +3302,56 @@
32953302
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
32963303
** <dd>The database is opened for reading and writing, and is created if
32973304
** it does not already exist. This is the behavior that is always used for
32983305
** sqlite3_open() and sqlite3_open16().</dd>)^
32993306
** </dl>
3307
+**
3308
+** In addition to the required flags, the following optional flags are
3309
+** also supported:
3310
+**
3311
+** <dl>
3312
+** ^(<dt>[SQLITE_OPEN_URI]</dt>
3313
+** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
3314
+**
3315
+** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
3316
+** <dd>The database will be opened as an in-memory database. The database
3317
+** is named by the "filename" argument for the purposes of cache-sharing,
3318
+** if shared cache mode is enabled, but the "filename" is otherwise ignored.
3319
+** </dd>)^
3320
+**
3321
+** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
3322
+** <dd>The new database connection will use the "multi-thread"
3323
+** [threading mode].)^ This means that separate threads are allowed
3324
+** to use SQLite at the same time, as long as each thread is using
3325
+** a different [database connection].
3326
+**
3327
+** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
3328
+** <dd>The new database connection will use the "serialized"
3329
+** [threading mode].)^ This means the multiple threads can safely
3330
+** attempt to use the same database connection at the same time.
3331
+** (Mutexes will block any actual concurrency, but in this mode
3332
+** there is no harm in trying.)
3333
+**
3334
+** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3335
+** <dd>The database is opened [shared cache] enabled, overriding
3336
+** the default shared cache setting provided by
3337
+** [sqlite3_enable_shared_cache()].)^
3338
+**
3339
+** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3340
+** <dd>The database is opened [shared cache] disabled, overriding
3341
+** the default shared cache setting provided by
3342
+** [sqlite3_enable_shared_cache()].)^
3343
+**
3344
+** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3345
+** <dd>The database filename is not allowed to be a symbolic link</dd>
3346
+** </dl>)^
33003347
**
33013348
** If the 3rd parameter to sqlite3_open_v2() is not one of the
3302
-** combinations shown above optionally combined with other
3349
+** required combinations shown above optionally combined with other
33033350
** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
33043351
** then the behavior is undefined.
33053352
**
3306
-** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
3307
-** opens in the multi-thread [threading mode] as long as the single-thread
3308
-** mode has not been set at compile-time or start-time. ^If the
3309
-** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
3310
-** in the serialized [threading mode] unless single-thread was
3311
-** previously selected at compile-time or start-time.
3312
-** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
3313
-** eligible to use [shared cache mode], regardless of whether or not shared
3314
-** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
3315
-** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
3316
-** participate in [shared cache mode] even if it is enabled.
3317
-**
33183353
** ^The fourth parameter to sqlite3_open_v2() is the name of the
33193354
** [sqlite3_vfs] object that defines the operating system interface that
33203355
** the new database connection should use. ^If the fourth parameter is
33213356
** a NULL pointer then the default [sqlite3_vfs] object is used.
33223357
**
@@ -3492,18 +3527,17 @@
34923527
);
34933528
34943529
/*
34953530
** CAPI3REF: Obtain Values For URI Parameters
34963531
**
3497
-** These are utility routines, useful to VFS implementations, that check
3498
-** to see if a database file was a URI that contained a specific query
3532
+** These are utility routines, useful to [VFS|custom VFS implementations],
3533
+** that check if a database file was a URI that contained a specific query
34993534
** parameter, and if so obtains the value of that query parameter.
35003535
**
35013536
** If F is the database filename pointer passed into the xOpen() method of
3502
-** a VFS implementation when the flags parameter to xOpen() has one or
3503
-** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
3504
-** P is the name of the query parameter, then
3537
+** a VFS implementation or it is the return value of [sqlite3_db_filename()]
3538
+** and if P is the name of the query parameter, then
35053539
** sqlite3_uri_parameter(F,P) returns the value of the P
35063540
** parameter if it exists or a NULL pointer if P does not appear as a
35073541
** query parameter on F. If P is a query parameter of F and it
35083542
** has no explicit value, then sqlite3_uri_parameter(F,P) returns
35093543
** a pointer to an empty string.
@@ -3521,22 +3555,69 @@
35213555
**
35223556
** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
35233557
** 64-bit signed integer and returns that integer, or D if P does not
35243558
** exist. If the value of P is something other than an integer, then
35253559
** zero is returned.
3560
+**
3561
+** The sqlite3_uri_key(F,N) returns a pointer to the name (not
3562
+** the value) of the N-th query parameter for filename F, or a NULL
3563
+** pointer if N is less than zero or greater than the number of query
3564
+** parameters minus 1. The N value is zero-based so N should be 0 to obtain
3565
+** the name of the first query parameter, 1 for the second parameter, and
3566
+** so forth.
35263567
**
35273568
** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
35283569
** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
3529
-** is not a database file pathname pointer that SQLite passed into the xOpen
3530
-** VFS method, then the behavior of this routine is undefined and probably
3531
-** undesirable.
3570
+** is not a database file pathname pointer that the SQLite core passed
3571
+** into the xOpen VFS method, then the behavior of this routine is undefined
3572
+** and probably undesirable.
3573
+**
3574
+** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
3575
+** parameter can also be the name of a rollback journal file or WAL file
3576
+** in addition to the main database file. Prior to version 3.31.0, these
3577
+** routines would only work if F was the name of the main database file.
3578
+** When the F parameter is the name of the rollback journal or WAL file,
3579
+** it has access to all the same query parameters as were found on the
3580
+** main database file.
35323581
**
35333582
** See the [URI filename] documentation for additional information.
35343583
*/
35353584
SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
35363585
SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
35373586
SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3587
+SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N);
3588
+
3589
+/*
3590
+** CAPI3REF: Translate filenames
3591
+**
3592
+** These routines are available to [VFS|custom VFS implementations] for
3593
+** translating filenames between the main database file, the journal file,
3594
+** and the WAL file.
3595
+**
3596
+** If F is the name of an sqlite database file, journal file, or WAL file
3597
+** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
3598
+** returns the name of the corresponding database file.
3599
+**
3600
+** If F is the name of an sqlite database file, journal file, or WAL file
3601
+** passed by the SQLite core into the VFS, or if F is a database filename
3602
+** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
3603
+** returns the name of the corresponding rollback journal file.
3604
+**
3605
+** If F is the name of an sqlite database file, journal file, or WAL file
3606
+** that was passed by the SQLite core into the VFS, or if F is a database
3607
+** filename obtained from [sqlite3_db_filename()], then
3608
+** sqlite3_filename_wal(F) returns the name of the corresponding
3609
+** WAL file.
3610
+**
3611
+** In all of the above, if F is not the name of a database, journal or WAL
3612
+** filename passed into the VFS from the SQLite core and F is not the
3613
+** return value from [sqlite3_db_filename()], then the result is
3614
+** undefined and is likely a memory access violation.
3615
+*/
3616
+SQLITE_API const char *sqlite3_filename_database(const char*);
3617
+SQLITE_API const char *sqlite3_filename_journal(const char*);
3618
+SQLITE_API const char *sqlite3_filename_wal(const char*);
35383619
35393620
35403621
/*
35413622
** CAPI3REF: Error Codes And Messages
35423623
** METHOD: sqlite3
@@ -4835,12 +4916,10 @@
48354916
SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
48364917
48374918
/*
48384919
** CAPI3REF: Create Or Redefine SQL Functions
48394920
** KEYWORDS: {function creation routines}
4840
-** KEYWORDS: {application-defined SQL function}
4841
-** KEYWORDS: {application-defined SQL functions}
48424921
** METHOD: sqlite3
48434922
**
48444923
** ^These functions (collectively known as "function creation routines")
48454924
** are used to add SQL functions or aggregates or to redefine the behavior
48464925
** of existing SQL functions or aggregates. The only differences between
@@ -4892,13 +4971,24 @@
48924971
** perform additional optimizations on deterministic functions, so use
48934972
** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
48944973
**
48954974
** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
48964975
** flag, which if present prevents the function from being invoked from
4897
-** within VIEWs or TRIGGERs. For security reasons, the [SQLITE_DIRECTONLY]
4898
-** flag is recommended for any application-defined SQL function that has
4899
-** side-effects.
4976
+** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
4977
+** index expressions, or the WHERE clause of partial indexes.
4978
+**
4979
+** <span style="background-color:#ffff90;">
4980
+** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
4981
+** all application-defined SQL functions that do not need to be
4982
+** used inside of triggers, view, CHECK constraints, or other elements of
4983
+** the database schema. This flags is especially recommended for SQL
4984
+** functions that have side effects or reveal internal application state.
4985
+** Without this flag, an attacker might be able to modify the schema of
4986
+** a database file to include invocations of the function with parameters
4987
+** chosen by the attacker, which the application will then execute when
4988
+** the database file is opened and read.
4989
+** </span>
49004990
**
49014991
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
49024992
** function can gain access to this pointer using [sqlite3_user_data()].)^
49034993
**
49044994
** ^The sixth, seventh and eighth parameters passed to the three
@@ -5013,46 +5103,66 @@
50135103
** These constants may be ORed together with the
50145104
** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
50155105
** to [sqlite3_create_function()], [sqlite3_create_function16()], or
50165106
** [sqlite3_create_function_v2()].
50175107
**
5108
+** <dl>
5109
+** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
50185110
** The SQLITE_DETERMINISTIC flag means that the new function always gives
50195111
** the same output when the input parameters are the same.
50205112
** The [abs|abs() function] is deterministic, for example, but
50215113
** [randomblob|randomblob()] is not. Functions must
50225114
** be deterministic in order to be used in certain contexts such as
5023
-** [CHECK constraints] or [generated columns]. SQLite might also optimize
5024
-** deterministic functions by factoring them out of inner loops.
5115
+** with the WHERE clause of [partial indexes] or in [generated columns].
5116
+** SQLite might also optimize deterministic functions by factoring them
5117
+** out of inner loops.
5118
+** </dd>
5119
+**
5120
+** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
5121
+** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5122
+** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5123
+** schema structures such as [CHECK constraints], [DEFAULT clauses],
5124
+** [expression indexes], [partial indexes], or [generated columns].
5125
+** The SQLITE_DIRECTONLY flags is a security feature which is recommended
5126
+** for all [application-defined SQL functions], and especially for functions
5127
+** that have side-effects or that could potentially leak sensitive
5128
+** information.
5129
+** </dd>
50255130
**
5026
-** The SQLITE_INNOCUOUS flag means that the new function is unlikely
5131
+** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
5132
+** The SQLITE_INNOCUOUS flag means that the function is unlikely
50275133
** to cause problems even if misused. An innocuous function should have
5028
-** no side effects and consume few resources. The [abs|abs() function]
5029
-** is an example of an innocuous function.
5134
+** no side effects and should not depend on any values other than its
5135
+** input parameters. The [abs|abs() function] is an example of an
5136
+** innocuous function.
50305137
** The [load_extension() SQL function] is not innocuous because of its
5031
-** side effects. Some heightened security settings
5032
-** ([SQLITE_DBCONFIG_UNSAFE_FUNC_IN_VIEW])
5033
-** disable the use of SQLlfunctions inside views and triggers unless
5138
+** side effects.
5139
+** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not
5140
+** exactly the same. The [random|random() function] is an example of a
5141
+** function that is innocuous but not deterministic.
5142
+** <p>Some heightened security settings
5143
+** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF])
5144
+** disable the use of SQL functions inside views and triggers and in
5145
+** schema structures such as [CHECK constraints], [DEFAULT clauses],
5146
+** [expression indexes], [partial indexes], and [generated columns] unless
50345147
** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
50355148
** are innocuous. Developers are advised to avoid using the
50365149
** SQLITE_INNOCUOUS flag for application-defined functions unless the
5037
-** function is specifically intended for use inside of views and triggers.
5038
-**
5039
-** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5040
-** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
5041
-** a security feature which is recommended for all
5042
-** [application-defined SQL functions] that have side-effects. This flag
5043
-** prevents an attacker from adding triggers and views to a schema then
5044
-** tricking a high-privilege application into causing unintended side-effects
5045
-** while performing ordinary queries.
5046
-**
5150
+** function has been carefully audited and found to be free of potentially
5151
+** security-adverse side-effects and information-leaks.
5152
+** </dd>
5153
+**
5154
+** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd>
50475155
** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
50485156
** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
50495157
** Specifying this flag makes no difference for scalar or aggregate user
50505158
** functions. However, if it is not specified for a user-defined window
50515159
** function, then any sub-types belonging to arguments passed to the window
50525160
** function may be discarded before the window function is called (i.e.
50535161
** sqlite3_value_subtype() will always return 0).
5162
+** </dd>
5163
+** </dl>
50545164
*/
50555165
#define SQLITE_DETERMINISTIC 0x000000800
50565166
#define SQLITE_DIRECTONLY 0x000080000
50575167
#define SQLITE_SUBTYPE 0x000100000
50585168
#define SQLITE_INNOCUOUS 0x000200000
@@ -5964,10 +6074,21 @@
59646074
**
59656075
** ^The filename returned by this function is the output of the
59666076
** xFullPathname method of the [VFS]. ^In other words, the filename
59676077
** will be an absolute pathname, even if the filename used
59686078
** to open the database originally was a URI or relative pathname.
6079
+**
6080
+** If the filename pointer returned by this routine is not NULL, then it
6081
+** can be used as the filename input parameter to these routines:
6082
+** <ul>
6083
+** <li> [sqlite3_uri_parameter()]
6084
+** <li> [sqlite3_uri_boolean()]
6085
+** <li> [sqlite3_uri_int64()]
6086
+** <li> [sqlite3_filename_database()]
6087
+** <li> [sqlite3_filename_journal()]
6088
+** <li> [sqlite3_filename_wal()]
6089
+** </ul>
59696090
*/
59706091
SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
59716092
59726093
/*
59736094
** CAPI3REF: Determine if a database is read-only
@@ -8932,10 +9053,18 @@
89329053
** silently replace the appropriate rows within the xUpdate callback and
89339054
** return SQLITE_OK. Or, if this is not possible, it may return
89349055
** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
89359056
** constraint handling.
89369057
** </dd>
9058
+**
9059
+** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
9060
+** <dd>Calls of the form
9061
+** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9062
+** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9063
+** prohibits that virtual table from being used from within triggers and
9064
+** views.
9065
+** </dd>
89379066
**
89389067
** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
89399068
** <dd>Calls of the form
89409069
** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
89419070
** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
@@ -8943,18 +9072,10 @@
89439072
** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
89449073
** virtual table can do no serious harm even if it is controlled by a
89459074
** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
89469075
** flag unless absolutely necessary.
89479076
** </dd>
8948
-**
8949
-** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
8950
-** <dd>Calls of the form
8951
-** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
8952
-** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
8953
-** prohibits that virtual table from being used from within triggers and
8954
-** views.
8955
-** </dd>
89569077
** </dl>
89579078
*/
89589079
#define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
89599080
#define SQLITE_VTAB_INNOCUOUS 2
89609081
#define SQLITE_VTAB_DIRECTONLY 3
89619082
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.31.0"
127 #define SQLITE_VERSION_NUMBER 3031000
128 #define SQLITE_SOURCE_ID "2020-01-09 20:44:37 5720924cb07766cd54fb042da58f4b4acf12b60029fba86a23a606ad0d0f7c68"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1109,10 +1109,16 @@
1109 ** a single attached database that occur due to other database connections,
1110 ** but omits changes implemented by the database connection on which it is
1111 ** called. This file control is the only mechanism to detect changes that
1112 ** happen either internally or externally and that are associated with
1113 ** a particular attached database.
 
 
 
 
 
 
1114 ** </ul>
1115 */
1116 #define SQLITE_FCNTL_LOCKSTATE 1
1117 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1118 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1146,10 +1152,11 @@
1146 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
1147 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
1148 #define SQLITE_FCNTL_LOCK_TIMEOUT 34
1149 #define SQLITE_FCNTL_DATA_VERSION 35
1150 #define SQLITE_FCNTL_SIZE_LIMIT 36
 
1151
1152 /* deprecated names */
1153 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1154 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1155 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2265,25 +2272,27 @@
2265 ** compile-time option.
2266 ** </dd>
2267 **
2268 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2269 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2270 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells the SQLite to
2271 ** assume that database schemas are untainted by malicious content.
 
2272 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2273 ** takes additional defensive steps to protect the application from harm
2274 ** including, but not limited to, the following:
2275 ** <ul>
2276 ** <li> Prohibit the use of SQL functions inside triggers, views,
2277 ** CHECK constraints, DEFAULT VALUEs, index definitions, and/or
2278 ** generated columns unless those functions are tagged
2279 ** with [SQLITE_INNOCUOUS].
2280 ** <li> Pohibit the use of virtual tables inside of triggers and/or views
2281 ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
2282 ** </ul>
2283 ** This setting defaults to "on" for legacy compatibility, however
2284 ** all applications are advised to turn it off if possible.
 
2285 ** </dd>
2286 **
2287 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2288 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
2289 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
@@ -2792,11 +2801,11 @@
2792 /*
2793 ** CAPI3REF: Memory Allocation Subsystem
2794 **
2795 ** The SQLite core uses these three routines for all of its own
2796 ** internal memory allocation needs. "Core" in the previous sentence
2797 ** does not include operating-system specific VFS implementation. The
2798 ** Windows VFS uses native malloc() and free() for some operations.
2799 **
2800 ** ^The sqlite3_malloc() routine returns a pointer to a block
2801 ** of memory at least N bytes in length, where N is the parameter.
2802 ** ^If sqlite3_malloc() is unable to obtain sufficient free
@@ -3275,14 +3284,12 @@
3275 ** passing it to [sqlite3_close()] when it is no longer required.
3276 **
3277 ** The sqlite3_open_v2() interface works like sqlite3_open()
3278 ** except that it accepts two additional parameters for additional control
3279 ** over the new database connection. ^(The flags parameter to
3280 ** sqlite3_open_v2() can take one of
3281 ** the following three values, optionally combined with the
3282 ** [SQLITE_OPEN_NOMUTEX], [SQLITE_OPEN_FULLMUTEX], [SQLITE_OPEN_SHAREDCACHE],
3283 ** [SQLITE_OPEN_PRIVATECACHE], and/or [SQLITE_OPEN_URI] flags:)^
3284 **
3285 ** <dl>
3286 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3287 ** <dd>The database is opened in read-only mode. If the database does not
3288 ** already exist, an error is returned.</dd>)^
@@ -3295,28 +3302,56 @@
3295 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3296 ** <dd>The database is opened for reading and writing, and is created if
3297 ** it does not already exist. This is the behavior that is always used for
3298 ** sqlite3_open() and sqlite3_open16().</dd>)^
3299 ** </dl>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3300 **
3301 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3302 ** combinations shown above optionally combined with other
3303 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3304 ** then the behavior is undefined.
3305 **
3306 ** ^If the [SQLITE_OPEN_NOMUTEX] flag is set, then the database connection
3307 ** opens in the multi-thread [threading mode] as long as the single-thread
3308 ** mode has not been set at compile-time or start-time. ^If the
3309 ** [SQLITE_OPEN_FULLMUTEX] flag is set then the database connection opens
3310 ** in the serialized [threading mode] unless single-thread was
3311 ** previously selected at compile-time or start-time.
3312 ** ^The [SQLITE_OPEN_SHAREDCACHE] flag causes the database connection to be
3313 ** eligible to use [shared cache mode], regardless of whether or not shared
3314 ** cache is enabled using [sqlite3_enable_shared_cache()]. ^The
3315 ** [SQLITE_OPEN_PRIVATECACHE] flag causes the database connection to not
3316 ** participate in [shared cache mode] even if it is enabled.
3317 **
3318 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3319 ** [sqlite3_vfs] object that defines the operating system interface that
3320 ** the new database connection should use. ^If the fourth parameter is
3321 ** a NULL pointer then the default [sqlite3_vfs] object is used.
3322 **
@@ -3492,18 +3527,17 @@
3492 );
3493
3494 /*
3495 ** CAPI3REF: Obtain Values For URI Parameters
3496 **
3497 ** These are utility routines, useful to VFS implementations, that check
3498 ** to see if a database file was a URI that contained a specific query
3499 ** parameter, and if so obtains the value of that query parameter.
3500 **
3501 ** If F is the database filename pointer passed into the xOpen() method of
3502 ** a VFS implementation when the flags parameter to xOpen() has one or
3503 ** more of the [SQLITE_OPEN_URI] or [SQLITE_OPEN_MAIN_DB] bits set and
3504 ** P is the name of the query parameter, then
3505 ** sqlite3_uri_parameter(F,P) returns the value of the P
3506 ** parameter if it exists or a NULL pointer if P does not appear as a
3507 ** query parameter on F. If P is a query parameter of F and it
3508 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
3509 ** a pointer to an empty string.
@@ -3521,22 +3555,69 @@
3521 **
3522 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
3523 ** 64-bit signed integer and returns that integer, or D if P does not
3524 ** exist. If the value of P is something other than an integer, then
3525 ** zero is returned.
 
 
 
 
 
 
 
3526 **
3527 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
3528 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
3529 ** is not a database file pathname pointer that SQLite passed into the xOpen
3530 ** VFS method, then the behavior of this routine is undefined and probably
3531 ** undesirable.
 
 
 
 
 
 
 
 
3532 **
3533 ** See the [URI filename] documentation for additional information.
3534 */
3535 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
3536 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
3537 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3538
3539
3540 /*
3541 ** CAPI3REF: Error Codes And Messages
3542 ** METHOD: sqlite3
@@ -4835,12 +4916,10 @@
4835 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
4836
4837 /*
4838 ** CAPI3REF: Create Or Redefine SQL Functions
4839 ** KEYWORDS: {function creation routines}
4840 ** KEYWORDS: {application-defined SQL function}
4841 ** KEYWORDS: {application-defined SQL functions}
4842 ** METHOD: sqlite3
4843 **
4844 ** ^These functions (collectively known as "function creation routines")
4845 ** are used to add SQL functions or aggregates or to redefine the behavior
4846 ** of existing SQL functions or aggregates. The only differences between
@@ -4892,13 +4971,24 @@
4892 ** perform additional optimizations on deterministic functions, so use
4893 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
4894 **
4895 ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
4896 ** flag, which if present prevents the function from being invoked from
4897 ** within VIEWs or TRIGGERs. For security reasons, the [SQLITE_DIRECTONLY]
4898 ** flag is recommended for any application-defined SQL function that has
4899 ** side-effects.
 
 
 
 
 
 
 
 
 
 
 
4900 **
4901 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
4902 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4903 **
4904 ** ^The sixth, seventh and eighth parameters passed to the three
@@ -5013,46 +5103,66 @@
5013 ** These constants may be ORed together with the
5014 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
5015 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
5016 ** [sqlite3_create_function_v2()].
5017 **
 
 
5018 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
5019 ** the same output when the input parameters are the same.
5020 ** The [abs|abs() function] is deterministic, for example, but
5021 ** [randomblob|randomblob()] is not. Functions must
5022 ** be deterministic in order to be used in certain contexts such as
5023 ** [CHECK constraints] or [generated columns]. SQLite might also optimize
5024 ** deterministic functions by factoring them out of inner loops.
 
 
 
 
 
 
 
 
 
 
 
 
 
5025 **
5026 ** The SQLITE_INNOCUOUS flag means that the new function is unlikely
 
5027 ** to cause problems even if misused. An innocuous function should have
5028 ** no side effects and consume few resources. The [abs|abs() function]
5029 ** is an example of an innocuous function.
 
5030 ** The [load_extension() SQL function] is not innocuous because of its
5031 ** side effects. Some heightened security settings
5032 ** ([SQLITE_DBCONFIG_UNSAFE_FUNC_IN_VIEW])
5033 ** disable the use of SQLlfunctions inside views and triggers unless
 
 
 
 
 
 
5034 ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
5035 ** are innocuous. Developers are advised to avoid using the
5036 ** SQLITE_INNOCUOUS flag for application-defined functions unless the
5037 ** function is specifically intended for use inside of views and triggers.
5038 **
5039 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5040 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs. This is
5041 ** a security feature which is recommended for all
5042 ** [application-defined SQL functions] that have side-effects. This flag
5043 ** prevents an attacker from adding triggers and views to a schema then
5044 ** tricking a high-privilege application into causing unintended side-effects
5045 ** while performing ordinary queries.
5046 **
5047 ** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
5048 ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
5049 ** Specifying this flag makes no difference for scalar or aggregate user
5050 ** functions. However, if it is not specified for a user-defined window
5051 ** function, then any sub-types belonging to arguments passed to the window
5052 ** function may be discarded before the window function is called (i.e.
5053 ** sqlite3_value_subtype() will always return 0).
 
 
5054 */
5055 #define SQLITE_DETERMINISTIC 0x000000800
5056 #define SQLITE_DIRECTONLY 0x000080000
5057 #define SQLITE_SUBTYPE 0x000100000
5058 #define SQLITE_INNOCUOUS 0x000200000
@@ -5964,10 +6074,21 @@
5964 **
5965 ** ^The filename returned by this function is the output of the
5966 ** xFullPathname method of the [VFS]. ^In other words, the filename
5967 ** will be an absolute pathname, even if the filename used
5968 ** to open the database originally was a URI or relative pathname.
 
 
 
 
 
 
 
 
 
 
 
5969 */
5970 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
5971
5972 /*
5973 ** CAPI3REF: Determine if a database is read-only
@@ -8932,10 +9053,18 @@
8932 ** silently replace the appropriate rows within the xUpdate callback and
8933 ** return SQLITE_OK. Or, if this is not possible, it may return
8934 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
8935 ** constraint handling.
8936 ** </dd>
 
 
 
 
 
 
 
 
8937 **
8938 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
8939 ** <dd>Calls of the form
8940 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
8941 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
@@ -8943,18 +9072,10 @@
8943 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
8944 ** virtual table can do no serious harm even if it is controlled by a
8945 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
8946 ** flag unless absolutely necessary.
8947 ** </dd>
8948 **
8949 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
8950 ** <dd>Calls of the form
8951 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
8952 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
8953 ** prohibits that virtual table from being used from within triggers and
8954 ** views.
8955 ** </dd>
8956 ** </dl>
8957 */
8958 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
8959 #define SQLITE_VTAB_INNOCUOUS 2
8960 #define SQLITE_VTAB_DIRECTONLY 3
8961
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.31.0"
127 #define SQLITE_VERSION_NUMBER 3031000
128 #define SQLITE_SOURCE_ID "2020-01-20 14:42:09 63d886f4ce3c770498b8bdad45b04143a3f63197d81793bde107450aba4a9c87"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -1109,10 +1109,16 @@
1109 ** a single attached database that occur due to other database connections,
1110 ** but omits changes implemented by the database connection on which it is
1111 ** called. This file control is the only mechanism to detect changes that
1112 ** happen either internally or externally and that are associated with
1113 ** a particular attached database.
1114 **
1115 ** <li>[[SQLITE_FCNTL_CKPT_DONE]]
1116 ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint
1117 ** in wal mode after the client has finished copying pages from the wal
1118 ** file to the database file, but before the *-shm file is updated to
1119 ** record the fact that the pages have been checkpointed.
1120 ** </ul>
1121 */
1122 #define SQLITE_FCNTL_LOCKSTATE 1
1123 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1124 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1146,10 +1152,11 @@
1152 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
1153 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
1154 #define SQLITE_FCNTL_LOCK_TIMEOUT 34
1155 #define SQLITE_FCNTL_DATA_VERSION 35
1156 #define SQLITE_FCNTL_SIZE_LIMIT 36
1157 #define SQLITE_FCNTL_CKPT_DONE 37
1158
1159 /* deprecated names */
1160 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1161 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1162 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2265,25 +2272,27 @@
2272 ** compile-time option.
2273 ** </dd>
2274 **
2275 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2276 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2277 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2278 ** assume that database schemas (the contents of the [sqlite_master] tables)
2279 ** are untainted by malicious content.
2280 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2281 ** takes additional defensive steps to protect the application from harm
2282 ** including:
2283 ** <ul>
2284 ** <li> Prohibit the use of SQL functions inside triggers, views,
2285 ** CHECK constraints, DEFAULT clauses, expression indexes,
2286 ** partial indexes, or generated columns
2287 ** unless those functions are tagged with [SQLITE_INNOCUOUS].
2288 ** <li> Prohibit the use of virtual tables inside of triggers or views
2289 ** unless those virtual tables are tagged with [SQLITE_VTAB_INNOCUOUS].
2290 ** </ul>
2291 ** This setting defaults to "on" for legacy compatibility, however
2292 ** all applications are advised to turn it off if possible. This setting
2293 ** can also be controlled using the [PRAGMA trusted_schema] statement.
2294 ** </dd>
2295 **
2296 ** [[SQLITE_DBCONFIG_LEGACY_FILE_FORMAT]]
2297 ** <dt>SQLITE_DBCONFIG_LEGACY_FILE_FORMAT</td>
2298 ** <dd>The SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option activates or deactivates
@@ -2792,11 +2801,11 @@
2801 /*
2802 ** CAPI3REF: Memory Allocation Subsystem
2803 **
2804 ** The SQLite core uses these three routines for all of its own
2805 ** internal memory allocation needs. "Core" in the previous sentence
2806 ** does not include operating-system specific [VFS] implementation. The
2807 ** Windows VFS uses native malloc() and free() for some operations.
2808 **
2809 ** ^The sqlite3_malloc() routine returns a pointer to a block
2810 ** of memory at least N bytes in length, where N is the parameter.
2811 ** ^If sqlite3_malloc() is unable to obtain sufficient free
@@ -3275,14 +3284,12 @@
3284 ** passing it to [sqlite3_close()] when it is no longer required.
3285 **
3286 ** The sqlite3_open_v2() interface works like sqlite3_open()
3287 ** except that it accepts two additional parameters for additional control
3288 ** over the new database connection. ^(The flags parameter to
3289 ** sqlite3_open_v2() must include, at a minimum, one of the following
3290 ** three flag combinations:)^
 
 
3291 **
3292 ** <dl>
3293 ** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3294 ** <dd>The database is opened in read-only mode. If the database does not
3295 ** already exist, an error is returned.</dd>)^
@@ -3295,28 +3302,56 @@
3302 ** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3303 ** <dd>The database is opened for reading and writing, and is created if
3304 ** it does not already exist. This is the behavior that is always used for
3305 ** sqlite3_open() and sqlite3_open16().</dd>)^
3306 ** </dl>
3307 **
3308 ** In addition to the required flags, the following optional flags are
3309 ** also supported:
3310 **
3311 ** <dl>
3312 ** ^(<dt>[SQLITE_OPEN_URI]</dt>
3313 ** <dd>The filename can be interpreted as a URI if this flag is set.</dd>)^
3314 **
3315 ** ^(<dt>[SQLITE_OPEN_MEMORY]</dt>
3316 ** <dd>The database will be opened as an in-memory database. The database
3317 ** is named by the "filename" argument for the purposes of cache-sharing,
3318 ** if shared cache mode is enabled, but the "filename" is otherwise ignored.
3319 ** </dd>)^
3320 **
3321 ** ^(<dt>[SQLITE_OPEN_NOMUTEX]</dt>
3322 ** <dd>The new database connection will use the "multi-thread"
3323 ** [threading mode].)^ This means that separate threads are allowed
3324 ** to use SQLite at the same time, as long as each thread is using
3325 ** a different [database connection].
3326 **
3327 ** ^(<dt>[SQLITE_OPEN_FULLMUTEX]</dt>
3328 ** <dd>The new database connection will use the "serialized"
3329 ** [threading mode].)^ This means the multiple threads can safely
3330 ** attempt to use the same database connection at the same time.
3331 ** (Mutexes will block any actual concurrency, but in this mode
3332 ** there is no harm in trying.)
3333 **
3334 ** ^(<dt>[SQLITE_OPEN_SHAREDCACHE]</dt>
3335 ** <dd>The database is opened [shared cache] enabled, overriding
3336 ** the default shared cache setting provided by
3337 ** [sqlite3_enable_shared_cache()].)^
3338 **
3339 ** ^(<dt>[SQLITE_OPEN_PRIVATECACHE]</dt>
3340 ** <dd>The database is opened [shared cache] disabled, overriding
3341 ** the default shared cache setting provided by
3342 ** [sqlite3_enable_shared_cache()].)^
3343 **
3344 ** [[OPEN_NOFOLLOW]] ^(<dt>[SQLITE_OPEN_NOFOLLOW]</dt>
3345 ** <dd>The database filename is not allowed to be a symbolic link</dd>
3346 ** </dl>)^
3347 **
3348 ** If the 3rd parameter to sqlite3_open_v2() is not one of the
3349 ** required combinations shown above optionally combined with other
3350 ** [SQLITE_OPEN_READONLY | SQLITE_OPEN_* bits]
3351 ** then the behavior is undefined.
3352 **
 
 
 
 
 
 
 
 
 
 
 
 
3353 ** ^The fourth parameter to sqlite3_open_v2() is the name of the
3354 ** [sqlite3_vfs] object that defines the operating system interface that
3355 ** the new database connection should use. ^If the fourth parameter is
3356 ** a NULL pointer then the default [sqlite3_vfs] object is used.
3357 **
@@ -3492,18 +3527,17 @@
3527 );
3528
3529 /*
3530 ** CAPI3REF: Obtain Values For URI Parameters
3531 **
3532 ** These are utility routines, useful to [VFS|custom VFS implementations],
3533 ** that check if a database file was a URI that contained a specific query
3534 ** parameter, and if so obtains the value of that query parameter.
3535 **
3536 ** If F is the database filename pointer passed into the xOpen() method of
3537 ** a VFS implementation or it is the return value of [sqlite3_db_filename()]
3538 ** and if P is the name of the query parameter, then
 
3539 ** sqlite3_uri_parameter(F,P) returns the value of the P
3540 ** parameter if it exists or a NULL pointer if P does not appear as a
3541 ** query parameter on F. If P is a query parameter of F and it
3542 ** has no explicit value, then sqlite3_uri_parameter(F,P) returns
3543 ** a pointer to an empty string.
@@ -3521,22 +3555,69 @@
3555 **
3556 ** The sqlite3_uri_int64(F,P,D) routine converts the value of P into a
3557 ** 64-bit signed integer and returns that integer, or D if P does not
3558 ** exist. If the value of P is something other than an integer, then
3559 ** zero is returned.
3560 **
3561 ** The sqlite3_uri_key(F,N) returns a pointer to the name (not
3562 ** the value) of the N-th query parameter for filename F, or a NULL
3563 ** pointer if N is less than zero or greater than the number of query
3564 ** parameters minus 1. The N value is zero-based so N should be 0 to obtain
3565 ** the name of the first query parameter, 1 for the second parameter, and
3566 ** so forth.
3567 **
3568 ** If F is a NULL pointer, then sqlite3_uri_parameter(F,P) returns NULL and
3569 ** sqlite3_uri_boolean(F,P,B) returns B. If F is not a NULL pointer and
3570 ** is not a database file pathname pointer that the SQLite core passed
3571 ** into the xOpen VFS method, then the behavior of this routine is undefined
3572 ** and probably undesirable.
3573 **
3574 ** Beginning with SQLite [version 3.31.0] ([dateof:3.31.0]) the input F
3575 ** parameter can also be the name of a rollback journal file or WAL file
3576 ** in addition to the main database file. Prior to version 3.31.0, these
3577 ** routines would only work if F was the name of the main database file.
3578 ** When the F parameter is the name of the rollback journal or WAL file,
3579 ** it has access to all the same query parameters as were found on the
3580 ** main database file.
3581 **
3582 ** See the [URI filename] documentation for additional information.
3583 */
3584 SQLITE_API const char *sqlite3_uri_parameter(const char *zFilename, const char *zParam);
3585 SQLITE_API int sqlite3_uri_boolean(const char *zFile, const char *zParam, int bDefault);
3586 SQLITE_API sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64);
3587 SQLITE_API const char *sqlite3_uri_key(const char *zFilename, int N);
3588
3589 /*
3590 ** CAPI3REF: Translate filenames
3591 **
3592 ** These routines are available to [VFS|custom VFS implementations] for
3593 ** translating filenames between the main database file, the journal file,
3594 ** and the WAL file.
3595 **
3596 ** If F is the name of an sqlite database file, journal file, or WAL file
3597 ** passed by the SQLite core into the VFS, then sqlite3_filename_database(F)
3598 ** returns the name of the corresponding database file.
3599 **
3600 ** If F is the name of an sqlite database file, journal file, or WAL file
3601 ** passed by the SQLite core into the VFS, or if F is a database filename
3602 ** obtained from [sqlite3_db_filename()], then sqlite3_filename_journal(F)
3603 ** returns the name of the corresponding rollback journal file.
3604 **
3605 ** If F is the name of an sqlite database file, journal file, or WAL file
3606 ** that was passed by the SQLite core into the VFS, or if F is a database
3607 ** filename obtained from [sqlite3_db_filename()], then
3608 ** sqlite3_filename_wal(F) returns the name of the corresponding
3609 ** WAL file.
3610 **
3611 ** In all of the above, if F is not the name of a database, journal or WAL
3612 ** filename passed into the VFS from the SQLite core and F is not the
3613 ** return value from [sqlite3_db_filename()], then the result is
3614 ** undefined and is likely a memory access violation.
3615 */
3616 SQLITE_API const char *sqlite3_filename_database(const char*);
3617 SQLITE_API const char *sqlite3_filename_journal(const char*);
3618 SQLITE_API const char *sqlite3_filename_wal(const char*);
3619
3620
3621 /*
3622 ** CAPI3REF: Error Codes And Messages
3623 ** METHOD: sqlite3
@@ -4835,12 +4916,10 @@
4916 SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
4917
4918 /*
4919 ** CAPI3REF: Create Or Redefine SQL Functions
4920 ** KEYWORDS: {function creation routines}
 
 
4921 ** METHOD: sqlite3
4922 **
4923 ** ^These functions (collectively known as "function creation routines")
4924 ** are used to add SQL functions or aggregates or to redefine the behavior
4925 ** of existing SQL functions or aggregates. The only differences between
@@ -4892,13 +4971,24 @@
4971 ** perform additional optimizations on deterministic functions, so use
4972 ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible.
4973 **
4974 ** ^The fourth parameter may also optionally include the [SQLITE_DIRECTONLY]
4975 ** flag, which if present prevents the function from being invoked from
4976 ** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
4977 ** index expressions, or the WHERE clause of partial indexes.
4978 **
4979 ** <span style="background-color:#ffff90;">
4980 ** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
4981 ** all application-defined SQL functions that do not need to be
4982 ** used inside of triggers, view, CHECK constraints, or other elements of
4983 ** the database schema. This flags is especially recommended for SQL
4984 ** functions that have side effects or reveal internal application state.
4985 ** Without this flag, an attacker might be able to modify the schema of
4986 ** a database file to include invocations of the function with parameters
4987 ** chosen by the attacker, which the application will then execute when
4988 ** the database file is opened and read.
4989 ** </span>
4990 **
4991 ** ^(The fifth parameter is an arbitrary pointer. The implementation of the
4992 ** function can gain access to this pointer using [sqlite3_user_data()].)^
4993 **
4994 ** ^The sixth, seventh and eighth parameters passed to the three
@@ -5013,46 +5103,66 @@
5103 ** These constants may be ORed together with the
5104 ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument
5105 ** to [sqlite3_create_function()], [sqlite3_create_function16()], or
5106 ** [sqlite3_create_function_v2()].
5107 **
5108 ** <dl>
5109 ** [[SQLITE_DETERMINISTIC]] <dt>SQLITE_DETERMINISTIC</dt><dd>
5110 ** The SQLITE_DETERMINISTIC flag means that the new function always gives
5111 ** the same output when the input parameters are the same.
5112 ** The [abs|abs() function] is deterministic, for example, but
5113 ** [randomblob|randomblob()] is not. Functions must
5114 ** be deterministic in order to be used in certain contexts such as
5115 ** with the WHERE clause of [partial indexes] or in [generated columns].
5116 ** SQLite might also optimize deterministic functions by factoring them
5117 ** out of inner loops.
5118 ** </dd>
5119 **
5120 ** [[SQLITE_DIRECTONLY]] <dt>SQLITE_DIRECTONLY</dt><dd>
5121 ** The SQLITE_DIRECTONLY flag means that the function may only be invoked
5122 ** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5123 ** schema structures such as [CHECK constraints], [DEFAULT clauses],
5124 ** [expression indexes], [partial indexes], or [generated columns].
5125 ** The SQLITE_DIRECTONLY flags is a security feature which is recommended
5126 ** for all [application-defined SQL functions], and especially for functions
5127 ** that have side-effects or that could potentially leak sensitive
5128 ** information.
5129 ** </dd>
5130 **
5131 ** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
5132 ** The SQLITE_INNOCUOUS flag means that the function is unlikely
5133 ** to cause problems even if misused. An innocuous function should have
5134 ** no side effects and should not depend on any values other than its
5135 ** input parameters. The [abs|abs() function] is an example of an
5136 ** innocuous function.
5137 ** The [load_extension() SQL function] is not innocuous because of its
5138 ** side effects.
5139 ** <p> SQLITE_INNOCUOUS is similar to SQLITE_DETERMINISTIC, but is not
5140 ** exactly the same. The [random|random() function] is an example of a
5141 ** function that is innocuous but not deterministic.
5142 ** <p>Some heightened security settings
5143 ** ([SQLITE_DBCONFIG_TRUSTED_SCHEMA] and [PRAGMA trusted_schema=OFF])
5144 ** disable the use of SQL functions inside views and triggers and in
5145 ** schema structures such as [CHECK constraints], [DEFAULT clauses],
5146 ** [expression indexes], [partial indexes], and [generated columns] unless
5147 ** the function is tagged with SQLITE_INNOCUOUS. Most built-in functions
5148 ** are innocuous. Developers are advised to avoid using the
5149 ** SQLITE_INNOCUOUS flag for application-defined functions unless the
5150 ** function has been carefully audited and found to be free of potentially
5151 ** security-adverse side-effects and information-leaks.
5152 ** </dd>
5153 **
5154 ** [[SQLITE_SUBTYPE]] <dt>SQLITE_SUBTYPE</dt><dd>
 
 
 
 
 
5155 ** The SQLITE_SUBTYPE flag indicates to SQLite that a function may call
5156 ** [sqlite3_value_subtype()] to inspect the sub-types of its arguments.
5157 ** Specifying this flag makes no difference for scalar or aggregate user
5158 ** functions. However, if it is not specified for a user-defined window
5159 ** function, then any sub-types belonging to arguments passed to the window
5160 ** function may be discarded before the window function is called (i.e.
5161 ** sqlite3_value_subtype() will always return 0).
5162 ** </dd>
5163 ** </dl>
5164 */
5165 #define SQLITE_DETERMINISTIC 0x000000800
5166 #define SQLITE_DIRECTONLY 0x000080000
5167 #define SQLITE_SUBTYPE 0x000100000
5168 #define SQLITE_INNOCUOUS 0x000200000
@@ -5964,10 +6074,21 @@
6074 **
6075 ** ^The filename returned by this function is the output of the
6076 ** xFullPathname method of the [VFS]. ^In other words, the filename
6077 ** will be an absolute pathname, even if the filename used
6078 ** to open the database originally was a URI or relative pathname.
6079 **
6080 ** If the filename pointer returned by this routine is not NULL, then it
6081 ** can be used as the filename input parameter to these routines:
6082 ** <ul>
6083 ** <li> [sqlite3_uri_parameter()]
6084 ** <li> [sqlite3_uri_boolean()]
6085 ** <li> [sqlite3_uri_int64()]
6086 ** <li> [sqlite3_filename_database()]
6087 ** <li> [sqlite3_filename_journal()]
6088 ** <li> [sqlite3_filename_wal()]
6089 ** </ul>
6090 */
6091 SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
6092
6093 /*
6094 ** CAPI3REF: Determine if a database is read-only
@@ -8932,10 +9053,18 @@
9053 ** silently replace the appropriate rows within the xUpdate callback and
9054 ** return SQLITE_OK. Or, if this is not possible, it may return
9055 ** SQLITE_CONSTRAINT, in which case SQLite falls back to OR ABORT
9056 ** constraint handling.
9057 ** </dd>
9058 **
9059 ** [[SQLITE_VTAB_DIRECTONLY]]<dt>SQLITE_VTAB_DIRECTONLY</dt>
9060 ** <dd>Calls of the form
9061 ** [sqlite3_vtab_config](db,SQLITE_VTAB_DIRECTONLY) from within the
9062 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
9063 ** prohibits that virtual table from being used from within triggers and
9064 ** views.
9065 ** </dd>
9066 **
9067 ** [[SQLITE_VTAB_INNOCUOUS]]<dt>SQLITE_VTAB_INNOCUOUS</dt>
9068 ** <dd>Calls of the form
9069 ** [sqlite3_vtab_config](db,SQLITE_VTAB_INNOCUOUS) from within the
9070 ** the [xConnect] or [xCreate] methods of a [virtual table] implmentation
@@ -8943,18 +9072,10 @@
9072 ** and views. Conceptually, the SQLITE_VTAB_INNOCUOUS tag means that the
9073 ** virtual table can do no serious harm even if it is controlled by a
9074 ** malicious hacker. Developers should avoid setting the SQLITE_VTAB_INNOCUOUS
9075 ** flag unless absolutely necessary.
9076 ** </dd>
 
 
 
 
 
 
 
 
9077 ** </dl>
9078 */
9079 #define SQLITE_VTAB_CONSTRAINT_SUPPORT 1
9080 #define SQLITE_VTAB_INNOCUOUS 2
9081 #define SQLITE_VTAB_DIRECTONLY 3
9082

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button