| | @@ -216,10 +216,13 @@ |
| 216 | 216 | "ENABLE_ATOMIC_WRITE", |
| 217 | 217 | #endif |
| 218 | 218 | #if SQLITE_ENABLE_BATCH_ATOMIC_WRITE |
| 219 | 219 | "ENABLE_BATCH_ATOMIC_WRITE", |
| 220 | 220 | #endif |
| 221 | +#if SQLITE_ENABLE_BYTECODE_VTAB |
| 222 | + "ENABLE_BYTECODE_VTAB", |
| 223 | +#endif |
| 221 | 224 | #if SQLITE_ENABLE_CEROD |
| 222 | 225 | "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD), |
| 223 | 226 | #endif |
| 224 | 227 | #if SQLITE_ENABLE_COLUMN_METADATA |
| 225 | 228 | "ENABLE_COLUMN_METADATA", |
| | @@ -534,13 +537,10 @@ |
| 534 | 537 | "OMIT_BETWEEN_OPTIMIZATION", |
| 535 | 538 | #endif |
| 536 | 539 | #if SQLITE_OMIT_BLOB_LITERAL |
| 537 | 540 | "OMIT_BLOB_LITERAL", |
| 538 | 541 | #endif |
| 539 | | -#if SQLITE_OMIT_BTREECOUNT |
| 540 | | - "OMIT_BTREECOUNT", |
| 541 | | -#endif |
| 542 | 542 | #if SQLITE_OMIT_CAST |
| 543 | 543 | "OMIT_CAST", |
| 544 | 544 | #endif |
| 545 | 545 | #if SQLITE_OMIT_CHECK |
| 546 | 546 | "OMIT_CHECK", |
| | @@ -1162,11 +1162,11 @@ |
| 1162 | 1162 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1163 | 1163 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1164 | 1164 | */ |
| 1165 | 1165 | #define SQLITE_VERSION "3.32.0" |
| 1166 | 1166 | #define SQLITE_VERSION_NUMBER 3032000 |
| 1167 | | -#define SQLITE_SOURCE_ID "2020-04-20 17:35:32 2fc80ef16ce5878311ab88a0c64631813572ffbb71f75363b4619c9667e0926b" |
| 1167 | +#define SQLITE_SOURCE_ID "2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb216eda" |
| 1168 | 1168 | |
| 1169 | 1169 | /* |
| 1170 | 1170 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1171 | 1171 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1172 | 1172 | ** |
| | @@ -1336,30 +1336,26 @@ |
| 1336 | 1336 | ** for the [sqlite3] object. |
| 1337 | 1337 | ** ^Calls to sqlite3_close() and sqlite3_close_v2() return [SQLITE_OK] if |
| 1338 | 1338 | ** the [sqlite3] object is successfully destroyed and all associated |
| 1339 | 1339 | ** resources are deallocated. |
| 1340 | 1340 | ** |
| 1341 | +** Ideally, applications should [sqlite3_finalize | finalize] all |
| 1342 | +** [prepared statements], [sqlite3_blob_close | close] all [BLOB handles], and |
| 1343 | +** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 1344 | +** with the [sqlite3] object prior to attempting to close the object. |
| 1341 | 1345 | ** ^If the database connection is associated with unfinalized prepared |
| 1342 | | -** statements or unfinished sqlite3_backup objects then sqlite3_close() |
| 1343 | | -** will leave the database connection open and return [SQLITE_BUSY]. |
| 1344 | | -** ^If sqlite3_close_v2() is called with unfinalized prepared statements |
| 1345 | | -** and/or unfinished sqlite3_backups, then the database connection becomes |
| 1346 | | -** an unusable "zombie" which will automatically be deallocated when the |
| 1347 | | -** last prepared statement is finalized or the last sqlite3_backup is |
| 1348 | | -** finished. The sqlite3_close_v2() interface is intended for use with |
| 1349 | | -** host languages that are garbage collected, and where the order in which |
| 1350 | | -** destructors are called is arbitrary. |
| 1351 | | -** |
| 1352 | | -** Applications should [sqlite3_finalize | finalize] all [prepared statements], |
| 1353 | | -** [sqlite3_blob_close | close] all [BLOB handles], and |
| 1354 | | -** [sqlite3_backup_finish | finish] all [sqlite3_backup] objects associated |
| 1355 | | -** with the [sqlite3] object prior to attempting to close the object. ^If |
| 1356 | | -** sqlite3_close_v2() is called on a [database connection] that still has |
| 1357 | | -** outstanding [prepared statements], [BLOB handles], and/or |
| 1358 | | -** [sqlite3_backup] objects then it returns [SQLITE_OK] and the deallocation |
| 1359 | | -** of resources is deferred until all [prepared statements], [BLOB handles], |
| 1360 | | -** and [sqlite3_backup] objects are also destroyed. |
| 1346 | +** statements, BLOB handlers, and/or unfinished sqlite3_backup objects then |
| 1347 | +** sqlite3_close() will leave the database connection open and return |
| 1348 | +** [SQLITE_BUSY]. ^If sqlite3_close_v2() is called with unfinalized prepared |
| 1349 | +** statements, unclosed BLOB handlers, and/or unfinished sqlite3_backups, |
| 1350 | +** it returns [SQLITE_OK] regardless, but instead of deallocating the database |
| 1351 | +** connection immediately, it marks the database connection as an unusable |
| 1352 | +** "zombie" and makes arrangements to automatically deallocate the database |
| 1353 | +** connection after all prepared statements are finalized, all BLOB handles |
| 1354 | +** are closed, and all backups have finished. The sqlite3_close_v2() interface |
| 1355 | +** is intended for use with host languages that are garbage collected, and |
| 1356 | +** where the order in which destructors are called is arbitrary. |
| 1361 | 1357 | ** |
| 1362 | 1358 | ** ^If an [sqlite3] object is destroyed while a transaction is open, |
| 1363 | 1359 | ** the transaction is automatically rolled back. |
| 1364 | 1360 | ** |
| 1365 | 1361 | ** The C parameter to [sqlite3_close(C)] and [sqlite3_close_v2(C)] |
| | @@ -1544,10 +1540,11 @@ |
| 1544 | 1540 | #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8)) |
| 1545 | 1541 | #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8)) |
| 1546 | 1542 | #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8)) |
| 1547 | 1543 | #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8)) |
| 1548 | 1544 | #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8)) |
| 1545 | +#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8)) |
| 1549 | 1546 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1550 | 1547 | #define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8)) |
| 1551 | 1548 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1552 | 1549 | #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 1553 | 1550 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| | @@ -2150,10 +2147,15 @@ |
| 2150 | 2147 | ** a single attached database that occur due to other database connections, |
| 2151 | 2148 | ** but omits changes implemented by the database connection on which it is |
| 2152 | 2149 | ** called. This file control is the only mechanism to detect changes that |
| 2153 | 2150 | ** happen either internally or externally and that are associated with |
| 2154 | 2151 | ** a particular attached database. |
| 2152 | +** |
| 2153 | +** <li>[[SQLITE_FCNTL_CKPT_START]] |
| 2154 | +** The [SQLITE_FCNTL_CKPT_START] opcode is invoked from within a checkpoint |
| 2155 | +** in wal mode before the client starts to copy pages from the wal |
| 2156 | +** file to the database file. |
| 2155 | 2157 | ** |
| 2156 | 2158 | ** <li>[[SQLITE_FCNTL_CKPT_DONE]] |
| 2157 | 2159 | ** The [SQLITE_FCNTL_CKPT_DONE] opcode is invoked from within a checkpoint |
| 2158 | 2160 | ** in wal mode after the client has finished copying pages from the wal |
| 2159 | 2161 | ** file to the database file, but before the *-shm file is updated to |
| | @@ -2195,10 +2197,11 @@ |
| 2195 | 2197 | #define SQLITE_FCNTL_LOCK_TIMEOUT 34 |
| 2196 | 2198 | #define SQLITE_FCNTL_DATA_VERSION 35 |
| 2197 | 2199 | #define SQLITE_FCNTL_SIZE_LIMIT 36 |
| 2198 | 2200 | #define SQLITE_FCNTL_CKPT_DONE 37 |
| 2199 | 2201 | #define SQLITE_FCNTL_RESERVE_BYTES 38 |
| 2202 | +#define SQLITE_FCNTL_CKPT_START 39 |
| 2200 | 2203 | |
| 2201 | 2204 | /* deprecated names */ |
| 2202 | 2205 | #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE |
| 2203 | 2206 | #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE |
| 2204 | 2207 | #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO |
| | @@ -4573,12 +4576,23 @@ |
| 4573 | 4576 | ** |
| 4574 | 4577 | ** These are utility routines, useful to [VFS|custom VFS implementations], |
| 4575 | 4578 | ** that check if a database file was a URI that contained a specific query |
| 4576 | 4579 | ** parameter, and if so obtains the value of that query parameter. |
| 4577 | 4580 | ** |
| 4578 | | -** If F is the database filename pointer passed into the xOpen() method of |
| 4579 | | -** a VFS implementation or it is the return value of [sqlite3_db_filename()] |
| 4581 | +** The first parameter to these interfaces (hereafter referred to |
| 4582 | +** as F) must be one of: |
| 4583 | +** <ul> |
| 4584 | +** <li> A database filename pointer created by the SQLite core and |
| 4585 | +** passed into the xOpen() method of a VFS implemention, or |
| 4586 | +** <li> A filename obtained from [sqlite3_db_filename()], or |
| 4587 | +** <li> A new filename constructed using [sqlite3_create_filename()]. |
| 4588 | +** </ul> |
| 4589 | +** If the F parameter is not one of the above, then the behavior is |
| 4590 | +** undefined and probably undesirable. Older versions of SQLite were |
| 4591 | +** more tolerant of invalid F parameters than newer versions. |
| 4592 | +** |
| 4593 | +** If F is a suitable filename (as described in the previous paragraph) |
| 4580 | 4594 | ** and if P is the name of the query parameter, then |
| 4581 | 4595 | ** sqlite3_uri_parameter(F,P) returns the value of the P |
| 4582 | 4596 | ** parameter if it exists or a NULL pointer if P does not appear as a |
| 4583 | 4597 | ** query parameter on F. If P is a query parameter of F and it |
| 4584 | 4598 | ** has no explicit value, then sqlite3_uri_parameter(F,P) returns |
| | @@ -4657,10 +4671,29 @@ |
| 4657 | 4671 | */ |
| 4658 | 4672 | SQLITE_API const char *sqlite3_filename_database(const char*); |
| 4659 | 4673 | SQLITE_API const char *sqlite3_filename_journal(const char*); |
| 4660 | 4674 | SQLITE_API const char *sqlite3_filename_wal(const char*); |
| 4661 | 4675 | |
| 4676 | +/* |
| 4677 | +** CAPI3REF: Database File Corresponding To A Journal |
| 4678 | +** |
| 4679 | +** ^If X is the name of a rollback or WAL-mode journal file that is |
| 4680 | +** passed into the xOpen method of [sqlite3_vfs], then |
| 4681 | +** sqlite3_database_file_object(X) returns a pointer to the [sqlite3_file] |
| 4682 | +** object that represents the main database file. |
| 4683 | +** |
| 4684 | +** This routine is intended for use in custom [VFS] implementations |
| 4685 | +** only. It is not a general-purpose interface. |
| 4686 | +** The argument sqlite3_file_object(X) must be a filename pointer that |
| 4687 | +** has been passed into [sqlite3_vfs].xOpen method where the |
| 4688 | +** flags parameter to xOpen contains one of the bits |
| 4689 | +** [SQLITE_OPEN_MAIN_JOURNAL] or [SQLITE_OPEN_WAL]. Any other use |
| 4690 | +** of this routine results in undefined and probably undesirable |
| 4691 | +** behavior. |
| 4692 | +*/ |
| 4693 | +SQLITE_API sqlite3_file *sqlite3_database_file_object(const char*); |
| 4694 | + |
| 4662 | 4695 | /* |
| 4663 | 4696 | ** CAPI3REF: Create and Destroy VFS Filenames |
| 4664 | 4697 | ** |
| 4665 | 4698 | ** These interfces are provided for use by [VFS shim] implementations and |
| 4666 | 4699 | ** are not useful outside of that context. |
| | @@ -4691,11 +4724,11 @@ |
| 4691 | 4724 | ** None of the D, J, or W parameters to sqlite3_create_filename(D,J,W,N,P) may |
| 4692 | 4725 | ** be NULL pointers, though they can be empty strings. |
| 4693 | 4726 | ** |
| 4694 | 4727 | ** The sqlite3_free_filename(Y) routine releases a memory allocation |
| 4695 | 4728 | ** previously obtained from sqlite3_create_filename(). Invoking |
| 4696 | | -** sqlite3_free_filename(Y) is a NULL pointer is a harmless no-op. |
| 4729 | +** sqlite3_free_filename(Y) where Y is a NULL pointer is a harmless no-op. |
| 4697 | 4730 | ** |
| 4698 | 4731 | ** If the Y parameter to sqlite3_free_filename(Y) is anything other |
| 4699 | 4732 | ** than a NULL pointer or a pointer previously acquired from |
| 4700 | 4733 | ** sqlite3_create_filename(), then bad things such as heap |
| 4701 | 4734 | ** corruption or segfaults may occur. The value Y should be |
| | @@ -15022,13 +15055,11 @@ |
| 15022 | 15055 | #ifndef NDEBUG |
| 15023 | 15056 | SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*); |
| 15024 | 15057 | #endif |
| 15025 | 15058 | SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*); |
| 15026 | 15059 | |
| 15027 | | -#ifndef SQLITE_OMIT_BTREECOUNT |
| 15028 | 15060 | SQLITE_PRIVATE int sqlite3BtreeCount(sqlite3*, BtCursor*, i64*); |
| 15029 | | -#endif |
| 15030 | 15061 | |
| 15031 | 15062 | #ifdef SQLITE_TEST |
| 15032 | 15063 | SQLITE_PRIVATE int sqlite3BtreeCursorInfo(BtCursor*, int*, int); |
| 15033 | 15064 | SQLITE_PRIVATE void sqlite3BtreeCursorList(Btree*); |
| 15034 | 15065 | #endif |
| | @@ -15599,10 +15630,13 @@ |
| 15599 | 15630 | |
| 15600 | 15631 | SQLITE_PRIVATE void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *); |
| 15601 | 15632 | SQLITE_PRIVATE int sqlite3VdbeHasSubProgram(Vdbe*); |
| 15602 | 15633 | |
| 15603 | 15634 | SQLITE_PRIVATE int sqlite3NotPureFunc(sqlite3_context*); |
| 15635 | +#ifdef SQLITE_ENABLE_BYTECODE_VTAB |
| 15636 | +SQLITE_PRIVATE int sqlite3VdbeBytecodeVtabInit(sqlite3*); |
| 15637 | +#endif |
| 15604 | 15638 | |
| 15605 | 15639 | /* Use SQLITE_ENABLE_COMMENTS to enable generation of extra comments on |
| 15606 | 15640 | ** each VDBE opcode. |
| 15607 | 15641 | ** |
| 15608 | 15642 | ** Use the SQLITE_ENABLE_MODULE_COMMENTS macro to see some extra no-op |
| | @@ -16855,10 +16889,11 @@ |
| 16855 | 16889 | Hash aFunc; /* Hash table of connection functions */ |
| 16856 | 16890 | Hash aCollSeq; /* All collating sequences */ |
| 16857 | 16891 | BusyHandler busyHandler; /* Busy callback */ |
| 16858 | 16892 | Db aDbStatic[2]; /* Static space for the 2 default backends */ |
| 16859 | 16893 | Savepoint *pSavepoint; /* List of active savepoints */ |
| 16894 | + int nAnalysisLimit; /* Number of index rows to ANALYZE */ |
| 16860 | 16895 | int busyTimeout; /* Busy handler timeout, in msec */ |
| 16861 | 16896 | int nSavepoint; /* Number of non-transaction savepoints */ |
| 16862 | 16897 | int nStatement; /* Number of nested statement-transactions */ |
| 16863 | 16898 | i64 nDeferredCons; /* Net deferred constraints this transaction. */ |
| 16864 | 16899 | i64 nDeferredImmCons; /* Net deferred immediate constraints */ |
| | @@ -20636,11 +20671,12 @@ |
| 20636 | 20671 | /* |
| 20637 | 20672 | ** VDBE_DISPLAY_P4 is true or false depending on whether or not the |
| 20638 | 20673 | ** "explain" P4 display logic is enabled. |
| 20639 | 20674 | */ |
| 20640 | 20675 | #if !defined(SQLITE_OMIT_EXPLAIN) || !defined(NDEBUG) \ |
| 20641 | | - || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) |
| 20676 | + || defined(VDBE_PROFILE) || defined(SQLITE_DEBUG) \ |
| 20677 | + || defined(SQLITE_ENABLE_BYTECODE_VTAB) |
| 20642 | 20678 | # define VDBE_DISPLAY_P4 1 |
| 20643 | 20679 | #else |
| 20644 | 20680 | # define VDBE_DISPLAY_P4 0 |
| 20645 | 20681 | #endif |
| 20646 | 20682 | |
| | @@ -21101,11 +21137,18 @@ |
| 21101 | 21137 | |
| 21102 | 21138 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 21103 | 21139 | SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*); |
| 21104 | 21140 | SQLITE_PRIVATE int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*); |
| 21105 | 21141 | SQLITE_PRIVATE int sqlite3VdbeExec(Vdbe*); |
| 21106 | | -#ifndef SQLITE_OMIT_EXPLAIN |
| 21142 | +#if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB) |
| 21143 | +SQLITE_PRIVATE int sqlite3VdbeNextOpcode(Vdbe*,Mem*,int,int*,int*,Op**); |
| 21144 | +SQLITE_PRIVATE char *sqlite3VdbeDisplayP4(sqlite3*,Op*); |
| 21145 | +#endif |
| 21146 | +#if defined(SQLITE_ENABLE_EXPLAIN_COMMENTS) |
| 21147 | +SQLITE_PRIVATE char *sqlite3VdbeDisplayComment(sqlite3*,const Op*,const char*); |
| 21148 | +#endif |
| 21149 | +#if !defined(SQLITE_OMIT_EXPLAIN) |
| 21107 | 21150 | SQLITE_PRIVATE int sqlite3VdbeList(Vdbe*); |
| 21108 | 21151 | #endif |
| 21109 | 21152 | SQLITE_PRIVATE int sqlite3VdbeHalt(Vdbe*); |
| 21110 | 21153 | SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *, int); |
| 21111 | 21154 | SQLITE_PRIVATE int sqlite3VdbeMemTooBig(Mem*); |
| | @@ -21143,11 +21186,11 @@ |
| 21143 | 21186 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 21144 | 21187 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 21145 | 21188 | #ifndef SQLITE_OMIT_WINDOWFUNC |
| 21146 | 21189 | SQLITE_PRIVATE int sqlite3VdbeMemAggValue(Mem*, Mem*, FuncDef*); |
| 21147 | 21190 | #endif |
| 21148 | | -#ifndef SQLITE_OMIT_EXPLAIN |
| 21191 | +#if !defined(SQLITE_OMIT_EXPLAIN) || defined(SQLITE_ENABLE_BYTECODE_VTAB) |
| 21149 | 21192 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int); |
| 21150 | 21193 | #endif |
| 21151 | 21194 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 21152 | 21195 | SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n); |
| 21153 | 21196 | SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int); |
| | @@ -27316,11 +27359,11 @@ |
| 27316 | 27359 | if( mem0.hardLimit>0 && (n>mem0.hardLimit || n==0) ){ |
| 27317 | 27360 | n = mem0.hardLimit; |
| 27318 | 27361 | } |
| 27319 | 27362 | mem0.alarmThreshold = n; |
| 27320 | 27363 | nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 27321 | | - mem0.nearlyFull = (n>0 && n<=nUsed); |
| 27364 | + AtomicStore(&mem0.nearlyFull, n>0 && n<=nUsed); |
| 27322 | 27365 | sqlite3_mutex_leave(mem0.mutex); |
| 27323 | 27366 | excess = sqlite3_memory_used() - n; |
| 27324 | 27367 | if( excess>0 ) sqlite3_release_memory((int)(excess & 0x7fffffff)); |
| 27325 | 27368 | return priorLimit; |
| 27326 | 27369 | } |
| | @@ -27384,11 +27427,11 @@ |
| 27384 | 27427 | ** Return true if the heap is currently under memory pressure - in other |
| 27385 | 27428 | ** words if the amount of heap used is close to the limit set by |
| 27386 | 27429 | ** sqlite3_soft_heap_limit(). |
| 27387 | 27430 | */ |
| 27388 | 27431 | SQLITE_PRIVATE int sqlite3HeapNearlyFull(void){ |
| 27389 | | - return mem0.nearlyFull; |
| 27432 | + return AtomicLoad(&mem0.nearlyFull); |
| 27390 | 27433 | } |
| 27391 | 27434 | |
| 27392 | 27435 | /* |
| 27393 | 27436 | ** Deinitialize the memory allocation subsystem. |
| 27394 | 27437 | */ |
| | @@ -27448,21 +27491,21 @@ |
| 27448 | 27491 | |
| 27449 | 27492 | sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, n); |
| 27450 | 27493 | if( mem0.alarmThreshold>0 ){ |
| 27451 | 27494 | sqlite3_int64 nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 27452 | 27495 | if( nUsed >= mem0.alarmThreshold - nFull ){ |
| 27453 | | - mem0.nearlyFull = 1; |
| 27496 | + AtomicStore(&mem0.nearlyFull, 1); |
| 27454 | 27497 | sqlite3MallocAlarm(nFull); |
| 27455 | 27498 | if( mem0.hardLimit ){ |
| 27456 | 27499 | nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED); |
| 27457 | 27500 | if( nUsed >= mem0.hardLimit - nFull ){ |
| 27458 | 27501 | *pp = 0; |
| 27459 | 27502 | return; |
| 27460 | 27503 | } |
| 27461 | 27504 | } |
| 27462 | 27505 | }else{ |
| 27463 | | - mem0.nearlyFull = 0; |
| 27506 | + AtomicStore(&mem0.nearlyFull, 0); |
| 27464 | 27507 | } |
| 27465 | 27508 | } |
| 27466 | 27509 | p = sqlite3GlobalConfig.m.xMalloc(nFull); |
| 27467 | 27510 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 27468 | 27511 | if( p==0 && mem0.alarmThreshold>0 ){ |
| | @@ -54026,13 +54069,16 @@ |
| 54026 | 54069 | } |
| 54027 | 54070 | if( exists ){ |
| 54028 | 54071 | /* One of the journals pointed to by the master journal exists. |
| 54029 | 54072 | ** Open it and check if it points at the master journal. If |
| 54030 | 54073 | ** so, return without deleting the master journal file. |
| 54074 | + ** NB: zJournal is really a MAIN_JOURNAL. But call it a |
| 54075 | + ** MASTER_JOURNAL here so that the VFS will not send the zJournal |
| 54076 | + ** name into sqlite3_database_file_object(). |
| 54031 | 54077 | */ |
| 54032 | 54078 | int c; |
| 54033 | | - int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MAIN_JOURNAL); |
| 54079 | + int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL); |
| 54034 | 54080 | rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0); |
| 54035 | 54081 | if( rc!=SQLITE_OK ){ |
| 54036 | 54082 | goto delmaster_out; |
| 54037 | 54083 | } |
| 54038 | 54084 | |
| | @@ -56232,10 +56278,11 @@ |
| 56232 | 56278 | ** Pager object (sizeof(Pager) bytes) |
| 56233 | 56279 | ** PCache object (sqlite3PcacheSize() bytes) |
| 56234 | 56280 | ** Database file handle (pVfs->szOsFile bytes) |
| 56235 | 56281 | ** Sub-journal file handle (journalFileSize bytes) |
| 56236 | 56282 | ** Main journal file handle (journalFileSize bytes) |
| 56283 | + ** Ptr back to the Pager (sizeof(Pager*) bytes) |
| 56237 | 56284 | ** \0\0\0\0 database prefix (4 bytes) |
| 56238 | 56285 | ** Database file name (nPathname+1 bytes) |
| 56239 | 56286 | ** URI query parameters (nUriByte bytes) |
| 56240 | 56287 | ** Journal filename (nPathname+8+1 bytes) |
| 56241 | 56288 | ** WAL filename (nPathname+4+1 bytes) |
| | @@ -56271,10 +56318,11 @@ |
| 56271 | 56318 | pPtr = (u8 *)sqlite3MallocZero( |
| 56272 | 56319 | ROUND8(sizeof(*pPager)) + /* Pager structure */ |
| 56273 | 56320 | ROUND8(pcacheSize) + /* PCache object */ |
| 56274 | 56321 | ROUND8(pVfs->szOsFile) + /* The main db file */ |
| 56275 | 56322 | journalFileSize * 2 + /* The two journal files */ |
| 56323 | + sizeof(pPager) + /* Space to hold a pointer */ |
| 56276 | 56324 | 4 + /* Database prefix */ |
| 56277 | 56325 | nPathname + 1 + /* database filename */ |
| 56278 | 56326 | nUriByte + /* query parameters */ |
| 56279 | 56327 | nPathname + 8 + 1 + /* Journal filename */ |
| 56280 | 56328 | #ifndef SQLITE_OMIT_WAL |
| | @@ -56291,10 +56339,11 @@ |
| 56291 | 56339 | pPager->pPCache = (PCache*)pPtr; pPtr += ROUND8(pcacheSize); |
| 56292 | 56340 | pPager->fd = (sqlite3_file*)pPtr; pPtr += ROUND8(pVfs->szOsFile); |
| 56293 | 56341 | pPager->sjfd = (sqlite3_file*)pPtr; pPtr += journalFileSize; |
| 56294 | 56342 | pPager->jfd = (sqlite3_file*)pPtr; pPtr += journalFileSize; |
| 56295 | 56343 | assert( EIGHT_BYTE_ALIGNMENT(pPager->jfd) ); |
| 56344 | + memcpy(pPtr, &pPager, sizeof(pPager)); pPtr += sizeof(pPager); |
| 56296 | 56345 | |
| 56297 | 56346 | /* Fill in the Pager.zFilename and pPager.zQueryParam fields */ |
| 56298 | 56347 | pPtr += 4; /* Skip zero prefix */ |
| 56299 | 56348 | pPager->zFilename = (char*)pPtr; |
| 56300 | 56349 | if( nPathname>0 ){ |
| | @@ -56491,10 +56540,23 @@ |
| 56491 | 56540 | |
| 56492 | 56541 | *ppPager = pPager; |
| 56493 | 56542 | return SQLITE_OK; |
| 56494 | 56543 | } |
| 56495 | 56544 | |
| 56545 | +/* |
| 56546 | +** Return the sqlite3_file for the main database given the name |
| 56547 | +** of the corresonding WAL or Journal name as passed into |
| 56548 | +** xOpen. |
| 56549 | +*/ |
| 56550 | +SQLITE_API sqlite3_file *sqlite3_database_file_object(const char *zName){ |
| 56551 | + Pager *pPager; |
| 56552 | + while( zName[-1]!=0 || zName[-2]!=0 || zName[-3]!=0 || zName[-4]!=0 ){ |
| 56553 | + zName--; |
| 56554 | + } |
| 56555 | + pPager = *(Pager**)(zName - 4 - sizeof(Pager*)); |
| 56556 | + return pPager->fd; |
| 56557 | +} |
| 56496 | 56558 | |
| 56497 | 56559 | |
| 56498 | 56560 | /* |
| 56499 | 56561 | ** This function is called after transitioning from PAGER_UNLOCK to |
| 56500 | 56562 | ** PAGER_SHARED state. It tests if there is a hot journal present in |
| | @@ -61023,10 +61085,11 @@ |
| 61023 | 61085 | ** about the eventual size of the db file to the VFS layer. |
| 61024 | 61086 | */ |
| 61025 | 61087 | if( rc==SQLITE_OK ){ |
| 61026 | 61088 | i64 nReq = ((i64)mxPage * szPage); |
| 61027 | 61089 | i64 nSize; /* Current size of database file */ |
| 61090 | + sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_START, 0); |
| 61028 | 61091 | rc = sqlite3OsFileSize(pWal->pDbFd, &nSize); |
| 61029 | 61092 | if( rc==SQLITE_OK && nSize<nReq ){ |
| 61030 | 61093 | sqlite3OsFileControlHint(pWal->pDbFd, SQLITE_FCNTL_SIZE_HINT, &nReq); |
| 61031 | 61094 | } |
| 61032 | 61095 | } |
| | @@ -61050,10 +61113,11 @@ |
| 61050 | 61113 | iOffset = (iDbpage-1)*(i64)szPage; |
| 61051 | 61114 | testcase( IS_BIG_INT(iOffset) ); |
| 61052 | 61115 | rc = sqlite3OsWrite(pWal->pDbFd, zBuf, szPage, iOffset); |
| 61053 | 61116 | if( rc!=SQLITE_OK ) break; |
| 61054 | 61117 | } |
| 61118 | + sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0); |
| 61055 | 61119 | |
| 61056 | 61120 | /* If work was actually accomplished... */ |
| 61057 | 61121 | if( rc==SQLITE_OK ){ |
| 61058 | 61122 | if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){ |
| 61059 | 61123 | i64 szDb = pWal->hdr.nPage*(i64)szPage; |
| | @@ -61061,14 +61125,10 @@ |
| 61061 | 61125 | rc = sqlite3OsTruncate(pWal->pDbFd, szDb); |
| 61062 | 61126 | if( rc==SQLITE_OK ){ |
| 61063 | 61127 | rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags)); |
| 61064 | 61128 | } |
| 61065 | 61129 | } |
| 61066 | | - if( rc==SQLITE_OK ){ |
| 61067 | | - rc = sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_CKPT_DONE, 0); |
| 61068 | | - if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 61069 | | - } |
| 61070 | 61130 | if( rc==SQLITE_OK ){ |
| 61071 | 61131 | pInfo->nBackfill = mxSafeFrame; |
| 61072 | 61132 | } |
| 61073 | 61133 | } |
| 61074 | 61134 | |
| | @@ -66965,10 +67025,14 @@ |
| 66965 | 67025 | |
| 66966 | 67026 | /* |
| 66967 | 67027 | ** Return the number of bytes of space at the end of every page that |
| 66968 | 67028 | ** are intentually left unused. This is the "reserved" space that is |
| 66969 | 67029 | ** sometimes used by extensions. |
| 67030 | +** |
| 67031 | +** The value returned is the larger of the current reserve size and |
| 67032 | +** the latest reserve size requested by SQLITE_FILECTRL_RESERVE_BYTES. |
| 67033 | +** The amount of reserve can only grow - never shrink. |
| 66970 | 67034 | */ |
| 66971 | 67035 | SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree *p){ |
| 66972 | 67036 | int n; |
| 66973 | 67037 | sqlite3BtreeEnter(p); |
| 66974 | 67038 | n = ((int)p->pBt->nReserveWanted) - 1; |
| | @@ -73560,11 +73624,10 @@ |
| 73560 | 73624 | } |
| 73561 | 73625 | sqlite3BtreeLeave(p); |
| 73562 | 73626 | return rc; |
| 73563 | 73627 | } |
| 73564 | 73628 | |
| 73565 | | -#ifndef SQLITE_OMIT_BTREECOUNT |
| 73566 | 73629 | /* |
| 73567 | 73630 | ** The first argument, pCur, is a cursor opened on some b-tree. Count the |
| 73568 | 73631 | ** number of entries in the b-tree and write the result to *pnEntry. |
| 73569 | 73632 | ** |
| 73570 | 73633 | ** SQLITE_OK is returned if the operation is successfully executed. |
| | @@ -73633,11 +73696,10 @@ |
| 73633 | 73696 | } |
| 73634 | 73697 | |
| 73635 | 73698 | /* An error has occurred. Return an error code. */ |
| 73636 | 73699 | return rc; |
| 73637 | 73700 | } |
| 73638 | | -#endif |
| 73639 | 73701 | |
| 73640 | 73702 | /* |
| 73641 | 73703 | ** Return the pager associated with a BTree. This routine is used for |
| 73642 | 73704 | ** testing and debugging only. |
| 73643 | 73705 | */ |
| | @@ -78709,24 +78771,23 @@ |
| 78709 | 78771 | ** "PX" -> "r[X]" |
| 78710 | 78772 | ** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1 |
| 78711 | 78773 | ** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0 |
| 78712 | 78774 | ** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x |
| 78713 | 78775 | */ |
| 78714 | | -static int displayComment( |
| 78776 | +SQLITE_PRIVATE char *sqlite3VdbeDisplayComment( |
| 78777 | + sqlite3 *db, /* Optional - Oom error reporting only */ |
| 78715 | 78778 | const Op *pOp, /* The opcode to be commented */ |
| 78716 | | - const char *zP4, /* Previously obtained value for P4 */ |
| 78717 | | - char *zTemp, /* Write result here */ |
| 78718 | | - int nTemp /* Space available in zTemp[] */ |
| 78779 | + const char *zP4 /* Previously obtained value for P4 */ |
| 78719 | 78780 | ){ |
| 78720 | 78781 | const char *zOpName; |
| 78721 | 78782 | const char *zSynopsis; |
| 78722 | 78783 | int nOpName; |
| 78723 | 78784 | int ii; |
| 78724 | 78785 | char zAlt[50]; |
| 78725 | 78786 | StrAccum x; |
| 78726 | | - sqlite3StrAccumInit(&x, 0, zTemp, nTemp, 0); |
| 78727 | 78787 | |
| 78788 | + sqlite3StrAccumInit(&x, 0, 0, 0, SQLITE_MAX_LENGTH); |
| 78728 | 78789 | zOpName = sqlite3OpcodeName(pOp->opcode); |
| 78729 | 78790 | nOpName = sqlite3Strlen30(zOpName); |
| 78730 | 78791 | if( zOpName[nOpName+1] ){ |
| 78731 | 78792 | int seenCom = 0; |
| 78732 | 78793 | char c; |
| | @@ -78789,14 +78850,16 @@ |
| 78789 | 78850 | sqlite3_str_appendf(&x, "; %s", pOp->zComment); |
| 78790 | 78851 | } |
| 78791 | 78852 | }else if( pOp->zComment ){ |
| 78792 | 78853 | sqlite3_str_appendall(&x, pOp->zComment); |
| 78793 | 78854 | } |
| 78794 | | - sqlite3StrAccumFinish(&x); |
| 78795 | | - return x.nChar; |
| 78855 | + if( (x.accError & SQLITE_NOMEM)!=0 && db!=0 ){ |
| 78856 | + sqlite3OomFault(db); |
| 78857 | + } |
| 78858 | + return sqlite3StrAccumFinish(&x); |
| 78796 | 78859 | } |
| 78797 | | -#endif /* SQLITE_DEBUG */ |
| 78860 | +#endif /* SQLITE_ENABLE_EXPLAIN_COMMENTS */ |
| 78798 | 78861 | |
| 78799 | 78862 | #if VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) |
| 78800 | 78863 | /* |
| 78801 | 78864 | ** Translate the P4.pExpr value for an OP_CursorHint opcode into text |
| 78802 | 78865 | ** that can be displayed in the P4 column of EXPLAIN output. |
| | @@ -78873,15 +78936,15 @@ |
| 78873 | 78936 | #if VDBE_DISPLAY_P4 |
| 78874 | 78937 | /* |
| 78875 | 78938 | ** Compute a string that describes the P4 parameter for an opcode. |
| 78876 | 78939 | ** Use zTemp for any required temporary buffer space. |
| 78877 | 78940 | */ |
| 78878 | | -static char *displayP4(Op *pOp, char *zTemp, int nTemp){ |
| 78879 | | - char *zP4 = zTemp; |
| 78941 | +SQLITE_PRIVATE char *sqlite3VdbeDisplayP4(sqlite3 *db, Op *pOp){ |
| 78942 | + char *zP4 = 0; |
| 78880 | 78943 | StrAccum x; |
| 78881 | | - assert( nTemp>=20 ); |
| 78882 | | - sqlite3StrAccumInit(&x, 0, zTemp, nTemp, 0); |
| 78944 | + |
| 78945 | + sqlite3StrAccumInit(&x, 0, 0, 0, SQLITE_MAX_LENGTH); |
| 78883 | 78946 | switch( pOp->p4type ){ |
| 78884 | 78947 | case P4_KEYINFO: { |
| 78885 | 78948 | int j; |
| 78886 | 78949 | KeyInfo *pKeyInfo = pOp->p4.pKeyInfo; |
| 78887 | 78950 | assert( pKeyInfo->aSortFlags!=0 ); |
| | @@ -78961,40 +79024,36 @@ |
| 78961 | 79024 | int i; |
| 78962 | 79025 | int *ai = pOp->p4.ai; |
| 78963 | 79026 | int n = ai[0]; /* The first element of an INTARRAY is always the |
| 78964 | 79027 | ** count of the number of elements to follow */ |
| 78965 | 79028 | for(i=1; i<=n; i++){ |
| 78966 | | - sqlite3_str_appendf(&x, ",%d", ai[i]); |
| 79029 | + sqlite3_str_appendf(&x, "%c%d", (i==1 ? '[' : ','), ai[i]); |
| 78967 | 79030 | } |
| 78968 | | - zTemp[0] = '['; |
| 78969 | 79031 | sqlite3_str_append(&x, "]", 1); |
| 78970 | 79032 | break; |
| 78971 | 79033 | } |
| 78972 | 79034 | case P4_SUBPROGRAM: { |
| 78973 | | - sqlite3_str_appendf(&x, "program"); |
| 79035 | + zP4 = "program"; |
| 78974 | 79036 | break; |
| 78975 | 79037 | } |
| 78976 | 79038 | case P4_DYNBLOB: |
| 78977 | 79039 | case P4_ADVANCE: { |
| 78978 | | - zTemp[0] = 0; |
| 78979 | 79040 | break; |
| 78980 | 79041 | } |
| 78981 | 79042 | case P4_TABLE: { |
| 78982 | | - sqlite3_str_appendf(&x, "%s", pOp->p4.pTab->zName); |
| 79043 | + zP4 = pOp->p4.pTab->zName; |
| 78983 | 79044 | break; |
| 78984 | 79045 | } |
| 78985 | 79046 | default: { |
| 78986 | 79047 | zP4 = pOp->p4.z; |
| 78987 | | - if( zP4==0 ){ |
| 78988 | | - zP4 = zTemp; |
| 78989 | | - zTemp[0] = 0; |
| 78990 | | - } |
| 78991 | 79048 | } |
| 78992 | 79049 | } |
| 78993 | | - sqlite3StrAccumFinish(&x); |
| 78994 | | - assert( zP4!=0 ); |
| 78995 | | - return zP4; |
| 79050 | + if( zP4 ) sqlite3_str_appendall(&x, zP4); |
| 79051 | + if( (x.accError & SQLITE_NOMEM)!=0 ){ |
| 79052 | + sqlite3OomFault(db); |
| 79053 | + } |
| 79054 | + return sqlite3StrAccumFinish(&x); |
| 78996 | 79055 | } |
| 78997 | 79056 | #endif /* VDBE_DISPLAY_P4 */ |
| 78998 | 79057 | |
| 78999 | 79058 | /* |
| 79000 | 79059 | ** Declare to the Vdbe that the BTree object at db->aDb[i] is used. |
| | @@ -79080,28 +79139,32 @@ |
| 79080 | 79139 | /* |
| 79081 | 79140 | ** Print a single opcode. This routine is used for debugging only. |
| 79082 | 79141 | */ |
| 79083 | 79142 | SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE *pOut, int pc, VdbeOp *pOp){ |
| 79084 | 79143 | char *zP4; |
| 79085 | | - char zPtr[50]; |
| 79086 | | - char zCom[100]; |
| 79144 | + char *zCom; |
| 79145 | + sqlite3 dummyDb; |
| 79087 | 79146 | static const char *zFormat1 = "%4d %-13s %4d %4d %4d %-13s %.2X %s\n"; |
| 79088 | 79147 | if( pOut==0 ) pOut = stdout; |
| 79089 | | - zP4 = displayP4(pOp, zPtr, sizeof(zPtr)); |
| 79148 | + dummyDb.mallocFailed = 1; |
| 79149 | + zP4 = sqlite3VdbeDisplayP4(&dummyDb, pOp); |
| 79090 | 79150 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 79091 | | - displayComment(pOp, zP4, zCom, sizeof(zCom)); |
| 79151 | + zCom = sqlite3VdbeDisplayComment(0, pOp, zP4); |
| 79092 | 79152 | #else |
| 79093 | | - zCom[0] = 0; |
| 79153 | + zCom = 0; |
| 79094 | 79154 | #endif |
| 79095 | 79155 | /* NB: The sqlite3OpcodeName() function is implemented by code created |
| 79096 | 79156 | ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the |
| 79097 | 79157 | ** information from the vdbe.c source text */ |
| 79098 | 79158 | fprintf(pOut, zFormat1, pc, |
| 79099 | | - sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5, |
| 79100 | | - zCom |
| 79159 | + sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, |
| 79160 | + zP4 ? zP4 : "", pOp->p5, |
| 79161 | + zCom ? zCom : "" |
| 79101 | 79162 | ); |
| 79102 | 79163 | fflush(pOut); |
| 79164 | + sqlite3_free(zP4); |
| 79165 | + sqlite3_free(zCom); |
| 79103 | 79166 | } |
| 79104 | 79167 | #endif |
| 79105 | 79168 | |
| 79106 | 79169 | /* |
| 79107 | 79170 | ** Initialize an array of N Mem element. |
| | @@ -79188,10 +79251,125 @@ |
| 79188 | 79251 | assert( sqlite3VdbeFrameIsValid(pFrame) ); |
| 79189 | 79252 | pFrame->pParent = pFrame->v->pDelFrame; |
| 79190 | 79253 | pFrame->v->pDelFrame = pFrame; |
| 79191 | 79254 | } |
| 79192 | 79255 | |
| 79256 | +#if defined(SQLITE_ENABLE_BYTECODE_VTAB) || !defined(SQLITE_OMIT_EXPLAIN) |
| 79257 | +/* |
| 79258 | +** Locate the next opcode to be displayed in EXPLAIN or EXPLAIN |
| 79259 | +** QUERY PLAN output. |
| 79260 | +** |
| 79261 | +** Return SQLITE_ROW on success. Return SQLITE_DONE if there are no |
| 79262 | +** more opcodes to be displayed. |
| 79263 | +*/ |
| 79264 | +SQLITE_PRIVATE int sqlite3VdbeNextOpcode( |
| 79265 | + Vdbe *p, /* The statement being explained */ |
| 79266 | + Mem *pSub, /* Storage for keeping track of subprogram nesting */ |
| 79267 | + int eMode, /* 0: normal. 1: EQP. 2: TablesUsed */ |
| 79268 | + int *piPc, /* IN/OUT: Current rowid. Overwritten with next rowid */ |
| 79269 | + int *piAddr, /* OUT: Write index into (*paOp)[] here */ |
| 79270 | + Op **paOp /* OUT: Write the opcode array here */ |
| 79271 | +){ |
| 79272 | + int nRow; /* Stop when row count reaches this */ |
| 79273 | + int nSub = 0; /* Number of sub-vdbes seen so far */ |
| 79274 | + SubProgram **apSub = 0; /* Array of sub-vdbes */ |
| 79275 | + int i; /* Next instruction address */ |
| 79276 | + int rc = SQLITE_OK; /* Result code */ |
| 79277 | + Op *aOp = 0; /* Opcode array */ |
| 79278 | + int iPc; /* Rowid. Copy of value in *piPc */ |
| 79279 | + |
| 79280 | + /* When the number of output rows reaches nRow, that means the |
| 79281 | + ** listing has finished and sqlite3_step() should return SQLITE_DONE. |
| 79282 | + ** nRow is the sum of the number of rows in the main program, plus |
| 79283 | + ** the sum of the number of rows in all trigger subprograms encountered |
| 79284 | + ** so far. The nRow value will increase as new trigger subprograms are |
| 79285 | + ** encountered, but p->pc will eventually catch up to nRow. |
| 79286 | + */ |
| 79287 | + nRow = p->nOp; |
| 79288 | + if( pSub!=0 ){ |
| 79289 | + if( pSub->flags&MEM_Blob ){ |
| 79290 | + /* pSub is initiallly NULL. It is initialized to a BLOB by |
| 79291 | + ** the P4_SUBPROGRAM processing logic below */ |
| 79292 | + nSub = pSub->n/sizeof(Vdbe*); |
| 79293 | + apSub = (SubProgram **)pSub->z; |
| 79294 | + } |
| 79295 | + for(i=0; i<nSub; i++){ |
| 79296 | + nRow += apSub[i]->nOp; |
| 79297 | + } |
| 79298 | + } |
| 79299 | + iPc = *piPc; |
| 79300 | + while(1){ /* Loop exits via break */ |
| 79301 | + i = iPc++; |
| 79302 | + if( i>=nRow ){ |
| 79303 | + p->rc = SQLITE_OK; |
| 79304 | + rc = SQLITE_DONE; |
| 79305 | + break; |
| 79306 | + } |
| 79307 | + if( i<p->nOp ){ |
| 79308 | + /* The rowid is small enough that we are still in the |
| 79309 | + ** main program. */ |
| 79310 | + aOp = p->aOp; |
| 79311 | + }else{ |
| 79312 | + /* We are currently listing subprograms. Figure out which one and |
| 79313 | + ** pick up the appropriate opcode. */ |
| 79314 | + int j; |
| 79315 | + i -= p->nOp; |
| 79316 | + assert( apSub!=0 ); |
| 79317 | + assert( nSub>0 ); |
| 79318 | + for(j=0; i>=apSub[j]->nOp; j++){ |
| 79319 | + i -= apSub[j]->nOp; |
| 79320 | + assert( i<apSub[j]->nOp || j+1<nSub ); |
| 79321 | + } |
| 79322 | + aOp = apSub[j]->aOp; |
| 79323 | + } |
| 79324 | + |
| 79325 | + /* When an OP_Program opcode is encounter (the only opcode that has |
| 79326 | + ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms |
| 79327 | + ** kept in p->aMem[9].z to hold the new program - assuming this subprogram |
| 79328 | + ** has not already been seen. |
| 79329 | + */ |
| 79330 | + if( pSub!=0 && aOp[i].p4type==P4_SUBPROGRAM ){ |
| 79331 | + int nByte = (nSub+1)*sizeof(SubProgram*); |
| 79332 | + int j; |
| 79333 | + for(j=0; j<nSub; j++){ |
| 79334 | + if( apSub[j]==aOp[i].p4.pProgram ) break; |
| 79335 | + } |
| 79336 | + if( j==nSub ){ |
| 79337 | + p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0); |
| 79338 | + if( p->rc!=SQLITE_OK ){ |
| 79339 | + rc = SQLITE_ERROR; |
| 79340 | + break; |
| 79341 | + } |
| 79342 | + apSub = (SubProgram **)pSub->z; |
| 79343 | + apSub[nSub++] = aOp[i].p4.pProgram; |
| 79344 | + MemSetTypeFlag(pSub, MEM_Blob); |
| 79345 | + pSub->n = nSub*sizeof(SubProgram*); |
| 79346 | + nRow += aOp[i].p4.pProgram->nOp; |
| 79347 | + } |
| 79348 | + } |
| 79349 | + if( eMode==0 ) break; |
| 79350 | +#ifdef SQLITE_ENABLE_BYTECODE_VTAB |
| 79351 | + if( eMode==2 ){ |
| 79352 | + Op *pOp = aOp + i; |
| 79353 | + if( pOp->opcode==OP_OpenRead ) break; |
| 79354 | + if( pOp->opcode==OP_OpenWrite && (pOp->p5 & OPFLAG_P2ISREG)==0 ) break; |
| 79355 | + if( pOp->opcode==OP_ReopenIdx ) break; |
| 79356 | + }else |
| 79357 | +#endif |
| 79358 | + { |
| 79359 | + assert( eMode==1 ); |
| 79360 | + if( aOp[i].opcode==OP_Explain ) break; |
| 79361 | + if( aOp[i].opcode==OP_Init && iPc>1 ) break; |
| 79362 | + } |
| 79363 | + } |
| 79364 | + *piPc = iPc; |
| 79365 | + *piAddr = i; |
| 79366 | + *paOp = aOp; |
| 79367 | + return rc; |
| 79368 | +} |
| 79369 | +#endif /* SQLITE_ENABLE_BYTECODE_VTAB || !SQLITE_OMIT_EXPLAIN */ |
| 79370 | + |
| 79193 | 79371 | |
| 79194 | 79372 | /* |
| 79195 | 79373 | ** Delete a VdbeFrame object and its contents. VdbeFrame objects are |
| 79196 | 79374 | ** allocated by the OP_Program opcode in sqlite3VdbeExec(). |
| 79197 | 79375 | */ |
| | @@ -79228,20 +79406,18 @@ |
| 79228 | 79406 | ** the trigger subprograms are listed one by one. |
| 79229 | 79407 | */ |
| 79230 | 79408 | SQLITE_PRIVATE int sqlite3VdbeList( |
| 79231 | 79409 | Vdbe *p /* The VDBE */ |
| 79232 | 79410 | ){ |
| 79233 | | - int nRow; /* Stop when row count reaches this */ |
| 79234 | | - int nSub = 0; /* Number of sub-vdbes seen so far */ |
| 79235 | | - SubProgram **apSub = 0; /* Array of sub-vdbes */ |
| 79236 | 79411 | Mem *pSub = 0; /* Memory cell hold array of subprogs */ |
| 79237 | 79412 | sqlite3 *db = p->db; /* The database connection */ |
| 79238 | 79413 | int i; /* Loop counter */ |
| 79239 | 79414 | int rc = SQLITE_OK; /* Return code */ |
| 79240 | 79415 | Mem *pMem = &p->aMem[1]; /* First Mem of result set */ |
| 79241 | 79416 | int bListSubprogs = (p->explain==1 || (db->flags & SQLITE_TriggerEQP)!=0); |
| 79242 | | - Op *pOp = 0; |
| 79417 | + Op *aOp; /* Array of opcodes */ |
| 79418 | + Op *pOp; /* Current opcode */ |
| 79243 | 79419 | |
| 79244 | 79420 | assert( p->explain ); |
| 79245 | 79421 | assert( p->magic==VDBE_MAGIC_RUN ); |
| 79246 | 79422 | assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY || p->rc==SQLITE_NOMEM ); |
| 79247 | 79423 | |
| | @@ -79257,166 +79433,66 @@ |
| 79257 | 79433 | ** sqlite3_column_text16() failed. */ |
| 79258 | 79434 | sqlite3OomFault(db); |
| 79259 | 79435 | return SQLITE_ERROR; |
| 79260 | 79436 | } |
| 79261 | 79437 | |
| 79262 | | - /* When the number of output rows reaches nRow, that means the |
| 79263 | | - ** listing has finished and sqlite3_step() should return SQLITE_DONE. |
| 79264 | | - ** nRow is the sum of the number of rows in the main program, plus |
| 79265 | | - ** the sum of the number of rows in all trigger subprograms encountered |
| 79266 | | - ** so far. The nRow value will increase as new trigger subprograms are |
| 79267 | | - ** encountered, but p->pc will eventually catch up to nRow. |
| 79268 | | - */ |
| 79269 | | - nRow = p->nOp; |
| 79270 | 79438 | if( bListSubprogs ){ |
| 79271 | 79439 | /* The first 8 memory cells are used for the result set. So we will |
| 79272 | 79440 | ** commandeer the 9th cell to use as storage for an array of pointers |
| 79273 | 79441 | ** to trigger subprograms. The VDBE is guaranteed to have at least 9 |
| 79274 | 79442 | ** cells. */ |
| 79275 | 79443 | assert( p->nMem>9 ); |
| 79276 | 79444 | pSub = &p->aMem[9]; |
| 79277 | | - if( pSub->flags&MEM_Blob ){ |
| 79278 | | - /* On the first call to sqlite3_step(), pSub will hold a NULL. It is |
| 79279 | | - ** initialized to a BLOB by the P4_SUBPROGRAM processing logic below */ |
| 79280 | | - nSub = pSub->n/sizeof(Vdbe*); |
| 79281 | | - apSub = (SubProgram **)pSub->z; |
| 79282 | | - } |
| 79283 | | - for(i=0; i<nSub; i++){ |
| 79284 | | - nRow += apSub[i]->nOp; |
| 79285 | | - } |
| 79286 | | - } |
| 79287 | | - |
| 79288 | | - while(1){ /* Loop exits via break */ |
| 79289 | | - i = p->pc++; |
| 79290 | | - if( i>=nRow ){ |
| 79291 | | - p->rc = SQLITE_OK; |
| 79292 | | - rc = SQLITE_DONE; |
| 79293 | | - break; |
| 79294 | | - } |
| 79295 | | - if( i<p->nOp ){ |
| 79296 | | - /* The output line number is small enough that we are still in the |
| 79297 | | - ** main program. */ |
| 79298 | | - pOp = &p->aOp[i]; |
| 79299 | | - }else{ |
| 79300 | | - /* We are currently listing subprograms. Figure out which one and |
| 79301 | | - ** pick up the appropriate opcode. */ |
| 79302 | | - int j; |
| 79303 | | - i -= p->nOp; |
| 79304 | | - assert( apSub!=0 ); |
| 79305 | | - assert( nSub>0 ); |
| 79306 | | - for(j=0; i>=apSub[j]->nOp; j++){ |
| 79307 | | - i -= apSub[j]->nOp; |
| 79308 | | - assert( i<apSub[j]->nOp || j+1<nSub ); |
| 79309 | | - } |
| 79310 | | - pOp = &apSub[j]->aOp[i]; |
| 79311 | | - } |
| 79312 | | - |
| 79313 | | - /* When an OP_Program opcode is encounter (the only opcode that has |
| 79314 | | - ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms |
| 79315 | | - ** kept in p->aMem[9].z to hold the new program - assuming this subprogram |
| 79316 | | - ** has not already been seen. |
| 79317 | | - */ |
| 79318 | | - if( bListSubprogs && pOp->p4type==P4_SUBPROGRAM ){ |
| 79319 | | - int nByte = (nSub+1)*sizeof(SubProgram*); |
| 79320 | | - int j; |
| 79321 | | - for(j=0; j<nSub; j++){ |
| 79322 | | - if( apSub[j]==pOp->p4.pProgram ) break; |
| 79323 | | - } |
| 79324 | | - if( j==nSub ){ |
| 79325 | | - p->rc = sqlite3VdbeMemGrow(pSub, nByte, nSub!=0); |
| 79326 | | - if( p->rc!=SQLITE_OK ){ |
| 79327 | | - rc = SQLITE_ERROR; |
| 79328 | | - break; |
| 79329 | | - } |
| 79330 | | - apSub = (SubProgram **)pSub->z; |
| 79331 | | - apSub[nSub++] = pOp->p4.pProgram; |
| 79332 | | - pSub->flags |= MEM_Blob; |
| 79333 | | - pSub->n = nSub*sizeof(SubProgram*); |
| 79334 | | - nRow += pOp->p4.pProgram->nOp; |
| 79335 | | - } |
| 79336 | | - } |
| 79337 | | - if( p->explain<2 ) break; |
| 79338 | | - if( pOp->opcode==OP_Explain ) break; |
| 79339 | | - if( pOp->opcode==OP_Init && p->pc>1 ) break; |
| 79340 | | - } |
| 79341 | | - |
| 79342 | | - if( rc==SQLITE_OK ){ |
| 79445 | + }else{ |
| 79446 | + pSub = 0; |
| 79447 | + } |
| 79448 | + |
| 79449 | + /* Figure out which opcode is next to display */ |
| 79450 | + rc = sqlite3VdbeNextOpcode(p, pSub, p->explain==2, &p->pc, &i, &aOp); |
| 79451 | + |
| 79452 | + if( rc==SQLITE_OK ){ |
| 79453 | + pOp = aOp + i; |
| 79343 | 79454 | if( AtomicLoad(&db->u1.isInterrupted) ){ |
| 79344 | 79455 | p->rc = SQLITE_INTERRUPT; |
| 79345 | 79456 | rc = SQLITE_ERROR; |
| 79346 | 79457 | sqlite3VdbeError(p, sqlite3ErrStr(p->rc)); |
| 79347 | 79458 | }else{ |
| 79348 | | - char *zP4; |
| 79349 | | - if( p->explain==1 ){ |
| 79350 | | - pMem->flags = MEM_Int; |
| 79351 | | - pMem->u.i = i; /* Program counter */ |
| 79352 | | - pMem++; |
| 79353 | | - |
| 79354 | | - pMem->flags = MEM_Static|MEM_Str|MEM_Term; |
| 79355 | | - pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */ |
| 79356 | | - assert( pMem->z!=0 ); |
| 79357 | | - pMem->n = sqlite3Strlen30(pMem->z); |
| 79358 | | - pMem->enc = SQLITE_UTF8; |
| 79359 | | - pMem++; |
| 79360 | | - } |
| 79361 | | - |
| 79362 | | - pMem->flags = MEM_Int; |
| 79363 | | - pMem->u.i = pOp->p1; /* P1 */ |
| 79364 | | - pMem++; |
| 79365 | | - |
| 79366 | | - pMem->flags = MEM_Int; |
| 79367 | | - pMem->u.i = pOp->p2; /* P2 */ |
| 79368 | | - pMem++; |
| 79369 | | - |
| 79370 | | - pMem->flags = MEM_Int; |
| 79371 | | - pMem->u.i = pOp->p3; /* P3 */ |
| 79372 | | - pMem++; |
| 79373 | | - |
| 79374 | | - if( sqlite3VdbeMemClearAndResize(pMem, 100) ){ /* P4 */ |
| 79375 | | - assert( p->db->mallocFailed ); |
| 79376 | | - return SQLITE_ERROR; |
| 79377 | | - } |
| 79378 | | - pMem->flags = MEM_Str|MEM_Term; |
| 79379 | | - zP4 = displayP4(pOp, pMem->z, pMem->szMalloc); |
| 79380 | | - if( zP4!=pMem->z ){ |
| 79381 | | - pMem->n = 0; |
| 79382 | | - sqlite3VdbeMemSetStr(pMem, zP4, -1, SQLITE_UTF8, 0); |
| 79459 | + char *zP4 = sqlite3VdbeDisplayP4(db, pOp); |
| 79460 | + if( p->explain==2 ){ |
| 79461 | + sqlite3VdbeMemSetInt64(pMem, pOp->p1); |
| 79462 | + sqlite3VdbeMemSetInt64(pMem+1, pOp->p2); |
| 79463 | + sqlite3VdbeMemSetInt64(pMem+2, pOp->p3); |
| 79464 | + sqlite3VdbeMemSetStr(pMem+3, zP4, -1, SQLITE_UTF8, sqlite3_free); |
| 79465 | + p->nResColumn = 4; |
| 79383 | 79466 | }else{ |
| 79384 | | - assert( pMem->z!=0 ); |
| 79385 | | - pMem->n = sqlite3Strlen30(pMem->z); |
| 79386 | | - pMem->enc = SQLITE_UTF8; |
| 79387 | | - } |
| 79388 | | - pMem++; |
| 79389 | | - |
| 79390 | | - if( p->explain==1 ){ |
| 79391 | | - if( sqlite3VdbeMemClearAndResize(pMem, 4) ){ |
| 79392 | | - assert( p->db->mallocFailed ); |
| 79393 | | - return SQLITE_ERROR; |
| 79394 | | - } |
| 79395 | | - pMem->flags = MEM_Str|MEM_Term; |
| 79396 | | - pMem->n = 2; |
| 79397 | | - sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */ |
| 79398 | | - pMem->enc = SQLITE_UTF8; |
| 79399 | | - pMem++; |
| 79400 | | - |
| 79467 | + sqlite3VdbeMemSetInt64(pMem+0, i); |
| 79468 | + sqlite3VdbeMemSetStr(pMem+1, (char*)sqlite3OpcodeName(pOp->opcode), |
| 79469 | + -1, SQLITE_UTF8, SQLITE_STATIC); |
| 79470 | + sqlite3VdbeMemSetInt64(pMem+2, pOp->p1); |
| 79471 | + sqlite3VdbeMemSetInt64(pMem+3, pOp->p2); |
| 79472 | + sqlite3VdbeMemSetInt64(pMem+4, pOp->p3); |
| 79473 | + /* pMem+5 for p4 is done last */ |
| 79474 | + sqlite3VdbeMemSetInt64(pMem+6, pOp->p5); |
| 79401 | 79475 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 79402 | | - if( sqlite3VdbeMemClearAndResize(pMem, 500) ){ |
| 79403 | | - assert( p->db->mallocFailed ); |
| 79404 | | - return SQLITE_ERROR; |
| 79405 | | - } |
| 79406 | | - pMem->flags = MEM_Str|MEM_Term; |
| 79407 | | - pMem->n = displayComment(pOp, zP4, pMem->z, 500); |
| 79408 | | - pMem->enc = SQLITE_UTF8; |
| 79409 | | -#else |
| 79410 | | - pMem->flags = MEM_Null; /* Comment */ |
| 79411 | | -#endif |
| 79412 | | - } |
| 79413 | | - |
| 79414 | | - p->nResColumn = 8 - 4*(p->explain-1); |
| 79415 | | - p->pResultSet = &p->aMem[1]; |
| 79416 | | - p->rc = SQLITE_OK; |
| 79417 | | - rc = SQLITE_ROW; |
| 79476 | + { |
| 79477 | + char *zCom = sqlite3VdbeDisplayComment(db, pOp, zP4); |
| 79478 | + sqlite3VdbeMemSetStr(pMem+7, zCom, -1, SQLITE_UTF8, sqlite3_free); |
| 79479 | + } |
| 79480 | +#else |
| 79481 | + sqlite3VdbeMemSetNull(pMem+7); |
| 79482 | +#endif |
| 79483 | + sqlite3VdbeMemSetStr(pMem+5, zP4, -1, SQLITE_UTF8, sqlite3_free); |
| 79484 | + p->nResColumn = 8; |
| 79485 | + } |
| 79486 | + p->pResultSet = pMem; |
| 79487 | + if( db->mallocFailed ){ |
| 79488 | + p->rc = SQLITE_NOMEM; |
| 79489 | + rc = SQLITE_ERROR; |
| 79490 | + }else{ |
| 79491 | + p->rc = SQLITE_OK; |
| 79492 | + rc = SQLITE_ROW; |
| 79493 | + } |
| 79418 | 79494 | } |
| 79419 | 79495 | } |
| 79420 | 79496 | return rc; |
| 79421 | 79497 | } |
| 79422 | 79498 | #endif /* SQLITE_OMIT_EXPLAIN */ |
| | @@ -79982,12 +80058,13 @@ |
| 79982 | 80058 | int retryCount = 0; |
| 79983 | 80059 | int nMainFile; |
| 79984 | 80060 | |
| 79985 | 80061 | /* Select a master journal file name */ |
| 79986 | 80062 | nMainFile = sqlite3Strlen30(zMainFile); |
| 79987 | | - zMaster = sqlite3MPrintf(db, "%s-mjXXXXXX9XXz%c%c", zMainFile, 0, 0); |
| 80063 | + zMaster = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0); |
| 79988 | 80064 | if( zMaster==0 ) return SQLITE_NOMEM_BKPT; |
| 80065 | + zMaster += 4; |
| 79989 | 80066 | do { |
| 79990 | 80067 | u32 iRandom; |
| 79991 | 80068 | if( retryCount ){ |
| 79992 | 80069 | if( retryCount>100 ){ |
| 79993 | 80070 | sqlite3_log(SQLITE_FULL, "MJ delete: %s", zMaster); |
| | @@ -80013,11 +80090,11 @@ |
| 80013 | 80090 | SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| |
| 80014 | 80091 | SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_MASTER_JOURNAL, 0 |
| 80015 | 80092 | ); |
| 80016 | 80093 | } |
| 80017 | 80094 | if( rc!=SQLITE_OK ){ |
| 80018 | | - sqlite3DbFree(db, zMaster); |
| 80095 | + sqlite3DbFree(db, zMaster-4); |
| 80019 | 80096 | return rc; |
| 80020 | 80097 | } |
| 80021 | 80098 | |
| 80022 | 80099 | /* Write the name of each database file in the transaction into the new |
| 80023 | 80100 | ** master journal file. If an error occurs at this point close |
| | @@ -80036,11 +80113,11 @@ |
| 80036 | 80113 | rc = sqlite3OsWrite(pMaster, zFile, sqlite3Strlen30(zFile)+1, offset); |
| 80037 | 80114 | offset += sqlite3Strlen30(zFile)+1; |
| 80038 | 80115 | if( rc!=SQLITE_OK ){ |
| 80039 | 80116 | sqlite3OsCloseFree(pMaster); |
| 80040 | 80117 | sqlite3OsDelete(pVfs, zMaster, 0); |
| 80041 | | - sqlite3DbFree(db, zMaster); |
| 80118 | + sqlite3DbFree(db, zMaster-4); |
| 80042 | 80119 | return rc; |
| 80043 | 80120 | } |
| 80044 | 80121 | } |
| 80045 | 80122 | } |
| 80046 | 80123 | |
| | @@ -80050,11 +80127,11 @@ |
| 80050 | 80127 | if( 0==(sqlite3OsDeviceCharacteristics(pMaster)&SQLITE_IOCAP_SEQUENTIAL) |
| 80051 | 80128 | && SQLITE_OK!=(rc = sqlite3OsSync(pMaster, SQLITE_SYNC_NORMAL)) |
| 80052 | 80129 | ){ |
| 80053 | 80130 | sqlite3OsCloseFree(pMaster); |
| 80054 | 80131 | sqlite3OsDelete(pVfs, zMaster, 0); |
| 80055 | | - sqlite3DbFree(db, zMaster); |
| 80132 | + sqlite3DbFree(db, zMaster-4); |
| 80056 | 80133 | return rc; |
| 80057 | 80134 | } |
| 80058 | 80135 | |
| 80059 | 80136 | /* Sync all the db files involved in the transaction. The same call |
| 80060 | 80137 | ** sets the master journal pointer in each individual journal. If |
| | @@ -80073,20 +80150,20 @@ |
| 80073 | 80150 | } |
| 80074 | 80151 | } |
| 80075 | 80152 | sqlite3OsCloseFree(pMaster); |
| 80076 | 80153 | assert( rc!=SQLITE_BUSY ); |
| 80077 | 80154 | if( rc!=SQLITE_OK ){ |
| 80078 | | - sqlite3DbFree(db, zMaster); |
| 80155 | + sqlite3DbFree(db, zMaster-4); |
| 80079 | 80156 | return rc; |
| 80080 | 80157 | } |
| 80081 | 80158 | |
| 80082 | 80159 | /* Delete the master journal file. This commits the transaction. After |
| 80083 | 80160 | ** doing this the directory is synced again before any individual |
| 80084 | 80161 | ** transaction files are deleted. |
| 80085 | 80162 | */ |
| 80086 | 80163 | rc = sqlite3OsDelete(pVfs, zMaster, 1); |
| 80087 | | - sqlite3DbFree(db, zMaster); |
| 80164 | + sqlite3DbFree(db, zMaster-4); |
| 80088 | 80165 | zMaster = 0; |
| 80089 | 80166 | if( rc ){ |
| 80090 | 80167 | return rc; |
| 80091 | 80168 | } |
| 80092 | 80169 | |
| | @@ -87998,32 +88075,38 @@ |
| 87998 | 88075 | assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 87999 | 88076 | REGISTER_TRACE(pOp->p3, pOut); |
| 88000 | 88077 | break; |
| 88001 | 88078 | } |
| 88002 | 88079 | |
| 88003 | | -/* Opcode: Count P1 P2 * * * |
| 88080 | +/* Opcode: Count P1 P2 p3 * * |
| 88004 | 88081 | ** Synopsis: r[P2]=count() |
| 88005 | 88082 | ** |
| 88006 | 88083 | ** Store the number of entries (an integer value) in the table or index |
| 88007 | | -** opened by cursor P1 in register P2 |
| 88084 | +** opened by cursor P1 in register P2. |
| 88085 | +** |
| 88086 | +** If P3==0, then an exact count is obtained, which involves visiting |
| 88087 | +** every btree page of the table. But if P3 is non-zero, an estimate |
| 88088 | +** is returned based on the current cursor position. |
| 88008 | 88089 | */ |
| 88009 | | -#ifndef SQLITE_OMIT_BTREECOUNT |
| 88010 | 88090 | case OP_Count: { /* out2 */ |
| 88011 | 88091 | i64 nEntry; |
| 88012 | 88092 | BtCursor *pCrsr; |
| 88013 | 88093 | |
| 88014 | 88094 | assert( p->apCsr[pOp->p1]->eCurType==CURTYPE_BTREE ); |
| 88015 | 88095 | pCrsr = p->apCsr[pOp->p1]->uc.pCursor; |
| 88016 | 88096 | assert( pCrsr ); |
| 88017 | | - nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 88018 | | - rc = sqlite3BtreeCount(db, pCrsr, &nEntry); |
| 88019 | | - if( rc ) goto abort_due_to_error; |
| 88097 | + if( pOp->p3 ){ |
| 88098 | + nEntry = sqlite3BtreeRowCountEst(pCrsr); |
| 88099 | + }else{ |
| 88100 | + nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 88101 | + rc = sqlite3BtreeCount(db, pCrsr, &nEntry); |
| 88102 | + if( rc ) goto abort_due_to_error; |
| 88103 | + } |
| 88020 | 88104 | pOut = out2Prerelease(p, pOp); |
| 88021 | 88105 | pOut->u.i = nEntry; |
| 88022 | 88106 | goto check_for_interrupt; |
| 88023 | 88107 | } |
| 88024 | | -#endif |
| 88025 | 88108 | |
| 88026 | 88109 | /* Opcode: Savepoint P1 * * P4 * |
| 88027 | 88110 | ** |
| 88028 | 88111 | ** Open, release or rollback the savepoint named by parameter P4, depending |
| 88029 | 88112 | ** on the value of P1. To open a new savepoint set P1==0 (SAVEPOINT_BEGIN). |
| | @@ -96093,10 +96176,435 @@ |
| 96093 | 96176 | *pRes = sqlite3VdbeRecordCompare(pVal->n, pVal->z, r2); |
| 96094 | 96177 | return SQLITE_OK; |
| 96095 | 96178 | } |
| 96096 | 96179 | |
| 96097 | 96180 | /************** End of vdbesort.c ********************************************/ |
| 96181 | +/************** Begin file vdbevtab.c ****************************************/ |
| 96182 | +/* |
| 96183 | +** 2020-03-23 |
| 96184 | +** |
| 96185 | +** The author disclaims copyright to this source code. In place of |
| 96186 | +** a legal notice, here is a blessing: |
| 96187 | +** |
| 96188 | +** May you do good and not evil. |
| 96189 | +** May you find forgiveness for yourself and forgive others. |
| 96190 | +** May you share freely, never taking more than you give. |
| 96191 | +** |
| 96192 | +************************************************************************* |
| 96193 | +** |
| 96194 | +** This file implements virtual-tables for examining the bytecode content |
| 96195 | +** of a prepared statement. |
| 96196 | +*/ |
| 96197 | +#ifdef SQLITE_ENABLE_BYTECODE_VTAB |
| 96198 | +/* #include "sqliteInt.h" */ |
| 96199 | +/* #include "vdbeInt.h" */ |
| 96200 | + |
| 96201 | +/* An instance of the bytecode() table-valued function. |
| 96202 | +*/ |
| 96203 | +typedef struct bytecodevtab bytecodevtab; |
| 96204 | +struct bytecodevtab { |
| 96205 | + sqlite3_vtab base; /* Base class - must be first */ |
| 96206 | + sqlite3 *db; /* Database connection */ |
| 96207 | + int bTablesUsed; /* 2 for tables_used(). 0 for bytecode(). */ |
| 96208 | +}; |
| 96209 | + |
| 96210 | +/* A cursor for scanning through the bytecode |
| 96211 | +*/ |
| 96212 | +typedef struct bytecodevtab_cursor bytecodevtab_cursor; |
| 96213 | +struct bytecodevtab_cursor { |
| 96214 | + sqlite3_vtab_cursor base; /* Base class - must be first */ |
| 96215 | + sqlite3_stmt *pStmt; /* The statement whose bytecode is displayed */ |
| 96216 | + int iRowid; /* The rowid of the output table */ |
| 96217 | + int iAddr; /* Address */ |
| 96218 | + int needFinalize; /* Cursors owns pStmt and must finalize it */ |
| 96219 | + int showSubprograms; /* Provide a listing of subprograms */ |
| 96220 | + Op *aOp; /* Operand array */ |
| 96221 | + char *zP4; /* Rendered P4 value */ |
| 96222 | + const char *zType; /* tables_used.type */ |
| 96223 | + const char *zSchema; /* tables_used.schema */ |
| 96224 | + const char *zName; /* tables_used.name */ |
| 96225 | + Mem sub; /* Subprograms */ |
| 96226 | +}; |
| 96227 | + |
| 96228 | +/* |
| 96229 | +** Create a new bytecode() table-valued function. |
| 96230 | +*/ |
| 96231 | +static int bytecodevtabConnect( |
| 96232 | + sqlite3 *db, |
| 96233 | + void *pAux, |
| 96234 | + int argc, const char *const*argv, |
| 96235 | + sqlite3_vtab **ppVtab, |
| 96236 | + char **pzErr |
| 96237 | +){ |
| 96238 | + bytecodevtab *pNew; |
| 96239 | + int rc; |
| 96240 | + int isTabUsed = pAux!=0; |
| 96241 | + const char *azSchema[2] = { |
| 96242 | + /* bytecode() schema */ |
| 96243 | + "CREATE TABLE x(" |
| 96244 | + "addr INT," |
| 96245 | + "opcode TEXT," |
| 96246 | + "p1 INT," |
| 96247 | + "p2 INT," |
| 96248 | + "p3 INT," |
| 96249 | + "p4 TEXT," |
| 96250 | + "p5 INT," |
| 96251 | + "comment TEXT," |
| 96252 | + "subprog TEXT," |
| 96253 | + "stmt HIDDEN" |
| 96254 | + ");", |
| 96255 | + |
| 96256 | + /* Tables_used() schema */ |
| 96257 | + "CREATE TABLE x(" |
| 96258 | + "type TEXT," |
| 96259 | + "schema TEXT," |
| 96260 | + "name TEXT," |
| 96261 | + "wr INT," |
| 96262 | + "subprog TEXT," |
| 96263 | + "stmt HIDDEN" |
| 96264 | + ");" |
| 96265 | + }; |
| 96266 | + |
| 96267 | + rc = sqlite3_declare_vtab(db, azSchema[isTabUsed]); |
| 96268 | + if( rc==SQLITE_OK ){ |
| 96269 | + pNew = sqlite3_malloc( sizeof(*pNew) ); |
| 96270 | + *ppVtab = (sqlite3_vtab*)pNew; |
| 96271 | + if( pNew==0 ) return SQLITE_NOMEM; |
| 96272 | + memset(pNew, 0, sizeof(*pNew)); |
| 96273 | + pNew->db = db; |
| 96274 | + pNew->bTablesUsed = isTabUsed*2; |
| 96275 | + } |
| 96276 | + return rc; |
| 96277 | +} |
| 96278 | + |
| 96279 | +/* |
| 96280 | +** This method is the destructor for bytecodevtab objects. |
| 96281 | +*/ |
| 96282 | +static int bytecodevtabDisconnect(sqlite3_vtab *pVtab){ |
| 96283 | + bytecodevtab *p = (bytecodevtab*)pVtab; |
| 96284 | + sqlite3_free(p); |
| 96285 | + return SQLITE_OK; |
| 96286 | +} |
| 96287 | + |
| 96288 | +/* |
| 96289 | +** Constructor for a new bytecodevtab_cursor object. |
| 96290 | +*/ |
| 96291 | +static int bytecodevtabOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){ |
| 96292 | + bytecodevtab *pVTab = (bytecodevtab*)p; |
| 96293 | + bytecodevtab_cursor *pCur; |
| 96294 | + pCur = sqlite3_malloc( sizeof(*pCur) ); |
| 96295 | + if( pCur==0 ) return SQLITE_NOMEM; |
| 96296 | + memset(pCur, 0, sizeof(*pCur)); |
| 96297 | + sqlite3VdbeMemInit(&pCur->sub, pVTab->db, 1); |
| 96298 | + *ppCursor = &pCur->base; |
| 96299 | + return SQLITE_OK; |
| 96300 | +} |
| 96301 | + |
| 96302 | +/* |
| 96303 | +** Clear all internal content from a bytecodevtab cursor. |
| 96304 | +*/ |
| 96305 | +static void bytecodevtabCursorClear(bytecodevtab_cursor *pCur){ |
| 96306 | + sqlite3_free(pCur->zP4); |
| 96307 | + pCur->zP4 = 0; |
| 96308 | + sqlite3VdbeMemRelease(&pCur->sub); |
| 96309 | + sqlite3VdbeMemSetNull(&pCur->sub); |
| 96310 | + if( pCur->needFinalize ){ |
| 96311 | + sqlite3_finalize(pCur->pStmt); |
| 96312 | + } |
| 96313 | + pCur->pStmt = 0; |
| 96314 | + pCur->needFinalize = 0; |
| 96315 | + pCur->zType = 0; |
| 96316 | + pCur->zSchema = 0; |
| 96317 | + pCur->zName = 0; |
| 96318 | +} |
| 96319 | + |
| 96320 | +/* |
| 96321 | +** Destructor for a bytecodevtab_cursor. |
| 96322 | +*/ |
| 96323 | +static int bytecodevtabClose(sqlite3_vtab_cursor *cur){ |
| 96324 | + bytecodevtab_cursor *pCur = (bytecodevtab_cursor*)cur; |
| 96325 | + bytecodevtabCursorClear(pCur); |
| 96326 | + sqlite3_free(pCur); |
| 96327 | + return SQLITE_OK; |
| 96328 | +} |
| 96329 | + |
| 96330 | + |
| 96331 | +/* |
| 96332 | +** Advance a bytecodevtab_cursor to its next row of output. |
| 96333 | +*/ |
| 96334 | +static int bytecodevtabNext(sqlite3_vtab_cursor *cur){ |
| 96335 | + bytecodevtab_cursor *pCur = (bytecodevtab_cursor*)cur; |
| 96336 | + bytecodevtab *pTab = (bytecodevtab*)cur->pVtab; |
| 96337 | + int rc; |
| 96338 | + if( pCur->zP4 ){ |
| 96339 | + sqlite3_free(pCur->zP4); |
| 96340 | + pCur->zP4 = 0; |
| 96341 | + } |
| 96342 | + if( pCur->zName ){ |
| 96343 | + pCur->zName = 0; |
| 96344 | + pCur->zType = 0; |
| 96345 | + pCur->zSchema = 0; |
| 96346 | + } |
| 96347 | + rc = sqlite3VdbeNextOpcode( |
| 96348 | + (Vdbe*)pCur->pStmt, |
| 96349 | + pCur->showSubprograms ? &pCur->sub : 0, |
| 96350 | + pTab->bTablesUsed, |
| 96351 | + &pCur->iRowid, |
| 96352 | + &pCur->iAddr, |
| 96353 | + &pCur->aOp); |
| 96354 | + if( rc!=SQLITE_OK ){ |
| 96355 | + sqlite3VdbeMemSetNull(&pCur->sub); |
| 96356 | + pCur->aOp = 0; |
| 96357 | + } |
| 96358 | + return SQLITE_OK; |
| 96359 | +} |
| 96360 | + |
| 96361 | +/* |
| 96362 | +** Return TRUE if the cursor has been moved off of the last |
| 96363 | +** row of output. |
| 96364 | +*/ |
| 96365 | +static int bytecodevtabEof(sqlite3_vtab_cursor *cur){ |
| 96366 | + bytecodevtab_cursor *pCur = (bytecodevtab_cursor*)cur; |
| 96367 | + return pCur->aOp==0; |
| 96368 | +} |
| 96369 | + |
| 96370 | +/* |
| 96371 | +** Return values of columns for the row at which the bytecodevtab_cursor |
| 96372 | +** is currently pointing. |
| 96373 | +*/ |
| 96374 | +static int bytecodevtabColumn( |
| 96375 | + sqlite3_vtab_cursor *cur, /* The cursor */ |
| 96376 | + sqlite3_context *ctx, /* First argument to sqlite3_result_...() */ |
| 96377 | + int i /* Which column to return */ |
| 96378 | +){ |
| 96379 | + bytecodevtab_cursor *pCur = (bytecodevtab_cursor*)cur; |
| 96380 | + bytecodevtab *pVTab = (bytecodevtab*)cur->pVtab; |
| 96381 | + Op *pOp = pCur->aOp + pCur->iAddr; |
| 96382 | + if( pVTab->bTablesUsed ){ |
| 96383 | + if( i==4 ){ |
| 96384 | + i = 8; |
| 96385 | + }else{ |
| 96386 | + if( i<=2 && pCur->zType==0 ){ |
| 96387 | + Schema *pSchema; |
| 96388 | + HashElem *k; |
| 96389 | + int iDb = pOp->p3; |
| 96390 | + int iRoot = pOp->p2; |
| 96391 | + sqlite3 *db = pVTab->db; |
| 96392 | + pSchema = db->aDb[iDb].pSchema; |
| 96393 | + pCur->zSchema = db->aDb[iDb].zDbSName; |
| 96394 | + for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){ |
| 96395 | + Table *pTab = (Table*)sqliteHashData(k); |
| 96396 | + if( !IsVirtual(pTab) && pTab->tnum==iRoot ){ |
| 96397 | + pCur->zName = pTab->zName; |
| 96398 | + pCur->zType = "table"; |
| 96399 | + break; |
| 96400 | + } |
| 96401 | + } |
| 96402 | + if( pCur->zName==0 ){ |
| 96403 | + for(k=sqliteHashFirst(&pSchema->idxHash); k; k=sqliteHashNext(k)){ |
| 96404 | + Index *pIdx = (Index*)sqliteHashData(k); |
| 96405 | + if( pIdx->tnum==iRoot ){ |
| 96406 | + pCur->zName = pIdx->zName; |
| 96407 | + pCur->zType = "index"; |
| 96408 | + } |
| 96409 | + } |
| 96410 | + } |
| 96411 | + } |
| 96412 | + i += 10; |
| 96413 | + } |
| 96414 | + } |
| 96415 | + switch( i ){ |
| 96416 | + case 0: /* addr */ |
| 96417 | + sqlite3_result_int(ctx, pCur->iAddr); |
| 96418 | + break; |
| 96419 | + case 1: /* opcode */ |
| 96420 | + sqlite3_result_text(ctx, (char*)sqlite3OpcodeName(pOp->opcode), |
| 96421 | + -1, SQLITE_STATIC); |
| 96422 | + break; |
| 96423 | + case 2: /* p1 */ |
| 96424 | + sqlite3_result_int(ctx, pOp->p1); |
| 96425 | + break; |
| 96426 | + case 3: /* p2 */ |
| 96427 | + sqlite3_result_int(ctx, pOp->p2); |
| 96428 | + break; |
| 96429 | + case 4: /* p3 */ |
| 96430 | + sqlite3_result_int(ctx, pOp->p3); |
| 96431 | + break; |
| 96432 | + case 5: /* p4 */ |
| 96433 | + case 7: /* comment */ |
| 96434 | + if( pCur->zP4==0 ){ |
| 96435 | + pCur->zP4 = sqlite3VdbeDisplayP4(pVTab->db, pOp); |
| 96436 | + } |
| 96437 | + if( i==5 ){ |
| 96438 | + sqlite3_result_text(ctx, pCur->zP4, -1, SQLITE_STATIC); |
| 96439 | + }else{ |
| 96440 | +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 96441 | + char *zCom = sqlite3VdbeDisplayComment(pVTab->db, pOp, pCur->zP4); |
| 96442 | + sqlite3_result_text(ctx, zCom, -1, sqlite3_free); |
| 96443 | +#endif |
| 96444 | + } |
| 96445 | + break; |
| 96446 | + case 6: /* p5 */ |
| 96447 | + sqlite3_result_int(ctx, pOp->p5); |
| 96448 | + break; |
| 96449 | + case 8: { /* subprog */ |
| 96450 | + Op *aOp = pCur->aOp; |
| 96451 | + assert( aOp[0].opcode==OP_Init ); |
| 96452 | + assert( aOp[0].p4.z==0 || strncmp(aOp[0].p4.z,"-" "- ",3)==0 ); |
| 96453 | + if( pCur->iRowid==pCur->iAddr+1 ){ |
| 96454 | + break; /* Result is NULL for the main program */ |
| 96455 | + }else if( aOp[0].p4.z!=0 ){ |
| 96456 | + sqlite3_result_text(ctx, aOp[0].p4.z+3, -1, SQLITE_STATIC); |
| 96457 | + }else{ |
| 96458 | + sqlite3_result_text(ctx, "(FK)", 4, SQLITE_STATIC); |
| 96459 | + } |
| 96460 | + break; |
| 96461 | + } |
| 96462 | + case 10: /* tables_used.type */ |
| 96463 | + sqlite3_result_text(ctx, pCur->zType, -1, SQLITE_STATIC); |
| 96464 | + break; |
| 96465 | + case 11: /* tables_used.schema */ |
| 96466 | + sqlite3_result_text(ctx, pCur->zSchema, -1, SQLITE_STATIC); |
| 96467 | + break; |
| 96468 | + case 12: /* tables_used.name */ |
| 96469 | + sqlite3_result_text(ctx, pCur->zName, -1, SQLITE_STATIC); |
| 96470 | + break; |
| 96471 | + case 13: /* tables_used.wr */ |
| 96472 | + sqlite3_result_int(ctx, pOp->opcode==OP_OpenWrite); |
| 96473 | + break; |
| 96474 | + } |
| 96475 | + return SQLITE_OK; |
| 96476 | +} |
| 96477 | + |
| 96478 | +/* |
| 96479 | +** Return the rowid for the current row. In this implementation, the |
| 96480 | +** rowid is the same as the output value. |
| 96481 | +*/ |
| 96482 | +static int bytecodevtabRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){ |
| 96483 | + bytecodevtab_cursor *pCur = (bytecodevtab_cursor*)cur; |
| 96484 | + *pRowid = pCur->iRowid; |
| 96485 | + return SQLITE_OK; |
| 96486 | +} |
| 96487 | + |
| 96488 | +/* |
| 96489 | +** Initialize a cursor. |
| 96490 | +** |
| 96491 | +** idxNum==0 means show all subprograms |
| 96492 | +** idxNum==1 means show only the main bytecode and omit subprograms. |
| 96493 | +*/ |
| 96494 | +static int bytecodevtabFilter( |
| 96495 | + sqlite3_vtab_cursor *pVtabCursor, |
| 96496 | + int idxNum, const char *idxStr, |
| 96497 | + int argc, sqlite3_value **argv |
| 96498 | +){ |
| 96499 | + bytecodevtab_cursor *pCur = (bytecodevtab_cursor *)pVtabCursor; |
| 96500 | + bytecodevtab *pVTab = (bytecodevtab *)pVtabCursor->pVtab; |
| 96501 | + int rc = SQLITE_OK; |
| 96502 | + |
| 96503 | + bytecodevtabCursorClear(pCur); |
| 96504 | + pCur->iRowid = 0; |
| 96505 | + pCur->iAddr = 0; |
| 96506 | + pCur->showSubprograms = idxNum==0; |
| 96507 | + assert( argc==1 ); |
| 96508 | + if( sqlite3_value_type(argv[0])==SQLITE_TEXT ){ |
| 96509 | + const char *zSql = (const char*)sqlite3_value_text(argv[0]); |
| 96510 | + if( zSql==0 ){ |
| 96511 | + rc = SQLITE_NOMEM; |
| 96512 | + }else{ |
| 96513 | + rc = sqlite3_prepare_v2(pVTab->db, zSql, -1, &pCur->pStmt, 0); |
| 96514 | + pCur->needFinalize = 1; |
| 96515 | + } |
| 96516 | + }else{ |
| 96517 | + pCur->pStmt = (sqlite3_stmt*)sqlite3_value_pointer(argv[0],"stmt-pointer"); |
| 96518 | + } |
| 96519 | + if( pCur->pStmt==0 ){ |
| 96520 | + pVTab->base.zErrMsg = sqlite3_mprintf( |
| 96521 | + "argument to %s() is not a valid SQL statement", |
| 96522 | + pVTab->bTablesUsed ? "tables_used" : "bytecode" |
| 96523 | + ); |
| 96524 | + rc = SQLITE_ERROR; |
| 96525 | + }else{ |
| 96526 | + bytecodevtabNext(pVtabCursor); |
| 96527 | + } |
| 96528 | + return rc; |
| 96529 | +} |
| 96530 | + |
| 96531 | +/* |
| 96532 | +** We must have a single stmt=? constraint that will be passed through |
| 96533 | +** into the xFilter method. If there is no valid stmt=? constraint, |
| 96534 | +** then return an SQLITE_CONSTRAINT error. |
| 96535 | +*/ |
| 96536 | +static int bytecodevtabBestIndex( |
| 96537 | + sqlite3_vtab *tab, |
| 96538 | + sqlite3_index_info *pIdxInfo |
| 96539 | +){ |
| 96540 | + int i; |
| 96541 | + int rc = SQLITE_CONSTRAINT; |
| 96542 | + struct sqlite3_index_constraint *p; |
| 96543 | + bytecodevtab *pVTab = (bytecodevtab*)tab; |
| 96544 | + int iBaseCol = pVTab->bTablesUsed ? 4 : 8; |
| 96545 | + pIdxInfo->estimatedCost = (double)100; |
| 96546 | + pIdxInfo->estimatedRows = 100; |
| 96547 | + pIdxInfo->idxNum = 0; |
| 96548 | + for(i=0, p=pIdxInfo->aConstraint; i<pIdxInfo->nConstraint; i++, p++){ |
| 96549 | + if( p->usable==0 ) continue; |
| 96550 | + if( p->op==SQLITE_INDEX_CONSTRAINT_EQ && p->iColumn==iBaseCol+1 ){ |
| 96551 | + rc = SQLITE_OK; |
| 96552 | + pIdxInfo->aConstraintUsage[i].omit = 1; |
| 96553 | + pIdxInfo->aConstraintUsage[i].argvIndex = 1; |
| 96554 | + } |
| 96555 | + if( p->op==SQLITE_INDEX_CONSTRAINT_ISNULL && p->iColumn==iBaseCol ){ |
| 96556 | + pIdxInfo->aConstraintUsage[i].omit = 1; |
| 96557 | + pIdxInfo->idxNum = 1; |
| 96558 | + } |
| 96559 | + } |
| 96560 | + return rc; |
| 96561 | +} |
| 96562 | + |
| 96563 | +/* |
| 96564 | +** This following structure defines all the methods for the |
| 96565 | +** virtual table. |
| 96566 | +*/ |
| 96567 | +static sqlite3_module bytecodevtabModule = { |
| 96568 | + /* iVersion */ 0, |
| 96569 | + /* xCreate */ 0, |
| 96570 | + /* xConnect */ bytecodevtabConnect, |
| 96571 | + /* xBestIndex */ bytecodevtabBestIndex, |
| 96572 | + /* xDisconnect */ bytecodevtabDisconnect, |
| 96573 | + /* xDestroy */ 0, |
| 96574 | + /* xOpen */ bytecodevtabOpen, |
| 96575 | + /* xClose */ bytecodevtabClose, |
| 96576 | + /* xFilter */ bytecodevtabFilter, |
| 96577 | + /* xNext */ bytecodevtabNext, |
| 96578 | + /* xEof */ bytecodevtabEof, |
| 96579 | + /* xColumn */ bytecodevtabColumn, |
| 96580 | + /* xRowid */ bytecodevtabRowid, |
| 96581 | + /* xUpdate */ 0, |
| 96582 | + /* xBegin */ 0, |
| 96583 | + /* xSync */ 0, |
| 96584 | + /* xCommit */ 0, |
| 96585 | + /* xRollback */ 0, |
| 96586 | + /* xFindMethod */ 0, |
| 96587 | + /* xRename */ 0, |
| 96588 | + /* xSavepoint */ 0, |
| 96589 | + /* xRelease */ 0, |
| 96590 | + /* xRollbackTo */ 0, |
| 96591 | + /* xShadowName */ 0 |
| 96592 | +}; |
| 96593 | + |
| 96594 | + |
| 96595 | +SQLITE_PRIVATE int sqlite3VdbeBytecodeVtabInit(sqlite3 *db){ |
| 96596 | + int rc; |
| 96597 | + rc = sqlite3_create_module(db, "bytecode", &bytecodevtabModule, 0); |
| 96598 | + if( rc==SQLITE_OK ){ |
| 96599 | + rc = sqlite3_create_module(db, "tables_used", &bytecodevtabModule, &db); |
| 96600 | + } |
| 96601 | + return rc; |
| 96602 | +} |
| 96603 | +#endif /* SQLITE_ENABLE_BYTECODE_VTAB */ |
| 96604 | + |
| 96605 | +/************** End of vdbevtab.c ********************************************/ |
| 96098 | 96606 | /************** Begin file memjournal.c **************************************/ |
| 96099 | 96607 | /* |
| 96100 | 96608 | ** 2008 October 7 |
| 96101 | 96609 | ** |
| 96102 | 96610 | ** The author disclaims copyright to this source code. In place of |
| | @@ -98739,11 +99247,11 @@ |
| 98739 | 99247 | ** SELECT * FROM t1 WHERE (select a from t1); |
| 98740 | 99248 | */ |
| 98741 | 99249 | SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){ |
| 98742 | 99250 | int op; |
| 98743 | 99251 | while( ExprHasProperty(pExpr, EP_Skip) ){ |
| 98744 | | - assert( pExpr->op==TK_COLLATE ); |
| 99252 | + assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW ); |
| 98745 | 99253 | pExpr = pExpr->pLeft; |
| 98746 | 99254 | assert( pExpr!=0 ); |
| 98747 | 99255 | } |
| 98748 | 99256 | op = pExpr->op; |
| 98749 | 99257 | if( op==TK_SELECT ){ |
| | @@ -98806,11 +99314,11 @@ |
| 98806 | 99314 | /* |
| 98807 | 99315 | ** Skip over any TK_COLLATE operators. |
| 98808 | 99316 | */ |
| 98809 | 99317 | SQLITE_PRIVATE Expr *sqlite3ExprSkipCollate(Expr *pExpr){ |
| 98810 | 99318 | while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){ |
| 98811 | | - assert( pExpr->op==TK_COLLATE ); |
| 99319 | + assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW ); |
| 98812 | 99320 | pExpr = pExpr->pLeft; |
| 98813 | 99321 | } |
| 98814 | 99322 | return pExpr; |
| 98815 | 99323 | } |
| 98816 | 99324 | |
| | @@ -98825,11 +99333,11 @@ |
| 98825 | 99333 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 98826 | 99334 | assert( pExpr->x.pList->nExpr>0 ); |
| 98827 | 99335 | assert( pExpr->op==TK_FUNCTION ); |
| 98828 | 99336 | pExpr = pExpr->x.pList->a[0].pExpr; |
| 98829 | 99337 | }else{ |
| 98830 | | - assert( pExpr->op==TK_COLLATE ); |
| 99338 | + assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW ); |
| 98831 | 99339 | pExpr = pExpr->pLeft; |
| 98832 | 99340 | } |
| 98833 | 99341 | } |
| 98834 | 99342 | return pExpr; |
| 98835 | 99343 | } |
| | @@ -106605,10 +107113,15 @@ |
| 106605 | 107113 | sqlite3 *db = pParse->db; |
| 106606 | 107114 | Db *pDb; |
| 106607 | 107115 | Vdbe *v = sqlite3GetVdbe(pParse); |
| 106608 | 107116 | int aRoot[ArraySize(aTable)]; |
| 106609 | 107117 | u8 aCreateTbl[ArraySize(aTable)]; |
| 107118 | +#ifdef SQLITE_ENABLE_STAT4 |
| 107119 | + const int nToOpen = OptimizationEnabled(db,SQLITE_Stat4) ? 2 : 1; |
| 107120 | +#else |
| 107121 | + const int nToOpen = 1; |
| 107122 | +#endif |
| 106610 | 107123 | |
| 106611 | 107124 | if( v==0 ) return; |
| 106612 | 107125 | assert( sqlite3BtreeHoldsAllMutexes(db) ); |
| 106613 | 107126 | assert( sqlite3VdbeDb(v)==db ); |
| 106614 | 107127 | pDb = &db->aDb[iDb]; |
| | @@ -106617,12 +107130,13 @@ |
| 106617 | 107130 | ** if they do already exist. |
| 106618 | 107131 | */ |
| 106619 | 107132 | for(i=0; i<ArraySize(aTable); i++){ |
| 106620 | 107133 | const char *zTab = aTable[i].zName; |
| 106621 | 107134 | Table *pStat; |
| 107135 | + aCreateTbl[i] = 0; |
| 106622 | 107136 | if( (pStat = sqlite3FindTable(db, zTab, pDb->zDbSName))==0 ){ |
| 106623 | | - if( aTable[i].zCols ){ |
| 107137 | + if( i<nToOpen ){ |
| 106624 | 107138 | /* The sqlite_statN table does not exist. Create it. Note that a |
| 106625 | 107139 | ** side-effect of the CREATE TABLE statement is to leave the rootpage |
| 106626 | 107140 | ** of the new table in register pParse->regRoot. This is important |
| 106627 | 107141 | ** because the OpenWrite opcode below will be needing it. */ |
| 106628 | 107142 | sqlite3NestedParse(pParse, |
| | @@ -106634,11 +107148,10 @@ |
| 106634 | 107148 | }else{ |
| 106635 | 107149 | /* The table already exists. If zWhere is not NULL, delete all entries |
| 106636 | 107150 | ** associated with the table zWhere. If zWhere is NULL, delete the |
| 106637 | 107151 | ** entire contents of the table. */ |
| 106638 | 107152 | aRoot[i] = pStat->tnum; |
| 106639 | | - aCreateTbl[i] = 0; |
| 106640 | 107153 | sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab); |
| 106641 | 107154 | if( zWhere ){ |
| 106642 | 107155 | sqlite3NestedParse(pParse, |
| 106643 | 107156 | "DELETE FROM %Q.%s WHERE %s=%Q", |
| 106644 | 107157 | pDb->zDbSName, zTab, zWhereType, zWhere |
| | @@ -106653,11 +107166,11 @@ |
| 106653 | 107166 | } |
| 106654 | 107167 | } |
| 106655 | 107168 | } |
| 106656 | 107169 | |
| 106657 | 107170 | /* Open the sqlite_stat[134] tables for writing. */ |
| 106658 | | - for(i=0; aTable[i].zCols; i++){ |
| 107171 | + for(i=0; i<nToOpen; i++){ |
| 106659 | 107172 | assert( i<ArraySize(aTable) ); |
| 106660 | 107173 | sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iStatCur+i, aRoot[i], iDb, 3); |
| 106661 | 107174 | sqlite3VdbeChangeP5(v, aCreateTbl[i]); |
| 106662 | 107175 | VdbeComment((v, aTable[i].zName)); |
| 106663 | 107176 | } |
| | @@ -106692,13 +107205,16 @@ |
| 106692 | 107205 | u32 iHash; /* Tiebreaker hash */ |
| 106693 | 107206 | #endif |
| 106694 | 107207 | }; |
| 106695 | 107208 | struct StatAccum { |
| 106696 | 107209 | sqlite3 *db; /* Database connection, for malloc() */ |
| 106697 | | - tRowcnt nRow; /* Number of rows in the entire table */ |
| 107210 | + tRowcnt nEst; /* Estimated number of rows */ |
| 107211 | + tRowcnt nRow; /* Number of rows visited so far */ |
| 107212 | + int nLimit; /* Analysis row-scan limit */ |
| 106698 | 107213 | int nCol; /* Number of columns in index + pk/rowid */ |
| 106699 | 107214 | int nKeyCol; /* Number of index columns w/o the pk/rowid */ |
| 107215 | + u8 nSkipAhead; /* Number of times of skip-ahead */ |
| 106700 | 107216 | StatSample current; /* Current row as a StatSample */ |
| 106701 | 107217 | #ifdef SQLITE_ENABLE_STAT4 |
| 106702 | 107218 | tRowcnt nPSample; /* How often to do a periodic sample */ |
| 106703 | 107219 | int mxSample; /* Maximum number of samples to accumulate */ |
| 106704 | 107220 | u32 iPrn; /* Pseudo-random number used for sampling */ |
| | @@ -106774,31 +107290,32 @@ |
| 106774 | 107290 | ** Reclaim all memory of a StatAccum structure. |
| 106775 | 107291 | */ |
| 106776 | 107292 | static void statAccumDestructor(void *pOld){ |
| 106777 | 107293 | StatAccum *p = (StatAccum*)pOld; |
| 106778 | 107294 | #ifdef SQLITE_ENABLE_STAT4 |
| 106779 | | - int i; |
| 106780 | | - for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i); |
| 106781 | | - for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i); |
| 106782 | | - sampleClear(p->db, &p->current); |
| 107295 | + if( p->mxSample ){ |
| 107296 | + int i; |
| 107297 | + for(i=0; i<p->nCol; i++) sampleClear(p->db, p->aBest+i); |
| 107298 | + for(i=0; i<p->mxSample; i++) sampleClear(p->db, p->a+i); |
| 107299 | + sampleClear(p->db, &p->current); |
| 107300 | + } |
| 106783 | 107301 | #endif |
| 106784 | 107302 | sqlite3DbFree(p->db, p); |
| 106785 | 107303 | } |
| 106786 | 107304 | |
| 106787 | 107305 | /* |
| 106788 | | -** Implementation of the stat_init(N,K,C) SQL function. The three parameters |
| 107306 | +** Implementation of the stat_init(N,K,C,L) SQL function. The four parameters |
| 106789 | 107307 | ** are: |
| 106790 | 107308 | ** N: The number of columns in the index including the rowid/pk (note 1) |
| 106791 | 107309 | ** K: The number of columns in the index excluding the rowid/pk. |
| 106792 | | -** C: The number of rows in the index (note 2) |
| 107310 | +** C: Estimated number of rows in the index |
| 107311 | +** L: A limit on the number of rows to scan, or 0 for no-limit |
| 106793 | 107312 | ** |
| 106794 | 107313 | ** Note 1: In the special case of the covering index that implements a |
| 106795 | 107314 | ** WITHOUT ROWID table, N is the number of PRIMARY KEY columns, not the |
| 106796 | 107315 | ** total number of columns in the table. |
| 106797 | 107316 | ** |
| 106798 | | -** Note 2: C is only used for STAT4. |
| 106799 | | -** |
| 106800 | 107317 | ** For indexes on ordinary rowid tables, N==K+1. But for indexes on |
| 106801 | 107318 | ** WITHOUT ROWID tables, N=K+P where P is the number of columns in the |
| 106802 | 107319 | ** PRIMARY KEY of the table. The covering index that implements the |
| 106803 | 107320 | ** original WITHOUT ROWID table as N==K as a special case. |
| 106804 | 107321 | ** |
| | @@ -106815,13 +107332,14 @@ |
| 106815 | 107332 | StatAccum *p; |
| 106816 | 107333 | int nCol; /* Number of columns in index being sampled */ |
| 106817 | 107334 | int nKeyCol; /* Number of key columns */ |
| 106818 | 107335 | int nColUp; /* nCol rounded up for alignment */ |
| 106819 | 107336 | int n; /* Bytes of space to allocate */ |
| 106820 | | - sqlite3 *db; /* Database connection */ |
| 107337 | + sqlite3 *db = sqlite3_context_db_handle(context); /* Database connection */ |
| 106821 | 107338 | #ifdef SQLITE_ENABLE_STAT4 |
| 106822 | | - int mxSample = SQLITE_STAT4_SAMPLES; |
| 107339 | + /* Maximum number of samples. 0 if STAT4 data is not collected */ |
| 107340 | + int mxSample = OptimizationEnabled(db,SQLITE_Stat4) ?SQLITE_STAT4_SAMPLES :0; |
| 106823 | 107341 | #endif |
| 106824 | 107342 | |
| 106825 | 107343 | /* Decode the three function arguments */ |
| 106826 | 107344 | UNUSED_PARAMETER(argc); |
| 106827 | 107345 | nCol = sqlite3_value_int(argv[0]); |
| | @@ -106832,39 +107350,43 @@ |
| 106832 | 107350 | assert( nKeyCol>0 ); |
| 106833 | 107351 | |
| 106834 | 107352 | /* Allocate the space required for the StatAccum object */ |
| 106835 | 107353 | n = sizeof(*p) |
| 106836 | 107354 | + sizeof(tRowcnt)*nColUp /* StatAccum.anEq */ |
| 106837 | | - + sizeof(tRowcnt)*nColUp /* StatAccum.anDLt */ |
| 107355 | + + sizeof(tRowcnt)*nColUp; /* StatAccum.anDLt */ |
| 106838 | 107356 | #ifdef SQLITE_ENABLE_STAT4 |
| 106839 | | - + sizeof(tRowcnt)*nColUp /* StatAccum.anLt */ |
| 106840 | | - + sizeof(StatSample)*(nCol+mxSample) /* StatAccum.aBest[], a[] */ |
| 106841 | | - + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample) |
| 107357 | + if( mxSample ){ |
| 107358 | + n += sizeof(tRowcnt)*nColUp /* StatAccum.anLt */ |
| 107359 | + + sizeof(StatSample)*(nCol+mxSample) /* StatAccum.aBest[], a[] */ |
| 107360 | + + sizeof(tRowcnt)*3*nColUp*(nCol+mxSample); |
| 107361 | + } |
| 106842 | 107362 | #endif |
| 106843 | | - ; |
| 106844 | 107363 | db = sqlite3_context_db_handle(context); |
| 106845 | 107364 | p = sqlite3DbMallocZero(db, n); |
| 106846 | 107365 | if( p==0 ){ |
| 106847 | 107366 | sqlite3_result_error_nomem(context); |
| 106848 | 107367 | return; |
| 106849 | 107368 | } |
| 106850 | 107369 | |
| 106851 | 107370 | p->db = db; |
| 107371 | + p->nEst = sqlite3_value_int64(argv[2]); |
| 106852 | 107372 | p->nRow = 0; |
| 107373 | + p->nLimit = sqlite3_value_int64(argv[3]); |
| 106853 | 107374 | p->nCol = nCol; |
| 106854 | 107375 | p->nKeyCol = nKeyCol; |
| 107376 | + p->nSkipAhead = 0; |
| 106855 | 107377 | p->current.anDLt = (tRowcnt*)&p[1]; |
| 106856 | 107378 | p->current.anEq = &p->current.anDLt[nColUp]; |
| 106857 | 107379 | |
| 106858 | 107380 | #ifdef SQLITE_ENABLE_STAT4 |
| 106859 | | - { |
| 107381 | + p->mxSample = p->nLimit==0 ? mxSample : 0; |
| 107382 | + if( mxSample ){ |
| 106860 | 107383 | u8 *pSpace; /* Allocated space not yet assigned */ |
| 106861 | 107384 | int i; /* Used to iterate through p->aSample[] */ |
| 106862 | 107385 | |
| 106863 | 107386 | p->iGet = -1; |
| 106864 | | - p->mxSample = mxSample; |
| 106865 | | - p->nPSample = (tRowcnt)(sqlite3_value_int64(argv[2])/(mxSample/3+1) + 1); |
| 107387 | + p->nPSample = (tRowcnt)(p->nEst/(mxSample/3+1) + 1); |
| 106866 | 107388 | p->current.anLt = &p->current.anEq[nColUp]; |
| 106867 | 107389 | p->iPrn = 0x689e962d*(u32)nCol ^ 0xd0944565*(u32)sqlite3_value_int(argv[2]); |
| 106868 | 107390 | |
| 106869 | 107391 | /* Set up the StatAccum.a[] and aBest[] arrays */ |
| 106870 | 107392 | p->a = (struct StatSample*)&p->current.anLt[nColUp]; |
| | @@ -106888,11 +107410,11 @@ |
| 106888 | 107410 | ** (given by the 3rd parameter) is never used and can be any positive |
| 106889 | 107411 | ** value. */ |
| 106890 | 107412 | sqlite3_result_blob(context, p, sizeof(*p), statAccumDestructor); |
| 106891 | 107413 | } |
| 106892 | 107414 | static const FuncDef statInitFuncdef = { |
| 106893 | | - 2+IsStat4, /* nArg */ |
| 107415 | + 4, /* nArg */ |
| 106894 | 107416 | SQLITE_UTF8, /* funcFlags */ |
| 106895 | 107417 | 0, /* pUserData */ |
| 106896 | 107418 | 0, /* pNext */ |
| 106897 | 107419 | statInit, /* xSFunc */ |
| 106898 | 107420 | 0, /* xFinalize */ |
| | @@ -107092,14 +107614,17 @@ |
| 107092 | 107614 | ** P Pointer to the StatAccum object created by stat_init() |
| 107093 | 107615 | ** C Index of left-most column to differ from previous row |
| 107094 | 107616 | ** R Rowid for the current row. Might be a key record for |
| 107095 | 107617 | ** WITHOUT ROWID tables. |
| 107096 | 107618 | ** |
| 107097 | | -** This SQL function always returns NULL. It's purpose it to accumulate |
| 107098 | | -** statistical data and/or samples in the StatAccum object about the |
| 107099 | | -** index being analyzed. The stat_get() SQL function will later be used to |
| 107100 | | -** extract relevant information for constructing the sqlite_statN tables. |
| 107619 | +** The purpose of this routine is to collect statistical data and/or |
| 107620 | +** samples from the index being analyzed into the StatAccum object. |
| 107621 | +** The stat_get() SQL function will be used afterwards to |
| 107622 | +** retrieve the information gathered. |
| 107623 | +** |
| 107624 | +** This SQL function usually returns NULL, but might return an integer |
| 107625 | +** if it wants the byte-code to do special processing. |
| 107101 | 107626 | ** |
| 107102 | 107627 | ** The R parameter is only used for STAT4 |
| 107103 | 107628 | */ |
| 107104 | 107629 | static void statPush( |
| 107105 | 107630 | sqlite3_context *context, |
| | @@ -107121,11 +107646,11 @@ |
| 107121 | 107646 | /* This is the first call to this function. Do initialization. */ |
| 107122 | 107647 | for(i=0; i<p->nCol; i++) p->current.anEq[i] = 1; |
| 107123 | 107648 | }else{ |
| 107124 | 107649 | /* Second and subsequent calls get processed here */ |
| 107125 | 107650 | #ifdef SQLITE_ENABLE_STAT4 |
| 107126 | | - samplePushPrevious(p, iChng); |
| 107651 | + if( p->mxSample ) samplePushPrevious(p, iChng); |
| 107127 | 107652 | #endif |
| 107128 | 107653 | |
| 107129 | 107654 | /* Update anDLt[], anLt[] and anEq[] to reflect the values that apply |
| 107130 | 107655 | ** to the current row of the index. */ |
| 107131 | 107656 | for(i=0; i<iChng; i++){ |
| | @@ -107132,30 +107657,29 @@ |
| 107132 | 107657 | p->current.anEq[i]++; |
| 107133 | 107658 | } |
| 107134 | 107659 | for(i=iChng; i<p->nCol; i++){ |
| 107135 | 107660 | p->current.anDLt[i]++; |
| 107136 | 107661 | #ifdef SQLITE_ENABLE_STAT4 |
| 107137 | | - p->current.anLt[i] += p->current.anEq[i]; |
| 107662 | + if( p->mxSample ) p->current.anLt[i] += p->current.anEq[i]; |
| 107138 | 107663 | #endif |
| 107139 | 107664 | p->current.anEq[i] = 1; |
| 107140 | 107665 | } |
| 107141 | 107666 | } |
| 107667 | + |
| 107142 | 107668 | p->nRow++; |
| 107143 | 107669 | #ifdef SQLITE_ENABLE_STAT4 |
| 107144 | | - if( sqlite3_value_type(argv[2])==SQLITE_INTEGER ){ |
| 107145 | | - sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2])); |
| 107146 | | - }else{ |
| 107147 | | - sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]), |
| 107148 | | - sqlite3_value_blob(argv[2])); |
| 107149 | | - } |
| 107150 | | - p->current.iHash = p->iPrn = p->iPrn*1103515245 + 12345; |
| 107151 | | -#endif |
| 107152 | | - |
| 107153 | | -#ifdef SQLITE_ENABLE_STAT4 |
| 107154 | | - { |
| 107155 | | - tRowcnt nLt = p->current.anLt[p->nCol-1]; |
| 107156 | | - |
| 107670 | + if( p->mxSample ){ |
| 107671 | + tRowcnt nLt; |
| 107672 | + if( sqlite3_value_type(argv[2])==SQLITE_INTEGER ){ |
| 107673 | + sampleSetRowidInt64(p->db, &p->current, sqlite3_value_int64(argv[2])); |
| 107674 | + }else{ |
| 107675 | + sampleSetRowid(p->db, &p->current, sqlite3_value_bytes(argv[2]), |
| 107676 | + sqlite3_value_blob(argv[2])); |
| 107677 | + } |
| 107678 | + p->current.iHash = p->iPrn = p->iPrn*1103515245 + 12345; |
| 107679 | + |
| 107680 | + nLt = p->current.anLt[p->nCol-1]; |
| 107157 | 107681 | /* Check if this is to be a periodic sample. If so, add it. */ |
| 107158 | 107682 | if( (nLt/p->nPSample)!=(nLt+1)/p->nPSample ){ |
| 107159 | 107683 | p->current.isPSample = 1; |
| 107160 | 107684 | p->current.iCol = 0; |
| 107161 | 107685 | sampleInsert(p, &p->current, p->nCol-1); |
| | @@ -107167,13 +107691,18 @@ |
| 107167 | 107691 | p->current.iCol = i; |
| 107168 | 107692 | if( i>=iChng || sampleIsBetterPost(p, &p->current, &p->aBest[i]) ){ |
| 107169 | 107693 | sampleCopy(p, &p->aBest[i], &p->current); |
| 107170 | 107694 | } |
| 107171 | 107695 | } |
| 107696 | + }else |
| 107697 | +#endif |
| 107698 | + if( p->nLimit && p->nRow>(tRowcnt)p->nLimit*(p->nSkipAhead+1) ){ |
| 107699 | + p->nSkipAhead++; |
| 107700 | + sqlite3_result_int(context, p->current.anDLt[0]>0); |
| 107172 | 107701 | } |
| 107173 | | -#endif |
| 107174 | 107702 | } |
| 107703 | + |
| 107175 | 107704 | static const FuncDef statPushFuncdef = { |
| 107176 | 107705 | 2+IsStat4, /* nArg */ |
| 107177 | 107706 | SQLITE_UTF8, /* funcFlags */ |
| 107178 | 107707 | 0, /* pUserData */ |
| 107179 | 107708 | 0, /* pNext */ |
| | @@ -107221,10 +107750,11 @@ |
| 107221 | 107750 | assert( argc==2 ); |
| 107222 | 107751 | assert( eCall==STAT_GET_STAT1 || eCall==STAT_GET_NEQ |
| 107223 | 107752 | || eCall==STAT_GET_ROWID || eCall==STAT_GET_NLT |
| 107224 | 107753 | || eCall==STAT_GET_NDLT |
| 107225 | 107754 | ); |
| 107755 | + assert( eCall==STAT_GET_STAT1 || p->mxSample ); |
| 107226 | 107756 | if( eCall==STAT_GET_STAT1 ) |
| 107227 | 107757 | #else |
| 107228 | 107758 | assert( argc==1 ); |
| 107229 | 107759 | #endif |
| 107230 | 107760 | { |
| | @@ -107256,11 +107786,12 @@ |
| 107256 | 107786 | if( zRet==0 ){ |
| 107257 | 107787 | sqlite3_result_error_nomem(context); |
| 107258 | 107788 | return; |
| 107259 | 107789 | } |
| 107260 | 107790 | |
| 107261 | | - sqlite3_snprintf(24, zRet, "%llu", (u64)p->nRow); |
| 107791 | + sqlite3_snprintf(24, zRet, "%llu", |
| 107792 | + p->nSkipAhead ? (u64)p->nEst : (u64)p->nRow); |
| 107262 | 107793 | z = zRet + sqlite3Strlen30(zRet); |
| 107263 | 107794 | for(i=0; i<p->nKeyCol; i++){ |
| 107264 | 107795 | u64 nDistinct = p->current.anDLt[i] + 1; |
| 107265 | 107796 | u64 iVal = (p->nRow + nDistinct - 1) / nDistinct; |
| 107266 | 107797 | sqlite3_snprintf(24, z, " %llu", iVal); |
| | @@ -107332,20 +107863,20 @@ |
| 107332 | 107863 | 0, 0, /* xValue, xInverse */ |
| 107333 | 107864 | "stat_get", /* zName */ |
| 107334 | 107865 | {0} |
| 107335 | 107866 | }; |
| 107336 | 107867 | |
| 107337 | | -static void callStatGet(Parse *pParse, int regStat4, int iParam, int regOut){ |
| 107868 | +static void callStatGet(Parse *pParse, int regStat, int iParam, int regOut){ |
| 107338 | 107869 | #ifdef SQLITE_ENABLE_STAT4 |
| 107339 | | - sqlite3VdbeAddOp2(pParse->pVdbe, OP_Integer, iParam, regStat4+1); |
| 107870 | + sqlite3VdbeAddOp2(pParse->pVdbe, OP_Integer, iParam, regStat+1); |
| 107340 | 107871 | #elif SQLITE_DEBUG |
| 107341 | 107872 | assert( iParam==STAT_GET_STAT1 ); |
| 107342 | 107873 | #else |
| 107343 | 107874 | UNUSED_PARAMETER( iParam ); |
| 107344 | 107875 | #endif |
| 107345 | | - assert( regOut!=regStat4 && regOut!=regStat4+1 ); |
| 107346 | | - sqlite3VdbeAddFunctionCall(pParse, 0, regStat4, regOut, 1+IsStat4, |
| 107876 | + assert( regOut!=regStat && regOut!=regStat+1 ); |
| 107877 | + sqlite3VdbeAddFunctionCall(pParse, 0, regStat, regOut, 1+IsStat4, |
| 107347 | 107878 | &statGetFuncdef, 0); |
| 107348 | 107879 | } |
| 107349 | 107880 | |
| 107350 | 107881 | /* |
| 107351 | 107882 | ** Generate code to do an analysis of all indices associated with |
| | @@ -107367,16 +107898,15 @@ |
| 107367 | 107898 | int i; /* Loop counter */ |
| 107368 | 107899 | int jZeroRows = -1; /* Jump from here if number of rows is zero */ |
| 107369 | 107900 | int iDb; /* Index of database containing pTab */ |
| 107370 | 107901 | u8 needTableCnt = 1; /* True to count the table */ |
| 107371 | 107902 | int regNewRowid = iMem++; /* Rowid for the inserted record */ |
| 107372 | | - int regStat4 = iMem++; /* Register to hold StatAccum object */ |
| 107903 | + int regStat = iMem++; /* Register to hold StatAccum object */ |
| 107373 | 107904 | int regChng = iMem++; /* Index of changed index field */ |
| 107374 | | -#ifdef SQLITE_ENABLE_STAT4 |
| 107375 | 107905 | int regRowid = iMem++; /* Rowid argument passed to stat_push() */ |
| 107376 | | -#endif |
| 107377 | 107906 | int regTemp = iMem++; /* Temporary use register */ |
| 107907 | + int regTemp2 = iMem++; /* Second temporary use register */ |
| 107378 | 107908 | int regTabname = iMem++; /* Register containing table name */ |
| 107379 | 107909 | int regIdxname = iMem++; /* Register containing index name */ |
| 107380 | 107910 | int regStat1 = iMem++; /* Value for the stat column of sqlite_stat1 */ |
| 107381 | 107911 | int regPrev = iMem; /* MUST BE LAST (see below) */ |
| 107382 | 107912 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| | @@ -107500,21 +108030,30 @@ |
| 107500 | 108030 | /* Invoke the stat_init() function. The arguments are: |
| 107501 | 108031 | ** |
| 107502 | 108032 | ** (1) the number of columns in the index including the rowid |
| 107503 | 108033 | ** (or for a WITHOUT ROWID table, the number of PK columns), |
| 107504 | 108034 | ** (2) the number of columns in the key without the rowid/pk |
| 107505 | | - ** (3) the number of rows in the index, |
| 107506 | | - ** |
| 107507 | | - ** |
| 107508 | | - ** The third argument is only used for STAT4 |
| 108035 | + ** (3) estimated number of rows in the index, |
| 107509 | 108036 | */ |
| 108037 | + sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat+1); |
| 108038 | + assert( regRowid==regStat+2 ); |
| 108039 | + sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regRowid); |
| 107510 | 108040 | #ifdef SQLITE_ENABLE_STAT4 |
| 107511 | | - sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regStat4+3); |
| 108041 | + if( OptimizationEnabled(db, SQLITE_Stat4) ){ |
| 108042 | + sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regTemp); |
| 108043 | + addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur); |
| 108044 | + VdbeCoverage(v); |
| 108045 | + }else |
| 107512 | 108046 | #endif |
| 107513 | | - sqlite3VdbeAddOp2(v, OP_Integer, nCol, regStat4+1); |
| 107514 | | - sqlite3VdbeAddOp2(v, OP_Integer, pIdx->nKeyCol, regStat4+2); |
| 107515 | | - sqlite3VdbeAddFunctionCall(pParse, 0, regStat4+1, regStat4, 2+IsStat4, |
| 108047 | + { |
| 108048 | + addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur); |
| 108049 | + VdbeCoverage(v); |
| 108050 | + sqlite3VdbeAddOp3(v, OP_Count, iIdxCur, regTemp, 1); |
| 108051 | + } |
| 108052 | + assert( regTemp2==regStat+4 ); |
| 108053 | + sqlite3VdbeAddOp2(v, OP_Integer, db->nAnalysisLimit, regTemp2); |
| 108054 | + sqlite3VdbeAddFunctionCall(pParse, 0, regStat+1, regStat, 4, |
| 107516 | 108055 | &statInitFuncdef, 0); |
| 107517 | 108056 | |
| 107518 | 108057 | /* Implementation of the following: |
| 107519 | 108058 | ** |
| 107520 | 108059 | ** Rewind csr |
| | @@ -107521,12 +108060,10 @@ |
| 107521 | 108060 | ** if eof(csr) goto end_of_scan; |
| 107522 | 108061 | ** regChng = 0 |
| 107523 | 108062 | ** goto next_push_0; |
| 107524 | 108063 | ** |
| 107525 | 108064 | */ |
| 107526 | | - addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur); |
| 107527 | | - VdbeCoverage(v); |
| 107528 | 108065 | sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng); |
| 107529 | 108066 | addrNextRow = sqlite3VdbeCurrentAddr(v); |
| 107530 | 108067 | |
| 107531 | 108068 | if( nColTest>0 ){ |
| 107532 | 108069 | int endDistinctTest = sqlite3VdbeMakeLabel(pParse); |
| | @@ -107555,10 +108092,11 @@ |
| 107555 | 108092 | } |
| 107556 | 108093 | for(i=0; i<nColTest; i++){ |
| 107557 | 108094 | char *pColl = (char*)sqlite3LocateCollSeq(pParse, pIdx->azColl[i]); |
| 107558 | 108095 | sqlite3VdbeAddOp2(v, OP_Integer, i, regChng); |
| 107559 | 108096 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp); |
| 108097 | + VdbeComment((v, "%s.column(%d)", pIdx->zName, i)); |
| 107560 | 108098 | aGotoChng[i] = |
| 107561 | 108099 | sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ); |
| 107562 | 108100 | sqlite3VdbeChangeP5(v, SQLITE_NULLEQ); |
| 107563 | 108101 | VdbeCoverage(v); |
| 107564 | 108102 | } |
| | @@ -107575,10 +108113,11 @@ |
| 107575 | 108113 | */ |
| 107576 | 108114 | sqlite3VdbeJumpHere(v, addrNextRow-1); |
| 107577 | 108115 | for(i=0; i<nColTest; i++){ |
| 107578 | 108116 | sqlite3VdbeJumpHere(v, aGotoChng[i]); |
| 107579 | 108117 | sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regPrev+i); |
| 108118 | + VdbeComment((v, "%s.column(%d)", pIdx->zName, i)); |
| 107580 | 108119 | } |
| 107581 | 108120 | sqlite3VdbeResolveLabel(v, endDistinctTest); |
| 107582 | 108121 | sqlite3DbFree(db, aGotoChng); |
| 107583 | 108122 | } |
| 107584 | 108123 | |
| | @@ -107588,34 +108127,50 @@ |
| 107588 | 108127 | ** stat_push(P, regChng, regRowid) // 3rd parameter STAT4 only |
| 107589 | 108128 | ** Next csr |
| 107590 | 108129 | ** if !eof(csr) goto next_row; |
| 107591 | 108130 | */ |
| 107592 | 108131 | #ifdef SQLITE_ENABLE_STAT4 |
| 107593 | | - assert( regRowid==(regStat4+2) ); |
| 107594 | | - if( HasRowid(pTab) ){ |
| 107595 | | - sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid); |
| 107596 | | - }else{ |
| 107597 | | - Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); |
| 107598 | | - int j, k, regKey; |
| 107599 | | - regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol); |
| 107600 | | - for(j=0; j<pPk->nKeyCol; j++){ |
| 107601 | | - k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]); |
| 107602 | | - assert( k>=0 && k<pIdx->nColumn ); |
| 107603 | | - sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j); |
| 107604 | | - VdbeComment((v, "%s", pTab->aCol[pPk->aiColumn[j]].zName)); |
| 107605 | | - } |
| 107606 | | - sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid); |
| 107607 | | - sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol); |
| 108132 | + if( OptimizationEnabled(db, SQLITE_Stat4) ){ |
| 108133 | + assert( regRowid==(regStat+2) ); |
| 108134 | + if( HasRowid(pTab) ){ |
| 108135 | + sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, regRowid); |
| 108136 | + }else{ |
| 108137 | + Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable); |
| 108138 | + int j, k, regKey; |
| 108139 | + regKey = sqlite3GetTempRange(pParse, pPk->nKeyCol); |
| 108140 | + for(j=0; j<pPk->nKeyCol; j++){ |
| 108141 | + k = sqlite3TableColumnToIndex(pIdx, pPk->aiColumn[j]); |
| 108142 | + assert( k>=0 && k<pIdx->nColumn ); |
| 108143 | + sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, regKey+j); |
| 108144 | + VdbeComment((v, "%s.column(%d)", pIdx->zName, i)); |
| 108145 | + } |
| 108146 | + sqlite3VdbeAddOp3(v, OP_MakeRecord, regKey, pPk->nKeyCol, regRowid); |
| 108147 | + sqlite3ReleaseTempRange(pParse, regKey, pPk->nKeyCol); |
| 108148 | + } |
| 107608 | 108149 | } |
| 107609 | 108150 | #endif |
| 107610 | | - assert( regChng==(regStat4+1) ); |
| 107611 | | - sqlite3VdbeAddFunctionCall(pParse, 1, regStat4, regTemp, 2+IsStat4, |
| 107612 | | - &statPushFuncdef, 0); |
| 107613 | | - sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v); |
| 108151 | + assert( regChng==(regStat+1) ); |
| 108152 | + { |
| 108153 | + sqlite3VdbeAddFunctionCall(pParse, 1, regStat, regTemp, 2+IsStat4, |
| 108154 | + &statPushFuncdef, 0); |
| 108155 | + if( db->nAnalysisLimit ){ |
| 108156 | + int j1, j2, j3; |
| 108157 | + j1 = sqlite3VdbeAddOp1(v, OP_IsNull, regTemp); VdbeCoverage(v); |
| 108158 | + j2 = sqlite3VdbeAddOp1(v, OP_If, regTemp); VdbeCoverage(v); |
| 108159 | + j3 = sqlite3VdbeAddOp4Int(v, OP_SeekGT, iIdxCur, 0, regPrev, 1); |
| 108160 | + VdbeCoverage(v); |
| 108161 | + sqlite3VdbeJumpHere(v, j1); |
| 108162 | + sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v); |
| 108163 | + sqlite3VdbeJumpHere(v, j2); |
| 108164 | + sqlite3VdbeJumpHere(v, j3); |
| 108165 | + }else{ |
| 108166 | + sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v); |
| 108167 | + } |
| 108168 | + } |
| 107614 | 108169 | |
| 107615 | 108170 | /* Add the entry to the stat1 table. */ |
| 107616 | | - callStatGet(pParse, regStat4, STAT_GET_STAT1, regStat1); |
| 108171 | + callStatGet(pParse, regStat, STAT_GET_STAT1, regStat1); |
| 107617 | 108172 | assert( "BBB"[0]==SQLITE_AFF_TEXT ); |
| 107618 | 108173 | sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "BBB", 0); |
| 107619 | 108174 | sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid); |
| 107620 | 108175 | sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid); |
| 107621 | 108176 | #ifdef SQLITE_ENABLE_PREUPDATE_HOOK |
| | @@ -107623,11 +108178,11 @@ |
| 107623 | 108178 | #endif |
| 107624 | 108179 | sqlite3VdbeChangeP5(v, OPFLAG_APPEND); |
| 107625 | 108180 | |
| 107626 | 108181 | /* Add the entries to the stat4 table. */ |
| 107627 | 108182 | #ifdef SQLITE_ENABLE_STAT4 |
| 107628 | | - { |
| 108183 | + if( OptimizationEnabled(db, SQLITE_Stat4) && db->nAnalysisLimit==0 ){ |
| 107629 | 108184 | int regEq = regStat1; |
| 107630 | 108185 | int regLt = regStat1+1; |
| 107631 | 108186 | int regDLt = regStat1+2; |
| 107632 | 108187 | int regSample = regStat1+3; |
| 107633 | 108188 | int regCol = regStat1+4; |
| | @@ -107637,16 +108192,16 @@ |
| 107637 | 108192 | u8 seekOp = HasRowid(pTab) ? OP_NotExists : OP_NotFound; |
| 107638 | 108193 | |
| 107639 | 108194 | pParse->nMem = MAX(pParse->nMem, regCol+nCol); |
| 107640 | 108195 | |
| 107641 | 108196 | addrNext = sqlite3VdbeCurrentAddr(v); |
| 107642 | | - callStatGet(pParse, regStat4, STAT_GET_ROWID, regSampleRowid); |
| 108197 | + callStatGet(pParse, regStat, STAT_GET_ROWID, regSampleRowid); |
| 107643 | 108198 | addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid); |
| 107644 | 108199 | VdbeCoverage(v); |
| 107645 | | - callStatGet(pParse, regStat4, STAT_GET_NEQ, regEq); |
| 107646 | | - callStatGet(pParse, regStat4, STAT_GET_NLT, regLt); |
| 107647 | | - callStatGet(pParse, regStat4, STAT_GET_NDLT, regDLt); |
| 108200 | + callStatGet(pParse, regStat, STAT_GET_NEQ, regEq); |
| 108201 | + callStatGet(pParse, regStat, STAT_GET_NLT, regLt); |
| 108202 | + callStatGet(pParse, regStat, STAT_GET_NDLT, regDLt); |
| 107648 | 108203 | sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0); |
| 107649 | 108204 | VdbeCoverage(v); |
| 107650 | 108205 | for(i=0; i<nCol; i++){ |
| 107651 | 108206 | sqlite3ExprCodeLoadIndexColumn(pParse, pIdx, iTabCur, i, regCol+i); |
| 107652 | 108207 | } |
| | @@ -122629,10 +123184,11 @@ |
| 122629 | 123184 | const char *(*filename_wal)(const char*); |
| 122630 | 123185 | /* Version 3.32.0 and later */ |
| 122631 | 123186 | char *(*create_filename)(const char*,const char*,const char*, |
| 122632 | 123187 | int,const char**); |
| 122633 | 123188 | void (*free_filename)(char*); |
| 123189 | + sqlite3_file *(*database_file_object)(const char*); |
| 122634 | 123190 | }; |
| 122635 | 123191 | |
| 122636 | 123192 | /* |
| 122637 | 123193 | ** This is the function signature used for all extension entry points. It |
| 122638 | 123194 | ** is also defined in the file "loadext.c". |
| | @@ -122932,10 +123488,11 @@ |
| 122932 | 123488 | #define sqlite3_filename_journal sqlite3_api->filename_journal |
| 122933 | 123489 | #define sqlite3_filename_wal sqlite3_api->filename_wal |
| 122934 | 123490 | /* Version 3.32.0 and later */ |
| 122935 | 123491 | #define sqlite3_create_filename sqlite3_api->create_filename |
| 122936 | 123492 | #define sqlite3_free_filename sqlite3_api->free_filename |
| 123493 | +#define sqlite3_database_file_object sqlite3_api->database_file_object |
| 122937 | 123494 | #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */ |
| 122938 | 123495 | |
| 122939 | 123496 | #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 122940 | 123497 | /* This case when the file really is being compiled as a loadable |
| 122941 | 123498 | ** extension */ |
| | @@ -123413,11 +123970,20 @@ |
| 123413 | 123970 | sqlite3_filename_journal, |
| 123414 | 123971 | sqlite3_filename_wal, |
| 123415 | 123972 | /* Version 3.32.0 and later */ |
| 123416 | 123973 | sqlite3_create_filename, |
| 123417 | 123974 | sqlite3_free_filename, |
| 123975 | + sqlite3_database_file_object, |
| 123418 | 123976 | }; |
| 123977 | + |
| 123978 | +/* True if x is the directory separator character |
| 123979 | +*/ |
| 123980 | +#if SQLITE_OS_WIN |
| 123981 | +# define DirSep(X) ((X)=='/'||(X)=='\\') |
| 123982 | +#else |
| 123983 | +# define DirSep(X) ((X)=='/') |
| 123984 | +#endif |
| 123419 | 123985 | |
| 123420 | 123986 | /* |
| 123421 | 123987 | ** Attempt to load an SQLite extension library contained in the file |
| 123422 | 123988 | ** zFile. The entry point is zProc. zProc may be 0 in which case a |
| 123423 | 123989 | ** default entry point name (sqlite3_extension_init) is used. Use |
| | @@ -123516,11 +124082,11 @@ |
| 123516 | 124082 | if( zAltEntry==0 ){ |
| 123517 | 124083 | sqlite3OsDlClose(pVfs, handle); |
| 123518 | 124084 | return SQLITE_NOMEM_BKPT; |
| 123519 | 124085 | } |
| 123520 | 124086 | memcpy(zAltEntry, "sqlite3_", 8); |
| 123521 | | - for(iFile=ncFile-1; iFile>=0 && zFile[iFile]!='/'; iFile--){} |
| 124087 | + for(iFile=ncFile-1; iFile>=0 && !DirSep(zFile[iFile]); iFile--){} |
| 123522 | 124088 | iFile++; |
| 123523 | 124089 | if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3; |
| 123524 | 124090 | for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){ |
| 123525 | 124091 | if( sqlite3Isalpha(c) ){ |
| 123526 | 124092 | zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c]; |
| | @@ -123820,53 +124386,54 @@ |
| 123820 | 124386 | ** that script and rerun it. |
| 123821 | 124387 | */ |
| 123822 | 124388 | |
| 123823 | 124389 | /* The various pragma types */ |
| 123824 | 124390 | #define PragTyp_ACTIVATE_EXTENSIONS 0 |
| 123825 | | -#define PragTyp_HEADER_VALUE 1 |
| 123826 | | -#define PragTyp_AUTO_VACUUM 2 |
| 123827 | | -#define PragTyp_FLAG 3 |
| 123828 | | -#define PragTyp_BUSY_TIMEOUT 4 |
| 123829 | | -#define PragTyp_CACHE_SIZE 5 |
| 123830 | | -#define PragTyp_CACHE_SPILL 6 |
| 123831 | | -#define PragTyp_CASE_SENSITIVE_LIKE 7 |
| 123832 | | -#define PragTyp_COLLATION_LIST 8 |
| 123833 | | -#define PragTyp_COMPILE_OPTIONS 9 |
| 123834 | | -#define PragTyp_DATA_STORE_DIRECTORY 10 |
| 123835 | | -#define PragTyp_DATABASE_LIST 11 |
| 123836 | | -#define PragTyp_DEFAULT_CACHE_SIZE 12 |
| 123837 | | -#define PragTyp_ENCODING 13 |
| 123838 | | -#define PragTyp_FOREIGN_KEY_CHECK 14 |
| 123839 | | -#define PragTyp_FOREIGN_KEY_LIST 15 |
| 123840 | | -#define PragTyp_FUNCTION_LIST 16 |
| 123841 | | -#define PragTyp_HARD_HEAP_LIMIT 17 |
| 123842 | | -#define PragTyp_INCREMENTAL_VACUUM 18 |
| 123843 | | -#define PragTyp_INDEX_INFO 19 |
| 123844 | | -#define PragTyp_INDEX_LIST 20 |
| 123845 | | -#define PragTyp_INTEGRITY_CHECK 21 |
| 123846 | | -#define PragTyp_JOURNAL_MODE 22 |
| 123847 | | -#define PragTyp_JOURNAL_SIZE_LIMIT 23 |
| 123848 | | -#define PragTyp_LOCK_PROXY_FILE 24 |
| 123849 | | -#define PragTyp_LOCKING_MODE 25 |
| 123850 | | -#define PragTyp_PAGE_COUNT 26 |
| 123851 | | -#define PragTyp_MMAP_SIZE 27 |
| 123852 | | -#define PragTyp_MODULE_LIST 28 |
| 123853 | | -#define PragTyp_OPTIMIZE 29 |
| 123854 | | -#define PragTyp_PAGE_SIZE 30 |
| 123855 | | -#define PragTyp_PRAGMA_LIST 31 |
| 123856 | | -#define PragTyp_SECURE_DELETE 32 |
| 123857 | | -#define PragTyp_SHRINK_MEMORY 33 |
| 123858 | | -#define PragTyp_SOFT_HEAP_LIMIT 34 |
| 123859 | | -#define PragTyp_SYNCHRONOUS 35 |
| 123860 | | -#define PragTyp_TABLE_INFO 36 |
| 123861 | | -#define PragTyp_TEMP_STORE 37 |
| 123862 | | -#define PragTyp_TEMP_STORE_DIRECTORY 38 |
| 123863 | | -#define PragTyp_THREADS 39 |
| 123864 | | -#define PragTyp_WAL_AUTOCHECKPOINT 40 |
| 123865 | | -#define PragTyp_WAL_CHECKPOINT 41 |
| 123866 | | -#define PragTyp_LOCK_STATUS 42 |
| 123867 | | -#define PragTyp_STATS 43 |
| 124391 | +#define PragTyp_ANALYSIS_LIMIT 1 |
| 124392 | +#define PragTyp_HEADER_VALUE 2 |
| 124393 | +#define PragTyp_AUTO_VACUUM 3 |
| 124394 | +#define PragTyp_FLAG 4 |
| 124395 | +#define PragTyp_BUSY_TIMEOUT 5 |
| 124396 | +#define PragTyp_CACHE_SIZE 6 |
| 124397 | +#define PragTyp_CACHE_SPILL 7 |
| 124398 | +#define PragTyp_CASE_SENSITIVE_LIKE 8 |
| 124399 | +#define PragTyp_COLLATION_LIST 9 |
| 124400 | +#define PragTyp_COMPILE_OPTIONS 10 |
| 124401 | +#define PragTyp_DATA_STORE_DIRECTORY 11 |
| 124402 | +#define PragTyp_DATABASE_LIST 12 |
| 124403 | +#define PragTyp_DEFAULT_CACHE_SIZE 13 |
| 124404 | +#define PragTyp_ENCODING 14 |
| 124405 | +#define PragTyp_FOREIGN_KEY_CHECK 15 |
| 124406 | +#define PragTyp_FOREIGN_KEY_LIST 16 |
| 124407 | +#define PragTyp_FUNCTION_LIST 17 |
| 124408 | +#define PragTyp_HARD_HEAP_LIMIT 18 |
| 124409 | +#define PragTyp_INCREMENTAL_VACUUM 19 |
| 124410 | +#define PragTyp_INDEX_INFO 20 |
| 124411 | +#define PragTyp_INDEX_LIST 21 |
| 124412 | +#define PragTyp_INTEGRITY_CHECK 22 |
| 124413 | +#define PragTyp_JOURNAL_MODE 23 |
| 124414 | +#define PragTyp_JOURNAL_SIZE_LIMIT 24 |
| 124415 | +#define PragTyp_LOCK_PROXY_FILE 25 |
| 124416 | +#define PragTyp_LOCKING_MODE 26 |
| 124417 | +#define PragTyp_PAGE_COUNT 27 |
| 124418 | +#define PragTyp_MMAP_SIZE 28 |
| 124419 | +#define PragTyp_MODULE_LIST 29 |
| 124420 | +#define PragTyp_OPTIMIZE 30 |
| 124421 | +#define PragTyp_PAGE_SIZE 31 |
| 124422 | +#define PragTyp_PRAGMA_LIST 32 |
| 124423 | +#define PragTyp_SECURE_DELETE 33 |
| 124424 | +#define PragTyp_SHRINK_MEMORY 34 |
| 124425 | +#define PragTyp_SOFT_HEAP_LIMIT 35 |
| 124426 | +#define PragTyp_SYNCHRONOUS 36 |
| 124427 | +#define PragTyp_TABLE_INFO 37 |
| 124428 | +#define PragTyp_TEMP_STORE 38 |
| 124429 | +#define PragTyp_TEMP_STORE_DIRECTORY 39 |
| 124430 | +#define PragTyp_THREADS 40 |
| 124431 | +#define PragTyp_WAL_AUTOCHECKPOINT 41 |
| 124432 | +#define PragTyp_WAL_CHECKPOINT 42 |
| 124433 | +#define PragTyp_LOCK_STATUS 43 |
| 124434 | +#define PragTyp_STATS 44 |
| 123868 | 124435 | |
| 123869 | 124436 | /* Property flags associated with various pragma. */ |
| 123870 | 124437 | #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ |
| 123871 | 124438 | #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ |
| 123872 | 124439 | #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
| | @@ -123953,10 +124520,15 @@ |
| 123953 | 124520 | /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS, |
| 123954 | 124521 | /* ePragFlg: */ 0, |
| 123955 | 124522 | /* ColNames: */ 0, 0, |
| 123956 | 124523 | /* iArg: */ 0 }, |
| 123957 | 124524 | #endif |
| 124525 | + {/* zName: */ "analysis_limit", |
| 124526 | + /* ePragTyp: */ PragTyp_ANALYSIS_LIMIT, |
| 124527 | + /* ePragFlg: */ PragFlg_Result0, |
| 124528 | + /* ColNames: */ 0, 0, |
| 124529 | + /* iArg: */ 0 }, |
| 123958 | 124530 | #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) |
| 123959 | 124531 | {/* zName: */ "application_id", |
| 123960 | 124532 | /* ePragTyp: */ PragTyp_HEADER_VALUE, |
| 123961 | 124533 | /* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0, |
| 123962 | 124534 | /* ColNames: */ 0, 0, |
| | @@ -124453,11 +125025,11 @@ |
| 124453 | 125025 | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, |
| 124454 | 125026 | /* ColNames: */ 0, 0, |
| 124455 | 125027 | /* iArg: */ SQLITE_WriteSchema|SQLITE_NoSchemaError }, |
| 124456 | 125028 | #endif |
| 124457 | 125029 | }; |
| 124458 | | -/* Number of pragmas: 66 on by default, 76 total. */ |
| 125030 | +/* Number of pragmas: 67 on by default, 77 total. */ |
| 124459 | 125031 | |
| 124460 | 125032 | /************** End of pragma.h **********************************************/ |
| 124461 | 125033 | /************** Continuing where we left off in pragma.c *********************/ |
| 124462 | 125034 | |
| 124463 | 125035 | /* |
| | @@ -126157,11 +126729,10 @@ |
| 126157 | 126729 | sqlite3ResolvePartIdxLabel(pParse, jmp3); |
| 126158 | 126730 | } |
| 126159 | 126731 | } |
| 126160 | 126732 | sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v); |
| 126161 | 126733 | sqlite3VdbeJumpHere(v, loopTop-1); |
| 126162 | | -#ifndef SQLITE_OMIT_BTREECOUNT |
| 126163 | 126734 | if( !isQuick ){ |
| 126164 | 126735 | sqlite3VdbeLoadString(v, 2, "wrong # of entries in index "); |
| 126165 | 126736 | for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){ |
| 126166 | 126737 | if( pPk==pIdx ) continue; |
| 126167 | 126738 | sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3); |
| | @@ -126171,11 +126742,10 @@ |
| 126171 | 126742 | sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3); |
| 126172 | 126743 | integrityCheckResultRow(v); |
| 126173 | 126744 | sqlite3VdbeJumpHere(v, addr); |
| 126174 | 126745 | } |
| 126175 | 126746 | } |
| 126176 | | -#endif /* SQLITE_OMIT_BTREECOUNT */ |
| 126177 | 126747 | } |
| 126178 | 126748 | } |
| 126179 | 126749 | { |
| 126180 | 126750 | static const int iLn = VDBE_OFFSET_LINENO(2); |
| 126181 | 126751 | static const VdbeOpList endCode[] = { |
| | @@ -126605,10 +127175,29 @@ |
| 126605 | 127175 | sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff)); |
| 126606 | 127176 | } |
| 126607 | 127177 | returnSingleInt(v, sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1)); |
| 126608 | 127178 | break; |
| 126609 | 127179 | } |
| 127180 | + |
| 127181 | + /* |
| 127182 | + ** PRAGMA analysis_limit |
| 127183 | + ** PRAGMA analysis_limit = N |
| 127184 | + ** |
| 127185 | + ** Configure the maximum number of rows that ANALYZE will examine |
| 127186 | + ** in each index that it looks at. Return the new limit. |
| 127187 | + */ |
| 127188 | + case PragTyp_ANALYSIS_LIMIT: { |
| 127189 | + sqlite3_int64 N; |
| 127190 | + if( zRight |
| 127191 | + && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK |
| 127192 | + && N>=0 |
| 127193 | + ){ |
| 127194 | + db->nAnalysisLimit = (int)(N&0x7fffffff); |
| 127195 | + } |
| 127196 | + returnSingleInt(v, db->nAnalysisLimit); |
| 127197 | + break; |
| 127198 | + } |
| 126610 | 127199 | |
| 126611 | 127200 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) |
| 126612 | 127201 | /* |
| 126613 | 127202 | ** Report the current state of file logs for all databases |
| 126614 | 127203 | */ |
| | @@ -131404,10 +131993,11 @@ |
| 131404 | 131993 | if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){ |
| 131405 | 131994 | memset(&ifNullRow, 0, sizeof(ifNullRow)); |
| 131406 | 131995 | ifNullRow.op = TK_IF_NULL_ROW; |
| 131407 | 131996 | ifNullRow.pLeft = pCopy; |
| 131408 | 131997 | ifNullRow.iTable = pSubst->iNewTable; |
| 131998 | + ifNullRow.flags = EP_Skip; |
| 131409 | 131999 | pCopy = &ifNullRow; |
| 131410 | 132000 | } |
| 131411 | 132001 | testcase( ExprHasProperty(pCopy, EP_Subquery) ); |
| 131412 | 132002 | pNew = sqlite3ExprDup(db, pCopy, 0); |
| 131413 | 132003 | if( pNew && pSubst->isLeftJoin ){ |
| | @@ -134568,11 +135158,10 @@ |
| 134568 | 135158 | VdbeComment((v, "indicate accumulator empty")); |
| 134569 | 135159 | sqlite3VdbeAddOp1(v, OP_Return, regReset); |
| 134570 | 135160 | |
| 134571 | 135161 | } /* endif pGroupBy. Begin aggregate queries without GROUP BY: */ |
| 134572 | 135162 | else { |
| 134573 | | -#ifndef SQLITE_OMIT_BTREECOUNT |
| 134574 | 135163 | Table *pTab; |
| 134575 | 135164 | if( (pTab = isSimpleCount(p, &sAggInfo))!=0 ){ |
| 134576 | 135165 | /* If isSimpleCount() returns a pointer to a Table structure, then |
| 134577 | 135166 | ** the SQL statement is of the form: |
| 134578 | 135167 | ** |
| | @@ -134626,13 +135215,11 @@ |
| 134626 | 135215 | sqlite3VdbeChangeP4(v, -1, (char *)pKeyInfo, P4_KEYINFO); |
| 134627 | 135216 | } |
| 134628 | 135217 | sqlite3VdbeAddOp2(v, OP_Count, iCsr, sAggInfo.aFunc[0].iMem); |
| 134629 | 135218 | sqlite3VdbeAddOp1(v, OP_Close, iCsr); |
| 134630 | 135219 | explainSimpleCount(pParse, pTab, pBest); |
| 134631 | | - }else |
| 134632 | | -#endif /* SQLITE_OMIT_BTREECOUNT */ |
| 134633 | | - { |
| 135220 | + }else{ |
| 134634 | 135221 | int regAcc = 0; /* "populate accumulators" flag */ |
| 134635 | 135222 | |
| 134636 | 135223 | /* If there are accumulator registers but no min() or max() functions |
| 134637 | 135224 | ** without FILTER clauses, allocate register regAcc. Register regAcc |
| 134638 | 135225 | ** will contain 0 the first time the inner loop runs, and 1 thereafter. |
| | @@ -159255,19 +159842,82 @@ |
| 159255 | 159842 | |
| 159256 | 159843 | |
| 159257 | 159844 | /************** End of sqliteicu.h *******************************************/ |
| 159258 | 159845 | /************** Continuing where we left off in main.c ***********************/ |
| 159259 | 159846 | #endif |
| 159847 | + |
| 159848 | +/* |
| 159849 | +** This is an extension initializer that is a no-op and always |
| 159850 | +** succeeds, except that it fails if the fault-simulation is set |
| 159851 | +** to 500. |
| 159852 | +*/ |
| 159853 | +static int sqlite3TestExtInit(sqlite3 *db){ |
| 159854 | + (void)db; |
| 159855 | + return sqlite3FaultSim(500); |
| 159856 | +} |
| 159857 | + |
| 159858 | + |
| 159859 | +/* |
| 159860 | +** Forward declarations of external module initializer functions |
| 159861 | +** for modules that need them. |
| 159862 | +*/ |
| 159863 | +#ifdef SQLITE_ENABLE_FTS1 |
| 159864 | +SQLITE_PRIVATE int sqlite3Fts1Init(sqlite3*); |
| 159865 | +#endif |
| 159866 | +#ifdef SQLITE_ENABLE_FTS2 |
| 159867 | +SQLITE_PRIVATE int sqlite3Fts2Init(sqlite3*); |
| 159868 | +#endif |
| 159869 | +#ifdef SQLITE_ENABLE_FTS5 |
| 159870 | +SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*); |
| 159871 | +#endif |
| 159260 | 159872 | #ifdef SQLITE_ENABLE_JSON1 |
| 159261 | 159873 | SQLITE_PRIVATE int sqlite3Json1Init(sqlite3*); |
| 159262 | 159874 | #endif |
| 159263 | 159875 | #ifdef SQLITE_ENABLE_STMTVTAB |
| 159264 | 159876 | SQLITE_PRIVATE int sqlite3StmtVtabInit(sqlite3*); |
| 159265 | 159877 | #endif |
| 159878 | + |
| 159879 | +/* |
| 159880 | +** An array of pointers to extension initializer functions for |
| 159881 | +** built-in extensions. |
| 159882 | +*/ |
| 159883 | +static int (*const sqlite3BuiltinExtensions[])(sqlite3*) = { |
| 159884 | +#ifdef SQLITE_ENABLE_FTS1 |
| 159885 | + sqlite3Fts1Init, |
| 159886 | +#endif |
| 159887 | +#ifdef SQLITE_ENABLE_FTS2 |
| 159888 | + sqlite3Fts2Init, |
| 159889 | +#endif |
| 159890 | +#ifdef SQLITE_ENABLE_FTS3 |
| 159891 | + sqlite3Fts3Init, |
| 159892 | +#endif |
| 159266 | 159893 | #ifdef SQLITE_ENABLE_FTS5 |
| 159267 | | -SQLITE_PRIVATE int sqlite3Fts5Init(sqlite3*); |
| 159894 | + sqlite3Fts5Init, |
| 159268 | 159895 | #endif |
| 159896 | +#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) |
| 159897 | + sqlite3IcuInit, |
| 159898 | +#endif |
| 159899 | +#ifdef SQLITE_ENABLE_RTREE |
| 159900 | + sqlite3RtreeInit, |
| 159901 | +#endif |
| 159902 | +#ifdef SQLITE_ENABLE_DBPAGE_VTAB |
| 159903 | + sqlite3DbpageRegister, |
| 159904 | +#endif |
| 159905 | +#ifdef SQLITE_ENABLE_DBSTAT_VTAB |
| 159906 | + sqlite3DbstatRegister, |
| 159907 | +#endif |
| 159908 | + sqlite3TestExtInit, |
| 159909 | +#ifdef SQLITE_ENABLE_JSON1 |
| 159910 | + sqlite3Json1Init, |
| 159911 | +#endif |
| 159912 | +#ifdef SQLITE_ENABLE_STMTVTAB |
| 159913 | + sqlite3StmtVtabInit, |
| 159914 | +#endif |
| 159915 | +#ifdef SQLITE_ENABLE_BYTECODE_VTAB |
| 159916 | + sqlite3VdbeBytecodeVtabInit, |
| 159917 | +#endif |
| 159918 | +}; |
| 159269 | 159919 | |
| 159270 | 159920 | #ifndef SQLITE_AMALGAMATION |
| 159271 | 159921 | /* IMPLEMENTATION-OF: R-46656-45156 The sqlite3_version[] string constant |
| 159272 | 159922 | ** contains the text of SQLITE_VERSION macro. |
| 159273 | 159923 | */ |
| | @@ -162272,10 +162922,11 @@ |
| 162272 | 162922 | sqlite3 *db; /* Store allocated handle here */ |
| 162273 | 162923 | int rc; /* Return code */ |
| 162274 | 162924 | int isThreadsafe; /* True for threadsafe connections */ |
| 162275 | 162925 | char *zOpen = 0; /* Filename argument to pass to BtreeOpen() */ |
| 162276 | 162926 | char *zErrMsg = 0; /* Error message from sqlite3ParseUri() */ |
| 162927 | + int i; /* Loop counter */ |
| 162277 | 162928 | |
| 162278 | 162929 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 162279 | 162930 | if( ppDb==0 ) return SQLITE_MISUSE_BKPT; |
| 162280 | 162931 | #endif |
| 162281 | 162932 | *ppDb = 0; |
| | @@ -162512,18 +163163,15 @@ |
| 162512 | 163163 | */ |
| 162513 | 163164 | sqlite3Error(db, SQLITE_OK); |
| 162514 | 163165 | sqlite3RegisterPerConnectionBuiltinFunctions(db); |
| 162515 | 163166 | rc = sqlite3_errcode(db); |
| 162516 | 163167 | |
| 162517 | | -#ifdef SQLITE_ENABLE_FTS5 |
| 162518 | | - /* Register any built-in FTS5 module before loading the automatic |
| 162519 | | - ** extensions. This allows automatic extensions to register FTS5 |
| 162520 | | - ** tokenizers and auxiliary functions. */ |
| 162521 | | - if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 162522 | | - rc = sqlite3Fts5Init(db); |
| 162523 | | - } |
| 162524 | | -#endif |
| 163168 | + |
| 163169 | + /* Load compiled-in extensions */ |
| 163170 | + for(i=0; rc==SQLITE_OK && i<ArraySize(sqlite3BuiltinExtensions); i++){ |
| 163171 | + rc = sqlite3BuiltinExtensions[i](db); |
| 163172 | + } |
| 162525 | 163173 | |
| 162526 | 163174 | /* Load automatic extensions - extensions that have been registered |
| 162527 | 163175 | ** using the sqlite3_automatic_extension() API. |
| 162528 | 163176 | */ |
| 162529 | 163177 | if( rc==SQLITE_OK ){ |
| | @@ -162532,66 +163180,10 @@ |
| 162532 | 163180 | if( rc!=SQLITE_OK ){ |
| 162533 | 163181 | goto opendb_out; |
| 162534 | 163182 | } |
| 162535 | 163183 | } |
| 162536 | 163184 | |
| 162537 | | -#ifdef SQLITE_ENABLE_FTS1 |
| 162538 | | - if( !db->mallocFailed ){ |
| 162539 | | - extern int sqlite3Fts1Init(sqlite3*); |
| 162540 | | - rc = sqlite3Fts1Init(db); |
| 162541 | | - } |
| 162542 | | -#endif |
| 162543 | | - |
| 162544 | | -#ifdef SQLITE_ENABLE_FTS2 |
| 162545 | | - if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 162546 | | - extern int sqlite3Fts2Init(sqlite3*); |
| 162547 | | - rc = sqlite3Fts2Init(db); |
| 162548 | | - } |
| 162549 | | -#endif |
| 162550 | | - |
| 162551 | | -#ifdef SQLITE_ENABLE_FTS3 /* automatically defined by SQLITE_ENABLE_FTS4 */ |
| 162552 | | - if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 162553 | | - rc = sqlite3Fts3Init(db); |
| 162554 | | - } |
| 162555 | | -#endif |
| 162556 | | - |
| 162557 | | -#if defined(SQLITE_ENABLE_ICU) || defined(SQLITE_ENABLE_ICU_COLLATIONS) |
| 162558 | | - if( !db->mallocFailed && rc==SQLITE_OK ){ |
| 162559 | | - rc = sqlite3IcuInit(db); |
| 162560 | | - } |
| 162561 | | -#endif |
| 162562 | | - |
| 162563 | | -#ifdef SQLITE_ENABLE_RTREE |
| 162564 | | - if( !db->mallocFailed && rc==SQLITE_OK){ |
| 162565 | | - rc = sqlite3RtreeInit(db); |
| 162566 | | - } |
| 162567 | | -#endif |
| 162568 | | - |
| 162569 | | -#ifdef SQLITE_ENABLE_DBPAGE_VTAB |
| 162570 | | - if( !db->mallocFailed && rc==SQLITE_OK){ |
| 162571 | | - rc = sqlite3DbpageRegister(db); |
| 162572 | | - } |
| 162573 | | -#endif |
| 162574 | | - |
| 162575 | | -#ifdef SQLITE_ENABLE_DBSTAT_VTAB |
| 162576 | | - if( !db->mallocFailed && rc==SQLITE_OK){ |
| 162577 | | - rc = sqlite3DbstatRegister(db); |
| 162578 | | - } |
| 162579 | | -#endif |
| 162580 | | - |
| 162581 | | -#ifdef SQLITE_ENABLE_JSON1 |
| 162582 | | - if( !db->mallocFailed && rc==SQLITE_OK){ |
| 162583 | | - rc = sqlite3Json1Init(db); |
| 162584 | | - } |
| 162585 | | -#endif |
| 162586 | | - |
| 162587 | | -#ifdef SQLITE_ENABLE_STMTVTAB |
| 162588 | | - if( !db->mallocFailed && rc==SQLITE_OK){ |
| 162589 | | - rc = sqlite3StmtVtabInit(db); |
| 162590 | | - } |
| 162591 | | -#endif |
| 162592 | | - |
| 162593 | 163185 | #ifdef SQLITE_ENABLE_INTERNAL_FUNCTIONS |
| 162594 | 163186 | /* Testing use only!!! The -DSQLITE_ENABLE_INTERNAL_FUNCTIONS=1 compile-time |
| 162595 | 163187 | ** option gives access to internal functions by default. |
| 162596 | 163188 | ** Testing use only!!! */ |
| 162597 | 163189 | db->mDbFlags |= DBFLAG_InternalFunc; |
| | @@ -165357,10 +165949,11 @@ |
| 165357 | 165949 | SQLITE_PRIVATE void sqlite3Fts3DoclistPrev(int,char*,int,char**,sqlite3_int64*,int*,u8*); |
| 165358 | 165950 | SQLITE_PRIVATE int sqlite3Fts3EvalPhraseStats(Fts3Cursor *, Fts3Expr *, u32 *); |
| 165359 | 165951 | SQLITE_PRIVATE int sqlite3Fts3FirstFilter(sqlite3_int64, char *, int, char *); |
| 165360 | 165952 | SQLITE_PRIVATE void sqlite3Fts3CreateStatTable(int*, Fts3Table*); |
| 165361 | 165953 | SQLITE_PRIVATE int sqlite3Fts3EvalTestDeferred(Fts3Cursor *pCsr, int *pRc); |
| 165954 | +SQLITE_PRIVATE int sqlite3Fts3ReadInt(const char *z, int *pnOut); |
| 165362 | 165955 | |
| 165363 | 165956 | /* fts3_tokenizer.c */ |
| 165364 | 165957 | SQLITE_PRIVATE const char *sqlite3Fts3NextToken(const char *, int *); |
| 165365 | 165958 | SQLITE_PRIVATE int sqlite3Fts3InitHashTable(sqlite3 *, Fts3Hash *, const char *); |
| 165366 | 165959 | SQLITE_PRIVATE int sqlite3Fts3InitTokenizer(Fts3Hash *pHash, const char *, |
| | @@ -166088,10 +166681,26 @@ |
| 166088 | 166681 | fts3Appendf(pRc, &zRet, ", ?"); |
| 166089 | 166682 | } |
| 166090 | 166683 | sqlite3_free(zFree); |
| 166091 | 166684 | return zRet; |
| 166092 | 166685 | } |
| 166686 | + |
| 166687 | +/* |
| 166688 | +** Buffer z contains a positive integer value encoded as utf-8 text. |
| 166689 | +** Decode this value and store it in *pnOut, returning the number of bytes |
| 166690 | +** consumed. If an overflow error occurs return a negative value. |
| 166691 | +*/ |
| 166692 | +SQLITE_PRIVATE int sqlite3Fts3ReadInt(const char *z, int *pnOut){ |
| 166693 | + u64 iVal = 0; |
| 166694 | + int i; |
| 166695 | + for(i=0; z[i]>='0' && z[i]<='9'; i++){ |
| 166696 | + iVal = iVal*10 + (z[i] - '0'); |
| 166697 | + if( iVal>0x7FFFFFFF ) return -1; |
| 166698 | + } |
| 166699 | + *pnOut = (int)iVal; |
| 166700 | + return i; |
| 166701 | +} |
| 166093 | 166702 | |
| 166094 | 166703 | /* |
| 166095 | 166704 | ** This function interprets the string at (*pp) as a non-negative integer |
| 166096 | 166705 | ** value. It reads the integer and sets *pnOut to the value read, then |
| 166097 | 166706 | ** sets *pp to point to the byte immediately following the last byte of |
| | @@ -166104,23 +166713,21 @@ |
| 166104 | 166713 | ** |
| 166105 | 166714 | ** This function is used when parsing the "prefix=" FTS4 parameter. |
| 166106 | 166715 | */ |
| 166107 | 166716 | static int fts3GobbleInt(const char **pp, int *pnOut){ |
| 166108 | 166717 | const int MAX_NPREFIX = 10000000; |
| 166109 | | - const char *p; /* Iterator pointer */ |
| 166110 | 166718 | int nInt = 0; /* Output value */ |
| 166111 | | - |
| 166112 | | - for(p=*pp; p[0]>='0' && p[0]<='9'; p++){ |
| 166113 | | - nInt = nInt * 10 + (p[0] - '0'); |
| 166114 | | - if( nInt>MAX_NPREFIX ){ |
| 166115 | | - nInt = 0; |
| 166116 | | - break; |
| 166117 | | - } |
| 166118 | | - } |
| 166119 | | - if( p==*pp ) return SQLITE_ERROR; |
| 166719 | + int nByte; |
| 166720 | + nByte = sqlite3Fts3ReadInt(*pp, &nInt); |
| 166721 | + if( nInt>MAX_NPREFIX ){ |
| 166722 | + nInt = 0; |
| 166723 | + } |
| 166724 | + if( nByte==0 ){ |
| 166725 | + return SQLITE_ERROR; |
| 166726 | + } |
| 166120 | 166727 | *pnOut = nInt; |
| 166121 | | - *pp = p; |
| 166728 | + *pp += nByte; |
| 166122 | 166729 | return SQLITE_OK; |
| 166123 | 166730 | } |
| 166124 | 166731 | |
| 166125 | 166732 | /* |
| 166126 | 166733 | ** This function is called to allocate an array of Fts3Index structures |
| | @@ -172198,14 +172805,11 @@ |
| 172198 | 172805 | |
| 172199 | 172806 | /* If this is a "NEAR" keyword, check for an explicit nearness. */ |
| 172200 | 172807 | if( pKey->eType==FTSQUERY_NEAR ){ |
| 172201 | 172808 | assert( nKey==4 ); |
| 172202 | 172809 | if( zInput[4]=='/' && zInput[5]>='0' && zInput[5]<='9' ){ |
| 172203 | | - nNear = 0; |
| 172204 | | - for(nKey=5; zInput[nKey]>='0' && zInput[nKey]<='9'; nKey++){ |
| 172205 | | - nNear = nNear * 10 + (zInput[nKey] - '0'); |
| 172206 | | - } |
| 172810 | + nKey += 1+sqlite3Fts3ReadInt(&zInput[nKey+1], &nNear); |
| 172207 | 172811 | } |
| 172208 | 172812 | } |
| 172209 | 172813 | |
| 172210 | 172814 | /* At this point this is probably a keyword. But for that to be true, |
| 172211 | 172815 | ** the next byte must contain either whitespace, an open or close |
| | @@ -178384,25 +178988,25 @@ |
| 178384 | 178988 | ){ |
| 178385 | 178989 | const unsigned char *zText = sqlite3_column_text(pStmt, iCol); |
| 178386 | 178990 | if( zText ){ |
| 178387 | 178991 | int i; |
| 178388 | 178992 | int iMul = 1; |
| 178389 | | - i64 iVal = 0; |
| 178993 | + u64 iVal = 0; |
| 178390 | 178994 | for(i=0; zText[i]>='0' && zText[i]<='9'; i++){ |
| 178391 | 178995 | iVal = iVal*10 + (zText[i] - '0'); |
| 178392 | 178996 | } |
| 178393 | | - *piEndBlock = iVal; |
| 178997 | + *piEndBlock = (i64)iVal; |
| 178394 | 178998 | while( zText[i]==' ' ) i++; |
| 178395 | 178999 | iVal = 0; |
| 178396 | 179000 | if( zText[i]=='-' ){ |
| 178397 | 179001 | i++; |
| 178398 | 179002 | iMul = -1; |
| 178399 | 179003 | } |
| 178400 | 179004 | for(/* no-op */; zText[i]>='0' && zText[i]<='9'; i++){ |
| 178401 | 179005 | iVal = iVal*10 + (zText[i] - '0'); |
| 178402 | 179006 | } |
| 178403 | | - *pnByte = (iVal * (i64)iMul); |
| 179007 | + *pnByte = ((i64)iVal * (i64)iMul); |
| 178404 | 179008 | } |
| 178405 | 179009 | } |
| 178406 | 179010 | |
| 178407 | 179011 | |
| 178408 | 179012 | /* |
| | @@ -223901,11 +224505,11 @@ |
| 223901 | 224505 | int nArg, /* Number of args */ |
| 223902 | 224506 | sqlite3_value **apUnused /* Function arguments */ |
| 223903 | 224507 | ){ |
| 223904 | 224508 | assert( nArg==0 ); |
| 223905 | 224509 | UNUSED_PARAM2(nArg, apUnused); |
| 223906 | | - sqlite3_result_text(pCtx, "fts5: 2020-03-03 20:04:29 bd94d7d052734460904c687756231f8aa243a2252f07f742dd1e437aa940f536", -1, SQLITE_TRANSIENT); |
| 224510 | + sqlite3_result_text(pCtx, "fts5: 2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb216eda", -1, SQLITE_TRANSIENT); |
| 223907 | 224511 | } |
| 223908 | 224512 | |
| 223909 | 224513 | /* |
| 223910 | 224514 | ** Return true if zName is the extension on one of the shadow tables used |
| 223911 | 224515 | ** by this module. |
| | @@ -228552,11 +229156,12 @@ |
| 228552 | 229156 | } |
| 228553 | 229157 | case STMT_COLUMN_BUSY: { |
| 228554 | 229158 | sqlite3_result_int(ctx, sqlite3_stmt_busy(pCur->pStmt)); |
| 228555 | 229159 | break; |
| 228556 | 229160 | } |
| 228557 | | - case STMT_COLUMN_MEM: { |
| 229161 | + default: { |
| 229162 | + assert( i==STMT_COLUMN_MEM ); |
| 228558 | 229163 | i = SQLITE_STMTSTATUS_MEMUSED + |
| 228559 | 229164 | STMT_COLUMN_NSCAN - SQLITE_STMTSTATUS_FULLSCAN_STEP; |
| 228560 | 229165 | /* Fall thru */ |
| 228561 | 229166 | } |
| 228562 | 229167 | case STMT_COLUMN_NSCAN: |
| | @@ -228683,12 +229288,12 @@ |
| 228683 | 229288 | } |
| 228684 | 229289 | #endif /* SQLITE_CORE */ |
| 228685 | 229290 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 228686 | 229291 | |
| 228687 | 229292 | /************** End of stmt.c ************************************************/ |
| 228688 | | -#if __LINE__!=228688 |
| 229293 | +#if __LINE__!=229293 |
| 228689 | 229294 | #undef SQLITE_SOURCE_ID |
| 228690 | | -#define SQLITE_SOURCE_ID "2020-04-20 17:35:32 2fc80ef16ce5878311ab88a0c64631813572ffbb71f75363b4619c9667e0alt2" |
| 229295 | +#define SQLITE_SOURCE_ID "2020-05-04 19:52:00 8eee591d3cb9fadfd5cac5543bd66ef9cb371a72d3ad3241fb3bfd67fb21alt2" |
| 228691 | 229296 | #endif |
| 228692 | 229297 | /* Return the source-id for this library */ |
| 228693 | 229298 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 228694 | 229299 | /************************** End of sqlite3.c ******************************/ |
| 228695 | 229300 | |