Update SQLITE to version 3.41.2 (#15031)
Upgrade sqlite to 3.41.2
Stelios Fragkakis committed
May 12, 2023 at 09:57 UTC
f2c5cb6b0bc743d5258fdc378a17ffc68ce20d83
2 files changed
+3126
-1411
database/sqlite/sqlite3.c
+2969
-1330
@@ -1,6 +1,6 @@
1
/******************************************************************************
2
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.40.1. By combining all the individual C code files into this
3
+** version 3.41.2. By combining all the individual C code files into this
4
** single large file, the entire code can be compiled as a single translation
5
** unit. This allows many compilers to do optimizations that would not be
6
** possible if the files were compiled separately. Performance improvements
@@ -17,7 +17,6 @@
17
** language. The code for the "sqlite3" command-line shell is also in a
18
** separate file. This file contains only code for the core SQLite library.
19
*/
20
-#define __maybe_unused __attribute__((unused))
20
#define SQLITE_CORE 1
21
#define SQLITE_AMALGAMATION 1
22
#ifndef SQLITE_PRIVATE
@@ -457,9 +456,9 @@ extern "C" {
456
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
457
** [sqlite_version()] and [sqlite_source_id()].
458
*/
460
-#define SQLITE_VERSION "3.40.1"
461
-#define SQLITE_VERSION_NUMBER 3040001
462
-#define SQLITE_SOURCE_ID "2022-12-28 14:03:47 df5c253c0b3dd24916e4ec7cf77d3db5294cc9fd45ae7b9c5e82ad8197f38a24"
459
+#define SQLITE_VERSION "3.41.2"
460
+#define SQLITE_VERSION_NUMBER 3041002
461
+#define SQLITE_SOURCE_ID "2023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69cffde2924203304e8ffc4155597af0c191da"
462
463
/*
464
** CAPI3REF: Run-Time Library Version Numbers
@@ -874,6 +873,7 @@ SQLITE_API int sqlite3_exec(
873
#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
874
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
875
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
876
+#define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))
877
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
878
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
879
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
@@ -1486,7 +1486,6 @@ struct sqlite3_io_methods {
1486
** in wal mode after the client has finished copying pages from the wal
1487
** file to the database file, but before the *-shm file is updated to
1488
** record the fact that the pages have been checkpointed.
1489
-** </ul>
1489
**
1490
** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1491
** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
@@ -1499,16 +1498,16 @@ struct sqlite3_io_methods {
1498
** the database is not a wal-mode db, or if there is no such connection in any
1499
** other process. This opcode cannot be used to detect transactions opened
1500
** by clients within the current process, only within other processes.
1502
-** </ul>
1501
**
1502
** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1505
-** Used by the cksmvfs VFS module only.
1503
+** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the
1504
+** [checksum VFS shim] only.
1505
**
1506
** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1507
** If there is currently no transaction open on the database, and the
1509
-** database is not a temp db, then this file-control purges the contents
1510
-** of the in-memory page cache. If there is an open transaction, or if
1511
-** the db is a temp-db, it is a no-op, not an error.
1508
+** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
1509
+** purges the contents of the in-memory page cache. If there is an open
1510
+** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.
1511
** </ul>
1512
*/
1513
#define SQLITE_FCNTL_LOCKSTATE 1
@@ -2495,7 +2494,7 @@ struct sqlite3_mem_methods {
2494
** configuration for a database connection can only be changed when that
2495
** connection is not currently using lookaside memory, or in other words
2496
** when the "current value" returned by
2498
-** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2497
+** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2498
** Any attempt to change the lookaside memory configuration when lookaside
2499
** memory is in use leaves the configuration unchanged and returns
2500
** [SQLITE_BUSY].)^</dd>
@@ -2645,8 +2644,12 @@ struct sqlite3_mem_methods {
2644
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2645
** </ol>
2646
** Because resetting a database is destructive and irreversible, the
2648
-** process requires the use of this obscure API and multiple steps to help
2649
-** ensure that it does not happen by accident.
2647
+** process requires the use of this obscure API and multiple steps to
2648
+** help ensure that it does not happen by accident. Because this
2649
+** feature must be capable of resetting corrupt databases, and
2650
+** shutting down virtual tables may require access to that corrupt
2651
+** storage, the library must abandon any installed virtual tables
2652
+** without calling their xDestroy() methods.
2653
**
2654
** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2655
** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
@@ -2985,8 +2988,12 @@ SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
2988
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2989
** SQL statements is a no-op and has no effect on SQL statements
2990
** that are started after the sqlite3_interrupt() call returns.
2991
+**
2992
+** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2993
+** or not an interrupt is currently in effect for [database connection] D.
2994
*/
2995
SQLITE_API void sqlite3_interrupt(sqlite3*);
2996
+SQLITE_API int sqlite3_is_interrupted(sqlite3*);
2997
2998
/*
2999
** CAPI3REF: Determine If An SQL Statement Is Complete
@@ -3604,8 +3611,8 @@ SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
3611
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3612
** information as is provided by the [sqlite3_profile()] callback.
3613
** ^The P argument is a pointer to the [prepared statement] and the
3607
-** X argument points to a 64-bit integer which is the estimated of
3608
-** the number of nanosecond that the prepared statement took to run.
3614
+** X argument points to a 64-bit integer which is approximately
3615
+** the number of nanoseconds that the prepared statement took to run.
3616
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3617
**
3618
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
@@ -3668,7 +3675,7 @@ SQLITE_API int sqlite3_trace_v2(
3675
**
3676
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3677
** function X to be invoked periodically during long running calls to
3671
-** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3678
+** [sqlite3_step()] and [sqlite3_prepare()] and similar for
3679
** database connection D. An example use for this
3680
** interface is to keep a GUI updated during a large query.
3681
**
@@ -3693,6 +3700,13 @@ SQLITE_API int sqlite3_trace_v2(
3700
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3701
** database connections for the meaning of "modify" in this paragraph.
3702
**
3703
+** The progress handler callback would originally only be invoked from the
3704
+** bytecode engine. It still might be invoked during [sqlite3_prepare()]
3705
+** and similar because those routines might force a reparse of the schema
3706
+** which involves running the bytecode engine. However, beginning with
3707
+** SQLite version 3.41.0, the progress handler callback might also be
3708
+** invoked directly from [sqlite3_prepare()] while analyzing and generating
3709
+** code for complex queries.
3710
*/
3711
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3712
@@ -3729,13 +3743,18 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3743
**
3744
** <dl>
3745
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3732
-** <dd>The database is opened in read-only mode. If the database does not
3733
-** already exist, an error is returned.</dd>)^
3746
+** <dd>The database is opened in read-only mode. If the database does
3747
+** not already exist, an error is returned.</dd>)^
3748
**
3749
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3736
-** <dd>The database is opened for reading and writing if possible, or reading
3737
-** only if the file is write protected by the operating system. In either
3738
-** case the database must already exist, otherwise an error is returned.</dd>)^
3750
+** <dd>The database is opened for reading and writing if possible, or
3751
+** reading only if the file is write protected by the operating
3752
+** system. In either case the database must already exist, otherwise
3753
+** an error is returned. For historical reasons, if opening in
3754
+** read-write mode fails due to OS-level permissions, an attempt is
3755
+** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3756
+** used to determine whether the database is actually
3757
+** read-write.</dd>)^
3758
**
3759
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3760
** <dd>The database is opened for reading and writing, and is created if
@@ -5716,10 +5735,21 @@ SQLITE_API int sqlite3_create_window_function(
5735
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5736
** schema structures such as [CHECK constraints], [DEFAULT clauses],
5737
** [expression indexes], [partial indexes], or [generated columns].
5719
-** The SQLITE_DIRECTONLY flags is a security feature which is recommended
5720
-** for all [application-defined SQL functions], and especially for functions
5721
-** that have side-effects or that could potentially leak sensitive
5722
-** information.
5738
+** <p>
5739
+** The SQLITE_DIRECTONLY flag is recommended for any
5740
+** [application-defined SQL function]
5741
+** that has side-effects or that could potentially leak sensitive information.
5742
+** This will prevent attacks in which an application is tricked
5743
+** into using a database file that has had its schema surreptiously
5744
+** modified to invoke the application-defined function in ways that are
5745
+** harmful.
5746
+** <p>
5747
+** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5748
+** [application-defined SQL functions], regardless of whether or not they
5749
+** are security sensitive, as doing so prevents those functions from being used
5750
+** inside of the database schema, and thus ensures that the database
5751
+** can be inspected and modified using generic tools (such as the [CLI])
5752
+** that do not have access to the application-defined functions.
5753
** </dd>
5754
**
5755
** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
@@ -5860,16 +5890,6 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6
5890
** then the conversion is performed. Otherwise no conversion occurs.
5891
** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
5892
**
5863
-** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],
5864
-** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current encoding
5865
-** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)
5866
-** returns something other than SQLITE_TEXT, then the return value from
5867
-** sqlite3_value_encoding(X) is meaningless. ^Calls to
5868
-** sqlite3_value_text(X), sqlite3_value_text16(X), sqlite3_value_text16be(X),
5869
-** sqlite3_value_text16le(X), sqlite3_value_bytes(X), or
5870
-** sqlite3_value_bytes16(X) might change the encoding of the value X and
5871
-** thus change the return from subsequent calls to sqlite3_value_encoding(X).
5872
-**
5893
** ^Within the [xUpdate] method of a [virtual table], the
5894
** sqlite3_value_nochange(X) interface returns true if and only if
5895
** the column corresponding to X is unchanged by the UPDATE operation
@@ -5934,6 +5954,27 @@ SQLITE_API int sqlite3_value_type(sqlite3_value*);
5954
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5955
SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
5956
SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
5957
+
5958
+/*
5959
+** CAPI3REF: Report the internal text encoding state of an sqlite3_value object
5960
+** METHOD: sqlite3_value
5961
+**
5962
+** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],
5963
+** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding
5964
+** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)
5965
+** returns something other than SQLITE_TEXT, then the return value from
5966
+** sqlite3_value_encoding(X) is meaningless. ^Calls to
5967
+** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)],
5968
+** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or
5969
+** [sqlite3_value_bytes16(X)] might change the encoding of the value X and
5970
+** thus change the return from subsequent calls to sqlite3_value_encoding(X).
5971
+**
5972
+** This routine is intended for used by applications that test and validate
5973
+** the SQLite implementation. This routine is inquiring about the opaque
5974
+** internal state of an [sqlite3_value] object. Ordinary applications should
5975
+** not need to know what the internal state of an sqlite3_value object is and
5976
+** hence should not need to use this interface.
5977
+*/
5978
SQLITE_API int sqlite3_value_encoding(sqlite3_value*);
5979
5980
/*
@@ -7314,15 +7355,6 @@ SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));
7355
*/
7356
SQLITE_API void sqlite3_reset_auto_extension(void);
7357
7317
-/*
7318
-** The interface to the virtual-table mechanism is currently considered
7319
-** to be experimental. The interface might change in incompatible ways.
7320
-** If this is a problem for you, do not use the interface at this time.
7321
-**
7322
-** When the virtual-table mechanism stabilizes, we will declare the
7323
-** interface fixed, support it indefinitely, and remove this comment.
7324
-*/
7325
-
7358
/*
7359
** Structures used by the virtual table interface
7360
*/
@@ -7441,10 +7473,10 @@ struct sqlite3_module {
7473
** when the omit flag is true there is no guarantee that the constraint will
7474
** not be checked again using byte code.)^
7475
**
7444
-** ^The idxNum and idxPtr values are recorded and passed into the
7476
+** ^The idxNum and idxStr values are recorded and passed into the
7477
** [xFilter] method.
7446
-** ^[sqlite3_free()] is used to free idxPtr if and only if
7447
-** needToFreeIdxPtr is true.
7478
+** ^[sqlite3_free()] is used to free idxStr if and only if
7479
+** needToFreeIdxStr is true.
7480
**
7481
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
7482
** the correct order to satisfy the ORDER BY clause so that no separate
@@ -7564,7 +7596,7 @@ struct sqlite3_index_info {
7596
** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7597
** tables, the collating sequence of constraints does not matter (for example
7598
** because the constraints are numeric) and so the sqlite3_vtab_collation()
7567
-** interface is no commonly needed.
7599
+** interface is not commonly needed.
7600
*/
7601
#define SQLITE_INDEX_CONSTRAINT_EQ 2
7602
#define SQLITE_INDEX_CONSTRAINT_GT 4
@@ -7723,16 +7755,6 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
7755
*/
7756
SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
7757
7726
-/*
7727
-** The interface to the virtual-table mechanism defined above (back up
7728
-** to a comment remarkably similar to this one) is currently considered
7729
-** to be experimental. The interface might change in incompatible ways.
7730
-** If this is a problem for you, do not use the interface at this time.
7731
-**
7732
-** When the virtual-table mechanism stabilizes, we will declare the
7733
-** interface fixed, support it indefinitely, and remove this comment.
7734
-*/
7735
-
7758
/*
7759
** CAPI3REF: A Handle To An Open BLOB
7760
** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -9936,7 +9958,7 @@ SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9958
** <li><p> Otherwise, "BINARY" is returned.
9959
** </ol>
9960
*/
9939
-SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9961
+SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9962
9963
/*
9964
** CAPI3REF: Determine if a virtual table query is DISTINCT
@@ -10093,21 +10115,20 @@ SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
10115
** is undefined and probably harmful.
10116
**
10117
** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
10096
-** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
10118
+** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
10119
** xFilter method which invokes these routines, and specifically
10120
** a parameter that was previously selected for all-at-once IN constraint
10121
** processing use the [sqlite3_vtab_in()] interface in the
10122
** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
10123
** an xFilter argument that was selected for all-at-once IN constraint
10102
-** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
10103
-** exhibit some other undefined or harmful behavior.
10124
+** processing, then these routines return [SQLITE_ERROR].)^
10125
**
10126
** ^(Use these routines to access all values on the right-hand side
10127
** of the IN constraint using code like the following:
10128
**
10129
** <blockquote><pre>
10130
** for(rc=sqlite3_vtab_in_first(pList, &pVal);
10110
-** rc==SQLITE_OK && pVal
10131
+** rc==SQLITE_OK && pVal;
10132
** rc=sqlite3_vtab_in_next(pList, &pVal)
10133
** ){
10134
** // do something with pVal
@@ -10205,6 +10226,10 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **
10226
** managed by the prepared statement S and will be automatically freed when
10227
** S is finalized.
10228
**
10229
+** Not all values are available for all query elements. When a value is
10230
+** not available, the output variable is set to -1 if the value is numeric,
10231
+** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).
10232
+**
10233
** <dl>
10234
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
10235
** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
@@ -10232,12 +10257,24 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **
10257
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10258
** description for the X-th loop.
10259
**
10235
-** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
10260
+** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
10261
** <dd>^The "int" variable pointed to by the V parameter will be set to the
10237
-** "select-id" for the X-th loop. The select-id identifies which query or
10238
-** subquery the loop is part of. The main query has a select-id of zero.
10239
-** The select-id is the same value as is output in the first column
10240
-** of an [EXPLAIN QUERY PLAN] query.
10262
+** id for the X-th query plan element. The id value is unique within the
10263
+** statement. The select-id is the same value as is output in the first
10264
+** column of an [EXPLAIN QUERY PLAN] query.
10265
+**
10266
+** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
10267
+** <dd>The "int" variable pointed to by the V parameter will be set to the
10268
+** the id of the parent of the current query element, if applicable, or
10269
+** to zero if the query element has no parent. This is the same value as
10270
+** returned in the second column of an [EXPLAIN QUERY PLAN] query.
10271
+**
10272
+** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
10273
+** <dd>The sqlite3_int64 output value is set to the number of cycles,
10274
+** according to the processor time-stamp counter, that elapsed while the
10275
+** query element was being processed. This value is not available for
10276
+** all query elements - if it is unavailable the output variable is
10277
+** set to -1.
10278
** </dl>
10279
*/
10280
#define SQLITE_SCANSTAT_NLOOP 0
@@ -10246,12 +10283,14 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **
10283
#define SQLITE_SCANSTAT_NAME 3
10284
#define SQLITE_SCANSTAT_EXPLAIN 4
10285
#define SQLITE_SCANSTAT_SELECTID 5
10286
+#define SQLITE_SCANSTAT_PARENTID 6
10287
+#define SQLITE_SCANSTAT_NCYCLE 7
10288
10289
/*
10290
** CAPI3REF: Prepared Statement Scan Status
10291
** METHOD: sqlite3_stmt
10292
**
10254
-** This interface returns information about the predicted and measured
10293
+** These interfaces return information about the predicted and measured
10294
** performance for pStmt. Advanced applications can use this
10295
** interface to compare the predicted and the measured performance and
10296
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -10262,19 +10301,25 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **
10301
**
10302
** The "iScanStatusOp" parameter determines which status information to return.
10303
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
10265
-** of this interface is undefined.
10266
-** ^The requested measurement is written into a variable pointed to by
10267
-** the "pOut" parameter.
10268
-** Parameter "idx" identifies the specific loop to retrieve statistics for.
10269
-** Loops are numbered starting from zero. ^If idx is out of range - less than
10270
-** zero or greater than or equal to the total number of loops used to implement
10271
-** the statement - a non-zero value is returned and the variable that pOut
10272
-** points to is unchanged.
10273
-**
10274
-** ^Statistics might not be available for all loops in all statements. ^In cases
10275
-** where there exist loops with no available statistics, this function behaves
10276
-** as if the loop did not exist - it returns non-zero and leave the variable
10277
-** that pOut points to unchanged.
10304
+** of this interface is undefined. ^The requested measurement is written into
10305
+** a variable pointed to by the "pOut" parameter.
10306
+**
10307
+** The "flags" parameter must be passed a mask of flags. At present only
10308
+** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX
10309
+** is specified, then status information is available for all elements
10310
+** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If
10311
+** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements
10312
+** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of
10313
+** the EXPLAIN QUERY PLAN output) are available. Invoking API
10314
+** sqlite3_stmt_scanstatus() is equivalent to calling
10315
+** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10316
+**
10317
+** Parameter "idx" identifies the specific query element to retrieve statistics
10318
+** for. Query elements are numbered starting from zero. A value of -1 may be
10319
+** to query for statistics regarding the entire query. ^If idx is out of range
10320
+** - less than -1 or greater than or equal to the total number of query
10321
+** elements used to implement the statement - a non-zero value is returned and
10322
+** the variable that pOut points to is unchanged.
10323
**
10324
** See also: [sqlite3_stmt_scanstatus_reset()]
10325
*/
@@ -10284,6 +10329,19 @@ SQLITE_API int sqlite3_stmt_scanstatus(
10329
int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10330
void *pOut /* Result written here */
10331
);
10332
+SQLITE_API int sqlite3_stmt_scanstatus_v2(
10333
+ sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
10334
+ int idx, /* Index of loop to report on */
10335
+ int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10336
+ int flags, /* Mask of flags defined below */
10337
+ void *pOut /* Result written here */
10338
+);
10339
+
10340
+/*
10341
+** CAPI3REF: Prepared Statement Scan Status
10342
+** KEYWORDS: {scan status flags}
10343
+*/
10344
+#define SQLITE_SCANSTAT_COMPLEX 0x0001
10345
10346
/*
10347
** CAPI3REF: Zero Scan-Status Counters
@@ -10374,6 +10432,10 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
10432
** function is not defined for operations on WITHOUT ROWID tables, or for
10433
** DELETE operations on rowid tables.
10434
**
10435
+** ^The sqlite3_preupdate_hook(D,C,P) function returns the P argument from
10436
+** the previous call on the same [database connection] D, or NULL for
10437
+** the first call on D.
10438
+**
10439
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
10440
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
10441
** provide additional information about a preupdate event. These routines
@@ -10779,6 +10841,19 @@ SQLITE_API int sqlite3_deserialize(
10841
# undef double
10842
#endif
10843
10844
+#if defined(__wasi__)
10845
+# undef SQLITE_WASI
10846
+# define SQLITE_WASI 1
10847
+# undef SQLITE_OMIT_WAL
10848
+# define SQLITE_OMIT_WAL 1/* because it requires shared memory APIs */
10849
+# ifndef SQLITE_OMIT_LOAD_EXTENSION
10850
+# define SQLITE_OMIT_LOAD_EXTENSION
10851
+# endif
10852
+# ifndef SQLITE_THREADSAFE
10853
+# define SQLITE_THREADSAFE 0
10854
+# endif
10855
+#endif
10856
+
10857
#if 0
10858
} /* End of the 'extern "C"' block */
10859
#endif
@@ -14330,15 +14405,9 @@ typedef INT8_TYPE i8; /* 1-byte signed integer */
14405
14406
/*
14407
** The datatype used to store estimates of the number of rows in a
14333
-** table or index. This is an unsigned integer type. For 99.9% of
14334
-** the world, a 32-bit integer is sufficient. But a 64-bit integer
14335
-** can be used at compile-time if desired.
14408
+** table or index.
14409
*/
14337
-#ifdef SQLITE_64BIT_STATS
14338
- typedef u64 tRowcnt; /* 64-bit only if requested at compile-time */
14339
-#else
14340
- typedef u32 tRowcnt; /* 32-bit is the default */
14341
-#endif
14410
+typedef u64 tRowcnt;
14411
14412
/*
14413
** Estimated quantities used for query planning are stored as 16-bit
@@ -14484,9 +14553,9 @@ typedef INT16_TYPE LogEst;
14553
** pointers. In that case, only verify 4-byte alignment.
14554
*/
14555
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
14487
-# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&3)==0)
14556
+# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&3)==0)
14557
#else
14489
-# define EIGHT_BYTE_ALIGNMENT(X) ((((char*)(X) - (char*)0)&7)==0)
14558
+# define EIGHT_BYTE_ALIGNMENT(X) ((((uptr)(X) - (uptr)0)&7)==0)
14559
#endif
14560
14561
/*
@@ -14540,15 +14609,38 @@ SQLITE_PRIVATE u32 sqlite3TreeTrace;
14609
&& (defined(SQLITE_TEST) || defined(SQLITE_ENABLE_SELECTTRACE) \
14610
|| defined(SQLITE_ENABLE_TREETRACE))
14611
# define TREETRACE_ENABLED 1
14543
-# define SELECTTRACE(K,P,S,X) \
14612
+# define TREETRACE(K,P,S,X) \
14613
if(sqlite3TreeTrace&(K)) \
14614
sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
14615
sqlite3DebugPrintf X
14616
#else
14548
-# define SELECTTRACE(K,P,S,X)
14617
+# define TREETRACE(K,P,S,X)
14618
# define TREETRACE_ENABLED 0
14619
#endif
14620
14621
+/* TREETRACE flag meanings:
14622
+**
14623
+** 0x00000001 Beginning and end of SELECT processing
14624
+** 0x00000002 WHERE clause processing
14625
+** 0x00000004 Query flattener
14626
+** 0x00000008 Result-set wildcard expansion
14627
+** 0x00000010 Query name resolution
14628
+** 0x00000020 Aggregate analysis
14629
+** 0x00000040 Window functions
14630
+** 0x00000080 Generated column names
14631
+** 0x00000100 Move HAVING terms into WHERE
14632
+** 0x00000200 Count-of-view optimization
14633
+** 0x00000400 Compound SELECT processing
14634
+** 0x00000800 Drop superfluous ORDER BY
14635
+** 0x00001000 LEFT JOIN simplifies to JOIN
14636
+** 0x00002000 Constant propagation
14637
+** 0x00004000 Push-down optimization
14638
+** 0x00008000 After all FROM-clause analysis
14639
+** 0x00010000 Beginning of DELETE/INSERT/UPDATE processing
14640
+** 0x00020000 Transform DISTINCT into GROUP BY
14641
+** 0x00040000 SELECT tree dump after all code has been generated
14642
+*/
14643
+
14644
/*
14645
** Macros for "wheretrace"
14646
*/
@@ -14561,6 +14653,36 @@ SQLITE_PRIVATE u32 sqlite3WhereTrace;
14653
# define WHERETRACE(K,X)
14654
#endif
14655
14656
+/*
14657
+** Bits for the sqlite3WhereTrace mask:
14658
+**
14659
+** (---any--) Top-level block structure
14660
+** 0x-------F High-level debug messages
14661
+** 0x----FFF- More detail
14662
+** 0xFFFF---- Low-level debug messages
14663
+**
14664
+** 0x00000001 Code generation
14665
+** 0x00000002 Solver
14666
+** 0x00000004 Solver costs
14667
+** 0x00000008 WhereLoop inserts
14668
+**
14669
+** 0x00000010 Display sqlite3_index_info xBestIndex calls
14670
+** 0x00000020 Range an equality scan metrics
14671
+** 0x00000040 IN operator decisions
14672
+** 0x00000080 WhereLoop cost adjustements
14673
+** 0x00000100
14674
+** 0x00000200 Covering index decisions
14675
+** 0x00000400 OR optimization
14676
+** 0x00000800 Index scanner
14677
+** 0x00001000 More details associated with code generation
14678
+** 0x00002000
14679
+** 0x00004000 Show all WHERE terms at key points
14680
+** 0x00008000 Show the full SELECT statement at key places
14681
+**
14682
+** 0x00010000 Show more detail when printing WHERE terms
14683
+** 0x00020000 Show WHERE terms returned from whereScanNext()
14684
+*/
14685
+
14686
14687
/*
14688
** An instance of the following structure is used to store the busy-handler
@@ -15541,7 +15663,7 @@ SQLITE_PRIVATE int sqlite3BtreeNewDb(Btree *p);
15663
** reduce network bandwidth.
15664
**
15665
** Note that BTREE_HINT_FLAGS with BTREE_BULKLOAD is the only hint used by
15544
-** standard SQLite. The other hints are provided for extentions that use
15666
+** standard SQLite. The other hints are provided for extensions that use
15667
** the SQLite parser and code generator but substitute their own storage
15668
** engine.
15669
*/
@@ -15687,7 +15809,15 @@ SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt);
15809
SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*);
15810
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor*);
15811
15690
-SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(sqlite3*,Btree*,Pgno*aRoot,int nRoot,int,int*);
15812
+SQLITE_PRIVATE int sqlite3BtreeIntegrityCheck(
15813
+ sqlite3 *db, /* Database connection that is running the check */
15814
+ Btree *p, /* The btree to be checked */
15815
+ Pgno *aRoot, /* An array of root pages numbers for individual trees */
15816
+ int nRoot, /* Number of entries in aRoot[] */
15817
+ int mxErr, /* Stop reporting errors after this many */
15818
+ int *pnErr, /* OUT: Write number of errors seen to this variable */
15819
+ char **pzOut /* OUT: Write the error message string here */
15820
+);
15821
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
15822
SQLITE_PRIVATE i64 sqlite3BtreeRowCountEst(BtCursor*);
15823
@@ -15844,14 +15974,14 @@ struct VdbeOp {
15974
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
15975
char *zComment; /* Comment to improve readability */
15976
#endif
15847
-#ifdef VDBE_PROFILE
15848
- u32 cnt; /* Number of times this instruction was executed */
15849
- u64 cycles; /* Total time spent executing this instruction */
15850
-#endif
15977
#ifdef SQLITE_VDBE_COVERAGE
15978
u32 iSrcLine; /* Source-code line that generated this opcode
15979
** with flags in the upper 8 bits */
15980
#endif
15981
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
15982
+ u64 nExec;
15983
+ u64 nCycle;
15984
+#endif
15985
};
15986
typedef struct VdbeOp VdbeOp;
15987
@@ -16142,29 +16272,30 @@ typedef struct VdbeOpList VdbeOpList;
16272
#define OPFLG_IN3 0x08 /* in3: P3 is an input */
16273
#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
16274
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
16275
+#define OPFLG_NCYCLE 0x40 /* ncycle:Cycles count against P1 */
16276
#define OPFLG_INITIALIZER {\
16146
-/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
16277
+/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x00,\
16278
/* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
16148
-/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x09, 0x09, 0x09,\
16149
-/* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
16150
-/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
16151
-/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\
16279
+/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x49, 0x49, 0x49,\
16280
+/* 24 */ 0x49, 0x01, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49,\
16281
+/* 32 */ 0x41, 0x01, 0x01, 0x01, 0x41, 0x01, 0x41, 0x41,\
16282
+/* 40 */ 0x41, 0x41, 0x41, 0x26, 0x26, 0x41, 0x23, 0x0b,\
16283
/* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
16153
-/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
16284
+/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x41,\
16285
/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
16286
/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
16287
/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
16157
-/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
16158
-/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
16288
+/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x40, 0x00,\
16289
+/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x26, 0x26,\
16290
/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
16160
-/* 112 */ 0x00, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00,\
16161
-/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
16162
-/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
16163
-/* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
16291
+/* 112 */ 0x40, 0x00, 0x12, 0x40, 0x40, 0x10, 0x40, 0x00,\
16292
+/* 120 */ 0x00, 0x00, 0x40, 0x00, 0x40, 0x40, 0x10, 0x10,\
16293
+/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,\
16294
+/* 136 */ 0x00, 0x40, 0x04, 0x04, 0x00, 0x40, 0x50, 0x40,\
16295
/* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
16296
/* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
16297
/* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
16167
-/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
16298
+/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x50, 0x40,\
16299
/* 176 */ 0x00, 0x10, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00,\
16300
/* 184 */ 0x00, 0x00, 0x00,}
16301
@@ -16219,14 +16350,20 @@ SQLITE_PRIVATE void sqlite3VdbeNoJumpsOutsideSubrtn(Vdbe*,int,int,int);
16350
#endif
16351
SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
16352
#ifndef SQLITE_OMIT_EXPLAIN
16222
-SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
16353
+SQLITE_PRIVATE int sqlite3VdbeExplain(Parse*,u8,const char*,...);
16354
SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
16355
SQLITE_PRIVATE int sqlite3VdbeExplainParent(Parse*);
16356
# define ExplainQueryPlan(P) sqlite3VdbeExplain P
16357
+# ifdef SQLITE_ENABLE_STMT_SCANSTATUS
16358
+# define ExplainQueryPlan2(V,P) (V = sqlite3VdbeExplain P)
16359
+# else
16360
+# define ExplainQueryPlan2(V,P) ExplainQueryPlan(P)
16361
+# endif
16362
# define ExplainQueryPlanPop(P) sqlite3VdbeExplainPop(P)
16363
# define ExplainQueryPlanParent(P) sqlite3VdbeExplainParent(P)
16364
#else
16365
# define ExplainQueryPlan(P)
16366
+# define ExplainQueryPlan2(V,P)
16367
# define ExplainQueryPlanPop(P)
16368
# define ExplainQueryPlanParent(P) 0
16369
# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
@@ -16399,8 +16536,12 @@ SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe*,int);
16536
16537
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
16538
SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
16539
+SQLITE_PRIVATE void sqlite3VdbeScanStatusRange(Vdbe*, int, int, int);
16540
+SQLITE_PRIVATE void sqlite3VdbeScanStatusCounters(Vdbe*, int, int, int);
16541
#else
16403
-# define sqlite3VdbeScanStatus(a,b,c,d,e)
16542
+# define sqlite3VdbeScanStatus(a,b,c,d,e,f)
16543
+# define sqlite3VdbeScanStatusRange(a,b,c,d)
16544
+# define sqlite3VdbeScanStatusCounters(a,b,c,d)
16545
#endif
16546
16547
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
@@ -16455,7 +16596,7 @@ struct PgHdr {
16596
** private to pcache.c and should not be accessed by other modules.
16597
** pCache is grouped with the public elements for efficiency.
16598
*/
16458
- i16 nRef; /* Number of users of this page */
16599
+ i64 nRef; /* Number of users of this page */
16600
PgHdr *pDirtyNext; /* Next element in list of dirty pages */
16601
PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
16602
/* NB: pDirtyNext and pDirtyPrev are undefined if the
@@ -16536,12 +16677,12 @@ SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *);
16677
SQLITE_PRIVATE void sqlite3PcacheClear(PCache*);
16678
16679
/* Return the total number of outstanding page references */
16539
-SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache*);
16680
+SQLITE_PRIVATE i64 sqlite3PcacheRefCount(PCache*);
16681
16682
/* Increment the reference count of an existing page */
16683
SQLITE_PRIVATE void sqlite3PcacheRef(PgHdr*);
16684
16544
-SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr*);
16685
+SQLITE_PRIVATE i64 sqlite3PcachePageRefcount(PgHdr*);
16686
16687
/* Return the total number of pages stored in the cache */
16688
SQLITE_PRIVATE int sqlite3PcachePagecount(PCache*);
@@ -17197,6 +17338,7 @@ struct sqlite3 {
17338
#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17339
/* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17340
#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17341
+#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
17342
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
17343
17344
/*
@@ -17281,8 +17423,14 @@ struct FuncDestructor {
17423
** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
17424
** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
17425
** SQLITE_FUNC_DIRECT == SQLITE_DIRECTONLY from the API
17284
-** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS
17426
+** SQLITE_FUNC_UNSAFE == SQLITE_INNOCUOUS -- opposite meanings!!!
17427
** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
17428
+**
17429
+** Note that even though SQLITE_FUNC_UNSAFE and SQLITE_INNOCUOUS have the
17430
+** same bit value, their meanings are inverted. SQLITE_FUNC_UNSAFE is
17431
+** used internally and if set means tha the function has side effects.
17432
+** SQLITE_INNOCUOUS is used by application code and means "not unsafe".
17433
+** See multiple instances of tag-20230109-1.
17434
*/
17435
#define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
17436
#define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
@@ -17399,7 +17547,7 @@ struct FuncDestructor {
17547
{nArg, SQLITE_FUNC_BUILTIN|SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
17548
xPtr, 0, xFunc, 0, 0, 0, #zName, {0} }
17549
#define JFUNCTION(zName, nArg, iArg, xFunc) \
17402
- {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|SQLITE_INNOCUOUS|\
17550
+ {nArg, SQLITE_FUNC_BUILTIN|SQLITE_DETERMINISTIC|\
17551
SQLITE_FUNC_CONSTANT|SQLITE_UTF8, \
17552
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, 0, #zName, {0} }
17553
#define INLINE_FUNC(zName, nArg, iArg, mFlags) \
@@ -17591,6 +17739,7 @@ struct CollSeq {
17739
#define SQLITE_AFF_NUMERIC 0x43 /* 'C' */
17740
#define SQLITE_AFF_INTEGER 0x44 /* 'D' */
17741
#define SQLITE_AFF_REAL 0x45 /* 'E' */
17742
+#define SQLITE_AFF_FLEXNUM 0x46 /* 'F' */
17743
17744
#define sqlite3IsNumericAffinity(X) ((X)>=SQLITE_AFF_NUMERIC)
17745
@@ -18122,16 +18271,15 @@ struct AggInfo {
18271
** from source tables rather than from accumulators */
18272
u8 useSortingIdx; /* In direct mode, reference the sorting index rather
18273
** than the source table */
18274
+ u16 nSortingColumn; /* Number of columns in the sorting index */
18275
int sortingIdx; /* Cursor number of the sorting index */
18276
int sortingIdxPTab; /* Cursor number of pseudo-table */
18127
- int nSortingColumn; /* Number of columns in the sorting index */
18128
- int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
18277
+ int iFirstReg; /* First register in range for aCol[] and aFunc[] */
18278
ExprList *pGroupBy; /* The group by clause */
18279
struct AggInfo_col { /* For each column used in source tables */
18280
Table *pTab; /* Source table */
18281
Expr *pCExpr; /* The original expression */
18282
int iTable; /* Cursor number of the source table */
18134
- int iMem; /* Memory location that acts as accumulator */
18283
i16 iColumn; /* Column number within the source table */
18284
i16 iSorterColumn; /* Column number in the sorting index */
18285
} *aCol;
@@ -18142,14 +18290,27 @@ struct AggInfo {
18290
struct AggInfo_func { /* For each aggregate function */
18291
Expr *pFExpr; /* Expression encoding the function */
18292
FuncDef *pFunc; /* The aggregate function implementation */
18145
- int iMem; /* Memory location that acts as accumulator */
18293
int iDistinct; /* Ephemeral table used to enforce DISTINCT */
18294
int iDistAddr; /* Address of OP_OpenEphemeral */
18295
} *aFunc;
18296
int nFunc; /* Number of entries in aFunc[] */
18297
u32 selId; /* Select to which this AggInfo belongs */
18298
+#ifdef SQLITE_DEBUG
18299
+ Select *pSelect; /* SELECT statement that this AggInfo supports */
18300
+#endif
18301
};
18302
18303
+/*
18304
+** Macros to compute aCol[] and aFunc[] register numbers.
18305
+**
18306
+** These macros should not be used prior to the call to
18307
+** assignAggregateRegisters() that computes the value of pAggInfo->iFirstReg.
18308
+** The assert()s that are part of this macro verify that constraint.
18309
+*/
18310
+#define AggInfoColumnReg(A,I) (assert((A)->iFirstReg),(A)->iFirstReg+(I))
18311
+#define AggInfoFuncReg(A,I) \
18312
+ (assert((A)->iFirstReg),(A)->iFirstReg+(A)->nColumn+(I))
18313
+
18314
/*
18315
** The datatype ynVar is a signed integer, either 16-bit or 32-bit.
18316
** Usually it is 16-bits. But if SQLITE_MAX_VARIABLE_NUMBER is greater
@@ -18680,7 +18841,7 @@ struct NameContext {
18841
#define NC_HasAgg 0x000010 /* One or more aggregate functions seen */
18842
#define NC_IdxExpr 0x000020 /* True if resolving columns of CREATE INDEX */
18843
#define NC_SelfRef 0x00002e /* Combo: PartIdx, isCheck, GenCol, and IdxExpr */
18683
-#define NC_VarSelect 0x000040 /* A correlated subquery has been seen */
18844
+#define NC_Subquery 0x000040 /* A subquery has been seen */
18845
#define NC_UEList 0x000080 /* True if uNC.pEList is used */
18846
#define NC_UAggInfo 0x000100 /* True if uNC.pAggInfo is used */
18847
#define NC_UUpsert 0x000200 /* True if uNC.pUpsert is used */
@@ -18809,6 +18970,7 @@ struct Select {
18970
#define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
18971
#define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
18972
#define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
18973
+#define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
18974
18975
/* True if S exists and has SF_NestedFrom */
18976
#define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0)
@@ -18917,7 +19079,7 @@ struct SelectDest {
19079
int iSDParm2; /* A second parameter for the eDest disposal method */
19080
int iSdst; /* Base register where results are written */
19081
int nSdst; /* Number of registers allocated */
18920
- char *zAffSdst; /* Affinity used for SRT_Set, SRT_Table, and similar */
19082
+ char *zAffSdst; /* Affinity used for SRT_Set */
19083
ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */
19084
};
19085
@@ -18976,10 +19138,10 @@ struct TriggerPrg {
19138
#else
19139
typedef unsigned int yDbMask;
19140
# define DbMaskTest(M,I) (((M)&(((yDbMask)1)<<(I)))!=0)
18979
-# define DbMaskZero(M) (M)=0
18980
-# define DbMaskSet(M,I) (M)|=(((yDbMask)1)<<(I))
18981
-# define DbMaskAllZero(M) (M)==0
18982
-# define DbMaskNonZero(M) (M)!=0
19141
+# define DbMaskZero(M) ((M)=0)
19142
+# define DbMaskSet(M,I) ((M)|=(((yDbMask)1)<<(I)))
19143
+# define DbMaskAllZero(M) ((M)==0)
19144
+# define DbMaskNonZero(M) ((M)!=0)
19145
#endif
19146
19147
/*
@@ -18998,6 +19160,7 @@ struct IndexedExpr {
19160
int iIdxCur; /* The index cursor */
19161
int iIdxCol; /* The index column that contains value of pExpr */
19162
u8 bMaybeNullRow; /* True if we need an OP_IfNullRow check */
19163
+ u8 aff; /* Affinity of the pExpr expression */
19164
IndexedExpr *pIENext; /* Next in a list of all indexed expressions */
19165
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
19166
const char *zIdxName; /* Name of index, used only for bytecode comments */
@@ -19049,6 +19212,9 @@ struct Parse {
19212
u8 withinRJSubrtn; /* Nesting level for RIGHT JOIN body subroutines */
19213
#if defined(SQLITE_DEBUG) || defined(SQLITE_COVERAGE_TEST)
19214
u8 earlyCleanup; /* OOM inside sqlite3ParserAddCleanup() */
19215
+#endif
19216
+#ifdef SQLITE_DEBUG
19217
+ u8 ifNotExists; /* Might be true if IF NOT EXISTS. Assert()s only */
19218
#endif
19219
int nRangeReg; /* Size of the temporary register block */
19220
int iRangeReg; /* First register in temporary register block */
@@ -19062,7 +19228,7 @@ struct Parse {
19228
int nLabelAlloc; /* Number of slots in aLabel */
19229
int *aLabel; /* Space to hold the labels */
19230
ExprList *pConstExpr;/* Constant expressions */
19065
- IndexedExpr *pIdxExpr;/* List of expressions used by active indexes */
19231
+ IndexedExpr *pIdxEpr;/* List of expressions used by active indexes */
19232
Token constraintName;/* Name of the constraint currently being parsed */
19233
yDbMask writeMask; /* Start a write transaction on these databases */
19234
yDbMask cookieMask; /* Bitmask of schema verified databases */
@@ -19086,6 +19252,9 @@ struct Parse {
19252
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
19253
u32 oldmask; /* Mask of old.* columns referenced */
19254
u32 newmask; /* Mask of new.* columns referenced */
19255
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
19256
+ u32 nProgressSteps; /* xProgress steps taken during sqlite3_prepare() */
19257
+#endif
19258
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
19259
u8 bReturning; /* Coding a RETURNING trigger */
19260
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
@@ -19834,13 +20003,11 @@ SQLITE_PRIVATE int sqlite3HeapNearlyFull(void);
20003
#ifdef SQLITE_USE_ALLOCA
20004
# define sqlite3StackAllocRaw(D,N) alloca(N)
20005
# define sqlite3StackAllocRawNN(D,N) alloca(N)
19837
-# define sqlite3StackAllocZero(D,N) memset(alloca(N), 0, N)
20006
# define sqlite3StackFree(D,P)
20007
# define sqlite3StackFreeNN(D,P)
20008
#else
20009
# define sqlite3StackAllocRaw(D,N) sqlite3DbMallocRaw(D,N)
20010
# define sqlite3StackAllocRawNN(D,N) sqlite3DbMallocRawNN(D,N)
19843
-# define sqlite3StackAllocZero(D,N) sqlite3DbMallocZero(D,N)
20011
# define sqlite3StackFree(D,P) sqlite3DbFree(D,P)
20012
# define sqlite3StackFreeNN(D,P) sqlite3DbFreeNN(D,P)
20013
#endif
@@ -19965,6 +20132,7 @@ SQLITE_PRIVATE void sqlite3ShowWinFunc(const Window*);
20132
#endif
20133
20134
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
20135
+SQLITE_PRIVATE void sqlite3ProgressCheck(Parse*);
20136
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
20137
SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
20138
SQLITE_PRIVATE void sqlite3Dequote(char*);
@@ -20022,7 +20190,7 @@ SQLITE_PRIVATE const char *sqlite3ColumnColl(Column*);
20190
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
20191
SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect);
20192
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
20025
-SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
20193
+SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(Parse*,Table*,Select*,char);
20194
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
20195
SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *, int);
20196
SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
@@ -20342,7 +20510,7 @@ SQLITE_PRIVATE int sqlite3FixExpr(DbFixer*, Expr*);
20510
SQLITE_PRIVATE int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
20511
SQLITE_PRIVATE int sqlite3RealSameAsInt(double,sqlite3_int64);
20512
SQLITE_PRIVATE i64 sqlite3RealToI64(double);
20345
-SQLITE_PRIVATE void sqlite3Int64ToText(i64,char*);
20513
+SQLITE_PRIVATE int sqlite3Int64ToText(i64,char*);
20514
SQLITE_PRIVATE int sqlite3AtoF(const char *z, double*, int, u8);
20515
SQLITE_PRIVATE int sqlite3GetInt32(const char *, int*);
20516
SQLITE_PRIVATE int sqlite3GetUInt32(const char*, u32*);
@@ -20393,6 +20561,7 @@ SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2);
20561
SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity);
20562
SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table*,int);
20563
SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr);
20564
+SQLITE_PRIVATE int sqlite3ExprDataType(const Expr *pExpr);
20565
SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
20566
SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
20567
SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...);
@@ -20409,6 +20578,9 @@ SQLITE_PRIVATE const char *sqlite3ErrName(int);
20578
20579
#ifndef SQLITE_OMIT_DESERIALIZE
20580
SQLITE_PRIVATE int sqlite3MemdbInit(void);
20581
+SQLITE_PRIVATE int sqlite3IsMemdb(const sqlite3_vfs*);
20582
+#else
20583
+# define sqlite3IsMemdb(X) 0
20584
#endif
20585
20586
SQLITE_PRIVATE const char *sqlite3ErrStr(int);
@@ -20548,7 +20720,7 @@ SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
20720
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
20721
20722
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
20551
-SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, int);
20723
+SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum*, i64);
20724
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
20725
SQLITE_PRIVATE void sqlite3StrAccumSetError(StrAccum*, u8);
20726
SQLITE_PRIVATE void sqlite3ResultStrAccum(sqlite3_context*,StrAccum*);
@@ -20906,6 +21078,12 @@ SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt);
21078
SQLITE_PRIVATE int sqlite3KvvfsInit(void);
21079
#endif
21080
21081
+#if defined(VDBE_PROFILE) \
21082
+ || defined(SQLITE_PERFORMANCE_TRACE) \
21083
+ || defined(SQLITE_ENABLE_STMT_SCANSTATUS)
21084
+SQLITE_PRIVATE sqlite3_uint64 sqlite3Hwtime(void);
21085
+#endif
21086
+
21087
#endif /* SQLITEINT_H */
21088
21089
/************** End of sqliteInt.h *******************************************/
@@ -20947,101 +21125,6 @@ SQLITE_PRIVATE int sqlite3KvvfsInit(void);
21125
*/
21126
#ifdef SQLITE_PERFORMANCE_TRACE
21127
20950
-/*
20951
-** hwtime.h contains inline assembler code for implementing
20952
-** high-performance timing routines.
20953
-*/
20954
-/************** Include hwtime.h in the middle of os_common.h ****************/
20955
-/************** Begin file hwtime.h ******************************************/
20956
-/*
20957
-** 2008 May 27
20958
-**
20959
-** The author disclaims copyright to this source code. In place of
20960
-** a legal notice, here is a blessing:
20961
-**
20962
-** May you do good and not evil.
20963
-** May you find forgiveness for yourself and forgive others.
20964
-** May you share freely, never taking more than you give.
20965
-**
20966
-******************************************************************************
20967
-**
20968
-** This file contains inline asm code for retrieving "high-performance"
20969
-** counters for x86 and x86_64 class CPUs.
20970
-*/
20971
-#ifndef SQLITE_HWTIME_H
20972
-#define SQLITE_HWTIME_H
20973
-
20974
-/*
20975
-** The following routine only works on pentium-class (or newer) processors.
20976
-** It uses the RDTSC opcode to read the cycle count value out of the
20977
-** processor and returns that value. This can be used for high-res
20978
-** profiling.
20979
-*/
20980
-#if !defined(__STRICT_ANSI__) && \
20981
- (defined(__GNUC__) || defined(_MSC_VER)) && \
20982
- (defined(i386) || defined(__i386__) || defined(_M_IX86))
20983
-
20984
- #if defined(__GNUC__)
20985
-
20986
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
20987
- unsigned int lo, hi;
20988
- __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
20989
- return (sqlite_uint64)hi << 32 | lo;
20990
- }
20991
-
20992
- #elif defined(_MSC_VER)
20993
-
20994
- __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
20995
- __asm {
20996
- rdtsc
20997
- ret ; return value at EDX:EAX
20998
- }
20999
- }
21000
-
21001
- #endif
21002
-
21003
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
21004
-
21005
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
21006
- unsigned long val;
21007
- __asm__ __volatile__ ("rdtsc" : "=A" (val));
21008
- return val;
21009
- }
21010
-
21011
-#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
21012
-
21013
- __inline__ sqlite_uint64 sqlite3Hwtime(void){
21014
- unsigned long long retval;
21015
- unsigned long junk;
21016
- __asm__ __volatile__ ("\n\
21017
- 1: mftbu %1\n\
21018
- mftb %L0\n\
21019
- mftbu %0\n\
21020
- cmpw %0,%1\n\
21021
- bne 1b"
21022
- : "=r" (retval), "=r" (junk));
21023
- return retval;
21024
- }
21025
-
21026
-#else
21027
-
21028
- /*
21029
- ** asm() is needed for hardware timing support. Without asm(),
21030
- ** disable the sqlite3Hwtime() routine.
21031
- **
21032
- ** sqlite3Hwtime() is only used for some obscure debugging
21033
- ** and analysis configurations, not in any deliverable, so this
21034
- ** should not be a great loss.
21035
- */
21036
-SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
21037
-
21038
-#endif
21039
-
21040
-#endif /* !defined(SQLITE_HWTIME_H) */
21041
-
21042
-/************** End of hwtime.h **********************************************/
21043
-/************** Continuing where we left off in os_common.h ******************/
21044
-
21128
static sqlite_uint64 g_start;
21129
static sqlite_uint64 g_elapsed;
21130
#define TIMER_START g_start=sqlite3Hwtime()
@@ -22486,7 +22569,6 @@ struct VdbeFrame {
22569
Vdbe *v; /* VM this frame belongs to */
22570
VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
22571
Op *aOp; /* Program instructions for parent frame */
22489
- i64 *anExec; /* Event counters from parent frame */
22572
Mem *aMem; /* Array of memory cells for parent frame */
22573
VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
22574
u8 *aOnce; /* Bitmask used by OP_Once */
@@ -22702,10 +22784,19 @@ typedef unsigned bft; /* Bit Field Type */
22784
22785
/* The ScanStatus object holds a single value for the
22786
** sqlite3_stmt_scanstatus() interface.
22787
+**
22788
+** aAddrRange[]:
22789
+** This array is used by ScanStatus elements associated with EQP
22790
+** notes that make an SQLITE_SCANSTAT_NCYCLE value available. It is
22791
+** an array of up to 3 ranges of VM addresses for which the Vdbe.anCycle[]
22792
+** values should be summed to calculate the NCYCLE value. Each pair of
22793
+** integer addresses is a start and end address (both inclusive) for a range
22794
+** instructions. A start value of 0 indicates an empty range.
22795
*/
22796
typedef struct ScanStatus ScanStatus;
22797
struct ScanStatus {
22798
int addrExplain; /* OP_Explain for loop */
22799
+ int aAddrRange[6];
22800
int addrLoop; /* Address of "loops" counter */
22801
int addrVisit; /* Address of "rows visited" counter */
22802
int iSelectID; /* The "Select-ID" for this loop */
@@ -22761,7 +22852,7 @@ struct Vdbe {
22852
int nOp; /* Number of instructions in the program */
22853
int nOpAlloc; /* Slots allocated for aOp[] */
22854
Mem *aColName; /* Column names to return */
22764
- Mem *pResultSet; /* Pointer to an array of results */
22855
+ Mem *pResultRow; /* Current output row */
22856
char *zErrMsg; /* Error message written here */
22857
VList *pVList; /* Name of variables */
22858
#ifndef SQLITE_OMIT_TRACE
@@ -22798,7 +22889,6 @@ struct Vdbe {
22889
SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
22890
AuxData *pAuxData; /* Linked list of auxdata allocations */
22891
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
22801
- i64 *anExec; /* Number of times each op has been executed */
22892
int nScan; /* Entries in aScan[] */
22893
ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
22894
#endif
@@ -22965,6 +23055,8 @@ SQLITE_PRIVATE int sqlite3VdbeSorterRewind(const VdbeCursor *, int *);
23055
SQLITE_PRIVATE int sqlite3VdbeSorterWrite(const VdbeCursor *, Mem *);
23056
SQLITE_PRIVATE int sqlite3VdbeSorterCompare(const VdbeCursor *, Mem *, int, int *);
23057
23058
+SQLITE_PRIVATE void sqlite3VdbeValueListFree(void*);
23059
+
23060
#ifdef SQLITE_DEBUG
23061
SQLITE_PRIVATE void sqlite3VdbeIncrWriteCounter(Vdbe*, VdbeCursor*);
23062
SQLITE_PRIVATE void sqlite3VdbeAssertAbortable(Vdbe*);
@@ -24152,7 +24244,7 @@ static int parseModifier(
24244
i64 iOrigJD; /* Original localtime */
24245
i64 iGuess; /* Guess at the corresponding utc time */
24246
int cnt = 0; /* Safety to prevent infinite loop */
24155
- int iErr; /* Guess is off by this much */
24247
+ i64 iErr; /* Guess is off by this much */
24248
24249
computeJD(p);
24250
iGuess = iOrigJD = p->iJD;
@@ -29220,7 +29312,7 @@ static void mallocWithAlarm(int n, void **pp){
29312
** The upper bound is slightly less than 2GiB: 0x7ffffeff == 2,147,483,391
29313
** This provides a 256-byte safety margin for defense against 32-bit
29314
** signed integer overflow bugs when computing memory allocation sizes.
29223
-** Parnoid applications might want to reduce the maximum allocation size
29315
+** Paranoid applications might want to reduce the maximum allocation size
29316
** further for an even larger safety margin. 0x3fffffff or 0x0fffffff
29317
** or even smaller would be reasonable upper bounds on the size of a memory
29318
** allocations for most applications.
@@ -29734,9 +29826,14 @@ SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3 *db, const char *z, u64 n){
29826
*/
29827
SQLITE_PRIVATE char *sqlite3DbSpanDup(sqlite3 *db, const char *zStart, const char *zEnd){
29828
int n;
29829
+#ifdef SQLITE_DEBUG
29830
+ /* Because of the way the parser works, the span is guaranteed to contain
29831
+ ** at least one non-space character */
29832
+ for(n=0; sqlite3Isspace(zStart[n]); n++){ assert( &zStart[n]<zEnd ); }
29833
+#endif
29834
while( sqlite3Isspace(zStart[0]) ) zStart++;
29835
n = (int)(zEnd - zStart);
29739
- while( ALWAYS(n>0) && sqlite3Isspace(zStart[n-1]) ) n--;
29836
+ while( sqlite3Isspace(zStart[n-1]) ) n--;
29837
return sqlite3DbStrNDup(db, zStart, n);
29838
}
29839
@@ -30575,13 +30672,26 @@ SQLITE_API void sqlite3_str_vappendf(
30672
}
30673
}
30674
if( precision>1 ){
30675
+ i64 nPrior = 1;
30676
width -= precision-1;
30677
if( width>1 && !flag_leftjustify ){
30678
sqlite3_str_appendchar(pAccum, width-1, ' ');
30679
width = 0;
30680
}
30583
- while( precision-- > 1 ){
30584
- sqlite3_str_append(pAccum, buf, length);
30681
+ sqlite3_str_append(pAccum, buf, length);
30682
+ precision--;
30683
+ while( precision > 1 ){
30684
+ i64 nCopyBytes;
30685
+ if( nPrior > precision-1 ) nPrior = precision - 1;
30686
+ nCopyBytes = length*nPrior;
30687
+ if( nCopyBytes + pAccum->nChar >= pAccum->nAlloc ){
30688
+ sqlite3StrAccumEnlarge(pAccum, nCopyBytes);
30689
+ }
30690
+ if( pAccum->accError ) break;
30691
+ sqlite3_str_append(pAccum,
30692
+ &pAccum->zText[pAccum->nChar-nCopyBytes], nCopyBytes);
30693
+ precision -= nPrior;
30694
+ nPrior *= 2;
30695
}
30696
}
30697
bufpt = buf;
@@ -30809,9 +30919,9 @@ SQLITE_PRIVATE void sqlite3RecordErrorOffsetOfExpr(sqlite3 *db, const Expr *pExp
30919
** Return the number of bytes of text that StrAccum is able to accept
30920
** after the attempted enlargement. The value returned might be zero.
30921
*/
30812
-SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, int N){
30922
+SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, i64 N){
30923
char *zNew;
30814
- assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
30924
+ assert( p->nChar+N >= p->nAlloc ); /* Only called if really needed */
30925
if( p->accError ){
30926
testcase(p->accError==SQLITE_TOOBIG);
30927
testcase(p->accError==SQLITE_NOMEM);
@@ -30822,8 +30932,7 @@ SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, int N){
30932
return p->nAlloc - p->nChar - 1;
30933
}else{
30934
char *zOld = isMalloced(p) ? p->zText : 0;
30825
- i64 szNew = p->nChar;
30826
- szNew += (sqlite3_int64)N + 1;
30935
+ i64 szNew = p->nChar + N + 1;
30936
if( szNew+p->nChar<=p->mxAlloc ){
30937
/* Force exponential buffer size growth as long as it does not overflow,
30938
** to avoid having to call this routine too often */
@@ -30853,7 +30962,8 @@ SQLITE_PRIVATE int sqlite3StrAccumEnlarge(StrAccum *p, int N){
30962
return 0;
30963
}
30964
}
30856
- return N;
30965
+ assert( N>=0 && N<=0x7fffffff );
30966
+ return (int)N;
30967
}
30968
30969
/*
@@ -31449,6 +31559,13 @@ SQLITE_PRIVATE void sqlite3TreeViewSrcList(TreeView *pView, const SrcList *pSrc)
31559
if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){
31560
sqlite3_str_appendf(&x, " ON");
31561
}
31562
+ if( pItem->fg.isTabFunc ) sqlite3_str_appendf(&x, " isTabFunc");
31563
+ if( pItem->fg.isCorrelated ) sqlite3_str_appendf(&x, " isCorrelated");
31564
+ if( pItem->fg.isMaterialized ) sqlite3_str_appendf(&x, " isMaterialized");
31565
+ if( pItem->fg.viaCoroutine ) sqlite3_str_appendf(&x, " viaCoroutine");
31566
+ if( pItem->fg.notCte ) sqlite3_str_appendf(&x, " notCte");
31567
+ if( pItem->fg.isNestedFrom ) sqlite3_str_appendf(&x, " isNestedFrom");
31568
+
31569
sqlite3StrAccumFinish(&x);
31570
sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1);
31571
n = 0;
@@ -31718,7 +31835,7 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31835
sqlite3TreeViewPop(&pView);
31836
return;
31837
}
31721
- if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags ){
31838
+ if( pExpr->flags || pExpr->affExpr || pExpr->vvaFlags || pExpr->pAggInfo ){
31839
StrAccum x;
31840
sqlite3StrAccumInit(&x, 0, zFlgs, sizeof(zFlgs), 0);
31841
sqlite3_str_appendf(&x, " fg.af=%x.%c",
@@ -31735,6 +31852,9 @@ SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 m
31852
if( ExprHasVVAProperty(pExpr, EP_Immutable) ){
31853
sqlite3_str_appendf(&x, " IMMUTABLE");
31854
}
31855
+ if( pExpr->pAggInfo!=0 ){
31856
+ sqlite3_str_appendf(&x, " agg-column[%d]", pExpr->iAgg);
31857
+ }
31858
sqlite3StrAccumFinish(&x);
31859
}else{
31860
zFlgs[0] = 0;
@@ -33674,6 +33794,26 @@ SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3 *db, int err_code, const char *z
33794
}
33795
}
33796
33797
+/*
33798
+** Check for interrupts and invoke progress callback.
33799
+*/
33800
+SQLITE_PRIVATE void sqlite3ProgressCheck(Parse *p){
33801
+ sqlite3 *db = p->db;
33802
+ if( AtomicLoad(&db->u1.isInterrupted) ){
33803
+ p->nErr++;
33804
+ p->rc = SQLITE_INTERRUPT;
33805
+ }
33806
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
33807
+ if( db->xProgress && (++p->nProgressSteps)>=db->nProgressOps ){
33808
+ if( db->xProgress(db->pProgressArg) ){
33809
+ p->nErr++;
33810
+ p->rc = SQLITE_INTERRUPT;
33811
+ }
33812
+ p->nProgressSteps = 0;
33813
+ }
33814
+#endif
33815
+}
33816
+
33817
/*
33818
** Add an error message to pParse->zErrMsg and increment pParse->nErr.
33819
**
@@ -34131,11 +34271,14 @@ do_atof_calc:
34271
#endif
34272
34273
/*
34134
-** Render an signed 64-bit integer as text. Store the result in zOut[].
34274
+** Render an signed 64-bit integer as text. Store the result in zOut[] and
34275
+** return the length of the string that was stored, in bytes. The value
34276
+** returned does not include the zero terminator at the end of the output
34277
+** string.
34278
**
34279
** The caller must ensure that zOut[] is at least 21 bytes in size.
34280
*/
34138
-SQLITE_PRIVATE void sqlite3Int64ToText(i64 v, char *zOut){
34281
+SQLITE_PRIVATE int sqlite3Int64ToText(i64 v, char *zOut){
34282
int i;
34283
u64 x;
34284
char zTemp[22];
@@ -34152,6 +34295,7 @@ SQLITE_PRIVATE void sqlite3Int64ToText(i64 v, char *zOut){
34295
}while( x );
34296
if( v<0 ) zTemp[i--] = '-';
34297
memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i);
34298
+ return sizeof(zTemp)-2-i;
34299
}
34300
34301
/*
@@ -35213,6 +35357,104 @@ SQLITE_PRIVATE int sqlite3VListNameToNum(VList *pIn, const char *zName, int nNam
35357
return 0;
35358
}
35359
35360
+/*
35361
+** High-resolution hardware timer used for debugging and testing only.
35362
+*/
35363
+#if defined(VDBE_PROFILE) \
35364
+ || defined(SQLITE_PERFORMANCE_TRACE) \
35365
+ || defined(SQLITE_ENABLE_STMT_SCANSTATUS)
35366
+/************** Include hwtime.h in the middle of util.c *********************/
35367
+/************** Begin file hwtime.h ******************************************/
35368
+/*
35369
+** 2008 May 27
35370
+**
35371
+** The author disclaims copyright to this source code. In place of
35372
+** a legal notice, here is a blessing:
35373
+**
35374
+** May you do good and not evil.
35375
+** May you find forgiveness for yourself and forgive others.
35376
+** May you share freely, never taking more than you give.
35377
+**
35378
+******************************************************************************
35379
+**
35380
+** This file contains inline asm code for retrieving "high-performance"
35381
+** counters for x86 and x86_64 class CPUs.
35382
+*/
35383
+#ifndef SQLITE_HWTIME_H
35384
+#define SQLITE_HWTIME_H
35385
+
35386
+/*
35387
+** The following routine only works on pentium-class (or newer) processors.
35388
+** It uses the RDTSC opcode to read the cycle count value out of the
35389
+** processor and returns that value. This can be used for high-res
35390
+** profiling.
35391
+*/
35392
+#if !defined(__STRICT_ANSI__) && \
35393
+ (defined(__GNUC__) || defined(_MSC_VER)) && \
35394
+ (defined(i386) || defined(__i386__) || defined(_M_IX86))
35395
+
35396
+ #if defined(__GNUC__)
35397
+
35398
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
35399
+ unsigned int lo, hi;
35400
+ __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
35401
+ return (sqlite_uint64)hi << 32 | lo;
35402
+ }
35403
+
35404
+ #elif defined(_MSC_VER)
35405
+
35406
+ __declspec(naked) __inline sqlite_uint64 __cdecl sqlite3Hwtime(void){
35407
+ __asm {
35408
+ rdtsc
35409
+ ret ; return value at EDX:EAX
35410
+ }
35411
+ }
35412
+
35413
+ #endif
35414
+
35415
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
35416
+
35417
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
35418
+ unsigned int lo, hi;
35419
+ __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
35420
+ return (sqlite_uint64)hi << 32 | lo;
35421
+ }
35422
+
35423
+#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
35424
+
35425
+ __inline__ sqlite_uint64 sqlite3Hwtime(void){
35426
+ unsigned long long retval;
35427
+ unsigned long junk;
35428
+ __asm__ __volatile__ ("\n\
35429
+ 1: mftbu %1\n\
35430
+ mftb %L0\n\
35431
+ mftbu %0\n\
35432
+ cmpw %0,%1\n\
35433
+ bne 1b"
35434
+ : "=r" (retval), "=r" (junk));
35435
+ return retval;
35436
+ }
35437
+
35438
+#else
35439
+
35440
+ /*
35441
+ ** asm() is needed for hardware timing support. Without asm(),
35442
+ ** disable the sqlite3Hwtime() routine.
35443
+ **
35444
+ ** sqlite3Hwtime() is only used for some obscure debugging
35445
+ ** and analysis configurations, not in any deliverable, so this
35446
+ ** should not be a great loss.
35447
+ */
35448
+SQLITE_PRIVATE sqlite_uint64 sqlite3Hwtime(void){ return ((sqlite_uint64)0); }
35449
+
35450
+#endif
35451
+
35452
+#endif /* !defined(SQLITE_HWTIME_H) */
35453
+
35454
+/************** End of hwtime.h **********************************************/
35455
+/************** Continuing where we left off in util.c ***********************/
35456
+#endif
35457
+
35458
/************** End of util.c ************************************************/
35459
/************** Begin file hash.c ********************************************/
35460
/*
@@ -35383,12 +35625,13 @@ static HashElem *findElementWithHash(
35625
count = pH->count;
35626
}
35627
if( pHash ) *pHash = h;
35386
- while( count-- ){
35628
+ while( count ){
35629
assert( elem!=0 );
35630
if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
35631
return elem;
35632
}
35633
elem = elem->next;
35634
+ count--;
35635
}
35636
return &nullElement;
35637
}
@@ -35747,7 +35990,9 @@ struct KVVfsFile {
35990
char *aJrnl; /* Journal content */
35991
int szPage; /* Last known page size */
35992
sqlite3_int64 szDb; /* Database file size. -1 means unknown */
35993
+ char *aData; /* Buffer to hold page data */
35994
};
35995
+#define SQLITE_KVOS_SZ 133073
35996
35997
/*
35998
** Methods for KVVfsFile
@@ -36110,8 +36355,7 @@ static int kvvfsDecode(const char *a, char *aOut, int nOut){
36355
if( j+n>nOut ) return -1;
36356
memset(&aOut[j], 0, n);
36357
j += n;
36113
- c = aIn[i];
36114
- if( c==0 ) break;
36358
+ if( c==0 || mult==1 ) break; /* progress stalled if mult==1 */
36359
}else{
36360
aOut[j] = c<<4;
36361
c = kvvfsHexValue[aIn[++i]];
@@ -36188,6 +36432,7 @@ static int kvvfsClose(sqlite3_file *pProtoFile){
36432
SQLITE_KV_LOG(("xClose %s %s\n", pFile->zClass,
36433
pFile->isJournal ? "journal" : "db"));
36434
sqlite3_free(pFile->aJrnl);
36435
+ sqlite3_free(pFile->aData);
36436
return SQLITE_OK;
36437
}
36438
@@ -36236,7 +36481,7 @@ static int kvvfsReadDb(
36481
unsigned int pgno;
36482
int got, n;
36483
char zKey[30];
36239
- char aData[133073];
36484
+ char *aData = pFile->aData;
36485
assert( iOfst>=0 );
36486
assert( iAmt>=0 );
36487
SQLITE_KV_LOG(("xRead('%s-db',%d,%lld)\n", pFile->zClass, iAmt, iOfst));
@@ -36253,7 +36498,8 @@ static int kvvfsReadDb(
36498
pgno = 1;
36499
}
36500
sqlite3_snprintf(sizeof(zKey), zKey, "%u", pgno);
36256
- got = sqlite3KvvfsMethods.xRead(pFile->zClass, zKey, aData, sizeof(aData)-1);
36501
+ got = sqlite3KvvfsMethods.xRead(pFile->zClass, zKey,
36502
+ aData, SQLITE_KVOS_SZ-1);
36503
if( got<0 ){
36504
n = 0;
36505
}else{
@@ -36261,7 +36507,7 @@ static int kvvfsReadDb(
36507
if( iOfst+iAmt<512 ){
36508
int k = iOfst+iAmt;
36509
aData[k*2] = 0;
36264
- n = kvvfsDecode(aData, &aData[2000], sizeof(aData)-2000);
36510
+ n = kvvfsDecode(aData, &aData[2000], SQLITE_KVOS_SZ-2000);
36511
if( n>=iOfst+iAmt ){
36512
memcpy(zBuf, &aData[2000+iOfst], iAmt);
36513
n = iAmt;
@@ -36320,7 +36566,7 @@ static int kvvfsWriteDb(
36566
KVVfsFile *pFile = (KVVfsFile*)pProtoFile;
36567
unsigned int pgno;
36568
char zKey[30];
36323
- char aData[131073];
36569
+ char *aData = pFile->aData;
36570
SQLITE_KV_LOG(("xWrite('%s-db',%d,%lld)\n", pFile->zClass, iAmt, iOfst));
36571
assert( iAmt>=512 && iAmt<=65536 );
36572
assert( (iAmt & (iAmt-1))==0 );
@@ -36529,6 +36775,10 @@ static int kvvfsOpen(
36775
}else{
36776
pFile->zClass = "local";
36777
}
36778
+ pFile->aData = sqlite3_malloc64(SQLITE_KVOS_SZ);
36779
+ if( pFile->aData==0 ){
36780
+ return SQLITE_NOMEM;
36781
+ }
36782
pFile->aJrnl = 0;
36783
pFile->nJrnl = 0;
36784
pFile->szPage = -1;
@@ -36765,7 +37015,8 @@ SQLITE_PRIVATE int sqlite3KvvfsInit(void){
37015
/* #include <time.h> */
37016
#include <sys/time.h> /* amalgamator: keep */
37017
#include <errno.h>
36768
-#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
37018
+#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
37019
+ && !defined(SQLITE_WASI)
37020
# include <sys/mman.h>
37021
#endif
37022
@@ -36853,9 +37104,46 @@ SQLITE_PRIVATE int sqlite3KvvfsInit(void){
37104
*/
37105
#define SQLITE_MAX_SYMLINKS 100
37106
37107
+/*
37108
+** Remove and stub certain info for WASI (WebAssembly System
37109
+** Interface) builds.
37110
+*/
37111
+#ifdef SQLITE_WASI
37112
+# undef HAVE_FCHMOD
37113
+# undef HAVE_FCHOWN
37114
+# undef HAVE_MREMAP
37115
+# define HAVE_MREMAP 0
37116
+# ifndef SQLITE_DEFAULT_UNIX_VFS
37117
+# define SQLITE_DEFAULT_UNIX_VFS "unix-dotfile"
37118
+ /* ^^^ should SQLITE_DEFAULT_UNIX_VFS be "unix-none"? */
37119
+# endif
37120
+# ifndef F_RDLCK
37121
+# define F_RDLCK 0
37122
+# define F_WRLCK 1
37123
+# define F_UNLCK 2
37124
+# if __LONG_MAX == 0x7fffffffL
37125
+# define F_GETLK 12
37126
+# define F_SETLK 13
37127
+# define F_SETLKW 14
37128
+# else
37129
+# define F_GETLK 5
37130
+# define F_SETLK 6
37131
+# define F_SETLKW 7
37132
+# endif
37133
+# endif
37134
+#else /* !SQLITE_WASI */
37135
+# ifndef HAVE_FCHMOD
37136
+# define HAVE_FCHMOD
37137
+# endif
37138
+#endif /* SQLITE_WASI */
37139
+
37140
+#ifdef SQLITE_WASI
37141
+# define osGetpid(X) (pid_t)1
37142
+#else
37143
/* Always cast the getpid() return type for compatibility with
37144
** kernel modules in VxWorks. */
36858
-#define osGetpid(X) (pid_t)getpid()
37145
+# define osGetpid(X) (pid_t)getpid()
37146
+#endif
37147
37148
/*
37149
** Only set the lastErrno if the error code is a real error and not
@@ -37127,7 +37415,11 @@ static struct unix_syscall {
37415
#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
37416
aSyscall[13].pCurrent)
37417
37418
+#if defined(HAVE_FCHMOD)
37419
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
37420
+#else
37421
+ { "fchmod", (sqlite3_syscall_ptr)0, 0 },
37422
+#endif
37423
#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
37424
37425
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
@@ -37163,14 +37455,16 @@ static struct unix_syscall {
37455
#endif
37456
#define osGeteuid ((uid_t(*)(void))aSyscall[21].pCurrent)
37457
37166
-#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
37458
+#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
37459
+ && !defined(SQLITE_WASI)
37460
{ "mmap", (sqlite3_syscall_ptr)mmap, 0 },
37461
#else
37462
{ "mmap", (sqlite3_syscall_ptr)0, 0 },
37463
#endif
37464
#define osMmap ((void*(*)(void*,size_t,int,int,int,off_t))aSyscall[22].pCurrent)
37465
37173
-#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
37466
+#if (!defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0) \
37467
+ && !defined(SQLITE_WASI)
37468
{ "munmap", (sqlite3_syscall_ptr)munmap, 0 },
37469
#else
37470
{ "munmap", (sqlite3_syscall_ptr)0, 0 },
@@ -38321,7 +38615,7 @@ static int unixFileLock(unixFile *pFile, struct flock *pLock){
38615
**
38616
** UNLOCKED -> SHARED
38617
** SHARED -> RESERVED
38324
-** SHARED -> (PENDING) -> EXCLUSIVE
38618
+** SHARED -> EXCLUSIVE
38619
** RESERVED -> (PENDING) -> EXCLUSIVE
38620
** PENDING -> EXCLUSIVE
38621
**
@@ -38354,19 +38648,20 @@ static int unixLock(sqlite3_file *id, int eFileLock){
38648
** A RESERVED lock is implemented by grabbing a write-lock on the
38649
** 'reserved byte'.
38650
**
38357
- ** A process may only obtain a PENDING lock after it has obtained a
38358
- ** SHARED lock. A PENDING lock is implemented by obtaining a write-lock
38359
- ** on the 'pending byte'. This ensures that no new SHARED locks can be
38360
- ** obtained, but existing SHARED locks are allowed to persist. A process
38361
- ** does not have to obtain a RESERVED lock on the way to a PENDING lock.
38362
- ** This property is used by the algorithm for rolling back a journal file
38363
- ** after a crash.
38651
+ ** An EXCLUSIVE lock may only be requested after either a SHARED or
38652
+ ** RESERVED lock is held. An EXCLUSIVE lock is implemented by obtaining
38653
+ ** a write-lock on the entire 'shared byte range'. Since all other locks
38654
+ ** require a read-lock on one of the bytes within this range, this ensures
38655
+ ** that no other locks are held on the database.
38656
**
38365
- ** An EXCLUSIVE lock, obtained after a PENDING lock is held, is
38366
- ** implemented by obtaining a write-lock on the entire 'shared byte
38367
- ** range'. Since all other locks require a read-lock on one of the bytes
38368
- ** within this range, this ensures that no other locks are held on the
38369
- ** database.
38657
+ ** If a process that holds a RESERVED lock requests an EXCLUSIVE, then
38658
+ ** a PENDING lock is obtained first. A PENDING lock is implemented by
38659
+ ** obtaining a write-lock on the 'pending byte'. This ensures that no new
38660
+ ** SHARED locks can be obtained, but existing SHARED locks are allowed to
38661
+ ** persist. If the call to this function fails to obtain the EXCLUSIVE
38662
+ ** lock in this case, it holds the PENDING lock intead. The client may
38663
+ ** then re-attempt the EXCLUSIVE lock later on, after existing SHARED
38664
+ ** locks have cleared.
38665
*/
38666
int rc = SQLITE_OK;
38667
unixFile *pFile = (unixFile*)id;
@@ -38437,7 +38732,7 @@ static int unixLock(sqlite3_file *id, int eFileLock){
38732
lock.l_len = 1L;
38733
lock.l_whence = SEEK_SET;
38734
if( eFileLock==SHARED_LOCK
38440
- || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK)
38735
+ || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock==RESERVED_LOCK)
38736
){
38737
lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK);
38738
lock.l_start = PENDING_BYTE;
@@ -38448,6 +38743,9 @@ static int unixLock(sqlite3_file *id, int eFileLock){
38743
storeLastErrno(pFile, tErrno);
38744
}
38745
goto end_lock;
38746
+ }else if( eFileLock==EXCLUSIVE_LOCK ){
38747
+ pFile->eFileLock = PENDING_LOCK;
38748
+ pInode->eFileLock = PENDING_LOCK;
38749
}
38750
}
38751
@@ -38535,13 +38833,9 @@ static int unixLock(sqlite3_file *id, int eFileLock){
38833
}
38834
#endif
38835
38538
-
38836
if( rc==SQLITE_OK ){
38837
pFile->eFileLock = eFileLock;
38838
pInode->eFileLock = eFileLock;
38542
- }else if( eFileLock==EXCLUSIVE_LOCK ){
38543
- pFile->eFileLock = PENDING_LOCK;
38544
- pInode->eFileLock = PENDING_LOCK;
38839
}
38840
38841
end_lock:
@@ -43132,12 +43426,10 @@ static void appendOnePathElement(
43426
if( zName[0]=='.' ){
43427
if( nName==1 ) return;
43428
if( zName[1]=='.' && nName==2 ){
43135
- if( pPath->nUsed<=1 ){
43136
- pPath->rc = SQLITE_ERROR;
43137
- return;
43429
+ if( pPath->nUsed>1 ){
43430
+ assert( pPath->zOut[0]=='/' );
43431
+ while( pPath->zOut[--pPath->nUsed]!='/' ){}
43432
}
43139
- assert( pPath->zOut[0]=='/' );
43140
- while( pPath->zOut[--pPath->nUsed]!='/' ){}
43433
return;
43434
}
43435
}
@@ -43349,7 +43641,7 @@ static int unixRandomness(sqlite3_vfs *NotUsed, int nBuf, char *zBuf){
43641
** than the argument.
43642
*/
43643
static int unixSleep(sqlite3_vfs *NotUsed, int microseconds){
43352
-#if OS_VXWORKS
43644
+#if OS_VXWORKS || _POSIX_C_SOURCE >= 199309L
43645
struct timespec sp;
43646
43647
sp.tv_sec = microseconds / 1000000;
@@ -51886,9 +52178,9 @@ end_deserialize:
52178
/*
52179
** Return true if the VFS is the memvfs.
52180
*/
51889
-//SQLITE_PRIVATE int sqlite3IsMemdb(const sqlite3_vfs *pVfs){
51890
-// return pVfs==&memdb_vfs;
51891
-//}
52181
+SQLITE_PRIVATE int sqlite3IsMemdb(const sqlite3_vfs *pVfs){
52182
+ return pVfs==&memdb_vfs;
52183
+}
52184
52185
/*
52186
** This routine is called when the extension is loaded.
@@ -52369,7 +52661,7 @@ bitvec_end:
52661
struct PCache {
52662
PgHdr *pDirty, *pDirtyTail; /* List of dirty pages in LRU order */
52663
PgHdr *pSynced; /* Last synced page in dirty page list */
52372
- int nRefSum; /* Sum of ref counts over all pages */
52664
+ i64 nRefSum; /* Sum of ref counts over all pages */
52665
int szCache; /* Configured cache size */
52666
int szSpill; /* Size before spilling occurs */
52667
int szPage; /* Size of every page in this cache */
@@ -52399,7 +52691,7 @@ struct PCache {
52691
unsigned char *a;
52692
int j;
52693
pPg = (PgHdr*)pLower->pExtra;
52402
- printf("%3d: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
52694
+ printf("%3lld: nRef %2d flgs %02x data ", i, pPg->nRef, pPg->flags);
52695
a = (unsigned char *)pLower->pBuf;
52696
for(j=0; j<12; j++) printf("%02x", a[j]);
52697
printf(" ptr %p\n", pPg);
@@ -53143,14 +53435,14 @@ SQLITE_PRIVATE PgHdr *sqlite3PcacheDirtyList(PCache *pCache){
53435
** This is not the total number of pages referenced, but the sum of the
53436
** reference count for all pages.
53437
*/
53146
-SQLITE_PRIVATE int sqlite3PcacheRefCount(PCache *pCache){
53438
+SQLITE_PRIVATE i64 sqlite3PcacheRefCount(PCache *pCache){
53439
return pCache->nRefSum;
53440
}
53441
53442
/*
53443
** Return the number of references to the page supplied as an argument.
53444
*/
53153
-SQLITE_PRIVATE int sqlite3PcachePageRefcount(PgHdr *p){
53445
+SQLITE_PRIVATE i64 sqlite3PcachePageRefcount(PgHdr *p){
53446
return p->nRef;
53447
}
53448
@@ -58135,7 +58427,7 @@ end_playback:
58427
** see if it is possible to delete the super-journal.
58428
*/
58429
assert( zSuper==&pPager->pTmpSpace[4] );
58138
- memset(&zSuper[-4], 0, 4);
58430
+ memset(pPager->pTmpSpace, 0, 4);
58431
rc = pager_delsuper(pPager, zSuper);
58432
testcase( rc!=SQLITE_OK );
58433
}
@@ -58756,7 +59048,6 @@ SQLITE_PRIVATE void sqlite3PagerShrink(Pager *pPager){
59048
** Numeric values associated with these states are OFF==1, NORMAL=2,
59049
** and FULL=3.
59050
*/
58759
-#ifndef SQLITE_OMIT_PAGER_PRAGMAS
59051
SQLITE_PRIVATE void sqlite3PagerSetFlags(
59052
Pager *pPager, /* The pager to set safety level for */
59053
unsigned pgFlags /* Various flags */
@@ -58791,7 +59082,6 @@ SQLITE_PRIVATE void sqlite3PagerSetFlags(
59082
pPager->doNotSpill |= SPILLFLAG_OFF;
59083
}
59084
}
58794
-#endif
59085
59086
/*
59087
** The following global variable is incremented whenever the library
@@ -59893,7 +60183,6 @@ SQLITE_PRIVATE int sqlite3PagerOpen(
60183
u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */
60184
const char *zUri = 0; /* URI args to copy */
60185
int nUriByte = 1; /* Number of bytes of URI args at *zUri */
59896
- int nUri = 0; /* Number of URI parameters */
60186
60187
/* Figure out how much space is required for each journal file-handle
60188
** (there are two of them, the main journal and the sub-journal). */
@@ -59941,7 +60230,6 @@ SQLITE_PRIVATE int sqlite3PagerOpen(
60230
while( *z ){
60231
z += strlen(z)+1;
60232
z += strlen(z)+1;
59944
- nUri++;
60233
}
60234
nUriByte = (int)(&z[1] - zUri);
60235
assert( nUriByte>=1 );
@@ -60197,18 +60485,7 @@ act_like_temp_file:
60485
pPager->memDb = (u8)memDb;
60486
pPager->readOnly = (u8)readOnly;
60487
assert( useJournal || pPager->tempFile );
60200
- pPager->noSync = pPager->tempFile;
60201
- if( pPager->noSync ){
60202
- assert( pPager->fullSync==0 );
60203
- assert( pPager->extraSync==0 );
60204
- assert( pPager->syncFlags==0 );
60205
- assert( pPager->walSyncFlags==0 );
60206
- }else{
60207
- pPager->fullSync = 1;
60208
- pPager->extraSync = 0;
60209
- pPager->syncFlags = SQLITE_SYNC_NORMAL;
60210
- pPager->walSyncFlags = SQLITE_SYNC_NORMAL | (SQLITE_SYNC_NORMAL<<2);
60211
- }
60488
+ sqlite3PagerSetFlags(pPager, (SQLITE_DEFAULT_SYNCHRONOUS+1)|PAGER_CACHESPILL);
60489
/* pPager->pFirst = 0; */
60490
/* pPager->pFirstSynced = 0; */
60491
/* pPager->pLast = 0; */
@@ -61469,7 +61746,7 @@ static int pager_incr_changecounter(Pager *pPager, int isDirectMode){
61746
# define DIRECT_MODE isDirectMode
61747
#endif
61748
61472
- if( !pPager->changeCountDone && ALWAYS(pPager->dbSize>0) ){
61749
+ if( !pPager->changeCountDone && pPager->dbSize>0 ){
61750
PgHdr *pPgHdr; /* Reference to page 1 */
61751
61752
assert( !pPager->tempFile && isOpen(pPager->fd) );
@@ -62209,7 +62486,11 @@ SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint){
62486
*/
62487
SQLITE_PRIVATE const char *sqlite3PagerFilename(const Pager *pPager, int nullIfMemDb){
62488
static const char zFake[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
62212
- return (nullIfMemDb && pPager->memDb) ? &zFake[4] : pPager->zFilename;
62489
+ if( nullIfMemDb && (pPager->memDb || sqlite3IsMemdb(pPager->pVfs)) ){
62490
+ return &zFake[4];
62491
+ }else{
62492
+ return pPager->zFilename;
62493
+ }
62494
}
62495
62496
/*
@@ -67792,15 +68073,15 @@ struct BtCursor {
68073
** So, this macro is defined instead.
68074
*/
68075
#ifndef SQLITE_OMIT_AUTOVACUUM
67795
-#define ISAUTOVACUUM (pBt->autoVacuum)
68076
+#define ISAUTOVACUUM(pBt) (pBt->autoVacuum)
68077
#else
67797
-#define ISAUTOVACUUM 0
68078
+#define ISAUTOVACUUM(pBt) 0
68079
#endif
68080
68081
68082
/*
67802
-** This structure is passed around through all the sanity checking routines
67803
-** in order to keep track of some global state information.
68083
+** This structure is passed around through all the PRAGMA integrity_check
68084
+** checking routines in order to keep track of some global state information.
68085
**
68086
** The aRef[] array is allocated so that there is 1 bit for each page in
68087
** the database. As the integrity-check proceeds, for each page used in
@@ -67816,7 +68097,8 @@ struct IntegrityCk {
68097
Pgno nPage; /* Number of pages in the database */
68098
int mxErr; /* Stop accumulating errors when this reaches zero */
68099
int nErr; /* Number of messages written to zErrMsg so far */
67819
- int bOomFault; /* A memory allocation error has occurred */
68100
+ int rc; /* SQLITE_OK, SQLITE_NOMEM, or SQLITE_INTERRUPT */
68101
+ u32 nStep; /* Number of steps into the integrity_check process */
68102
const char *zPfx; /* Error message prefix */
68103
Pgno v1; /* Value for first %u substitution in zPfx */
68104
int v2; /* Value for second %d substitution in zPfx */
@@ -70046,62 +70328,67 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
70328
** Only the following combinations are supported. Anything different
70329
** indicates a corrupt database files:
70330
**
70049
-** PTF_ZERODATA
70050
-** PTF_ZERODATA | PTF_LEAF
70051
-** PTF_LEAFDATA | PTF_INTKEY
70052
-** PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF
70331
+** PTF_ZERODATA (0x02, 2)
70332
+** PTF_LEAFDATA | PTF_INTKEY (0x05, 5)
70333
+** PTF_ZERODATA | PTF_LEAF (0x0a, 10)
70334
+** PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF (0x0d, 13)
70335
*/
70336
static int decodeFlags(MemPage *pPage, int flagByte){
70337
BtShared *pBt; /* A copy of pPage->pBt */
70338
70339
assert( pPage->hdrOffset==(pPage->pgno==1 ? 100 : 0) );
70340
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
70059
- pPage->leaf = (u8)(flagByte>>3); assert( PTF_LEAF == 1<<3 );
70060
- flagByte &= ~PTF_LEAF;
70061
- pPage->childPtrSize = 4-4*pPage->leaf;
70341
pBt = pPage->pBt;
70063
- if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
70064
- /* EVIDENCE-OF: R-07291-35328 A value of 5 (0x05) means the page is an
70065
- ** interior table b-tree page. */
70066
- assert( (PTF_LEAFDATA|PTF_INTKEY)==5 );
70067
- /* EVIDENCE-OF: R-26900-09176 A value of 13 (0x0d) means the page is a
70068
- ** leaf table b-tree page. */
70069
- assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 );
70070
- pPage->intKey = 1;
70071
- if( pPage->leaf ){
70342
+ pPage->max1bytePayload = pBt->max1bytePayload;
70343
+ if( flagByte>=(PTF_ZERODATA | PTF_LEAF) ){
70344
+ pPage->childPtrSize = 0;
70345
+ pPage->leaf = 1;
70346
+ if( flagByte==(PTF_LEAFDATA | PTF_INTKEY | PTF_LEAF) ){
70347
pPage->intKeyLeaf = 1;
70348
pPage->xCellSize = cellSizePtrTableLeaf;
70349
pPage->xParseCell = btreeParseCellPtr;
70350
+ pPage->intKey = 1;
70351
+ pPage->maxLocal = pBt->maxLeaf;
70352
+ pPage->minLocal = pBt->minLeaf;
70353
+ }else if( flagByte==(PTF_ZERODATA | PTF_LEAF) ){
70354
+ pPage->intKey = 0;
70355
+ pPage->intKeyLeaf = 0;
70356
+ pPage->xCellSize = cellSizePtr;
70357
+ pPage->xParseCell = btreeParseCellPtrIndex;
70358
+ pPage->maxLocal = pBt->maxLocal;
70359
+ pPage->minLocal = pBt->minLocal;
70360
}else{
70361
+ pPage->intKey = 0;
70362
+ pPage->intKeyLeaf = 0;
70363
+ pPage->xCellSize = cellSizePtr;
70364
+ pPage->xParseCell = btreeParseCellPtrIndex;
70365
+ return SQLITE_CORRUPT_PAGE(pPage);
70366
+ }
70367
+ }else{
70368
+ pPage->childPtrSize = 4;
70369
+ pPage->leaf = 0;
70370
+ if( flagByte==(PTF_ZERODATA) ){
70371
+ pPage->intKey = 0;
70372
+ pPage->intKeyLeaf = 0;
70373
+ pPage->xCellSize = cellSizePtr;
70374
+ pPage->xParseCell = btreeParseCellPtrIndex;
70375
+ pPage->maxLocal = pBt->maxLocal;
70376
+ pPage->minLocal = pBt->minLocal;
70377
+ }else if( flagByte==(PTF_LEAFDATA | PTF_INTKEY) ){
70378
pPage->intKeyLeaf = 0;
70379
pPage->xCellSize = cellSizePtrNoPayload;
70380
pPage->xParseCell = btreeParseCellPtrNoPayload;
70381
+ pPage->intKey = 1;
70382
+ pPage->maxLocal = pBt->maxLeaf;
70383
+ pPage->minLocal = pBt->minLeaf;
70384
+ }else{
70385
+ pPage->intKey = 0;
70386
+ pPage->intKeyLeaf = 0;
70387
+ pPage->xCellSize = cellSizePtr;
70388
+ pPage->xParseCell = btreeParseCellPtrIndex;
70389
+ return SQLITE_CORRUPT_PAGE(pPage);
70390
}
70080
- pPage->maxLocal = pBt->maxLeaf;
70081
- pPage->minLocal = pBt->minLeaf;
70082
- }else if( flagByte==PTF_ZERODATA ){
70083
- /* EVIDENCE-OF: R-43316-37308 A value of 2 (0x02) means the page is an
70084
- ** interior index b-tree page. */
70085
- assert( (PTF_ZERODATA)==2 );
70086
- /* EVIDENCE-OF: R-59615-42828 A value of 10 (0x0a) means the page is a
70087
- ** leaf index b-tree page. */
70088
- assert( (PTF_ZERODATA|PTF_LEAF)==10 );
70089
- pPage->intKey = 0;
70090
- pPage->intKeyLeaf = 0;
70091
- pPage->xCellSize = cellSizePtr;
70092
- pPage->xParseCell = btreeParseCellPtrIndex;
70093
- pPage->maxLocal = pBt->maxLocal;
70094
- pPage->minLocal = pBt->minLocal;
70095
- }else{
70096
- /* EVIDENCE-OF: R-47608-56469 Any other value for the b-tree page type is
70097
- ** an error. */
70098
- pPage->intKey = 0;
70099
- pPage->intKeyLeaf = 0;
70100
- pPage->xCellSize = cellSizePtr;
70101
- pPage->xParseCell = btreeParseCellPtrIndex;
70102
- return SQLITE_CORRUPT_PAGE(pPage);
70391
}
70104
- pPage->max1bytePayload = pBt->max1bytePayload;
70392
return SQLITE_OK;
70393
}
70394
@@ -73641,9 +73928,25 @@ SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor *pCur, int *pRes){
73928
** on success. Set *pRes to 0 if the cursor actually points to something
73929
** or set *pRes to 1 if the table is empty.
73930
*/
73931
+static SQLITE_NOINLINE int btreeLast(BtCursor *pCur, int *pRes){
73932
+ int rc = moveToRoot(pCur);
73933
+ if( rc==SQLITE_OK ){
73934
+ assert( pCur->eState==CURSOR_VALID );
73935
+ *pRes = 0;
73936
+ rc = moveToRightmost(pCur);
73937
+ if( rc==SQLITE_OK ){
73938
+ pCur->curFlags |= BTCF_AtLast;
73939
+ }else{
73940
+ pCur->curFlags &= ~BTCF_AtLast;
73941
+ }
73942
+ }else if( rc==SQLITE_EMPTY ){
73943
+ assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
73944
+ *pRes = 1;
73945
+ rc = SQLITE_OK;
73946
+ }
73947
+ return rc;
73948
+}
73949
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
73645
- int rc;
73646
-
73950
assert( cursorOwnsBtShared(pCur) );
73951
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
73952
@@ -73664,23 +73967,7 @@ SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
73967
*pRes = 0;
73968
return SQLITE_OK;
73969
}
73667
-
73668
- rc = moveToRoot(pCur);
73669
- if( rc==SQLITE_OK ){
73670
- assert( pCur->eState==CURSOR_VALID );
73671
- *pRes = 0;
73672
- rc = moveToRightmost(pCur);
73673
- if( rc==SQLITE_OK ){
73674
- pCur->curFlags |= BTCF_AtLast;
73675
- }else{
73676
- pCur->curFlags &= ~BTCF_AtLast;
73677
- }
73678
- }else if( rc==SQLITE_EMPTY ){
73679
- assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
73680
- *pRes = 1;
73681
- rc = SQLITE_OK;
73682
- }
73683
- return rc;
73970
+ return btreeLast(pCur, pRes);
73971
}
73972
73973
/* Move the cursor so that it points to an entry in a table (a.k.a INTKEY)
@@ -74225,7 +74512,7 @@ static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
74512
74513
pPage = pCur->pPage;
74514
idx = ++pCur->ix;
74228
- if( NEVER(!pPage->isInit) || sqlite3FaultSim(412) ){
74515
+ if( !pPage->isInit || sqlite3FaultSim(412) ){
74516
return SQLITE_CORRUPT_BKPT;
74517
}
74518
@@ -74747,7 +75034,7 @@ static int freePage2(BtShared *pBt, MemPage *pMemPage, Pgno iPage){
75034
/* If the database supports auto-vacuum, write an entry in the pointer-map
75035
** to indicate that the page is free.
75036
*/
74750
- if( ISAUTOVACUUM ){
75037
+ if( ISAUTOVACUUM(pBt) ){
75038
ptrmapPut(pBt, iPage, PTRMAP_FREEPAGE, 0, &rc);
75039
if( rc ) goto freepage_out;
75040
}
@@ -75187,24 +75474,20 @@ static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){
75474
** in pTemp or the original pCell) and also record its index.
75475
** Allocating a new entry in pPage->aCell[] implies that
75476
** pPage->nOverflow is incremented.
75190
-**
75191
-** *pRC must be SQLITE_OK when this routine is called.
75477
*/
75193
-static void insertCell(
75478
+static int insertCell(
75479
MemPage *pPage, /* Page into which we are copying */
75480
int i, /* New cell becomes the i-th cell of the page */
75481
u8 *pCell, /* Content of the new cell */
75482
int sz, /* Bytes of content in pCell */
75483
u8 *pTemp, /* Temp storage space for pCell, if needed */
75199
- Pgno iChild, /* If non-zero, replace first 4 bytes with this value */
75200
- int *pRC /* Read and write return code from here */
75484
+ Pgno iChild /* If non-zero, replace first 4 bytes with this value */
75485
){
75486
int idx = 0; /* Where to write new cell content in data[] */
75487
int j; /* Loop counter */
75488
u8 *data; /* The content of the whole page */
75489
u8 *pIns; /* The point in pPage->aCellIdx[] where no cell inserted */
75490
75207
- assert( *pRC==SQLITE_OK );
75491
assert( i>=0 && i<=pPage->nCell+pPage->nOverflow );
75492
assert( MX_CELL(pPage->pBt)<=10921 );
75493
assert( pPage->nCell<=MX_CELL(pPage->pBt) || CORRUPT_DB );
@@ -75239,14 +75522,13 @@ static void insertCell(
75522
}else{
75523
int rc = sqlite3PagerWrite(pPage->pDbPage);
75524
if( rc!=SQLITE_OK ){
75242
- *pRC = rc;
75243
- return;
75525
+ return rc;
75526
}
75527
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
75528
data = pPage->aData;
75529
assert( &data[pPage->cellOffset]==pPage->aCellIdx );
75530
rc = allocateSpace(pPage, sz, &idx);
75249
- if( rc ){ *pRC = rc; return; }
75531
+ if( rc ){ return rc; }
75532
/* The allocateSpace() routine guarantees the following properties
75533
** if it returns successfully */
75534
assert( idx >= 0 );
@@ -75273,13 +75555,16 @@ static void insertCell(
75555
assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
75556
#ifndef SQLITE_OMIT_AUTOVACUUM
75557
if( pPage->pBt->autoVacuum ){
75558
+ int rc2 = SQLITE_OK;
75559
/* The cell may contain a pointer to an overflow page. If so, write
75560
** the entry for the overflow page into the pointer map.
75561
*/
75279
- ptrmapPutOvflPtr(pPage, pPage, pCell, pRC);
75562
+ ptrmapPutOvflPtr(pPage, pPage, pCell, &rc2);
75563
+ if( rc2 ) return rc2;
75564
}
75565
#endif
75566
}
75567
+ return SQLITE_OK;
75568
}
75569
75570
/*
@@ -75380,14 +75665,16 @@ struct CellArray {
75665
** computed.
75666
*/
75667
static void populateCellCache(CellArray *p, int idx, int N){
75668
+ MemPage *pRef = p->pRef;
75669
+ u16 *szCell = p->szCell;
75670
assert( idx>=0 && idx+N<=p->nCell );
75671
while( N>0 ){
75672
assert( p->apCell[idx]!=0 );
75386
- if( p->szCell[idx]==0 ){
75387
- p->szCell[idx] = p->pRef->xCellSize(p->pRef, p->apCell[idx]);
75673
+ if( szCell[idx]==0 ){
75674
+ szCell[idx] = pRef->xCellSize(pRef, p->apCell[idx]);
75675
}else{
75676
assert( CORRUPT_DB ||
75390
- p->szCell[idx]==p->pRef->xCellSize(p->pRef, p->apCell[idx]) );
75677
+ szCell[idx]==pRef->xCellSize(pRef, p->apCell[idx]) );
75678
}
75679
idx++;
75680
N--;
@@ -75589,8 +75876,8 @@ static int pageFreeArray(
75876
int nRet = 0;
75877
int i;
75878
int iEnd = iFirst + nCell;
75592
- u8 *pFree = 0;
75593
- int szFree = 0;
75879
+ u8 *pFree = 0; /* \__ Parameters for pending call to */
75880
+ int szFree = 0; /* / freeSpace() */
75881
75882
for(i=iFirst; i<iEnd; i++){
75883
u8 *pCell = pCArray->apCell[i];
@@ -75611,6 +75898,9 @@ static int pageFreeArray(
75898
return 0;
75899
}
75900
}else{
75901
+ /* The current cell is adjacent to and before the pFree cell.
75902
+ ** Combine the two regions into one to reduce the number of calls
75903
+ ** to freeSpace(). */
75904
pFree = pCell;
75905
szFree += sz;
75906
}
@@ -75818,7 +76108,7 @@ static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace){
76108
** be marked as dirty. Returning an error code will cause a
76109
** rollback, undoing any changes made to the parent page.
76110
*/
75821
- if( ISAUTOVACUUM ){
76111
+ if( ISAUTOVACUUM(pBt) ){
76112
ptrmapPut(pBt, pgnoNew, PTRMAP_BTREE, pParent->pgno, &rc);
76113
if( szCell>pNew->minLocal ){
76114
ptrmapPutOvflPtr(pNew, pNew, pCell, &rc);
@@ -75846,8 +76136,8 @@ static int balance_quick(MemPage *pParent, MemPage *pPage, u8 *pSpace){
76136
76137
/* Insert the new divider cell into pParent. */
76138
if( rc==SQLITE_OK ){
75849
- insertCell(pParent, pParent->nCell, pSpace, (int)(pOut-pSpace),
75850
- 0, pPage->pgno, &rc);
76139
+ rc = insertCell(pParent, pParent->nCell, pSpace, (int)(pOut-pSpace),
76140
+ 0, pPage->pgno);
76141
}
76142
76143
/* Set the right-child pointer of pParent to point to the new page. */
@@ -75956,7 +76246,7 @@ static void copyNodeContent(MemPage *pFrom, MemPage *pTo, int *pRC){
76246
/* If this is an auto-vacuum database, update the pointer-map entries
76247
** for any b-tree or overflow pages that pTo now contains the pointers to.
76248
*/
75959
- if( ISAUTOVACUUM ){
76249
+ if( ISAUTOVACUUM(pBt) ){
76250
*pRC = setChildPtrmaps(pTo);
76251
}
76252
}
@@ -76380,15 +76670,17 @@ static int balance_nonroot(
76670
d = r + 1 - leafData;
76671
(void)cachedCellSize(&b, d);
76672
do{
76673
+ int szR, szD;
76674
assert( d<nMaxCells );
76675
assert( r<nMaxCells );
76385
- (void)cachedCellSize(&b, r);
76676
+ szR = cachedCellSize(&b, r);
76677
+ szD = b.szCell[d];
76678
if( szRight!=0
76387
- && (bBulk || szRight+b.szCell[d]+2 > szLeft-(b.szCell[r]+(i==k-1?0:2)))){
76679
+ && (bBulk || szRight+szD+2 > szLeft-(szR+(i==k-1?0:2)))){
76680
break;
76681
}
76390
- szRight += b.szCell[d] + 2;
76391
- szLeft -= b.szCell[r] + 2;
76682
+ szRight += szD + 2;
76683
+ szLeft -= szR + 2;
76684
cntNew[i-1] = r;
76685
r--;
76686
d--;
@@ -76442,7 +76734,7 @@ static int balance_nonroot(
76734
cntOld[i] = b.nCell;
76735
76736
/* Set the pointer-map entry for the new sibling page. */
76445
- if( ISAUTOVACUUM ){
76737
+ if( ISAUTOVACUUM(pBt) ){
76738
ptrmapPut(pBt, pNew->pgno, PTRMAP_BTREE, pParent->pgno, &rc);
76739
if( rc!=SQLITE_OK ){
76740
goto balance_cleanup;
@@ -76535,7 +76827,7 @@ static int balance_nonroot(
76827
** updated. This happens below, after the sibling pages have been
76828
** populated, not here.
76829
*/
76538
- if( ISAUTOVACUUM ){
76830
+ if( ISAUTOVACUUM(pBt) ){
76831
MemPage *pOld;
76832
MemPage *pNew = pOld = apNew[0];
76833
int cntOldNext = pNew->nCell + pNew->nOverflow;
@@ -76632,7 +76924,7 @@ static int balance_nonroot(
76924
rc = SQLITE_CORRUPT_BKPT;
76925
goto balance_cleanup;
76926
}
76635
- insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno, &rc);
76927
+ rc = insertCell(pParent, nxDiv+i, pCell, sz, pTemp, pNew->pgno);
76928
if( rc!=SQLITE_OK ) goto balance_cleanup;
76929
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
76930
}
@@ -76728,7 +77020,7 @@ static int balance_nonroot(
77020
);
77021
copyNodeContent(apNew[0], pParent, &rc);
77022
freePage(apNew[0], &rc);
76731
- }else if( ISAUTOVACUUM && !leafCorrection ){
77023
+ }else if( ISAUTOVACUUM(pBt) && !leafCorrection ){
77024
/* Fix the pointer map entries associated with the right-child of each
77025
** sibling page. All other pointer map entries have already been taken
77026
** care of. */
@@ -76749,7 +77041,7 @@ static int balance_nonroot(
77041
}
77042
77043
#if 0
76752
- if( ISAUTOVACUUM && rc==SQLITE_OK && apNew[0]->isInit ){
77044
+ if( ISAUTOVACUUM(pBt) && rc==SQLITE_OK && apNew[0]->isInit ){
77045
/* The ptrmapCheckPages() contains assert() statements that verify that
77046
** all pointer map pages are set correctly. This is helpful while
77047
** debugging. This is usually disabled because a corrupt database may
@@ -76811,7 +77103,7 @@ static int balance_deeper(MemPage *pRoot, MemPage **ppChild){
77103
if( rc==SQLITE_OK ){
77104
rc = allocateBtreePage(pBt,&pChild,&pgnoChild,pRoot->pgno,0);
77105
copyNodeContent(pRoot, pChild, &rc);
76814
- if( ISAUTOVACUUM ){
77106
+ if( ISAUTOVACUUM(pBt) ){
77107
ptrmapPut(pBt, pgnoChild, PTRMAP_BTREE, pRoot->pgno, &rc);
77108
}
77109
}
@@ -77050,9 +77342,13 @@ static int btreeOverwriteContent(
77342
77343
/*
77344
** Overwrite the cell that cursor pCur is pointing to with fresh content
77053
-** contained in pX.
77345
+** contained in pX. In this variant, pCur is pointing to an overflow
77346
+** cell.
77347
*/
77055
-static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
77348
+static SQLITE_NOINLINE int btreeOverwriteOverflowCell(
77349
+ BtCursor *pCur, /* Cursor pointing to cell to ovewrite */
77350
+ const BtreePayload *pX /* Content to write into the cell */
77351
+){
77352
int iOffset; /* Next byte of pX->pData to write */
77353
int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
77354
int rc; /* Return code */
@@ -77061,16 +77357,12 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
77357
Pgno ovflPgno; /* Next overflow page to write */
77358
u32 ovflPageSize; /* Size to write on overflow page */
77359
77064
- if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
77065
- || pCur->info.pPayload < pPage->aData + pPage->cellOffset
77066
- ){
77067
- return SQLITE_CORRUPT_BKPT;
77068
- }
77360
+ assert( pCur->info.nLocal<nTotal ); /* pCur is an overflow cell */
77361
+
77362
/* Overwrite the local portion first */
77363
rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
77364
0, pCur->info.nLocal);
77365
if( rc ) return rc;
77073
- if( pCur->info.nLocal==nTotal ) return SQLITE_OK;
77366
77367
/* Now overwrite the overflow pages */
77368
iOffset = pCur->info.nLocal;
@@ -77100,6 +77392,29 @@ static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
77392
return SQLITE_OK;
77393
}
77394
77395
+/*
77396
+** Overwrite the cell that cursor pCur is pointing to with fresh content
77397
+** contained in pX.
77398
+*/
77399
+static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
77400
+ int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
77401
+ MemPage *pPage = pCur->pPage; /* Page being written */
77402
+
77403
+ if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd
77404
+ || pCur->info.pPayload < pPage->aData + pPage->cellOffset
77405
+ ){
77406
+ return SQLITE_CORRUPT_BKPT;
77407
+ }
77408
+ if( pCur->info.nLocal==nTotal ){
77409
+ /* The entire cell is local */
77410
+ return btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
77411
+ 0, pCur->info.nLocal);
77412
+ }else{
77413
+ /* The cell contains overflow content */
77414
+ return btreeOverwriteOverflowCell(pCur, pX);
77415
+ }
77416
+}
77417
+
77418
77419
/*
77420
** Insert a new record into the BTree. The content of the new record
@@ -77143,7 +77458,6 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77458
int idx;
77459
MemPage *pPage;
77460
Btree *p = pCur->pBtree;
77146
- BtShared *pBt = p->pBt;
77461
unsigned char *oldCell;
77462
unsigned char *newCell = 0;
77463
@@ -77162,7 +77476,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77476
** not to clear the cursor here.
77477
*/
77478
if( pCur->curFlags & BTCF_Multiple ){
77165
- rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
77479
+ rc = saveAllCursors(p->pBt, pCur->pgnoRoot, pCur);
77480
if( rc ) return rc;
77481
if( loc && pCur->iPage<0 ){
77482
/* This can only happen if the schema is corrupt such that there is more
@@ -77186,8 +77500,8 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77500
77501
assert( cursorOwnsBtShared(pCur) );
77502
assert( (pCur->curFlags & BTCF_WriteFlag)!=0
77189
- && pBt->inTransaction==TRANS_WRITE
77190
- && (pBt->btsFlags & BTS_READ_ONLY)==0 );
77503
+ && p->pBt->inTransaction==TRANS_WRITE
77504
+ && (p->pBt->btsFlags & BTS_READ_ONLY)==0 );
77505
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
77506
77507
/* Assert that the caller has been consistent. If this cursor was opened
@@ -77304,27 +77618,30 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77618
pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
77619
loc==0 ? "overwrite" : "new entry"));
77620
assert( pPage->isInit || CORRUPT_DB );
77307
- newCell = pBt->pTmpSpace;
77621
+ newCell = p->pBt->pTmpSpace;
77622
assert( newCell!=0 );
77623
+ assert( BTREE_PREFORMAT==OPFLAG_PREFORMAT );
77624
if( flags & BTREE_PREFORMAT ){
77625
rc = SQLITE_OK;
77311
- szNew = pBt->nPreformatSize;
77626
+ szNew = p->pBt->nPreformatSize;
77627
if( szNew<4 ) szNew = 4;
77313
- if( ISAUTOVACUUM && szNew>pPage->maxLocal ){
77628
+ if( ISAUTOVACUUM(p->pBt) && szNew>pPage->maxLocal ){
77629
CellInfo info;
77630
pPage->xParseCell(pPage, newCell, &info);
77631
if( info.nPayload!=info.nLocal ){
77632
Pgno ovfl = get4byte(&newCell[szNew-4]);
77318
- ptrmapPut(pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, &rc);
77633
+ ptrmapPut(p->pBt, ovfl, PTRMAP_OVERFLOW1, pPage->pgno, &rc);
77634
+ if( NEVER(rc) ) goto end_insert;
77635
}
77636
}
77637
}else{
77638
rc = fillInCell(pPage, newCell, pX, &szNew);
77639
+ if( rc ) goto end_insert;
77640
}
77324
- if( rc ) goto end_insert;
77641
assert( szNew==pPage->xCellSize(pPage, newCell) );
77326
- assert( szNew <= MX_CELL_SIZE(pBt) );
77642
+ assert( szNew <= MX_CELL_SIZE(p->pBt) );
77643
idx = pCur->ix;
77644
+ pCur->info.nSize = 0;
77645
if( loc==0 ){
77646
CellInfo info;
77647
assert( idx>=0 );
@@ -77343,7 +77660,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77660
testcase( pCur->curFlags & BTCF_ValidOvfl );
77661
invalidateOverflowCache(pCur);
77662
if( info.nSize==szNew && info.nLocal==info.nPayload
77346
- && (!ISAUTOVACUUM || szNew<pPage->minLocal)
77663
+ && (!ISAUTOVACUUM(p->pBt) || szNew<pPage->minLocal)
77664
){
77665
/* Overwrite the old cell with the new if they are the same size.
77666
** We could also try to do this if the old cell is smaller, then add
@@ -77373,7 +77690,7 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77690
}else{
77691
assert( pPage->leaf );
77692
}
77376
- insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
77693
+ rc = insertCell(pPage, idx, newCell, szNew, 0, 0);
77694
assert( pPage->nOverflow==0 || rc==SQLITE_OK );
77695
assert( rc!=SQLITE_OK || pPage->nCell>0 || pPage->nOverflow>0 );
77696
@@ -77397,7 +77714,6 @@ SQLITE_PRIVATE int sqlite3BtreeInsert(
77714
** larger than the largest existing key, it is possible to insert the
77715
** row without seeking the cursor. This can be a big performance boost.
77716
*/
77400
- pCur->info.nSize = 0;
77717
if( pPage->nOverflow ){
77718
assert( rc==SQLITE_OK );
77719
pCur->curFlags &= ~(BTCF_ValidNKey);
@@ -77446,7 +77762,6 @@ end_insert:
77762
** SQLITE_OK is returned if successful, or an SQLite error code otherwise.
77763
*/
77764
SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64 iKey){
77449
- int rc = SQLITE_OK;
77765
BtShared *pBt = pDest->pBt;
77766
u8 *aOut = pBt->pTmpSpace; /* Pointer to next output buffer */
77767
const u8 *aIn; /* Pointer to next input buffer */
@@ -77469,7 +77784,9 @@ SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64
77784
if( nIn==nRem && nIn<pDest->pPage->maxLocal ){
77785
memcpy(aOut, aIn, nIn);
77786
pBt->nPreformatSize = nIn + (aOut - pBt->pTmpSpace);
77787
+ return SQLITE_OK;
77788
}else{
77789
+ int rc = SQLITE_OK;
77790
Pager *pSrcPager = pSrc->pBt->pPager;
77791
u8 *pPgnoOut = 0;
77792
Pgno ovflIn = 0;
@@ -77521,7 +77838,7 @@ SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64
77838
MemPage *pNew = 0;
77839
rc = allocateBtreePage(pBt, &pNew, &pgnoNew, 0, 0);
77840
put4byte(pPgnoOut, pgnoNew);
77524
- if( ISAUTOVACUUM && pPageOut ){
77841
+ if( ISAUTOVACUUM(pBt) && pPageOut ){
77842
ptrmapPut(pBt, pgnoNew, PTRMAP_OVERFLOW2, pPageOut->pgno, &rc);
77843
}
77844
releasePage(pPageOut);
@@ -77537,9 +77854,8 @@ SQLITE_PRIVATE int sqlite3BtreeTransferRow(BtCursor *pDest, BtCursor *pSrc, i64
77854
77855
releasePage(pPageOut);
77856
sqlite3PagerUnref(pPageIn);
77857
+ return rc;
77858
}
77541
-
77542
- return rc;
77859
}
77860
77861
/*
@@ -77694,7 +78010,7 @@ SQLITE_PRIVATE int sqlite3BtreeDelete(BtCursor *pCur, u8 flags){
78010
assert( pTmp!=0 );
78011
rc = sqlite3PagerWrite(pLeaf->pDbPage);
78012
if( rc==SQLITE_OK ){
77697
- insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n, &rc);
78013
+ rc = insertCell(pPage, iCellIdx, pCell-4, nCell+4, pTmp, n);
78014
}
78015
dropCell(pLeaf, pLeaf->nCell-1, nCell, &rc);
78016
if( rc ) return rc;
@@ -78293,6 +78609,41 @@ SQLITE_PRIVATE Pager *sqlite3BtreePager(Btree *p){
78609
}
78610
78611
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
78612
+/*
78613
+** Record an OOM error during integrity_check
78614
+*/
78615
+static void checkOom(IntegrityCk *pCheck){
78616
+ pCheck->rc = SQLITE_NOMEM;
78617
+ pCheck->mxErr = 0; /* Causes integrity_check processing to stop */
78618
+ if( pCheck->nErr==0 ) pCheck->nErr++;
78619
+}
78620
+
78621
+/*
78622
+** Invoke the progress handler, if appropriate. Also check for an
78623
+** interrupt.
78624
+*/
78625
+static void checkProgress(IntegrityCk *pCheck){
78626
+ sqlite3 *db = pCheck->db;
78627
+ if( AtomicLoad(&db->u1.isInterrupted) ){
78628
+ pCheck->rc = SQLITE_INTERRUPT;
78629
+ pCheck->nErr++;
78630
+ pCheck->mxErr = 0;
78631
+ }
78632
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
78633
+ if( db->xProgress ){
78634
+ assert( db->nProgressOps>0 );
78635
+ pCheck->nStep++;
78636
+ if( (pCheck->nStep % db->nProgressOps)==0
78637
+ && db->xProgress(db->pProgressArg)
78638
+ ){
78639
+ pCheck->rc = SQLITE_INTERRUPT;
78640
+ pCheck->nErr++;
78641
+ pCheck->mxErr = 0;
78642
+ }
78643
+ }
78644
+#endif
78645
+}
78646
+
78647
/*
78648
** Append a message to the error message string.
78649
*/
@@ -78302,6 +78653,7 @@ static void checkAppendMsg(
78653
...
78654
){
78655
va_list ap;
78656
+ checkProgress(pCheck);
78657
if( !pCheck->mxErr ) return;
78658
pCheck->mxErr--;
78659
pCheck->nErr++;
@@ -78315,7 +78667,7 @@ static void checkAppendMsg(
78667
sqlite3_str_vappendf(&pCheck->errMsg, zFormat, ap);
78668
va_end(ap);
78669
if( pCheck->errMsg.accError==SQLITE_NOMEM ){
78318
- pCheck->bOomFault = 1;
78670
+ checkOom(pCheck);
78671
}
78672
}
78673
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
@@ -78357,7 +78709,6 @@ static int checkRef(IntegrityCk *pCheck, Pgno iPage){
78709
checkAppendMsg(pCheck, "2nd reference to page %d", iPage);
78710
return 1;
78711
}
78360
- if( AtomicLoad(&pCheck->db->u1.isInterrupted) ) return 1;
78712
setPageReferenced(pCheck, iPage);
78713
return 0;
78714
}
@@ -78380,7 +78731,7 @@ static void checkPtrmap(
78731
78732
rc = ptrmapGet(pCheck->pBt, iChild, &ePtrmapType, &iPtrmapParent);
78733
if( rc!=SQLITE_OK ){
78383
- if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) pCheck->bOomFault = 1;
78734
+ if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ) checkOom(pCheck);
78735
checkAppendMsg(pCheck, "Failed to read ptrmap key=%d", iChild);
78736
return;
78737
}
@@ -78487,7 +78838,9 @@ static void checkList(
78838
** lower 16 bits are the index of the last byte of that range.
78839
*/
78840
static void btreeHeapInsert(u32 *aHeap, u32 x){
78490
- u32 j, i = ++aHeap[0];
78841
+ u32 j, i;
78842
+ assert( aHeap!=0 );
78843
+ i = ++aHeap[0];
78844
aHeap[i] = x;
78845
while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){
78846
x = aHeap[j];
@@ -78564,6 +78917,8 @@ static int checkTreePage(
78917
78918
/* Check that the page exists
78919
*/
78920
+ checkProgress(pCheck);
78921
+ if( pCheck->mxErr==0 ) goto end_of_check;
78922
pBt = pCheck->pBt;
78923
usableSize = pBt->usableSize;
78924
if( iPage==0 ) return 0;
@@ -78809,13 +79164,14 @@ end_of_check:
79164
** the unverified btrees. Except, if aRoot[1] is 1, then the freelist
79165
** checks are still performed.
79166
*/
78812
-SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
79167
+SQLITE_PRIVATE int sqlite3BtreeIntegrityCheck(
79168
sqlite3 *db, /* Database connection that is running the check */
79169
Btree *p, /* The btree to be checked */
79170
Pgno *aRoot, /* An array of root pages numbers for individual trees */
79171
int nRoot, /* Number of entries in aRoot[] */
79172
int mxErr, /* Stop reporting errors after this many */
78818
- int *pnErr /* Write number of errors seen to this variable */
79173
+ int *pnErr, /* OUT: Write number of errors seen to this variable */
79174
+ char **pzOut /* OUT: Write the error message string here */
79175
){
79176
Pgno i;
79177
IntegrityCk sCheck;
@@ -78838,18 +79194,12 @@ SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
79194
assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
79195
VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
79196
assert( nRef>=0 );
79197
+ memset(&sCheck, 0, sizeof(sCheck));
79198
sCheck.db = db;
79199
sCheck.pBt = pBt;
79200
sCheck.pPager = pBt->pPager;
79201
sCheck.nPage = btreePagecount(sCheck.pBt);
79202
sCheck.mxErr = mxErr;
78846
- sCheck.nErr = 0;
78847
- sCheck.bOomFault = 0;
78848
- sCheck.zPfx = 0;
78849
- sCheck.v1 = 0;
78850
- sCheck.v2 = 0;
78851
- sCheck.aPgRef = 0;
78852
- sCheck.heap = 0;
79203
sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
79204
sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL;
79205
if( sCheck.nPage==0 ){
@@ -78858,12 +79208,12 @@ SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
79208
79209
sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1);
79210
if( !sCheck.aPgRef ){
78861
- sCheck.bOomFault = 1;
79211
+ checkOom(&sCheck);
79212
goto integrity_ck_cleanup;
79213
}
79214
sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
79215
if( sCheck.heap==0 ){
78866
- sCheck.bOomFault = 1;
79216
+ checkOom(&sCheck);
79217
goto integrity_ck_cleanup;
79218
}
79219
@@ -78944,16 +79294,17 @@ SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
79294
integrity_ck_cleanup:
79295
sqlite3PageFree(sCheck.heap);
79296
sqlite3_free(sCheck.aPgRef);
78947
- if( sCheck.bOomFault ){
79297
+ *pnErr = sCheck.nErr;
79298
+ if( sCheck.nErr==0 ){
79299
sqlite3_str_reset(&sCheck.errMsg);
78949
- sCheck.nErr++;
79300
+ *pzOut = 0;
79301
+ }else{
79302
+ *pzOut = sqlite3StrAccumFinish(&sCheck.errMsg);
79303
}
78951
- *pnErr = sCheck.nErr;
78952
- if( sCheck.nErr==0 ) sqlite3_str_reset(&sCheck.errMsg);
79304
/* Make sure this analysis did not leave any unref() pages. */
79305
assert( nRef==sqlite3PagerRefcount(pBt->pPager) );
79306
sqlite3BtreeLeave(p);
78956
- return sqlite3StrAccumFinish(&sCheck.errMsg);
79307
+ return sCheck.rc;
79308
}
79309
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
79310
@@ -80139,9 +80490,9 @@ static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){
80490
i64 x;
80491
assert( (p->flags&MEM_Int)*2==sizeof(x) );
80492
memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2);
80142
- sqlite3Int64ToText(x, zBuf);
80493
+ p->n = sqlite3Int64ToText(x, zBuf);
80494
#else
80144
- sqlite3Int64ToText(p->u.i, zBuf);
80495
+ p->n = sqlite3Int64ToText(p->u.i, zBuf);
80496
#endif
80497
}else{
80498
sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0);
@@ -80149,6 +80500,7 @@ static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){
80500
(p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r);
80501
assert( acc.zText==zBuf && acc.mxAlloc<=0 );
80502
zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */
80503
+ p->n = acc.nChar;
80504
}
80505
}
80506
@@ -80176,6 +80528,7 @@ static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){
80528
** This routine is for use inside of assert() statements only.
80529
*/
80530
SQLITE_PRIVATE int sqlite3VdbeMemValidStrRep(Mem *p){
80531
+ Mem tmp;
80532
char zBuf[100];
80533
char *z;
80534
int i, j, incr;
@@ -80192,7 +80545,8 @@ SQLITE_PRIVATE int sqlite3VdbeMemValidStrRep(Mem *p){
80545
assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 );
80546
}
80547
if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1;
80195
- vdbeMemRenderNum(sizeof(zBuf), zBuf, p);
80548
+ memcpy(&tmp, p, sizeof(tmp));
80549
+ vdbeMemRenderNum(sizeof(zBuf), zBuf, &tmp);
80550
z = p->z;
80551
i = j = 0;
80552
incr = 1;
@@ -80461,7 +80815,7 @@ SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){
80815
80816
vdbeMemRenderNum(nByte, pMem->z, pMem);
80817
assert( pMem->z!=0 );
80464
- pMem->n = sqlite3Strlen30NN(pMem->z);
80818
+ assert( pMem->n==sqlite3Strlen30NN(pMem->z) );
80819
pMem->enc = SQLITE_UTF8;
80820
pMem->flags |= MEM_Str|MEM_Term;
80821
if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
@@ -80701,32 +81055,35 @@ SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem *pMem, int ifNull){
81055
}
81056
81057
/*
80704
-** The MEM structure is already a MEM_Real. Try to also make it a
80705
-** MEM_Int if we can.
81058
+** The MEM structure is already a MEM_Real or MEM_IntReal. Try to
81059
+** make it a MEM_Int if we can.
81060
*/
81061
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
80708
- i64 ix;
81062
assert( pMem!=0 );
80710
- assert( pMem->flags & MEM_Real );
81063
+ assert( pMem->flags & (MEM_Real|MEM_IntReal) );
81064
assert( !sqlite3VdbeMemIsRowSet(pMem) );
81065
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81066
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
81067
80715
- ix = doubleToInt64(pMem->u.r);
80716
-
80717
- /* Only mark the value as an integer if
80718
- **
80719
- ** (1) the round-trip conversion real->int->real is a no-op, and
80720
- ** (2) The integer is neither the largest nor the smallest
80721
- ** possible integer (ticket #3922)
80722
- **
80723
- ** The second and third terms in the following conditional enforces
80724
- ** the second condition under the assumption that addition overflow causes
80725
- ** values to wrap around.
80726
- */
80727
- if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
80728
- pMem->u.i = ix;
81068
+ if( pMem->flags & MEM_IntReal ){
81069
MemSetTypeFlag(pMem, MEM_Int);
81070
+ }else{
81071
+ i64 ix = doubleToInt64(pMem->u.r);
81072
+
81073
+ /* Only mark the value as an integer if
81074
+ **
81075
+ ** (1) the round-trip conversion real->int->real is a no-op, and
81076
+ ** (2) The integer is neither the largest nor the smallest
81077
+ ** possible integer (ticket #3922)
81078
+ **
81079
+ ** The second and third terms in the following conditional enforces
81080
+ ** the second condition under the assumption that addition overflow causes
81081
+ ** values to wrap around.
81082
+ */
81083
+ if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
81084
+ pMem->u.i = ix;
81085
+ MemSetTypeFlag(pMem, MEM_Int);
81086
+ }
81087
}
81088
}
81089
@@ -81527,8 +81884,6 @@ static int valueFromFunction(
81884
goto value_from_function_out;
81885
}
81886
81530
- testcase( pCtx->pParse->rc==SQLITE_ERROR );
81531
- testcase( pCtx->pParse->rc==SQLITE_OK );
81887
memset(&ctx, 0, sizeof(ctx));
81888
ctx.pOut = pVal;
81889
ctx.pFunc = pFunc;
@@ -81540,17 +81895,22 @@ static int valueFromFunction(
81895
}else{
81896
sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8);
81897
assert( rc==SQLITE_OK );
81898
+ assert( enc==pVal->enc
81899
+ || (pVal->flags & MEM_Str)==0
81900
+ || db->mallocFailed );
81901
+#if 0 /* Not reachable except after a prior failure */
81902
rc = sqlite3VdbeChangeEncoding(pVal, enc);
81903
if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){
81904
rc = SQLITE_TOOBIG;
81905
pCtx->pParse->nErr++;
81906
}
81907
+#endif
81908
}
81549
- pCtx->pParse->rc = rc;
81909
81910
value_from_function_out:
81911
if( rc!=SQLITE_OK ){
81912
pVal = 0;
81913
+ pCtx->pParse->rc = rc;
81914
}
81915
if( apVal ){
81916
for(i=0; i<nVal; i++){
@@ -82223,6 +82583,8 @@ static int growOpArray(Vdbe *v, int nOp){
82583
*/
82584
static void test_addop_breakpoint(int pc, Op *pOp){
82585
static int n = 0;
82586
+ (void)pc;
82587
+ (void)pOp;
82588
n++;
82589
}
82590
#endif
@@ -82273,16 +82635,16 @@ SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe *p, int op, int p1, int p2, int p3){
82635
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
82636
pOp->zComment = 0;
82637
#endif
82638
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
82639
+ pOp->nExec = 0;
82640
+ pOp->nCycle = 0;
82641
+#endif
82642
#ifdef SQLITE_DEBUG
82643
if( p->db->flags & SQLITE_VdbeAddopTrace ){
82644
sqlite3VdbePrintOp(0, i, &p->aOp[i]);
82645
test_addop_breakpoint(i, &p->aOp[i]);
82646
}
82647
#endif
82282
-#ifdef VDBE_PROFILE
82283
- pOp->cycles = 0;
82284
- pOp->cnt = 0;
82285
-#endif
82648
#ifdef SQLITE_VDBE_COVERAGE
82649
pOp->iSrcLine = 0;
82650
#endif
@@ -82450,8 +82812,9 @@ SQLITE_PRIVATE void sqlite3ExplainBreakpoint(const char *z1, const char *z2){
82812
** If the bPush flag is true, then make this opcode the parent for
82813
** subsequent Explains until sqlite3VdbeExplainPop() is called.
82814
*/
82453
-SQLITE_PRIVATE void sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){
82454
-#ifndef SQLITE_DEBUG
82815
+SQLITE_PRIVATE int sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){
82816
+ int addr = 0;
82817
+#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
82818
/* Always include the OP_Explain opcodes if SQLITE_DEBUG is defined.
82819
** But omit them (for performance) during production builds */
82820
if( pParse->explain==2 )
@@ -82466,13 +82829,15 @@ SQLITE_PRIVATE void sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt
82829
va_end(ap);
82830
v = pParse->pVdbe;
82831
iThis = v->nOp;
82469
- sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
82832
+ addr = sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
82833
zMsg, P4_DYNAMIC);
82834
sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetLastOp(v)->p4.z);
82835
if( bPush){
82836
pParse->addrExplain = iThis;
82837
}
82838
+ sqlite3VdbeScanStatus(v, iThis, 0, 0, 0, 0);
82839
}
82840
+ return addr;
82841
}
82842
82843
/*
@@ -82580,6 +82945,9 @@ static SQLITE_NOINLINE void resizeResolveLabel(Parse *p, Vdbe *v, int j){
82945
int i;
82946
for(i=p->nLabelAlloc; i<nNewSize; i++) p->aLabel[i] = -1;
82947
#endif
82948
+ if( nNewSize>=100 && (nNewSize/100)>(p->nLabelAlloc/100) ){
82949
+ sqlite3ProgressCheck(p);
82950
+ }
82951
p->nLabelAlloc = nNewSize;
82952
p->aLabel[j] = v->nOp;
82953
}
@@ -83130,6 +83498,7 @@ SQLITE_PRIVATE void sqlite3VdbeScanStatus(
83498
aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
83499
if( aNew ){
83500
ScanStatus *pNew = &aNew[p->nScan++];
83501
+ memset(pNew, 0, sizeof(ScanStatus));
83502
pNew->addrExplain = addrExplain;
83503
pNew->addrLoop = addrLoop;
83504
pNew->addrVisit = addrVisit;
@@ -83138,6 +83507,62 @@ SQLITE_PRIVATE void sqlite3VdbeScanStatus(
83507
p->aScan = aNew;
83508
}
83509
}
83510
+
83511
+/*
83512
+** Add the range of instructions from addrStart to addrEnd (inclusive) to
83513
+** the set of those corresponding to the sqlite3_stmt_scanstatus() counters
83514
+** associated with the OP_Explain instruction at addrExplain. The
83515
+** sum of the sqlite3Hwtime() values for each of these instructions
83516
+** will be returned for SQLITE_SCANSTAT_NCYCLE requests.
83517
+*/
83518
+SQLITE_PRIVATE void sqlite3VdbeScanStatusRange(
83519
+ Vdbe *p,
83520
+ int addrExplain,
83521
+ int addrStart,
83522
+ int addrEnd
83523
+){
83524
+ ScanStatus *pScan = 0;
83525
+ int ii;
83526
+ for(ii=p->nScan-1; ii>=0; ii--){
83527
+ pScan = &p->aScan[ii];
83528
+ if( pScan->addrExplain==addrExplain ) break;
83529
+ pScan = 0;
83530
+ }
83531
+ if( pScan ){
83532
+ if( addrEnd<0 ) addrEnd = sqlite3VdbeCurrentAddr(p)-1;
83533
+ for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
83534
+ if( pScan->aAddrRange[ii]==0 ){
83535
+ pScan->aAddrRange[ii] = addrStart;
83536
+ pScan->aAddrRange[ii+1] = addrEnd;
83537
+ break;
83538
+ }
83539
+ }
83540
+ }
83541
+}
83542
+
83543
+/*
83544
+** Set the addresses for the SQLITE_SCANSTAT_NLOOP and SQLITE_SCANSTAT_NROW
83545
+** counters for the query element associated with the OP_Explain at
83546
+** addrExplain.
83547
+*/
83548
+SQLITE_PRIVATE void sqlite3VdbeScanStatusCounters(
83549
+ Vdbe *p,
83550
+ int addrExplain,
83551
+ int addrLoop,
83552
+ int addrVisit
83553
+){
83554
+ ScanStatus *pScan = 0;
83555
+ int ii;
83556
+ for(ii=p->nScan-1; ii>=0; ii--){
83557
+ pScan = &p->aScan[ii];
83558
+ if( pScan->addrExplain==addrExplain ) break;
83559
+ pScan = 0;
83560
+ }
83561
+ if( pScan ){
83562
+ pScan->addrLoop = addrLoop;
83563
+ pScan->addrVisit = addrVisit;
83564
+ }
83565
+}
83566
#endif
83567
83568
@@ -84267,7 +84692,6 @@ SQLITE_PRIVATE int sqlite3VdbeList(
84692
** sqlite3_column_text16(), causing a translation to UTF-16 encoding.
84693
*/
84694
releaseMemArray(pMem, 8);
84270
- p->pResultSet = 0;
84695
84696
if( p->rc==SQLITE_NOMEM ){
84697
/* This happens if a malloc() inside a call to sqlite3_column_text() or
@@ -84324,7 +84748,7 @@ SQLITE_PRIVATE int sqlite3VdbeList(
84748
sqlite3VdbeMemSetStr(pMem+5, zP4, -1, SQLITE_UTF8, sqlite3_free);
84749
p->nResColumn = 8;
84750
}
84327
- p->pResultSet = pMem;
84751
+ p->pResultRow = pMem;
84752
if( db->mallocFailed ){
84753
p->rc = SQLITE_NOMEM;
84754
rc = SQLITE_ERROR;
@@ -84435,7 +84859,7 @@ static void *allocSpace(
84859
** running it.
84860
*/
84861
SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
84438
-#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
84862
+#if defined(SQLITE_DEBUG)
84863
int i;
84864
#endif
84865
assert( p!=0 );
@@ -84464,8 +84888,8 @@ SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
84888
p->nFkConstraint = 0;
84889
#ifdef VDBE_PROFILE
84890
for(i=0; i<p->nOp; i++){
84467
- p->aOp[i].cnt = 0;
84468
- p->aOp[i].cycles = 0;
84891
+ p->aOp[i].nExec = 0;
84892
+ p->aOp[i].nCycle = 0;
84893
}
84894
#endif
84895
}
@@ -84574,9 +84998,6 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
84998
p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
84999
p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
85000
p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
84577
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84578
- p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
84579
-#endif
85001
if( x.nNeeded ){
85002
x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
85003
x.nFree = x.nNeeded;
@@ -84585,9 +85006,6 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
85006
p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
85007
p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
85008
p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
84588
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84589
- p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
84590
-#endif
85009
}
85010
}
85011
@@ -84602,9 +85020,6 @@ SQLITE_PRIVATE void sqlite3VdbeMakeReady(
85020
p->nMem = nMem;
85021
initMemArray(p->aMem, nMem, db, MEM_Undefined);
85022
memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
84605
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84606
- memset(p->anExec, 0, p->nOp*sizeof(i64));
84607
-#endif
85023
}
85024
sqlite3VdbeRewind(p);
85025
}
@@ -84662,9 +85077,6 @@ static void closeCursorsInFrame(Vdbe *p){
85077
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
85078
Vdbe *v = pFrame->v;
85079
closeCursorsInFrame(v);
84665
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84666
- v->anExec = pFrame->anExec;
84667
-#endif
85080
v->aOp = pFrame->aOp;
85081
v->nOp = pFrame->nOp;
85082
v->aMem = pFrame->aMem;
@@ -85468,7 +85880,7 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
85880
sqlite3DbFree(db, p->zErrMsg);
85881
p->zErrMsg = 0;
85882
}
85471
- p->pResultSet = 0;
85883
+ p->pResultRow = 0;
85884
#ifdef SQLITE_DEBUG
85885
p->nWrite = 0;
85886
#endif
@@ -85496,10 +85908,12 @@ SQLITE_PRIVATE int sqlite3VdbeReset(Vdbe *p){
85908
}
85909
for(i=0; i<p->nOp; i++){
85910
char zHdr[100];
85911
+ i64 cnt = p->aOp[i].nExec;
85912
+ i64 cycles = p->aOp[i].nCycle;
85913
sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
85500
- p->aOp[i].cnt,
85501
- p->aOp[i].cycles,
85502
- p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
85914
+ cnt,
85915
+ cycles,
85916
+ cnt>0 ? cycles/cnt : 0
85917
);
85918
fprintf(out, "%s", zHdr);
85919
sqlite3VdbePrintOp(out, i, &p->aOp[i]);
@@ -87354,6 +87768,7 @@ SQLITE_PRIVATE void sqlite3VdbePreUpdateHook(
87768
*/
87769
/* #include "sqliteInt.h" */
87770
/* #include "vdbeInt.h" */
87771
+/* #include "opcodes.h" */
87772
87773
#ifndef SQLITE_OMIT_DEPRECATED
87774
/*
@@ -87844,7 +88259,10 @@ SQLITE_API void sqlite3_result_text64(
88259
){
88260
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
88261
assert( xDel!=SQLITE_DYNAMIC );
87847
- if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
88262
+ if( enc!=SQLITE_UTF8 ){
88263
+ if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
88264
+ n &= ~(u64)1;
88265
+ }
88266
if( n>0x7fffffff ){
88267
(void)invokeValueDestructor(z, xDel, pCtx);
88268
}else{
@@ -87859,7 +88277,7 @@ SQLITE_API void sqlite3_result_text16(
88277
void (*xDel)(void *)
88278
){
88279
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
87862
- setResultStrOrError(pCtx, z, n, SQLITE_UTF16NATIVE, xDel);
88280
+ setResultStrOrError(pCtx, z, n & ~(u64)1, SQLITE_UTF16NATIVE, xDel);
88281
}
88282
SQLITE_API void sqlite3_result_text16be(
88283
sqlite3_context *pCtx,
@@ -87868,7 +88286,7 @@ SQLITE_API void sqlite3_result_text16be(
88286
void (*xDel)(void *)
88287
){
88288
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
87871
- setResultStrOrError(pCtx, z, n, SQLITE_UTF16BE, xDel);
88289
+ setResultStrOrError(pCtx, z, n & ~(u64)1, SQLITE_UTF16BE, xDel);
88290
}
88291
SQLITE_API void sqlite3_result_text16le(
88292
sqlite3_context *pCtx,
@@ -87877,7 +88295,7 @@ SQLITE_API void sqlite3_result_text16le(
88295
void (*xDel)(void *)
88296
){
88297
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
87880
- setResultStrOrError(pCtx, z, n, SQLITE_UTF16LE, xDel);
88298
+ setResultStrOrError(pCtx, z, n & ~(u64)1, SQLITE_UTF16LE, xDel);
88299
}
88300
#endif /* SQLITE_OMIT_UTF16 */
88301
SQLITE_API void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
@@ -88088,7 +88506,7 @@ static int sqlite3Step(Vdbe *p){
88506
/* If the statement completed successfully, invoke the profile callback */
88507
checkProfileCallback(db, p);
88508
#endif
88091
-
88509
+ p->pResultRow = 0;
88510
if( rc==SQLITE_DONE && db->autoCommit ){
88511
assert( p->rc==SQLITE_OK );
88512
p->rc = doWalCallbacks(db);
@@ -88217,6 +88635,17 @@ SQLITE_API int sqlite3_vtab_nochange(sqlite3_context *p){
88635
return sqlite3_value_nochange(p->pOut);
88636
}
88637
88638
+/*
88639
+** The destructor function for a ValueList object. This needs to be
88640
+** a separate function, unknowable to the application, to ensure that
88641
+** calls to sqlite3_vtab_in_first()/sqlite3_vtab_in_next() that are not
88642
+** preceeded by activation of IN processing via sqlite3_vtab_int() do not
88643
+** try to access a fake ValueList object inserted by a hostile extension.
88644
+*/
88645
+SQLITE_PRIVATE void sqlite3VdbeValueListFree(void *pToDelete){
88646
+ sqlite3_free(pToDelete);
88647
+}
88648
+
88649
/*
88650
** Implementation of sqlite3_vtab_in_first() (if bNext==0) and
88651
** sqlite3_vtab_in_next() (if bNext!=0).
@@ -88231,8 +88660,15 @@ static int valueFromValueList(
88660
88661
*ppOut = 0;
88662
if( pVal==0 ) return SQLITE_MISUSE;
88234
- pRhs = (ValueList*)sqlite3_value_pointer(pVal, "ValueList");
88235
- if( pRhs==0 ) return SQLITE_MISUSE;
88663
+ if( (pVal->flags & MEM_Dyn)==0 || pVal->xDel!=sqlite3VdbeValueListFree ){
88664
+ return SQLITE_ERROR;
88665
+ }else{
88666
+ assert( (pVal->flags&(MEM_TypeMask|MEM_Term|MEM_Subtype)) ==
88667
+ (MEM_Null|MEM_Term|MEM_Subtype) );
88668
+ assert( pVal->eSubtype=='p' );
88669
+ assert( pVal->u.zPType!=0 && strcmp(pVal->u.zPType,"ValueList")==0 );
88670
+ pRhs = (ValueList*)pVal->z;
88671
+ }
88672
if( bNext ){
88673
rc = sqlite3BtreeNext(pRhs->pCsr, 0);
88674
}else{
@@ -88452,7 +88888,7 @@ SQLITE_API int sqlite3_column_count(sqlite3_stmt *pStmt){
88888
*/
88889
SQLITE_API int sqlite3_data_count(sqlite3_stmt *pStmt){
88890
Vdbe *pVm = (Vdbe *)pStmt;
88455
- if( pVm==0 || pVm->pResultSet==0 ) return 0;
88891
+ if( pVm==0 || pVm->pResultRow==0 ) return 0;
88892
return pVm->nResColumn;
88893
}
88894
@@ -88507,8 +88943,8 @@ static Mem *columnMem(sqlite3_stmt *pStmt, int i){
88943
if( pVm==0 ) return (Mem*)columnNullValue();
88944
assert( pVm->db );
88945
sqlite3_mutex_enter(pVm->db->mutex);
88510
- if( pVm->pResultSet!=0 && i<pVm->nResColumn && i>=0 ){
88511
- pOut = &pVm->pResultSet[i];
88946
+ if( pVm->pResultRow!=0 && i<pVm->nResColumn && i>=0 ){
88947
+ pOut = &pVm->pResultRow[i];
88948
}else{
88949
sqlite3Error(pVm->db, SQLITE_RANGE);
88950
pOut = (Mem*)columnNullValue();
@@ -88942,7 +89378,10 @@ SQLITE_API int sqlite3_bind_text64(
89378
unsigned char enc
89379
){
89380
assert( xDel!=SQLITE_DYNAMIC );
88945
- if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
89381
+ if( enc!=SQLITE_UTF8 ){
89382
+ if( enc==SQLITE_UTF16 ) enc = SQLITE_UTF16NATIVE;
89383
+ nData &= ~(u16)1;
89384
+ }
89385
return bindText(pStmt, i, zData, nData, xDel, enc);
89386
}
89387
#ifndef SQLITE_OMIT_UTF16
@@ -88950,10 +89389,10 @@ SQLITE_API int sqlite3_bind_text16(
89389
sqlite3_stmt *pStmt,
89390
int i,
89391
const void *zData,
88953
- int nData,
89392
+ int n,
89393
void (*xDel)(void*)
89394
){
88956
- return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
89395
+ return bindText(pStmt, i, zData, n & ~(u64)1, xDel, SQLITE_UTF16NATIVE);
89396
}
89397
#endif /* SQLITE_OMIT_UTF16 */
89398
SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
@@ -89444,23 +89883,60 @@ SQLITE_API int sqlite3_preupdate_new(sqlite3 *db, int iIdx, sqlite3_value **ppVa
89883
/*
89884
** Return status data for a single loop within query pStmt.
89885
*/
89447
-SQLITE_API int sqlite3_stmt_scanstatus(
89886
+SQLITE_API int sqlite3_stmt_scanstatus_v2(
89887
sqlite3_stmt *pStmt, /* Prepared statement being queried */
89449
- int idx, /* Index of loop to report on */
89888
+ int iScan, /* Index of loop to report on */
89889
int iScanStatusOp, /* Which metric to return */
89890
+ int flags,
89891
void *pOut /* OUT: Write the answer here */
89892
){
89893
Vdbe *p = (Vdbe*)pStmt;
89894
ScanStatus *pScan;
89455
- if( idx<0 || idx>=p->nScan ) return 1;
89456
- pScan = &p->aScan[idx];
89895
+ int idx;
89896
+
89897
+ if( iScan<0 ){
89898
+ int ii;
89899
+ if( iScanStatusOp==SQLITE_SCANSTAT_NCYCLE ){
89900
+ i64 res = 0;
89901
+ for(ii=0; ii<p->nOp; ii++){
89902
+ res += p->aOp[ii].nCycle;
89903
+ }
89904
+ *(i64*)pOut = res;
89905
+ return 0;
89906
+ }
89907
+ return 1;
89908
+ }
89909
+ if( flags & SQLITE_SCANSTAT_COMPLEX ){
89910
+ idx = iScan;
89911
+ pScan = &p->aScan[idx];
89912
+ }else{
89913
+ /* If the COMPLEX flag is clear, then this function must ignore any
89914
+ ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
89915
+ for(idx=0; idx<p->nScan; idx++){
89916
+ pScan = &p->aScan[idx];
89917
+ if( pScan->zName ){
89918
+ iScan--;
89919
+ if( iScan<0 ) break;
89920
+ }
89921
+ }
89922
+ }
89923
+ if( idx>=p->nScan ) return 1;
89924
+
89925
switch( iScanStatusOp ){
89926
case SQLITE_SCANSTAT_NLOOP: {
89459
- *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop];
89927
+ if( pScan->addrLoop>0 ){
89928
+ *(sqlite3_int64*)pOut = p->aOp[pScan->addrLoop].nExec;
89929
+ }else{
89930
+ *(sqlite3_int64*)pOut = -1;
89931
+ }
89932
break;
89933
}
89934
case SQLITE_SCANSTAT_NVISIT: {
89463
- *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit];
89935
+ if( pScan->addrVisit>0 ){
89936
+ *(sqlite3_int64*)pOut = p->aOp[pScan->addrVisit].nExec;
89937
+ }else{
89938
+ *(sqlite3_int64*)pOut = -1;
89939
+ }
89940
break;
89941
}
89942
case SQLITE_SCANSTAT_EST: {
@@ -89493,6 +89969,45 @@ SQLITE_API int sqlite3_stmt_scanstatus(
89969
}
89970
break;
89971
}
89972
+ case SQLITE_SCANSTAT_PARENTID: {
89973
+ if( pScan->addrExplain ){
89974
+ *(int*)pOut = p->aOp[ pScan->addrExplain ].p2;
89975
+ }else{
89976
+ *(int*)pOut = -1;
89977
+ }
89978
+ break;
89979
+ }
89980
+ case SQLITE_SCANSTAT_NCYCLE: {
89981
+ i64 res = 0;
89982
+ if( pScan->aAddrRange[0]==0 ){
89983
+ res = -1;
89984
+ }else{
89985
+ int ii;
89986
+ for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
89987
+ int iIns = pScan->aAddrRange[ii];
89988
+ int iEnd = pScan->aAddrRange[ii+1];
89989
+ if( iIns==0 ) break;
89990
+ if( iIns>0 ){
89991
+ while( iIns<=iEnd ){
89992
+ res += p->aOp[iIns].nCycle;
89993
+ iIns++;
89994
+ }
89995
+ }else{
89996
+ int iOp;
89997
+ for(iOp=0; iOp<p->nOp; iOp++){
89998
+ Op *pOp = &p->aOp[iOp];
89999
+ if( pOp->p1!=iEnd ) continue;
90000
+ if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_NCYCLE)==0 ){
90001
+ continue;
90002
+ }
90003
+ res += p->aOp[iOp].nCycle;
90004
+ }
90005
+ }
90006
+ }
90007
+ }
90008
+ *(i64*)pOut = res;
90009
+ break;
90010
+ }
90011
default: {
90012
return 1;
90013
}
@@ -89500,12 +90015,29 @@ SQLITE_API int sqlite3_stmt_scanstatus(
90015
return 0;
90016
}
90017
90018
+/*
90019
+** Return status data for a single loop within query pStmt.
90020
+*/
90021
+SQLITE_API int sqlite3_stmt_scanstatus(
90022
+ sqlite3_stmt *pStmt, /* Prepared statement being queried */
90023
+ int iScan, /* Index of loop to report on */
90024
+ int iScanStatusOp, /* Which metric to return */
90025
+ void *pOut /* OUT: Write the answer here */
90026
+){
90027
+ return sqlite3_stmt_scanstatus_v2(pStmt, iScan, iScanStatusOp, 0, pOut);
90028
+}
90029
+
90030
/*
90031
** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
90032
*/
90033
SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
90034
Vdbe *p = (Vdbe*)pStmt;
89508
- memset(p->anExec, 0, p->nOp * sizeof(i64));
90035
+ int ii;
90036
+ for(ii=0; ii<p->nOp; ii++){
90037
+ Op *pOp = &p->aOp[ii];
90038
+ pOp->nExec = 0;
90039
+ pOp->nCycle = 0;
90040
+ }
90041
}
90042
#endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
90043
@@ -89841,6 +90373,9 @@ SQLITE_API int sqlite3_found_count = 0;
90373
*/
90374
static void test_trace_breakpoint(int pc, Op *pOp, Vdbe *v){
90375
static int n = 0;
90376
+ (void)pc;
90377
+ (void)pOp;
90378
+ (void)v;
90379
n++;
90380
}
90381
#endif
@@ -90079,6 +90614,10 @@ static void applyNumericAffinity(Mem *pRec, int bTryForInt){
90614
** always preferred, even if the affinity is REAL, because
90615
** an integer representation is more space efficient on disk.
90616
**
90617
+** SQLITE_AFF_FLEXNUM:
90618
+** If the value is text, then try to convert it into a number of
90619
+** some kind (integer or real) but do not make any other changes.
90620
+**
90621
** SQLITE_AFF_TEXT:
90622
** Convert pRec to a text representation.
90623
**
@@ -90093,11 +90632,11 @@ static void applyAffinity(
90632
){
90633
if( affinity>=SQLITE_AFF_NUMERIC ){
90634
assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
90096
- || affinity==SQLITE_AFF_NUMERIC );
90635
+ || affinity==SQLITE_AFF_NUMERIC || affinity==SQLITE_AFF_FLEXNUM );
90636
if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
90098
- if( (pRec->flags & MEM_Real)==0 ){
90637
+ if( (pRec->flags & (MEM_Real|MEM_IntReal))==0 ){
90638
if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
90100
- }else{
90639
+ }else if( affinity<=SQLITE_AFF_REAL ){
90640
sqlite3VdbeIntegerAffinity(pRec);
90641
}
90642
}
@@ -90325,17 +90864,6 @@ SQLITE_PRIVATE void sqlite3VdbeRegisterDump(Vdbe *v){
90864
# define REGISTER_TRACE(R,M)
90865
#endif
90866
90328
-
90329
-#ifdef VDBE_PROFILE
90330
-
90331
-/*
90332
-** hwtime.h contains inline assembler code for implementing
90333
-** high-performance timing routines.
90334
-*/
90335
-/* #include "hwtime.h" */
90336
-
90337
-#endif
90338
-
90867
#ifndef NDEBUG
90868
/*
90869
** This function is only called from within an assert() expression. It
@@ -90395,8 +90923,7 @@ static u64 filterHash(const Mem *aMem, const Op *pOp){
90923
}else if( p->flags & MEM_Real ){
90924
h += sqlite3VdbeIntValue(p);
90925
}else if( p->flags & (MEM_Str|MEM_Blob) ){
90398
- h += p->n;
90399
- if( p->flags & MEM_Zero ) h += p->u.nZero;
90926
+ /* no-op */
90927
}
90928
}
90929
return h;
@@ -90425,11 +90952,10 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
90952
){
90953
Op *aOp = p->aOp; /* Copy of p->aOp */
90954
Op *pOp = aOp; /* Current operation */
90428
-#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
90429
- Op *pOrigOp; /* Value of pOp at the top of the loop */
90430
-#endif
90955
#ifdef SQLITE_DEBUG
90956
+ Op *pOrigOp; /* Value of pOp at the top of the loop */
90957
int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
90958
+ u8 iCompareIsInit = 0; /* iCompare is initialized */
90959
#endif
90960
int rc = SQLITE_OK; /* Value to return */
90961
sqlite3 *db = p->db; /* The database */
@@ -90445,13 +90971,15 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
90971
Mem *pIn2 = 0; /* 2nd input operand */
90972
Mem *pIn3 = 0; /* 3rd input operand */
90973
Mem *pOut = 0; /* Output operand */
90448
-#ifdef VDBE_PROFILE
90449
- u64 start; /* CPU clock count at start of opcode */
90974
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
90975
+ u64 *pnCycle = 0;
90976
#endif
90977
/*** INSERT STACK UNION HERE ***/
90978
90979
assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
90454
- sqlite3VdbeEnter(p);
90980
+ if( DbMaskNonZero(p->lockMask) ){
90981
+ sqlite3VdbeEnter(p);
90982
+ }
90983
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
90984
if( db->xProgress ){
90985
u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
@@ -90472,7 +91000,6 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
91000
assert( p->bIsReader || p->readOnly!=0 );
91001
p->iCurrentTime = 0;
91002
assert( p->explain==0 );
90475
- p->pResultSet = 0;
91003
db->busyHandler.nBusy = 0;
91004
if( AtomicLoad(&db->u1.isInterrupted) ) goto abort_due_to_interrupt;
91005
sqlite3VdbeIOTraceSql(p);
@@ -90509,12 +91036,14 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
91036
assert( rc==SQLITE_OK );
91037
91038
assert( pOp>=aOp && pOp<&aOp[p->nOp]);
90512
-#ifdef VDBE_PROFILE
90513
- start = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
90514
-#endif
91039
nVmStep++;
90516
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
90517
- if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
91040
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
91041
+ pOp->nExec++;
91042
+ pnCycle = &pOp->nCycle;
91043
+# ifdef VDBE_PROFILE
91044
+ if( sqlite3NProfileCnt==0 )
91045
+# endif
91046
+ *pnCycle -= sqlite3Hwtime();
91047
#endif
91048
91049
/* Only allow tracing if SQLITE_DEBUG is defined.
@@ -90576,7 +91105,7 @@ SQLITE_PRIVATE int sqlite3VdbeExec(
91105
}
91106
}
91107
#endif
90579
-#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
91108
+#ifdef SQLITE_DEBUG
91109
pOrigOp = pOp;
91110
#endif
91111
@@ -90860,6 +91389,12 @@ case OP_Halt: {
91389
#ifdef SQLITE_DEBUG
91390
if( pOp->p2==OE_Abort ){ sqlite3VdbeAssertAbortable(p); }
91391
#endif
91392
+
91393
+ /* A deliberately coded "OP_Halt SQLITE_INTERNAL * * * *" opcode indicates
91394
+ ** something is wrong with the code generator. Raise an assertion in order
91395
+ ** to bring this to the attention of fuzzers and other testing tools. */
91396
+ assert( pOp->p1!=SQLITE_INTERNAL );
91397
+
91398
if( p->pFrame && pOp->p1==SQLITE_OK ){
91399
/* Halt the sub-program. Return control to the parent frame. */
91400
pFrame = p->pFrame;
@@ -91301,10 +91836,10 @@ case OP_ResultRow: {
91836
assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
91837
91838
p->cacheCtr = (p->cacheCtr + 2)|1;
91304
- p->pResultSet = &aMem[pOp->p1];
91839
+ p->pResultRow = &aMem[pOp->p1];
91840
#ifdef SQLITE_DEBUG
91841
{
91307
- Mem *pMem = p->pResultSet;
91842
+ Mem *pMem = p->pResultRow;
91843
int i;
91844
for(i=0; i<pOp->p2; i++){
91845
assert( memIsValid(&pMem[i]) );
@@ -91834,7 +92369,6 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
92369
flags1 = pIn1->flags;
92370
flags3 = pIn3->flags;
92371
if( (flags1 & flags3 & MEM_Int)!=0 ){
91837
- assert( (pOp->p5 & SQLITE_AFF_MASK)!=SQLITE_AFF_TEXT || CORRUPT_DB );
92372
/* Common case of comparison of two integers */
92373
if( pIn3->u.i > pIn1->u.i ){
92374
if( sqlite3aGTb[pOp->opcode] ){
@@ -91842,18 +92376,21 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
92376
goto jump_to_p2;
92377
}
92378
iCompare = +1;
92379
+ VVA_ONLY( iCompareIsInit = 1; )
92380
}else if( pIn3->u.i < pIn1->u.i ){
92381
if( sqlite3aLTb[pOp->opcode] ){
92382
VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92383
goto jump_to_p2;
92384
}
92385
iCompare = -1;
92386
+ VVA_ONLY( iCompareIsInit = 1; )
92387
}else{
92388
if( sqlite3aEQb[pOp->opcode] ){
92389
VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92390
goto jump_to_p2;
92391
}
92392
iCompare = 0;
92393
+ VVA_ONLY( iCompareIsInit = 1; )
92394
}
92395
VdbeBranchTaken(0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92396
break;
@@ -91885,6 +92422,7 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
92422
goto jump_to_p2;
92423
}
92424
iCompare = 1; /* Operands are not equal */
92425
+ VVA_ONLY( iCompareIsInit = 1; )
92426
break;
92427
}
92428
}else{
@@ -91895,14 +92433,14 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
92433
if( (flags1 | flags3)&MEM_Str ){
92434
if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
92435
applyNumericAffinity(pIn1,0);
91898
- testcase( flags3==pIn3->flags );
92436
+ assert( flags3==pIn3->flags || CORRUPT_DB );
92437
flags3 = pIn3->flags;
92438
}
92439
if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
92440
applyNumericAffinity(pIn3,0);
92441
}
92442
}
91905
- }else if( affinity==SQLITE_AFF_TEXT ){
92443
+ }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
92444
if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
92445
testcase( pIn1->flags & MEM_Int );
92446
testcase( pIn1->flags & MEM_Real );
@@ -91910,7 +92448,7 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
92448
sqlite3VdbeMemStringify(pIn1, encoding, 1);
92449
testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
92450
flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
91913
- if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
92451
+ if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
92452
}
92453
if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
92454
testcase( pIn3->flags & MEM_Int );
@@ -91941,6 +92479,7 @@ case OP_Ge: { /* same as TK_GE, jump, in1, in3 */
92479
res2 = sqlite3aGTb[pOp->opcode];
92480
}
92481
iCompare = res;
92482
+ VVA_ONLY( iCompareIsInit = 1; )
92483
92484
/* Undo any changes made by applyAffinity() to the input registers. */
92485
assert( (pIn3->flags & MEM_Dyn) == (flags3 & MEM_Dyn) );
@@ -91979,6 +92518,7 @@ case OP_ElseEq: { /* same as TK_ESCAPE, jump */
92518
break;
92519
}
92520
#endif /* SQLITE_DEBUG */
92521
+ assert( iCompareIsInit );
92522
VdbeBranchTaken(iCompare==0, 2);
92523
if( iCompare==0 ) goto jump_to_p2;
92524
break;
@@ -92073,6 +92613,7 @@ case OP_Compare: {
92613
pColl = pKeyInfo->aColl[i];
92614
bRev = (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_DESC);
92615
iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
92616
+ VVA_ONLY( iCompareIsInit = 1; )
92617
if( iCompare ){
92618
if( (pKeyInfo->aSortFlags[i] & KEYINFO_ORDER_BIGNULL)
92619
&& ((aMem[p1+idx].flags & MEM_Null) || (aMem[p2+idx].flags & MEM_Null))
@@ -92097,6 +92638,7 @@ case OP_Compare: {
92638
*/
92639
case OP_Jump: { /* jump */
92640
assert( pOp>aOp && pOp[-1].opcode==OP_Compare );
92641
+ assert( iCompareIsInit );
92642
if( iCompare<0 ){
92643
VdbeBranchTaken(0,4); pOp = &aOp[pOp->p1 - 1];
92644
}else if( iCompare==0 ){
@@ -92496,7 +93038,7 @@ case OP_Offset: { /* out3 */
93038
** typeof() function or the IS NULL or IS NOT NULL operators or the
93039
** equivalent. In this case, all content loading can be omitted.
93040
*/
92499
-case OP_Column: {
93041
+case OP_Column: { /* ncycle */
93042
u32 p2; /* column number to retrieve */
93043
VdbeCursor *pC; /* The VDBE cursor */
93044
BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */
@@ -92845,7 +93387,7 @@ case OP_TypeCheck: {
93387
}
93388
case COLTYPE_REAL: {
93389
testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
92848
- testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal );
93390
+ assert( (pIn1->flags & MEM_IntReal)==0 );
93391
if( pIn1->flags & MEM_Int ){
93392
/* When applying REAL affinity, if the result is still an MEM_Int
93393
** that will fit in 6 bytes, then change the type to MEM_IntReal
@@ -93848,7 +94390,7 @@ case OP_SetCookie: {
94390
**
94391
** See also: OP_OpenRead, OP_ReopenIdx
94392
*/
93851
-case OP_ReopenIdx: {
94393
+case OP_ReopenIdx: { /* ncycle */
94394
int nField;
94395
KeyInfo *pKeyInfo;
94396
u32 p2;
@@ -93869,7 +94411,7 @@ case OP_ReopenIdx: {
94411
}
94412
/* If the cursor is not currently open or is open on a different
94413
** index, then fall through into OP_OpenRead to force a reopen */
93872
-case OP_OpenRead:
94414
+case OP_OpenRead: /* ncycle */
94415
case OP_OpenWrite:
94416
94417
assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
@@ -93963,7 +94505,7 @@ open_cursor_set_hints:
94505
**
94506
** Duplicate ephemeral cursors are used for self-joins of materialized views.
94507
*/
93966
-case OP_OpenDup: {
94508
+case OP_OpenDup: { /* ncycle */
94509
VdbeCursor *pOrig; /* The original cursor to be duplicated */
94510
VdbeCursor *pCx; /* The new cursor */
94511
@@ -94025,8 +94567,8 @@ case OP_OpenDup: {
94567
** by this opcode will be used for automatically created transient
94568
** indices in joins.
94569
*/
94028
-case OP_OpenAutoindex:
94029
-case OP_OpenEphemeral: {
94570
+case OP_OpenAutoindex: /* ncycle */
94571
+case OP_OpenEphemeral: { /* ncycle */
94572
VdbeCursor *pCx;
94573
KeyInfo *pKeyInfo;
94574
@@ -94184,7 +94726,7 @@ case OP_OpenPseudo: {
94726
** Close a cursor previously opened as P1. If P1 is not
94727
** currently open, this instruction is a no-op.
94728
*/
94187
-case OP_Close: {
94729
+case OP_Close: { /* ncycle */
94730
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94731
sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
94732
p->apCsr[pOp->p1] = 0;
@@ -94301,10 +94843,10 @@ case OP_ColumnsUsed: {
94843
**
94844
** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
94845
*/
94304
-case OP_SeekLT: /* jump, in3, group */
94305
-case OP_SeekLE: /* jump, in3, group */
94306
-case OP_SeekGE: /* jump, in3, group */
94307
-case OP_SeekGT: { /* jump, in3, group */
94846
+case OP_SeekLT: /* jump, in3, group, ncycle */
94847
+case OP_SeekLE: /* jump, in3, group, ncycle */
94848
+case OP_SeekGE: /* jump, in3, group, ncycle */
94849
+case OP_SeekGT: { /* jump, in3, group, ncycle */
94850
int res; /* Comparison result */
94851
int oc; /* Opcode */
94852
VdbeCursor *pC; /* The cursor to seek */
@@ -94570,7 +95112,7 @@ seek_not_found:
95112
** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
95113
** </ol>
95114
*/
94573
-case OP_SeekScan: {
95115
+case OP_SeekScan: { /* ncycle */
95116
VdbeCursor *pC;
95117
int res;
95118
int nStep;
@@ -94692,7 +95234,7 @@ case OP_SeekScan: {
95234
**
95235
** P1 must be a valid b-tree cursor.
95236
*/
94695
-case OP_SeekHit: {
95237
+case OP_SeekHit: { /* ncycle */
95238
VdbeCursor *pC;
95239
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95240
pC = p->apCsr[pOp->p1];
@@ -94824,7 +95366,7 @@ case OP_IfNotOpen: { /* jump */
95366
**
95367
** See also: NotFound, Found, NotExists
95368
*/
94827
-case OP_IfNoHope: { /* jump, in3 */
95369
+case OP_IfNoHope: { /* jump, in3, ncycle */
95370
VdbeCursor *pC;
95371
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95372
pC = p->apCsr[pOp->p1];
@@ -94838,9 +95380,9 @@ case OP_IfNoHope: { /* jump, in3 */
95380
/* Fall through into OP_NotFound */
95381
/* no break */ deliberate_fall_through
95382
}
94841
-case OP_NoConflict: /* jump, in3 */
94842
-case OP_NotFound: /* jump, in3 */
94843
-case OP_Found: { /* jump, in3 */
95383
+case OP_NoConflict: /* jump, in3, ncycle */
95384
+case OP_NotFound: /* jump, in3, ncycle */
95385
+case OP_Found: { /* jump, in3, ncycle */
95386
int alreadyExists;
95387
int ii;
95388
VdbeCursor *pC;
@@ -94970,7 +95512,7 @@ case OP_Found: { /* jump, in3 */
95512
**
95513
** See also: Found, NotFound, NoConflict, SeekRowid
95514
*/
94973
-case OP_SeekRowid: { /* jump, in3 */
95515
+case OP_SeekRowid: { /* jump, in3, ncycle */
95516
VdbeCursor *pC;
95517
BtCursor *pCrsr;
95518
int res;
@@ -94995,7 +95537,7 @@ case OP_SeekRowid: { /* jump, in3 */
95537
}
95538
/* Fall through into OP_NotExists */
95539
/* no break */ deliberate_fall_through
94998
-case OP_NotExists: /* jump, in3 */
95540
+case OP_NotExists: /* jump, in3, ncycle */
95541
pIn3 = &aMem[pOp->p3];
95542
assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
95543
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -95275,8 +95817,11 @@ case OP_Insert: {
95817
if( pOp->p5 & OPFLAG_ISNOOP ) break;
95818
#endif
95819
95278
- if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
95279
- if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
95820
+ assert( (pOp->p5 & OPFLAG_LASTROWID)==0 || (pOp->p5 & OPFLAG_NCHANGE)!=0 );
95821
+ if( pOp->p5 & OPFLAG_NCHANGE ){
95822
+ p->nChange++;
95823
+ if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = x.nKey;
95824
+ }
95825
assert( (pData->flags & (MEM_Blob|MEM_Str))!=0 || pData->n==0 );
95826
x.pData = pData->z;
95827
x.nData = pData->n;
@@ -95287,6 +95832,7 @@ case OP_Insert: {
95832
x.nZero = 0;
95833
}
95834
x.pKey = 0;
95835
+ assert( BTREE_PREFORMAT==OPFLAG_PREFORMAT );
95836
rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
95837
(pOp->p5 & (OPFLAG_APPEND|OPFLAG_SAVEPOSITION|OPFLAG_PREFORMAT)),
95838
seekResult
@@ -95618,7 +96164,7 @@ case OP_RowData: {
96164
** be a separate OP_VRowid opcode for use with virtual tables, but this
96165
** one opcode now works for both table types.
96166
*/
95621
-case OP_Rowid: { /* out2 */
96167
+case OP_Rowid: { /* out2, ncycle */
96168
VdbeCursor *pC;
96169
i64 v;
96170
sqlite3_vtab *pVtab;
@@ -95717,8 +96263,8 @@ case OP_NullRow: {
96263
** from the end toward the beginning. In other words, the cursor is
96264
** configured to use Prev, not Next.
96265
*/
95720
-case OP_SeekEnd:
95721
-case OP_Last: { /* jump */
96266
+case OP_SeekEnd: /* ncycle */
96267
+case OP_Last: { /* jump, ncycle */
96268
VdbeCursor *pC;
96269
BtCursor *pCrsr;
96270
int res;
@@ -95819,17 +96365,22 @@ case OP_Sort: { /* jump */
96365
** If the table or index is not empty, fall through to the following
96366
** instruction.
96367
**
96368
+** If P2 is zero, that is an assertion that the P1 table is never
96369
+** empty and hence the jump will never be taken.
96370
+**
96371
** This opcode leaves the cursor configured to move in forward order,
96372
** from the beginning toward the end. In other words, the cursor is
96373
** configured to use Next, not Prev.
96374
*/
95826
-case OP_Rewind: { /* jump */
96375
+case OP_Rewind: { /* jump, ncycle */
96376
VdbeCursor *pC;
96377
BtCursor *pCrsr;
96378
int res;
96379
96380
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96381
assert( pOp->p5==0 );
96382
+ assert( pOp->p2>=0 && pOp->p2<p->nOp );
96383
+
96384
pC = p->apCsr[pOp->p1];
96385
assert( pC!=0 );
96386
assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
@@ -95849,9 +96400,10 @@ case OP_Rewind: { /* jump */
96400
}
96401
if( rc ) goto abort_due_to_error;
96402
pC->nullRow = (u8)res;
95852
- assert( pOp->p2>0 && pOp->p2<p->nOp );
95853
- VdbeBranchTaken(res!=0,2);
95854
- if( res ) goto jump_to_p2;
96403
+ if( pOp->p2>0 ){
96404
+ VdbeBranchTaken(res!=0,2);
96405
+ if( res ) goto jump_to_p2;
96406
+ }
96407
break;
96408
}
96409
@@ -95917,7 +96469,7 @@ case OP_SorterNext: { /* jump */
96469
rc = sqlite3VdbeSorterNext(db, pC);
96470
goto next_tail;
96471
95920
-case OP_Prev: /* jump */
96472
+case OP_Prev: /* jump, ncycle */
96473
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96474
assert( pOp->p5==0
96475
|| pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
@@ -95932,7 +96484,7 @@ case OP_Prev: /* jump */
96484
rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
96485
goto next_tail;
96486
95935
-case OP_Next: /* jump */
96487
+case OP_Next: /* jump, ncycle */
96488
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96489
assert( pOp->p5==0
96490
|| pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
@@ -96124,8 +96676,8 @@ case OP_IdxDelete: {
96676
**
96677
** See also: Rowid, MakeRecord.
96678
*/
96127
-case OP_DeferredSeek:
96128
-case OP_IdxRowid: { /* out2 */
96679
+case OP_DeferredSeek: /* ncycle */
96680
+case OP_IdxRowid: { /* out2, ncycle */
96681
VdbeCursor *pC; /* The P1 index cursor */
96682
VdbeCursor *pTabCur; /* The P2 table cursor (OP_DeferredSeek only) */
96683
i64 rowid; /* Rowid that P1 current points to */
@@ -96187,8 +96739,8 @@ case OP_IdxRowid: { /* out2 */
96739
** seek operation now, without further delay. If the cursor seek has
96740
** already occurred, this instruction is a no-op.
96741
*/
96190
-case OP_FinishSeek: {
96191
- VdbeCursor *pC; /* The P1 index cursor */
96742
+case OP_FinishSeek: { /* ncycle */
96743
+ VdbeCursor *pC; /* The P1 index cursor */
96744
96745
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96746
pC = p->apCsr[pOp->p1];
@@ -96243,10 +96795,10 @@ case OP_FinishSeek: {
96795
** If the P1 index entry is less than or equal to the key value then jump
96796
** to P2. Otherwise fall through to the next instruction.
96797
*/
96246
-case OP_IdxLE: /* jump */
96247
-case OP_IdxGT: /* jump */
96248
-case OP_IdxLT: /* jump */
96249
-case OP_IdxGE: { /* jump */
96798
+case OP_IdxLE: /* jump, ncycle */
96799
+case OP_IdxGT: /* jump, ncycle */
96800
+case OP_IdxLT: /* jump, ncycle */
96801
+case OP_IdxGE: { /* jump, ncycle */
96802
VdbeCursor *pC;
96803
int res;
96804
UnpackedRecord r;
@@ -96657,13 +97209,14 @@ case OP_IntegrityCk: {
97209
pIn1 = &aMem[pOp->p1];
97210
assert( pOp->p5<db->nDb );
97211
assert( DbMaskTest(p->btreeMask, pOp->p5) );
96660
- z = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot,
96661
- (int)pnErr->u.i+1, &nErr);
97212
+ rc = sqlite3BtreeIntegrityCheck(db, db->aDb[pOp->p5].pBt, &aRoot[1], nRoot,
97213
+ (int)pnErr->u.i+1, &nErr, &z);
97214
sqlite3VdbeMemSetNull(pIn1);
97215
if( nErr==0 ){
97216
assert( z==0 );
96665
- }else if( z==0 ){
96666
- goto no_mem;
97217
+ }else if( rc ){
97218
+ sqlite3_free(z);
97219
+ goto abort_due_to_error;
97220
}else{
97221
pnErr->u.i -= nErr-1;
97222
sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free);
@@ -96867,9 +97420,6 @@ case OP_Program: { /* jump */
97420
pFrame->aOp = p->aOp;
97421
pFrame->nOp = p->nOp;
97422
pFrame->token = pProgram->token;
96870
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
96871
- pFrame->anExec = p->anExec;
96872
-#endif
97423
#ifdef SQLITE_DEBUG
97424
pFrame->iFrameMagic = SQLITE_FRAME_MAGIC;
97425
#endif
@@ -96906,9 +97456,6 @@ case OP_Program: { /* jump */
97456
memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
97457
p->aOp = aOp = pProgram->aOp;
97458
p->nOp = pProgram->nOp;
96909
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
96910
- p->anExec = 0;
96911
-#endif
97459
#ifdef SQLITE_DEBUG
97460
/* Verify that second and subsequent executions of the same trigger do not
97461
** try to reuse register values from the first use. */
@@ -97665,7 +98212,7 @@ case OP_VDestroy: {
98212
** P1 is a cursor number. This opcode opens a cursor to the virtual
98213
** table and stores that cursor in P1.
98214
*/
97668
-case OP_VOpen: {
98215
+case OP_VOpen: { /* ncycle */
98216
VdbeCursor *pCur;
98217
sqlite3_vtab_cursor *pVCur;
98218
sqlite3_vtab *pVtab;
@@ -97712,7 +98259,7 @@ case OP_VOpen: {
98259
** cursor. Register P3 is used to hold the values returned by
98260
** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
98261
*/
97715
-case OP_VInitIn: { /* out2 */
98262
+case OP_VInitIn: { /* out2, ncycle */
98263
VdbeCursor *pC; /* The cursor containing the RHS values */
98264
ValueList *pRhs; /* New ValueList object to put in reg[P2] */
98265
@@ -97723,7 +98270,7 @@ case OP_VInitIn: { /* out2 */
98270
pRhs->pOut = &aMem[pOp->p3];
98271
pOut = out2Prerelease(p, pOp);
98272
pOut->flags = MEM_Null;
97726
- sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3_free);
98273
+ sqlite3VdbeMemSetPointer(pOut, pRhs, "ValueList", sqlite3VdbeValueListFree);
98274
break;
98275
}
98276
#endif /* SQLITE_OMIT_VIRTUALTABLE */
@@ -97749,7 +98296,7 @@ case OP_VInitIn: { /* out2 */
98296
**
98297
** A jump is made to P2 if the result set after filtering would be empty.
98298
*/
97752
-case OP_VFilter: { /* jump */
98299
+case OP_VFilter: { /* jump, ncycle */
98300
int nArg;
98301
int iQuery;
98302
const sqlite3_module *pModule;
@@ -97809,7 +98356,7 @@ case OP_VFilter: { /* jump */
98356
** bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are
98357
** unused by OP_VColumn.
98358
*/
97812
-case OP_VColumn: {
98359
+case OP_VColumn: { /* ncycle */
98360
sqlite3_vtab *pVtab;
98361
const sqlite3_module *pModule;
98362
Mem *pDest;
@@ -97861,7 +98408,7 @@ case OP_VColumn: {
98408
** jump to instruction P2. Or, if the virtual table has reached
98409
** the end of its result set, then fall through to the next instruction.
98410
*/
97864
-case OP_VNext: { /* jump */
98411
+case OP_VNext: { /* jump, ncycle */
98412
sqlite3_vtab *pVtab;
98413
const sqlite3_module *pModule;
98414
int res;
@@ -98444,12 +98991,12 @@ default: { /* This is really OP_Noop, OP_Explain */
98991
*****************************************************************************/
98992
}
98993
98447
-#ifdef VDBE_PROFILE
98448
- {
98449
- u64 endTime = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
98450
- if( endTime>start ) pOrigOp->cycles += endTime - start;
98451
- pOrigOp->cnt++;
98452
- }
98994
+#if defined(VDBE_PROFILE)
98995
+ *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
98996
+ pnCycle = 0;
98997
+#elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
98998
+ *pnCycle += sqlite3Hwtime();
98999
+ pnCycle = 0;
99000
#endif
99001
99002
/* The following code adds nothing to the actual functionality
@@ -98525,6 +99072,18 @@ abort_due_to_error:
99072
** release the mutexes on btrees that were acquired at the
99073
** top. */
99074
vdbe_return:
99075
+#if defined(VDBE_PROFILE)
99076
+ if( pnCycle ){
99077
+ *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
99078
+ pnCycle = 0;
99079
+ }
99080
+#elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
99081
+ if( pnCycle ){
99082
+ *pnCycle += sqlite3Hwtime();
99083
+ pnCycle = 0;
99084
+ }
99085
+#endif
99086
+
99087
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
99088
while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
99089
nProgressLimit += db->nProgressOps;
@@ -98536,7 +99095,9 @@ vdbe_return:
99095
}
99096
#endif
99097
p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
98539
- sqlite3VdbeLeave(p);
99098
+ if( DbMaskNonZero(p->lockMask) ){
99099
+ sqlite3VdbeLeave(p);
99100
+ }
99101
assert( rc!=SQLITE_OK || nExtraDelete==0
99102
|| sqlite3_strlike("DELETE%",p->zSql,0)!=0
99103
);
@@ -101943,6 +102504,9 @@ static int bytecodevtabConnect(
102504
");"
102505
};
102506
102507
+ (void)argc;
102508
+ (void)argv;
102509
+ (void)pzErr;
102510
rc = sqlite3_declare_vtab(db, azSchema[isTabUsed]);
102511
if( rc==SQLITE_OK ){
102512
pNew = sqlite3_malloc( sizeof(*pNew) );
@@ -102178,6 +102742,7 @@ static int bytecodevtabFilter(
102742
bytecodevtab_cursor *pCur = (bytecodevtab_cursor *)pVtabCursor;
102743
bytecodevtab *pVTab = (bytecodevtab *)pVtabCursor->pVtab;
102744
int rc = SQLITE_OK;
102745
+ (void)idxStr;
102746
102747
bytecodevtabCursorClear(pCur);
102748
pCur->iRowid = 0;
@@ -103192,6 +103757,32 @@ static void extendFJMatch(
103757
}
103758
}
103759
103760
+/*
103761
+** Return TRUE (non-zero) if zTab is a valid name for the schema table pTab.
103762
+*/
103763
+static SQLITE_NOINLINE int isValidSchemaTableName(
103764
+ const char *zTab, /* Name as it appears in the SQL */
103765
+ Table *pTab, /* The schema table we are trying to match */
103766
+ Schema *pSchema /* non-NULL if a database qualifier is present */
103767
+){
103768
+ const char *zLegacy;
103769
+ assert( pTab!=0 );
103770
+ assert( pTab->tnum==1 );
103771
+ if( sqlite3StrNICmp(zTab, "sqlite_", 7)!=0 ) return 0;
103772
+ zLegacy = pTab->zName;
103773
+ if( strcmp(zLegacy+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){
103774
+ if( sqlite3StrICmp(zTab+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){
103775
+ return 1;
103776
+ }
103777
+ if( pSchema==0 ) return 0;
103778
+ if( sqlite3StrICmp(zTab+7, &LEGACY_SCHEMA_TABLE[7])==0 ) return 1;
103779
+ if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1;
103780
+ }else{
103781
+ if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1;
103782
+ }
103783
+ return 0;
103784
+}
103785
+
103786
/*
103787
** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
103788
** that name in the set of source tables in pSrcList and make the pExpr
@@ -103345,15 +103936,17 @@ static int lookupName(
103936
}
103937
assert( zDb==0 || zTab!=0 );
103938
if( zTab ){
103348
- const char *zTabName;
103939
if( zDb ){
103940
if( pTab->pSchema!=pSchema ) continue;
103941
if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue;
103942
}
103353
- zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
103354
- assert( zTabName!=0 );
103355
- if( sqlite3StrICmp(zTabName, zTab)!=0 ){
103356
- continue;
103943
+ if( pItem->zAlias!=0 ){
103944
+ if( sqlite3StrICmp(zTab, pItem->zAlias)!=0 ){
103945
+ continue;
103946
+ }
103947
+ }else if( sqlite3StrICmp(zTab, pTab->zName)!=0 ){
103948
+ if( pTab->tnum!=1 ) continue;
103949
+ if( !isValidSchemaTableName(zTab, pTab, pSchema) ) continue;
103950
}
103951
assert( ExprUseYTab(pExpr) );
103952
if( IN_RENAME_OBJECT && pItem->zAlias ){
@@ -103496,6 +104089,7 @@ static int lookupName(
104089
if( pParse->bReturning ){
104090
eNewExprOp = TK_REGISTER;
104091
pExpr->op2 = TK_COLUMN;
104092
+ pExpr->iColumn = iCol;
104093
pExpr->iTable = pNC->uNC.iBaseReg + (pTab->nCol+1)*pExpr->iTable +
104094
sqlite3TableColumnToStorage(pTab, iCol) + 1;
104095
}else{
@@ -103908,14 +104502,10 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
104502
if( 0==sqlite3ExprCanBeNull(pExpr->pLeft) && !IN_RENAME_OBJECT ){
104503
testcase( ExprHasProperty(pExpr, EP_OuterON) );
104504
assert( !ExprHasProperty(pExpr, EP_IntValue) );
103911
- if( pExpr->op==TK_NOTNULL ){
103912
- pExpr->u.zToken = "true";
103913
- ExprSetProperty(pExpr, EP_IsTrue);
103914
- }else{
103915
- pExpr->u.zToken = "false";
103916
- ExprSetProperty(pExpr, EP_IsFalse);
103917
- }
103918
- pExpr->op = TK_TRUEFALSE;
104505
+ pExpr->u.iValue = (pExpr->op==TK_NOTNULL);
104506
+ pExpr->flags |= EP_IntValue;
104507
+ pExpr->op = TK_INTEGER;
104508
+
104509
for(i=0, p=pNC; p && i<ArraySize(anRef); p=p->pNext, i++){
104510
p->nRef = anRef[i];
104511
}
@@ -104217,8 +104807,8 @@ static int resolveExprStep(Walker *pWalker, Expr *pExpr){
104807
assert( pNC->nRef>=nRef );
104808
if( nRef!=pNC->nRef ){
104809
ExprSetProperty(pExpr, EP_VarSelect);
104220
- pNC->ncFlags |= NC_VarSelect;
104810
}
104811
+ pNC->ncFlags |= NC_Subquery;
104812
}
104813
break;
104814
}
@@ -105172,48 +105762,121 @@ SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table *pTab, int iCol){
105762
*/
105763
SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
105764
int op;
105175
- while( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
105176
- assert( pExpr->op==TK_COLLATE
105177
- || pExpr->op==TK_IF_NULL_ROW
105178
- || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
105179
- pExpr = pExpr->pLeft;
105180
- assert( pExpr!=0 );
105181
- }
105765
op = pExpr->op;
105183
- if( op==TK_REGISTER ) op = pExpr->op2;
105184
- if( op==TK_COLUMN || op==TK_AGG_COLUMN ){
105185
- assert( ExprUseYTab(pExpr) );
105186
- assert( pExpr->y.pTab!=0 );
105187
- return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105188
- }
105189
- if( op==TK_SELECT ){
105190
- assert( ExprUseXSelect(pExpr) );
105191
- assert( pExpr->x.pSelect!=0 );
105192
- assert( pExpr->x.pSelect->pEList!=0 );
105193
- assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
105194
- return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
105195
- }
105766
+ while( 1 /* exit-by-break */ ){
105767
+ if( op==TK_COLUMN || (op==TK_AGG_COLUMN && pExpr->y.pTab!=0) ){
105768
+ assert( ExprUseYTab(pExpr) );
105769
+ assert( pExpr->y.pTab!=0 );
105770
+ return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105771
+ }
105772
+ if( op==TK_SELECT ){
105773
+ assert( ExprUseXSelect(pExpr) );
105774
+ assert( pExpr->x.pSelect!=0 );
105775
+ assert( pExpr->x.pSelect->pEList!=0 );
105776
+ assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
105777
+ return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
105778
+ }
105779
#ifndef SQLITE_OMIT_CAST
105197
- if( op==TK_CAST ){
105198
- assert( !ExprHasProperty(pExpr, EP_IntValue) );
105199
- return sqlite3AffinityType(pExpr->u.zToken, 0);
105200
- }
105780
+ if( op==TK_CAST ){
105781
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
105782
+ return sqlite3AffinityType(pExpr->u.zToken, 0);
105783
+ }
105784
#endif
105202
- if( op==TK_SELECT_COLUMN ){
105203
- assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
105204
- assert( pExpr->iColumn < pExpr->iTable );
105205
- assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
105206
- return sqlite3ExprAffinity(
105207
- pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
105208
- );
105209
- }
105210
- if( op==TK_VECTOR ){
105211
- assert( ExprUseXList(pExpr) );
105212
- return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
105785
+ if( op==TK_SELECT_COLUMN ){
105786
+ assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
105787
+ assert( pExpr->iColumn < pExpr->iTable );
105788
+ assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
105789
+ return sqlite3ExprAffinity(
105790
+ pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
105791
+ );
105792
+ }
105793
+ if( op==TK_VECTOR ){
105794
+ assert( ExprUseXList(pExpr) );
105795
+ return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
105796
+ }
105797
+ if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
105798
+ assert( pExpr->op==TK_COLLATE
105799
+ || pExpr->op==TK_IF_NULL_ROW
105800
+ || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
105801
+ pExpr = pExpr->pLeft;
105802
+ op = pExpr->op;
105803
+ continue;
105804
+ }
105805
+ if( op!=TK_REGISTER || (op = pExpr->op2)==TK_REGISTER ) break;
105806
}
105807
return pExpr->affExpr;
105808
}
105809
105810
+/*
105811
+** Make a guess at all the possible datatypes of the result that could
105812
+** be returned by an expression. Return a bitmask indicating the answer:
105813
+**
105814
+** 0x01 Numeric
105815
+** 0x02 Text
105816
+** 0x04 Blob
105817
+**
105818
+** If the expression must return NULL, then 0x00 is returned.
105819
+*/
105820
+SQLITE_PRIVATE int sqlite3ExprDataType(const Expr *pExpr){
105821
+ while( pExpr ){
105822
+ switch( pExpr->op ){
105823
+ case TK_COLLATE:
105824
+ case TK_IF_NULL_ROW:
105825
+ case TK_UPLUS: {
105826
+ pExpr = pExpr->pLeft;
105827
+ break;
105828
+ }
105829
+ case TK_NULL: {
105830
+ pExpr = 0;
105831
+ break;
105832
+ }
105833
+ case TK_STRING: {
105834
+ return 0x02;
105835
+ }
105836
+ case TK_BLOB: {
105837
+ return 0x04;
105838
+ }
105839
+ case TK_CONCAT: {
105840
+ return 0x06;
105841
+ }
105842
+ case TK_VARIABLE:
105843
+ case TK_AGG_FUNCTION:
105844
+ case TK_FUNCTION: {
105845
+ return 0x07;
105846
+ }
105847
+ case TK_COLUMN:
105848
+ case TK_AGG_COLUMN:
105849
+ case TK_SELECT:
105850
+ case TK_CAST:
105851
+ case TK_SELECT_COLUMN:
105852
+ case TK_VECTOR: {
105853
+ int aff = sqlite3ExprAffinity(pExpr);
105854
+ if( aff>=SQLITE_AFF_NUMERIC ) return 0x05;
105855
+ if( aff==SQLITE_AFF_TEXT ) return 0x06;
105856
+ return 0x07;
105857
+ }
105858
+ case TK_CASE: {
105859
+ int res = 0;
105860
+ int ii;
105861
+ ExprList *pList = pExpr->x.pList;
105862
+ assert( ExprUseXList(pExpr) && pList!=0 );
105863
+ assert( pList->nExpr > 0);
105864
+ for(ii=1; ii<pList->nExpr; ii+=2){
105865
+ res |= sqlite3ExprDataType(pList->a[ii].pExpr);
105866
+ }
105867
+ if( pList->nExpr % 2 ){
105868
+ res |= sqlite3ExprDataType(pList->a[pList->nExpr-1].pExpr);
105869
+ }
105870
+ return res;
105871
+ }
105872
+ default: {
105873
+ return 0x01;
105874
+ }
105875
+ } /* End of switch(op) */
105876
+ } /* End of while(pExpr) */
105877
+ return 0x00;
105878
+}
105879
+
105880
/*
105881
** Set the collating sequence for expression pExpr to be the collating
105882
** sequence named by pToken. Return a pointer to a new Expr node that
@@ -105301,7 +105964,9 @@ SQLITE_PRIVATE CollSeq *sqlite3ExprCollSeq(Parse *pParse, const Expr *pExpr){
105964
while( p ){
105965
int op = p->op;
105966
if( op==TK_REGISTER ) op = p->op2;
105304
- if( op==TK_AGG_COLUMN || op==TK_COLUMN || op==TK_TRIGGER ){
105967
+ if( (op==TK_AGG_COLUMN && p->y.pTab!=0)
105968
+ || op==TK_COLUMN || op==TK_TRIGGER
105969
+ ){
105970
int j;
105971
assert( ExprUseYTab(p) );
105972
assert( p->y.pTab!=0 );
@@ -108383,6 +109048,9 @@ SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
109048
SelectDest dest; /* How to deal with SELECT result */
109049
int nReg; /* Registers to allocate */
109050
Expr *pLimit; /* New limit expression */
109051
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
109052
+ int addrExplain; /* Address of OP_Explain instruction */
109053
+#endif
109054
109055
Vdbe *v = pParse->pVdbe;
109056
assert( v!=0 );
@@ -108435,8 +109103,9 @@ SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
109103
** In both cases, the query is augmented with "LIMIT 1". Any
109104
** preexisting limit is discarded in place of the new LIMIT 1.
109105
*/
108438
- ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY %d",
109106
+ ExplainQueryPlan2(addrExplain, (pParse, 1, "%sSCALAR SUBQUERY %d",
109107
addrOnce?"":"CORRELATED ", pSel->selId));
109108
+ sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, -1);
109109
nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
109110
sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
109111
pParse->nMem += nReg;
@@ -108479,6 +109148,7 @@ SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *pParse, Expr *pExpr){
109148
if( addrOnce ){
109149
sqlite3VdbeJumpHere(v, addrOnce);
109150
}
109151
+ sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
109152
109153
/* Subroutine return */
109154
assert( ExprUseYSub(pExpr) );
@@ -108887,6 +109557,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
109557
){
109558
int iAddr;
109559
Vdbe *v = pParse->pVdbe;
109560
+ int nErr = pParse->nErr;
109561
assert( v!=0 );
109562
assert( pParse->iSelfTab!=0 );
109563
if( pParse->iSelfTab>0 ){
@@ -108899,6 +109570,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGeneratedColumn(
109570
sqlite3VdbeAddOp4(v, OP_Affinity, regOut, 1, 0, &pCol->affinity, 1);
109571
}
109572
if( iAddr ) sqlite3VdbeJumpHere(v, iAddr);
109573
+ if( pParse->nErr>nErr ) pParse->db->errByteOffset = -1;
109574
}
109575
#endif /* SQLITE_OMIT_GENERATED_COLUMNS */
109576
@@ -108915,6 +109587,7 @@ SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(
109587
Column *pCol;
109588
assert( v!=0 );
109589
assert( pTab!=0 );
109590
+ assert( iCol!=XN_EXPR );
109591
if( iCol<0 || iCol==pTab->iPKey ){
109592
sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
109593
VdbeComment((v, "%s.rowid", pTab->zName));
@@ -109151,10 +109824,13 @@ static int exprCodeInlineFunction(
109824
** the type affinity of the argument. This is used for testing of
109825
** the SQLite type logic.
109826
*/
109154
- const char *azAff[] = { "blob", "text", "numeric", "integer", "real" };
109827
+ const char *azAff[] = { "blob", "text", "numeric", "integer",
109828
+ "real", "flexnum" };
109829
char aff;
109830
assert( nFarg==1 );
109831
aff = sqlite3ExprAffinity(pFarg->a[0].pExpr);
109832
+ assert( aff<=SQLITE_AFF_NONE
109833
+ || (aff>=SQLITE_AFF_BLOB && aff<=SQLITE_AFF_FLEXNUM) );
109834
sqlite3VdbeLoadString(v, target,
109835
(aff<=SQLITE_AFF_NONE) ? "none" : azAff[aff-SQLITE_AFF_BLOB]);
109836
break;
@@ -109165,7 +109841,7 @@ static int exprCodeInlineFunction(
109841
}
109842
109843
/*
109168
-** Check to see if pExpr is one of the indexed expressions on pParse->pIdxExpr.
109844
+** Check to see if pExpr is one of the indexed expressions on pParse->pIdxEpr.
109845
** If it is, then resolve the expression by reading from the index and
109846
** return the register into which the value has been read. If pExpr is
109847
** not an indexed expression, then return negative.
@@ -109177,7 +109853,8 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup(
109853
){
109854
IndexedExpr *p;
109855
Vdbe *v;
109180
- for(p=pParse->pIdxExpr; p; p=p->pIENext){
109856
+ for(p=pParse->pIdxEpr; p; p=p->pIENext){
109857
+ u8 exprAff;
109858
int iDataCur = p->iDataCur;
109859
if( iDataCur<0 ) continue;
109860
if( pParse->iSelfTab ){
@@ -109185,6 +109862,16 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup(
109862
iDataCur = -1;
109863
}
109864
if( sqlite3ExprCompare(0, pExpr, p->pExpr, iDataCur)!=0 ) continue;
109865
+ assert( p->aff>=SQLITE_AFF_BLOB && p->aff<=SQLITE_AFF_NUMERIC );
109866
+ exprAff = sqlite3ExprAffinity(pExpr);
109867
+ if( (exprAff<=SQLITE_AFF_BLOB && p->aff!=SQLITE_AFF_BLOB)
109868
+ || (exprAff==SQLITE_AFF_TEXT && p->aff!=SQLITE_AFF_TEXT)
109869
+ || (exprAff>=SQLITE_AFF_NUMERIC && p->aff!=SQLITE_AFF_NUMERIC)
109870
+ ){
109871
+ /* Affinity mismatch on a generated column */
109872
+ continue;
109873
+ }
109874
+
109875
v = pParse->pVdbe;
109876
assert( v!=0 );
109877
if( p->bMaybeNullRow ){
@@ -109197,10 +109884,10 @@ static SQLITE_NOINLINE int sqlite3IndexedExprLookup(
109884
sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target);
109885
VdbeComment((v, "%s expr-column %d", p->zIdxName, p->iIdxCol));
109886
sqlite3VdbeGoto(v, 0);
109200
- p = pParse->pIdxExpr;
109201
- pParse->pIdxExpr = 0;
109887
+ p = pParse->pIdxEpr;
109888
+ pParse->pIdxEpr = 0;
109889
sqlite3ExprCode(pParse, pExpr, target);
109203
- pParse->pIdxExpr = p;
109890
+ pParse->pIdxEpr = p;
109891
sqlite3VdbeJumpHere(v, addr+2);
109892
}else{
109893
sqlite3VdbeAddOp3(v, OP_Column, p->iIdxCur, p->iIdxCol, target);
@@ -109239,7 +109926,7 @@ SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse *pParse, Expr *pExpr, int target)
109926
expr_code_doover:
109927
if( pExpr==0 ){
109928
op = TK_NULL;
109242
- }else if( pParse->pIdxExpr!=0
109929
+ }else if( pParse->pIdxEpr!=0
109930
&& !ExprHasProperty(pExpr, EP_Leaf)
109931
&& (r1 = sqlite3IndexedExprLookup(pParse, pExpr, target))>=0
109932
){
@@ -109256,15 +109943,16 @@ expr_code_doover:
109943
assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
109944
pCol = &pAggInfo->aCol[pExpr->iAgg];
109945
if( !pAggInfo->directMode ){
109259
- assert( pCol->iMem>0 );
109260
- return pCol->iMem;
109946
+ return AggInfoColumnReg(pAggInfo, pExpr->iAgg);
109947
}else if( pAggInfo->useSortingIdx ){
109948
Table *pTab = pCol->pTab;
109949
sqlite3VdbeAddOp3(v, OP_Column, pAggInfo->sortingIdxPTab,
109950
pCol->iSorterColumn, target);
109265
- if( pCol->iColumn<0 ){
109951
+ if( pTab==0 ){
109952
+ /* No comment added */
109953
+ }else if( pCol->iColumn<0 ){
109954
VdbeComment((v,"%s.rowid",pTab->zName));
109267
- }else if( ALWAYS(pTab!=0) ){
109955
+ }else{
109956
VdbeComment((v,"%s.%s",
109957
pTab->zName, pTab->aCol[pCol->iColumn].zCnName));
109958
if( pTab->aCol[pCol->iColumn].affinity==SQLITE_AFF_REAL ){
@@ -109272,6 +109960,11 @@ expr_code_doover:
109960
}
109961
}
109962
return target;
109963
+ }else if( pExpr->y.pTab==0 ){
109964
+ /* This case happens when the argument to an aggregate function
109965
+ ** is rewritten by aggregateConvertIndexedExprRefToColumn() */
109966
+ sqlite3VdbeAddOp3(v, OP_Column, pExpr->iTable, pExpr->iColumn, target);
109967
+ return target;
109968
}
109969
/* Otherwise, fall thru into the TK_COLUMN case */
109970
/* no break */ deliberate_fall_through
@@ -109292,7 +109985,7 @@ expr_code_doover:
109985
assert( pExpr->y.pTab!=0 );
109986
aff = sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
109987
if( aff>SQLITE_AFF_BLOB ){
109295
- static const char zAff[] = "B\000C\000D\000E";
109988
+ static const char zAff[] = "B\000C\000D\000E\000F";
109989
assert( SQLITE_AFF_BLOB=='A' );
109990
assert( SQLITE_AFF_TEXT=='B' );
109991
sqlite3VdbeAddOp4(v, OP_Affinity, iReg, 1, 0,
@@ -109569,7 +110262,7 @@ expr_code_doover:
110262
assert( !ExprHasProperty(pExpr, EP_IntValue) );
110263
sqlite3ErrorMsg(pParse, "misuse of aggregate: %#T()", pExpr);
110264
}else{
109572
- return pInfo->aFunc[pExpr->iAgg].iMem;
110265
+ return AggInfoFuncReg(pInfo, pExpr->iAgg);
110266
}
110267
break;
110268
}
@@ -109758,10 +110451,13 @@ expr_code_doover:
110451
return target;
110452
}
110453
case TK_COLLATE: {
109761
- if( !ExprHasProperty(pExpr, EP_Collate)
109762
- && ALWAYS(pExpr->pLeft)
109763
- && pExpr->pLeft->op==TK_FUNCTION
109764
- ){
110454
+ if( !ExprHasProperty(pExpr, EP_Collate) ){
110455
+ /* A TK_COLLATE Expr node without the EP_Collate tag is a so-called
110456
+ ** "SOFT-COLLATE" that is added to constraints that are pushed down
110457
+ ** from outer queries into sub-queries by the push-down optimization.
110458
+ ** Clear subtypes as subtypes may not cross a subquery boundary.
110459
+ */
110460
+ assert( pExpr->pLeft );
110461
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
110462
if( inReg!=target ){
110463
sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
@@ -109858,7 +110554,7 @@ expr_code_doover:
110554
if( pAggInfo ){
110555
assert( pExpr->iAgg>=0 && pExpr->iAgg<pAggInfo->nColumn );
110556
if( !pAggInfo->directMode ){
109861
- inReg = pAggInfo->aCol[pExpr->iAgg].iMem;
110557
+ inReg = AggInfoColumnReg(pAggInfo, pExpr->iAgg);
110558
break;
110559
}
110560
if( pExpr->pAggInfo->useSortingIdx ){
@@ -109869,16 +110565,22 @@ expr_code_doover:
110565
break;
110566
}
110567
}
109872
- addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
109873
- /* Temporarily disable factoring of constant expressions, since
109874
- ** even though expressions may appear to be constant, they are not
109875
- ** really constant because they originate from the right-hand side
109876
- ** of a LEFT JOIN. */
109877
- pParse->okConstFactor = 0;
110568
+ addrINR = sqlite3VdbeAddOp3(v, OP_IfNullRow, pExpr->iTable, 0, target);
110569
+ /* The OP_IfNullRow opcode above can overwrite the result register with
110570
+ ** NULL. So we have to ensure that the result register is not a value
110571
+ ** that is suppose to be a constant. Two defenses are needed:
110572
+ ** (1) Temporarily disable factoring of constant expressions
110573
+ ** (2) Make sure the computed value really is stored in register
110574
+ ** "target" and not someplace else.
110575
+ */
110576
+ pParse->okConstFactor = 0; /* note (1) above */
110577
inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
110578
pParse->okConstFactor = okConstFactor;
110579
+ if( inReg!=target ){ /* note (2) above */
110580
+ sqlite3VdbeAddOp2(v, OP_SCopy, inReg, target);
110581
+ inReg = target;
110582
+ }
110583
sqlite3VdbeJumpHere(v, addrINR);
109881
- sqlite3VdbeChangeP3(v, addrINR, inReg);
110584
break;
110585
}
110586
@@ -111289,10 +111991,8 @@ SQLITE_PRIVATE int sqlite3ReferencesSrcList(Parse *pParse, Expr *pExpr, SrcList
111991
** it does, make a copy. This is done because the pExpr argument is
111992
** subject to change.
111993
**
111292
-** The copy is stored on pParse->pConstExpr with a register number of 0.
111293
-** This will cause the expression to be deleted automatically when the
111294
-** Parse object is destroyed, but the zero register number means that it
111295
-** will not generate any code in the preamble.
111994
+** The copy is scheduled for deletion using the sqlite3ExprDeferredDelete()
111995
+** which builds on the sqlite3ParserAddCleanup() mechanism.
111996
*/
111997
static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
111998
if( ALWAYS(!ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced))
@@ -111303,7 +112003,6 @@ static int agginfoPersistExprCb(Walker *pWalker, Expr *pExpr){
112003
Parse *pParse = pWalker->pParse;
112004
sqlite3 *db = pParse->db;
112005
if( pExpr->op!=TK_AGG_FUNCTION ){
111306
- assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_IF_NULL_ROW );
112006
assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
112007
if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
112008
pExpr = sqlite3ExprDup(db, pExpr, 0);
@@ -111370,6 +112069,73 @@ static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){
112069
return i;
112070
}
112071
112072
+/*
112073
+** Search the AggInfo object for an aCol[] entry that has iTable and iColumn.
112074
+** Return the index in aCol[] of the entry that describes that column.
112075
+**
112076
+** If no prior entry is found, create a new one and return -1. The
112077
+** new column will have an idex of pAggInfo->nColumn-1.
112078
+*/
112079
+static void findOrCreateAggInfoColumn(
112080
+ Parse *pParse, /* Parsing context */
112081
+ AggInfo *pAggInfo, /* The AggInfo object to search and/or modify */
112082
+ Expr *pExpr /* Expr describing the column to find or insert */
112083
+){
112084
+ struct AggInfo_col *pCol;
112085
+ int k;
112086
+
112087
+ assert( pAggInfo->iFirstReg==0 );
112088
+ pCol = pAggInfo->aCol;
112089
+ for(k=0; k<pAggInfo->nColumn; k++, pCol++){
112090
+ if( pCol->iTable==pExpr->iTable
112091
+ && pCol->iColumn==pExpr->iColumn
112092
+ && pExpr->op!=TK_IF_NULL_ROW
112093
+ ){
112094
+ goto fix_up_expr;
112095
+ }
112096
+ }
112097
+ k = addAggInfoColumn(pParse->db, pAggInfo);
112098
+ if( k<0 ){
112099
+ /* OOM on resize */
112100
+ assert( pParse->db->mallocFailed );
112101
+ return;
112102
+ }
112103
+ pCol = &pAggInfo->aCol[k];
112104
+ assert( ExprUseYTab(pExpr) );
112105
+ pCol->pTab = pExpr->y.pTab;
112106
+ pCol->iTable = pExpr->iTable;
112107
+ pCol->iColumn = pExpr->iColumn;
112108
+ pCol->iSorterColumn = -1;
112109
+ pCol->pCExpr = pExpr;
112110
+ if( pAggInfo->pGroupBy && pExpr->op!=TK_IF_NULL_ROW ){
112111
+ int j, n;
112112
+ ExprList *pGB = pAggInfo->pGroupBy;
112113
+ struct ExprList_item *pTerm = pGB->a;
112114
+ n = pGB->nExpr;
112115
+ for(j=0; j<n; j++, pTerm++){
112116
+ Expr *pE = pTerm->pExpr;
112117
+ if( pE->op==TK_COLUMN
112118
+ && pE->iTable==pExpr->iTable
112119
+ && pE->iColumn==pExpr->iColumn
112120
+ ){
112121
+ pCol->iSorterColumn = j;
112122
+ break;
112123
+ }
112124
+ }
112125
+ }
112126
+ if( pCol->iSorterColumn<0 ){
112127
+ pCol->iSorterColumn = pAggInfo->nSortingColumn++;
112128
+ }
112129
+fix_up_expr:
112130
+ ExprSetVVAProperty(pExpr, EP_NoReduce);
112131
+ assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
112132
+ pExpr->pAggInfo = pAggInfo;
112133
+ if( pExpr->op==TK_COLUMN ){
112134
+ pExpr->op = TK_AGG_COLUMN;
112135
+ }
112136
+ pExpr->iAgg = (i16)k;
112137
+}
112138
+
112139
/*
112140
** This is the xExprCallback for a tree walker. It is used to
112141
** implement sqlite3ExprAnalyzeAggregates(). See sqlite3ExprAnalyzeAggregates
@@ -111383,7 +112149,37 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
112149
AggInfo *pAggInfo = pNC->uNC.pAggInfo;
112150
112151
assert( pNC->ncFlags & NC_UAggInfo );
112152
+ assert( pAggInfo->iFirstReg==0 );
112153
switch( pExpr->op ){
112154
+ default: {
112155
+ IndexedExpr *pIEpr;
112156
+ Expr tmp;
112157
+ assert( pParse->iSelfTab==0 );
112158
+ if( (pNC->ncFlags & NC_InAggFunc)==0 ) break;
112159
+ if( pParse->pIdxEpr==0 ) break;
112160
+ for(pIEpr=pParse->pIdxEpr; pIEpr; pIEpr=pIEpr->pIENext){
112161
+ int iDataCur = pIEpr->iDataCur;
112162
+ if( iDataCur<0 ) continue;
112163
+ if( sqlite3ExprCompare(0, pExpr, pIEpr->pExpr, iDataCur)==0 ) break;
112164
+ }
112165
+ if( pIEpr==0 ) break;
112166
+ if( NEVER(!ExprUseYTab(pExpr)) ) break;
112167
+ if( pExpr->pAggInfo!=0 ) break; /* Already resolved by outer context */
112168
+
112169
+ /* If we reach this point, it means that expression pExpr can be
112170
+ ** translated into a reference to an index column as described by
112171
+ ** pIEpr.
112172
+ */
112173
+ memset(&tmp, 0, sizeof(tmp));
112174
+ tmp.op = TK_AGG_COLUMN;
112175
+ tmp.iTable = pIEpr->iIdxCur;
112176
+ tmp.iColumn = pIEpr->iIdxCol;
112177
+ findOrCreateAggInfoColumn(pParse, pAggInfo, &tmp);
112178
+ pAggInfo->aCol[tmp.iAgg].pCExpr = pExpr;
112179
+ pExpr->pAggInfo = pAggInfo;
112180
+ pExpr->iAgg = tmp.iAgg;
112181
+ return WRC_Prune;
112182
+ }
112183
case TK_IF_NULL_ROW:
112184
case TK_AGG_COLUMN:
112185
case TK_COLUMN: {
@@ -111395,67 +112191,9 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
112191
if( ALWAYS(pSrcList!=0) ){
112192
SrcItem *pItem = pSrcList->a;
112193
for(i=0; i<pSrcList->nSrc; i++, pItem++){
111398
- struct AggInfo_col *pCol;
112194
assert( !ExprHasProperty(pExpr, EP_TokenOnly|EP_Reduced) );
112195
if( pExpr->iTable==pItem->iCursor ){
111401
- /* If we reach this point, it means that pExpr refers to a table
111402
- ** that is in the FROM clause of the aggregate query.
111403
- **
111404
- ** Make an entry for the column in pAggInfo->aCol[] if there
111405
- ** is not an entry there already.
111406
- */
111407
- int k;
111408
- pCol = pAggInfo->aCol;
111409
- for(k=0; k<pAggInfo->nColumn; k++, pCol++){
111410
- if( pCol->iTable==pExpr->iTable
111411
- && pCol->iColumn==pExpr->iColumn
111412
- && pExpr->op!=TK_IF_NULL_ROW
111413
- ){
111414
- break;
111415
- }
111416
- }
111417
- if( (k>=pAggInfo->nColumn)
111418
- && (k = addAggInfoColumn(pParse->db, pAggInfo))>=0
111419
- ){
111420
- pCol = &pAggInfo->aCol[k];
111421
- assert( ExprUseYTab(pExpr) );
111422
- pCol->pTab = pExpr->y.pTab;
111423
- pCol->iTable = pExpr->iTable;
111424
- pCol->iColumn = pExpr->iColumn;
111425
- pCol->iMem = ++pParse->nMem;
111426
- pCol->iSorterColumn = -1;
111427
- pCol->pCExpr = pExpr;
111428
- if( pAggInfo->pGroupBy && pExpr->op!=TK_IF_NULL_ROW ){
111429
- int j, n;
111430
- ExprList *pGB = pAggInfo->pGroupBy;
111431
- struct ExprList_item *pTerm = pGB->a;
111432
- n = pGB->nExpr;
111433
- for(j=0; j<n; j++, pTerm++){
111434
- Expr *pE = pTerm->pExpr;
111435
- if( pE->op==TK_COLUMN
111436
- && pE->iTable==pExpr->iTable
111437
- && pE->iColumn==pExpr->iColumn
111438
- ){
111439
- pCol->iSorterColumn = j;
111440
- break;
111441
- }
111442
- }
111443
- }
111444
- if( pCol->iSorterColumn<0 ){
111445
- pCol->iSorterColumn = pAggInfo->nSortingColumn++;
111446
- }
111447
- }
111448
- /* There is now an entry for pExpr in pAggInfo->aCol[] (either
111449
- ** because it was there before or because we just created it).
111450
- ** Convert the pExpr to be a TK_AGG_COLUMN referring to that
111451
- ** pAggInfo->aCol[] entry.
111452
- */
111453
- ExprSetVVAProperty(pExpr, EP_NoReduce);
111454
- pExpr->pAggInfo = pAggInfo;
111455
- if( pExpr->op==TK_COLUMN ){
111456
- pExpr->op = TK_AGG_COLUMN;
111457
- }
111458
- pExpr->iAgg = (i16)k;
112196
+ findOrCreateAggInfoColumn(pParse, pAggInfo, pExpr);
112197
break;
112198
} /* endif pExpr->iTable==pItem->iCursor */
112199
} /* end loop over pSrcList */
@@ -111485,7 +112223,6 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
112223
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
112224
pItem = &pAggInfo->aFunc[i];
112225
pItem->pFExpr = pExpr;
111488
- pItem->iMem = ++pParse->nMem;
112226
assert( ExprUseUToken(pExpr) );
112227
pItem->pFunc = sqlite3FindFunction(pParse->db,
112228
pExpr->u.zToken,
@@ -112382,13 +113119,14 @@ static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
113119
assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
113120
if( pParse->nErr==0 ){
113121
const RenameToken *p;
112385
- u8 i = 0;
113122
+ u32 i = 1;
113123
for(p=pParse->pRename; p; p=p->pNext){
113124
if( p->p ){
113125
assert( p->p!=pPtr );
112389
- i += *(u8*)(p->p);
113126
+ i += *(u8*)(p->p) | 1;
113127
}
113128
}
113129
+ assert( i>0 );
113130
}
113131
}
113132
#else
@@ -115518,6 +116256,8 @@ static int analysisLoader(void *pData, int argc, char **argv, char **NotUsed){
116256
** and its contents.
116257
*/
116258
SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
116259
+ assert( db!=0 );
116260
+ assert( pIdx!=0 );
116261
#ifdef SQLITE_ENABLE_STAT4
116262
if( pIdx->aSample ){
116263
int j;
@@ -115527,7 +116267,7 @@ SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
116267
}
116268
sqlite3DbFree(db, pIdx->aSample);
116269
}
115530
- if( db && db->pnBytesFreed==0 ){
116270
+ if( db->pnBytesFreed==0 ){
116271
pIdx->nSample = 0;
116272
pIdx->aSample = 0;
116273
}
@@ -115946,7 +116686,7 @@ static void attachFunc(
116686
char *zErr = 0;
116687
unsigned int flags;
116688
Db *aNew; /* New array of Db pointers */
115949
- Db *pNew; /* Db object for the newly attached database */
116689
+ Db *pNew = 0; /* Db object for the newly attached database */
116690
char *zErrDyn = 0;
116691
sqlite3_vfs *pVfs;
116692
@@ -115966,13 +116706,26 @@ static void attachFunc(
116706
/* This is not a real ATTACH. Instead, this routine is being called
116707
** from sqlite3_deserialize() to close database db->init.iDb and
116708
** reopen it as a MemDB */
116709
+ Btree *pNewBt = 0;
116710
pVfs = sqlite3_vfs_find("memdb");
116711
if( pVfs==0 ) return;
115971
- pNew = &db->aDb[db->init.iDb];
115972
- if( pNew->pBt ) sqlite3BtreeClose(pNew->pBt);
115973
- pNew->pBt = 0;
115974
- pNew->pSchema = 0;
115975
- rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNew->pBt, 0, SQLITE_OPEN_MAIN_DB);
116712
+ rc = sqlite3BtreeOpen(pVfs, "x\0", db, &pNewBt, 0, SQLITE_OPEN_MAIN_DB);
116713
+ if( rc==SQLITE_OK ){
116714
+ Schema *pNewSchema = sqlite3SchemaGet(db, pNewBt);
116715
+ if( pNewSchema ){
116716
+ /* Both the Btree and the new Schema were allocated successfully.
116717
+ ** Close the old db and update the aDb[] slot with the new memdb
116718
+ ** values. */
116719
+ pNew = &db->aDb[db->init.iDb];
116720
+ if( ALWAYS(pNew->pBt) ) sqlite3BtreeClose(pNew->pBt);
116721
+ pNew->pBt = pNewBt;
116722
+ pNew->pSchema = pNewSchema;
116723
+ }else{
116724
+ sqlite3BtreeClose(pNewBt);
116725
+ rc = SQLITE_NOMEM;
116726
+ }
116727
+ }
116728
+ if( rc ) goto attach_error;
116729
}else{
116730
/* This is a real ATTACH
116731
**
@@ -116085,7 +116838,7 @@ static void attachFunc(
116838
}
116839
#endif
116840
if( rc ){
116088
- if( !REOPEN_AS_MEMDB(db) ){
116841
+ if( ALWAYS(!REOPEN_AS_MEMDB(db)) ){
116842
int iDb = db->nDb - 1;
116843
assert( iDb>=2 );
116844
if( db->aDb[iDb].pBt ){
@@ -116202,6 +116955,8 @@ static void codeAttach(
116955
sqlite3* db = pParse->db;
116956
int regArgs;
116957
116958
+ if( SQLITE_OK!=sqlite3ReadSchema(pParse) ) goto attach_end;
116959
+
116960
if( pParse->nErr ) goto attach_end;
116961
memset(&sName, 0, sizeof(NameContext));
116962
sName.pParse = pParse;
@@ -117044,6 +117799,7 @@ SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
117799
char saveBuf[PARSE_TAIL_SZ];
117800
117801
if( pParse->nErr ) return;
117802
+ if( pParse->eParseMode ) return;
117803
assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
117804
va_start(ap, zFormat);
117805
zSql = sqlite3VMPrintf(db, zFormat, ap);
@@ -118187,7 +118943,7 @@ SQLITE_PRIVATE void sqlite3AddReturning(Parse *pParse, ExprList *pList){
118943
if( pParse->pNewTrigger ){
118944
sqlite3ErrorMsg(pParse, "cannot use RETURNING in a trigger");
118945
}else{
118190
- assert( pParse->bReturning==0 );
118946
+ assert( pParse->bReturning==0 || pParse->ifNotExists );
118947
}
118948
pParse->bReturning = 1;
118949
pRet = sqlite3DbMallocZero(db, sizeof(*pRet));
@@ -118213,7 +118969,8 @@ SQLITE_PRIVATE void sqlite3AddReturning(Parse *pParse, ExprList *pList){
118969
pRet->retTStep.pTrig = &pRet->retTrig;
118970
pRet->retTStep.pExprList = pList;
118971
pHash = &(db->aDb[1].pSchema->trigHash);
118216
- assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0 || pParse->nErr );
118972
+ assert( sqlite3HashFind(pHash, RETURNING_TRIGGER_NAME)==0
118973
+ || pParse->nErr || pParse->ifNotExists );
118974
if( sqlite3HashInsert(pHash, RETURNING_TRIGGER_NAME, &pRet->retTrig)
118975
==&pRet->retTrig ){
118976
sqlite3OomFault(db);
@@ -118741,6 +119498,14 @@ SQLITE_PRIVATE void sqlite3AddGenerated(Parse *pParse, Expr *pExpr, Token *pType
119498
if( pCol->colFlags & COLFLAG_PRIMKEY ){
119499
makeColumnPartOfPrimaryKey(pParse, pCol); /* For the error message */
119500
}
119501
+ if( ALWAYS(pExpr) && pExpr->op==TK_ID ){
119502
+ /* The value of a generated column needs to be a real expression, not
119503
+ ** just a reference to another column, in order for covering index
119504
+ ** optimizations to work correctly. So if the value is not an expression,
119505
+ ** turn it into one by adding a unary "+" operator. */
119506
+ pExpr = sqlite3PExpr(pParse, TK_UPLUS, pExpr, 0);
119507
+ }
119508
+ if( pExpr && pExpr->op!=TK_RAISE ) pExpr->affExpr = pCol->affinity;
119509
sqlite3ColumnSetExpr(pParse, pTab, pCol, pExpr);
119510
pExpr = 0;
119511
goto generated_done;
@@ -118877,7 +119642,8 @@ static char *createTableStmt(sqlite3 *db, Table *p){
119642
/* SQLITE_AFF_TEXT */ " TEXT",
119643
/* SQLITE_AFF_NUMERIC */ " NUM",
119644
/* SQLITE_AFF_INTEGER */ " INT",
118880
- /* SQLITE_AFF_REAL */ " REAL"
119645
+ /* SQLITE_AFF_REAL */ " REAL",
119646
+ /* SQLITE_AFF_FLEXNUM */ " NUM",
119647
};
119648
int len;
119649
const char *zType;
@@ -118893,10 +119659,12 @@ static char *createTableStmt(sqlite3 *db, Table *p){
119659
testcase( pCol->affinity==SQLITE_AFF_NUMERIC );
119660
testcase( pCol->affinity==SQLITE_AFF_INTEGER );
119661
testcase( pCol->affinity==SQLITE_AFF_REAL );
119662
+ testcase( pCol->affinity==SQLITE_AFF_FLEXNUM );
119663
119664
zType = azType[pCol->affinity - SQLITE_AFF_BLOB];
119665
len = sqlite3Strlen30(zType);
119666
assert( pCol->affinity==SQLITE_AFF_BLOB
119667
+ || pCol->affinity==SQLITE_AFF_FLEXNUM
119668
|| pCol->affinity==sqlite3AffinityType(zType, 0) );
119669
memcpy(&zStmt[k], zType, len);
119670
k += len;
@@ -119311,6 +120079,7 @@ SQLITE_PRIVATE int sqlite3ShadowTableName(sqlite3 *db, const char *zName){
120079
** not pass them into code generator routines by mistake.
120080
*/
120081
static int markImmutableExprStep(Walker *pWalker, Expr *pExpr){
120082
+ (void)pWalker;
120083
ExprSetVVAProperty(pExpr, EP_Immutable);
120084
return WRC_Continue;
120085
}
@@ -119877,8 +120646,7 @@ static SQLITE_NOINLINE int viewGetColumnNames(Parse *pParse, Table *pTable){
120646
&& pTable->nCol==pSel->pEList->nExpr
120647
){
120648
assert( db->mallocFailed==0 );
119880
- sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
119881
- SQLITE_AFF_NONE);
120649
+ sqlite3SubqueryColumnTypes(pParse, pTable, pSel, SQLITE_AFF_NONE);
120650
}
120651
}else{
120652
/* CREATE VIEW name AS... without an argument list. Construct
@@ -123444,7 +124212,7 @@ SQLITE_PRIVATE void sqlite3DeleteFrom(
124212
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
124213
{
124214
u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
123447
- if( sNC.ncFlags & NC_VarSelect ) bComplex = 1;
124215
+ if( sNC.ncFlags & NC_Subquery ) bComplex = 1;
124216
wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
124217
if( HasRowid(pTab) ){
124218
/* For a rowid table, initialize the RowSet to an empty set */
@@ -125062,7 +125830,7 @@ SQLITE_PRIVATE void sqlite3QuoteValue(StrAccum *pStr, sqlite3_value *pValue){
125830
}
125831
case SQLITE_BLOB: {
125832
char const *zBlob = sqlite3_value_blob(pValue);
125065
- int nBlob = sqlite3_value_bytes(pValue);
125833
+ i64 nBlob = sqlite3_value_bytes(pValue);
125834
assert( zBlob==sqlite3_value_blob(pValue) ); /* No encoding change */
125835
sqlite3StrAccumEnlarge(pStr, nBlob*2 + 4);
125836
if( pStr->accError==0 ){
@@ -125203,6 +125971,96 @@ static void hexFunc(
125971
}
125972
}
125973
125974
+/*
125975
+** Buffer zStr contains nStr bytes of utf-8 encoded text. Return 1 if zStr
125976
+** contains character ch, or 0 if it does not.
125977
+*/
125978
+static int strContainsChar(const u8 *zStr, int nStr, u32 ch){
125979
+ const u8 *zEnd = &zStr[nStr];
125980
+ const u8 *z = zStr;
125981
+ while( z<zEnd ){
125982
+ u32 tst = Utf8Read(z);
125983
+ if( tst==ch ) return 1;
125984
+ }
125985
+ return 0;
125986
+}
125987
+
125988
+/*
125989
+** The unhex() function. This function may be invoked with either one or
125990
+** two arguments. In both cases the first argument is interpreted as text
125991
+** a text value containing a set of pairs of hexadecimal digits which are
125992
+** decoded and returned as a blob.
125993
+**
125994
+** If there is only a single argument, then it must consist only of an
125995
+** even number of hexadeximal digits. Otherwise, return NULL.
125996
+**
125997
+** Or, if there is a second argument, then any character that appears in
125998
+** the second argument is also allowed to appear between pairs of hexadecimal
125999
+** digits in the first argument. If any other character appears in the
126000
+** first argument, or if one of the allowed characters appears between
126001
+** two hexadecimal digits that make up a single byte, NULL is returned.
126002
+**
126003
+** The following expressions are all true:
126004
+**
126005
+** unhex('ABCD') IS x'ABCD'
126006
+** unhex('AB CD') IS NULL
126007
+** unhex('AB CD', ' ') IS x'ABCD'
126008
+** unhex('A BCD', ' ') IS NULL
126009
+*/
126010
+static void unhexFunc(
126011
+ sqlite3_context *pCtx,
126012
+ int argc,
126013
+ sqlite3_value **argv
126014
+){
126015
+ const u8 *zPass = (const u8*)"";
126016
+ int nPass = 0;
126017
+ const u8 *zHex = sqlite3_value_text(argv[0]);
126018
+ int nHex = sqlite3_value_bytes(argv[0]);
126019
+#ifdef SQLITE_DEBUG
126020
+ const u8 *zEnd = zHex ? &zHex[nHex] : 0;
126021
+#endif
126022
+ u8 *pBlob = 0;
126023
+ u8 *p = 0;
126024
+
126025
+ assert( argc==1 || argc==2 );
126026
+ if( argc==2 ){
126027
+ zPass = sqlite3_value_text(argv[1]);
126028
+ nPass = sqlite3_value_bytes(argv[1]);
126029
+ }
126030
+ if( !zHex || !zPass ) return;
126031
+
126032
+ p = pBlob = contextMalloc(pCtx, (nHex/2)+1);
126033
+ if( pBlob ){
126034
+ u8 c; /* Most significant digit of next byte */
126035
+ u8 d; /* Least significant digit of next byte */
126036
+
126037
+ while( (c = *zHex)!=0x00 ){
126038
+ while( !sqlite3Isxdigit(c) ){
126039
+ u32 ch = Utf8Read(zHex);
126040
+ assert( zHex<=zEnd );
126041
+ if( !strContainsChar(zPass, nPass, ch) ) goto unhex_null;
126042
+ c = *zHex;
126043
+ if( c==0x00 ) goto unhex_done;
126044
+ }
126045
+ zHex++;
126046
+ assert( *zEnd==0x00 );
126047
+ assert( zHex<=zEnd );
126048
+ d = *(zHex++);
126049
+ if( !sqlite3Isxdigit(d) ) goto unhex_null;
126050
+ *(p++) = (sqlite3HexToInt(c)<<4) | sqlite3HexToInt(d);
126051
+ }
126052
+ }
126053
+
126054
+ unhex_done:
126055
+ sqlite3_result_blob(pCtx, pBlob, (p - pBlob), sqlite3_free);
126056
+ return;
126057
+
126058
+ unhex_null:
126059
+ sqlite3_free(pBlob);
126060
+ return;
126061
+}
126062
+
126063
+
126064
/*
126065
** The zeroblob(N) function returns a zero-filled blob of size N bytes.
126066
*/
@@ -125420,6 +126278,9 @@ static void unknownFunc(
126278
sqlite3_value **argv
126279
){
126280
/* no-op */
126281
+ (void)context;
126282
+ (void)argc;
126283
+ (void)argv;
126284
}
126285
#endif /*SQLITE_ENABLE_UNKNOWN_SQL_FUNCTION*/
126286
@@ -126048,6 +126909,18 @@ static void ceilingFunc(
126909
static double xCeil(double x){ return ceil(x); }
126910
static double xFloor(double x){ return floor(x); }
126911
126912
+/*
126913
+** Some systems do not have log2() and log10() in their standard math
126914
+** libraries.
126915
+*/
126916
+#if defined(HAVE_LOG10) && HAVE_LOG10==0
126917
+# define log10(X) (0.4342944819032517867*log(X))
126918
+#endif
126919
+#if defined(HAVE_LOG2) && HAVE_LOG2==0
126920
+# define log2(X) (1.442695040888963456*log(X))
126921
+#endif
126922
+
126923
+
126924
/*
126925
** Implementation of SQL functions:
126926
**
@@ -126086,17 +126959,15 @@ static void logFunc(
126959
}
126960
ans = log(x)/b;
126961
}else{
126089
- ans = log(x);
126962
switch( SQLITE_PTR_TO_INT(sqlite3_user_data(context)) ){
126963
case 1:
126092
- /* Convert from natural logarithm to log base 10 */
126093
- ans /= M_LN10;
126964
+ ans = log10(x);
This file is too large to show in full.
database/sqlite/sqlite3.h
+157
-81
@@ -146,9 +146,9 @@ extern "C" {
146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147
** [sqlite_version()] and [sqlite_source_id()].
148
*/
149
-#define SQLITE_VERSION "3.40.1"
150
-#define SQLITE_VERSION_NUMBER 3040001
151
-#define SQLITE_SOURCE_ID "2022-12-28 14:03:47 df5c253c0b3dd24916e4ec7cf77d3db5294cc9fd45ae7b9c5e82ad8197f38a24"
149
+#define SQLITE_VERSION "3.41.2"
150
+#define SQLITE_VERSION_NUMBER 3041002
151
+#define SQLITE_SOURCE_ID "2023-03-22 11:56:21 0d1fc92f94cb6b76bffe3ec34d69cffde2924203304e8ffc4155597af0c191da"
152
153
/*
154
** CAPI3REF: Run-Time Library Version Numbers
@@ -563,6 +563,7 @@ SQLITE_API int sqlite3_exec(
563
#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
564
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
565
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
566
+#define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))
567
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
568
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
569
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
@@ -1175,7 +1176,6 @@ struct sqlite3_io_methods {
1176
** in wal mode after the client has finished copying pages from the wal
1177
** file to the database file, but before the *-shm file is updated to
1178
** record the fact that the pages have been checkpointed.
1178
-** </ul>
1179
**
1180
** <li>[[SQLITE_FCNTL_EXTERNAL_READER]]
1181
** The EXPERIMENTAL [SQLITE_FCNTL_EXTERNAL_READER] opcode is used to detect
@@ -1188,16 +1188,16 @@ struct sqlite3_io_methods {
1188
** the database is not a wal-mode db, or if there is no such connection in any
1189
** other process. This opcode cannot be used to detect transactions opened
1190
** by clients within the current process, only within other processes.
1191
-** </ul>
1191
**
1192
** <li>[[SQLITE_FCNTL_CKSM_FILE]]
1194
-** Used by the cksmvfs VFS module only.
1193
+** The [SQLITE_FCNTL_CKSM_FILE] opcode is for use interally by the
1194
+** [checksum VFS shim] only.
1195
**
1196
** <li>[[SQLITE_FCNTL_RESET_CACHE]]
1197
** If there is currently no transaction open on the database, and the
1198
-** database is not a temp db, then this file-control purges the contents
1199
-** of the in-memory page cache. If there is an open transaction, or if
1200
-** the db is a temp-db, it is a no-op, not an error.
1198
+** database is not a temp db, then the [SQLITE_FCNTL_RESET_CACHE] file-control
1199
+** purges the contents of the in-memory page cache. If there is an open
1200
+** transaction, or if the db is a temp-db, this opcode is a no-op, not an error.
1201
** </ul>
1202
*/
1203
#define SQLITE_FCNTL_LOCKSTATE 1
@@ -2184,7 +2184,7 @@ struct sqlite3_mem_methods {
2184
** configuration for a database connection can only be changed when that
2185
** connection is not currently using lookaside memory, or in other words
2186
** when the "current value" returned by
2187
-** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2187
+** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2188
** Any attempt to change the lookaside memory configuration when lookaside
2189
** memory is in use leaves the configuration unchanged and returns
2190
** [SQLITE_BUSY].)^</dd>
@@ -2334,8 +2334,12 @@ struct sqlite3_mem_methods {
2334
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2335
** </ol>
2336
** Because resetting a database is destructive and irreversible, the
2337
-** process requires the use of this obscure API and multiple steps to help
2338
-** ensure that it does not happen by accident.
2337
+** process requires the use of this obscure API and multiple steps to
2338
+** help ensure that it does not happen by accident. Because this
2339
+** feature must be capable of resetting corrupt databases, and
2340
+** shutting down virtual tables may require access to that corrupt
2341
+** storage, the library must abandon any installed virtual tables
2342
+** without calling their xDestroy() methods.
2343
**
2344
** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2345
** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
@@ -2674,8 +2678,12 @@ SQLITE_API sqlite3_int64 sqlite3_total_changes64(sqlite3*);
2678
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2679
** SQL statements is a no-op and has no effect on SQL statements
2680
** that are started after the sqlite3_interrupt() call returns.
2681
+**
2682
+** ^The [sqlite3_is_interrupted(D)] interface can be used to determine whether
2683
+** or not an interrupt is currently in effect for [database connection] D.
2684
*/
2685
SQLITE_API void sqlite3_interrupt(sqlite3*);
2686
+SQLITE_API int sqlite3_is_interrupted(sqlite3*);
2687
2688
/*
2689
** CAPI3REF: Determine If An SQL Statement Is Complete
@@ -3293,8 +3301,8 @@ SQLITE_API SQLITE_DEPRECATED void *sqlite3_profile(sqlite3*,
3301
** <dd>^An SQLITE_TRACE_PROFILE callback provides approximately the same
3302
** information as is provided by the [sqlite3_profile()] callback.
3303
** ^The P argument is a pointer to the [prepared statement] and the
3296
-** X argument points to a 64-bit integer which is the estimated of
3297
-** the number of nanosecond that the prepared statement took to run.
3304
+** X argument points to a 64-bit integer which is approximately
3305
+** the number of nanoseconds that the prepared statement took to run.
3306
** ^The SQLITE_TRACE_PROFILE callback is invoked when the statement finishes.
3307
**
3308
** [[SQLITE_TRACE_ROW]] <dt>SQLITE_TRACE_ROW</dt>
@@ -3357,7 +3365,7 @@ SQLITE_API int sqlite3_trace_v2(
3365
**
3366
** ^The sqlite3_progress_handler(D,N,X,P) interface causes the callback
3367
** function X to be invoked periodically during long running calls to
3360
-** [sqlite3_exec()], [sqlite3_step()] and [sqlite3_get_table()] for
3368
+** [sqlite3_step()] and [sqlite3_prepare()] and similar for
3369
** database connection D. An example use for this
3370
** interface is to keep a GUI updated during a large query.
3371
**
@@ -3382,6 +3390,13 @@ SQLITE_API int sqlite3_trace_v2(
3390
** Note that [sqlite3_prepare_v2()] and [sqlite3_step()] both modify their
3391
** database connections for the meaning of "modify" in this paragraph.
3392
**
3393
+** The progress handler callback would originally only be invoked from the
3394
+** bytecode engine. It still might be invoked during [sqlite3_prepare()]
3395
+** and similar because those routines might force a reparse of the schema
3396
+** which involves running the bytecode engine. However, beginning with
3397
+** SQLite version 3.41.0, the progress handler callback might also be
3398
+** invoked directly from [sqlite3_prepare()] while analyzing and generating
3399
+** code for complex queries.
3400
*/
3401
SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3402
@@ -3418,13 +3433,18 @@ SQLITE_API void sqlite3_progress_handler(sqlite3*, int, int(*)(void*), void*);
3433
**
3434
** <dl>
3435
** ^(<dt>[SQLITE_OPEN_READONLY]</dt>
3421
-** <dd>The database is opened in read-only mode. If the database does not
3422
-** already exist, an error is returned.</dd>)^
3436
+** <dd>The database is opened in read-only mode. If the database does
3437
+** not already exist, an error is returned.</dd>)^
3438
**
3439
** ^(<dt>[SQLITE_OPEN_READWRITE]</dt>
3425
-** <dd>The database is opened for reading and writing if possible, or reading
3426
-** only if the file is write protected by the operating system. In either
3427
-** case the database must already exist, otherwise an error is returned.</dd>)^
3440
+** <dd>The database is opened for reading and writing if possible, or
3441
+** reading only if the file is write protected by the operating
3442
+** system. In either case the database must already exist, otherwise
3443
+** an error is returned. For historical reasons, if opening in
3444
+** read-write mode fails due to OS-level permissions, an attempt is
3445
+** made to open it in read-only mode. [sqlite3_db_readonly()] can be
3446
+** used to determine whether the database is actually
3447
+** read-write.</dd>)^
3448
**
3449
** ^(<dt>[SQLITE_OPEN_READWRITE] | [SQLITE_OPEN_CREATE]</dt>
3450
** <dd>The database is opened for reading and writing, and is created if
@@ -5405,10 +5425,21 @@ SQLITE_API int sqlite3_create_window_function(
5425
** from top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in
5426
** schema structures such as [CHECK constraints], [DEFAULT clauses],
5427
** [expression indexes], [partial indexes], or [generated columns].
5408
-** The SQLITE_DIRECTONLY flags is a security feature which is recommended
5409
-** for all [application-defined SQL functions], and especially for functions
5410
-** that have side-effects or that could potentially leak sensitive
5411
-** information.
5428
+** <p>
5429
+** The SQLITE_DIRECTONLY flag is recommended for any
5430
+** [application-defined SQL function]
5431
+** that has side-effects or that could potentially leak sensitive information.
5432
+** This will prevent attacks in which an application is tricked
5433
+** into using a database file that has had its schema surreptiously
5434
+** modified to invoke the application-defined function in ways that are
5435
+** harmful.
5436
+** <p>
5437
+** Some people say it is good practice to set SQLITE_DIRECTONLY on all
5438
+** [application-defined SQL functions], regardless of whether or not they
5439
+** are security sensitive, as doing so prevents those functions from being used
5440
+** inside of the database schema, and thus ensures that the database
5441
+** can be inspected and modified using generic tools (such as the [CLI])
5442
+** that do not have access to the application-defined functions.
5443
** </dd>
5444
**
5445
** [[SQLITE_INNOCUOUS]] <dt>SQLITE_INNOCUOUS</dt><dd>
@@ -5549,16 +5580,6 @@ SQLITE_API SQLITE_DEPRECATED int sqlite3_memory_alarm(void(*)(void*,sqlite3_int6
5580
** then the conversion is performed. Otherwise no conversion occurs.
5581
** The [SQLITE_INTEGER | datatype] after conversion is returned.)^
5582
**
5552
-** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],
5553
-** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current encoding
5554
-** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)
5555
-** returns something other than SQLITE_TEXT, then the return value from
5556
-** sqlite3_value_encoding(X) is meaningless. ^Calls to
5557
-** sqlite3_value_text(X), sqlite3_value_text16(X), sqlite3_value_text16be(X),
5558
-** sqlite3_value_text16le(X), sqlite3_value_bytes(X), or
5559
-** sqlite3_value_bytes16(X) might change the encoding of the value X and
5560
-** thus change the return from subsequent calls to sqlite3_value_encoding(X).
5561
-**
5583
** ^Within the [xUpdate] method of a [virtual table], the
5584
** sqlite3_value_nochange(X) interface returns true if and only if
5585
** the column corresponding to X is unchanged by the UPDATE operation
@@ -5623,6 +5644,27 @@ SQLITE_API int sqlite3_value_type(sqlite3_value*);
5644
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5645
SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
5646
SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
5647
+
5648
+/*
5649
+** CAPI3REF: Report the internal text encoding state of an sqlite3_value object
5650
+** METHOD: sqlite3_value
5651
+**
5652
+** ^(The sqlite3_value_encoding(X) interface returns one of [SQLITE_UTF8],
5653
+** [SQLITE_UTF16BE], or [SQLITE_UTF16LE] according to the current text encoding
5654
+** of the value X, assuming that X has type TEXT.)^ If sqlite3_value_type(X)
5655
+** returns something other than SQLITE_TEXT, then the return value from
5656
+** sqlite3_value_encoding(X) is meaningless. ^Calls to
5657
+** [sqlite3_value_text(X)], [sqlite3_value_text16(X)], [sqlite3_value_text16be(X)],
5658
+** [sqlite3_value_text16le(X)], [sqlite3_value_bytes(X)], or
5659
+** [sqlite3_value_bytes16(X)] might change the encoding of the value X and
5660
+** thus change the return from subsequent calls to sqlite3_value_encoding(X).
5661
+**
5662
+** This routine is intended for used by applications that test and validate
5663
+** the SQLite implementation. This routine is inquiring about the opaque
5664
+** internal state of an [sqlite3_value] object. Ordinary applications should
5665
+** not need to know what the internal state of an sqlite3_value object is and
5666
+** hence should not need to use this interface.
5667
+*/
5668
SQLITE_API int sqlite3_value_encoding(sqlite3_value*);
5669
5670
/*
@@ -7003,15 +7045,6 @@ SQLITE_API int sqlite3_cancel_auto_extension(void(*xEntryPoint)(void));
7045
*/
7046
SQLITE_API void sqlite3_reset_auto_extension(void);
7047
7006
-/*
7007
-** The interface to the virtual-table mechanism is currently considered
7008
-** to be experimental. The interface might change in incompatible ways.
7009
-** If this is a problem for you, do not use the interface at this time.
7010
-**
7011
-** When the virtual-table mechanism stabilizes, we will declare the
7012
-** interface fixed, support it indefinitely, and remove this comment.
7013
-*/
7014
-
7048
/*
7049
** Structures used by the virtual table interface
7050
*/
@@ -7130,10 +7163,10 @@ struct sqlite3_module {
7163
** when the omit flag is true there is no guarantee that the constraint will
7164
** not be checked again using byte code.)^
7165
**
7133
-** ^The idxNum and idxPtr values are recorded and passed into the
7166
+** ^The idxNum and idxStr values are recorded and passed into the
7167
** [xFilter] method.
7135
-** ^[sqlite3_free()] is used to free idxPtr if and only if
7136
-** needToFreeIdxPtr is true.
7168
+** ^[sqlite3_free()] is used to free idxStr if and only if
7169
+** needToFreeIdxStr is true.
7170
**
7171
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
7172
** the correct order to satisfy the ORDER BY clause so that no separate
@@ -7253,7 +7286,7 @@ struct sqlite3_index_info {
7286
** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7287
** tables, the collating sequence of constraints does not matter (for example
7288
** because the constraints are numeric) and so the sqlite3_vtab_collation()
7256
-** interface is no commonly needed.
7289
+** interface is not commonly needed.
7290
*/
7291
#define SQLITE_INDEX_CONSTRAINT_EQ 2
7292
#define SQLITE_INDEX_CONSTRAINT_GT 4
@@ -7412,16 +7445,6 @@ SQLITE_API int sqlite3_declare_vtab(sqlite3*, const char *zSQL);
7445
*/
7446
SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
7447
7415
-/*
7416
-** The interface to the virtual-table mechanism defined above (back up
7417
-** to a comment remarkably similar to this one) is currently considered
7418
-** to be experimental. The interface might change in incompatible ways.
7419
-** If this is a problem for you, do not use the interface at this time.
7420
-**
7421
-** When the virtual-table mechanism stabilizes, we will declare the
7422
-** interface fixed, support it indefinitely, and remove this comment.
7423
-*/
7424
-
7448
/*
7449
** CAPI3REF: A Handle To An Open BLOB
7450
** KEYWORDS: {BLOB handle} {BLOB handles}
@@ -9625,7 +9648,7 @@ SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9648
** <li><p> Otherwise, "BINARY" is returned.
9649
** </ol>
9650
*/
9628
-SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9651
+SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9652
9653
/*
9654
** CAPI3REF: Determine if a virtual table query is DISTINCT
@@ -9782,21 +9805,20 @@ SQLITE_API int sqlite3_vtab_in(sqlite3_index_info*, int iCons, int bHandle);
9805
** is undefined and probably harmful.
9806
**
9807
** The X parameter in a call to sqlite3_vtab_in_first(X,P) or
9785
-** sqlite3_vtab_in_next(X,P) must be one of the parameters to the
9808
+** sqlite3_vtab_in_next(X,P) should be one of the parameters to the
9809
** xFilter method which invokes these routines, and specifically
9810
** a parameter that was previously selected for all-at-once IN constraint
9811
** processing use the [sqlite3_vtab_in()] interface in the
9812
** [xBestIndex|xBestIndex method]. ^(If the X parameter is not
9813
** an xFilter argument that was selected for all-at-once IN constraint
9791
-** processing, then these routines return [SQLITE_MISUSE])^ or perhaps
9792
-** exhibit some other undefined or harmful behavior.
9814
+** processing, then these routines return [SQLITE_ERROR].)^
9815
**
9816
** ^(Use these routines to access all values on the right-hand side
9817
** of the IN constraint using code like the following:
9818
**
9819
** <blockquote><pre>
9820
** for(rc=sqlite3_vtab_in_first(pList, &pVal);
9799
-** rc==SQLITE_OK && pVal
9821
+** rc==SQLITE_OK && pVal;
9822
** rc=sqlite3_vtab_in_next(pList, &pVal)
9823
** ){
9824
** // do something with pVal
@@ -9894,6 +9916,10 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **
9916
** managed by the prepared statement S and will be automatically freed when
9917
** S is finalized.
9918
**
9919
+** Not all values are available for all query elements. When a value is
9920
+** not available, the output variable is set to -1 if the value is numeric,
9921
+** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).
9922
+**
9923
** <dl>
9924
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
9925
** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
@@ -9921,12 +9947,24 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **
9947
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
9948
** description for the X-th loop.
9949
**
9924
-** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
9950
+** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
9951
** <dd>^The "int" variable pointed to by the V parameter will be set to the
9926
-** "select-id" for the X-th loop. The select-id identifies which query or
9927
-** subquery the loop is part of. The main query has a select-id of zero.
9928
-** The select-id is the same value as is output in the first column
9929
-** of an [EXPLAIN QUERY PLAN] query.
9952
+** id for the X-th query plan element. The id value is unique within the
9953
+** statement. The select-id is the same value as is output in the first
9954
+** column of an [EXPLAIN QUERY PLAN] query.
9955
+**
9956
+** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
9957
+** <dd>The "int" variable pointed to by the V parameter will be set to the
9958
+** the id of the parent of the current query element, if applicable, or
9959
+** to zero if the query element has no parent. This is the same value as
9960
+** returned in the second column of an [EXPLAIN QUERY PLAN] query.
9961
+**
9962
+** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
9963
+** <dd>The sqlite3_int64 output value is set to the number of cycles,
9964
+** according to the processor time-stamp counter, that elapsed while the
9965
+** query element was being processed. This value is not available for
9966
+** all query elements - if it is unavailable the output variable is
9967
+** set to -1.
9968
** </dl>
9969
*/
9970
#define SQLITE_SCANSTAT_NLOOP 0
@@ -9935,12 +9973,14 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **
9973
#define SQLITE_SCANSTAT_NAME 3
9974
#define SQLITE_SCANSTAT_EXPLAIN 4
9975
#define SQLITE_SCANSTAT_SELECTID 5
9976
+#define SQLITE_SCANSTAT_PARENTID 6
9977
+#define SQLITE_SCANSTAT_NCYCLE 7
9978
9979
/*
9980
** CAPI3REF: Prepared Statement Scan Status
9981
** METHOD: sqlite3_stmt
9982
**
9943
-** This interface returns information about the predicted and measured
9983
+** These interfaces return information about the predicted and measured
9984
** performance for pStmt. Advanced applications can use this
9985
** interface to compare the predicted and the measured performance and
9986
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
@@ -9951,19 +9991,25 @@ SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **
9991
**
9992
** The "iScanStatusOp" parameter determines which status information to return.
9993
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
9954
-** of this interface is undefined.
9955
-** ^The requested measurement is written into a variable pointed to by
9956
-** the "pOut" parameter.
9957
-** Parameter "idx" identifies the specific loop to retrieve statistics for.
9958
-** Loops are numbered starting from zero. ^If idx is out of range - less than
9959
-** zero or greater than or equal to the total number of loops used to implement
9960
-** the statement - a non-zero value is returned and the variable that pOut
9961
-** points to is unchanged.
9962
-**
9963
-** ^Statistics might not be available for all loops in all statements. ^In cases
9964
-** where there exist loops with no available statistics, this function behaves
9965
-** as if the loop did not exist - it returns non-zero and leave the variable
9966
-** that pOut points to unchanged.
9994
+** of this interface is undefined. ^The requested measurement is written into
9995
+** a variable pointed to by the "pOut" parameter.
9996
+**
9997
+** The "flags" parameter must be passed a mask of flags. At present only
9998
+** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX
9999
+** is specified, then status information is available for all elements
10000
+** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If
10001
+** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements
10002
+** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of
10003
+** the EXPLAIN QUERY PLAN output) are available. Invoking API
10004
+** sqlite3_stmt_scanstatus() is equivalent to calling
10005
+** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10006
+**
10007
+** Parameter "idx" identifies the specific query element to retrieve statistics
10008
+** for. Query elements are numbered starting from zero. A value of -1 may be
10009
+** to query for statistics regarding the entire query. ^If idx is out of range
10010
+** - less than -1 or greater than or equal to the total number of query
10011
+** elements used to implement the statement - a non-zero value is returned and
10012
+** the variable that pOut points to is unchanged.
10013
**
10014
** See also: [sqlite3_stmt_scanstatus_reset()]
10015
*/
@@ -9973,6 +10019,19 @@ SQLITE_API int sqlite3_stmt_scanstatus(
10019
int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10020
void *pOut /* Result written here */
10021
);
10022
+SQLITE_API int sqlite3_stmt_scanstatus_v2(
10023
+ sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
10024
+ int idx, /* Index of loop to report on */
10025
+ int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10026
+ int flags, /* Mask of flags defined below */
10027
+ void *pOut /* Result written here */
10028
+);
10029
+
10030
+/*
10031
+** CAPI3REF: Prepared Statement Scan Status
10032
+** KEYWORDS: {scan status flags}
10033
+*/
10034
+#define SQLITE_SCANSTAT_COMPLEX 0x0001
10035
10036
/*
10037
** CAPI3REF: Zero Scan-Status Counters
@@ -10063,6 +10122,10 @@ SQLITE_API int sqlite3_db_cacheflush(sqlite3*);
10122
** function is not defined for operations on WITHOUT ROWID tables, or for
10123
** DELETE operations on rowid tables.
10124
**
10125
+** ^The sqlite3_preupdate_hook(D,C,P) function returns the P argument from
10126
+** the previous call on the same [database connection] D, or NULL for
10127
+** the first call on D.
10128
+**
10129
** The [sqlite3_preupdate_old()], [sqlite3_preupdate_new()],
10130
** [sqlite3_preupdate_count()], and [sqlite3_preupdate_depth()] interfaces
10131
** provide additional information about a preupdate event. These routines
@@ -10468,6 +10531,19 @@ SQLITE_API int sqlite3_deserialize(
10531
# undef double
10532
#endif
10533
10534
+#if defined(__wasi__)
10535
+# undef SQLITE_WASI
10536
+# define SQLITE_WASI 1
10537
+# undef SQLITE_OMIT_WAL
10538
+# define SQLITE_OMIT_WAL 1/* because it requires shared memory APIs */
10539
+# ifndef SQLITE_OMIT_LOAD_EXTENSION
10540
+# define SQLITE_OMIT_LOAD_EXTENSION
10541
+# endif
10542
+# ifndef SQLITE_THREADSAFE
10543
+# define SQLITE_THREADSAFE 0
10544
+# endif
10545
+#endif
10546
+
10547
#ifdef __cplusplus
10548
} /* End of the 'extern "C"' block */
10549
#endif