SQLite v3.36.0 (#11423)
- SQLITE_ENABLE_UPDATE_DELETE_LIMIT 1 - SQLITE_OMIT_LOAD_EXTENSION 1 - SQLITE_ENABLE_DBSTAT_VTAB 1 - Fix compilation warnings
Stelios Fragkakis committed
Aug 16, 2021 at 10:24 UTC
6bdaf0fdee567caf0c10a80e545779f4adcce989
2 files changed
+11291
-6111
database/sqlite/sqlite3.c
+11073
-6072
@@ -1,6 +1,6 @@
1
/******************************************************************************
2
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.33.0. By combining all the individual C code files into this
3
+** version 3.36.0. By combining all the individual C code files into this
4
** single large file, the entire code can be compiled as a single translation
5
** unit. This allows many compilers to do optimizations that would not be
6
** possible if the files were compiled separately. Performance improvements
@@ -23,6 +23,7 @@
23
#ifndef SQLITE_PRIVATE
24
# define SQLITE_PRIVATE static
25
#endif
26
+#define SQLITE_UDL_CAPABLE_PARSER 1
27
/************** Begin file ctime.c *******************************************/
28
/*
29
** 2010 February 23
@@ -86,8 +87,10 @@ static const char * const sqlite3azCompileOpt[] = {
87
#if SQLITE_64BIT_STATS
88
"64BIT_STATS",
89
#endif
89
-#if SQLITE_ALLOW_COVERING_INDEX_SCAN
90
- "ALLOW_COVERING_INDEX_SCAN",
90
+#ifdef SQLITE_ALLOW_COVERING_INDEX_SCAN
91
+# if SQLITE_ALLOW_COVERING_INDEX_SCAN != 1
92
+ "ALLOW_COVERING_INDEX_SCAN=" CTIMEOPT_VAL(SQLITE_ALLOW_COVERING_INDEX_SCAN),
93
+# endif
94
#endif
95
#if SQLITE_ALLOW_URI_AUTHORITY
96
"ALLOW_URI_AUTHORITY",
@@ -149,8 +152,10 @@ static const char * const sqlite3azCompileOpt[] = {
152
#ifdef SQLITE_DEFAULT_LOOKASIDE
153
"DEFAULT_LOOKASIDE=" CTIMEOPT_VAL2(SQLITE_DEFAULT_LOOKASIDE),
154
#endif
152
-#if SQLITE_DEFAULT_MEMSTATUS
153
- "DEFAULT_MEMSTATUS",
155
+#ifdef SQLITE_DEFAULT_MEMSTATUS
156
+# if SQLITE_DEFAULT_MEMSTATUS != 1
157
+ "DEFAULT_MEMSTATUS=" CTIMEOPT_VAL(SQLITE_DEFAULT_MEMSTATUS),
158
+# endif
159
#endif
160
#ifdef SQLITE_DEFAULT_MMAP_SIZE
161
"DEFAULT_MMAP_SIZE=" CTIMEOPT_VAL(SQLITE_DEFAULT_MMAP_SIZE),
@@ -224,7 +229,7 @@ static const char * const sqlite3azCompileOpt[] = {
229
#if SQLITE_ENABLE_BYTECODE_VTAB
230
"ENABLE_BYTECODE_VTAB",
231
#endif
227
-#if SQLITE_ENABLE_CEROD
232
+#ifdef SQLITE_ENABLE_CEROD
233
"ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD),
234
#endif
235
#if SQLITE_ENABLE_COLUMN_METADATA
@@ -239,17 +244,17 @@ static const char * const sqlite3azCompileOpt[] = {
244
#if SQLITE_ENABLE_CURSOR_HINTS
245
"ENABLE_CURSOR_HINTS",
246
#endif
247
+#if SQLITE_ENABLE_DBPAGE_VTAB
248
+ "ENABLE_DBPAGE_VTAB",
249
+#endif
250
#if SQLITE_ENABLE_DBSTAT_VTAB
251
"ENABLE_DBSTAT_VTAB",
252
#endif
253
#if SQLITE_ENABLE_EXPENSIVE_ASSERT
254
"ENABLE_EXPENSIVE_ASSERT",
255
#endif
248
-#if SQLITE_ENABLE_FTS1
249
- "ENABLE_FTS1",
250
-#endif
251
-#if SQLITE_ENABLE_FTS2
252
- "ENABLE_FTS2",
256
+#if SQLITE_ENABLE_EXPLAIN_COMMENTS
257
+ "ENABLE_EXPLAIN_COMMENTS",
258
#endif
259
#if SQLITE_ENABLE_FTS3
260
"ENABLE_FTS3",
@@ -287,6 +292,9 @@ static const char * const sqlite3azCompileOpt[] = {
292
#ifdef SQLITE_ENABLE_LOCKING_STYLE
293
"ENABLE_LOCKING_STYLE=" CTIMEOPT_VAL(SQLITE_ENABLE_LOCKING_STYLE),
294
#endif
295
+#if SQLITE_ENABLE_MATH_FUNCTIONS
296
+ "ENABLE_MATH_FUNCTIONS",
297
+#endif
298
#if SQLITE_ENABLE_MEMORY_MANAGEMENT
299
"ENABLE_MEMORY_MANAGEMENT",
300
#endif
@@ -305,6 +313,9 @@ static const char * const sqlite3azCompileOpt[] = {
313
#if SQLITE_ENABLE_NULL_TRIM
314
"ENABLE_NULL_TRIM",
315
#endif
316
+#if SQLITE_ENABLE_OFFSET_SQL_FUNC
317
+ "ENABLE_OFFSET_SQL_FUNC",
318
+#endif
319
#if SQLITE_ENABLE_OVERSIZE_CELL_CHECK
320
"ENABLE_OVERSIZE_CELL_CHECK",
321
#endif
@@ -335,7 +346,7 @@ static const char * const sqlite3azCompileOpt[] = {
346
#if SQLITE_ENABLE_SQLLOG
347
"ENABLE_SQLLOG",
348
#endif
338
-#if defined(SQLITE_ENABLE_STAT4)
349
+#if SQLITE_ENABLE_STAT4
350
"ENABLE_STAT4",
351
#endif
352
#if SQLITE_ENABLE_STMTVTAB
@@ -389,8 +400,10 @@ static const char * const sqlite3azCompileOpt[] = {
400
#if HAVE_ISNAN || SQLITE_HAVE_ISNAN
401
"HAVE_ISNAN",
402
#endif
392
-#if SQLITE_HOMEGROWN_RECURSIVE_MUTEX
393
- "HOMEGROWN_RECURSIVE_MUTEX",
403
+#ifdef SQLITE_HOMEGROWN_RECURSIVE_MUTEX
404
+# if SQLITE_HOMEGROWN_RECURSIVE_MUTEX != 1
405
+ "HOMEGROWN_RECURSIVE_MUTEX=" CTIMEOPT_VAL(SQLITE_HOMEGROWN_RECURSIVE_MUTEX),
406
+# endif
407
#endif
408
#if SQLITE_IGNORE_AFP_LOCK_ERRORS
409
"IGNORE_AFP_LOCK_ERRORS",
@@ -488,9 +501,6 @@ static const char * const sqlite3azCompileOpt[] = {
501
#if SQLITE_MUTEX_NOOP
502
"MUTEX_NOOP",
503
#endif
491
-#if SQLITE_MUTEX_NREF
492
- "MUTEX_NREF",
493
-#endif
504
#if SQLITE_MUTEX_OMIT
505
"MUTEX_OMIT",
506
#endif
@@ -560,7 +570,7 @@ static const char * const sqlite3azCompileOpt[] = {
570
#if SQLITE_OMIT_CTE
571
"OMIT_CTE",
572
#endif
563
-#if SQLITE_OMIT_DATETIME_FUNCS
573
+#if defined(SQLITE_OMIT_DATETIME_FUNCS) || defined(SQLITE_OMIT_FLOATING_POINT)
574
"OMIT_DATETIME_FUNCS",
575
#endif
576
#if SQLITE_OMIT_DECLTYPE
@@ -569,6 +579,9 @@ static const char * const sqlite3azCompileOpt[] = {
579
#if SQLITE_OMIT_DEPRECATED
580
"OMIT_DEPRECATED",
581
#endif
582
+#if SQLITE_OMIT_DESERIALIZE
583
+ "OMIT_DESERIALIZE",
584
+#endif
585
#if SQLITE_OMIT_DISKIO
586
"OMIT_DISKIO",
587
#endif
@@ -596,6 +609,9 @@ static const char * const sqlite3azCompileOpt[] = {
609
#if SQLITE_OMIT_INTEGRITY_CHECK
610
"OMIT_INTEGRITY_CHECK",
611
#endif
612
+#if SQLITE_OMIT_INTROSPECTION_PRAGMAS
613
+ "OMIT_INTROSPECTION_PRAGMAS",
614
+#endif
615
#if SQLITE_OMIT_LIKE_OPTIMIZATION
616
"OMIT_LIKE_OPTIMIZATION",
617
#endif
@@ -659,8 +675,10 @@ static const char * const sqlite3azCompileOpt[] = {
675
#if SQLITE_OMIT_TEST_CONTROL
676
"OMIT_TEST_CONTROL",
677
#endif
662
-#if SQLITE_OMIT_TRACE
663
- "OMIT_TRACE",
678
+#ifdef SQLITE_OMIT_TRACE
679
+# if SQLITE_OMIT_TRACE != 1
680
+ "OMIT_TRACE=" CTIMEOPT_VAL(SQLITE_OMIT_TRACE),
681
+# endif
682
#endif
683
#if SQLITE_OMIT_TRIGGER
684
"OMIT_TRIGGER",
@@ -695,8 +713,10 @@ static const char * const sqlite3azCompileOpt[] = {
713
#if SQLITE_PERFORMANCE_TRACE
714
"PERFORMANCE_TRACE",
715
#endif
698
-#if SQLITE_POWERSAFE_OVERWRITE
699
- "POWERSAFE_OVERWRITE",
716
+#ifdef SQLITE_POWERSAFE_OVERWRITE
717
+# if SQLITE_POWERSAFE_OVERWRITE != 1
718
+ "POWERSAFE_OVERWRITE=" CTIMEOPT_VAL(SQLITE_POWERSAFE_OVERWRITE),
719
+# endif
720
#endif
721
#if SQLITE_PREFER_PROXY_LOCKING
722
"PREFER_PROXY_LOCKING",
@@ -731,7 +751,10 @@ static const char * const sqlite3azCompileOpt[] = {
751
#if SQLITE_SUBSTR_COMPATIBILITY
752
"SUBSTR_COMPATIBILITY",
753
#endif
734
-#if SQLITE_SYSTEM_MALLOC
754
+#if (!defined(SQLITE_WIN32_MALLOC) \
755
+ && !defined(SQLITE_ZERO_MALLOC) \
756
+ && !defined(SQLITE_MEMDEBUG) \
757
+ ) || defined(SQLITE_SYSTEM_MALLOC)
758
"SYSTEM_MALLOC",
759
#endif
760
#if SQLITE_TCL
@@ -993,6 +1016,18 @@ SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
1016
# define MSVC_VERSION 0
1017
#endif
1018
1019
+/*
1020
+** Some C99 functions in "math.h" are only present for MSVC when its version
1021
+** is associated with Visual Studio 2013 or higher.
1022
+*/
1023
+#ifndef SQLITE_HAVE_C99_MATH_FUNCS
1024
+# if MSVC_VERSION==0 || MSVC_VERSION>=1800
1025
+# define SQLITE_HAVE_C99_MATH_FUNCS (1)
1026
+# else
1027
+# define SQLITE_HAVE_C99_MATH_FUNCS (0)
1028
+# endif
1029
+#endif
1030
+
1031
/* Needed for various definitions... */
1032
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
1033
# define _GNU_SOURCE
@@ -1174,9 +1209,9 @@ extern "C" {
1209
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1210
** [sqlite_version()] and [sqlite_source_id()].
1211
*/
1177
-#define SQLITE_VERSION "3.33.0"
1178
-#define SQLITE_VERSION_NUMBER 3033000
1179
-#define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt1"
1212
+#define SQLITE_VERSION "3.36.0"
1213
+#define SQLITE_VERSION_NUMBER 3036000
1214
+#define SQLITE_SOURCE_ID "2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5"
1215
1216
/*
1217
** CAPI3REF: Run-Time Library Version Numbers
@@ -1555,6 +1590,7 @@ SQLITE_API int sqlite3_exec(
1590
#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
1591
#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
1592
#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
1593
+#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
1594
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1595
#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
1596
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
@@ -2178,6 +2214,23 @@ struct sqlite3_io_methods {
2214
** file to the database file, but before the *-shm file is updated to
2215
** record the fact that the pages have been checkpointed.
2216
** </ul>
2217
+**
2218
+** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
2219
+** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
2220
+** whether or not there is a database client in another process with a wal-mode
2221
+** transaction open on the database or not. It is only available on unix.The
2222
+** (void*) argument passed with this file-control should be a pointer to a
2223
+** value of type (int). The integer value is set to 1 if the database is a wal
2224
+** mode database and there exists at least one client in another process that
2225
+** currently has an SQL transaction open on the database. It is set to 0 if
2226
+** the database is not a wal-mode db, or if there is no such connection in any
2227
+** other process. This opcode cannot be used to detect transactions opened
2228
+** by clients within the current process, only within other processes.
2229
+** </ul>
2230
+**
2231
+** <li>[[SQLITE_FCNTL_CKSM_FILE]]
2232
+** Used by the cksmvfs VFS module only.
2233
+** </ul>
2234
*/
2235
#define SQLITE_FCNTL_LOCKSTATE 1
2236
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
@@ -2217,6 +2270,8 @@ struct sqlite3_io_methods {
2270
#define SQLITE_FCNTL_CKPT_DONE 37
2271
#define SQLITE_FCNTL_RESERVE_BYTES 38
2272
#define SQLITE_FCNTL_CKPT_START 39
2273
+#define SQLITE_FCNTL_EXTERNAL_READER 40
2274
+#define SQLITE_FCNTL_CKSM_FILE 41
2275
2276
/* deprecated names */
2277
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
@@ -3165,7 +3220,13 @@ struct sqlite3_mem_methods {
3220
** The second parameter is a pointer to an integer into which
3221
** is written 0 or 1 to indicate whether triggers are disabled or enabled
3222
** following this call. The second parameter may be a NULL pointer, in
3168
-** which case the trigger setting is not reported back. </dd>
3223
+** which case the trigger setting is not reported back.
3224
+**
3225
+** <p>Originally this option disabled all triggers. ^(However, since
3226
+** SQLite version 3.35.0, TEMP triggers are still allowed even if
3227
+** this option is off. So, in other words, this option now only disables
3228
+** triggers in the main database schema or in the schemas of ATTACH-ed
3229
+** databases.)^ </dd>
3230
**
3231
** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
3232
** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
@@ -3176,7 +3237,13 @@ struct sqlite3_mem_methods {
3237
** The second parameter is a pointer to an integer into which
3238
** is written 0 or 1 to indicate whether views are disabled or enabled
3239
** following this call. The second parameter may be a NULL pointer, in
3179
-** which case the view setting is not reported back. </dd>
3240
+** which case the view setting is not reported back.
3241
+**
3242
+** <p>Originally this option disabled all views. ^(However, since
3243
+** SQLite version 3.35.0, TEMP views are still allowed even if
3244
+** this option is off. So, in other words, this option now only disables
3245
+** views in the main database schema or in the schemas of ATTACH-ed
3246
+** databases.)^ </dd>
3247
**
3248
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
3249
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
@@ -4549,6 +4616,7 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
4616
** that uses dot-files in place of posix advisory locking.
4617
** <tr><td> file:data.db?mode=readonly <td>
4618
** An error. "readonly" is not a valid option for the "mode" parameter.
4619
+** Use "ro" instead: "file:data.db?mode=ro".
4620
** </table>
4621
**
4622
** ^URI hexadecimal escape sequences (%HH) are supported within the path and
@@ -4747,7 +4815,7 @@ SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
4815
** If the Y parameter to sqlite3_free_filename(Y) is anything other
4816
** than a NULL pointer or a pointer previously acquired from
4817
** sqlite3_create_filename(), then bad things such as heap
4750
-** corruption or segfaults may occur. The value Y should be
4818
+** corruption or segfaults may occur. The value Y should not be
4819
** used again after sqlite3_free_filename(Y) has been called. This means
4820
** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,
4821
** then the corresponding [sqlite3_module.xClose() method should also be
@@ -5216,6 +5284,15 @@ SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
5284
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
5285
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
5286
** sqlite3_stmt_readonly() returns false for those commands.
5287
+**
5288
+** ^This routine returns false if there is any possibility that the
5289
+** statement might change the database file. ^A false return does
5290
+** not guarantee that the statement will change the database file.
5291
+** ^For example, an UPDATE statement might have a WHERE clause that
5292
+** makes it a no-op, but the sqlite3_stmt_readonly() result would still
5293
+** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
5294
+** read-only no-op if the table already exists, but
5295
+** sqlite3_stmt_readonly() still returns false for such a statement.
5296
*/
5297
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
5298
@@ -5385,18 +5462,22 @@ typedef struct sqlite3_context sqlite3_context;
5462
** contain embedded NULs. The result of expressions involving strings
5463
** with embedded NULs is undefined.
5464
**
5388
-** ^The fifth argument to the BLOB and string binding interfaces
5389
-** is a destructor used to dispose of the BLOB or
5390
-** string after SQLite has finished with it. ^The destructor is called
5391
-** to dispose of the BLOB or string even if the call to the bind API fails,
5392
-** except the destructor is not called if the third parameter is a NULL
5393
-** pointer or the fourth parameter is negative.
5394
-** ^If the fifth argument is
5395
-** the special value [SQLITE_STATIC], then SQLite assumes that the
5396
-** information is in static, unmanaged space and does not need to be freed.
5397
-** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
5398
-** SQLite makes its own private copy of the data immediately, before
5399
-** the sqlite3_bind_*() routine returns.
5465
+** ^The fifth argument to the BLOB and string binding interfaces controls
5466
+** or indicates the lifetime of the object referenced by the third parameter.
5467
+** These three options exist:
5468
+** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
5469
+** with it may be passed. ^It is called to dispose of the BLOB or string even
5470
+** if the call to the bind API fails, except the destructor is not called if
5471
+** the third parameter is a NULL pointer or the fourth parameter is negative.
5472
+** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
5473
+** the application remains responsible for disposing of the object. ^In this
5474
+** case, the object and the provided pointer to it must remain valid until
5475
+** either the prepared statement is finalized or the same SQL parameter is
5476
+** bound to something else, whichever occurs sooner.
5477
+** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
5478
+** object is to be copied prior to the return from sqlite3_bind_*(). ^The
5479
+** object and pointer to it must remain valid until then. ^SQLite will then
5480
+** manage the lifetime of its private copy.
5481
**
5482
** ^The sixth argument to sqlite3_bind_text64() must be one of
5483
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
@@ -6138,7 +6219,6 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
6219
** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
6220
** index expressions, or the WHERE clause of partial indexes.
6221
**
6141
-** <span style="background-color:#ffff90;">
6222
** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
6223
** all application-defined SQL functions that do not need to be
6224
** used inside of triggers, view, CHECK constraints, or other elements of
@@ -6148,7 +6228,6 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
6228
** a database file to include invocations of the function with parameters
6229
** chosen by the attacker, which the application will then execute when
6230
** the database file is opened and read.
6151
-** </span>
6231
**
6232
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
6233
** function can gain access to this pointer using [sqlite3_user_data()].)^
@@ -7237,6 +7316,57 @@ SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
7316
*/
7317
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
7318
7319
+/*
7320
+** CAPI3REF: Determine the transaction state of a database
7321
+** METHOD: sqlite3
7322
+**
7323
+** ^The sqlite3_txn_state(D,S) interface returns the current
7324
+** [transaction state] of schema S in database connection D. ^If S is NULL,
7325
+** then the highest transaction state of any schema on database connection D
7326
+** is returned. Transaction states are (in order of lowest to highest):
7327
+** <ol>
7328
+** <li value="0"> SQLITE_TXN_NONE
7329
+** <li value="1"> SQLITE_TXN_READ
7330
+** <li value="2"> SQLITE_TXN_WRITE
7331
+** </ol>
7332
+** ^If the S argument to sqlite3_txn_state(D,S) is not the name of
7333
+** a valid schema, then -1 is returned.
7334
+*/
7335
+SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
7336
+
7337
+/*
7338
+** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
7339
+** KEYWORDS: {transaction state}
7340
+**
7341
+** These constants define the current transaction state of a database file.
7342
+** ^The [sqlite3_txn_state(D,S)] interface returns one of these
7343
+** constants in order to describe the transaction state of schema S
7344
+** in [database connection] D.
7345
+**
7346
+** <dl>
7347
+** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
7348
+** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
7349
+** pending.</dd>
7350
+**
7351
+** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
7352
+** <dd>The SQLITE_TXN_READ state means that the database is currently
7353
+** in a read transaction. Content has been read from the database file
7354
+** but nothing in the database file has changed. The transaction state
7355
+** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
7356
+** no other conflicting concurrent write transactions. The transaction
7357
+** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
7358
+** [COMMIT].</dd>
7359
+**
7360
+** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
7361
+** <dd>The SQLITE_TXN_WRITE state means that the database is currently
7362
+** in a write transaction. Content has been written to the database file
7363
+** but has not yet committed. The transaction state will change to
7364
+** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
7365
+*/
7366
+#define SQLITE_TXN_NONE 0
7367
+#define SQLITE_TXN_READ 1
7368
+#define SQLITE_TXN_WRITE 2
7369
+
7370
/*
7371
** CAPI3REF: Find the next prepared statement
7372
** METHOD: sqlite3
@@ -8763,7 +8893,10 @@ SQLITE_API int sqlite3_test_control(int op, ...);
8893
#define SQLITE_TESTCTRL_RESULT_INTREAL 27
8894
#define SQLITE_TESTCTRL_PRNG_SEED 28
8895
#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29
8766
-#define SQLITE_TESTCTRL_LAST 29 /* Largest TESTCTRL */
8896
+#define SQLITE_TESTCTRL_SEEK_COUNT 30
8897
+#define SQLITE_TESTCTRL_TRACEFLAGS 31
8898
+#define SQLITE_TESTCTRL_TUNE 32
8899
+#define SQLITE_TESTCTRL_LAST 32 /* Largest TESTCTRL */
8900
8901
/*
8902
** CAPI3REF: SQL Keyword Checking
@@ -10243,10 +10376,11 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
10376
** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE
10377
**
10378
** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]
10246
-** method of a [virtual table], then it returns true if and only if the
10379
+** method of a [virtual table], then it might return true if the
10380
** column is being fetched as part of an UPDATE operation during which the
10248
-** column value will not change. Applications might use this to substitute
10249
-** a return value that is less expensive to compute and that the corresponding
10381
+** column value will not change. The virtual table implementation can use
10382
+** this hint as permission to substitute a return value that is less
10383
+** expensive to compute and that the corresponding
10384
** [xUpdate] method understands as a "no-change" value.
10385
**
10386
** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
@@ -10255,6 +10389,12 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
10389
** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
10390
** In that case, [sqlite3_value_nochange(X)] will return true for the
10391
** same column in the [xUpdate] method.
10392
+**
10393
+** The sqlite3_vtab_nochange() routine is an optimization. Virtual table
10394
+** implementations should continue to give a correct answer even if the
10395
+** sqlite3_vtab_nochange() interface were to always return false. In the
10396
+** current implementation, the sqlite3_vtab_nochange() interface does always
10397
+** returns false for the enhanced [UPDATE FROM] statement.
10398
*/
10399
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
10400
@@ -10396,6 +10536,7 @@ SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
10536
10537
/*
10538
** CAPI3REF: Flush caches to disk mid-transaction
10539
+** METHOD: sqlite3
10540
**
10541
** ^If a write-transaction is open on [database connection] D when the
10542
** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
@@ -10428,6 +10569,7 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
10569
10570
/*
10571
** CAPI3REF: The pre-update hook.
10572
+** METHOD: sqlite3
10573
**
10574
** ^These interfaces are only available if SQLite is compiled using the
10575
** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
@@ -10468,7 +10610,7 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
10610
** seventh parameter is the final rowid value of the row being inserted
10611
** or updated. The value of the seventh parameter passed to the callback
10612
** function is not defined for operations on WITHOUT ROWID tables, or for
10471
-** INSERT operations on rowid tables.
10613
+** DELETE operations on rowid tables.
10614
**
10615
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
10616
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
@@ -10506,6 +10648,15 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
10648
** triggers; or 2 for changes resulting from triggers called by top-level
10649
** triggers; and so forth.
10650
**
10651
+** When the [sqlite3_blob_write()] API is used to update a blob column,
10652
+** the pre-update hook is invoked with SQLITE_DELETE. This is because the
10653
+** in this case the new values are not available. In this case, when a
10654
+** callback made with op==SQLITE_DELETE is actuall a write using the
10655
+** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
10656
+** the index of the column being written. In other cases, where the
10657
+** pre-update hook is being invoked for some other reason, including a
10658
+** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
10659
+**
10660
** See also: [sqlite3_update_hook()]
10661
*/
10662
#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
@@ -10526,10 +10677,12 @@ SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
10677
SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
10678
SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
10679
SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
10680
+SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
10681
#endif
10682
10683
/*
10684
** CAPI3REF: Low-level system error code
10685
+** METHOD: sqlite3
10686
**
10687
** ^Attempt to return the underlying operating system error code or error
10688
** number that caused the most recent I/O error or failure to open a file.
@@ -10763,8 +10916,8 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const c
10916
** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
10917
** allocation error occurs.
10918
**
10766
-** This interface is only available if SQLite is compiled with the
10767
-** [SQLITE_ENABLE_DESERIALIZE] option.
10919
+** This interface is omitted if SQLite is compiled with the
10920
+** [SQLITE_OMIT_DESERIALIZE] option.
10921
*/
10922
SQLITE_API unsigned char *sqlite3_serialize(
10923
sqlite3 *db, /* The database connection */
@@ -10815,8 +10968,8 @@ SQLITE_API unsigned char *sqlite3_serialize(
10968
** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
10969
** [sqlite3_free()] is invoked on argument P prior to returning.
10970
**
10818
-** This interface is only available if SQLite is compiled with the
10819
-** [SQLITE_ENABLE_DESERIALIZE] option.
10971
+** This interface is omitted if SQLite is compiled with the
10972
+** [SQLITE_OMIT_DESERIALIZE] option.
10973
*/
10974
SQLITE_API int sqlite3_deserialize(
10975
sqlite3 *db, /* The database connection */
@@ -11065,6 +11218,38 @@ SQLITE_API int sqlite3session_create(
11218
*/
11219
SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
11220
11221
+/*
11222
+** CAPIREF: Conigure a Session Object
11223
+** METHOD: sqlite3_session
11224
+**
11225
+** This method is used to configure a session object after it has been
11226
+** created. At present the only valid value for the second parameter is
11227
+** [SQLITE_SESSION_OBJCONFIG_SIZE].
11228
+**
11229
+** Arguments for sqlite3session_object_config()
11230
+**
11231
+** The following values may passed as the the 4th parameter to
11232
+** sqlite3session_object_config().
11233
+**
11234
+** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
11235
+** This option is used to set, clear or query the flag that enables
11236
+** the [sqlite3session_changeset_size()] API. Because it imposes some
11237
+** computational overhead, this API is disabled by default. Argument
11238
+** pArg must point to a value of type (int). If the value is initially
11239
+** 0, then the sqlite3session_changeset_size() API is disabled. If it
11240
+** is greater than 0, then the same API is enabled. Or, if the initial
11241
+** value is less than zero, no change is made. In all cases the (int)
11242
+** variable is set to 1 if the sqlite3session_changeset_size() API is
11243
+** enabled following the current call, or 0 otherwise.
11244
+**
11245
+** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
11246
+** the first table has been attached to the session object.
11247
+*/
11248
+SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
11249
+
11250
+/*
11251
+*/
11252
+#define SQLITE_SESSION_OBJCONFIG_SIZE 1
11253
11254
/*
11255
** CAPI3REF: Enable Or Disable A Session Object
@@ -11309,6 +11494,22 @@ SQLITE_API int sqlite3session_changeset(
11494
void **ppChangeset /* OUT: Buffer containing changeset */
11495
);
11496
11497
+/*
11498
+** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
11499
+** METHOD: sqlite3_session
11500
+**
11501
+** By default, this function always returns 0. For it to return
11502
+** a useful result, the sqlite3_session object must have been configured
11503
+** to enable this API using sqlite3session_object_config() with the
11504
+** SQLITE_SESSION_OBJCONFIG_SIZE verb.
11505
+**
11506
+** When enabled, this function returns an upper limit, in bytes, for the size
11507
+** of the changeset that might be produced if sqlite3session_changeset() were
11508
+** called. The final changeset size might be equal to or smaller than the
11509
+** size in bytes returned by this function.
11510
+*/
11511
+SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
11512
+
11513
/*
11514
** CAPI3REF: Load The Difference Between Tables Into A Session
11515
** METHOD: sqlite3_session
@@ -11426,6 +11627,14 @@ SQLITE_API int sqlite3session_patchset(
11627
*/
11628
SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
11629
11630
+/*
11631
+** CAPI3REF: Query for the amount of heap memory used by a session object.
11632
+**
11633
+** This API returns the total amount of heap memory in bytes currently
11634
+** used by the session object passed as the only argument.
11635
+*/
11636
+SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
11637
+
11638
/*
11639
** CAPI3REF: Create An Iterator To Traverse A Changeset
11640
** CONSTRUCTOR: sqlite3_changeset_iter
@@ -11528,18 +11737,23 @@ SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
11737
** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
11738
** is not the case, this function returns [SQLITE_MISUSE].
11739
**
11531
-** If argument pzTab is not NULL, then *pzTab is set to point to a
11532
-** nul-terminated utf-8 encoded string containing the name of the table
11533
-** affected by the current change. The buffer remains valid until either
11534
-** sqlite3changeset_next() is called on the iterator or until the
11535
-** conflict-handler function returns. If pnCol is not NULL, then *pnCol is
11536
-** set to the number of columns in the table affected by the change. If
11537
-** pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
11740
+** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three
11741
+** outputs are set through these pointers:
11742
+**
11743
+** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
11744
+** depending on the type of change that the iterator currently points to;
11745
+**
11746
+** *pnCol is set to the number of columns in the table affected by the change; and
11747
+**
11748
+** *pzTab is set to point to a nul-terminated utf-8 encoded string containing
11749
+** the name of the table affected by the current change. The buffer remains
11750
+** valid until either sqlite3changeset_next() is called on the iterator
11751
+** or until the conflict-handler function returns.
11752
+**
11753
+** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
11754
** is an indirect change, or false (0) otherwise. See the documentation for
11755
** [sqlite3session_indirect()] for a description of direct and indirect
11540
-** changes. Finally, if pOp is not NULL, then *pOp is set to one of
11541
-** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the
11542
-** type of change that the iterator currently points to.
11756
+** changes.
11757
**
11758
** If no error occurs, SQLITE_OK is returned. If an error does occur, an
11759
** SQLite error code is returned. The values of the output variables may not
@@ -13300,11 +13514,7 @@ struct fts5_api {
13514
** The maximum depth of an expression tree. This is limited to
13515
** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
13516
** want to place more severe limits on the complexity of an
13303
-** expression.
13304
-**
13305
-** A value of 0 used to mean that the limit was not enforced.
13306
-** But that is no longer true. The limit is now strictly enforced
13307
-** at all times.
13517
+** expression. A value of 0 means that there is no limit.
13518
*/
13519
#ifndef SQLITE_MAX_EXPR_DEPTH
13520
# define SQLITE_MAX_EXPR_DEPTH 1000
@@ -13472,7 +13682,8 @@ struct fts5_api {
13682
#ifndef __has_extension
13683
# define __has_extension(x) 0 /* compatibility with non-clang compilers */
13684
#endif
13475
-#if GCC_VERSION>=4007000 || __has_extension(c_atomic)
13685
+#if GCC_VERSION>=4007000 || \
13686
+ (__has_extension(c_atomic) && __has_extension(c_atomic_store_n))
13687
# define AtomicLoad(PTR) __atomic_load_n((PTR),__ATOMIC_RELAXED)
13688
# define AtomicStore(PTR,VAL) __atomic_store_n((PTR),(VAL),__ATOMIC_RELAXED)
13689
#else
@@ -14039,90 +14250,93 @@ SQLITE_PRIVATE void sqlite3HashClear(Hash*);
14250
#define TK_TIES 94
14251
#define TK_GENERATED 95
14252
#define TK_ALWAYS 96
14042
-#define TK_REINDEX 97
14043
-#define TK_RENAME 98
14044
-#define TK_CTIME_KW 99
14045
-#define TK_ANY 100
14046
-#define TK_BITAND 101
14047
-#define TK_BITOR 102
14048
-#define TK_LSHIFT 103
14049
-#define TK_RSHIFT 104
14050
-#define TK_PLUS 105
14051
-#define TK_MINUS 106
14052
-#define TK_STAR 107
14053
-#define TK_SLASH 108
14054
-#define TK_REM 109
14055
-#define TK_CONCAT 110
14056
-#define TK_COLLATE 111
14057
-#define TK_BITNOT 112
14058
-#define TK_ON 113
14059
-#define TK_INDEXED 114
14060
-#define TK_STRING 115
14061
-#define TK_JOIN_KW 116
14062
-#define TK_CONSTRAINT 117
14063
-#define TK_DEFAULT 118
14064
-#define TK_NULL 119
14065
-#define TK_PRIMARY 120
14066
-#define TK_UNIQUE 121
14067
-#define TK_CHECK 122
14068
-#define TK_REFERENCES 123
14069
-#define TK_AUTOINCR 124
14070
-#define TK_INSERT 125
14071
-#define TK_DELETE 126
14072
-#define TK_UPDATE 127
14073
-#define TK_SET 128
14074
-#define TK_DEFERRABLE 129
14075
-#define TK_FOREIGN 130
14076
-#define TK_DROP 131
14077
-#define TK_UNION 132
14078
-#define TK_ALL 133
14079
-#define TK_EXCEPT 134
14080
-#define TK_INTERSECT 135
14081
-#define TK_SELECT 136
14082
-#define TK_VALUES 137
14083
-#define TK_DISTINCT 138
14084
-#define TK_DOT 139
14085
-#define TK_FROM 140
14086
-#define TK_JOIN 141
14087
-#define TK_USING 142
14088
-#define TK_ORDER 143
14089
-#define TK_GROUP 144
14090
-#define TK_HAVING 145
14091
-#define TK_LIMIT 146
14092
-#define TK_WHERE 147
14093
-#define TK_INTO 148
14094
-#define TK_NOTHING 149
14095
-#define TK_FLOAT 150
14096
-#define TK_BLOB 151
14097
-#define TK_INTEGER 152
14098
-#define TK_VARIABLE 153
14099
-#define TK_CASE 154
14100
-#define TK_WHEN 155
14101
-#define TK_THEN 156
14102
-#define TK_ELSE 157
14103
-#define TK_INDEX 158
14104
-#define TK_ALTER 159
14105
-#define TK_ADD 160
14106
-#define TK_WINDOW 161
14107
-#define TK_OVER 162
14108
-#define TK_FILTER 163
14109
-#define TK_COLUMN 164
14110
-#define TK_AGG_FUNCTION 165
14111
-#define TK_AGG_COLUMN 166
14112
-#define TK_TRUEFALSE 167
14113
-#define TK_ISNOT 168
14114
-#define TK_FUNCTION 169
14115
-#define TK_UMINUS 170
14116
-#define TK_UPLUS 171
14117
-#define TK_TRUTH 172
14118
-#define TK_REGISTER 173
14119
-#define TK_VECTOR 174
14120
-#define TK_SELECT_COLUMN 175
14121
-#define TK_IF_NULL_ROW 176
14122
-#define TK_ASTERISK 177
14123
-#define TK_SPAN 178
14124
-#define TK_SPACE 179
14125
-#define TK_ILLEGAL 180
14253
+#define TK_MATERIALIZED 97
14254
+#define TK_REINDEX 98
14255
+#define TK_RENAME 99
14256
+#define TK_CTIME_KW 100
14257
+#define TK_ANY 101
14258
+#define TK_BITAND 102
14259
+#define TK_BITOR 103
14260
+#define TK_LSHIFT 104
14261
+#define TK_RSHIFT 105
14262
+#define TK_PLUS 106
14263
+#define TK_MINUS 107
14264
+#define TK_STAR 108
14265
+#define TK_SLASH 109
14266
+#define TK_REM 110
14267
+#define TK_CONCAT 111
14268
+#define TK_COLLATE 112
14269
+#define TK_BITNOT 113
14270
+#define TK_ON 114
14271
+#define TK_INDEXED 115
14272
+#define TK_STRING 116
14273
+#define TK_JOIN_KW 117
14274
+#define TK_CONSTRAINT 118
14275
+#define TK_DEFAULT 119
14276
+#define TK_NULL 120
14277
+#define TK_PRIMARY 121
14278
+#define TK_UNIQUE 122
14279
+#define TK_CHECK 123
14280
+#define TK_REFERENCES 124
14281
+#define TK_AUTOINCR 125
14282
+#define TK_INSERT 126
14283
+#define TK_DELETE 127
14284
+#define TK_UPDATE 128
14285
+#define TK_SET 129
14286
+#define TK_DEFERRABLE 130
14287
+#define TK_FOREIGN 131
14288
+#define TK_DROP 132
14289
+#define TK_UNION 133
14290
+#define TK_ALL 134
14291
+#define TK_EXCEPT 135
14292
+#define TK_INTERSECT 136
14293
+#define TK_SELECT 137
14294
+#define TK_VALUES 138
14295
+#define TK_DISTINCT 139
14296
+#define TK_DOT 140
14297
+#define TK_FROM 141
14298
+#define TK_JOIN 142
14299
+#define TK_USING 143
14300
+#define TK_ORDER 144
14301
+#define TK_GROUP 145
14302
+#define TK_HAVING 146
14303
+#define TK_LIMIT 147
14304
+#define TK_WHERE 148
14305
+#define TK_RETURNING 149
14306
+#define TK_INTO 150
14307
+#define TK_NOTHING 151
14308
+#define TK_FLOAT 152
14309
+#define TK_BLOB 153
14310
+#define TK_INTEGER 154
14311
+#define TK_VARIABLE 155
14312
+#define TK_CASE 156
14313
+#define TK_WHEN 157
14314
+#define TK_THEN 158
14315
+#define TK_ELSE 159
14316
+#define TK_INDEX 160
14317
+#define TK_ALTER 161
14318
+#define TK_ADD 162
14319
+#define TK_WINDOW 163
14320
+#define TK_OVER 164
14321
+#define TK_FILTER 165
14322
+#define TK_COLUMN 166
14323
+#define TK_AGG_FUNCTION 167
14324
+#define TK_AGG_COLUMN 168
14325
+#define TK_TRUEFALSE 169
14326
+#define TK_ISNOT 170
14327
+#define TK_FUNCTION 171
14328
+#define TK_UMINUS 172
14329
+#define TK_UPLUS 173
14330
+#define TK_TRUTH 174
14331
+#define TK_REGISTER 175
14332
+#define TK_VECTOR 176
14333
+#define TK_SELECT_COLUMN 177
14334
+#define TK_IF_NULL_ROW 178
14335
+#define TK_ASTERISK 179
14336
+#define TK_SPAN 180
14337
+#define TK_ERROR 181
14338
+#define TK_SPACE 182
14339
+#define TK_ILLEGAL 183
14340
14341
/************** End of parse.h ***********************************************/
14342
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -14538,15 +14752,14 @@ typedef INT16_TYPE LogEst;
14752
** SELECTTRACE_ENABLED will be either 1 or 0 depending on whether or not
14753
** the Select query generator tracing logic is turned on.
14754
*/
14541
-#if defined(SQLITE_ENABLE_SELECTTRACE)
14542
-# define SELECTTRACE_ENABLED 1
14543
-#else
14544
-# define SELECTTRACE_ENABLED 0
14755
+#if !defined(SQLITE_AMALGAMATION)
14756
+SQLITE_PRIVATE u32 sqlite3SelectTrace;
14757
#endif
14546
-#if defined(SQLITE_ENABLE_SELECTTRACE)
14758
+#if defined(SQLITE_DEBUG) \
14759
+ && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_SELECTTRACE))
14760
# define SELECTTRACE_ENABLED 1
14761
# define SELECTTRACE(K,P,S,X) \
14549
- if(sqlite3_unsupported_selecttrace&(K)) \
14762
+ if(sqlite3SelectTrace&(K)) \
14763
sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
14764
sqlite3DebugPrintf X
14765
#else
@@ -14554,6 +14767,19 @@ typedef INT16_TYPE LogEst;
14767
# define SELECTTRACE_ENABLED 0
14768
#endif
14769
14770
+/*
14771
+** Macros for "wheretrace"
14772
+*/
14773
+SQLITE_PRIVATE u32 sqlite3WhereTrace;
14774
+#if defined(SQLITE_DEBUG) \
14775
+ && (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_WHERETRACE))
14776
+# define WHERETRACE(K,X) if(sqlite3WhereTrace&(K)) sqlite3DebugPrintf X
14777
+# define WHERETRACE_ENABLED 1
14778
+#else
14779
+# define WHERETRACE(K,X)
14780
+#endif
14781
+
14782
+
14783
/*
14784
** An instance of the following structure is used to store the busy-handler
14785
** callback for a given sqlite handle.
@@ -14665,7 +14891,10 @@ typedef struct AutoincInfo AutoincInfo;
14891
typedef struct Bitvec Bitvec;
14892
typedef struct CollSeq CollSeq;
14893
typedef struct Column Column;
14894
+typedef struct Cte Cte;
14895
+typedef struct CteUse CteUse;
14896
typedef struct Db Db;
14897
+typedef struct DbFixer DbFixer;
14898
typedef struct Schema Schema;
14899
typedef struct Expr Expr;
14900
typedef struct ExprList ExprList;
@@ -14683,14 +14912,17 @@ typedef struct LookasideSlot LookasideSlot;
14912
typedef struct Module Module;
14913
typedef struct NameContext NameContext;
14914
typedef struct Parse Parse;
14915
+typedef struct ParseCleanup ParseCleanup;
14916
typedef struct PreUpdate PreUpdate;
14917
typedef struct PrintfArguments PrintfArguments;
14918
typedef struct RenameToken RenameToken;
14919
+typedef struct Returning Returning;
14920
typedef struct RowSet RowSet;
14921
typedef struct Savepoint Savepoint;
14922
typedef struct Select Select;
14923
typedef struct SQLiteThread SQLiteThread;
14924
typedef struct SelectDest SelectDest;
14925
+typedef struct SrcItem SrcItem;
14926
typedef struct SrcList SrcList;
14927
typedef struct sqlite3_str StrAccum; /* Internal alias for sqlite3_str */
14928
typedef struct Table Table;
@@ -15085,16 +15317,24 @@ SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
15317
SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
15318
SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
15319
SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, Pgno*, int flags);
15088
-SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree*);
15089
-SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree*);
15320
+SQLITE_PRIVATE int sqlite3BtreeTxnState(Btree*);
15321
SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree*);
15322
+
15323
SQLITE_PRIVATE void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
15324
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *pBtree);
15325
#ifndef SQLITE_OMIT_SHARED_CACHE
15326
SQLITE_PRIVATE int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
15327
#endif
15328
+
15329
+/* Savepoints are named, nestable SQL transactions mostly implemented */
15330
+/* in vdbe.c and pager.c See https://sqlite.org/lang_savepoint.html */
15331
SQLITE_PRIVATE int sqlite3BtreeSavepoint(Btree *, int, int);
15332
15333
+/* "Checkpoint" only refers to WAL. See https://sqlite.org/wal.html#ckpt */
15334
+#ifndef SQLITE_OMIT_WAL
15335
+SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
15336
+#endif
15337
+
15338
SQLITE_PRIVATE const char *sqlite3BtreeGetFilename(Btree *);
15339
SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *);
15340
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *, Btree *);
@@ -15254,6 +15494,7 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor*, u8 flags);
15494
#define BTREE_SAVEPOSITION 0x02 /* Leave cursor pointing at NEXT or PREV */
15495
#define BTREE_AUXDELETE 0x04 /* not the primary delete operation */
15496
#define BTREE_APPEND 0x08 /* Insert is likely an append */
15497
+#define BTREE_PREFORMAT 0x80 /* Inserted data is a preformated cell */
15498
15499
/* An instance of the BtreePayload object describes the content of a single
15500
** entry in either an index or table btree.
@@ -15331,6 +15572,12 @@ SQLITE_PRIVATE int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask);
15572
SQLITE_PRIVATE int sqlite3BtreeIsReadonly(Btree *pBt);
15573
SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
15574
15575
+#ifdef SQLITE_DEBUG
15576
+SQLITE_PRIVATE sqlite3_uint64 sqlite3BtreeSeekCount(Btree*);
15577
+#else
15578
+# define sqlite3BtreeSeekCount(X) 0
15579
+#endif
15580
+
15581
#ifndef NDEBUG
15582
SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
15583
#endif
@@ -15347,6 +15594,8 @@ SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*);
15594
SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
15595
#endif
15596
15597
+SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor*, BtCursor*, i64);
15598
+
15599
/*
15600
** If we are not using shared cache, then there is no need to
15601
** use mutexes to access the BtShared structures. So make the
@@ -15624,7 +15873,7 @@ typedef struct VdbeOpList VdbeOpList;
15873
#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
15874
#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
15875
#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
15627
-#define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
15876
+#define OP_ElseEq 58 /* jump, same as TK_ESCAPE */
15877
#define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
15878
#define OP_IncrVacuum 60 /* jump */
15879
#define OP_VNext 61 /* jump */
@@ -15646,102 +15895,106 @@ typedef struct VdbeOpList VdbeOpList;
15895
#define OP_Copy 77 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
15896
#define OP_SCopy 78 /* synopsis: r[P2]=r[P1] */
15897
#define OP_IntCopy 79 /* synopsis: r[P2]=r[P1] */
15649
-#define OP_ResultRow 80 /* synopsis: output=r[P1@P2] */
15650
-#define OP_CollSeq 81
15651
-#define OP_AddImm 82 /* synopsis: r[P1]=r[P1]+P2 */
15652
-#define OP_RealAffinity 83
15653
-#define OP_Cast 84 /* synopsis: affinity(r[P1]) */
15654
-#define OP_Permutation 85
15655
-#define OP_Compare 86 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15656
-#define OP_IsTrue 87 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15657
-#define OP_Offset 88 /* synopsis: r[P3] = sqlite_offset(P1) */
15658
-#define OP_Column 89 /* synopsis: r[P3]=PX */
15659
-#define OP_Affinity 90 /* synopsis: affinity(r[P1@P2]) */
15660
-#define OP_MakeRecord 91 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15661
-#define OP_Count 92 /* synopsis: r[P2]=count() */
15662
-#define OP_ReadCookie 93
15663
-#define OP_SetCookie 94
15664
-#define OP_ReopenIdx 95 /* synopsis: root=P2 iDb=P3 */
15665
-#define OP_OpenRead 96 /* synopsis: root=P2 iDb=P3 */
15666
-#define OP_OpenWrite 97 /* synopsis: root=P2 iDb=P3 */
15667
-#define OP_OpenDup 98
15668
-#define OP_OpenAutoindex 99 /* synopsis: nColumn=P2 */
15669
-#define OP_OpenEphemeral 100 /* synopsis: nColumn=P2 */
15670
-#define OP_BitAnd 101 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15671
-#define OP_BitOr 102 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15672
-#define OP_ShiftLeft 103 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
15673
-#define OP_ShiftRight 104 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
15674
-#define OP_Add 105 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
15675
-#define OP_Subtract 106 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
15676
-#define OP_Multiply 107 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
15677
-#define OP_Divide 108 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15678
-#define OP_Remainder 109 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15679
-#define OP_Concat 110 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15680
-#define OP_SorterOpen 111
15681
-#define OP_BitNot 112 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15682
-#define OP_SequenceTest 113 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15683
-#define OP_OpenPseudo 114 /* synopsis: P3 columns in r[P2] */
15684
-#define OP_String8 115 /* same as TK_STRING, synopsis: r[P2]='P4' */
15685
-#define OP_Close 116
15686
-#define OP_ColumnsUsed 117
15687
-#define OP_SeekHit 118 /* synopsis: seekHit=P2 */
15688
-#define OP_Sequence 119 /* synopsis: r[P2]=cursor[P1].ctr++ */
15689
-#define OP_NewRowid 120 /* synopsis: r[P2]=rowid */
15690
-#define OP_Insert 121 /* synopsis: intkey=r[P3] data=r[P2] */
15691
-#define OP_Delete 122
15692
-#define OP_ResetCount 123
15693
-#define OP_SorterCompare 124 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15694
-#define OP_SorterData 125 /* synopsis: r[P2]=data */
15695
-#define OP_RowData 126 /* synopsis: r[P2]=data */
15696
-#define OP_Rowid 127 /* synopsis: r[P2]=rowid */
15697
-#define OP_NullRow 128
15698
-#define OP_SeekEnd 129
15699
-#define OP_IdxInsert 130 /* synopsis: key=r[P2] */
15700
-#define OP_SorterInsert 131 /* synopsis: key=r[P2] */
15701
-#define OP_IdxDelete 132 /* synopsis: key=r[P2@P3] */
15702
-#define OP_DeferredSeek 133 /* synopsis: Move P3 to P1.rowid if needed */
15703
-#define OP_IdxRowid 134 /* synopsis: r[P2]=rowid */
15704
-#define OP_FinishSeek 135
15705
-#define OP_Destroy 136
15706
-#define OP_Clear 137
15707
-#define OP_ResetSorter 138
15708
-#define OP_CreateBtree 139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15709
-#define OP_SqlExec 140
15710
-#define OP_ParseSchema 141
15711
-#define OP_LoadAnalysis 142
15712
-#define OP_DropTable 143
15713
-#define OP_DropIndex 144
15714
-#define OP_DropTrigger 145
15715
-#define OP_IntegrityCk 146
15716
-#define OP_RowSetAdd 147 /* synopsis: rowset(P1)=r[P2] */
15717
-#define OP_Param 148
15718
-#define OP_FkCounter 149 /* synopsis: fkctr[P1]+=P2 */
15719
-#define OP_Real 150 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15720
-#define OP_MemMax 151 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15721
-#define OP_OffsetLimit 152 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15722
-#define OP_AggInverse 153 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15723
-#define OP_AggStep 154 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15724
-#define OP_AggStep1 155 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15725
-#define OP_AggValue 156 /* synopsis: r[P3]=value N=P2 */
15726
-#define OP_AggFinal 157 /* synopsis: accum=r[P1] N=P2 */
15727
-#define OP_Expire 158
15728
-#define OP_CursorLock 159
15729
-#define OP_CursorUnlock 160
15730
-#define OP_TableLock 161 /* synopsis: iDb=P1 root=P2 write=P3 */
15731
-#define OP_VBegin 162
15732
-#define OP_VCreate 163
15733
-#define OP_VDestroy 164
15734
-#define OP_VOpen 165
15735
-#define OP_VColumn 166 /* synopsis: r[P3]=vcolumn(P2) */
15736
-#define OP_VRename 167
15737
-#define OP_Pagecount 168
15738
-#define OP_MaxPgcnt 169
15739
-#define OP_Trace 170
15740
-#define OP_CursorHint 171
15741
-#define OP_ReleaseReg 172 /* synopsis: release r[P1@P2] mask P3 */
15742
-#define OP_Noop 173
15743
-#define OP_Explain 174
15744
-#define OP_Abortable 175
15898
+#define OP_ChngCntRow 80 /* synopsis: output=r[P1] */
15899
+#define OP_ResultRow 81 /* synopsis: output=r[P1@P2] */
15900
+#define OP_CollSeq 82
15901
+#define OP_AddImm 83 /* synopsis: r[P1]=r[P1]+P2 */
15902
+#define OP_RealAffinity 84
15903
+#define OP_Cast 85 /* synopsis: affinity(r[P1]) */
15904
+#define OP_Permutation 86
15905
+#define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */
15906
+#define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
15907
+#define OP_ZeroOrNull 89 /* synopsis: r[P2] = 0 OR NULL */
15908
+#define OP_Offset 90 /* synopsis: r[P3] = sqlite_offset(P1) */
15909
+#define OP_Column 91 /* synopsis: r[P3]=PX */
15910
+#define OP_Affinity 92 /* synopsis: affinity(r[P1@P2]) */
15911
+#define OP_MakeRecord 93 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
15912
+#define OP_Count 94 /* synopsis: r[P2]=count() */
15913
+#define OP_ReadCookie 95
15914
+#define OP_SetCookie 96
15915
+#define OP_ReopenIdx 97 /* synopsis: root=P2 iDb=P3 */
15916
+#define OP_OpenRead 98 /* synopsis: root=P2 iDb=P3 */
15917
+#define OP_OpenWrite 99 /* synopsis: root=P2 iDb=P3 */
15918
+#define OP_OpenDup 100
15919
+#define OP_OpenAutoindex 101 /* synopsis: nColumn=P2 */
15920
+#define OP_BitAnd 102 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
15921
+#define OP_BitOr 103 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
15922
+#define OP_ShiftLeft 104 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
15923
+#define OP_ShiftRight 105 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
15924
+#define OP_Add 106 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
15925
+#define OP_Subtract 107 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
15926
+#define OP_Multiply 108 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
15927
+#define OP_Divide 109 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
15928
+#define OP_Remainder 110 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
15929
+#define OP_Concat 111 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
15930
+#define OP_OpenEphemeral 112 /* synopsis: nColumn=P2 */
15931
+#define OP_BitNot 113 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
15932
+#define OP_SorterOpen 114
15933
+#define OP_SequenceTest 115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
15934
+#define OP_String8 116 /* same as TK_STRING, synopsis: r[P2]='P4' */
15935
+#define OP_OpenPseudo 117 /* synopsis: P3 columns in r[P2] */
15936
+#define OP_Close 118
15937
+#define OP_ColumnsUsed 119
15938
+#define OP_SeekScan 120 /* synopsis: Scan-ahead up to P1 rows */
15939
+#define OP_SeekHit 121 /* synopsis: set P2<=seekHit<=P3 */
15940
+#define OP_Sequence 122 /* synopsis: r[P2]=cursor[P1].ctr++ */
15941
+#define OP_NewRowid 123 /* synopsis: r[P2]=rowid */
15942
+#define OP_Insert 124 /* synopsis: intkey=r[P3] data=r[P2] */
15943
+#define OP_RowCell 125
15944
+#define OP_Delete 126
15945
+#define OP_ResetCount 127
15946
+#define OP_SorterCompare 128 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
15947
+#define OP_SorterData 129 /* synopsis: r[P2]=data */
15948
+#define OP_RowData 130 /* synopsis: r[P2]=data */
15949
+#define OP_Rowid 131 /* synopsis: r[P2]=rowid */
15950
+#define OP_NullRow 132
15951
+#define OP_SeekEnd 133
15952
+#define OP_IdxInsert 134 /* synopsis: key=r[P2] */
15953
+#define OP_SorterInsert 135 /* synopsis: key=r[P2] */
15954
+#define OP_IdxDelete 136 /* synopsis: key=r[P2@P3] */
15955
+#define OP_DeferredSeek 137 /* synopsis: Move P3 to P1.rowid if needed */
15956
+#define OP_IdxRowid 138 /* synopsis: r[P2]=rowid */
15957
+#define OP_FinishSeek 139
15958
+#define OP_Destroy 140
15959
+#define OP_Clear 141
15960
+#define OP_ResetSorter 142
15961
+#define OP_CreateBtree 143 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
15962
+#define OP_SqlExec 144
15963
+#define OP_ParseSchema 145
15964
+#define OP_LoadAnalysis 146
15965
+#define OP_DropTable 147
15966
+#define OP_DropIndex 148
15967
+#define OP_DropTrigger 149
15968
+#define OP_IntegrityCk 150
15969
+#define OP_RowSetAdd 151 /* synopsis: rowset(P1)=r[P2] */
15970
+#define OP_Real 152 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
15971
+#define OP_Param 153
15972
+#define OP_FkCounter 154 /* synopsis: fkctr[P1]+=P2 */
15973
+#define OP_MemMax 155 /* synopsis: r[P1]=max(r[P1],r[P2]) */
15974
+#define OP_OffsetLimit 156 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
15975
+#define OP_AggInverse 157 /* synopsis: accum=r[P3] inverse(r[P2@P5]) */
15976
+#define OP_AggStep 158 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15977
+#define OP_AggStep1 159 /* synopsis: accum=r[P3] step(r[P2@P5]) */
15978
+#define OP_AggValue 160 /* synopsis: r[P3]=value N=P2 */
15979
+#define OP_AggFinal 161 /* synopsis: accum=r[P1] N=P2 */
15980
+#define OP_Expire 162
15981
+#define OP_CursorLock 163
15982
+#define OP_CursorUnlock 164
15983
+#define OP_TableLock 165 /* synopsis: iDb=P1 root=P2 write=P3 */
15984
+#define OP_VBegin 166
15985
+#define OP_VCreate 167
15986
+#define OP_VDestroy 168
15987
+#define OP_VOpen 169
15988
+#define OP_VColumn 170 /* synopsis: r[P3]=vcolumn(P2) */
15989
+#define OP_VRename 171
15990
+#define OP_Pagecount 172
15991
+#define OP_MaxPgcnt 173
15992
+#define OP_Trace 174
15993
+#define OP_CursorHint 175
15994
+#define OP_ReleaseReg 176 /* synopsis: release r[P1@P2] mask P3 */
15995
+#define OP_Noop 177
15996
+#define OP_Explain 178
15997
+#define OP_Abortable 179
15998
15999
/* Properties such as "out2" or "jump" that are specified in
16000
** comments following the "case" for each opcode in the vdbe.c
@@ -15764,21 +16017,21 @@ typedef struct VdbeOpList VdbeOpList;
16017
/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00,\
16018
/* 64 */ 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
16019
/* 72 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
15767
-/* 80 */ 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x12,\
15768
-/* 88 */ 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
15769
-/* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26, 0x26,\
15770
-/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
15771
-/* 112 */ 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10,\
15772
-/* 120 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
15773
-/* 128 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
15774
-/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15775
-/* 144 */ 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x10, 0x04,\
15776
-/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
16020
+/* 80 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
16021
+/* 88 */ 0x12, 0x1e, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10,\
16022
+/* 96 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x26,\
16023
+/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
16024
+/* 112 */ 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,\
16025
+/* 120 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
16026
+/* 128 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\
16027
+/* 136 */ 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10,\
16028
+/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
16029
+/* 152 */ 0x10, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00,\
16030
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15778
-/* 168 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15779
-}
16031
+/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
16032
+/* 176 */ 0x00, 0x00, 0x00, 0x00,}
16033
15781
-/* The sqlite3P2Values() routine is able to run faster if it knows
16034
+/* The resolve3P2Values() routine is able to run faster if it knows
16035
** the value of the largest JUMP opcode. The smaller the maximum
16036
** JUMP opcode the better, so the mkopcodeh.tcl script that
16037
** generated this include file strives to group all JUMP opcodes
@@ -15844,7 +16097,7 @@ SQLITE_PRIVATE void sqlite3ExplainBreakpoint(const char*,const char*);
16097
#else
16098
# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
16099
#endif
15847
-SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
16100
+SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*, int, char*, u16);
16101
SQLITE_PRIVATE void sqlite3VdbeChangeOpcode(Vdbe*, int addr, u8);
16102
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, int addr, int P1);
16103
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, int addr, int P2);
@@ -16311,6 +16564,12 @@ SQLITE_PRIVATE int sqlite3PCacheIsDirty(PCache *pCache);
16564
# define SET_FULLSYNC(x,y)
16565
#endif
16566
16567
+/* Maximum pathname length. Note: FILENAME_MAX defined by stdio.h
16568
+*/
16569
+#ifndef SQLITE_MAX_PATHLEN
16570
+# define SQLITE_MAX_PATHLEN FILENAME_MAX
16571
+#endif
16572
+
16573
/*
16574
** The default size of a disk sector
16575
*/
@@ -16816,6 +17075,11 @@ SQLITE_PRIVATE void sqlite3CryptFunc(sqlite3_context*,int,sqlite3_value**);
17075
#endif /* SQLITE_OMIT_DEPRECATED */
17076
#define SQLITE_TRACE_NONLEGACY_MASK 0x0f /* Normal flags */
17077
17078
+/*
17079
+** Maximum number of sqlite3.aDb[] entries. This is the number of attached
17080
+** databases plus 2 for "main" and "temp".
17081
+*/
17082
+#define SQLITE_MAX_DB (SQLITE_MAX_ATTACHED+2)
17083
17084
/*
17085
** Each database connection is an instance of the following structure.
@@ -16836,7 +17100,7 @@ struct sqlite3 {
17100
int errCode; /* Most recent error code (SQLITE_*) */
17101
int errMask; /* & result codes with this before returning */
17102
int iSysErrno; /* Errno value from last system error */
16839
- u16 dbOptFlags; /* Flags to enable/disable optimizations */
17103
+ u32 dbOptFlags; /* Flags to enable/disable optimizations */
17104
u8 enc; /* Text encoding */
17105
u8 autoCommit; /* The auto-commit flag. */
17106
u8 temp_store; /* 1: file 2: memory 0: default */
@@ -17043,24 +17307,26 @@ struct sqlite3 {
17307
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
17308
** selectively disable various optimizations.
17309
*/
17046
-#define SQLITE_QueryFlattener 0x0001 /* Query flattening */
17047
-#define SQLITE_WindowFunc 0x0002 /* Use xInverse for window functions */
17048
-#define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
17049
-#define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
17050
-#define SQLITE_DistinctOpt 0x0010 /* DISTINCT using indexes */
17051
-#define SQLITE_CoverIdxScan 0x0020 /* Covering index scans */
17052
-#define SQLITE_OrderByIdxJoin 0x0040 /* ORDER BY of joins via index */
17053
-#define SQLITE_Transitive 0x0080 /* Transitive constraints */
17054
-#define SQLITE_OmitNoopJoin 0x0100 /* Omit unused tables in joins */
17055
-#define SQLITE_CountOfView 0x0200 /* The count-of-view optimization */
17056
-#define SQLITE_CursorHints 0x0400 /* Add OP_CursorHint opcodes */
17057
-#define SQLITE_Stat4 0x0800 /* Use STAT4 data */
17058
- /* TH3 expects the Stat4 ^^^^^^ value to be 0x0800. Don't change it */
17059
-#define SQLITE_PushDown 0x1000 /* The push-down optimization */
17060
-#define SQLITE_SimplifyJoin 0x2000 /* Convert LEFT JOIN to JOIN */
17061
-#define SQLITE_SkipScan 0x4000 /* Skip-scans */
17062
-#define SQLITE_PropagateConst 0x8000 /* The constant propagation opt */
17063
-#define SQLITE_AllOpts 0xffff /* All optimizations */
17310
+#define SQLITE_QueryFlattener 0x00000001 /* Query flattening */
17311
+#define SQLITE_WindowFunc 0x00000002 /* Use xInverse for window functions */
17312
+#define SQLITE_GroupByOrder 0x00000004 /* GROUPBY cover of ORDERBY */
17313
+#define SQLITE_FactorOutConst 0x00000008 /* Constant factoring */
17314
+#define SQLITE_DistinctOpt 0x00000010 /* DISTINCT using indexes */
17315
+#define SQLITE_CoverIdxScan 0x00000020 /* Covering index scans */
17316
+#define SQLITE_OrderByIdxJoin 0x00000040 /* ORDER BY of joins via index */
17317
+#define SQLITE_Transitive 0x00000080 /* Transitive constraints */
17318
+#define SQLITE_OmitNoopJoin 0x00000100 /* Omit unused tables in joins */
17319
+#define SQLITE_CountOfView 0x00000200 /* The count-of-view optimization */
17320
+#define SQLITE_CursorHints 0x00000400 /* Add OP_CursorHint opcodes */
17321
+#define SQLITE_Stat4 0x00000800 /* Use STAT4 data */
17322
+ /* TH3 expects this value ^^^^^^^^^^ to be 0x0000800. Don't change it */
17323
+#define SQLITE_PushDown 0x00001000 /* The push-down optimization */
17324
+#define SQLITE_SimplifyJoin 0x00002000 /* Convert LEFT JOIN to JOIN */
17325
+#define SQLITE_SkipScan 0x00004000 /* Skip-scans */
17326
+#define SQLITE_PropagateConst 0x00008000 /* The constant propagation opt */
17327
+#define SQLITE_MinMaxOpt 0x00010000 /* The min/max optimization */
17328
+#define SQLITE_SeekScan 0x00020000 /* The OP_SeekScan optimization */
17329
+#define SQLITE_AllOpts 0xffffffff /* All optimizations */
17330
17331
/*
17332
** Macros for testing whether or not optimizations are enabled or disabled.
@@ -17216,6 +17482,9 @@ struct FuncDestructor {
17482
** a single query. The iArg is ignored. The user-data is always set
17483
** to a NULL pointer. The bNC parameter is not used.
17484
**
17485
+** MFUNCTION(zName, nArg, xPtr, xFunc)
17486
+** For math-library functions. xPtr is an arbitrary pointer.
17487
+**
17488
** PURE_DATE(zName, nArg, iArg, bNC, xFunc)
17489
** Used for "pure" date/time functions, this macro is like DFUNCTION
17490
** except that it does set the SQLITE_FUNC_CONSTANT flags. iArg is
@@ -17251,6 +17520,9 @@ struct FuncDestructor {
17520
#define SFUNCTION(zName, nArg, iArg, bNC, xFunc) \
17521
{nArg, SQLITE_UTF8|SQLITE_DIRECTONLY|SQLITE_FUNC_UNSAFE, \
17522
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
17523
+#define MFUNCTION(zName, nArg, xPtr, xFunc) \
17524
+ {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
17525
+ xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
17526
#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
17527
{nArg, SQLITE_UTF8|SQLITE_FUNC_INLINE|SQLITE_FUNC_CONSTANT|(mFlags), \
17528
SQLITE_INT_TO_PTR(iArg), 0, noopFunc, 0, 0, 0, #zName, {0} }
@@ -17345,7 +17617,12 @@ struct Column {
17617
u16 colFlags; /* Boolean properties. See COLFLAG_ defines below */
17618
};
17619
17348
-/* Allowed values for Column.colFlags:
17620
+/* Allowed values for Column.colFlags.
17621
+**
17622
+** Constraints:
17623
+** TF_HasVirtual == COLFLAG_VIRTUAL
17624
+** TF_HasStored == COLFLAG_STORED
17625
+** TF_HasHidden == COLFLAG_HIDDEN
17626
*/
17627
#define COLFLAG_PRIMKEY 0x0001 /* Column is part of the primary key */
17628
#define COLFLAG_HIDDEN 0x0002 /* A hidden column in a virtual table */
@@ -17421,9 +17698,7 @@ struct CollSeq {
17698
** operator is NULL. It is added to certain comparison operators to
17699
** prove that the operands are always NOT NULL.
17700
*/
17424
-#define SQLITE_KEEPNULL 0x08 /* Used by vector == or <> */
17701
#define SQLITE_JUMPIFNULL 0x10 /* jumps if either operand is NULL */
17426
-#define SQLITE_STOREP2 0x20 /* Store result in reg[P2] rather than jump */
17702
#define SQLITE_NULLEQ 0x80 /* NULL=NULL */
17703
#define SQLITE_NOTNULL 0x90 /* Assert that operands are never NULL */
17704
@@ -17521,7 +17796,6 @@ struct Table {
17796
#endif
17797
Trigger *pTrigger; /* List of triggers stored in pSchema */
17798
Schema *pSchema; /* Schema that contains this table */
17524
- Table *pNextZombie; /* Next on the Parse.pZombieTab list */
17799
};
17800
17801
/*
@@ -17535,11 +17809,12 @@ struct Table {
17809
**
17810
** Constraints:
17811
**
17538
-** TF_HasVirtual == COLFLAG_Virtual
17539
-** TF_HasStored == COLFLAG_Stored
17812
+** TF_HasVirtual == COLFLAG_VIRTUAL
17813
+** TF_HasStored == COLFLAG_STORED
17814
+** TF_HasHidden == COLFLAG_HIDDEN
17815
*/
17816
#define TF_Readonly 0x0001 /* Read-only system table */
17542
-#define TF_Ephemeral 0x0002 /* An ephemeral table */
17817
+#define TF_HasHidden 0x0002 /* Has one or more hidden columns */
17818
#define TF_HasPrimaryKey 0x0004 /* Table has a primary key */
17819
#define TF_Autoincrement 0x0008 /* Integer primary key is autoincrement */
17820
#define TF_HasStat1 0x0010 /* nRowLogEst set from sqlite_stat1 */
@@ -17553,6 +17828,9 @@ struct Table {
17828
#define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */
17829
#define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */
17830
#define TF_Shadow 0x1000 /* True for a shadow table */
17831
+#define TF_HasStat4 0x2000 /* STAT4 info available for this table */
17832
+#define TF_Ephemeral 0x4000 /* An ephemeral table */
17833
+#define TF_Eponymous 0x8000 /* An eponymous virtual table */
17834
17835
/*
17836
** Test to see whether or not a table is a virtual table. This is
@@ -17649,16 +17927,22 @@ struct FKey {
17927
** is returned. REPLACE means that preexisting database rows that caused
17928
** a UNIQUE constraint violation are removed so that the new insert or
17929
** update can proceed. Processing continues and no error is reported.
17930
+** UPDATE applies to insert operations only and means that the insert
17931
+** is omitted and the DO UPDATE clause of an upsert is run instead.
17932
**
17653
-** RESTRICT, SETNULL, and CASCADE actions apply only to foreign keys.
17933
+** RESTRICT, SETNULL, SETDFLT, and CASCADE actions apply only to foreign keys.
17934
** RESTRICT is the same as ABORT for IMMEDIATE foreign keys and the
17935
** same as ROLLBACK for DEFERRED keys. SETNULL means that the foreign
17656
-** key is set to NULL. CASCADE means that a DELETE or UPDATE of the
17936
+** key is set to NULL. SETDFLT means that the foreign key is set
17937
+** to its default value. CASCADE means that a DELETE or UPDATE of the
17938
** referenced table row is propagated into the row that holds the
17939
** foreign key.
17940
**
17941
+** The OE_Default value is a place holder that means to use whatever
17942
+** conflict resolution algorthm is required from context.
17943
+**
17944
** The following symbolic values are used to record which type
17661
-** of action to take.
17945
+** of conflict resolution action to take.
17946
*/
17947
#define OE_None 0 /* There is no constraint to check */
17948
#define OE_Rollback 1 /* Fail the operation and rollback the transaction */
@@ -17912,10 +18196,10 @@ struct AggInfo {
18196
FuncDef *pFunc; /* The aggregate function implementation */
18197
int iMem; /* Memory location that acts as accumulator */
18198
int iDistinct; /* Ephemeral table used to enforce DISTINCT */
18199
+ int iDistAddr; /* Address of OP_OpenEphemeral */
18200
} *aFunc;
18201
int nFunc; /* Number of entries in aFunc[] */
18202
u32 selId; /* Select to which this AggInfo belongs */
17918
- AggInfo *pNext; /* Next in list of them all */
18203
};
18204
18205
/*
@@ -18044,7 +18328,7 @@ struct Expr {
18328
** TK_VARIABLE: variable number (always >= 1).
18329
** TK_SELECT_COLUMN: column of the result vector */
18330
i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */
18047
- i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
18331
+ int iRightJoinTable; /* If EP_FromJoin, the right table of the join */
18332
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
18333
union {
18334
Table *pTab; /* TK_COLUMN: Table containing column. Can be NULL
@@ -18081,12 +18365,12 @@ struct Expr {
18365
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
18366
#define EP_Win 0x008000 /* Contains window functions */
18367
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
18084
- /* 0x020000 // available for reuse */
18368
+#define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */
18369
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
18370
#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
18371
#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
18372
#define EP_Subquery 0x200000 /* Tree contains a TK_SELECT operator */
18089
-#define EP_Alias 0x400000 /* Is an alias for a result set column */
18373
+ /* 0x400000 // Available */
18374
#define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
18375
#define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
18376
#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
@@ -18185,6 +18469,7 @@ struct Expr {
18469
*/
18470
struct ExprList {
18471
int nExpr; /* Number of expressions on the list */
18472
+ int nAlloc; /* Number of a[] slots allocated */
18473
struct ExprList_item { /* For each expression in the list */
18474
Expr *pExpr; /* The parse tree for this expression */
18475
char *zEName; /* Token associated with this expression */
@@ -18234,6 +18519,46 @@ struct IdList {
18519
int nId; /* Number of identifiers on the list */
18520
};
18521
18522
+/*
18523
+** The SrcItem object represents a single term in the FROM clause of a query.
18524
+** The SrcList object is mostly an array of SrcItems.
18525
+*/
18526
+struct SrcItem {
18527
+ Schema *pSchema; /* Schema to which this item is fixed */
18528
+ char *zDatabase; /* Name of database holding this table */
18529
+ char *zName; /* Name of the table */
18530
+ char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
18531
+ Table *pTab; /* An SQL table corresponding to zName */
18532
+ Select *pSelect; /* A SELECT statement used in place of a table name */
18533
+ int addrFillSub; /* Address of subroutine to manifest a subquery */
18534
+ int regReturn; /* Register holding return address of addrFillSub */
18535
+ int regResult; /* Registers holding results of a co-routine */
18536
+ struct {
18537
+ u8 jointype; /* Type of join between this table and the previous */
18538
+ unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
18539
+ unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
18540
+ unsigned isTabFunc :1; /* True if table-valued-function syntax */
18541
+ unsigned isCorrelated :1; /* True if sub-query is correlated */
18542
+ unsigned viaCoroutine :1; /* Implemented as a co-routine */
18543
+ unsigned isRecursive :1; /* True for recursive reference in WITH */
18544
+ unsigned fromDDL :1; /* Comes from sqlite_schema */
18545
+ unsigned isCte :1; /* This is a CTE */
18546
+ unsigned notCte :1; /* This item may not match a CTE */
18547
+ } fg;
18548
+ int iCursor; /* The VDBE cursor number used to access this table */
18549
+ Expr *pOn; /* The ON clause of a join */
18550
+ IdList *pUsing; /* The USING clause of a join */
18551
+ Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
18552
+ union {
18553
+ char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
18554
+ ExprList *pFuncArg; /* Arguments to table-valued-function */
18555
+ } u1;
18556
+ union {
18557
+ Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */
18558
+ CteUse *pCteUse; /* CTE Usage info info fg.isCte is true */
18559
+ } u2;
18560
+};
18561
+
18562
/*
18563
** The following structure describes the FROM clause of a SELECT statement.
18564
** Each table or subquery in the FROM clause is a separate element of
@@ -18256,36 +18581,7 @@ struct IdList {
18581
struct SrcList {
18582
int nSrc; /* Number of tables or subqueries in the FROM clause */
18583
u32 nAlloc; /* Number of entries allocated in a[] below */
18259
- struct SrcList_item {
18260
- Schema *pSchema; /* Schema to which this item is fixed */
18261
- char *zDatabase; /* Name of database holding this table */
18262
- char *zName; /* Name of the table */
18263
- char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
18264
- Table *pTab; /* An SQL table corresponding to zName */
18265
- Select *pSelect; /* A SELECT statement used in place of a table name */
18266
- int addrFillSub; /* Address of subroutine to manifest a subquery */
18267
- int regReturn; /* Register holding return address of addrFillSub */
18268
- int regResult; /* Registers holding results of a co-routine */
18269
- struct {
18270
- u8 jointype; /* Type of join between this table and the previous */
18271
- unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
18272
- unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
18273
- unsigned isTabFunc :1; /* True if table-valued-function syntax */
18274
- unsigned isCorrelated :1; /* True if sub-query is correlated */
18275
- unsigned viaCoroutine :1; /* Implemented as a co-routine */
18276
- unsigned isRecursive :1; /* True for recursive reference in WITH */
18277
- unsigned fromDDL :1; /* Comes from sqlite_schema */
18278
- } fg;
18279
- int iCursor; /* The VDBE cursor number used to access this table */
18280
- Expr *pOn; /* The ON clause of a join */
18281
- IdList *pUsing; /* The USING clause of a join */
18282
- Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
18283
- union {
18284
- char *zIndexedBy; /* Identifier from "INDEXED BY <zIndex>" clause */
18285
- ExprList *pFuncArg; /* Arguments to table-valued-function */
18286
- } u1;
18287
- Index *pIBIndex; /* Index structure corresponding to u1.zIndexedBy */
18288
- } a[1]; /* One entry for each identifier on the list */
18584
+ SrcItem a[1]; /* One entry for each identifier on the list */
18585
};
18586
18587
/*
@@ -18319,9 +18615,9 @@ struct SrcList {
18615
#define WHERE_DISTINCTBY 0x0080 /* pOrderby is really a DISTINCT clause */
18616
#define WHERE_WANT_DISTINCT 0x0100 /* All output needs to be distinct */
18617
#define WHERE_SORTBYGROUP 0x0200 /* Support sqlite3WhereIsSorted() */
18322
-#define WHERE_SEEK_TABLE 0x0400 /* Do not defer seeks on main table */
18618
+#define WHERE_AGG_DISTINCT 0x0400 /* Query is "SELECT agg(DISTINCT ...)" */
18619
#define WHERE_ORDERBY_LIMIT 0x0800 /* ORDERBY+LIMIT on the inner loop */
18324
-#define WHERE_SEEK_UNIQ_TABLE 0x1000 /* Do not defer seeks if unique */
18620
+ /* 0x1000 not currently used */
18621
/* 0x2000 not currently used */
18622
#define WHERE_USE_LIMIT 0x4000 /* Use the LIMIT in cost estimates */
18623
/* 0x8000 not currently used */
@@ -18361,10 +18657,11 @@ struct NameContext {
18657
ExprList *pEList; /* Optional list of result-set columns */
18658
AggInfo *pAggInfo; /* Information about aggregates at this level */
18659
Upsert *pUpsert; /* ON CONFLICT clause information from an upsert */
18660
+ int iBaseReg; /* For TK_REGISTER when parsing RETURNING */
18661
} uNC;
18662
NameContext *pNext; /* Next outer name context. NULL for outermost */
18663
int nRef; /* Number of names resolved by this context */
18367
- int nErr; /* Number of errors encountered while resolving names */
18664
+ int nNcErr; /* Number of errors encountered while resolving names */
18665
int ncFlags; /* Zero or more NC_* flags defined below */
18666
Select *pWinSelect; /* SELECT statement for any window functions */
18667
};
@@ -18389,6 +18686,7 @@ struct NameContext {
18686
#define NC_UEList 0x00080 /* True if uNC.pEList is used */
18687
#define NC_UAggInfo 0x00100 /* True if uNC.pAggInfo is used */
18688
#define NC_UUpsert 0x00200 /* True if uNC.pUpsert is used */
18689
+#define NC_UBaseReg 0x00400 /* True if uNC.iBaseReg is used */
18690
#define NC_MinMaxAgg 0x01000 /* min/max aggregates seen. See note above */
18691
#define NC_Complex 0x02000 /* True if a function or subquery seen */
18692
#define NC_AllowWin 0x04000 /* Window functions are allowed here */
@@ -18396,6 +18694,7 @@ struct NameContext {
18694
#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
18695
#define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18696
#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */
18697
+#define NC_NoSelect 0x80000 /* Do not descend into sub-selects */
18698
18699
/*
18700
** An instance of the following object describes a single ON CONFLICT
@@ -18412,15 +18711,21 @@ struct NameContext {
18711
** WHERE clause is omitted.
18712
*/
18713
struct Upsert {
18415
- ExprList *pUpsertTarget; /* Optional description of conflicting index */
18714
+ ExprList *pUpsertTarget; /* Optional description of conflict target */
18715
Expr *pUpsertTargetWhere; /* WHERE clause for partial index targets */
18716
ExprList *pUpsertSet; /* The SET clause from an ON CONFLICT UPDATE */
18717
Expr *pUpsertWhere; /* WHERE clause for the ON CONFLICT UPDATE */
18419
- /* The fields above comprise the parse tree for the upsert clause.
18420
- ** The fields below are used to transfer information from the INSERT
18421
- ** processing down into the UPDATE processing while generating code.
18422
- ** Upsert owns the memory allocated above, but not the memory below. */
18423
- Index *pUpsertIdx; /* Constraint that pUpsertTarget identifies */
18718
+ Upsert *pNextUpsert; /* Next ON CONFLICT clause in the list */
18719
+ u8 isDoUpdate; /* True for DO UPDATE. False for DO NOTHING */
18720
+ /* Above this point is the parse tree for the ON CONFLICT clauses.
18721
+ ** The next group of fields stores intermediate data. */
18722
+ void *pToFree; /* Free memory when deleting the Upsert object */
18723
+ /* All fields above are owned by the Upsert object and must be freed
18724
+ ** when the Upsert is destroyed. The fields below are used to transfer
18725
+ ** information from the INSERT processing down into the UPDATE processing
18726
+ ** while generating code. The fields below are owned by the INSERT
18727
+ ** statement and will be freed by INSERT processing. */
18728
+ Index *pUpsertIdx; /* UNIQUE constraint specified by pUpsertTarget */
18729
SrcList *pUpsertSrc; /* Table to be updated */
18730
int regData; /* First register holding array of VALUES */
18731
int iDataCur; /* Index of the data cursor */
@@ -18500,6 +18805,9 @@ struct Select {
18805
#define SF_View 0x0200000 /* SELECT statement is a view */
18806
#define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */
18807
#define SF_UpdateFrom 0x0800000 /* Statement is an UPDATE...FROM */
18808
+#define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */
18809
+#define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
18810
+#define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
18811
18812
/*
18813
** The results of a SELECT can be distributed in several ways, as defined
@@ -18518,9 +18826,6 @@ struct Select {
18826
** statements within triggers whose only purpose is
18827
** the side-effects of functions.
18828
**
18521
-** All of the above are free to ignore their ORDER BY clause. Those that
18522
-** follow must honor the ORDER BY clause.
18523
-**
18829
** SRT_Output Generate a row of output (using the OP_ResultRow
18830
** opcode) for each row in the result set.
18831
**
@@ -18577,13 +18882,18 @@ struct Select {
18882
#define SRT_Except 2 /* Remove result from a UNION index */
18883
#define SRT_Exists 3 /* Store 1 if the result is not empty */
18884
#define SRT_Discard 4 /* Do not save the results anywhere */
18580
-#define SRT_Fifo 5 /* Store result as data with an automatic rowid */
18581
-#define SRT_DistFifo 6 /* Like SRT_Fifo, but unique results only */
18885
+#define SRT_DistFifo 5 /* Like SRT_Fifo, but unique results only */
18886
+#define SRT_DistQueue 6 /* Like SRT_Queue, but unique results only */
18887
+
18888
+/* The DISTINCT clause is ignored for all of the above. Not that
18889
+** IgnorableDistinct() implies IgnorableOrderby() */
18890
+#define IgnorableDistinct(X) ((X->eDest)<=SRT_DistQueue)
18891
+
18892
#define SRT_Queue 7 /* Store result in an queue */
18583
-#define SRT_DistQueue 8 /* Like SRT_Queue, but unique results only */
18893
+#define SRT_Fifo 8 /* Store result as data with an automatic rowid */
18894
18895
/* The ORDER BY clause is ignored for all of the above */
18586
-#define IgnorableOrderby(X) ((X->eDest)<=SRT_DistQueue)
18896
+#define IgnorableOrderby(X) ((X->eDest)<=SRT_Fifo)
18897
18898
#define SRT_Output 9 /* Output each row of result */
18899
#define SRT_Mem 10 /* Store result in a memory cell */
@@ -18668,6 +18978,17 @@ struct TriggerPrg {
18978
# define DbMaskNonZero(M) (M)!=0
18979
#endif
18980
18981
+/*
18982
+** An instance of the ParseCleanup object specifies an operation that
18983
+** should be performed after parsing to deallocation resources obtained
18984
+** during the parse and which are no longer needed.
18985
+*/
18986
+struct ParseCleanup {
18987
+ ParseCleanup *pNext; /* Next cleanup task */
18988
+ void *pPtr; /* Pointer to object to deallocate */
18989
+ void (*xCleanup)(sqlite3*,void*); /* Deallocation routine */
18990
+};
18991
+
18992
/*
18993
** An SQL parser context. A copy of this structure is passed through
18994
** the parser and down into all the parser action routine in order to
@@ -18699,6 +19020,9 @@ struct Parse {
19020
u8 okConstFactor; /* OK to factor out constants */
19021
u8 disableLookaside; /* Number of times lookaside has been disabled */
19022
u8 disableVtab; /* Disable all virtual tables for this parse */
19023
+#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
19024
+ u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
19025
+#endif
19026
int nRangeReg; /* Size of the temporary register block */
19027
int iRangeReg; /* First register in temporary register block */
19028
int nErr; /* Number of errors seen */
@@ -18726,12 +19050,15 @@ struct Parse {
19050
Parse *pToplevel; /* Parse structure for main program (or NULL) */
19051
Table *pTriggerTab; /* Table triggers are being coded for */
19052
Parse *pParentParse; /* Parent parser if this parser is nested */
18729
- AggInfo *pAggList; /* List of all AggInfo objects */
18730
- int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
19053
+ union {
19054
+ int addrCrTab; /* Address of OP_CreateBtree on CREATE TABLE */
19055
+ Returning *pReturning; /* The RETURNING clause */
19056
+ } u1;
19057
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
19058
u32 oldmask; /* Mask of old.* columns referenced */
19059
u32 newmask; /* Mask of new.* columns referenced */
19060
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
19061
+ u8 bReturning; /* Coding a RETURNING trigger */
19062
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
19063
u8 disableTriggers; /* True to disable triggers */
19064
@@ -18777,10 +19104,9 @@ struct Parse {
19104
Token sArg; /* Complete text of a module argument */
19105
Table **apVtabLock; /* Pointer to virtual tables needing locking */
19106
#endif
18780
- Table *pZombieTab; /* List of Table objects to delete after code gen */
19107
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
19108
With *pWith; /* Current WITH clause, or NULL */
18783
- With *pWithToFree; /* Free this WITH object at the end of the parse */
19109
+ ParseCleanup *pCleanup; /* List of cleanup operations to run after parse */
19110
#ifndef SQLITE_OMIT_ALTERTABLE
19111
RenameToken *pRename; /* Tokens subject to renaming by ALTER TABLE */
19112
#endif
@@ -18860,6 +19186,7 @@ struct AuthContext {
19186
#define OPFLAG_SAVEPOSITION 0x02 /* OP_Delete/Insert: save cursor pos */
19187
#define OPFLAG_AUXDELETE 0x04 /* OP_Delete: index in a DELETE op */
19188
#define OPFLAG_NOCHNG_MAGIC 0x6d /* OP_MakeRecord: serialtype 10 is ok */
19189
+#define OPFLAG_PREFORMAT 0x80 /* OP_Insert uses preformatted cell */
19190
19191
/*
19192
* Each trigger present in the database schema is stored as an instance of
@@ -18881,6 +19208,7 @@ struct Trigger {
19208
char *table; /* The table or view to which the trigger applies */
19209
u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT */
19210
u8 tr_tm; /* One of TRIGGER_BEFORE, TRIGGER_AFTER */
19211
+ u8 bReturning; /* This trigger implements a RETURNING clause */
19212
Expr *pWhen; /* The WHEN clause of the expression (may be NULL) */
19213
IdList *pColumns; /* If this is an UPDATE OF <column-list> trigger,
19214
the <column-list> is stored here */
@@ -18939,14 +19267,15 @@ struct Trigger {
19267
*
19268
*/
19269
struct TriggerStep {
18942
- u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT */
19270
+ u8 op; /* One of TK_DELETE, TK_UPDATE, TK_INSERT, TK_SELECT,
19271
+ ** or TK_RETURNING */
19272
u8 orconf; /* OE_Rollback etc. */
19273
Trigger *pTrig; /* The trigger that this step is a part of */
19274
Select *pSelect; /* SELECT statement or RHS of INSERT INTO SELECT ... */
19275
char *zTarget; /* Target table for DELETE, UPDATE, INSERT */
19276
SrcList *pFrom; /* FROM clause for UPDATE statement (if any) */
19277
Expr *pWhere; /* The WHERE clause for DELETE or UPDATE steps */
18949
- ExprList *pExprList; /* SET clause for UPDATE */
19278
+ ExprList *pExprList; /* SET clause for UPDATE, or RETURNING clause */
19279
IdList *pIdList; /* Column names for INSERT */
19280
Upsert *pUpsert; /* Upsert clauses on an INSERT */
19281
char *zSpan; /* Original SQL text of this command */
@@ -18955,18 +19284,16 @@ struct TriggerStep {
19284
};
19285
19286
/*
18958
-** The following structure contains information used by the sqliteFix...
18959
-** routines as they walk the parse tree to make database references
18960
-** explicit.
19287
+** Information about a RETURNING clause
19288
*/
18962
-typedef struct DbFixer DbFixer;
18963
-struct DbFixer {
18964
- Parse *pParse; /* The parsing context. Error messages written here */
18965
- Schema *pSchema; /* Fix items to this schema */
18966
- u8 bTemp; /* True for TEMP schema entries */
18967
- const char *zDb; /* Make sure all objects are contained in this database */
18968
- const char *zType; /* Type of the container - used for error messages */
18969
- const Token *pName; /* Name of the container - used for error messages */
19289
+struct Returning {
19290
+ Parse *pParse; /* The parse that includes the RETURNING clause */
19291
+ ExprList *pReturnEL; /* List of expressions to return */
19292
+ Trigger retTrig; /* The transient trigger that implements RETURNING */
19293
+ TriggerStep retTStep; /* The trigger step */
19294
+ int iRetCur; /* Transient table holding RETURNING results */
19295
+ int nRetCol; /* Number of in pReturnEL after expansion */
19296
+ int iRetReg; /* Register array for holding a row of RETURNING */
19297
};
19298
19299
/*
@@ -19006,7 +19333,24 @@ typedef struct {
19333
/*
19334
** Allowed values for mInitFlags
19335
*/
19009
-#define INITFLAG_AlterTable 0x0001 /* This is a reparse after ALTER TABLE */
19336
+#define INITFLAG_AlterRename 0x0001 /* Reparse after a RENAME */
19337
+#define INITFLAG_AlterDrop 0x0002 /* Reparse after a DROP COLUMN */
19338
+
19339
+/* Tuning parameters are set using SQLITE_TESTCTRL_TUNE and are controlled
19340
+** on debug-builds of the CLI using ".testctrl tune ID VALUE". Tuning
19341
+** parameters are for temporary use during development, to help find
19342
+** optimial values for parameters in the query planner. The should not
19343
+** be used on trunk check-ins. They are a temporary mechanism available
19344
+** for transient development builds only.
19345
+**
19346
+** Tuning parameters are numbered starting with 1.
19347
+*/
19348
+#define SQLITE_NTUNE 6 /* Should be zero for all trunk check-ins */
19349
+#ifdef SQLITE_DEBUG
19350
+# define Tuning(X) (sqlite3Config.aTune[(X)-1])
19351
+#else
19352
+# define Tuning(X) 0
19353
+#endif
19354
19355
/*
19356
** Structure containing global configuration data for the SQLite library.
@@ -19062,7 +19406,7 @@ struct Sqlite3Config {
19406
void (*xVdbeBranch)(void*,unsigned iSrcLine,u8 eThis,u8 eMx); /* Callback */
19407
void *pVdbeBranchArg; /* 1st argument */
19408
#endif
19065
-#ifdef SQLITE_ENABLE_DESERIALIZE
19409
+#ifndef SQLITE_OMIT_DESERIALIZE
19410
sqlite3_int64 mxMemdbSize; /* Default max memdb size */
19411
#endif
19412
#ifndef SQLITE_UNTESTABLE
@@ -19072,6 +19416,10 @@ struct Sqlite3Config {
19416
int iOnceResetThreshold; /* When to reset OP_Once counters */
19417
u32 szSorterRef; /* Min size in bytes to use sorter-refs */
19418
unsigned int iPrngSeed; /* Alternative fixed seed for the PRNG */
19419
+ /* vvvv--- must be last ---vvv */
19420
+#ifdef SQLITE_DEBUG
19421
+ sqlite3_int64 aTune[SQLITE_NTUNE]; /* Tuning parameters */
19422
+#endif
19423
};
19424
19425
/*
@@ -19118,10 +19466,26 @@ struct Walker {
19466
struct WhereConst *pConst; /* WHERE clause constants */
19467
struct RenameCtx *pRename; /* RENAME COLUMN context */
19468
struct Table *pTab; /* Table of generated column */
19121
- struct SrcList_item *pSrcItem; /* A single FROM clause item */
19469
+ SrcItem *pSrcItem; /* A single FROM clause item */
19470
+ DbFixer *pFix;
19471
} u;
19472
};
19473
19474
+/*
19475
+** The following structure contains information used by the sqliteFix...
19476
+** routines as they walk the parse tree to make database references
19477
+** explicit.
19478
+*/
19479
+struct DbFixer {
19480
+ Parse *pParse; /* The parsing context. Error messages written here */
19481
+ Walker w; /* Walker object */
19482
+ Schema *pSchema; /* Fix items to this schema */
19483
+ u8 bTemp; /* True for TEMP schema entries */
19484
+ const char *zDb; /* Make sure all objects are contained in this database */
19485
+ const char *zType; /* Type of the container - used for error messages */
19486
+ const Token *pName; /* Name of the container - used for error messages */
19487
+};
19488
+
19489
/* Forward declarations */
19490
SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
19491
SQLITE_PRIVATE int sqlite3WalkExprList(Walker*, ExprList*);
@@ -19133,11 +19497,18 @@ SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
19497
SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*);
19498
SQLITE_PRIVATE int sqlite3WalkerDepthIncrease(Walker*,Select*);
19499
SQLITE_PRIVATE void sqlite3WalkerDepthDecrease(Walker*,Select*);
19500
+SQLITE_PRIVATE void sqlite3WalkWinDefnDummyCallback(Walker*,Select*);
19501
19502
#ifdef SQLITE_DEBUG
19503
SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
19504
#endif
19505
19506
+#ifndef SQLITE_OMIT_CTE
19507
+SQLITE_PRIVATE void sqlite3SelectPopWith(Walker*, Select*);
19508
+#else
19509
+# define sqlite3SelectPopWith 0
19510
+#endif
19511
+
19512
/*
19513
** Return code from the parse-tree walking primitives and their
19514
** callbacks.
@@ -19147,20 +19518,56 @@ SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
19518
#define WRC_Abort 2 /* Abandon the tree walk */
19519
19520
/*
19150
-** An instance of this structure represents a set of one or more CTEs
19151
-** (common table expressions) created by a single WITH clause.
19521
+** A single common table expression
19522
+*/
19523
+struct Cte {
19524
+ char *zName; /* Name of this CTE */
19525
+ ExprList *pCols; /* List of explicit column names, or NULL */
19526
+ Select *pSelect; /* The definition of this CTE */
19527
+ const char *zCteErr; /* Error message for circular references */
19528
+ CteUse *pUse; /* Usage information for this CTE */
19529
+ u8 eM10d; /* The MATERIALIZED flag */
19530
+};
19531
+
19532
+/*
19533
+** Allowed values for the materialized flag (eM10d):
19534
+*/
19535
+#define M10d_Yes 0 /* AS MATERIALIZED */
19536
+#define M10d_Any 1 /* Not specified. Query planner's choice */
19537
+#define M10d_No 2 /* AS NOT MATERIALIZED */
19538
+
19539
+/*
19540
+** An instance of the With object represents a WITH clause containing
19541
+** one or more CTEs (common table expressions).
19542
*/
19543
struct With {
19154
- int nCte; /* Number of CTEs in the WITH clause */
19155
- With *pOuter; /* Containing WITH clause, or NULL */
19156
- struct Cte { /* For each CTE in the WITH clause.... */
19157
- char *zName; /* Name of this CTE */
19158
- ExprList *pCols; /* List of explicit column names, or NULL */
19159
- Select *pSelect; /* The definition of this CTE */
19160
- const char *zCteErr; /* Error message for circular references */
19161
- } a[1];
19544
+ int nCte; /* Number of CTEs in the WITH clause */
19545
+ int bView; /* Belongs to the outermost Select of a view */
19546
+ With *pOuter; /* Containing WITH clause, or NULL */
19547
+ Cte a[1]; /* For each CTE in the WITH clause.... */
19548
+};
19549
+
19550
+/*
19551
+** The Cte object is not guaranteed to persist for the entire duration
19552
+** of code generation. (The query flattener or other parser tree
19553
+** edits might delete it.) The following object records information
19554
+** about each Common Table Expression that must be preserved for the
19555
+** duration of the parse.
19556
+**
19557
+** The CteUse objects are freed using sqlite3ParserAddCleanup() rather
19558
+** than sqlite3SelectDelete(), which is what enables them to persist
19559
+** until the end of code generation.
19560
+*/
19561
+struct CteUse {
19562
+ int nUse; /* Number of users of this CTE */
19563
+ int addrM9e; /* Start of subroutine to compute materialization */
19564
+ int regRtn; /* Return address register for addrM9e subroutine */
19565
+ int iCur; /* Ephemeral table holding the materialization */
19566
+ LogEst nRowEst; /* Estimated number of rows in the table */
19567
+ u8 eM10d; /* The MATERIALIZED flag */
19568
};
19569
19570
+
19571
#ifdef SQLITE_DEBUG
19572
/*
19573
** An instance of the TreeView object is used for printing the content of
@@ -19238,7 +19645,6 @@ SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*, int);
19645
SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Select*);
19646
SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
19647
SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
19241
-SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
19648
SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
19649
SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
19650
SQLITE_PRIVATE Window *sqlite3WindowListDup(sqlite3 *db, Window *p);
@@ -19507,6 +19913,7 @@ SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*, int);
19913
SQLITE_PRIVATE void sqlite3ExprFunctionUsable(Parse*,Expr*,FuncDef*);
19914
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32);
19915
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
19916
+SQLITE_PRIVATE void sqlite3ExprDeferredDelete(Parse*, Expr*);
19917
SQLITE_PRIVATE void sqlite3ExprUnmapAndDelete(Parse*, Expr*);
19918
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
19919
SQLITE_PRIVATE ExprList *sqlite3ExprListAppendVector(Parse*,ExprList*,IdList*,Expr*);
@@ -19528,6 +19935,7 @@ SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
19935
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
19936
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
19937
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
19938
+SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect);
19939
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
19940
SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
19941
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
@@ -19550,11 +19958,12 @@ SQLITE_PRIVATE void sqlite3ColumnPropertiesFromName(Table*, Column*);
19958
SQLITE_PRIVATE void sqlite3AddColumn(Parse*,Token*,Token*);
19959
SQLITE_PRIVATE void sqlite3AddNotNull(Parse*, int);
19960
SQLITE_PRIVATE void sqlite3AddPrimaryKey(Parse*, ExprList*, int, int, int);
19553
-SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*);
19961
+SQLITE_PRIVATE void sqlite3AddCheckConstraint(Parse*, Expr*, const char*, const char*);
19962
SQLITE_PRIVATE void sqlite3AddDefaultValue(Parse*,Expr*,const char*,const char*);
19963
SQLITE_PRIVATE void sqlite3AddCollateType(Parse*, Token*);
19964
SQLITE_PRIVATE void sqlite3AddGenerated(Parse*,Expr*,Token*);
19965
SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*);
19966
+SQLITE_PRIVATE void sqlite3AddReturning(Parse*,ExprList*);
19967
SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*,
19968
sqlite3_vfs**,char**,char **);
19969
#define sqlite3CodecQueryParameters(A,B,C) 0
@@ -19620,7 +20029,7 @@ SQLITE_PRIVATE SrcList *sqlite3SrcListAppendFromTerm(Parse*, SrcList*, Token*, T
20029
Token*, Select*, Expr*, IdList*);
20030
SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *, SrcList *, Token *);
20031
SQLITE_PRIVATE void sqlite3SrcListFuncArgs(Parse*, SrcList*, ExprList*);
19623
-SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
20032
+SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, SrcItem *);
20033
SQLITE_PRIVATE void sqlite3SrcListShiftJoinType(SrcList*);
20034
SQLITE_PRIVATE void sqlite3SrcListAssignCursors(Parse*, SrcList*);
20035
SQLITE_PRIVATE void sqlite3IdListDelete(sqlite3*, IdList*);
@@ -19648,6 +20057,7 @@ SQLITE_PRIVATE LogEst sqlite3WhereOutputRowCount(WhereInfo*);
20057
SQLITE_PRIVATE int sqlite3WhereIsDistinct(WhereInfo*);
20058
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo*);
20059
SQLITE_PRIVATE int sqlite3WhereOrderByLimitOptLabel(WhereInfo*);
20060
+SQLITE_PRIVATE void sqlite3WhereMinMaxOptEarlyOut(Vdbe*,WhereInfo*);
20061
SQLITE_PRIVATE int sqlite3WhereIsSorted(WhereInfo*);
20062
SQLITE_PRIVATE int sqlite3WhereContinueLabel(WhereInfo*);
20063
SQLITE_PRIVATE int sqlite3WhereBreakLabel(WhereInfo*);
@@ -19681,7 +20091,7 @@ SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
20091
#define LOCATE_VIEW 0x01
20092
#define LOCATE_NOERR 0x02
20093
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,u32 flags,const char*, const char*);
19684
-SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,struct SrcList_item *);
20094
+SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,u32 flags,SrcItem *);
20095
SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
20096
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteTable(sqlite3*,int,const char*);
20097
SQLITE_PRIVATE void sqlite3UnlinkAndDeleteIndex(sqlite3*,int,const char*);
@@ -19761,6 +20171,7 @@ SQLITE_PRIVATE void sqlite3RegisterPerConnectionBuiltinFunctions(sqlite3*);
20171
SQLITE_PRIVATE int sqlite3SafetyCheckOk(sqlite3*);
20172
SQLITE_PRIVATE int sqlite3SafetyCheckSickOrOk(sqlite3*);
20173
SQLITE_PRIVATE void sqlite3ChangeCookie(Parse*, int);
20174
+SQLITE_PRIVATE With *sqlite3WithDup(sqlite3 *db, With *p);
20175
20176
#if !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER)
20177
SQLITE_PRIVATE void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,int);
@@ -19809,6 +20220,7 @@ SQLITE_PRIVATE SrcList *sqlite3TriggerStepSrc(Parse*, TriggerStep*);
20220
#endif
20221
20222
SQLITE_PRIVATE int sqlite3JoinType(Parse*, Token*, Token*, Token*);
20223
+SQLITE_PRIVATE int sqlite3ColumnIndex(Table *pTab, const char *zCol);
20224
SQLITE_PRIVATE void sqlite3SetJoinExpr(Expr*,int);
20225
SQLITE_PRIVATE void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int);
20226
SQLITE_PRIVATE void sqlite3DeferForeignKey(Parse*, int);
@@ -19831,7 +20243,6 @@ SQLITE_PRIVATE void sqlite3FixInit(DbFixer*, Parse*, int, const char*, const Tok
20243
SQLITE_PRIVATE int sqlite3FixSrcList(DbFixer*, SrcList*);
20244
SQLITE_PRIVATE int sqlite3FixSelect(DbFixer*, Select*);
20245
SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
19834
-SQLITE_PRIVATE int sqlite3FixExprList(DbFixer*, ExprList*);
20246
SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
20247
SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
20248
SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
@@ -19894,6 +20305,7 @@ SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
20305
SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
20306
SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...);
20307
SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
20308
+SQLITE_PRIVATE void sqlite3ErrorClear(sqlite3*);
20309
SQLITE_PRIVATE void sqlite3SystemError(sqlite3*,int);
20310
SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n);
20311
SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
@@ -19903,7 +20315,7 @@ SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);
20315
SQLITE_PRIVATE const char *sqlite3ErrName(int);
20316
#endif
20317
19906
-#ifdef SQLITE_ENABLE_DESERIALIZE
20318
+#ifndef SQLITE_OMIT_DESERIALIZE
20319
SQLITE_PRIVATE int sqlite3MemdbInit(void);
20320
#endif
20321
@@ -19954,10 +20366,12 @@ SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8);
20366
SQLITE_PRIVATE const unsigned char sqlite3OpcodeProperty[];
20367
SQLITE_PRIVATE const char sqlite3StrBINARY[];
20368
SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
20369
+SQLITE_PRIVATE const unsigned char *sqlite3aLTb;
20370
+SQLITE_PRIVATE const unsigned char *sqlite3aEQb;
20371
+SQLITE_PRIVATE const unsigned char *sqlite3aGTb;
20372
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
20373
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
20374
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
19960
-SQLITE_API extern u32 sqlite3_unsupported_selecttrace;
20375
#ifndef SQLITE_OMIT_WSD
20376
SQLITE_PRIVATE int sqlite3PendingByte;
20377
#endif
@@ -19976,6 +20390,7 @@ SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*, int);
20390
SQLITE_PRIVATE void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
20391
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse*, Expr*);
20392
SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
20393
+SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, SrcItem*);
20394
SQLITE_PRIVATE void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
20395
SQLITE_PRIVATE int sqlite3MatchEName(
20396
const struct ExprList_item*,
@@ -19993,6 +20408,7 @@ SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const
20408
SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
20409
SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
20410
SQLITE_PRIVATE void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
20411
+SQLITE_PRIVATE void sqlite3AlterDropColumn(Parse*, SrcList*, Token*);
20412
SQLITE_PRIVATE void *sqlite3RenameTokenMap(Parse*, void*, Token*);
20413
SQLITE_PRIVATE void sqlite3RenameTokenRemap(Parse*, void *pTo, void *pFrom);
20414
SQLITE_PRIVATE void sqlite3RenameExprUnmap(Parse*, Expr*);
@@ -20016,6 +20432,7 @@ SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo*);
20432
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoRef(KeyInfo*);
20433
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoOfIndex(Parse*, Index*);
20434
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoFromExprList(Parse*, ExprList*, int, int);
20435
+SQLITE_PRIVATE const char *sqlite3SelectOpName(int);
20436
SQLITE_PRIVATE int sqlite3HasExplicitNulls(Parse*, ExprList*);
20437
20438
#ifdef SQLITE_DEBUG
@@ -20146,6 +20563,7 @@ SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
20563
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
20564
SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
20565
SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
20566
+SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*);
20567
#ifdef SQLITE_ENABLE_NORMALIZE
20568
SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*);
20569
#endif
@@ -20160,23 +20578,32 @@ SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3*, int, int, int*, int*);
20578
SQLITE_PRIVATE int sqlite3WalDefaultHook(void*,sqlite3*,const char*,int);
20579
#endif
20580
#ifndef SQLITE_OMIT_CTE
20163
-SQLITE_PRIVATE With *sqlite3WithAdd(Parse*,With*,Token*,ExprList*,Select*);
20581
+SQLITE_PRIVATE Cte *sqlite3CteNew(Parse*,Token*,ExprList*,Select*,u8);
20582
+SQLITE_PRIVATE void sqlite3CteDelete(sqlite3*,Cte*);
20583
+SQLITE_PRIVATE With *sqlite3WithAdd(Parse*,With*,Cte*);
20584
SQLITE_PRIVATE void sqlite3WithDelete(sqlite3*,With*);
20165
-SQLITE_PRIVATE void sqlite3WithPush(Parse*, With*, u8);
20585
+SQLITE_PRIVATE With *sqlite3WithPush(Parse*, With*, u8);
20586
#else
20167
-#define sqlite3WithPush(x,y,z)
20168
-#define sqlite3WithDelete(x,y)
20587
+# define sqlite3CteNew(P,T,E,S) ((void*)0)
20588
+# define sqlite3CteDelete(D,C)
20589
+# define sqlite3CteWithAdd(P,W,C) ((void*)0)
20590
+# define sqlite3WithDelete(x,y)
20591
+# define sqlite3WithPush(x,y,z)
20592
#endif
20593
#ifndef SQLITE_OMIT_UPSERT
20171
-SQLITE_PRIVATE Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*);
20594
+SQLITE_PRIVATE Upsert *sqlite3UpsertNew(sqlite3*,ExprList*,Expr*,ExprList*,Expr*,Upsert*);
20595
SQLITE_PRIVATE void sqlite3UpsertDelete(sqlite3*,Upsert*);
20596
SQLITE_PRIVATE Upsert *sqlite3UpsertDup(sqlite3*,Upsert*);
20597
SQLITE_PRIVATE int sqlite3UpsertAnalyzeTarget(Parse*,SrcList*,Upsert*);
20598
SQLITE_PRIVATE void sqlite3UpsertDoUpdate(Parse*,Upsert*,Table*,Index*,int);
20599
+SQLITE_PRIVATE Upsert *sqlite3UpsertOfIndex(Upsert*,Index*);
20600
+SQLITE_PRIVATE int sqlite3UpsertNextIsIPK(Upsert*);
20601
#else
20177
-#define sqlite3UpsertNew(v,w,x,y,z) ((Upsert*)0)
20602
+#define sqlite3UpsertNew(u,v,w,x,y,z) ((Upsert*)0)
20603
#define sqlite3UpsertDelete(x,y)
20179
-#define sqlite3UpsertDup(x,y) ((Upsert*)0)
20604
+#define sqlite3UpsertDup(x,y) ((Upsert*)0)
20605
+#define sqlite3UpsertOfIndex(x,y) ((Upsert*)0)
20606
+#define sqlite3UpsertNextIsIPK(x) 0
20607
#endif
20608
20609
@@ -20408,7 +20835,7 @@ SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[] = {
20835
198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
20836
216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
20837
234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
20411
- 252,253,254,255
20838
+ 252,253,254,255,
20839
#endif
20840
#ifdef SQLITE_EBCDIC
20841
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, /* 0x */
@@ -20428,7 +20855,35 @@ SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[] = {
20855
224,225,162,163,164,165,166,167,168,169,234,235,236,237,238,239, /* Ex */
20856
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, /* Fx */
20857
#endif
20858
+/* All of the upper-to-lower conversion data is above. The following
20859
+** 18 integers are completely unrelated. They are appended to the
20860
+** sqlite3UpperToLower[] array to avoid UBSAN warnings. Here's what is
20861
+** going on:
20862
+**
20863
+** The SQL comparison operators (<>, =, >, <=, <, and >=) are implemented
20864
+** by invoking sqlite3MemCompare(A,B) which compares values A and B and
20865
+** returns negative, zero, or positive if A is less then, equal to, or
20866
+** greater than B, respectively. Then the true false results is found by
20867
+** consulting sqlite3aLTb[opcode], sqlite3aEQb[opcode], or
20868
+** sqlite3aGTb[opcode] depending on whether the result of compare(A,B)
20869
+** is negative, zero, or positive, where opcode is the specific opcode.
20870
+** The only works because the comparison opcodes are consecutive and in
20871
+** this order: NE EQ GT LE LT GE. Various assert()s throughout the code
20872
+** ensure that is the case.
20873
+**
20874
+** These elements must be appended to another array. Otherwise the
20875
+** index (here shown as [256-OP_Ne]) would be out-of-bounds and thus
20876
+** be undefined behavior. That's goofy, but the C-standards people thought
20877
+** it was a good idea, so here we are.
20878
+*/
20879
+/* NE EQ GT LE LT GE */
20880
+ 1, 0, 0, 1, 1, 0, /* aLTb[]: Use when compare(A,B) less than zero */
20881
+ 0, 1, 0, 1, 0, 1, /* aEQb[]: Use when compare(A,B) equals zero */
20882
+ 1, 0, 1, 0, 0, 1 /* aGTb[]: Use when compare(A,B) greater than zero*/
20883
};
20884
+SQLITE_PRIVATE const unsigned char *sqlite3aLTb = &sqlite3UpperToLower[256-OP_Ne];
20885
+SQLITE_PRIVATE const unsigned char *sqlite3aEQb = &sqlite3UpperToLower[256+6-OP_Ne];
20886
+SQLITE_PRIVATE const unsigned char *sqlite3aGTb = &sqlite3UpperToLower[256+12-OP_Ne];
20887
20888
/*
20889
** The following 256 byte lookup table is used to support SQLites built-in
@@ -20622,7 +21077,7 @@ SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config = {
21077
0, /* xVdbeBranch */
21078
0, /* pVbeBranchArg */
21079
#endif
20625
-#ifdef SQLITE_ENABLE_DESERIALIZE
21080
+#ifndef SQLITE_OMIT_DESERIALIZE
21081
SQLITE_MEMDB_DEFAULT_MAXSIZE, /* mxMemdbSize */
21082
#endif
21083
#ifndef SQLITE_UNTESTABLE
@@ -20672,9 +21127,10 @@ SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
21127
#endif
21128
21129
/*
20675
-** Flags for select tracing and the ".selecttrace" macro of the CLI
21130
+** Tracing flags set by SQLITE_TESTCTRL_TRACEFLAGS.
21131
*/
20677
-SQLITE_API u32 sqlite3_unsupported_selecttrace = 0;
21132
+SQLITE_PRIVATE u32 sqlite3SelectTrace = 0;
21133
+SQLITE_PRIVATE u32 sqlite3WhereTrace = 0;
21134
21135
/* #include "opcodes.h" */
21136
/*
@@ -20798,7 +21254,8 @@ struct VdbeCursor {
21254
Bool isEphemeral:1; /* True for an ephemeral table */
21255
Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
21256
Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
20801
- Bool seekHit:1; /* See the OP_SeekHit and OP_IfNoHope opcodes */
21257
+ Bool hasBeenDuped:1; /* This cursor was source or target of OP_OpenDup */
21258
+ u16 seekHit; /* See the OP_SeekHit and OP_IfNoHope opcodes */
21259
Btree *pBtx; /* Separate file holding temporary table */
21260
i64 seqCount; /* Sequence counter */
21261
u32 *aAltMap; /* Mapping from table to index column numbers */
@@ -21093,7 +21550,7 @@ struct Vdbe {
21550
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
21551
Parse *pParse; /* Parsing context used to create this Vdbe */
21552
ynVar nVar; /* Number of entries in aVar[] */
21096
- u32 magic; /* Magic number for sanity checking */
21553
+ u32 iVdbeMagic; /* Magic number defining state of the SQL statement */
21554
int nMem; /* Number of memory locations currently allocated */
21555
int nCursor; /* Number of slots in apCsr[] */
21556
u32 cacheCtr; /* VdbeCursor row cache generation counter */
@@ -21183,6 +21640,7 @@ struct PreUpdate {
21640
UnpackedRecord *pUnpacked; /* Unpacked version of aRecord[] */
21641
UnpackedRecord *pNewUnpacked; /* Unpacked version of new.* record */
21642
int iNewReg; /* Register for new.* values */
21643
+ int iBlobWrite; /* Value returned by preupdate_blobwrite() */
21644
i64 iKey1; /* First key value passed to hook */
21645
i64 iKey2; /* Second key value passed to hook */
21646
Mem *aNew; /* Array of new.* values */
@@ -21226,7 +21684,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemCopy(Mem*, const Mem*);
21684
SQLITE_PRIVATE void sqlite3VdbeMemShallowCopy(Mem*, const Mem*, int);
21685
SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem*, Mem*);
21686
SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem*);
21229
-SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
21687
+SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, i64, u8, void(*)(void*));
21688
SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem*, i64);
21689
#ifdef SQLITE_OMIT_FLOATING_POINT
21690
# define sqlite3VdbeMemSetDouble sqlite3VdbeMemSetInt64
@@ -21271,7 +21729,8 @@ SQLITE_PRIVATE void sqlite3VdbeFrameMemDel(void*); /* Destructor on Mem */
21729
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*); /* Actually deletes the Frame */
21730
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
21731
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
21274
-SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int);
21732
+SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(
21733
+ Vdbe*,VdbeCursor*,int,const char*,Table*,i64,int,int);
21734
#endif
21735
SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
21736
@@ -22598,6 +23057,7 @@ static int isDate(
23057
int eType;
23058
memset(p, 0, sizeof(*p));
23059
if( argc==0 ){
23060
+ if( !sqlite3NotPureFunc(context) ) return 1;
23061
return setDateTimeToCurrent(context, p);
23062
}
23063
if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT
@@ -23098,6 +23558,8 @@ SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
23558
#ifdef SQLITE_TEST
23559
if( op!=SQLITE_FCNTL_COMMIT_PHASETWO
23560
&& op!=SQLITE_FCNTL_LOCK_TIMEOUT
23561
+ && op!=SQLITE_FCNTL_CKPT_DONE
23562
+ && op!=SQLITE_FCNTL_CKPT_START
23563
){
23564
/* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite
23565
** is using a regular VFS, it is called after the corresponding
@@ -23108,7 +23570,12 @@ SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){
23570
** The core must call OsFileControl() though, not OsFileControlHint(),
23571
** as if a custom VFS (e.g. zipvfs) returns an error here, it probably
23572
** means the commit really has failed and an error should be returned
23111
- ** to the user. */
23573
+ ** to the user.
23574
+ **
23575
+ ** The CKPT_DONE and CKPT_START file-controls are write-only signals
23576
+ ** to the cksumvfs. Their return code is meaningless and is ignored
23577
+ ** by the SQLite core, so there is no point in simulating OOMs for them.
23578
+ */
23579
DO_OS_MALLOC_TEST(id);
23580
}
23581
#endif
@@ -23191,7 +23658,7 @@ SQLITE_PRIVATE int sqlite3OsOpen(
23658
SQLITE_PRIVATE int sqlite3OsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
23659
DO_OS_MALLOC_TEST(0);
23660
assert( dirSync==0 || dirSync==1 );
23194
- return pVfs->xDelete(pVfs, zPath, dirSync);
23661
+ return pVfs->xDelete!=0 ? pVfs->xDelete(pVfs, zPath, dirSync) : SQLITE_OK;
23662
}
23663
SQLITE_PRIVATE int sqlite3OsAccess(
23664
sqlite3_vfs *pVfs,
@@ -23214,6 +23681,8 @@ SQLITE_PRIVATE int sqlite3OsFullPathname(
23681
}
23682
#ifndef SQLITE_OMIT_LOAD_EXTENSION
23683
SQLITE_PRIVATE void *sqlite3OsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
23684
+ assert( zPath!=0 );
23685
+ assert( strlen(zPath)<=SQLITE_MAX_PATHLEN ); /* tag-20210611-1 */
23686
return pVfs->xDlOpen(pVfs, zPath);
23687
}
23688
SQLITE_PRIVATE void sqlite3OsDlError(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
@@ -27481,7 +27950,6 @@ SQLITE_PRIVATE int sqlite3MallocInit(void){
27950
if( sqlite3GlobalConfig.m.xMalloc==0 ){
27951
sqlite3MemSetDefault();
27952
}
27484
- memset(&mem0, 0, sizeof(mem0));
27953
mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
27954
if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
27955
|| sqlite3GlobalConfig.nPage<=0 ){
@@ -27794,12 +28262,17 @@ SQLITE_PRIVATE void *sqlite3Realloc(void *pOld, u64 nBytes){
28262
if( nOld==nNew ){
28263
pNew = pOld;
28264
}else if( sqlite3GlobalConfig.bMemstat ){
28265
+ sqlite3_int64 nUsed;
28266
sqlite3_mutex_enter(mem0.mutex);
28267
sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes);
28268
nDiff = nNew - nOld;
27800
- if( nDiff>0 && sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >=
28269
+ if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >=
28270
mem0.alarmThreshold-nDiff ){
28271
sqlite3MallocAlarm(nDiff);
28272
+ if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){
28273
+ sqlite3_mutex_leave(mem0.mutex);
28274
+ return 0;
28275
+ }
28276
}
28277
pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew);
28278
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
@@ -28106,12 +28579,15 @@ SQLITE_PRIVATE void sqlite3OomClear(sqlite3 *db){
28579
}
28580
28581
/*
28109
-** Take actions at the end of an API call to indicate an OOM error
28582
+** Take actions at the end of an API call to deal with error codes.
28583
*/
28111
-static SQLITE_NOINLINE int apiOomError(sqlite3 *db){
28112
- sqlite3OomClear(db);
28113
- sqlite3Error(db, SQLITE_NOMEM);
28114
- return SQLITE_NOMEM_BKPT;
28584
+static SQLITE_NOINLINE int apiHandleError(sqlite3 *db, int rc){
28585
+ if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
28586
+ sqlite3OomClear(db);
28587
+ sqlite3Error(db, SQLITE_NOMEM);
28588
+ return SQLITE_NOMEM_BKPT;
28589
+ }
28590
+ return rc & db->errMask;
28591
}
28592
28593
/*
@@ -28133,8 +28609,8 @@ SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
28609
*/
28610
assert( db!=0 );
28611
assert( sqlite3_mutex_held(db->mutex) );
28136
- if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
28137
- return apiOomError(db);
28612
+ if( db->mallocFailed || rc ){
28613
+ return apiHandleError(db, rc);
28614
}
28615
return rc & db->errMask;
28616
}
@@ -28172,7 +28648,7 @@ SQLITE_PRIVATE int sqlite3ApiExit(sqlite3* db, int rc){
28648
#define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
28649
NULL pointers replaced by SQL NULL. %Q */
28650
#define etTOKEN 11 /* a pointer to a Token structure */
28175
-#define etSRCLIST 12 /* a pointer to a SrcList */
28651
+#define etSRCITEM 12 /* a pointer to a SrcItem */
28652
#define etPOINTER 13 /* The %p conversion */
28653
#define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
28654
#define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
@@ -28238,10 +28714,16 @@ static const et_info fmtinfo[] = {
28714
28715
/* All the rest are undocumented and are for internal use only */
28716
{ 'T', 0, 0, etTOKEN, 0, 0 },
28241
- { 'S', 0, 0, etSRCLIST, 0, 0 },
28717
+ { 'S', 0, 0, etSRCITEM, 0, 0 },
28718
{ 'r', 10, 1, etORDINAL, 0, 0 },
28719
};
28720
28721
+/* Notes:
28722
+**
28723
+** %S Takes a pointer to SrcItem. Shows name or database.name
28724
+** %!S Like %S but prefer the zName over the zAlias
28725
+*/
28726
+
28727
/* Floating point constants used for rounding */
28728
static const double arRound[] = {
28729
5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
@@ -28570,11 +29052,10 @@ SQLITE_API void sqlite3_str_vappendf(
29052
v = va_arg(ap,int);
29053
}
29054
if( v<0 ){
28573
- if( v==SMALLEST_INT64 ){
28574
- longvalue = ((u64)1)<<63;
28575
- }else{
28576
- longvalue = -v;
28577
- }
29055
+ testcase( v==SMALLEST_INT64 );
29056
+ testcase( v==(-1) );
29057
+ longvalue = ~v;
29058
+ longvalue++;
29059
prefix = '-';
29060
}else{
29061
longvalue = v;
@@ -28997,21 +29478,24 @@ SQLITE_API void sqlite3_str_vappendf(
29478
length = width = 0;
29479
break;
29480
}
29000
- case etSRCLIST: {
29001
- SrcList *pSrc;
29002
- int k;
29003
- struct SrcList_item *pItem;
29481
+ case etSRCITEM: {
29482
+ SrcItem *pItem;
29483
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
29005
- pSrc = va_arg(ap, SrcList*);
29006
- k = va_arg(ap, int);
29007
- pItem = &pSrc->a[k];
29484
+ pItem = va_arg(ap, SrcItem*);
29485
assert( bArgList==0 );
29009
- assert( k>=0 && k<pSrc->nSrc );
29010
- if( pItem->zDatabase ){
29011
- sqlite3_str_appendall(pAccum, pItem->zDatabase);
29012
- sqlite3_str_append(pAccum, ".", 1);
29486
+ if( pItem->zAlias && !flag_altform2 ){
29487
+ sqlite3_str_appendall(pAccum, pItem->zAlias);
29488
+ }else if( pItem->zName ){
29489
+ if( pItem->zDatabase ){
29490
+ sqlite3_str_appendall(pAccum, pItem->zDatabase);
29491
+ sqlite3_str_append(pAccum, ".", 1);
29492
+ }
29493
+ sqlite3_str_appendall(pAccum, pItem->zName);
29494
+ }else if( pItem->zAlias ){
29495
+ sqlite3_str_appendall(pAccum, pItem->zAlias);
29496
+ }else if( ALWAYS(pItem->pSelect) ){
29497
+ sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
29498
}
29014
- sqlite3_str_appendall(pAccum, pItem->zName);
29499
length = width = 0;
29500
break;
29501
}
@@ -29065,7 +29549,7 @@ static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
29549
}else{
29550
char *zOld = isMalloced(p) ? p->zText : 0;
29551
i64 szNew = p->nChar;
29068
- szNew += N + 1;
29552
+ szNew += (sqlite3_int64)N + 1;
29553
if( szNew+p->nChar<=p->mxAlloc ){
29554
/* Force exponential buffer size growth as long as it does not overflow,
29555
** to avoid having to call this routine too often */
@@ -29568,7 +30052,10 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
30052
}
30053
sqlite3_str_appendf(&x, ")");
30054
}
29571
- sqlite3_str_appendf(&x, " AS");
30055
+ if( pCte->pUse ){
30056
+ sqlite3_str_appendf(&x, " (pUse=0x%p, nUse=%d)", pCte->pUse,
30057
+ pCte->pUse->nUse);
30058
+ }
30059
sqlite3StrAccumFinish(&x);
30060
sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
30061
sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
@@ -29584,29 +30071,25 @@ SQLITE_PRIVATE void sqlite3TreeViewWith(TreeView *pView, const With *pWith, u8 m
30071
SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc){
30072
int i;
30073
for(i=0; i<pSrc->nSrc; i++){
29587
- const struct SrcList_item *pItem = &pSrc->a[i];
30074
+ const SrcItem *pItem = &pSrc->a[i];
30075
StrAccum x;
30076
char zLine[100];
30077
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
29591
- sqlite3_str_appendf(&x, "{%d:*}", pItem->iCursor);
29592
- if( pItem->zDatabase ){
29593
- sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
29594
- }else if( pItem->zName ){
29595
- sqlite3_str_appendf(&x, " %s", pItem->zName);
29596
- }
30078
+ x.printfFlags |= SQLITE_PRINTF_INTERNAL;
30079
+ sqlite3_str_appendf(&x, "{%d:*} %!S", pItem->iCursor, pItem);
30080
if( pItem->pTab ){
30081
sqlite3_str_appendf(&x, " tab=%Q nCol=%d ptr=%p used=%llx",
30082
pItem->pTab->zName, pItem->pTab->nCol, pItem->pTab, pItem->colUsed);
30083
}
29601
- if( pItem->zAlias ){
29602
- sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
29603
- }
30084
if( pItem->fg.jointype & JT_LEFT ){
30085
sqlite3_str_appendf(&x, " LEFT-JOIN");
30086
}
30087
if( pItem->fg.fromDDL ){
30088
sqlite3_str_appendf(&x, " DDL");
30089
}
30090
+ if( pItem->fg.isCte ){
30091
+ sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse);
30092
+ }
30093
sqlite3StrAccumFinish(&x);
30094
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
30095
if( pItem->pSelect ){
@@ -30164,6 +30647,14 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
30647
sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
30648
break;
30649
}
30650
+ case TK_ERROR: {
30651
+ Expr tmp;
30652
+ sqlite3TreeViewLine(pView, "ERROR");
30653
+ tmp = *pExpr;
30654
+ tmp.op = pExpr->op2;
30655
+ sqlite3TreeViewExpr(pView, &tmp, 0);
30656
+ break;
30657
+ }
30658
default: {
30659
sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
30660
break;
@@ -30313,11 +30804,16 @@ SQLITE_API void sqlite3_randomness(int N, void *pBuf){
30804
** number generator) not as an encryption device.
30805
*/
30806
if( !wsdPrng.isInit ){
30807
+ sqlite3_vfs *pVfs = sqlite3_vfs_find(0);
30808
int i;
30809
char k[256];
30810
wsdPrng.j = 0;
30811
wsdPrng.i = 0;
30320
- sqlite3OsRandomness(sqlite3_vfs_find(0), 256, k);
30812
+ if( NEVER(pVfs==0) ){
30813
+ memset(k, 0, sizeof(k));
30814
+ }else{
30815
+ sqlite3OsRandomness(pVfs, 256, k);
30816
+ }
30817
for(i=0; i<256; i++){
30818
wsdPrng.s[i] = (u8)i;
30819
}
@@ -31303,6 +31799,16 @@ SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code){
31799
if( err_code || db->pErr ) sqlite3ErrorFinish(db, err_code);
31800
}
31801
31802
+/*
31803
+** The equivalent of sqlite3Error(db, SQLITE_OK). Clear the error state
31804
+** and error message.
31805
+*/
31806
+SQLITE_PRIVATE void sqlite3ErrorClear(sqlite3 *db){
31807
+ assert( db!=0 );
31808
+ db->errCode = SQLITE_OK;
31809
+ if( db->pErr ) sqlite3ValueSetNull(db->pErr);
31810
+}
31811
+
31812
/*
31813
** Load the sqlite3.iSysErrno field if that is an appropriate thing
31814
** to do based on the SQLite error code in rc.
@@ -31870,6 +32376,7 @@ SQLITE_PRIVATE int sqlite3Atoi64(const char *zNum, i64 *pNum, int length, u8 enc
32376
incr = 1;
32377
}else{
32378
incr = 2;
32379
+ length &= ~1;
32380
assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
32381
for(i=3-enc; i<length && zNum[i]==0; i+=2){}
32382
nonNum = i<length;
@@ -33226,7 +33733,7 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
33733
/* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
33734
/* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
33735
/* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
33229
- /* 58 */ "ElseNotEq" OpHelp(""),
33736
+ /* 58 */ "ElseEq" OpHelp(""),
33737
/* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
33738
/* 60 */ "IncrVacuum" OpHelp(""),
33739
/* 61 */ "VNext" OpHelp(""),
@@ -33248,102 +33755,106 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
33755
/* 77 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
33756
/* 78 */ "SCopy" OpHelp("r[P2]=r[P1]"),
33757
/* 79 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
33251
- /* 80 */ "ResultRow" OpHelp("output=r[P1@P2]"),
33252
- /* 81 */ "CollSeq" OpHelp(""),
33253
- /* 82 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
33254
- /* 83 */ "RealAffinity" OpHelp(""),
33255
- /* 84 */ "Cast" OpHelp("affinity(r[P1])"),
33256
- /* 85 */ "Permutation" OpHelp(""),
33257
- /* 86 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
33258
- /* 87 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
33259
- /* 88 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
33260
- /* 89 */ "Column" OpHelp("r[P3]=PX"),
33261
- /* 90 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
33262
- /* 91 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
33263
- /* 92 */ "Count" OpHelp("r[P2]=count()"),
33264
- /* 93 */ "ReadCookie" OpHelp(""),
33265
- /* 94 */ "SetCookie" OpHelp(""),
33266
- /* 95 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
33267
- /* 96 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
33268
- /* 97 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
33269
- /* 98 */ "OpenDup" OpHelp(""),
33270
- /* 99 */ "OpenAutoindex" OpHelp("nColumn=P2"),
33271
- /* 100 */ "OpenEphemeral" OpHelp("nColumn=P2"),
33272
- /* 101 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
33273
- /* 102 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
33274
- /* 103 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
33275
- /* 104 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
33276
- /* 105 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
33277
- /* 106 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
33278
- /* 107 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
33279
- /* 108 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
33280
- /* 109 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
33281
- /* 110 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
33282
- /* 111 */ "SorterOpen" OpHelp(""),
33283
- /* 112 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
33284
- /* 113 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
33285
- /* 114 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
33286
- /* 115 */ "String8" OpHelp("r[P2]='P4'"),
33287
- /* 116 */ "Close" OpHelp(""),
33288
- /* 117 */ "ColumnsUsed" OpHelp(""),
33289
- /* 118 */ "SeekHit" OpHelp("seekHit=P2"),
33290
- /* 119 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
33291
- /* 120 */ "NewRowid" OpHelp("r[P2]=rowid"),
33292
- /* 121 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
33293
- /* 122 */ "Delete" OpHelp(""),
33294
- /* 123 */ "ResetCount" OpHelp(""),
33295
- /* 124 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
33296
- /* 125 */ "SorterData" OpHelp("r[P2]=data"),
33297
- /* 126 */ "RowData" OpHelp("r[P2]=data"),
33298
- /* 127 */ "Rowid" OpHelp("r[P2]=rowid"),
33299
- /* 128 */ "NullRow" OpHelp(""),
33300
- /* 129 */ "SeekEnd" OpHelp(""),
33301
- /* 130 */ "IdxInsert" OpHelp("key=r[P2]"),
33302
- /* 131 */ "SorterInsert" OpHelp("key=r[P2]"),
33303
- /* 132 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
33304
- /* 133 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
33305
- /* 134 */ "IdxRowid" OpHelp("r[P2]=rowid"),
33306
- /* 135 */ "FinishSeek" OpHelp(""),
33307
- /* 136 */ "Destroy" OpHelp(""),
33308
- /* 137 */ "Clear" OpHelp(""),
33309
- /* 138 */ "ResetSorter" OpHelp(""),
33310
- /* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
33311
- /* 140 */ "SqlExec" OpHelp(""),
33312
- /* 141 */ "ParseSchema" OpHelp(""),
33313
- /* 142 */ "LoadAnalysis" OpHelp(""),
33314
- /* 143 */ "DropTable" OpHelp(""),
33315
- /* 144 */ "DropIndex" OpHelp(""),
33316
- /* 145 */ "DropTrigger" OpHelp(""),
33317
- /* 146 */ "IntegrityCk" OpHelp(""),
33318
- /* 147 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
33319
- /* 148 */ "Param" OpHelp(""),
33320
- /* 149 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33321
- /* 150 */ "Real" OpHelp("r[P2]=P4"),
33322
- /* 151 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
33323
- /* 152 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
33324
- /* 153 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
33325
- /* 154 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
33326
- /* 155 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
33327
- /* 156 */ "AggValue" OpHelp("r[P3]=value N=P2"),
33328
- /* 157 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
33329
- /* 158 */ "Expire" OpHelp(""),
33330
- /* 159 */ "CursorLock" OpHelp(""),
33331
- /* 160 */ "CursorUnlock" OpHelp(""),
33332
- /* 161 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
33333
- /* 162 */ "VBegin" OpHelp(""),
33334
- /* 163 */ "VCreate" OpHelp(""),
33335
- /* 164 */ "VDestroy" OpHelp(""),
33336
- /* 165 */ "VOpen" OpHelp(""),
33337
- /* 166 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
33338
- /* 167 */ "VRename" OpHelp(""),
33339
- /* 168 */ "Pagecount" OpHelp(""),
33340
- /* 169 */ "MaxPgcnt" OpHelp(""),
33341
- /* 170 */ "Trace" OpHelp(""),
33342
- /* 171 */ "CursorHint" OpHelp(""),
33343
- /* 172 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
33344
- /* 173 */ "Noop" OpHelp(""),
33345
- /* 174 */ "Explain" OpHelp(""),
33346
- /* 175 */ "Abortable" OpHelp(""),
33758
+ /* 80 */ "ChngCntRow" OpHelp("output=r[P1]"),
33759
+ /* 81 */ "ResultRow" OpHelp("output=r[P1@P2]"),
33760
+ /* 82 */ "CollSeq" OpHelp(""),
33761
+ /* 83 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
33762
+ /* 84 */ "RealAffinity" OpHelp(""),
33763
+ /* 85 */ "Cast" OpHelp("affinity(r[P1])"),
33764
+ /* 86 */ "Permutation" OpHelp(""),
33765
+ /* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
33766
+ /* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
33767
+ /* 89 */ "ZeroOrNull" OpHelp("r[P2] = 0 OR NULL"),
33768
+ /* 90 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
33769
+ /* 91 */ "Column" OpHelp("r[P3]=PX"),
33770
+ /* 92 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
33771
+ /* 93 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
33772
+ /* 94 */ "Count" OpHelp("r[P2]=count()"),
33773
+ /* 95 */ "ReadCookie" OpHelp(""),
33774
+ /* 96 */ "SetCookie" OpHelp(""),
33775
+ /* 97 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
33776
+ /* 98 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
33777
+ /* 99 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
33778
+ /* 100 */ "OpenDup" OpHelp(""),
33779
+ /* 101 */ "OpenAutoindex" OpHelp("nColumn=P2"),
33780
+ /* 102 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
33781
+ /* 103 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
33782
+ /* 104 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
33783
+ /* 105 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
33784
+ /* 106 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
33785
+ /* 107 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
33786
+ /* 108 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
33787
+ /* 109 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
33788
+ /* 110 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
33789
+ /* 111 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
33790
+ /* 112 */ "OpenEphemeral" OpHelp("nColumn=P2"),
33791
+ /* 113 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
33792
+ /* 114 */ "SorterOpen" OpHelp(""),
33793
+ /* 115 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
33794
+ /* 116 */ "String8" OpHelp("r[P2]='P4'"),
33795
+ /* 117 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
33796
+ /* 118 */ "Close" OpHelp(""),
33797
+ /* 119 */ "ColumnsUsed" OpHelp(""),
33798
+ /* 120 */ "SeekScan" OpHelp("Scan-ahead up to P1 rows"),
33799
+ /* 121 */ "SeekHit" OpHelp("set P2<=seekHit<=P3"),
33800
+ /* 122 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
33801
+ /* 123 */ "NewRowid" OpHelp("r[P2]=rowid"),
33802
+ /* 124 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
33803
+ /* 125 */ "RowCell" OpHelp(""),
33804
+ /* 126 */ "Delete" OpHelp(""),
33805
+ /* 127 */ "ResetCount" OpHelp(""),
33806
+ /* 128 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
33807
+ /* 129 */ "SorterData" OpHelp("r[P2]=data"),
33808
+ /* 130 */ "RowData" OpHelp("r[P2]=data"),
33809
+ /* 131 */ "Rowid" OpHelp("r[P2]=rowid"),
33810
+ /* 132 */ "NullRow" OpHelp(""),
33811
+ /* 133 */ "SeekEnd" OpHelp(""),
33812
+ /* 134 */ "IdxInsert" OpHelp("key=r[P2]"),
33813
+ /* 135 */ "SorterInsert" OpHelp("key=r[P2]"),
33814
+ /* 136 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
33815
+ /* 137 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
33816
+ /* 138 */ "IdxRowid" OpHelp("r[P2]=rowid"),
33817
+ /* 139 */ "FinishSeek" OpHelp(""),
33818
+ /* 140 */ "Destroy" OpHelp(""),
33819
+ /* 141 */ "Clear" OpHelp(""),
33820
+ /* 142 */ "ResetSorter" OpHelp(""),
33821
+ /* 143 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
33822
+ /* 144 */ "SqlExec" OpHelp(""),
33823
+ /* 145 */ "ParseSchema" OpHelp(""),
33824
+ /* 146 */ "LoadAnalysis" OpHelp(""),
33825
+ /* 147 */ "DropTable" OpHelp(""),
33826
+ /* 148 */ "DropIndex" OpHelp(""),
33827
+ /* 149 */ "DropTrigger" OpHelp(""),
33828
+ /* 150 */ "IntegrityCk" OpHelp(""),
33829
+ /* 151 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
33830
+ /* 152 */ "Real" OpHelp("r[P2]=P4"),
33831
+ /* 153 */ "Param" OpHelp(""),
33832
+ /* 154 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
33833
+ /* 155 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
33834
+ /* 156 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
33835
+ /* 157 */ "AggInverse" OpHelp("accum=r[P3] inverse(r[P2@P5])"),
33836
+ /* 158 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
33837
+ /* 159 */ "AggStep1" OpHelp("accum=r[P3] step(r[P2@P5])"),
33838
+ /* 160 */ "AggValue" OpHelp("r[P3]=value N=P2"),
33839
+ /* 161 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
33840
+ /* 162 */ "Expire" OpHelp(""),
33841
+ /* 163 */ "CursorLock" OpHelp(""),
33842
+ /* 164 */ "CursorUnlock" OpHelp(""),
33843
+ /* 165 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
33844
+ /* 166 */ "VBegin" OpHelp(""),
33845
+ /* 167 */ "VCreate" OpHelp(""),
33846
+ /* 168 */ "VDestroy" OpHelp(""),
33847
+ /* 169 */ "VOpen" OpHelp(""),
33848
+ /* 170 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
33849
+ /* 171 */ "VRename" OpHelp(""),
33850
+ /* 172 */ "Pagecount" OpHelp(""),
33851
+ /* 173 */ "MaxPgcnt" OpHelp(""),
33852
+ /* 174 */ "Trace" OpHelp(""),
33853
+ /* 175 */ "CursorHint" OpHelp(""),
33854
+ /* 176 */ "ReleaseReg" OpHelp("release r[P1@P2] mask P3"),
33855
+ /* 177 */ "Noop" OpHelp(""),
33856
+ /* 178 */ "Explain" OpHelp(""),
33857
+ /* 179 */ "Abortable" OpHelp(""),
33858
};
33859
return azName[i];
33860
}
@@ -33475,7 +33986,8 @@ SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){
33986
# if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
33987
(__IPHONE_OS_VERSION_MIN_REQUIRED > 2000))
33988
# if (!defined(TARGET_OS_EMBEDDED) || (TARGET_OS_EMBEDDED==0)) \
33478
- && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))
33989
+ && (!defined(TARGET_IPHONE_SIMULATOR) || (TARGET_IPHONE_SIMULATOR==0))\
33990
+ && (!defined(TARGET_OS_MACCATALYST) || (TARGET_OS_MACCATALYST==0))
33991
# undef HAVE_GETHOSTUUID
33992
# define HAVE_GETHOSTUUID 1
33993
# else
@@ -35095,6 +35607,9 @@ static int unixCheckReservedLock(sqlite3_file *id, int *pResOut){
35607
return rc;
35608
}
35609
35610
+/* Forward declaration*/
35611
+static int unixSleep(sqlite3_vfs*,int);
35612
+
35613
/*
35614
** Set a posix-advisory-lock.
35615
**
@@ -35124,7 +35639,7 @@ static int osSetPosixAdvisoryLock(
35639
** generic posix, however, there is no such API. So we simply try the
35640
** lock once every millisecond until either the timeout expires, or until
35641
** the lock is obtained. */
35127
- usleep(1000);
35642
+ unixSleep(0,1000);
35643
rc = osFcntl(h,F_SETLK,pLock);
35644
tm--;
35645
}
@@ -35695,6 +36210,7 @@ static int unixClose(sqlite3_file *id){
36210
}
36211
sqlite3_mutex_leave(pInode->pLockMutex);
36212
releaseInodeInfo(pFile);
36213
+ assert( pFile->pShm==0 );
36214
rc = closeUnixFile(id);
36215
unixLeaveMutex();
36216
return rc;
@@ -36921,7 +37437,24 @@ static int unixRead(
37437
if( got==amt ){
37438
return SQLITE_OK;
37439
}else if( got<0 ){
36924
- /* lastErrno set by seekAndRead */
37440
+ /* pFile->lastErrno has been set by seekAndRead().
37441
+ ** Usually we return SQLITE_IOERR_READ here, though for some
37442
+ ** kinds of errors we return SQLITE_IOERR_CORRUPTFS. The
37443
+ ** SQLITE_IOERR_CORRUPTFS will be converted into SQLITE_CORRUPT
37444
+ ** prior to returning to the application by the sqlite3ApiExit()
37445
+ ** routine.
37446
+ */
37447
+ switch( pFile->lastErrno ){
37448
+ case ERANGE:
37449
+ case EIO:
37450
+#ifdef ENXIO
37451
+ case ENXIO:
37452
+#endif
37453
+#ifdef EDEVERR
37454
+ case EDEVERR:
37455
+#endif
37456
+ return SQLITE_IOERR_CORRUPTFS;
37457
+ }
37458
return SQLITE_IOERR_READ;
37459
}else{
37460
storeLastErrno(pFile, 0); /* not a system error */
@@ -37480,6 +38013,7 @@ static void unixModeBit(unixFile *pFile, unsigned char mask, int *pArg){
38013
38014
/* Forward declaration */
38015
static int unixGetTempname(int nBuf, char *zBuf);
38016
+static int unixFcntlExternalReader(unixFile*, int*);
38017
38018
/*
38019
** Information and control of an open file handle.
@@ -37596,6 +38130,10 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
38130
return proxyFileControl(id,op,pArg);
38131
}
38132
#endif /* SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__) */
38133
+
38134
+ case SQLITE_FCNTL_EXTERNAL_READER: {
38135
+ return unixFcntlExternalReader((unixFile*)id, (int*)pArg);
38136
+ }
38137
}
38138
return SQLITE_NOTFOUND;
38139
}
@@ -37805,6 +38343,7 @@ struct unixShmNode {
38343
char **apRegion; /* Array of mapped shared-memory regions */
38344
int nRef; /* Number of unixShm objects pointing to this */
38345
unixShm *pFirst; /* All unixShm objects pointing to this */
38346
+ int aLock[SQLITE_SHM_NLOCK]; /* # shared locks on slot, -1==excl lock */
38347
#ifdef SQLITE_DEBUG
38348
u8 exclMask; /* Mask of exclusive locks held */
38349
u8 sharedMask; /* Mask of shared locks held */
@@ -37840,6 +38379,40 @@ struct unixShm {
38379
#define UNIX_SHM_BASE ((22+SQLITE_SHM_NLOCK)*4) /* first lock byte */
38380
#define UNIX_SHM_DMS (UNIX_SHM_BASE+SQLITE_SHM_NLOCK) /* deadman switch */
38381
38382
+/*
38383
+** Use F_GETLK to check whether or not there are any readers with open
38384
+** wal-mode transactions in other processes on database file pFile. If
38385
+** no error occurs, return SQLITE_OK and set (*piOut) to 1 if there are
38386
+** such transactions, or 0 otherwise. If an error occurs, return an
38387
+** SQLite error code. The final value of *piOut is undefined in this
38388
+** case.
38389
+*/
38390
+static int unixFcntlExternalReader(unixFile *pFile, int *piOut){
38391
+ int rc = SQLITE_OK;
38392
+ *piOut = 0;
38393
+ if( pFile->pShm){
38394
+ unixShmNode *pShmNode = pFile->pShm->pShmNode;
38395
+ struct flock f;
38396
+
38397
+ memset(&f, 0, sizeof(f));
38398
+ f.l_type = F_WRLCK;
38399
+ f.l_whence = SEEK_SET;
38400
+ f.l_start = UNIX_SHM_BASE + 3;
38401
+ f.l_len = SQLITE_SHM_NLOCK - 3;
38402
+
38403
+ sqlite3_mutex_enter(pShmNode->pShmMutex);
38404
+ if( osFcntl(pShmNode->hShm, F_GETLK, &f)<0 ){
38405
+ rc = SQLITE_IOERR_LOCK;
38406
+ }else{
38407
+ *piOut = (f.l_type!=F_UNLCK);
38408
+ }
38409
+ sqlite3_mutex_leave(pShmNode->pShmMutex);
38410
+ }
38411
+
38412
+ return rc;
38413
+}
38414
+
38415
+
38416
/*
38417
** Apply posix advisory locks for all bytes from ofst through ofst+n-1.
38418
**
@@ -38345,6 +38918,38 @@ shmpage_out:
38918
return rc;
38919
}
38920
38921
+/*
38922
+** Check that the pShmNode->aLock[] array comports with the locking bitmasks
38923
+** held by each client. Return true if it does, or false otherwise. This
38924
+** is to be used in an assert(). e.g.
38925
+**
38926
+** assert( assertLockingArrayOk(pShmNode) );
38927
+*/
38928
+#ifdef SQLITE_DEBUG
38929
+static int assertLockingArrayOk(unixShmNode *pShmNode){
38930
+ unixShm *pX;
38931
+ int aLock[SQLITE_SHM_NLOCK];
38932
+ assert( sqlite3_mutex_held(pShmNode->pShmMutex) );
38933
+
38934
+ memset(aLock, 0, sizeof(aLock));
38935
+ for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
38936
+ int i;
38937
+ for(i=0; i<SQLITE_SHM_NLOCK; i++){
38938
+ if( pX->exclMask & (1<<i) ){
38939
+ assert( aLock[i]==0 );
38940
+ aLock[i] = -1;
38941
+ }else if( pX->sharedMask & (1<<i) ){
38942
+ assert( aLock[i]>=0 );
38943
+ aLock[i]++;
38944
+ }
38945
+ }
38946
+ }
38947
+
38948
+ assert( 0==memcmp(pShmNode->aLock, aLock, sizeof(aLock)) );
38949
+ return (memcmp(pShmNode->aLock, aLock, sizeof(aLock))==0);
38950
+}
38951
+#endif
38952
+
38953
/*
38954
** Change the lock state for a shared-memory segment.
38955
**
@@ -38361,10 +38966,10 @@ static int unixShmLock(
38966
){
38967
unixFile *pDbFd = (unixFile*)fd; /* Connection holding shared memory */
38968
unixShm *p = pDbFd->pShm; /* The shared memory being locked */
38364
- unixShm *pX; /* For looping over all siblings */
38969
unixShmNode *pShmNode = p->pShmNode; /* The underlying file iNode */
38970
int rc = SQLITE_OK; /* Result code */
38971
u16 mask; /* Mask of locks to take or release */
38972
+ int *aLock = pShmNode->aLock;
38973
38974
assert( pShmNode==pDbFd->pInode->pShmNode );
38975
assert( pShmNode->pInode==pDbFd->pInode );
@@ -38403,78 +39008,76 @@ static int unixShmLock(
39008
mask = (1<<(ofst+n)) - (1<<ofst);
39009
assert( n>1 || mask==(1<<ofst) );
39010
sqlite3_mutex_enter(pShmNode->pShmMutex);
39011
+ assert( assertLockingArrayOk(pShmNode) );
39012
if( flags & SQLITE_SHM_UNLOCK ){
38407
- u16 allMask = 0; /* Mask of locks held by siblings */
39013
+ if( (p->exclMask|p->sharedMask) & mask ){
39014
+ int ii;
39015
+ int bUnlock = 1;
39016
38409
- /* See if any siblings hold this same lock */
38410
- for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
38411
- if( pX==p ) continue;
38412
- assert( (pX->exclMask & (p->exclMask|p->sharedMask))==0 );
38413
- allMask |= pX->sharedMask;
38414
- }
39017
+ for(ii=ofst; ii<ofst+n; ii++){
39018
+ if( aLock[ii]>((p->sharedMask & (1<<ii)) ? 1 : 0) ){
39019
+ bUnlock = 0;
39020
+ }
39021
+ }
39022
38416
- /* Unlock the system-level locks */
38417
- if( (mask & allMask)==0 ){
38418
- rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n);
38419
- }else{
38420
- rc = SQLITE_OK;
38421
- }
39023
+ if( bUnlock ){
39024
+ rc = unixShmSystemLock(pDbFd, F_UNLCK, ofst+UNIX_SHM_BASE, n);
39025
+ if( rc==SQLITE_OK ){
39026
+ memset(&aLock[ofst], 0, sizeof(int)*n);
39027
+ }
39028
+ }else if( ALWAYS(p->sharedMask & (1<<ofst)) ){
39029
+ assert( n==1 && aLock[ofst]>1 );
39030
+ aLock[ofst]--;
39031
+ }
39032
38423
- /* Undo the local locks */
38424
- if( rc==SQLITE_OK ){
38425
- p->exclMask &= ~mask;
38426
- p->sharedMask &= ~mask;
39033
+ /* Undo the local locks */
39034
+ if( rc==SQLITE_OK ){
39035
+ p->exclMask &= ~mask;
39036
+ p->sharedMask &= ~mask;
39037
+ }
39038
}
39039
}else if( flags & SQLITE_SHM_SHARED ){
38429
- u16 allShared = 0; /* Union of locks held by connections other than "p" */
38430
-
38431
- /* Find out which shared locks are already held by sibling connections.
38432
- ** If any sibling already holds an exclusive lock, go ahead and return
38433
- ** SQLITE_BUSY.
38434
- */
38435
- for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
38436
- if( (pX->exclMask & mask)!=0 ){
39040
+ assert( n==1 );
39041
+ assert( (p->exclMask & (1<<ofst))==0 );
39042
+ if( (p->sharedMask & mask)==0 ){
39043
+ if( aLock[ofst]<0 ){
39044
rc = SQLITE_BUSY;
38438
- break;
38439
- }
38440
- allShared |= pX->sharedMask;
38441
- }
38442
-
38443
- /* Get shared locks at the system level, if necessary */
38444
- if( rc==SQLITE_OK ){
38445
- if( (allShared & mask)==0 ){
39045
+ }else if( aLock[ofst]==0 ){
39046
rc = unixShmSystemLock(pDbFd, F_RDLCK, ofst+UNIX_SHM_BASE, n);
38447
- }else{
38448
- rc = SQLITE_OK;
39047
}
38450
- }
39048
38452
- /* Get the local shared locks */
38453
- if( rc==SQLITE_OK ){
38454
- p->sharedMask |= mask;
39049
+ /* Get the local shared locks */
39050
+ if( rc==SQLITE_OK ){
39051
+ p->sharedMask |= mask;
39052
+ aLock[ofst]++;
39053
+ }
39054
}
39055
}else{
39056
/* Make sure no sibling connections hold locks that will block this
38458
- ** lock. If any do, return SQLITE_BUSY right away.
38459
- */
38460
- for(pX=pShmNode->pFirst; pX; pX=pX->pNext){
38461
- if( (pX->exclMask & mask)!=0 || (pX->sharedMask & mask)!=0 ){
39057
+ ** lock. If any do, return SQLITE_BUSY right away. */
39058
+ int ii;
39059
+ for(ii=ofst; ii<ofst+n; ii++){
39060
+ assert( (p->sharedMask & mask)==0 );
39061
+ if( ALWAYS((p->exclMask & (1<<ii))==0) && aLock[ii] ){
39062
rc = SQLITE_BUSY;
39063
break;
39064
}
39065
}
39066
38467
- /* Get the exclusive locks at the system level. Then if successful
38468
- ** also mark the local connection as being locked.
38469
- */
39067
+ /* Get the exclusive locks at the system level. Then if successful
39068
+ ** also update the in-memory values. */
39069
if( rc==SQLITE_OK ){
39070
rc = unixShmSystemLock(pDbFd, F_WRLCK, ofst+UNIX_SHM_BASE, n);
39071
if( rc==SQLITE_OK ){
39072
assert( (p->sharedMask & mask)==0 );
39073
p->exclMask |= mask;
39074
+ for(ii=ofst; ii<ofst+n; ii++){
39075
+ aLock[ii] = -1;
39076
+ }
39077
}
39078
}
39079
}
39080
+ assert( assertLockingArrayOk(pShmNode) );
39081
sqlite3_mutex_leave(pShmNode->pShmMutex);
39082
OSTRACE(("SHM-LOCK shmid-%d, pid-%d got %03x,%03x\n",
39083
p->id, osGetpid(0), p->sharedMask, p->exclMask));
@@ -39851,7 +40454,27 @@ static int unixAccess(
40454
}
40455
40456
/*
40457
+** If the last component of the pathname in z[0]..z[j-1] is something
40458
+** other than ".." then back it out and return true. If the last
40459
+** component is empty or if it is ".." then return false.
40460
+*/
40461
+static int unixBackupDir(const char *z, int *pJ){
40462
+ int j = *pJ;
40463
+ int i;
40464
+ if( j<=0 ) return 0;
40465
+ for(i=j-1; i>0 && z[i-1]!='/'; i--){}
40466
+ if( i==0 ) return 0;
40467
+ if( z[i]=='.' && i==j-2 && z[i+1]=='.' ) return 0;
40468
+ *pJ = i-1;
40469
+ return 1;
40470
+}
40471
+
40472
+/*
40473
+** Convert a relative pathname into a full pathname. Also
40474
+** simplify the pathname as follows:
40475
**
40476
+** Remove all instances of /./
40477
+** Remove all isntances of /X/../ for any X
40478
*/
40479
static int mkFullPathname(
40480
const char *zPath, /* Input path */
@@ -39860,6 +40483,7 @@ static int mkFullPathname(
40483
){
40484
int nPath = sqlite3Strlen30(zPath);
40485
int iOff = 0;
40486
+ int i, j;
40487
if( zPath[0]!='/' ){
40488
if( osGetcwd(zOut, nOut-2)==0 ){
40489
return unixLogError(SQLITE_CANTOPEN_BKPT, "getcwd", zPath);
@@ -39874,6 +40498,41 @@ static int mkFullPathname(
40498
return SQLITE_CANTOPEN_BKPT;
40499
}
40500
sqlite3_snprintf(nOut-iOff, &zOut[iOff], "%s", zPath);
40501
+
40502
+ /* Remove duplicate '/' characters. Except, two // at the beginning
40503
+ ** of a pathname is allowed since this is important on windows. */
40504
+ for(i=j=1; zOut[i]; i++){
40505
+ zOut[j++] = zOut[i];
40506
+ while( zOut[i]=='/' && zOut[i+1]=='/' ) i++;
40507
+ }
40508
+ zOut[j] = 0;
40509
+
40510
+ assert( zOut[0]=='/' );
40511
+ for(i=j=0; zOut[i]; i++){
40512
+ if( zOut[i]=='/' ){
40513
+ /* Skip over internal "/." directory components */
40514
+ if( zOut[i+1]=='.' && zOut[i+2]=='/' ){
40515
+ i += 1;
40516
+ continue;
40517
+ }
40518
+
40519
+ /* If this is a "/.." directory component then back out the
40520
+ ** previous term of the directory if it is something other than "..".
40521
+ */
40522
+ if( zOut[i+1]=='.'
40523
+ && zOut[i+2]=='.'
40524
+ && zOut[i+3]=='/'
40525
+ && unixBackupDir(zOut, &j)
40526
+ ){
40527
+ i += 2;
40528
+ continue;
40529
+ }
40530
+ }
40531
+ if( ALWAYS(j>=0) ) zOut[j] = zOut[i];
40532
+ j++;
40533
+ }
40534
+ if( NEVER(j==0) ) zOut[j++] = '/';
40535
+ zOut[j] = 0;
40536
return SQLITE_OK;
40537
}
40538
@@ -40094,7 +40753,8 @@ static int unixSleep(sqlite3_vfs *NotUsed, int microseconds){
40753
UNUSED_PARAMETER(NotUsed);
40754
return microseconds;
40755
#elif defined(HAVE_USLEEP) && HAVE_USLEEP
40097
- usleep(microseconds);
40756
+ if( microseconds>=1000000 ) sleep(microseconds/1000000);
40757
+ if( microseconds%1000000 ) usleep(microseconds%1000000);
40758
UNUSED_PARAMETER(NotUsed);
40759
return microseconds;
40760
#else
@@ -40667,7 +41327,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
41327
41328
if( nTries==1 ){
41329
conchModTime = buf.st_mtimespec;
40670
- usleep(500000); /* wait 0.5 sec and try the lock again*/
41330
+ unixSleep(0,500000); /* wait 0.5 sec and try the lock again*/
41331
continue;
41332
}
41333
@@ -40693,7 +41353,7 @@ static int proxyConchLock(unixFile *pFile, uuid_t myHostID, int lockType){
41353
/* don't break the lock on short read or a version mismatch */
41354
return SQLITE_BUSY;
41355
}
40696
- usleep(10000000); /* wait 10 sec and try the lock again */
41356
+ unixSleep(0,10000000); /* wait 10 sec and try the lock again */
41357
continue;
41358
}
41359
@@ -41469,6 +42129,25 @@ SQLITE_API int sqlite3_os_init(void){
42129
sqlite3_vfs_register(&aVfs[i], i==0);
42130
}
42131
unixBigLock = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
42132
+
42133
+#ifndef SQLITE_OMIT_WAL
42134
+ /* Validate lock assumptions */
42135
+ assert( SQLITE_SHM_NLOCK==8 ); /* Number of available locks */
42136
+ assert( UNIX_SHM_BASE==120 ); /* Start of locking area */
42137
+ /* Locks:
42138
+ ** WRITE UNIX_SHM_BASE 120
42139
+ ** CKPT UNIX_SHM_BASE+1 121
42140
+ ** RECOVER UNIX_SHM_BASE+2 122
42141
+ ** READ-0 UNIX_SHM_BASE+3 123
42142
+ ** READ-1 UNIX_SHM_BASE+4 124
42143
+ ** READ-2 UNIX_SHM_BASE+5 125
42144
+ ** READ-3 UNIX_SHM_BASE+6 126
42145
+ ** READ-4 UNIX_SHM_BASE+7 127
42146
+ ** DMS UNIX_SHM_BASE+8 128
42147
+ */
42148
+ assert( UNIX_SHM_DMS==128 ); /* Byte offset of the deadman-switch */
42149
+#endif
42150
+
42151
return SQLITE_OK;
42152
}
42153
@@ -46814,7 +47493,11 @@ static int winOpen(
47493
dwCreationDisposition = OPEN_EXISTING;
47494
}
47495
46817
- dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
47496
+ if( 0==sqlite3_uri_boolean(zName, "exclusive", 0) ){
47497
+ dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
47498
+ }else{
47499
+ dwShareMode = 0;
47500
+ }
47501
47502
if( isDelete ){
47503
#if SQLITE_OS_WINCE
@@ -47858,31 +48541,88 @@ SQLITE_API int sqlite3_os_end(void){
48541
** sqlite3_deserialize().
48542
*/
48543
/* #include "sqliteInt.h" */
47861
-#ifdef SQLITE_ENABLE_DESERIALIZE
48544
+#ifndef SQLITE_OMIT_DESERIALIZE
48545
48546
/*
48547
** Forward declaration of objects used by this utility
48548
*/
48549
typedef struct sqlite3_vfs MemVfs;
48550
typedef struct MemFile MemFile;
48551
+typedef struct MemStore MemStore;
48552
48553
/* Access to a lower-level VFS that (might) implement dynamic loading,
48554
** access to randomness, etc.
48555
*/
48556
#define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
48557
47874
-/* An open file */
47875
-struct MemFile {
47876
- sqlite3_file base; /* IO methods */
48558
+/* Storage for a memdb file.
48559
+**
48560
+** An memdb object can be shared or separate. Shared memdb objects can be
48561
+** used by more than one database connection. Mutexes are used by shared
48562
+** memdb objects to coordinate access. Separate memdb objects are only
48563
+** connected to a single database connection and do not require additional
48564
+** mutexes.
48565
+**
48566
+** Shared memdb objects have .zFName!=0 and .pMutex!=0. They are created
48567
+** using "file:/name?vfs=memdb". The first character of the name must be
48568
+** "/" or else the object will be a separate memdb object. All shared
48569
+** memdb objects are stored in memdb_g.apMemStore[] in an arbitrary order.
48570
+**
48571
+** Separate memdb objects are created using a name that does not begin
48572
+** with "/" or using sqlite3_deserialize().
48573
+**
48574
+** Access rules for shared MemStore objects:
48575
+**
48576
+** * .zFName is initialized when the object is created and afterwards
48577
+** is unchanged until the object is destroyed. So it can be accessed
48578
+** at any time as long as we know the object is not being destroyed,
48579
+** which means while either the SQLITE_MUTEX_STATIC_VFS1 or
48580
+** .pMutex is held or the object is not part of memdb_g.apMemStore[].
48581
+**
48582
+** * Can .pMutex can only be changed while holding the
48583
+** SQLITE_MUTEX_STATIC_VFS1 mutex or while the object is not part
48584
+** of memdb_g.apMemStore[].
48585
+**
48586
+** * Other fields can only be changed while holding the .pMutex mutex
48587
+** or when the .nRef is less than zero and the object is not part of
48588
+** memdb_g.apMemStore[].
48589
+**
48590
+** * The .aData pointer has the added requirement that it can can only
48591
+** be changed (for resizing) when nMmap is zero.
48592
+**
48593
+*/
48594
+struct MemStore {
48595
sqlite3_int64 sz; /* Size of the file */
48596
sqlite3_int64 szAlloc; /* Space allocated to aData */
48597
sqlite3_int64 szMax; /* Maximum allowed size of the file */
48598
unsigned char *aData; /* content of the file */
48599
+ sqlite3_mutex *pMutex; /* Used by shared stores only */
48600
int nMmap; /* Number of memory mapped pages */
48601
unsigned mFlags; /* Flags */
48602
+ int nRdLock; /* Number of readers */
48603
+ int nWrLock; /* Number of writers. (Always 0 or 1) */
48604
+ int nRef; /* Number of users of this MemStore */
48605
+ char *zFName; /* The filename for shared stores */
48606
+};
48607
+
48608
+/* An open file */
48609
+struct MemFile {
48610
+ sqlite3_file base; /* IO methods */
48611
+ MemStore *pStore; /* The storage */
48612
int eLock; /* Most recent lock against this file */
48613
};
48614
48615
+/*
48616
+** File-scope variables for holding the memdb files that are accessible
48617
+** to multiple database connections in separate threads.
48618
+**
48619
+** Must hold SQLITE_MUTEX_STATIC_VFS1 to access any part of this object.
48620
+*/
48621
+static struct MemFS {
48622
+ int nMemStore; /* Number of shared MemStore objects */
48623
+ MemStore **apMemStore; /* Array of all shared MemStore objects */
48624
+} memdb_g;
48625
+
48626
/*
48627
** Methods for MemFile
48628
*/
@@ -47936,7 +48676,10 @@ static sqlite3_vfs memdb_vfs = {
48676
memdbSleep, /* xSleep */
48677
0, /* memdbCurrentTime, */ /* xCurrentTime */
48678
memdbGetLastError, /* xGetLastError */
47939
- memdbCurrentTimeInt64 /* xCurrentTimeInt64 */
48679
+ memdbCurrentTimeInt64, /* xCurrentTimeInt64 */
48680
+ 0, /* xSetSystemCall */
48681
+ 0, /* xGetSystemCall */
48682
+ 0, /* xNextSystemCall */
48683
};
48684
48685
static const sqlite3_io_methods memdb_io_methods = {
@@ -47961,17 +48704,68 @@ static const sqlite3_io_methods memdb_io_methods = {
48704
memdbUnfetch /* xUnfetch */
48705
};
48706
48707
+/*
48708
+** Enter/leave the mutex on a MemStore
48709
+*/
48710
+#if defined(SQLITE_THREADSAFE) && SQLITE_THREADSAFE==0
48711
+static void memdbEnter(MemStore *p){
48712
+ UNUSED_PARAMETER(p);
48713
+}
48714
+static void memdbLeave(MemStore *p){
48715
+ UNUSED_PARAMETER(p);
48716
+}
48717
+#else
48718
+static void memdbEnter(MemStore *p){
48719
+ sqlite3_mutex_enter(p->pMutex);
48720
+}
48721
+static void memdbLeave(MemStore *p){
48722
+ sqlite3_mutex_leave(p->pMutex);
48723
+}
48724
+#endif
48725
+
48726
48727
48728
/*
48729
** Close an memdb-file.
47968
-**
47969
-** The pData pointer is owned by the application, so there is nothing
47970
-** to free.
48730
+** Free the underlying MemStore object when its refcount drops to zero
48731
+** or less.
48732
*/
48733
static int memdbClose(sqlite3_file *pFile){
47973
- MemFile *p = (MemFile *)pFile;
47974
- if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ) sqlite3_free(p->aData);
48734
+ MemStore *p = ((MemFile*)pFile)->pStore;
48735
+ if( p->zFName ){
48736
+ int i;
48737
+#ifndef SQLITE_MUTEX_OMIT
48738
+ sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
48739
+#endif
48740
+ sqlite3_mutex_enter(pVfsMutex);
48741
+ for(i=0; ALWAYS(i<memdb_g.nMemStore); i++){
48742
+ if( memdb_g.apMemStore[i]==p ){
48743
+ memdbEnter(p);
48744
+ if( p->nRef==1 ){
48745
+ memdb_g.apMemStore[i] = memdb_g.apMemStore[--memdb_g.nMemStore];
48746
+ if( memdb_g.nMemStore==0 ){
48747
+ sqlite3_free(memdb_g.apMemStore);
48748
+ memdb_g.apMemStore = 0;
48749
+ }
48750
+ }
48751
+ break;
48752
+ }
48753
+ }
48754
+ sqlite3_mutex_leave(pVfsMutex);
48755
+ }else{
48756
+ memdbEnter(p);
48757
+ }
48758
+ p->nRef--;
48759
+ if( p->nRef<=0 ){
48760
+ if( p->mFlags & SQLITE_DESERIALIZE_FREEONCLOSE ){
48761
+ sqlite3_free(p->aData);
48762
+ }
48763
+ memdbLeave(p);
48764
+ sqlite3_mutex_free(p->pMutex);
48765
+ sqlite3_free(p);
48766
+ }else{
48767
+ memdbLeave(p);
48768
+ }
48769
return SQLITE_OK;
48770
}
48771
@@ -47984,20 +48778,23 @@ static int memdbRead(
48778
int iAmt,
48779
sqlite_int64 iOfst
48780
){
47987
- MemFile *p = (MemFile *)pFile;
48781
+ MemStore *p = ((MemFile*)pFile)->pStore;
48782
+ memdbEnter(p);
48783
if( iOfst+iAmt>p->sz ){
48784
memset(zBuf, 0, iAmt);
48785
if( iOfst<p->sz ) memcpy(zBuf, p->aData+iOfst, p->sz - iOfst);
48786
+ memdbLeave(p);
48787
return SQLITE_IOERR_SHORT_READ;
48788
}
48789
memcpy(zBuf, p->aData+iOfst, iAmt);
48790
+ memdbLeave(p);
48791
return SQLITE_OK;
48792
}
48793
48794
/*
48795
** Try to enlarge the memory allocation to hold at least sz bytes
48796
*/
48000
-static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
48797
+static int memdbEnlarge(MemStore *p, sqlite3_int64 newSz){
48798
unsigned char *pNew;
48799
if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
48800
return SQLITE_FULL;
@@ -48008,7 +48805,7 @@ static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
48805
newSz *= 2;
48806
if( newSz>p->szMax ) newSz = p->szMax;
48807
pNew = sqlite3Realloc(p->aData, newSz);
48011
- if( pNew==0 ) return SQLITE_NOMEM;
48808
+ if( pNew==0 ) return SQLITE_IOERR_NOMEM;
48809
p->aData = pNew;
48810
p->szAlloc = newSz;
48811
return SQLITE_OK;
@@ -48023,19 +48820,27 @@ static int memdbWrite(
48820
int iAmt,
48821
sqlite_int64 iOfst
48822
){
48026
- MemFile *p = (MemFile *)pFile;
48027
- if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ) return SQLITE_READONLY;
48823
+ MemStore *p = ((MemFile*)pFile)->pStore;
48824
+ memdbEnter(p);
48825
+ if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ){
48826
+ /* Can't happen: memdbLock() will return SQLITE_READONLY before
48827
+ ** reaching this point */
48828
+ memdbLeave(p);
48829
+ return SQLITE_IOERR_WRITE;
48830
+ }
48831
if( iOfst+iAmt>p->sz ){
48832
int rc;
48833
if( iOfst+iAmt>p->szAlloc
48834
&& (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK
48835
){
48836
+ memdbLeave(p);
48837
return rc;
48838
}
48839
if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
48840
p->sz = iOfst+iAmt;
48841
}
48842
memcpy(p->aData+iOfst, z, iAmt);
48843
+ memdbLeave(p);
48844
return SQLITE_OK;
48845
}
48846
@@ -48047,16 +48852,24 @@ static int memdbWrite(
48852
** the size of a file, never to increase the size.
48853
*/
48854
static int memdbTruncate(sqlite3_file *pFile, sqlite_int64 size){
48050
- MemFile *p = (MemFile *)pFile;
48051
- if( NEVER(size>p->sz) ) return SQLITE_FULL;
48052
- p->sz = size;
48053
- return SQLITE_OK;
48855
+ MemStore *p = ((MemFile*)pFile)->pStore;
48856
+ int rc = SQLITE_OK;
48857
+ memdbEnter(p);
48858
+ if( NEVER(size>p->sz) ){
48859
+ rc = SQLITE_FULL;
48860
+ }else{
48861
+ p->sz = size;
48862
+ }
48863
+ memdbLeave(p);
48864
+ return rc;
48865
}
48866
48867
/*
48868
** Sync an memdb-file.
48869
*/
48870
static int memdbSync(sqlite3_file *pFile, int flags){
48871
+ UNUSED_PARAMETER(pFile);
48872
+ UNUSED_PARAMETER(flags);
48873
return SQLITE_OK;
48874
}
48875
@@ -48064,8 +48877,10 @@ static int memdbSync(sqlite3_file *pFile, int flags){
48877
** Return the current file-size of an memdb-file.
48878
*/
48879
static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
48067
- MemFile *p = (MemFile *)pFile;
48880
+ MemStore *p = ((MemFile*)pFile)->pStore;
48881
+ memdbEnter(p);
48882
*pSize = p->sz;
48883
+ memdbLeave(p);
48884
return SQLITE_OK;
48885
}
48886
@@ -48073,19 +48888,48 @@ static int memdbFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
48888
** Lock an memdb-file.
48889
*/
48890
static int memdbLock(sqlite3_file *pFile, int eLock){
48076
- MemFile *p = (MemFile *)pFile;
48077
- if( eLock>SQLITE_LOCK_SHARED
48078
- && (p->mFlags & SQLITE_DESERIALIZE_READONLY)!=0
48079
- ){
48080
- return SQLITE_READONLY;
48891
+ MemFile *pThis = (MemFile*)pFile;
48892
+ MemStore *p = pThis->pStore;
48893
+ int rc = SQLITE_OK;
48894
+ if( eLock==pThis->eLock ) return SQLITE_OK;
48895
+ memdbEnter(p);
48896
+ if( eLock>SQLITE_LOCK_SHARED ){
48897
+ if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
48898
+ rc = SQLITE_READONLY;
48899
+ }else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
48900
+ if( p->nWrLock ){
48901
+ rc = SQLITE_BUSY;
48902
+ }else{
48903
+ p->nWrLock = 1;
48904
+ }
48905
+ }
48906
+ }else if( eLock==SQLITE_LOCK_SHARED ){
48907
+ if( pThis->eLock > SQLITE_LOCK_SHARED ){
48908
+ assert( p->nWrLock==1 );
48909
+ p->nWrLock = 0;
48910
+ }else if( p->nWrLock ){
48911
+ rc = SQLITE_BUSY;
48912
+ }else{
48913
+ p->nRdLock++;
48914
+ }
48915
+ }else{
48916
+ assert( eLock==SQLITE_LOCK_NONE );
48917
+ if( pThis->eLock>SQLITE_LOCK_SHARED ){
48918
+ assert( p->nWrLock==1 );
48919
+ p->nWrLock = 0;
48920
+ }
48921
+ assert( p->nRdLock>0 );
48922
+ p->nRdLock--;
48923
}
48082
- p->eLock = eLock;
48083
- return SQLITE_OK;
48924
+ if( rc==SQLITE_OK ) pThis->eLock = eLock;
48925
+ memdbLeave(p);
48926
+ return rc;
48927
}
48928
48086
-#if 0 /* Never used because memdbAccess() always returns false */
48929
+#if 0
48930
/*
48088
-** Check if another file-handle holds a RESERVED lock on an memdb-file.
48931
+** This interface is only used for crash recovery, which does not
48932
+** occur on an in-memory database.
48933
*/
48934
static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
48935
*pResOut = 0;
@@ -48093,12 +48937,14 @@ static int memdbCheckReservedLock(sqlite3_file *pFile, int *pResOut){
48937
}
48938
#endif
48939
48940
+
48941
/*
48942
** File control method. For custom operations on an memdb-file.
48943
*/
48944
static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
48100
- MemFile *p = (MemFile *)pFile;
48945
+ MemStore *p = ((MemFile*)pFile)->pStore;
48946
int rc = SQLITE_NOTFOUND;
48947
+ memdbEnter(p);
48948
if( op==SQLITE_FCNTL_VFSNAME ){
48949
*(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
48950
rc = SQLITE_OK;
@@ -48116,6 +48962,7 @@ static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
48962
*(sqlite3_int64*)pArg = iLimit;
48963
rc = SQLITE_OK;
48964
}
48965
+ memdbLeave(p);
48966
return rc;
48967
}
48968
@@ -48132,6 +48979,7 @@ static int memdbSectorSize(sqlite3_file *pFile){
48979
** Return the device characteristic flags supported by an memdb-file.
48980
*/
48981
static int memdbDeviceCharacteristics(sqlite3_file *pFile){
48982
+ UNUSED_PARAMETER(pFile);
48983
return SQLITE_IOCAP_ATOMIC |
48984
SQLITE_IOCAP_POWERSAFE_OVERWRITE |
48985
SQLITE_IOCAP_SAFE_APPEND |
@@ -48145,20 +48993,26 @@ static int memdbFetch(
48993
int iAmt,
48994
void **pp
48995
){
48148
- MemFile *p = (MemFile *)pFile;
48996
+ MemStore *p = ((MemFile*)pFile)->pStore;
48997
+ memdbEnter(p);
48998
if( iOfst+iAmt>p->sz ){
48999
*pp = 0;
49000
}else{
49001
p->nMmap++;
49002
*pp = (void*)(p->aData + iOfst);
49003
}
49004
+ memdbLeave(p);
49005
return SQLITE_OK;
49006
}
49007
49008
/* Release a memory-mapped page */
49009
static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
48160
- MemFile *p = (MemFile *)pFile;
49010
+ MemStore *p = ((MemFile*)pFile)->pStore;
49011
+ UNUSED_PARAMETER(iOfst);
49012
+ UNUSED_PARAMETER(pPage);
49013
+ memdbEnter(p);
49014
p->nMmap--;
49015
+ memdbLeave(p);
49016
return SQLITE_OK;
49017
}
49018
@@ -48168,20 +49022,79 @@ static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
49022
static int memdbOpen(
49023
sqlite3_vfs *pVfs,
49024
const char *zName,
48171
- sqlite3_file *pFile,
49025
+ sqlite3_file *pFd,
49026
int flags,
49027
int *pOutFlags
49028
){
48175
- MemFile *p = (MemFile*)pFile;
49029
+ MemFile *pFile = (MemFile*)pFd;
49030
+ MemStore *p = 0;
49031
+ int szName;
49032
if( (flags & SQLITE_OPEN_MAIN_DB)==0 ){
48177
- return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags);
49033
+ return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFd, flags, pOutFlags);
49034
}
48179
- memset(p, 0, sizeof(*p));
48180
- p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
49035
+ memset(pFile, 0, sizeof(*p));
49036
+ szName = sqlite3Strlen30(zName);
49037
+ if( szName>1 && zName[0]=='/' ){
49038
+ int i;
49039
+#ifndef SQLITE_MUTEX_OMIT
49040
+ sqlite3_mutex *pVfsMutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_VFS1);
49041
+#endif
49042
+ sqlite3_mutex_enter(pVfsMutex);
49043
+ for(i=0; i<memdb_g.nMemStore; i++){
49044
+ if( strcmp(memdb_g.apMemStore[i]->zFName,zName)==0 ){
49045
+ p = memdb_g.apMemStore[i];
49046
+ break;
49047
+ }
49048
+ }
49049
+ if( p==0 ){
49050
+ MemStore **apNew;
49051
+ p = sqlite3Malloc( sizeof(*p) + szName + 3 );
49052
+ if( p==0 ){
49053
+ sqlite3_mutex_leave(pVfsMutex);
49054
+ return SQLITE_NOMEM;
49055
+ }
49056
+ apNew = sqlite3Realloc(memdb_g.apMemStore,
49057
+ sizeof(apNew[0])*(memdb_g.nMemStore+1) );
49058
+ if( apNew==0 ){
49059
+ sqlite3_free(p);
49060
+ sqlite3_mutex_leave(pVfsMutex);
49061
+ return SQLITE_NOMEM;
49062
+ }
49063
+ apNew[memdb_g.nMemStore++] = p;
49064
+ memdb_g.apMemStore = apNew;
49065
+ memset(p, 0, sizeof(*p));
49066
+ p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE|SQLITE_DESERIALIZE_FREEONCLOSE;
49067
+ p->szMax = sqlite3GlobalConfig.mxMemdbSize;
49068
+ p->zFName = (char*)&p[1];
49069
+ memcpy(p->zFName, zName, szName+1);
49070
+ p->pMutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
49071
+ if( p->pMutex==0 ){
49072
+ memdb_g.nMemStore--;
49073
+ sqlite3_free(p);
49074
+ sqlite3_mutex_leave(pVfsMutex);
49075
+ return SQLITE_NOMEM;
49076
+ }
49077
+ p->nRef = 1;
49078
+ memdbEnter(p);
49079
+ }else{
49080
+ memdbEnter(p);
49081
+ p->nRef++;
49082
+ }
49083
+ sqlite3_mutex_leave(pVfsMutex);
49084
+ }else{
49085
+ p = sqlite3Malloc( sizeof(*p) );
49086
+ if( p==0 ){
49087
+ return SQLITE_NOMEM;
49088
+ }
49089
+ memset(p, 0, sizeof(*p));
49090
+ p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
49091
+ p->szMax = sqlite3GlobalConfig.mxMemdbSize;
49092
+ }
49093
+ pFile->pStore = p;
49094
assert( pOutFlags!=0 ); /* True because flags==SQLITE_OPEN_MAIN_DB */
49095
*pOutFlags = flags | SQLITE_OPEN_MEMORY;
48183
- pFile->pMethods = &memdb_io_methods;
48184
- p->szMax = sqlite3GlobalConfig.mxMemdbSize;
49096
+ pFd->pMethods = &memdb_io_methods;
49097
+ memdbLeave(p);
49098
return SQLITE_OK;
49099
}
49100
@@ -48209,6 +49122,9 @@ static int memdbAccess(
49122
int flags,
49123
int *pResOut
49124
){
49125
+ UNUSED_PARAMETER(pVfs);
49126
+ UNUSED_PARAMETER(zPath);
49127
+ UNUSED_PARAMETER(flags);
49128
*pResOut = 0;
49129
return SQLITE_OK;
49130
}
@@ -48224,6 +49140,7 @@ static int memdbFullPathname(
49140
int nOut,
49141
char *zOut
49142
){
49143
+ UNUSED_PARAMETER(pVfs);
49144
sqlite3_snprintf(nOut, zOut, "%s", zPath);
49145
return SQLITE_OK;
49146
}
@@ -48296,9 +49213,14 @@ static int memdbCurrentTimeInt64(sqlite3_vfs *pVfs, sqlite3_int64 *p){
49213
*/
49214
static MemFile *memdbFromDbSchema(sqlite3 *db, const char *zSchema){
49215
MemFile *p = 0;
49216
+ MemStore *pStore;
49217
int rc = sqlite3_file_control(db, zSchema, SQLITE_FCNTL_FILE_POINTER, &p);
49218
if( rc ) return 0;
49219
if( p->base.pMethods!=&memdb_io_methods ) return 0;
49220
+ pStore = p->pStore;
49221
+ memdbEnter(pStore);
49222
+ if( pStore->zFName!=0 ) p = 0;
49223
+ memdbLeave(pStore);
49224
return p;
49225
}
49226
@@ -48334,12 +49256,14 @@ SQLITE_API unsigned char *sqlite3_serialize(
49256
if( piSize ) *piSize = -1;
49257
if( iDb<0 ) return 0;
49258
if( p ){
48337
- if( piSize ) *piSize = p->sz;
49259
+ MemStore *pStore = p->pStore;
49260
+ assert( pStore->pMutex==0 );
49261
+ if( piSize ) *piSize = pStore->sz;
49262
if( mFlags & SQLITE_SERIALIZE_NOCOPY ){
48339
- pOut = p->aData;
49263
+ pOut = pStore->aData;
49264
}else{
48341
- pOut = sqlite3_malloc64( p->sz );
48342
- if( pOut ) memcpy(pOut, p->aData, p->sz);
49265
+ pOut = sqlite3_malloc64( pStore->sz );
49266
+ if( pOut ) memcpy(pOut, pStore->aData, pStore->sz);
49267
}
49268
return pOut;
49269
}
@@ -48414,8 +49338,12 @@ SQLITE_API int sqlite3_deserialize(
49338
goto end_deserialize;
49339
}
49340
zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema);
48417
- rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
48418
- sqlite3_free(zSql);
49341
+ if( zSql==0 ){
49342
+ rc = SQLITE_NOMEM;
49343
+ }else{
49344
+ rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
49345
+ sqlite3_free(zSql);
49346
+ }
49347
if( rc ) goto end_deserialize;
49348
db->init.iDb = (u8)iDb;
49349
db->init.reopenMemdb = 1;
@@ -48429,19 +49357,24 @@ SQLITE_API int sqlite3_deserialize(
49357
if( p==0 ){
49358
rc = SQLITE_ERROR;
49359
}else{
48432
- p->aData = pData;
48433
- p->sz = szDb;
48434
- p->szAlloc = szBuf;
48435
- p->szMax = szBuf;
48436
- if( p->szMax<sqlite3GlobalConfig.mxMemdbSize ){
48437
- p->szMax = sqlite3GlobalConfig.mxMemdbSize;
49360
+ MemStore *pStore = p->pStore;
49361
+ pStore->aData = pData;
49362
+ pData = 0;
49363
+ pStore->sz = szDb;
49364
+ pStore->szAlloc = szBuf;
49365
+ pStore->szMax = szBuf;
49366
+ if( pStore->szMax<sqlite3GlobalConfig.mxMemdbSize ){
49367
+ pStore->szMax = sqlite3GlobalConfig.mxMemdbSize;
49368
}
48439
- p->mFlags = mFlags;
49369
+ pStore->mFlags = mFlags;
49370
rc = SQLITE_OK;
49371
}
49372
49373
end_deserialize:
49374
sqlite3_finalize(pStmt);
49375
+ if( pData && (mFlags & SQLITE_DESERIALIZE_FREEONCLOSE)!=0 ){
49376
+ sqlite3_free(pData);
49377
+ }
49378
sqlite3_mutex_leave(db->mutex);
49379
return rc;
49380
}
@@ -48452,7 +49385,9 @@ end_deserialize:
49385
*/
49386
SQLITE_PRIVATE int sqlite3MemdbInit(void){
49387
sqlite3_vfs *pLower = sqlite3_vfs_find(0);
48455
- int sz = pLower->szOsFile;
49388
+ unsigned int sz;
49389
+ if( NEVER(pLower==0) ) return SQLITE_ERROR;
49390
+ sz = pLower->szOsFile;
49391
memdb_vfs.pAppData = pLower;
49392
/* The following conditional can only be true when compiled for
49393
** Windows x86 and SQLITE_MAX_MMAP_SIZE=0. We always leave
@@ -48462,7 +49397,7 @@ SQLITE_PRIVATE int sqlite3MemdbInit(void){
49397
memdb_vfs.szOsFile = sz;
49398
return sqlite3_vfs_register(&memdb_vfs, 0);
49399
}
48465
-#endif /* SQLITE_ENABLE_DESERIALIZE */
49400
+#endif /* SQLITE_OMIT_DESERIALIZE */
49401
49402
/************** End of memdb.c ***********************************************/
49403
/************** Begin file bitvec.c ******************************************/
@@ -50228,6 +51163,7 @@ static PgHdr1 *pcache1AllocPage(PCache1 *pCache, int benignMalloc){
51163
p->page.pExtra = &p[1];
51164
p->isBulkLocal = 0;
51165
p->isAnchor = 0;
51166
+ p->pLruPrev = 0; /* Initializing this saves a valgrind error */
51167
}
51168
(*pCache->pnPurgeable)++;
51169
return p;
@@ -52146,6 +53082,7 @@ struct PagerSavepoint {
53082
Bitvec *pInSavepoint; /* Set of pages in this savepoint */
53083
Pgno nOrig; /* Original number of pages in file */
53084
Pgno iSubRec; /* Index of first record in sub-journal */
53085
+ int bTruncateOnRelease; /* If stmt journal may be truncated on RELEASE */
53086
#ifndef SQLITE_OMIT_WAL
53087
u32 aWalData[WAL_SAVEPOINT_NDATA]; /* WAL savepoint context */
53088
#endif
@@ -52781,6 +53718,9 @@ static int subjRequiresPage(PgHdr *pPg){
53718
for(i=0; i<pPager->nSavepoint; i++){
53719
p = &pPager->aSavepoint[i];
53720
if( p->nOrig>=pgno && 0==sqlite3BitvecTestNotNull(p->pInSavepoint, pgno) ){
53721
+ for(i=i+1; i<pPager->nSavepoint; i++){
53722
+ pPager->aSavepoint[i].bTruncateOnRelease = 0;
53723
+ }
53724
return 1;
53725
}
53726
}
@@ -54197,6 +55137,7 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){
55137
i64 nSuperJournal; /* Size of super-journal file */
55138
char *zJournal; /* Pointer to one journal within MJ file */
55139
char *zSuperPtr; /* Space to hold super-journal filename */
55140
+ char *zFree = 0; /* Free this buffer */
55141
int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
55142
55143
/* Allocate space for both the pJournal and pSuper file descriptors.
@@ -54221,11 +55162,13 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){
55162
rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
55163
if( rc!=SQLITE_OK ) goto delsuper_out;
55164
nSuperPtr = pVfs->mxPathname+1;
54224
- zSuperJournal = sqlite3Malloc(nSuperJournal + nSuperPtr + 2);
54225
- if( !zSuperJournal ){
55165
+ zFree = sqlite3Malloc(4 + nSuperJournal + nSuperPtr + 2);
55166
+ if( !zFree ){
55167
rc = SQLITE_NOMEM_BKPT;
55168
goto delsuper_out;
55169
}
55170
+ zFree[0] = zFree[1] = zFree[2] = zFree[3] = 0;
55171
+ zSuperJournal = &zFree[4];
55172
zSuperPtr = &zSuperJournal[nSuperJournal+2];
55173
rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
55174
if( rc!=SQLITE_OK ) goto delsuper_out;
@@ -54273,7 +55216,7 @@ static int pager_delsuper(Pager *pPager, const char *zSuper){
55216
rc = sqlite3OsDelete(pVfs, zSuper, 0);
55217
55218
delsuper_out:
54276
- sqlite3_free(zSuperJournal);
55219
+ sqlite3_free(zFree);
55220
if( pSuper ){
55221
sqlite3OsClose(pSuper);
55222
assert( !isOpen(pJournal) );
@@ -54611,7 +55554,11 @@ end_playback:
55554
pPager->changeCountDone = pPager->tempFile;
55555
55556
if( rc==SQLITE_OK ){
54614
- zSuper = pPager->pTmpSpace;
55557
+ /* Leave 4 bytes of space before the super-journal filename in memory.
55558
+ ** This is because it may end up being passed to sqlite3OsOpen(), in
55559
+ ** which case it requires 4 0x00 bytes in memory immediately before
55560
+ ** the filename. */
55561
+ zSuper = &pPager->pTmpSpace[4];
55562
rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
55563
testcase( rc!=SQLITE_OK );
55564
}
@@ -54628,6 +55575,8 @@ end_playback:
55575
/* If there was a super-journal and this routine will return success,
55576
** see if it is possible to delete the super-journal.
55577
*/
55578
+ assert( zSuper==&pPager->pTmpSpace[4] );
55579
+ memset(&zSuper[-4], 0, 4);
55580
rc = pager_delsuper(pPager, zSuper);
55581
testcase( rc!=SQLITE_OK );
55582
}
@@ -55634,7 +56583,8 @@ static void assertTruncateConstraint(Pager *pPager){
56583
** then continue writing to the database.
56584
*/
56585
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
55637
- assert( pPager->dbSize>=nPage );
56586
+ assert( pPager->dbSize>=nPage || CORRUPT_DB );
56587
+ testcase( pPager->dbSize<nPage );
56588
assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
56589
pPager->dbSize = nPage;
56590
@@ -56362,7 +57312,7 @@ SQLITE_PRIVATE int sqlite3PagerOpen(
57312
int rc = SQLITE_OK; /* Return code */
57313
int tempFile = 0; /* True for temp files (incl. in-memory files) */
57314
int memDb = 0; /* True if this is an in-memory file */
56365
-#ifdef SQLITE_ENABLE_DESERIALIZE
57315
+#ifndef SQLITE_OMIT_DESERIALIZE
57316
int memJM = 0; /* Memory journal mode */
57317
#else
57318
# define memJM 0
@@ -56566,7 +57516,7 @@ SQLITE_PRIVATE int sqlite3PagerOpen(
57516
int fout = 0; /* VFS flags returned by xOpen() */
57517
rc = sqlite3OsOpen(pVfs, pPager->zFilename, pPager->fd, vfsFlags, &fout);
57518
assert( !memDb );
56569
-#ifdef SQLITE_ENABLE_DESERIALIZE
57519
+#ifndef SQLITE_OMIT_DESERIALIZE
57520
memJM = (fout&SQLITE_OPEN_MEMORY)!=0;
57521
#endif
57522
readOnly = (fout&SQLITE_OPEN_READONLY)!=0;
@@ -57534,7 +58484,7 @@ SQLITE_PRIVATE int sqlite3PagerBegin(Pager *pPager, int exFlag, int subjInMemory
58484
assert( pPager->eState>=PAGER_READER && pPager->eState<PAGER_ERROR );
58485
pPager->subjInMemory = (u8)subjInMemory;
58486
57537
- if( ALWAYS(pPager->eState==PAGER_READER) ){
58487
+ if( pPager->eState==PAGER_READER ){
58488
assert( pPager->pInJournal==0 );
58489
58490
if( pagerUseWal(pPager) ){
@@ -58550,6 +59500,7 @@ static SQLITE_NOINLINE int pagerOpenSavepoint(Pager *pPager, int nSavepoint){
59500
}
59501
aNew[ii].iSubRec = pPager->nSubRec;
59502
aNew[ii].pInSavepoint = sqlite3BitvecCreate(pPager->dbSize);
59503
+ aNew[ii].bTruncateOnRelease = 1;
59504
if( !aNew[ii].pInSavepoint ){
59505
return SQLITE_NOMEM_BKPT;
59506
}
@@ -58631,13 +59582,15 @@ SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){
59582
/* If this is a release of the outermost savepoint, truncate
59583
** the sub-journal to zero bytes in size. */
59584
if( op==SAVEPOINT_RELEASE ){
58634
- if( nNew==0 && isOpen(pPager->sjfd) ){
59585
+ PagerSavepoint *pRel = &pPager->aSavepoint[nNew];
59586
+ if( pRel->bTruncateOnRelease && isOpen(pPager->sjfd) ){
59587
/* Only truncate if it is an in-memory sub-journal. */
59588
if( sqlite3JournalIsInMemory(pPager->sjfd) ){
58637
- rc = sqlite3OsTruncate(pPager->sjfd, 0);
59589
+ i64 sz = (pPager->pageSize+4)*pRel->iSubRec;
59590
+ rc = sqlite3OsTruncate(pPager->sjfd, sz);
59591
assert( rc==SQLITE_OK );
59592
}
58640
- pPager->nSubRec = 0;
59593
+ pPager->nSubRec = pRel->iSubRec;
59594
}
59595
}
59596
/* Else this is a rollback operation, playback the specified savepoint.
@@ -60405,7 +61358,6 @@ static void walCleanupHash(Wal *pWal){
61358
int iLimit = 0; /* Zero values greater than this */
61359
int nByte; /* Number of bytes to zero in aPgno[] */
61360
int i; /* Used to iterate through aHash[] */
60408
- int rc; /* Return code form walHashGet() */
61361
61362
assert( pWal->writeLock );
61363
testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
@@ -60420,8 +61372,8 @@ static void walCleanupHash(Wal *pWal){
61372
*/
61373
assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
61374
assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
60423
- rc = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
60424
- if( NEVER(rc) ) return; /* Defense-in-depth, in case (1) above is wrong */
61375
+ i = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
61376
+ if( NEVER(i) ) return; /* Defense-in-depth, in case (1) above is wrong */
61377
61378
/* Zero all hash-table entries that correspond to frame numbers greater
61379
** than pWal->hdr.mxFrame.
@@ -63828,9 +64780,12 @@ struct Btree {
64780
u8 hasIncrblobCur; /* True if there are one or more Incrblob cursors */
64781
int wantToLock; /* Number of nested calls to sqlite3BtreeEnter() */
64782
int nBackup; /* Number of backup operations reading this btree */
63831
- u32 iDataVersion; /* Combines with pBt->pPager->iDataVersion */
64783
+ u32 iBDataVersion; /* Combines with pBt->pPager->iDataVersion */
64784
Btree *pNext; /* List of other sharable Btrees from the same db */
64785
Btree *pPrev; /* Back pointer of the same list */
64786
+#ifdef SQLITE_DEBUG
64787
+ u64 nSeek; /* Calls to sqlite3BtreeMovetoUnpacked() */
64788
+#endif
64789
#ifndef SQLITE_OMIT_SHARED_CACHE
64790
BtLock lock; /* Object used to lock page 1 */
64791
#endif
@@ -63842,11 +64797,25 @@ struct Btree {
64797
** If the shared-data extension is enabled, there may be multiple users
64798
** of the Btree structure. At most one of these may open a write transaction,
64799
** but any number may have active read transactions.
64800
+**
64801
+** These values must match SQLITE_TXN_NONE, SQLITE_TXN_READ, and
64802
+** SQLITE_TXN_WRITE
64803
*/
64804
#define TRANS_NONE 0
64805
#define TRANS_READ 1
64806
#define TRANS_WRITE 2
64807
64808
+#if TRANS_NONE!=SQLITE_TXN_NONE
64809
+# error wrong numeric code for no-transaction
64810
+#endif
64811
+#if TRANS_READ!=SQLITE_TXN_READ
64812
+# error wrong numeric code for read-transaction
64813
+#endif
64814
+#if TRANS_WRITE!=SQLITE_TXN_WRITE
64815
+# error wrong numeric code for write-transaction
64816
+#endif
64817
+
64818
+
64819
/*
64820
** An instance of this object represents a single database file.
64821
**
@@ -63916,6 +64885,7 @@ struct BtShared {
64885
Btree *pWriter; /* Btree with currently open write transaction */
64886
#endif
64887
u8 *pTmpSpace; /* Temp space sufficient to hold a single cell */
64888
+ int nPreformatSize; /* Size of last cell written by TransferRow() */
64889
};
64890
64891
/*
@@ -64598,6 +65568,17 @@ SQLITE_API int sqlite3_enable_shared_cache(int enable){
65568
#define hasReadConflicts(a, b) 0
65569
#endif
65570
65571
+#ifdef SQLITE_DEBUG
65572
+/*
65573
+** Return and reset the seek counter for a Btree object.
65574
+*/
65575
+SQLITE_PRIVATE sqlite3_uint64 sqlite3BtreeSeekCount(Btree *pBt){
65576
+ u64 n = pBt->nSeek;
65577
+ pBt->nSeek = 0;
65578
+ return n;
65579
+}
65580
+#endif
65581
+
65582
/*
65583
** Implementation of the SQLITE_CORRUPT_PAGE() macro. Takes a single
65584
** (MemPage*) as an argument. The (MemPage*) must not be NULL.
@@ -65022,7 +66003,7 @@ static void invalidateIncrblobCursors(
66003
int isClearTable /* True if all rows are being deleted */
66004
){
66005
BtCursor *p;
65025
- if( pBtree->hasIncrblobCur==0 ) return;
66006
+ assert( pBtree->hasIncrblobCur );
66007
assert( sqlite3BtreeHoldsMutex(pBtree) );
66008
pBtree->hasIncrblobCur = 0;
66009
for(p=pBtree->pBt->pCursor; p; p=p->pNext){
@@ -65618,6 +66599,24 @@ static SQLITE_NOINLINE void btreeParseCellAdjustSizeForOverflow(
66599
pInfo->nSize = (u16)(&pInfo->pPayload[pInfo->nLocal] - pCell) + 4;
66600
}
66601
66602
+/*
66603
+** Given a record with nPayload bytes of payload stored within btree
66604
+** page pPage, return the number of bytes of payload stored locally.
66605
+*/
66606
+static int btreePayloadToLocal(MemPage *pPage, i64 nPayload){
66607
+ int maxLocal; /* Maximum amount of payload held locally */
66608
+ maxLocal = pPage->maxLocal;
66609
+ if( nPayload<=maxLocal ){
66610
+ return nPayload;
66611
+ }else{
66612
+ int minLocal; /* Minimum amount of payload held locally */
66613
+ int surplus; /* Overflow payload available for local storage */
66614
+ minLocal = pPage->minLocal;
66615
+ surplus = minLocal + (nPayload - minLocal)%(pPage->pBt->usableSize-4);
66616
+ return ( surplus <= maxLocal ) ? surplus : minLocal;
66617
+ }
66618
+}
66619
+
66620
/*
66621
** The following routines are implementations of the MemPage.xParseCell()
66622
** method.
@@ -65905,6 +66904,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
66904
unsigned char *src; /* Source of content */
66905
int iCellFirst; /* First allowable cell index */
66906
int iCellLast; /* Last possible cell index */
66907
+ int iCellStart; /* First cell offset in input */
66908
66909
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
66910
assert( pPage->pBt!=0 );
@@ -65946,7 +66946,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
66946
if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
66947
memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
66948
sz += sz2;
65949
- }else if( NEVER(iFree+sz>usableSize) ){
66949
+ }else if( iFree+sz>usableSize ){
66950
return SQLITE_CORRUPT_PAGE(pPage);
66951
}
66952
@@ -65965,6 +66965,7 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
66965
66966
cbrk = usableSize;
66967
iCellLast = usableSize - 4;
66968
+ iCellStart = get2byte(&data[hdr+5]);
66969
for(i=0; i<nCell; i++){
66970
u8 *pAddr; /* The i-th cell pointer */
66971
pAddr = &data[cellOffset + i*2];
@@ -65974,25 +66975,23 @@ static int defragmentPage(MemPage *pPage, int nMaxFrag){
66975
/* These conditions have already been verified in btreeInitPage()
66976
** if PRAGMA cell_size_check=ON.
66977
*/
65977
- if( pc<iCellFirst || pc>iCellLast ){
66978
+ if( pc<iCellStart || pc>iCellLast ){
66979
return SQLITE_CORRUPT_PAGE(pPage);
66980
}
65980
- assert( pc>=iCellFirst && pc<=iCellLast );
66981
+ assert( pc>=iCellStart && pc<=iCellLast );
66982
size = pPage->xCellSize(pPage, &src[pc]);
66983
cbrk -= size;
65983
- if( cbrk<iCellFirst || pc+size>usableSize ){
66984
+ if( cbrk<iCellStart || pc+size>usableSize ){
66985
return SQLITE_CORRUPT_PAGE(pPage);
66986
}
65986
- assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
66987
+ assert( cbrk+size<=usableSize && cbrk>=iCellStart );
66988
testcase( cbrk+size==usableSize );
66989
testcase( pc+size==usableSize );
66990
put2byte(pAddr, cbrk);
66991
if( temp==0 ){
65991
- int x;
66992
if( cbrk==pc ) continue;
66993
temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
65994
- x = get2byte(&data[hdr+5]);
65995
- memcpy(&temp[x], &data[x], (cbrk+size) - x);
66994
+ memcpy(&temp[iCellStart], &data[iCellStart], usableSize - iCellStart);
66995
src = temp;
66996
}
66997
memcpy(&data[cbrk], &src[pc], size);
@@ -67091,7 +68090,7 @@ btree_open_out:
68090
** do not change the pager-cache size.
68091
*/
68092
if( sqlite3BtreeSchema(p, 0, 0)==0 ){
67094
- sqlite3PagerSetCachesize(p->pBt->pPager, SQLITE_DEFAULT_CACHE_SIZE);
68093
+ sqlite3BtreeSetCacheSize(p, SQLITE_DEFAULT_CACHE_SIZE);
68094
}
68095
68096
pFile = sqlite3PagerFile(pBt->pPager);
@@ -67194,19 +68193,23 @@ static void freeTempSpace(BtShared *pBt){
68193
*/
68194
SQLITE_PRIVATE int sqlite3BtreeClose(Btree *p){
68195
BtShared *pBt = p->pBt;
67197
- BtCursor *pCur;
68196
68197
/* Close all cursors opened via this handle. */
68198
assert( sqlite3_mutex_held(p->db->mutex) );
68199
sqlite3BtreeEnter(p);
67202
- pCur = pBt->pCursor;
67203
- while( pCur ){
67204
- BtCursor *pTmp = pCur;
67205
- pCur = pCur->pNext;
67206
- if( pTmp->pBtree==p ){
67207
- sqlite3BtreeCloseCursor(pTmp);
68200
+
68201
+ /* Verify that no other cursors have this Btree open */
68202
+#ifdef SQLITE_DEBUG
68203
+ {
68204
+ BtCursor *pCur = pBt->pCursor;
68205
+ while( pCur ){
68206
+ BtCursor *pTmp = pCur;
68207
+ pCur = pCur->pNext;
68208
+ assert( pTmp->pBtree!=p );
68209
+
68210
}
68211
}
68212
+#endif
68213
68214
/* Rollback any active transaction and free the handle structure.
68215
** The call to sqlite3BtreeRollback() drops any table-locks held by
@@ -67358,6 +68361,7 @@ SQLITE_PRIVATE int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve,
68361
((pageSize-1)&pageSize)==0 ){
68362
assert( (pageSize & 7)==0 );
68363
assert( !pBt->pCursor );
68364
+ if( nReserve>32 && pageSize==512 ) pageSize = 1024;
68365
pBt->pageSize = (u32)pageSize;
68366
freeTempSpace(pBt);
68367
}
@@ -68587,7 +69591,7 @@ SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree *p, int bCleanup){
69591
sqlite3BtreeLeave(p);
69592
return rc;
69593
}
68590
- p->iDataVersion--; /* Compensate for pPager->iDataVersion++; */
69594
+ p->iBDataVersion--; /* Compensate for pPager->iDataVersion++; */
69595
pBt->inTransaction = TRANS_READ;
69596
btreeClearHasContent(pBt);
69597
}
@@ -68997,7 +70001,14 @@ SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
70001
unlockBtreeIfUnused(pBt);
70002
sqlite3_free(pCur->aOverflow);
70003
sqlite3_free(pCur->pKey);
69000
- sqlite3BtreeLeave(pBtree);
70004
+ if( (pBt->openFlags & BTREE_SINGLE) && pBt->pCursor==0 ){
70005
+ /* Since the BtShared is not sharable, there is no need to
70006
+ ** worry about the missing sqlite3BtreeLeave() call here. */
70007
+ assert( pBtree->sharable==0 );
70008
+ sqlite3BtreeClose(pBtree);
70009
+ }else{
70010
+ sqlite3BtreeLeave(pBtree);
70011
+ }
70012
pCur->pBtree = 0;
70013
}
70014
return SQLITE_OK;
@@ -69839,7 +70850,9 @@ SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
70850
for(ii=0; ii<pCur->iPage; ii++){
70851
assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
70852
}
69842
- assert( pCur->ix==pCur->pPage->nCell-1 );
70853
+ assert( pCur->ix==pCur->pPage->nCell-1 || CORRUPT_DB );
70854
+ testcase( pCur->ix!=pCur->pPage->nCell-1 );
70855
+ /* ^-- dbsqlfuzz b92b72e4de80b5140c30ab71372ca719b8feb618 */
70856
assert( pCur->pPage->leaf );
70857
#endif
70858
*pRes = 0;
@@ -69945,6 +70958,10 @@ SQLITE_PRIVATE int sqlite3BtreeMovetoUnpacked(
70958
}
70959
}
70960
70961
+#ifdef SQLITE_DEBUG
70962
+ pCur->pBtree->nSeek++; /* Performance measurement during testing */
70963
+#endif
70964
+
70965
if( pIdxKey ){
70966
xRecordCompare = sqlite3VdbeFindCompare(pIdxKey);
70967
pIdxKey->errCode = 0;
@@ -70221,7 +71238,7 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
71238
71239
pPage = pCur->pPage;
71240
idx = ++pCur->ix;
70224
- if( !pPage->isInit ){
71241
+ if( !pPage->isInit || sqlite3FaultSim(412) ){
71242
/* The only known way for this to happen is for there to be a
71243
** recursive SQL function that does a DELETE operation as part of a
71244
** SELECT which deletes content out from under an active cursor
@@ -70602,7 +71619,7 @@ static int allocateBtreePage(
71619
71620
iPage = get4byte(&aData[8+closest*4]);
71621
testcase( iPage==mxPage );
70605
- if( iPage>mxPage ){
71622
+ if( iPage>mxPage || iPage<2 ){
71623
rc = SQLITE_CORRUPT_PGNO(iTrunk);
71624
goto end_allocate_page;
71625
}
@@ -70858,10 +71875,9 @@ static void freePage(MemPage *pPage, int *pRC){
71875
}
71876
71877
/*
70861
-** Free any overflow pages associated with the given Cell. Store
70862
-** size information about the cell in pInfo.
71878
+** Free the overflow pages associated with the given Cell.
71879
*/
70864
-static int clearCell(
71880
+static SQLITE_NOINLINE int clearCellOverflow(
71881
MemPage *pPage, /* The page that contains the Cell */
71882
unsigned char *pCell, /* First byte of the Cell */
71883
CellInfo *pInfo /* Size information about the cell */
@@ -70873,10 +71889,7 @@ static int clearCell(
71889
u32 ovflPageSize;
71890
71891
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
70876
- pPage->xParseCell(pPage, pCell, pInfo);
70877
- if( pInfo->nLocal==pInfo->nPayload ){
70878
- return SQLITE_OK; /* No overflow pages. Return without doing anything */
70879
- }
71892
+ assert( pInfo->nLocal!=pInfo->nPayload );
71893
testcase( pCell + pInfo->nSize == pPage->aDataEnd );
71894
testcase( pCell + (pInfo->nSize-1) == pPage->aDataEnd );
71895
if( pCell + pInfo->nSize > pPage->aDataEnd ){
@@ -70932,6 +71945,21 @@ static int clearCell(
71945
return SQLITE_OK;
71946
}
71947
71948
+/* Call xParseCell to compute the size of a cell. If the cell contains
71949
+** overflow, then invoke cellClearOverflow to clear out that overflow.
71950
+** STore the result code (SQLITE_OK or some error code) in rc.
71951
+**
71952
+** Implemented as macro to force inlining for performance.
71953
+*/
71954
+#define BTREE_CLEAR_CELL(rc, pPage, pCell, sInfo) \
71955
+ pPage->xParseCell(pPage, pCell, &sInfo); \
71956
+ if( sInfo.nLocal!=sInfo.nPayload ){ \
71957
+ rc = clearCellOverflow(pPage, pCell, &sInfo); \
71958
+ }else{ \
71959
+ rc = SQLITE_OK; \
71960
+ }
71961
+
71962
+
71963
/*
71964
** Create the byte sequence used to represent a cell on page pPage
71965
** and write that byte sequence into pCell[]. Overflow pages are
@@ -71454,7 +72482,7 @@ static int rebuildPage(
72482
u8 *pCell = pCArray->apCell[i];
72483
u16 sz = pCArray->szCell[i];
72484
assert( sz>0 );
71457
- if( SQLITE_WITHIN(pCell,aData,pEnd) ){
72485
+ if( SQLITE_WITHIN(pCell,aData+j,pEnd) ){
72486
if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
72487
pCell = &pTmp[pCell - aData];
72488
}else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
@@ -71467,9 +72495,8 @@ static int rebuildPage(
72495
put2byte(pCellptr, (pData - aData));
72496
pCellptr += 2;
72497
if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
71470
- memcpy(pData, pCell, sz);
72498
+ memmove(pData, pCell, sz);
72499
assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
71472
- testcase( sz!=pPg->xCellSize(pPg,pCell) )
72500
i++;
72501
if( i>=iEnd ) break;
72502
if( pCArray->ixNx[k]<=i ){
@@ -71608,7 +72635,9 @@ static int pageFreeArray(
72635
}
72636
pFree = pCell;
72637
szFree = sz;
71611
- if( pFree+sz>pEnd ) return 0;
72638
+ if( pFree+sz>pEnd ){
72639
+ return 0;
72640
+ }
72641
}else{
72642
pFree = pCell;
72643
szFree += sz;
@@ -72089,7 +73118,9 @@ static int balance_nonroot(
73118
}
73119
pgno = get4byte(pRight);
73120
while( 1 ){
72092
- rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
73121
+ if( rc==SQLITE_OK ){
73122
+ rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
73123
+ }
73124
if( rc ){
73125
memset(apOld, 0, (i+1)*sizeof(MemPage*));
73126
goto balance_cleanup;
@@ -72128,12 +73159,10 @@ static int balance_nonroot(
73159
if( pBt->btsFlags & BTS_FAST_SECURE ){
73160
int iOff;
73161
73162
+ /* If the following if() condition is not true, the db is corrupted.
73163
+ ** The call to dropCell() below will detect this. */
73164
iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
72132
- if( (iOff+szNew[i])>(int)pBt->usableSize ){
72133
- rc = SQLITE_CORRUPT_BKPT;
72134
- memset(apOld, 0, (i+1)*sizeof(MemPage*));
72135
- goto balance_cleanup;
72136
- }else{
73165
+ if( (iOff+szNew[i])<=(int)pBt->usableSize ){
73166
memcpy(&aOvflSpace[iOff], apDiv[i], szNew[i]);
73167
apDiv[i] = &aOvflSpace[apDiv[i]-pParent->aData];
73168
}
@@ -72261,7 +73290,7 @@ static int balance_nonroot(
73290
b.szCell[b.nCell] = b.szCell[b.nCell] - leafCorrection;
73291
if( !pOld->leaf ){
73292
assert( leafCorrection==0 );
72264
- assert( pOld->hdrOffset==0 );
73293
+ assert( pOld->hdrOffset==0 || CORRUPT_DB );
73294
/* The right pointer of the child page pOld becomes the left
73295
** pointer of the divider cell */
73296
memcpy(b.apCell[b.nCell], &pOld->aData[8], 4);
@@ -72427,6 +73456,9 @@ static int balance_nonroot(
73456
apOld[i] = 0;
73457
rc = sqlite3PagerWrite(pNew->pDbPage);
73458
nNew++;
73459
+ if( sqlite3PagerPageRefcount(pNew->pDbPage)!=1+(i==(iParentIdx-nxDiv)) ){
73460
+ rc = SQLITE_CORRUPT_BKPT;
73461
+ }
73462
if( rc ) goto balance_cleanup;
73463
}else{
73464
assert( i>0 );
@@ -72463,7 +73495,7 @@ static int balance_nonroot(
73495
aPgOrder[i] = aPgno[i] = apNew[i]->pgno;
73496
aPgFlags[i] = apNew[i]->pDbPage->flags;
73497
for(j=0; j<i; j++){
72466
- if( aPgno[j]==aPgno[i] ){
73498
+ if( NEVER(aPgno[j]==aPgno[i]) ){
73499
/* This branch is taken if the set of sibling pages somehow contains
73500
** duplicate entries. This can happen if the database is corrupt.
73501
** It would be simpler to detect this as part of the loop below, but
@@ -72581,6 +73613,7 @@ static int balance_nonroot(
73613
u8 *pCell;
73614
u8 *pTemp;
73615
int sz;
73616
+ u8 *pSrcEnd;
73617
MemPage *pNew = apNew[i];
73618
j = cntNew[i];
73619
@@ -72624,6 +73657,12 @@ static int balance_nonroot(
73657
iOvflSpace += sz;
73658
assert( sz<=pBt->maxLocal+23 );
73659
assert( iOvflSpace <= (int)pBt->pageSize );
73660
+ for(k=0; b.ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
73661
+ pSrcEnd = b.apEnd[k];
73662
+ if( SQLITE_WITHIN(pSrcEnd, pCell, pCell+sz) ){
73663
+ rc = SQLITE_CORRUPT_BKPT;
73664
+ goto balance_cleanup;
73665
+ }
73666
insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
73667
if( rc!=SQLITE_OK ) goto balance_cleanup;
73668
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
@@ -73131,7 +74170,8 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
74170
unsigned char *oldCell;
74171
unsigned char *newCell = 0;
74172
73134
- assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND))==flags );
74173
+ assert( (flags & (BTREE_SAVEPOSITION|BTREE_APPEND|BTREE_PREFORMAT))==flags );
74174
+ assert( (flags & BTREE_PREFORMAT)==0 || seekResult || pCur->pKeyInfo==0 );
74175
74176
if( pCur->eState==CURSOR_FAULT ){
74177
assert( pCur->skipNext!=SQLITE_OK );
@@ -73149,7 +74189,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
74189
** keys with no associated data. If the cursor was opened expecting an
74190
** intkey table, the caller should be inserting integer keys with a
74191
** blob of associated data. */
73152
- assert( (pX->pKey==0)==(pCur->pKeyInfo==0) );
74192
+ assert( (flags & BTREE_PREFORMAT) || (pX->pKey==0)==(pCur->pKeyInfo==0) );
74193
74194
/* Save the positions of any other cursors open on this table.
74195
**
@@ -73165,13 +74205,23 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
74205
if( pCur->curFlags & BTCF_Multiple ){
74206
rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
74207
if( rc ) return rc;
74208
+ if( loc && pCur->iPage<0 ){
74209
+ /* This can only happen if the schema is corrupt such that there is more
74210
+ ** than one table or index with the same root page as used by the cursor.
74211
+ ** Which can only happen if the SQLITE_NoSchemaError flag was set when
74212
+ ** the schema was loaded. This cannot be asserted though, as a user might
74213
+ ** set the flag, load the schema, and then unset the flag. */
74214
+ return SQLITE_CORRUPT_BKPT;
74215
+ }
74216
}
74217
74218
if( pCur->pKeyInfo==0 ){
74219
assert( pX->pKey==0 );
74220
/* If this is an insert into a table b-tree, invalidate any incrblob
74221
** cursors open on the row being replaced */
73174
- invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
74222
+ if( p->hasIncrblobCur ){
74223
+ invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
74224
+ }
74225
74226
/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
74227
** to a row with the same key as the new entry being inserted.
@@ -73252,17 +74302,16 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
74302
return btreeOverwriteCell(pCur, &x2);
74303
}
74304
}
73255
-
74305
}
74306
assert( pCur->eState==CURSOR_VALID
74307
|| (pCur->eState==CURSOR_INVALID && loc)
74308
|| CORRUPT_DB );
74309
74310
pPage = pCur->pPage;
73262
- assert( pPage->intKey || pX->nKey>=0 );
74311
+ assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) );
74312
assert( pPage->leaf || !pPage->intKey );
74313
if( pPage->nFree<0 ){
73265
- if( pCur->eState>CURSOR_INVALID ){
74314
+ if( NEVER(pCur->eState>CURSOR_INVALID) ){
74315
rc = SQLITE_CORRUPT_BKPT;
74316
}else{
74317
rc = btreeComputeFreeSpace(pPage);
@@ -73276,7 +74325,21 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
74325
assert( pPage->isInit );
74326
newCell = pBt->pTmpSpace;
74327
assert( newCell!=0 );
73279
- rc = fillInCell(pPage, newCell, pX, &szNew);
74328
+ if( flags & BTREE_PREFORMAT ){
74329
+ rc = SQLITE_OK;
74330
+ szNew = pBt->nPreformatSize;
74331
+ if( szNew<4 ) szNew = 4;
74332
+ if( ISAUTOVACUUM && szNew>pPage->maxLocal ){
74333
+ CellInfo info;
74334
+ pPage->xParseCell(pPage, newCell, &info);
74335
+ if( info.nPayload!=info.nLocal ){
74336
+ Pgno ovfl = get4byte(&newCell[szNew-4]);
74337
+ ptrmapPut(pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, &rc);
74338
+ }
74339
+ }
74340
+ }else{
74341
+ rc = fillInCell(pPage, newCell, pX, &szNew);
74342
+ }
74343
if( rc ) goto end_insert;
74344
assert( szNew==pPage->xCellSize(pPage, newCell) );
74345
assert( szNew <= MX_CELL_SIZE(pBt) );
@@ -73292,7 +74355,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
74355
if( !pPage->leaf ){
74356
memcpy(newCell, oldCell, 4);
74357
}
73295
- rc = clearCell(pPage, oldCell, &info);
74358
+ BTREE_CLEAR_CELL(rc, pPage, oldCell, info);
74359
testcase( pCur->curFlags & BTCF_ValidOvfl );
74360
invalidateOverflowCache(pCur);
74361
if( info.nSize==szNew && info.nLocal==info.nPayload
@@ -73383,6 +74446,114 @@ end_insert:
74446
return rc;
74447
}
74448
74449
+/*
74450
+** This function is used as part of copying the current row from cursor
74451
+** pSrc into cursor pDest. If the cursors are open on intkey tables, then
74452
+** parameter iKey is used as the rowid value when the record is copied
74453
+** into pDest. Otherwise, the record is copied verbatim.
74454
+**
74455
+** This function does not actually write the new value to cursor pDest.
74456
+** Instead, it creates and populates any required overflow pages and
74457
+** writes the data for the new cell into the BtShared.pTmpSpace buffer
74458
+** for the destination database. The size of the cell, in bytes, is left
74459
+** in BtShared.nPreformatSize. The caller completes the insertion by
74460
+** calling sqlite3BtreeInsert() with the BTREE_PREFORMAT flag specified.
74461
+**
74462
+** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
74463
+*/
74464
+SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 iKey){
74465
+ int rc = SQLITE_OK;
74466
+ BtShared *pBt = pDest->pBt;
74467
+ u8 *aOut = pBt->pTmpSpace; /* Pointer to next output buffer */
74468
+ const u8 *aIn; /* Pointer to next input buffer */
74469
+ u32 nIn; /* Size of input buffer aIn[] */
74470
+ u32 nRem; /* Bytes of data still to copy */
74471
+
74472
+ getCellInfo(pSrc);
74473
+ aOut += putVarint32(aOut, pSrc->info.nPayload);
74474
+ if( pDest->pKeyInfo==0 ) aOut += putVarint(aOut, iKey);
74475
+ nIn = pSrc->info.nLocal;
74476
+ aIn = pSrc->info.pPayload;
74477
+ if( aIn+nIn>pSrc->pPage->aDataEnd ){
74478
+ return SQLITE_CORRUPT_BKPT;
74479
+ }
74480
+ nRem = pSrc->info.nPayload;
74481
+ if( nIn==nRem && nIn<pDest->pPage->maxLocal ){
74482
+ memcpy(aOut, aIn, nIn);
74483
+ pBt->nPreformatSize = nIn + (aOut - pBt->pTmpSpace);
74484
+ }else{
74485
+ Pager *pSrcPager = pSrc->pBt->pPager;
74486
+ u8 *pPgnoOut = 0;
74487
+ Pgno ovflIn = 0;
74488
+ DbPage *pPageIn = 0;
74489
+ MemPage *pPageOut = 0;
74490
+ u32 nOut; /* Size of output buffer aOut[] */
74491
+
74492
+ nOut = btreePayloadToLocal(pDest->pPage, pSrc->info.nPayload);
74493
+ pBt->nPreformatSize = nOut + (aOut - pBt->pTmpSpace);
74494
+ if( nOut<pSrc->info.nPayload ){
74495
+ pPgnoOut = &aOut[nOut];
74496
+ pBt->nPreformatSize += 4;
74497
+ }
74498
+
74499
+ if( nRem>nIn ){
74500
+ if( aIn+nIn+4>pSrc->pPage->aDataEnd ){
74501
+ return SQLITE_CORRUPT_BKPT;
74502
+ }
74503
+ ovflIn = get4byte(&pSrc->info.pPayload[nIn]);
74504
+ }
74505
+
74506
+ do {
74507
+ nRem -= nOut;
74508
+ do{
74509
+ assert( nOut>0 );
74510
+ if( nIn>0 ){
74511
+ int nCopy = MIN(nOut, nIn);
74512
+ memcpy(aOut, aIn, nCopy);
74513
+ nOut -= nCopy;
74514
+ nIn -= nCopy;
74515
+ aOut += nCopy;
74516
+ aIn += nCopy;
74517
+ }
74518
+ if( nOut>0 ){
74519
+ sqlite3PagerUnref(pPageIn);
74520
+ pPageIn = 0;
74521
+ rc = sqlite3PagerGet(pSrcPager, ovflIn, &pPageIn, PAGER_GET_READONLY);
74522
+ if( rc==SQLITE_OK ){
74523
+ aIn = (const u8*)sqlite3PagerGetData(pPageIn);
74524
+ ovflIn = get4byte(aIn);
74525
+ aIn += 4;
74526
+ nIn = pSrc->pBt->usableSize - 4;
74527
+ }
74528
+ }
74529
+ }while( rc==SQLITE_OK && nOut>0 );
74530
+
74531
+ if( rc==SQLITE_OK && nRem>0 ){
74532
+ Pgno pgnoNew;
74533
+ MemPage *pNew = 0;
74534
+ rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
74535
+ put4byte(pPgnoOut, pgnoNew);
74536
+ if( ISAUTOVACUUM && pPageOut ){
74537
+ ptrmapPut(pBt, pgnoNew, PTRMAP_OVERFLOW2, pPageOut->pgno, &rc);
74538
+ }
74539
+ releasePage(pPageOut);
74540
+ pPageOut = pNew;
74541
+ if( pPageOut ){
74542
+ pPgnoOut = pPageOut->aData;
74543
+ put4byte(pPgnoOut, 0);
74544
+ aOut = &pPgnoOut[4];
74545
+ nOut = MIN(pBt->usableSize - 4, nRem);
74546
+ }
74547
+ }
74548
+ }while( nRem>0 && rc==SQLITE_OK );
74549
+
74550
+ releasePage(pPageOut);
74551
+ sqlite3PagerUnref(pPageIn);
74552
+ }
74553
+
74554
+ return rc;
74555
+}
74556
+
74557
/*
74558
** Delete the entry that the cursor is pointing to.
74559
**
@@ -73421,9 +74592,10 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
74592
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
74593
if( pCur->eState==CURSOR_REQUIRESEEK ){
74594
rc = btreeRestoreCursorPosition(pCur);
73424
- if( rc ) return rc;
74595
+ assert( rc!=SQLITE_OK || CORRUPT_DB || pCur->eState==CURSOR_VALID );
74596
+ if( rc || pCur->eState!=CURSOR_VALID ) return rc;
74597
}
73426
- assert( pCur->eState==CURSOR_VALID );
74598
+ assert( CORRUPT_DB || pCur->eState==CURSOR_VALID );
74599
74600
iCellDepth = pCur->iPage;
74601
iCellIdx = pCur->ix;
@@ -73476,7 +74648,7 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
74648
74649
/* If this is a delete operation to remove a row from a table b-tree,
74650
** invalidate any incrblob cursors open on the row being deleted. */
73479
- if( pCur->pKeyInfo==0 ){
74651
+ if( pCur->pKeyInfo==0 && p->hasIncrblobCur ){
74652
invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
74653
}
74654
@@ -73485,7 +74657,7 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
74657
** itself from within the page. */
74658
rc = sqlite3PagerWrite(pPage->pDbPage);
74659
if( rc ) return rc;
73488
- rc = clearCell(pPage, pCell, &info);
74660
+ BTREE_CLEAR_CELL(rc, pPage, pCell, info);
74661
dropCell(pPage, iCellIdx, info.nSize, &rc);
74662
if( rc ) return rc;
74663
@@ -73772,14 +74944,14 @@ static int clearDatabasePage(
74944
rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
74945
if( rc ) goto cleardatabasepage_out;
74946
}
73775
- rc = clearCell(pPage, pCell, &info);
74947
+ BTREE_CLEAR_CELL(rc, pPage, pCell, info);
74948
if( rc ) goto cleardatabasepage_out;
74949
}
74950
if( !pPage->leaf ){
74951
rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
74952
if( rc ) goto cleardatabasepage_out;
73781
- }else if( pnChange ){
73782
- assert( pPage->intKey || CORRUPT_DB );
74953
+ }
74954
+ if( pnChange ){
74955
testcase( !pPage->intKey );
74956
*pnChange += pPage->nCell;
74957
}
@@ -73804,9 +74976,8 @@ cleardatabasepage_out:
74976
** read cursors on the table. Open write cursors are moved to the
74977
** root of the table.
74978
**
73807
-** If pnChange is not NULL, then table iTable must be an intkey table. The
73808
-** integer value pointed to by pnChange is incremented by the number of
73809
-** entries in the table.
74979
+** If pnChange is not NULL, then the integer value pointed to by pnChange
74980
+** is incremented by the number of entries in the table.
74981
*/
74982
SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
74983
int rc;
@@ -73820,7 +74991,9 @@ SQLITE_PRIVATE int sqlite3BtreeClearTable(Btree *p, int iTable, int *pnChange){
74991
/* Invalidate all incrblob cursors open on table iTable (assuming iTable
74992
** is the root of a table b-tree - if it is not, the following call is
74993
** a no-op). */
73823
- invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
74994
+ if( p->hasIncrblobCur ){
74995
+ invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
74996
+ }
74997
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
74998
}
74999
sqlite3BtreeLeave(p);
@@ -73980,7 +75153,7 @@ SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
75153
assert( idx>=0 && idx<=15 );
75154
75155
if( idx==BTREE_DATA_VERSION ){
73983
- *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
75156
+ *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iBDataVersion;
75157
}else{
75158
*pMeta = get4byte(&pBt->pPage1->aData[36 + idx*4]);
75159
}
@@ -74796,11 +75969,12 @@ SQLITE_PRIVATE const char *sqlite3BtreeGetJournalname(Btree *p){
75969
}
75970
75971
/*
74799
-** Return non-zero if a transaction is active.
75972
+** Return one of SQLITE_TXN_NONE, SQLITE_TXN_READ, or SQLITE_TXN_WRITE
75973
+** to describe the current transaction state of Btree p.
75974
*/
74801
-SQLITE_PRIVATE int sqlite3BtreeIsInTrans(Btree *p){
75975
+SQLITE_PRIVATE int sqlite3BtreeTxnState(Btree *p){
75976
assert( p==0 || sqlite3_mutex_held(p->db->mutex) );
74803
- return (p && (p->inTrans==TRANS_WRITE));
75977
+ return p ? p->inTrans : 0;
75978
}
75979
75980
#ifndef SQLITE_OMIT_WAL
@@ -74829,14 +76003,8 @@ SQLITE_PRIVATE int sqlite3BtreeCheckpoint(Btree *p, int eMode, int *pnLog, int *
76003
#endif
76004
76005
/*
74832
-** Return non-zero if a read (or write) transaction is active.
76006
+** Return true if there is currently a backup running on Btree p.
76007
*/
74834
-SQLITE_PRIVATE int sqlite3BtreeIsInReadTrans(Btree *p){
74835
- assert( p );
74836
- assert( sqlite3_mutex_held(p->db->mutex) );
74837
- return p->inTrans!=TRANS_NONE;
74838
-}
74839
-
76008
SQLITE_PRIVATE int sqlite3BtreeIsInBackup(Btree *p){
76009
assert( p );
76010
assert( sqlite3_mutex_held(p->db->mutex) );
@@ -75182,7 +76350,7 @@ static int setDestPgsz(sqlite3_backup *p){
76350
** message in database handle db.
76351
*/
76352
static int checkReadTransaction(sqlite3 *db, Btree *p){
75185
- if( sqlite3BtreeIsInReadTrans(p) ){
76353
+ if( sqlite3BtreeTxnState(p)!=SQLITE_TXN_NONE ){
76354
sqlite3ErrorWithMsg(db, SQLITE_ERROR, "destination database is in use");
76355
return SQLITE_ERROR;
76356
}
@@ -75413,7 +76581,7 @@ SQLITE_API int sqlite3_backup_step(sqlite3_backup *p, int nPage){
76581
** one now. If a transaction is opened here, then it will be closed
76582
** before this function exits.
76583
*/
75416
- if( rc==SQLITE_OK && 0==sqlite3BtreeIsInReadTrans(p->pSrc) ){
76584
+ if( rc==SQLITE_OK && SQLITE_TXN_NONE==sqlite3BtreeTxnState(p->pSrc) ){
76585
rc = sqlite3BtreeBeginTrans(p->pSrc, 0, 0);
76586
bCloseTrans = 1;
76587
}
@@ -75785,7 +76953,7 @@ SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
76953
sqlite3BtreeEnter(pTo);
76954
sqlite3BtreeEnter(pFrom);
76955
75788
- assert( sqlite3BtreeIsInTrans(pTo) );
76956
+ assert( sqlite3BtreeTxnState(pTo)==SQLITE_TXN_WRITE );
76957
pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
76958
if( pFd->pMethods ){
76959
i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
@@ -75821,7 +76989,7 @@ SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
76989
sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
76990
}
76991
75824
- assert( sqlite3BtreeIsInTrans(pTo)==0 );
76992
+ assert( sqlite3BtreeTxnState(pTo)!=SQLITE_TXN_WRITE );
76993
copy_finished:
76994
sqlite3BtreeLeave(pFrom);
76995
sqlite3BtreeLeave(pTo);
@@ -75908,7 +77076,9 @@ SQLITE_PRIVATE int sqlite3VdbeCheckMemInvariants(Mem *p){
77076
77077
/* The szMalloc field holds the correct memory allocation size */
77078
assert( p->szMalloc==0
75911
- || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
77079
+ || (p->flags==MEM_Undefined
77080
+ && p->szMalloc<=sqlite3DbMallocSize(p->db,p->zMalloc))
77081
+ || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc));
77082
77083
/* If p holds a string or blob, the Mem.z must point to exactly
77084
** one of the following:
@@ -76072,7 +77242,9 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPre
77242
testcase( bPreserve && pMem->z==0 );
77243
77244
assert( pMem->szMalloc==0
76075
- || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
77245
+ || (pMem->flags==MEM_Undefined
77246
+ && pMem->szMalloc<=sqlite3DbMallocSize(pMem->db,pMem->zMalloc))
77247
+ || pMem->szMalloc==sqlite3DbMallocSize(pMem->db,pMem->zMalloc));
77248
if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
77249
if( pMem->db ){
77250
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
@@ -76901,11 +78073,11 @@ SQLITE_PRIVATE void sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){
78073
SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78074
Mem *pMem, /* Memory cell to set to string value */
78075
const char *z, /* String pointer */
76904
- int n, /* Bytes in string, or negative */
78076
+ i64 n, /* Bytes in string, or negative */
78077
u8 enc, /* Encoding of z. 0 for BLOBs */
78078
void (*xDel)(void*) /* Destructor function */
78079
){
76908
- int nByte = n; /* New value for pMem->n */
78080
+ i64 nByte = n; /* New value for pMem->n */
78081
int iLimit; /* Maximum allowed string or blob size */
78082
u16 flags = 0; /* New value for pMem->flags */
78083
@@ -76927,7 +78099,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78099
if( nByte<0 ){
78100
assert( enc!=0 );
78101
if( enc==SQLITE_UTF8 ){
76930
- nByte = 0x7fffffff & (int)strlen(z);
78102
+ nByte = strlen(z);
78103
}else{
78104
for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
78105
}
@@ -76939,7 +78111,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78111
** management (one of MEM_Dyn or MEM_Static).
78112
*/
78113
if( xDel==SQLITE_TRANSIENT ){
76942
- u32 nAlloc = nByte;
78114
+ i64 nAlloc = nByte;
78115
if( flags&MEM_Term ){
78116
nAlloc += (enc==SQLITE_UTF8?1:2);
78117
}
@@ -76965,7 +78137,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78137
}
78138
}
78139
76968
- pMem->n = nByte;
78140
+ pMem->n = (int)(nByte & 0x7fffffff);
78141
pMem->flags = flags;
78142
if( enc ){
78143
pMem->enc = enc;
@@ -76985,7 +78157,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemSetStr(
78157
#endif
78158
78159
if( nByte>iLimit ){
76988
- return SQLITE_TOOBIG;
78160
+ return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
78161
}
78162
78163
return SQLITE_OK;
@@ -77776,7 +78948,7 @@ SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){
78948
p->pNext = db->pVdbe;
78949
p->pPrev = 0;
78950
db->pVdbe = p;
77779
- p->magic = VDBE_MAGIC_INIT;
78951
+ p->iVdbeMagic = VDBE_MAGIC_INIT;
78952
p->pParse = pParse;
78953
pParse->pVdbe = p;
78954
assert( pParse->aLabel==0 );
@@ -77977,7 +79149,7 @@ SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
79149
VdbeOp *pOp;
79150
79151
i = p->nOp;
77980
- assert( p->magic==VDBE_MAGIC_INIT );
79152
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
79153
assert( op>=0 && op<0xff );
79154
if( p->nOpAlloc<=i ){
79155
return growOp3(p, op, p1, p2, p3);
@@ -78212,10 +79384,12 @@ SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse *pParse){
79384
** The zWhere string must have been obtained from sqlite3_malloc().
79385
** This routine will take ownership of the allocated memory.
79386
*/
78215
-SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere){
79387
+SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere, u16 p5){
79388
int j;
79389
sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC);
79390
+ sqlite3VdbeChangeP5(p, p5);
79391
for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j);
79392
+ sqlite3MayAbort(p->pParse);
79393
}
79394
79395
/*
@@ -78305,7 +79479,7 @@ static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
79479
SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){
79480
Parse *p = v->pParse;
79481
int j = ADDR(x);
78308
- assert( v->magic==VDBE_MAGIC_INIT );
79482
+ assert( v->iVdbeMagic==VDBE_MAGIC_INIT );
79483
assert( j<-p->nLabel );
79484
assert( j>=0 );
79485
#ifdef SQLITE_DEBUG
@@ -78444,7 +79618,7 @@ SQLITE_PRIVATE int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
79618
if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
79619
|| opcode==OP_VDestroy
79620
|| opcode==OP_VCreate
78447
- || (opcode==OP_ParseSchema && pOp->p4.z==0)
79621
+ || opcode==OP_ParseSchema
79622
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
79623
&& ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
79624
){
@@ -78630,7 +79804,7 @@ static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
79804
** Return the address of the next instruction to be inserted.
79805
*/
79806
SQLITE_PRIVATE int sqlite3VdbeCurrentAddr(Vdbe *p){
78633
- assert( p->magic==VDBE_MAGIC_INIT );
79807
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
79808
return p->nOp;
79809
}
79810
@@ -78715,7 +79889,7 @@ SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(
79889
int i;
79890
VdbeOp *pOut, *pFirst;
79891
assert( nOp>0 );
78718
- assert( p->magic==VDBE_MAGIC_INIT );
79892
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
79893
if( p->nOp + nOp > p->nOpAlloc && growOpArray(p, nOp) ){
79894
return 0;
79895
}
@@ -79039,7 +80213,7 @@ SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe *p, int addr, const char *zP4, int
80213
sqlite3 *db;
80214
assert( p!=0 );
80215
db = p->db;
79042
- assert( p->magic==VDBE_MAGIC_INIT );
80216
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
80217
assert( p->aOp!=0 || db->mallocFailed );
80218
if( db->mallocFailed ){
80219
if( n!=P4_VTAB ) freeP4(db, n, (void*)*(char**)&zP4);
@@ -79168,7 +80342,7 @@ SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
80342
/* C89 specifies that the constant "dummy" will be initialized to all
80343
** zeros, which is correct. MSVC generates a warning, nevertheless. */
80344
static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
79171
- assert( p->magic==VDBE_MAGIC_INIT );
80345
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
80346
if( addr<0 ){
80347
addr = p->nOp - 1;
80348
}
@@ -79226,11 +80400,7 @@ SQLITE_PRIVATE char *sqlite3VdbeDisplayComment(
80400
char c;
80401
zSynopsis = zOpName += nOpName + 1;
80402
if( strncmp(zSynopsis,"IF ",3)==0 ){
79229
- if( pOp->p5 & SQLITE_STOREP2 ){
79230
- sqlite3_snprintf(sizeof(zAlt), zAlt, "r[P2] = (%s)", zSynopsis+3);
79231
- }else{
79232
- sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3);
79233
- }
80403
+ sqlite3_snprintf(sizeof(zAlt), zAlt, "if %s goto P2", zSynopsis+3);
80404
zSynopsis = zAlt;
80405
}
80406
for(ii=0; (c = zSynopsis[ii])!=0; ii++){
@@ -79262,7 +80432,7 @@ SQLITE_PRIVATE char *sqlite3VdbeDisplayComment(
80432
sqlite3_str_appendf(&x, "%d", v1);
80433
}else if( pCtx->argc>1 ){
80434
sqlite3_str_appendf(&x, "%d..%d", v1, v1+pCtx->argc-1);
79265
- }else{
80435
+ }else if( x.accError==0 ){
80436
assert( x.nChar>2 );
80437
x.nChar -= 2;
80438
ii++;
@@ -79853,7 +81023,7 @@ SQLITE_PRIVATE int sqlite3VdbeList(
81023
Op *pOp; /* Current opcode */
81024
81025
assert( p->explain );
79856
- assert( p->magic==VDBE_MAGIC_RUN );
81026
+ assert( p->iVdbeMagic==VDBE_MAGIC_RUN );
81027
assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM );
81028
81029
/* Even though this opcode does not use dynamic strings for
@@ -80033,14 +81203,14 @@ SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
81203
int i;
81204
#endif
81205
assert( p!=0 );
80036
- assert( p->magic==VDBE_MAGIC_INIT || p->magic==VDBE_MAGIC_RESET );
81206
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT || p->iVdbeMagic==VDBE_MAGIC_RESET );
81207
81208
/* There should be at least one opcode.
81209
*/
81210
assert( p->nOp>0 );
81211
81212
/* Set the magic to VDBE_MAGIC_RUN sooner rather than later. */
80043
- p->magic = VDBE_MAGIC_RUN;
81213
+ p->iVdbeMagic = VDBE_MAGIC_RUN;
81214
81215
#ifdef SQLITE_DEBUG
81216
for(i=0; i<p->nMem; i++){
@@ -80096,8 +81266,10 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
81266
assert( p!=0 );
81267
assert( p->nOp>0 );
81268
assert( pParse!=0 );
80099
- assert( p->magic==VDBE_MAGIC_INIT );
81269
+ assert( p->iVdbeMagic==VDBE_MAGIC_INIT );
81270
assert( pParse==p->pParse );
81271
+ p->pVList = pParse->pVList;
81272
+ pParse->pVList = 0;
81273
db = p->db;
81274
assert( db->mallocFailed==0 );
81275
nVar = pParse->nVar;
@@ -80182,8 +81354,6 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
81354
}
81355
}
This file is too large to show in full.
database/sqlite/sqlite3.h
+218
-39
@@ -123,9 +123,9 @@ extern "C" {
123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124
** [sqlite_version()] and [sqlite_source_id()].
125
*/
126
-#define SQLITE_VERSION "3.33.0"
127
-#define SQLITE_VERSION_NUMBER 3033000
128
-#define SQLITE_SOURCE_ID "2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt1"
126
+#define SQLITE_VERSION "3.36.0"
127
+#define SQLITE_VERSION_NUMBER 3036000
128
+#define SQLITE_SOURCE_ID "2021-06-18 18:36:39 5c9a6c06871cb9fe42814af9c039eb6da5427a6ec28f187af7ebfb62eafa66e5"
129
130
/*
131
** CAPI3REF: Run-Time Library Version Numbers
@@ -504,6 +504,7 @@ SQLITE_API int sqlite3_exec(
504
#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
505
#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
506
#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
507
+#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
508
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
509
#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
510
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
@@ -1127,6 +1128,23 @@ struct sqlite3_io_methods {
1128
** file to the database file, but before the *-shm file is updated to
1129
** record the fact that the pages have been checkpointed.
1130
** </ul>
1131
+**
1132
+** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1133
+** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
1134
+** whether or not there is a database client in another process with a wal-mode
1135
+** transaction open on the database or not. It is only available on unix.The
1136
+** (void*) argument passed with this file-control should be a pointer to a
1137
+** value of type (int). The integer value is set to 1 if the database is a wal
1138
+** mode database and there exists at least one client in another process that
1139
+** currently has an SQL transaction open on the database. It is set to 0 if
1140
+** the database is not a wal-mode db, or if there is no such connection in any
1141
+** other process. This opcode cannot be used to detect transactions opened
1142
+** by clients within the current process, only within other processes.
1143
+** </ul>
1144
+**
1145
+** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1146
+** Used by the cksmvfs VFS module only.
1147
+** </ul>
1148
*/
1149
#define SQLITE_FCNTL_LOCKSTATE 1
1150
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
@@ -1166,6 +1184,8 @@ struct sqlite3_io_methods {
1184
#define SQLITE_FCNTL_CKPT_DONE 37
1185
#define SQLITE_FCNTL_RESERVE_BYTES 38
1186
#define SQLITE_FCNTL_CKPT_START 39
1187
+#define SQLITE_FCNTL_EXTERNAL_READER 40
1188
+#define SQLITE_FCNTL_CKSM_FILE 41
1189
1190
/* deprecated names */
1191
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
@@ -2114,7 +2134,13 @@ struct sqlite3_mem_methods {
2134
** The second parameter is a pointer to an integer into which
2135
** is written 0 or 1 to indicate whether triggers are disabled or enabled
2136
** following this call. The second parameter may be a NULL pointer, in
2117
-** which case the trigger setting is not reported back. </dd>
2137
+** which case the trigger setting is not reported back.
2138
+**
2139
+** <p>Originally this option disabled all triggers. ^(However, since
2140
+** SQLite version 3.35.0, TEMP triggers are still allowed even if
2141
+** this option is off. So, in other words, this option now only disables
2142
+** triggers in the main database schema or in the schemas of ATTACH-ed
2143
+** databases.)^ </dd>
2144
**
2145
** [[SQLITE_DBCONFIG_ENABLE_VIEW]]
2146
** <dt>SQLITE_DBCONFIG_ENABLE_VIEW</dt>
@@ -2125,7 +2151,13 @@ struct sqlite3_mem_methods {
2151
** The second parameter is a pointer to an integer into which
2152
** is written 0 or 1 to indicate whether views are disabled or enabled
2153
** following this call. The second parameter may be a NULL pointer, in
2128
-** which case the view setting is not reported back. </dd>
2154
+** which case the view setting is not reported back.
2155
+**
2156
+** <p>Originally this option disabled all views. ^(However, since
2157
+** SQLite version 3.35.0, TEMP views are still allowed even if
2158
+** this option is off. So, in other words, this option now only disables
2159
+** views in the main database schema or in the schemas of ATTACH-ed
2160
+** databases.)^ </dd>
2161
**
2162
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2163
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
@@ -3498,6 +3530,7 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3530
** that uses dot-files in place of posix advisory locking.
3531
** <tr><td> file:data.db?mode=readonly <td>
3532
** An error. "readonly" is not a valid option for the "mode" parameter.
3533
+** Use "ro" instead: "file:data.db?mode=ro".
3534
** </table>
3535
**
3536
** ^URI hexadecimal escape sequences (%HH) are supported within the path and
@@ -3696,7 +3729,7 @@ SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*);
3729
** If the Y parameter to sqlite3_free_filename(Y) is anything other
3730
** than a NULL pointer or a pointer previously acquired from
3731
** sqlite3_create_filename(), then bad things such as heap
3699
-** corruption or segfaults may occur. The value Y should be
3732
+** corruption or segfaults may occur. The value Y should not be
3733
** used again after sqlite3_free_filename(Y) has been called. This means
3734
** that if the [sqlite3_vfs.xOpen()] method of a VFS has been called using Y,
3735
** then the corresponding [sqlite3_module.xClose() method should also be
@@ -4165,6 +4198,15 @@ SQLITE_API const char *sqlite3_normalized_sql(sqlite3_stmt *pStmt);
4198
** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and
4199
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4200
** sqlite3_stmt_readonly() returns false for those commands.
4201
+**
4202
+** ^This routine returns false if there is any possibility that the
4203
+** statement might change the database file. ^A false return does
4204
+** not guarantee that the statement will change the database file.
4205
+** ^For example, an UPDATE statement might have a WHERE clause that
4206
+** makes it a no-op, but the sqlite3_stmt_readonly() result would still
4207
+** be false. ^Similarly, a CREATE TABLE IF NOT EXISTS statement is a
4208
+** read-only no-op if the table already exists, but
4209
+** sqlite3_stmt_readonly() still returns false for such a statement.
4210
*/
4211
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4212
@@ -4334,18 +4376,22 @@ typedef struct sqlite3_context sqlite3_context;
4376
** contain embedded NULs. The result of expressions involving strings
4377
** with embedded NULs is undefined.
4378
**
4337
-** ^The fifth argument to the BLOB and string binding interfaces
4338
-** is a destructor used to dispose of the BLOB or
4339
-** string after SQLite has finished with it. ^The destructor is called
4340
-** to dispose of the BLOB or string even if the call to the bind API fails,
4341
-** except the destructor is not called if the third parameter is a NULL
4342
-** pointer or the fourth parameter is negative.
4343
-** ^If the fifth argument is
4344
-** the special value [SQLITE_STATIC], then SQLite assumes that the
4345
-** information is in static, unmanaged space and does not need to be freed.
4346
-** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
4347
-** SQLite makes its own private copy of the data immediately, before
4348
-** the sqlite3_bind_*() routine returns.
4379
+** ^The fifth argument to the BLOB and string binding interfaces controls
4380
+** or indicates the lifetime of the object referenced by the third parameter.
4381
+** These three options exist:
4382
+** ^ (1) A destructor to dispose of the BLOB or string after SQLite has finished
4383
+** with it may be passed. ^It is called to dispose of the BLOB or string even
4384
+** if the call to the bind API fails, except the destructor is not called if
4385
+** the third parameter is a NULL pointer or the fourth parameter is negative.
4386
+** ^ (2) The special constant, [SQLITE_STATIC], may be passsed to indicate that
4387
+** the application remains responsible for disposing of the object. ^In this
4388
+** case, the object and the provided pointer to it must remain valid until
4389
+** either the prepared statement is finalized or the same SQL parameter is
4390
+** bound to something else, whichever occurs sooner.
4391
+** ^ (3) The constant, [SQLITE_TRANSIENT], may be passed to indicate that the
4392
+** object is to be copied prior to the return from sqlite3_bind_*(). ^The
4393
+** object and pointer to it must remain valid until then. ^SQLite will then
4394
+** manage the lifetime of its private copy.
4395
**
4396
** ^The sixth argument to sqlite3_bind_text64() must be one of
4397
** [SQLITE_UTF8], [SQLITE_UTF16], [SQLITE_UTF16BE], or [SQLITE_UTF16LE]
@@ -5087,7 +5133,6 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
5133
** within VIEWs, TRIGGERs, CHECK constraints, generated column expressions,
5134
** index expressions, or the WHERE clause of partial indexes.
5135
**
5090
-** <span style="background-color:#ffff90;">
5136
** For best security, the [SQLITE_DIRECTONLY] flag is recommended for
5137
** all application-defined SQL functions that do not need to be
5138
** used inside of triggers, view, CHECK constraints, or other elements of
@@ -5097,7 +5142,6 @@ SQLITE_API int sqlite3_reset(sqlite3_stmt *pStmt);
5142
** a database file to include invocations of the function with parameters
5143
** chosen by the attacker, which the application will then execute when
5144
** the database file is opened and read.
5100
-** </span>
5145
**
5146
** ^(The fifth parameter is an arbitrary pointer. The implementation of the
5147
** function can gain access to this pointer using [sqlite3_user_data()].)^
@@ -6186,6 +6230,57 @@ SQLITE_API const char *sqlite3_db_filename(sqlite3 *db, const char *zDbName);
6230
*/
6231
SQLITE_API int sqlite3_db_readonly(sqlite3 *db, const char *zDbName);
6232
6233
+/*
6234
+** CAPI3REF: Determine the transaction state of a database
6235
+** METHOD: sqlite3
6236
+**
6237
+** ^The sqlite3_txn_state(D,S) interface returns the current
6238
+** [transaction state] of schema S in database connection D. ^If S is NULL,
6239
+** then the highest transaction state of any schema on database connection D
6240
+** is returned. Transaction states are (in order of lowest to highest):
6241
+** <ol>
6242
+** <li value="0"> SQLITE_TXN_NONE
6243
+** <li value="1"> SQLITE_TXN_READ
6244
+** <li value="2"> SQLITE_TXN_WRITE
6245
+** </ol>
6246
+** ^If the S argument to sqlite3_txn_state(D,S) is not the name of
6247
+** a valid schema, then -1 is returned.
6248
+*/
6249
+SQLITE_API int sqlite3_txn_state(sqlite3*,const char *zSchema);
6250
+
6251
+/*
6252
+** CAPI3REF: Allowed return values from [sqlite3_txn_state()]
6253
+** KEYWORDS: {transaction state}
6254
+**
6255
+** These constants define the current transaction state of a database file.
6256
+** ^The [sqlite3_txn_state(D,S)] interface returns one of these
6257
+** constants in order to describe the transaction state of schema S
6258
+** in [database connection] D.
6259
+**
6260
+** <dl>
6261
+** [[SQLITE_TXN_NONE]] <dt>SQLITE_TXN_NONE</dt>
6262
+** <dd>The SQLITE_TXN_NONE state means that no transaction is currently
6263
+** pending.</dd>
6264
+**
6265
+** [[SQLITE_TXN_READ]] <dt>SQLITE_TXN_READ</dt>
6266
+** <dd>The SQLITE_TXN_READ state means that the database is currently
6267
+** in a read transaction. Content has been read from the database file
6268
+** but nothing in the database file has changed. The transaction state
6269
+** will advanced to SQLITE_TXN_WRITE if any changes occur and there are
6270
+** no other conflicting concurrent write transactions. The transaction
6271
+** state will revert to SQLITE_TXN_NONE following a [ROLLBACK] or
6272
+** [COMMIT].</dd>
6273
+**
6274
+** [[SQLITE_TXN_WRITE]] <dt>SQLITE_TXN_WRITE</dt>
6275
+** <dd>The SQLITE_TXN_WRITE state means that the database is currently
6276
+** in a write transaction. Content has been written to the database file
6277
+** but has not yet committed. The transaction state will change to
6278
+** to SQLITE_TXN_NONE at the next [ROLLBACK] or [COMMIT].</dd>
6279
+*/
6280
+#define SQLITE_TXN_NONE 0
6281
+#define SQLITE_TXN_READ 1
6282
+#define SQLITE_TXN_WRITE 2
6283
+
6284
/*
6285
** CAPI3REF: Find the next prepared statement
6286
** METHOD: sqlite3
@@ -7712,7 +7807,10 @@ SQLITE_API int sqlite3_test_control(int op, ...);
7807
#define SQLITE_TESTCTRL_RESULT_INTREAL 27
7808
#define SQLITE_TESTCTRL_PRNG_SEED 28
7809
#define SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS 29
7715
-#define SQLITE_TESTCTRL_LAST 29 /* Largest TESTCTRL */
7810
+#define SQLITE_TESTCTRL_SEEK_COUNT 30
7811
+#define SQLITE_TESTCTRL_TRACEFLAGS 31
7812
+#define SQLITE_TESTCTRL_TUNE 32
7813
+#define SQLITE_TESTCTRL_LAST 32 /* Largest TESTCTRL */
7814
7815
/*
7816
** CAPI3REF: SQL Keyword Checking
@@ -9192,10 +9290,11 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
9290
** CAPI3REF: Determine If Virtual Table Column Access Is For UPDATE
9291
**
9292
** If the sqlite3_vtab_nochange(X) routine is called within the [xColumn]
9195
-** method of a [virtual table], then it returns true if and only if the
9293
+** method of a [virtual table], then it might return true if the
9294
** column is being fetched as part of an UPDATE operation during which the
9197
-** column value will not change. Applications might use this to substitute
9198
-** a return value that is less expensive to compute and that the corresponding
9295
+** column value will not change. The virtual table implementation can use
9296
+** this hint as permission to substitute a return value that is less
9297
+** expensive to compute and that the corresponding
9298
** [xUpdate] method understands as a "no-change" value.
9299
**
9300
** If the [xColumn] method calls sqlite3_vtab_nochange() and finds that
@@ -9204,6 +9303,12 @@ SQLITE_API int sqlite3_vtab_on_conflict(sqlite3 *);
9303
** any of the [sqlite3_result_int|sqlite3_result_xxxxx() interfaces].
9304
** In that case, [sqlite3_value_nochange(X)] will return true for the
9305
** same column in the [xUpdate] method.
9306
+**
9307
+** The sqlite3_vtab_nochange() routine is an optimization. Virtual table
9308
+** implementations should continue to give a correct answer even if the
9309
+** sqlite3_vtab_nochange() interface were to always return false. In the
9310
+** current implementation, the sqlite3_vtab_nochange() interface does always
9311
+** returns false for the enhanced [UPDATE FROM] statement.
9312
*/
9313
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9314
@@ -9345,6 +9450,7 @@ SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt*);
9450
9451
/*
9452
** CAPI3REF: Flush caches to disk mid-transaction
9453
+** METHOD: sqlite3
9454
**
9455
** ^If a write-transaction is open on [database connection] D when the
9456
** [sqlite3_db_cacheflush(D)] interface invoked, any dirty
@@ -9377,6 +9483,7 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
9483
9484
/*
9485
** CAPI3REF: The pre-update hook.
9486
+** METHOD: sqlite3
9487
**
9488
** ^These interfaces are only available if SQLite is compiled using the
9489
** [SQLITE_ENABLE_PREUPDATE_HOOK] compile-time option.
@@ -9417,7 +9524,7 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
9524
** seventh parameter is the final rowid value of the row being inserted
9525
** or updated. The value of the seventh parameter passed to the callback
9526
** function is not defined for operations on WITHOUT ROWID tables, or for
9420
-** INSERT operations on rowid tables.
9527
+** DELETE operations on rowid tables.
9528
**
9529
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
9530
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
@@ -9455,6 +9562,15 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
9562
** triggers; or 2 for changes resulting from triggers called by top-level
9563
** triggers; and so forth.
9564
**
9565
+** When the [sqlite3_blob_write()] API is used to update a blob column,
9566
+** the pre-update hook is invoked with SQLITE_DELETE. This is because the
9567
+** in this case the new values are not available. In this case, when a
9568
+** callback made with op==SQLITE_DELETE is actuall a write using the
9569
+** sqlite3_blob_write() API, the [sqlite3_preupdate_blobwrite()] returns
9570
+** the index of the column being written. In other cases, where the
9571
+** pre-update hook is being invoked for some other reason, including a
9572
+** regular DELETE, sqlite3_preupdate_blobwrite() returns -1.
9573
+**
9574
** See also: [sqlite3_update_hook()]
9575
*/
9576
#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
@@ -9475,10 +9591,12 @@ SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
9591
SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
9592
SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
9593
SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
9594
+SQLITE_API int sqlite3_preupdate_blobwrite(sqlite3 *);
9595
#endif
9596
9597
/*
9598
** CAPI3REF: Low-level system error code
9599
+** METHOD: sqlite3
9600
**
9601
** ^Attempt to return the underlying operating system error code or error
9602
** number that caused the most recent I/O error or failure to open a file.
@@ -9712,8 +9830,8 @@ SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const c
9830
** SQLITE_SERIALIZE_NOCOPY bit is omitted from argument F if a memory
9831
** allocation error occurs.
9832
**
9715
-** This interface is only available if SQLite is compiled with the
9716
-** [SQLITE_ENABLE_DESERIALIZE] option.
9833
+** This interface is omitted if SQLite is compiled with the
9834
+** [SQLITE_OMIT_DESERIALIZE] option.
9835
*/
9836
SQLITE_API unsigned char *sqlite3_serialize(
9837
sqlite3 *db, /* The database connection */
@@ -9764,8 +9882,8 @@ SQLITE_API unsigned char *sqlite3_serialize(
9882
** SQLITE_DESERIALIZE_FREEONCLOSE bit is set in argument F, then
9883
** [sqlite3_free()] is invoked on argument P prior to returning.
9884
**
9767
-** This interface is only available if SQLite is compiled with the
9768
-** [SQLITE_ENABLE_DESERIALIZE] option.
9885
+** This interface is omitted if SQLite is compiled with the
9886
+** [SQLITE_OMIT_DESERIALIZE] option.
9887
*/
9888
SQLITE_API int sqlite3_deserialize(
9889
sqlite3 *db, /* The database connection */
@@ -10014,6 +10132,38 @@ SQLITE_API int sqlite3session_create(
10132
*/
10133
SQLITE_API void sqlite3session_delete(sqlite3_session *pSession);
10134
10135
+/*
10136
+** CAPIREF: Conigure a Session Object
10137
+** METHOD: sqlite3_session
10138
+**
10139
+** This method is used to configure a session object after it has been
10140
+** created. At present the only valid value for the second parameter is
10141
+** [SQLITE_SESSION_OBJCONFIG_SIZE].
10142
+**
10143
+** Arguments for sqlite3session_object_config()
10144
+**
10145
+** The following values may passed as the the 4th parameter to
10146
+** sqlite3session_object_config().
10147
+**
10148
+** <dt>SQLITE_SESSION_OBJCONFIG_SIZE <dd>
10149
+** This option is used to set, clear or query the flag that enables
10150
+** the [sqlite3session_changeset_size()] API. Because it imposes some
10151
+** computational overhead, this API is disabled by default. Argument
10152
+** pArg must point to a value of type (int). If the value is initially
10153
+** 0, then the sqlite3session_changeset_size() API is disabled. If it
10154
+** is greater than 0, then the same API is enabled. Or, if the initial
10155
+** value is less than zero, no change is made. In all cases the (int)
10156
+** variable is set to 1 if the sqlite3session_changeset_size() API is
10157
+** enabled following the current call, or 0 otherwise.
10158
+**
10159
+** It is an error (SQLITE_MISUSE) to attempt to modify this setting after
10160
+** the first table has been attached to the session object.
10161
+*/
10162
+SQLITE_API int sqlite3session_object_config(sqlite3_session*, int op, void *pArg);
10163
+
10164
+/*
10165
+*/
10166
+#define SQLITE_SESSION_OBJCONFIG_SIZE 1
10167
10168
/*
10169
** CAPI3REF: Enable Or Disable A Session Object
@@ -10258,6 +10408,22 @@ SQLITE_API int sqlite3session_changeset(
10408
void **ppChangeset /* OUT: Buffer containing changeset */
10409
);
10410
10411
+/*
10412
+** CAPI3REF: Return An Upper-limit For The Size Of The Changeset
10413
+** METHOD: sqlite3_session
10414
+**
10415
+** By default, this function always returns 0. For it to return
10416
+** a useful result, the sqlite3_session object must have been configured
10417
+** to enable this API using sqlite3session_object_config() with the
10418
+** SQLITE_SESSION_OBJCONFIG_SIZE verb.
10419
+**
10420
+** When enabled, this function returns an upper limit, in bytes, for the size
10421
+** of the changeset that might be produced if sqlite3session_changeset() were
10422
+** called. The final changeset size might be equal to or smaller than the
10423
+** size in bytes returned by this function.
10424
+*/
10425
+SQLITE_API sqlite3_int64 sqlite3session_changeset_size(sqlite3_session *pSession);
10426
+
10427
/*
10428
** CAPI3REF: Load The Difference Between Tables Into A Session
10429
** METHOD: sqlite3_session
@@ -10375,6 +10541,14 @@ SQLITE_API int sqlite3session_patchset(
10541
*/
10542
SQLITE_API int sqlite3session_isempty(sqlite3_session *pSession);
10543
10544
+/*
10545
+** CAPI3REF: Query for the amount of heap memory used by a session object.
10546
+**
10547
+** This API returns the total amount of heap memory in bytes currently
10548
+** used by the session object passed as the only argument.
10549
+*/
10550
+SQLITE_API sqlite3_int64 sqlite3session_memory_used(sqlite3_session *pSession);
10551
+
10552
/*
10553
** CAPI3REF: Create An Iterator To Traverse A Changeset
10554
** CONSTRUCTOR: sqlite3_changeset_iter
@@ -10477,18 +10651,23 @@ SQLITE_API int sqlite3changeset_next(sqlite3_changeset_iter *pIter);
10651
** call to [sqlite3changeset_next()] must have returned [SQLITE_ROW]. If this
10652
** is not the case, this function returns [SQLITE_MISUSE].
10653
**
10480
-** If argument pzTab is not NULL, then *pzTab is set to point to a
10481
-** nul-terminated utf-8 encoded string containing the name of the table
10482
-** affected by the current change. The buffer remains valid until either
10483
-** sqlite3changeset_next() is called on the iterator or until the
10484
-** conflict-handler function returns. If pnCol is not NULL, then *pnCol is
10485
-** set to the number of columns in the table affected by the change. If
10486
-** pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
10654
+** Arguments pOp, pnCol and pzTab may not be NULL. Upon return, three
10655
+** outputs are set through these pointers:
10656
+**
10657
+** *pOp is set to one of [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE],
10658
+** depending on the type of change that the iterator currently points to;
10659
+**
10660
+** *pnCol is set to the number of columns in the table affected by the change; and
10661
+**
10662
+** *pzTab is set to point to a nul-terminated utf-8 encoded string containing
10663
+** the name of the table affected by the current change. The buffer remains
10664
+** valid until either sqlite3changeset_next() is called on the iterator
10665
+** or until the conflict-handler function returns.
10666
+**
10667
+** If pbIndirect is not NULL, then *pbIndirect is set to true (1) if the change
10668
** is an indirect change, or false (0) otherwise. See the documentation for
10669
** [sqlite3session_indirect()] for a description of direct and indirect
10489
-** changes. Finally, if pOp is not NULL, then *pOp is set to one of
10490
-** [SQLITE_INSERT], [SQLITE_DELETE] or [SQLITE_UPDATE], depending on the
10491
-** type of change that the iterator currently points to.
10670
+** changes.
10671
**
10672
** If no error occurs, SQLITE_OK is returned. If an error does occur, an
10673
** SQLite error code is returned. The values of the output variables may not