Fossil SCM
Replace embedded SQLite version to version 3.8.2 stable.
Commit
1e4b84864acfc1f1089758f2d4d6e8ab8523aa55
Parent
ad2dd5680baf348…
2 files changed
+2429
-2229
+25
-71
+2429
-2229
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | /****************************************************************************** |
| 2 | 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | -** version 3.8.3. By combining all the individual C code files into this | |
| 3 | +** version 3.8.2. By combining all the individual C code files into this | |
| 4 | 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | 8 | ** translation unit. |
| @@ -133,13 +133,13 @@ | ||
| 133 | 133 | ** |
| 134 | 134 | ** See also: [sqlite3_libversion()], |
| 135 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 137 | */ |
| 138 | -#define SQLITE_VERSION "3.8.3" | |
| 139 | -#define SQLITE_VERSION_NUMBER 3008003 | |
| 140 | -#define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6" | |
| 138 | +#define SQLITE_VERSION "3.8.2" | |
| 139 | +#define SQLITE_VERSION_NUMBER 3008002 | |
| 140 | +#define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d" | |
| 141 | 141 | |
| 142 | 142 | /* |
| 143 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 145 | ** |
| @@ -517,11 +517,10 @@ | ||
| 517 | 517 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 518 | 518 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 519 | 519 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 520 | 520 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 521 | 521 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 522 | -#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) | |
| 523 | 522 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 524 | 523 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 525 | 524 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 526 | 525 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 527 | 526 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -585,12 +584,11 @@ | ||
| 585 | 584 | ** information is written to disk in the same order as calls |
| 586 | 585 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 587 | 586 | ** after reboot following a crash or power loss, the only bytes in a |
| 588 | 587 | ** file that were written at the application level might have changed |
| 589 | 588 | ** and that adjacent bytes, even bytes within the same sector are |
| 590 | -** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | |
| 591 | -** flag indicate that a file cannot be deleted when open. | |
| 589 | +** guaranteed to be unchanged. | |
| 592 | 590 | */ |
| 593 | 591 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 594 | 592 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 595 | 593 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 596 | 594 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| @@ -817,33 +815,19 @@ | ||
| 817 | 815 | ** to the [sqlite3_file] object associated with a particular database |
| 818 | 816 | ** connection. See the [sqlite3_file_control()] documentation for |
| 819 | 817 | ** additional information. |
| 820 | 818 | ** |
| 821 | 819 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 822 | -** No longer in use. | |
| 823 | -** | |
| 824 | -** <li>[[SQLITE_FCNTL_SYNC]] | |
| 825 | -** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and | |
| 826 | -** sent to the VFS immediately before the xSync method is invoked on a | |
| 827 | -** database file descriptor. Or, if the xSync method is not invoked | |
| 828 | -** because the user has configured SQLite with | |
| 829 | -** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place | |
| 830 | -** of the xSync method. In most cases, the pointer argument passed with | |
| 831 | -** this file-control is NULL. However, if the database file is being synced | |
| 832 | -** as part of a multi-database commit, the argument points to a nul-terminated | |
| 833 | -** string containing the transactions master-journal file name. VFSes that | |
| 834 | -** do not need this signal should silently ignore this opcode. Applications | |
| 835 | -** should not call [sqlite3_file_control()] with this opcode as doing so may | |
| 836 | -** disrupt the operation of the specialized VFSes that do require it. | |
| 837 | -** | |
| 838 | -** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] | |
| 839 | -** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite | |
| 840 | -** and sent to the VFS after a transaction has been committed immediately | |
| 841 | -** but before the database is unlocked. VFSes that do not need this signal | |
| 842 | -** should silently ignore this opcode. Applications should not call | |
| 843 | -** [sqlite3_file_control()] with this opcode as doing so may disrupt the | |
| 844 | -** operation of the specialized VFSes that do require it. | |
| 820 | +** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by | |
| 821 | +** SQLite and sent to all VFSes in place of a call to the xSync method | |
| 822 | +** when the database connection has [PRAGMA synchronous] set to OFF.)^ | |
| 823 | +** Some specialized VFSes need this signal in order to operate correctly | |
| 824 | +** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most | |
| 825 | +** VFSes do not need this signal and should silently ignore this opcode. | |
| 826 | +** Applications should not call [sqlite3_file_control()] with this | |
| 827 | +** opcode as doing so may disrupt the operation of the specialized VFSes | |
| 828 | +** that do require it. | |
| 845 | 829 | ** |
| 846 | 830 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 847 | 831 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 848 | 832 | ** retry counts and intervals for certain disk I/O operations for the |
| 849 | 833 | ** windows [VFS] in order to provide robustness in the presence of |
| @@ -963,16 +947,10 @@ | ||
| 963 | 947 | ** This file control is used by some VFS activity tracing [shims]. |
| 964 | 948 | ** The argument is a zero-terminated string. Higher layers in the |
| 965 | 949 | ** SQLite stack may generate instances of this file control if |
| 966 | 950 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
| 967 | 951 | ** |
| 968 | -** <li>[[SQLITE_FCNTL_HAS_MOVED]] | |
| 969 | -** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a | |
| 970 | -** pointer to an integer and it writes a boolean into that integer depending | |
| 971 | -** on whether or not the file has been renamed, moved, or deleted since it | |
| 972 | -** was first opened. | |
| 973 | -** | |
| 974 | 952 | ** </ul> |
| 975 | 953 | */ |
| 976 | 954 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 977 | 955 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 978 | 956 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| @@ -989,13 +967,10 @@ | ||
| 989 | 967 | #define SQLITE_FCNTL_PRAGMA 14 |
| 990 | 968 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 991 | 969 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 992 | 970 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 993 | 971 | #define SQLITE_FCNTL_TRACE 19 |
| 994 | -#define SQLITE_FCNTL_HAS_MOVED 20 | |
| 995 | -#define SQLITE_FCNTL_SYNC 21 | |
| 996 | -#define SQLITE_FCNTL_COMMIT_PHASETWO 22 | |
| 997 | 972 | |
| 998 | 973 | /* |
| 999 | 974 | ** CAPI3REF: Mutex Handle |
| 1000 | 975 | ** |
| 1001 | 976 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2426,17 +2401,15 @@ | ||
| 2426 | 2401 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2427 | 2402 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2428 | 2403 | ** applications to access the same PRNG for other purposes. |
| 2429 | 2404 | ** |
| 2430 | 2405 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2431 | -** ^If N is less than one, then P can be a NULL pointer. | |
| 2432 | 2406 | ** |
| 2433 | -** ^If this routine has not been previously called or if the previous | |
| 2434 | -** call had N less than one, then the PRNG is seeded using randomness | |
| 2435 | -** obtained from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2436 | -** ^If the previous call to this routine had an N of 1 or more then | |
| 2437 | -** the pseudo-randomness is generated | |
| 2407 | +** ^The first time this routine is invoked (either internally or by | |
| 2408 | +** the application) the PRNG is seeded using randomness obtained | |
| 2409 | +** from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2410 | +** ^On all subsequent invocations, the pseudo-randomness is generated | |
| 2438 | 2411 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2439 | 2412 | ** method. |
| 2440 | 2413 | */ |
| 2441 | 2414 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2442 | 2415 | |
| @@ -4010,28 +3983,19 @@ | ||
| 4010 | 3983 | ** parameter is less than -1 or greater than 127 then the behavior is |
| 4011 | 3984 | ** undefined. |
| 4012 | 3985 | ** |
| 4013 | 3986 | ** ^The fourth parameter, eTextRep, specifies what |
| 4014 | 3987 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
| 4015 | -** its parameters. The application should set this parameter to | |
| 4016 | -** [SQLITE_UTF16LE] if the function implementation invokes | |
| 4017 | -** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the | |
| 4018 | -** implementation invokes [sqlite3_value_text16be()] on an input, or | |
| 4019 | -** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] | |
| 4020 | -** otherwise. ^The same SQL function may be registered multiple times using | |
| 4021 | -** different preferred text encodings, with different implementations for | |
| 4022 | -** each encoding. | |
| 3988 | +** its parameters. Every SQL function implementation must be able to work | |
| 3989 | +** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be | |
| 3990 | +** more efficient with one encoding than another. ^An application may | |
| 3991 | +** invoke sqlite3_create_function() or sqlite3_create_function16() multiple | |
| 3992 | +** times with the same function but with different values of eTextRep. | |
| 4023 | 3993 | ** ^When multiple implementations of the same function are available, SQLite |
| 4024 | 3994 | ** will pick the one that involves the least amount of data conversion. |
| 4025 | -** | |
| 4026 | -** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] | |
| 4027 | -** to signal that the function will always return the same result given | |
| 4028 | -** the same inputs within a single SQL statement. Most SQL functions are | |
| 4029 | -** deterministic. The built-in [random()] SQL function is an example of a | |
| 4030 | -** function that is not deterministic. The SQLite query planner is able to | |
| 4031 | -** perform additional optimizations on deterministic functions, so use | |
| 4032 | -** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. | |
| 3995 | +** If there is only a single implementation which does not care what text | |
| 3996 | +** encoding is used, then the fourth argument should be [SQLITE_ANY]. | |
| 4033 | 3997 | ** |
| 4034 | 3998 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 4035 | 3999 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 4036 | 4000 | ** |
| 4037 | 4001 | ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are |
| @@ -4113,23 +4077,13 @@ | ||
| 4113 | 4077 | */ |
| 4114 | 4078 | #define SQLITE_UTF8 1 |
| 4115 | 4079 | #define SQLITE_UTF16LE 2 |
| 4116 | 4080 | #define SQLITE_UTF16BE 3 |
| 4117 | 4081 | #define SQLITE_UTF16 4 /* Use native byte order */ |
| 4118 | -#define SQLITE_ANY 5 /* Deprecated */ | |
| 4082 | +#define SQLITE_ANY 5 /* sqlite3_create_function only */ | |
| 4119 | 4083 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
| 4120 | 4084 | |
| 4121 | -/* | |
| 4122 | -** CAPI3REF: Function Flags | |
| 4123 | -** | |
| 4124 | -** These constants may be ORed together with the | |
| 4125 | -** [SQLITE_UTF8 | preferred text encoding] as the fourth argument | |
| 4126 | -** to [sqlite3_create_function()], [sqlite3_create_function16()], or | |
| 4127 | -** [sqlite3_create_function_v2()]. | |
| 4128 | -*/ | |
| 4129 | -#define SQLITE_DETERMINISTIC 0x800 | |
| 4130 | - | |
| 4131 | 4085 | /* |
| 4132 | 4086 | ** CAPI3REF: Deprecated Functions |
| 4133 | 4087 | ** DEPRECATED |
| 4134 | 4088 | ** |
| 4135 | 4089 | ** These functions are [deprecated]. In order to maintain |
| @@ -8627,11 +8581,10 @@ | ||
| 8627 | 8581 | typedef struct Lookaside Lookaside; |
| 8628 | 8582 | typedef struct LookasideSlot LookasideSlot; |
| 8629 | 8583 | typedef struct Module Module; |
| 8630 | 8584 | typedef struct NameContext NameContext; |
| 8631 | 8585 | typedef struct Parse Parse; |
| 8632 | -typedef struct PrintfArguments PrintfArguments; | |
| 8633 | 8586 | typedef struct RowSet RowSet; |
| 8634 | 8587 | typedef struct Savepoint Savepoint; |
| 8635 | 8588 | typedef struct Select Select; |
| 8636 | 8589 | typedef struct SelectDest SelectDest; |
| 8637 | 8590 | typedef struct SrcList SrcList; |
| @@ -9100,11 +9053,11 @@ | ||
| 9100 | 9053 | #define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */ |
| 9101 | 9054 | #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */ |
| 9102 | 9055 | #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */ |
| 9103 | 9056 | #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 9104 | 9057 | #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9105 | -#define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ | |
| 9058 | +#define OP_Copy 30 /* synopsis: r[P2@P3]=r[P1@P3] */ | |
| 9106 | 9059 | #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */ |
| 9107 | 9060 | #define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */ |
| 9108 | 9061 | #define OP_CollSeq 33 |
| 9109 | 9062 | #define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */ |
| 9110 | 9063 | #define OP_MustBeInt 35 |
| @@ -9265,11 +9218,11 @@ | ||
| 9265 | 9218 | |
| 9266 | 9219 | /* |
| 9267 | 9220 | ** Prototypes for the VDBE interface. See comments on the implementation |
| 9268 | 9221 | ** for a description of what each of these routines does. |
| 9269 | 9222 | */ |
| 9270 | -SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*); | |
| 9223 | +SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3*); | |
| 9271 | 9224 | SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int); |
| 9272 | 9225 | SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int); |
| 9273 | 9226 | SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int); |
| 9274 | 9227 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 9275 | 9228 | SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| @@ -9280,11 +9233,10 @@ | ||
| 9280 | 9233 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 9281 | 9234 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 9282 | 9235 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 9283 | 9236 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 9284 | 9237 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 9285 | -SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe*); | |
| 9286 | 9238 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 9287 | 9239 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 9288 | 9240 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 9289 | 9241 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| 9290 | 9242 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*); |
| @@ -9487,11 +9439,10 @@ | ||
| 9487 | 9439 | SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); |
| 9488 | 9440 | #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0) |
| 9489 | 9441 | SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); |
| 9490 | 9442 | SQLITE_PRIVATE void sqlite3PagerRef(DbPage*); |
| 9491 | 9443 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*); |
| 9492 | -SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*); | |
| 9493 | 9444 | |
| 9494 | 9445 | /* Operations on page references. */ |
| 9495 | 9446 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*); |
| 9496 | 9447 | SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*); |
| 9497 | 9448 | SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int); |
| @@ -9502,11 +9453,11 @@ | ||
| 9502 | 9453 | /* Functions used to manage pager transactions and savepoints. */ |
| 9503 | 9454 | SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*); |
| 9504 | 9455 | SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int); |
| 9505 | 9456 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int); |
| 9506 | 9457 | SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*); |
| 9507 | -SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster); | |
| 9458 | +SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager); | |
| 9508 | 9459 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*); |
| 9509 | 9460 | SQLITE_PRIVATE int sqlite3PagerRollback(Pager*); |
| 9510 | 9461 | SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n); |
| 9511 | 9462 | SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint); |
| 9512 | 9463 | SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager); |
| @@ -10374,11 +10325,11 @@ | ||
| 10374 | 10325 | */ |
| 10375 | 10326 | #define SQLITE_QueryFlattener 0x0001 /* Query flattening */ |
| 10376 | 10327 | #define SQLITE_ColumnCache 0x0002 /* Column cache */ |
| 10377 | 10328 | #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ |
| 10378 | 10329 | #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ |
| 10379 | -/* not used 0x0010 // Was: SQLITE_IdxRealAsInt */ | |
| 10330 | +#define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */ | |
| 10380 | 10331 | #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ |
| 10381 | 10332 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10382 | 10333 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10383 | 10334 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10384 | 10335 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| @@ -11006,11 +10957,10 @@ | ||
| 11006 | 10957 | u8 useSortingIdx; /* In direct mode, reference the sorting index rather |
| 11007 | 10958 | ** than the source table */ |
| 11008 | 10959 | int sortingIdx; /* Cursor number of the sorting index */ |
| 11009 | 10960 | int sortingIdxPTab; /* Cursor number of pseudo-table */ |
| 11010 | 10961 | int nSortingColumn; /* Number of columns in the sorting index */ |
| 11011 | - int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */ | |
| 11012 | 10962 | ExprList *pGroupBy; /* The group by clause */ |
| 11013 | 10963 | struct AggInfo_col { /* For each column used in source tables */ |
| 11014 | 10964 | Table *pTab; /* Source table */ |
| 11015 | 10965 | int iTable; /* Cursor number of the source table */ |
| 11016 | 10966 | int iColumn; /* Column number within the source table */ |
| @@ -11608,13 +11558,10 @@ | ||
| 11608 | 11558 | int nErr; /* Number of errors seen */ |
| 11609 | 11559 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 11610 | 11560 | int nMem; /* Number of memory cells used so far */ |
| 11611 | 11561 | int nSet; /* Number of sets used so far */ |
| 11612 | 11562 | int nOnce; /* Number of OP_Once instructions so far */ |
| 11613 | - int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ | |
| 11614 | - int nLabel; /* Number of labels used */ | |
| 11615 | - int *aLabel; /* Space to hold the labels */ | |
| 11616 | 11563 | int ckBase; /* Base register of data during check constraints */ |
| 11617 | 11564 | int iPartIdxTab; /* Table corresponding to a partial index */ |
| 11618 | 11565 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 11619 | 11566 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 11620 | 11567 | struct yColCache { |
| @@ -12087,24 +12034,14 @@ | ||
| 12087 | 12034 | SQLITE_PRIVATE int sqlite3IsNaN(double); |
| 12088 | 12035 | #else |
| 12089 | 12036 | # define sqlite3IsNaN(X) 0 |
| 12090 | 12037 | #endif |
| 12091 | 12038 | |
| 12092 | -/* | |
| 12093 | -** An instance of the following structure holds information about SQL | |
| 12094 | -** functions arguments that are the parameters to the printf() function. | |
| 12095 | -*/ | |
| 12096 | -struct PrintfArguments { | |
| 12097 | - int nArg; /* Total number of arguments */ | |
| 12098 | - int nUsed; /* Number of arguments used so far */ | |
| 12099 | - sqlite3_value **apArg; /* The argument values */ | |
| 12100 | -}; | |
| 12101 | - | |
| 12102 | -#define SQLITE_PRINTF_INTERNAL 0x01 | |
| 12103 | -#define SQLITE_PRINTF_SQLFUNC 0x02 | |
| 12104 | -SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); | |
| 12105 | -SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...); | |
| 12039 | +SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, int, const char*, va_list); | |
| 12040 | +#ifndef SQLITE_OMIT_TRACE | |
| 12041 | +SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...); | |
| 12042 | +#endif | |
| 12106 | 12043 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 12107 | 12044 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 12108 | 12045 | SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); |
| 12109 | 12046 | #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
| 12110 | 12047 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| @@ -12290,10 +12227,11 @@ | ||
| 12290 | 12227 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12291 | 12228 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12292 | 12229 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12293 | 12230 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12294 | 12231 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12232 | +SQLITE_PRIVATE void sqlite3PrngResetState(void); | |
| 12295 | 12233 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12296 | 12234 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12297 | 12235 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12298 | 12236 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12299 | 12237 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -12458,11 +12396,12 @@ | ||
| 12458 | 12396 | SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...); |
| 12459 | 12397 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 12460 | 12398 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 12461 | 12399 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 12462 | 12400 | |
| 12463 | -#if defined(SQLITE_TEST) | |
| 12401 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \ | |
| 12402 | + defined(SQLITE_DEBUG_OS_TRACE) | |
| 12464 | 12403 | SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 12465 | 12404 | #endif |
| 12466 | 12405 | |
| 12467 | 12406 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 12468 | 12407 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| @@ -12488,11 +12427,10 @@ | ||
| 12488 | 12427 | |
| 12489 | 12428 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 12490 | 12429 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 12491 | 12430 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 12492 | 12431 | void(*)(void*)); |
| 12493 | -SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*); | |
| 12494 | 12432 | SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*); |
| 12495 | 12433 | SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *); |
| 12496 | 12434 | SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); |
| 12497 | 12435 | SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
| 12498 | 12436 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| @@ -12554,11 +12492,10 @@ | ||
| 12554 | 12492 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 12555 | 12493 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 12556 | 12494 | |
| 12557 | 12495 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); |
| 12558 | 12496 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 12559 | -SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*); | |
| 12560 | 12497 | SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int); |
| 12561 | 12498 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 12562 | 12499 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| 12563 | 12500 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 12564 | 12501 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| @@ -13781,13 +13718,16 @@ | ||
| 13781 | 13718 | Op *aOp; /* Space to hold the virtual machine's program */ |
| 13782 | 13719 | Mem *aMem; /* The memory locations */ |
| 13783 | 13720 | Mem **apArg; /* Arguments to currently executing user function */ |
| 13784 | 13721 | Mem *aColName; /* Column names to return */ |
| 13785 | 13722 | Mem *pResultSet; /* Pointer to an array of results */ |
| 13786 | - Parse *pParse; /* Parsing context used to create this Vdbe */ | |
| 13787 | 13723 | int nMem; /* Number of memory locations currently allocated */ |
| 13788 | 13724 | int nOp; /* Number of instructions in the program */ |
| 13725 | + int nOpAlloc; /* Number of slots allocated for aOp[] */ | |
| 13726 | + int nLabel; /* Number of labels used */ | |
| 13727 | + int *aLabel; /* Space to hold the labels */ | |
| 13728 | + u16 nResColumn; /* Number of columns in one row of the result set */ | |
| 13789 | 13729 | int nCursor; /* Number of slots in apCsr[] */ |
| 13790 | 13730 | u32 magic; /* Magic number for sanity checking */ |
| 13791 | 13731 | char *zErrMsg; /* Error message written here */ |
| 13792 | 13732 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 13793 | 13733 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| @@ -13796,11 +13736,10 @@ | ||
| 13796 | 13736 | ynVar nVar; /* Number of entries in aVar[] */ |
| 13797 | 13737 | ynVar nzVar; /* Number of entries in azVar[] */ |
| 13798 | 13738 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 13799 | 13739 | int pc; /* The program counter */ |
| 13800 | 13740 | int rc; /* Value to return */ |
| 13801 | - u16 nResColumn; /* Number of columns in one row of the result set */ | |
| 13802 | 13741 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 13803 | 13742 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 13804 | 13743 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 13805 | 13744 | bft inVtabMethod:2; /* See comments above */ |
| 13806 | 13745 | bft changeCntOn:1; /* True to update the change-counter */ |
| @@ -13856,11 +13795,11 @@ | ||
| 13856 | 13795 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 13857 | 13796 | SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*); |
| 13858 | 13797 | #endif |
| 13859 | 13798 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 13860 | 13799 | SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int); |
| 13861 | -SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); | |
| 13800 | +SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int); | |
| 13862 | 13801 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| 13863 | 13802 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); |
| 13864 | 13803 | |
| 13865 | 13804 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 13866 | 13805 | SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*); |
| @@ -15446,25 +15385,11 @@ | ||
| 15446 | 15385 | ** really care if the VFS receives and understands the information since it |
| 15447 | 15386 | ** is only a hint and can be safely ignored. The sqlite3OsFileControlHint() |
| 15448 | 15387 | ** routine has no return value since the return value would be meaningless. |
| 15449 | 15388 | */ |
| 15450 | 15389 | SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ |
| 15451 | -#ifdef SQLITE_TEST | |
| 15452 | - if( op!=SQLITE_FCNTL_COMMIT_PHASETWO ){ | |
| 15453 | - /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite | |
| 15454 | - ** is using a regular VFS, it is called after the corresponding | |
| 15455 | - ** transaction has been committed. Injecting a fault at this point | |
| 15456 | - ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM | |
| 15457 | - ** but the transaction is committed anyway. | |
| 15458 | - ** | |
| 15459 | - ** The core must call OsFileControl() though, not OsFileControlHint(), | |
| 15460 | - ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably | |
| 15461 | - ** means the commit really has failed and an error should be returned | |
| 15462 | - ** to the user. */ | |
| 15463 | - DO_OS_MALLOC_TEST(id); | |
| 15464 | - } | |
| 15465 | -#endif | |
| 15390 | + DO_OS_MALLOC_TEST(id); | |
| 15466 | 15391 | return id->pMethods->xFileControl(id, op, pArg); |
| 15467 | 15392 | } |
| 15468 | 15393 | SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){ |
| 15469 | 15394 | (void)id->pMethods->xFileControl(id, op, pArg); |
| 15470 | 15395 | } |
| @@ -19455,11 +19380,11 @@ | ||
| 19455 | 19380 | /* |
| 19456 | 19381 | ** TRUE if p is a lookaside memory allocation from db |
| 19457 | 19382 | */ |
| 19458 | 19383 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 19459 | 19384 | static int isLookaside(sqlite3 *db, void *p){ |
| 19460 | - return p>=db->lookaside.pStart && p<db->lookaside.pEnd; | |
| 19385 | + return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd; | |
| 19461 | 19386 | } |
| 19462 | 19387 | #else |
| 19463 | 19388 | #define isLookaside(A,B) 0 |
| 19464 | 19389 | #endif |
| 19465 | 19390 | |
| @@ -19471,13 +19396,12 @@ | ||
| 19471 | 19396 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 19472 | 19397 | assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); |
| 19473 | 19398 | return sqlite3GlobalConfig.m.xSize(p); |
| 19474 | 19399 | } |
| 19475 | 19400 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ |
| 19476 | - assert( db!=0 ); | |
| 19477 | - assert( sqlite3_mutex_held(db->mutex) ); | |
| 19478 | - if( isLookaside(db, p) ){ | |
| 19401 | + assert( db==0 || sqlite3_mutex_held(db->mutex) ); | |
| 19402 | + if( db && isLookaside(db, p) ){ | |
| 19479 | 19403 | return db->lookaside.sz; |
| 19480 | 19404 | }else{ |
| 19481 | 19405 | assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 19482 | 19406 | assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) ); |
| 19483 | 19407 | assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| @@ -19955,35 +19879,10 @@ | ||
| 19955 | 19879 | } |
| 19956 | 19880 | if( N>0 ){ |
| 19957 | 19881 | sqlite3StrAccumAppend(pAccum, zSpaces, N); |
| 19958 | 19882 | } |
| 19959 | 19883 | } |
| 19960 | - | |
| 19961 | -/* | |
| 19962 | -** Set the StrAccum object to an error mode. | |
| 19963 | -*/ | |
| 19964 | -static void setStrAccumError(StrAccum *p, u8 eError){ | |
| 19965 | - p->accError = eError; | |
| 19966 | - p->nAlloc = 0; | |
| 19967 | -} | |
| 19968 | - | |
| 19969 | -/* | |
| 19970 | -** Extra argument values from a PrintfArguments object | |
| 19971 | -*/ | |
| 19972 | -static sqlite3_int64 getIntArg(PrintfArguments *p){ | |
| 19973 | - if( p->nArg<=p->nUsed ) return 0; | |
| 19974 | - return sqlite3_value_int64(p->apArg[p->nUsed++]); | |
| 19975 | -} | |
| 19976 | -static double getDoubleArg(PrintfArguments *p){ | |
| 19977 | - if( p->nArg<=p->nUsed ) return 0.0; | |
| 19978 | - return sqlite3_value_double(p->apArg[p->nUsed++]); | |
| 19979 | -} | |
| 19980 | -static char *getTextArg(PrintfArguments *p){ | |
| 19981 | - if( p->nArg<=p->nUsed ) return 0; | |
| 19982 | - return (char*)sqlite3_value_text(p->apArg[p->nUsed++]); | |
| 19983 | -} | |
| 19984 | - | |
| 19985 | 19884 | |
| 19986 | 19885 | /* |
| 19987 | 19886 | ** On machines with a small stack size, you can redefine the |
| 19988 | 19887 | ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. |
| 19989 | 19888 | */ |
| @@ -19994,14 +19893,14 @@ | ||
| 19994 | 19893 | |
| 19995 | 19894 | /* |
| 19996 | 19895 | ** Render a string given by "fmt" into the StrAccum object. |
| 19997 | 19896 | */ |
| 19998 | 19897 | SQLITE_PRIVATE void sqlite3VXPrintf( |
| 19999 | - StrAccum *pAccum, /* Accumulate results here */ | |
| 20000 | - u32 bFlags, /* SQLITE_PRINTF_* flags */ | |
| 20001 | - const char *fmt, /* Format string */ | |
| 20002 | - va_list ap /* arguments */ | |
| 19898 | + StrAccum *pAccum, /* Accumulate results here */ | |
| 19899 | + int useExtended, /* Allow extended %-conversions */ | |
| 19900 | + const char *fmt, /* Format string */ | |
| 19901 | + va_list ap /* arguments */ | |
| 20003 | 19902 | ){ |
| 20004 | 19903 | int c; /* Next character in the format string */ |
| 20005 | 19904 | char *bufpt; /* Pointer to the conversion buffer */ |
| 20006 | 19905 | int precision; /* Precision of the current field */ |
| 20007 | 19906 | int length; /* Length of the field */ |
| @@ -20015,12 +19914,10 @@ | ||
| 20015 | 19914 | etByte flag_zeropad; /* True if field width constant starts with zero */ |
| 20016 | 19915 | etByte flag_long; /* True if "l" flag is present */ |
| 20017 | 19916 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 20018 | 19917 | etByte done; /* Loop termination flag */ |
| 20019 | 19918 | etByte xtype = 0; /* Conversion paradigm */ |
| 20020 | - u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ | |
| 20021 | - u8 useIntern; /* Ok to use internal conversions (ex: %T) */ | |
| 20022 | 19919 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 20023 | 19920 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 20024 | 19921 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| 20025 | 19922 | const et_info *infop; /* Pointer to the appropriate info structure */ |
| 20026 | 19923 | char *zOut; /* Rendering buffer */ |
| @@ -20031,22 +19928,13 @@ | ||
| 20031 | 19928 | int nsd; /* Number of significant digits returned */ |
| 20032 | 19929 | double rounder; /* Used for rounding floating point values */ |
| 20033 | 19930 | etByte flag_dp; /* True if decimal point should be shown */ |
| 20034 | 19931 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 20035 | 19932 | #endif |
| 20036 | - PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ | |
| 20037 | 19933 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 20038 | 19934 | |
| 20039 | 19935 | bufpt = 0; |
| 20040 | - if( bFlags ){ | |
| 20041 | - if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ | |
| 20042 | - pArgList = va_arg(ap, PrintfArguments*); | |
| 20043 | - } | |
| 20044 | - useIntern = bFlags & SQLITE_PRINTF_INTERNAL; | |
| 20045 | - }else{ | |
| 20046 | - bArgList = useIntern = 0; | |
| 20047 | - } | |
| 20048 | 19936 | for(; (c=(*fmt))!=0; ++fmt){ |
| 20049 | 19937 | if( c!='%' ){ |
| 20050 | 19938 | int amt; |
| 20051 | 19939 | bufpt = (char *)fmt; |
| 20052 | 19940 | amt = 1; |
| @@ -20074,15 +19962,11 @@ | ||
| 20074 | 19962 | } |
| 20075 | 19963 | }while( !done && (c=(*++fmt))!=0 ); |
| 20076 | 19964 | /* Get the field width */ |
| 20077 | 19965 | width = 0; |
| 20078 | 19966 | if( c=='*' ){ |
| 20079 | - if( bArgList ){ | |
| 20080 | - width = (int)getIntArg(pArgList); | |
| 20081 | - }else{ | |
| 20082 | - width = va_arg(ap,int); | |
| 20083 | - } | |
| 19967 | + width = va_arg(ap,int); | |
| 20084 | 19968 | if( width<0 ){ |
| 20085 | 19969 | flag_leftjustify = 1; |
| 20086 | 19970 | width = -width; |
| 20087 | 19971 | } |
| 20088 | 19972 | c = *++fmt; |
| @@ -20095,15 +19979,11 @@ | ||
| 20095 | 19979 | /* Get the precision */ |
| 20096 | 19980 | if( c=='.' ){ |
| 20097 | 19981 | precision = 0; |
| 20098 | 19982 | c = *++fmt; |
| 20099 | 19983 | if( c=='*' ){ |
| 20100 | - if( bArgList ){ | |
| 20101 | - precision = (int)getIntArg(pArgList); | |
| 20102 | - }else{ | |
| 20103 | - precision = va_arg(ap,int); | |
| 20104 | - } | |
| 19984 | + precision = va_arg(ap,int); | |
| 20105 | 19985 | if( precision<0 ) precision = -precision; |
| 20106 | 19986 | c = *++fmt; |
| 20107 | 19987 | }else{ |
| 20108 | 19988 | while( c>='0' && c<='9' ){ |
| 20109 | 19989 | precision = precision*10 + c - '0'; |
| @@ -20130,11 +20010,11 @@ | ||
| 20130 | 20010 | infop = &fmtinfo[0]; |
| 20131 | 20011 | xtype = etINVALID; |
| 20132 | 20012 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| 20133 | 20013 | if( c==fmtinfo[idx].fmttype ){ |
| 20134 | 20014 | infop = &fmtinfo[idx]; |
| 20135 | - if( useIntern || (infop->flags & FLAG_INTERN)==0 ){ | |
| 20015 | + if( useExtended || (infop->flags & FLAG_INTERN)==0 ){ | |
| 20136 | 20016 | xtype = infop->type; |
| 20137 | 20017 | }else{ |
| 20138 | 20018 | return; |
| 20139 | 20019 | } |
| 20140 | 20020 | break; |
| @@ -20170,13 +20050,11 @@ | ||
| 20170 | 20050 | /* Fall through into the next case */ |
| 20171 | 20051 | case etORDINAL: |
| 20172 | 20052 | case etRADIX: |
| 20173 | 20053 | if( infop->flags & FLAG_SIGNED ){ |
| 20174 | 20054 | i64 v; |
| 20175 | - if( bArgList ){ | |
| 20176 | - v = getIntArg(pArgList); | |
| 20177 | - }else if( flag_longlong ){ | |
| 20055 | + if( flag_longlong ){ | |
| 20178 | 20056 | v = va_arg(ap,i64); |
| 20179 | 20057 | }else if( flag_long ){ |
| 20180 | 20058 | v = va_arg(ap,long int); |
| 20181 | 20059 | }else{ |
| 20182 | 20060 | v = va_arg(ap,int); |
| @@ -20193,13 +20071,11 @@ | ||
| 20193 | 20071 | if( flag_plussign ) prefix = '+'; |
| 20194 | 20072 | else if( flag_blanksign ) prefix = ' '; |
| 20195 | 20073 | else prefix = 0; |
| 20196 | 20074 | } |
| 20197 | 20075 | }else{ |
| 20198 | - if( bArgList ){ | |
| 20199 | - longvalue = (u64)getIntArg(pArgList); | |
| 20200 | - }else if( flag_longlong ){ | |
| 20076 | + if( flag_longlong ){ | |
| 20201 | 20077 | longvalue = va_arg(ap,u64); |
| 20202 | 20078 | }else if( flag_long ){ |
| 20203 | 20079 | longvalue = va_arg(ap,unsigned long int); |
| 20204 | 20080 | }else{ |
| 20205 | 20081 | longvalue = va_arg(ap,unsigned int); |
| @@ -20215,11 +20091,11 @@ | ||
| 20215 | 20091 | zOut = buf; |
| 20216 | 20092 | }else{ |
| 20217 | 20093 | nOut = precision + 10; |
| 20218 | 20094 | zOut = zExtra = sqlite3Malloc( nOut ); |
| 20219 | 20095 | if( zOut==0 ){ |
| 20220 | - setStrAccumError(pAccum, STRACCUM_NOMEM); | |
| 20096 | + pAccum->accError = STRACCUM_NOMEM; | |
| 20221 | 20097 | return; |
| 20222 | 20098 | } |
| 20223 | 20099 | } |
| 20224 | 20100 | bufpt = &zOut[nOut-1]; |
| 20225 | 20101 | if( xtype==etORDINAL ){ |
| @@ -20255,15 +20131,11 @@ | ||
| 20255 | 20131 | length = (int)(&zOut[nOut-1]-bufpt); |
| 20256 | 20132 | break; |
| 20257 | 20133 | case etFLOAT: |
| 20258 | 20134 | case etEXP: |
| 20259 | 20135 | case etGENERIC: |
| 20260 | - if( bArgList ){ | |
| 20261 | - realvalue = getDoubleArg(pArgList); | |
| 20262 | - }else{ | |
| 20263 | - realvalue = va_arg(ap,double); | |
| 20264 | - } | |
| 20136 | + realvalue = va_arg(ap,double); | |
| 20265 | 20137 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 20266 | 20138 | length = 0; |
| 20267 | 20139 | #else |
| 20268 | 20140 | if( precision<0 ) precision = 6; /* Set default precision */ |
| 20269 | 20141 | if( realvalue<0.0 ){ |
| @@ -20331,11 +20203,11 @@ | ||
| 20331 | 20203 | e2 = exp; |
| 20332 | 20204 | } |
| 20333 | 20205 | if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ |
| 20334 | 20206 | bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); |
| 20335 | 20207 | if( bufpt==0 ){ |
| 20336 | - setStrAccumError(pAccum, STRACCUM_NOMEM); | |
| 20208 | + pAccum->accError = STRACCUM_NOMEM; | |
| 20337 | 20209 | return; |
| 20338 | 20210 | } |
| 20339 | 20211 | } |
| 20340 | 20212 | zOut = bufpt; |
| 20341 | 20213 | nsd = 16 + flag_altform2*10; |
| @@ -20414,27 +20286,20 @@ | ||
| 20414 | 20286 | length = width; |
| 20415 | 20287 | } |
| 20416 | 20288 | #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */ |
| 20417 | 20289 | break; |
| 20418 | 20290 | case etSIZE: |
| 20419 | - if( !bArgList ){ | |
| 20420 | - *(va_arg(ap,int*)) = pAccum->nChar; | |
| 20421 | - } | |
| 20291 | + *(va_arg(ap,int*)) = pAccum->nChar; | |
| 20422 | 20292 | length = width = 0; |
| 20423 | 20293 | break; |
| 20424 | 20294 | case etPERCENT: |
| 20425 | 20295 | buf[0] = '%'; |
| 20426 | 20296 | bufpt = buf; |
| 20427 | 20297 | length = 1; |
| 20428 | 20298 | break; |
| 20429 | 20299 | case etCHARX: |
| 20430 | - if( bArgList ){ | |
| 20431 | - bufpt = getTextArg(pArgList); | |
| 20432 | - c = bufpt ? bufpt[0] : 0; | |
| 20433 | - }else{ | |
| 20434 | - c = va_arg(ap,int); | |
| 20435 | - } | |
| 20300 | + c = va_arg(ap,int); | |
| 20436 | 20301 | buf[0] = (char)c; |
| 20437 | 20302 | if( precision>=0 ){ |
| 20438 | 20303 | for(idx=1; idx<precision; idx++) buf[idx] = (char)c; |
| 20439 | 20304 | length = precision; |
| 20440 | 20305 | }else{ |
| @@ -20442,18 +20307,14 @@ | ||
| 20442 | 20307 | } |
| 20443 | 20308 | bufpt = buf; |
| 20444 | 20309 | break; |
| 20445 | 20310 | case etSTRING: |
| 20446 | 20311 | case etDYNSTRING: |
| 20447 | - if( bArgList ){ | |
| 20448 | - bufpt = getTextArg(pArgList); | |
| 20449 | - }else{ | |
| 20450 | - bufpt = va_arg(ap,char*); | |
| 20451 | - } | |
| 20312 | + bufpt = va_arg(ap,char*); | |
| 20452 | 20313 | if( bufpt==0 ){ |
| 20453 | 20314 | bufpt = ""; |
| 20454 | - }else if( xtype==etDYNSTRING && !bArgList ){ | |
| 20315 | + }else if( xtype==etDYNSTRING ){ | |
| 20455 | 20316 | zExtra = bufpt; |
| 20456 | 20317 | } |
| 20457 | 20318 | if( precision>=0 ){ |
| 20458 | 20319 | for(length=0; length<precision && bufpt[length]; length++){} |
| 20459 | 20320 | }else{ |
| @@ -20465,17 +20326,11 @@ | ||
| 20465 | 20326 | case etSQLESCAPE3: { |
| 20466 | 20327 | int i, j, k, n, isnull; |
| 20467 | 20328 | int needQuote; |
| 20468 | 20329 | char ch; |
| 20469 | 20330 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */ |
| 20470 | - char *escarg; | |
| 20471 | - | |
| 20472 | - if( bArgList ){ | |
| 20473 | - escarg = getTextArg(pArgList); | |
| 20474 | - }else{ | |
| 20475 | - escarg = va_arg(ap,char*); | |
| 20476 | - } | |
| 20331 | + char *escarg = va_arg(ap,char*); | |
| 20477 | 20332 | isnull = escarg==0; |
| 20478 | 20333 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 20479 | 20334 | k = precision; |
| 20480 | 20335 | for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ |
| 20481 | 20336 | if( ch==q ) n++; |
| @@ -20483,11 +20338,11 @@ | ||
| 20483 | 20338 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 20484 | 20339 | n += i + 1 + needQuote*2; |
| 20485 | 20340 | if( n>etBUFSIZE ){ |
| 20486 | 20341 | bufpt = zExtra = sqlite3Malloc( n ); |
| 20487 | 20342 | if( bufpt==0 ){ |
| 20488 | - setStrAccumError(pAccum, STRACCUM_NOMEM); | |
| 20343 | + pAccum->accError = STRACCUM_NOMEM; | |
| 20489 | 20344 | return; |
| 20490 | 20345 | } |
| 20491 | 20346 | }else{ |
| 20492 | 20347 | bufpt = buf; |
| 20493 | 20348 | } |
| @@ -20506,28 +20361,26 @@ | ||
| 20506 | 20361 | ** if( precision>=0 && precision<length ) length = precision; */ |
| 20507 | 20362 | break; |
| 20508 | 20363 | } |
| 20509 | 20364 | case etTOKEN: { |
| 20510 | 20365 | Token *pToken = va_arg(ap, Token*); |
| 20511 | - assert( bArgList==0 ); | |
| 20512 | - if( pToken && pToken->n ){ | |
| 20366 | + if( pToken ){ | |
| 20513 | 20367 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
| 20514 | 20368 | } |
| 20515 | 20369 | length = width = 0; |
| 20516 | 20370 | break; |
| 20517 | 20371 | } |
| 20518 | 20372 | case etSRCLIST: { |
| 20519 | 20373 | SrcList *pSrc = va_arg(ap, SrcList*); |
| 20520 | 20374 | int k = va_arg(ap, int); |
| 20521 | 20375 | struct SrcList_item *pItem = &pSrc->a[k]; |
| 20522 | - assert( bArgList==0 ); | |
| 20523 | 20376 | assert( k>=0 && k<pSrc->nSrc ); |
| 20524 | 20377 | if( pItem->zDatabase ){ |
| 20525 | - sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); | |
| 20378 | + sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1); | |
| 20526 | 20379 | sqlite3StrAccumAppend(pAccum, ".", 1); |
| 20527 | 20380 | } |
| 20528 | - sqlite3StrAccumAppendAll(pAccum, pItem->zName); | |
| 20381 | + sqlite3StrAccumAppend(pAccum, pItem->zName, -1); | |
| 20529 | 20382 | length = width = 0; |
| 20530 | 20383 | break; |
| 20531 | 20384 | } |
| 20532 | 20385 | default: { |
| 20533 | 20386 | assert( xtype==etINVALID ); |
| @@ -20554,42 +20407,44 @@ | ||
| 20554 | 20407 | nspace = width-length; |
| 20555 | 20408 | if( nspace>0 ){ |
| 20556 | 20409 | sqlite3AppendSpace(pAccum, nspace); |
| 20557 | 20410 | } |
| 20558 | 20411 | } |
| 20559 | - if( zExtra ) sqlite3_free(zExtra); | |
| 20412 | + sqlite3_free(zExtra); | |
| 20560 | 20413 | }/* End for loop over the format string */ |
| 20561 | 20414 | } /* End of function */ |
| 20562 | 20415 | |
| 20563 | 20416 | /* |
| 20564 | 20417 | ** Append N bytes of text from z to the StrAccum object. |
| 20565 | 20418 | */ |
| 20566 | 20419 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 20567 | - assert( z!=0 ); | |
| 20568 | - assert( p->zText!=0 || p->nChar==0 || p->accError ); | |
| 20569 | - assert( N>=0 ); | |
| 20570 | - assert( p->accError==0 || p->nAlloc==0 ); | |
| 20420 | + assert( z!=0 || N==0 ); | |
| 20421 | + if( p->accError ){ | |
| 20422 | + testcase(p->accError==STRACCUM_TOOBIG); | |
| 20423 | + testcase(p->accError==STRACCUM_NOMEM); | |
| 20424 | + return; | |
| 20425 | + } | |
| 20426 | + assert( p->zText!=0 || p->nChar==0 ); | |
| 20427 | + if( N<=0 ){ | |
| 20428 | + if( N==0 || z[0]==0 ) return; | |
| 20429 | + N = sqlite3Strlen30(z); | |
| 20430 | + } | |
| 20571 | 20431 | if( p->nChar+N >= p->nAlloc ){ |
| 20572 | 20432 | char *zNew; |
| 20573 | - if( p->accError ){ | |
| 20574 | - testcase(p->accError==STRACCUM_TOOBIG); | |
| 20575 | - testcase(p->accError==STRACCUM_NOMEM); | |
| 20576 | - return; | |
| 20577 | - } | |
| 20578 | 20433 | if( !p->useMalloc ){ |
| 20434 | + p->accError = STRACCUM_TOOBIG; | |
| 20579 | 20435 | N = p->nAlloc - p->nChar - 1; |
| 20580 | - setStrAccumError(p, STRACCUM_TOOBIG); | |
| 20581 | 20436 | if( N<=0 ){ |
| 20582 | 20437 | return; |
| 20583 | 20438 | } |
| 20584 | 20439 | }else{ |
| 20585 | 20440 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 20586 | 20441 | i64 szNew = p->nChar; |
| 20587 | 20442 | szNew += N + 1; |
| 20588 | 20443 | if( szNew > p->mxAlloc ){ |
| 20589 | 20444 | sqlite3StrAccumReset(p); |
| 20590 | - setStrAccumError(p, STRACCUM_TOOBIG); | |
| 20445 | + p->accError = STRACCUM_TOOBIG; | |
| 20591 | 20446 | return; |
| 20592 | 20447 | }else{ |
| 20593 | 20448 | p->nAlloc = (int)szNew; |
| 20594 | 20449 | } |
| 20595 | 20450 | if( p->useMalloc==1 ){ |
| @@ -20599,28 +20454,20 @@ | ||
| 20599 | 20454 | } |
| 20600 | 20455 | if( zNew ){ |
| 20601 | 20456 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 20602 | 20457 | p->zText = zNew; |
| 20603 | 20458 | }else{ |
| 20459 | + p->accError = STRACCUM_NOMEM; | |
| 20604 | 20460 | sqlite3StrAccumReset(p); |
| 20605 | - setStrAccumError(p, STRACCUM_NOMEM); | |
| 20606 | 20461 | return; |
| 20607 | 20462 | } |
| 20608 | 20463 | } |
| 20609 | 20464 | } |
| 20610 | 20465 | assert( p->zText ); |
| 20611 | 20466 | memcpy(&p->zText[p->nChar], z, N); |
| 20612 | 20467 | p->nChar += N; |
| 20613 | 20468 | } |
| 20614 | - | |
| 20615 | -/* | |
| 20616 | -** Append the complete text of zero-terminated string z[] to the p string. | |
| 20617 | -*/ | |
| 20618 | -SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){ | |
| 20619 | - sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z)); | |
| 20620 | -} | |
| 20621 | - | |
| 20622 | 20469 | |
| 20623 | 20470 | /* |
| 20624 | 20471 | ** Finish off a string by making sure it is zero-terminated. |
| 20625 | 20472 | ** Return a pointer to the resulting string. Return a NULL |
| 20626 | 20473 | ** pointer if any kind of error was encountered. |
| @@ -20635,11 +20482,11 @@ | ||
| 20635 | 20482 | p->zText = sqlite3_malloc(p->nChar+1); |
| 20636 | 20483 | } |
| 20637 | 20484 | if( p->zText ){ |
| 20638 | 20485 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 20639 | 20486 | }else{ |
| 20640 | - setStrAccumError(p, STRACCUM_NOMEM); | |
| 20487 | + p->accError = STRACCUM_NOMEM; | |
| 20641 | 20488 | } |
| 20642 | 20489 | } |
| 20643 | 20490 | } |
| 20644 | 20491 | return p->zText; |
| 20645 | 20492 | } |
| @@ -20681,11 +20528,11 @@ | ||
| 20681 | 20528 | StrAccum acc; |
| 20682 | 20529 | assert( db!=0 ); |
| 20683 | 20530 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), |
| 20684 | 20531 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 20685 | 20532 | acc.db = db; |
| 20686 | - sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); | |
| 20533 | + sqlite3VXPrintf(&acc, 1, zFormat, ap); | |
| 20687 | 20534 | z = sqlite3StrAccumFinish(&acc); |
| 20688 | 20535 | if( acc.accError==STRACCUM_NOMEM ){ |
| 20689 | 20536 | db->mallocFailed = 1; |
| 20690 | 20537 | } |
| 20691 | 20538 | return z; |
| @@ -20837,19 +20684,21 @@ | ||
| 20837 | 20684 | fprintf(stdout,"%s", zBuf); |
| 20838 | 20685 | fflush(stdout); |
| 20839 | 20686 | } |
| 20840 | 20687 | #endif |
| 20841 | 20688 | |
| 20689 | +#ifndef SQLITE_OMIT_TRACE | |
| 20842 | 20690 | /* |
| 20843 | 20691 | ** variable-argument wrapper around sqlite3VXPrintf(). |
| 20844 | 20692 | */ |
| 20845 | -SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){ | |
| 20693 | +SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){ | |
| 20846 | 20694 | va_list ap; |
| 20847 | 20695 | va_start(ap,zFormat); |
| 20848 | - sqlite3VXPrintf(p, bFlags, zFormat, ap); | |
| 20696 | + sqlite3VXPrintf(p, 1, zFormat, ap); | |
| 20849 | 20697 | va_end(ap); |
| 20850 | 20698 | } |
| 20699 | +#endif | |
| 20851 | 20700 | |
| 20852 | 20701 | /************** End of printf.c **********************************************/ |
| 20853 | 20702 | /************** Begin file random.c ******************************************/ |
| 20854 | 20703 | /* |
| 20855 | 20704 | ** 2001 September 15 |
| @@ -20902,16 +20751,10 @@ | ||
| 20902 | 20751 | #if SQLITE_THREADSAFE |
| 20903 | 20752 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20904 | 20753 | sqlite3_mutex_enter(mutex); |
| 20905 | 20754 | #endif |
| 20906 | 20755 | |
| 20907 | - if( N<=0 ){ | |
| 20908 | - wsdPrng.isInit = 0; | |
| 20909 | - sqlite3_mutex_leave(mutex); | |
| 20910 | - return; | |
| 20911 | - } | |
| 20912 | - | |
| 20913 | 20756 | /* Initialize the state of the random number generator once, |
| 20914 | 20757 | ** the first time this routine is called. The seed value does |
| 20915 | 20758 | ** not need to contain a lot of randomness since we are not |
| 20916 | 20759 | ** trying to do secure encryption or anything like that... |
| 20917 | 20760 | ** |
| @@ -20935,20 +20778,19 @@ | ||
| 20935 | 20778 | wsdPrng.s[i] = t; |
| 20936 | 20779 | } |
| 20937 | 20780 | wsdPrng.isInit = 1; |
| 20938 | 20781 | } |
| 20939 | 20782 | |
| 20940 | - assert( N>0 ); | |
| 20941 | - do{ | |
| 20783 | + while( N-- ){ | |
| 20942 | 20784 | wsdPrng.i++; |
| 20943 | 20785 | t = wsdPrng.s[wsdPrng.i]; |
| 20944 | 20786 | wsdPrng.j += t; |
| 20945 | 20787 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20946 | 20788 | wsdPrng.s[wsdPrng.j] = t; |
| 20947 | 20789 | t += wsdPrng.s[wsdPrng.i]; |
| 20948 | 20790 | *(zBuf++) = wsdPrng.s[t]; |
| 20949 | - }while( --N ); | |
| 20791 | + } | |
| 20950 | 20792 | sqlite3_mutex_leave(mutex); |
| 20951 | 20793 | } |
| 20952 | 20794 | |
| 20953 | 20795 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20954 | 20796 | /* |
| @@ -20973,10 +20815,13 @@ | ||
| 20973 | 20815 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20974 | 20816 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20975 | 20817 | sizeof(sqlite3Prng) |
| 20976 | 20818 | ); |
| 20977 | 20819 | } |
| 20820 | +SQLITE_PRIVATE void sqlite3PrngResetState(void){ | |
| 20821 | + GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0; | |
| 20822 | +} | |
| 20978 | 20823 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20979 | 20824 | |
| 20980 | 20825 | /************** End of random.c **********************************************/ |
| 20981 | 20826 | /************** Begin file utf.c *********************************************/ |
| 20982 | 20827 | /* |
| @@ -21624,21 +21469,22 @@ | ||
| 21624 | 21469 | ** To clear the most recent error for sqlite handle "db", sqlite3Error |
| 21625 | 21470 | ** should be called with err_code set to SQLITE_OK and zFormat set |
| 21626 | 21471 | ** to NULL. |
| 21627 | 21472 | */ |
| 21628 | 21473 | SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){ |
| 21629 | - assert( db!=0 ); | |
| 21630 | - db->errCode = err_code; | |
| 21631 | - if( zFormat && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){ | |
| 21632 | - char *z; | |
| 21633 | - va_list ap; | |
| 21634 | - va_start(ap, zFormat); | |
| 21635 | - z = sqlite3VMPrintf(db, zFormat, ap); | |
| 21636 | - va_end(ap); | |
| 21637 | - sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC); | |
| 21638 | - }else if( db->pErr ){ | |
| 21639 | - sqlite3ValueSetNull(db->pErr); | |
| 21474 | + if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){ | |
| 21475 | + db->errCode = err_code; | |
| 21476 | + if( zFormat ){ | |
| 21477 | + char *z; | |
| 21478 | + va_list ap; | |
| 21479 | + va_start(ap, zFormat); | |
| 21480 | + z = sqlite3VMPrintf(db, zFormat, ap); | |
| 21481 | + va_end(ap); | |
| 21482 | + sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC); | |
| 21483 | + }else{ | |
| 21484 | + sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC); | |
| 21485 | + } | |
| 21640 | 21486 | } |
| 21641 | 21487 | } |
| 21642 | 21488 | |
| 21643 | 21489 | /* |
| 21644 | 21490 | ** Add an error message to pParse->zErrMsg and increment pParse->nErr. |
| @@ -23119,11 +22965,11 @@ | ||
| 23119 | 22965 | /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 23120 | 22966 | /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 23121 | 22967 | /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 23122 | 22968 | /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 23123 | 22969 | /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 23124 | - /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), | |
| 22970 | + /* 30 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"), | |
| 23125 | 22971 | /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 23126 | 22972 | /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 23127 | 22973 | /* 33 */ "CollSeq" OpHelp(""), |
| 23128 | 22974 | /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 23129 | 22975 | /* 35 */ "MustBeInt" OpHelp(""), |
| @@ -23510,16 +23356,10 @@ | ||
| 23510 | 23356 | */ |
| 23511 | 23357 | char aPadding[32]; |
| 23512 | 23358 | #endif |
| 23513 | 23359 | }; |
| 23514 | 23360 | |
| 23515 | -/* This variable holds the process id (pid) from when the xRandomness() | |
| 23516 | -** method was called. If xOpen() is called from a different process id, | |
| 23517 | -** indicating that a fork() has occurred, the PRNG will be reset. | |
| 23518 | -*/ | |
| 23519 | -static int randomnessPid = 0; | |
| 23520 | - | |
| 23521 | 23361 | /* |
| 23522 | 23362 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23523 | 23363 | */ |
| 23524 | 23364 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| 23525 | 23365 | #define UNIXFILE_RDONLY 0x02 /* Connection is read only */ |
| @@ -24779,19 +24619,10 @@ | ||
| 24779 | 24619 | } |
| 24780 | 24620 | *ppInode = pInode; |
| 24781 | 24621 | return SQLITE_OK; |
| 24782 | 24622 | } |
| 24783 | 24623 | |
| 24784 | -/* | |
| 24785 | -** Return TRUE if pFile has been renamed or unlinked since it was first opened. | |
| 24786 | -*/ | |
| 24787 | -static int fileHasMoved(unixFile *pFile){ | |
| 24788 | - struct stat buf; | |
| 24789 | - return pFile->pInode!=0 && | |
| 24790 | - (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); | |
| 24791 | -} | |
| 24792 | - | |
| 24793 | 24624 | |
| 24794 | 24625 | /* |
| 24795 | 24626 | ** Check a unixFile that is a database. Verify the following: |
| 24796 | 24627 | ** |
| 24797 | 24628 | ** (1) There is exactly one hard link on the file |
| @@ -24822,11 +24653,14 @@ | ||
| 24822 | 24653 | if( buf.st_nlink>1 ){ |
| 24823 | 24654 | sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); |
| 24824 | 24655 | pFile->ctrlFlags |= UNIXFILE_WARNED; |
| 24825 | 24656 | return; |
| 24826 | 24657 | } |
| 24827 | - if( fileHasMoved(pFile) ){ | |
| 24658 | + if( pFile->pInode!=0 | |
| 24659 | + && ((rc = osStat(pFile->zPath, &buf))!=0 | |
| 24660 | + || buf.st_ino!=pFile->pInode->fileId.ino) | |
| 24661 | + ){ | |
| 24828 | 24662 | sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); |
| 24829 | 24663 | pFile->ctrlFlags |= UNIXFILE_WARNED; |
| 24830 | 24664 | return; |
| 24831 | 24665 | } |
| 24832 | 24666 | } |
| @@ -27271,14 +27105,10 @@ | ||
| 27271 | 27105 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 27272 | 27106 | *(char**)pArg = zTFile; |
| 27273 | 27107 | } |
| 27274 | 27108 | return SQLITE_OK; |
| 27275 | 27109 | } |
| 27276 | - case SQLITE_FCNTL_HAS_MOVED: { | |
| 27277 | - *(int*)pArg = fileHasMoved(pFile); | |
| 27278 | - return SQLITE_OK; | |
| 27279 | - } | |
| 27280 | 27110 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 27281 | 27111 | case SQLITE_FCNTL_MMAP_SIZE: { |
| 27282 | 27112 | i64 newLimit = *(i64*)pArg; |
| 27283 | 27113 | int rc = SQLITE_OK; |
| 27284 | 27114 | if( newLimit>sqlite3GlobalConfig.mxMmap ){ |
| @@ -29115,20 +28945,10 @@ | ||
| 29115 | 28945 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 29116 | 28946 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 29117 | 28947 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 29118 | 28948 | ); |
| 29119 | 28949 | |
| 29120 | - /* Detect a pid change and reset the PRNG. There is a race condition | |
| 29121 | - ** here such that two or more threads all trying to open databases at | |
| 29122 | - ** the same instant might all reset the PRNG. But multiple resets | |
| 29123 | - ** are harmless. | |
| 29124 | - */ | |
| 29125 | - if( randomnessPid!=getpid() ){ | |
| 29126 | - randomnessPid = getpid(); | |
| 29127 | - sqlite3_randomness(0,0); | |
| 29128 | - } | |
| 29129 | - | |
| 29130 | 28950 | memset(p, 0, sizeof(unixFile)); |
| 29131 | 28951 | |
| 29132 | 28952 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 29133 | 28953 | UnixUnusedFd *pUnused; |
| 29134 | 28954 | pUnused = findReusableFd(zName, flags); |
| @@ -29512,22 +29332,22 @@ | ||
| 29512 | 29332 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29513 | 29333 | ** that we always use the same random number sequence. This makes the |
| 29514 | 29334 | ** tests repeatable. |
| 29515 | 29335 | */ |
| 29516 | 29336 | memset(zBuf, 0, nBuf); |
| 29517 | - randomnessPid = getpid(); | |
| 29518 | 29337 | #if !defined(SQLITE_TEST) |
| 29519 | 29338 | { |
| 29520 | - int fd, got; | |
| 29339 | + int pid, fd, got; | |
| 29521 | 29340 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29522 | 29341 | if( fd<0 ){ |
| 29523 | 29342 | time_t t; |
| 29524 | 29343 | time(&t); |
| 29525 | 29344 | memcpy(zBuf, &t, sizeof(t)); |
| 29526 | - memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid)); | |
| 29527 | - assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf ); | |
| 29528 | - nBuf = sizeof(t) + sizeof(randomnessPid); | |
| 29345 | + pid = getpid(); | |
| 29346 | + memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); | |
| 29347 | + assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); | |
| 29348 | + nBuf = sizeof(t) + sizeof(pid); | |
| 29529 | 29349 | }else{ |
| 29530 | 29350 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29531 | 29351 | robust_close(0, fd, __LINE__); |
| 29532 | 29352 | } |
| 29533 | 29353 | } |
| @@ -34261,11 +34081,11 @@ | ||
| 34261 | 34081 | winModeBit(pFile, WINFILE_PSOW, (int*)pArg); |
| 34262 | 34082 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 34263 | 34083 | return SQLITE_OK; |
| 34264 | 34084 | } |
| 34265 | 34085 | case SQLITE_FCNTL_VFSNAME: { |
| 34266 | - *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); | |
| 34086 | + *(char**)pArg = sqlite3_mprintf("win32"); | |
| 34267 | 34087 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 34268 | 34088 | return SQLITE_OK; |
| 34269 | 34089 | } |
| 34270 | 34090 | case SQLITE_FCNTL_WIN32_AV_RETRY: { |
| 34271 | 34091 | int *a = (int*)pArg; |
| @@ -37703,11 +37523,10 @@ | ||
| 37703 | 37523 | ** in memory. |
| 37704 | 37524 | */ |
| 37705 | 37525 | struct PgHdr1 { |
| 37706 | 37526 | sqlite3_pcache_page page; |
| 37707 | 37527 | unsigned int iKey; /* Key value (page number) */ |
| 37708 | - u8 isPinned; /* Page in use, not on the LRU list */ | |
| 37709 | 37528 | PgHdr1 *pNext; /* Next in hash table chain */ |
| 37710 | 37529 | PCache1 *pCache; /* Cache that currently owns this page */ |
| 37711 | 37530 | PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */ |
| 37712 | 37531 | PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */ |
| 37713 | 37532 | }; |
| @@ -38032,36 +37851,38 @@ | ||
| 38032 | 37851 | ** This function is used internally to remove the page pPage from the |
| 38033 | 37852 | ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup |
| 38034 | 37853 | ** LRU list, then this function is a no-op. |
| 38035 | 37854 | ** |
| 38036 | 37855 | ** The PGroup mutex must be held when this function is called. |
| 37856 | +** | |
| 37857 | +** If pPage is NULL then this routine is a no-op. | |
| 38037 | 37858 | */ |
| 38038 | 37859 | static void pcache1PinPage(PgHdr1 *pPage){ |
| 38039 | 37860 | PCache1 *pCache; |
| 38040 | 37861 | PGroup *pGroup; |
| 38041 | 37862 | |
| 38042 | - assert( pPage!=0 ); | |
| 38043 | - assert( pPage->isPinned==0 ); | |
| 37863 | + if( pPage==0 ) return; | |
| 38044 | 37864 | pCache = pPage->pCache; |
| 38045 | 37865 | pGroup = pCache->pGroup; |
| 38046 | - assert( pPage->pLruNext || pPage==pGroup->pLruTail ); | |
| 38047 | - assert( pPage->pLruPrev || pPage==pGroup->pLruHead ); | |
| 38048 | 37866 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 38049 | - if( pPage->pLruPrev ){ | |
| 38050 | - pPage->pLruPrev->pLruNext = pPage->pLruNext; | |
| 38051 | - }else{ | |
| 38052 | - pGroup->pLruHead = pPage->pLruNext; | |
| 38053 | - } | |
| 38054 | - if( pPage->pLruNext ){ | |
| 38055 | - pPage->pLruNext->pLruPrev = pPage->pLruPrev; | |
| 38056 | - }else{ | |
| 38057 | - pGroup->pLruTail = pPage->pLruPrev; | |
| 38058 | - } | |
| 38059 | - pPage->pLruNext = 0; | |
| 38060 | - pPage->pLruPrev = 0; | |
| 38061 | - pPage->isPinned = 1; | |
| 38062 | - pCache->nRecyclable--; | |
| 37867 | + if( pPage->pLruNext || pPage==pGroup->pLruTail ){ | |
| 37868 | + if( pPage->pLruPrev ){ | |
| 37869 | + pPage->pLruPrev->pLruNext = pPage->pLruNext; | |
| 37870 | + } | |
| 37871 | + if( pPage->pLruNext ){ | |
| 37872 | + pPage->pLruNext->pLruPrev = pPage->pLruPrev; | |
| 37873 | + } | |
| 37874 | + if( pGroup->pLruHead==pPage ){ | |
| 37875 | + pGroup->pLruHead = pPage->pLruNext; | |
| 37876 | + } | |
| 37877 | + if( pGroup->pLruTail==pPage ){ | |
| 37878 | + pGroup->pLruTail = pPage->pLruPrev; | |
| 37879 | + } | |
| 37880 | + pPage->pLruNext = 0; | |
| 37881 | + pPage->pLruPrev = 0; | |
| 37882 | + pPage->pCache->nRecyclable--; | |
| 37883 | + } | |
| 38063 | 37884 | } |
| 38064 | 37885 | |
| 38065 | 37886 | |
| 38066 | 37887 | /* |
| 38067 | 37888 | ** Remove the page supplied as an argument from the hash table |
| @@ -38089,11 +37910,10 @@ | ||
| 38089 | 37910 | static void pcache1EnforceMaxPage(PGroup *pGroup){ |
| 38090 | 37911 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 38091 | 37912 | while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){ |
| 38092 | 37913 | PgHdr1 *p = pGroup->pLruTail; |
| 38093 | 37914 | assert( p->pCache->pGroup==pGroup ); |
| 38094 | - assert( p->isPinned==0 ); | |
| 38095 | 37915 | pcache1PinPage(p); |
| 38096 | 37916 | pcache1RemoveFromHash(p); |
| 38097 | 37917 | pcache1FreePage(p); |
| 38098 | 37918 | } |
| 38099 | 37919 | } |
| @@ -38117,11 +37937,11 @@ | ||
| 38117 | 37937 | PgHdr1 *pPage; |
| 38118 | 37938 | while( (pPage = *pp)!=0 ){ |
| 38119 | 37939 | if( pPage->iKey>=iLimit ){ |
| 38120 | 37940 | pCache->nPage--; |
| 38121 | 37941 | *pp = pPage->pNext; |
| 38122 | - if( !pPage->isPinned ) pcache1PinPage(pPage); | |
| 37942 | + pcache1PinPage(pPage); | |
| 38123 | 37943 | pcache1FreePage(pPage); |
| 38124 | 37944 | }else{ |
| 38125 | 37945 | pp = &pPage->pNext; |
| 38126 | 37946 | TESTONLY( nPage++; ) |
| 38127 | 37947 | } |
| @@ -38340,15 +38160,12 @@ | ||
| 38340 | 38160 | unsigned int h = iKey % pCache->nHash; |
| 38341 | 38161 | for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext); |
| 38342 | 38162 | } |
| 38343 | 38163 | |
| 38344 | 38164 | /* Step 2: Abort if no existing page is found and createFlag is 0 */ |
| 38345 | - if( pPage ){ | |
| 38346 | - if( !pPage->isPinned ) pcache1PinPage(pPage); | |
| 38347 | - goto fetch_out; | |
| 38348 | - } | |
| 38349 | - if( createFlag==0 ){ | |
| 38165 | + if( pPage || createFlag==0 ){ | |
| 38166 | + pcache1PinPage(pPage); | |
| 38350 | 38167 | goto fetch_out; |
| 38351 | 38168 | } |
| 38352 | 38169 | |
| 38353 | 38170 | /* The pGroup local variable will normally be initialized by the |
| 38354 | 38171 | ** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined, |
| @@ -38385,11 +38202,10 @@ | ||
| 38385 | 38202 | || pGroup->nCurrentPage>=pGroup->nMaxPage |
| 38386 | 38203 | || pcache1UnderMemoryPressure(pCache) |
| 38387 | 38204 | )){ |
| 38388 | 38205 | PCache1 *pOther; |
| 38389 | 38206 | pPage = pGroup->pLruTail; |
| 38390 | - assert( pPage->isPinned==0 ); | |
| 38391 | 38207 | pcache1RemoveFromHash(pPage); |
| 38392 | 38208 | pcache1PinPage(pPage); |
| 38393 | 38209 | pOther = pPage->pCache; |
| 38394 | 38210 | |
| 38395 | 38211 | /* We want to verify that szPage and szExtra are the same for pOther |
| @@ -38422,11 +38238,10 @@ | ||
| 38422 | 38238 | pPage->iKey = iKey; |
| 38423 | 38239 | pPage->pNext = pCache->apHash[h]; |
| 38424 | 38240 | pPage->pCache = pCache; |
| 38425 | 38241 | pPage->pLruPrev = 0; |
| 38426 | 38242 | pPage->pLruNext = 0; |
| 38427 | - pPage->isPinned = 1; | |
| 38428 | 38243 | *(void **)pPage->page.pExtra = 0; |
| 38429 | 38244 | pCache->apHash[h] = pPage; |
| 38430 | 38245 | } |
| 38431 | 38246 | |
| 38432 | 38247 | fetch_out: |
| @@ -38458,11 +38273,10 @@ | ||
| 38458 | 38273 | /* It is an error to call this function if the page is already |
| 38459 | 38274 | ** part of the PGroup LRU list. |
| 38460 | 38275 | */ |
| 38461 | 38276 | assert( pPage->pLruPrev==0 && pPage->pLruNext==0 ); |
| 38462 | 38277 | assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage ); |
| 38463 | - assert( pPage->isPinned==1 ); | |
| 38464 | 38278 | |
| 38465 | 38279 | if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){ |
| 38466 | 38280 | pcache1RemoveFromHash(pPage); |
| 38467 | 38281 | pcache1FreePage(pPage); |
| 38468 | 38282 | }else{ |
| @@ -38474,11 +38288,10 @@ | ||
| 38474 | 38288 | }else{ |
| 38475 | 38289 | pGroup->pLruTail = pPage; |
| 38476 | 38290 | pGroup->pLruHead = pPage; |
| 38477 | 38291 | } |
| 38478 | 38292 | pCache->nRecyclable++; |
| 38479 | - pPage->isPinned = 0; | |
| 38480 | 38293 | } |
| 38481 | 38294 | |
| 38482 | 38295 | pcache1LeaveMutex(pCache->pGroup); |
| 38483 | 38296 | } |
| 38484 | 38297 | |
| @@ -38601,11 +38414,10 @@ | ||
| 38601 | 38414 | while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){ |
| 38602 | 38415 | nFree += pcache1MemSize(p->page.pBuf); |
| 38603 | 38416 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 38604 | 38417 | nFree += sqlite3MemSize(p); |
| 38605 | 38418 | #endif |
| 38606 | - assert( p->isPinned==0 ); | |
| 38607 | 38419 | pcache1PinPage(p); |
| 38608 | 38420 | pcache1RemoveFromHash(p); |
| 38609 | 38421 | pcache1FreePage(p); |
| 38610 | 38422 | } |
| 38611 | 38423 | pcache1LeaveMutex(&pcache1.grp); |
| @@ -38626,11 +38438,10 @@ | ||
| 38626 | 38438 | int *pnRecyclable /* OUT: Total number of pages available for recycling */ |
| 38627 | 38439 | ){ |
| 38628 | 38440 | PgHdr1 *p; |
| 38629 | 38441 | int nRecyclable = 0; |
| 38630 | 38442 | for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){ |
| 38631 | - assert( p->isPinned==0 ); | |
| 38632 | 38443 | nRecyclable++; |
| 38633 | 38444 | } |
| 38634 | 38445 | *pnCurrent = pcache1.grp.nCurrentPage; |
| 38635 | 38446 | *pnMax = (int)pcache1.grp.nMaxPage; |
| 38636 | 38447 | *pnMin = (int)pcache1.grp.nMinPage; |
| @@ -40313,26 +40124,29 @@ | ||
| 40313 | 40124 | ** PagerSavepoint.pInSavepoint. |
| 40314 | 40125 | */ |
| 40315 | 40126 | static int subjRequiresPage(PgHdr *pPg){ |
| 40316 | 40127 | Pager *pPager = pPg->pPager; |
| 40317 | 40128 | PagerSavepoint *p; |
| 40318 | - Pgno pgno = pPg->pgno; | |
| 40129 | + Pgno pgno; | |
| 40319 | 40130 | int i; |
| 40320 | - for(i=0; i<pPager->nSavepoint; i++){ | |
| 40321 | - p = &pPager->aSavepoint[i]; | |
| 40322 | - if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){ | |
| 40323 | - return 1; | |
| 40131 | + if( pPager->nSavepoint ){ | |
| 40132 | + pgno = pPg->pgno; | |
| 40133 | + for(i=0; i<pPager->nSavepoint; i++){ | |
| 40134 | + p = &pPager->aSavepoint[i]; | |
| 40135 | + if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){ | |
| 40136 | + return 1; | |
| 40137 | + } | |
| 40324 | 40138 | } |
| 40325 | 40139 | } |
| 40326 | 40140 | return 0; |
| 40327 | 40141 | } |
| 40328 | 40142 | |
| 40329 | 40143 | /* |
| 40330 | 40144 | ** Return true if the page is already in the journal file. |
| 40331 | 40145 | */ |
| 40332 | -static int pageInJournal(Pager *pPager, PgHdr *pPg){ | |
| 40333 | - return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno); | |
| 40146 | +static int pageInJournal(PgHdr *pPg){ | |
| 40147 | + return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno); | |
| 40334 | 40148 | } |
| 40335 | 40149 | |
| 40336 | 40150 | /* |
| 40337 | 40151 | ** Read a 32-bit integer from the given file descriptor. Store the integer |
| 40338 | 40152 | ** that is read in *pRes. Return SQLITE_OK if everything worked, or an |
| @@ -40535,11 +40349,10 @@ | ||
| 40535 | 40349 | |
| 40536 | 40350 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 40537 | 40351 | || szJ<16 |
| 40538 | 40352 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 40539 | 40353 | || len>=nMaster |
| 40540 | - || len==0 | |
| 40541 | 40354 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 40542 | 40355 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 40543 | 40356 | || memcmp(aMagic, aJournalMagic, 8) |
| 40544 | 40357 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len)) |
| 40545 | 40358 | ){ |
| @@ -41276,11 +41089,11 @@ | ||
| 41276 | 41089 | sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash); |
| 41277 | 41090 | if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){ |
| 41278 | 41091 | PgHdr *p = pager_lookup(pPager, 1); |
| 41279 | 41092 | if( p ){ |
| 41280 | 41093 | p->pageHash = 0; |
| 41281 | - sqlite3PagerUnrefNotNull(p); | |
| 41094 | + sqlite3PagerUnref(p); | |
| 41282 | 41095 | } |
| 41283 | 41096 | } |
| 41284 | 41097 | #endif |
| 41285 | 41098 | |
| 41286 | 41099 | sqlite3BitvecDestroy(pPager->pInJournal); |
| @@ -41305,15 +41118,10 @@ | ||
| 41305 | 41118 | ** required size. */ |
| 41306 | 41119 | assert( pPager->eLock==EXCLUSIVE_LOCK ); |
| 41307 | 41120 | rc = pager_truncate(pPager, pPager->dbSize); |
| 41308 | 41121 | } |
| 41309 | 41122 | |
| 41310 | - if( rc==SQLITE_OK && bCommit && isOpen(pPager->fd) ){ | |
| 41311 | - rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0); | |
| 41312 | - if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; | |
| 41313 | - } | |
| 41314 | - | |
| 41315 | 41123 | if( !pPager->exclusiveMode |
| 41316 | 41124 | && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0)) |
| 41317 | 41125 | ){ |
| 41318 | 41126 | rc2 = pagerUnlockDb(pPager, SHARED_LOCK); |
| 41319 | 41127 | pPager->changeCountDone = 0; |
| @@ -42123,11 +41931,11 @@ | ||
| 42123 | 41931 | testcase( rc!=SQLITE_OK ); |
| 42124 | 41932 | } |
| 42125 | 41933 | if( rc==SQLITE_OK |
| 42126 | 41934 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 42127 | 41935 | ){ |
| 42128 | - rc = sqlite3PagerSync(pPager, 0); | |
| 41936 | + rc = sqlite3PagerSync(pPager); | |
| 42129 | 41937 | } |
| 42130 | 41938 | if( rc==SQLITE_OK ){ |
| 42131 | 41939 | rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0); |
| 42132 | 41940 | testcase( rc!=SQLITE_OK ); |
| 42133 | 41941 | } |
| @@ -42269,11 +42077,11 @@ | ||
| 42269 | 42077 | rc = readDbPage(pPg, iFrame); |
| 42270 | 42078 | } |
| 42271 | 42079 | if( rc==SQLITE_OK ){ |
| 42272 | 42080 | pPager->xReiniter(pPg); |
| 42273 | 42081 | } |
| 42274 | - sqlite3PagerUnrefNotNull(pPg); | |
| 42082 | + sqlite3PagerUnref(pPg); | |
| 42275 | 42083 | } |
| 42276 | 42084 | } |
| 42277 | 42085 | |
| 42278 | 42086 | /* Normally, if a transaction is rolled back, any backup processes are |
| 42279 | 42087 | ** updated as data is copied out of the rollback journal and into the |
| @@ -43624,11 +43432,11 @@ | ||
| 43624 | 43432 | /* Open the sub-journal, if it has not already been opened */ |
| 43625 | 43433 | assert( pPager->useJournal ); |
| 43626 | 43434 | assert( isOpen(pPager->jfd) || pagerUseWal(pPager) ); |
| 43627 | 43435 | assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 ); |
| 43628 | 43436 | assert( pagerUseWal(pPager) |
| 43629 | - || pageInJournal(pPager, pPg) | |
| 43437 | + || pageInJournal(pPg) | |
| 43630 | 43438 | || pPg->pgno>pPager->dbOrigSize |
| 43631 | 43439 | ); |
| 43632 | 43440 | rc = openSubJournal(pPager); |
| 43633 | 43441 | |
| 43634 | 43442 | /* If the sub-journal was opened successfully (or was already open), |
| @@ -44089,34 +43897,10 @@ | ||
| 44089 | 43897 | *ppPager = pPager; |
| 44090 | 43898 | return SQLITE_OK; |
| 44091 | 43899 | } |
| 44092 | 43900 | |
| 44093 | 43901 | |
| 44094 | -/* Verify that the database file has not be deleted or renamed out from | |
| 44095 | -** under the pager. Return SQLITE_OK if the database is still were it ought | |
| 44096 | -** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error | |
| 44097 | -** code from sqlite3OsAccess()) if the database has gone missing. | |
| 44098 | -*/ | |
| 44099 | -static int databaseIsUnmoved(Pager *pPager){ | |
| 44100 | - int bHasMoved = 0; | |
| 44101 | - int rc; | |
| 44102 | - | |
| 44103 | - if( pPager->tempFile ) return SQLITE_OK; | |
| 44104 | - if( pPager->dbSize==0 ) return SQLITE_OK; | |
| 44105 | - assert( pPager->zFilename && pPager->zFilename[0] ); | |
| 44106 | - rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved); | |
| 44107 | - if( rc==SQLITE_NOTFOUND ){ | |
| 44108 | - /* If the HAS_MOVED file-control is unimplemented, assume that the file | |
| 44109 | - ** has not been moved. That is the historical behavior of SQLite: prior to | |
| 44110 | - ** version 3.8.3, it never checked */ | |
| 44111 | - rc = SQLITE_OK; | |
| 44112 | - }else if( rc==SQLITE_OK && bHasMoved ){ | |
| 44113 | - rc = SQLITE_READONLY_DBMOVED; | |
| 44114 | - } | |
| 44115 | - return rc; | |
| 44116 | -} | |
| 44117 | - | |
| 44118 | 43902 | |
| 44119 | 43903 | /* |
| 44120 | 43904 | ** This function is called after transitioning from PAGER_UNLOCK to |
| 44121 | 43905 | ** PAGER_SHARED state. It tests if there is a hot journal present in |
| 44122 | 43906 | ** the file-system for the given pager. A hot journal is one that |
| @@ -44584,11 +44368,11 @@ | ||
| 44584 | 44368 | if( bMmapOk && pagerUseWal(pPager) ){ |
| 44585 | 44369 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame); |
| 44586 | 44370 | if( rc!=SQLITE_OK ) goto pager_acquire_err; |
| 44587 | 44371 | } |
| 44588 | 44372 | |
| 44589 | - if( bMmapOk && iFrame==0 ){ | |
| 44373 | + if( iFrame==0 && bMmapOk ){ | |
| 44590 | 44374 | void *pData = 0; |
| 44591 | 44375 | |
| 44592 | 44376 | rc = sqlite3OsFetch(pPager->fd, |
| 44593 | 44377 | (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData |
| 44594 | 44378 | ); |
| @@ -44725,23 +44509,20 @@ | ||
| 44725 | 44509 | ** If the number of references to the page drop to zero, then the |
| 44726 | 44510 | ** page is added to the LRU list. When all references to all pages |
| 44727 | 44511 | ** are released, a rollback occurs and the lock on the database is |
| 44728 | 44512 | ** removed. |
| 44729 | 44513 | */ |
| 44730 | -SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){ | |
| 44731 | - Pager *pPager; | |
| 44732 | - assert( pPg!=0 ); | |
| 44733 | - pPager = pPg->pPager; | |
| 44734 | - if( pPg->flags & PGHDR_MMAP ){ | |
| 44735 | - pagerReleaseMapPage(pPg); | |
| 44736 | - }else{ | |
| 44737 | - sqlite3PcacheRelease(pPg); | |
| 44738 | - } | |
| 44739 | - pagerUnlockIfUnused(pPager); | |
| 44740 | -} | |
| 44741 | 44514 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){ |
| 44742 | - if( pPg ) sqlite3PagerUnrefNotNull(pPg); | |
| 44515 | + if( pPg ){ | |
| 44516 | + Pager *pPager = pPg->pPager; | |
| 44517 | + if( pPg->flags & PGHDR_MMAP ){ | |
| 44518 | + pagerReleaseMapPage(pPg); | |
| 44519 | + }else{ | |
| 44520 | + sqlite3PcacheRelease(pPg); | |
| 44521 | + } | |
| 44522 | + pagerUnlockIfUnused(pPager); | |
| 44523 | + } | |
| 44743 | 44524 | } |
| 44744 | 44525 | |
| 44745 | 44526 | /* |
| 44746 | 44527 | ** This function is called at the start of every write transaction. |
| 44747 | 44528 | ** There must already be a RESERVED or EXCLUSIVE lock on the database |
| @@ -44792,23 +44573,17 @@ | ||
| 44792 | 44573 | SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| |
| 44793 | 44574 | (pPager->tempFile ? |
| 44794 | 44575 | (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL): |
| 44795 | 44576 | (SQLITE_OPEN_MAIN_JOURNAL) |
| 44796 | 44577 | ); |
| 44797 | - | |
| 44798 | - /* Verify that the database still has the same name as it did when | |
| 44799 | - ** it was originally opened. */ | |
| 44800 | - rc = databaseIsUnmoved(pPager); | |
| 44801 | - if( rc==SQLITE_OK ){ | |
| 44802 | -#ifdef SQLITE_ENABLE_ATOMIC_WRITE | |
| 44803 | - rc = sqlite3JournalOpen( | |
| 44804 | - pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager) | |
| 44805 | - ); | |
| 44806 | -#else | |
| 44807 | - rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0); | |
| 44808 | -#endif | |
| 44809 | - } | |
| 44578 | + #ifdef SQLITE_ENABLE_ATOMIC_WRITE | |
| 44579 | + rc = sqlite3JournalOpen( | |
| 44580 | + pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager) | |
| 44581 | + ); | |
| 44582 | + #else | |
| 44583 | + rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0); | |
| 44584 | + #endif | |
| 44810 | 44585 | } |
| 44811 | 44586 | assert( rc!=SQLITE_OK || isOpen(pPager->jfd) ); |
| 44812 | 44587 | } |
| 44813 | 44588 | |
| 44814 | 44589 | |
| @@ -44925,13 +44700,13 @@ | ||
| 44925 | 44700 | ** one of the journals, the corresponding bit is set in the |
| 44926 | 44701 | ** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs |
| 44927 | 44702 | ** of any open savepoints as appropriate. |
| 44928 | 44703 | */ |
| 44929 | 44704 | static int pager_write(PgHdr *pPg){ |
| 44705 | + void *pData = pPg->pData; | |
| 44930 | 44706 | Pager *pPager = pPg->pPager; |
| 44931 | 44707 | int rc = SQLITE_OK; |
| 44932 | - int inJournal; | |
| 44933 | 44708 | |
| 44934 | 44709 | /* This routine is not called unless a write-transaction has already |
| 44935 | 44710 | ** been started. The journal file may or may not be open at this point. |
| 44936 | 44711 | ** It is never called in the ERROR state. |
| 44937 | 44712 | */ |
| @@ -44938,12 +44713,18 @@ | ||
| 44938 | 44713 | assert( pPager->eState==PAGER_WRITER_LOCKED |
| 44939 | 44714 | || pPager->eState==PAGER_WRITER_CACHEMOD |
| 44940 | 44715 | || pPager->eState==PAGER_WRITER_DBMOD |
| 44941 | 44716 | ); |
| 44942 | 44717 | assert( assert_pager_state(pPager) ); |
| 44943 | - assert( pPager->errCode==0 ); | |
| 44944 | - assert( pPager->readOnly==0 ); | |
| 44718 | + | |
| 44719 | + /* If an error has been previously detected, report the same error | |
| 44720 | + ** again. This should not happen, but the check provides robustness. */ | |
| 44721 | + if( NEVER(pPager->errCode) ) return pPager->errCode; | |
| 44722 | + | |
| 44723 | + /* Higher-level routines never call this function if database is not | |
| 44724 | + ** writable. But check anyway, just for robustness. */ | |
| 44725 | + if( NEVER(pPager->readOnly) ) return SQLITE_PERM; | |
| 44945 | 44726 | |
| 44946 | 44727 | CHECK_PAGE(pPg); |
| 44947 | 44728 | |
| 44948 | 44729 | /* The journal file needs to be opened. Higher level routines have already |
| 44949 | 44730 | ** obtained the necessary locks to begin the write-transaction, but the |
| @@ -44963,20 +44744,19 @@ | ||
| 44963 | 44744 | |
| 44964 | 44745 | /* Mark the page as dirty. If the page has already been written |
| 44965 | 44746 | ** to the journal then we can return right away. |
| 44966 | 44747 | */ |
| 44967 | 44748 | sqlite3PcacheMakeDirty(pPg); |
| 44968 | - inJournal = pageInJournal(pPager, pPg); | |
| 44969 | - if( inJournal && (pPager->nSavepoint==0 || !subjRequiresPage(pPg)) ){ | |
| 44749 | + if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){ | |
| 44970 | 44750 | assert( !pagerUseWal(pPager) ); |
| 44971 | 44751 | }else{ |
| 44972 | 44752 | |
| 44973 | 44753 | /* The transaction journal now exists and we have a RESERVED or an |
| 44974 | 44754 | ** EXCLUSIVE lock on the main database file. Write the current page to |
| 44975 | 44755 | ** the transaction journal if it is not there already. |
| 44976 | 44756 | */ |
| 44977 | - if( !inJournal && !pagerUseWal(pPager) ){ | |
| 44757 | + if( !pageInJournal(pPg) && !pagerUseWal(pPager) ){ | |
| 44978 | 44758 | assert( pagerUseWal(pPager)==0 ); |
| 44979 | 44759 | if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){ |
| 44980 | 44760 | u32 cksum; |
| 44981 | 44761 | char *pData2; |
| 44982 | 44762 | i64 iOff = pPager->journalOff; |
| @@ -44985,11 +44765,11 @@ | ||
| 44985 | 44765 | ** contains the database locks. The following assert verifies |
| 44986 | 44766 | ** that we do not. */ |
| 44987 | 44767 | assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 44988 | 44768 | |
| 44989 | 44769 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 44990 | - CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2); | |
| 44770 | + CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2); | |
| 44991 | 44771 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 44992 | 44772 | |
| 44993 | 44773 | /* Even if an IO or diskfull error occurs while journalling the |
| 44994 | 44774 | ** page in the block above, set the need-sync flag for the page. |
| 44995 | 44775 | ** Otherwise, when the transaction is rolled back, the logic in |
| @@ -45037,11 +44817,11 @@ | ||
| 45037 | 44817 | /* If the statement journal is open and the page is not in it, |
| 45038 | 44818 | ** then write the current page to the statement journal. Note that |
| 45039 | 44819 | ** the statement journal format differs from the standard journal format |
| 45040 | 44820 | ** in that it omits the checksums and the header. |
| 45041 | 44821 | */ |
| 45042 | - if( pPager->nSavepoint>0 && subjRequiresPage(pPg) ){ | |
| 44822 | + if( subjRequiresPage(pPg) ){ | |
| 45043 | 44823 | rc = subjournalPage(pPg); |
| 45044 | 44824 | } |
| 45045 | 44825 | } |
| 45046 | 44826 | |
| 45047 | 44827 | /* Update the database size and return. |
| @@ -45069,23 +44849,23 @@ | ||
| 45069 | 44849 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){ |
| 45070 | 44850 | int rc = SQLITE_OK; |
| 45071 | 44851 | |
| 45072 | 44852 | PgHdr *pPg = pDbPage; |
| 45073 | 44853 | Pager *pPager = pPg->pPager; |
| 44854 | + Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); | |
| 45074 | 44855 | |
| 45075 | 44856 | assert( (pPg->flags & PGHDR_MMAP)==0 ); |
| 45076 | 44857 | assert( pPager->eState>=PAGER_WRITER_LOCKED ); |
| 45077 | 44858 | assert( pPager->eState!=PAGER_ERROR ); |
| 45078 | 44859 | assert( assert_pager_state(pPager) ); |
| 45079 | 44860 | |
| 45080 | - if( pPager->sectorSize > (u32)pPager->pageSize ){ | |
| 44861 | + if( nPagePerSector>1 ){ | |
| 45081 | 44862 | Pgno nPageCount; /* Total number of pages in database file */ |
| 45082 | 44863 | Pgno pg1; /* First page of the sector pPg is located on. */ |
| 45083 | 44864 | int nPage = 0; /* Number of pages starting at pg1 to journal */ |
| 45084 | 44865 | int ii; /* Loop counter */ |
| 45085 | 44866 | int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */ |
| 45086 | - Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); | |
| 45087 | 44867 | |
| 45088 | 44868 | /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow |
| 45089 | 44869 | ** a journal header to be written between the pages journaled by |
| 45090 | 44870 | ** this function. |
| 45091 | 44871 | */ |
| @@ -45120,18 +44900,18 @@ | ||
| 45120 | 44900 | if( rc==SQLITE_OK ){ |
| 45121 | 44901 | rc = pager_write(pPage); |
| 45122 | 44902 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 45123 | 44903 | needSync = 1; |
| 45124 | 44904 | } |
| 45125 | - sqlite3PagerUnrefNotNull(pPage); | |
| 44905 | + sqlite3PagerUnref(pPage); | |
| 45126 | 44906 | } |
| 45127 | 44907 | } |
| 45128 | 44908 | }else if( (pPage = pager_lookup(pPager, pg))!=0 ){ |
| 45129 | 44909 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 45130 | 44910 | needSync = 1; |
| 45131 | 44911 | } |
| 45132 | - sqlite3PagerUnrefNotNull(pPage); | |
| 44912 | + sqlite3PagerUnref(pPage); | |
| 45133 | 44913 | } |
| 45134 | 44914 | } |
| 45135 | 44915 | |
| 45136 | 44916 | /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages |
| 45137 | 44917 | ** starting at pg1, then it needs to be set for all of them. Because |
| @@ -45143,11 +44923,11 @@ | ||
| 45143 | 44923 | assert( !MEMDB ); |
| 45144 | 44924 | for(ii=0; ii<nPage; ii++){ |
| 45145 | 44925 | PgHdr *pPage = pager_lookup(pPager, pg1+ii); |
| 45146 | 44926 | if( pPage ){ |
| 45147 | 44927 | pPage->flags |= PGHDR_NEED_SYNC; |
| 45148 | - sqlite3PagerUnrefNotNull(pPage); | |
| 44928 | + sqlite3PagerUnref(pPage); | |
| 45149 | 44929 | } |
| 45150 | 44930 | } |
| 45151 | 44931 | } |
| 45152 | 44932 | |
| 45153 | 44933 | assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 ); |
| @@ -45296,21 +45076,21 @@ | ||
| 45296 | 45076 | ** or pages with the Pager.noSync flag set. |
| 45297 | 45077 | ** |
| 45298 | 45078 | ** If successful, or if called on a pager for which it is a no-op, this |
| 45299 | 45079 | ** function returns SQLITE_OK. Otherwise, an IO error code is returned. |
| 45300 | 45080 | */ |
| 45301 | -SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){ | |
| 45081 | +SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){ | |
| 45302 | 45082 | int rc = SQLITE_OK; |
| 45303 | - | |
| 45304 | - if( isOpen(pPager->fd) ){ | |
| 45305 | - void *pArg = (void*)zMaster; | |
| 45306 | - rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg); | |
| 45307 | - if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; | |
| 45308 | - } | |
| 45309 | - if( rc==SQLITE_OK && !pPager->noSync ){ | |
| 45083 | + if( !pPager->noSync ){ | |
| 45310 | 45084 | assert( !MEMDB ); |
| 45311 | 45085 | rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); |
| 45086 | + }else if( isOpen(pPager->fd) ){ | |
| 45087 | + assert( !MEMDB ); | |
| 45088 | + rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, 0); | |
| 45089 | + if( rc==SQLITE_NOTFOUND ){ | |
| 45090 | + rc = SQLITE_OK; | |
| 45091 | + } | |
| 45312 | 45092 | } |
| 45313 | 45093 | return rc; |
| 45314 | 45094 | } |
| 45315 | 45095 | |
| 45316 | 45096 | /* |
| @@ -45505,11 +45285,11 @@ | ||
| 45505 | 45285 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 45506 | 45286 | } |
| 45507 | 45287 | |
| 45508 | 45288 | /* Finally, sync the database file. */ |
| 45509 | 45289 | if( !noSync ){ |
| 45510 | - rc = sqlite3PagerSync(pPager, zMaster); | |
| 45290 | + rc = sqlite3PagerSync(pPager); | |
| 45511 | 45291 | } |
| 45512 | 45292 | IOTRACE(("DBSYNC %p\n", pPager)) |
| 45513 | 45293 | } |
| 45514 | 45294 | } |
| 45515 | 45295 | |
| @@ -45634,13 +45414,11 @@ | ||
| 45634 | 45414 | rc = pager_playback(pPager, 0); |
| 45635 | 45415 | } |
| 45636 | 45416 | |
| 45637 | 45417 | assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK ); |
| 45638 | 45418 | assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT |
| 45639 | - || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR | |
| 45640 | - || rc==SQLITE_CANTOPEN | |
| 45641 | - ); | |
| 45419 | + || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR ); | |
| 45642 | 45420 | |
| 45643 | 45421 | /* If an error occurs during a ROLLBACK, we can no longer trust the pager |
| 45644 | 45422 | ** cache. So call pager_error() on the way out to make any error persistent. |
| 45645 | 45423 | */ |
| 45646 | 45424 | return pager_error(pPager, rc); |
| @@ -46039,11 +45817,11 @@ | ||
| 46039 | 45817 | ** can be written to. The caller has already promised not to write to it. |
| 46040 | 45818 | */ |
| 46041 | 45819 | if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){ |
| 46042 | 45820 | needSyncPgno = pPg->pgno; |
| 46043 | 45821 | assert( pPager->journalMode==PAGER_JOURNALMODE_OFF || |
| 46044 | - pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize ); | |
| 45822 | + pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize ); | |
| 46045 | 45823 | assert( pPg->flags&PGHDR_DIRTY ); |
| 46046 | 45824 | } |
| 46047 | 45825 | |
| 46048 | 45826 | /* If the cache contains a page with page-number pgno, remove it |
| 46049 | 45827 | ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for |
| @@ -46073,11 +45851,11 @@ | ||
| 46073 | 45851 | ** as the original page since it has already been allocated. |
| 46074 | 45852 | */ |
| 46075 | 45853 | if( MEMDB ){ |
| 46076 | 45854 | assert( pPgOld ); |
| 46077 | 45855 | sqlite3PcacheMove(pPgOld, origPgno); |
| 46078 | - sqlite3PagerUnrefNotNull(pPgOld); | |
| 45856 | + sqlite3PagerUnref(pPgOld); | |
| 46079 | 45857 | } |
| 46080 | 45858 | |
| 46081 | 45859 | if( needSyncPgno ){ |
| 46082 | 45860 | /* If needSyncPgno is non-zero, then the journal file needs to be |
| 46083 | 45861 | ** sync()ed before any data is written to database file page needSyncPgno. |
| @@ -46102,11 +45880,11 @@ | ||
| 46102 | 45880 | } |
| 46103 | 45881 | return rc; |
| 46104 | 45882 | } |
| 46105 | 45883 | pPgHdr->flags |= PGHDR_NEED_SYNC; |
| 46106 | 45884 | sqlite3PcacheMakeDirty(pPgHdr); |
| 46107 | - sqlite3PagerUnrefNotNull(pPgHdr); | |
| 45885 | + sqlite3PagerUnref(pPgHdr); | |
| 46108 | 45886 | } |
| 46109 | 45887 | |
| 46110 | 45888 | return SQLITE_OK; |
| 46111 | 45889 | } |
| 46112 | 45890 | #endif |
| @@ -52221,11 +51999,11 @@ | ||
| 52221 | 51999 | |
| 52222 | 52000 | if( pgno>btreePagecount(pBt) ){ |
| 52223 | 52001 | rc = SQLITE_CORRUPT_BKPT; |
| 52224 | 52002 | }else{ |
| 52225 | 52003 | rc = btreeGetPage(pBt, pgno, ppPage, bReadonly); |
| 52226 | - if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){ | |
| 52004 | + if( rc==SQLITE_OK ){ | |
| 52227 | 52005 | rc = btreeInitPage(*ppPage); |
| 52228 | 52006 | if( rc!=SQLITE_OK ){ |
| 52229 | 52007 | releasePage(*ppPage); |
| 52230 | 52008 | } |
| 52231 | 52009 | } |
| @@ -52242,15 +52020,14 @@ | ||
| 52242 | 52020 | */ |
| 52243 | 52021 | static void releasePage(MemPage *pPage){ |
| 52244 | 52022 | if( pPage ){ |
| 52245 | 52023 | assert( pPage->aData ); |
| 52246 | 52024 | assert( pPage->pBt ); |
| 52247 | - assert( pPage->pDbPage!=0 ); | |
| 52248 | 52025 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 52249 | 52026 | assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData ); |
| 52250 | 52027 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 52251 | - sqlite3PagerUnrefNotNull(pPage->pDbPage); | |
| 52028 | + sqlite3PagerUnref(pPage->pDbPage); | |
| 52252 | 52029 | } |
| 52253 | 52030 | } |
| 52254 | 52031 | |
| 52255 | 52032 | /* |
| 52256 | 52033 | ** During a rollback, when the pager reloads information into the cache |
| @@ -54762,14 +54539,14 @@ | ||
| 54762 | 54539 | } |
| 54763 | 54540 | |
| 54764 | 54541 | /* |
| 54765 | 54542 | ** Return a pointer to payload information from the entry that the |
| 54766 | 54543 | ** pCur cursor is pointing to. The pointer is to the beginning of |
| 54767 | -** the key if index btrees (pPage->intKey==0) and is the data for | |
| 54768 | -** table btrees (pPage->intKey==1). The number of bytes of available | |
| 54769 | -** key/data is written into *pAmt. If *pAmt==0, then the value | |
| 54770 | -** returned will not be a valid pointer. | |
| 54544 | +** the key if skipKey==0 and it points to the beginning of data if | |
| 54545 | +** skipKey==1. The number of bytes of available key/data is written | |
| 54546 | +** into *pAmt. If *pAmt==0, then the value returned will not be | |
| 54547 | +** a valid pointer. | |
| 54771 | 54548 | ** |
| 54772 | 54549 | ** This routine is an optimization. It is common for the entire key |
| 54773 | 54550 | ** and data to fit on the local page and for there to be no overflow |
| 54774 | 54551 | ** pages. When that is so, this routine can be used to access the |
| 54775 | 54552 | ** key and data without making a copy. If the key and/or data spills |
| @@ -54778,25 +54555,45 @@ | ||
| 54778 | 54555 | ** |
| 54779 | 54556 | ** The pointer returned by this routine looks directly into the cached |
| 54780 | 54557 | ** page of the database. The data might change or move the next time |
| 54781 | 54558 | ** any btree routine is called. |
| 54782 | 54559 | */ |
| 54783 | -static const void *fetchPayload( | |
| 54560 | +static const unsigned char *fetchPayload( | |
| 54784 | 54561 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 54785 | - u32 *pAmt /* Write the number of available bytes here */ | |
| 54562 | + u32 *pAmt, /* Write the number of available bytes here */ | |
| 54563 | + int skipKey /* read beginning at data if this is true */ | |
| 54786 | 54564 | ){ |
| 54565 | + unsigned char *aPayload; | |
| 54566 | + MemPage *pPage; | |
| 54567 | + u32 nKey; | |
| 54568 | + u32 nLocal; | |
| 54569 | + | |
| 54787 | 54570 | assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 54788 | 54571 | assert( pCur->eState==CURSOR_VALID ); |
| 54789 | - assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); | |
| 54790 | 54572 | assert( cursorHoldsMutex(pCur) ); |
| 54791 | - assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); | |
| 54573 | + pPage = pCur->apPage[pCur->iPage]; | |
| 54574 | + assert( pCur->aiIdx[pCur->iPage]<pPage->nCell ); | |
| 54792 | 54575 | if( pCur->info.nSize==0 ){ |
| 54793 | 54576 | btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage], |
| 54794 | 54577 | &pCur->info); |
| 54795 | 54578 | } |
| 54796 | - *pAmt = pCur->info.nLocal; | |
| 54797 | - return (void*)(pCur->info.pCell + pCur->info.nHeader); | |
| 54579 | + aPayload = pCur->info.pCell; | |
| 54580 | + aPayload += pCur->info.nHeader; | |
| 54581 | + if( pPage->intKey ){ | |
| 54582 | + nKey = 0; | |
| 54583 | + }else{ | |
| 54584 | + nKey = (int)pCur->info.nKey; | |
| 54585 | + } | |
| 54586 | + if( skipKey ){ | |
| 54587 | + aPayload += nKey; | |
| 54588 | + nLocal = pCur->info.nLocal - nKey; | |
| 54589 | + }else{ | |
| 54590 | + nLocal = pCur->info.nLocal; | |
| 54591 | + assert( nLocal<=nKey ); | |
| 54592 | + } | |
| 54593 | + *pAmt = nLocal; | |
| 54594 | + return aPayload; | |
| 54798 | 54595 | } |
| 54799 | 54596 | |
| 54800 | 54597 | |
| 54801 | 54598 | /* |
| 54802 | 54599 | ** For the entry that cursor pCur is point to, return as |
| @@ -54811,14 +54608,26 @@ | ||
| 54811 | 54608 | ** |
| 54812 | 54609 | ** These routines is used to get quick access to key and data |
| 54813 | 54610 | ** in the common case where no overflow pages are used. |
| 54814 | 54611 | */ |
| 54815 | 54612 | SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){ |
| 54816 | - return fetchPayload(pCur, pAmt); | |
| 54613 | + const void *p = 0; | |
| 54614 | + assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); | |
| 54615 | + assert( cursorHoldsMutex(pCur) ); | |
| 54616 | + if( ALWAYS(pCur->eState==CURSOR_VALID) ){ | |
| 54617 | + p = (const void*)fetchPayload(pCur, pAmt, 0); | |
| 54618 | + } | |
| 54619 | + return p; | |
| 54817 | 54620 | } |
| 54818 | 54621 | SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){ |
| 54819 | - return fetchPayload(pCur, pAmt); | |
| 54622 | + const void *p = 0; | |
| 54623 | + assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); | |
| 54624 | + assert( cursorHoldsMutex(pCur) ); | |
| 54625 | + if( ALWAYS(pCur->eState==CURSOR_VALID) ){ | |
| 54626 | + p = (const void*)fetchPayload(pCur, pAmt, 1); | |
| 54627 | + } | |
| 54628 | + return p; | |
| 54820 | 54629 | } |
| 54821 | 54630 | |
| 54822 | 54631 | |
| 54823 | 54632 | /* |
| 54824 | 54633 | ** Move the cursor down to a new child page. The newPgno argument is the |
| @@ -54933,10 +54742,12 @@ | ||
| 54933 | 54742 | ** b-tree). |
| 54934 | 54743 | */ |
| 54935 | 54744 | static int moveToRoot(BtCursor *pCur){ |
| 54936 | 54745 | MemPage *pRoot; |
| 54937 | 54746 | int rc = SQLITE_OK; |
| 54747 | + Btree *p = pCur->pBtree; | |
| 54748 | + BtShared *pBt = p->pBt; | |
| 54938 | 54749 | |
| 54939 | 54750 | assert( cursorHoldsMutex(pCur) ); |
| 54940 | 54751 | assert( CURSOR_INVALID < CURSOR_REQUIRESEEK ); |
| 54941 | 54752 | assert( CURSOR_VALID < CURSOR_REQUIRESEEK ); |
| 54942 | 54753 | assert( CURSOR_FAULT > CURSOR_REQUIRESEEK ); |
| @@ -54947,16 +54758,20 @@ | ||
| 54947 | 54758 | } |
| 54948 | 54759 | sqlite3BtreeClearCursor(pCur); |
| 54949 | 54760 | } |
| 54950 | 54761 | |
| 54951 | 54762 | if( pCur->iPage>=0 ){ |
| 54952 | - while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]); | |
| 54763 | + int i; | |
| 54764 | + for(i=1; i<=pCur->iPage; i++){ | |
| 54765 | + releasePage(pCur->apPage[i]); | |
| 54766 | + } | |
| 54767 | + pCur->iPage = 0; | |
| 54953 | 54768 | }else if( pCur->pgnoRoot==0 ){ |
| 54954 | 54769 | pCur->eState = CURSOR_INVALID; |
| 54955 | 54770 | return SQLITE_OK; |
| 54956 | 54771 | }else{ |
| 54957 | - rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0], | |
| 54772 | + rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0], | |
| 54958 | 54773 | pCur->wrFlag==0 ? PAGER_GET_READONLY : 0); |
| 54959 | 54774 | if( rc!=SQLITE_OK ){ |
| 54960 | 54775 | pCur->eState = CURSOR_INVALID; |
| 54961 | 54776 | return rc; |
| 54962 | 54777 | } |
| @@ -54985,20 +54800,18 @@ | ||
| 54985 | 54800 | pCur->aiIdx[0] = 0; |
| 54986 | 54801 | pCur->info.nSize = 0; |
| 54987 | 54802 | pCur->atLast = 0; |
| 54988 | 54803 | pCur->validNKey = 0; |
| 54989 | 54804 | |
| 54990 | - if( pRoot->nCell>0 ){ | |
| 54991 | - pCur->eState = CURSOR_VALID; | |
| 54992 | - }else if( !pRoot->leaf ){ | |
| 54805 | + if( pRoot->nCell==0 && !pRoot->leaf ){ | |
| 54993 | 54806 | Pgno subpage; |
| 54994 | 54807 | if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT; |
| 54995 | 54808 | subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]); |
| 54996 | 54809 | pCur->eState = CURSOR_VALID; |
| 54997 | 54810 | rc = moveToChild(pCur, subpage); |
| 54998 | 54811 | }else{ |
| 54999 | - pCur->eState = CURSOR_INVALID; | |
| 54812 | + pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID); | |
| 55000 | 54813 | } |
| 55001 | 54814 | return rc; |
| 55002 | 54815 | } |
| 55003 | 54816 | |
| 55004 | 54817 | /* |
| @@ -55250,18 +55063,21 @@ | ||
| 55250 | 55063 | ** the entire cell by checking for the cases where the record is |
| 55251 | 55064 | ** stored entirely within the b-tree page by inspecting the first |
| 55252 | 55065 | ** 2 bytes of the cell. |
| 55253 | 55066 | */ |
| 55254 | 55067 | nCell = pCell[0]; |
| 55255 | - if( nCell<=pPage->max1bytePayload ){ | |
| 55068 | + if( nCell<=pPage->max1bytePayload | |
| 55069 | + /* && (pCell+nCell)<pPage->aDataEnd */ | |
| 55070 | + ){ | |
| 55256 | 55071 | /* This branch runs if the record-size field of the cell is a |
| 55257 | 55072 | ** single byte varint and the record fits entirely on the main |
| 55258 | 55073 | ** b-tree page. */ |
| 55259 | 55074 | testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 55260 | 55075 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 55261 | 55076 | }else if( !(pCell[1] & 0x80) |
| 55262 | 55077 | && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 55078 | + /* && (pCell+nCell+2)<=pPage->aDataEnd */ | |
| 55263 | 55079 | ){ |
| 55264 | 55080 | /* The record-size field is a 2 byte varint and the record |
| 55265 | 55081 | ** fits entirely on the main b-tree page. */ |
| 55266 | 55082 | testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 55267 | 55083 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| @@ -56081,11 +55897,11 @@ | ||
| 56081 | 55897 | nHeader = 0; |
| 56082 | 55898 | if( !pPage->leaf ){ |
| 56083 | 55899 | nHeader += 4; |
| 56084 | 55900 | } |
| 56085 | 55901 | if( pPage->hasData ){ |
| 56086 | - nHeader += putVarint32(&pCell[nHeader], nData+nZero); | |
| 55902 | + nHeader += putVarint(&pCell[nHeader], nData+nZero); | |
| 56087 | 55903 | }else{ |
| 56088 | 55904 | nData = nZero = 0; |
| 56089 | 55905 | } |
| 56090 | 55906 | nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey); |
| 56091 | 55907 | btreeParseCellPtr(pPage, pCell, &info); |
| @@ -56209,10 +56025,11 @@ | ||
| 56209 | 56025 | */ |
| 56210 | 56026 | static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){ |
| 56211 | 56027 | u32 pc; /* Offset to cell content of cell being deleted */ |
| 56212 | 56028 | u8 *data; /* pPage->aData */ |
| 56213 | 56029 | u8 *ptr; /* Used to move bytes around within data[] */ |
| 56030 | + u8 *endPtr; /* End of loop */ | |
| 56214 | 56031 | int rc; /* The return code */ |
| 56215 | 56032 | int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */ |
| 56216 | 56033 | |
| 56217 | 56034 | if( *pRC ) return; |
| 56218 | 56035 | |
| @@ -56232,13 +56049,18 @@ | ||
| 56232 | 56049 | } |
| 56233 | 56050 | rc = freeSpace(pPage, pc, sz); |
| 56234 | 56051 | if( rc ){ |
| 56235 | 56052 | *pRC = rc; |
| 56236 | 56053 | return; |
| 56054 | + } | |
| 56055 | + endPtr = &pPage->aCellIdx[2*pPage->nCell - 2]; | |
| 56056 | + assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */ | |
| 56057 | + while( ptr<endPtr ){ | |
| 56058 | + *(u16*)ptr = *(u16*)&ptr[2]; | |
| 56059 | + ptr += 2; | |
| 56237 | 56060 | } |
| 56238 | 56061 | pPage->nCell--; |
| 56239 | - memmove(ptr, ptr+2, 2*(pPage->nCell - idx)); | |
| 56240 | 56062 | put2byte(&data[hdr+3], pPage->nCell); |
| 56241 | 56063 | pPage->nFree += 2; |
| 56242 | 56064 | } |
| 56243 | 56065 | |
| 56244 | 56066 | /* |
| @@ -56271,10 +56093,13 @@ | ||
| 56271 | 56093 | int j; /* Loop counter */ |
| 56272 | 56094 | int end; /* First byte past the last cell pointer in data[] */ |
| 56273 | 56095 | int ins; /* Index in data[] where new cell pointer is inserted */ |
| 56274 | 56096 | int cellOffset; /* Address of first cell pointer in data[] */ |
| 56275 | 56097 | u8 *data; /* The content of the whole page */ |
| 56098 | + u8 *ptr; /* Used for moving information around in data[] */ | |
| 56099 | + u8 *endPtr; /* End of the loop */ | |
| 56100 | + | |
| 56276 | 56101 | int nSkip = (iChild ? 4 : 0); |
| 56277 | 56102 | |
| 56278 | 56103 | if( *pRC ) return; |
| 56279 | 56104 | |
| 56280 | 56105 | assert( i>=0 && i<=pPage->nCell+pPage->nOverflow ); |
| @@ -56321,11 +56146,17 @@ | ||
| 56321 | 56146 | pPage->nFree -= (u16)(2 + sz); |
| 56322 | 56147 | memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip); |
| 56323 | 56148 | if( iChild ){ |
| 56324 | 56149 | put4byte(&data[idx], iChild); |
| 56325 | 56150 | } |
| 56326 | - memmove(&data[ins+2], &data[ins], end-ins); | |
| 56151 | + ptr = &data[end]; | |
| 56152 | + endPtr = &data[ins]; | |
| 56153 | + assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */ | |
| 56154 | + while( ptr>endPtr ){ | |
| 56155 | + *(u16*)ptr = *(u16*)&ptr[-2]; | |
| 56156 | + ptr -= 2; | |
| 56157 | + } | |
| 56327 | 56158 | put2byte(&data[ins], idx); |
| 56328 | 56159 | put2byte(&data[pPage->hdrOffset+3], pPage->nCell); |
| 56329 | 56160 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 56330 | 56161 | if( pPage->pBt->autoVacuum ){ |
| 56331 | 56162 | /* The cell may contain a pointer to an overflow page. If so, write |
| @@ -58283,11 +58114,11 @@ | ||
| 58283 | 58114 | va_start(ap, zFormat); |
| 58284 | 58115 | if( pCheck->errMsg.nChar ){ |
| 58285 | 58116 | sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1); |
| 58286 | 58117 | } |
| 58287 | 58118 | if( zMsg1 ){ |
| 58288 | - sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1); | |
| 58119 | + sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1); | |
| 58289 | 58120 | } |
| 58290 | 58121 | sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); |
| 58291 | 58122 | va_end(ap); |
| 58292 | 58123 | if( pCheck->errMsg.accError==STRACCUM_NOMEM ){ |
| 58293 | 58124 | pCheck->mallocFailed = 1; |
| @@ -59577,11 +59408,11 @@ | ||
| 59577 | 59408 | rc = backupTruncateFile(pFile, iSize); |
| 59578 | 59409 | } |
| 59579 | 59410 | |
| 59580 | 59411 | /* Sync the database file to disk. */ |
| 59581 | 59412 | if( rc==SQLITE_OK ){ |
| 59582 | - rc = sqlite3PagerSync(pDestPager, 0); | |
| 59413 | + rc = sqlite3PagerSync(pDestPager); | |
| 59583 | 59414 | } |
| 59584 | 59415 | }else{ |
| 59585 | 59416 | sqlite3PagerTruncateImage(pDestPager, nDestTruncate); |
| 59586 | 59417 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 59587 | 59418 | } |
| @@ -59652,14 +59483,14 @@ | ||
| 59652 | 59483 | /* If a transaction is still open on the Btree, roll it back. */ |
| 59653 | 59484 | sqlite3BtreeRollback(p->pDest, SQLITE_OK); |
| 59654 | 59485 | |
| 59655 | 59486 | /* Set the error code of the destination database handle. */ |
| 59656 | 59487 | rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc; |
| 59488 | + sqlite3Error(p->pDestDb, rc, 0); | |
| 59489 | + | |
| 59490 | + /* Exit the mutexes and free the backup context structure. */ | |
| 59657 | 59491 | if( p->pDestDb ){ |
| 59658 | - sqlite3Error(p->pDestDb, rc, 0); | |
| 59659 | - | |
| 59660 | - /* Exit the mutexes and free the backup context structure. */ | |
| 59661 | 59492 | sqlite3LeaveMutexAndCloseZombie(p->pDestDb); |
| 59662 | 59493 | } |
| 59663 | 59494 | sqlite3BtreeLeave(p->pSrc); |
| 59664 | 59495 | if( p->pDestDb ){ |
| 59665 | 59496 | /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a |
| @@ -59859,59 +59690,61 @@ | ||
| 59859 | 59690 | #endif |
| 59860 | 59691 | } |
| 59861 | 59692 | |
| 59862 | 59693 | /* |
| 59863 | 59694 | ** Make sure pMem->z points to a writable allocation of at least |
| 59864 | -** min(n,32) bytes. | |
| 59695 | +** n bytes. | |
| 59865 | 59696 | ** |
| 59866 | -** If the bPreserve argument is true, then copy of the content of | |
| 59867 | -** pMem->z into the new allocation. pMem must be either a string or | |
| 59868 | -** blob if bPreserve is true. If bPreserve is false, any prior content | |
| 59869 | -** in pMem->z is discarded. | |
| 59697 | +** If the third argument passed to this function is true, then memory | |
| 59698 | +** cell pMem must contain a string or blob. In this case the content is | |
| 59699 | +** preserved. Otherwise, if the third parameter to this function is false, | |
| 59700 | +** any current string or blob value may be discarded. | |
| 59701 | +** | |
| 59702 | +** This function sets the MEM_Dyn flag and clears any xDel callback. | |
| 59703 | +** It also clears MEM_Ephem and MEM_Static. If the preserve flag is | |
| 59704 | +** not set, Mem.n is zeroed. | |
| 59870 | 59705 | */ |
| 59871 | -SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){ | |
| 59706 | +SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ | |
| 59872 | 59707 | assert( 1 >= |
| 59873 | 59708 | ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + |
| 59874 | 59709 | (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + |
| 59875 | 59710 | ((pMem->flags&MEM_Ephem) ? 1 : 0) + |
| 59876 | 59711 | ((pMem->flags&MEM_Static) ? 1 : 0) |
| 59877 | 59712 | ); |
| 59878 | 59713 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 59879 | 59714 | |
| 59880 | - /* If the bPreserve flag is set to true, then the memory cell must already | |
| 59715 | + /* If the preserve flag is set to true, then the memory cell must already | |
| 59881 | 59716 | ** contain a valid string or blob value. */ |
| 59882 | - assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); | |
| 59883 | - testcase( bPreserve && pMem->z==0 ); | |
| 59717 | + assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); | |
| 59884 | 59718 | |
| 59885 | - if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ | |
| 59886 | - if( n<32 ) n = 32; | |
| 59887 | - if( bPreserve && pMem->z==pMem->zMalloc ){ | |
| 59719 | + if( n<32 ) n = 32; | |
| 59720 | + if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ | |
| 59721 | + if( preserve && pMem->z==pMem->zMalloc ){ | |
| 59888 | 59722 | pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); |
| 59889 | - bPreserve = 0; | |
| 59723 | + preserve = 0; | |
| 59890 | 59724 | }else{ |
| 59891 | 59725 | sqlite3DbFree(pMem->db, pMem->zMalloc); |
| 59892 | 59726 | pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); |
| 59893 | 59727 | } |
| 59894 | - if( pMem->zMalloc==0 ){ | |
| 59895 | - sqlite3VdbeMemRelease(pMem); | |
| 59896 | - pMem->flags = MEM_Null; | |
| 59897 | - return SQLITE_NOMEM; | |
| 59898 | - } | |
| 59899 | 59728 | } |
| 59900 | 59729 | |
| 59901 | - if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){ | |
| 59730 | + if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){ | |
| 59902 | 59731 | memcpy(pMem->zMalloc, pMem->z, pMem->n); |
| 59903 | 59732 | } |
| 59904 | - if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){ | |
| 59733 | + if( pMem->flags&MEM_Dyn && pMem->xDel ){ | |
| 59905 | 59734 | assert( pMem->xDel!=SQLITE_DYNAMIC ); |
| 59906 | 59735 | pMem->xDel((void *)(pMem->z)); |
| 59907 | 59736 | } |
| 59908 | 59737 | |
| 59909 | 59738 | pMem->z = pMem->zMalloc; |
| 59910 | - pMem->flags &= ~(MEM_Ephem|MEM_Static); | |
| 59739 | + if( pMem->z==0 ){ | |
| 59740 | + pMem->flags = MEM_Null; | |
| 59741 | + }else{ | |
| 59742 | + pMem->flags &= ~(MEM_Ephem|MEM_Static); | |
| 59743 | + } | |
| 59911 | 59744 | pMem->xDel = 0; |
| 59912 | - return SQLITE_OK; | |
| 59745 | + return (pMem->z ? SQLITE_OK : SQLITE_NOMEM); | |
| 59913 | 59746 | } |
| 59914 | 59747 | |
| 59915 | 59748 | /* |
| 59916 | 59749 | ** Make the given Mem object MEM_Dyn. In other words, make it so |
| 59917 | 59750 | ** that any TEXT or BLOB content is stored in memory obtained from |
| @@ -60093,16 +59926,14 @@ | ||
| 60093 | 59926 | ** inconsistent state, for example with (Mem.z==0) and |
| 60094 | 59927 | ** (Mem.type==SQLITE_TEXT). |
| 60095 | 59928 | */ |
| 60096 | 59929 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){ |
| 60097 | 59930 | VdbeMemRelease(p); |
| 60098 | - if( p->zMalloc ){ | |
| 60099 | - sqlite3DbFree(p->db, p->zMalloc); | |
| 60100 | - p->zMalloc = 0; | |
| 60101 | - } | |
| 59931 | + sqlite3DbFree(p->db, p->zMalloc); | |
| 60102 | 59932 | p->z = 0; |
| 60103 | - assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */ | |
| 59933 | + p->zMalloc = 0; | |
| 59934 | + p->xDel = 0; | |
| 60104 | 59935 | } |
| 60105 | 59936 | |
| 60106 | 59937 | /* |
| 60107 | 59938 | ** Convert a 64-bit IEEE double into a 64-bit signed integer. |
| 60108 | 59939 | ** If the double is out of range of a 64-bit signed integer then |
| @@ -60282,13 +60113,10 @@ | ||
| 60282 | 60113 | sqlite3RowSetClear(pMem->u.pRowSet); |
| 60283 | 60114 | } |
| 60284 | 60115 | MemSetTypeFlag(pMem, MEM_Null); |
| 60285 | 60116 | pMem->type = SQLITE_NULL; |
| 60286 | 60117 | } |
| 60287 | -SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){ | |
| 60288 | - sqlite3VdbeMemSetNull((Mem*)p); | |
| 60289 | -} | |
| 60290 | 60118 | |
| 60291 | 60119 | /* |
| 60292 | 60120 | ** Delete any previous value and set the value to be a BLOB of length |
| 60293 | 60121 | ** n containing all zeros. |
| 60294 | 60122 | */ |
| @@ -61022,11 +60850,11 @@ | ||
| 61022 | 60850 | if( aRet==0 ){ |
| 61023 | 60851 | sqlite3_result_error_nomem(context); |
| 61024 | 60852 | }else{ |
| 61025 | 60853 | aRet[0] = nSerial+1; |
| 61026 | 60854 | sqlite3PutVarint(&aRet[1], iSerial); |
| 61027 | - sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial); | |
| 60855 | + sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format); | |
| 61028 | 60856 | sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT); |
| 61029 | 60857 | sqlite3DbFree(db, aRet); |
| 61030 | 60858 | } |
| 61031 | 60859 | } |
| 61032 | 60860 | |
| @@ -61207,12 +61035,11 @@ | ||
| 61207 | 61035 | */ |
| 61208 | 61036 | |
| 61209 | 61037 | /* |
| 61210 | 61038 | ** Create a new virtual database engine. |
| 61211 | 61039 | */ |
| 61212 | -SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){ | |
| 61213 | - sqlite3 *db = pParse->db; | |
| 61040 | +SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){ | |
| 61214 | 61041 | Vdbe *p; |
| 61215 | 61042 | p = sqlite3DbMallocZero(db, sizeof(Vdbe) ); |
| 61216 | 61043 | if( p==0 ) return 0; |
| 61217 | 61044 | p->db = db; |
| 61218 | 61045 | if( db->pVdbe ){ |
| @@ -61220,14 +61047,10 @@ | ||
| 61220 | 61047 | } |
| 61221 | 61048 | p->pNext = db->pVdbe; |
| 61222 | 61049 | p->pPrev = 0; |
| 61223 | 61050 | db->pVdbe = p; |
| 61224 | 61051 | p->magic = VDBE_MAGIC_INIT; |
| 61225 | - p->pParse = pParse; | |
| 61226 | - assert( pParse->aLabel==0 ); | |
| 61227 | - assert( pParse->nLabel==0 ); | |
| 61228 | - assert( pParse->nOpAlloc==0 ); | |
| 61229 | 61052 | return p; |
| 61230 | 61053 | } |
| 61231 | 61054 | |
| 61232 | 61055 | /* |
| 61233 | 61056 | ** Remember the SQL string for a prepared statement. |
| @@ -61279,18 +61102,17 @@ | ||
| 61279 | 61102 | ** If an out-of-memory error occurs while resizing the array, return |
| 61280 | 61103 | ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain |
| 61281 | 61104 | ** unchanged (this is so that any opcodes already allocated can be |
| 61282 | 61105 | ** correctly deallocated along with the rest of the Vdbe). |
| 61283 | 61106 | */ |
| 61284 | -static int growOpArray(Vdbe *v){ | |
| 61107 | +static int growOpArray(Vdbe *p){ | |
| 61285 | 61108 | VdbeOp *pNew; |
| 61286 | - Parse *p = v->pParse; | |
| 61287 | 61109 | int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op))); |
| 61288 | - pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); | |
| 61110 | + pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op)); | |
| 61289 | 61111 | if( pNew ){ |
| 61290 | 61112 | p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op); |
| 61291 | - v->aOp = pNew; | |
| 61113 | + p->aOp = pNew; | |
| 61292 | 61114 | } |
| 61293 | 61115 | return (pNew ? SQLITE_OK : SQLITE_NOMEM); |
| 61294 | 61116 | } |
| 61295 | 61117 | |
| 61296 | 61118 | #ifdef SQLITE_DEBUG |
| @@ -61325,11 +61147,11 @@ | ||
| 61325 | 61147 | VdbeOp *pOp; |
| 61326 | 61148 | |
| 61327 | 61149 | i = p->nOp; |
| 61328 | 61150 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61329 | 61151 | assert( op>0 && op<0xff ); |
| 61330 | - if( p->pParse->nOpAlloc<=i ){ | |
| 61152 | + if( p->nOpAlloc<=i ){ | |
| 61331 | 61153 | if( growOpArray(p) ){ |
| 61332 | 61154 | return 1; |
| 61333 | 61155 | } |
| 61334 | 61156 | } |
| 61335 | 61157 | p->nOp++; |
| @@ -61344,19 +61166,10 @@ | ||
| 61344 | 61166 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 61345 | 61167 | pOp->zComment = 0; |
| 61346 | 61168 | #endif |
| 61347 | 61169 | #ifdef SQLITE_DEBUG |
| 61348 | 61170 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 61349 | - int jj, kk; | |
| 61350 | - Parse *pParse = p->pParse; | |
| 61351 | - for(jj=kk=0; jj<SQLITE_N_COLCACHE; jj++){ | |
| 61352 | - struct yColCache *x = pParse->aColCache + jj; | |
| 61353 | - if( x->iLevel>pParse->iCacheLevel || x->iReg==0 ) continue; | |
| 61354 | - printf(" r[%d]={%d:%d}", x->iReg, x->iTable, x->iColumn); | |
| 61355 | - kk++; | |
| 61356 | - } | |
| 61357 | - if( kk ) printf("\n"); | |
| 61358 | 61171 | sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 61359 | 61172 | test_addop_breakpoint(); |
| 61360 | 61173 | } |
| 61361 | 61174 | #endif |
| 61362 | 61175 | #ifdef VDBE_PROFILE |
| @@ -61436,14 +61249,13 @@ | ||
| 61436 | 61249 | ** always negative and P2 values are suppose to be non-negative. |
| 61437 | 61250 | ** Hence, a negative P2 value is a label that has yet to be resolved. |
| 61438 | 61251 | ** |
| 61439 | 61252 | ** Zero is returned if a malloc() fails. |
| 61440 | 61253 | */ |
| 61441 | -SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *v){ | |
| 61442 | - Parse *p = v->pParse; | |
| 61254 | +SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){ | |
| 61443 | 61255 | int i = p->nLabel++; |
| 61444 | - assert( v->magic==VDBE_MAGIC_INIT ); | |
| 61256 | + assert( p->magic==VDBE_MAGIC_INIT ); | |
| 61445 | 61257 | if( (i & (i-1))==0 ){ |
| 61446 | 61258 | p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, |
| 61447 | 61259 | (i*2+1)*sizeof(p->aLabel[0])); |
| 61448 | 61260 | } |
| 61449 | 61261 | if( p->aLabel ){ |
| @@ -61455,17 +61267,16 @@ | ||
| 61455 | 61267 | /* |
| 61456 | 61268 | ** Resolve label "x" to be the address of the next instruction to |
| 61457 | 61269 | ** be inserted. The parameter "x" must have been obtained from |
| 61458 | 61270 | ** a prior call to sqlite3VdbeMakeLabel(). |
| 61459 | 61271 | */ |
| 61460 | -SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ | |
| 61461 | - Parse *p = v->pParse; | |
| 61272 | +SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){ | |
| 61462 | 61273 | int j = -1-x; |
| 61463 | - assert( v->magic==VDBE_MAGIC_INIT ); | |
| 61274 | + assert( p->magic==VDBE_MAGIC_INIT ); | |
| 61464 | 61275 | assert( j<p->nLabel ); |
| 61465 | 61276 | if( j>=0 && p->aLabel ){ |
| 61466 | - p->aLabel[j] = v->nOp; | |
| 61277 | + p->aLabel[j] = p->nOp; | |
| 61467 | 61278 | } |
| 61468 | 61279 | } |
| 61469 | 61280 | |
| 61470 | 61281 | /* |
| 61471 | 61282 | ** Mark the VDBE as one that can only be run one time. |
| @@ -61610,12 +61421,11 @@ | ||
| 61610 | 61421 | */ |
| 61611 | 61422 | static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ |
| 61612 | 61423 | int i; |
| 61613 | 61424 | int nMaxArgs = *pMaxFuncArgs; |
| 61614 | 61425 | Op *pOp; |
| 61615 | - Parse *pParse = p->pParse; | |
| 61616 | - int *aLabel = pParse->aLabel; | |
| 61426 | + int *aLabel = p->aLabel; | |
| 61617 | 61427 | p->readOnly = 1; |
| 61618 | 61428 | p->bIsReader = 0; |
| 61619 | 61429 | for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ |
| 61620 | 61430 | u8 opcode = pOp->opcode; |
| 61621 | 61431 | |
| @@ -61674,17 +61484,16 @@ | ||
| 61674 | 61484 | } |
| 61675 | 61485 | } |
| 61676 | 61486 | |
| 61677 | 61487 | pOp->opflags = sqlite3OpcodeProperty[opcode]; |
| 61678 | 61488 | if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 61679 | - assert( -1-pOp->p2<pParse->nLabel ); | |
| 61489 | + assert( -1-pOp->p2<p->nLabel ); | |
| 61680 | 61490 | pOp->p2 = aLabel[-1-pOp->p2]; |
| 61681 | 61491 | } |
| 61682 | 61492 | } |
| 61683 | - sqlite3DbFree(p->db, pParse->aLabel); | |
| 61684 | - pParse->aLabel = 0; | |
| 61685 | - pParse->nLabel = 0; | |
| 61493 | + sqlite3DbFree(p->db, p->aLabel); | |
| 61494 | + p->aLabel = 0; | |
| 61686 | 61495 | *pMaxFuncArgs = nMaxArgs; |
| 61687 | 61496 | assert( p->bIsReader!=0 || p->btreeMask==0 ); |
| 61688 | 61497 | } |
| 61689 | 61498 | |
| 61690 | 61499 | /* |
| @@ -61724,11 +61533,11 @@ | ||
| 61724 | 61533 | ** address of the first operation added. |
| 61725 | 61534 | */ |
| 61726 | 61535 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ |
| 61727 | 61536 | int addr; |
| 61728 | 61537 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61729 | - if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){ | |
| 61538 | + if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){ | |
| 61730 | 61539 | return 0; |
| 61731 | 61540 | } |
| 61732 | 61541 | addr = p->nOp; |
| 61733 | 61542 | if( ALWAYS(nOp>0) ){ |
| 61734 | 61543 | int i; |
| @@ -61913,17 +61722,10 @@ | ||
| 61913 | 61722 | pOp->opcode = OP_Noop; |
| 61914 | 61723 | if( addr==p->nOp-1 ) p->nOp--; |
| 61915 | 61724 | } |
| 61916 | 61725 | } |
| 61917 | 61726 | |
| 61918 | -/* | |
| 61919 | -** Remove the last opcode inserted | |
| 61920 | -*/ | |
| 61921 | -SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe *p){ | |
| 61922 | - p->nOp--; | |
| 61923 | -} | |
| 61924 | - | |
| 61925 | 61727 | /* |
| 61926 | 61728 | ** Change the value of the P4 operand for a specific instruction. |
| 61927 | 61729 | ** This routine is useful when a large program is loaded from a |
| 61928 | 61730 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| 61929 | 61731 | ** few minor changes to the program. |
| @@ -62085,21 +61887,11 @@ | ||
| 62085 | 61887 | if( c=='4' ) return pOp->p4.i; |
| 62086 | 61888 | return pOp->p5; |
| 62087 | 61889 | } |
| 62088 | 61890 | |
| 62089 | 61891 | /* |
| 62090 | -** Compute a string for the "comment" field of a VDBE opcode listing. | |
| 62091 | -** | |
| 62092 | -** The Synopsis: field in comments in the vdbe.c source file gets converted | |
| 62093 | -** to an extra string that is appended to the sqlite3OpcodeName(). In the | |
| 62094 | -** absence of other comments, this synopsis becomes the comment on the opcode. | |
| 62095 | -** Some translation occurs: | |
| 62096 | -** | |
| 62097 | -** "PX" -> "r[X]" | |
| 62098 | -** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1 | |
| 62099 | -** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0 | |
| 62100 | -** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x | |
| 61892 | +** Compute a string for the "comment" field of a VDBE opcode listing | |
| 62101 | 61893 | */ |
| 62102 | 61894 | static int displayComment( |
| 62103 | 61895 | const Op *pOp, /* The opcode to be commented */ |
| 62104 | 61896 | const char *zP4, /* Previously obtained value for P4 */ |
| 62105 | 61897 | char *zTemp, /* Write result here */ |
| @@ -62129,17 +61921,11 @@ | ||
| 62129 | 61921 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1); |
| 62130 | 61922 | if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){ |
| 62131 | 61923 | ii += 3; |
| 62132 | 61924 | jj += sqlite3Strlen30(zTemp+jj); |
| 62133 | 61925 | v2 = translateP(zSynopsis[ii], pOp); |
| 62134 | - if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){ | |
| 62135 | - ii += 2; | |
| 62136 | - v2++; | |
| 62137 | - } | |
| 62138 | - if( v2>1 ){ | |
| 62139 | - sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1); | |
| 62140 | - } | |
| 61926 | + if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1); | |
| 62141 | 61927 | }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){ |
| 62142 | 61928 | ii += 4; |
| 62143 | 61929 | } |
| 62144 | 61930 | } |
| 62145 | 61931 | jj += sqlite3Strlen30(zTemp+jj); |
| @@ -62367,13 +62153,10 @@ | ||
| 62367 | 62153 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 62368 | 62154 | displayComment(pOp, zP4, zCom, sizeof(zCom)); |
| 62369 | 62155 | #else |
| 62370 | 62156 | zCom[0] = 0 |
| 62371 | 62157 | #endif |
| 62372 | - /* NB: The sqlite3OpcodeName() function is implemented by code created | |
| 62373 | - ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the | |
| 62374 | - ** information from the vdbe.c source text */ | |
| 62375 | 62158 | fprintf(pOut, zFormat1, pc, |
| 62376 | 62159 | sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5, |
| 62377 | 62160 | zCom |
| 62378 | 62161 | ); |
| 62379 | 62162 | fflush(pOut); |
| @@ -62801,11 +62584,10 @@ | ||
| 62801 | 62584 | |
| 62802 | 62585 | assert( p!=0 ); |
| 62803 | 62586 | assert( p->nOp>0 ); |
| 62804 | 62587 | assert( pParse!=0 ); |
| 62805 | 62588 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 62806 | - assert( pParse==p->pParse ); | |
| 62807 | 62589 | db = p->db; |
| 62808 | 62590 | assert( db->mallocFailed==0 ); |
| 62809 | 62591 | nVar = pParse->nVar; |
| 62810 | 62592 | nMem = pParse->nMem; |
| 62811 | 62593 | nCursor = pParse->nTab; |
| @@ -62825,12 +62607,12 @@ | ||
| 62825 | 62607 | nMem += nCursor; |
| 62826 | 62608 | |
| 62827 | 62609 | /* Allocate space for memory registers, SQL variables, VDBE cursors and |
| 62828 | 62610 | ** an array to marshal SQL function arguments in. |
| 62829 | 62611 | */ |
| 62830 | - zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ | |
| 62831 | - zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */ | |
| 62612 | + zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ | |
| 62613 | + zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */ | |
| 62832 | 62614 | |
| 62833 | 62615 | resolveP2Values(p, &nArg); |
| 62834 | 62616 | p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort); |
| 62835 | 62617 | if( pParse->explain && nMem<10 ){ |
| 62836 | 62618 | nMem = 10; |
| @@ -63653,11 +63435,10 @@ | ||
| 63653 | 63435 | sqlite3 *db = p->db; |
| 63654 | 63436 | int rc = p->rc; |
| 63655 | 63437 | if( p->zErrMsg ){ |
| 63656 | 63438 | u8 mallocFailed = db->mallocFailed; |
| 63657 | 63439 | sqlite3BeginBenignMalloc(); |
| 63658 | - if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db); | |
| 63659 | 63440 | sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63660 | 63441 | sqlite3EndBenignMalloc(); |
| 63661 | 63442 | db->mallocFailed = mallocFailed; |
| 63662 | 63443 | db->errCode = rc; |
| 63663 | 63444 | }else{ |
| @@ -63722,11 +63503,12 @@ | ||
| 63722 | 63503 | }else if( p->rc && p->expired ){ |
| 63723 | 63504 | /* The expired flag was set on the VDBE before the first call |
| 63724 | 63505 | ** to sqlite3_step(). For consistency (since sqlite3_step() was |
| 63725 | 63506 | ** called), set the database error in this case as well. |
| 63726 | 63507 | */ |
| 63727 | - sqlite3Error(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg); | |
| 63508 | + sqlite3Error(db, p->rc, 0); | |
| 63509 | + sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT); | |
| 63728 | 63510 | sqlite3DbFree(db, p->zErrMsg); |
| 63729 | 63511 | p->zErrMsg = 0; |
| 63730 | 63512 | } |
| 63731 | 63513 | |
| 63732 | 63514 | /* Reclaim all memory used by the VDBE |
| @@ -63829,10 +63611,11 @@ | ||
| 63829 | 63611 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 63830 | 63612 | sqlite3DbFree(db, pSub); |
| 63831 | 63613 | } |
| 63832 | 63614 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 63833 | 63615 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 63616 | + sqlite3DbFree(db, p->aLabel); | |
| 63834 | 63617 | sqlite3DbFree(db, p->aColName); |
| 63835 | 63618 | sqlite3DbFree(db, p->zSql); |
| 63836 | 63619 | sqlite3DbFree(db, p->pFree); |
| 63837 | 63620 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 63838 | 63621 | sqlite3DbFree(db, p->zExplain); |
| @@ -64059,19 +63842,25 @@ | ||
| 64059 | 63842 | /* |
| 64060 | 63843 | ** Write the serialized data blob for the value stored in pMem into |
| 64061 | 63844 | ** buf. It is assumed that the caller has allocated sufficient space. |
| 64062 | 63845 | ** Return the number of bytes written. |
| 64063 | 63846 | ** |
| 64064 | -** nBuf is the amount of space left in buf[]. The caller is responsible | |
| 64065 | -** for allocating enough space to buf[] to hold the entire field, exclusive | |
| 64066 | -** of the pMem->u.nZero bytes for a MEM_Zero value. | |
| 63847 | +** nBuf is the amount of space left in buf[]. nBuf must always be | |
| 63848 | +** large enough to hold the entire field. Except, if the field is | |
| 63849 | +** a blob with a zero-filled tail, then buf[] might be just the right | |
| 63850 | +** size to hold everything except for the zero-filled tail. If buf[] | |
| 63851 | +** is only big enough to hold the non-zero prefix, then only write that | |
| 63852 | +** prefix into buf[]. But if buf[] is large enough to hold both the | |
| 63853 | +** prefix and the tail then write the prefix and set the tail to all | |
| 63854 | +** zeros. | |
| 64067 | 63855 | ** |
| 64068 | 63856 | ** Return the number of bytes actually written into buf[]. The number |
| 64069 | 63857 | ** of bytes in the zero-filled tail is included in the return value only |
| 64070 | 63858 | ** if those bytes were zeroed in buf[]. |
| 64071 | 63859 | */ |
| 64072 | -SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){ | |
| 63860 | +SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){ | |
| 63861 | + u32 serial_type = sqlite3VdbeSerialType(pMem, file_format); | |
| 64073 | 63862 | u32 len; |
| 64074 | 63863 | |
| 64075 | 63864 | /* Integer and Real */ |
| 64076 | 63865 | if( serial_type<=7 && serial_type>0 ){ |
| 64077 | 63866 | u64 v; |
| @@ -64082,10 +63871,11 @@ | ||
| 64082 | 63871 | swapMixedEndianFloat(v); |
| 64083 | 63872 | }else{ |
| 64084 | 63873 | v = pMem->u.i; |
| 64085 | 63874 | } |
| 64086 | 63875 | len = i = sqlite3VdbeSerialTypeLen(serial_type); |
| 63876 | + assert( len<=(u32)nBuf ); | |
| 64087 | 63877 | while( i-- ){ |
| 64088 | 63878 | buf[i] = (u8)(v&0xFF); |
| 64089 | 63879 | v >>= 8; |
| 64090 | 63880 | } |
| 64091 | 63881 | return len; |
| @@ -64093,12 +63883,21 @@ | ||
| 64093 | 63883 | |
| 64094 | 63884 | /* String or blob */ |
| 64095 | 63885 | if( serial_type>=12 ){ |
| 64096 | 63886 | assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0) |
| 64097 | 63887 | == (int)sqlite3VdbeSerialTypeLen(serial_type) ); |
| 63888 | + assert( pMem->n<=nBuf ); | |
| 64098 | 63889 | len = pMem->n; |
| 64099 | 63890 | memcpy(buf, pMem->z, len); |
| 63891 | + if( pMem->flags & MEM_Zero ){ | |
| 63892 | + len += pMem->u.nZero; | |
| 63893 | + assert( nBuf>=0 ); | |
| 63894 | + if( len > (u32)nBuf ){ | |
| 63895 | + len = (u32)nBuf; | |
| 63896 | + } | |
| 63897 | + memset(&buf[pMem->n], 0, len-pMem->n); | |
| 63898 | + } | |
| 64100 | 63899 | return len; |
| 64101 | 63900 | } |
| 64102 | 63901 | |
| 64103 | 63902 | /* NULL or constants 0 or 1 */ |
| 64104 | 63903 | return 0; |
| @@ -65095,21 +64894,20 @@ | ||
| 65095 | 64894 | && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){ |
| 65096 | 64895 | sqlite3_reset(pStmt); |
| 65097 | 64896 | v->doingRerun = 1; |
| 65098 | 64897 | assert( v->expired==0 ); |
| 65099 | 64898 | } |
| 65100 | - if( rc2!=SQLITE_OK ){ | |
| 64899 | + if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){ | |
| 65101 | 64900 | /* This case occurs after failing to recompile an sql statement. |
| 65102 | 64901 | ** The error message from the SQL compiler has already been loaded |
| 65103 | 64902 | ** into the database handle. This block copies the error message |
| 65104 | 64903 | ** from the database handle into the statement and sets the statement |
| 65105 | 64904 | ** program counter to 0 to ensure that when the statement is |
| 65106 | 64905 | ** finalized or reset the parser error message is available via |
| 65107 | 64906 | ** sqlite3_errmsg() and sqlite3_errcode(). |
| 65108 | 64907 | */ |
| 65109 | 64908 | const char *zErr = (const char *)sqlite3_value_text(db->pErr); |
| 65110 | - assert( zErr!=0 || db->mallocFailed ); | |
| 65111 | 64909 | sqlite3DbFree(db, v->zErrMsg); |
| 65112 | 64910 | if( !db->mallocFailed ){ |
| 65113 | 64911 | v->zErrMsg = sqlite3DbStrDup(db, zErr); |
| 65114 | 64912 | v->rc = rc2; |
| 65115 | 64913 | } else { |
| @@ -66021,11 +65819,10 @@ | ||
| 66021 | 65819 | if( db->nVdbeExec>1 ){ |
| 66022 | 65820 | while( *zRawSql ){ |
| 66023 | 65821 | const char *zStart = zRawSql; |
| 66024 | 65822 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 66025 | 65823 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 66026 | - assert( (zRawSql - zStart) > 0 ); | |
| 66027 | 65824 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| 66028 | 65825 | } |
| 66029 | 65826 | }else{ |
| 66030 | 65827 | while( zRawSql[0] ){ |
| 66031 | 65828 | n = findNextHostParameter(zRawSql, &nToken); |
| @@ -66054,13 +65851,13 @@ | ||
| 66054 | 65851 | assert( idx>0 && idx<=p->nVar ); |
| 66055 | 65852 | pVar = &p->aVar[idx-1]; |
| 66056 | 65853 | if( pVar->flags & MEM_Null ){ |
| 66057 | 65854 | sqlite3StrAccumAppend(&out, "NULL", 4); |
| 66058 | 65855 | }else if( pVar->flags & MEM_Int ){ |
| 66059 | - sqlite3XPrintf(&out, 0, "%lld", pVar->u.i); | |
| 65856 | + sqlite3XPrintf(&out, "%lld", pVar->u.i); | |
| 66060 | 65857 | }else if( pVar->flags & MEM_Real ){ |
| 66061 | - sqlite3XPrintf(&out, 0, "%!.15g", pVar->r); | |
| 65858 | + sqlite3XPrintf(&out, "%!.15g", pVar->r); | |
| 66062 | 65859 | }else if( pVar->flags & MEM_Str ){ |
| 66063 | 65860 | int nOut; /* Number of bytes of the string text to include in output */ |
| 66064 | 65861 | #ifndef SQLITE_OMIT_UTF16 |
| 66065 | 65862 | u8 enc = ENC(db); |
| 66066 | 65863 | Mem utf8; |
| @@ -66077,37 +65874,33 @@ | ||
| 66077 | 65874 | if( nOut>SQLITE_TRACE_SIZE_LIMIT ){ |
| 66078 | 65875 | nOut = SQLITE_TRACE_SIZE_LIMIT; |
| 66079 | 65876 | while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; } |
| 66080 | 65877 | } |
| 66081 | 65878 | #endif |
| 66082 | - sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z); | |
| 65879 | + sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z); | |
| 66083 | 65880 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 66084 | - if( nOut<pVar->n ){ | |
| 66085 | - sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut); | |
| 66086 | - } | |
| 65881 | + if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut); | |
| 66087 | 65882 | #endif |
| 66088 | 65883 | #ifndef SQLITE_OMIT_UTF16 |
| 66089 | 65884 | if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8); |
| 66090 | 65885 | #endif |
| 66091 | 65886 | }else if( pVar->flags & MEM_Zero ){ |
| 66092 | - sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero); | |
| 65887 | + sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero); | |
| 66093 | 65888 | }else{ |
| 66094 | 65889 | int nOut; /* Number of bytes of the blob to include in output */ |
| 66095 | 65890 | assert( pVar->flags & MEM_Blob ); |
| 66096 | 65891 | sqlite3StrAccumAppend(&out, "x'", 2); |
| 66097 | 65892 | nOut = pVar->n; |
| 66098 | 65893 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 66099 | 65894 | if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT; |
| 66100 | 65895 | #endif |
| 66101 | 65896 | for(i=0; i<nOut; i++){ |
| 66102 | - sqlite3XPrintf(&out, 0, "%02x", pVar->z[i]&0xff); | |
| 65897 | + sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff); | |
| 66103 | 65898 | } |
| 66104 | 65899 | sqlite3StrAccumAppend(&out, "'", 1); |
| 66105 | 65900 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 66106 | - if( nOut<pVar->n ){ | |
| 66107 | - sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut); | |
| 66108 | - } | |
| 65901 | + if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut); | |
| 66109 | 65902 | #endif |
| 66110 | 65903 | } |
| 66111 | 65904 | } |
| 66112 | 65905 | } |
| 66113 | 65906 | return sqlite3StrAccumFinish(&out); |
| @@ -66162,11 +65955,11 @@ | ||
| 66162 | 65955 | int n = p->nIndent; |
| 66163 | 65956 | if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent); |
| 66164 | 65957 | sqlite3AppendSpace(&p->str, p->aIndent[n-1]); |
| 66165 | 65958 | } |
| 66166 | 65959 | va_start(ap, zFormat); |
| 66167 | - sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap); | |
| 65960 | + sqlite3VXPrintf(&p->str, 1, zFormat, ap); | |
| 66168 | 65961 | va_end(ap); |
| 66169 | 65962 | } |
| 66170 | 65963 | } |
| 66171 | 65964 | |
| 66172 | 65965 | /* |
| @@ -66869,11 +66662,433 @@ | ||
| 66869 | 66662 | i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ |
| 66870 | 66663 | #ifdef VDBE_PROFILE |
| 66871 | 66664 | u64 start; /* CPU clock count at start of opcode */ |
| 66872 | 66665 | int origPc; /* Program counter at start of opcode */ |
| 66873 | 66666 | #endif |
| 66874 | - /*** INSERT STACK UNION HERE ***/ | |
| 66667 | + /******************************************************************** | |
| 66668 | + ** Automatically generated code | |
| 66669 | + ** | |
| 66670 | + ** The following union is automatically generated by the | |
| 66671 | + ** vdbe-compress.tcl script. The purpose of this union is to | |
| 66672 | + ** reduce the amount of stack space required by this function. | |
| 66673 | + ** See comments in the vdbe-compress.tcl script for details. | |
| 66674 | + */ | |
| 66675 | + union vdbeExecUnion { | |
| 66676 | + struct OP_Yield_stack_vars { | |
| 66677 | + int pcDest; | |
| 66678 | + } aa; | |
| 66679 | + struct OP_Halt_stack_vars { | |
| 66680 | + const char *zType; | |
| 66681 | + const char *zLogFmt; | |
| 66682 | + } ab; | |
| 66683 | + struct OP_Null_stack_vars { | |
| 66684 | + int cnt; | |
| 66685 | + u16 nullFlag; | |
| 66686 | + } ac; | |
| 66687 | + struct OP_Variable_stack_vars { | |
| 66688 | + Mem *pVar; /* Value being transferred */ | |
| 66689 | + } ad; | |
| 66690 | + struct OP_Move_stack_vars { | |
| 66691 | + char *zMalloc; /* Holding variable for allocated memory */ | |
| 66692 | + int n; /* Number of registers left to copy */ | |
| 66693 | + int p1; /* Register to copy from */ | |
| 66694 | + int p2; /* Register to copy to */ | |
| 66695 | + } ae; | |
| 66696 | + struct OP_Copy_stack_vars { | |
| 66697 | + int n; | |
| 66698 | + } af; | |
| 66699 | + struct OP_ResultRow_stack_vars { | |
| 66700 | + Mem *pMem; | |
| 66701 | + int i; | |
| 66702 | + } ag; | |
| 66703 | + struct OP_Concat_stack_vars { | |
| 66704 | + i64 nByte; | |
| 66705 | + } ah; | |
| 66706 | + struct OP_Remainder_stack_vars { | |
| 66707 | + char bIntint; /* Started out as two integer operands */ | |
| 66708 | + int flags; /* Combined MEM_* flags from both inputs */ | |
| 66709 | + i64 iA; /* Integer value of left operand */ | |
| 66710 | + i64 iB; /* Integer value of right operand */ | |
| 66711 | + double rA; /* Real value of left operand */ | |
| 66712 | + double rB; /* Real value of right operand */ | |
| 66713 | + } ai; | |
| 66714 | + struct OP_Function_stack_vars { | |
| 66715 | + int i; | |
| 66716 | + Mem *pArg; | |
| 66717 | + sqlite3_context ctx; | |
| 66718 | + sqlite3_value **apVal; | |
| 66719 | + int n; | |
| 66720 | + } aj; | |
| 66721 | + struct OP_ShiftRight_stack_vars { | |
| 66722 | + i64 iA; | |
| 66723 | + u64 uA; | |
| 66724 | + i64 iB; | |
| 66725 | + u8 op; | |
| 66726 | + } ak; | |
| 66727 | + struct OP_Ge_stack_vars { | |
| 66728 | + int res; /* Result of the comparison of pIn1 against pIn3 */ | |
| 66729 | + char affinity; /* Affinity to use for comparison */ | |
| 66730 | + u16 flags1; /* Copy of initial value of pIn1->flags */ | |
| 66731 | + u16 flags3; /* Copy of initial value of pIn3->flags */ | |
| 66732 | + } al; | |
| 66733 | + struct OP_Compare_stack_vars { | |
| 66734 | + int n; | |
| 66735 | + int i; | |
| 66736 | + int p1; | |
| 66737 | + int p2; | |
| 66738 | + const KeyInfo *pKeyInfo; | |
| 66739 | + int idx; | |
| 66740 | + CollSeq *pColl; /* Collating sequence to use on this term */ | |
| 66741 | + int bRev; /* True for DESCENDING sort order */ | |
| 66742 | + } am; | |
| 66743 | + struct OP_Or_stack_vars { | |
| 66744 | + int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ | |
| 66745 | + int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ | |
| 66746 | + } an; | |
| 66747 | + struct OP_IfNot_stack_vars { | |
| 66748 | + int c; | |
| 66749 | + } ao; | |
| 66750 | + struct OP_Column_stack_vars { | |
| 66751 | + i64 payloadSize64; /* Number of bytes in the record */ | |
| 66752 | + int p2; /* column number to retrieve */ | |
| 66753 | + VdbeCursor *pC; /* The VDBE cursor */ | |
| 66754 | + BtCursor *pCrsr; /* The BTree cursor */ | |
| 66755 | + u32 *aType; /* aType[i] holds the numeric type of the i-th column */ | |
| 66756 | + u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ | |
| 66757 | + int len; /* The length of the serialized data for the column */ | |
| 66758 | + int i; /* Loop counter */ | |
| 66759 | + Mem *pDest; /* Where to write the extracted value */ | |
| 66760 | + Mem sMem; /* For storing the record being decoded */ | |
| 66761 | + const u8 *zData; /* Part of the record being decoded */ | |
| 66762 | + const u8 *zHdr; /* Next unparsed byte of the header */ | |
| 66763 | + const u8 *zEndHdr; /* Pointer to first byte after the header */ | |
| 66764 | + u32 offset; /* Offset into the data */ | |
| 66765 | + u32 szField; /* Number of bytes in the content of a field */ | |
| 66766 | + u32 avail; /* Number of bytes of available data */ | |
| 66767 | + u32 t; /* A type code from the record header */ | |
| 66768 | + Mem *pReg; /* PseudoTable input register */ | |
| 66769 | + } ap; | |
| 66770 | + struct OP_Affinity_stack_vars { | |
| 66771 | + const char *zAffinity; /* The affinity to be applied */ | |
| 66772 | + char cAff; /* A single character of affinity */ | |
| 66773 | + } aq; | |
| 66774 | + struct OP_MakeRecord_stack_vars { | |
| 66775 | + u8 *zNewRecord; /* A buffer to hold the data for the new record */ | |
| 66776 | + Mem *pRec; /* The new record */ | |
| 66777 | + u64 nData; /* Number of bytes of data space */ | |
| 66778 | + int nHdr; /* Number of bytes of header space */ | |
| 66779 | + i64 nByte; /* Data space required for this record */ | |
| 66780 | + int nZero; /* Number of zero bytes at the end of the record */ | |
| 66781 | + int nVarint; /* Number of bytes in a varint */ | |
| 66782 | + u32 serial_type; /* Type field */ | |
| 66783 | + Mem *pData0; /* First field to be combined into the record */ | |
| 66784 | + Mem *pLast; /* Last field of the record */ | |
| 66785 | + int nField; /* Number of fields in the record */ | |
| 66786 | + char *zAffinity; /* The affinity string for the record */ | |
| 66787 | + int file_format; /* File format to use for encoding */ | |
| 66788 | + int i; /* Space used in zNewRecord[] */ | |
| 66789 | + int len; /* Length of a field */ | |
| 66790 | + } ar; | |
| 66791 | + struct OP_Count_stack_vars { | |
| 66792 | + i64 nEntry; | |
| 66793 | + BtCursor *pCrsr; | |
| 66794 | + } as; | |
| 66795 | + struct OP_Savepoint_stack_vars { | |
| 66796 | + int p1; /* Value of P1 operand */ | |
| 66797 | + char *zName; /* Name of savepoint */ | |
| 66798 | + int nName; | |
| 66799 | + Savepoint *pNew; | |
| 66800 | + Savepoint *pSavepoint; | |
| 66801 | + Savepoint *pTmp; | |
| 66802 | + int iSavepoint; | |
| 66803 | + int ii; | |
| 66804 | + } at; | |
| 66805 | + struct OP_AutoCommit_stack_vars { | |
| 66806 | + int desiredAutoCommit; | |
| 66807 | + int iRollback; | |
| 66808 | + int turnOnAC; | |
| 66809 | + } au; | |
| 66810 | + struct OP_Transaction_stack_vars { | |
| 66811 | + Btree *pBt; | |
| 66812 | + } av; | |
| 66813 | + struct OP_ReadCookie_stack_vars { | |
| 66814 | + int iMeta; | |
| 66815 | + int iDb; | |
| 66816 | + int iCookie; | |
| 66817 | + } aw; | |
| 66818 | + struct OP_SetCookie_stack_vars { | |
| 66819 | + Db *pDb; | |
| 66820 | + } ax; | |
| 66821 | + struct OP_VerifyCookie_stack_vars { | |
| 66822 | + int iMeta; | |
| 66823 | + int iGen; | |
| 66824 | + Btree *pBt; | |
| 66825 | + } ay; | |
| 66826 | + struct OP_OpenWrite_stack_vars { | |
| 66827 | + int nField; | |
| 66828 | + KeyInfo *pKeyInfo; | |
| 66829 | + int p2; | |
| 66830 | + int iDb; | |
| 66831 | + int wrFlag; | |
| 66832 | + Btree *pX; | |
| 66833 | + VdbeCursor *pCur; | |
| 66834 | + Db *pDb; | |
| 66835 | + } az; | |
| 66836 | + struct OP_OpenEphemeral_stack_vars { | |
| 66837 | + VdbeCursor *pCx; | |
| 66838 | + KeyInfo *pKeyInfo; | |
| 66839 | + } ba; | |
| 66840 | + struct OP_SorterOpen_stack_vars { | |
| 66841 | + VdbeCursor *pCx; | |
| 66842 | + } bb; | |
| 66843 | + struct OP_OpenPseudo_stack_vars { | |
| 66844 | + VdbeCursor *pCx; | |
| 66845 | + } bc; | |
| 66846 | + struct OP_SeekGt_stack_vars { | |
| 66847 | + int res; | |
| 66848 | + int oc; | |
| 66849 | + VdbeCursor *pC; | |
| 66850 | + UnpackedRecord r; | |
| 66851 | + int nField; | |
| 66852 | + i64 iKey; /* The rowid we are to seek to */ | |
| 66853 | + } bd; | |
| 66854 | + struct OP_Seek_stack_vars { | |
| 66855 | + VdbeCursor *pC; | |
| 66856 | + } be; | |
| 66857 | + struct OP_Found_stack_vars { | |
| 66858 | + int alreadyExists; | |
| 66859 | + int ii; | |
| 66860 | + VdbeCursor *pC; | |
| 66861 | + int res; | |
| 66862 | + char *pFree; | |
| 66863 | + UnpackedRecord *pIdxKey; | |
| 66864 | + UnpackedRecord r; | |
| 66865 | + char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; | |
| 66866 | + } bf; | |
| 66867 | + struct OP_NotExists_stack_vars { | |
| 66868 | + VdbeCursor *pC; | |
| 66869 | + BtCursor *pCrsr; | |
| 66870 | + int res; | |
| 66871 | + u64 iKey; | |
| 66872 | + } bg; | |
| 66873 | + struct OP_NewRowid_stack_vars { | |
| 66874 | + i64 v; /* The new rowid */ | |
| 66875 | + VdbeCursor *pC; /* Cursor of table to get the new rowid */ | |
| 66876 | + int res; /* Result of an sqlite3BtreeLast() */ | |
| 66877 | + int cnt; /* Counter to limit the number of searches */ | |
| 66878 | + Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ | |
| 66879 | + VdbeFrame *pFrame; /* Root frame of VDBE */ | |
| 66880 | + } bh; | |
| 66881 | + struct OP_InsertInt_stack_vars { | |
| 66882 | + Mem *pData; /* MEM cell holding data for the record to be inserted */ | |
| 66883 | + Mem *pKey; /* MEM cell holding key for the record */ | |
| 66884 | + i64 iKey; /* The integer ROWID or key for the record to be inserted */ | |
| 66885 | + VdbeCursor *pC; /* Cursor to table into which insert is written */ | |
| 66886 | + int nZero; /* Number of zero-bytes to append */ | |
| 66887 | + int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ | |
| 66888 | + const char *zDb; /* database name - used by the update hook */ | |
| 66889 | + const char *zTbl; /* Table name - used by the opdate hook */ | |
| 66890 | + int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ | |
| 66891 | + } bi; | |
| 66892 | + struct OP_Delete_stack_vars { | |
| 66893 | + i64 iKey; | |
| 66894 | + VdbeCursor *pC; | |
| 66895 | + } bj; | |
| 66896 | + struct OP_SorterCompare_stack_vars { | |
| 66897 | + VdbeCursor *pC; | |
| 66898 | + int res; | |
| 66899 | + int nIgnore; | |
| 66900 | + } bk; | |
| 66901 | + struct OP_SorterData_stack_vars { | |
| 66902 | + VdbeCursor *pC; | |
| 66903 | + } bl; | |
| 66904 | + struct OP_RowData_stack_vars { | |
| 66905 | + VdbeCursor *pC; | |
| 66906 | + BtCursor *pCrsr; | |
| 66907 | + u32 n; | |
| 66908 | + i64 n64; | |
| 66909 | + } bm; | |
| 66910 | + struct OP_Rowid_stack_vars { | |
| 66911 | + VdbeCursor *pC; | |
| 66912 | + i64 v; | |
| 66913 | + sqlite3_vtab *pVtab; | |
| 66914 | + const sqlite3_module *pModule; | |
| 66915 | + } bn; | |
| 66916 | + struct OP_NullRow_stack_vars { | |
| 66917 | + VdbeCursor *pC; | |
| 66918 | + } bo; | |
| 66919 | + struct OP_Last_stack_vars { | |
| 66920 | + VdbeCursor *pC; | |
| 66921 | + BtCursor *pCrsr; | |
| 66922 | + int res; | |
| 66923 | + } bp; | |
| 66924 | + struct OP_Rewind_stack_vars { | |
| 66925 | + VdbeCursor *pC; | |
| 66926 | + BtCursor *pCrsr; | |
| 66927 | + int res; | |
| 66928 | + } bq; | |
| 66929 | + struct OP_SorterNext_stack_vars { | |
| 66930 | + VdbeCursor *pC; | |
| 66931 | + int res; | |
| 66932 | + } br; | |
| 66933 | + struct OP_IdxInsert_stack_vars { | |
| 66934 | + VdbeCursor *pC; | |
| 66935 | + BtCursor *pCrsr; | |
| 66936 | + int nKey; | |
| 66937 | + const char *zKey; | |
| 66938 | + } bs; | |
| 66939 | + struct OP_IdxDelete_stack_vars { | |
| 66940 | + VdbeCursor *pC; | |
| 66941 | + BtCursor *pCrsr; | |
| 66942 | + int res; | |
| 66943 | + UnpackedRecord r; | |
| 66944 | + } bt; | |
| 66945 | + struct OP_IdxRowid_stack_vars { | |
| 66946 | + BtCursor *pCrsr; | |
| 66947 | + VdbeCursor *pC; | |
| 66948 | + i64 rowid; | |
| 66949 | + } bu; | |
| 66950 | + struct OP_IdxGE_stack_vars { | |
| 66951 | + VdbeCursor *pC; | |
| 66952 | + int res; | |
| 66953 | + UnpackedRecord r; | |
| 66954 | + } bv; | |
| 66955 | + struct OP_Destroy_stack_vars { | |
| 66956 | + int iMoved; | |
| 66957 | + int iCnt; | |
| 66958 | + Vdbe *pVdbe; | |
| 66959 | + int iDb; | |
| 66960 | + } bw; | |
| 66961 | + struct OP_Clear_stack_vars { | |
| 66962 | + int nChange; | |
| 66963 | + } bx; | |
| 66964 | + struct OP_CreateTable_stack_vars { | |
| 66965 | + int pgno; | |
| 66966 | + int flags; | |
| 66967 | + Db *pDb; | |
| 66968 | + } by; | |
| 66969 | + struct OP_ParseSchema_stack_vars { | |
| 66970 | + int iDb; | |
| 66971 | + const char *zMaster; | |
| 66972 | + char *zSql; | |
| 66973 | + InitData initData; | |
| 66974 | + } bz; | |
| 66975 | + struct OP_IntegrityCk_stack_vars { | |
| 66976 | + int nRoot; /* Number of tables to check. (Number of root pages.) */ | |
| 66977 | + int *aRoot; /* Array of rootpage numbers for tables to be checked */ | |
| 66978 | + int j; /* Loop counter */ | |
| 66979 | + int nErr; /* Number of errors reported */ | |
| 66980 | + char *z; /* Text of the error report */ | |
| 66981 | + Mem *pnErr; /* Register keeping track of errors remaining */ | |
| 66982 | + } ca; | |
| 66983 | + struct OP_RowSetRead_stack_vars { | |
| 66984 | + i64 val; | |
| 66985 | + } cb; | |
| 66986 | + struct OP_RowSetTest_stack_vars { | |
| 66987 | + int iSet; | |
| 66988 | + int exists; | |
| 66989 | + } cc; | |
| 66990 | + struct OP_Program_stack_vars { | |
| 66991 | + int nMem; /* Number of memory registers for sub-program */ | |
| 66992 | + int nByte; /* Bytes of runtime space required for sub-program */ | |
| 66993 | + Mem *pRt; /* Register to allocate runtime space */ | |
| 66994 | + Mem *pMem; /* Used to iterate through memory cells */ | |
| 66995 | + Mem *pEnd; /* Last memory cell in new array */ | |
| 66996 | + VdbeFrame *pFrame; /* New vdbe frame to execute in */ | |
| 66997 | + SubProgram *pProgram; /* Sub-program to execute */ | |
| 66998 | + void *t; /* Token identifying trigger */ | |
| 66999 | + } cd; | |
| 67000 | + struct OP_Param_stack_vars { | |
| 67001 | + VdbeFrame *pFrame; | |
| 67002 | + Mem *pIn; | |
| 67003 | + } ce; | |
| 67004 | + struct OP_MemMax_stack_vars { | |
| 67005 | + Mem *pIn1; | |
| 67006 | + VdbeFrame *pFrame; | |
| 67007 | + } cf; | |
| 67008 | + struct OP_AggStep_stack_vars { | |
| 67009 | + int n; | |
| 67010 | + int i; | |
| 67011 | + Mem *pMem; | |
| 67012 | + Mem *pRec; | |
| 67013 | + sqlite3_context ctx; | |
| 67014 | + sqlite3_value **apVal; | |
| 67015 | + } cg; | |
| 67016 | + struct OP_AggFinal_stack_vars { | |
| 67017 | + Mem *pMem; | |
| 67018 | + } ch; | |
| 67019 | + struct OP_Checkpoint_stack_vars { | |
| 67020 | + int i; /* Loop counter */ | |
| 67021 | + int aRes[3]; /* Results */ | |
| 67022 | + Mem *pMem; /* Write results here */ | |
| 67023 | + } ci; | |
| 67024 | + struct OP_JournalMode_stack_vars { | |
| 67025 | + Btree *pBt; /* Btree to change journal mode of */ | |
| 67026 | + Pager *pPager; /* Pager associated with pBt */ | |
| 67027 | + int eNew; /* New journal mode */ | |
| 67028 | + int eOld; /* The old journal mode */ | |
| 67029 | +#ifndef SQLITE_OMIT_WAL | |
| 67030 | + const char *zFilename; /* Name of database file for pPager */ | |
| 67031 | +#endif | |
| 67032 | + } cj; | |
| 67033 | + struct OP_IncrVacuum_stack_vars { | |
| 67034 | + Btree *pBt; | |
| 67035 | + } ck; | |
| 67036 | + struct OP_VBegin_stack_vars { | |
| 67037 | + VTable *pVTab; | |
| 67038 | + } cl; | |
| 67039 | + struct OP_VOpen_stack_vars { | |
| 67040 | + VdbeCursor *pCur; | |
| 67041 | + sqlite3_vtab_cursor *pVtabCursor; | |
| 67042 | + sqlite3_vtab *pVtab; | |
| 67043 | + sqlite3_module *pModule; | |
| 67044 | + } cm; | |
| 67045 | + struct OP_VFilter_stack_vars { | |
| 67046 | + int nArg; | |
| 67047 | + int iQuery; | |
| 67048 | + const sqlite3_module *pModule; | |
| 67049 | + Mem *pQuery; | |
| 67050 | + Mem *pArgc; | |
| 67051 | + sqlite3_vtab_cursor *pVtabCursor; | |
| 67052 | + sqlite3_vtab *pVtab; | |
| 67053 | + VdbeCursor *pCur; | |
| 67054 | + int res; | |
| 67055 | + int i; | |
| 67056 | + Mem **apArg; | |
| 67057 | + } cn; | |
| 67058 | + struct OP_VColumn_stack_vars { | |
| 67059 | + sqlite3_vtab *pVtab; | |
| 67060 | + const sqlite3_module *pModule; | |
| 67061 | + Mem *pDest; | |
| 67062 | + sqlite3_context sContext; | |
| 67063 | + } co; | |
| 67064 | + struct OP_VNext_stack_vars { | |
| 67065 | + sqlite3_vtab *pVtab; | |
| 67066 | + const sqlite3_module *pModule; | |
| 67067 | + int res; | |
| 67068 | + VdbeCursor *pCur; | |
| 67069 | + } cp; | |
| 67070 | + struct OP_VRename_stack_vars { | |
| 67071 | + sqlite3_vtab *pVtab; | |
| 67072 | + Mem *pName; | |
| 67073 | + } cq; | |
| 67074 | + struct OP_VUpdate_stack_vars { | |
| 67075 | + sqlite3_vtab *pVtab; | |
| 67076 | + sqlite3_module *pModule; | |
| 67077 | + int nArg; | |
| 67078 | + int i; | |
| 67079 | + sqlite_int64 rowid; | |
| 67080 | + Mem **apArg; | |
| 67081 | + Mem *pX; | |
| 67082 | + } cr; | |
| 67083 | + struct OP_Trace_stack_vars { | |
| 67084 | + char *zTrace; | |
| 67085 | + char *z; | |
| 67086 | + } cs; | |
| 67087 | + } u; | |
| 67088 | + /* End automatically generated code | |
| 67089 | + ********************************************************************/ | |
| 66875 | 67090 | |
| 66876 | 67091 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 66877 | 67092 | sqlite3VdbeEnter(p); |
| 66878 | 67093 | if( p->rc==SQLITE_NOMEM ){ |
| 66879 | 67094 | /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| @@ -67115,18 +67330,20 @@ | ||
| 67115 | 67330 | /* Opcode: Yield P1 * * * * |
| 67116 | 67331 | ** |
| 67117 | 67332 | ** Swap the program counter with the value in register P1. |
| 67118 | 67333 | */ |
| 67119 | 67334 | case OP_Yield: { /* in1 */ |
| 67335 | +#if 0 /* local variables moved into u.aa */ | |
| 67120 | 67336 | int pcDest; |
| 67337 | +#endif /* local variables moved into u.aa */ | |
| 67121 | 67338 | pIn1 = &aMem[pOp->p1]; |
| 67122 | 67339 | assert( (pIn1->flags & MEM_Dyn)==0 ); |
| 67123 | 67340 | pIn1->flags = MEM_Int; |
| 67124 | - pcDest = (int)pIn1->u.i; | |
| 67341 | + u.aa.pcDest = (int)pIn1->u.i; | |
| 67125 | 67342 | pIn1->u.i = pc; |
| 67126 | 67343 | REGISTER_TRACE(pOp->p1, pIn1); |
| 67127 | - pc = pcDest; | |
| 67344 | + pc = u.aa.pcDest; | |
| 67128 | 67345 | break; |
| 67129 | 67346 | } |
| 67130 | 67347 | |
| 67131 | 67348 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 67132 | 67349 | ** Synopsis: if r[P3] null then halt |
| @@ -67171,12 +67388,14 @@ | ||
| 67171 | 67388 | ** There is an implied "Halt 0 0 0" instruction inserted at the very end of |
| 67172 | 67389 | ** every program. So a jump past the last instruction of the program |
| 67173 | 67390 | ** is the same as executing Halt. |
| 67174 | 67391 | */ |
| 67175 | 67392 | case OP_Halt: { |
| 67393 | +#if 0 /* local variables moved into u.ab */ | |
| 67176 | 67394 | const char *zType; |
| 67177 | 67395 | const char *zLogFmt; |
| 67396 | +#endif /* local variables moved into u.ab */ | |
| 67178 | 67397 | |
| 67179 | 67398 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 67180 | 67399 | /* Halt the sub-program. Return control to the parent frame. */ |
| 67181 | 67400 | VdbeFrame *pFrame = p->pFrame; |
| 67182 | 67401 | p->pFrame = pFrame->pParent; |
| @@ -67183,11 +67402,11 @@ | ||
| 67183 | 67402 | p->nFrame--; |
| 67184 | 67403 | sqlite3VdbeSetChanges(db, p->nChange); |
| 67185 | 67404 | pc = sqlite3VdbeFrameRestore(pFrame); |
| 67186 | 67405 | lastRowid = db->lastRowid; |
| 67187 | 67406 | if( pOp->p2==OE_Ignore ){ |
| 67188 | - /* Instruction pc is the OP_Program that invoked the sub-program | |
| 67407 | + /* Instruction pc is the OP_Program that invoked the sub-program | |
| 67189 | 67408 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 67190 | 67409 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 67191 | 67410 | ** an IGNORE exception. In this case jump to the address specified |
| 67192 | 67411 | ** as the p2 of the calling OP_Program. */ |
| 67193 | 67412 | pc = p->aOp[pc].p2-1; |
| @@ -67206,25 +67425,25 @@ | ||
| 67206 | 67425 | assert( pOp->p5>=1 && pOp->p5<=4 ); |
| 67207 | 67426 | testcase( pOp->p5==1 ); |
| 67208 | 67427 | testcase( pOp->p5==2 ); |
| 67209 | 67428 | testcase( pOp->p5==3 ); |
| 67210 | 67429 | testcase( pOp->p5==4 ); |
| 67211 | - zType = azType[pOp->p5-1]; | |
| 67430 | + u.ab.zType = azType[pOp->p5-1]; | |
| 67212 | 67431 | }else{ |
| 67213 | - zType = 0; | |
| 67432 | + u.ab.zType = 0; | |
| 67214 | 67433 | } |
| 67215 | - assert( zType!=0 || pOp->p4.z!=0 ); | |
| 67216 | - zLogFmt = "abort at %d in [%s]: %s"; | |
| 67217 | - if( zType && pOp->p4.z ){ | |
| 67218 | - sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s", | |
| 67219 | - zType, pOp->p4.z); | |
| 67434 | + assert( u.ab.zType!=0 || pOp->p4.z!=0 ); | |
| 67435 | + u.ab.zLogFmt = "abort at %d in [%s]: %s"; | |
| 67436 | + if( u.ab.zType && pOp->p4.z ){ | |
| 67437 | + sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s", | |
| 67438 | + u.ab.zType, pOp->p4.z); | |
| 67220 | 67439 | }else if( pOp->p4.z ){ |
| 67221 | 67440 | sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); |
| 67222 | 67441 | }else{ |
| 67223 | - sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); | |
| 67442 | + sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType); | |
| 67224 | 67443 | } |
| 67225 | - sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg); | |
| 67444 | + sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg); | |
| 67226 | 67445 | } |
| 67227 | 67446 | rc = sqlite3VdbeHalt(p); |
| 67228 | 67447 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 67229 | 67448 | if( rc==SQLITE_BUSY ){ |
| 67230 | 67449 | p->rc = rc = SQLITE_BUSY; |
| @@ -67334,21 +67553,23 @@ | ||
| 67334 | 67553 | ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 67335 | 67554 | ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 67336 | 67555 | ** OP_Ne or OP_Eq. |
| 67337 | 67556 | */ |
| 67338 | 67557 | case OP_Null: { /* out2-prerelease */ |
| 67558 | +#if 0 /* local variables moved into u.ac */ | |
| 67339 | 67559 | int cnt; |
| 67340 | 67560 | u16 nullFlag; |
| 67341 | - cnt = pOp->p3-pOp->p2; | |
| 67561 | +#endif /* local variables moved into u.ac */ | |
| 67562 | + u.ac.cnt = pOp->p3-pOp->p2; | |
| 67342 | 67563 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 67343 | - pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; | |
| 67344 | - while( cnt>0 ){ | |
| 67564 | + pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; | |
| 67565 | + while( u.ac.cnt>0 ){ | |
| 67345 | 67566 | pOut++; |
| 67346 | 67567 | memAboutToChange(p, pOut); |
| 67347 | 67568 | VdbeMemRelease(pOut); |
| 67348 | - pOut->flags = nullFlag; | |
| 67349 | - cnt--; | |
| 67569 | + pOut->flags = u.ac.nullFlag; | |
| 67570 | + u.ac.cnt--; | |
| 67350 | 67571 | } |
| 67351 | 67572 | break; |
| 67352 | 67573 | } |
| 67353 | 67574 | |
| 67354 | 67575 | |
| @@ -67373,19 +67594,21 @@ | ||
| 67373 | 67594 | ** |
| 67374 | 67595 | ** If the parameter is named, then its name appears in P4 and P3==1. |
| 67375 | 67596 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 67376 | 67597 | */ |
| 67377 | 67598 | case OP_Variable: { /* out2-prerelease */ |
| 67599 | +#if 0 /* local variables moved into u.ad */ | |
| 67378 | 67600 | Mem *pVar; /* Value being transferred */ |
| 67601 | +#endif /* local variables moved into u.ad */ | |
| 67379 | 67602 | |
| 67380 | 67603 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 67381 | 67604 | assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 67382 | - pVar = &p->aVar[pOp->p1 - 1]; | |
| 67383 | - if( sqlite3VdbeMemTooBig(pVar) ){ | |
| 67605 | + u.ad.pVar = &p->aVar[pOp->p1 - 1]; | |
| 67606 | + if( sqlite3VdbeMemTooBig(u.ad.pVar) ){ | |
| 67384 | 67607 | goto too_big; |
| 67385 | 67608 | } |
| 67386 | - sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); | |
| 67609 | + sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static); | |
| 67387 | 67610 | UPDATE_MAX_BLOBSIZE(pOut); |
| 67388 | 67611 | break; |
| 67389 | 67612 | } |
| 67390 | 67613 | |
| 67391 | 67614 | /* Opcode: Move P1 P2 P3 * * |
| @@ -67395,67 +67618,71 @@ | ||
| 67395 | 67618 | ** registers P2..P2+P3. Registers P1..P1+P3 are |
| 67396 | 67619 | ** left holding a NULL. It is an error for register ranges |
| 67397 | 67620 | ** P1..P1+P3 and P2..P2+P3 to overlap. |
| 67398 | 67621 | */ |
| 67399 | 67622 | case OP_Move: { |
| 67623 | +#if 0 /* local variables moved into u.ae */ | |
| 67400 | 67624 | char *zMalloc; /* Holding variable for allocated memory */ |
| 67401 | 67625 | int n; /* Number of registers left to copy */ |
| 67402 | 67626 | int p1; /* Register to copy from */ |
| 67403 | 67627 | int p2; /* Register to copy to */ |
| 67404 | - | |
| 67405 | - n = pOp->p3; | |
| 67406 | - p1 = pOp->p1; | |
| 67407 | - p2 = pOp->p2; | |
| 67408 | - assert( n>=0 && p1>0 && p2>0 ); | |
| 67409 | - assert( p1+n<=p2 || p2+n<=p1 ); | |
| 67410 | - | |
| 67411 | - pIn1 = &aMem[p1]; | |
| 67412 | - pOut = &aMem[p2]; | |
| 67628 | +#endif /* local variables moved into u.ae */ | |
| 67629 | + | |
| 67630 | + u.ae.n = pOp->p3; | |
| 67631 | + u.ae.p1 = pOp->p1; | |
| 67632 | + u.ae.p2 = pOp->p2; | |
| 67633 | + assert( u.ae.n>=0 && u.ae.p1>0 && u.ae.p2>0 ); | |
| 67634 | + assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 ); | |
| 67635 | + | |
| 67636 | + pIn1 = &aMem[u.ae.p1]; | |
| 67637 | + pOut = &aMem[u.ae.p2]; | |
| 67413 | 67638 | do{ |
| 67414 | 67639 | assert( pOut<=&aMem[(p->nMem-p->nCursor)] ); |
| 67415 | 67640 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 67416 | 67641 | assert( memIsValid(pIn1) ); |
| 67417 | 67642 | memAboutToChange(p, pOut); |
| 67418 | - zMalloc = pOut->zMalloc; | |
| 67643 | + u.ae.zMalloc = pOut->zMalloc; | |
| 67419 | 67644 | pOut->zMalloc = 0; |
| 67420 | 67645 | sqlite3VdbeMemMove(pOut, pIn1); |
| 67421 | 67646 | #ifdef SQLITE_DEBUG |
| 67422 | - if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){ | |
| 67423 | - pOut->pScopyFrom += p1 - pOp->p2; | |
| 67647 | + if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){ | |
| 67648 | + pOut->pScopyFrom += u.ae.p1 - pOp->p2; | |
| 67424 | 67649 | } |
| 67425 | 67650 | #endif |
| 67426 | - pIn1->zMalloc = zMalloc; | |
| 67427 | - REGISTER_TRACE(p2++, pOut); | |
| 67651 | + pIn1->zMalloc = u.ae.zMalloc; | |
| 67652 | + REGISTER_TRACE(u.ae.p2++, pOut); | |
| 67428 | 67653 | pIn1++; |
| 67429 | 67654 | pOut++; |
| 67430 | - }while( n-- ); | |
| 67655 | + }while( u.ae.n-- ); | |
| 67431 | 67656 | break; |
| 67432 | 67657 | } |
| 67433 | 67658 | |
| 67434 | 67659 | /* Opcode: Copy P1 P2 P3 * * |
| 67435 | -** Synopsis: r[P2@P3+1]=r[P1@P3+1] | |
| 67660 | +** Synopsis: r[P2@P3]=r[P1@P3] | |
| 67436 | 67661 | ** |
| 67437 | 67662 | ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3. |
| 67438 | 67663 | ** |
| 67439 | 67664 | ** This instruction makes a deep copy of the value. A duplicate |
| 67440 | 67665 | ** is made of any string or blob constant. See also OP_SCopy. |
| 67441 | 67666 | */ |
| 67442 | 67667 | case OP_Copy: { |
| 67668 | +#if 0 /* local variables moved into u.af */ | |
| 67443 | 67669 | int n; |
| 67670 | +#endif /* local variables moved into u.af */ | |
| 67444 | 67671 | |
| 67445 | - n = pOp->p3; | |
| 67672 | + u.af.n = pOp->p3; | |
| 67446 | 67673 | pIn1 = &aMem[pOp->p1]; |
| 67447 | 67674 | pOut = &aMem[pOp->p2]; |
| 67448 | 67675 | assert( pOut!=pIn1 ); |
| 67449 | 67676 | while( 1 ){ |
| 67450 | 67677 | sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); |
| 67451 | 67678 | Deephemeralize(pOut); |
| 67452 | 67679 | #ifdef SQLITE_DEBUG |
| 67453 | 67680 | pOut->pScopyFrom = 0; |
| 67454 | 67681 | #endif |
| 67455 | - REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut); | |
| 67456 | - if( (n--)==0 ) break; | |
| 67682 | + REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut); | |
| 67683 | + if( (u.af.n--)==0 ) break; | |
| 67457 | 67684 | pOut++; |
| 67458 | 67685 | pIn1++; |
| 67459 | 67686 | } |
| 67460 | 67687 | break; |
| 67461 | 67688 | } |
| @@ -67492,12 +67719,14 @@ | ||
| 67492 | 67719 | ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt |
| 67493 | 67720 | ** structure to provide access to the top P1 values as the result |
| 67494 | 67721 | ** row. |
| 67495 | 67722 | */ |
| 67496 | 67723 | case OP_ResultRow: { |
| 67724 | +#if 0 /* local variables moved into u.ag */ | |
| 67497 | 67725 | Mem *pMem; |
| 67498 | 67726 | int i; |
| 67727 | +#endif /* local variables moved into u.ag */ | |
| 67499 | 67728 | assert( p->nResColumn==pOp->p2 ); |
| 67500 | 67729 | assert( pOp->p1>0 ); |
| 67501 | 67730 | assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 ); |
| 67502 | 67731 | |
| 67503 | 67732 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| @@ -67519,12 +67748,12 @@ | ||
| 67519 | 67748 | assert( db->flags&SQLITE_CountRows ); |
| 67520 | 67749 | assert( p->usesStmtJournal ); |
| 67521 | 67750 | break; |
| 67522 | 67751 | } |
| 67523 | 67752 | |
| 67524 | - /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then | |
| 67525 | - ** DML statements invoke this opcode to return the number of rows | |
| 67753 | + /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then | |
| 67754 | + ** DML statements invoke this opcode to return the number of rows | |
| 67526 | 67755 | ** modified to the user. This is the only way that a VM that |
| 67527 | 67756 | ** opens a statement transaction may invoke this opcode. |
| 67528 | 67757 | ** |
| 67529 | 67758 | ** In case this is such a statement, close any statement transaction |
| 67530 | 67759 | ** opened by this VM before returning control to the user. This is to |
| @@ -67547,19 +67776,19 @@ | ||
| 67547 | 67776 | |
| 67548 | 67777 | /* Make sure the results of the current row are \000 terminated |
| 67549 | 67778 | ** and have an assigned type. The results are de-ephemeralized as |
| 67550 | 67779 | ** a side effect. |
| 67551 | 67780 | */ |
| 67552 | - pMem = p->pResultSet = &aMem[pOp->p1]; | |
| 67553 | - for(i=0; i<pOp->p2; i++){ | |
| 67554 | - assert( memIsValid(&pMem[i]) ); | |
| 67555 | - Deephemeralize(&pMem[i]); | |
| 67556 | - assert( (pMem[i].flags & MEM_Ephem)==0 | |
| 67557 | - || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 ); | |
| 67558 | - sqlite3VdbeMemNulTerminate(&pMem[i]); | |
| 67559 | - sqlite3VdbeMemStoreType(&pMem[i]); | |
| 67560 | - REGISTER_TRACE(pOp->p1+i, &pMem[i]); | |
| 67781 | + u.ag.pMem = p->pResultSet = &aMem[pOp->p1]; | |
| 67782 | + for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){ | |
| 67783 | + assert( memIsValid(&u.ag.pMem[u.ag.i]) ); | |
| 67784 | + Deephemeralize(&u.ag.pMem[u.ag.i]); | |
| 67785 | + assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0 | |
| 67786 | + || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 ); | |
| 67787 | + sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]); | |
| 67788 | + sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]); | |
| 67789 | + REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]); | |
| 67561 | 67790 | } |
| 67562 | 67791 | if( db->mallocFailed ) goto no_mem; |
| 67563 | 67792 | |
| 67564 | 67793 | /* Return SQLITE_ROW |
| 67565 | 67794 | */ |
| @@ -67580,11 +67809,13 @@ | ||
| 67580 | 67809 | ** It is illegal for P1 and P3 to be the same register. Sometimes, |
| 67581 | 67810 | ** if P3 is the same register as P2, the implementation is able |
| 67582 | 67811 | ** to avoid a memcpy(). |
| 67583 | 67812 | */ |
| 67584 | 67813 | case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */ |
| 67814 | +#if 0 /* local variables moved into u.ah */ | |
| 67585 | 67815 | i64 nByte; |
| 67816 | +#endif /* local variables moved into u.ah */ | |
| 67586 | 67817 | |
| 67587 | 67818 | pIn1 = &aMem[pOp->p1]; |
| 67588 | 67819 | pIn2 = &aMem[pOp->p2]; |
| 67589 | 67820 | pOut = &aMem[pOp->p3]; |
| 67590 | 67821 | assert( pIn1!=pOut ); |
| @@ -67593,26 +67824,26 @@ | ||
| 67593 | 67824 | break; |
| 67594 | 67825 | } |
| 67595 | 67826 | if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem; |
| 67596 | 67827 | Stringify(pIn1, encoding); |
| 67597 | 67828 | Stringify(pIn2, encoding); |
| 67598 | - nByte = pIn1->n + pIn2->n; | |
| 67599 | - if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 67829 | + u.ah.nByte = pIn1->n + pIn2->n; | |
| 67830 | + if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 67600 | 67831 | goto too_big; |
| 67601 | 67832 | } |
| 67602 | 67833 | MemSetTypeFlag(pOut, MEM_Str); |
| 67603 | - if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){ | |
| 67834 | + if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){ | |
| 67604 | 67835 | goto no_mem; |
| 67605 | 67836 | } |
| 67606 | 67837 | if( pOut!=pIn2 ){ |
| 67607 | 67838 | memcpy(pOut->z, pIn2->z, pIn2->n); |
| 67608 | 67839 | } |
| 67609 | 67840 | memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n); |
| 67610 | - pOut->z[nByte]=0; | |
| 67611 | - pOut->z[nByte+1] = 0; | |
| 67841 | + pOut->z[u.ah.nByte]=0; | |
| 67842 | + pOut->z[u.ah.nByte+1] = 0; | |
| 67612 | 67843 | pOut->flags |= MEM_Term; |
| 67613 | - pOut->n = (int)nByte; | |
| 67844 | + pOut->n = (int)u.ah.nByte; | |
| 67614 | 67845 | pOut->enc = encoding; |
| 67615 | 67846 | UPDATE_MAX_BLOBSIZE(pOut); |
| 67616 | 67847 | break; |
| 67617 | 67848 | } |
| 67618 | 67849 | |
| @@ -67657,81 +67888,83 @@ | ||
| 67657 | 67888 | case OP_Add: /* same as TK_PLUS, in1, in2, out3 */ |
| 67658 | 67889 | case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */ |
| 67659 | 67890 | case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */ |
| 67660 | 67891 | case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */ |
| 67661 | 67892 | case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ |
| 67893 | +#if 0 /* local variables moved into u.ai */ | |
| 67662 | 67894 | char bIntint; /* Started out as two integer operands */ |
| 67663 | 67895 | int flags; /* Combined MEM_* flags from both inputs */ |
| 67664 | 67896 | i64 iA; /* Integer value of left operand */ |
| 67665 | 67897 | i64 iB; /* Integer value of right operand */ |
| 67666 | 67898 | double rA; /* Real value of left operand */ |
| 67667 | 67899 | double rB; /* Real value of right operand */ |
| 67900 | +#endif /* local variables moved into u.ai */ | |
| 67668 | 67901 | |
| 67669 | 67902 | pIn1 = &aMem[pOp->p1]; |
| 67670 | 67903 | applyNumericAffinity(pIn1); |
| 67671 | 67904 | pIn2 = &aMem[pOp->p2]; |
| 67672 | 67905 | applyNumericAffinity(pIn2); |
| 67673 | 67906 | pOut = &aMem[pOp->p3]; |
| 67674 | - flags = pIn1->flags | pIn2->flags; | |
| 67675 | - if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; | |
| 67907 | + u.ai.flags = pIn1->flags | pIn2->flags; | |
| 67908 | + if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; | |
| 67676 | 67909 | if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ |
| 67677 | - iA = pIn1->u.i; | |
| 67678 | - iB = pIn2->u.i; | |
| 67679 | - bIntint = 1; | |
| 67910 | + u.ai.iA = pIn1->u.i; | |
| 67911 | + u.ai.iB = pIn2->u.i; | |
| 67912 | + u.ai.bIntint = 1; | |
| 67680 | 67913 | switch( pOp->opcode ){ |
| 67681 | - case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break; | |
| 67682 | - case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break; | |
| 67683 | - case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break; | |
| 67914 | + case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; | |
| 67915 | + case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; | |
| 67916 | + case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; | |
| 67684 | 67917 | case OP_Divide: { |
| 67685 | - if( iA==0 ) goto arithmetic_result_is_null; | |
| 67686 | - if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math; | |
| 67687 | - iB /= iA; | |
| 67918 | + if( u.ai.iA==0 ) goto arithmetic_result_is_null; | |
| 67919 | + if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math; | |
| 67920 | + u.ai.iB /= u.ai.iA; | |
| 67688 | 67921 | break; |
| 67689 | 67922 | } |
| 67690 | 67923 | default: { |
| 67691 | - if( iA==0 ) goto arithmetic_result_is_null; | |
| 67692 | - if( iA==-1 ) iA = 1; | |
| 67693 | - iB %= iA; | |
| 67924 | + if( u.ai.iA==0 ) goto arithmetic_result_is_null; | |
| 67925 | + if( u.ai.iA==-1 ) u.ai.iA = 1; | |
| 67926 | + u.ai.iB %= u.ai.iA; | |
| 67694 | 67927 | break; |
| 67695 | 67928 | } |
| 67696 | 67929 | } |
| 67697 | - pOut->u.i = iB; | |
| 67930 | + pOut->u.i = u.ai.iB; | |
| 67698 | 67931 | MemSetTypeFlag(pOut, MEM_Int); |
| 67699 | 67932 | }else{ |
| 67700 | - bIntint = 0; | |
| 67933 | + u.ai.bIntint = 0; | |
| 67701 | 67934 | fp_math: |
| 67702 | - rA = sqlite3VdbeRealValue(pIn1); | |
| 67703 | - rB = sqlite3VdbeRealValue(pIn2); | |
| 67935 | + u.ai.rA = sqlite3VdbeRealValue(pIn1); | |
| 67936 | + u.ai.rB = sqlite3VdbeRealValue(pIn2); | |
| 67704 | 67937 | switch( pOp->opcode ){ |
| 67705 | - case OP_Add: rB += rA; break; | |
| 67706 | - case OP_Subtract: rB -= rA; break; | |
| 67707 | - case OP_Multiply: rB *= rA; break; | |
| 67938 | + case OP_Add: u.ai.rB += u.ai.rA; break; | |
| 67939 | + case OP_Subtract: u.ai.rB -= u.ai.rA; break; | |
| 67940 | + case OP_Multiply: u.ai.rB *= u.ai.rA; break; | |
| 67708 | 67941 | case OP_Divide: { |
| 67709 | 67942 | /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ |
| 67710 | - if( rA==(double)0 ) goto arithmetic_result_is_null; | |
| 67711 | - rB /= rA; | |
| 67943 | + if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null; | |
| 67944 | + u.ai.rB /= u.ai.rA; | |
| 67712 | 67945 | break; |
| 67713 | 67946 | } |
| 67714 | 67947 | default: { |
| 67715 | - iA = (i64)rA; | |
| 67716 | - iB = (i64)rB; | |
| 67717 | - if( iA==0 ) goto arithmetic_result_is_null; | |
| 67718 | - if( iA==-1 ) iA = 1; | |
| 67719 | - rB = (double)(iB % iA); | |
| 67948 | + u.ai.iA = (i64)u.ai.rA; | |
| 67949 | + u.ai.iB = (i64)u.ai.rB; | |
| 67950 | + if( u.ai.iA==0 ) goto arithmetic_result_is_null; | |
| 67951 | + if( u.ai.iA==-1 ) u.ai.iA = 1; | |
| 67952 | + u.ai.rB = (double)(u.ai.iB % u.ai.iA); | |
| 67720 | 67953 | break; |
| 67721 | 67954 | } |
| 67722 | 67955 | } |
| 67723 | 67956 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 67724 | - pOut->u.i = rB; | |
| 67957 | + pOut->u.i = u.ai.rB; | |
| 67725 | 67958 | MemSetTypeFlag(pOut, MEM_Int); |
| 67726 | 67959 | #else |
| 67727 | - if( sqlite3IsNaN(rB) ){ | |
| 67960 | + if( sqlite3IsNaN(u.ai.rB) ){ | |
| 67728 | 67961 | goto arithmetic_result_is_null; |
| 67729 | 67962 | } |
| 67730 | - pOut->r = rB; | |
| 67963 | + pOut->r = u.ai.rB; | |
| 67731 | 67964 | MemSetTypeFlag(pOut, MEM_Real); |
| 67732 | - if( (flags & MEM_Real)==0 && !bIntint ){ | |
| 67965 | + if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){ | |
| 67733 | 67966 | sqlite3VdbeIntegerAffinity(pOut); |
| 67734 | 67967 | } |
| 67735 | 67968 | #endif |
| 67736 | 67969 | } |
| 67737 | 67970 | break; |
| @@ -67780,83 +68013,85 @@ | ||
| 67780 | 68013 | ** invocation of this opcode. |
| 67781 | 68014 | ** |
| 67782 | 68015 | ** See also: AggStep and AggFinal |
| 67783 | 68016 | */ |
| 67784 | 68017 | case OP_Function: { |
| 68018 | +#if 0 /* local variables moved into u.aj */ | |
| 67785 | 68019 | int i; |
| 67786 | 68020 | Mem *pArg; |
| 67787 | 68021 | sqlite3_context ctx; |
| 67788 | 68022 | sqlite3_value **apVal; |
| 67789 | 68023 | int n; |
| 68024 | +#endif /* local variables moved into u.aj */ | |
| 67790 | 68025 | |
| 67791 | - n = pOp->p5; | |
| 67792 | - apVal = p->apArg; | |
| 67793 | - assert( apVal || n==0 ); | |
| 68026 | + u.aj.n = pOp->p5; | |
| 68027 | + u.aj.apVal = p->apArg; | |
| 68028 | + assert( u.aj.apVal || u.aj.n==0 ); | |
| 67794 | 68029 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 67795 | 68030 | pOut = &aMem[pOp->p3]; |
| 67796 | 68031 | memAboutToChange(p, pOut); |
| 67797 | 68032 | |
| 67798 | - assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) ); | |
| 67799 | - assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n ); | |
| 67800 | - pArg = &aMem[pOp->p2]; | |
| 67801 | - for(i=0; i<n; i++, pArg++){ | |
| 67802 | - assert( memIsValid(pArg) ); | |
| 67803 | - apVal[i] = pArg; | |
| 67804 | - Deephemeralize(pArg); | |
| 67805 | - sqlite3VdbeMemStoreType(pArg); | |
| 67806 | - REGISTER_TRACE(pOp->p2+i, pArg); | |
| 68033 | + assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) ); | |
| 68034 | + assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n ); | |
| 68035 | + u.aj.pArg = &aMem[pOp->p2]; | |
| 68036 | + for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){ | |
| 68037 | + assert( memIsValid(u.aj.pArg) ); | |
| 68038 | + u.aj.apVal[u.aj.i] = u.aj.pArg; | |
| 68039 | + Deephemeralize(u.aj.pArg); | |
| 68040 | + sqlite3VdbeMemStoreType(u.aj.pArg); | |
| 68041 | + REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg); | |
| 67807 | 68042 | } |
| 67808 | 68043 | |
| 67809 | 68044 | assert( pOp->p4type==P4_FUNCDEF ); |
| 67810 | - ctx.pFunc = pOp->p4.pFunc; | |
| 67811 | - ctx.iOp = pc; | |
| 67812 | - ctx.pVdbe = p; | |
| 68045 | + u.aj.ctx.pFunc = pOp->p4.pFunc; | |
| 68046 | + u.aj.ctx.iOp = pc; | |
| 68047 | + u.aj.ctx.pVdbe = p; | |
| 67813 | 68048 | |
| 67814 | 68049 | /* The output cell may already have a buffer allocated. Move |
| 67815 | - ** the pointer to ctx.s so in case the user-function can use | |
| 68050 | + ** the pointer to u.aj.ctx.s so in case the user-function can use | |
| 67816 | 68051 | ** the already allocated buffer instead of allocating a new one. |
| 67817 | 68052 | */ |
| 67818 | - memcpy(&ctx.s, pOut, sizeof(Mem)); | |
| 68053 | + memcpy(&u.aj.ctx.s, pOut, sizeof(Mem)); | |
| 67819 | 68054 | pOut->flags = MEM_Null; |
| 67820 | 68055 | pOut->xDel = 0; |
| 67821 | 68056 | pOut->zMalloc = 0; |
| 67822 | - MemSetTypeFlag(&ctx.s, MEM_Null); | |
| 68057 | + MemSetTypeFlag(&u.aj.ctx.s, MEM_Null); | |
| 67823 | 68058 | |
| 67824 | - ctx.fErrorOrAux = 0; | |
| 67825 | - if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ | |
| 68059 | + u.aj.ctx.fErrorOrAux = 0; | |
| 68060 | + if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ | |
| 67826 | 68061 | assert( pOp>aOp ); |
| 67827 | 68062 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 67828 | 68063 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 67829 | - ctx.pColl = pOp[-1].p4.pColl; | |
| 68064 | + u.aj.ctx.pColl = pOp[-1].p4.pColl; | |
| 67830 | 68065 | } |
| 67831 | 68066 | db->lastRowid = lastRowid; |
| 67832 | - (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ | |
| 68067 | + (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */ | |
| 67833 | 68068 | lastRowid = db->lastRowid; |
| 67834 | 68069 | |
| 67835 | 68070 | if( db->mallocFailed ){ |
| 67836 | 68071 | /* Even though a malloc() has failed, the implementation of the |
| 67837 | 68072 | ** user function may have called an sqlite3_result_XXX() function |
| 67838 | 68073 | ** to return a value. The following call releases any resources |
| 67839 | 68074 | ** associated with such a value. |
| 67840 | 68075 | */ |
| 67841 | - sqlite3VdbeMemRelease(&ctx.s); | |
| 68076 | + sqlite3VdbeMemRelease(&u.aj.ctx.s); | |
| 67842 | 68077 | goto no_mem; |
| 67843 | 68078 | } |
| 67844 | 68079 | |
| 67845 | 68080 | /* If the function returned an error, throw an exception */ |
| 67846 | - if( ctx.fErrorOrAux ){ | |
| 67847 | - if( ctx.isError ){ | |
| 67848 | - sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); | |
| 67849 | - rc = ctx.isError; | |
| 68081 | + if( u.aj.ctx.fErrorOrAux ){ | |
| 68082 | + if( u.aj.ctx.isError ){ | |
| 68083 | + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s)); | |
| 68084 | + rc = u.aj.ctx.isError; | |
| 67850 | 68085 | } |
| 67851 | 68086 | sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 67852 | 68087 | } |
| 67853 | 68088 | |
| 67854 | 68089 | /* Copy the result of the function into register P3 */ |
| 67855 | - sqlite3VdbeChangeEncoding(&ctx.s, encoding); | |
| 68090 | + sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding); | |
| 67856 | 68091 | assert( pOut->flags==MEM_Null ); |
| 67857 | - memcpy(pOut, &ctx.s, sizeof(Mem)); | |
| 68092 | + memcpy(pOut, &u.aj.ctx.s, sizeof(Mem)); | |
| 67858 | 68093 | if( sqlite3VdbeMemTooBig(pOut) ){ |
| 67859 | 68094 | goto too_big; |
| 67860 | 68095 | } |
| 67861 | 68096 | |
| 67862 | 68097 | #if 0 |
| @@ -67904,54 +68139,56 @@ | ||
| 67904 | 68139 | */ |
| 67905 | 68140 | case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */ |
| 67906 | 68141 | case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */ |
| 67907 | 68142 | case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */ |
| 67908 | 68143 | case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */ |
| 68144 | +#if 0 /* local variables moved into u.ak */ | |
| 67909 | 68145 | i64 iA; |
| 67910 | 68146 | u64 uA; |
| 67911 | 68147 | i64 iB; |
| 67912 | 68148 | u8 op; |
| 68149 | +#endif /* local variables moved into u.ak */ | |
| 67913 | 68150 | |
| 67914 | 68151 | pIn1 = &aMem[pOp->p1]; |
| 67915 | 68152 | pIn2 = &aMem[pOp->p2]; |
| 67916 | 68153 | pOut = &aMem[pOp->p3]; |
| 67917 | 68154 | if( (pIn1->flags | pIn2->flags) & MEM_Null ){ |
| 67918 | 68155 | sqlite3VdbeMemSetNull(pOut); |
| 67919 | 68156 | break; |
| 67920 | 68157 | } |
| 67921 | - iA = sqlite3VdbeIntValue(pIn2); | |
| 67922 | - iB = sqlite3VdbeIntValue(pIn1); | |
| 67923 | - op = pOp->opcode; | |
| 67924 | - if( op==OP_BitAnd ){ | |
| 67925 | - iA &= iB; | |
| 67926 | - }else if( op==OP_BitOr ){ | |
| 67927 | - iA |= iB; | |
| 67928 | - }else if( iB!=0 ){ | |
| 67929 | - assert( op==OP_ShiftRight || op==OP_ShiftLeft ); | |
| 68158 | + u.ak.iA = sqlite3VdbeIntValue(pIn2); | |
| 68159 | + u.ak.iB = sqlite3VdbeIntValue(pIn1); | |
| 68160 | + u.ak.op = pOp->opcode; | |
| 68161 | + if( u.ak.op==OP_BitAnd ){ | |
| 68162 | + u.ak.iA &= u.ak.iB; | |
| 68163 | + }else if( u.ak.op==OP_BitOr ){ | |
| 68164 | + u.ak.iA |= u.ak.iB; | |
| 68165 | + }else if( u.ak.iB!=0 ){ | |
| 68166 | + assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft ); | |
| 67930 | 68167 | |
| 67931 | 68168 | /* If shifting by a negative amount, shift in the other direction */ |
| 67932 | - if( iB<0 ){ | |
| 68169 | + if( u.ak.iB<0 ){ | |
| 67933 | 68170 | assert( OP_ShiftRight==OP_ShiftLeft+1 ); |
| 67934 | - op = 2*OP_ShiftLeft + 1 - op; | |
| 67935 | - iB = iB>(-64) ? -iB : 64; | |
| 68171 | + u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op; | |
| 68172 | + u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64; | |
| 67936 | 68173 | } |
| 67937 | 68174 | |
| 67938 | - if( iB>=64 ){ | |
| 67939 | - iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1; | |
| 67940 | - }else{ | |
| 67941 | - memcpy(&uA, &iA, sizeof(uA)); | |
| 67942 | - if( op==OP_ShiftLeft ){ | |
| 67943 | - uA <<= iB; | |
| 67944 | - }else{ | |
| 67945 | - uA >>= iB; | |
| 68175 | + if( u.ak.iB>=64 ){ | |
| 68176 | + u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1; | |
| 68177 | + }else{ | |
| 68178 | + memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA)); | |
| 68179 | + if( u.ak.op==OP_ShiftLeft ){ | |
| 68180 | + u.ak.uA <<= u.ak.iB; | |
| 68181 | + }else{ | |
| 68182 | + u.ak.uA >>= u.ak.iB; | |
| 67946 | 68183 | /* Sign-extend on a right shift of a negative number */ |
| 67947 | - if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB); | |
| 68184 | + if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB); | |
| 67948 | 68185 | } |
| 67949 | - memcpy(&iA, &uA, sizeof(iA)); | |
| 68186 | + memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA)); | |
| 67950 | 68187 | } |
| 67951 | 68188 | } |
| 67952 | - pOut->u.i = iA; | |
| 68189 | + pOut->u.i = u.ak.iA; | |
| 67953 | 68190 | MemSetTypeFlag(pOut, MEM_Int); |
| 67954 | 68191 | break; |
| 67955 | 68192 | } |
| 67956 | 68193 | |
| 67957 | 68194 | /* Opcode: AddImm P1 P2 * * * |
| @@ -68201,35 +68438,37 @@ | ||
| 68201 | 68438 | case OP_Ne: /* same as TK_NE, jump, in1, in3 */ |
| 68202 | 68439 | case OP_Lt: /* same as TK_LT, jump, in1, in3 */ |
| 68203 | 68440 | case OP_Le: /* same as TK_LE, jump, in1, in3 */ |
| 68204 | 68441 | case OP_Gt: /* same as TK_GT, jump, in1, in3 */ |
| 68205 | 68442 | case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ |
| 68443 | +#if 0 /* local variables moved into u.al */ | |
| 68206 | 68444 | int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 68207 | 68445 | char affinity; /* Affinity to use for comparison */ |
| 68208 | 68446 | u16 flags1; /* Copy of initial value of pIn1->flags */ |
| 68209 | 68447 | u16 flags3; /* Copy of initial value of pIn3->flags */ |
| 68448 | +#endif /* local variables moved into u.al */ | |
| 68210 | 68449 | |
| 68211 | 68450 | pIn1 = &aMem[pOp->p1]; |
| 68212 | 68451 | pIn3 = &aMem[pOp->p3]; |
| 68213 | - flags1 = pIn1->flags; | |
| 68214 | - flags3 = pIn3->flags; | |
| 68215 | - if( (flags1 | flags3)&MEM_Null ){ | |
| 68452 | + u.al.flags1 = pIn1->flags; | |
| 68453 | + u.al.flags3 = pIn3->flags; | |
| 68454 | + if( (u.al.flags1 | u.al.flags3)&MEM_Null ){ | |
| 68216 | 68455 | /* One or both operands are NULL */ |
| 68217 | 68456 | if( pOp->p5 & SQLITE_NULLEQ ){ |
| 68218 | 68457 | /* If SQLITE_NULLEQ is set (which will only happen if the operator is |
| 68219 | 68458 | ** OP_Eq or OP_Ne) then take the jump or not depending on whether |
| 68220 | 68459 | ** or not both operands are null. |
| 68221 | 68460 | */ |
| 68222 | 68461 | assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne ); |
| 68223 | - assert( (flags1 & MEM_Cleared)==0 ); | |
| 68224 | - if( (flags1&MEM_Null)!=0 | |
| 68225 | - && (flags3&MEM_Null)!=0 | |
| 68226 | - && (flags3&MEM_Cleared)==0 | |
| 68462 | + assert( (u.al.flags1 & MEM_Cleared)==0 ); | |
| 68463 | + if( (u.al.flags1&MEM_Null)!=0 | |
| 68464 | + && (u.al.flags3&MEM_Null)!=0 | |
| 68465 | + && (u.al.flags3&MEM_Cleared)==0 | |
| 68227 | 68466 | ){ |
| 68228 | - res = 0; /* Results are equal */ | |
| 68467 | + u.al.res = 0; /* Results are equal */ | |
| 68229 | 68468 | }else{ |
| 68230 | - res = 1; /* Results are not equal */ | |
| 68469 | + u.al.res = 1; /* Results are not equal */ | |
| 68231 | 68470 | } |
| 68232 | 68471 | }else{ |
| 68233 | 68472 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 68234 | 68473 | ** then the result is always NULL. |
| 68235 | 68474 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| @@ -68243,44 +68482,44 @@ | ||
| 68243 | 68482 | } |
| 68244 | 68483 | break; |
| 68245 | 68484 | } |
| 68246 | 68485 | }else{ |
| 68247 | 68486 | /* Neither operand is NULL. Do a comparison. */ |
| 68248 | - affinity = pOp->p5 & SQLITE_AFF_MASK; | |
| 68249 | - if( affinity ){ | |
| 68250 | - applyAffinity(pIn1, affinity, encoding); | |
| 68251 | - applyAffinity(pIn3, affinity, encoding); | |
| 68487 | + u.al.affinity = pOp->p5 & SQLITE_AFF_MASK; | |
| 68488 | + if( u.al.affinity ){ | |
| 68489 | + applyAffinity(pIn1, u.al.affinity, encoding); | |
| 68490 | + applyAffinity(pIn3, u.al.affinity, encoding); | |
| 68252 | 68491 | if( db->mallocFailed ) goto no_mem; |
| 68253 | 68492 | } |
| 68254 | 68493 | |
| 68255 | 68494 | assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); |
| 68256 | 68495 | ExpandBlob(pIn1); |
| 68257 | 68496 | ExpandBlob(pIn3); |
| 68258 | - res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); | |
| 68497 | + u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); | |
| 68259 | 68498 | } |
| 68260 | 68499 | switch( pOp->opcode ){ |
| 68261 | - case OP_Eq: res = res==0; break; | |
| 68262 | - case OP_Ne: res = res!=0; break; | |
| 68263 | - case OP_Lt: res = res<0; break; | |
| 68264 | - case OP_Le: res = res<=0; break; | |
| 68265 | - case OP_Gt: res = res>0; break; | |
| 68266 | - default: res = res>=0; break; | |
| 68500 | + case OP_Eq: u.al.res = u.al.res==0; break; | |
| 68501 | + case OP_Ne: u.al.res = u.al.res!=0; break; | |
| 68502 | + case OP_Lt: u.al.res = u.al.res<0; break; | |
| 68503 | + case OP_Le: u.al.res = u.al.res<=0; break; | |
| 68504 | + case OP_Gt: u.al.res = u.al.res>0; break; | |
| 68505 | + default: u.al.res = u.al.res>=0; break; | |
| 68267 | 68506 | } |
| 68268 | 68507 | |
| 68269 | 68508 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 68270 | 68509 | pOut = &aMem[pOp->p2]; |
| 68271 | 68510 | memAboutToChange(p, pOut); |
| 68272 | 68511 | MemSetTypeFlag(pOut, MEM_Int); |
| 68273 | - pOut->u.i = res; | |
| 68512 | + pOut->u.i = u.al.res; | |
| 68274 | 68513 | REGISTER_TRACE(pOp->p2, pOut); |
| 68275 | - }else if( res ){ | |
| 68514 | + }else if( u.al.res ){ | |
| 68276 | 68515 | pc = pOp->p2-1; |
| 68277 | 68516 | } |
| 68278 | 68517 | |
| 68279 | 68518 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 68280 | - pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask); | |
| 68281 | - pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask); | |
| 68519 | + pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask); | |
| 68520 | + pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask); | |
| 68282 | 68521 | break; |
| 68283 | 68522 | } |
| 68284 | 68523 | |
| 68285 | 68524 | /* Opcode: Permutation * * * P4 * |
| 68286 | 68525 | ** |
| @@ -68316,49 +68555,51 @@ | ||
| 68316 | 68555 | ** The comparison is a sort comparison, so NULLs compare equal, |
| 68317 | 68556 | ** NULLs are less than numbers, numbers are less than strings, |
| 68318 | 68557 | ** and strings are less than blobs. |
| 68319 | 68558 | */ |
| 68320 | 68559 | case OP_Compare: { |
| 68560 | +#if 0 /* local variables moved into u.am */ | |
| 68321 | 68561 | int n; |
| 68322 | 68562 | int i; |
| 68323 | 68563 | int p1; |
| 68324 | 68564 | int p2; |
| 68325 | 68565 | const KeyInfo *pKeyInfo; |
| 68326 | 68566 | int idx; |
| 68327 | 68567 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 68328 | 68568 | int bRev; /* True for DESCENDING sort order */ |
| 68569 | +#endif /* local variables moved into u.am */ | |
| 68329 | 68570 | |
| 68330 | 68571 | if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; |
| 68331 | - n = pOp->p3; | |
| 68332 | - pKeyInfo = pOp->p4.pKeyInfo; | |
| 68333 | - assert( n>0 ); | |
| 68334 | - assert( pKeyInfo!=0 ); | |
| 68335 | - p1 = pOp->p1; | |
| 68336 | - p2 = pOp->p2; | |
| 68572 | + u.am.n = pOp->p3; | |
| 68573 | + u.am.pKeyInfo = pOp->p4.pKeyInfo; | |
| 68574 | + assert( u.am.n>0 ); | |
| 68575 | + assert( u.am.pKeyInfo!=0 ); | |
| 68576 | + u.am.p1 = pOp->p1; | |
| 68577 | + u.am.p2 = pOp->p2; | |
| 68337 | 68578 | #if SQLITE_DEBUG |
| 68338 | 68579 | if( aPermute ){ |
| 68339 | 68580 | int k, mx = 0; |
| 68340 | - for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k]; | |
| 68341 | - assert( p1>0 && p1+mx<=(p->nMem-p->nCursor)+1 ); | |
| 68342 | - assert( p2>0 && p2+mx<=(p->nMem-p->nCursor)+1 ); | |
| 68581 | + for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k]; | |
| 68582 | + assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 ); | |
| 68583 | + assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 ); | |
| 68343 | 68584 | }else{ |
| 68344 | - assert( p1>0 && p1+n<=(p->nMem-p->nCursor)+1 ); | |
| 68345 | - assert( p2>0 && p2+n<=(p->nMem-p->nCursor)+1 ); | |
| 68585 | + assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 ); | |
| 68586 | + assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 ); | |
| 68346 | 68587 | } |
| 68347 | 68588 | #endif /* SQLITE_DEBUG */ |
| 68348 | - for(i=0; i<n; i++){ | |
| 68349 | - idx = aPermute ? aPermute[i] : i; | |
| 68350 | - assert( memIsValid(&aMem[p1+idx]) ); | |
| 68351 | - assert( memIsValid(&aMem[p2+idx]) ); | |
| 68352 | - REGISTER_TRACE(p1+idx, &aMem[p1+idx]); | |
| 68353 | - REGISTER_TRACE(p2+idx, &aMem[p2+idx]); | |
| 68354 | - assert( i<pKeyInfo->nField ); | |
| 68355 | - pColl = pKeyInfo->aColl[i]; | |
| 68356 | - bRev = pKeyInfo->aSortOrder[i]; | |
| 68357 | - iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl); | |
| 68589 | + for(u.am.i=0; u.am.i<u.am.n; u.am.i++){ | |
| 68590 | + u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i; | |
| 68591 | + assert( memIsValid(&aMem[u.am.p1+u.am.idx]) ); | |
| 68592 | + assert( memIsValid(&aMem[u.am.p2+u.am.idx]) ); | |
| 68593 | + REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]); | |
| 68594 | + REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]); | |
| 68595 | + assert( u.am.i<u.am.pKeyInfo->nField ); | |
| 68596 | + u.am.pColl = u.am.pKeyInfo->aColl[u.am.i]; | |
| 68597 | + u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i]; | |
| 68598 | + iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl); | |
| 68358 | 68599 | if( iCompare ){ |
| 68359 | - if( bRev ) iCompare = -iCompare; | |
| 68600 | + if( u.am.bRev ) iCompare = -iCompare; | |
| 68360 | 68601 | break; |
| 68361 | 68602 | } |
| 68362 | 68603 | } |
| 68363 | 68604 | aPermute = 0; |
| 68364 | 68605 | break; |
| @@ -68401,37 +68642,39 @@ | ||
| 68401 | 68642 | ** even if the other input is NULL. A NULL and false or two NULLs |
| 68402 | 68643 | ** give a NULL output. |
| 68403 | 68644 | */ |
| 68404 | 68645 | case OP_And: /* same as TK_AND, in1, in2, out3 */ |
| 68405 | 68646 | case OP_Or: { /* same as TK_OR, in1, in2, out3 */ |
| 68647 | +#if 0 /* local variables moved into u.an */ | |
| 68406 | 68648 | int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 68407 | 68649 | int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 68650 | +#endif /* local variables moved into u.an */ | |
| 68408 | 68651 | |
| 68409 | 68652 | pIn1 = &aMem[pOp->p1]; |
| 68410 | 68653 | if( pIn1->flags & MEM_Null ){ |
| 68411 | - v1 = 2; | |
| 68654 | + u.an.v1 = 2; | |
| 68412 | 68655 | }else{ |
| 68413 | - v1 = sqlite3VdbeIntValue(pIn1)!=0; | |
| 68656 | + u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0; | |
| 68414 | 68657 | } |
| 68415 | 68658 | pIn2 = &aMem[pOp->p2]; |
| 68416 | 68659 | if( pIn2->flags & MEM_Null ){ |
| 68417 | - v2 = 2; | |
| 68660 | + u.an.v2 = 2; | |
| 68418 | 68661 | }else{ |
| 68419 | - v2 = sqlite3VdbeIntValue(pIn2)!=0; | |
| 68662 | + u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0; | |
| 68420 | 68663 | } |
| 68421 | 68664 | if( pOp->opcode==OP_And ){ |
| 68422 | 68665 | static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 }; |
| 68423 | - v1 = and_logic[v1*3+v2]; | |
| 68666 | + u.an.v1 = and_logic[u.an.v1*3+u.an.v2]; | |
| 68424 | 68667 | }else{ |
| 68425 | 68668 | static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 }; |
| 68426 | - v1 = or_logic[v1*3+v2]; | |
| 68669 | + u.an.v1 = or_logic[u.an.v1*3+u.an.v2]; | |
| 68427 | 68670 | } |
| 68428 | 68671 | pOut = &aMem[pOp->p3]; |
| 68429 | - if( v1==2 ){ | |
| 68672 | + if( u.an.v1==2 ){ | |
| 68430 | 68673 | MemSetTypeFlag(pOut, MEM_Null); |
| 68431 | 68674 | }else{ |
| 68432 | - pOut->u.i = v1; | |
| 68675 | + pOut->u.i = u.an.v1; | |
| 68433 | 68676 | MemSetTypeFlag(pOut, MEM_Int); |
| 68434 | 68677 | } |
| 68435 | 68678 | break; |
| 68436 | 68679 | } |
| 68437 | 68680 | |
| @@ -68498,23 +68741,25 @@ | ||
| 68498 | 68741 | ** is considered false if it has a numeric value of zero. If the value |
| 68499 | 68742 | ** in P1 is NULL then take the jump if P3 is zero. |
| 68500 | 68743 | */ |
| 68501 | 68744 | case OP_If: /* jump, in1 */ |
| 68502 | 68745 | case OP_IfNot: { /* jump, in1 */ |
| 68746 | +#if 0 /* local variables moved into u.ao */ | |
| 68503 | 68747 | int c; |
| 68748 | +#endif /* local variables moved into u.ao */ | |
| 68504 | 68749 | pIn1 = &aMem[pOp->p1]; |
| 68505 | 68750 | if( pIn1->flags & MEM_Null ){ |
| 68506 | - c = pOp->p3; | |
| 68751 | + u.ao.c = pOp->p3; | |
| 68507 | 68752 | }else{ |
| 68508 | 68753 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 68509 | - c = sqlite3VdbeIntValue(pIn1)!=0; | |
| 68754 | + u.ao.c = sqlite3VdbeIntValue(pIn1)!=0; | |
| 68510 | 68755 | #else |
| 68511 | - c = sqlite3VdbeRealValue(pIn1)!=0.0; | |
| 68756 | + u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0; | |
| 68512 | 68757 | #endif |
| 68513 | - if( pOp->opcode==OP_IfNot ) c = !c; | |
| 68758 | + if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c; | |
| 68514 | 68759 | } |
| 68515 | - if( c ){ | |
| 68760 | + if( u.ao.c ){ | |
| 68516 | 68761 | pc = pOp->p2-1; |
| 68517 | 68762 | } |
| 68518 | 68763 | break; |
| 68519 | 68764 | } |
| 68520 | 68765 | |
| @@ -68568,10 +68813,11 @@ | ||
| 68568 | 68813 | ** the result is guaranteed to only be used as the argument of a length() |
| 68569 | 68814 | ** or typeof() function, respectively. The loading of large blobs can be |
| 68570 | 68815 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 68571 | 68816 | */ |
| 68572 | 68817 | case OP_Column: { |
| 68818 | +#if 0 /* local variables moved into u.ap */ | |
| 68573 | 68819 | i64 payloadSize64; /* Number of bytes in the record */ |
| 68574 | 68820 | int p2; /* column number to retrieve */ |
| 68575 | 68821 | VdbeCursor *pC; /* The VDBE cursor */ |
| 68576 | 68822 | BtCursor *pCrsr; /* The BTree cursor */ |
| 68577 | 68823 | u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| @@ -68586,88 +68832,89 @@ | ||
| 68586 | 68832 | u32 offset; /* Offset into the data */ |
| 68587 | 68833 | u32 szField; /* Number of bytes in the content of a field */ |
| 68588 | 68834 | u32 avail; /* Number of bytes of available data */ |
| 68589 | 68835 | u32 t; /* A type code from the record header */ |
| 68590 | 68836 | Mem *pReg; /* PseudoTable input register */ |
| 68591 | - | |
| 68592 | - p2 = pOp->p2; | |
| 68593 | - assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); | |
| 68594 | - pDest = &aMem[pOp->p3]; | |
| 68595 | - memAboutToChange(p, pDest); | |
| 68596 | - assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | |
| 68597 | - pC = p->apCsr[pOp->p1]; | |
| 68598 | - assert( pC!=0 ); | |
| 68599 | - assert( p2<pC->nField ); | |
| 68600 | - aType = pC->aType; | |
| 68601 | - aOffset = aType + pC->nField; | |
| 68602 | -#ifndef SQLITE_OMIT_VIRTUALTABLE | |
| 68603 | - assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ | |
| 68604 | -#endif | |
| 68605 | - pCrsr = pC->pCursor; | |
| 68606 | - assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */ | |
| 68607 | - assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */ | |
| 68608 | - | |
| 68609 | - /* If the cursor cache is stale, bring it up-to-date */ | |
| 68610 | - rc = sqlite3VdbeCursorMoveto(pC); | |
| 68611 | - if( rc ) goto abort_due_to_error; | |
| 68612 | - if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){ | |
| 68613 | - if( pC->nullRow ){ | |
| 68614 | - if( pCrsr==0 ){ | |
| 68615 | - assert( pC->pseudoTableReg>0 ); | |
| 68616 | - pReg = &aMem[pC->pseudoTableReg]; | |
| 68617 | - if( pC->multiPseudo ){ | |
| 68618 | - sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem); | |
| 68619 | - Deephemeralize(pDest); | |
| 68620 | - goto op_column_out; | |
| 68621 | - } | |
| 68622 | - assert( pReg->flags & MEM_Blob ); | |
| 68623 | - assert( memIsValid(pReg) ); | |
| 68624 | - pC->payloadSize = pC->szRow = avail = pReg->n; | |
| 68625 | - pC->aRow = (u8*)pReg->z; | |
| 68626 | - }else{ | |
| 68627 | - MemSetTypeFlag(pDest, MEM_Null); | |
| 68628 | - goto op_column_out; | |
| 68629 | - } | |
| 68630 | - }else{ | |
| 68631 | - assert( pCrsr ); | |
| 68632 | - if( pC->isTable==0 ){ | |
| 68633 | - assert( sqlite3BtreeCursorIsValid(pCrsr) ); | |
| 68634 | - VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64); | |
| 68635 | - assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ | |
| 68636 | - /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the | |
| 68637 | - ** payload size, so it is impossible for payloadSize64 to be | |
| 68638 | - ** larger than 32 bits. */ | |
| 68639 | - assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 ); | |
| 68640 | - pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail); | |
| 68641 | - pC->payloadSize = (u32)payloadSize64; | |
| 68642 | - }else{ | |
| 68643 | - assert( sqlite3BtreeCursorIsValid(pCrsr) ); | |
| 68644 | - VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize); | |
| 68645 | - assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ | |
| 68646 | - pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail); | |
| 68647 | - } | |
| 68648 | - assert( avail<=65536 ); /* Maximum page size is 64KiB */ | |
| 68649 | - if( pC->payloadSize <= (u32)avail ){ | |
| 68650 | - pC->szRow = pC->payloadSize; | |
| 68651 | - }else{ | |
| 68652 | - pC->szRow = avail; | |
| 68653 | - } | |
| 68654 | - if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 68655 | - goto too_big; | |
| 68656 | - } | |
| 68657 | - } | |
| 68658 | - pC->cacheStatus = p->cacheCtr; | |
| 68659 | - pC->iHdrOffset = getVarint32(pC->aRow, offset); | |
| 68660 | - pC->nHdrParsed = 0; | |
| 68661 | - aOffset[0] = offset; | |
| 68662 | - if( avail<offset ){ | |
| 68663 | - /* pC->aRow does not have to hold the entire row, but it does at least | |
| 68664 | - ** need to cover the header of the record. If pC->aRow does not contain | |
| 68665 | - ** the complete header, then set it to zero, forcing the header to be | |
| 68666 | - ** dynamically allocated. */ | |
| 68667 | - pC->aRow = 0; | |
| 68668 | - pC->szRow = 0; | |
| 68837 | +#endif /* local variables moved into u.ap */ | |
| 68838 | + | |
| 68839 | + u.ap.p2 = pOp->p2; | |
| 68840 | + assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); | |
| 68841 | + u.ap.pDest = &aMem[pOp->p3]; | |
| 68842 | + memAboutToChange(p, u.ap.pDest); | |
| 68843 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | |
| 68844 | + u.ap.pC = p->apCsr[pOp->p1]; | |
| 68845 | + assert( u.ap.pC!=0 ); | |
| 68846 | + assert( u.ap.p2<u.ap.pC->nField ); | |
| 68847 | + u.ap.aType = u.ap.pC->aType; | |
| 68848 | + u.ap.aOffset = u.ap.aType + u.ap.pC->nField; | |
| 68849 | +#ifndef SQLITE_OMIT_VIRTUALTABLE | |
| 68850 | + assert( u.ap.pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ | |
| 68851 | +#endif | |
| 68852 | + u.ap.pCrsr = u.ap.pC->pCursor; | |
| 68853 | + assert( u.ap.pCrsr!=0 || u.ap.pC->pseudoTableReg>0 ); /* u.ap.pCrsr NULL on PseudoTables */ | |
| 68854 | + assert( u.ap.pCrsr!=0 || u.ap.pC->nullRow ); /* u.ap.pC->nullRow on PseudoTables */ | |
| 68855 | + | |
| 68856 | + /* If the cursor cache is stale, bring it up-to-date */ | |
| 68857 | + rc = sqlite3VdbeCursorMoveto(u.ap.pC); | |
| 68858 | + if( rc ) goto abort_due_to_error; | |
| 68859 | + if( u.ap.pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){ | |
| 68860 | + if( u.ap.pC->nullRow ){ | |
| 68861 | + if( u.ap.pCrsr==0 ){ | |
| 68862 | + assert( u.ap.pC->pseudoTableReg>0 ); | |
| 68863 | + u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg]; | |
| 68864 | + if( u.ap.pC->multiPseudo ){ | |
| 68865 | + sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem); | |
| 68866 | + Deephemeralize(u.ap.pDest); | |
| 68867 | + goto op_column_out; | |
| 68868 | + } | |
| 68869 | + assert( u.ap.pReg->flags & MEM_Blob ); | |
| 68870 | + assert( memIsValid(u.ap.pReg) ); | |
| 68871 | + u.ap.pC->payloadSize = u.ap.pC->szRow = u.ap.avail = u.ap.pReg->n; | |
| 68872 | + u.ap.pC->aRow = (u8*)u.ap.pReg->z; | |
| 68873 | + }else{ | |
| 68874 | + MemSetTypeFlag(u.ap.pDest, MEM_Null); | |
| 68875 | + goto op_column_out; | |
| 68876 | + } | |
| 68877 | + }else{ | |
| 68878 | + assert( u.ap.pCrsr ); | |
| 68879 | + if( u.ap.pC->isTable==0 ){ | |
| 68880 | + assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); | |
| 68881 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64); | |
| 68882 | + assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ | |
| 68883 | + /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the | |
| 68884 | + ** payload size, so it is impossible for u.ap.payloadSize64 to be | |
| 68885 | + ** larger than 32 bits. */ | |
| 68886 | + assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 ); | |
| 68887 | + u.ap.pC->aRow = sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail); | |
| 68888 | + u.ap.pC->payloadSize = (u32)u.ap.payloadSize64; | |
| 68889 | + }else{ | |
| 68890 | + assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); | |
| 68891 | + VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.pC->payloadSize); | |
| 68892 | + assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ | |
| 68893 | + u.ap.pC->aRow = sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail); | |
| 68894 | + } | |
| 68895 | + assert( u.ap.avail<=65536 ); /* Maximum page size is 64KiB */ | |
| 68896 | + if( u.ap.pC->payloadSize <= (u32)u.ap.avail ){ | |
| 68897 | + u.ap.pC->szRow = u.ap.pC->payloadSize; | |
| 68898 | + }else{ | |
| 68899 | + u.ap.pC->szRow = u.ap.avail; | |
| 68900 | + } | |
| 68901 | + if( u.ap.pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 68902 | + goto too_big; | |
| 68903 | + } | |
| 68904 | + } | |
| 68905 | + u.ap.pC->cacheStatus = p->cacheCtr; | |
| 68906 | + u.ap.pC->iHdrOffset = getVarint32(u.ap.pC->aRow, u.ap.offset); | |
| 68907 | + u.ap.pC->nHdrParsed = 0; | |
| 68908 | + u.ap.aOffset[0] = u.ap.offset; | |
| 68909 | + if( u.ap.avail<u.ap.offset ){ | |
| 68910 | + /* u.ap.pC->aRow does not have to hold the entire row, but it does at least | |
| 68911 | + ** need to cover the header of the record. If u.ap.pC->aRow does not contain | |
| 68912 | + ** the complete header, then set it to zero, forcing the header to be | |
| 68913 | + ** dynamically allocated. */ | |
| 68914 | + u.ap.pC->aRow = 0; | |
| 68915 | + u.ap.pC->szRow = 0; | |
| 68669 | 68916 | } |
| 68670 | 68917 | |
| 68671 | 68918 | /* Make sure a corrupt database has not given us an oversize header. |
| 68672 | 68919 | ** Do this now to avoid an oversize memory allocation. |
| 68673 | 68920 | ** |
| @@ -68675,154 +68922,154 @@ | ||
| 68675 | 68922 | ** types use so much data space that there can only be 4096 and 32 of |
| 68676 | 68923 | ** them, respectively. So the maximum header length results from a |
| 68677 | 68924 | ** 3-byte type for each of the maximum of 32768 columns plus three |
| 68678 | 68925 | ** extra bytes for the header length itself. 32768*3 + 3 = 98307. |
| 68679 | 68926 | */ |
| 68680 | - if( offset > 98307 || offset > pC->payloadSize ){ | |
| 68927 | + if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){ | |
| 68681 | 68928 | rc = SQLITE_CORRUPT_BKPT; |
| 68682 | 68929 | goto op_column_error; |
| 68683 | 68930 | } |
| 68684 | 68931 | } |
| 68685 | 68932 | |
| 68686 | - /* Make sure at least the first p2+1 entries of the header have been | |
| 68687 | - ** parsed and valid information is in aOffset[] and aType[]. | |
| 68933 | + /* Make sure at least the first u.ap.p2+1 entries of the header have been | |
| 68934 | + ** parsed and valid information is in u.ap.aOffset[] and u.ap.aType[]. | |
| 68688 | 68935 | */ |
| 68689 | - if( pC->nHdrParsed<=p2 ){ | |
| 68936 | + if( u.ap.pC->nHdrParsed<=u.ap.p2 ){ | |
| 68690 | 68937 | /* If there is more header available for parsing in the record, try |
| 68691 | - ** to extract additional fields up through the p2+1-th field | |
| 68938 | + ** to extract additional fields up through the u.ap.p2+1-th field | |
| 68692 | 68939 | */ |
| 68693 | - if( pC->iHdrOffset<aOffset[0] ){ | |
| 68694 | - /* Make sure zData points to enough of the record to cover the header. */ | |
| 68695 | - if( pC->aRow==0 ){ | |
| 68696 | - memset(&sMem, 0, sizeof(sMem)); | |
| 68697 | - rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], | |
| 68698 | - !pC->isTable, &sMem); | |
| 68940 | + if( u.ap.pC->iHdrOffset<u.ap.aOffset[0] ){ | |
| 68941 | + /* Make sure u.ap.zData points to enough of the record to cover the header. */ | |
| 68942 | + if( u.ap.pC->aRow==0 ){ | |
| 68943 | + memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); | |
| 68944 | + rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.aOffset[0], | |
| 68945 | + !u.ap.pC->isTable, &u.ap.sMem); | |
| 68699 | 68946 | if( rc!=SQLITE_OK ){ |
| 68700 | 68947 | goto op_column_error; |
| 68701 | 68948 | } |
| 68702 | - zData = (u8*)sMem.z; | |
| 68949 | + u.ap.zData = (u8*)u.ap.sMem.z; | |
| 68703 | 68950 | }else{ |
| 68704 | - zData = pC->aRow; | |
| 68705 | - } | |
| 68706 | - | |
| 68707 | - /* Fill in aType[i] and aOffset[i] values through the p2-th field. */ | |
| 68708 | - i = pC->nHdrParsed; | |
| 68709 | - offset = aOffset[i]; | |
| 68710 | - zHdr = zData + pC->iHdrOffset; | |
| 68711 | - zEndHdr = zData + aOffset[0]; | |
| 68712 | - assert( i<=p2 && zHdr<zEndHdr ); | |
| 68951 | + u.ap.zData = u.ap.pC->aRow; | |
| 68952 | + } | |
| 68953 | + | |
| 68954 | + /* Fill in u.ap.aType[u.ap.i] and u.ap.aOffset[u.ap.i] values through the u.ap.p2-th field. */ | |
| 68955 | + u.ap.i = u.ap.pC->nHdrParsed; | |
| 68956 | + u.ap.offset = u.ap.aOffset[u.ap.i]; | |
| 68957 | + u.ap.zHdr = u.ap.zData + u.ap.pC->iHdrOffset; | |
| 68958 | + u.ap.zEndHdr = u.ap.zData + u.ap.aOffset[0]; | |
| 68959 | + assert( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr ); | |
| 68713 | 68960 | do{ |
| 68714 | - if( zHdr[0]<0x80 ){ | |
| 68715 | - t = zHdr[0]; | |
| 68716 | - zHdr++; | |
| 68961 | + if( u.ap.zHdr[0]<0x80 ){ | |
| 68962 | + u.ap.t = u.ap.zHdr[0]; | |
| 68963 | + u.ap.zHdr++; | |
| 68717 | 68964 | }else{ |
| 68718 | - zHdr += sqlite3GetVarint32(zHdr, &t); | |
| 68965 | + u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t); | |
| 68719 | 68966 | } |
| 68720 | - aType[i] = t; | |
| 68721 | - szField = sqlite3VdbeSerialTypeLen(t); | |
| 68722 | - offset += szField; | |
| 68723 | - if( offset<szField ){ /* True if offset overflows */ | |
| 68724 | - zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ | |
| 68967 | + u.ap.aType[u.ap.i] = u.ap.t; | |
| 68968 | + u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t); | |
| 68969 | + u.ap.offset += u.ap.szField; | |
| 68970 | + if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */ | |
| 68971 | + u.ap.zHdr = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ | |
| 68725 | 68972 | break; |
| 68726 | 68973 | } |
| 68727 | - i++; | |
| 68728 | - aOffset[i] = offset; | |
| 68729 | - }while( i<=p2 && zHdr<zEndHdr ); | |
| 68730 | - pC->nHdrParsed = i; | |
| 68731 | - pC->iHdrOffset = (u32)(zHdr - zData); | |
| 68732 | - if( pC->aRow==0 ){ | |
| 68733 | - sqlite3VdbeMemRelease(&sMem); | |
| 68734 | - sMem.flags = MEM_Null; | |
| 68735 | - } | |
| 68736 | - | |
| 68974 | + u.ap.i++; | |
| 68975 | + u.ap.aOffset[u.ap.i] = u.ap.offset; | |
| 68976 | + }while( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr ); | |
| 68977 | + u.ap.pC->nHdrParsed = u.ap.i; | |
| 68978 | + u.ap.pC->iHdrOffset = (u32)(u.ap.zHdr - u.ap.zData); | |
| 68979 | + if( u.ap.pC->aRow==0 ){ | |
| 68980 | + sqlite3VdbeMemRelease(&u.ap.sMem); | |
| 68981 | + u.ap.sMem.flags = MEM_Null; | |
| 68982 | + } | |
| 68983 | + | |
| 68737 | 68984 | /* If we have read more header data than was contained in the header, |
| 68738 | 68985 | ** or if the end of the last field appears to be past the end of the |
| 68739 | 68986 | ** record, or if the end of the last field appears to be before the end |
| 68740 | - ** of the record (when all fields present), then we must be dealing | |
| 68987 | + ** of the record (when all fields present), then we must be dealing | |
| 68741 | 68988 | ** with a corrupt database. |
| 68742 | 68989 | */ |
| 68743 | - if( (zHdr > zEndHdr) | |
| 68744 | - || (offset > pC->payloadSize) | |
| 68745 | - || (zHdr==zEndHdr && offset!=pC->payloadSize) | |
| 68990 | + if( (u.ap.zHdr > u.ap.zEndHdr) | |
| 68991 | + || (u.ap.offset > u.ap.pC->payloadSize) | |
| 68992 | + || (u.ap.zHdr==u.ap.zEndHdr && u.ap.offset!=u.ap.pC->payloadSize) | |
| 68746 | 68993 | ){ |
| 68747 | 68994 | rc = SQLITE_CORRUPT_BKPT; |
| 68748 | 68995 | goto op_column_error; |
| 68749 | 68996 | } |
| 68750 | 68997 | } |
| 68751 | 68998 | |
| 68752 | 68999 | /* If after trying to extra new entries from the header, nHdrParsed is |
| 68753 | - ** still not up to p2, that means that the record has fewer than p2 | |
| 69000 | + ** still not up to u.ap.p2, that means that the record has fewer than u.ap.p2 | |
| 68754 | 69001 | ** columns. So the result will be either the default value or a NULL. |
| 68755 | 69002 | */ |
| 68756 | - if( pC->nHdrParsed<=p2 ){ | |
| 69003 | + if( u.ap.pC->nHdrParsed<=u.ap.p2 ){ | |
| 68757 | 69004 | if( pOp->p4type==P4_MEM ){ |
| 68758 | - sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); | |
| 69005 | + sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static); | |
| 68759 | 69006 | }else{ |
| 68760 | - MemSetTypeFlag(pDest, MEM_Null); | |
| 69007 | + MemSetTypeFlag(u.ap.pDest, MEM_Null); | |
| 68761 | 69008 | } |
| 68762 | 69009 | goto op_column_out; |
| 68763 | 69010 | } |
| 68764 | 69011 | } |
| 68765 | 69012 | |
| 68766 | - /* Extract the content for the p2+1-th column. Control can only | |
| 68767 | - ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are | |
| 69013 | + /* Extract the content for the u.ap.p2+1-th column. Control can only | |
| 69014 | + ** reach this point if u.ap.aOffset[u.ap.p2], u.ap.aOffset[u.ap.p2+1], and u.ap.aType[u.ap.p2] are | |
| 68768 | 69015 | ** all valid. |
| 68769 | 69016 | */ |
| 68770 | - assert( p2<pC->nHdrParsed ); | |
| 69017 | + assert( u.ap.p2<u.ap.pC->nHdrParsed ); | |
| 68771 | 69018 | assert( rc==SQLITE_OK ); |
| 68772 | - if( pC->szRow>=aOffset[p2+1] ){ | |
| 69019 | + if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){ | |
| 68773 | 69020 | /* This is the common case where the desired content fits on the original |
| 68774 | 69021 | ** page - where the content is not on an overflow page */ |
| 68775 | - VdbeMemRelease(pDest); | |
| 68776 | - sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest); | |
| 69022 | + VdbeMemRelease(u.ap.pDest); | |
| 69023 | + sqlite3VdbeSerialGet(u.ap.pC->aRow+u.ap.aOffset[u.ap.p2], u.ap.aType[u.ap.p2], u.ap.pDest); | |
| 68777 | 69024 | }else{ |
| 68778 | 69025 | /* This branch happens only when content is on overflow pages */ |
| 68779 | - t = aType[p2]; | |
| 69026 | + u.ap.t = u.ap.aType[u.ap.p2]; | |
| 68780 | 69027 | if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 68781 | - && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) | |
| 68782 | - || (len = sqlite3VdbeSerialTypeLen(t))==0 | |
| 69028 | + && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) | |
| 69029 | + || (u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t))==0 | |
| 68783 | 69030 | ){ |
| 68784 | 69031 | /* Content is irrelevant for the typeof() function and for |
| 68785 | 69032 | ** the length(X) function if X is a blob. So we might as well use |
| 68786 | 69033 | ** bogus content rather than reading content from disk. NULL works |
| 68787 | - ** for text and blob and whatever is in the payloadSize64 variable | |
| 69034 | + ** for text and blob and whatever is in the u.ap.payloadSize64 variable | |
| 68788 | 69035 | ** will work for everything else. Content is also irrelevant if |
| 68789 | 69036 | ** the content length is 0. */ |
| 68790 | - zData = t<=13 ? (u8*)&payloadSize64 : 0; | |
| 68791 | - sMem.zMalloc = 0; | |
| 69037 | + u.ap.zData = u.ap.t<=13 ? (u8*)&u.ap.payloadSize64 : 0; | |
| 69038 | + u.ap.sMem.zMalloc = 0; | |
| 68792 | 69039 | }else{ |
| 68793 | - memset(&sMem, 0, sizeof(sMem)); | |
| 68794 | - sqlite3VdbeMemMove(&sMem, pDest); | |
| 68795 | - rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable, | |
| 68796 | - &sMem); | |
| 69040 | + memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); | |
| 69041 | + sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest); | |
| 69042 | + rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, !u.ap.pC->isTable, | |
| 69043 | + &u.ap.sMem); | |
| 68797 | 69044 | if( rc!=SQLITE_OK ){ |
| 68798 | 69045 | goto op_column_error; |
| 68799 | 69046 | } |
| 68800 | - zData = (u8*)sMem.z; | |
| 69047 | + u.ap.zData = (u8*)u.ap.sMem.z; | |
| 68801 | 69048 | } |
| 68802 | - sqlite3VdbeSerialGet(zData, t, pDest); | |
| 69049 | + sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest); | |
| 68803 | 69050 | /* If we dynamically allocated space to hold the data (in the |
| 68804 | 69051 | ** sqlite3VdbeMemFromBtree() call above) then transfer control of that |
| 68805 | - ** dynamically allocated space over to the pDest structure. | |
| 69052 | + ** dynamically allocated space over to the u.ap.pDest structure. | |
| 68806 | 69053 | ** This prevents a memory copy. */ |
| 68807 | - if( sMem.zMalloc ){ | |
| 68808 | - assert( sMem.z==sMem.zMalloc ); | |
| 68809 | - assert( !(pDest->flags & MEM_Dyn) ); | |
| 68810 | - assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z ); | |
| 68811 | - pDest->flags &= ~(MEM_Ephem|MEM_Static); | |
| 68812 | - pDest->flags |= MEM_Term; | |
| 68813 | - pDest->z = sMem.z; | |
| 68814 | - pDest->zMalloc = sMem.zMalloc; | |
| 69054 | + if( u.ap.sMem.zMalloc ){ | |
| 69055 | + assert( u.ap.sMem.z==u.ap.sMem.zMalloc ); | |
| 69056 | + assert( !(u.ap.pDest->flags & MEM_Dyn) ); | |
| 69057 | + assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z ); | |
| 69058 | + u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static); | |
| 69059 | + u.ap.pDest->flags |= MEM_Term; | |
| 69060 | + u.ap.pDest->z = u.ap.sMem.z; | |
| 69061 | + u.ap.pDest->zMalloc = u.ap.sMem.zMalloc; | |
| 68815 | 69062 | } |
| 68816 | 69063 | } |
| 68817 | - pDest->enc = encoding; | |
| 69064 | + u.ap.pDest->enc = encoding; | |
| 68818 | 69065 | |
| 68819 | 69066 | op_column_out: |
| 68820 | - Deephemeralize(pDest); | |
| 69067 | + rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest); | |
| 68821 | 69068 | op_column_error: |
| 68822 | - UPDATE_MAX_BLOBSIZE(pDest); | |
| 68823 | - REGISTER_TRACE(pOp->p3, pDest); | |
| 69069 | + UPDATE_MAX_BLOBSIZE(u.ap.pDest); | |
| 69070 | + REGISTER_TRACE(pOp->p3, u.ap.pDest); | |
| 68824 | 69071 | break; |
| 68825 | 69072 | } |
| 68826 | 69073 | |
| 68827 | 69074 | /* Opcode: Affinity P1 P2 * P4 * |
| 68828 | 69075 | ** Synopsis: affinity(r[P1@P2]) |
| @@ -68832,22 +69079,24 @@ | ||
| 68832 | 69079 | ** P4 is a string that is P2 characters long. The nth character of the |
| 68833 | 69080 | ** string indicates the column affinity that should be used for the nth |
| 68834 | 69081 | ** memory cell in the range. |
| 68835 | 69082 | */ |
| 68836 | 69083 | case OP_Affinity: { |
| 69084 | +#if 0 /* local variables moved into u.aq */ | |
| 68837 | 69085 | const char *zAffinity; /* The affinity to be applied */ |
| 68838 | 69086 | char cAff; /* A single character of affinity */ |
| 69087 | +#endif /* local variables moved into u.aq */ | |
| 68839 | 69088 | |
| 68840 | - zAffinity = pOp->p4.z; | |
| 68841 | - assert( zAffinity!=0 ); | |
| 68842 | - assert( zAffinity[pOp->p2]==0 ); | |
| 69089 | + u.aq.zAffinity = pOp->p4.z; | |
| 69090 | + assert( u.aq.zAffinity!=0 ); | |
| 69091 | + assert( u.aq.zAffinity[pOp->p2]==0 ); | |
| 68843 | 69092 | pIn1 = &aMem[pOp->p1]; |
| 68844 | - while( (cAff = *(zAffinity++))!=0 ){ | |
| 69093 | + while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){ | |
| 68845 | 69094 | assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] ); |
| 68846 | 69095 | assert( memIsValid(pIn1) ); |
| 68847 | 69096 | ExpandBlob(pIn1); |
| 68848 | - applyAffinity(pIn1, cAff, encoding); | |
| 69097 | + applyAffinity(pIn1, u.aq.cAff, encoding); | |
| 68849 | 69098 | pIn1++; |
| 68850 | 69099 | } |
| 68851 | 69100 | break; |
| 68852 | 69101 | } |
| 68853 | 69102 | |
| @@ -68866,10 +69115,11 @@ | ||
| 68866 | 69115 | ** macros defined in sqliteInt.h. |
| 68867 | 69116 | ** |
| 68868 | 69117 | ** If P4 is NULL then all index fields have the affinity NONE. |
| 68869 | 69118 | */ |
| 68870 | 69119 | case OP_MakeRecord: { |
| 69120 | +#if 0 /* local variables moved into u.ar */ | |
| 68871 | 69121 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 68872 | 69122 | Mem *pRec; /* The new record */ |
| 68873 | 69123 | u64 nData; /* Number of bytes of data space */ |
| 68874 | 69124 | int nHdr; /* Number of bytes of header space */ |
| 68875 | 69125 | i64 nByte; /* Data space required for this record */ |
| @@ -68879,123 +69129,106 @@ | ||
| 68879 | 69129 | Mem *pData0; /* First field to be combined into the record */ |
| 68880 | 69130 | Mem *pLast; /* Last field of the record */ |
| 68881 | 69131 | int nField; /* Number of fields in the record */ |
| 68882 | 69132 | char *zAffinity; /* The affinity string for the record */ |
| 68883 | 69133 | int file_format; /* File format to use for encoding */ |
| 68884 | - int i; /* Space used in zNewRecord[] header */ | |
| 68885 | - int j; /* Space used in zNewRecord[] content */ | |
| 69134 | + int i; /* Space used in zNewRecord[] */ | |
| 68886 | 69135 | int len; /* Length of a field */ |
| 69136 | +#endif /* local variables moved into u.ar */ | |
| 68887 | 69137 | |
| 68888 | 69138 | /* Assuming the record contains N fields, the record format looks |
| 68889 | 69139 | ** like this: |
| 68890 | 69140 | ** |
| 68891 | 69141 | ** ------------------------------------------------------------------------ |
| 68892 | - ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | | |
| 69142 | + ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | | |
| 68893 | 69143 | ** ------------------------------------------------------------------------ |
| 68894 | 69144 | ** |
| 68895 | 69145 | ** Data(0) is taken from register P1. Data(1) comes from register P1+1 |
| 68896 | 69146 | ** and so froth. |
| 68897 | 69147 | ** |
| 68898 | - ** Each type field is a varint representing the serial type of the | |
| 69148 | + ** Each type field is a varint representing the serial type of the | |
| 68899 | 69149 | ** corresponding data element (see sqlite3VdbeSerialType()). The |
| 68900 | 69150 | ** hdr-size field is also a varint which is the offset from the beginning |
| 68901 | 69151 | ** of the record to data0. |
| 68902 | 69152 | */ |
| 68903 | - nData = 0; /* Number of bytes of data space */ | |
| 68904 | - nHdr = 0; /* Number of bytes of header space */ | |
| 68905 | - nZero = 0; /* Number of zero bytes at the end of the record */ | |
| 68906 | - nField = pOp->p1; | |
| 68907 | - zAffinity = pOp->p4.z; | |
| 68908 | - assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem-p->nCursor)+1 ); | |
| 68909 | - pData0 = &aMem[nField]; | |
| 68910 | - nField = pOp->p2; | |
| 68911 | - pLast = &pData0[nField-1]; | |
| 68912 | - file_format = p->minWriteFileFormat; | |
| 69153 | + u.ar.nData = 0; /* Number of bytes of data space */ | |
| 69154 | + u.ar.nHdr = 0; /* Number of bytes of header space */ | |
| 69155 | + u.ar.nZero = 0; /* Number of zero bytes at the end of the record */ | |
| 69156 | + u.ar.nField = pOp->p1; | |
| 69157 | + u.ar.zAffinity = pOp->p4.z; | |
| 69158 | + assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 ); | |
| 69159 | + u.ar.pData0 = &aMem[u.ar.nField]; | |
| 69160 | + u.ar.nField = pOp->p2; | |
| 69161 | + u.ar.pLast = &u.ar.pData0[u.ar.nField-1]; | |
| 69162 | + u.ar.file_format = p->minWriteFileFormat; | |
| 68913 | 69163 | |
| 68914 | 69164 | /* Identify the output register */ |
| 68915 | 69165 | assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); |
| 68916 | 69166 | pOut = &aMem[pOp->p3]; |
| 68917 | 69167 | memAboutToChange(p, pOut); |
| 68918 | 69168 | |
| 68919 | - /* Apply the requested affinity to all inputs | |
| 68920 | - */ | |
| 68921 | - assert( pData0<=pLast ); | |
| 68922 | - if( zAffinity ){ | |
| 68923 | - pRec = pData0; | |
| 68924 | - do{ | |
| 68925 | - applyAffinity(pRec, *(zAffinity++), encoding); | |
| 68926 | - }while( (++pRec)<=pLast ); | |
| 68927 | - } | |
| 68928 | - | |
| 68929 | 69169 | /* Loop through the elements that will make up the record to figure |
| 68930 | 69170 | ** out how much space is required for the new record. |
| 68931 | 69171 | */ |
| 68932 | - pRec = pLast; | |
| 68933 | - do{ | |
| 68934 | - assert( memIsValid(pRec) ); | |
| 68935 | - serial_type = sqlite3VdbeSerialType(pRec, file_format); | |
| 68936 | - len = sqlite3VdbeSerialTypeLen(serial_type); | |
| 68937 | - if( pRec->flags & MEM_Zero ){ | |
| 68938 | - if( nData ){ | |
| 68939 | - sqlite3VdbeMemExpandBlob(pRec); | |
| 68940 | - }else{ | |
| 68941 | - nZero += pRec->u.nZero; | |
| 68942 | - len -= pRec->u.nZero; | |
| 68943 | - } | |
| 68944 | - } | |
| 68945 | - nData += len; | |
| 68946 | - testcase( serial_type==127 ); | |
| 68947 | - testcase( serial_type==128 ); | |
| 68948 | - nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type); | |
| 68949 | - }while( (--pRec)>=pData0 ); | |
| 69172 | + for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ | |
| 69173 | + assert( memIsValid(u.ar.pRec) ); | |
| 69174 | + if( u.ar.zAffinity ){ | |
| 69175 | + applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding); | |
| 69176 | + } | |
| 69177 | + if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){ | |
| 69178 | + sqlite3VdbeMemExpandBlob(u.ar.pRec); | |
| 69179 | + } | |
| 69180 | + u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format); | |
| 69181 | + u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type); | |
| 69182 | + u.ar.nData += u.ar.len; | |
| 69183 | + u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type); | |
| 69184 | + if( u.ar.pRec->flags & MEM_Zero ){ | |
| 69185 | + /* Only pure zero-filled BLOBs can be input to this Opcode. | |
| 69186 | + ** We do not allow blobs with a prefix and a zero-filled tail. */ | |
| 69187 | + u.ar.nZero += u.ar.pRec->u.nZero; | |
| 69188 | + }else if( u.ar.len ){ | |
| 69189 | + u.ar.nZero = 0; | |
| 69190 | + } | |
| 69191 | + } | |
| 68950 | 69192 | |
| 68951 | 69193 | /* Add the initial header varint and total the size */ |
| 68952 | - testcase( nHdr==126 ); | |
| 68953 | - testcase( nHdr==127 ); | |
| 68954 | - if( nHdr<=126 ){ | |
| 68955 | - /* The common case */ | |
| 68956 | - nHdr += 1; | |
| 68957 | - }else{ | |
| 68958 | - /* Rare case of a really large header */ | |
| 68959 | - nVarint = sqlite3VarintLen(nHdr); | |
| 68960 | - nHdr += nVarint; | |
| 68961 | - if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; | |
| 68962 | - } | |
| 68963 | - nByte = nHdr+nData; | |
| 68964 | - if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 69194 | + u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr); | |
| 69195 | + if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){ | |
| 69196 | + u.ar.nHdr++; | |
| 69197 | + } | |
| 69198 | + u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero; | |
| 69199 | + if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 68965 | 69200 | goto too_big; |
| 68966 | 69201 | } |
| 68967 | 69202 | |
| 68968 | - /* Make sure the output register has a buffer large enough to store | |
| 69203 | + /* Make sure the output register has a buffer large enough to store | |
| 68969 | 69204 | ** the new record. The output register (pOp->p3) is not allowed to |
| 68970 | 69205 | ** be one of the input registers (because the following call to |
| 68971 | 69206 | ** sqlite3VdbeMemGrow() could clobber the value before it is used). |
| 68972 | 69207 | */ |
| 68973 | - if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){ | |
| 69208 | + if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){ | |
| 68974 | 69209 | goto no_mem; |
| 68975 | 69210 | } |
| 68976 | - zNewRecord = (u8 *)pOut->z; | |
| 69211 | + u.ar.zNewRecord = (u8 *)pOut->z; | |
| 68977 | 69212 | |
| 68978 | 69213 | /* Write the record */ |
| 68979 | - i = putVarint32(zNewRecord, nHdr); | |
| 68980 | - j = nHdr; | |
| 68981 | - assert( pData0<=pLast ); | |
| 68982 | - pRec = pData0; | |
| 68983 | - do{ | |
| 68984 | - serial_type = sqlite3VdbeSerialType(pRec, file_format); | |
| 68985 | - i += putVarint32(&zNewRecord[i], serial_type); /* serial type */ | |
| 68986 | - j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */ | |
| 68987 | - }while( (++pRec)<=pLast ); | |
| 68988 | - assert( i==nHdr ); | |
| 68989 | - assert( j==nByte ); | |
| 69214 | + u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr); | |
| 69215 | + for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ | |
| 69216 | + u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format); | |
| 69217 | + u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */ | |
| 69218 | + } | |
| 69219 | + for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */ | |
| 69220 | + u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format); | |
| 69221 | + } | |
| 69222 | + assert( u.ar.i==u.ar.nByte ); | |
| 68990 | 69223 | |
| 68991 | 69224 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68992 | - pOut->n = (int)nByte; | |
| 69225 | + pOut->n = (int)u.ar.nByte; | |
| 68993 | 69226 | pOut->flags = MEM_Blob | MEM_Dyn; |
| 68994 | 69227 | pOut->xDel = 0; |
| 68995 | - if( nZero ){ | |
| 68996 | - pOut->u.nZero = nZero; | |
| 69228 | + if( u.ar.nZero ){ | |
| 69229 | + pOut->u.nZero = u.ar.nZero; | |
| 68997 | 69230 | pOut->flags |= MEM_Zero; |
| 68998 | 69231 | } |
| 68999 | 69232 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ |
| 69000 | 69233 | REGISTER_TRACE(pOp->p3, pOut); |
| 69001 | 69234 | UPDATE_MAX_BLOBSIZE(pOut); |
| @@ -69008,18 +69241,19 @@ | ||
| 69008 | 69241 | ** Store the number of entries (an integer value) in the table or index |
| 69009 | 69242 | ** opened by cursor P1 in register P2 |
| 69010 | 69243 | */ |
| 69011 | 69244 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 69012 | 69245 | case OP_Count: { /* out2-prerelease */ |
| 69246 | +#if 0 /* local variables moved into u.as */ | |
| 69013 | 69247 | i64 nEntry; |
| 69014 | 69248 | BtCursor *pCrsr; |
| 69249 | +#endif /* local variables moved into u.as */ | |
| 69015 | 69250 | |
| 69016 | - pCrsr = p->apCsr[pOp->p1]->pCursor; | |
| 69017 | - assert( pCrsr ); | |
| 69018 | - nEntry = 0; /* Not needed. Only used to silence a warning. */ | |
| 69019 | - rc = sqlite3BtreeCount(pCrsr, &nEntry); | |
| 69020 | - pOut->u.i = nEntry; | |
| 69251 | + u.as.pCrsr = p->apCsr[pOp->p1]->pCursor; | |
| 69252 | + assert( u.as.pCrsr ); | |
| 69253 | + rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry); | |
| 69254 | + pOut->u.i = u.as.nEntry; | |
| 69021 | 69255 | break; |
| 69022 | 69256 | } |
| 69023 | 69257 | #endif |
| 69024 | 69258 | |
| 69025 | 69259 | /* Opcode: Savepoint P1 * * P4 * |
| @@ -69027,41 +69261,43 @@ | ||
| 69027 | 69261 | ** Open, release or rollback the savepoint named by parameter P4, depending |
| 69028 | 69262 | ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an |
| 69029 | 69263 | ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2. |
| 69030 | 69264 | */ |
| 69031 | 69265 | case OP_Savepoint: { |
| 69266 | +#if 0 /* local variables moved into u.at */ | |
| 69032 | 69267 | int p1; /* Value of P1 operand */ |
| 69033 | 69268 | char *zName; /* Name of savepoint */ |
| 69034 | 69269 | int nName; |
| 69035 | 69270 | Savepoint *pNew; |
| 69036 | 69271 | Savepoint *pSavepoint; |
| 69037 | 69272 | Savepoint *pTmp; |
| 69038 | 69273 | int iSavepoint; |
| 69039 | 69274 | int ii; |
| 69275 | +#endif /* local variables moved into u.at */ | |
| 69040 | 69276 | |
| 69041 | - p1 = pOp->p1; | |
| 69042 | - zName = pOp->p4.z; | |
| 69277 | + u.at.p1 = pOp->p1; | |
| 69278 | + u.at.zName = pOp->p4.z; | |
| 69043 | 69279 | |
| 69044 | - /* Assert that the p1 parameter is valid. Also that if there is no open | |
| 69045 | - ** transaction, then there cannot be any savepoints. | |
| 69280 | + /* Assert that the u.at.p1 parameter is valid. Also that if there is no open | |
| 69281 | + ** transaction, then there cannot be any savepoints. | |
| 69046 | 69282 | */ |
| 69047 | 69283 | assert( db->pSavepoint==0 || db->autoCommit==0 ); |
| 69048 | - assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK ); | |
| 69284 | + assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK ); | |
| 69049 | 69285 | assert( db->pSavepoint || db->isTransactionSavepoint==0 ); |
| 69050 | 69286 | assert( checkSavepointCount(db) ); |
| 69051 | 69287 | assert( p->bIsReader ); |
| 69052 | 69288 | |
| 69053 | - if( p1==SAVEPOINT_BEGIN ){ | |
| 69289 | + if( u.at.p1==SAVEPOINT_BEGIN ){ | |
| 69054 | 69290 | if( db->nVdbeWrite>0 ){ |
| 69055 | - /* A new savepoint cannot be created if there are active write | |
| 69291 | + /* A new savepoint cannot be created if there are active write | |
| 69056 | 69292 | ** statements (i.e. open read/write incremental blob handles). |
| 69057 | 69293 | */ |
| 69058 | 69294 | sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - " |
| 69059 | 69295 | "SQL statements in progress"); |
| 69060 | 69296 | rc = SQLITE_BUSY; |
| 69061 | 69297 | }else{ |
| 69062 | - nName = sqlite3Strlen30(zName); | |
| 69298 | + u.at.nName = sqlite3Strlen30(u.at.zName); | |
| 69063 | 69299 | |
| 69064 | 69300 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 69065 | 69301 | /* This call is Ok even if this savepoint is actually a transaction |
| 69066 | 69302 | ** savepoint (and therefore should not prompt xSavepoint()) callbacks. |
| 69067 | 69303 | ** If this is a transaction savepoint being opened, it is guaranteed |
| @@ -69071,62 +69307,62 @@ | ||
| 69071 | 69307 | db->nStatement+db->nSavepoint); |
| 69072 | 69308 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69073 | 69309 | #endif |
| 69074 | 69310 | |
| 69075 | 69311 | /* Create a new savepoint structure. */ |
| 69076 | - pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1); | |
| 69077 | - if( pNew ){ | |
| 69078 | - pNew->zName = (char *)&pNew[1]; | |
| 69079 | - memcpy(pNew->zName, zName, nName+1); | |
| 69080 | - | |
| 69312 | + u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1); | |
| 69313 | + if( u.at.pNew ){ | |
| 69314 | + u.at.pNew->zName = (char *)&u.at.pNew[1]; | |
| 69315 | + memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1); | |
| 69316 | + | |
| 69081 | 69317 | /* If there is no open transaction, then mark this as a special |
| 69082 | 69318 | ** "transaction savepoint". */ |
| 69083 | 69319 | if( db->autoCommit ){ |
| 69084 | 69320 | db->autoCommit = 0; |
| 69085 | 69321 | db->isTransactionSavepoint = 1; |
| 69086 | 69322 | }else{ |
| 69087 | 69323 | db->nSavepoint++; |
| 69088 | 69324 | } |
| 69089 | - | |
| 69325 | + | |
| 69090 | 69326 | /* Link the new savepoint into the database handle's list. */ |
| 69091 | - pNew->pNext = db->pSavepoint; | |
| 69092 | - db->pSavepoint = pNew; | |
| 69093 | - pNew->nDeferredCons = db->nDeferredCons; | |
| 69094 | - pNew->nDeferredImmCons = db->nDeferredImmCons; | |
| 69327 | + u.at.pNew->pNext = db->pSavepoint; | |
| 69328 | + db->pSavepoint = u.at.pNew; | |
| 69329 | + u.at.pNew->nDeferredCons = db->nDeferredCons; | |
| 69330 | + u.at.pNew->nDeferredImmCons = db->nDeferredImmCons; | |
| 69095 | 69331 | } |
| 69096 | 69332 | } |
| 69097 | 69333 | }else{ |
| 69098 | - iSavepoint = 0; | |
| 69334 | + u.at.iSavepoint = 0; | |
| 69099 | 69335 | |
| 69100 | 69336 | /* Find the named savepoint. If there is no such savepoint, then an |
| 69101 | 69337 | ** an error is returned to the user. */ |
| 69102 | 69338 | for( |
| 69103 | - pSavepoint = db->pSavepoint; | |
| 69104 | - pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName); | |
| 69105 | - pSavepoint = pSavepoint->pNext | |
| 69339 | + u.at.pSavepoint = db->pSavepoint; | |
| 69340 | + u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName); | |
| 69341 | + u.at.pSavepoint = u.at.pSavepoint->pNext | |
| 69106 | 69342 | ){ |
| 69107 | - iSavepoint++; | |
| 69343 | + u.at.iSavepoint++; | |
| 69108 | 69344 | } |
| 69109 | - if( !pSavepoint ){ | |
| 69110 | - sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName); | |
| 69345 | + if( !u.at.pSavepoint ){ | |
| 69346 | + sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName); | |
| 69111 | 69347 | rc = SQLITE_ERROR; |
| 69112 | - }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){ | |
| 69113 | - /* It is not possible to release (commit) a savepoint if there are | |
| 69348 | + }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){ | |
| 69349 | + /* It is not possible to release (commit) a savepoint if there are | |
| 69114 | 69350 | ** active write statements. |
| 69115 | 69351 | */ |
| 69116 | - sqlite3SetString(&p->zErrMsg, db, | |
| 69352 | + sqlite3SetString(&p->zErrMsg, db, | |
| 69117 | 69353 | "cannot release savepoint - SQL statements in progress" |
| 69118 | 69354 | ); |
| 69119 | 69355 | rc = SQLITE_BUSY; |
| 69120 | 69356 | }else{ |
| 69121 | 69357 | |
| 69122 | 69358 | /* Determine whether or not this is a transaction savepoint. If so, |
| 69123 | - ** and this is a RELEASE command, then the current transaction | |
| 69124 | - ** is committed. | |
| 69359 | + ** and this is a RELEASE command, then the current transaction | |
| 69360 | + ** is committed. | |
| 69125 | 69361 | */ |
| 69126 | - int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint; | |
| 69127 | - if( isTransaction && p1==SAVEPOINT_RELEASE ){ | |
| 69362 | + int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint; | |
| 69363 | + if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){ | |
| 69128 | 69364 | if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 69129 | 69365 | goto vdbe_return; |
| 69130 | 69366 | } |
| 69131 | 69367 | db->autoCommit = 1; |
| 69132 | 69368 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| @@ -69136,56 +69372,56 @@ | ||
| 69136 | 69372 | goto vdbe_return; |
| 69137 | 69373 | } |
| 69138 | 69374 | db->isTransactionSavepoint = 0; |
| 69139 | 69375 | rc = p->rc; |
| 69140 | 69376 | }else{ |
| 69141 | - iSavepoint = db->nSavepoint - iSavepoint - 1; | |
| 69142 | - if( p1==SAVEPOINT_ROLLBACK ){ | |
| 69143 | - for(ii=0; ii<db->nDb; ii++){ | |
| 69144 | - sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT); | |
| 69377 | + u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1; | |
| 69378 | + if( u.at.p1==SAVEPOINT_ROLLBACK ){ | |
| 69379 | + for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){ | |
| 69380 | + sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT); | |
| 69145 | 69381 | } |
| 69146 | 69382 | } |
| 69147 | - for(ii=0; ii<db->nDb; ii++){ | |
| 69148 | - rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint); | |
| 69383 | + for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){ | |
| 69384 | + rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint); | |
| 69149 | 69385 | if( rc!=SQLITE_OK ){ |
| 69150 | 69386 | goto abort_due_to_error; |
| 69151 | 69387 | } |
| 69152 | 69388 | } |
| 69153 | - if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ | |
| 69389 | + if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ | |
| 69154 | 69390 | sqlite3ExpirePreparedStatements(db); |
| 69155 | 69391 | sqlite3ResetAllSchemasOfConnection(db); |
| 69156 | 69392 | db->flags = (db->flags | SQLITE_InternChanges); |
| 69157 | 69393 | } |
| 69158 | 69394 | } |
| 69159 | - | |
| 69160 | - /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all | |
| 69395 | + | |
| 69396 | + /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all | |
| 69161 | 69397 | ** savepoints nested inside of the savepoint being operated on. */ |
| 69162 | - while( db->pSavepoint!=pSavepoint ){ | |
| 69163 | - pTmp = db->pSavepoint; | |
| 69164 | - db->pSavepoint = pTmp->pNext; | |
| 69165 | - sqlite3DbFree(db, pTmp); | |
| 69398 | + while( db->pSavepoint!=u.at.pSavepoint ){ | |
| 69399 | + u.at.pTmp = db->pSavepoint; | |
| 69400 | + db->pSavepoint = u.at.pTmp->pNext; | |
| 69401 | + sqlite3DbFree(db, u.at.pTmp); | |
| 69166 | 69402 | db->nSavepoint--; |
| 69167 | 69403 | } |
| 69168 | 69404 | |
| 69169 | - /* If it is a RELEASE, then destroy the savepoint being operated on | |
| 69170 | - ** too. If it is a ROLLBACK TO, then set the number of deferred | |
| 69405 | + /* If it is a RELEASE, then destroy the savepoint being operated on | |
| 69406 | + ** too. If it is a ROLLBACK TO, then set the number of deferred | |
| 69171 | 69407 | ** constraint violations present in the database to the value stored |
| 69172 | 69408 | ** when the savepoint was created. */ |
| 69173 | - if( p1==SAVEPOINT_RELEASE ){ | |
| 69174 | - assert( pSavepoint==db->pSavepoint ); | |
| 69175 | - db->pSavepoint = pSavepoint->pNext; | |
| 69176 | - sqlite3DbFree(db, pSavepoint); | |
| 69409 | + if( u.at.p1==SAVEPOINT_RELEASE ){ | |
| 69410 | + assert( u.at.pSavepoint==db->pSavepoint ); | |
| 69411 | + db->pSavepoint = u.at.pSavepoint->pNext; | |
| 69412 | + sqlite3DbFree(db, u.at.pSavepoint); | |
| 69177 | 69413 | if( !isTransaction ){ |
| 69178 | 69414 | db->nSavepoint--; |
| 69179 | 69415 | } |
| 69180 | 69416 | }else{ |
| 69181 | - db->nDeferredCons = pSavepoint->nDeferredCons; | |
| 69182 | - db->nDeferredImmCons = pSavepoint->nDeferredImmCons; | |
| 69417 | + db->nDeferredCons = u.at.pSavepoint->nDeferredCons; | |
| 69418 | + db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons; | |
| 69183 | 69419 | } |
| 69184 | 69420 | |
| 69185 | 69421 | if( !isTransaction ){ |
| 69186 | - rc = sqlite3VtabSavepoint(db, p1, iSavepoint); | |
| 69422 | + rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint); | |
| 69187 | 69423 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69188 | 69424 | } |
| 69189 | 69425 | } |
| 69190 | 69426 | } |
| 69191 | 69427 | |
| @@ -69200,52 +69436,54 @@ | ||
| 69200 | 69436 | ** there are active writing VMs or active VMs that use shared cache. |
| 69201 | 69437 | ** |
| 69202 | 69438 | ** This instruction causes the VM to halt. |
| 69203 | 69439 | */ |
| 69204 | 69440 | case OP_AutoCommit: { |
| 69441 | +#if 0 /* local variables moved into u.au */ | |
| 69205 | 69442 | int desiredAutoCommit; |
| 69206 | 69443 | int iRollback; |
| 69207 | 69444 | int turnOnAC; |
| 69445 | +#endif /* local variables moved into u.au */ | |
| 69208 | 69446 | |
| 69209 | - desiredAutoCommit = pOp->p1; | |
| 69210 | - iRollback = pOp->p2; | |
| 69211 | - turnOnAC = desiredAutoCommit && !db->autoCommit; | |
| 69212 | - assert( desiredAutoCommit==1 || desiredAutoCommit==0 ); | |
| 69213 | - assert( desiredAutoCommit==1 || iRollback==0 ); | |
| 69447 | + u.au.desiredAutoCommit = pOp->p1; | |
| 69448 | + u.au.iRollback = pOp->p2; | |
| 69449 | + u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit; | |
| 69450 | + assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 ); | |
| 69451 | + assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 ); | |
| 69214 | 69452 | assert( db->nVdbeActive>0 ); /* At least this one VM is active */ |
| 69215 | 69453 | assert( p->bIsReader ); |
| 69216 | 69454 | |
| 69217 | 69455 | #if 0 |
| 69218 | - if( turnOnAC && iRollback && db->nVdbeActive>1 ){ | |
| 69456 | + if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){ | |
| 69219 | 69457 | /* If this instruction implements a ROLLBACK and other VMs are |
| 69220 | 69458 | ** still running, and a transaction is active, return an error indicating |
| 69221 | - ** that the other VMs must complete first. | |
| 69459 | + ** that the other VMs must complete first. | |
| 69222 | 69460 | */ |
| 69223 | 69461 | sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - " |
| 69224 | 69462 | "SQL statements in progress"); |
| 69225 | 69463 | rc = SQLITE_BUSY; |
| 69226 | 69464 | }else |
| 69227 | 69465 | #endif |
| 69228 | - if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){ | |
| 69466 | + if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){ | |
| 69229 | 69467 | /* If this instruction implements a COMMIT and other VMs are writing |
| 69230 | - ** return an error indicating that the other VMs must complete first. | |
| 69468 | + ** return an error indicating that the other VMs must complete first. | |
| 69231 | 69469 | */ |
| 69232 | 69470 | sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - " |
| 69233 | 69471 | "SQL statements in progress"); |
| 69234 | 69472 | rc = SQLITE_BUSY; |
| 69235 | - }else if( desiredAutoCommit!=db->autoCommit ){ | |
| 69236 | - if( iRollback ){ | |
| 69237 | - assert( desiredAutoCommit==1 ); | |
| 69473 | + }else if( u.au.desiredAutoCommit!=db->autoCommit ){ | |
| 69474 | + if( u.au.iRollback ){ | |
| 69475 | + assert( u.au.desiredAutoCommit==1 ); | |
| 69238 | 69476 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 69239 | 69477 | db->autoCommit = 1; |
| 69240 | 69478 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 69241 | 69479 | goto vdbe_return; |
| 69242 | 69480 | }else{ |
| 69243 | - db->autoCommit = (u8)desiredAutoCommit; | |
| 69481 | + db->autoCommit = (u8)u.au.desiredAutoCommit; | |
| 69244 | 69482 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 69245 | 69483 | p->pc = pc; |
| 69246 | - db->autoCommit = (u8)(1-desiredAutoCommit); | |
| 69484 | + db->autoCommit = (u8)(1-u.au.desiredAutoCommit); | |
| 69247 | 69485 | p->rc = rc = SQLITE_BUSY; |
| 69248 | 69486 | goto vdbe_return; |
| 69249 | 69487 | } |
| 69250 | 69488 | } |
| 69251 | 69489 | assert( db->nStatement==0 ); |
| @@ -69256,14 +69494,14 @@ | ||
| 69256 | 69494 | rc = SQLITE_ERROR; |
| 69257 | 69495 | } |
| 69258 | 69496 | goto vdbe_return; |
| 69259 | 69497 | }else{ |
| 69260 | 69498 | sqlite3SetString(&p->zErrMsg, db, |
| 69261 | - (!desiredAutoCommit)?"cannot start a transaction within a transaction":( | |
| 69262 | - (iRollback)?"cannot rollback - no transaction is active": | |
| 69499 | + (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":( | |
| 69500 | + (u.au.iRollback)?"cannot rollback - no transaction is active": | |
| 69263 | 69501 | "cannot commit - no transaction is active")); |
| 69264 | - | |
| 69502 | + | |
| 69265 | 69503 | rc = SQLITE_ERROR; |
| 69266 | 69504 | } |
| 69267 | 69505 | break; |
| 69268 | 69506 | } |
| 69269 | 69507 | |
| @@ -69297,46 +69535,48 @@ | ||
| 69297 | 69535 | ** will automatically commit when the VDBE halts. |
| 69298 | 69536 | ** |
| 69299 | 69537 | ** If P2 is zero, then a read-lock is obtained on the database file. |
| 69300 | 69538 | */ |
| 69301 | 69539 | case OP_Transaction: { |
| 69540 | +#if 0 /* local variables moved into u.av */ | |
| 69302 | 69541 | Btree *pBt; |
| 69542 | +#endif /* local variables moved into u.av */ | |
| 69303 | 69543 | |
| 69304 | 69544 | assert( p->bIsReader ); |
| 69305 | 69545 | assert( p->readOnly==0 || pOp->p2==0 ); |
| 69306 | 69546 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69307 | 69547 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69308 | 69548 | if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ |
| 69309 | 69549 | rc = SQLITE_READONLY; |
| 69310 | 69550 | goto abort_due_to_error; |
| 69311 | 69551 | } |
| 69312 | - pBt = db->aDb[pOp->p1].pBt; | |
| 69552 | + u.av.pBt = db->aDb[pOp->p1].pBt; | |
| 69313 | 69553 | |
| 69314 | - if( pBt ){ | |
| 69315 | - rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); | |
| 69554 | + if( u.av.pBt ){ | |
| 69555 | + rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2); | |
| 69316 | 69556 | if( rc==SQLITE_BUSY ){ |
| 69317 | 69557 | p->pc = pc; |
| 69318 | 69558 | p->rc = rc = SQLITE_BUSY; |
| 69319 | 69559 | goto vdbe_return; |
| 69320 | 69560 | } |
| 69321 | 69561 | if( rc!=SQLITE_OK ){ |
| 69322 | 69562 | goto abort_due_to_error; |
| 69323 | 69563 | } |
| 69324 | 69564 | |
| 69325 | - if( pOp->p2 && p->usesStmtJournal | |
| 69326 | - && (db->autoCommit==0 || db->nVdbeRead>1) | |
| 69565 | + if( pOp->p2 && p->usesStmtJournal | |
| 69566 | + && (db->autoCommit==0 || db->nVdbeRead>1) | |
| 69327 | 69567 | ){ |
| 69328 | - assert( sqlite3BtreeIsInTrans(pBt) ); | |
| 69568 | + assert( sqlite3BtreeIsInTrans(u.av.pBt) ); | |
| 69329 | 69569 | if( p->iStatement==0 ){ |
| 69330 | 69570 | assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 69331 | - db->nStatement++; | |
| 69571 | + db->nStatement++; | |
| 69332 | 69572 | p->iStatement = db->nSavepoint + db->nStatement; |
| 69333 | 69573 | } |
| 69334 | 69574 | |
| 69335 | 69575 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1); |
| 69336 | 69576 | if( rc==SQLITE_OK ){ |
| 69337 | - rc = sqlite3BtreeBeginStmt(pBt, p->iStatement); | |
| 69577 | + rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement); | |
| 69338 | 69578 | } |
| 69339 | 69579 | |
| 69340 | 69580 | /* Store the current value of the database handles deferred constraint |
| 69341 | 69581 | ** counter. If the statement transaction needs to be rolled back, |
| 69342 | 69582 | ** the value of this counter needs to be restored too. */ |
| @@ -69358,24 +69598,26 @@ | ||
| 69358 | 69598 | ** There must be a read-lock on the database (either a transaction |
| 69359 | 69599 | ** must be started or there must be an open cursor) before |
| 69360 | 69600 | ** executing this instruction. |
| 69361 | 69601 | */ |
| 69362 | 69602 | case OP_ReadCookie: { /* out2-prerelease */ |
| 69603 | +#if 0 /* local variables moved into u.aw */ | |
| 69363 | 69604 | int iMeta; |
| 69364 | 69605 | int iDb; |
| 69365 | 69606 | int iCookie; |
| 69607 | +#endif /* local variables moved into u.aw */ | |
| 69366 | 69608 | |
| 69367 | 69609 | assert( p->bIsReader ); |
| 69368 | - iDb = pOp->p1; | |
| 69369 | - iCookie = pOp->p3; | |
| 69610 | + u.aw.iDb = pOp->p1; | |
| 69611 | + u.aw.iCookie = pOp->p3; | |
| 69370 | 69612 | assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 69371 | - assert( iDb>=0 && iDb<db->nDb ); | |
| 69372 | - assert( db->aDb[iDb].pBt!=0 ); | |
| 69373 | - assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); | |
| 69613 | + assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb ); | |
| 69614 | + assert( db->aDb[u.aw.iDb].pBt!=0 ); | |
| 69615 | + assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 ); | |
| 69374 | 69616 | |
| 69375 | - sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); | |
| 69376 | - pOut->u.i = iMeta; | |
| 69617 | + sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta); | |
| 69618 | + pOut->u.i = u.aw.iMeta; | |
| 69377 | 69619 | break; |
| 69378 | 69620 | } |
| 69379 | 69621 | |
| 69380 | 69622 | /* Opcode: SetCookie P1 P2 P3 * * |
| 69381 | 69623 | ** |
| @@ -69386,29 +69628,31 @@ | ||
| 69386 | 69628 | ** database file used to store temporary tables. |
| 69387 | 69629 | ** |
| 69388 | 69630 | ** A transaction must be started before executing this opcode. |
| 69389 | 69631 | */ |
| 69390 | 69632 | case OP_SetCookie: { /* in3 */ |
| 69633 | +#if 0 /* local variables moved into u.ax */ | |
| 69391 | 69634 | Db *pDb; |
| 69635 | +#endif /* local variables moved into u.ax */ | |
| 69392 | 69636 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 69393 | 69637 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69394 | 69638 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69395 | 69639 | assert( p->readOnly==0 ); |
| 69396 | - pDb = &db->aDb[pOp->p1]; | |
| 69397 | - assert( pDb->pBt!=0 ); | |
| 69640 | + u.ax.pDb = &db->aDb[pOp->p1]; | |
| 69641 | + assert( u.ax.pDb->pBt!=0 ); | |
| 69398 | 69642 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69399 | 69643 | pIn3 = &aMem[pOp->p3]; |
| 69400 | 69644 | sqlite3VdbeMemIntegerify(pIn3); |
| 69401 | 69645 | /* See note about index shifting on OP_ReadCookie */ |
| 69402 | - rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i); | |
| 69646 | + rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i); | |
| 69403 | 69647 | if( pOp->p2==BTREE_SCHEMA_VERSION ){ |
| 69404 | 69648 | /* When the schema cookie changes, record the new cookie internally */ |
| 69405 | - pDb->pSchema->schema_cookie = (int)pIn3->u.i; | |
| 69649 | + u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i; | |
| 69406 | 69650 | db->flags |= SQLITE_InternChanges; |
| 69407 | 69651 | }else if( pOp->p2==BTREE_FILE_FORMAT ){ |
| 69408 | 69652 | /* Record changes in the file format */ |
| 69409 | - pDb->pSchema->file_format = (u8)pIn3->u.i; | |
| 69653 | + u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i; | |
| 69410 | 69654 | } |
| 69411 | 69655 | if( pOp->p1==1 ){ |
| 69412 | 69656 | /* Invalidate all prepared statements whenever the TEMP database |
| 69413 | 69657 | ** schema is changed. Ticket #1644 */ |
| 69414 | 69658 | sqlite3ExpirePreparedStatements(db); |
| @@ -69434,42 +69678,44 @@ | ||
| 69434 | 69678 | ** Either a transaction needs to have been started or an OP_Open needs |
| 69435 | 69679 | ** to be executed (to establish a read lock) before this opcode is |
| 69436 | 69680 | ** invoked. |
| 69437 | 69681 | */ |
| 69438 | 69682 | case OP_VerifyCookie: { |
| 69683 | +#if 0 /* local variables moved into u.ay */ | |
| 69439 | 69684 | int iMeta; |
| 69440 | 69685 | int iGen; |
| 69441 | 69686 | Btree *pBt; |
| 69687 | +#endif /* local variables moved into u.ay */ | |
| 69442 | 69688 | |
| 69443 | 69689 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69444 | 69690 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69445 | 69691 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69446 | 69692 | assert( p->bIsReader ); |
| 69447 | - pBt = db->aDb[pOp->p1].pBt; | |
| 69448 | - if( pBt ){ | |
| 69449 | - sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta); | |
| 69450 | - iGen = db->aDb[pOp->p1].pSchema->iGeneration; | |
| 69693 | + u.ay.pBt = db->aDb[pOp->p1].pBt; | |
| 69694 | + if( u.ay.pBt ){ | |
| 69695 | + sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta); | |
| 69696 | + u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration; | |
| 69451 | 69697 | }else{ |
| 69452 | - iGen = iMeta = 0; | |
| 69698 | + u.ay.iGen = u.ay.iMeta = 0; | |
| 69453 | 69699 | } |
| 69454 | - if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){ | |
| 69700 | + if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){ | |
| 69455 | 69701 | sqlite3DbFree(db, p->zErrMsg); |
| 69456 | 69702 | p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 69457 | - /* If the schema-cookie from the database file matches the cookie | |
| 69703 | + /* If the schema-cookie from the database file matches the cookie | |
| 69458 | 69704 | ** stored with the in-memory representation of the schema, do |
| 69459 | 69705 | ** not reload the schema from the database file. |
| 69460 | 69706 | ** |
| 69461 | 69707 | ** If virtual-tables are in use, this is not just an optimization. |
| 69462 | 69708 | ** Often, v-tables store their data in other SQLite tables, which |
| 69463 | 69709 | ** are queried from within xNext() and other v-table methods using |
| 69464 | 69710 | ** prepared queries. If such a query is out-of-date, we do not want to |
| 69465 | 69711 | ** discard the database schema, as the user code implementing the |
| 69466 | 69712 | ** v-table would have to be ready for the sqlite3_vtab structure itself |
| 69467 | - ** to be invalidated whenever sqlite3_step() is called from within | |
| 69713 | + ** to be invalidated whenever sqlite3_step() is called from within | |
| 69468 | 69714 | ** a v-table method. |
| 69469 | 69715 | */ |
| 69470 | - if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){ | |
| 69716 | + if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){ | |
| 69471 | 69717 | sqlite3ResetOneSchema(db, pOp->p1); |
| 69472 | 69718 | } |
| 69473 | 69719 | |
| 69474 | 69720 | p->expired = 1; |
| 69475 | 69721 | rc = SQLITE_SCHEMA; |
| @@ -69528,18 +69774,20 @@ | ||
| 69528 | 69774 | ** |
| 69529 | 69775 | ** See also OpenRead. |
| 69530 | 69776 | */ |
| 69531 | 69777 | case OP_OpenRead: |
| 69532 | 69778 | case OP_OpenWrite: { |
| 69779 | +#if 0 /* local variables moved into u.az */ | |
| 69533 | 69780 | int nField; |
| 69534 | 69781 | KeyInfo *pKeyInfo; |
| 69535 | 69782 | int p2; |
| 69536 | 69783 | int iDb; |
| 69537 | 69784 | int wrFlag; |
| 69538 | 69785 | Btree *pX; |
| 69539 | 69786 | VdbeCursor *pCur; |
| 69540 | 69787 | Db *pDb; |
| 69788 | +#endif /* local variables moved into u.az */ | |
| 69541 | 69789 | |
| 69542 | 69790 | assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 ); |
| 69543 | 69791 | assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 ); |
| 69544 | 69792 | assert( p->bIsReader ); |
| 69545 | 69793 | assert( pOp->opcode==OP_OpenRead || p->readOnly==0 ); |
| @@ -69547,74 +69795,74 @@ | ||
| 69547 | 69795 | if( p->expired ){ |
| 69548 | 69796 | rc = SQLITE_ABORT; |
| 69549 | 69797 | break; |
| 69550 | 69798 | } |
| 69551 | 69799 | |
| 69552 | - nField = 0; | |
| 69553 | - pKeyInfo = 0; | |
| 69554 | - p2 = pOp->p2; | |
| 69555 | - iDb = pOp->p3; | |
| 69556 | - assert( iDb>=0 && iDb<db->nDb ); | |
| 69557 | - assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); | |
| 69558 | - pDb = &db->aDb[iDb]; | |
| 69559 | - pX = pDb->pBt; | |
| 69560 | - assert( pX!=0 ); | |
| 69800 | + u.az.nField = 0; | |
| 69801 | + u.az.pKeyInfo = 0; | |
| 69802 | + u.az.p2 = pOp->p2; | |
| 69803 | + u.az.iDb = pOp->p3; | |
| 69804 | + assert( u.az.iDb>=0 && u.az.iDb<db->nDb ); | |
| 69805 | + assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 ); | |
| 69806 | + u.az.pDb = &db->aDb[u.az.iDb]; | |
| 69807 | + u.az.pX = u.az.pDb->pBt; | |
| 69808 | + assert( u.az.pX!=0 ); | |
| 69561 | 69809 | if( pOp->opcode==OP_OpenWrite ){ |
| 69562 | - wrFlag = 1; | |
| 69563 | - assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); | |
| 69564 | - if( pDb->pSchema->file_format < p->minWriteFileFormat ){ | |
| 69565 | - p->minWriteFileFormat = pDb->pSchema->file_format; | |
| 69810 | + u.az.wrFlag = 1; | |
| 69811 | + assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) ); | |
| 69812 | + if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){ | |
| 69813 | + p->minWriteFileFormat = u.az.pDb->pSchema->file_format; | |
| 69566 | 69814 | } |
| 69567 | 69815 | }else{ |
| 69568 | - wrFlag = 0; | |
| 69816 | + u.az.wrFlag = 0; | |
| 69569 | 69817 | } |
| 69570 | 69818 | if( pOp->p5 & OPFLAG_P2ISREG ){ |
| 69571 | - assert( p2>0 ); | |
| 69572 | - assert( p2<=(p->nMem-p->nCursor) ); | |
| 69573 | - pIn2 = &aMem[p2]; | |
| 69819 | + assert( u.az.p2>0 ); | |
| 69820 | + assert( u.az.p2<=(p->nMem-p->nCursor) ); | |
| 69821 | + pIn2 = &aMem[u.az.p2]; | |
| 69574 | 69822 | assert( memIsValid(pIn2) ); |
| 69575 | 69823 | assert( (pIn2->flags & MEM_Int)!=0 ); |
| 69576 | 69824 | sqlite3VdbeMemIntegerify(pIn2); |
| 69577 | - p2 = (int)pIn2->u.i; | |
| 69578 | - /* The p2 value always comes from a prior OP_CreateTable opcode and | |
| 69579 | - ** that opcode will always set the p2 value to 2 or more or else fail. | |
| 69825 | + u.az.p2 = (int)pIn2->u.i; | |
| 69826 | + /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and | |
| 69827 | + ** that opcode will always set the u.az.p2 value to 2 or more or else fail. | |
| 69580 | 69828 | ** If there were a failure, the prepared statement would have halted |
| 69581 | 69829 | ** before reaching this instruction. */ |
| 69582 | - if( NEVER(p2<2) ) { | |
| 69830 | + if( NEVER(u.az.p2<2) ) { | |
| 69583 | 69831 | rc = SQLITE_CORRUPT_BKPT; |
| 69584 | 69832 | goto abort_due_to_error; |
| 69585 | 69833 | } |
| 69586 | 69834 | } |
| 69587 | 69835 | if( pOp->p4type==P4_KEYINFO ){ |
| 69588 | - pKeyInfo = pOp->p4.pKeyInfo; | |
| 69589 | - assert( pKeyInfo->enc==ENC(db) ); | |
| 69590 | - assert( pKeyInfo->db==db ); | |
| 69591 | - nField = pKeyInfo->nField+pKeyInfo->nXField; | |
| 69836 | + u.az.pKeyInfo = pOp->p4.pKeyInfo; | |
| 69837 | + assert( u.az.pKeyInfo->enc==ENC(db) ); | |
| 69838 | + assert( u.az.pKeyInfo->db==db ); | |
| 69839 | + u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField; | |
| 69592 | 69840 | }else if( pOp->p4type==P4_INT32 ){ |
| 69593 | - nField = pOp->p4.i; | |
| 69841 | + u.az.nField = pOp->p4.i; | |
| 69594 | 69842 | } |
| 69595 | 69843 | assert( pOp->p1>=0 ); |
| 69596 | - assert( nField>=0 ); | |
| 69597 | - testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ | |
| 69598 | - pCur = allocateCursor(p, pOp->p1, nField, iDb, 1); | |
| 69599 | - if( pCur==0 ) goto no_mem; | |
| 69600 | - pCur->nullRow = 1; | |
| 69601 | - pCur->isOrdered = 1; | |
| 69602 | - rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor); | |
| 69603 | - pCur->pKeyInfo = pKeyInfo; | |
| 69844 | + assert( u.az.nField>=0 ); | |
| 69845 | + testcase( u.az.nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ | |
| 69846 | + u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1); | |
| 69847 | + if( u.az.pCur==0 ) goto no_mem; | |
| 69848 | + u.az.pCur->nullRow = 1; | |
| 69849 | + u.az.pCur->isOrdered = 1; | |
| 69850 | + rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor); | |
| 69851 | + u.az.pCur->pKeyInfo = u.az.pKeyInfo; | |
| 69604 | 69852 | assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); |
| 69605 | - sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR)); | |
| 69853 | + sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR)); | |
| 69606 | 69854 | |
| 69607 | 69855 | /* Since it performs no memory allocation or IO, the only value that |
| 69608 | 69856 | ** sqlite3BtreeCursor() may return is SQLITE_OK. */ |
| 69609 | 69857 | assert( rc==SQLITE_OK ); |
| 69610 | 69858 | |
| 69611 | 69859 | /* Set the VdbeCursor.isTable variable. Previous versions of |
| 69612 | 69860 | ** SQLite used to check if the root-page flags were sane at this point |
| 69613 | 69861 | ** and report database corruption if they were not, but this check has |
| 69614 | - ** since moved into the btree layer. */ | |
| 69615 | - pCur->isTable = pOp->p4type!=P4_KEYINFO; | |
| 69862 | + ** since moved into the btree layer. */ | |
| 69863 | + u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO; | |
| 69616 | 69864 | break; |
| 69617 | 69865 | } |
| 69618 | 69866 | |
| 69619 | 69867 | /* Opcode: OpenEphemeral P1 P2 * P4 P5 |
| 69620 | 69868 | ** Synopsis: nColumn=P2 |
| @@ -69642,53 +69890,55 @@ | ||
| 69642 | 69890 | ** by this opcode will be used for automatically created transient |
| 69643 | 69891 | ** indices in joins. |
| 69644 | 69892 | */ |
| 69645 | 69893 | case OP_OpenAutoindex: |
| 69646 | 69894 | case OP_OpenEphemeral: { |
| 69895 | +#if 0 /* local variables moved into u.ba */ | |
| 69647 | 69896 | VdbeCursor *pCx; |
| 69648 | 69897 | KeyInfo *pKeyInfo; |
| 69898 | +#endif /* local variables moved into u.ba */ | |
| 69649 | 69899 | |
| 69650 | - static const int vfsFlags = | |
| 69900 | + static const int vfsFlags = | |
| 69651 | 69901 | SQLITE_OPEN_READWRITE | |
| 69652 | 69902 | SQLITE_OPEN_CREATE | |
| 69653 | 69903 | SQLITE_OPEN_EXCLUSIVE | |
| 69654 | 69904 | SQLITE_OPEN_DELETEONCLOSE | |
| 69655 | 69905 | SQLITE_OPEN_TRANSIENT_DB; |
| 69656 | 69906 | assert( pOp->p1>=0 ); |
| 69657 | 69907 | assert( pOp->p2>=0 ); |
| 69658 | - pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); | |
| 69659 | - if( pCx==0 ) goto no_mem; | |
| 69660 | - pCx->nullRow = 1; | |
| 69661 | - rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt, | |
| 69908 | + u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); | |
| 69909 | + if( u.ba.pCx==0 ) goto no_mem; | |
| 69910 | + u.ba.pCx->nullRow = 1; | |
| 69911 | + rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt, | |
| 69662 | 69912 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| 69663 | 69913 | if( rc==SQLITE_OK ){ |
| 69664 | - rc = sqlite3BtreeBeginTrans(pCx->pBt, 1); | |
| 69914 | + rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1); | |
| 69665 | 69915 | } |
| 69666 | 69916 | if( rc==SQLITE_OK ){ |
| 69667 | 69917 | /* If a transient index is required, create it by calling |
| 69668 | 69918 | ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before |
| 69669 | 69919 | ** opening it. If a transient table is required, just use the |
| 69670 | 69920 | ** automatically created table with root-page 1 (an BLOB_INTKEY table). |
| 69671 | 69921 | */ |
| 69672 | - if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ | |
| 69922 | + if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ | |
| 69673 | 69923 | int pgno; |
| 69674 | 69924 | assert( pOp->p4type==P4_KEYINFO ); |
| 69675 | - rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); | |
| 69925 | + rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); | |
| 69676 | 69926 | if( rc==SQLITE_OK ){ |
| 69677 | 69927 | assert( pgno==MASTER_ROOT+1 ); |
| 69678 | - assert( pKeyInfo->db==db ); | |
| 69679 | - assert( pKeyInfo->enc==ENC(db) ); | |
| 69680 | - pCx->pKeyInfo = pKeyInfo; | |
| 69681 | - rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor); | |
| 69682 | - } | |
| 69683 | - pCx->isTable = 0; | |
| 69684 | - }else{ | |
| 69685 | - rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor); | |
| 69686 | - pCx->isTable = 1; | |
| 69928 | + assert( u.ba.pKeyInfo->db==db ); | |
| 69929 | + assert( u.ba.pKeyInfo->enc==ENC(db) ); | |
| 69930 | + u.ba.pCx->pKeyInfo = u.ba.pKeyInfo; | |
| 69931 | + rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor); | |
| 69932 | + } | |
| 69933 | + u.ba.pCx->isTable = 0; | |
| 69934 | + }else{ | |
| 69935 | + rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor); | |
| 69936 | + u.ba.pCx->isTable = 1; | |
| 69687 | 69937 | } |
| 69688 | 69938 | } |
| 69689 | - pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); | |
| 69939 | + u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); | |
| 69690 | 69940 | break; |
| 69691 | 69941 | } |
| 69692 | 69942 | |
| 69693 | 69943 | /* Opcode: SorterOpen P1 * * P4 * |
| 69694 | 69944 | ** |
| @@ -69695,20 +69945,22 @@ | ||
| 69695 | 69945 | ** This opcode works like OP_OpenEphemeral except that it opens |
| 69696 | 69946 | ** a transient index that is specifically designed to sort large |
| 69697 | 69947 | ** tables using an external merge-sort algorithm. |
| 69698 | 69948 | */ |
| 69699 | 69949 | case OP_SorterOpen: { |
| 69950 | +#if 0 /* local variables moved into u.bb */ | |
| 69700 | 69951 | VdbeCursor *pCx; |
| 69952 | +#endif /* local variables moved into u.bb */ | |
| 69701 | 69953 | |
| 69702 | 69954 | assert( pOp->p1>=0 ); |
| 69703 | 69955 | assert( pOp->p2>=0 ); |
| 69704 | - pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); | |
| 69705 | - if( pCx==0 ) goto no_mem; | |
| 69706 | - pCx->pKeyInfo = pOp->p4.pKeyInfo; | |
| 69707 | - assert( pCx->pKeyInfo->db==db ); | |
| 69708 | - assert( pCx->pKeyInfo->enc==ENC(db) ); | |
| 69709 | - rc = sqlite3VdbeSorterInit(db, pCx); | |
| 69956 | + u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); | |
| 69957 | + if( u.bb.pCx==0 ) goto no_mem; | |
| 69958 | + u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo; | |
| 69959 | + assert( u.bb.pCx->pKeyInfo->db==db ); | |
| 69960 | + assert( u.bb.pCx->pKeyInfo->enc==ENC(db) ); | |
| 69961 | + rc = sqlite3VdbeSorterInit(db, u.bb.pCx); | |
| 69710 | 69962 | break; |
| 69711 | 69963 | } |
| 69712 | 69964 | |
| 69713 | 69965 | /* Opcode: OpenPseudo P1 P2 P3 * P5 |
| 69714 | 69966 | ** Synopsis: content in r[P2@P3] |
| @@ -69726,20 +69978,22 @@ | ||
| 69726 | 69978 | ** |
| 69727 | 69979 | ** P3 is the number of fields in the records that will be stored by |
| 69728 | 69980 | ** the pseudo-table. |
| 69729 | 69981 | */ |
| 69730 | 69982 | case OP_OpenPseudo: { |
| 69983 | +#if 0 /* local variables moved into u.bc */ | |
| 69731 | 69984 | VdbeCursor *pCx; |
| 69985 | +#endif /* local variables moved into u.bc */ | |
| 69732 | 69986 | |
| 69733 | 69987 | assert( pOp->p1>=0 ); |
| 69734 | 69988 | assert( pOp->p3>=0 ); |
| 69735 | - pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); | |
| 69736 | - if( pCx==0 ) goto no_mem; | |
| 69737 | - pCx->nullRow = 1; | |
| 69738 | - pCx->pseudoTableReg = pOp->p2; | |
| 69739 | - pCx->isTable = 1; | |
| 69740 | - pCx->multiPseudo = pOp->p5; | |
| 69989 | + u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); | |
| 69990 | + if( u.bc.pCx==0 ) goto no_mem; | |
| 69991 | + u.bc.pCx->nullRow = 1; | |
| 69992 | + u.bc.pCx->pseudoTableReg = pOp->p2; | |
| 69993 | + u.bc.pCx->isTable = 1; | |
| 69994 | + u.bc.pCx->multiPseudo = pOp->p5; | |
| 69741 | 69995 | break; |
| 69742 | 69996 | } |
| 69743 | 69997 | |
| 69744 | 69998 | /* Opcode: Close P1 * * * * |
| 69745 | 69999 | ** |
| @@ -69811,37 +70065,39 @@ | ||
| 69811 | 70065 | */ |
| 69812 | 70066 | case OP_SeekLt: /* jump, in3 */ |
| 69813 | 70067 | case OP_SeekLe: /* jump, in3 */ |
| 69814 | 70068 | case OP_SeekGe: /* jump, in3 */ |
| 69815 | 70069 | case OP_SeekGt: { /* jump, in3 */ |
| 70070 | +#if 0 /* local variables moved into u.bd */ | |
| 69816 | 70071 | int res; |
| 69817 | 70072 | int oc; |
| 69818 | 70073 | VdbeCursor *pC; |
| 69819 | 70074 | UnpackedRecord r; |
| 69820 | 70075 | int nField; |
| 69821 | 70076 | i64 iKey; /* The rowid we are to seek to */ |
| 70077 | +#endif /* local variables moved into u.bd */ | |
| 69822 | 70078 | |
| 69823 | 70079 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 69824 | 70080 | assert( pOp->p2!=0 ); |
| 69825 | - pC = p->apCsr[pOp->p1]; | |
| 69826 | - assert( pC!=0 ); | |
| 69827 | - assert( pC->pseudoTableReg==0 ); | |
| 70081 | + u.bd.pC = p->apCsr[pOp->p1]; | |
| 70082 | + assert( u.bd.pC!=0 ); | |
| 70083 | + assert( u.bd.pC->pseudoTableReg==0 ); | |
| 69828 | 70084 | assert( OP_SeekLe == OP_SeekLt+1 ); |
| 69829 | 70085 | assert( OP_SeekGe == OP_SeekLt+2 ); |
| 69830 | 70086 | assert( OP_SeekGt == OP_SeekLt+3 ); |
| 69831 | - assert( pC->isOrdered ); | |
| 69832 | - assert( pC->pCursor!=0 ); | |
| 69833 | - oc = pOp->opcode; | |
| 69834 | - pC->nullRow = 0; | |
| 69835 | - if( pC->isTable ){ | |
| 70087 | + assert( u.bd.pC->isOrdered ); | |
| 70088 | + assert( u.bd.pC->pCursor!=0 ); | |
| 70089 | + u.bd.oc = pOp->opcode; | |
| 70090 | + u.bd.pC->nullRow = 0; | |
| 70091 | + if( u.bd.pC->isTable ){ | |
| 69836 | 70092 | /* The input value in P3 might be of any type: integer, real, string, |
| 69837 | 70093 | ** blob, or NULL. But it needs to be an integer before we can do |
| 69838 | 70094 | ** the seek, so covert it. */ |
| 69839 | 70095 | pIn3 = &aMem[pOp->p3]; |
| 69840 | 70096 | applyNumericAffinity(pIn3); |
| 69841 | - iKey = sqlite3VdbeIntValue(pIn3); | |
| 69842 | - pC->rowidIsValid = 0; | |
| 70097 | + u.bd.iKey = sqlite3VdbeIntValue(pIn3); | |
| 70098 | + u.bd.pC->rowidIsValid = 0; | |
| 69843 | 70099 | |
| 69844 | 70100 | /* If the P3 value could not be converted into an integer without |
| 69845 | 70101 | ** loss of information, then special processing is required... */ |
| 69846 | 70102 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 69847 | 70103 | if( (pIn3->flags & MEM_Real)==0 ){ |
| @@ -69849,100 +70105,100 @@ | ||
| 69849 | 70105 | ** then the seek is not possible, so jump to P2 */ |
| 69850 | 70106 | pc = pOp->p2 - 1; |
| 69851 | 70107 | break; |
| 69852 | 70108 | } |
| 69853 | 70109 | |
| 69854 | - /* If the approximation iKey is larger than the actual real search | |
| 70110 | + /* If the approximation u.bd.iKey is larger than the actual real search | |
| 69855 | 70111 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| 69856 | 70112 | ** is 4.9 and the integer approximation 5: |
| 69857 | 70113 | ** |
| 69858 | 70114 | ** (x > 4.9) -> (x >= 5) |
| 69859 | 70115 | ** (x <= 4.9) -> (x < 5) |
| 69860 | 70116 | */ |
| 69861 | - if( pIn3->r<(double)iKey ){ | |
| 69862 | - assert( OP_SeekGe==(OP_SeekGt-1) ); | |
| 69863 | - assert( OP_SeekLt==(OP_SeekLe-1) ); | |
| 69864 | - assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); | |
| 69865 | - if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--; | |
| 69866 | - } | |
| 69867 | - | |
| 69868 | - /* If the approximation iKey is smaller than the actual real search | |
| 69869 | - ** term, substitute <= for < and > for >=. */ | |
| 69870 | - else if( pIn3->r>(double)iKey ){ | |
| 69871 | - assert( OP_SeekLe==(OP_SeekLt+1) ); | |
| 69872 | - assert( OP_SeekGt==(OP_SeekGe+1) ); | |
| 69873 | - assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); | |
| 69874 | - if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++; | |
| 69875 | - } | |
| 69876 | - } | |
| 69877 | - rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res); | |
| 69878 | - if( rc!=SQLITE_OK ){ | |
| 69879 | - goto abort_due_to_error; | |
| 69880 | - } | |
| 69881 | - if( res==0 ){ | |
| 69882 | - pC->rowidIsValid = 1; | |
| 69883 | - pC->lastRowid = iKey; | |
| 69884 | - } | |
| 69885 | - }else{ | |
| 69886 | - nField = pOp->p4.i; | |
| 69887 | - assert( pOp->p4type==P4_INT32 ); | |
| 69888 | - assert( nField>0 ); | |
| 69889 | - r.pKeyInfo = pC->pKeyInfo; | |
| 69890 | - r.nField = (u16)nField; | |
| 69891 | - | |
| 69892 | - /* The next line of code computes as follows, only faster: | |
| 69893 | - ** if( oc==OP_SeekGt || oc==OP_SeekLe ){ | |
| 69894 | - ** r.flags = UNPACKED_INCRKEY; | |
| 69895 | - ** }else{ | |
| 69896 | - ** r.flags = 0; | |
| 69897 | - ** } | |
| 69898 | - */ | |
| 69899 | - r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt))); | |
| 69900 | - assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY ); | |
| 69901 | - assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY ); | |
| 69902 | - assert( oc!=OP_SeekGe || r.flags==0 ); | |
| 69903 | - assert( oc!=OP_SeekLt || r.flags==0 ); | |
| 69904 | - | |
| 69905 | - r.aMem = &aMem[pOp->p3]; | |
| 69906 | -#ifdef SQLITE_DEBUG | |
| 69907 | - { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } | |
| 69908 | -#endif | |
| 69909 | - ExpandBlob(r.aMem); | |
| 69910 | - rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res); | |
| 69911 | - if( rc!=SQLITE_OK ){ | |
| 69912 | - goto abort_due_to_error; | |
| 69913 | - } | |
| 69914 | - pC->rowidIsValid = 0; | |
| 69915 | - } | |
| 69916 | - pC->deferredMoveto = 0; | |
| 69917 | - pC->cacheStatus = CACHE_STALE; | |
| 69918 | -#ifdef SQLITE_TEST | |
| 69919 | - sqlite3_search_count++; | |
| 69920 | -#endif | |
| 69921 | - if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt ); | |
| 69922 | - if( res<0 || (res==0 && oc==OP_SeekGt) ){ | |
| 69923 | - rc = sqlite3BtreeNext(pC->pCursor, &res); | |
| 69924 | - if( rc!=SQLITE_OK ) goto abort_due_to_error; | |
| 69925 | - pC->rowidIsValid = 0; | |
| 69926 | - }else{ | |
| 69927 | - res = 0; | |
| 69928 | - } | |
| 69929 | - }else{ | |
| 69930 | - assert( oc==OP_SeekLt || oc==OP_SeekLe ); | |
| 69931 | - if( res>0 || (res==0 && oc==OP_SeekLt) ){ | |
| 69932 | - rc = sqlite3BtreePrevious(pC->pCursor, &res); | |
| 69933 | - if( rc!=SQLITE_OK ) goto abort_due_to_error; | |
| 69934 | - pC->rowidIsValid = 0; | |
| 69935 | - }else{ | |
| 69936 | - /* res might be negative because the table is empty. Check to | |
| 69937 | - ** see if this is the case. | |
| 69938 | - */ | |
| 69939 | - res = sqlite3BtreeEof(pC->pCursor); | |
| 69940 | - } | |
| 69941 | - } | |
| 69942 | - assert( pOp->p2>0 ); | |
| 69943 | - if( res ){ | |
| 70117 | + if( pIn3->r<(double)u.bd.iKey ){ | |
| 70118 | + assert( OP_SeekGe==(OP_SeekGt-1) ); | |
| 70119 | + assert( OP_SeekLt==(OP_SeekLe-1) ); | |
| 70120 | + assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); | |
| 70121 | + if( (u.bd.oc & 0x0001)==(OP_SeekGt & 0x0001) ) u.bd.oc--; | |
| 70122 | + } | |
| 70123 | + | |
| 70124 | + /* If the approximation u.bd.iKey is smaller than the actual real search | |
| 70125 | + ** term, substitute <= for < and > for >=. */ | |
| 70126 | + else if( pIn3->r>(double)u.bd.iKey ){ | |
| 70127 | + assert( OP_SeekLe==(OP_SeekLt+1) ); | |
| 70128 | + assert( OP_SeekGt==(OP_SeekGe+1) ); | |
| 70129 | + assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); | |
| 70130 | + if( (u.bd.oc & 0x0001)==(OP_SeekLt & 0x0001) ) u.bd.oc++; | |
| 70131 | + } | |
| 70132 | + } | |
| 70133 | + rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res); | |
| 70134 | + if( rc!=SQLITE_OK ){ | |
| 70135 | + goto abort_due_to_error; | |
| 70136 | + } | |
| 70137 | + if( u.bd.res==0 ){ | |
| 70138 | + u.bd.pC->rowidIsValid = 1; | |
| 70139 | + u.bd.pC->lastRowid = u.bd.iKey; | |
| 70140 | + } | |
| 70141 | + }else{ | |
| 70142 | + u.bd.nField = pOp->p4.i; | |
| 70143 | + assert( pOp->p4type==P4_INT32 ); | |
| 70144 | + assert( u.bd.nField>0 ); | |
| 70145 | + u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo; | |
| 70146 | + u.bd.r.nField = (u16)u.bd.nField; | |
| 70147 | + | |
| 70148 | + /* The next line of code computes as follows, only faster: | |
| 70149 | + ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){ | |
| 70150 | + ** u.bd.r.flags = UNPACKED_INCRKEY; | |
| 70151 | + ** }else{ | |
| 70152 | + ** u.bd.r.flags = 0; | |
| 70153 | + ** } | |
| 70154 | + */ | |
| 70155 | + u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt))); | |
| 70156 | + assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY ); | |
| 70157 | + assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY ); | |
| 70158 | + assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 ); | |
| 70159 | + assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 ); | |
| 70160 | + | |
| 70161 | + u.bd.r.aMem = &aMem[pOp->p3]; | |
| 70162 | +#ifdef SQLITE_DEBUG | |
| 70163 | + { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); } | |
| 70164 | +#endif | |
| 70165 | + ExpandBlob(u.bd.r.aMem); | |
| 70166 | + rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res); | |
| 70167 | + if( rc!=SQLITE_OK ){ | |
| 70168 | + goto abort_due_to_error; | |
| 70169 | + } | |
| 70170 | + u.bd.pC->rowidIsValid = 0; | |
| 70171 | + } | |
| 70172 | + u.bd.pC->deferredMoveto = 0; | |
| 70173 | + u.bd.pC->cacheStatus = CACHE_STALE; | |
| 70174 | +#ifdef SQLITE_TEST | |
| 70175 | + sqlite3_search_count++; | |
| 70176 | +#endif | |
| 70177 | + if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt ); | |
| 70178 | + if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){ | |
| 70179 | + rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res); | |
| 70180 | + if( rc!=SQLITE_OK ) goto abort_due_to_error; | |
| 70181 | + u.bd.pC->rowidIsValid = 0; | |
| 70182 | + }else{ | |
| 70183 | + u.bd.res = 0; | |
| 70184 | + } | |
| 70185 | + }else{ | |
| 70186 | + assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe ); | |
| 70187 | + if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){ | |
| 70188 | + rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res); | |
| 70189 | + if( rc!=SQLITE_OK ) goto abort_due_to_error; | |
| 70190 | + u.bd.pC->rowidIsValid = 0; | |
| 70191 | + }else{ | |
| 70192 | + /* u.bd.res might be negative because the table is empty. Check to | |
| 70193 | + ** see if this is the case. | |
| 70194 | + */ | |
| 70195 | + u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor); | |
| 70196 | + } | |
| 70197 | + } | |
| 70198 | + assert( pOp->p2>0 ); | |
| 70199 | + if( u.bd.res ){ | |
| 69944 | 70200 | pc = pOp->p2 - 1; |
| 69945 | 70201 | } |
| 69946 | 70202 | break; |
| 69947 | 70203 | } |
| 69948 | 70204 | |
| @@ -69955,22 +70211,24 @@ | ||
| 69955 | 70211 | ** This is actually a deferred seek. Nothing actually happens until |
| 69956 | 70212 | ** the cursor is used to read a record. That way, if no reads |
| 69957 | 70213 | ** occur, no unnecessary I/O happens. |
| 69958 | 70214 | */ |
| 69959 | 70215 | case OP_Seek: { /* in2 */ |
| 70216 | +#if 0 /* local variables moved into u.be */ | |
| 69960 | 70217 | VdbeCursor *pC; |
| 70218 | +#endif /* local variables moved into u.be */ | |
| 69961 | 70219 | |
| 69962 | 70220 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 69963 | - pC = p->apCsr[pOp->p1]; | |
| 69964 | - assert( pC!=0 ); | |
| 69965 | - assert( pC->pCursor!=0 ); | |
| 69966 | - assert( pC->isTable ); | |
| 69967 | - pC->nullRow = 0; | |
| 70221 | + u.be.pC = p->apCsr[pOp->p1]; | |
| 70222 | + assert( u.be.pC!=0 ); | |
| 70223 | + assert( u.be.pC->pCursor!=0 ); | |
| 70224 | + assert( u.be.pC->isTable ); | |
| 70225 | + u.be.pC->nullRow = 0; | |
| 69968 | 70226 | pIn2 = &aMem[pOp->p2]; |
| 69969 | - pC->movetoTarget = sqlite3VdbeIntValue(pIn2); | |
| 69970 | - pC->rowidIsValid = 0; | |
| 69971 | - pC->deferredMoveto = 1; | |
| 70227 | + u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2); | |
| 70228 | + u.be.pC->rowidIsValid = 0; | |
| 70229 | + u.be.pC->deferredMoveto = 1; | |
| 69972 | 70230 | break; |
| 69973 | 70231 | } |
| 69974 | 70232 | |
| 69975 | 70233 | |
| 69976 | 70234 | /* Opcode: Found P1 P2 P3 P4 * |
| @@ -70021,83 +70279,85 @@ | ||
| 70021 | 70279 | ** See also: NotFound, Found, NotExists |
| 70022 | 70280 | */ |
| 70023 | 70281 | case OP_NoConflict: /* jump, in3 */ |
| 70024 | 70282 | case OP_NotFound: /* jump, in3 */ |
| 70025 | 70283 | case OP_Found: { /* jump, in3 */ |
| 70284 | +#if 0 /* local variables moved into u.bf */ | |
| 70026 | 70285 | int alreadyExists; |
| 70027 | 70286 | int ii; |
| 70028 | 70287 | VdbeCursor *pC; |
| 70029 | 70288 | int res; |
| 70030 | 70289 | char *pFree; |
| 70031 | 70290 | UnpackedRecord *pIdxKey; |
| 70032 | 70291 | UnpackedRecord r; |
| 70033 | 70292 | char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; |
| 70293 | +#endif /* local variables moved into u.bf */ | |
| 70034 | 70294 | |
| 70035 | 70295 | #ifdef SQLITE_TEST |
| 70036 | 70296 | if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++; |
| 70037 | 70297 | #endif |
| 70038 | 70298 | |
| 70299 | + u.bf.alreadyExists = 0; | |
| 70039 | 70300 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70040 | 70301 | assert( pOp->p4type==P4_INT32 ); |
| 70041 | - pC = p->apCsr[pOp->p1]; | |
| 70042 | - assert( pC!=0 ); | |
| 70302 | + u.bf.pC = p->apCsr[pOp->p1]; | |
| 70303 | + assert( u.bf.pC!=0 ); | |
| 70043 | 70304 | pIn3 = &aMem[pOp->p3]; |
| 70044 | - assert( pC->pCursor!=0 ); | |
| 70045 | - assert( pC->isTable==0 ); | |
| 70046 | - pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ | |
| 70305 | + assert( u.bf.pC->pCursor!=0 ); | |
| 70306 | + assert( u.bf.pC->isTable==0 ); | |
| 70047 | 70307 | if( pOp->p4.i>0 ){ |
| 70048 | - r.pKeyInfo = pC->pKeyInfo; | |
| 70049 | - r.nField = (u16)pOp->p4.i; | |
| 70050 | - r.aMem = pIn3; | |
| 70308 | + u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo; | |
| 70309 | + u.bf.r.nField = (u16)pOp->p4.i; | |
| 70310 | + u.bf.r.aMem = pIn3; | |
| 70051 | 70311 | #ifdef SQLITE_DEBUG |
| 70052 | 70312 | { |
| 70053 | 70313 | int i; |
| 70054 | - for(i=0; i<r.nField; i++){ | |
| 70055 | - assert( memIsValid(&r.aMem[i]) ); | |
| 70056 | - if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]); | |
| 70314 | + for(i=0; i<u.bf.r.nField; i++){ | |
| 70315 | + assert( memIsValid(&u.bf.r.aMem[i]) ); | |
| 70316 | + if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]); | |
| 70057 | 70317 | } |
| 70058 | 70318 | } |
| 70059 | 70319 | #endif |
| 70060 | - r.flags = UNPACKED_PREFIX_MATCH; | |
| 70061 | - pIdxKey = &r; | |
| 70320 | + u.bf.r.flags = UNPACKED_PREFIX_MATCH; | |
| 70321 | + u.bf.pIdxKey = &u.bf.r; | |
| 70062 | 70322 | }else{ |
| 70063 | - pIdxKey = sqlite3VdbeAllocUnpackedRecord( | |
| 70064 | - pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree | |
| 70065 | - ); | |
| 70066 | - if( pIdxKey==0 ) goto no_mem; | |
| 70323 | + u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord( | |
| 70324 | + u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree | |
| 70325 | + ); | |
| 70326 | + if( u.bf.pIdxKey==0 ) goto no_mem; | |
| 70067 | 70327 | assert( pIn3->flags & MEM_Blob ); |
| 70068 | 70328 | assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */ |
| 70069 | - sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); | |
| 70070 | - pIdxKey->flags |= UNPACKED_PREFIX_MATCH; | |
| 70329 | + sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey); | |
| 70330 | + u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH; | |
| 70071 | 70331 | } |
| 70072 | 70332 | if( pOp->opcode==OP_NoConflict ){ |
| 70073 | 70333 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 70074 | 70334 | ** input fields are NULL, since any key with a NULL will not |
| 70075 | 70335 | ** conflict */ |
| 70076 | - for(ii=0; ii<r.nField; ii++){ | |
| 70077 | - if( r.aMem[ii].flags & MEM_Null ){ | |
| 70336 | + for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){ | |
| 70337 | + if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){ | |
| 70078 | 70338 | pc = pOp->p2 - 1; |
| 70079 | 70339 | break; |
| 70080 | 70340 | } |
| 70081 | 70341 | } |
| 70082 | 70342 | } |
| 70083 | - rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); | |
| 70343 | + rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res); | |
| 70084 | 70344 | if( pOp->p4.i==0 ){ |
| 70085 | - sqlite3DbFree(db, pFree); | |
| 70345 | + sqlite3DbFree(db, u.bf.pFree); | |
| 70086 | 70346 | } |
| 70087 | 70347 | if( rc!=SQLITE_OK ){ |
| 70088 | 70348 | break; |
| 70089 | 70349 | } |
| 70090 | - pC->seekResult = res; | |
| 70091 | - alreadyExists = (res==0); | |
| 70092 | - pC->nullRow = 1-alreadyExists; | |
| 70093 | - pC->deferredMoveto = 0; | |
| 70094 | - pC->cacheStatus = CACHE_STALE; | |
| 70350 | + u.bf.pC->seekResult = u.bf.res; | |
| 70351 | + u.bf.alreadyExists = (u.bf.res==0); | |
| 70352 | + u.bf.pC->nullRow = 1-u.bf.alreadyExists; | |
| 70353 | + u.bf.pC->deferredMoveto = 0; | |
| 70354 | + u.bf.pC->cacheStatus = CACHE_STALE; | |
| 70095 | 70355 | if( pOp->opcode==OP_Found ){ |
| 70096 | - if( alreadyExists ) pc = pOp->p2 - 1; | |
| 70356 | + if( u.bf.alreadyExists ) pc = pOp->p2 - 1; | |
| 70097 | 70357 | }else{ |
| 70098 | - if( !alreadyExists ) pc = pOp->p2 - 1; | |
| 70358 | + if( !u.bf.alreadyExists ) pc = pOp->p2 - 1; | |
| 70099 | 70359 | } |
| 70100 | 70360 | break; |
| 70101 | 70361 | } |
| 70102 | 70362 | |
| 70103 | 70363 | /* Opcode: NotExists P1 P2 P3 * * |
| @@ -70113,37 +70373,39 @@ | ||
| 70113 | 70373 | ** (with arbitrary multi-value keys). |
| 70114 | 70374 | ** |
| 70115 | 70375 | ** See also: Found, NotFound, NoConflict |
| 70116 | 70376 | */ |
| 70117 | 70377 | case OP_NotExists: { /* jump, in3 */ |
| 70378 | +#if 0 /* local variables moved into u.bg */ | |
| 70118 | 70379 | VdbeCursor *pC; |
| 70119 | 70380 | BtCursor *pCrsr; |
| 70120 | 70381 | int res; |
| 70121 | 70382 | u64 iKey; |
| 70383 | +#endif /* local variables moved into u.bg */ | |
| 70122 | 70384 | |
| 70123 | 70385 | pIn3 = &aMem[pOp->p3]; |
| 70124 | 70386 | assert( pIn3->flags & MEM_Int ); |
| 70125 | 70387 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70126 | - pC = p->apCsr[pOp->p1]; | |
| 70127 | - assert( pC!=0 ); | |
| 70128 | - assert( pC->isTable ); | |
| 70129 | - assert( pC->pseudoTableReg==0 ); | |
| 70130 | - pCrsr = pC->pCursor; | |
| 70131 | - assert( pCrsr!=0 ); | |
| 70132 | - res = 0; | |
| 70133 | - iKey = pIn3->u.i; | |
| 70134 | - rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); | |
| 70135 | - pC->lastRowid = pIn3->u.i; | |
| 70136 | - pC->rowidIsValid = res==0 ?1:0; | |
| 70137 | - pC->nullRow = 0; | |
| 70138 | - pC->cacheStatus = CACHE_STALE; | |
| 70139 | - pC->deferredMoveto = 0; | |
| 70140 | - if( res!=0 ){ | |
| 70388 | + u.bg.pC = p->apCsr[pOp->p1]; | |
| 70389 | + assert( u.bg.pC!=0 ); | |
| 70390 | + assert( u.bg.pC->isTable ); | |
| 70391 | + assert( u.bg.pC->pseudoTableReg==0 ); | |
| 70392 | + u.bg.pCrsr = u.bg.pC->pCursor; | |
| 70393 | + assert( u.bg.pCrsr!=0 ); | |
| 70394 | + u.bg.res = 0; | |
| 70395 | + u.bg.iKey = pIn3->u.i; | |
| 70396 | + rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res); | |
| 70397 | + u.bg.pC->lastRowid = pIn3->u.i; | |
| 70398 | + u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0; | |
| 70399 | + u.bg.pC->nullRow = 0; | |
| 70400 | + u.bg.pC->cacheStatus = CACHE_STALE; | |
| 70401 | + u.bg.pC->deferredMoveto = 0; | |
| 70402 | + if( u.bg.res!=0 ){ | |
| 70141 | 70403 | pc = pOp->p2 - 1; |
| 70142 | - assert( pC->rowidIsValid==0 ); | |
| 70404 | + assert( u.bg.pC->rowidIsValid==0 ); | |
| 70143 | 70405 | } |
| 70144 | - pC->seekResult = res; | |
| 70406 | + u.bg.pC->seekResult = u.bg.res; | |
| 70145 | 70407 | break; |
| 70146 | 70408 | } |
| 70147 | 70409 | |
| 70148 | 70410 | /* Opcode: Sequence P1 P2 * * * |
| 70149 | 70411 | ** Synopsis: r[P2]=rowid |
| @@ -70175,23 +70437,25 @@ | ||
| 70175 | 70437 | ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 70176 | 70438 | ** generated record number. This P3 mechanism is used to help implement the |
| 70177 | 70439 | ** AUTOINCREMENT feature. |
| 70178 | 70440 | */ |
| 70179 | 70441 | case OP_NewRowid: { /* out2-prerelease */ |
| 70442 | +#if 0 /* local variables moved into u.bh */ | |
| 70180 | 70443 | i64 v; /* The new rowid */ |
| 70181 | 70444 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 70182 | 70445 | int res; /* Result of an sqlite3BtreeLast() */ |
| 70183 | 70446 | int cnt; /* Counter to limit the number of searches */ |
| 70184 | 70447 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 70185 | 70448 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 70449 | +#endif /* local variables moved into u.bh */ | |
| 70186 | 70450 | |
| 70187 | - v = 0; | |
| 70188 | - res = 0; | |
| 70451 | + u.bh.v = 0; | |
| 70452 | + u.bh.res = 0; | |
| 70189 | 70453 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70190 | - pC = p->apCsr[pOp->p1]; | |
| 70191 | - assert( pC!=0 ); | |
| 70192 | - if( NEVER(pC->pCursor==0) ){ | |
| 70454 | + u.bh.pC = p->apCsr[pOp->p1]; | |
| 70455 | + assert( u.bh.pC!=0 ); | |
| 70456 | + if( NEVER(u.bh.pC->pCursor==0) ){ | |
| 70193 | 70457 | /* The zero initialization above is all that is needed */ |
| 70194 | 70458 | }else{ |
| 70195 | 70459 | /* The next rowid or record number (different terms for the same |
| 70196 | 70460 | ** thing) is obtained in a two-step algorithm. |
| 70197 | 70461 | ** |
| @@ -70203,11 +70467,11 @@ | ||
| 70203 | 70467 | ** The second algorithm is to select a rowid at random and see if |
| 70204 | 70468 | ** it already exists in the table. If it does not exist, we have |
| 70205 | 70469 | ** succeeded. If the random rowid does exist, we select a new one |
| 70206 | 70470 | ** and try again, up to 100 times. |
| 70207 | 70471 | */ |
| 70208 | - assert( pC->isTable ); | |
| 70472 | + assert( u.bh.pC->isTable ); | |
| 70209 | 70473 | |
| 70210 | 70474 | #ifdef SQLITE_32BIT_ROWID |
| 70211 | 70475 | # define MAX_ROWID 0x7fffffff |
| 70212 | 70476 | #else |
| 70213 | 70477 | /* Some compilers complain about constants of the form 0x7fffffffffffffff. |
| @@ -70215,101 +70479,101 @@ | ||
| 70215 | 70479 | ** to provide the constant while making all compilers happy. |
| 70216 | 70480 | */ |
| 70217 | 70481 | # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff ) |
| 70218 | 70482 | #endif |
| 70219 | 70483 | |
| 70220 | - if( !pC->useRandomRowid ){ | |
| 70221 | - v = sqlite3BtreeGetCachedRowid(pC->pCursor); | |
| 70222 | - if( v==0 ){ | |
| 70223 | - rc = sqlite3BtreeLast(pC->pCursor, &res); | |
| 70484 | + if( !u.bh.pC->useRandomRowid ){ | |
| 70485 | + u.bh.v = sqlite3BtreeGetCachedRowid(u.bh.pC->pCursor); | |
| 70486 | + if( u.bh.v==0 ){ | |
| 70487 | + rc = sqlite3BtreeLast(u.bh.pC->pCursor, &u.bh.res); | |
| 70224 | 70488 | if( rc!=SQLITE_OK ){ |
| 70225 | 70489 | goto abort_due_to_error; |
| 70226 | 70490 | } |
| 70227 | - if( res ){ | |
| 70228 | - v = 1; /* IMP: R-61914-48074 */ | |
| 70491 | + if( u.bh.res ){ | |
| 70492 | + u.bh.v = 1; /* IMP: R-61914-48074 */ | |
| 70229 | 70493 | }else{ |
| 70230 | - assert( sqlite3BtreeCursorIsValid(pC->pCursor) ); | |
| 70231 | - rc = sqlite3BtreeKeySize(pC->pCursor, &v); | |
| 70494 | + assert( sqlite3BtreeCursorIsValid(u.bh.pC->pCursor) ); | |
| 70495 | + rc = sqlite3BtreeKeySize(u.bh.pC->pCursor, &u.bh.v); | |
| 70232 | 70496 | assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ |
| 70233 | - if( v>=MAX_ROWID ){ | |
| 70234 | - pC->useRandomRowid = 1; | |
| 70497 | + if( u.bh.v>=MAX_ROWID ){ | |
| 70498 | + u.bh.pC->useRandomRowid = 1; | |
| 70235 | 70499 | }else{ |
| 70236 | - v++; /* IMP: R-29538-34987 */ | |
| 70500 | + u.bh.v++; /* IMP: R-29538-34987 */ | |
| 70237 | 70501 | } |
| 70238 | 70502 | } |
| 70239 | 70503 | } |
| 70240 | 70504 | |
| 70241 | 70505 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 70242 | 70506 | if( pOp->p3 ){ |
| 70243 | 70507 | /* Assert that P3 is a valid memory cell. */ |
| 70244 | 70508 | assert( pOp->p3>0 ); |
| 70245 | 70509 | if( p->pFrame ){ |
| 70246 | - for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); | |
| 70510 | + for(u.bh.pFrame=p->pFrame; u.bh.pFrame->pParent; u.bh.pFrame=u.bh.pFrame->pParent); | |
| 70247 | 70511 | /* Assert that P3 is a valid memory cell. */ |
| 70248 | - assert( pOp->p3<=pFrame->nMem ); | |
| 70249 | - pMem = &pFrame->aMem[pOp->p3]; | |
| 70512 | + assert( pOp->p3<=u.bh.pFrame->nMem ); | |
| 70513 | + u.bh.pMem = &u.bh.pFrame->aMem[pOp->p3]; | |
| 70250 | 70514 | }else{ |
| 70251 | 70515 | /* Assert that P3 is a valid memory cell. */ |
| 70252 | 70516 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 70253 | - pMem = &aMem[pOp->p3]; | |
| 70254 | - memAboutToChange(p, pMem); | |
| 70255 | - } | |
| 70256 | - assert( memIsValid(pMem) ); | |
| 70257 | - | |
| 70258 | - REGISTER_TRACE(pOp->p3, pMem); | |
| 70259 | - sqlite3VdbeMemIntegerify(pMem); | |
| 70260 | - assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ | |
| 70261 | - if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){ | |
| 70517 | + u.bh.pMem = &aMem[pOp->p3]; | |
| 70518 | + memAboutToChange(p, u.bh.pMem); | |
| 70519 | + } | |
| 70520 | + assert( memIsValid(u.bh.pMem) ); | |
| 70521 | + | |
| 70522 | + REGISTER_TRACE(pOp->p3, u.bh.pMem); | |
| 70523 | + sqlite3VdbeMemIntegerify(u.bh.pMem); | |
| 70524 | + assert( (u.bh.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ | |
| 70525 | + if( u.bh.pMem->u.i==MAX_ROWID || u.bh.pC->useRandomRowid ){ | |
| 70262 | 70526 | rc = SQLITE_FULL; /* IMP: R-12275-61338 */ |
| 70263 | 70527 | goto abort_due_to_error; |
| 70264 | 70528 | } |
| 70265 | - if( v<pMem->u.i+1 ){ | |
| 70266 | - v = pMem->u.i + 1; | |
| 70529 | + if( u.bh.v<u.bh.pMem->u.i+1 ){ | |
| 70530 | + u.bh.v = u.bh.pMem->u.i + 1; | |
| 70267 | 70531 | } |
| 70268 | - pMem->u.i = v; | |
| 70532 | + u.bh.pMem->u.i = u.bh.v; | |
| 70269 | 70533 | } |
| 70270 | 70534 | #endif |
| 70271 | 70535 | |
| 70272 | - sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0); | |
| 70536 | + sqlite3BtreeSetCachedRowid(u.bh.pC->pCursor, u.bh.v<MAX_ROWID ? u.bh.v+1 : 0); | |
| 70273 | 70537 | } |
| 70274 | - if( pC->useRandomRowid ){ | |
| 70538 | + if( u.bh.pC->useRandomRowid ){ | |
| 70275 | 70539 | /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the |
| 70276 | 70540 | ** largest possible integer (9223372036854775807) then the database |
| 70277 | 70541 | ** engine starts picking positive candidate ROWIDs at random until |
| 70278 | 70542 | ** it finds one that is not previously used. */ |
| 70279 | 70543 | assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is |
| 70280 | 70544 | ** an AUTOINCREMENT table. */ |
| 70281 | 70545 | /* on the first attempt, simply do one more than previous */ |
| 70282 | - v = lastRowid; | |
| 70283 | - v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ | |
| 70284 | - v++; /* ensure non-zero */ | |
| 70285 | - cnt = 0; | |
| 70286 | - while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v, | |
| 70287 | - 0, &res))==SQLITE_OK) | |
| 70288 | - && (res==0) | |
| 70289 | - && (++cnt<100)){ | |
| 70546 | + u.bh.v = lastRowid; | |
| 70547 | + u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ | |
| 70548 | + u.bh.v++; /* ensure non-zero */ | |
| 70549 | + u.bh.cnt = 0; | |
| 70550 | + while( ((rc = sqlite3BtreeMovetoUnpacked(u.bh.pC->pCursor, 0, (u64)u.bh.v, | |
| 70551 | + 0, &u.bh.res))==SQLITE_OK) | |
| 70552 | + && (u.bh.res==0) | |
| 70553 | + && (++u.bh.cnt<100)){ | |
| 70290 | 70554 | /* collision - try another random rowid */ |
| 70291 | - sqlite3_randomness(sizeof(v), &v); | |
| 70292 | - if( cnt<5 ){ | |
| 70555 | + sqlite3_randomness(sizeof(u.bh.v), &u.bh.v); | |
| 70556 | + if( u.bh.cnt<5 ){ | |
| 70293 | 70557 | /* try "small" random rowids for the initial attempts */ |
| 70294 | - v &= 0xffffff; | |
| 70558 | + u.bh.v &= 0xffffff; | |
| 70295 | 70559 | }else{ |
| 70296 | - v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ | |
| 70560 | + u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ | |
| 70297 | 70561 | } |
| 70298 | - v++; /* ensure non-zero */ | |
| 70562 | + u.bh.v++; /* ensure non-zero */ | |
| 70299 | 70563 | } |
| 70300 | - if( rc==SQLITE_OK && res==0 ){ | |
| 70564 | + if( rc==SQLITE_OK && u.bh.res==0 ){ | |
| 70301 | 70565 | rc = SQLITE_FULL; /* IMP: R-38219-53002 */ |
| 70302 | 70566 | goto abort_due_to_error; |
| 70303 | 70567 | } |
| 70304 | - assert( v>0 ); /* EV: R-40812-03570 */ | |
| 70568 | + assert( u.bh.v>0 ); /* EV: R-40812-03570 */ | |
| 70305 | 70569 | } |
| 70306 | - pC->rowidIsValid = 0; | |
| 70307 | - pC->deferredMoveto = 0; | |
| 70308 | - pC->cacheStatus = CACHE_STALE; | |
| 70570 | + u.bh.pC->rowidIsValid = 0; | |
| 70571 | + u.bh.pC->deferredMoveto = 0; | |
| 70572 | + u.bh.pC->cacheStatus = CACHE_STALE; | |
| 70309 | 70573 | } |
| 70310 | - pOut->u.i = v; | |
| 70574 | + pOut->u.i = u.bh.v; | |
| 70311 | 70575 | break; |
| 70312 | 70576 | } |
| 70313 | 70577 | |
| 70314 | 70578 | /* Opcode: Insert P1 P2 P3 P4 P5 |
| 70315 | 70579 | ** Synopsis: intkey=r[P3] data=r[P2] |
| @@ -70357,72 +70621,74 @@ | ||
| 70357 | 70621 | ** This works exactly like OP_Insert except that the key is the |
| 70358 | 70622 | ** integer value P3, not the value of the integer stored in register P3. |
| 70359 | 70623 | */ |
| 70360 | 70624 | case OP_Insert: |
| 70361 | 70625 | case OP_InsertInt: { |
| 70626 | +#if 0 /* local variables moved into u.bi */ | |
| 70362 | 70627 | Mem *pData; /* MEM cell holding data for the record to be inserted */ |
| 70363 | 70628 | Mem *pKey; /* MEM cell holding key for the record */ |
| 70364 | 70629 | i64 iKey; /* The integer ROWID or key for the record to be inserted */ |
| 70365 | 70630 | VdbeCursor *pC; /* Cursor to table into which insert is written */ |
| 70366 | 70631 | int nZero; /* Number of zero-bytes to append */ |
| 70367 | 70632 | int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ |
| 70368 | 70633 | const char *zDb; /* database name - used by the update hook */ |
| 70369 | 70634 | const char *zTbl; /* Table name - used by the opdate hook */ |
| 70370 | 70635 | int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ |
| 70636 | +#endif /* local variables moved into u.bi */ | |
| 70371 | 70637 | |
| 70372 | - pData = &aMem[pOp->p2]; | |
| 70638 | + u.bi.pData = &aMem[pOp->p2]; | |
| 70373 | 70639 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70374 | - assert( memIsValid(pData) ); | |
| 70375 | - pC = p->apCsr[pOp->p1]; | |
| 70376 | - assert( pC!=0 ); | |
| 70377 | - assert( pC->pCursor!=0 ); | |
| 70378 | - assert( pC->pseudoTableReg==0 ); | |
| 70379 | - assert( pC->isTable ); | |
| 70380 | - REGISTER_TRACE(pOp->p2, pData); | |
| 70640 | + assert( memIsValid(u.bi.pData) ); | |
| 70641 | + u.bi.pC = p->apCsr[pOp->p1]; | |
| 70642 | + assert( u.bi.pC!=0 ); | |
| 70643 | + assert( u.bi.pC->pCursor!=0 ); | |
| 70644 | + assert( u.bi.pC->pseudoTableReg==0 ); | |
| 70645 | + assert( u.bi.pC->isTable ); | |
| 70646 | + REGISTER_TRACE(pOp->p2, u.bi.pData); | |
| 70381 | 70647 | |
| 70382 | 70648 | if( pOp->opcode==OP_Insert ){ |
| 70383 | - pKey = &aMem[pOp->p3]; | |
| 70384 | - assert( pKey->flags & MEM_Int ); | |
| 70385 | - assert( memIsValid(pKey) ); | |
| 70386 | - REGISTER_TRACE(pOp->p3, pKey); | |
| 70387 | - iKey = pKey->u.i; | |
| 70649 | + u.bi.pKey = &aMem[pOp->p3]; | |
| 70650 | + assert( u.bi.pKey->flags & MEM_Int ); | |
| 70651 | + assert( memIsValid(u.bi.pKey) ); | |
| 70652 | + REGISTER_TRACE(pOp->p3, u.bi.pKey); | |
| 70653 | + u.bi.iKey = u.bi.pKey->u.i; | |
| 70388 | 70654 | }else{ |
| 70389 | 70655 | assert( pOp->opcode==OP_InsertInt ); |
| 70390 | - iKey = pOp->p3; | |
| 70656 | + u.bi.iKey = pOp->p3; | |
| 70391 | 70657 | } |
| 70392 | 70658 | |
| 70393 | 70659 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 70394 | - if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey; | |
| 70395 | - if( pData->flags & MEM_Null ){ | |
| 70396 | - pData->z = 0; | |
| 70397 | - pData->n = 0; | |
| 70398 | - }else{ | |
| 70399 | - assert( pData->flags & (MEM_Blob|MEM_Str) ); | |
| 70400 | - } | |
| 70401 | - seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0); | |
| 70402 | - if( pData->flags & MEM_Zero ){ | |
| 70403 | - nZero = pData->u.nZero; | |
| 70404 | - }else{ | |
| 70405 | - nZero = 0; | |
| 70406 | - } | |
| 70407 | - sqlite3BtreeSetCachedRowid(pC->pCursor, 0); | |
| 70408 | - rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, | |
| 70409 | - pData->z, pData->n, nZero, | |
| 70410 | - (pOp->p5 & OPFLAG_APPEND)!=0, seekResult | |
| 70660 | + if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bi.iKey; | |
| 70661 | + if( u.bi.pData->flags & MEM_Null ){ | |
| 70662 | + u.bi.pData->z = 0; | |
| 70663 | + u.bi.pData->n = 0; | |
| 70664 | + }else{ | |
| 70665 | + assert( u.bi.pData->flags & (MEM_Blob|MEM_Str) ); | |
| 70666 | + } | |
| 70667 | + u.bi.seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bi.pC->seekResult : 0); | |
| 70668 | + if( u.bi.pData->flags & MEM_Zero ){ | |
| 70669 | + u.bi.nZero = u.bi.pData->u.nZero; | |
| 70670 | + }else{ | |
| 70671 | + u.bi.nZero = 0; | |
| 70672 | + } | |
| 70673 | + sqlite3BtreeSetCachedRowid(u.bi.pC->pCursor, 0); | |
| 70674 | + rc = sqlite3BtreeInsert(u.bi.pC->pCursor, 0, u.bi.iKey, | |
| 70675 | + u.bi.pData->z, u.bi.pData->n, u.bi.nZero, | |
| 70676 | + (pOp->p5 & OPFLAG_APPEND)!=0, u.bi.seekResult | |
| 70411 | 70677 | ); |
| 70412 | - pC->rowidIsValid = 0; | |
| 70413 | - pC->deferredMoveto = 0; | |
| 70414 | - pC->cacheStatus = CACHE_STALE; | |
| 70678 | + u.bi.pC->rowidIsValid = 0; | |
| 70679 | + u.bi.pC->deferredMoveto = 0; | |
| 70680 | + u.bi.pC->cacheStatus = CACHE_STALE; | |
| 70415 | 70681 | |
| 70416 | 70682 | /* Invoke the update-hook if required. */ |
| 70417 | 70683 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){ |
| 70418 | - zDb = db->aDb[pC->iDb].zName; | |
| 70419 | - zTbl = pOp->p4.z; | |
| 70420 | - op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); | |
| 70421 | - assert( pC->isTable ); | |
| 70422 | - db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey); | |
| 70423 | - assert( pC->iDb>=0 ); | |
| 70684 | + u.bi.zDb = db->aDb[u.bi.pC->iDb].zName; | |
| 70685 | + u.bi.zTbl = pOp->p4.z; | |
| 70686 | + u.bi.op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); | |
| 70687 | + assert( u.bi.pC->isTable ); | |
| 70688 | + db->xUpdateCallback(db->pUpdateArg, u.bi.op, u.bi.zDb, u.bi.zTbl, u.bi.iKey); | |
| 70689 | + assert( u.bi.pC->iDb>=0 ); | |
| 70424 | 70690 | } |
| 70425 | 70691 | break; |
| 70426 | 70692 | } |
| 70427 | 70693 | |
| 70428 | 70694 | /* Opcode: Delete P1 P2 * P4 * |
| @@ -70444,39 +70710,41 @@ | ||
| 70444 | 70710 | ** pointing to. The update hook will be invoked, if it exists. |
| 70445 | 70711 | ** If P4 is not NULL then the P1 cursor must have been positioned |
| 70446 | 70712 | ** using OP_NotFound prior to invoking this opcode. |
| 70447 | 70713 | */ |
| 70448 | 70714 | case OP_Delete: { |
| 70715 | +#if 0 /* local variables moved into u.bj */ | |
| 70449 | 70716 | i64 iKey; |
| 70450 | 70717 | VdbeCursor *pC; |
| 70718 | +#endif /* local variables moved into u.bj */ | |
| 70451 | 70719 | |
| 70452 | 70720 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70453 | - pC = p->apCsr[pOp->p1]; | |
| 70454 | - assert( pC!=0 ); | |
| 70455 | - assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ | |
| 70456 | - iKey = pC->lastRowid; /* Only used for the update hook */ | |
| 70721 | + u.bj.pC = p->apCsr[pOp->p1]; | |
| 70722 | + assert( u.bj.pC!=0 ); | |
| 70723 | + assert( u.bj.pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ | |
| 70724 | + u.bj.iKey = u.bj.pC->lastRowid; /* Only used for the update hook */ | |
| 70457 | 70725 | |
| 70458 | 70726 | /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or |
| 70459 | 70727 | ** OP_Column on the same table without any intervening operations that |
| 70460 | - ** might move or invalidate the cursor. Hence cursor pC is always pointing | |
| 70728 | + ** might move or invalidate the cursor. Hence cursor u.bj.pC is always pointing | |
| 70461 | 70729 | ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation |
| 70462 | 70730 | ** below is always a no-op and cannot fail. We will run it anyhow, though, |
| 70463 | 70731 | ** to guard against future changes to the code generator. |
| 70464 | 70732 | **/ |
| 70465 | - assert( pC->deferredMoveto==0 ); | |
| 70466 | - rc = sqlite3VdbeCursorMoveto(pC); | |
| 70733 | + assert( u.bj.pC->deferredMoveto==0 ); | |
| 70734 | + rc = sqlite3VdbeCursorMoveto(u.bj.pC); | |
| 70467 | 70735 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70468 | 70736 | |
| 70469 | - sqlite3BtreeSetCachedRowid(pC->pCursor, 0); | |
| 70470 | - rc = sqlite3BtreeDelete(pC->pCursor); | |
| 70471 | - pC->cacheStatus = CACHE_STALE; | |
| 70737 | + sqlite3BtreeSetCachedRowid(u.bj.pC->pCursor, 0); | |
| 70738 | + rc = sqlite3BtreeDelete(u.bj.pC->pCursor); | |
| 70739 | + u.bj.pC->cacheStatus = CACHE_STALE; | |
| 70472 | 70740 | |
| 70473 | 70741 | /* Invoke the update-hook if required. */ |
| 70474 | - if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ | |
| 70742 | + if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && u.bj.pC->isTable ){ | |
| 70475 | 70743 | db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 70476 | - db->aDb[pC->iDb].zName, pOp->p4.z, iKey); | |
| 70477 | - assert( pC->iDb>=0 ); | |
| 70744 | + db->aDb[u.bj.pC->iDb].zName, pOp->p4.z, u.bj.iKey); | |
| 70745 | + assert( u.bj.pC->iDb>=0 ); | |
| 70478 | 70746 | } |
| 70479 | 70747 | if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| 70480 | 70748 | break; |
| 70481 | 70749 | } |
| 70482 | 70750 | /* Opcode: ResetCount * * * * * |
| @@ -70506,21 +70774,23 @@ | ||
| 70506 | 70774 | ** |
| 70507 | 70775 | ** Fall through to next instruction if the two records compare equal to |
| 70508 | 70776 | ** each other. Jump to P2 if they are different. |
| 70509 | 70777 | */ |
| 70510 | 70778 | case OP_SorterCompare: { |
| 70779 | +#if 0 /* local variables moved into u.bk */ | |
| 70511 | 70780 | VdbeCursor *pC; |
| 70512 | 70781 | int res; |
| 70513 | 70782 | int nIgnore; |
| 70783 | +#endif /* local variables moved into u.bk */ | |
| 70514 | 70784 | |
| 70515 | - pC = p->apCsr[pOp->p1]; | |
| 70516 | - assert( isSorter(pC) ); | |
| 70785 | + u.bk.pC = p->apCsr[pOp->p1]; | |
| 70786 | + assert( isSorter(u.bk.pC) ); | |
| 70517 | 70787 | assert( pOp->p4type==P4_INT32 ); |
| 70518 | 70788 | pIn3 = &aMem[pOp->p3]; |
| 70519 | - nIgnore = pOp->p4.i; | |
| 70520 | - rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res); | |
| 70521 | - if( res ){ | |
| 70789 | + u.bk.nIgnore = pOp->p4.i; | |
| 70790 | + rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res); | |
| 70791 | + if( u.bk.res ){ | |
| 70522 | 70792 | pc = pOp->p2-1; |
| 70523 | 70793 | } |
| 70524 | 70794 | break; |
| 70525 | 70795 | }; |
| 70526 | 70796 | |
| @@ -70528,16 +70798,18 @@ | ||
| 70528 | 70798 | ** Synopsis: r[P2]=data |
| 70529 | 70799 | ** |
| 70530 | 70800 | ** Write into register P2 the current sorter data for sorter cursor P1. |
| 70531 | 70801 | */ |
| 70532 | 70802 | case OP_SorterData: { |
| 70803 | +#if 0 /* local variables moved into u.bl */ | |
| 70533 | 70804 | VdbeCursor *pC; |
| 70805 | +#endif /* local variables moved into u.bl */ | |
| 70534 | 70806 | |
| 70535 | 70807 | pOut = &aMem[pOp->p2]; |
| 70536 | - pC = p->apCsr[pOp->p1]; | |
| 70537 | - assert( isSorter(pC) ); | |
| 70538 | - rc = sqlite3VdbeSorterRowkey(pC, pOut); | |
| 70808 | + u.bl.pC = p->apCsr[pOp->p1]; | |
| 70809 | + assert( isSorter(u.bl.pC) ); | |
| 70810 | + rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut); | |
| 70539 | 70811 | break; |
| 70540 | 70812 | } |
| 70541 | 70813 | |
| 70542 | 70814 | /* Opcode: RowData P1 P2 * * * |
| 70543 | 70815 | ** Synopsis: r[P2]=data |
| @@ -70561,64 +70833,66 @@ | ||
| 70561 | 70833 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 70562 | 70834 | ** of a real table, not a pseudo-table. |
| 70563 | 70835 | */ |
| 70564 | 70836 | case OP_RowKey: |
| 70565 | 70837 | case OP_RowData: { |
| 70838 | +#if 0 /* local variables moved into u.bm */ | |
| 70566 | 70839 | VdbeCursor *pC; |
| 70567 | 70840 | BtCursor *pCrsr; |
| 70568 | 70841 | u32 n; |
| 70569 | 70842 | i64 n64; |
| 70843 | +#endif /* local variables moved into u.bm */ | |
| 70570 | 70844 | |
| 70571 | 70845 | pOut = &aMem[pOp->p2]; |
| 70572 | 70846 | memAboutToChange(p, pOut); |
| 70573 | 70847 | |
| 70574 | 70848 | /* Note that RowKey and RowData are really exactly the same instruction */ |
| 70575 | 70849 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70576 | - pC = p->apCsr[pOp->p1]; | |
| 70577 | - assert( isSorter(pC)==0 ); | |
| 70578 | - assert( pC->isTable || pOp->opcode!=OP_RowData ); | |
| 70579 | - assert( pC->isTable==0 || pOp->opcode==OP_RowData ); | |
| 70580 | - assert( pC!=0 ); | |
| 70581 | - assert( pC->nullRow==0 ); | |
| 70582 | - assert( pC->pseudoTableReg==0 ); | |
| 70583 | - assert( pC->pCursor!=0 ); | |
| 70584 | - pCrsr = pC->pCursor; | |
| 70585 | - assert( sqlite3BtreeCursorIsValid(pCrsr) ); | |
| 70850 | + u.bm.pC = p->apCsr[pOp->p1]; | |
| 70851 | + assert( isSorter(u.bm.pC)==0 ); | |
| 70852 | + assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData ); | |
| 70853 | + assert( u.bm.pC->isTable==0 || pOp->opcode==OP_RowData ); | |
| 70854 | + assert( u.bm.pC!=0 ); | |
| 70855 | + assert( u.bm.pC->nullRow==0 ); | |
| 70856 | + assert( u.bm.pC->pseudoTableReg==0 ); | |
| 70857 | + assert( u.bm.pC->pCursor!=0 ); | |
| 70858 | + u.bm.pCrsr = u.bm.pC->pCursor; | |
| 70859 | + assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) ); | |
| 70586 | 70860 | |
| 70587 | 70861 | /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or |
| 70588 | 70862 | ** OP_Rewind/Op_Next with no intervening instructions that might invalidate |
| 70589 | 70863 | ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always |
| 70590 | 70864 | ** a no-op and can never fail. But we leave it in place as a safety. |
| 70591 | 70865 | */ |
| 70592 | - assert( pC->deferredMoveto==0 ); | |
| 70593 | - rc = sqlite3VdbeCursorMoveto(pC); | |
| 70594 | - if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; | |
| 70595 | - | |
| 70596 | - if( pC->isTable==0 ){ | |
| 70597 | - assert( !pC->isTable ); | |
| 70598 | - VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64); | |
| 70599 | - assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ | |
| 70600 | - if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 70601 | - goto too_big; | |
| 70602 | - } | |
| 70603 | - n = (u32)n64; | |
| 70604 | - }else{ | |
| 70605 | - VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n); | |
| 70606 | - assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ | |
| 70607 | - if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 70608 | - goto too_big; | |
| 70609 | - } | |
| 70610 | - } | |
| 70611 | - if( sqlite3VdbeMemGrow(pOut, n, 0) ){ | |
| 70612 | - goto no_mem; | |
| 70613 | - } | |
| 70614 | - pOut->n = n; | |
| 70615 | - MemSetTypeFlag(pOut, MEM_Blob); | |
| 70616 | - if( pC->isTable==0 ){ | |
| 70617 | - rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z); | |
| 70618 | - }else{ | |
| 70619 | - rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z); | |
| 70866 | + assert( u.bm.pC->deferredMoveto==0 ); | |
| 70867 | + rc = sqlite3VdbeCursorMoveto(u.bm.pC); | |
| 70868 | + if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; | |
| 70869 | + | |
| 70870 | + if( u.bm.pC->isTable==0 ){ | |
| 70871 | + assert( !u.bm.pC->isTable ); | |
| 70872 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64); | |
| 70873 | + assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ | |
| 70874 | + if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 70875 | + goto too_big; | |
| 70876 | + } | |
| 70877 | + u.bm.n = (u32)u.bm.n64; | |
| 70878 | + }else{ | |
| 70879 | + VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bm.pCrsr, &u.bm.n); | |
| 70880 | + assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ | |
| 70881 | + if( u.bm.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 70882 | + goto too_big; | |
| 70883 | + } | |
| 70884 | + } | |
| 70885 | + if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){ | |
| 70886 | + goto no_mem; | |
| 70887 | + } | |
| 70888 | + pOut->n = u.bm.n; | |
| 70889 | + MemSetTypeFlag(pOut, MEM_Blob); | |
| 70890 | + if( u.bm.pC->isTable==0 ){ | |
| 70891 | + rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z); | |
| 70892 | + }else{ | |
| 70893 | + rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z); | |
| 70620 | 70894 | } |
| 70621 | 70895 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ |
| 70622 | 70896 | UPDATE_MAX_BLOBSIZE(pOut); |
| 70623 | 70897 | REGISTER_TRACE(pOp->p2, pOut); |
| 70624 | 70898 | break; |
| @@ -70633,44 +70907,46 @@ | ||
| 70633 | 70907 | ** P1 can be either an ordinary table or a virtual table. There used to |
| 70634 | 70908 | ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 70635 | 70909 | ** one opcode now works for both table types. |
| 70636 | 70910 | */ |
| 70637 | 70911 | case OP_Rowid: { /* out2-prerelease */ |
| 70912 | +#if 0 /* local variables moved into u.bn */ | |
| 70638 | 70913 | VdbeCursor *pC; |
| 70639 | 70914 | i64 v; |
| 70640 | 70915 | sqlite3_vtab *pVtab; |
| 70641 | 70916 | const sqlite3_module *pModule; |
| 70917 | +#endif /* local variables moved into u.bn */ | |
| 70642 | 70918 | |
| 70643 | 70919 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70644 | - pC = p->apCsr[pOp->p1]; | |
| 70645 | - assert( pC!=0 ); | |
| 70646 | - assert( pC->pseudoTableReg==0 || pC->nullRow ); | |
| 70647 | - if( pC->nullRow ){ | |
| 70920 | + u.bn.pC = p->apCsr[pOp->p1]; | |
| 70921 | + assert( u.bn.pC!=0 ); | |
| 70922 | + assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow ); | |
| 70923 | + if( u.bn.pC->nullRow ){ | |
| 70648 | 70924 | pOut->flags = MEM_Null; |
| 70649 | 70925 | break; |
| 70650 | - }else if( pC->deferredMoveto ){ | |
| 70651 | - v = pC->movetoTarget; | |
| 70926 | + }else if( u.bn.pC->deferredMoveto ){ | |
| 70927 | + u.bn.v = u.bn.pC->movetoTarget; | |
| 70652 | 70928 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 70653 | - }else if( pC->pVtabCursor ){ | |
| 70654 | - pVtab = pC->pVtabCursor->pVtab; | |
| 70655 | - pModule = pVtab->pModule; | |
| 70656 | - assert( pModule->xRowid ); | |
| 70657 | - rc = pModule->xRowid(pC->pVtabCursor, &v); | |
| 70658 | - sqlite3VtabImportErrmsg(p, pVtab); | |
| 70929 | + }else if( u.bn.pC->pVtabCursor ){ | |
| 70930 | + u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab; | |
| 70931 | + u.bn.pModule = u.bn.pVtab->pModule; | |
| 70932 | + assert( u.bn.pModule->xRowid ); | |
| 70933 | + rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v); | |
| 70934 | + sqlite3VtabImportErrmsg(p, u.bn.pVtab); | |
| 70659 | 70935 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 70660 | 70936 | }else{ |
| 70661 | - assert( pC->pCursor!=0 ); | |
| 70662 | - rc = sqlite3VdbeCursorMoveto(pC); | |
| 70937 | + assert( u.bn.pC->pCursor!=0 ); | |
| 70938 | + rc = sqlite3VdbeCursorMoveto(u.bn.pC); | |
| 70663 | 70939 | if( rc ) goto abort_due_to_error; |
| 70664 | - if( pC->rowidIsValid ){ | |
| 70665 | - v = pC->lastRowid; | |
| 70940 | + if( u.bn.pC->rowidIsValid ){ | |
| 70941 | + u.bn.v = u.bn.pC->lastRowid; | |
| 70666 | 70942 | }else{ |
| 70667 | - rc = sqlite3BtreeKeySize(pC->pCursor, &v); | |
| 70943 | + rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v); | |
| 70668 | 70944 | assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */ |
| 70669 | 70945 | } |
| 70670 | 70946 | } |
| 70671 | - pOut->u.i = v; | |
| 70947 | + pOut->u.i = u.bn.v; | |
| 70672 | 70948 | break; |
| 70673 | 70949 | } |
| 70674 | 70950 | |
| 70675 | 70951 | /* Opcode: NullRow P1 * * * * |
| 70676 | 70952 | ** |
| @@ -70677,21 +70953,23 @@ | ||
| 70677 | 70953 | ** Move the cursor P1 to a null row. Any OP_Column operations |
| 70678 | 70954 | ** that occur while the cursor is on the null row will always |
| 70679 | 70955 | ** write a NULL. |
| 70680 | 70956 | */ |
| 70681 | 70957 | case OP_NullRow: { |
| 70958 | +#if 0 /* local variables moved into u.bo */ | |
| 70682 | 70959 | VdbeCursor *pC; |
| 70960 | +#endif /* local variables moved into u.bo */ | |
| 70683 | 70961 | |
| 70684 | 70962 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70685 | - pC = p->apCsr[pOp->p1]; | |
| 70686 | - assert( pC!=0 ); | |
| 70687 | - pC->nullRow = 1; | |
| 70688 | - pC->rowidIsValid = 0; | |
| 70689 | - pC->cacheStatus = CACHE_STALE; | |
| 70690 | - assert( pC->pCursor || pC->pVtabCursor ); | |
| 70691 | - if( pC->pCursor ){ | |
| 70692 | - sqlite3BtreeClearCursor(pC->pCursor); | |
| 70963 | + u.bo.pC = p->apCsr[pOp->p1]; | |
| 70964 | + assert( u.bo.pC!=0 ); | |
| 70965 | + u.bo.pC->nullRow = 1; | |
| 70966 | + u.bo.pC->rowidIsValid = 0; | |
| 70967 | + u.bo.pC->cacheStatus = CACHE_STALE; | |
| 70968 | + assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor ); | |
| 70969 | + if( u.bo.pC->pCursor ){ | |
| 70970 | + sqlite3BtreeClearCursor(u.bo.pC->pCursor); | |
| 70693 | 70971 | } |
| 70694 | 70972 | break; |
| 70695 | 70973 | } |
| 70696 | 70974 | |
| 70697 | 70975 | /* Opcode: Last P1 P2 * * * |
| @@ -70701,26 +70979,28 @@ | ||
| 70701 | 70979 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 70702 | 70980 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 70703 | 70981 | ** to the following instruction. |
| 70704 | 70982 | */ |
| 70705 | 70983 | case OP_Last: { /* jump */ |
| 70984 | +#if 0 /* local variables moved into u.bp */ | |
| 70706 | 70985 | VdbeCursor *pC; |
| 70707 | 70986 | BtCursor *pCrsr; |
| 70708 | 70987 | int res; |
| 70988 | +#endif /* local variables moved into u.bp */ | |
| 70709 | 70989 | |
| 70710 | 70990 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70711 | - pC = p->apCsr[pOp->p1]; | |
| 70712 | - assert( pC!=0 ); | |
| 70713 | - pCrsr = pC->pCursor; | |
| 70714 | - res = 0; | |
| 70715 | - assert( pCrsr!=0 ); | |
| 70716 | - rc = sqlite3BtreeLast(pCrsr, &res); | |
| 70717 | - pC->nullRow = (u8)res; | |
| 70718 | - pC->deferredMoveto = 0; | |
| 70719 | - pC->rowidIsValid = 0; | |
| 70720 | - pC->cacheStatus = CACHE_STALE; | |
| 70721 | - if( pOp->p2>0 && res ){ | |
| 70991 | + u.bp.pC = p->apCsr[pOp->p1]; | |
| 70992 | + assert( u.bp.pC!=0 ); | |
| 70993 | + u.bp.pCrsr = u.bp.pC->pCursor; | |
| 70994 | + u.bp.res = 0; | |
| 70995 | + assert( u.bp.pCrsr!=0 ); | |
| 70996 | + rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res); | |
| 70997 | + u.bp.pC->nullRow = (u8)u.bp.res; | |
| 70998 | + u.bp.pC->deferredMoveto = 0; | |
| 70999 | + u.bp.pC->rowidIsValid = 0; | |
| 71000 | + u.bp.pC->cacheStatus = CACHE_STALE; | |
| 71001 | + if( pOp->p2>0 && u.bp.res ){ | |
| 70722 | 71002 | pc = pOp->p2 - 1; |
| 70723 | 71003 | } |
| 70724 | 71004 | break; |
| 70725 | 71005 | } |
| 70726 | 71006 | |
| @@ -70753,32 +71033,34 @@ | ||
| 70753 | 71033 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 70754 | 71034 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 70755 | 71035 | ** to the following instruction. |
| 70756 | 71036 | */ |
| 70757 | 71037 | case OP_Rewind: { /* jump */ |
| 71038 | +#if 0 /* local variables moved into u.bq */ | |
| 70758 | 71039 | VdbeCursor *pC; |
| 70759 | 71040 | BtCursor *pCrsr; |
| 70760 | 71041 | int res; |
| 71042 | +#endif /* local variables moved into u.bq */ | |
| 70761 | 71043 | |
| 70762 | 71044 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70763 | - pC = p->apCsr[pOp->p1]; | |
| 70764 | - assert( pC!=0 ); | |
| 70765 | - assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) ); | |
| 70766 | - res = 1; | |
| 70767 | - if( isSorter(pC) ){ | |
| 70768 | - rc = sqlite3VdbeSorterRewind(db, pC, &res); | |
| 71045 | + u.bq.pC = p->apCsr[pOp->p1]; | |
| 71046 | + assert( u.bq.pC!=0 ); | |
| 71047 | + assert( isSorter(u.bq.pC)==(pOp->opcode==OP_SorterSort) ); | |
| 71048 | + u.bq.res = 1; | |
| 71049 | + if( isSorter(u.bq.pC) ){ | |
| 71050 | + rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res); | |
| 70769 | 71051 | }else{ |
| 70770 | - pCrsr = pC->pCursor; | |
| 70771 | - assert( pCrsr ); | |
| 70772 | - rc = sqlite3BtreeFirst(pCrsr, &res); | |
| 70773 | - pC->deferredMoveto = 0; | |
| 70774 | - pC->cacheStatus = CACHE_STALE; | |
| 70775 | - pC->rowidIsValid = 0; | |
| 70776 | - } | |
| 70777 | - pC->nullRow = (u8)res; | |
| 71052 | + u.bq.pCrsr = u.bq.pC->pCursor; | |
| 71053 | + assert( u.bq.pCrsr ); | |
| 71054 | + rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res); | |
| 71055 | + u.bq.pC->deferredMoveto = 0; | |
| 71056 | + u.bq.pC->cacheStatus = CACHE_STALE; | |
| 71057 | + u.bq.pC->rowidIsValid = 0; | |
| 71058 | + } | |
| 71059 | + u.bq.pC->nullRow = (u8)u.bq.res; | |
| 70778 | 71060 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 70779 | - if( res ){ | |
| 71061 | + if( u.bq.res ){ | |
| 70780 | 71062 | pc = pOp->p2 - 1; |
| 70781 | 71063 | } |
| 70782 | 71064 | break; |
| 70783 | 71065 | } |
| 70784 | 71066 | |
| @@ -70825,47 +71107,49 @@ | ||
| 70825 | 71107 | ** |
| 70826 | 71108 | ** This opcode works just like OP_Prev except that if cursor P1 is not |
| 70827 | 71109 | ** open it behaves a no-op. |
| 70828 | 71110 | */ |
| 70829 | 71111 | case OP_SorterNext: { /* jump */ |
| 71112 | +#if 0 /* local variables moved into u.br */ | |
| 70830 | 71113 | VdbeCursor *pC; |
| 70831 | 71114 | int res; |
| 71115 | +#endif /* local variables moved into u.br */ | |
| 70832 | 71116 | |
| 70833 | - pC = p->apCsr[pOp->p1]; | |
| 70834 | - assert( isSorter(pC) ); | |
| 70835 | - rc = sqlite3VdbeSorterNext(db, pC, &res); | |
| 71117 | + u.br.pC = p->apCsr[pOp->p1]; | |
| 71118 | + assert( isSorter(u.br.pC) ); | |
| 71119 | + rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res); | |
| 70836 | 71120 | goto next_tail; |
| 70837 | 71121 | case OP_PrevIfOpen: /* jump */ |
| 70838 | 71122 | case OP_NextIfOpen: /* jump */ |
| 70839 | 71123 | if( p->apCsr[pOp->p1]==0 ) break; |
| 70840 | 71124 | /* Fall through */ |
| 70841 | 71125 | case OP_Prev: /* jump */ |
| 70842 | 71126 | case OP_Next: /* jump */ |
| 70843 | 71127 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70844 | 71128 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 70845 | - pC = p->apCsr[pOp->p1]; | |
| 70846 | - assert( pC!=0 ); | |
| 70847 | - assert( pC->deferredMoveto==0 ); | |
| 70848 | - assert( pC->pCursor ); | |
| 71129 | + u.br.pC = p->apCsr[pOp->p1]; | |
| 71130 | + assert( u.br.pC!=0 ); | |
| 71131 | + assert( u.br.pC->deferredMoveto==0 ); | |
| 71132 | + assert( u.br.pC->pCursor ); | |
| 70849 | 71133 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70850 | 71134 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 70851 | 71135 | assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70852 | 71136 | assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); |
| 70853 | - rc = pOp->p4.xAdvance(pC->pCursor, &res); | |
| 71137 | + rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res); | |
| 70854 | 71138 | next_tail: |
| 70855 | - pC->cacheStatus = CACHE_STALE; | |
| 70856 | - if( res==0 ){ | |
| 70857 | - pC->nullRow = 0; | |
| 71139 | + u.br.pC->cacheStatus = CACHE_STALE; | |
| 71140 | + if( u.br.res==0 ){ | |
| 71141 | + u.br.pC->nullRow = 0; | |
| 70858 | 71142 | pc = pOp->p2 - 1; |
| 70859 | 71143 | p->aCounter[pOp->p5]++; |
| 70860 | 71144 | #ifdef SQLITE_TEST |
| 70861 | 71145 | sqlite3_search_count++; |
| 70862 | 71146 | #endif |
| 70863 | 71147 | }else{ |
| 70864 | - pC->nullRow = 1; | |
| 71148 | + u.br.pC->nullRow = 1; | |
| 70865 | 71149 | } |
| 70866 | - pC->rowidIsValid = 0; | |
| 71150 | + u.br.pC->rowidIsValid = 0; | |
| 70867 | 71151 | goto check_for_interrupt; |
| 70868 | 71152 | } |
| 70869 | 71153 | |
| 70870 | 71154 | /* Opcode: IdxInsert P1 P2 P3 * P5 |
| 70871 | 71155 | ** Synopsis: key=r[P2] |
| @@ -70880,37 +71164,39 @@ | ||
| 70880 | 71164 | ** This instruction only works for indices. The equivalent instruction |
| 70881 | 71165 | ** for tables is OP_Insert. |
| 70882 | 71166 | */ |
| 70883 | 71167 | case OP_SorterInsert: /* in2 */ |
| 70884 | 71168 | case OP_IdxInsert: { /* in2 */ |
| 71169 | +#if 0 /* local variables moved into u.bs */ | |
| 70885 | 71170 | VdbeCursor *pC; |
| 70886 | 71171 | BtCursor *pCrsr; |
| 70887 | 71172 | int nKey; |
| 70888 | 71173 | const char *zKey; |
| 71174 | +#endif /* local variables moved into u.bs */ | |
| 70889 | 71175 | |
| 70890 | 71176 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70891 | - pC = p->apCsr[pOp->p1]; | |
| 70892 | - assert( pC!=0 ); | |
| 70893 | - assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) ); | |
| 71177 | + u.bs.pC = p->apCsr[pOp->p1]; | |
| 71178 | + assert( u.bs.pC!=0 ); | |
| 71179 | + assert( isSorter(u.bs.pC)==(pOp->opcode==OP_SorterInsert) ); | |
| 70894 | 71180 | pIn2 = &aMem[pOp->p2]; |
| 70895 | 71181 | assert( pIn2->flags & MEM_Blob ); |
| 70896 | - pCrsr = pC->pCursor; | |
| 71182 | + u.bs.pCrsr = u.bs.pC->pCursor; | |
| 70897 | 71183 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 70898 | - assert( pCrsr!=0 ); | |
| 70899 | - assert( pC->isTable==0 ); | |
| 71184 | + assert( u.bs.pCrsr!=0 ); | |
| 71185 | + assert( u.bs.pC->isTable==0 ); | |
| 70900 | 71186 | rc = ExpandBlob(pIn2); |
| 70901 | 71187 | if( rc==SQLITE_OK ){ |
| 70902 | - if( isSorter(pC) ){ | |
| 70903 | - rc = sqlite3VdbeSorterWrite(db, pC, pIn2); | |
| 71188 | + if( isSorter(u.bs.pC) ){ | |
| 71189 | + rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2); | |
| 70904 | 71190 | }else{ |
| 70905 | - nKey = pIn2->n; | |
| 70906 | - zKey = pIn2->z; | |
| 70907 | - rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3, | |
| 70908 | - ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) | |
| 71191 | + u.bs.nKey = pIn2->n; | |
| 71192 | + u.bs.zKey = pIn2->z; | |
| 71193 | + rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3, | |
| 71194 | + ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0) | |
| 70909 | 71195 | ); |
| 70910 | - assert( pC->deferredMoveto==0 ); | |
| 70911 | - pC->cacheStatus = CACHE_STALE; | |
| 71196 | + assert( u.bs.pC->deferredMoveto==0 ); | |
| 71197 | + u.bs.pC->cacheStatus = CACHE_STALE; | |
| 70912 | 71198 | } |
| 70913 | 71199 | } |
| 70914 | 71200 | break; |
| 70915 | 71201 | } |
| 70916 | 71202 | |
| @@ -70920,36 +71206,38 @@ | ||
| 70920 | 71206 | ** The content of P3 registers starting at register P2 form |
| 70921 | 71207 | ** an unpacked index key. This opcode removes that entry from the |
| 70922 | 71208 | ** index opened by cursor P1. |
| 70923 | 71209 | */ |
| 70924 | 71210 | case OP_IdxDelete: { |
| 71211 | +#if 0 /* local variables moved into u.bt */ | |
| 70925 | 71212 | VdbeCursor *pC; |
| 70926 | 71213 | BtCursor *pCrsr; |
| 70927 | 71214 | int res; |
| 70928 | 71215 | UnpackedRecord r; |
| 71216 | +#endif /* local variables moved into u.bt */ | |
| 70929 | 71217 | |
| 70930 | 71218 | assert( pOp->p3>0 ); |
| 70931 | 71219 | assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 ); |
| 70932 | 71220 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70933 | - pC = p->apCsr[pOp->p1]; | |
| 70934 | - assert( pC!=0 ); | |
| 70935 | - pCrsr = pC->pCursor; | |
| 70936 | - assert( pCrsr!=0 ); | |
| 71221 | + u.bt.pC = p->apCsr[pOp->p1]; | |
| 71222 | + assert( u.bt.pC!=0 ); | |
| 71223 | + u.bt.pCrsr = u.bt.pC->pCursor; | |
| 71224 | + assert( u.bt.pCrsr!=0 ); | |
| 70937 | 71225 | assert( pOp->p5==0 ); |
| 70938 | - r.pKeyInfo = pC->pKeyInfo; | |
| 70939 | - r.nField = (u16)pOp->p3; | |
| 70940 | - r.flags = UNPACKED_PREFIX_MATCH; | |
| 70941 | - r.aMem = &aMem[pOp->p2]; | |
| 71226 | + u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo; | |
| 71227 | + u.bt.r.nField = (u16)pOp->p3; | |
| 71228 | + u.bt.r.flags = UNPACKED_PREFIX_MATCH; | |
| 71229 | + u.bt.r.aMem = &aMem[pOp->p2]; | |
| 70942 | 71230 | #ifdef SQLITE_DEBUG |
| 70943 | - { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } | |
| 71231 | + { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); } | |
| 70944 | 71232 | #endif |
| 70945 | - rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); | |
| 70946 | - if( rc==SQLITE_OK && res==0 ){ | |
| 70947 | - rc = sqlite3BtreeDelete(pCrsr); | |
| 71233 | + rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res); | |
| 71234 | + if( rc==SQLITE_OK && u.bt.res==0 ){ | |
| 71235 | + rc = sqlite3BtreeDelete(u.bt.pCrsr); | |
| 70948 | 71236 | } |
| 70949 | - assert( pC->deferredMoveto==0 ); | |
| 70950 | - pC->cacheStatus = CACHE_STALE; | |
| 71237 | + assert( u.bt.pC->deferredMoveto==0 ); | |
| 71238 | + u.bt.pC->cacheStatus = CACHE_STALE; | |
| 70951 | 71239 | break; |
| 70952 | 71240 | } |
| 70953 | 71241 | |
| 70954 | 71242 | /* Opcode: IdxRowid P1 P2 * * * |
| 70955 | 71243 | ** Synopsis: r[P2]=rowid |
| @@ -70959,31 +71247,32 @@ | ||
| 70959 | 71247 | ** the rowid of the table entry to which this index entry points. |
| 70960 | 71248 | ** |
| 70961 | 71249 | ** See also: Rowid, MakeRecord. |
| 70962 | 71250 | */ |
| 70963 | 71251 | case OP_IdxRowid: { /* out2-prerelease */ |
| 71252 | +#if 0 /* local variables moved into u.bu */ | |
| 70964 | 71253 | BtCursor *pCrsr; |
| 70965 | 71254 | VdbeCursor *pC; |
| 70966 | 71255 | i64 rowid; |
| 71256 | +#endif /* local variables moved into u.bu */ | |
| 70967 | 71257 | |
| 70968 | 71258 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70969 | - pC = p->apCsr[pOp->p1]; | |
| 70970 | - assert( pC!=0 ); | |
| 70971 | - pCrsr = pC->pCursor; | |
| 70972 | - assert( pCrsr!=0 ); | |
| 71259 | + u.bu.pC = p->apCsr[pOp->p1]; | |
| 71260 | + assert( u.bu.pC!=0 ); | |
| 71261 | + u.bu.pCrsr = u.bu.pC->pCursor; | |
| 71262 | + assert( u.bu.pCrsr!=0 ); | |
| 70973 | 71263 | pOut->flags = MEM_Null; |
| 70974 | - rc = sqlite3VdbeCursorMoveto(pC); | |
| 71264 | + rc = sqlite3VdbeCursorMoveto(u.bu.pC); | |
| 70975 | 71265 | if( NEVER(rc) ) goto abort_due_to_error; |
| 70976 | - assert( pC->deferredMoveto==0 ); | |
| 70977 | - assert( pC->isTable==0 ); | |
| 70978 | - if( !pC->nullRow ){ | |
| 70979 | - rowid = 0; /* Not needed. Only used to silence a warning. */ | |
| 70980 | - rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid); | |
| 71266 | + assert( u.bu.pC->deferredMoveto==0 ); | |
| 71267 | + assert( u.bu.pC->isTable==0 ); | |
| 71268 | + if( !u.bu.pC->nullRow ){ | |
| 71269 | + rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid); | |
| 70981 | 71270 | if( rc!=SQLITE_OK ){ |
| 70982 | 71271 | goto abort_due_to_error; |
| 70983 | 71272 | } |
| 70984 | - pOut->u.i = rowid; | |
| 71273 | + pOut->u.i = u.bu.rowid; | |
| 70985 | 71274 | pOut->flags = MEM_Int; |
| 70986 | 71275 | } |
| 70987 | 71276 | break; |
| 70988 | 71277 | } |
| 70989 | 71278 | |
| @@ -71015,42 +71304,43 @@ | ||
| 71015 | 71304 | ** If P5 is non-zero then the key value is increased by an epsilon prior |
| 71016 | 71305 | ** to the comparison. This makes the opcode work like IdxLE. |
| 71017 | 71306 | */ |
| 71018 | 71307 | case OP_IdxLT: /* jump */ |
| 71019 | 71308 | case OP_IdxGE: { /* jump */ |
| 71309 | +#if 0 /* local variables moved into u.bv */ | |
| 71020 | 71310 | VdbeCursor *pC; |
| 71021 | 71311 | int res; |
| 71022 | 71312 | UnpackedRecord r; |
| 71313 | +#endif /* local variables moved into u.bv */ | |
| 71023 | 71314 | |
| 71024 | 71315 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71025 | - pC = p->apCsr[pOp->p1]; | |
| 71026 | - assert( pC!=0 ); | |
| 71027 | - assert( pC->isOrdered ); | |
| 71028 | - assert( pC->pCursor!=0); | |
| 71029 | - assert( pC->deferredMoveto==0 ); | |
| 71316 | + u.bv.pC = p->apCsr[pOp->p1]; | |
| 71317 | + assert( u.bv.pC!=0 ); | |
| 71318 | + assert( u.bv.pC->isOrdered ); | |
| 71319 | + assert( u.bv.pC->pCursor!=0); | |
| 71320 | + assert( u.bv.pC->deferredMoveto==0 ); | |
| 71030 | 71321 | assert( pOp->p5==0 || pOp->p5==1 ); |
| 71031 | 71322 | assert( pOp->p4type==P4_INT32 ); |
| 71032 | - r.pKeyInfo = pC->pKeyInfo; | |
| 71033 | - r.nField = (u16)pOp->p4.i; | |
| 71323 | + u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo; | |
| 71324 | + u.bv.r.nField = (u16)pOp->p4.i; | |
| 71034 | 71325 | if( pOp->p5 ){ |
| 71035 | - r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH; | |
| 71326 | + u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH; | |
| 71036 | 71327 | }else{ |
| 71037 | - r.flags = UNPACKED_PREFIX_MATCH; | |
| 71328 | + u.bv.r.flags = UNPACKED_PREFIX_MATCH; | |
| 71038 | 71329 | } |
| 71039 | - r.aMem = &aMem[pOp->p3]; | |
| 71330 | + u.bv.r.aMem = &aMem[pOp->p3]; | |
| 71040 | 71331 | #ifdef SQLITE_DEBUG |
| 71041 | - { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } | |
| 71332 | + { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); } | |
| 71042 | 71333 | #endif |
| 71043 | - res = 0; /* Not needed. Only used to silence a warning. */ | |
| 71044 | - rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res); | |
| 71334 | + rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res); | |
| 71045 | 71335 | if( pOp->opcode==OP_IdxLT ){ |
| 71046 | - res = -res; | |
| 71336 | + u.bv.res = -u.bv.res; | |
| 71047 | 71337 | }else{ |
| 71048 | 71338 | assert( pOp->opcode==OP_IdxGE ); |
| 71049 | - res++; | |
| 71339 | + u.bv.res++; | |
| 71050 | 71340 | } |
| 71051 | - if( res>0 ){ | |
| 71341 | + if( u.bv.res>0 ){ | |
| 71052 | 71342 | pc = pOp->p2 - 1 ; |
| 71053 | 71343 | } |
| 71054 | 71344 | break; |
| 71055 | 71345 | } |
| 71056 | 71346 | |
| @@ -71073,46 +71363,47 @@ | ||
| 71073 | 71363 | ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 71074 | 71364 | ** |
| 71075 | 71365 | ** See also: Clear |
| 71076 | 71366 | */ |
| 71077 | 71367 | case OP_Destroy: { /* out2-prerelease */ |
| 71368 | +#if 0 /* local variables moved into u.bw */ | |
| 71078 | 71369 | int iMoved; |
| 71079 | 71370 | int iCnt; |
| 71080 | 71371 | Vdbe *pVdbe; |
| 71081 | 71372 | int iDb; |
| 71373 | +#endif /* local variables moved into u.bw */ | |
| 71082 | 71374 | |
| 71083 | 71375 | assert( p->readOnly==0 ); |
| 71084 | 71376 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 71085 | - iCnt = 0; | |
| 71086 | - for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){ | |
| 71087 | - if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader | |
| 71088 | - && pVdbe->inVtabMethod<2 && pVdbe->pc>=0 | |
| 71377 | + u.bw.iCnt = 0; | |
| 71378 | + for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){ | |
| 71379 | + if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader | |
| 71380 | + && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0 | |
| 71089 | 71381 | ){ |
| 71090 | - iCnt++; | |
| 71382 | + u.bw.iCnt++; | |
| 71091 | 71383 | } |
| 71092 | 71384 | } |
| 71093 | 71385 | #else |
| 71094 | - iCnt = db->nVdbeRead; | |
| 71386 | + u.bw.iCnt = db->nVdbeRead; | |
| 71095 | 71387 | #endif |
| 71096 | 71388 | pOut->flags = MEM_Null; |
| 71097 | - if( iCnt>1 ){ | |
| 71389 | + if( u.bw.iCnt>1 ){ | |
| 71098 | 71390 | rc = SQLITE_LOCKED; |
| 71099 | 71391 | p->errorAction = OE_Abort; |
| 71100 | 71392 | }else{ |
| 71101 | - iDb = pOp->p3; | |
| 71102 | - assert( iCnt==1 ); | |
| 71103 | - assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); | |
| 71104 | - iMoved = 0; /* Not needed. Only to silence a warning. */ | |
| 71105 | - rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved); | |
| 71393 | + u.bw.iDb = pOp->p3; | |
| 71394 | + assert( u.bw.iCnt==1 ); | |
| 71395 | + assert( (p->btreeMask & (((yDbMask)1)<<u.bw.iDb))!=0 ); | |
| 71396 | + rc = sqlite3BtreeDropTable(db->aDb[u.bw.iDb].pBt, pOp->p1, &u.bw.iMoved); | |
| 71106 | 71397 | pOut->flags = MEM_Int; |
| 71107 | - pOut->u.i = iMoved; | |
| 71398 | + pOut->u.i = u.bw.iMoved; | |
| 71108 | 71399 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 71109 | - if( rc==SQLITE_OK && iMoved!=0 ){ | |
| 71110 | - sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1); | |
| 71400 | + if( rc==SQLITE_OK && u.bw.iMoved!=0 ){ | |
| 71401 | + sqlite3RootPageMoved(db, u.bw.iDb, u.bw.iMoved, pOp->p1); | |
| 71111 | 71402 | /* All OP_Destroy operations occur on the same btree */ |
| 71112 | - assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 ); | |
| 71113 | - resetSchemaOnFault = iDb+1; | |
| 71403 | + assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.bw.iDb+1 ); | |
| 71404 | + resetSchemaOnFault = u.bw.iDb+1; | |
| 71114 | 71405 | } |
| 71115 | 71406 | #endif |
| 71116 | 71407 | } |
| 71117 | 71408 | break; |
| 71118 | 71409 | } |
| @@ -71134,25 +71425,27 @@ | ||
| 71134 | 71425 | ** also incremented by the number of rows in the table being cleared. |
| 71135 | 71426 | ** |
| 71136 | 71427 | ** See also: Destroy |
| 71137 | 71428 | */ |
| 71138 | 71429 | case OP_Clear: { |
| 71430 | +#if 0 /* local variables moved into u.bx */ | |
| 71139 | 71431 | int nChange; |
| 71140 | - | |
| 71141 | - nChange = 0; | |
| 71432 | +#endif /* local variables moved into u.bx */ | |
| 71433 | + | |
| 71434 | + u.bx.nChange = 0; | |
| 71142 | 71435 | assert( p->readOnly==0 ); |
| 71143 | 71436 | assert( pOp->p1!=1 ); |
| 71144 | 71437 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 ); |
| 71145 | 71438 | rc = sqlite3BtreeClearTable( |
| 71146 | - db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0) | |
| 71439 | + db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0) | |
| 71147 | 71440 | ); |
| 71148 | 71441 | if( pOp->p3 ){ |
| 71149 | - p->nChange += nChange; | |
| 71442 | + p->nChange += u.bx.nChange; | |
| 71150 | 71443 | if( pOp->p3>0 ){ |
| 71151 | 71444 | assert( memIsValid(&aMem[pOp->p3]) ); |
| 71152 | 71445 | memAboutToChange(p, &aMem[pOp->p3]); |
| 71153 | - aMem[pOp->p3].u.i += nChange; | |
| 71446 | + aMem[pOp->p3].u.i += u.bx.nChange; | |
| 71154 | 71447 | } |
| 71155 | 71448 | } |
| 71156 | 71449 | break; |
| 71157 | 71450 | } |
| 71158 | 71451 | |
| @@ -71180,28 +71473,30 @@ | ||
| 71180 | 71473 | ** |
| 71181 | 71474 | ** See documentation on OP_CreateTable for additional information. |
| 71182 | 71475 | */ |
| 71183 | 71476 | case OP_CreateIndex: /* out2-prerelease */ |
| 71184 | 71477 | case OP_CreateTable: { /* out2-prerelease */ |
| 71478 | +#if 0 /* local variables moved into u.by */ | |
| 71185 | 71479 | int pgno; |
| 71186 | 71480 | int flags; |
| 71187 | 71481 | Db *pDb; |
| 71482 | +#endif /* local variables moved into u.by */ | |
| 71188 | 71483 | |
| 71189 | - pgno = 0; | |
| 71484 | + u.by.pgno = 0; | |
| 71190 | 71485 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 71191 | 71486 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 71192 | 71487 | assert( p->readOnly==0 ); |
| 71193 | - pDb = &db->aDb[pOp->p1]; | |
| 71194 | - assert( pDb->pBt!=0 ); | |
| 71488 | + u.by.pDb = &db->aDb[pOp->p1]; | |
| 71489 | + assert( u.by.pDb->pBt!=0 ); | |
| 71195 | 71490 | if( pOp->opcode==OP_CreateTable ){ |
| 71196 | - /* flags = BTREE_INTKEY; */ | |
| 71197 | - flags = BTREE_INTKEY; | |
| 71491 | + /* u.by.flags = BTREE_INTKEY; */ | |
| 71492 | + u.by.flags = BTREE_INTKEY; | |
| 71198 | 71493 | }else{ |
| 71199 | - flags = BTREE_BLOBKEY; | |
| 71494 | + u.by.flags = BTREE_BLOBKEY; | |
| 71200 | 71495 | } |
| 71201 | - rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags); | |
| 71202 | - pOut->u.i = pgno; | |
| 71496 | + rc = sqlite3BtreeCreateTable(u.by.pDb->pBt, &u.by.pgno, u.by.flags); | |
| 71497 | + pOut->u.i = u.by.pgno; | |
| 71203 | 71498 | break; |
| 71204 | 71499 | } |
| 71205 | 71500 | |
| 71206 | 71501 | /* Opcode: ParseSchema P1 * * P4 * |
| 71207 | 71502 | ** |
| @@ -71210,54 +71505,56 @@ | ||
| 71210 | 71505 | ** |
| 71211 | 71506 | ** This opcode invokes the parser to create a new virtual machine, |
| 71212 | 71507 | ** then runs the new virtual machine. It is thus a re-entrant opcode. |
| 71213 | 71508 | */ |
| 71214 | 71509 | case OP_ParseSchema: { |
| 71510 | +#if 0 /* local variables moved into u.bz */ | |
| 71215 | 71511 | int iDb; |
| 71216 | 71512 | const char *zMaster; |
| 71217 | 71513 | char *zSql; |
| 71218 | 71514 | InitData initData; |
| 71515 | +#endif /* local variables moved into u.bz */ | |
| 71219 | 71516 | |
| 71220 | 71517 | /* Any prepared statement that invokes this opcode will hold mutexes |
| 71221 | - ** on every btree. This is a prerequisite for invoking | |
| 71518 | + ** on every btree. This is a prerequisite for invoking | |
| 71222 | 71519 | ** sqlite3InitCallback(). |
| 71223 | 71520 | */ |
| 71224 | 71521 | #ifdef SQLITE_DEBUG |
| 71225 | - for(iDb=0; iDb<db->nDb; iDb++){ | |
| 71226 | - assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); | |
| 71522 | + for(u.bz.iDb=0; u.bz.iDb<db->nDb; u.bz.iDb++){ | |
| 71523 | + assert( u.bz.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bz.iDb].pBt) ); | |
| 71227 | 71524 | } |
| 71228 | 71525 | #endif |
| 71229 | 71526 | |
| 71230 | - iDb = pOp->p1; | |
| 71231 | - assert( iDb>=0 && iDb<db->nDb ); | |
| 71232 | - assert( DbHasProperty(db, iDb, DB_SchemaLoaded) ); | |
| 71527 | + u.bz.iDb = pOp->p1; | |
| 71528 | + assert( u.bz.iDb>=0 && u.bz.iDb<db->nDb ); | |
| 71529 | + assert( DbHasProperty(db, u.bz.iDb, DB_SchemaLoaded) ); | |
| 71233 | 71530 | /* Used to be a conditional */ { |
| 71234 | - zMaster = SCHEMA_TABLE(iDb); | |
| 71235 | - initData.db = db; | |
| 71236 | - initData.iDb = pOp->p1; | |
| 71237 | - initData.pzErrMsg = &p->zErrMsg; | |
| 71238 | - zSql = sqlite3MPrintf(db, | |
| 71531 | + u.bz.zMaster = SCHEMA_TABLE(u.bz.iDb); | |
| 71532 | + u.bz.initData.db = db; | |
| 71533 | + u.bz.initData.iDb = pOp->p1; | |
| 71534 | + u.bz.initData.pzErrMsg = &p->zErrMsg; | |
| 71535 | + u.bz.zSql = sqlite3MPrintf(db, | |
| 71239 | 71536 | "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid", |
| 71240 | - db->aDb[iDb].zName, zMaster, pOp->p4.z); | |
| 71241 | - if( zSql==0 ){ | |
| 71537 | + db->aDb[u.bz.iDb].zName, u.bz.zMaster, pOp->p4.z); | |
| 71538 | + if( u.bz.zSql==0 ){ | |
| 71242 | 71539 | rc = SQLITE_NOMEM; |
| 71243 | 71540 | }else{ |
| 71244 | 71541 | assert( db->init.busy==0 ); |
| 71245 | 71542 | db->init.busy = 1; |
| 71246 | - initData.rc = SQLITE_OK; | |
| 71543 | + u.bz.initData.rc = SQLITE_OK; | |
| 71247 | 71544 | assert( !db->mallocFailed ); |
| 71248 | - rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); | |
| 71249 | - if( rc==SQLITE_OK ) rc = initData.rc; | |
| 71250 | - sqlite3DbFree(db, zSql); | |
| 71545 | + rc = sqlite3_exec(db, u.bz.zSql, sqlite3InitCallback, &u.bz.initData, 0); | |
| 71546 | + if( rc==SQLITE_OK ) rc = u.bz.initData.rc; | |
| 71547 | + sqlite3DbFree(db, u.bz.zSql); | |
| 71251 | 71548 | db->init.busy = 0; |
| 71252 | 71549 | } |
| 71253 | 71550 | } |
| 71254 | 71551 | if( rc ) sqlite3ResetAllSchemasOfConnection(db); |
| 71255 | 71552 | if( rc==SQLITE_NOMEM ){ |
| 71256 | 71553 | goto no_mem; |
| 71257 | 71554 | } |
| 71258 | - break; | |
| 71555 | + break; | |
| 71259 | 71556 | } |
| 71260 | 71557 | |
| 71261 | 71558 | #if !defined(SQLITE_OMIT_ANALYZE) |
| 71262 | 71559 | /* Opcode: LoadAnalysis P1 * * * * |
| 71263 | 71560 | ** |
| @@ -71329,44 +71626,46 @@ | ||
| 71329 | 71626 | ** file, not the main database file. |
| 71330 | 71627 | ** |
| 71331 | 71628 | ** This opcode is used to implement the integrity_check pragma. |
| 71332 | 71629 | */ |
| 71333 | 71630 | case OP_IntegrityCk: { |
| 71631 | +#if 0 /* local variables moved into u.ca */ | |
| 71334 | 71632 | int nRoot; /* Number of tables to check. (Number of root pages.) */ |
| 71335 | 71633 | int *aRoot; /* Array of rootpage numbers for tables to be checked */ |
| 71336 | 71634 | int j; /* Loop counter */ |
| 71337 | 71635 | int nErr; /* Number of errors reported */ |
| 71338 | 71636 | char *z; /* Text of the error report */ |
| 71339 | 71637 | Mem *pnErr; /* Register keeping track of errors remaining */ |
| 71638 | +#endif /* local variables moved into u.ca */ | |
| 71340 | 71639 | |
| 71341 | 71640 | assert( p->bIsReader ); |
| 71342 | - nRoot = pOp->p2; | |
| 71343 | - assert( nRoot>0 ); | |
| 71344 | - aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) ); | |
| 71345 | - if( aRoot==0 ) goto no_mem; | |
| 71641 | + u.ca.nRoot = pOp->p2; | |
| 71642 | + assert( u.ca.nRoot>0 ); | |
| 71643 | + u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) ); | |
| 71644 | + if( u.ca.aRoot==0 ) goto no_mem; | |
| 71346 | 71645 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 71347 | - pnErr = &aMem[pOp->p3]; | |
| 71348 | - assert( (pnErr->flags & MEM_Int)!=0 ); | |
| 71349 | - assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 ); | |
| 71646 | + u.ca.pnErr = &aMem[pOp->p3]; | |
| 71647 | + assert( (u.ca.pnErr->flags & MEM_Int)!=0 ); | |
| 71648 | + assert( (u.ca.pnErr->flags & (MEM_Str|MEM_Blob))==0 ); | |
| 71350 | 71649 | pIn1 = &aMem[pOp->p1]; |
| 71351 | - for(j=0; j<nRoot; j++){ | |
| 71352 | - aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]); | |
| 71650 | + for(u.ca.j=0; u.ca.j<u.ca.nRoot; u.ca.j++){ | |
| 71651 | + u.ca.aRoot[u.ca.j] = (int)sqlite3VdbeIntValue(&pIn1[u.ca.j]); | |
| 71353 | 71652 | } |
| 71354 | - aRoot[j] = 0; | |
| 71653 | + u.ca.aRoot[u.ca.j] = 0; | |
| 71355 | 71654 | assert( pOp->p5<db->nDb ); |
| 71356 | 71655 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 ); |
| 71357 | - z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot, | |
| 71358 | - (int)pnErr->u.i, &nErr); | |
| 71359 | - sqlite3DbFree(db, aRoot); | |
| 71360 | - pnErr->u.i -= nErr; | |
| 71656 | + u.ca.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.ca.aRoot, u.ca.nRoot, | |
| 71657 | + (int)u.ca.pnErr->u.i, &u.ca.nErr); | |
| 71658 | + sqlite3DbFree(db, u.ca.aRoot); | |
| 71659 | + u.ca.pnErr->u.i -= u.ca.nErr; | |
| 71361 | 71660 | sqlite3VdbeMemSetNull(pIn1); |
| 71362 | - if( nErr==0 ){ | |
| 71363 | - assert( z==0 ); | |
| 71364 | - }else if( z==0 ){ | |
| 71661 | + if( u.ca.nErr==0 ){ | |
| 71662 | + assert( u.ca.z==0 ); | |
| 71663 | + }else if( u.ca.z==0 ){ | |
| 71365 | 71664 | goto no_mem; |
| 71366 | 71665 | }else{ |
| 71367 | - sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free); | |
| 71666 | + sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free); | |
| 71368 | 71667 | } |
| 71369 | 71668 | UPDATE_MAX_BLOBSIZE(pIn1); |
| 71370 | 71669 | sqlite3VdbeChangeEncoding(pIn1, encoding); |
| 71371 | 71670 | break; |
| 71372 | 71671 | } |
| @@ -71398,22 +71697,24 @@ | ||
| 71398 | 71697 | ** Extract the smallest value from boolean index P1 and put that value into |
| 71399 | 71698 | ** register P3. Or, if boolean index P1 is initially empty, leave P3 |
| 71400 | 71699 | ** unchanged and jump to instruction P2. |
| 71401 | 71700 | */ |
| 71402 | 71701 | case OP_RowSetRead: { /* jump, in1, out3 */ |
| 71702 | +#if 0 /* local variables moved into u.cb */ | |
| 71403 | 71703 | i64 val; |
| 71704 | +#endif /* local variables moved into u.cb */ | |
| 71404 | 71705 | |
| 71405 | 71706 | pIn1 = &aMem[pOp->p1]; |
| 71406 | - if( (pIn1->flags & MEM_RowSet)==0 | |
| 71407 | - || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 | |
| 71707 | + if( (pIn1->flags & MEM_RowSet)==0 | |
| 71708 | + || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0 | |
| 71408 | 71709 | ){ |
| 71409 | 71710 | /* The boolean index is empty */ |
| 71410 | 71711 | sqlite3VdbeMemSetNull(pIn1); |
| 71411 | 71712 | pc = pOp->p2 - 1; |
| 71412 | 71713 | }else{ |
| 71413 | 71714 | /* A value was pulled from the index */ |
| 71414 | - sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); | |
| 71715 | + sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val); | |
| 71415 | 71716 | } |
| 71416 | 71717 | goto check_for_interrupt; |
| 71417 | 71718 | } |
| 71418 | 71719 | |
| 71419 | 71720 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| @@ -71439,16 +71740,18 @@ | ||
| 71439 | 71740 | ** inserted, there is no need to search to see if the same value was |
| 71440 | 71741 | ** previously inserted as part of set X (only if it was previously |
| 71441 | 71742 | ** inserted as part of some other set). |
| 71442 | 71743 | */ |
| 71443 | 71744 | case OP_RowSetTest: { /* jump, in1, in3 */ |
| 71745 | +#if 0 /* local variables moved into u.cc */ | |
| 71444 | 71746 | int iSet; |
| 71445 | 71747 | int exists; |
| 71748 | +#endif /* local variables moved into u.cc */ | |
| 71446 | 71749 | |
| 71447 | 71750 | pIn1 = &aMem[pOp->p1]; |
| 71448 | 71751 | pIn3 = &aMem[pOp->p3]; |
| 71449 | - iSet = pOp->p4.i; | |
| 71752 | + u.cc.iSet = pOp->p4.i; | |
| 71450 | 71753 | assert( pIn3->flags&MEM_Int ); |
| 71451 | 71754 | |
| 71452 | 71755 | /* If there is anything other than a rowset object in memory cell P1, |
| 71453 | 71756 | ** delete it now and initialize P1 with an empty rowset |
| 71454 | 71757 | */ |
| @@ -71456,21 +71759,21 @@ | ||
| 71456 | 71759 | sqlite3VdbeMemSetRowSet(pIn1); |
| 71457 | 71760 | if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem; |
| 71458 | 71761 | } |
| 71459 | 71762 | |
| 71460 | 71763 | assert( pOp->p4type==P4_INT32 ); |
| 71461 | - assert( iSet==-1 || iSet>=0 ); | |
| 71462 | - if( iSet ){ | |
| 71463 | - exists = sqlite3RowSetTest(pIn1->u.pRowSet, | |
| 71464 | - (u8)(iSet>=0 ? iSet & 0xf : 0xff), | |
| 71764 | + assert( u.cc.iSet==-1 || u.cc.iSet>=0 ); | |
| 71765 | + if( u.cc.iSet ){ | |
| 71766 | + u.cc.exists = sqlite3RowSetTest(pIn1->u.pRowSet, | |
| 71767 | + (u8)(u.cc.iSet>=0 ? u.cc.iSet & 0xf : 0xff), | |
| 71465 | 71768 | pIn3->u.i); |
| 71466 | - if( exists ){ | |
| 71769 | + if( u.cc.exists ){ | |
| 71467 | 71770 | pc = pOp->p2 - 1; |
| 71468 | 71771 | break; |
| 71469 | 71772 | } |
| 71470 | 71773 | } |
| 71471 | - if( iSet>=0 ){ | |
| 71774 | + if( u.cc.iSet>=0 ){ | |
| 71472 | 71775 | sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 71473 | 71776 | } |
| 71474 | 71777 | break; |
| 71475 | 71778 | } |
| 71476 | 71779 | |
| @@ -71489,109 +71792,111 @@ | ||
| 71489 | 71792 | ** memory required by the sub-vdbe at runtime. |
| 71490 | 71793 | ** |
| 71491 | 71794 | ** P4 is a pointer to the VM containing the trigger program. |
| 71492 | 71795 | */ |
| 71493 | 71796 | case OP_Program: { /* jump */ |
| 71797 | +#if 0 /* local variables moved into u.cd */ | |
| 71494 | 71798 | int nMem; /* Number of memory registers for sub-program */ |
| 71495 | 71799 | int nByte; /* Bytes of runtime space required for sub-program */ |
| 71496 | 71800 | Mem *pRt; /* Register to allocate runtime space */ |
| 71497 | 71801 | Mem *pMem; /* Used to iterate through memory cells */ |
| 71498 | 71802 | Mem *pEnd; /* Last memory cell in new array */ |
| 71499 | 71803 | VdbeFrame *pFrame; /* New vdbe frame to execute in */ |
| 71500 | 71804 | SubProgram *pProgram; /* Sub-program to execute */ |
| 71501 | 71805 | void *t; /* Token identifying trigger */ |
| 71806 | +#endif /* local variables moved into u.cd */ | |
| 71502 | 71807 | |
| 71503 | - pProgram = pOp->p4.pProgram; | |
| 71504 | - pRt = &aMem[pOp->p3]; | |
| 71505 | - assert( pProgram->nOp>0 ); | |
| 71506 | - | |
| 71507 | - /* If the p5 flag is clear, then recursive invocation of triggers is | |
| 71808 | + u.cd.pProgram = pOp->p4.pProgram; | |
| 71809 | + u.cd.pRt = &aMem[pOp->p3]; | |
| 71810 | + assert( u.cd.pProgram->nOp>0 ); | |
| 71811 | + | |
| 71812 | + /* If the p5 flag is clear, then recursive invocation of triggers is | |
| 71508 | 71813 | ** disabled for backwards compatibility (p5 is set if this sub-program |
| 71509 | 71814 | ** is really a trigger, not a foreign key action, and the flag set |
| 71510 | 71815 | ** and cleared by the "PRAGMA recursive_triggers" command is clear). |
| 71511 | - ** | |
| 71512 | - ** It is recursive invocation of triggers, at the SQL level, that is | |
| 71513 | - ** disabled. In some cases a single trigger may generate more than one | |
| 71514 | - ** SubProgram (if the trigger may be executed with more than one different | |
| 71816 | + ** | |
| 71817 | + ** It is recursive invocation of triggers, at the SQL level, that is | |
| 71818 | + ** disabled. In some cases a single trigger may generate more than one | |
| 71819 | + ** SubProgram (if the trigger may be executed with more than one different | |
| 71515 | 71820 | ** ON CONFLICT algorithm). SubProgram structures associated with a |
| 71516 | - ** single trigger all have the same value for the SubProgram.token | |
| 71821 | + ** single trigger all have the same value for the SubProgram.token | |
| 71517 | 71822 | ** variable. */ |
| 71518 | 71823 | if( pOp->p5 ){ |
| 71519 | - t = pProgram->token; | |
| 71520 | - for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent); | |
| 71521 | - if( pFrame ) break; | |
| 71824 | + u.cd.t = u.cd.pProgram->token; | |
| 71825 | + for(u.cd.pFrame=p->pFrame; u.cd.pFrame && u.cd.pFrame->token!=u.cd.t; u.cd.pFrame=u.cd.pFrame->pParent); | |
| 71826 | + if( u.cd.pFrame ) break; | |
| 71522 | 71827 | } |
| 71523 | 71828 | |
| 71524 | 71829 | if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 71525 | 71830 | rc = SQLITE_ERROR; |
| 71526 | 71831 | sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion"); |
| 71527 | 71832 | break; |
| 71528 | 71833 | } |
| 71529 | 71834 | |
| 71530 | - /* Register pRt is used to store the memory required to save the state | |
| 71835 | + /* Register u.cd.pRt is used to store the memory required to save the state | |
| 71531 | 71836 | ** of the current program, and the memory required at runtime to execute |
| 71532 | - ** the trigger program. If this trigger has been fired before, then pRt | |
| 71837 | + ** the trigger program. If this trigger has been fired before, then u.cd.pRt | |
| 71533 | 71838 | ** is already allocated. Otherwise, it must be initialized. */ |
| 71534 | - if( (pRt->flags&MEM_Frame)==0 ){ | |
| 71535 | - /* SubProgram.nMem is set to the number of memory cells used by the | |
| 71839 | + if( (u.cd.pRt->flags&MEM_Frame)==0 ){ | |
| 71840 | + /* SubProgram.nMem is set to the number of memory cells used by the | |
| 71536 | 71841 | ** program stored in SubProgram.aOp. As well as these, one memory |
| 71537 | 71842 | ** cell is required for each cursor used by the program. Set local |
| 71538 | - ** variable nMem (and later, VdbeFrame.nChildMem) to this value. | |
| 71843 | + ** variable u.cd.nMem (and later, VdbeFrame.nChildMem) to this value. | |
| 71539 | 71844 | */ |
| 71540 | - nMem = pProgram->nMem + pProgram->nCsr; | |
| 71541 | - nByte = ROUND8(sizeof(VdbeFrame)) | |
| 71542 | - + nMem * sizeof(Mem) | |
| 71543 | - + pProgram->nCsr * sizeof(VdbeCursor *) | |
| 71544 | - + pProgram->nOnce * sizeof(u8); | |
| 71545 | - pFrame = sqlite3DbMallocZero(db, nByte); | |
| 71546 | - if( !pFrame ){ | |
| 71845 | + u.cd.nMem = u.cd.pProgram->nMem + u.cd.pProgram->nCsr; | |
| 71846 | + u.cd.nByte = ROUND8(sizeof(VdbeFrame)) | |
| 71847 | + + u.cd.nMem * sizeof(Mem) | |
| 71848 | + + u.cd.pProgram->nCsr * sizeof(VdbeCursor *) | |
| 71849 | + + u.cd.pProgram->nOnce * sizeof(u8); | |
| 71850 | + u.cd.pFrame = sqlite3DbMallocZero(db, u.cd.nByte); | |
| 71851 | + if( !u.cd.pFrame ){ | |
| 71547 | 71852 | goto no_mem; |
| 71548 | 71853 | } |
| 71549 | - sqlite3VdbeMemRelease(pRt); | |
| 71550 | - pRt->flags = MEM_Frame; | |
| 71551 | - pRt->u.pFrame = pFrame; | |
| 71552 | - | |
| 71553 | - pFrame->v = p; | |
| 71554 | - pFrame->nChildMem = nMem; | |
| 71555 | - pFrame->nChildCsr = pProgram->nCsr; | |
| 71556 | - pFrame->pc = pc; | |
| 71557 | - pFrame->aMem = p->aMem; | |
| 71558 | - pFrame->nMem = p->nMem; | |
| 71559 | - pFrame->apCsr = p->apCsr; | |
| 71560 | - pFrame->nCursor = p->nCursor; | |
| 71561 | - pFrame->aOp = p->aOp; | |
| 71562 | - pFrame->nOp = p->nOp; | |
| 71563 | - pFrame->token = pProgram->token; | |
| 71564 | - pFrame->aOnceFlag = p->aOnceFlag; | |
| 71565 | - pFrame->nOnceFlag = p->nOnceFlag; | |
| 71566 | - | |
| 71567 | - pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; | |
| 71568 | - for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ | |
| 71569 | - pMem->flags = MEM_Invalid; | |
| 71570 | - pMem->db = db; | |
| 71854 | + sqlite3VdbeMemRelease(u.cd.pRt); | |
| 71855 | + u.cd.pRt->flags = MEM_Frame; | |
| 71856 | + u.cd.pRt->u.pFrame = u.cd.pFrame; | |
| 71857 | + | |
| 71858 | + u.cd.pFrame->v = p; | |
| 71859 | + u.cd.pFrame->nChildMem = u.cd.nMem; | |
| 71860 | + u.cd.pFrame->nChildCsr = u.cd.pProgram->nCsr; | |
| 71861 | + u.cd.pFrame->pc = pc; | |
| 71862 | + u.cd.pFrame->aMem = p->aMem; | |
| 71863 | + u.cd.pFrame->nMem = p->nMem; | |
| 71864 | + u.cd.pFrame->apCsr = p->apCsr; | |
| 71865 | + u.cd.pFrame->nCursor = p->nCursor; | |
| 71866 | + u.cd.pFrame->aOp = p->aOp; | |
| 71867 | + u.cd.pFrame->nOp = p->nOp; | |
| 71868 | + u.cd.pFrame->token = u.cd.pProgram->token; | |
| 71869 | + u.cd.pFrame->aOnceFlag = p->aOnceFlag; | |
| 71870 | + u.cd.pFrame->nOnceFlag = p->nOnceFlag; | |
| 71871 | + | |
| 71872 | + u.cd.pEnd = &VdbeFrameMem(u.cd.pFrame)[u.cd.pFrame->nChildMem]; | |
| 71873 | + for(u.cd.pMem=VdbeFrameMem(u.cd.pFrame); u.cd.pMem!=u.cd.pEnd; u.cd.pMem++){ | |
| 71874 | + u.cd.pMem->flags = MEM_Invalid; | |
| 71875 | + u.cd.pMem->db = db; | |
| 71571 | 71876 | } |
| 71572 | 71877 | }else{ |
| 71573 | - pFrame = pRt->u.pFrame; | |
| 71574 | - assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); | |
| 71575 | - assert( pProgram->nCsr==pFrame->nChildCsr ); | |
| 71576 | - assert( pc==pFrame->pc ); | |
| 71878 | + u.cd.pFrame = u.cd.pRt->u.pFrame; | |
| 71879 | + assert( u.cd.pProgram->nMem+u.cd.pProgram->nCsr==u.cd.pFrame->nChildMem ); | |
| 71880 | + assert( u.cd.pProgram->nCsr==u.cd.pFrame->nChildCsr ); | |
| 71881 | + assert( pc==u.cd.pFrame->pc ); | |
| 71577 | 71882 | } |
| 71578 | 71883 | |
| 71579 | 71884 | p->nFrame++; |
| 71580 | - pFrame->pParent = p->pFrame; | |
| 71581 | - pFrame->lastRowid = lastRowid; | |
| 71582 | - pFrame->nChange = p->nChange; | |
| 71885 | + u.cd.pFrame->pParent = p->pFrame; | |
| 71886 | + u.cd.pFrame->lastRowid = lastRowid; | |
| 71887 | + u.cd.pFrame->nChange = p->nChange; | |
| 71583 | 71888 | p->nChange = 0; |
| 71584 | - p->pFrame = pFrame; | |
| 71585 | - p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; | |
| 71586 | - p->nMem = pFrame->nChildMem; | |
| 71587 | - p->nCursor = (u16)pFrame->nChildCsr; | |
| 71889 | + p->pFrame = u.cd.pFrame; | |
| 71890 | + p->aMem = aMem = &VdbeFrameMem(u.cd.pFrame)[-1]; | |
| 71891 | + p->nMem = u.cd.pFrame->nChildMem; | |
| 71892 | + p->nCursor = (u16)u.cd.pFrame->nChildCsr; | |
| 71588 | 71893 | p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 71589 | - p->aOp = aOp = pProgram->aOp; | |
| 71590 | - p->nOp = pProgram->nOp; | |
| 71894 | + p->aOp = aOp = u.cd.pProgram->aOp; | |
| 71895 | + p->nOp = u.cd.pProgram->nOp; | |
| 71591 | 71896 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 71592 | - p->nOnceFlag = pProgram->nOnce; | |
| 71897 | + p->nOnceFlag = u.cd.pProgram->nOnce; | |
| 71593 | 71898 | pc = -1; |
| 71594 | 71899 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 71595 | 71900 | |
| 71596 | 71901 | break; |
| 71597 | 71902 | } |
| @@ -71607,15 +71912,17 @@ | ||
| 71607 | 71912 | ** The address of the cell in the parent frame is determined by adding |
| 71608 | 71913 | ** the value of the P1 argument to the value of the P1 argument to the |
| 71609 | 71914 | ** calling OP_Program instruction. |
| 71610 | 71915 | */ |
| 71611 | 71916 | case OP_Param: { /* out2-prerelease */ |
| 71917 | +#if 0 /* local variables moved into u.ce */ | |
| 71612 | 71918 | VdbeFrame *pFrame; |
| 71613 | 71919 | Mem *pIn; |
| 71614 | - pFrame = p->pFrame; | |
| 71615 | - pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; | |
| 71616 | - sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); | |
| 71920 | +#endif /* local variables moved into u.ce */ | |
| 71921 | + u.ce.pFrame = p->pFrame; | |
| 71922 | + u.ce.pIn = &u.ce.pFrame->aMem[pOp->p1 + u.ce.pFrame->aOp[u.ce.pFrame->pc].p1]; | |
| 71923 | + sqlite3VdbeMemShallowCopy(pOut, u.ce.pIn, MEM_Ephem); | |
| 71617 | 71924 | break; |
| 71618 | 71925 | } |
| 71619 | 71926 | |
| 71620 | 71927 | #endif /* #ifndef SQLITE_OMIT_TRIGGER */ |
| 71621 | 71928 | |
| @@ -71672,23 +71979,26 @@ | ||
| 71672 | 71979 | ** |
| 71673 | 71980 | ** This instruction throws an error if the memory cell is not initially |
| 71674 | 71981 | ** an integer. |
| 71675 | 71982 | */ |
| 71676 | 71983 | case OP_MemMax: { /* in2 */ |
| 71984 | +#if 0 /* local variables moved into u.cf */ | |
| 71985 | + Mem *pIn1; | |
| 71677 | 71986 | VdbeFrame *pFrame; |
| 71987 | +#endif /* local variables moved into u.cf */ | |
| 71678 | 71988 | if( p->pFrame ){ |
| 71679 | - for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); | |
| 71680 | - pIn1 = &pFrame->aMem[pOp->p1]; | |
| 71989 | + for(u.cf.pFrame=p->pFrame; u.cf.pFrame->pParent; u.cf.pFrame=u.cf.pFrame->pParent); | |
| 71990 | + u.cf.pIn1 = &u.cf.pFrame->aMem[pOp->p1]; | |
| 71681 | 71991 | }else{ |
| 71682 | - pIn1 = &aMem[pOp->p1]; | |
| 71992 | + u.cf.pIn1 = &aMem[pOp->p1]; | |
| 71683 | 71993 | } |
| 71684 | - assert( memIsValid(pIn1) ); | |
| 71685 | - sqlite3VdbeMemIntegerify(pIn1); | |
| 71994 | + assert( memIsValid(u.cf.pIn1) ); | |
| 71995 | + sqlite3VdbeMemIntegerify(u.cf.pIn1); | |
| 71686 | 71996 | pIn2 = &aMem[pOp->p2]; |
| 71687 | 71997 | sqlite3VdbeMemIntegerify(pIn2); |
| 71688 | - if( pIn1->u.i<pIn2->u.i){ | |
| 71689 | - pIn1->u.i = pIn2->u.i; | |
| 71998 | + if( u.cf.pIn1->u.i<pIn2->u.i){ | |
| 71999 | + u.cf.pIn1->u.i = pIn2->u.i; | |
| 71690 | 72000 | } |
| 71691 | 72001 | break; |
| 71692 | 72002 | } |
| 71693 | 72003 | #endif /* SQLITE_OMIT_AUTOINCREMENT */ |
| 71694 | 72004 | |
| @@ -71755,58 +72065,60 @@ | ||
| 71755 | 72065 | ** |
| 71756 | 72066 | ** The P5 arguments are taken from register P2 and its |
| 71757 | 72067 | ** successors. |
| 71758 | 72068 | */ |
| 71759 | 72069 | case OP_AggStep: { |
| 72070 | +#if 0 /* local variables moved into u.cg */ | |
| 71760 | 72071 | int n; |
| 71761 | 72072 | int i; |
| 71762 | 72073 | Mem *pMem; |
| 71763 | 72074 | Mem *pRec; |
| 71764 | 72075 | sqlite3_context ctx; |
| 71765 | 72076 | sqlite3_value **apVal; |
| 71766 | - | |
| 71767 | - n = pOp->p5; | |
| 71768 | - assert( n>=0 ); | |
| 71769 | - pRec = &aMem[pOp->p2]; | |
| 71770 | - apVal = p->apArg; | |
| 71771 | - assert( apVal || n==0 ); | |
| 71772 | - for(i=0; i<n; i++, pRec++){ | |
| 71773 | - assert( memIsValid(pRec) ); | |
| 71774 | - apVal[i] = pRec; | |
| 71775 | - memAboutToChange(p, pRec); | |
| 71776 | - sqlite3VdbeMemStoreType(pRec); | |
| 71777 | - } | |
| 71778 | - ctx.pFunc = pOp->p4.pFunc; | |
| 72077 | +#endif /* local variables moved into u.cg */ | |
| 72078 | + | |
| 72079 | + u.cg.n = pOp->p5; | |
| 72080 | + assert( u.cg.n>=0 ); | |
| 72081 | + u.cg.pRec = &aMem[pOp->p2]; | |
| 72082 | + u.cg.apVal = p->apArg; | |
| 72083 | + assert( u.cg.apVal || u.cg.n==0 ); | |
| 72084 | + for(u.cg.i=0; u.cg.i<u.cg.n; u.cg.i++, u.cg.pRec++){ | |
| 72085 | + assert( memIsValid(u.cg.pRec) ); | |
| 72086 | + u.cg.apVal[u.cg.i] = u.cg.pRec; | |
| 72087 | + memAboutToChange(p, u.cg.pRec); | |
| 72088 | + sqlite3VdbeMemStoreType(u.cg.pRec); | |
| 72089 | + } | |
| 72090 | + u.cg.ctx.pFunc = pOp->p4.pFunc; | |
| 71779 | 72091 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 71780 | - ctx.pMem = pMem = &aMem[pOp->p3]; | |
| 71781 | - pMem->n++; | |
| 71782 | - ctx.s.flags = MEM_Null; | |
| 71783 | - ctx.s.z = 0; | |
| 71784 | - ctx.s.zMalloc = 0; | |
| 71785 | - ctx.s.xDel = 0; | |
| 71786 | - ctx.s.db = db; | |
| 71787 | - ctx.isError = 0; | |
| 71788 | - ctx.pColl = 0; | |
| 71789 | - ctx.skipFlag = 0; | |
| 71790 | - if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ | |
| 72092 | + u.cg.ctx.pMem = u.cg.pMem = &aMem[pOp->p3]; | |
| 72093 | + u.cg.pMem->n++; | |
| 72094 | + u.cg.ctx.s.flags = MEM_Null; | |
| 72095 | + u.cg.ctx.s.z = 0; | |
| 72096 | + u.cg.ctx.s.zMalloc = 0; | |
| 72097 | + u.cg.ctx.s.xDel = 0; | |
| 72098 | + u.cg.ctx.s.db = db; | |
| 72099 | + u.cg.ctx.isError = 0; | |
| 72100 | + u.cg.ctx.pColl = 0; | |
| 72101 | + u.cg.ctx.skipFlag = 0; | |
| 72102 | + if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ | |
| 71791 | 72103 | assert( pOp>p->aOp ); |
| 71792 | 72104 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 71793 | 72105 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 71794 | - ctx.pColl = pOp[-1].p4.pColl; | |
| 71795 | - } | |
| 71796 | - (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ | |
| 71797 | - if( ctx.isError ){ | |
| 71798 | - sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); | |
| 71799 | - rc = ctx.isError; | |
| 71800 | - } | |
| 71801 | - if( ctx.skipFlag ){ | |
| 72106 | + u.cg.ctx.pColl = pOp[-1].p4.pColl; | |
| 72107 | + } | |
| 72108 | + (u.cg.ctx.pFunc->xStep)(&u.cg.ctx, u.cg.n, u.cg.apVal); /* IMP: R-24505-23230 */ | |
| 72109 | + if( u.cg.ctx.isError ){ | |
| 72110 | + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cg.ctx.s)); | |
| 72111 | + rc = u.cg.ctx.isError; | |
| 72112 | + } | |
| 72113 | + if( u.cg.ctx.skipFlag ){ | |
| 71802 | 72114 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 71803 | - i = pOp[-1].p1; | |
| 71804 | - if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); | |
| 72115 | + u.cg.i = pOp[-1].p1; | |
| 72116 | + if( u.cg.i ) sqlite3VdbeMemSetInt64(&aMem[u.cg.i], 1); | |
| 71805 | 72117 | } |
| 71806 | 72118 | |
| 71807 | - sqlite3VdbeMemRelease(&ctx.s); | |
| 72119 | + sqlite3VdbeMemRelease(&u.cg.ctx.s); | |
| 71808 | 72120 | |
| 71809 | 72121 | break; |
| 71810 | 72122 | } |
| 71811 | 72123 | |
| 71812 | 72124 | /* Opcode: AggFinal P1 P2 * P4 * |
| @@ -71821,21 +72133,23 @@ | ||
| 71821 | 72133 | ** functions that can take varying numbers of arguments. The |
| 71822 | 72134 | ** P4 argument is only needed for the degenerate case where |
| 71823 | 72135 | ** the step function was not previously called. |
| 71824 | 72136 | */ |
| 71825 | 72137 | case OP_AggFinal: { |
| 72138 | +#if 0 /* local variables moved into u.ch */ | |
| 71826 | 72139 | Mem *pMem; |
| 72140 | +#endif /* local variables moved into u.ch */ | |
| 71827 | 72141 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 71828 | - pMem = &aMem[pOp->p1]; | |
| 71829 | - assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); | |
| 71830 | - rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc); | |
| 72142 | + u.ch.pMem = &aMem[pOp->p1]; | |
| 72143 | + assert( (u.ch.pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); | |
| 72144 | + rc = sqlite3VdbeMemFinalize(u.ch.pMem, pOp->p4.pFunc); | |
| 71831 | 72145 | if( rc ){ |
| 71832 | - sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem)); | |
| 72146 | + sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem)); | |
| 71833 | 72147 | } |
| 71834 | - sqlite3VdbeChangeEncoding(pMem, encoding); | |
| 71835 | - UPDATE_MAX_BLOBSIZE(pMem); | |
| 71836 | - if( sqlite3VdbeMemTooBig(pMem) ){ | |
| 72148 | + sqlite3VdbeChangeEncoding(u.ch.pMem, encoding); | |
| 72149 | + UPDATE_MAX_BLOBSIZE(u.ch.pMem); | |
| 72150 | + if( sqlite3VdbeMemTooBig(u.ch.pMem) ){ | |
| 71837 | 72151 | goto too_big; |
| 71838 | 72152 | } |
| 71839 | 72153 | break; |
| 71840 | 72154 | } |
| 71841 | 72155 | |
| @@ -71850,29 +72164,31 @@ | ||
| 71850 | 72164 | ** in the WAL that have been checkpointed after the checkpoint |
| 71851 | 72165 | ** completes into mem[P3+2]. However on an error, mem[P3+1] and |
| 71852 | 72166 | ** mem[P3+2] are initialized to -1. |
| 71853 | 72167 | */ |
| 71854 | 72168 | case OP_Checkpoint: { |
| 72169 | +#if 0 /* local variables moved into u.ci */ | |
| 71855 | 72170 | int i; /* Loop counter */ |
| 71856 | 72171 | int aRes[3]; /* Results */ |
| 71857 | 72172 | Mem *pMem; /* Write results here */ |
| 72173 | +#endif /* local variables moved into u.ci */ | |
| 71858 | 72174 | |
| 71859 | 72175 | assert( p->readOnly==0 ); |
| 71860 | - aRes[0] = 0; | |
| 71861 | - aRes[1] = aRes[2] = -1; | |
| 72176 | + u.ci.aRes[0] = 0; | |
| 72177 | + u.ci.aRes[1] = u.ci.aRes[2] = -1; | |
| 71862 | 72178 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 71863 | 72179 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 71864 | 72180 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 71865 | 72181 | ); |
| 71866 | - rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); | |
| 72182 | + rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ci.aRes[1], &u.ci.aRes[2]); | |
| 71867 | 72183 | if( rc==SQLITE_BUSY ){ |
| 71868 | 72184 | rc = SQLITE_OK; |
| 71869 | - aRes[0] = 1; | |
| 72185 | + u.ci.aRes[0] = 1; | |
| 71870 | 72186 | } |
| 71871 | - for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){ | |
| 71872 | - sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]); | |
| 71873 | - } | |
| 72187 | + for(u.ci.i=0, u.ci.pMem = &aMem[pOp->p3]; u.ci.i<3; u.ci.i++, u.ci.pMem++){ | |
| 72188 | + sqlite3VdbeMemSetInt64(u.ci.pMem, (i64)u.ci.aRes[u.ci.i]); | |
| 72189 | + } | |
| 71874 | 72190 | break; |
| 71875 | 72191 | }; |
| 71876 | 72192 | #endif |
| 71877 | 72193 | |
| 71878 | 72194 | #ifndef SQLITE_OMIT_PRAGMA |
| @@ -71886,96 +72202,98 @@ | ||
| 71886 | 72202 | ** If changing into or out of WAL mode the procedure is more complicated. |
| 71887 | 72203 | ** |
| 71888 | 72204 | ** Write a string containing the final journal-mode to register P2. |
| 71889 | 72205 | */ |
| 71890 | 72206 | case OP_JournalMode: { /* out2-prerelease */ |
| 72207 | +#if 0 /* local variables moved into u.cj */ | |
| 71891 | 72208 | Btree *pBt; /* Btree to change journal mode of */ |
| 71892 | 72209 | Pager *pPager; /* Pager associated with pBt */ |
| 71893 | 72210 | int eNew; /* New journal mode */ |
| 71894 | 72211 | int eOld; /* The old journal mode */ |
| 71895 | 72212 | #ifndef SQLITE_OMIT_WAL |
| 71896 | 72213 | const char *zFilename; /* Name of database file for pPager */ |
| 71897 | 72214 | #endif |
| 71898 | - | |
| 71899 | - eNew = pOp->p3; | |
| 71900 | - assert( eNew==PAGER_JOURNALMODE_DELETE | |
| 71901 | - || eNew==PAGER_JOURNALMODE_TRUNCATE | |
| 71902 | - || eNew==PAGER_JOURNALMODE_PERSIST | |
| 71903 | - || eNew==PAGER_JOURNALMODE_OFF | |
| 71904 | - || eNew==PAGER_JOURNALMODE_MEMORY | |
| 71905 | - || eNew==PAGER_JOURNALMODE_WAL | |
| 71906 | - || eNew==PAGER_JOURNALMODE_QUERY | |
| 72215 | +#endif /* local variables moved into u.cj */ | |
| 72216 | + | |
| 72217 | + u.cj.eNew = pOp->p3; | |
| 72218 | + assert( u.cj.eNew==PAGER_JOURNALMODE_DELETE | |
| 72219 | + || u.cj.eNew==PAGER_JOURNALMODE_TRUNCATE | |
| 72220 | + || u.cj.eNew==PAGER_JOURNALMODE_PERSIST | |
| 72221 | + || u.cj.eNew==PAGER_JOURNALMODE_OFF | |
| 72222 | + || u.cj.eNew==PAGER_JOURNALMODE_MEMORY | |
| 72223 | + || u.cj.eNew==PAGER_JOURNALMODE_WAL | |
| 72224 | + || u.cj.eNew==PAGER_JOURNALMODE_QUERY | |
| 71907 | 72225 | ); |
| 71908 | 72226 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 71909 | 72227 | assert( p->readOnly==0 ); |
| 71910 | 72228 | |
| 71911 | - pBt = db->aDb[pOp->p1].pBt; | |
| 71912 | - pPager = sqlite3BtreePager(pBt); | |
| 71913 | - eOld = sqlite3PagerGetJournalMode(pPager); | |
| 71914 | - if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld; | |
| 71915 | - if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld; | |
| 72229 | + u.cj.pBt = db->aDb[pOp->p1].pBt; | |
| 72230 | + u.cj.pPager = sqlite3BtreePager(u.cj.pBt); | |
| 72231 | + u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager); | |
| 72232 | + if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld; | |
| 72233 | + if( !sqlite3PagerOkToChangeJournalMode(u.cj.pPager) ) u.cj.eNew = u.cj.eOld; | |
| 71916 | 72234 | |
| 71917 | 72235 | #ifndef SQLITE_OMIT_WAL |
| 71918 | - zFilename = sqlite3PagerFilename(pPager, 1); | |
| 72236 | + u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1); | |
| 71919 | 72237 | |
| 71920 | 72238 | /* Do not allow a transition to journal_mode=WAL for a database |
| 71921 | - ** in temporary storage or if the VFS does not support shared memory | |
| 72239 | + ** in temporary storage or if the VFS does not support shared memory | |
| 71922 | 72240 | */ |
| 71923 | - if( eNew==PAGER_JOURNALMODE_WAL | |
| 71924 | - && (sqlite3Strlen30(zFilename)==0 /* Temp file */ | |
| 71925 | - || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */ | |
| 72241 | + if( u.cj.eNew==PAGER_JOURNALMODE_WAL | |
| 72242 | + && (sqlite3Strlen30(u.cj.zFilename)==0 /* Temp file */ | |
| 72243 | + || !sqlite3PagerWalSupported(u.cj.pPager)) /* No shared-memory support */ | |
| 71926 | 72244 | ){ |
| 71927 | - eNew = eOld; | |
| 72245 | + u.cj.eNew = u.cj.eOld; | |
| 71928 | 72246 | } |
| 71929 | 72247 | |
| 71930 | - if( (eNew!=eOld) | |
| 71931 | - && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL) | |
| 72248 | + if( (u.cj.eNew!=u.cj.eOld) | |
| 72249 | + && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL) | |
| 71932 | 72250 | ){ |
| 71933 | 72251 | if( !db->autoCommit || db->nVdbeRead>1 ){ |
| 71934 | 72252 | rc = SQLITE_ERROR; |
| 71935 | - sqlite3SetString(&p->zErrMsg, db, | |
| 72253 | + sqlite3SetString(&p->zErrMsg, db, | |
| 71936 | 72254 | "cannot change %s wal mode from within a transaction", |
| 71937 | - (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") | |
| 72255 | + (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") | |
| 71938 | 72256 | ); |
| 71939 | 72257 | break; |
| 71940 | 72258 | }else{ |
| 71941 | - | |
| 71942 | - if( eOld==PAGER_JOURNALMODE_WAL ){ | |
| 72259 | + | |
| 72260 | + if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){ | |
| 71943 | 72261 | /* If leaving WAL mode, close the log file. If successful, the call |
| 71944 | - ** to PagerCloseWal() checkpoints and deletes the write-ahead-log | |
| 71945 | - ** file. An EXCLUSIVE lock may still be held on the database file | |
| 71946 | - ** after a successful return. | |
| 72262 | + ** to PagerCloseWal() checkpoints and deletes the write-ahead-log | |
| 72263 | + ** file. An EXCLUSIVE lock may still be held on the database file | |
| 72264 | + ** after a successful return. | |
| 71947 | 72265 | */ |
| 71948 | - rc = sqlite3PagerCloseWal(pPager); | |
| 72266 | + rc = sqlite3PagerCloseWal(u.cj.pPager); | |
| 71949 | 72267 | if( rc==SQLITE_OK ){ |
| 71950 | - sqlite3PagerSetJournalMode(pPager, eNew); | |
| 72268 | + sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew); | |
| 71951 | 72269 | } |
| 71952 | - }else if( eOld==PAGER_JOURNALMODE_MEMORY ){ | |
| 72270 | + }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){ | |
| 71953 | 72271 | /* Cannot transition directly from MEMORY to WAL. Use mode OFF |
| 71954 | 72272 | ** as an intermediate */ |
| 71955 | - sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF); | |
| 72273 | + sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF); | |
| 71956 | 72274 | } |
| 71957 | - | |
| 72275 | + | |
| 71958 | 72276 | /* Open a transaction on the database file. Regardless of the journal |
| 71959 | 72277 | ** mode, this transaction always uses a rollback journal. |
| 71960 | 72278 | */ |
| 71961 | - assert( sqlite3BtreeIsInTrans(pBt)==0 ); | |
| 72279 | + assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 ); | |
| 71962 | 72280 | if( rc==SQLITE_OK ){ |
| 71963 | - rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1)); | |
| 72281 | + rc = sqlite3BtreeSetVersion(u.cj.pBt, (u.cj.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1)); | |
| 71964 | 72282 | } |
| 71965 | 72283 | } |
| 71966 | 72284 | } |
| 71967 | 72285 | #endif /* ifndef SQLITE_OMIT_WAL */ |
| 71968 | 72286 | |
| 71969 | 72287 | if( rc ){ |
| 71970 | - eNew = eOld; | |
| 72288 | + u.cj.eNew = u.cj.eOld; | |
| 71971 | 72289 | } |
| 71972 | - eNew = sqlite3PagerSetJournalMode(pPager, eNew); | |
| 72290 | + u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew); | |
| 71973 | 72291 | |
| 71974 | 72292 | pOut = &aMem[pOp->p2]; |
| 71975 | 72293 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 71976 | - pOut->z = (char *)sqlite3JournalModename(eNew); | |
| 72294 | + pOut->z = (char *)sqlite3JournalModename(u.cj.eNew); | |
| 71977 | 72295 | pOut->n = sqlite3Strlen30(pOut->z); |
| 71978 | 72296 | pOut->enc = SQLITE_UTF8; |
| 71979 | 72297 | sqlite3VdbeChangeEncoding(pOut, encoding); |
| 71980 | 72298 | break; |
| 71981 | 72299 | }; |
| @@ -72001,17 +72319,19 @@ | ||
| 72001 | 72319 | ** Perform a single step of the incremental vacuum procedure on |
| 72002 | 72320 | ** the P1 database. If the vacuum has finished, jump to instruction |
| 72003 | 72321 | ** P2. Otherwise, fall through to the next instruction. |
| 72004 | 72322 | */ |
| 72005 | 72323 | case OP_IncrVacuum: { /* jump */ |
| 72324 | +#if 0 /* local variables moved into u.ck */ | |
| 72006 | 72325 | Btree *pBt; |
| 72326 | +#endif /* local variables moved into u.ck */ | |
| 72007 | 72327 | |
| 72008 | 72328 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 72009 | 72329 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 72010 | 72330 | assert( p->readOnly==0 ); |
| 72011 | - pBt = db->aDb[pOp->p1].pBt; | |
| 72012 | - rc = sqlite3BtreeIncrVacuum(pBt); | |
| 72331 | + u.ck.pBt = db->aDb[pOp->p1].pBt; | |
| 72332 | + rc = sqlite3BtreeIncrVacuum(u.ck.pBt); | |
| 72013 | 72333 | if( rc==SQLITE_DONE ){ |
| 72014 | 72334 | pc = pOp->p2 - 1; |
| 72015 | 72335 | rc = SQLITE_OK; |
| 72016 | 72336 | } |
| 72017 | 72337 | break; |
| @@ -72078,14 +72398,16 @@ | ||
| 72078 | 72398 | ** Also, whether or not P4 is set, check that this is not being called from |
| 72079 | 72399 | ** within a callback to a virtual table xSync() method. If it is, the error |
| 72080 | 72400 | ** code will be set to SQLITE_LOCKED. |
| 72081 | 72401 | */ |
| 72082 | 72402 | case OP_VBegin: { |
| 72403 | +#if 0 /* local variables moved into u.cl */ | |
| 72083 | 72404 | VTable *pVTab; |
| 72084 | - pVTab = pOp->p4.pVtab; | |
| 72085 | - rc = sqlite3VtabBegin(db, pVTab); | |
| 72086 | - if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab); | |
| 72405 | +#endif /* local variables moved into u.cl */ | |
| 72406 | + u.cl.pVTab = pOp->p4.pVtab; | |
| 72407 | + rc = sqlite3VtabBegin(db, u.cl.pVTab); | |
| 72408 | + if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab); | |
| 72087 | 72409 | break; |
| 72088 | 72410 | } |
| 72089 | 72411 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 72090 | 72412 | |
| 72091 | 72413 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -72120,34 +72442,36 @@ | ||
| 72120 | 72442 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72121 | 72443 | ** P1 is a cursor number. This opcode opens a cursor to the virtual |
| 72122 | 72444 | ** table and stores that cursor in P1. |
| 72123 | 72445 | */ |
| 72124 | 72446 | case OP_VOpen: { |
| 72447 | +#if 0 /* local variables moved into u.cm */ | |
| 72125 | 72448 | VdbeCursor *pCur; |
| 72126 | 72449 | sqlite3_vtab_cursor *pVtabCursor; |
| 72127 | 72450 | sqlite3_vtab *pVtab; |
| 72128 | 72451 | sqlite3_module *pModule; |
| 72452 | +#endif /* local variables moved into u.cm */ | |
| 72129 | 72453 | |
| 72130 | 72454 | assert( p->bIsReader ); |
| 72131 | - pCur = 0; | |
| 72132 | - pVtabCursor = 0; | |
| 72133 | - pVtab = pOp->p4.pVtab->pVtab; | |
| 72134 | - pModule = (sqlite3_module *)pVtab->pModule; | |
| 72135 | - assert(pVtab && pModule); | |
| 72136 | - rc = pModule->xOpen(pVtab, &pVtabCursor); | |
| 72137 | - sqlite3VtabImportErrmsg(p, pVtab); | |
| 72455 | + u.cm.pCur = 0; | |
| 72456 | + u.cm.pVtabCursor = 0; | |
| 72457 | + u.cm.pVtab = pOp->p4.pVtab->pVtab; | |
| 72458 | + u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule; | |
| 72459 | + assert(u.cm.pVtab && u.cm.pModule); | |
| 72460 | + rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor); | |
| 72461 | + sqlite3VtabImportErrmsg(p, u.cm.pVtab); | |
| 72138 | 72462 | if( SQLITE_OK==rc ){ |
| 72139 | 72463 | /* Initialize sqlite3_vtab_cursor base class */ |
| 72140 | - pVtabCursor->pVtab = pVtab; | |
| 72464 | + u.cm.pVtabCursor->pVtab = u.cm.pVtab; | |
| 72141 | 72465 | |
| 72142 | 72466 | /* Initialize vdbe cursor object */ |
| 72143 | - pCur = allocateCursor(p, pOp->p1, 0, -1, 0); | |
| 72144 | - if( pCur ){ | |
| 72145 | - pCur->pVtabCursor = pVtabCursor; | |
| 72467 | + u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0); | |
| 72468 | + if( u.cm.pCur ){ | |
| 72469 | + u.cm.pCur->pVtabCursor = u.cm.pVtabCursor; | |
| 72146 | 72470 | }else{ |
| 72147 | 72471 | db->mallocFailed = 1; |
| 72148 | - pModule->xClose(pVtabCursor); | |
| 72472 | + u.cm.pModule->xClose(u.cm.pVtabCursor); | |
| 72149 | 72473 | } |
| 72150 | 72474 | } |
| 72151 | 72475 | break; |
| 72152 | 72476 | } |
| 72153 | 72477 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -72171,10 +72495,11 @@ | ||
| 72171 | 72495 | ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter. |
| 72172 | 72496 | ** |
| 72173 | 72497 | ** A jump is made to P2 if the result set after filtering would be empty. |
| 72174 | 72498 | */ |
| 72175 | 72499 | case OP_VFilter: { /* jump */ |
| 72500 | +#if 0 /* local variables moved into u.cn */ | |
| 72176 | 72501 | int nArg; |
| 72177 | 72502 | int iQuery; |
| 72178 | 72503 | const sqlite3_module *pModule; |
| 72179 | 72504 | Mem *pQuery; |
| 72180 | 72505 | Mem *pArgc; |
| @@ -72182,48 +72507,49 @@ | ||
| 72182 | 72507 | sqlite3_vtab *pVtab; |
| 72183 | 72508 | VdbeCursor *pCur; |
| 72184 | 72509 | int res; |
| 72185 | 72510 | int i; |
| 72186 | 72511 | Mem **apArg; |
| 72187 | - | |
| 72188 | - pQuery = &aMem[pOp->p3]; | |
| 72189 | - pArgc = &pQuery[1]; | |
| 72190 | - pCur = p->apCsr[pOp->p1]; | |
| 72191 | - assert( memIsValid(pQuery) ); | |
| 72192 | - REGISTER_TRACE(pOp->p3, pQuery); | |
| 72193 | - assert( pCur->pVtabCursor ); | |
| 72194 | - pVtabCursor = pCur->pVtabCursor; | |
| 72195 | - pVtab = pVtabCursor->pVtab; | |
| 72196 | - pModule = pVtab->pModule; | |
| 72512 | +#endif /* local variables moved into u.cn */ | |
| 72513 | + | |
| 72514 | + u.cn.pQuery = &aMem[pOp->p3]; | |
| 72515 | + u.cn.pArgc = &u.cn.pQuery[1]; | |
| 72516 | + u.cn.pCur = p->apCsr[pOp->p1]; | |
| 72517 | + assert( memIsValid(u.cn.pQuery) ); | |
| 72518 | + REGISTER_TRACE(pOp->p3, u.cn.pQuery); | |
| 72519 | + assert( u.cn.pCur->pVtabCursor ); | |
| 72520 | + u.cn.pVtabCursor = u.cn.pCur->pVtabCursor; | |
| 72521 | + u.cn.pVtab = u.cn.pVtabCursor->pVtab; | |
| 72522 | + u.cn.pModule = u.cn.pVtab->pModule; | |
| 72197 | 72523 | |
| 72198 | 72524 | /* Grab the index number and argc parameters */ |
| 72199 | - assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); | |
| 72200 | - nArg = (int)pArgc->u.i; | |
| 72201 | - iQuery = (int)pQuery->u.i; | |
| 72525 | + assert( (u.cn.pQuery->flags&MEM_Int)!=0 && u.cn.pArgc->flags==MEM_Int ); | |
| 72526 | + u.cn.nArg = (int)u.cn.pArgc->u.i; | |
| 72527 | + u.cn.iQuery = (int)u.cn.pQuery->u.i; | |
| 72202 | 72528 | |
| 72203 | 72529 | /* Invoke the xFilter method */ |
| 72204 | 72530 | { |
| 72205 | - res = 0; | |
| 72206 | - apArg = p->apArg; | |
| 72207 | - for(i = 0; i<nArg; i++){ | |
| 72208 | - apArg[i] = &pArgc[i+1]; | |
| 72209 | - sqlite3VdbeMemStoreType(apArg[i]); | |
| 72531 | + u.cn.res = 0; | |
| 72532 | + u.cn.apArg = p->apArg; | |
| 72533 | + for(u.cn.i = 0; u.cn.i<u.cn.nArg; u.cn.i++){ | |
| 72534 | + u.cn.apArg[u.cn.i] = &u.cn.pArgc[u.cn.i+1]; | |
| 72535 | + sqlite3VdbeMemStoreType(u.cn.apArg[u.cn.i]); | |
| 72210 | 72536 | } |
| 72211 | 72537 | |
| 72212 | 72538 | p->inVtabMethod = 1; |
| 72213 | - rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); | |
| 72539 | + rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg); | |
| 72214 | 72540 | p->inVtabMethod = 0; |
| 72215 | - sqlite3VtabImportErrmsg(p, pVtab); | |
| 72541 | + sqlite3VtabImportErrmsg(p, u.cn.pVtab); | |
| 72216 | 72542 | if( rc==SQLITE_OK ){ |
| 72217 | - res = pModule->xEof(pVtabCursor); | |
| 72543 | + u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor); | |
| 72218 | 72544 | } |
| 72219 | 72545 | |
| 72220 | - if( res ){ | |
| 72546 | + if( u.cn.res ){ | |
| 72221 | 72547 | pc = pOp->p2 - 1; |
| 72222 | 72548 | } |
| 72223 | 72549 | } |
| 72224 | - pCur->nullRow = 0; | |
| 72550 | + u.cn.pCur->nullRow = 0; | |
| 72225 | 72551 | |
| 72226 | 72552 | break; |
| 72227 | 72553 | } |
| 72228 | 72554 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 72229 | 72555 | |
| @@ -72234,53 +72560,55 @@ | ||
| 72234 | 72560 | ** Store the value of the P2-th column of |
| 72235 | 72561 | ** the row of the virtual-table that the |
| 72236 | 72562 | ** P1 cursor is pointing to into register P3. |
| 72237 | 72563 | */ |
| 72238 | 72564 | case OP_VColumn: { |
| 72565 | +#if 0 /* local variables moved into u.co */ | |
| 72239 | 72566 | sqlite3_vtab *pVtab; |
| 72240 | 72567 | const sqlite3_module *pModule; |
| 72241 | 72568 | Mem *pDest; |
| 72242 | 72569 | sqlite3_context sContext; |
| 72570 | +#endif /* local variables moved into u.co */ | |
| 72243 | 72571 | |
| 72244 | 72572 | VdbeCursor *pCur = p->apCsr[pOp->p1]; |
| 72245 | 72573 | assert( pCur->pVtabCursor ); |
| 72246 | 72574 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 72247 | - pDest = &aMem[pOp->p3]; | |
| 72248 | - memAboutToChange(p, pDest); | |
| 72575 | + u.co.pDest = &aMem[pOp->p3]; | |
| 72576 | + memAboutToChange(p, u.co.pDest); | |
| 72249 | 72577 | if( pCur->nullRow ){ |
| 72250 | - sqlite3VdbeMemSetNull(pDest); | |
| 72578 | + sqlite3VdbeMemSetNull(u.co.pDest); | |
| 72251 | 72579 | break; |
| 72252 | 72580 | } |
| 72253 | - pVtab = pCur->pVtabCursor->pVtab; | |
| 72254 | - pModule = pVtab->pModule; | |
| 72255 | - assert( pModule->xColumn ); | |
| 72256 | - memset(&sContext, 0, sizeof(sContext)); | |
| 72581 | + u.co.pVtab = pCur->pVtabCursor->pVtab; | |
| 72582 | + u.co.pModule = u.co.pVtab->pModule; | |
| 72583 | + assert( u.co.pModule->xColumn ); | |
| 72584 | + memset(&u.co.sContext, 0, sizeof(u.co.sContext)); | |
| 72257 | 72585 | |
| 72258 | 72586 | /* The output cell may already have a buffer allocated. Move |
| 72259 | - ** the current contents to sContext.s so in case the user-function | |
| 72260 | - ** can use the already allocated buffer instead of allocating a | |
| 72587 | + ** the current contents to u.co.sContext.s so in case the user-function | |
| 72588 | + ** can use the already allocated buffer instead of allocating a | |
| 72261 | 72589 | ** new one. |
| 72262 | 72590 | */ |
| 72263 | - sqlite3VdbeMemMove(&sContext.s, pDest); | |
| 72264 | - MemSetTypeFlag(&sContext.s, MEM_Null); | |
| 72591 | + sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest); | |
| 72592 | + MemSetTypeFlag(&u.co.sContext.s, MEM_Null); | |
| 72265 | 72593 | |
| 72266 | - rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2); | |
| 72267 | - sqlite3VtabImportErrmsg(p, pVtab); | |
| 72268 | - if( sContext.isError ){ | |
| 72269 | - rc = sContext.isError; | |
| 72594 | + rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2); | |
| 72595 | + sqlite3VtabImportErrmsg(p, u.co.pVtab); | |
| 72596 | + if( u.co.sContext.isError ){ | |
| 72597 | + rc = u.co.sContext.isError; | |
| 72270 | 72598 | } |
| 72271 | 72599 | |
| 72272 | 72600 | /* Copy the result of the function to the P3 register. We |
| 72273 | 72601 | ** do this regardless of whether or not an error occurred to ensure any |
| 72274 | - ** dynamic allocation in sContext.s (a Mem struct) is released. | |
| 72602 | + ** dynamic allocation in u.co.sContext.s (a Mem struct) is released. | |
| 72275 | 72603 | */ |
| 72276 | - sqlite3VdbeChangeEncoding(&sContext.s, encoding); | |
| 72277 | - sqlite3VdbeMemMove(pDest, &sContext.s); | |
| 72278 | - REGISTER_TRACE(pOp->p3, pDest); | |
| 72279 | - UPDATE_MAX_BLOBSIZE(pDest); | |
| 72604 | + sqlite3VdbeChangeEncoding(&u.co.sContext.s, encoding); | |
| 72605 | + sqlite3VdbeMemMove(u.co.pDest, &u.co.sContext.s); | |
| 72606 | + REGISTER_TRACE(pOp->p3, u.co.pDest); | |
| 72607 | + UPDATE_MAX_BLOBSIZE(u.co.pDest); | |
| 72280 | 72608 | |
| 72281 | - if( sqlite3VdbeMemTooBig(pDest) ){ | |
| 72609 | + if( sqlite3VdbeMemTooBig(u.co.pDest) ){ | |
| 72282 | 72610 | goto too_big; |
| 72283 | 72611 | } |
| 72284 | 72612 | break; |
| 72285 | 72613 | } |
| 72286 | 72614 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -72291,40 +72619,42 @@ | ||
| 72291 | 72619 | ** Advance virtual table P1 to the next row in its result set and |
| 72292 | 72620 | ** jump to instruction P2. Or, if the virtual table has reached |
| 72293 | 72621 | ** the end of its result set, then fall through to the next instruction. |
| 72294 | 72622 | */ |
| 72295 | 72623 | case OP_VNext: { /* jump */ |
| 72624 | +#if 0 /* local variables moved into u.cp */ | |
| 72296 | 72625 | sqlite3_vtab *pVtab; |
| 72297 | 72626 | const sqlite3_module *pModule; |
| 72298 | 72627 | int res; |
| 72299 | 72628 | VdbeCursor *pCur; |
| 72629 | +#endif /* local variables moved into u.cp */ | |
| 72300 | 72630 | |
| 72301 | - res = 0; | |
| 72302 | - pCur = p->apCsr[pOp->p1]; | |
| 72303 | - assert( pCur->pVtabCursor ); | |
| 72304 | - if( pCur->nullRow ){ | |
| 72631 | + u.cp.res = 0; | |
| 72632 | + u.cp.pCur = p->apCsr[pOp->p1]; | |
| 72633 | + assert( u.cp.pCur->pVtabCursor ); | |
| 72634 | + if( u.cp.pCur->nullRow ){ | |
| 72305 | 72635 | break; |
| 72306 | 72636 | } |
| 72307 | - pVtab = pCur->pVtabCursor->pVtab; | |
| 72308 | - pModule = pVtab->pModule; | |
| 72309 | - assert( pModule->xNext ); | |
| 72637 | + u.cp.pVtab = u.cp.pCur->pVtabCursor->pVtab; | |
| 72638 | + u.cp.pModule = u.cp.pVtab->pModule; | |
| 72639 | + assert( u.cp.pModule->xNext ); | |
| 72310 | 72640 | |
| 72311 | 72641 | /* Invoke the xNext() method of the module. There is no way for the |
| 72312 | 72642 | ** underlying implementation to return an error if one occurs during |
| 72313 | - ** xNext(). Instead, if an error occurs, true is returned (indicating that | |
| 72643 | + ** xNext(). Instead, if an error occurs, true is returned (indicating that | |
| 72314 | 72644 | ** data is available) and the error code returned when xColumn or |
| 72315 | 72645 | ** some other method is next invoked on the save virtual table cursor. |
| 72316 | 72646 | */ |
| 72317 | 72647 | p->inVtabMethod = 1; |
| 72318 | - rc = pModule->xNext(pCur->pVtabCursor); | |
| 72648 | + rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor); | |
| 72319 | 72649 | p->inVtabMethod = 0; |
| 72320 | - sqlite3VtabImportErrmsg(p, pVtab); | |
| 72650 | + sqlite3VtabImportErrmsg(p, u.cp.pVtab); | |
| 72321 | 72651 | if( rc==SQLITE_OK ){ |
| 72322 | - res = pModule->xEof(pCur->pVtabCursor); | |
| 72652 | + u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor); | |
| 72323 | 72653 | } |
| 72324 | 72654 | |
| 72325 | - if( !res ){ | |
| 72655 | + if( !u.cp.res ){ | |
| 72326 | 72656 | /* If there is data, jump to P2 */ |
| 72327 | 72657 | pc = pOp->p2 - 1; |
| 72328 | 72658 | } |
| 72329 | 72659 | goto check_for_interrupt; |
| 72330 | 72660 | } |
| @@ -72336,27 +72666,29 @@ | ||
| 72336 | 72666 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72337 | 72667 | ** This opcode invokes the corresponding xRename method. The value |
| 72338 | 72668 | ** in register P1 is passed as the zName argument to the xRename method. |
| 72339 | 72669 | */ |
| 72340 | 72670 | case OP_VRename: { |
| 72671 | +#if 0 /* local variables moved into u.cq */ | |
| 72341 | 72672 | sqlite3_vtab *pVtab; |
| 72342 | 72673 | Mem *pName; |
| 72674 | +#endif /* local variables moved into u.cq */ | |
| 72343 | 72675 | |
| 72344 | - pVtab = pOp->p4.pVtab->pVtab; | |
| 72345 | - pName = &aMem[pOp->p1]; | |
| 72346 | - assert( pVtab->pModule->xRename ); | |
| 72347 | - assert( memIsValid(pName) ); | |
| 72676 | + u.cq.pVtab = pOp->p4.pVtab->pVtab; | |
| 72677 | + u.cq.pName = &aMem[pOp->p1]; | |
| 72678 | + assert( u.cq.pVtab->pModule->xRename ); | |
| 72679 | + assert( memIsValid(u.cq.pName) ); | |
| 72348 | 72680 | assert( p->readOnly==0 ); |
| 72349 | - REGISTER_TRACE(pOp->p1, pName); | |
| 72350 | - assert( pName->flags & MEM_Str ); | |
| 72351 | - testcase( pName->enc==SQLITE_UTF8 ); | |
| 72352 | - testcase( pName->enc==SQLITE_UTF16BE ); | |
| 72353 | - testcase( pName->enc==SQLITE_UTF16LE ); | |
| 72354 | - rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8); | |
| 72681 | + REGISTER_TRACE(pOp->p1, u.cq.pName); | |
| 72682 | + assert( u.cq.pName->flags & MEM_Str ); | |
| 72683 | + testcase( u.cq.pName->enc==SQLITE_UTF8 ); | |
| 72684 | + testcase( u.cq.pName->enc==SQLITE_UTF16BE ); | |
| 72685 | + testcase( u.cq.pName->enc==SQLITE_UTF16LE ); | |
| 72686 | + rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8); | |
| 72355 | 72687 | if( rc==SQLITE_OK ){ |
| 72356 | - rc = pVtab->pModule->xRename(pVtab, pName->z); | |
| 72357 | - sqlite3VtabImportErrmsg(p, pVtab); | |
| 72688 | + rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z); | |
| 72689 | + sqlite3VtabImportErrmsg(p, u.cq.pVtab); | |
| 72358 | 72690 | p->expired = 0; |
| 72359 | 72691 | } |
| 72360 | 72692 | break; |
| 72361 | 72693 | } |
| 72362 | 72694 | #endif |
| @@ -72385,44 +72717,46 @@ | ||
| 72385 | 72717 | ** P1 is a boolean flag. If it is set to true and the xUpdate call |
| 72386 | 72718 | ** is successful, then the value returned by sqlite3_last_insert_rowid() |
| 72387 | 72719 | ** is set to the value of the rowid for the row just inserted. |
| 72388 | 72720 | */ |
| 72389 | 72721 | case OP_VUpdate: { |
| 72722 | +#if 0 /* local variables moved into u.cr */ | |
| 72390 | 72723 | sqlite3_vtab *pVtab; |
| 72391 | 72724 | sqlite3_module *pModule; |
| 72392 | 72725 | int nArg; |
| 72393 | 72726 | int i; |
| 72394 | 72727 | sqlite_int64 rowid; |
| 72395 | 72728 | Mem **apArg; |
| 72396 | 72729 | Mem *pX; |
| 72730 | +#endif /* local variables moved into u.cr */ | |
| 72397 | 72731 | |
| 72398 | - assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback | |
| 72732 | + assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback | |
| 72399 | 72733 | || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| 72400 | 72734 | ); |
| 72401 | 72735 | assert( p->readOnly==0 ); |
| 72402 | - pVtab = pOp->p4.pVtab->pVtab; | |
| 72403 | - pModule = (sqlite3_module *)pVtab->pModule; | |
| 72404 | - nArg = pOp->p2; | |
| 72736 | + u.cr.pVtab = pOp->p4.pVtab->pVtab; | |
| 72737 | + u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule; | |
| 72738 | + u.cr.nArg = pOp->p2; | |
| 72405 | 72739 | assert( pOp->p4type==P4_VTAB ); |
| 72406 | - if( ALWAYS(pModule->xUpdate) ){ | |
| 72740 | + if( ALWAYS(u.cr.pModule->xUpdate) ){ | |
| 72407 | 72741 | u8 vtabOnConflict = db->vtabOnConflict; |
| 72408 | - apArg = p->apArg; | |
| 72409 | - pX = &aMem[pOp->p3]; | |
| 72410 | - for(i=0; i<nArg; i++){ | |
| 72411 | - assert( memIsValid(pX) ); | |
| 72412 | - memAboutToChange(p, pX); | |
| 72413 | - sqlite3VdbeMemStoreType(pX); | |
| 72414 | - apArg[i] = pX; | |
| 72415 | - pX++; | |
| 72742 | + u.cr.apArg = p->apArg; | |
| 72743 | + u.cr.pX = &aMem[pOp->p3]; | |
| 72744 | + for(u.cr.i=0; u.cr.i<u.cr.nArg; u.cr.i++){ | |
| 72745 | + assert( memIsValid(u.cr.pX) ); | |
| 72746 | + memAboutToChange(p, u.cr.pX); | |
| 72747 | + sqlite3VdbeMemStoreType(u.cr.pX); | |
| 72748 | + u.cr.apArg[u.cr.i] = u.cr.pX; | |
| 72749 | + u.cr.pX++; | |
| 72416 | 72750 | } |
| 72417 | 72751 | db->vtabOnConflict = pOp->p5; |
| 72418 | - rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); | |
| 72752 | + rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid); | |
| 72419 | 72753 | db->vtabOnConflict = vtabOnConflict; |
| 72420 | - sqlite3VtabImportErrmsg(p, pVtab); | |
| 72754 | + sqlite3VtabImportErrmsg(p, u.cr.pVtab); | |
| 72421 | 72755 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 72422 | - assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); | |
| 72423 | - db->lastRowid = lastRowid = rowid; | |
| 72756 | + assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) ); | |
| 72757 | + db->lastRowid = lastRowid = u.cr.rowid; | |
| 72424 | 72758 | } |
| 72425 | 72759 | if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 72426 | 72760 | if( pOp->p5==OE_Ignore ){ |
| 72427 | 72761 | rc = SQLITE_OK; |
| 72428 | 72762 | }else{ |
| @@ -72478,36 +72812,38 @@ | ||
| 72478 | 72812 | ** |
| 72479 | 72813 | ** If tracing is enabled (by the sqlite3_trace()) interface, then |
| 72480 | 72814 | ** the UTF-8 string contained in P4 is emitted on the trace callback. |
| 72481 | 72815 | */ |
| 72482 | 72816 | case OP_Trace: { |
| 72817 | +#if 0 /* local variables moved into u.cs */ | |
| 72483 | 72818 | char *zTrace; |
| 72484 | 72819 | char *z; |
| 72820 | +#endif /* local variables moved into u.cs */ | |
| 72485 | 72821 | |
| 72486 | 72822 | if( db->xTrace |
| 72487 | 72823 | && !p->doingRerun |
| 72488 | - && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 | |
| 72824 | + && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 | |
| 72489 | 72825 | ){ |
| 72490 | - z = sqlite3VdbeExpandSql(p, zTrace); | |
| 72491 | - db->xTrace(db->pTraceArg, z); | |
| 72492 | - sqlite3DbFree(db, z); | |
| 72826 | + u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace); | |
| 72827 | + db->xTrace(db->pTraceArg, u.cs.z); | |
| 72828 | + sqlite3DbFree(db, u.cs.z); | |
| 72493 | 72829 | } |
| 72494 | 72830 | #ifdef SQLITE_USE_FCNTL_TRACE |
| 72495 | - zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); | |
| 72496 | - if( zTrace ){ | |
| 72831 | + u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); | |
| 72832 | + if( u.cs.zTrace ){ | |
| 72497 | 72833 | int i; |
| 72498 | 72834 | for(i=0; i<db->nDb; i++){ |
| 72499 | 72835 | if( ((1<<i) & p->btreeMask)==0 ) continue; |
| 72500 | - sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace); | |
| 72836 | + sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace); | |
| 72501 | 72837 | } |
| 72502 | 72838 | } |
| 72503 | 72839 | #endif /* SQLITE_USE_FCNTL_TRACE */ |
| 72504 | 72840 | #ifdef SQLITE_DEBUG |
| 72505 | 72841 | if( (db->flags & SQLITE_SqlTrace)!=0 |
| 72506 | - && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 | |
| 72842 | + && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 | |
| 72507 | 72843 | ){ |
| 72508 | - sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); | |
| 72844 | + sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace); | |
| 72509 | 72845 | } |
| 72510 | 72846 | #endif /* SQLITE_DEBUG */ |
| 72511 | 72847 | break; |
| 72512 | 72848 | } |
| 72513 | 72849 | #endif |
| @@ -72632,11 +72968,10 @@ | ||
| 72632 | 72968 | rc = SQLITE_INTERRUPT; |
| 72633 | 72969 | p->rc = rc; |
| 72634 | 72970 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc)); |
| 72635 | 72971 | goto vdbe_error_halt; |
| 72636 | 72972 | } |
| 72637 | - | |
| 72638 | 72973 | |
| 72639 | 72974 | /************** End of vdbe.c ************************************************/ |
| 72640 | 72975 | /************** Begin file vdbeblob.c ****************************************/ |
| 72641 | 72976 | /* |
| 72642 | 72977 | ** 2007 May 1 |
| @@ -72891,11 +73226,11 @@ | ||
| 72891 | 73226 | sqlite3BtreeLeaveAll(db); |
| 72892 | 73227 | goto blob_open_out; |
| 72893 | 73228 | } |
| 72894 | 73229 | } |
| 72895 | 73230 | |
| 72896 | - pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse); | |
| 73231 | + pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db); | |
| 72897 | 73232 | assert( pBlob->pStmt || db->mallocFailed ); |
| 72898 | 73233 | if( pBlob->pStmt ){ |
| 72899 | 73234 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 72900 | 73235 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 72901 | 73236 | |
| @@ -76798,29 +77133,20 @@ | ||
| 76798 | 77133 | } |
| 76799 | 77134 | return p; |
| 76800 | 77135 | } |
| 76801 | 77136 | |
| 76802 | 77137 | /* |
| 76803 | -** If the expression is always either TRUE or FALSE (respectively), | |
| 76804 | -** then return 1. If one cannot determine the truth value of the | |
| 76805 | -** expression at compile-time return 0. | |
| 76806 | -** | |
| 76807 | -** This is an optimization. If is OK to return 0 here even if | |
| 76808 | -** the expression really is always false or false (a false negative). | |
| 76809 | -** But it is a bug to return 1 if the expression might have different | |
| 76810 | -** boolean values in different circumstances (a false positive.) | |
| 77138 | +** Return 1 if an expression must be FALSE in all cases and 0 if the | |
| 77139 | +** expression might be true. This is an optimization. If is OK to | |
| 77140 | +** return 0 here even if the expression really is always false (a | |
| 77141 | +** false negative). But it is a bug to return 1 if the expression | |
| 77142 | +** might be true in some rare circumstances (a false positive.) | |
| 76811 | 77143 | ** |
| 76812 | 77144 | ** Note that if the expression is part of conditional for a |
| 76813 | 77145 | ** LEFT JOIN, then we cannot determine at compile-time whether or not |
| 76814 | 77146 | ** is it true or false, so always return 0. |
| 76815 | 77147 | */ |
| 76816 | -static int exprAlwaysTrue(Expr *p){ | |
| 76817 | - int v = 0; | |
| 76818 | - if( ExprHasProperty(p, EP_FromJoin) ) return 0; | |
| 76819 | - if( !sqlite3ExprIsInteger(p, &v) ) return 0; | |
| 76820 | - return v!=0; | |
| 76821 | -} | |
| 76822 | 77148 | static int exprAlwaysFalse(Expr *p){ |
| 76823 | 77149 | int v = 0; |
| 76824 | 77150 | if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 76825 | 77151 | if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 76826 | 77152 | return v==0; |
| @@ -78454,15 +78780,10 @@ | ||
| 78454 | 78780 | ** added to the column cache after this call are removed when the |
| 78455 | 78781 | ** corresponding pop occurs. |
| 78456 | 78782 | */ |
| 78457 | 78783 | SQLITE_PRIVATE void sqlite3ExprCachePush(Parse *pParse){ |
| 78458 | 78784 | pParse->iCacheLevel++; |
| 78459 | -#ifdef SQLITE_DEBUG | |
| 78460 | - if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ | |
| 78461 | - printf("PUSH to %d\n", pParse->iCacheLevel); | |
| 78462 | - } | |
| 78463 | -#endif | |
| 78464 | 78785 | } |
| 78465 | 78786 | |
| 78466 | 78787 | /* |
| 78467 | 78788 | ** Remove from the column cache any entries that were added since the |
| 78468 | 78789 | ** the previous N Push operations. In other words, restore the cache |
| @@ -78472,15 +78793,10 @@ | ||
| 78472 | 78793 | int i; |
| 78473 | 78794 | struct yColCache *p; |
| 78474 | 78795 | assert( N>0 ); |
| 78475 | 78796 | assert( pParse->iCacheLevel>=N ); |
| 78476 | 78797 | pParse->iCacheLevel -= N; |
| 78477 | -#ifdef SQLITE_DEBUG | |
| 78478 | - if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ | |
| 78479 | - printf("POP to %d\n", pParse->iCacheLevel); | |
| 78480 | - } | |
| 78481 | -#endif | |
| 78482 | 78798 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 78483 | 78799 | if( p->iReg && p->iLevel>pParse->iCacheLevel ){ |
| 78484 | 78800 | cacheEntryClear(pParse, p); |
| 78485 | 78801 | p->iReg = 0; |
| 78486 | 78802 | } |
| @@ -78571,15 +78887,10 @@ | ||
| 78571 | 78887 | */ |
| 78572 | 78888 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){ |
| 78573 | 78889 | int i; |
| 78574 | 78890 | struct yColCache *p; |
| 78575 | 78891 | |
| 78576 | -#if SQLITE_DEBUG | |
| 78577 | - if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ | |
| 78578 | - printf("CLEAR\n"); | |
| 78579 | - } | |
| 78580 | -#endif | |
| 78581 | 78892 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 78582 | 78893 | if( p->iReg ){ |
| 78583 | 78894 | cacheEntryClear(pParse, p); |
| 78584 | 78895 | p->iReg = 0; |
| 78585 | 78896 | } |
| @@ -79663,11 +79974,11 @@ | ||
| 79663 | 79974 | sqlite3ExplainPush(pOut); |
| 79664 | 79975 | for(i=0; i<pList->nExpr; i++){ |
| 79665 | 79976 | sqlite3ExplainPrintf(pOut, "item[%d] = ", i); |
| 79666 | 79977 | sqlite3ExplainPush(pOut); |
| 79667 | 79978 | sqlite3ExplainExpr(pOut, pList->a[i].pExpr); |
| 79668 | - sqlite3ExplainPop(pOut, 1); | |
| 79979 | + sqlite3ExplainPop(pOut); | |
| 79669 | 79980 | if( pList->a[i].zName ){ |
| 79670 | 79981 | sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName); |
| 79671 | 79982 | } |
| 79672 | 79983 | if( pList->a[i].bSpanIsTab ){ |
| 79673 | 79984 | sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan); |
| @@ -79712,21 +80023,11 @@ | ||
| 79712 | 80023 | if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ |
| 79713 | 80024 | sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0); |
| 79714 | 80025 | }else{ |
| 79715 | 80026 | int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 79716 | 80027 | if( inReg!=target+i ){ |
| 79717 | - VdbeOp *pOp; | |
| 79718 | - Vdbe *v = pParse->pVdbe; | |
| 79719 | - if( copyOp==OP_Copy | |
| 79720 | - && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy | |
| 79721 | - && pOp->p1+pOp->p3+1==inReg | |
| 79722 | - && pOp->p2+pOp->p3+1==target+i | |
| 79723 | - ){ | |
| 79724 | - pOp->p3++; | |
| 79725 | - }else{ | |
| 79726 | - sqlite3VdbeAddOp2(v, copyOp, inReg, target+i); | |
| 79727 | - } | |
| 80028 | + sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i); | |
| 79728 | 80029 | } |
| 79729 | 80030 | } |
| 79730 | 80031 | } |
| 79731 | 80032 | return n; |
| 79732 | 80033 | } |
| @@ -79813,23 +80114,21 @@ | ||
| 79813 | 80114 | op = pExpr->op; |
| 79814 | 80115 | switch( op ){ |
| 79815 | 80116 | case TK_AND: { |
| 79816 | 80117 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79817 | 80118 | testcase( jumpIfNull==0 ); |
| 79818 | - sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL); | |
| 79819 | 80119 | sqlite3ExprCachePush(pParse); |
| 80120 | + sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL); | |
| 79820 | 80121 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79821 | 80122 | sqlite3VdbeResolveLabel(v, d2); |
| 79822 | 80123 | sqlite3ExprCachePop(pParse, 1); |
| 79823 | 80124 | break; |
| 79824 | 80125 | } |
| 79825 | 80126 | case TK_OR: { |
| 79826 | 80127 | testcase( jumpIfNull==0 ); |
| 79827 | 80128 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79828 | - sqlite3ExprCachePush(pParse); | |
| 79829 | 80129 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79830 | - sqlite3ExprCachePop(pParse, 1); | |
| 79831 | 80130 | break; |
| 79832 | 80131 | } |
| 79833 | 80132 | case TK_NOT: { |
| 79834 | 80133 | testcase( jumpIfNull==0 ); |
| 79835 | 80134 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| @@ -79900,20 +80199,14 @@ | ||
| 79900 | 80199 | sqlite3VdbeResolveLabel(v, destIfFalse); |
| 79901 | 80200 | break; |
| 79902 | 80201 | } |
| 79903 | 80202 | #endif |
| 79904 | 80203 | default: { |
| 79905 | - if( exprAlwaysTrue(pExpr) ){ | |
| 79906 | - sqlite3VdbeAddOp2(v, OP_Goto, 0, dest); | |
| 79907 | - }else if( exprAlwaysFalse(pExpr) ){ | |
| 79908 | - /* No-op */ | |
| 79909 | - }else{ | |
| 79910 | - r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); | |
| 79911 | - sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); | |
| 79912 | - testcase( regFree1==0 ); | |
| 79913 | - testcase( jumpIfNull==0 ); | |
| 79914 | - } | |
| 80204 | + r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); | |
| 80205 | + sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); | |
| 80206 | + testcase( regFree1==0 ); | |
| 80207 | + testcase( jumpIfNull==0 ); | |
| 79915 | 80208 | break; |
| 79916 | 80209 | } |
| 79917 | 80210 | } |
| 79918 | 80211 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 79919 | 80212 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -79972,20 +80265,18 @@ | ||
| 79972 | 80265 | |
| 79973 | 80266 | switch( pExpr->op ){ |
| 79974 | 80267 | case TK_AND: { |
| 79975 | 80268 | testcase( jumpIfNull==0 ); |
| 79976 | 80269 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79977 | - sqlite3ExprCachePush(pParse); | |
| 79978 | 80270 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79979 | - sqlite3ExprCachePop(pParse, 1); | |
| 79980 | 80271 | break; |
| 79981 | 80272 | } |
| 79982 | 80273 | case TK_OR: { |
| 79983 | 80274 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79984 | 80275 | testcase( jumpIfNull==0 ); |
| 79985 | - sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL); | |
| 79986 | 80276 | sqlite3ExprCachePush(pParse); |
| 80277 | + sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL); | |
| 79987 | 80278 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79988 | 80279 | sqlite3VdbeResolveLabel(v, d2); |
| 79989 | 80280 | sqlite3ExprCachePop(pParse, 1); |
| 79990 | 80281 | break; |
| 79991 | 80282 | } |
| @@ -80053,20 +80344,14 @@ | ||
| 80053 | 80344 | } |
| 80054 | 80345 | break; |
| 80055 | 80346 | } |
| 80056 | 80347 | #endif |
| 80057 | 80348 | default: { |
| 80058 | - if( exprAlwaysFalse(pExpr) ){ | |
| 80059 | - sqlite3VdbeAddOp2(v, OP_Goto, 0, dest); | |
| 80060 | - }else if( exprAlwaysTrue(pExpr) ){ | |
| 80061 | - /* no-op */ | |
| 80062 | - }else{ | |
| 80063 | - r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); | |
| 80064 | - sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); | |
| 80065 | - testcase( regFree1==0 ); | |
| 80066 | - testcase( jumpIfNull==0 ); | |
| 80067 | - } | |
| 80349 | + r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); | |
| 80350 | + sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); | |
| 80351 | + testcase( regFree1==0 ); | |
| 80352 | + testcase( jumpIfNull==0 ); | |
| 80068 | 80353 | break; |
| 80069 | 80354 | } |
| 80070 | 80355 | } |
| 80071 | 80356 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 80072 | 80357 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -83162,10 +83447,14 @@ | ||
| 83162 | 83447 | { |
| 83163 | 83448 | int rc = SQLITE_OK; |
| 83164 | 83449 | if( pExpr ){ |
| 83165 | 83450 | if( pExpr->op!=TK_ID ){ |
| 83166 | 83451 | rc = sqlite3ResolveExprNames(pName, pExpr); |
| 83452 | + if( rc==SQLITE_OK && !sqlite3ExprIsConstant(pExpr) ){ | |
| 83453 | + sqlite3ErrorMsg(pName->pParse, "invalid name: \"%s\"", pExpr->u.zToken); | |
| 83454 | + return SQLITE_ERROR; | |
| 83455 | + } | |
| 83167 | 83456 | }else{ |
| 83168 | 83457 | pExpr->op = TK_STRING; |
| 83169 | 83458 | } |
| 83170 | 83459 | } |
| 83171 | 83460 | return rc; |
| @@ -87940,13 +88229,13 @@ | ||
| 87940 | 88229 | sqlite3StrAccumInit(&errMsg, 0, 0, 200); |
| 87941 | 88230 | errMsg.db = pParse->db; |
| 87942 | 88231 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 87943 | 88232 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 87944 | 88233 | if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); |
| 87945 | - sqlite3StrAccumAppendAll(&errMsg, pTab->zName); | |
| 88234 | + sqlite3StrAccumAppend(&errMsg, pTab->zName, -1); | |
| 87946 | 88235 | sqlite3StrAccumAppend(&errMsg, ".", 1); |
| 87947 | - sqlite3StrAccumAppendAll(&errMsg, zCol); | |
| 88236 | + sqlite3StrAccumAppend(&errMsg, zCol, -1); | |
| 87948 | 88237 | } |
| 87949 | 88238 | zErr = sqlite3StrAccumFinish(&errMsg); |
| 87950 | 88239 | sqlite3HaltConstraint(pParse, |
| 87951 | 88240 | (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE, |
| 87952 | 88241 | onError, zErr, P4_DYNAMIC, P5_ConstraintUnique); |
| @@ -88134,13 +88423,12 @@ | ||
| 88134 | 88423 | } |
| 88135 | 88424 | if( pKey ){ |
| 88136 | 88425 | assert( sqlite3KeyInfoIsWriteable(pKey) ); |
| 88137 | 88426 | for(i=0; i<nCol; i++){ |
| 88138 | 88427 | char *zColl = pIdx->azColl[i]; |
| 88139 | - assert( zColl!=0 ); | |
| 88140 | - pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 : | |
| 88141 | - sqlite3LocateCollSeq(pParse, zColl); | |
| 88428 | + if( NEVER(zColl==0) ) zColl = "BINARY"; | |
| 88429 | + pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl); | |
| 88142 | 88430 | pKey->aSortOrder[i] = pIdx->aSortOrder[i]; |
| 88143 | 88431 | } |
| 88144 | 88432 | if( pParse->nErr ){ |
| 88145 | 88433 | sqlite3KeyInfoUnref(pKey); |
| 88146 | 88434 | }else{ |
| @@ -88509,10 +88797,11 @@ | ||
| 88509 | 88797 | int bestScore = 0; /* Score of best match */ |
| 88510 | 88798 | int h; /* Hash value */ |
| 88511 | 88799 | |
| 88512 | 88800 | assert( nArg>=(-2) ); |
| 88513 | 88801 | assert( nArg>=(-1) || createFlag==0 ); |
| 88802 | + assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); | |
| 88514 | 88803 | h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a); |
| 88515 | 88804 | |
| 88516 | 88805 | /* First search for a match amongst the application-defined functions. |
| 88517 | 88806 | */ |
| 88518 | 88807 | p = functionSearch(&db->aFunc, h, zName, nName); |
| @@ -89399,10 +89688,11 @@ | ||
| 89399 | 89688 | Vdbe *v = pParse->pVdbe; |
| 89400 | 89689 | int j; |
| 89401 | 89690 | Table *pTab = pIdx->pTable; |
| 89402 | 89691 | int regBase; |
| 89403 | 89692 | int nCol; |
| 89693 | + Index *pPk; | |
| 89404 | 89694 | |
| 89405 | 89695 | if( piPartIdxLabel ){ |
| 89406 | 89696 | if( pIdx->pPartIdxWhere ){ |
| 89407 | 89697 | *piPartIdxLabel = sqlite3VdbeMakeLabel(v); |
| 89408 | 89698 | pParse->iPartIdxTab = iDataCur; |
| @@ -89412,25 +89702,32 @@ | ||
| 89412 | 89702 | *piPartIdxLabel = 0; |
| 89413 | 89703 | } |
| 89414 | 89704 | } |
| 89415 | 89705 | nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn; |
| 89416 | 89706 | regBase = sqlite3GetTempRange(pParse, nCol); |
| 89707 | + pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); | |
| 89417 | 89708 | for(j=0; j<nCol; j++){ |
| 89418 | - sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j], | |
| 89419 | - regBase+j); | |
| 89420 | - /* If the column affinity is REAL but the number is an integer, then it | |
| 89421 | - ** might be stored in the table as an integer (using a compact | |
| 89422 | - ** representation) then converted to REAL by an OP_RealAffinity opcode. | |
| 89423 | - ** But we are getting ready to store this value back into an index, where | |
| 89424 | - ** it should be converted by to INTEGER again. So omit the OP_RealAffinity | |
| 89425 | - ** opcode if it is present */ | |
| 89426 | - if( sqlite3VdbeGetOp(v, -1)->opcode==OP_RealAffinity ){ | |
| 89427 | - sqlite3VdbeDeleteLastOpcode(v); | |
| 89709 | + i16 idx = pIdx->aiColumn[j]; | |
| 89710 | + if( pPk ) idx = sqlite3ColumnOfIndex(pPk, idx); | |
| 89711 | + if( idx<0 || idx==pTab->iPKey ){ | |
| 89712 | + sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regBase+j); | |
| 89713 | + }else{ | |
| 89714 | + sqlite3VdbeAddOp3(v, OP_Column, iDataCur, idx, regBase+j); | |
| 89715 | + sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[j], -1); | |
| 89428 | 89716 | } |
| 89429 | 89717 | } |
| 89430 | 89718 | if( regOut ){ |
| 89719 | + const char *zAff; | |
| 89720 | + if( pTab->pSelect | |
| 89721 | + || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt) | |
| 89722 | + ){ | |
| 89723 | + zAff = 0; | |
| 89724 | + }else{ | |
| 89725 | + zAff = sqlite3IndexAffinityStr(v, pIdx); | |
| 89726 | + } | |
| 89431 | 89727 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 89728 | + sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT); | |
| 89432 | 89729 | } |
| 89433 | 89730 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 89434 | 89731 | return regBase; |
| 89435 | 89732 | } |
| 89436 | 89733 | |
| @@ -89652,36 +89949,10 @@ | ||
| 89652 | 89949 | } |
| 89653 | 89950 | if( nNeedle>nHaystack ) N = 0; |
| 89654 | 89951 | sqlite3_result_int(context, N); |
| 89655 | 89952 | } |
| 89656 | 89953 | |
| 89657 | -/* | |
| 89658 | -** Implementation of the printf() function. | |
| 89659 | -*/ | |
| 89660 | -static void printfFunc( | |
| 89661 | - sqlite3_context *context, | |
| 89662 | - int argc, | |
| 89663 | - sqlite3_value **argv | |
| 89664 | -){ | |
| 89665 | - PrintfArguments x; | |
| 89666 | - StrAccum str; | |
| 89667 | - const char *zFormat; | |
| 89668 | - int n; | |
| 89669 | - | |
| 89670 | - if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ | |
| 89671 | - x.nArg = argc-1; | |
| 89672 | - x.nUsed = 0; | |
| 89673 | - x.apArg = argv+1; | |
| 89674 | - sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH); | |
| 89675 | - str.db = sqlite3_context_db_handle(context); | |
| 89676 | - sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); | |
| 89677 | - n = str.nChar; | |
| 89678 | - sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, | |
| 89679 | - SQLITE_DYNAMIC); | |
| 89680 | - } | |
| 89681 | -} | |
| 89682 | - | |
| 89683 | 89954 | /* |
| 89684 | 89955 | ** Implementation of the substr() function. |
| 89685 | 89956 | ** |
| 89686 | 89957 | ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. |
| 89687 | 89958 | ** p1 is 1-indexed. So substr(x,1,1) returns the first character |
| @@ -90971,15 +91242,15 @@ | ||
| 90971 | 91242 | nSep = sqlite3_value_bytes(argv[1]); |
| 90972 | 91243 | }else{ |
| 90973 | 91244 | zSep = ","; |
| 90974 | 91245 | nSep = 1; |
| 90975 | 91246 | } |
| 90976 | - if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep); | |
| 91247 | + sqlite3StrAccumAppend(pAccum, zSep, nSep); | |
| 90977 | 91248 | } |
| 90978 | 91249 | zVal = (char*)sqlite3_value_text(argv[0]); |
| 90979 | 91250 | nVal = sqlite3_value_bytes(argv[0]); |
| 90980 | - if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal); | |
| 91251 | + sqlite3StrAccumAppend(pAccum, zVal, nVal); | |
| 90981 | 91252 | } |
| 90982 | 91253 | } |
| 90983 | 91254 | static void groupConcatFinalize(sqlite3_context *context){ |
| 90984 | 91255 | StrAccum *pAccum; |
| 90985 | 91256 | pAccum = sqlite3_aggregate_context(context, 0); |
| @@ -91108,11 +91379,10 @@ | ||
| 91108 | 91379 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 91109 | 91380 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 91110 | 91381 | FUNCTION(instr, 2, 0, 0, instrFunc ), |
| 91111 | 91382 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 91112 | 91383 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| 91113 | - FUNCTION(printf, -1, 0, 0, printfFunc ), | |
| 91114 | 91384 | FUNCTION(unicode, 1, 0, 0, unicodeFunc ), |
| 91115 | 91385 | FUNCTION(char, -1, 0, 0, charFunc ), |
| 91116 | 91386 | FUNCTION(abs, 1, 0, 0, absFunc ), |
| 91117 | 91387 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 91118 | 91388 | FUNCTION(round, 1, 0, 0, roundFunc ), |
| @@ -93779,11 +94049,10 @@ | ||
| 93779 | 94049 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 93780 | 94050 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 93781 | 94051 | int ipkTop = 0; /* Top of the rowid change constraint check */ |
| 93782 | 94052 | int ipkBottom = 0; /* Bottom of the rowid change constraint check */ |
| 93783 | 94053 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| 93784 | - int regRowid = -1; /* Register holding ROWID value */ | |
| 93785 | 94054 | |
| 93786 | 94055 | isUpdate = regOldData!=0; |
| 93787 | 94056 | db = pParse->db; |
| 93788 | 94057 | v = sqlite3GetVdbe(pParse); |
| 93789 | 94058 | assert( v!=0 ); |
| @@ -94010,13 +94279,11 @@ | ||
| 94010 | 94279 | regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn); |
| 94011 | 94280 | for(i=0; i<pIdx->nColumn; i++){ |
| 94012 | 94281 | int iField = pIdx->aiColumn[i]; |
| 94013 | 94282 | int x; |
| 94014 | 94283 | if( iField<0 || iField==pTab->iPKey ){ |
| 94015 | - if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */ | |
| 94016 | 94284 | x = regNewData; |
| 94017 | - regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i; | |
| 94018 | 94285 | }else{ |
| 94019 | 94286 | x = iField + regNewData + 1; |
| 94020 | 94287 | } |
| 94021 | 94288 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 94022 | 94289 | VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); |
| @@ -94052,53 +94319,51 @@ | ||
| 94052 | 94319 | sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk, |
| 94053 | 94320 | regIdx, pIdx->nKeyCol); |
| 94054 | 94321 | |
| 94055 | 94322 | /* Generate code to handle collisions */ |
| 94056 | 94323 | regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField); |
| 94057 | - if( isUpdate || onError==OE_Replace ){ | |
| 94058 | - if( HasRowid(pTab) ){ | |
| 94059 | - sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR); | |
| 94060 | - /* Conflict only if the rowid of the existing index entry | |
| 94061 | - ** is different from old-rowid */ | |
| 94062 | - if( isUpdate ){ | |
| 94063 | - sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData); | |
| 94064 | - } | |
| 94065 | - }else{ | |
| 94066 | - int x; | |
| 94067 | - /* Extract the PRIMARY KEY from the end of the index entry and | |
| 94068 | - ** store it in registers regR..regR+nPk-1 */ | |
| 94069 | - if( pIdx!=pPk ){ | |
| 94070 | - for(i=0; i<pPk->nKeyCol; i++){ | |
| 94071 | - x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]); | |
| 94072 | - sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i); | |
| 94073 | - VdbeComment((v, "%s.%s", pTab->zName, | |
| 94074 | - pTab->aCol[pPk->aiColumn[i]].zName)); | |
| 94075 | - } | |
| 94076 | - } | |
| 94077 | - if( isUpdate ){ | |
| 94078 | - /* If currently processing the PRIMARY KEY of a WITHOUT ROWID | |
| 94079 | - ** table, only conflict if the new PRIMARY KEY values are actually | |
| 94080 | - ** different from the old. | |
| 94081 | - ** | |
| 94082 | - ** For a UNIQUE index, only conflict if the PRIMARY KEY values | |
| 94083 | - ** of the matched index row are different from the original PRIMARY | |
| 94084 | - ** KEY values of this row before the update. */ | |
| 94085 | - int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol; | |
| 94086 | - int op = OP_Ne; | |
| 94087 | - int regCmp = (pIdx->autoIndex==2 ? regIdx : regR); | |
| 94088 | - | |
| 94089 | - for(i=0; i<pPk->nKeyCol; i++){ | |
| 94090 | - char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]); | |
| 94091 | - x = pPk->aiColumn[i]; | |
| 94092 | - if( i==(pPk->nKeyCol-1) ){ | |
| 94093 | - addrJump = addrUniqueOk; | |
| 94094 | - op = OP_Eq; | |
| 94095 | - } | |
| 94096 | - sqlite3VdbeAddOp4(v, op, | |
| 94097 | - regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ | |
| 94098 | - ); | |
| 94099 | - } | |
| 94324 | + if( HasRowid(pTab) ){ | |
| 94325 | + sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR); | |
| 94326 | + /* Conflict only if the rowid of the existing index entry | |
| 94327 | + ** is different from old-rowid */ | |
| 94328 | + if( isUpdate ){ | |
| 94329 | + sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData); | |
| 94330 | + } | |
| 94331 | + }else{ | |
| 94332 | + int x; | |
| 94333 | + /* Extract the PRIMARY KEY from the end of the index entry and | |
| 94334 | + ** store it in registers regR..regR+nPk-1 */ | |
| 94335 | + if( (isUpdate || onError==OE_Replace) && pIdx!=pPk ){ | |
| 94336 | + for(i=0; i<pPk->nKeyCol; i++){ | |
| 94337 | + x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]); | |
| 94338 | + sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i); | |
| 94339 | + VdbeComment((v, "%s.%s", pTab->zName, | |
| 94340 | + pTab->aCol[pPk->aiColumn[i]].zName)); | |
| 94341 | + } | |
| 94342 | + } | |
| 94343 | + if( isUpdate ){ | |
| 94344 | + /* If currently processing the PRIMARY KEY of a WITHOUT ROWID | |
| 94345 | + ** table, only conflict if the new PRIMARY KEY values are actually | |
| 94346 | + ** different from the old. | |
| 94347 | + ** | |
| 94348 | + ** For a UNIQUE index, only conflict if the PRIMARY KEY values | |
| 94349 | + ** of the matched index row are different from the original PRIMARY | |
| 94350 | + ** KEY values of this row before the update. */ | |
| 94351 | + int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol; | |
| 94352 | + int op = OP_Ne; | |
| 94353 | + int regCmp = (pIdx->autoIndex==2 ? regIdx : regR); | |
| 94354 | + | |
| 94355 | + for(i=0; i<pPk->nKeyCol; i++){ | |
| 94356 | + char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]); | |
| 94357 | + x = pPk->aiColumn[i]; | |
| 94358 | + if( i==(pPk->nKeyCol-1) ){ | |
| 94359 | + addrJump = addrUniqueOk; | |
| 94360 | + op = OP_Eq; | |
| 94361 | + } | |
| 94362 | + sqlite3VdbeAddOp4(v, op, | |
| 94363 | + regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ | |
| 94364 | + ); | |
| 94100 | 94365 | } |
| 94101 | 94366 | } |
| 94102 | 94367 | } |
| 94103 | 94368 | |
| 94104 | 94369 | /* Generate code that executes if the new index entry is not unique */ |
| @@ -98841,15 +99106,11 @@ | ||
| 98841 | 99106 | |
| 98842 | 99107 | /* |
| 98843 | 99108 | ** Free all memory allocations in the pParse object |
| 98844 | 99109 | */ |
| 98845 | 99110 | SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ |
| 98846 | - if( pParse ){ | |
| 98847 | - sqlite3 *db = pParse->db; | |
| 98848 | - sqlite3DbFree(db, pParse->aLabel); | |
| 98849 | - sqlite3ExprListDelete(db, pParse->pConstExpr); | |
| 98850 | - } | |
| 99111 | + if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr); | |
| 98851 | 99112 | } |
| 98852 | 99113 | |
| 98853 | 99114 | /* |
| 98854 | 99115 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 98855 | 99116 | */ |
| @@ -99798,10 +100059,11 @@ | ||
| 99798 | 100059 | } |
| 99799 | 100060 | }else if( eDest!=SRT_Exists ){ |
| 99800 | 100061 | /* If the destination is an EXISTS(...) expression, the actual |
| 99801 | 100062 | ** values returned by the SELECT are not required. |
| 99802 | 100063 | */ |
| 100064 | + sqlite3ExprCacheClear(pParse); | |
| 99803 | 100065 | sqlite3ExprCodeExprList(pParse, pEList, regResult, |
| 99804 | 100066 | (eDest==SRT_Output)?SQLITE_ECEL_DUP:0); |
| 99805 | 100067 | } |
| 99806 | 100068 | nColumn = nResultCol; |
| 99807 | 100069 | |
| @@ -100764,11 +101026,11 @@ | ||
| 100764 | 101026 | ** If an error occurs, return NULL and leave a message in pParse. |
| 100765 | 101027 | */ |
| 100766 | 101028 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ |
| 100767 | 101029 | Vdbe *v = pParse->pVdbe; |
| 100768 | 101030 | if( v==0 ){ |
| 100769 | - v = pParse->pVdbe = sqlite3VdbeCreate(pParse); | |
| 101031 | + v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db); | |
| 100770 | 101032 | #ifndef SQLITE_OMIT_TRACE |
| 100771 | 101033 | if( v ){ |
| 100772 | 101034 | sqlite3VdbeAddOp0(v, OP_Trace); |
| 100773 | 101035 | } |
| 100774 | 101036 | #endif |
| @@ -103022,27 +103284,18 @@ | ||
| 103022 | 103284 | */ |
| 103023 | 103285 | static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){ |
| 103024 | 103286 | Vdbe *v = pParse->pVdbe; |
| 103025 | 103287 | int i; |
| 103026 | 103288 | struct AggInfo_func *pFunc; |
| 103027 | - int nReg = pAggInfo->nFunc + pAggInfo->nColumn; | |
| 103028 | - if( nReg==0 ) return; | |
| 103029 | -#ifdef SQLITE_DEBUG | |
| 103030 | - /* Verify that all AggInfo registers are within the range specified by | |
| 103031 | - ** AggInfo.mnReg..AggInfo.mxReg */ | |
| 103032 | - assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 ); | |
| 103289 | + if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){ | |
| 103290 | + return; | |
| 103291 | + } | |
| 103033 | 103292 | for(i=0; i<pAggInfo->nColumn; i++){ |
| 103034 | - assert( pAggInfo->aCol[i].iMem>=pAggInfo->mnReg | |
| 103035 | - && pAggInfo->aCol[i].iMem<=pAggInfo->mxReg ); | |
| 103036 | - } | |
| 103037 | - for(i=0; i<pAggInfo->nFunc; i++){ | |
| 103038 | - assert( pAggInfo->aFunc[i].iMem>=pAggInfo->mnReg | |
| 103039 | - && pAggInfo->aFunc[i].iMem<=pAggInfo->mxReg ); | |
| 103040 | - } | |
| 103041 | -#endif | |
| 103042 | - sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg); | |
| 103293 | + sqlite3VdbeAddOp2(v, OP_Null, 0, pAggInfo->aCol[i].iMem); | |
| 103294 | + } | |
| 103043 | 103295 | for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){ |
| 103296 | + sqlite3VdbeAddOp2(v, OP_Null, 0, pFunc->iMem); | |
| 103044 | 103297 | if( pFunc->iDistinct>=0 ){ |
| 103045 | 103298 | Expr *pE = pFunc->pExpr; |
| 103046 | 103299 | assert( !ExprHasProperty(pE, EP_xIsSelect) ); |
| 103047 | 103300 | if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){ |
| 103048 | 103301 | sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one " |
| @@ -103084,10 +103337,11 @@ | ||
| 103084 | 103337 | int addrHitTest = 0; |
| 103085 | 103338 | struct AggInfo_func *pF; |
| 103086 | 103339 | struct AggInfo_col *pC; |
| 103087 | 103340 | |
| 103088 | 103341 | pAggInfo->directMode = 1; |
| 103342 | + sqlite3ExprCacheClear(pParse); | |
| 103089 | 103343 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 103090 | 103344 | int nArg; |
| 103091 | 103345 | int addrNext = 0; |
| 103092 | 103346 | int regAgg; |
| 103093 | 103347 | ExprList *pList = pF->pExpr->x.pList; |
| @@ -103616,11 +103870,10 @@ | ||
| 103616 | 103870 | */ |
| 103617 | 103871 | memset(&sNC, 0, sizeof(sNC)); |
| 103618 | 103872 | sNC.pParse = pParse; |
| 103619 | 103873 | sNC.pSrcList = pTabList; |
| 103620 | 103874 | sNC.pAggInfo = &sAggInfo; |
| 103621 | - sAggInfo.mnReg = pParse->nMem+1; | |
| 103622 | 103875 | sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0; |
| 103623 | 103876 | sAggInfo.pGroupBy = pGroupBy; |
| 103624 | 103877 | sqlite3ExprAnalyzeAggList(&sNC, pEList); |
| 103625 | 103878 | sqlite3ExprAnalyzeAggList(&sNC, pOrderBy); |
| 103626 | 103879 | if( pHaving ){ |
| @@ -103631,11 +103884,10 @@ | ||
| 103631 | 103884 | assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) ); |
| 103632 | 103885 | sNC.ncFlags |= NC_InAggFunc; |
| 103633 | 103886 | sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList); |
| 103634 | 103887 | sNC.ncFlags &= ~NC_InAggFunc; |
| 103635 | 103888 | } |
| 103636 | - sAggInfo.mxReg = pParse->nMem; | |
| 103637 | 103889 | if( db->mallocFailed ) goto select_end; |
| 103638 | 103890 | |
| 103639 | 103891 | /* Processing for aggregates with GROUP BY is very different and |
| 103640 | 103892 | ** much more complex than aggregates without a GROUP BY. |
| 103641 | 103893 | */ |
| @@ -105536,11 +105788,11 @@ | ||
| 105536 | 105788 | pCol->affinity, &pValue); |
| 105537 | 105789 | if( pValue ){ |
| 105538 | 105790 | sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM); |
| 105539 | 105791 | } |
| 105540 | 105792 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 105541 | - if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ | |
| 105793 | + if( iReg>=0 && pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ | |
| 105542 | 105794 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 105543 | 105795 | } |
| 105544 | 105796 | #endif |
| 105545 | 105797 | } |
| 105546 | 105798 | } |
| @@ -105960,14 +106212,14 @@ | ||
| 105960 | 106212 | ** be used eliminates some redundant opcodes. |
| 105961 | 106213 | */ |
| 105962 | 106214 | newmask = sqlite3TriggerColmask( |
| 105963 | 106215 | pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError |
| 105964 | 106216 | ); |
| 105965 | - /*sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1);*/ | |
| 106217 | + sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1); | |
| 105966 | 106218 | for(i=0; i<pTab->nCol; i++){ |
| 105967 | 106219 | if( i==pTab->iPKey ){ |
| 105968 | - sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i); | |
| 106220 | + /*sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);*/ | |
| 105969 | 106221 | }else{ |
| 105970 | 106222 | j = aXRef[i]; |
| 105971 | 106223 | if( j>=0 ){ |
| 105972 | 106224 | sqlite3ExprCode(pParse, pChanges->a[j].pExpr, regNew+i); |
| 105973 | 106225 | }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask&(1<<i)) ){ |
| @@ -105977,12 +106229,10 @@ | ||
| 105977 | 106229 | ** a new.* reference in a trigger program. |
| 105978 | 106230 | */ |
| 105979 | 106231 | testcase( i==31 ); |
| 105980 | 106232 | testcase( i==32 ); |
| 105981 | 106233 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i); |
| 105982 | - }else{ | |
| 105983 | - sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i); | |
| 105984 | 106234 | } |
| 105985 | 106235 | } |
| 105986 | 106236 | } |
| 105987 | 106237 | |
| 105988 | 106238 | /* Fire any BEFORE UPDATE triggers. This happens before constraints are |
| @@ -110731,11 +110981,11 @@ | ||
| 110731 | 110981 | int iTerm, /* Index of this term. First is zero */ |
| 110732 | 110982 | const char *zColumn, /* Name of the column */ |
| 110733 | 110983 | const char *zOp /* Name of the operator */ |
| 110734 | 110984 | ){ |
| 110735 | 110985 | if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5); |
| 110736 | - sqlite3StrAccumAppendAll(pStr, zColumn); | |
| 110986 | + sqlite3StrAccumAppend(pStr, zColumn, -1); | |
| 110737 | 110987 | sqlite3StrAccumAppend(pStr, zOp, 1); |
| 110738 | 110988 | sqlite3StrAccumAppend(pStr, "?", 1); |
| 110739 | 110989 | } |
| 110740 | 110990 | |
| 110741 | 110991 | /* |
| @@ -110777,11 +111027,11 @@ | ||
| 110777 | 111027 | if( i>=nSkip ){ |
| 110778 | 111028 | explainAppendTerm(&txt, i, z, "="); |
| 110779 | 111029 | }else{ |
| 110780 | 111030 | if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5); |
| 110781 | 111031 | sqlite3StrAccumAppend(&txt, "ANY(", 4); |
| 110782 | - sqlite3StrAccumAppendAll(&txt, z); | |
| 111032 | + sqlite3StrAccumAppend(&txt, z, -1); | |
| 110783 | 111033 | sqlite3StrAccumAppend(&txt, ")", 1); |
| 110784 | 111034 | } |
| 110785 | 111035 | } |
| 110786 | 111036 | |
| 110787 | 111037 | j = i; |
| @@ -113593,16 +113843,13 @@ | ||
| 113593 | 113843 | sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 113594 | 113844 | |
| 113595 | 113845 | /* Special case: a WHERE clause that is constant. Evaluate the |
| 113596 | 113846 | ** expression and either jump over all of the code or fall thru. |
| 113597 | 113847 | */ |
| 113598 | - for(ii=0; ii<sWLB.pWC->nTerm; ii++){ | |
| 113599 | - if( nTabList==0 || sqlite3ExprIsConstantNotJoin(sWLB.pWC->a[ii].pExpr) ){ | |
| 113600 | - sqlite3ExprIfFalse(pParse, sWLB.pWC->a[ii].pExpr, pWInfo->iBreak, | |
| 113601 | - SQLITE_JUMPIFNULL); | |
| 113602 | - sWLB.pWC->a[ii].wtFlags |= TERM_CODED; | |
| 113603 | - } | |
| 113848 | + if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){ | |
| 113849 | + sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL); | |
| 113850 | + pWhere = 0; | |
| 113604 | 113851 | } |
| 113605 | 113852 | |
| 113606 | 113853 | /* Special case: No FROM clause |
| 113607 | 113854 | */ |
| 113608 | 113855 | if( nTabList==0 ){ |
| @@ -119339,12 +119586,11 @@ | ||
| 119339 | 119586 | } |
| 119340 | 119587 | db->lookaside.pEnd = p; |
| 119341 | 119588 | db->lookaside.bEnabled = 1; |
| 119342 | 119589 | db->lookaside.bMalloced = pBuf==0 ?1:0; |
| 119343 | 119590 | }else{ |
| 119344 | - db->lookaside.pStart = db; | |
| 119345 | - db->lookaside.pEnd = db; | |
| 119591 | + db->lookaside.pEnd = 0; | |
| 119346 | 119592 | db->lookaside.bEnabled = 0; |
| 119347 | 119593 | db->lookaside.bMalloced = 0; |
| 119348 | 119594 | } |
| 119349 | 119595 | return SQLITE_OK; |
| 119350 | 119596 | } |
| @@ -119738,11 +119984,13 @@ | ||
| 119738 | 119984 | } |
| 119739 | 119985 | sqlite3HashClear(&db->aModule); |
| 119740 | 119986 | #endif |
| 119741 | 119987 | |
| 119742 | 119988 | sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */ |
| 119743 | - sqlite3ValueFree(db->pErr); | |
| 119989 | + if( db->pErr ){ | |
| 119990 | + sqlite3ValueFree(db->pErr); | |
| 119991 | + } | |
| 119744 | 119992 | sqlite3CloseExtensions(db); |
| 119745 | 119993 | |
| 119746 | 119994 | db->magic = SQLITE_MAGIC_ERROR; |
| 119747 | 119995 | |
| 119748 | 119996 | /* The temp-database schema is allocated differently from the other schema |
| @@ -119813,11 +120061,12 @@ | ||
| 119813 | 120061 | |
| 119814 | 120062 | /* |
| 119815 | 120063 | ** Return a static string containing the name corresponding to the error code |
| 119816 | 120064 | ** specified in the argument. |
| 119817 | 120065 | */ |
| 119818 | -#if defined(SQLITE_TEST) | |
| 120066 | +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \ | |
| 120067 | + defined(SQLITE_DEBUG_OS_TRACE) | |
| 119819 | 120068 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 119820 | 120069 | const char *zName = 0; |
| 119821 | 120070 | int i, origRc = rc; |
| 119822 | 120071 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 119823 | 120072 | switch( rc ){ |
| @@ -119835,11 +120084,10 @@ | ||
| 119835 | 120084 | case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; |
| 119836 | 120085 | case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; |
| 119837 | 120086 | case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break; |
| 119838 | 120087 | case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break; |
| 119839 | 120088 | case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break; |
| 119840 | - case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break; | |
| 119841 | 120089 | case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; |
| 119842 | 120090 | case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; |
| 119843 | 120091 | case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break; |
| 119844 | 120092 | case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break; |
| 119845 | 120093 | case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break; |
| @@ -120120,11 +120368,10 @@ | ||
| 120120 | 120368 | void (*xFinal)(sqlite3_context*), |
| 120121 | 120369 | FuncDestructor *pDestructor |
| 120122 | 120370 | ){ |
| 120123 | 120371 | FuncDef *p; |
| 120124 | 120372 | int nName; |
| 120125 | - int extraFlags; | |
| 120126 | 120373 | |
| 120127 | 120374 | assert( sqlite3_mutex_held(db->mutex) ); |
| 120128 | 120375 | if( zFunctionName==0 || |
| 120129 | 120376 | (xFunc && (xFinal || xStep)) || |
| 120130 | 120377 | (!xFunc && (xFinal && !xStep)) || |
| @@ -120131,14 +120378,10 @@ | ||
| 120131 | 120378 | (!xFunc && (!xFinal && xStep)) || |
| 120132 | 120379 | (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
| 120133 | 120380 | (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
| 120134 | 120381 | return SQLITE_MISUSE_BKPT; |
| 120135 | 120382 | } |
| 120136 | - | |
| 120137 | - assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC ); | |
| 120138 | - extraFlags = enc & SQLITE_DETERMINISTIC; | |
| 120139 | - enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY); | |
| 120140 | 120383 | |
| 120141 | 120384 | #ifndef SQLITE_OMIT_UTF16 |
| 120142 | 120385 | /* If SQLITE_UTF16 is specified as the encoding type, transform this |
| 120143 | 120386 | ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
| 120144 | 120387 | ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
| @@ -120148,14 +120391,14 @@ | ||
| 120148 | 120391 | */ |
| 120149 | 120392 | if( enc==SQLITE_UTF16 ){ |
| 120150 | 120393 | enc = SQLITE_UTF16NATIVE; |
| 120151 | 120394 | }else if( enc==SQLITE_ANY ){ |
| 120152 | 120395 | int rc; |
| 120153 | - rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, | |
| 120396 | + rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8, | |
| 120154 | 120397 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 120155 | 120398 | if( rc==SQLITE_OK ){ |
| 120156 | - rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, | |
| 120399 | + rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE, | |
| 120157 | 120400 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 120158 | 120401 | } |
| 120159 | 120402 | if( rc!=SQLITE_OK ){ |
| 120160 | 120403 | return rc; |
| 120161 | 120404 | } |
| @@ -120194,12 +120437,11 @@ | ||
| 120194 | 120437 | |
| 120195 | 120438 | if( pDestructor ){ |
| 120196 | 120439 | pDestructor->nRef++; |
| 120197 | 120440 | } |
| 120198 | 120441 | p->pDestructor = pDestructor; |
| 120199 | - p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags; | |
| 120200 | - testcase( p->funcFlags & SQLITE_DETERMINISTIC ); | |
| 120442 | + p->funcFlags &= SQLITE_FUNC_ENCMASK; | |
| 120201 | 120443 | p->xFunc = xFunc; |
| 120202 | 120444 | p->xStep = xStep; |
| 120203 | 120445 | p->xFinalize = xFinal; |
| 120204 | 120446 | p->pUserData = pUserData; |
| 120205 | 120447 | p->nArg = (u16)nArg; |
| @@ -120625,11 +120867,10 @@ | ||
| 120625 | 120867 | } |
| 120626 | 120868 | sqlite3_mutex_enter(db->mutex); |
| 120627 | 120869 | if( db->mallocFailed ){ |
| 120628 | 120870 | z = sqlite3ErrStr(SQLITE_NOMEM); |
| 120629 | 120871 | }else{ |
| 120630 | - testcase( db->pErr==0 ); | |
| 120631 | 120872 | z = (char*)sqlite3_value_text(db->pErr); |
| 120632 | 120873 | assert( !db->mallocFailed ); |
| 120633 | 120874 | if( z==0 ){ |
| 120634 | 120875 | z = sqlite3ErrStr(db->errCode); |
| 120635 | 120876 | } |
| @@ -120667,11 +120908,12 @@ | ||
| 120667 | 120908 | if( db->mallocFailed ){ |
| 120668 | 120909 | z = (void *)outOfMem; |
| 120669 | 120910 | }else{ |
| 120670 | 120911 | z = sqlite3_value_text16(db->pErr); |
| 120671 | 120912 | if( z==0 ){ |
| 120672 | - sqlite3Error(db, db->errCode, sqlite3ErrStr(db->errCode)); | |
| 120913 | + sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode), | |
| 120914 | + SQLITE_UTF8, SQLITE_STATIC); | |
| 120673 | 120915 | z = sqlite3_value_text16(db->pErr); |
| 120674 | 120916 | } |
| 120675 | 120917 | /* A malloc() may have failed within the call to sqlite3_value_text16() |
| 120676 | 120918 | ** above. If this is the case, then the db->mallocFailed flag needs to |
| 120677 | 120919 | ** be cleared before returning. Do this directly, instead of via |
| @@ -121380,10 +121622,12 @@ | ||
| 121380 | 121622 | #ifdef SQLITE_ENABLE_RTREE |
| 121381 | 121623 | if( !db->mallocFailed && rc==SQLITE_OK){ |
| 121382 | 121624 | rc = sqlite3RtreeInit(db); |
| 121383 | 121625 | } |
| 121384 | 121626 | #endif |
| 121627 | + | |
| 121628 | + sqlite3Error(db, rc, 0); | |
| 121385 | 121629 | |
| 121386 | 121630 | /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking |
| 121387 | 121631 | ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking |
| 121388 | 121632 | ** mode. Doing nothing at all also makes NORMAL the default. |
| 121389 | 121633 | */ |
| @@ -121391,12 +121635,10 @@ | ||
| 121391 | 121635 | db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE; |
| 121392 | 121636 | sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt), |
| 121393 | 121637 | SQLITE_DEFAULT_LOCKING_MODE); |
| 121394 | 121638 | #endif |
| 121395 | 121639 | |
| 121396 | - if( rc ) sqlite3Error(db, rc, 0); | |
| 121397 | - | |
| 121398 | 121640 | /* Enable the lookaside-malloc subsystem */ |
| 121399 | 121641 | setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, |
| 121400 | 121642 | sqlite3GlobalConfig.nLookaside); |
| 121401 | 121643 | |
| 121402 | 121644 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| @@ -121852,11 +122094,11 @@ | ||
| 121852 | 122094 | ** Reset the PRNG back to its uninitialized state. The next call |
| 121853 | 122095 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 121854 | 122096 | ** to the xRandomness method of the default VFS. |
| 121855 | 122097 | */ |
| 121856 | 122098 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 121857 | - sqlite3_randomness(0,0); | |
| 122099 | + sqlite3PrngResetState(); | |
| 121858 | 122100 | break; |
| 121859 | 122101 | } |
| 121860 | 122102 | |
| 121861 | 122103 | /* |
| 121862 | 122104 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| @@ -124836,23 +125078,10 @@ | ||
| 124836 | 125078 | char **pzErr /* OUT: sqlite3_malloc'd error message */ |
| 124837 | 125079 | ){ |
| 124838 | 125080 | return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr); |
| 124839 | 125081 | } |
| 124840 | 125082 | |
| 124841 | -/* | |
| 124842 | -** Set the pIdxInfo->estimatedRows variable to nRow. Unless this | |
| 124843 | -** extension is currently being used by a version of SQLite too old to | |
| 124844 | -** support estimatedRows. In that case this function is a no-op. | |
| 124845 | -*/ | |
| 124846 | -static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){ | |
| 124847 | -#if SQLITE_VERSION_NUMBER>=3008002 | |
| 124848 | - if( sqlite3_libversion_number()>=3008002 ){ | |
| 124849 | - pIdxInfo->estimatedRows = nRow; | |
| 124850 | - } | |
| 124851 | -#endif | |
| 124852 | -} | |
| 124853 | - | |
| 124854 | 125083 | /* |
| 124855 | 125084 | ** Implementation of the xBestIndex method for FTS3 tables. There |
| 124856 | 125085 | ** are three possible strategies, in order of preference: |
| 124857 | 125086 | ** |
| 124858 | 125087 | ** 1. Direct lookup by rowid or docid. |
| @@ -124876,24 +125105,11 @@ | ||
| 124876 | 125105 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 124877 | 125106 | pInfo->estimatedCost = 5000000; |
| 124878 | 125107 | for(i=0; i<pInfo->nConstraint; i++){ |
| 124879 | 125108 | int bDocid; /* True if this constraint is on docid */ |
| 124880 | 125109 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 124881 | - if( pCons->usable==0 ){ | |
| 124882 | - if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH ){ | |
| 124883 | - /* There exists an unusable MATCH constraint. This means that if | |
| 124884 | - ** the planner does elect to use the results of this call as part | |
| 124885 | - ** of the overall query plan the user will see an "unable to use | |
| 124886 | - ** function MATCH in the requested context" error. To discourage | |
| 124887 | - ** this, return a very high cost here. */ | |
| 124888 | - pInfo->idxNum = FTS3_FULLSCAN_SEARCH; | |
| 124889 | - pInfo->estimatedCost = 1e50; | |
| 124890 | - setEstimatedRows(pInfo, ((sqlite3_int64)1) << 50); | |
| 124891 | - return SQLITE_OK; | |
| 124892 | - } | |
| 124893 | - continue; | |
| 124894 | - } | |
| 125110 | + if( pCons->usable==0 ) continue; | |
| 124895 | 125111 | |
| 124896 | 125112 | bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1); |
| 124897 | 125113 | |
| 124898 | 125114 | /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */ |
| 124899 | 125115 | if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){ |
| @@ -131750,74 +131966,61 @@ | ||
| 131750 | 131966 | } |
| 131751 | 131967 | |
| 131752 | 131968 | /* Step 2 */ |
| 131753 | 131969 | switch( z[1] ){ |
| 131754 | 131970 | case 'a': |
| 131755 | - if( !stem(&z, "lanoita", "ate", m_gt_0) ){ | |
| 131756 | - stem(&z, "lanoit", "tion", m_gt_0); | |
| 131757 | - } | |
| 131971 | + stem(&z, "lanoita", "ate", m_gt_0) || | |
| 131972 | + stem(&z, "lanoit", "tion", m_gt_0); | |
| 131758 | 131973 | break; |
| 131759 | 131974 | case 'c': |
| 131760 | - if( !stem(&z, "icne", "ence", m_gt_0) ){ | |
| 131761 | - stem(&z, "icna", "ance", m_gt_0); | |
| 131762 | - } | |
| 131975 | + stem(&z, "icne", "ence", m_gt_0) || | |
| 131976 | + stem(&z, "icna", "ance", m_gt_0); | |
| 131763 | 131977 | break; |
| 131764 | 131978 | case 'e': |
| 131765 | 131979 | stem(&z, "rezi", "ize", m_gt_0); |
| 131766 | 131980 | break; |
| 131767 | 131981 | case 'g': |
| 131768 | 131982 | stem(&z, "igol", "log", m_gt_0); |
| 131769 | 131983 | break; |
| 131770 | 131984 | case 'l': |
| 131771 | - if( !stem(&z, "ilb", "ble", m_gt_0) | |
| 131772 | - && !stem(&z, "illa", "al", m_gt_0) | |
| 131773 | - && !stem(&z, "iltne", "ent", m_gt_0) | |
| 131774 | - && !stem(&z, "ile", "e", m_gt_0) | |
| 131775 | - ){ | |
| 131776 | - stem(&z, "ilsuo", "ous", m_gt_0); | |
| 131777 | - } | |
| 131985 | + stem(&z, "ilb", "ble", m_gt_0) || | |
| 131986 | + stem(&z, "illa", "al", m_gt_0) || | |
| 131987 | + stem(&z, "iltne", "ent", m_gt_0) || | |
| 131988 | + stem(&z, "ile", "e", m_gt_0) || | |
| 131989 | + stem(&z, "ilsuo", "ous", m_gt_0); | |
| 131778 | 131990 | break; |
| 131779 | 131991 | case 'o': |
| 131780 | - if( !stem(&z, "noitazi", "ize", m_gt_0) | |
| 131781 | - && !stem(&z, "noita", "ate", m_gt_0) | |
| 131782 | - ){ | |
| 131783 | - stem(&z, "rota", "ate", m_gt_0); | |
| 131784 | - } | |
| 131992 | + stem(&z, "noitazi", "ize", m_gt_0) || | |
| 131993 | + stem(&z, "noita", "ate", m_gt_0) || | |
| 131994 | + stem(&z, "rota", "ate", m_gt_0); | |
| 131785 | 131995 | break; |
| 131786 | 131996 | case 's': |
| 131787 | - if( !stem(&z, "msila", "al", m_gt_0) | |
| 131788 | - && !stem(&z, "ssenevi", "ive", m_gt_0) | |
| 131789 | - && !stem(&z, "ssenluf", "ful", m_gt_0) | |
| 131790 | - ){ | |
| 131791 | - stem(&z, "ssensuo", "ous", m_gt_0); | |
| 131792 | - } | |
| 131997 | + stem(&z, "msila", "al", m_gt_0) || | |
| 131998 | + stem(&z, "ssenevi", "ive", m_gt_0) || | |
| 131999 | + stem(&z, "ssenluf", "ful", m_gt_0) || | |
| 132000 | + stem(&z, "ssensuo", "ous", m_gt_0); | |
| 131793 | 132001 | break; |
| 131794 | 132002 | case 't': |
| 131795 | - if( !stem(&z, "itila", "al", m_gt_0) | |
| 131796 | - && !stem(&z, "itivi", "ive", m_gt_0) | |
| 131797 | - ){ | |
| 131798 | - stem(&z, "itilib", "ble", m_gt_0); | |
| 131799 | - } | |
| 132003 | + stem(&z, "itila", "al", m_gt_0) || | |
| 132004 | + stem(&z, "itivi", "ive", m_gt_0) || | |
| 132005 | + stem(&z, "itilib", "ble", m_gt_0); | |
| 131800 | 132006 | break; |
| 131801 | 132007 | } |
| 131802 | 132008 | |
| 131803 | 132009 | /* Step 3 */ |
| 131804 | 132010 | switch( z[0] ){ |
| 131805 | 132011 | case 'e': |
| 131806 | - if( !stem(&z, "etaci", "ic", m_gt_0) | |
| 131807 | - && !stem(&z, "evita", "", m_gt_0) | |
| 131808 | - ){ | |
| 131809 | - stem(&z, "ezila", "al", m_gt_0); | |
| 131810 | - } | |
| 132012 | + stem(&z, "etaci", "ic", m_gt_0) || | |
| 132013 | + stem(&z, "evita", "", m_gt_0) || | |
| 132014 | + stem(&z, "ezila", "al", m_gt_0); | |
| 131811 | 132015 | break; |
| 131812 | 132016 | case 'i': |
| 131813 | 132017 | stem(&z, "itici", "ic", m_gt_0); |
| 131814 | 132018 | break; |
| 131815 | 132019 | case 'l': |
| 131816 | - if( !stem(&z, "laci", "ic", m_gt_0) ){ | |
| 131817 | - stem(&z, "luf", "", m_gt_0); | |
| 131818 | - } | |
| 132020 | + stem(&z, "laci", "ic", m_gt_0) || | |
| 132021 | + stem(&z, "luf", "", m_gt_0); | |
| 131819 | 132022 | break; |
| 131820 | 132023 | case 's': |
| 131821 | 132024 | stem(&z, "ssen", "", m_gt_0); |
| 131822 | 132025 | break; |
| 131823 | 132026 | } |
| @@ -131854,15 +132057,13 @@ | ||
| 131854 | 132057 | if( z[2]=='a' ){ |
| 131855 | 132058 | if( m_gt_1(z+3) ){ |
| 131856 | 132059 | z += 3; |
| 131857 | 132060 | } |
| 131858 | 132061 | }else if( z[2]=='e' ){ |
| 131859 | - if( !stem(&z, "tneme", "", m_gt_1) | |
| 131860 | - && !stem(&z, "tnem", "", m_gt_1) | |
| 131861 | - ){ | |
| 131862 | - stem(&z, "tne", "", m_gt_1); | |
| 131863 | - } | |
| 132062 | + stem(&z, "tneme", "", m_gt_1) || | |
| 132063 | + stem(&z, "tnem", "", m_gt_1) || | |
| 132064 | + stem(&z, "tne", "", m_gt_1); | |
| 131864 | 132065 | } |
| 131865 | 132066 | } |
| 131866 | 132067 | break; |
| 131867 | 132068 | case 'o': |
| 131868 | 132069 | if( z[0]=='u' ){ |
| @@ -131877,13 +132078,12 @@ | ||
| 131877 | 132078 | if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){ |
| 131878 | 132079 | z += 3; |
| 131879 | 132080 | } |
| 131880 | 132081 | break; |
| 131881 | 132082 | case 't': |
| 131882 | - if( !stem(&z, "eta", "", m_gt_1) ){ | |
| 131883 | - stem(&z, "iti", "", m_gt_1); | |
| 131884 | - } | |
| 132083 | + stem(&z, "eta", "", m_gt_1) || | |
| 132084 | + stem(&z, "iti", "", m_gt_1); | |
| 131885 | 132085 | break; |
| 131886 | 132086 | case 'u': |
| 131887 | 132087 | if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){ |
| 131888 | 132088 | z += 3; |
| 131889 | 132089 | } |
| 131890 | 132090 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.8.3. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -133,13 +133,13 @@ | |
| 133 | ** |
| 134 | ** See also: [sqlite3_libversion()], |
| 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | */ |
| 138 | #define SQLITE_VERSION "3.8.3" |
| 139 | #define SQLITE_VERSION_NUMBER 3008003 |
| 140 | #define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6" |
| 141 | |
| 142 | /* |
| 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | ** |
| @@ -517,11 +517,10 @@ | |
| 517 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 518 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 519 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 520 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 521 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 522 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 523 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 524 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 525 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 526 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 527 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -585,12 +584,11 @@ | |
| 585 | ** information is written to disk in the same order as calls |
| 586 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 587 | ** after reboot following a crash or power loss, the only bytes in a |
| 588 | ** file that were written at the application level might have changed |
| 589 | ** and that adjacent bytes, even bytes within the same sector are |
| 590 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 591 | ** flag indicate that a file cannot be deleted when open. |
| 592 | */ |
| 593 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 594 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 595 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 596 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| @@ -817,33 +815,19 @@ | |
| 817 | ** to the [sqlite3_file] object associated with a particular database |
| 818 | ** connection. See the [sqlite3_file_control()] documentation for |
| 819 | ** additional information. |
| 820 | ** |
| 821 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 822 | ** No longer in use. |
| 823 | ** |
| 824 | ** <li>[[SQLITE_FCNTL_SYNC]] |
| 825 | ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and |
| 826 | ** sent to the VFS immediately before the xSync method is invoked on a |
| 827 | ** database file descriptor. Or, if the xSync method is not invoked |
| 828 | ** because the user has configured SQLite with |
| 829 | ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place |
| 830 | ** of the xSync method. In most cases, the pointer argument passed with |
| 831 | ** this file-control is NULL. However, if the database file is being synced |
| 832 | ** as part of a multi-database commit, the argument points to a nul-terminated |
| 833 | ** string containing the transactions master-journal file name. VFSes that |
| 834 | ** do not need this signal should silently ignore this opcode. Applications |
| 835 | ** should not call [sqlite3_file_control()] with this opcode as doing so may |
| 836 | ** disrupt the operation of the specialized VFSes that do require it. |
| 837 | ** |
| 838 | ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] |
| 839 | ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite |
| 840 | ** and sent to the VFS after a transaction has been committed immediately |
| 841 | ** but before the database is unlocked. VFSes that do not need this signal |
| 842 | ** should silently ignore this opcode. Applications should not call |
| 843 | ** [sqlite3_file_control()] with this opcode as doing so may disrupt the |
| 844 | ** operation of the specialized VFSes that do require it. |
| 845 | ** |
| 846 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 847 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 848 | ** retry counts and intervals for certain disk I/O operations for the |
| 849 | ** windows [VFS] in order to provide robustness in the presence of |
| @@ -963,16 +947,10 @@ | |
| 963 | ** This file control is used by some VFS activity tracing [shims]. |
| 964 | ** The argument is a zero-terminated string. Higher layers in the |
| 965 | ** SQLite stack may generate instances of this file control if |
| 966 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
| 967 | ** |
| 968 | ** <li>[[SQLITE_FCNTL_HAS_MOVED]] |
| 969 | ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a |
| 970 | ** pointer to an integer and it writes a boolean into that integer depending |
| 971 | ** on whether or not the file has been renamed, moved, or deleted since it |
| 972 | ** was first opened. |
| 973 | ** |
| 974 | ** </ul> |
| 975 | */ |
| 976 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 977 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 978 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| @@ -989,13 +967,10 @@ | |
| 989 | #define SQLITE_FCNTL_PRAGMA 14 |
| 990 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 991 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 992 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 993 | #define SQLITE_FCNTL_TRACE 19 |
| 994 | #define SQLITE_FCNTL_HAS_MOVED 20 |
| 995 | #define SQLITE_FCNTL_SYNC 21 |
| 996 | #define SQLITE_FCNTL_COMMIT_PHASETWO 22 |
| 997 | |
| 998 | /* |
| 999 | ** CAPI3REF: Mutex Handle |
| 1000 | ** |
| 1001 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2426,17 +2401,15 @@ | |
| 2426 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2427 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2428 | ** applications to access the same PRNG for other purposes. |
| 2429 | ** |
| 2430 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2431 | ** ^If N is less than one, then P can be a NULL pointer. |
| 2432 | ** |
| 2433 | ** ^If this routine has not been previously called or if the previous |
| 2434 | ** call had N less than one, then the PRNG is seeded using randomness |
| 2435 | ** obtained from the xRandomness method of the default [sqlite3_vfs] object. |
| 2436 | ** ^If the previous call to this routine had an N of 1 or more then |
| 2437 | ** the pseudo-randomness is generated |
| 2438 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2439 | ** method. |
| 2440 | */ |
| 2441 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2442 | |
| @@ -4010,28 +3983,19 @@ | |
| 4010 | ** parameter is less than -1 or greater than 127 then the behavior is |
| 4011 | ** undefined. |
| 4012 | ** |
| 4013 | ** ^The fourth parameter, eTextRep, specifies what |
| 4014 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
| 4015 | ** its parameters. The application should set this parameter to |
| 4016 | ** [SQLITE_UTF16LE] if the function implementation invokes |
| 4017 | ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the |
| 4018 | ** implementation invokes [sqlite3_value_text16be()] on an input, or |
| 4019 | ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] |
| 4020 | ** otherwise. ^The same SQL function may be registered multiple times using |
| 4021 | ** different preferred text encodings, with different implementations for |
| 4022 | ** each encoding. |
| 4023 | ** ^When multiple implementations of the same function are available, SQLite |
| 4024 | ** will pick the one that involves the least amount of data conversion. |
| 4025 | ** |
| 4026 | ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] |
| 4027 | ** to signal that the function will always return the same result given |
| 4028 | ** the same inputs within a single SQL statement. Most SQL functions are |
| 4029 | ** deterministic. The built-in [random()] SQL function is an example of a |
| 4030 | ** function that is not deterministic. The SQLite query planner is able to |
| 4031 | ** perform additional optimizations on deterministic functions, so use |
| 4032 | ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. |
| 4033 | ** |
| 4034 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 4035 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 4036 | ** |
| 4037 | ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are |
| @@ -4113,23 +4077,13 @@ | |
| 4113 | */ |
| 4114 | #define SQLITE_UTF8 1 |
| 4115 | #define SQLITE_UTF16LE 2 |
| 4116 | #define SQLITE_UTF16BE 3 |
| 4117 | #define SQLITE_UTF16 4 /* Use native byte order */ |
| 4118 | #define SQLITE_ANY 5 /* Deprecated */ |
| 4119 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
| 4120 | |
| 4121 | /* |
| 4122 | ** CAPI3REF: Function Flags |
| 4123 | ** |
| 4124 | ** These constants may be ORed together with the |
| 4125 | ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument |
| 4126 | ** to [sqlite3_create_function()], [sqlite3_create_function16()], or |
| 4127 | ** [sqlite3_create_function_v2()]. |
| 4128 | */ |
| 4129 | #define SQLITE_DETERMINISTIC 0x800 |
| 4130 | |
| 4131 | /* |
| 4132 | ** CAPI3REF: Deprecated Functions |
| 4133 | ** DEPRECATED |
| 4134 | ** |
| 4135 | ** These functions are [deprecated]. In order to maintain |
| @@ -8627,11 +8581,10 @@ | |
| 8627 | typedef struct Lookaside Lookaside; |
| 8628 | typedef struct LookasideSlot LookasideSlot; |
| 8629 | typedef struct Module Module; |
| 8630 | typedef struct NameContext NameContext; |
| 8631 | typedef struct Parse Parse; |
| 8632 | typedef struct PrintfArguments PrintfArguments; |
| 8633 | typedef struct RowSet RowSet; |
| 8634 | typedef struct Savepoint Savepoint; |
| 8635 | typedef struct Select Select; |
| 8636 | typedef struct SelectDest SelectDest; |
| 8637 | typedef struct SrcList SrcList; |
| @@ -9100,11 +9053,11 @@ | |
| 9100 | #define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */ |
| 9101 | #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */ |
| 9102 | #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */ |
| 9103 | #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 9104 | #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9105 | #define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */ |
| 9106 | #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */ |
| 9107 | #define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */ |
| 9108 | #define OP_CollSeq 33 |
| 9109 | #define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */ |
| 9110 | #define OP_MustBeInt 35 |
| @@ -9265,11 +9218,11 @@ | |
| 9265 | |
| 9266 | /* |
| 9267 | ** Prototypes for the VDBE interface. See comments on the implementation |
| 9268 | ** for a description of what each of these routines does. |
| 9269 | */ |
| 9270 | SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse*); |
| 9271 | SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int); |
| 9272 | SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int); |
| 9273 | SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int); |
| 9274 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 9275 | SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| @@ -9280,11 +9233,10 @@ | |
| 9280 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 9281 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 9282 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 9283 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 9284 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 9285 | SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe*); |
| 9286 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 9287 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 9288 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 9289 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| 9290 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*); |
| @@ -9487,11 +9439,10 @@ | |
| 9487 | SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); |
| 9488 | #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0) |
| 9489 | SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); |
| 9490 | SQLITE_PRIVATE void sqlite3PagerRef(DbPage*); |
| 9491 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*); |
| 9492 | SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*); |
| 9493 | |
| 9494 | /* Operations on page references. */ |
| 9495 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*); |
| 9496 | SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*); |
| 9497 | SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int); |
| @@ -9502,11 +9453,11 @@ | |
| 9502 | /* Functions used to manage pager transactions and savepoints. */ |
| 9503 | SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*); |
| 9504 | SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int); |
| 9505 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int); |
| 9506 | SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*); |
| 9507 | SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster); |
| 9508 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*); |
| 9509 | SQLITE_PRIVATE int sqlite3PagerRollback(Pager*); |
| 9510 | SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n); |
| 9511 | SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint); |
| 9512 | SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager); |
| @@ -10374,11 +10325,11 @@ | |
| 10374 | */ |
| 10375 | #define SQLITE_QueryFlattener 0x0001 /* Query flattening */ |
| 10376 | #define SQLITE_ColumnCache 0x0002 /* Column cache */ |
| 10377 | #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ |
| 10378 | #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ |
| 10379 | /* not used 0x0010 // Was: SQLITE_IdxRealAsInt */ |
| 10380 | #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ |
| 10381 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10382 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10383 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10384 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| @@ -11006,11 +10957,10 @@ | |
| 11006 | u8 useSortingIdx; /* In direct mode, reference the sorting index rather |
| 11007 | ** than the source table */ |
| 11008 | int sortingIdx; /* Cursor number of the sorting index */ |
| 11009 | int sortingIdxPTab; /* Cursor number of pseudo-table */ |
| 11010 | int nSortingColumn; /* Number of columns in the sorting index */ |
| 11011 | int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */ |
| 11012 | ExprList *pGroupBy; /* The group by clause */ |
| 11013 | struct AggInfo_col { /* For each column used in source tables */ |
| 11014 | Table *pTab; /* Source table */ |
| 11015 | int iTable; /* Cursor number of the source table */ |
| 11016 | int iColumn; /* Column number within the source table */ |
| @@ -11608,13 +11558,10 @@ | |
| 11608 | int nErr; /* Number of errors seen */ |
| 11609 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 11610 | int nMem; /* Number of memory cells used so far */ |
| 11611 | int nSet; /* Number of sets used so far */ |
| 11612 | int nOnce; /* Number of OP_Once instructions so far */ |
| 11613 | int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ |
| 11614 | int nLabel; /* Number of labels used */ |
| 11615 | int *aLabel; /* Space to hold the labels */ |
| 11616 | int ckBase; /* Base register of data during check constraints */ |
| 11617 | int iPartIdxTab; /* Table corresponding to a partial index */ |
| 11618 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 11619 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 11620 | struct yColCache { |
| @@ -12087,24 +12034,14 @@ | |
| 12087 | SQLITE_PRIVATE int sqlite3IsNaN(double); |
| 12088 | #else |
| 12089 | # define sqlite3IsNaN(X) 0 |
| 12090 | #endif |
| 12091 | |
| 12092 | /* |
| 12093 | ** An instance of the following structure holds information about SQL |
| 12094 | ** functions arguments that are the parameters to the printf() function. |
| 12095 | */ |
| 12096 | struct PrintfArguments { |
| 12097 | int nArg; /* Total number of arguments */ |
| 12098 | int nUsed; /* Number of arguments used so far */ |
| 12099 | sqlite3_value **apArg; /* The argument values */ |
| 12100 | }; |
| 12101 | |
| 12102 | #define SQLITE_PRINTF_INTERNAL 0x01 |
| 12103 | #define SQLITE_PRINTF_SQLFUNC 0x02 |
| 12104 | SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, u32, const char*, va_list); |
| 12105 | SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, u32, const char*, ...); |
| 12106 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 12107 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 12108 | SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); |
| 12109 | #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
| 12110 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| @@ -12290,10 +12227,11 @@ | |
| 12290 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12291 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12292 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12293 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12294 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12295 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12296 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12297 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12298 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12299 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -12458,11 +12396,12 @@ | |
| 12458 | SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...); |
| 12459 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 12460 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 12461 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 12462 | |
| 12463 | #if defined(SQLITE_TEST) |
| 12464 | SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 12465 | #endif |
| 12466 | |
| 12467 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 12468 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| @@ -12488,11 +12427,10 @@ | |
| 12488 | |
| 12489 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 12490 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 12491 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 12492 | void(*)(void*)); |
| 12493 | SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value*); |
| 12494 | SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*); |
| 12495 | SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *); |
| 12496 | SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); |
| 12497 | SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
| 12498 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| @@ -12554,11 +12492,10 @@ | |
| 12554 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 12555 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 12556 | |
| 12557 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); |
| 12558 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 12559 | SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*); |
| 12560 | SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int); |
| 12561 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 12562 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| 12563 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 12564 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| @@ -13781,13 +13718,16 @@ | |
| 13781 | Op *aOp; /* Space to hold the virtual machine's program */ |
| 13782 | Mem *aMem; /* The memory locations */ |
| 13783 | Mem **apArg; /* Arguments to currently executing user function */ |
| 13784 | Mem *aColName; /* Column names to return */ |
| 13785 | Mem *pResultSet; /* Pointer to an array of results */ |
| 13786 | Parse *pParse; /* Parsing context used to create this Vdbe */ |
| 13787 | int nMem; /* Number of memory locations currently allocated */ |
| 13788 | int nOp; /* Number of instructions in the program */ |
| 13789 | int nCursor; /* Number of slots in apCsr[] */ |
| 13790 | u32 magic; /* Magic number for sanity checking */ |
| 13791 | char *zErrMsg; /* Error message written here */ |
| 13792 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 13793 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| @@ -13796,11 +13736,10 @@ | |
| 13796 | ynVar nVar; /* Number of entries in aVar[] */ |
| 13797 | ynVar nzVar; /* Number of entries in azVar[] */ |
| 13798 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 13799 | int pc; /* The program counter */ |
| 13800 | int rc; /* Value to return */ |
| 13801 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 13802 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 13803 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 13804 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 13805 | bft inVtabMethod:2; /* See comments above */ |
| 13806 | bft changeCntOn:1; /* True to update the change-counter */ |
| @@ -13856,11 +13795,11 @@ | |
| 13856 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 13857 | SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*); |
| 13858 | #endif |
| 13859 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 13860 | SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int); |
| 13861 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 13862 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| 13863 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); |
| 13864 | |
| 13865 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 13866 | SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*); |
| @@ -15446,25 +15385,11 @@ | |
| 15446 | ** really care if the VFS receives and understands the information since it |
| 15447 | ** is only a hint and can be safely ignored. The sqlite3OsFileControlHint() |
| 15448 | ** routine has no return value since the return value would be meaningless. |
| 15449 | */ |
| 15450 | SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ |
| 15451 | #ifdef SQLITE_TEST |
| 15452 | if( op!=SQLITE_FCNTL_COMMIT_PHASETWO ){ |
| 15453 | /* Faults are not injected into COMMIT_PHASETWO because, assuming SQLite |
| 15454 | ** is using a regular VFS, it is called after the corresponding |
| 15455 | ** transaction has been committed. Injecting a fault at this point |
| 15456 | ** confuses the test scripts - the COMMIT comand returns SQLITE_NOMEM |
| 15457 | ** but the transaction is committed anyway. |
| 15458 | ** |
| 15459 | ** The core must call OsFileControl() though, not OsFileControlHint(), |
| 15460 | ** as if a custom VFS (e.g. zipvfs) returns an error here, it probably |
| 15461 | ** means the commit really has failed and an error should be returned |
| 15462 | ** to the user. */ |
| 15463 | DO_OS_MALLOC_TEST(id); |
| 15464 | } |
| 15465 | #endif |
| 15466 | return id->pMethods->xFileControl(id, op, pArg); |
| 15467 | } |
| 15468 | SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){ |
| 15469 | (void)id->pMethods->xFileControl(id, op, pArg); |
| 15470 | } |
| @@ -19455,11 +19380,11 @@ | |
| 19455 | /* |
| 19456 | ** TRUE if p is a lookaside memory allocation from db |
| 19457 | */ |
| 19458 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 19459 | static int isLookaside(sqlite3 *db, void *p){ |
| 19460 | return p>=db->lookaside.pStart && p<db->lookaside.pEnd; |
| 19461 | } |
| 19462 | #else |
| 19463 | #define isLookaside(A,B) 0 |
| 19464 | #endif |
| 19465 | |
| @@ -19471,13 +19396,12 @@ | |
| 19471 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 19472 | assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); |
| 19473 | return sqlite3GlobalConfig.m.xSize(p); |
| 19474 | } |
| 19475 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ |
| 19476 | assert( db!=0 ); |
| 19477 | assert( sqlite3_mutex_held(db->mutex) ); |
| 19478 | if( isLookaside(db, p) ){ |
| 19479 | return db->lookaside.sz; |
| 19480 | }else{ |
| 19481 | assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 19482 | assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) ); |
| 19483 | assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| @@ -19955,35 +19879,10 @@ | |
| 19955 | } |
| 19956 | if( N>0 ){ |
| 19957 | sqlite3StrAccumAppend(pAccum, zSpaces, N); |
| 19958 | } |
| 19959 | } |
| 19960 | |
| 19961 | /* |
| 19962 | ** Set the StrAccum object to an error mode. |
| 19963 | */ |
| 19964 | static void setStrAccumError(StrAccum *p, u8 eError){ |
| 19965 | p->accError = eError; |
| 19966 | p->nAlloc = 0; |
| 19967 | } |
| 19968 | |
| 19969 | /* |
| 19970 | ** Extra argument values from a PrintfArguments object |
| 19971 | */ |
| 19972 | static sqlite3_int64 getIntArg(PrintfArguments *p){ |
| 19973 | if( p->nArg<=p->nUsed ) return 0; |
| 19974 | return sqlite3_value_int64(p->apArg[p->nUsed++]); |
| 19975 | } |
| 19976 | static double getDoubleArg(PrintfArguments *p){ |
| 19977 | if( p->nArg<=p->nUsed ) return 0.0; |
| 19978 | return sqlite3_value_double(p->apArg[p->nUsed++]); |
| 19979 | } |
| 19980 | static char *getTextArg(PrintfArguments *p){ |
| 19981 | if( p->nArg<=p->nUsed ) return 0; |
| 19982 | return (char*)sqlite3_value_text(p->apArg[p->nUsed++]); |
| 19983 | } |
| 19984 | |
| 19985 | |
| 19986 | /* |
| 19987 | ** On machines with a small stack size, you can redefine the |
| 19988 | ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. |
| 19989 | */ |
| @@ -19994,14 +19893,14 @@ | |
| 19994 | |
| 19995 | /* |
| 19996 | ** Render a string given by "fmt" into the StrAccum object. |
| 19997 | */ |
| 19998 | SQLITE_PRIVATE void sqlite3VXPrintf( |
| 19999 | StrAccum *pAccum, /* Accumulate results here */ |
| 20000 | u32 bFlags, /* SQLITE_PRINTF_* flags */ |
| 20001 | const char *fmt, /* Format string */ |
| 20002 | va_list ap /* arguments */ |
| 20003 | ){ |
| 20004 | int c; /* Next character in the format string */ |
| 20005 | char *bufpt; /* Pointer to the conversion buffer */ |
| 20006 | int precision; /* Precision of the current field */ |
| 20007 | int length; /* Length of the field */ |
| @@ -20015,12 +19914,10 @@ | |
| 20015 | etByte flag_zeropad; /* True if field width constant starts with zero */ |
| 20016 | etByte flag_long; /* True if "l" flag is present */ |
| 20017 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 20018 | etByte done; /* Loop termination flag */ |
| 20019 | etByte xtype = 0; /* Conversion paradigm */ |
| 20020 | u8 bArgList; /* True for SQLITE_PRINTF_SQLFUNC */ |
| 20021 | u8 useIntern; /* Ok to use internal conversions (ex: %T) */ |
| 20022 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 20023 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 20024 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| 20025 | const et_info *infop; /* Pointer to the appropriate info structure */ |
| 20026 | char *zOut; /* Rendering buffer */ |
| @@ -20031,22 +19928,13 @@ | |
| 20031 | int nsd; /* Number of significant digits returned */ |
| 20032 | double rounder; /* Used for rounding floating point values */ |
| 20033 | etByte flag_dp; /* True if decimal point should be shown */ |
| 20034 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 20035 | #endif |
| 20036 | PrintfArguments *pArgList = 0; /* Arguments for SQLITE_PRINTF_SQLFUNC */ |
| 20037 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 20038 | |
| 20039 | bufpt = 0; |
| 20040 | if( bFlags ){ |
| 20041 | if( (bArgList = (bFlags & SQLITE_PRINTF_SQLFUNC))!=0 ){ |
| 20042 | pArgList = va_arg(ap, PrintfArguments*); |
| 20043 | } |
| 20044 | useIntern = bFlags & SQLITE_PRINTF_INTERNAL; |
| 20045 | }else{ |
| 20046 | bArgList = useIntern = 0; |
| 20047 | } |
| 20048 | for(; (c=(*fmt))!=0; ++fmt){ |
| 20049 | if( c!='%' ){ |
| 20050 | int amt; |
| 20051 | bufpt = (char *)fmt; |
| 20052 | amt = 1; |
| @@ -20074,15 +19962,11 @@ | |
| 20074 | } |
| 20075 | }while( !done && (c=(*++fmt))!=0 ); |
| 20076 | /* Get the field width */ |
| 20077 | width = 0; |
| 20078 | if( c=='*' ){ |
| 20079 | if( bArgList ){ |
| 20080 | width = (int)getIntArg(pArgList); |
| 20081 | }else{ |
| 20082 | width = va_arg(ap,int); |
| 20083 | } |
| 20084 | if( width<0 ){ |
| 20085 | flag_leftjustify = 1; |
| 20086 | width = -width; |
| 20087 | } |
| 20088 | c = *++fmt; |
| @@ -20095,15 +19979,11 @@ | |
| 20095 | /* Get the precision */ |
| 20096 | if( c=='.' ){ |
| 20097 | precision = 0; |
| 20098 | c = *++fmt; |
| 20099 | if( c=='*' ){ |
| 20100 | if( bArgList ){ |
| 20101 | precision = (int)getIntArg(pArgList); |
| 20102 | }else{ |
| 20103 | precision = va_arg(ap,int); |
| 20104 | } |
| 20105 | if( precision<0 ) precision = -precision; |
| 20106 | c = *++fmt; |
| 20107 | }else{ |
| 20108 | while( c>='0' && c<='9' ){ |
| 20109 | precision = precision*10 + c - '0'; |
| @@ -20130,11 +20010,11 @@ | |
| 20130 | infop = &fmtinfo[0]; |
| 20131 | xtype = etINVALID; |
| 20132 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| 20133 | if( c==fmtinfo[idx].fmttype ){ |
| 20134 | infop = &fmtinfo[idx]; |
| 20135 | if( useIntern || (infop->flags & FLAG_INTERN)==0 ){ |
| 20136 | xtype = infop->type; |
| 20137 | }else{ |
| 20138 | return; |
| 20139 | } |
| 20140 | break; |
| @@ -20170,13 +20050,11 @@ | |
| 20170 | /* Fall through into the next case */ |
| 20171 | case etORDINAL: |
| 20172 | case etRADIX: |
| 20173 | if( infop->flags & FLAG_SIGNED ){ |
| 20174 | i64 v; |
| 20175 | if( bArgList ){ |
| 20176 | v = getIntArg(pArgList); |
| 20177 | }else if( flag_longlong ){ |
| 20178 | v = va_arg(ap,i64); |
| 20179 | }else if( flag_long ){ |
| 20180 | v = va_arg(ap,long int); |
| 20181 | }else{ |
| 20182 | v = va_arg(ap,int); |
| @@ -20193,13 +20071,11 @@ | |
| 20193 | if( flag_plussign ) prefix = '+'; |
| 20194 | else if( flag_blanksign ) prefix = ' '; |
| 20195 | else prefix = 0; |
| 20196 | } |
| 20197 | }else{ |
| 20198 | if( bArgList ){ |
| 20199 | longvalue = (u64)getIntArg(pArgList); |
| 20200 | }else if( flag_longlong ){ |
| 20201 | longvalue = va_arg(ap,u64); |
| 20202 | }else if( flag_long ){ |
| 20203 | longvalue = va_arg(ap,unsigned long int); |
| 20204 | }else{ |
| 20205 | longvalue = va_arg(ap,unsigned int); |
| @@ -20215,11 +20091,11 @@ | |
| 20215 | zOut = buf; |
| 20216 | }else{ |
| 20217 | nOut = precision + 10; |
| 20218 | zOut = zExtra = sqlite3Malloc( nOut ); |
| 20219 | if( zOut==0 ){ |
| 20220 | setStrAccumError(pAccum, STRACCUM_NOMEM); |
| 20221 | return; |
| 20222 | } |
| 20223 | } |
| 20224 | bufpt = &zOut[nOut-1]; |
| 20225 | if( xtype==etORDINAL ){ |
| @@ -20255,15 +20131,11 @@ | |
| 20255 | length = (int)(&zOut[nOut-1]-bufpt); |
| 20256 | break; |
| 20257 | case etFLOAT: |
| 20258 | case etEXP: |
| 20259 | case etGENERIC: |
| 20260 | if( bArgList ){ |
| 20261 | realvalue = getDoubleArg(pArgList); |
| 20262 | }else{ |
| 20263 | realvalue = va_arg(ap,double); |
| 20264 | } |
| 20265 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 20266 | length = 0; |
| 20267 | #else |
| 20268 | if( precision<0 ) precision = 6; /* Set default precision */ |
| 20269 | if( realvalue<0.0 ){ |
| @@ -20331,11 +20203,11 @@ | |
| 20331 | e2 = exp; |
| 20332 | } |
| 20333 | if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ |
| 20334 | bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); |
| 20335 | if( bufpt==0 ){ |
| 20336 | setStrAccumError(pAccum, STRACCUM_NOMEM); |
| 20337 | return; |
| 20338 | } |
| 20339 | } |
| 20340 | zOut = bufpt; |
| 20341 | nsd = 16 + flag_altform2*10; |
| @@ -20414,27 +20286,20 @@ | |
| 20414 | length = width; |
| 20415 | } |
| 20416 | #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */ |
| 20417 | break; |
| 20418 | case etSIZE: |
| 20419 | if( !bArgList ){ |
| 20420 | *(va_arg(ap,int*)) = pAccum->nChar; |
| 20421 | } |
| 20422 | length = width = 0; |
| 20423 | break; |
| 20424 | case etPERCENT: |
| 20425 | buf[0] = '%'; |
| 20426 | bufpt = buf; |
| 20427 | length = 1; |
| 20428 | break; |
| 20429 | case etCHARX: |
| 20430 | if( bArgList ){ |
| 20431 | bufpt = getTextArg(pArgList); |
| 20432 | c = bufpt ? bufpt[0] : 0; |
| 20433 | }else{ |
| 20434 | c = va_arg(ap,int); |
| 20435 | } |
| 20436 | buf[0] = (char)c; |
| 20437 | if( precision>=0 ){ |
| 20438 | for(idx=1; idx<precision; idx++) buf[idx] = (char)c; |
| 20439 | length = precision; |
| 20440 | }else{ |
| @@ -20442,18 +20307,14 @@ | |
| 20442 | } |
| 20443 | bufpt = buf; |
| 20444 | break; |
| 20445 | case etSTRING: |
| 20446 | case etDYNSTRING: |
| 20447 | if( bArgList ){ |
| 20448 | bufpt = getTextArg(pArgList); |
| 20449 | }else{ |
| 20450 | bufpt = va_arg(ap,char*); |
| 20451 | } |
| 20452 | if( bufpt==0 ){ |
| 20453 | bufpt = ""; |
| 20454 | }else if( xtype==etDYNSTRING && !bArgList ){ |
| 20455 | zExtra = bufpt; |
| 20456 | } |
| 20457 | if( precision>=0 ){ |
| 20458 | for(length=0; length<precision && bufpt[length]; length++){} |
| 20459 | }else{ |
| @@ -20465,17 +20326,11 @@ | |
| 20465 | case etSQLESCAPE3: { |
| 20466 | int i, j, k, n, isnull; |
| 20467 | int needQuote; |
| 20468 | char ch; |
| 20469 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */ |
| 20470 | char *escarg; |
| 20471 | |
| 20472 | if( bArgList ){ |
| 20473 | escarg = getTextArg(pArgList); |
| 20474 | }else{ |
| 20475 | escarg = va_arg(ap,char*); |
| 20476 | } |
| 20477 | isnull = escarg==0; |
| 20478 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 20479 | k = precision; |
| 20480 | for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ |
| 20481 | if( ch==q ) n++; |
| @@ -20483,11 +20338,11 @@ | |
| 20483 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 20484 | n += i + 1 + needQuote*2; |
| 20485 | if( n>etBUFSIZE ){ |
| 20486 | bufpt = zExtra = sqlite3Malloc( n ); |
| 20487 | if( bufpt==0 ){ |
| 20488 | setStrAccumError(pAccum, STRACCUM_NOMEM); |
| 20489 | return; |
| 20490 | } |
| 20491 | }else{ |
| 20492 | bufpt = buf; |
| 20493 | } |
| @@ -20506,28 +20361,26 @@ | |
| 20506 | ** if( precision>=0 && precision<length ) length = precision; */ |
| 20507 | break; |
| 20508 | } |
| 20509 | case etTOKEN: { |
| 20510 | Token *pToken = va_arg(ap, Token*); |
| 20511 | assert( bArgList==0 ); |
| 20512 | if( pToken && pToken->n ){ |
| 20513 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
| 20514 | } |
| 20515 | length = width = 0; |
| 20516 | break; |
| 20517 | } |
| 20518 | case etSRCLIST: { |
| 20519 | SrcList *pSrc = va_arg(ap, SrcList*); |
| 20520 | int k = va_arg(ap, int); |
| 20521 | struct SrcList_item *pItem = &pSrc->a[k]; |
| 20522 | assert( bArgList==0 ); |
| 20523 | assert( k>=0 && k<pSrc->nSrc ); |
| 20524 | if( pItem->zDatabase ){ |
| 20525 | sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase); |
| 20526 | sqlite3StrAccumAppend(pAccum, ".", 1); |
| 20527 | } |
| 20528 | sqlite3StrAccumAppendAll(pAccum, pItem->zName); |
| 20529 | length = width = 0; |
| 20530 | break; |
| 20531 | } |
| 20532 | default: { |
| 20533 | assert( xtype==etINVALID ); |
| @@ -20554,42 +20407,44 @@ | |
| 20554 | nspace = width-length; |
| 20555 | if( nspace>0 ){ |
| 20556 | sqlite3AppendSpace(pAccum, nspace); |
| 20557 | } |
| 20558 | } |
| 20559 | if( zExtra ) sqlite3_free(zExtra); |
| 20560 | }/* End for loop over the format string */ |
| 20561 | } /* End of function */ |
| 20562 | |
| 20563 | /* |
| 20564 | ** Append N bytes of text from z to the StrAccum object. |
| 20565 | */ |
| 20566 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 20567 | assert( z!=0 ); |
| 20568 | assert( p->zText!=0 || p->nChar==0 || p->accError ); |
| 20569 | assert( N>=0 ); |
| 20570 | assert( p->accError==0 || p->nAlloc==0 ); |
| 20571 | if( p->nChar+N >= p->nAlloc ){ |
| 20572 | char *zNew; |
| 20573 | if( p->accError ){ |
| 20574 | testcase(p->accError==STRACCUM_TOOBIG); |
| 20575 | testcase(p->accError==STRACCUM_NOMEM); |
| 20576 | return; |
| 20577 | } |
| 20578 | if( !p->useMalloc ){ |
| 20579 | N = p->nAlloc - p->nChar - 1; |
| 20580 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 20581 | if( N<=0 ){ |
| 20582 | return; |
| 20583 | } |
| 20584 | }else{ |
| 20585 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 20586 | i64 szNew = p->nChar; |
| 20587 | szNew += N + 1; |
| 20588 | if( szNew > p->mxAlloc ){ |
| 20589 | sqlite3StrAccumReset(p); |
| 20590 | setStrAccumError(p, STRACCUM_TOOBIG); |
| 20591 | return; |
| 20592 | }else{ |
| 20593 | p->nAlloc = (int)szNew; |
| 20594 | } |
| 20595 | if( p->useMalloc==1 ){ |
| @@ -20599,28 +20454,20 @@ | |
| 20599 | } |
| 20600 | if( zNew ){ |
| 20601 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 20602 | p->zText = zNew; |
| 20603 | }else{ |
| 20604 | sqlite3StrAccumReset(p); |
| 20605 | setStrAccumError(p, STRACCUM_NOMEM); |
| 20606 | return; |
| 20607 | } |
| 20608 | } |
| 20609 | } |
| 20610 | assert( p->zText ); |
| 20611 | memcpy(&p->zText[p->nChar], z, N); |
| 20612 | p->nChar += N; |
| 20613 | } |
| 20614 | |
| 20615 | /* |
| 20616 | ** Append the complete text of zero-terminated string z[] to the p string. |
| 20617 | */ |
| 20618 | SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){ |
| 20619 | sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z)); |
| 20620 | } |
| 20621 | |
| 20622 | |
| 20623 | /* |
| 20624 | ** Finish off a string by making sure it is zero-terminated. |
| 20625 | ** Return a pointer to the resulting string. Return a NULL |
| 20626 | ** pointer if any kind of error was encountered. |
| @@ -20635,11 +20482,11 @@ | |
| 20635 | p->zText = sqlite3_malloc(p->nChar+1); |
| 20636 | } |
| 20637 | if( p->zText ){ |
| 20638 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 20639 | }else{ |
| 20640 | setStrAccumError(p, STRACCUM_NOMEM); |
| 20641 | } |
| 20642 | } |
| 20643 | } |
| 20644 | return p->zText; |
| 20645 | } |
| @@ -20681,11 +20528,11 @@ | |
| 20681 | StrAccum acc; |
| 20682 | assert( db!=0 ); |
| 20683 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), |
| 20684 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 20685 | acc.db = db; |
| 20686 | sqlite3VXPrintf(&acc, SQLITE_PRINTF_INTERNAL, zFormat, ap); |
| 20687 | z = sqlite3StrAccumFinish(&acc); |
| 20688 | if( acc.accError==STRACCUM_NOMEM ){ |
| 20689 | db->mallocFailed = 1; |
| 20690 | } |
| 20691 | return z; |
| @@ -20837,19 +20684,21 @@ | |
| 20837 | fprintf(stdout,"%s", zBuf); |
| 20838 | fflush(stdout); |
| 20839 | } |
| 20840 | #endif |
| 20841 | |
| 20842 | /* |
| 20843 | ** variable-argument wrapper around sqlite3VXPrintf(). |
| 20844 | */ |
| 20845 | SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, u32 bFlags, const char *zFormat, ...){ |
| 20846 | va_list ap; |
| 20847 | va_start(ap,zFormat); |
| 20848 | sqlite3VXPrintf(p, bFlags, zFormat, ap); |
| 20849 | va_end(ap); |
| 20850 | } |
| 20851 | |
| 20852 | /************** End of printf.c **********************************************/ |
| 20853 | /************** Begin file random.c ******************************************/ |
| 20854 | /* |
| 20855 | ** 2001 September 15 |
| @@ -20902,16 +20751,10 @@ | |
| 20902 | #if SQLITE_THREADSAFE |
| 20903 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20904 | sqlite3_mutex_enter(mutex); |
| 20905 | #endif |
| 20906 | |
| 20907 | if( N<=0 ){ |
| 20908 | wsdPrng.isInit = 0; |
| 20909 | sqlite3_mutex_leave(mutex); |
| 20910 | return; |
| 20911 | } |
| 20912 | |
| 20913 | /* Initialize the state of the random number generator once, |
| 20914 | ** the first time this routine is called. The seed value does |
| 20915 | ** not need to contain a lot of randomness since we are not |
| 20916 | ** trying to do secure encryption or anything like that... |
| 20917 | ** |
| @@ -20935,20 +20778,19 @@ | |
| 20935 | wsdPrng.s[i] = t; |
| 20936 | } |
| 20937 | wsdPrng.isInit = 1; |
| 20938 | } |
| 20939 | |
| 20940 | assert( N>0 ); |
| 20941 | do{ |
| 20942 | wsdPrng.i++; |
| 20943 | t = wsdPrng.s[wsdPrng.i]; |
| 20944 | wsdPrng.j += t; |
| 20945 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20946 | wsdPrng.s[wsdPrng.j] = t; |
| 20947 | t += wsdPrng.s[wsdPrng.i]; |
| 20948 | *(zBuf++) = wsdPrng.s[t]; |
| 20949 | }while( --N ); |
| 20950 | sqlite3_mutex_leave(mutex); |
| 20951 | } |
| 20952 | |
| 20953 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20954 | /* |
| @@ -20973,10 +20815,13 @@ | |
| 20973 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20974 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20975 | sizeof(sqlite3Prng) |
| 20976 | ); |
| 20977 | } |
| 20978 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20979 | |
| 20980 | /************** End of random.c **********************************************/ |
| 20981 | /************** Begin file utf.c *********************************************/ |
| 20982 | /* |
| @@ -21624,21 +21469,22 @@ | |
| 21624 | ** To clear the most recent error for sqlite handle "db", sqlite3Error |
| 21625 | ** should be called with err_code set to SQLITE_OK and zFormat set |
| 21626 | ** to NULL. |
| 21627 | */ |
| 21628 | SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){ |
| 21629 | assert( db!=0 ); |
| 21630 | db->errCode = err_code; |
| 21631 | if( zFormat && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){ |
| 21632 | char *z; |
| 21633 | va_list ap; |
| 21634 | va_start(ap, zFormat); |
| 21635 | z = sqlite3VMPrintf(db, zFormat, ap); |
| 21636 | va_end(ap); |
| 21637 | sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC); |
| 21638 | }else if( db->pErr ){ |
| 21639 | sqlite3ValueSetNull(db->pErr); |
| 21640 | } |
| 21641 | } |
| 21642 | |
| 21643 | /* |
| 21644 | ** Add an error message to pParse->zErrMsg and increment pParse->nErr. |
| @@ -23119,11 +22965,11 @@ | |
| 23119 | /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 23120 | /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 23121 | /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 23122 | /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 23123 | /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 23124 | /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"), |
| 23125 | /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 23126 | /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 23127 | /* 33 */ "CollSeq" OpHelp(""), |
| 23128 | /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 23129 | /* 35 */ "MustBeInt" OpHelp(""), |
| @@ -23510,16 +23356,10 @@ | |
| 23510 | */ |
| 23511 | char aPadding[32]; |
| 23512 | #endif |
| 23513 | }; |
| 23514 | |
| 23515 | /* This variable holds the process id (pid) from when the xRandomness() |
| 23516 | ** method was called. If xOpen() is called from a different process id, |
| 23517 | ** indicating that a fork() has occurred, the PRNG will be reset. |
| 23518 | */ |
| 23519 | static int randomnessPid = 0; |
| 23520 | |
| 23521 | /* |
| 23522 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23523 | */ |
| 23524 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| 23525 | #define UNIXFILE_RDONLY 0x02 /* Connection is read only */ |
| @@ -24779,19 +24619,10 @@ | |
| 24779 | } |
| 24780 | *ppInode = pInode; |
| 24781 | return SQLITE_OK; |
| 24782 | } |
| 24783 | |
| 24784 | /* |
| 24785 | ** Return TRUE if pFile has been renamed or unlinked since it was first opened. |
| 24786 | */ |
| 24787 | static int fileHasMoved(unixFile *pFile){ |
| 24788 | struct stat buf; |
| 24789 | return pFile->pInode!=0 && |
| 24790 | (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); |
| 24791 | } |
| 24792 | |
| 24793 | |
| 24794 | /* |
| 24795 | ** Check a unixFile that is a database. Verify the following: |
| 24796 | ** |
| 24797 | ** (1) There is exactly one hard link on the file |
| @@ -24822,11 +24653,14 @@ | |
| 24822 | if( buf.st_nlink>1 ){ |
| 24823 | sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); |
| 24824 | pFile->ctrlFlags |= UNIXFILE_WARNED; |
| 24825 | return; |
| 24826 | } |
| 24827 | if( fileHasMoved(pFile) ){ |
| 24828 | sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); |
| 24829 | pFile->ctrlFlags |= UNIXFILE_WARNED; |
| 24830 | return; |
| 24831 | } |
| 24832 | } |
| @@ -27271,14 +27105,10 @@ | |
| 27271 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 27272 | *(char**)pArg = zTFile; |
| 27273 | } |
| 27274 | return SQLITE_OK; |
| 27275 | } |
| 27276 | case SQLITE_FCNTL_HAS_MOVED: { |
| 27277 | *(int*)pArg = fileHasMoved(pFile); |
| 27278 | return SQLITE_OK; |
| 27279 | } |
| 27280 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 27281 | case SQLITE_FCNTL_MMAP_SIZE: { |
| 27282 | i64 newLimit = *(i64*)pArg; |
| 27283 | int rc = SQLITE_OK; |
| 27284 | if( newLimit>sqlite3GlobalConfig.mxMmap ){ |
| @@ -29115,20 +28945,10 @@ | |
| 29115 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 29116 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 29117 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 29118 | ); |
| 29119 | |
| 29120 | /* Detect a pid change and reset the PRNG. There is a race condition |
| 29121 | ** here such that two or more threads all trying to open databases at |
| 29122 | ** the same instant might all reset the PRNG. But multiple resets |
| 29123 | ** are harmless. |
| 29124 | */ |
| 29125 | if( randomnessPid!=getpid() ){ |
| 29126 | randomnessPid = getpid(); |
| 29127 | sqlite3_randomness(0,0); |
| 29128 | } |
| 29129 | |
| 29130 | memset(p, 0, sizeof(unixFile)); |
| 29131 | |
| 29132 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 29133 | UnixUnusedFd *pUnused; |
| 29134 | pUnused = findReusableFd(zName, flags); |
| @@ -29512,22 +29332,22 @@ | |
| 29512 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29513 | ** that we always use the same random number sequence. This makes the |
| 29514 | ** tests repeatable. |
| 29515 | */ |
| 29516 | memset(zBuf, 0, nBuf); |
| 29517 | randomnessPid = getpid(); |
| 29518 | #if !defined(SQLITE_TEST) |
| 29519 | { |
| 29520 | int fd, got; |
| 29521 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29522 | if( fd<0 ){ |
| 29523 | time_t t; |
| 29524 | time(&t); |
| 29525 | memcpy(zBuf, &t, sizeof(t)); |
| 29526 | memcpy(&zBuf[sizeof(t)], &randomnessPid, sizeof(randomnessPid)); |
| 29527 | assert( sizeof(t)+sizeof(randomnessPid)<=(size_t)nBuf ); |
| 29528 | nBuf = sizeof(t) + sizeof(randomnessPid); |
| 29529 | }else{ |
| 29530 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29531 | robust_close(0, fd, __LINE__); |
| 29532 | } |
| 29533 | } |
| @@ -34261,11 +34081,11 @@ | |
| 34261 | winModeBit(pFile, WINFILE_PSOW, (int*)pArg); |
| 34262 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 34263 | return SQLITE_OK; |
| 34264 | } |
| 34265 | case SQLITE_FCNTL_VFSNAME: { |
| 34266 | *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName); |
| 34267 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 34268 | return SQLITE_OK; |
| 34269 | } |
| 34270 | case SQLITE_FCNTL_WIN32_AV_RETRY: { |
| 34271 | int *a = (int*)pArg; |
| @@ -37703,11 +37523,10 @@ | |
| 37703 | ** in memory. |
| 37704 | */ |
| 37705 | struct PgHdr1 { |
| 37706 | sqlite3_pcache_page page; |
| 37707 | unsigned int iKey; /* Key value (page number) */ |
| 37708 | u8 isPinned; /* Page in use, not on the LRU list */ |
| 37709 | PgHdr1 *pNext; /* Next in hash table chain */ |
| 37710 | PCache1 *pCache; /* Cache that currently owns this page */ |
| 37711 | PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */ |
| 37712 | PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */ |
| 37713 | }; |
| @@ -38032,36 +37851,38 @@ | |
| 38032 | ** This function is used internally to remove the page pPage from the |
| 38033 | ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup |
| 38034 | ** LRU list, then this function is a no-op. |
| 38035 | ** |
| 38036 | ** The PGroup mutex must be held when this function is called. |
| 38037 | */ |
| 38038 | static void pcache1PinPage(PgHdr1 *pPage){ |
| 38039 | PCache1 *pCache; |
| 38040 | PGroup *pGroup; |
| 38041 | |
| 38042 | assert( pPage!=0 ); |
| 38043 | assert( pPage->isPinned==0 ); |
| 38044 | pCache = pPage->pCache; |
| 38045 | pGroup = pCache->pGroup; |
| 38046 | assert( pPage->pLruNext || pPage==pGroup->pLruTail ); |
| 38047 | assert( pPage->pLruPrev || pPage==pGroup->pLruHead ); |
| 38048 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 38049 | if( pPage->pLruPrev ){ |
| 38050 | pPage->pLruPrev->pLruNext = pPage->pLruNext; |
| 38051 | }else{ |
| 38052 | pGroup->pLruHead = pPage->pLruNext; |
| 38053 | } |
| 38054 | if( pPage->pLruNext ){ |
| 38055 | pPage->pLruNext->pLruPrev = pPage->pLruPrev; |
| 38056 | }else{ |
| 38057 | pGroup->pLruTail = pPage->pLruPrev; |
| 38058 | } |
| 38059 | pPage->pLruNext = 0; |
| 38060 | pPage->pLruPrev = 0; |
| 38061 | pPage->isPinned = 1; |
| 38062 | pCache->nRecyclable--; |
| 38063 | } |
| 38064 | |
| 38065 | |
| 38066 | /* |
| 38067 | ** Remove the page supplied as an argument from the hash table |
| @@ -38089,11 +37910,10 @@ | |
| 38089 | static void pcache1EnforceMaxPage(PGroup *pGroup){ |
| 38090 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 38091 | while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){ |
| 38092 | PgHdr1 *p = pGroup->pLruTail; |
| 38093 | assert( p->pCache->pGroup==pGroup ); |
| 38094 | assert( p->isPinned==0 ); |
| 38095 | pcache1PinPage(p); |
| 38096 | pcache1RemoveFromHash(p); |
| 38097 | pcache1FreePage(p); |
| 38098 | } |
| 38099 | } |
| @@ -38117,11 +37937,11 @@ | |
| 38117 | PgHdr1 *pPage; |
| 38118 | while( (pPage = *pp)!=0 ){ |
| 38119 | if( pPage->iKey>=iLimit ){ |
| 38120 | pCache->nPage--; |
| 38121 | *pp = pPage->pNext; |
| 38122 | if( !pPage->isPinned ) pcache1PinPage(pPage); |
| 38123 | pcache1FreePage(pPage); |
| 38124 | }else{ |
| 38125 | pp = &pPage->pNext; |
| 38126 | TESTONLY( nPage++; ) |
| 38127 | } |
| @@ -38340,15 +38160,12 @@ | |
| 38340 | unsigned int h = iKey % pCache->nHash; |
| 38341 | for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext); |
| 38342 | } |
| 38343 | |
| 38344 | /* Step 2: Abort if no existing page is found and createFlag is 0 */ |
| 38345 | if( pPage ){ |
| 38346 | if( !pPage->isPinned ) pcache1PinPage(pPage); |
| 38347 | goto fetch_out; |
| 38348 | } |
| 38349 | if( createFlag==0 ){ |
| 38350 | goto fetch_out; |
| 38351 | } |
| 38352 | |
| 38353 | /* The pGroup local variable will normally be initialized by the |
| 38354 | ** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined, |
| @@ -38385,11 +38202,10 @@ | |
| 38385 | || pGroup->nCurrentPage>=pGroup->nMaxPage |
| 38386 | || pcache1UnderMemoryPressure(pCache) |
| 38387 | )){ |
| 38388 | PCache1 *pOther; |
| 38389 | pPage = pGroup->pLruTail; |
| 38390 | assert( pPage->isPinned==0 ); |
| 38391 | pcache1RemoveFromHash(pPage); |
| 38392 | pcache1PinPage(pPage); |
| 38393 | pOther = pPage->pCache; |
| 38394 | |
| 38395 | /* We want to verify that szPage and szExtra are the same for pOther |
| @@ -38422,11 +38238,10 @@ | |
| 38422 | pPage->iKey = iKey; |
| 38423 | pPage->pNext = pCache->apHash[h]; |
| 38424 | pPage->pCache = pCache; |
| 38425 | pPage->pLruPrev = 0; |
| 38426 | pPage->pLruNext = 0; |
| 38427 | pPage->isPinned = 1; |
| 38428 | *(void **)pPage->page.pExtra = 0; |
| 38429 | pCache->apHash[h] = pPage; |
| 38430 | } |
| 38431 | |
| 38432 | fetch_out: |
| @@ -38458,11 +38273,10 @@ | |
| 38458 | /* It is an error to call this function if the page is already |
| 38459 | ** part of the PGroup LRU list. |
| 38460 | */ |
| 38461 | assert( pPage->pLruPrev==0 && pPage->pLruNext==0 ); |
| 38462 | assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage ); |
| 38463 | assert( pPage->isPinned==1 ); |
| 38464 | |
| 38465 | if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){ |
| 38466 | pcache1RemoveFromHash(pPage); |
| 38467 | pcache1FreePage(pPage); |
| 38468 | }else{ |
| @@ -38474,11 +38288,10 @@ | |
| 38474 | }else{ |
| 38475 | pGroup->pLruTail = pPage; |
| 38476 | pGroup->pLruHead = pPage; |
| 38477 | } |
| 38478 | pCache->nRecyclable++; |
| 38479 | pPage->isPinned = 0; |
| 38480 | } |
| 38481 | |
| 38482 | pcache1LeaveMutex(pCache->pGroup); |
| 38483 | } |
| 38484 | |
| @@ -38601,11 +38414,10 @@ | |
| 38601 | while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){ |
| 38602 | nFree += pcache1MemSize(p->page.pBuf); |
| 38603 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 38604 | nFree += sqlite3MemSize(p); |
| 38605 | #endif |
| 38606 | assert( p->isPinned==0 ); |
| 38607 | pcache1PinPage(p); |
| 38608 | pcache1RemoveFromHash(p); |
| 38609 | pcache1FreePage(p); |
| 38610 | } |
| 38611 | pcache1LeaveMutex(&pcache1.grp); |
| @@ -38626,11 +38438,10 @@ | |
| 38626 | int *pnRecyclable /* OUT: Total number of pages available for recycling */ |
| 38627 | ){ |
| 38628 | PgHdr1 *p; |
| 38629 | int nRecyclable = 0; |
| 38630 | for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){ |
| 38631 | assert( p->isPinned==0 ); |
| 38632 | nRecyclable++; |
| 38633 | } |
| 38634 | *pnCurrent = pcache1.grp.nCurrentPage; |
| 38635 | *pnMax = (int)pcache1.grp.nMaxPage; |
| 38636 | *pnMin = (int)pcache1.grp.nMinPage; |
| @@ -40313,26 +40124,29 @@ | |
| 40313 | ** PagerSavepoint.pInSavepoint. |
| 40314 | */ |
| 40315 | static int subjRequiresPage(PgHdr *pPg){ |
| 40316 | Pager *pPager = pPg->pPager; |
| 40317 | PagerSavepoint *p; |
| 40318 | Pgno pgno = pPg->pgno; |
| 40319 | int i; |
| 40320 | for(i=0; i<pPager->nSavepoint; i++){ |
| 40321 | p = &pPager->aSavepoint[i]; |
| 40322 | if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){ |
| 40323 | return 1; |
| 40324 | } |
| 40325 | } |
| 40326 | return 0; |
| 40327 | } |
| 40328 | |
| 40329 | /* |
| 40330 | ** Return true if the page is already in the journal file. |
| 40331 | */ |
| 40332 | static int pageInJournal(Pager *pPager, PgHdr *pPg){ |
| 40333 | return sqlite3BitvecTest(pPager->pInJournal, pPg->pgno); |
| 40334 | } |
| 40335 | |
| 40336 | /* |
| 40337 | ** Read a 32-bit integer from the given file descriptor. Store the integer |
| 40338 | ** that is read in *pRes. Return SQLITE_OK if everything worked, or an |
| @@ -40535,11 +40349,10 @@ | |
| 40535 | |
| 40536 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 40537 | || szJ<16 |
| 40538 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 40539 | || len>=nMaster |
| 40540 | || len==0 |
| 40541 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 40542 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 40543 | || memcmp(aMagic, aJournalMagic, 8) |
| 40544 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len)) |
| 40545 | ){ |
| @@ -41276,11 +41089,11 @@ | |
| 41276 | sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash); |
| 41277 | if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){ |
| 41278 | PgHdr *p = pager_lookup(pPager, 1); |
| 41279 | if( p ){ |
| 41280 | p->pageHash = 0; |
| 41281 | sqlite3PagerUnrefNotNull(p); |
| 41282 | } |
| 41283 | } |
| 41284 | #endif |
| 41285 | |
| 41286 | sqlite3BitvecDestroy(pPager->pInJournal); |
| @@ -41305,15 +41118,10 @@ | |
| 41305 | ** required size. */ |
| 41306 | assert( pPager->eLock==EXCLUSIVE_LOCK ); |
| 41307 | rc = pager_truncate(pPager, pPager->dbSize); |
| 41308 | } |
| 41309 | |
| 41310 | if( rc==SQLITE_OK && bCommit && isOpen(pPager->fd) ){ |
| 41311 | rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0); |
| 41312 | if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 41313 | } |
| 41314 | |
| 41315 | if( !pPager->exclusiveMode |
| 41316 | && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0)) |
| 41317 | ){ |
| 41318 | rc2 = pagerUnlockDb(pPager, SHARED_LOCK); |
| 41319 | pPager->changeCountDone = 0; |
| @@ -42123,11 +41931,11 @@ | |
| 42123 | testcase( rc!=SQLITE_OK ); |
| 42124 | } |
| 42125 | if( rc==SQLITE_OK |
| 42126 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 42127 | ){ |
| 42128 | rc = sqlite3PagerSync(pPager, 0); |
| 42129 | } |
| 42130 | if( rc==SQLITE_OK ){ |
| 42131 | rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0); |
| 42132 | testcase( rc!=SQLITE_OK ); |
| 42133 | } |
| @@ -42269,11 +42077,11 @@ | |
| 42269 | rc = readDbPage(pPg, iFrame); |
| 42270 | } |
| 42271 | if( rc==SQLITE_OK ){ |
| 42272 | pPager->xReiniter(pPg); |
| 42273 | } |
| 42274 | sqlite3PagerUnrefNotNull(pPg); |
| 42275 | } |
| 42276 | } |
| 42277 | |
| 42278 | /* Normally, if a transaction is rolled back, any backup processes are |
| 42279 | ** updated as data is copied out of the rollback journal and into the |
| @@ -43624,11 +43432,11 @@ | |
| 43624 | /* Open the sub-journal, if it has not already been opened */ |
| 43625 | assert( pPager->useJournal ); |
| 43626 | assert( isOpen(pPager->jfd) || pagerUseWal(pPager) ); |
| 43627 | assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 ); |
| 43628 | assert( pagerUseWal(pPager) |
| 43629 | || pageInJournal(pPager, pPg) |
| 43630 | || pPg->pgno>pPager->dbOrigSize |
| 43631 | ); |
| 43632 | rc = openSubJournal(pPager); |
| 43633 | |
| 43634 | /* If the sub-journal was opened successfully (or was already open), |
| @@ -44089,34 +43897,10 @@ | |
| 44089 | *ppPager = pPager; |
| 44090 | return SQLITE_OK; |
| 44091 | } |
| 44092 | |
| 44093 | |
| 44094 | /* Verify that the database file has not be deleted or renamed out from |
| 44095 | ** under the pager. Return SQLITE_OK if the database is still were it ought |
| 44096 | ** to be on disk. Return non-zero (SQLITE_READONLY_DBMOVED or some other error |
| 44097 | ** code from sqlite3OsAccess()) if the database has gone missing. |
| 44098 | */ |
| 44099 | static int databaseIsUnmoved(Pager *pPager){ |
| 44100 | int bHasMoved = 0; |
| 44101 | int rc; |
| 44102 | |
| 44103 | if( pPager->tempFile ) return SQLITE_OK; |
| 44104 | if( pPager->dbSize==0 ) return SQLITE_OK; |
| 44105 | assert( pPager->zFilename && pPager->zFilename[0] ); |
| 44106 | rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_HAS_MOVED, &bHasMoved); |
| 44107 | if( rc==SQLITE_NOTFOUND ){ |
| 44108 | /* If the HAS_MOVED file-control is unimplemented, assume that the file |
| 44109 | ** has not been moved. That is the historical behavior of SQLite: prior to |
| 44110 | ** version 3.8.3, it never checked */ |
| 44111 | rc = SQLITE_OK; |
| 44112 | }else if( rc==SQLITE_OK && bHasMoved ){ |
| 44113 | rc = SQLITE_READONLY_DBMOVED; |
| 44114 | } |
| 44115 | return rc; |
| 44116 | } |
| 44117 | |
| 44118 | |
| 44119 | /* |
| 44120 | ** This function is called after transitioning from PAGER_UNLOCK to |
| 44121 | ** PAGER_SHARED state. It tests if there is a hot journal present in |
| 44122 | ** the file-system for the given pager. A hot journal is one that |
| @@ -44584,11 +44368,11 @@ | |
| 44584 | if( bMmapOk && pagerUseWal(pPager) ){ |
| 44585 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame); |
| 44586 | if( rc!=SQLITE_OK ) goto pager_acquire_err; |
| 44587 | } |
| 44588 | |
| 44589 | if( bMmapOk && iFrame==0 ){ |
| 44590 | void *pData = 0; |
| 44591 | |
| 44592 | rc = sqlite3OsFetch(pPager->fd, |
| 44593 | (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData |
| 44594 | ); |
| @@ -44725,23 +44509,20 @@ | |
| 44725 | ** If the number of references to the page drop to zero, then the |
| 44726 | ** page is added to the LRU list. When all references to all pages |
| 44727 | ** are released, a rollback occurs and the lock on the database is |
| 44728 | ** removed. |
| 44729 | */ |
| 44730 | SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){ |
| 44731 | Pager *pPager; |
| 44732 | assert( pPg!=0 ); |
| 44733 | pPager = pPg->pPager; |
| 44734 | if( pPg->flags & PGHDR_MMAP ){ |
| 44735 | pagerReleaseMapPage(pPg); |
| 44736 | }else{ |
| 44737 | sqlite3PcacheRelease(pPg); |
| 44738 | } |
| 44739 | pagerUnlockIfUnused(pPager); |
| 44740 | } |
| 44741 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){ |
| 44742 | if( pPg ) sqlite3PagerUnrefNotNull(pPg); |
| 44743 | } |
| 44744 | |
| 44745 | /* |
| 44746 | ** This function is called at the start of every write transaction. |
| 44747 | ** There must already be a RESERVED or EXCLUSIVE lock on the database |
| @@ -44792,23 +44573,17 @@ | |
| 44792 | SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| |
| 44793 | (pPager->tempFile ? |
| 44794 | (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL): |
| 44795 | (SQLITE_OPEN_MAIN_JOURNAL) |
| 44796 | ); |
| 44797 | |
| 44798 | /* Verify that the database still has the same name as it did when |
| 44799 | ** it was originally opened. */ |
| 44800 | rc = databaseIsUnmoved(pPager); |
| 44801 | if( rc==SQLITE_OK ){ |
| 44802 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 44803 | rc = sqlite3JournalOpen( |
| 44804 | pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager) |
| 44805 | ); |
| 44806 | #else |
| 44807 | rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0); |
| 44808 | #endif |
| 44809 | } |
| 44810 | } |
| 44811 | assert( rc!=SQLITE_OK || isOpen(pPager->jfd) ); |
| 44812 | } |
| 44813 | |
| 44814 | |
| @@ -44925,13 +44700,13 @@ | |
| 44925 | ** one of the journals, the corresponding bit is set in the |
| 44926 | ** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs |
| 44927 | ** of any open savepoints as appropriate. |
| 44928 | */ |
| 44929 | static int pager_write(PgHdr *pPg){ |
| 44930 | Pager *pPager = pPg->pPager; |
| 44931 | int rc = SQLITE_OK; |
| 44932 | int inJournal; |
| 44933 | |
| 44934 | /* This routine is not called unless a write-transaction has already |
| 44935 | ** been started. The journal file may or may not be open at this point. |
| 44936 | ** It is never called in the ERROR state. |
| 44937 | */ |
| @@ -44938,12 +44713,18 @@ | |
| 44938 | assert( pPager->eState==PAGER_WRITER_LOCKED |
| 44939 | || pPager->eState==PAGER_WRITER_CACHEMOD |
| 44940 | || pPager->eState==PAGER_WRITER_DBMOD |
| 44941 | ); |
| 44942 | assert( assert_pager_state(pPager) ); |
| 44943 | assert( pPager->errCode==0 ); |
| 44944 | assert( pPager->readOnly==0 ); |
| 44945 | |
| 44946 | CHECK_PAGE(pPg); |
| 44947 | |
| 44948 | /* The journal file needs to be opened. Higher level routines have already |
| 44949 | ** obtained the necessary locks to begin the write-transaction, but the |
| @@ -44963,20 +44744,19 @@ | |
| 44963 | |
| 44964 | /* Mark the page as dirty. If the page has already been written |
| 44965 | ** to the journal then we can return right away. |
| 44966 | */ |
| 44967 | sqlite3PcacheMakeDirty(pPg); |
| 44968 | inJournal = pageInJournal(pPager, pPg); |
| 44969 | if( inJournal && (pPager->nSavepoint==0 || !subjRequiresPage(pPg)) ){ |
| 44970 | assert( !pagerUseWal(pPager) ); |
| 44971 | }else{ |
| 44972 | |
| 44973 | /* The transaction journal now exists and we have a RESERVED or an |
| 44974 | ** EXCLUSIVE lock on the main database file. Write the current page to |
| 44975 | ** the transaction journal if it is not there already. |
| 44976 | */ |
| 44977 | if( !inJournal && !pagerUseWal(pPager) ){ |
| 44978 | assert( pagerUseWal(pPager)==0 ); |
| 44979 | if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){ |
| 44980 | u32 cksum; |
| 44981 | char *pData2; |
| 44982 | i64 iOff = pPager->journalOff; |
| @@ -44985,11 +44765,11 @@ | |
| 44985 | ** contains the database locks. The following assert verifies |
| 44986 | ** that we do not. */ |
| 44987 | assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 44988 | |
| 44989 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 44990 | CODEC2(pPager, pPg->pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2); |
| 44991 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 44992 | |
| 44993 | /* Even if an IO or diskfull error occurs while journalling the |
| 44994 | ** page in the block above, set the need-sync flag for the page. |
| 44995 | ** Otherwise, when the transaction is rolled back, the logic in |
| @@ -45037,11 +44817,11 @@ | |
| 45037 | /* If the statement journal is open and the page is not in it, |
| 45038 | ** then write the current page to the statement journal. Note that |
| 45039 | ** the statement journal format differs from the standard journal format |
| 45040 | ** in that it omits the checksums and the header. |
| 45041 | */ |
| 45042 | if( pPager->nSavepoint>0 && subjRequiresPage(pPg) ){ |
| 45043 | rc = subjournalPage(pPg); |
| 45044 | } |
| 45045 | } |
| 45046 | |
| 45047 | /* Update the database size and return. |
| @@ -45069,23 +44849,23 @@ | |
| 45069 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){ |
| 45070 | int rc = SQLITE_OK; |
| 45071 | |
| 45072 | PgHdr *pPg = pDbPage; |
| 45073 | Pager *pPager = pPg->pPager; |
| 45074 | |
| 45075 | assert( (pPg->flags & PGHDR_MMAP)==0 ); |
| 45076 | assert( pPager->eState>=PAGER_WRITER_LOCKED ); |
| 45077 | assert( pPager->eState!=PAGER_ERROR ); |
| 45078 | assert( assert_pager_state(pPager) ); |
| 45079 | |
| 45080 | if( pPager->sectorSize > (u32)pPager->pageSize ){ |
| 45081 | Pgno nPageCount; /* Total number of pages in database file */ |
| 45082 | Pgno pg1; /* First page of the sector pPg is located on. */ |
| 45083 | int nPage = 0; /* Number of pages starting at pg1 to journal */ |
| 45084 | int ii; /* Loop counter */ |
| 45085 | int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */ |
| 45086 | Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); |
| 45087 | |
| 45088 | /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow |
| 45089 | ** a journal header to be written between the pages journaled by |
| 45090 | ** this function. |
| 45091 | */ |
| @@ -45120,18 +44900,18 @@ | |
| 45120 | if( rc==SQLITE_OK ){ |
| 45121 | rc = pager_write(pPage); |
| 45122 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 45123 | needSync = 1; |
| 45124 | } |
| 45125 | sqlite3PagerUnrefNotNull(pPage); |
| 45126 | } |
| 45127 | } |
| 45128 | }else if( (pPage = pager_lookup(pPager, pg))!=0 ){ |
| 45129 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 45130 | needSync = 1; |
| 45131 | } |
| 45132 | sqlite3PagerUnrefNotNull(pPage); |
| 45133 | } |
| 45134 | } |
| 45135 | |
| 45136 | /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages |
| 45137 | ** starting at pg1, then it needs to be set for all of them. Because |
| @@ -45143,11 +44923,11 @@ | |
| 45143 | assert( !MEMDB ); |
| 45144 | for(ii=0; ii<nPage; ii++){ |
| 45145 | PgHdr *pPage = pager_lookup(pPager, pg1+ii); |
| 45146 | if( pPage ){ |
| 45147 | pPage->flags |= PGHDR_NEED_SYNC; |
| 45148 | sqlite3PagerUnrefNotNull(pPage); |
| 45149 | } |
| 45150 | } |
| 45151 | } |
| 45152 | |
| 45153 | assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 ); |
| @@ -45296,21 +45076,21 @@ | |
| 45296 | ** or pages with the Pager.noSync flag set. |
| 45297 | ** |
| 45298 | ** If successful, or if called on a pager for which it is a no-op, this |
| 45299 | ** function returns SQLITE_OK. Otherwise, an IO error code is returned. |
| 45300 | */ |
| 45301 | SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){ |
| 45302 | int rc = SQLITE_OK; |
| 45303 | |
| 45304 | if( isOpen(pPager->fd) ){ |
| 45305 | void *pArg = (void*)zMaster; |
| 45306 | rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg); |
| 45307 | if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK; |
| 45308 | } |
| 45309 | if( rc==SQLITE_OK && !pPager->noSync ){ |
| 45310 | assert( !MEMDB ); |
| 45311 | rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); |
| 45312 | } |
| 45313 | return rc; |
| 45314 | } |
| 45315 | |
| 45316 | /* |
| @@ -45505,11 +45285,11 @@ | |
| 45505 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 45506 | } |
| 45507 | |
| 45508 | /* Finally, sync the database file. */ |
| 45509 | if( !noSync ){ |
| 45510 | rc = sqlite3PagerSync(pPager, zMaster); |
| 45511 | } |
| 45512 | IOTRACE(("DBSYNC %p\n", pPager)) |
| 45513 | } |
| 45514 | } |
| 45515 | |
| @@ -45634,13 +45414,11 @@ | |
| 45634 | rc = pager_playback(pPager, 0); |
| 45635 | } |
| 45636 | |
| 45637 | assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK ); |
| 45638 | assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT |
| 45639 | || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR |
| 45640 | || rc==SQLITE_CANTOPEN |
| 45641 | ); |
| 45642 | |
| 45643 | /* If an error occurs during a ROLLBACK, we can no longer trust the pager |
| 45644 | ** cache. So call pager_error() on the way out to make any error persistent. |
| 45645 | */ |
| 45646 | return pager_error(pPager, rc); |
| @@ -46039,11 +45817,11 @@ | |
| 46039 | ** can be written to. The caller has already promised not to write to it. |
| 46040 | */ |
| 46041 | if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){ |
| 46042 | needSyncPgno = pPg->pgno; |
| 46043 | assert( pPager->journalMode==PAGER_JOURNALMODE_OFF || |
| 46044 | pageInJournal(pPager, pPg) || pPg->pgno>pPager->dbOrigSize ); |
| 46045 | assert( pPg->flags&PGHDR_DIRTY ); |
| 46046 | } |
| 46047 | |
| 46048 | /* If the cache contains a page with page-number pgno, remove it |
| 46049 | ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for |
| @@ -46073,11 +45851,11 @@ | |
| 46073 | ** as the original page since it has already been allocated. |
| 46074 | */ |
| 46075 | if( MEMDB ){ |
| 46076 | assert( pPgOld ); |
| 46077 | sqlite3PcacheMove(pPgOld, origPgno); |
| 46078 | sqlite3PagerUnrefNotNull(pPgOld); |
| 46079 | } |
| 46080 | |
| 46081 | if( needSyncPgno ){ |
| 46082 | /* If needSyncPgno is non-zero, then the journal file needs to be |
| 46083 | ** sync()ed before any data is written to database file page needSyncPgno. |
| @@ -46102,11 +45880,11 @@ | |
| 46102 | } |
| 46103 | return rc; |
| 46104 | } |
| 46105 | pPgHdr->flags |= PGHDR_NEED_SYNC; |
| 46106 | sqlite3PcacheMakeDirty(pPgHdr); |
| 46107 | sqlite3PagerUnrefNotNull(pPgHdr); |
| 46108 | } |
| 46109 | |
| 46110 | return SQLITE_OK; |
| 46111 | } |
| 46112 | #endif |
| @@ -52221,11 +51999,11 @@ | |
| 52221 | |
| 52222 | if( pgno>btreePagecount(pBt) ){ |
| 52223 | rc = SQLITE_CORRUPT_BKPT; |
| 52224 | }else{ |
| 52225 | rc = btreeGetPage(pBt, pgno, ppPage, bReadonly); |
| 52226 | if( rc==SQLITE_OK && (*ppPage)->isInit==0 ){ |
| 52227 | rc = btreeInitPage(*ppPage); |
| 52228 | if( rc!=SQLITE_OK ){ |
| 52229 | releasePage(*ppPage); |
| 52230 | } |
| 52231 | } |
| @@ -52242,15 +52020,14 @@ | |
| 52242 | */ |
| 52243 | static void releasePage(MemPage *pPage){ |
| 52244 | if( pPage ){ |
| 52245 | assert( pPage->aData ); |
| 52246 | assert( pPage->pBt ); |
| 52247 | assert( pPage->pDbPage!=0 ); |
| 52248 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 52249 | assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData ); |
| 52250 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 52251 | sqlite3PagerUnrefNotNull(pPage->pDbPage); |
| 52252 | } |
| 52253 | } |
| 52254 | |
| 52255 | /* |
| 52256 | ** During a rollback, when the pager reloads information into the cache |
| @@ -54762,14 +54539,14 @@ | |
| 54762 | } |
| 54763 | |
| 54764 | /* |
| 54765 | ** Return a pointer to payload information from the entry that the |
| 54766 | ** pCur cursor is pointing to. The pointer is to the beginning of |
| 54767 | ** the key if index btrees (pPage->intKey==0) and is the data for |
| 54768 | ** table btrees (pPage->intKey==1). The number of bytes of available |
| 54769 | ** key/data is written into *pAmt. If *pAmt==0, then the value |
| 54770 | ** returned will not be a valid pointer. |
| 54771 | ** |
| 54772 | ** This routine is an optimization. It is common for the entire key |
| 54773 | ** and data to fit on the local page and for there to be no overflow |
| 54774 | ** pages. When that is so, this routine can be used to access the |
| 54775 | ** key and data without making a copy. If the key and/or data spills |
| @@ -54778,25 +54555,45 @@ | |
| 54778 | ** |
| 54779 | ** The pointer returned by this routine looks directly into the cached |
| 54780 | ** page of the database. The data might change or move the next time |
| 54781 | ** any btree routine is called. |
| 54782 | */ |
| 54783 | static const void *fetchPayload( |
| 54784 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 54785 | u32 *pAmt /* Write the number of available bytes here */ |
| 54786 | ){ |
| 54787 | assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 54788 | assert( pCur->eState==CURSOR_VALID ); |
| 54789 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 54790 | assert( cursorHoldsMutex(pCur) ); |
| 54791 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 54792 | if( pCur->info.nSize==0 ){ |
| 54793 | btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage], |
| 54794 | &pCur->info); |
| 54795 | } |
| 54796 | *pAmt = pCur->info.nLocal; |
| 54797 | return (void*)(pCur->info.pCell + pCur->info.nHeader); |
| 54798 | } |
| 54799 | |
| 54800 | |
| 54801 | /* |
| 54802 | ** For the entry that cursor pCur is point to, return as |
| @@ -54811,14 +54608,26 @@ | |
| 54811 | ** |
| 54812 | ** These routines is used to get quick access to key and data |
| 54813 | ** in the common case where no overflow pages are used. |
| 54814 | */ |
| 54815 | SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){ |
| 54816 | return fetchPayload(pCur, pAmt); |
| 54817 | } |
| 54818 | SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){ |
| 54819 | return fetchPayload(pCur, pAmt); |
| 54820 | } |
| 54821 | |
| 54822 | |
| 54823 | /* |
| 54824 | ** Move the cursor down to a new child page. The newPgno argument is the |
| @@ -54933,10 +54742,12 @@ | |
| 54933 | ** b-tree). |
| 54934 | */ |
| 54935 | static int moveToRoot(BtCursor *pCur){ |
| 54936 | MemPage *pRoot; |
| 54937 | int rc = SQLITE_OK; |
| 54938 | |
| 54939 | assert( cursorHoldsMutex(pCur) ); |
| 54940 | assert( CURSOR_INVALID < CURSOR_REQUIRESEEK ); |
| 54941 | assert( CURSOR_VALID < CURSOR_REQUIRESEEK ); |
| 54942 | assert( CURSOR_FAULT > CURSOR_REQUIRESEEK ); |
| @@ -54947,16 +54758,20 @@ | |
| 54947 | } |
| 54948 | sqlite3BtreeClearCursor(pCur); |
| 54949 | } |
| 54950 | |
| 54951 | if( pCur->iPage>=0 ){ |
| 54952 | while( pCur->iPage ) releasePage(pCur->apPage[pCur->iPage--]); |
| 54953 | }else if( pCur->pgnoRoot==0 ){ |
| 54954 | pCur->eState = CURSOR_INVALID; |
| 54955 | return SQLITE_OK; |
| 54956 | }else{ |
| 54957 | rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0], |
| 54958 | pCur->wrFlag==0 ? PAGER_GET_READONLY : 0); |
| 54959 | if( rc!=SQLITE_OK ){ |
| 54960 | pCur->eState = CURSOR_INVALID; |
| 54961 | return rc; |
| 54962 | } |
| @@ -54985,20 +54800,18 @@ | |
| 54985 | pCur->aiIdx[0] = 0; |
| 54986 | pCur->info.nSize = 0; |
| 54987 | pCur->atLast = 0; |
| 54988 | pCur->validNKey = 0; |
| 54989 | |
| 54990 | if( pRoot->nCell>0 ){ |
| 54991 | pCur->eState = CURSOR_VALID; |
| 54992 | }else if( !pRoot->leaf ){ |
| 54993 | Pgno subpage; |
| 54994 | if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT; |
| 54995 | subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]); |
| 54996 | pCur->eState = CURSOR_VALID; |
| 54997 | rc = moveToChild(pCur, subpage); |
| 54998 | }else{ |
| 54999 | pCur->eState = CURSOR_INVALID; |
| 55000 | } |
| 55001 | return rc; |
| 55002 | } |
| 55003 | |
| 55004 | /* |
| @@ -55250,18 +55063,21 @@ | |
| 55250 | ** the entire cell by checking for the cases where the record is |
| 55251 | ** stored entirely within the b-tree page by inspecting the first |
| 55252 | ** 2 bytes of the cell. |
| 55253 | */ |
| 55254 | nCell = pCell[0]; |
| 55255 | if( nCell<=pPage->max1bytePayload ){ |
| 55256 | /* This branch runs if the record-size field of the cell is a |
| 55257 | ** single byte varint and the record fits entirely on the main |
| 55258 | ** b-tree page. */ |
| 55259 | testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 55260 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 55261 | }else if( !(pCell[1] & 0x80) |
| 55262 | && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 55263 | ){ |
| 55264 | /* The record-size field is a 2 byte varint and the record |
| 55265 | ** fits entirely on the main b-tree page. */ |
| 55266 | testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 55267 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| @@ -56081,11 +55897,11 @@ | |
| 56081 | nHeader = 0; |
| 56082 | if( !pPage->leaf ){ |
| 56083 | nHeader += 4; |
| 56084 | } |
| 56085 | if( pPage->hasData ){ |
| 56086 | nHeader += putVarint32(&pCell[nHeader], nData+nZero); |
| 56087 | }else{ |
| 56088 | nData = nZero = 0; |
| 56089 | } |
| 56090 | nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey); |
| 56091 | btreeParseCellPtr(pPage, pCell, &info); |
| @@ -56209,10 +56025,11 @@ | |
| 56209 | */ |
| 56210 | static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){ |
| 56211 | u32 pc; /* Offset to cell content of cell being deleted */ |
| 56212 | u8 *data; /* pPage->aData */ |
| 56213 | u8 *ptr; /* Used to move bytes around within data[] */ |
| 56214 | int rc; /* The return code */ |
| 56215 | int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */ |
| 56216 | |
| 56217 | if( *pRC ) return; |
| 56218 | |
| @@ -56232,13 +56049,18 @@ | |
| 56232 | } |
| 56233 | rc = freeSpace(pPage, pc, sz); |
| 56234 | if( rc ){ |
| 56235 | *pRC = rc; |
| 56236 | return; |
| 56237 | } |
| 56238 | pPage->nCell--; |
| 56239 | memmove(ptr, ptr+2, 2*(pPage->nCell - idx)); |
| 56240 | put2byte(&data[hdr+3], pPage->nCell); |
| 56241 | pPage->nFree += 2; |
| 56242 | } |
| 56243 | |
| 56244 | /* |
| @@ -56271,10 +56093,13 @@ | |
| 56271 | int j; /* Loop counter */ |
| 56272 | int end; /* First byte past the last cell pointer in data[] */ |
| 56273 | int ins; /* Index in data[] where new cell pointer is inserted */ |
| 56274 | int cellOffset; /* Address of first cell pointer in data[] */ |
| 56275 | u8 *data; /* The content of the whole page */ |
| 56276 | int nSkip = (iChild ? 4 : 0); |
| 56277 | |
| 56278 | if( *pRC ) return; |
| 56279 | |
| 56280 | assert( i>=0 && i<=pPage->nCell+pPage->nOverflow ); |
| @@ -56321,11 +56146,17 @@ | |
| 56321 | pPage->nFree -= (u16)(2 + sz); |
| 56322 | memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip); |
| 56323 | if( iChild ){ |
| 56324 | put4byte(&data[idx], iChild); |
| 56325 | } |
| 56326 | memmove(&data[ins+2], &data[ins], end-ins); |
| 56327 | put2byte(&data[ins], idx); |
| 56328 | put2byte(&data[pPage->hdrOffset+3], pPage->nCell); |
| 56329 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 56330 | if( pPage->pBt->autoVacuum ){ |
| 56331 | /* The cell may contain a pointer to an overflow page. If so, write |
| @@ -58283,11 +58114,11 @@ | |
| 58283 | va_start(ap, zFormat); |
| 58284 | if( pCheck->errMsg.nChar ){ |
| 58285 | sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1); |
| 58286 | } |
| 58287 | if( zMsg1 ){ |
| 58288 | sqlite3StrAccumAppendAll(&pCheck->errMsg, zMsg1); |
| 58289 | } |
| 58290 | sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); |
| 58291 | va_end(ap); |
| 58292 | if( pCheck->errMsg.accError==STRACCUM_NOMEM ){ |
| 58293 | pCheck->mallocFailed = 1; |
| @@ -59577,11 +59408,11 @@ | |
| 59577 | rc = backupTruncateFile(pFile, iSize); |
| 59578 | } |
| 59579 | |
| 59580 | /* Sync the database file to disk. */ |
| 59581 | if( rc==SQLITE_OK ){ |
| 59582 | rc = sqlite3PagerSync(pDestPager, 0); |
| 59583 | } |
| 59584 | }else{ |
| 59585 | sqlite3PagerTruncateImage(pDestPager, nDestTruncate); |
| 59586 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 59587 | } |
| @@ -59652,14 +59483,14 @@ | |
| 59652 | /* If a transaction is still open on the Btree, roll it back. */ |
| 59653 | sqlite3BtreeRollback(p->pDest, SQLITE_OK); |
| 59654 | |
| 59655 | /* Set the error code of the destination database handle. */ |
| 59656 | rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc; |
| 59657 | if( p->pDestDb ){ |
| 59658 | sqlite3Error(p->pDestDb, rc, 0); |
| 59659 | |
| 59660 | /* Exit the mutexes and free the backup context structure. */ |
| 59661 | sqlite3LeaveMutexAndCloseZombie(p->pDestDb); |
| 59662 | } |
| 59663 | sqlite3BtreeLeave(p->pSrc); |
| 59664 | if( p->pDestDb ){ |
| 59665 | /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a |
| @@ -59859,59 +59690,61 @@ | |
| 59859 | #endif |
| 59860 | } |
| 59861 | |
| 59862 | /* |
| 59863 | ** Make sure pMem->z points to a writable allocation of at least |
| 59864 | ** min(n,32) bytes. |
| 59865 | ** |
| 59866 | ** If the bPreserve argument is true, then copy of the content of |
| 59867 | ** pMem->z into the new allocation. pMem must be either a string or |
| 59868 | ** blob if bPreserve is true. If bPreserve is false, any prior content |
| 59869 | ** in pMem->z is discarded. |
| 59870 | */ |
| 59871 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){ |
| 59872 | assert( 1 >= |
| 59873 | ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + |
| 59874 | (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + |
| 59875 | ((pMem->flags&MEM_Ephem) ? 1 : 0) + |
| 59876 | ((pMem->flags&MEM_Static) ? 1 : 0) |
| 59877 | ); |
| 59878 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 59879 | |
| 59880 | /* If the bPreserve flag is set to true, then the memory cell must already |
| 59881 | ** contain a valid string or blob value. */ |
| 59882 | assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); |
| 59883 | testcase( bPreserve && pMem->z==0 ); |
| 59884 | |
| 59885 | if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ |
| 59886 | if( n<32 ) n = 32; |
| 59887 | if( bPreserve && pMem->z==pMem->zMalloc ){ |
| 59888 | pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); |
| 59889 | bPreserve = 0; |
| 59890 | }else{ |
| 59891 | sqlite3DbFree(pMem->db, pMem->zMalloc); |
| 59892 | pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); |
| 59893 | } |
| 59894 | if( pMem->zMalloc==0 ){ |
| 59895 | sqlite3VdbeMemRelease(pMem); |
| 59896 | pMem->flags = MEM_Null; |
| 59897 | return SQLITE_NOMEM; |
| 59898 | } |
| 59899 | } |
| 59900 | |
| 59901 | if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){ |
| 59902 | memcpy(pMem->zMalloc, pMem->z, pMem->n); |
| 59903 | } |
| 59904 | if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){ |
| 59905 | assert( pMem->xDel!=SQLITE_DYNAMIC ); |
| 59906 | pMem->xDel((void *)(pMem->z)); |
| 59907 | } |
| 59908 | |
| 59909 | pMem->z = pMem->zMalloc; |
| 59910 | pMem->flags &= ~(MEM_Ephem|MEM_Static); |
| 59911 | pMem->xDel = 0; |
| 59912 | return SQLITE_OK; |
| 59913 | } |
| 59914 | |
| 59915 | /* |
| 59916 | ** Make the given Mem object MEM_Dyn. In other words, make it so |
| 59917 | ** that any TEXT or BLOB content is stored in memory obtained from |
| @@ -60093,16 +59926,14 @@ | |
| 60093 | ** inconsistent state, for example with (Mem.z==0) and |
| 60094 | ** (Mem.type==SQLITE_TEXT). |
| 60095 | */ |
| 60096 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){ |
| 60097 | VdbeMemRelease(p); |
| 60098 | if( p->zMalloc ){ |
| 60099 | sqlite3DbFree(p->db, p->zMalloc); |
| 60100 | p->zMalloc = 0; |
| 60101 | } |
| 60102 | p->z = 0; |
| 60103 | assert( p->xDel==0 ); /* Zeroed by VdbeMemRelease() above */ |
| 60104 | } |
| 60105 | |
| 60106 | /* |
| 60107 | ** Convert a 64-bit IEEE double into a 64-bit signed integer. |
| 60108 | ** If the double is out of range of a 64-bit signed integer then |
| @@ -60282,13 +60113,10 @@ | |
| 60282 | sqlite3RowSetClear(pMem->u.pRowSet); |
| 60283 | } |
| 60284 | MemSetTypeFlag(pMem, MEM_Null); |
| 60285 | pMem->type = SQLITE_NULL; |
| 60286 | } |
| 60287 | SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){ |
| 60288 | sqlite3VdbeMemSetNull((Mem*)p); |
| 60289 | } |
| 60290 | |
| 60291 | /* |
| 60292 | ** Delete any previous value and set the value to be a BLOB of length |
| 60293 | ** n containing all zeros. |
| 60294 | */ |
| @@ -61022,11 +60850,11 @@ | |
| 61022 | if( aRet==0 ){ |
| 61023 | sqlite3_result_error_nomem(context); |
| 61024 | }else{ |
| 61025 | aRet[0] = nSerial+1; |
| 61026 | sqlite3PutVarint(&aRet[1], iSerial); |
| 61027 | sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial); |
| 61028 | sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT); |
| 61029 | sqlite3DbFree(db, aRet); |
| 61030 | } |
| 61031 | } |
| 61032 | |
| @@ -61207,12 +61035,11 @@ | |
| 61207 | */ |
| 61208 | |
| 61209 | /* |
| 61210 | ** Create a new virtual database engine. |
| 61211 | */ |
| 61212 | SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(Parse *pParse){ |
| 61213 | sqlite3 *db = pParse->db; |
| 61214 | Vdbe *p; |
| 61215 | p = sqlite3DbMallocZero(db, sizeof(Vdbe) ); |
| 61216 | if( p==0 ) return 0; |
| 61217 | p->db = db; |
| 61218 | if( db->pVdbe ){ |
| @@ -61220,14 +61047,10 @@ | |
| 61220 | } |
| 61221 | p->pNext = db->pVdbe; |
| 61222 | p->pPrev = 0; |
| 61223 | db->pVdbe = p; |
| 61224 | p->magic = VDBE_MAGIC_INIT; |
| 61225 | p->pParse = pParse; |
| 61226 | assert( pParse->aLabel==0 ); |
| 61227 | assert( pParse->nLabel==0 ); |
| 61228 | assert( pParse->nOpAlloc==0 ); |
| 61229 | return p; |
| 61230 | } |
| 61231 | |
| 61232 | /* |
| 61233 | ** Remember the SQL string for a prepared statement. |
| @@ -61279,18 +61102,17 @@ | |
| 61279 | ** If an out-of-memory error occurs while resizing the array, return |
| 61280 | ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain |
| 61281 | ** unchanged (this is so that any opcodes already allocated can be |
| 61282 | ** correctly deallocated along with the rest of the Vdbe). |
| 61283 | */ |
| 61284 | static int growOpArray(Vdbe *v){ |
| 61285 | VdbeOp *pNew; |
| 61286 | Parse *p = v->pParse; |
| 61287 | int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op))); |
| 61288 | pNew = sqlite3DbRealloc(p->db, v->aOp, nNew*sizeof(Op)); |
| 61289 | if( pNew ){ |
| 61290 | p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op); |
| 61291 | v->aOp = pNew; |
| 61292 | } |
| 61293 | return (pNew ? SQLITE_OK : SQLITE_NOMEM); |
| 61294 | } |
| 61295 | |
| 61296 | #ifdef SQLITE_DEBUG |
| @@ -61325,11 +61147,11 @@ | |
| 61325 | VdbeOp *pOp; |
| 61326 | |
| 61327 | i = p->nOp; |
| 61328 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61329 | assert( op>0 && op<0xff ); |
| 61330 | if( p->pParse->nOpAlloc<=i ){ |
| 61331 | if( growOpArray(p) ){ |
| 61332 | return 1; |
| 61333 | } |
| 61334 | } |
| 61335 | p->nOp++; |
| @@ -61344,19 +61166,10 @@ | |
| 61344 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 61345 | pOp->zComment = 0; |
| 61346 | #endif |
| 61347 | #ifdef SQLITE_DEBUG |
| 61348 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 61349 | int jj, kk; |
| 61350 | Parse *pParse = p->pParse; |
| 61351 | for(jj=kk=0; jj<SQLITE_N_COLCACHE; jj++){ |
| 61352 | struct yColCache *x = pParse->aColCache + jj; |
| 61353 | if( x->iLevel>pParse->iCacheLevel || x->iReg==0 ) continue; |
| 61354 | printf(" r[%d]={%d:%d}", x->iReg, x->iTable, x->iColumn); |
| 61355 | kk++; |
| 61356 | } |
| 61357 | if( kk ) printf("\n"); |
| 61358 | sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 61359 | test_addop_breakpoint(); |
| 61360 | } |
| 61361 | #endif |
| 61362 | #ifdef VDBE_PROFILE |
| @@ -61436,14 +61249,13 @@ | |
| 61436 | ** always negative and P2 values are suppose to be non-negative. |
| 61437 | ** Hence, a negative P2 value is a label that has yet to be resolved. |
| 61438 | ** |
| 61439 | ** Zero is returned if a malloc() fails. |
| 61440 | */ |
| 61441 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *v){ |
| 61442 | Parse *p = v->pParse; |
| 61443 | int i = p->nLabel++; |
| 61444 | assert( v->magic==VDBE_MAGIC_INIT ); |
| 61445 | if( (i & (i-1))==0 ){ |
| 61446 | p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, |
| 61447 | (i*2+1)*sizeof(p->aLabel[0])); |
| 61448 | } |
| 61449 | if( p->aLabel ){ |
| @@ -61455,17 +61267,16 @@ | |
| 61455 | /* |
| 61456 | ** Resolve label "x" to be the address of the next instruction to |
| 61457 | ** be inserted. The parameter "x" must have been obtained from |
| 61458 | ** a prior call to sqlite3VdbeMakeLabel(). |
| 61459 | */ |
| 61460 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *v, int x){ |
| 61461 | Parse *p = v->pParse; |
| 61462 | int j = -1-x; |
| 61463 | assert( v->magic==VDBE_MAGIC_INIT ); |
| 61464 | assert( j<p->nLabel ); |
| 61465 | if( j>=0 && p->aLabel ){ |
| 61466 | p->aLabel[j] = v->nOp; |
| 61467 | } |
| 61468 | } |
| 61469 | |
| 61470 | /* |
| 61471 | ** Mark the VDBE as one that can only be run one time. |
| @@ -61610,12 +61421,11 @@ | |
| 61610 | */ |
| 61611 | static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ |
| 61612 | int i; |
| 61613 | int nMaxArgs = *pMaxFuncArgs; |
| 61614 | Op *pOp; |
| 61615 | Parse *pParse = p->pParse; |
| 61616 | int *aLabel = pParse->aLabel; |
| 61617 | p->readOnly = 1; |
| 61618 | p->bIsReader = 0; |
| 61619 | for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ |
| 61620 | u8 opcode = pOp->opcode; |
| 61621 | |
| @@ -61674,17 +61484,16 @@ | |
| 61674 | } |
| 61675 | } |
| 61676 | |
| 61677 | pOp->opflags = sqlite3OpcodeProperty[opcode]; |
| 61678 | if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 61679 | assert( -1-pOp->p2<pParse->nLabel ); |
| 61680 | pOp->p2 = aLabel[-1-pOp->p2]; |
| 61681 | } |
| 61682 | } |
| 61683 | sqlite3DbFree(p->db, pParse->aLabel); |
| 61684 | pParse->aLabel = 0; |
| 61685 | pParse->nLabel = 0; |
| 61686 | *pMaxFuncArgs = nMaxArgs; |
| 61687 | assert( p->bIsReader!=0 || p->btreeMask==0 ); |
| 61688 | } |
| 61689 | |
| 61690 | /* |
| @@ -61724,11 +61533,11 @@ | |
| 61724 | ** address of the first operation added. |
| 61725 | */ |
| 61726 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ |
| 61727 | int addr; |
| 61728 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61729 | if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){ |
| 61730 | return 0; |
| 61731 | } |
| 61732 | addr = p->nOp; |
| 61733 | if( ALWAYS(nOp>0) ){ |
| 61734 | int i; |
| @@ -61913,17 +61722,10 @@ | |
| 61913 | pOp->opcode = OP_Noop; |
| 61914 | if( addr==p->nOp-1 ) p->nOp--; |
| 61915 | } |
| 61916 | } |
| 61917 | |
| 61918 | /* |
| 61919 | ** Remove the last opcode inserted |
| 61920 | */ |
| 61921 | SQLITE_PRIVATE void sqlite3VdbeDeleteLastOpcode(Vdbe *p){ |
| 61922 | p->nOp--; |
| 61923 | } |
| 61924 | |
| 61925 | /* |
| 61926 | ** Change the value of the P4 operand for a specific instruction. |
| 61927 | ** This routine is useful when a large program is loaded from a |
| 61928 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| 61929 | ** few minor changes to the program. |
| @@ -62085,21 +61887,11 @@ | |
| 62085 | if( c=='4' ) return pOp->p4.i; |
| 62086 | return pOp->p5; |
| 62087 | } |
| 62088 | |
| 62089 | /* |
| 62090 | ** Compute a string for the "comment" field of a VDBE opcode listing. |
| 62091 | ** |
| 62092 | ** The Synopsis: field in comments in the vdbe.c source file gets converted |
| 62093 | ** to an extra string that is appended to the sqlite3OpcodeName(). In the |
| 62094 | ** absence of other comments, this synopsis becomes the comment on the opcode. |
| 62095 | ** Some translation occurs: |
| 62096 | ** |
| 62097 | ** "PX" -> "r[X]" |
| 62098 | ** "PX@PY" -> "r[X..X+Y-1]" or "r[x]" if y is 0 or 1 |
| 62099 | ** "PX@PY+1" -> "r[X..X+Y]" or "r[x]" if y is 0 |
| 62100 | ** "PY..PY" -> "r[X..Y]" or "r[x]" if y<=x |
| 62101 | */ |
| 62102 | static int displayComment( |
| 62103 | const Op *pOp, /* The opcode to be commented */ |
| 62104 | const char *zP4, /* Previously obtained value for P4 */ |
| 62105 | char *zTemp, /* Write result here */ |
| @@ -62129,17 +61921,11 @@ | |
| 62129 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1); |
| 62130 | if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){ |
| 62131 | ii += 3; |
| 62132 | jj += sqlite3Strlen30(zTemp+jj); |
| 62133 | v2 = translateP(zSynopsis[ii], pOp); |
| 62134 | if( strncmp(zSynopsis+ii+1,"+1",2)==0 ){ |
| 62135 | ii += 2; |
| 62136 | v2++; |
| 62137 | } |
| 62138 | if( v2>1 ){ |
| 62139 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1); |
| 62140 | } |
| 62141 | }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){ |
| 62142 | ii += 4; |
| 62143 | } |
| 62144 | } |
| 62145 | jj += sqlite3Strlen30(zTemp+jj); |
| @@ -62367,13 +62153,10 @@ | |
| 62367 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 62368 | displayComment(pOp, zP4, zCom, sizeof(zCom)); |
| 62369 | #else |
| 62370 | zCom[0] = 0 |
| 62371 | #endif |
| 62372 | /* NB: The sqlite3OpcodeName() function is implemented by code created |
| 62373 | ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the |
| 62374 | ** information from the vdbe.c source text */ |
| 62375 | fprintf(pOut, zFormat1, pc, |
| 62376 | sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5, |
| 62377 | zCom |
| 62378 | ); |
| 62379 | fflush(pOut); |
| @@ -62801,11 +62584,10 @@ | |
| 62801 | |
| 62802 | assert( p!=0 ); |
| 62803 | assert( p->nOp>0 ); |
| 62804 | assert( pParse!=0 ); |
| 62805 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 62806 | assert( pParse==p->pParse ); |
| 62807 | db = p->db; |
| 62808 | assert( db->mallocFailed==0 ); |
| 62809 | nVar = pParse->nVar; |
| 62810 | nMem = pParse->nMem; |
| 62811 | nCursor = pParse->nTab; |
| @@ -62825,12 +62607,12 @@ | |
| 62825 | nMem += nCursor; |
| 62826 | |
| 62827 | /* Allocate space for memory registers, SQL variables, VDBE cursors and |
| 62828 | ** an array to marshal SQL function arguments in. |
| 62829 | */ |
| 62830 | zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ |
| 62831 | zEnd = (u8*)&p->aOp[pParse->nOpAlloc]; /* First byte past end of zCsr[] */ |
| 62832 | |
| 62833 | resolveP2Values(p, &nArg); |
| 62834 | p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort); |
| 62835 | if( pParse->explain && nMem<10 ){ |
| 62836 | nMem = 10; |
| @@ -63653,11 +63435,10 @@ | |
| 63653 | sqlite3 *db = p->db; |
| 63654 | int rc = p->rc; |
| 63655 | if( p->zErrMsg ){ |
| 63656 | u8 mallocFailed = db->mallocFailed; |
| 63657 | sqlite3BeginBenignMalloc(); |
| 63658 | if( db->pErr==0 ) db->pErr = sqlite3ValueNew(db); |
| 63659 | sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63660 | sqlite3EndBenignMalloc(); |
| 63661 | db->mallocFailed = mallocFailed; |
| 63662 | db->errCode = rc; |
| 63663 | }else{ |
| @@ -63722,11 +63503,12 @@ | |
| 63722 | }else if( p->rc && p->expired ){ |
| 63723 | /* The expired flag was set on the VDBE before the first call |
| 63724 | ** to sqlite3_step(). For consistency (since sqlite3_step() was |
| 63725 | ** called), set the database error in this case as well. |
| 63726 | */ |
| 63727 | sqlite3Error(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg); |
| 63728 | sqlite3DbFree(db, p->zErrMsg); |
| 63729 | p->zErrMsg = 0; |
| 63730 | } |
| 63731 | |
| 63732 | /* Reclaim all memory used by the VDBE |
| @@ -63829,10 +63611,11 @@ | |
| 63829 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 63830 | sqlite3DbFree(db, pSub); |
| 63831 | } |
| 63832 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 63833 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 63834 | sqlite3DbFree(db, p->aColName); |
| 63835 | sqlite3DbFree(db, p->zSql); |
| 63836 | sqlite3DbFree(db, p->pFree); |
| 63837 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 63838 | sqlite3DbFree(db, p->zExplain); |
| @@ -64059,19 +63842,25 @@ | |
| 64059 | /* |
| 64060 | ** Write the serialized data blob for the value stored in pMem into |
| 64061 | ** buf. It is assumed that the caller has allocated sufficient space. |
| 64062 | ** Return the number of bytes written. |
| 64063 | ** |
| 64064 | ** nBuf is the amount of space left in buf[]. The caller is responsible |
| 64065 | ** for allocating enough space to buf[] to hold the entire field, exclusive |
| 64066 | ** of the pMem->u.nZero bytes for a MEM_Zero value. |
| 64067 | ** |
| 64068 | ** Return the number of bytes actually written into buf[]. The number |
| 64069 | ** of bytes in the zero-filled tail is included in the return value only |
| 64070 | ** if those bytes were zeroed in buf[]. |
| 64071 | */ |
| 64072 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, Mem *pMem, u32 serial_type){ |
| 64073 | u32 len; |
| 64074 | |
| 64075 | /* Integer and Real */ |
| 64076 | if( serial_type<=7 && serial_type>0 ){ |
| 64077 | u64 v; |
| @@ -64082,10 +63871,11 @@ | |
| 64082 | swapMixedEndianFloat(v); |
| 64083 | }else{ |
| 64084 | v = pMem->u.i; |
| 64085 | } |
| 64086 | len = i = sqlite3VdbeSerialTypeLen(serial_type); |
| 64087 | while( i-- ){ |
| 64088 | buf[i] = (u8)(v&0xFF); |
| 64089 | v >>= 8; |
| 64090 | } |
| 64091 | return len; |
| @@ -64093,12 +63883,21 @@ | |
| 64093 | |
| 64094 | /* String or blob */ |
| 64095 | if( serial_type>=12 ){ |
| 64096 | assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0) |
| 64097 | == (int)sqlite3VdbeSerialTypeLen(serial_type) ); |
| 64098 | len = pMem->n; |
| 64099 | memcpy(buf, pMem->z, len); |
| 64100 | return len; |
| 64101 | } |
| 64102 | |
| 64103 | /* NULL or constants 0 or 1 */ |
| 64104 | return 0; |
| @@ -65095,21 +64894,20 @@ | |
| 65095 | && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){ |
| 65096 | sqlite3_reset(pStmt); |
| 65097 | v->doingRerun = 1; |
| 65098 | assert( v->expired==0 ); |
| 65099 | } |
| 65100 | if( rc2!=SQLITE_OK ){ |
| 65101 | /* This case occurs after failing to recompile an sql statement. |
| 65102 | ** The error message from the SQL compiler has already been loaded |
| 65103 | ** into the database handle. This block copies the error message |
| 65104 | ** from the database handle into the statement and sets the statement |
| 65105 | ** program counter to 0 to ensure that when the statement is |
| 65106 | ** finalized or reset the parser error message is available via |
| 65107 | ** sqlite3_errmsg() and sqlite3_errcode(). |
| 65108 | */ |
| 65109 | const char *zErr = (const char *)sqlite3_value_text(db->pErr); |
| 65110 | assert( zErr!=0 || db->mallocFailed ); |
| 65111 | sqlite3DbFree(db, v->zErrMsg); |
| 65112 | if( !db->mallocFailed ){ |
| 65113 | v->zErrMsg = sqlite3DbStrDup(db, zErr); |
| 65114 | v->rc = rc2; |
| 65115 | } else { |
| @@ -66021,11 +65819,10 @@ | |
| 66021 | if( db->nVdbeExec>1 ){ |
| 66022 | while( *zRawSql ){ |
| 66023 | const char *zStart = zRawSql; |
| 66024 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 66025 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 66026 | assert( (zRawSql - zStart) > 0 ); |
| 66027 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| 66028 | } |
| 66029 | }else{ |
| 66030 | while( zRawSql[0] ){ |
| 66031 | n = findNextHostParameter(zRawSql, &nToken); |
| @@ -66054,13 +65851,13 @@ | |
| 66054 | assert( idx>0 && idx<=p->nVar ); |
| 66055 | pVar = &p->aVar[idx-1]; |
| 66056 | if( pVar->flags & MEM_Null ){ |
| 66057 | sqlite3StrAccumAppend(&out, "NULL", 4); |
| 66058 | }else if( pVar->flags & MEM_Int ){ |
| 66059 | sqlite3XPrintf(&out, 0, "%lld", pVar->u.i); |
| 66060 | }else if( pVar->flags & MEM_Real ){ |
| 66061 | sqlite3XPrintf(&out, 0, "%!.15g", pVar->r); |
| 66062 | }else if( pVar->flags & MEM_Str ){ |
| 66063 | int nOut; /* Number of bytes of the string text to include in output */ |
| 66064 | #ifndef SQLITE_OMIT_UTF16 |
| 66065 | u8 enc = ENC(db); |
| 66066 | Mem utf8; |
| @@ -66077,37 +65874,33 @@ | |
| 66077 | if( nOut>SQLITE_TRACE_SIZE_LIMIT ){ |
| 66078 | nOut = SQLITE_TRACE_SIZE_LIMIT; |
| 66079 | while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; } |
| 66080 | } |
| 66081 | #endif |
| 66082 | sqlite3XPrintf(&out, 0, "'%.*q'", nOut, pVar->z); |
| 66083 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 66084 | if( nOut<pVar->n ){ |
| 66085 | sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut); |
| 66086 | } |
| 66087 | #endif |
| 66088 | #ifndef SQLITE_OMIT_UTF16 |
| 66089 | if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8); |
| 66090 | #endif |
| 66091 | }else if( pVar->flags & MEM_Zero ){ |
| 66092 | sqlite3XPrintf(&out, 0, "zeroblob(%d)", pVar->u.nZero); |
| 66093 | }else{ |
| 66094 | int nOut; /* Number of bytes of the blob to include in output */ |
| 66095 | assert( pVar->flags & MEM_Blob ); |
| 66096 | sqlite3StrAccumAppend(&out, "x'", 2); |
| 66097 | nOut = pVar->n; |
| 66098 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 66099 | if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT; |
| 66100 | #endif |
| 66101 | for(i=0; i<nOut; i++){ |
| 66102 | sqlite3XPrintf(&out, 0, "%02x", pVar->z[i]&0xff); |
| 66103 | } |
| 66104 | sqlite3StrAccumAppend(&out, "'", 1); |
| 66105 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 66106 | if( nOut<pVar->n ){ |
| 66107 | sqlite3XPrintf(&out, 0, "/*+%d bytes*/", pVar->n-nOut); |
| 66108 | } |
| 66109 | #endif |
| 66110 | } |
| 66111 | } |
| 66112 | } |
| 66113 | return sqlite3StrAccumFinish(&out); |
| @@ -66162,11 +65955,11 @@ | |
| 66162 | int n = p->nIndent; |
| 66163 | if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent); |
| 66164 | sqlite3AppendSpace(&p->str, p->aIndent[n-1]); |
| 66165 | } |
| 66166 | va_start(ap, zFormat); |
| 66167 | sqlite3VXPrintf(&p->str, SQLITE_PRINTF_INTERNAL, zFormat, ap); |
| 66168 | va_end(ap); |
| 66169 | } |
| 66170 | } |
| 66171 | |
| 66172 | /* |
| @@ -66869,11 +66662,433 @@ | |
| 66869 | i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ |
| 66870 | #ifdef VDBE_PROFILE |
| 66871 | u64 start; /* CPU clock count at start of opcode */ |
| 66872 | int origPc; /* Program counter at start of opcode */ |
| 66873 | #endif |
| 66874 | /*** INSERT STACK UNION HERE ***/ |
| 66875 | |
| 66876 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 66877 | sqlite3VdbeEnter(p); |
| 66878 | if( p->rc==SQLITE_NOMEM ){ |
| 66879 | /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| @@ -67115,18 +67330,20 @@ | |
| 67115 | /* Opcode: Yield P1 * * * * |
| 67116 | ** |
| 67117 | ** Swap the program counter with the value in register P1. |
| 67118 | */ |
| 67119 | case OP_Yield: { /* in1 */ |
| 67120 | int pcDest; |
| 67121 | pIn1 = &aMem[pOp->p1]; |
| 67122 | assert( (pIn1->flags & MEM_Dyn)==0 ); |
| 67123 | pIn1->flags = MEM_Int; |
| 67124 | pcDest = (int)pIn1->u.i; |
| 67125 | pIn1->u.i = pc; |
| 67126 | REGISTER_TRACE(pOp->p1, pIn1); |
| 67127 | pc = pcDest; |
| 67128 | break; |
| 67129 | } |
| 67130 | |
| 67131 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 67132 | ** Synopsis: if r[P3] null then halt |
| @@ -67171,12 +67388,14 @@ | |
| 67171 | ** There is an implied "Halt 0 0 0" instruction inserted at the very end of |
| 67172 | ** every program. So a jump past the last instruction of the program |
| 67173 | ** is the same as executing Halt. |
| 67174 | */ |
| 67175 | case OP_Halt: { |
| 67176 | const char *zType; |
| 67177 | const char *zLogFmt; |
| 67178 | |
| 67179 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 67180 | /* Halt the sub-program. Return control to the parent frame. */ |
| 67181 | VdbeFrame *pFrame = p->pFrame; |
| 67182 | p->pFrame = pFrame->pParent; |
| @@ -67183,11 +67402,11 @@ | |
| 67183 | p->nFrame--; |
| 67184 | sqlite3VdbeSetChanges(db, p->nChange); |
| 67185 | pc = sqlite3VdbeFrameRestore(pFrame); |
| 67186 | lastRowid = db->lastRowid; |
| 67187 | if( pOp->p2==OE_Ignore ){ |
| 67188 | /* Instruction pc is the OP_Program that invoked the sub-program |
| 67189 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 67190 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 67191 | ** an IGNORE exception. In this case jump to the address specified |
| 67192 | ** as the p2 of the calling OP_Program. */ |
| 67193 | pc = p->aOp[pc].p2-1; |
| @@ -67206,25 +67425,25 @@ | |
| 67206 | assert( pOp->p5>=1 && pOp->p5<=4 ); |
| 67207 | testcase( pOp->p5==1 ); |
| 67208 | testcase( pOp->p5==2 ); |
| 67209 | testcase( pOp->p5==3 ); |
| 67210 | testcase( pOp->p5==4 ); |
| 67211 | zType = azType[pOp->p5-1]; |
| 67212 | }else{ |
| 67213 | zType = 0; |
| 67214 | } |
| 67215 | assert( zType!=0 || pOp->p4.z!=0 ); |
| 67216 | zLogFmt = "abort at %d in [%s]: %s"; |
| 67217 | if( zType && pOp->p4.z ){ |
| 67218 | sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s", |
| 67219 | zType, pOp->p4.z); |
| 67220 | }else if( pOp->p4.z ){ |
| 67221 | sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); |
| 67222 | }else{ |
| 67223 | sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", zType); |
| 67224 | } |
| 67225 | sqlite3_log(pOp->p1, zLogFmt, pc, p->zSql, p->zErrMsg); |
| 67226 | } |
| 67227 | rc = sqlite3VdbeHalt(p); |
| 67228 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 67229 | if( rc==SQLITE_BUSY ){ |
| 67230 | p->rc = rc = SQLITE_BUSY; |
| @@ -67334,21 +67553,23 @@ | |
| 67334 | ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 67335 | ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 67336 | ** OP_Ne or OP_Eq. |
| 67337 | */ |
| 67338 | case OP_Null: { /* out2-prerelease */ |
| 67339 | int cnt; |
| 67340 | u16 nullFlag; |
| 67341 | cnt = pOp->p3-pOp->p2; |
| 67342 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 67343 | pOut->flags = nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 67344 | while( cnt>0 ){ |
| 67345 | pOut++; |
| 67346 | memAboutToChange(p, pOut); |
| 67347 | VdbeMemRelease(pOut); |
| 67348 | pOut->flags = nullFlag; |
| 67349 | cnt--; |
| 67350 | } |
| 67351 | break; |
| 67352 | } |
| 67353 | |
| 67354 | |
| @@ -67373,19 +67594,21 @@ | |
| 67373 | ** |
| 67374 | ** If the parameter is named, then its name appears in P4 and P3==1. |
| 67375 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 67376 | */ |
| 67377 | case OP_Variable: { /* out2-prerelease */ |
| 67378 | Mem *pVar; /* Value being transferred */ |
| 67379 | |
| 67380 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 67381 | assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 67382 | pVar = &p->aVar[pOp->p1 - 1]; |
| 67383 | if( sqlite3VdbeMemTooBig(pVar) ){ |
| 67384 | goto too_big; |
| 67385 | } |
| 67386 | sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static); |
| 67387 | UPDATE_MAX_BLOBSIZE(pOut); |
| 67388 | break; |
| 67389 | } |
| 67390 | |
| 67391 | /* Opcode: Move P1 P2 P3 * * |
| @@ -67395,67 +67618,71 @@ | |
| 67395 | ** registers P2..P2+P3. Registers P1..P1+P3 are |
| 67396 | ** left holding a NULL. It is an error for register ranges |
| 67397 | ** P1..P1+P3 and P2..P2+P3 to overlap. |
| 67398 | */ |
| 67399 | case OP_Move: { |
| 67400 | char *zMalloc; /* Holding variable for allocated memory */ |
| 67401 | int n; /* Number of registers left to copy */ |
| 67402 | int p1; /* Register to copy from */ |
| 67403 | int p2; /* Register to copy to */ |
| 67404 | |
| 67405 | n = pOp->p3; |
| 67406 | p1 = pOp->p1; |
| 67407 | p2 = pOp->p2; |
| 67408 | assert( n>=0 && p1>0 && p2>0 ); |
| 67409 | assert( p1+n<=p2 || p2+n<=p1 ); |
| 67410 | |
| 67411 | pIn1 = &aMem[p1]; |
| 67412 | pOut = &aMem[p2]; |
| 67413 | do{ |
| 67414 | assert( pOut<=&aMem[(p->nMem-p->nCursor)] ); |
| 67415 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 67416 | assert( memIsValid(pIn1) ); |
| 67417 | memAboutToChange(p, pOut); |
| 67418 | zMalloc = pOut->zMalloc; |
| 67419 | pOut->zMalloc = 0; |
| 67420 | sqlite3VdbeMemMove(pOut, pIn1); |
| 67421 | #ifdef SQLITE_DEBUG |
| 67422 | if( pOut->pScopyFrom>=&aMem[p1] && pOut->pScopyFrom<&aMem[p1+pOp->p3] ){ |
| 67423 | pOut->pScopyFrom += p1 - pOp->p2; |
| 67424 | } |
| 67425 | #endif |
| 67426 | pIn1->zMalloc = zMalloc; |
| 67427 | REGISTER_TRACE(p2++, pOut); |
| 67428 | pIn1++; |
| 67429 | pOut++; |
| 67430 | }while( n-- ); |
| 67431 | break; |
| 67432 | } |
| 67433 | |
| 67434 | /* Opcode: Copy P1 P2 P3 * * |
| 67435 | ** Synopsis: r[P2@P3+1]=r[P1@P3+1] |
| 67436 | ** |
| 67437 | ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3. |
| 67438 | ** |
| 67439 | ** This instruction makes a deep copy of the value. A duplicate |
| 67440 | ** is made of any string or blob constant. See also OP_SCopy. |
| 67441 | */ |
| 67442 | case OP_Copy: { |
| 67443 | int n; |
| 67444 | |
| 67445 | n = pOp->p3; |
| 67446 | pIn1 = &aMem[pOp->p1]; |
| 67447 | pOut = &aMem[pOp->p2]; |
| 67448 | assert( pOut!=pIn1 ); |
| 67449 | while( 1 ){ |
| 67450 | sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); |
| 67451 | Deephemeralize(pOut); |
| 67452 | #ifdef SQLITE_DEBUG |
| 67453 | pOut->pScopyFrom = 0; |
| 67454 | #endif |
| 67455 | REGISTER_TRACE(pOp->p2+pOp->p3-n, pOut); |
| 67456 | if( (n--)==0 ) break; |
| 67457 | pOut++; |
| 67458 | pIn1++; |
| 67459 | } |
| 67460 | break; |
| 67461 | } |
| @@ -67492,12 +67719,14 @@ | |
| 67492 | ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt |
| 67493 | ** structure to provide access to the top P1 values as the result |
| 67494 | ** row. |
| 67495 | */ |
| 67496 | case OP_ResultRow: { |
| 67497 | Mem *pMem; |
| 67498 | int i; |
| 67499 | assert( p->nResColumn==pOp->p2 ); |
| 67500 | assert( pOp->p1>0 ); |
| 67501 | assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 ); |
| 67502 | |
| 67503 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| @@ -67519,12 +67748,12 @@ | |
| 67519 | assert( db->flags&SQLITE_CountRows ); |
| 67520 | assert( p->usesStmtJournal ); |
| 67521 | break; |
| 67522 | } |
| 67523 | |
| 67524 | /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then |
| 67525 | ** DML statements invoke this opcode to return the number of rows |
| 67526 | ** modified to the user. This is the only way that a VM that |
| 67527 | ** opens a statement transaction may invoke this opcode. |
| 67528 | ** |
| 67529 | ** In case this is such a statement, close any statement transaction |
| 67530 | ** opened by this VM before returning control to the user. This is to |
| @@ -67547,19 +67776,19 @@ | |
| 67547 | |
| 67548 | /* Make sure the results of the current row are \000 terminated |
| 67549 | ** and have an assigned type. The results are de-ephemeralized as |
| 67550 | ** a side effect. |
| 67551 | */ |
| 67552 | pMem = p->pResultSet = &aMem[pOp->p1]; |
| 67553 | for(i=0; i<pOp->p2; i++){ |
| 67554 | assert( memIsValid(&pMem[i]) ); |
| 67555 | Deephemeralize(&pMem[i]); |
| 67556 | assert( (pMem[i].flags & MEM_Ephem)==0 |
| 67557 | || (pMem[i].flags & (MEM_Str|MEM_Blob))==0 ); |
| 67558 | sqlite3VdbeMemNulTerminate(&pMem[i]); |
| 67559 | sqlite3VdbeMemStoreType(&pMem[i]); |
| 67560 | REGISTER_TRACE(pOp->p1+i, &pMem[i]); |
| 67561 | } |
| 67562 | if( db->mallocFailed ) goto no_mem; |
| 67563 | |
| 67564 | /* Return SQLITE_ROW |
| 67565 | */ |
| @@ -67580,11 +67809,13 @@ | |
| 67580 | ** It is illegal for P1 and P3 to be the same register. Sometimes, |
| 67581 | ** if P3 is the same register as P2, the implementation is able |
| 67582 | ** to avoid a memcpy(). |
| 67583 | */ |
| 67584 | case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */ |
| 67585 | i64 nByte; |
| 67586 | |
| 67587 | pIn1 = &aMem[pOp->p1]; |
| 67588 | pIn2 = &aMem[pOp->p2]; |
| 67589 | pOut = &aMem[pOp->p3]; |
| 67590 | assert( pIn1!=pOut ); |
| @@ -67593,26 +67824,26 @@ | |
| 67593 | break; |
| 67594 | } |
| 67595 | if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem; |
| 67596 | Stringify(pIn1, encoding); |
| 67597 | Stringify(pIn2, encoding); |
| 67598 | nByte = pIn1->n + pIn2->n; |
| 67599 | if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 67600 | goto too_big; |
| 67601 | } |
| 67602 | MemSetTypeFlag(pOut, MEM_Str); |
| 67603 | if( sqlite3VdbeMemGrow(pOut, (int)nByte+2, pOut==pIn2) ){ |
| 67604 | goto no_mem; |
| 67605 | } |
| 67606 | if( pOut!=pIn2 ){ |
| 67607 | memcpy(pOut->z, pIn2->z, pIn2->n); |
| 67608 | } |
| 67609 | memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n); |
| 67610 | pOut->z[nByte]=0; |
| 67611 | pOut->z[nByte+1] = 0; |
| 67612 | pOut->flags |= MEM_Term; |
| 67613 | pOut->n = (int)nByte; |
| 67614 | pOut->enc = encoding; |
| 67615 | UPDATE_MAX_BLOBSIZE(pOut); |
| 67616 | break; |
| 67617 | } |
| 67618 | |
| @@ -67657,81 +67888,83 @@ | |
| 67657 | case OP_Add: /* same as TK_PLUS, in1, in2, out3 */ |
| 67658 | case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */ |
| 67659 | case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */ |
| 67660 | case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */ |
| 67661 | case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ |
| 67662 | char bIntint; /* Started out as two integer operands */ |
| 67663 | int flags; /* Combined MEM_* flags from both inputs */ |
| 67664 | i64 iA; /* Integer value of left operand */ |
| 67665 | i64 iB; /* Integer value of right operand */ |
| 67666 | double rA; /* Real value of left operand */ |
| 67667 | double rB; /* Real value of right operand */ |
| 67668 | |
| 67669 | pIn1 = &aMem[pOp->p1]; |
| 67670 | applyNumericAffinity(pIn1); |
| 67671 | pIn2 = &aMem[pOp->p2]; |
| 67672 | applyNumericAffinity(pIn2); |
| 67673 | pOut = &aMem[pOp->p3]; |
| 67674 | flags = pIn1->flags | pIn2->flags; |
| 67675 | if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; |
| 67676 | if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ |
| 67677 | iA = pIn1->u.i; |
| 67678 | iB = pIn2->u.i; |
| 67679 | bIntint = 1; |
| 67680 | switch( pOp->opcode ){ |
| 67681 | case OP_Add: if( sqlite3AddInt64(&iB,iA) ) goto fp_math; break; |
| 67682 | case OP_Subtract: if( sqlite3SubInt64(&iB,iA) ) goto fp_math; break; |
| 67683 | case OP_Multiply: if( sqlite3MulInt64(&iB,iA) ) goto fp_math; break; |
| 67684 | case OP_Divide: { |
| 67685 | if( iA==0 ) goto arithmetic_result_is_null; |
| 67686 | if( iA==-1 && iB==SMALLEST_INT64 ) goto fp_math; |
| 67687 | iB /= iA; |
| 67688 | break; |
| 67689 | } |
| 67690 | default: { |
| 67691 | if( iA==0 ) goto arithmetic_result_is_null; |
| 67692 | if( iA==-1 ) iA = 1; |
| 67693 | iB %= iA; |
| 67694 | break; |
| 67695 | } |
| 67696 | } |
| 67697 | pOut->u.i = iB; |
| 67698 | MemSetTypeFlag(pOut, MEM_Int); |
| 67699 | }else{ |
| 67700 | bIntint = 0; |
| 67701 | fp_math: |
| 67702 | rA = sqlite3VdbeRealValue(pIn1); |
| 67703 | rB = sqlite3VdbeRealValue(pIn2); |
| 67704 | switch( pOp->opcode ){ |
| 67705 | case OP_Add: rB += rA; break; |
| 67706 | case OP_Subtract: rB -= rA; break; |
| 67707 | case OP_Multiply: rB *= rA; break; |
| 67708 | case OP_Divide: { |
| 67709 | /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ |
| 67710 | if( rA==(double)0 ) goto arithmetic_result_is_null; |
| 67711 | rB /= rA; |
| 67712 | break; |
| 67713 | } |
| 67714 | default: { |
| 67715 | iA = (i64)rA; |
| 67716 | iB = (i64)rB; |
| 67717 | if( iA==0 ) goto arithmetic_result_is_null; |
| 67718 | if( iA==-1 ) iA = 1; |
| 67719 | rB = (double)(iB % iA); |
| 67720 | break; |
| 67721 | } |
| 67722 | } |
| 67723 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 67724 | pOut->u.i = rB; |
| 67725 | MemSetTypeFlag(pOut, MEM_Int); |
| 67726 | #else |
| 67727 | if( sqlite3IsNaN(rB) ){ |
| 67728 | goto arithmetic_result_is_null; |
| 67729 | } |
| 67730 | pOut->r = rB; |
| 67731 | MemSetTypeFlag(pOut, MEM_Real); |
| 67732 | if( (flags & MEM_Real)==0 && !bIntint ){ |
| 67733 | sqlite3VdbeIntegerAffinity(pOut); |
| 67734 | } |
| 67735 | #endif |
| 67736 | } |
| 67737 | break; |
| @@ -67780,83 +68013,85 @@ | |
| 67780 | ** invocation of this opcode. |
| 67781 | ** |
| 67782 | ** See also: AggStep and AggFinal |
| 67783 | */ |
| 67784 | case OP_Function: { |
| 67785 | int i; |
| 67786 | Mem *pArg; |
| 67787 | sqlite3_context ctx; |
| 67788 | sqlite3_value **apVal; |
| 67789 | int n; |
| 67790 | |
| 67791 | n = pOp->p5; |
| 67792 | apVal = p->apArg; |
| 67793 | assert( apVal || n==0 ); |
| 67794 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 67795 | pOut = &aMem[pOp->p3]; |
| 67796 | memAboutToChange(p, pOut); |
| 67797 | |
| 67798 | assert( n==0 || (pOp->p2>0 && pOp->p2+n<=(p->nMem-p->nCursor)+1) ); |
| 67799 | assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+n ); |
| 67800 | pArg = &aMem[pOp->p2]; |
| 67801 | for(i=0; i<n; i++, pArg++){ |
| 67802 | assert( memIsValid(pArg) ); |
| 67803 | apVal[i] = pArg; |
| 67804 | Deephemeralize(pArg); |
| 67805 | sqlite3VdbeMemStoreType(pArg); |
| 67806 | REGISTER_TRACE(pOp->p2+i, pArg); |
| 67807 | } |
| 67808 | |
| 67809 | assert( pOp->p4type==P4_FUNCDEF ); |
| 67810 | ctx.pFunc = pOp->p4.pFunc; |
| 67811 | ctx.iOp = pc; |
| 67812 | ctx.pVdbe = p; |
| 67813 | |
| 67814 | /* The output cell may already have a buffer allocated. Move |
| 67815 | ** the pointer to ctx.s so in case the user-function can use |
| 67816 | ** the already allocated buffer instead of allocating a new one. |
| 67817 | */ |
| 67818 | memcpy(&ctx.s, pOut, sizeof(Mem)); |
| 67819 | pOut->flags = MEM_Null; |
| 67820 | pOut->xDel = 0; |
| 67821 | pOut->zMalloc = 0; |
| 67822 | MemSetTypeFlag(&ctx.s, MEM_Null); |
| 67823 | |
| 67824 | ctx.fErrorOrAux = 0; |
| 67825 | if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 67826 | assert( pOp>aOp ); |
| 67827 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 67828 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 67829 | ctx.pColl = pOp[-1].p4.pColl; |
| 67830 | } |
| 67831 | db->lastRowid = lastRowid; |
| 67832 | (*ctx.pFunc->xFunc)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| 67833 | lastRowid = db->lastRowid; |
| 67834 | |
| 67835 | if( db->mallocFailed ){ |
| 67836 | /* Even though a malloc() has failed, the implementation of the |
| 67837 | ** user function may have called an sqlite3_result_XXX() function |
| 67838 | ** to return a value. The following call releases any resources |
| 67839 | ** associated with such a value. |
| 67840 | */ |
| 67841 | sqlite3VdbeMemRelease(&ctx.s); |
| 67842 | goto no_mem; |
| 67843 | } |
| 67844 | |
| 67845 | /* If the function returned an error, throw an exception */ |
| 67846 | if( ctx.fErrorOrAux ){ |
| 67847 | if( ctx.isError ){ |
| 67848 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); |
| 67849 | rc = ctx.isError; |
| 67850 | } |
| 67851 | sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 67852 | } |
| 67853 | |
| 67854 | /* Copy the result of the function into register P3 */ |
| 67855 | sqlite3VdbeChangeEncoding(&ctx.s, encoding); |
| 67856 | assert( pOut->flags==MEM_Null ); |
| 67857 | memcpy(pOut, &ctx.s, sizeof(Mem)); |
| 67858 | if( sqlite3VdbeMemTooBig(pOut) ){ |
| 67859 | goto too_big; |
| 67860 | } |
| 67861 | |
| 67862 | #if 0 |
| @@ -67904,54 +68139,56 @@ | |
| 67904 | */ |
| 67905 | case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */ |
| 67906 | case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */ |
| 67907 | case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */ |
| 67908 | case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */ |
| 67909 | i64 iA; |
| 67910 | u64 uA; |
| 67911 | i64 iB; |
| 67912 | u8 op; |
| 67913 | |
| 67914 | pIn1 = &aMem[pOp->p1]; |
| 67915 | pIn2 = &aMem[pOp->p2]; |
| 67916 | pOut = &aMem[pOp->p3]; |
| 67917 | if( (pIn1->flags | pIn2->flags) & MEM_Null ){ |
| 67918 | sqlite3VdbeMemSetNull(pOut); |
| 67919 | break; |
| 67920 | } |
| 67921 | iA = sqlite3VdbeIntValue(pIn2); |
| 67922 | iB = sqlite3VdbeIntValue(pIn1); |
| 67923 | op = pOp->opcode; |
| 67924 | if( op==OP_BitAnd ){ |
| 67925 | iA &= iB; |
| 67926 | }else if( op==OP_BitOr ){ |
| 67927 | iA |= iB; |
| 67928 | }else if( iB!=0 ){ |
| 67929 | assert( op==OP_ShiftRight || op==OP_ShiftLeft ); |
| 67930 | |
| 67931 | /* If shifting by a negative amount, shift in the other direction */ |
| 67932 | if( iB<0 ){ |
| 67933 | assert( OP_ShiftRight==OP_ShiftLeft+1 ); |
| 67934 | op = 2*OP_ShiftLeft + 1 - op; |
| 67935 | iB = iB>(-64) ? -iB : 64; |
| 67936 | } |
| 67937 | |
| 67938 | if( iB>=64 ){ |
| 67939 | iA = (iA>=0 || op==OP_ShiftLeft) ? 0 : -1; |
| 67940 | }else{ |
| 67941 | memcpy(&uA, &iA, sizeof(uA)); |
| 67942 | if( op==OP_ShiftLeft ){ |
| 67943 | uA <<= iB; |
| 67944 | }else{ |
| 67945 | uA >>= iB; |
| 67946 | /* Sign-extend on a right shift of a negative number */ |
| 67947 | if( iA<0 ) uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-iB); |
| 67948 | } |
| 67949 | memcpy(&iA, &uA, sizeof(iA)); |
| 67950 | } |
| 67951 | } |
| 67952 | pOut->u.i = iA; |
| 67953 | MemSetTypeFlag(pOut, MEM_Int); |
| 67954 | break; |
| 67955 | } |
| 67956 | |
| 67957 | /* Opcode: AddImm P1 P2 * * * |
| @@ -68201,35 +68438,37 @@ | |
| 68201 | case OP_Ne: /* same as TK_NE, jump, in1, in3 */ |
| 68202 | case OP_Lt: /* same as TK_LT, jump, in1, in3 */ |
| 68203 | case OP_Le: /* same as TK_LE, jump, in1, in3 */ |
| 68204 | case OP_Gt: /* same as TK_GT, jump, in1, in3 */ |
| 68205 | case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ |
| 68206 | int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 68207 | char affinity; /* Affinity to use for comparison */ |
| 68208 | u16 flags1; /* Copy of initial value of pIn1->flags */ |
| 68209 | u16 flags3; /* Copy of initial value of pIn3->flags */ |
| 68210 | |
| 68211 | pIn1 = &aMem[pOp->p1]; |
| 68212 | pIn3 = &aMem[pOp->p3]; |
| 68213 | flags1 = pIn1->flags; |
| 68214 | flags3 = pIn3->flags; |
| 68215 | if( (flags1 | flags3)&MEM_Null ){ |
| 68216 | /* One or both operands are NULL */ |
| 68217 | if( pOp->p5 & SQLITE_NULLEQ ){ |
| 68218 | /* If SQLITE_NULLEQ is set (which will only happen if the operator is |
| 68219 | ** OP_Eq or OP_Ne) then take the jump or not depending on whether |
| 68220 | ** or not both operands are null. |
| 68221 | */ |
| 68222 | assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne ); |
| 68223 | assert( (flags1 & MEM_Cleared)==0 ); |
| 68224 | if( (flags1&MEM_Null)!=0 |
| 68225 | && (flags3&MEM_Null)!=0 |
| 68226 | && (flags3&MEM_Cleared)==0 |
| 68227 | ){ |
| 68228 | res = 0; /* Results are equal */ |
| 68229 | }else{ |
| 68230 | res = 1; /* Results are not equal */ |
| 68231 | } |
| 68232 | }else{ |
| 68233 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 68234 | ** then the result is always NULL. |
| 68235 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| @@ -68243,44 +68482,44 @@ | |
| 68243 | } |
| 68244 | break; |
| 68245 | } |
| 68246 | }else{ |
| 68247 | /* Neither operand is NULL. Do a comparison. */ |
| 68248 | affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 68249 | if( affinity ){ |
| 68250 | applyAffinity(pIn1, affinity, encoding); |
| 68251 | applyAffinity(pIn3, affinity, encoding); |
| 68252 | if( db->mallocFailed ) goto no_mem; |
| 68253 | } |
| 68254 | |
| 68255 | assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); |
| 68256 | ExpandBlob(pIn1); |
| 68257 | ExpandBlob(pIn3); |
| 68258 | res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); |
| 68259 | } |
| 68260 | switch( pOp->opcode ){ |
| 68261 | case OP_Eq: res = res==0; break; |
| 68262 | case OP_Ne: res = res!=0; break; |
| 68263 | case OP_Lt: res = res<0; break; |
| 68264 | case OP_Le: res = res<=0; break; |
| 68265 | case OP_Gt: res = res>0; break; |
| 68266 | default: res = res>=0; break; |
| 68267 | } |
| 68268 | |
| 68269 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 68270 | pOut = &aMem[pOp->p2]; |
| 68271 | memAboutToChange(p, pOut); |
| 68272 | MemSetTypeFlag(pOut, MEM_Int); |
| 68273 | pOut->u.i = res; |
| 68274 | REGISTER_TRACE(pOp->p2, pOut); |
| 68275 | }else if( res ){ |
| 68276 | pc = pOp->p2-1; |
| 68277 | } |
| 68278 | |
| 68279 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 68280 | pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask); |
| 68281 | pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask); |
| 68282 | break; |
| 68283 | } |
| 68284 | |
| 68285 | /* Opcode: Permutation * * * P4 * |
| 68286 | ** |
| @@ -68316,49 +68555,51 @@ | |
| 68316 | ** The comparison is a sort comparison, so NULLs compare equal, |
| 68317 | ** NULLs are less than numbers, numbers are less than strings, |
| 68318 | ** and strings are less than blobs. |
| 68319 | */ |
| 68320 | case OP_Compare: { |
| 68321 | int n; |
| 68322 | int i; |
| 68323 | int p1; |
| 68324 | int p2; |
| 68325 | const KeyInfo *pKeyInfo; |
| 68326 | int idx; |
| 68327 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 68328 | int bRev; /* True for DESCENDING sort order */ |
| 68329 | |
| 68330 | if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; |
| 68331 | n = pOp->p3; |
| 68332 | pKeyInfo = pOp->p4.pKeyInfo; |
| 68333 | assert( n>0 ); |
| 68334 | assert( pKeyInfo!=0 ); |
| 68335 | p1 = pOp->p1; |
| 68336 | p2 = pOp->p2; |
| 68337 | #if SQLITE_DEBUG |
| 68338 | if( aPermute ){ |
| 68339 | int k, mx = 0; |
| 68340 | for(k=0; k<n; k++) if( aPermute[k]>mx ) mx = aPermute[k]; |
| 68341 | assert( p1>0 && p1+mx<=(p->nMem-p->nCursor)+1 ); |
| 68342 | assert( p2>0 && p2+mx<=(p->nMem-p->nCursor)+1 ); |
| 68343 | }else{ |
| 68344 | assert( p1>0 && p1+n<=(p->nMem-p->nCursor)+1 ); |
| 68345 | assert( p2>0 && p2+n<=(p->nMem-p->nCursor)+1 ); |
| 68346 | } |
| 68347 | #endif /* SQLITE_DEBUG */ |
| 68348 | for(i=0; i<n; i++){ |
| 68349 | idx = aPermute ? aPermute[i] : i; |
| 68350 | assert( memIsValid(&aMem[p1+idx]) ); |
| 68351 | assert( memIsValid(&aMem[p2+idx]) ); |
| 68352 | REGISTER_TRACE(p1+idx, &aMem[p1+idx]); |
| 68353 | REGISTER_TRACE(p2+idx, &aMem[p2+idx]); |
| 68354 | assert( i<pKeyInfo->nField ); |
| 68355 | pColl = pKeyInfo->aColl[i]; |
| 68356 | bRev = pKeyInfo->aSortOrder[i]; |
| 68357 | iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl); |
| 68358 | if( iCompare ){ |
| 68359 | if( bRev ) iCompare = -iCompare; |
| 68360 | break; |
| 68361 | } |
| 68362 | } |
| 68363 | aPermute = 0; |
| 68364 | break; |
| @@ -68401,37 +68642,39 @@ | |
| 68401 | ** even if the other input is NULL. A NULL and false or two NULLs |
| 68402 | ** give a NULL output. |
| 68403 | */ |
| 68404 | case OP_And: /* same as TK_AND, in1, in2, out3 */ |
| 68405 | case OP_Or: { /* same as TK_OR, in1, in2, out3 */ |
| 68406 | int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 68407 | int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 68408 | |
| 68409 | pIn1 = &aMem[pOp->p1]; |
| 68410 | if( pIn1->flags & MEM_Null ){ |
| 68411 | v1 = 2; |
| 68412 | }else{ |
| 68413 | v1 = sqlite3VdbeIntValue(pIn1)!=0; |
| 68414 | } |
| 68415 | pIn2 = &aMem[pOp->p2]; |
| 68416 | if( pIn2->flags & MEM_Null ){ |
| 68417 | v2 = 2; |
| 68418 | }else{ |
| 68419 | v2 = sqlite3VdbeIntValue(pIn2)!=0; |
| 68420 | } |
| 68421 | if( pOp->opcode==OP_And ){ |
| 68422 | static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 }; |
| 68423 | v1 = and_logic[v1*3+v2]; |
| 68424 | }else{ |
| 68425 | static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 }; |
| 68426 | v1 = or_logic[v1*3+v2]; |
| 68427 | } |
| 68428 | pOut = &aMem[pOp->p3]; |
| 68429 | if( v1==2 ){ |
| 68430 | MemSetTypeFlag(pOut, MEM_Null); |
| 68431 | }else{ |
| 68432 | pOut->u.i = v1; |
| 68433 | MemSetTypeFlag(pOut, MEM_Int); |
| 68434 | } |
| 68435 | break; |
| 68436 | } |
| 68437 | |
| @@ -68498,23 +68741,25 @@ | |
| 68498 | ** is considered false if it has a numeric value of zero. If the value |
| 68499 | ** in P1 is NULL then take the jump if P3 is zero. |
| 68500 | */ |
| 68501 | case OP_If: /* jump, in1 */ |
| 68502 | case OP_IfNot: { /* jump, in1 */ |
| 68503 | int c; |
| 68504 | pIn1 = &aMem[pOp->p1]; |
| 68505 | if( pIn1->flags & MEM_Null ){ |
| 68506 | c = pOp->p3; |
| 68507 | }else{ |
| 68508 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 68509 | c = sqlite3VdbeIntValue(pIn1)!=0; |
| 68510 | #else |
| 68511 | c = sqlite3VdbeRealValue(pIn1)!=0.0; |
| 68512 | #endif |
| 68513 | if( pOp->opcode==OP_IfNot ) c = !c; |
| 68514 | } |
| 68515 | if( c ){ |
| 68516 | pc = pOp->p2-1; |
| 68517 | } |
| 68518 | break; |
| 68519 | } |
| 68520 | |
| @@ -68568,10 +68813,11 @@ | |
| 68568 | ** the result is guaranteed to only be used as the argument of a length() |
| 68569 | ** or typeof() function, respectively. The loading of large blobs can be |
| 68570 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 68571 | */ |
| 68572 | case OP_Column: { |
| 68573 | i64 payloadSize64; /* Number of bytes in the record */ |
| 68574 | int p2; /* column number to retrieve */ |
| 68575 | VdbeCursor *pC; /* The VDBE cursor */ |
| 68576 | BtCursor *pCrsr; /* The BTree cursor */ |
| 68577 | u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| @@ -68586,88 +68832,89 @@ | |
| 68586 | u32 offset; /* Offset into the data */ |
| 68587 | u32 szField; /* Number of bytes in the content of a field */ |
| 68588 | u32 avail; /* Number of bytes of available data */ |
| 68589 | u32 t; /* A type code from the record header */ |
| 68590 | Mem *pReg; /* PseudoTable input register */ |
| 68591 | |
| 68592 | p2 = pOp->p2; |
| 68593 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68594 | pDest = &aMem[pOp->p3]; |
| 68595 | memAboutToChange(p, pDest); |
| 68596 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 68597 | pC = p->apCsr[pOp->p1]; |
| 68598 | assert( pC!=0 ); |
| 68599 | assert( p2<pC->nField ); |
| 68600 | aType = pC->aType; |
| 68601 | aOffset = aType + pC->nField; |
| 68602 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 68603 | assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ |
| 68604 | #endif |
| 68605 | pCrsr = pC->pCursor; |
| 68606 | assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */ |
| 68607 | assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */ |
| 68608 | |
| 68609 | /* If the cursor cache is stale, bring it up-to-date */ |
| 68610 | rc = sqlite3VdbeCursorMoveto(pC); |
| 68611 | if( rc ) goto abort_due_to_error; |
| 68612 | if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){ |
| 68613 | if( pC->nullRow ){ |
| 68614 | if( pCrsr==0 ){ |
| 68615 | assert( pC->pseudoTableReg>0 ); |
| 68616 | pReg = &aMem[pC->pseudoTableReg]; |
| 68617 | if( pC->multiPseudo ){ |
| 68618 | sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem); |
| 68619 | Deephemeralize(pDest); |
| 68620 | goto op_column_out; |
| 68621 | } |
| 68622 | assert( pReg->flags & MEM_Blob ); |
| 68623 | assert( memIsValid(pReg) ); |
| 68624 | pC->payloadSize = pC->szRow = avail = pReg->n; |
| 68625 | pC->aRow = (u8*)pReg->z; |
| 68626 | }else{ |
| 68627 | MemSetTypeFlag(pDest, MEM_Null); |
| 68628 | goto op_column_out; |
| 68629 | } |
| 68630 | }else{ |
| 68631 | assert( pCrsr ); |
| 68632 | if( pC->isTable==0 ){ |
| 68633 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 68634 | VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &payloadSize64); |
| 68635 | assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 68636 | /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the |
| 68637 | ** payload size, so it is impossible for payloadSize64 to be |
| 68638 | ** larger than 32 bits. */ |
| 68639 | assert( (payloadSize64 & SQLITE_MAX_U32)==(u64)payloadSize64 ); |
| 68640 | pC->aRow = sqlite3BtreeKeyFetch(pCrsr, &avail); |
| 68641 | pC->payloadSize = (u32)payloadSize64; |
| 68642 | }else{ |
| 68643 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 68644 | VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &pC->payloadSize); |
| 68645 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 68646 | pC->aRow = sqlite3BtreeDataFetch(pCrsr, &avail); |
| 68647 | } |
| 68648 | assert( avail<=65536 ); /* Maximum page size is 64KiB */ |
| 68649 | if( pC->payloadSize <= (u32)avail ){ |
| 68650 | pC->szRow = pC->payloadSize; |
| 68651 | }else{ |
| 68652 | pC->szRow = avail; |
| 68653 | } |
| 68654 | if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 68655 | goto too_big; |
| 68656 | } |
| 68657 | } |
| 68658 | pC->cacheStatus = p->cacheCtr; |
| 68659 | pC->iHdrOffset = getVarint32(pC->aRow, offset); |
| 68660 | pC->nHdrParsed = 0; |
| 68661 | aOffset[0] = offset; |
| 68662 | if( avail<offset ){ |
| 68663 | /* pC->aRow does not have to hold the entire row, but it does at least |
| 68664 | ** need to cover the header of the record. If pC->aRow does not contain |
| 68665 | ** the complete header, then set it to zero, forcing the header to be |
| 68666 | ** dynamically allocated. */ |
| 68667 | pC->aRow = 0; |
| 68668 | pC->szRow = 0; |
| 68669 | } |
| 68670 | |
| 68671 | /* Make sure a corrupt database has not given us an oversize header. |
| 68672 | ** Do this now to avoid an oversize memory allocation. |
| 68673 | ** |
| @@ -68675,154 +68922,154 @@ | |
| 68675 | ** types use so much data space that there can only be 4096 and 32 of |
| 68676 | ** them, respectively. So the maximum header length results from a |
| 68677 | ** 3-byte type for each of the maximum of 32768 columns plus three |
| 68678 | ** extra bytes for the header length itself. 32768*3 + 3 = 98307. |
| 68679 | */ |
| 68680 | if( offset > 98307 || offset > pC->payloadSize ){ |
| 68681 | rc = SQLITE_CORRUPT_BKPT; |
| 68682 | goto op_column_error; |
| 68683 | } |
| 68684 | } |
| 68685 | |
| 68686 | /* Make sure at least the first p2+1 entries of the header have been |
| 68687 | ** parsed and valid information is in aOffset[] and aType[]. |
| 68688 | */ |
| 68689 | if( pC->nHdrParsed<=p2 ){ |
| 68690 | /* If there is more header available for parsing in the record, try |
| 68691 | ** to extract additional fields up through the p2+1-th field |
| 68692 | */ |
| 68693 | if( pC->iHdrOffset<aOffset[0] ){ |
| 68694 | /* Make sure zData points to enough of the record to cover the header. */ |
| 68695 | if( pC->aRow==0 ){ |
| 68696 | memset(&sMem, 0, sizeof(sMem)); |
| 68697 | rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], |
| 68698 | !pC->isTable, &sMem); |
| 68699 | if( rc!=SQLITE_OK ){ |
| 68700 | goto op_column_error; |
| 68701 | } |
| 68702 | zData = (u8*)sMem.z; |
| 68703 | }else{ |
| 68704 | zData = pC->aRow; |
| 68705 | } |
| 68706 | |
| 68707 | /* Fill in aType[i] and aOffset[i] values through the p2-th field. */ |
| 68708 | i = pC->nHdrParsed; |
| 68709 | offset = aOffset[i]; |
| 68710 | zHdr = zData + pC->iHdrOffset; |
| 68711 | zEndHdr = zData + aOffset[0]; |
| 68712 | assert( i<=p2 && zHdr<zEndHdr ); |
| 68713 | do{ |
| 68714 | if( zHdr[0]<0x80 ){ |
| 68715 | t = zHdr[0]; |
| 68716 | zHdr++; |
| 68717 | }else{ |
| 68718 | zHdr += sqlite3GetVarint32(zHdr, &t); |
| 68719 | } |
| 68720 | aType[i] = t; |
| 68721 | szField = sqlite3VdbeSerialTypeLen(t); |
| 68722 | offset += szField; |
| 68723 | if( offset<szField ){ /* True if offset overflows */ |
| 68724 | zHdr = &zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 68725 | break; |
| 68726 | } |
| 68727 | i++; |
| 68728 | aOffset[i] = offset; |
| 68729 | }while( i<=p2 && zHdr<zEndHdr ); |
| 68730 | pC->nHdrParsed = i; |
| 68731 | pC->iHdrOffset = (u32)(zHdr - zData); |
| 68732 | if( pC->aRow==0 ){ |
| 68733 | sqlite3VdbeMemRelease(&sMem); |
| 68734 | sMem.flags = MEM_Null; |
| 68735 | } |
| 68736 | |
| 68737 | /* If we have read more header data than was contained in the header, |
| 68738 | ** or if the end of the last field appears to be past the end of the |
| 68739 | ** record, or if the end of the last field appears to be before the end |
| 68740 | ** of the record (when all fields present), then we must be dealing |
| 68741 | ** with a corrupt database. |
| 68742 | */ |
| 68743 | if( (zHdr > zEndHdr) |
| 68744 | || (offset > pC->payloadSize) |
| 68745 | || (zHdr==zEndHdr && offset!=pC->payloadSize) |
| 68746 | ){ |
| 68747 | rc = SQLITE_CORRUPT_BKPT; |
| 68748 | goto op_column_error; |
| 68749 | } |
| 68750 | } |
| 68751 | |
| 68752 | /* If after trying to extra new entries from the header, nHdrParsed is |
| 68753 | ** still not up to p2, that means that the record has fewer than p2 |
| 68754 | ** columns. So the result will be either the default value or a NULL. |
| 68755 | */ |
| 68756 | if( pC->nHdrParsed<=p2 ){ |
| 68757 | if( pOp->p4type==P4_MEM ){ |
| 68758 | sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); |
| 68759 | }else{ |
| 68760 | MemSetTypeFlag(pDest, MEM_Null); |
| 68761 | } |
| 68762 | goto op_column_out; |
| 68763 | } |
| 68764 | } |
| 68765 | |
| 68766 | /* Extract the content for the p2+1-th column. Control can only |
| 68767 | ** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are |
| 68768 | ** all valid. |
| 68769 | */ |
| 68770 | assert( p2<pC->nHdrParsed ); |
| 68771 | assert( rc==SQLITE_OK ); |
| 68772 | if( pC->szRow>=aOffset[p2+1] ){ |
| 68773 | /* This is the common case where the desired content fits on the original |
| 68774 | ** page - where the content is not on an overflow page */ |
| 68775 | VdbeMemRelease(pDest); |
| 68776 | sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest); |
| 68777 | }else{ |
| 68778 | /* This branch happens only when content is on overflow pages */ |
| 68779 | t = aType[p2]; |
| 68780 | if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 68781 | && ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) |
| 68782 | || (len = sqlite3VdbeSerialTypeLen(t))==0 |
| 68783 | ){ |
| 68784 | /* Content is irrelevant for the typeof() function and for |
| 68785 | ** the length(X) function if X is a blob. So we might as well use |
| 68786 | ** bogus content rather than reading content from disk. NULL works |
| 68787 | ** for text and blob and whatever is in the payloadSize64 variable |
| 68788 | ** will work for everything else. Content is also irrelevant if |
| 68789 | ** the content length is 0. */ |
| 68790 | zData = t<=13 ? (u8*)&payloadSize64 : 0; |
| 68791 | sMem.zMalloc = 0; |
| 68792 | }else{ |
| 68793 | memset(&sMem, 0, sizeof(sMem)); |
| 68794 | sqlite3VdbeMemMove(&sMem, pDest); |
| 68795 | rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable, |
| 68796 | &sMem); |
| 68797 | if( rc!=SQLITE_OK ){ |
| 68798 | goto op_column_error; |
| 68799 | } |
| 68800 | zData = (u8*)sMem.z; |
| 68801 | } |
| 68802 | sqlite3VdbeSerialGet(zData, t, pDest); |
| 68803 | /* If we dynamically allocated space to hold the data (in the |
| 68804 | ** sqlite3VdbeMemFromBtree() call above) then transfer control of that |
| 68805 | ** dynamically allocated space over to the pDest structure. |
| 68806 | ** This prevents a memory copy. */ |
| 68807 | if( sMem.zMalloc ){ |
| 68808 | assert( sMem.z==sMem.zMalloc ); |
| 68809 | assert( !(pDest->flags & MEM_Dyn) ); |
| 68810 | assert( !(pDest->flags & (MEM_Blob|MEM_Str)) || pDest->z==sMem.z ); |
| 68811 | pDest->flags &= ~(MEM_Ephem|MEM_Static); |
| 68812 | pDest->flags |= MEM_Term; |
| 68813 | pDest->z = sMem.z; |
| 68814 | pDest->zMalloc = sMem.zMalloc; |
| 68815 | } |
| 68816 | } |
| 68817 | pDest->enc = encoding; |
| 68818 | |
| 68819 | op_column_out: |
| 68820 | Deephemeralize(pDest); |
| 68821 | op_column_error: |
| 68822 | UPDATE_MAX_BLOBSIZE(pDest); |
| 68823 | REGISTER_TRACE(pOp->p3, pDest); |
| 68824 | break; |
| 68825 | } |
| 68826 | |
| 68827 | /* Opcode: Affinity P1 P2 * P4 * |
| 68828 | ** Synopsis: affinity(r[P1@P2]) |
| @@ -68832,22 +69079,24 @@ | |
| 68832 | ** P4 is a string that is P2 characters long. The nth character of the |
| 68833 | ** string indicates the column affinity that should be used for the nth |
| 68834 | ** memory cell in the range. |
| 68835 | */ |
| 68836 | case OP_Affinity: { |
| 68837 | const char *zAffinity; /* The affinity to be applied */ |
| 68838 | char cAff; /* A single character of affinity */ |
| 68839 | |
| 68840 | zAffinity = pOp->p4.z; |
| 68841 | assert( zAffinity!=0 ); |
| 68842 | assert( zAffinity[pOp->p2]==0 ); |
| 68843 | pIn1 = &aMem[pOp->p1]; |
| 68844 | while( (cAff = *(zAffinity++))!=0 ){ |
| 68845 | assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] ); |
| 68846 | assert( memIsValid(pIn1) ); |
| 68847 | ExpandBlob(pIn1); |
| 68848 | applyAffinity(pIn1, cAff, encoding); |
| 68849 | pIn1++; |
| 68850 | } |
| 68851 | break; |
| 68852 | } |
| 68853 | |
| @@ -68866,10 +69115,11 @@ | |
| 68866 | ** macros defined in sqliteInt.h. |
| 68867 | ** |
| 68868 | ** If P4 is NULL then all index fields have the affinity NONE. |
| 68869 | */ |
| 68870 | case OP_MakeRecord: { |
| 68871 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 68872 | Mem *pRec; /* The new record */ |
| 68873 | u64 nData; /* Number of bytes of data space */ |
| 68874 | int nHdr; /* Number of bytes of header space */ |
| 68875 | i64 nByte; /* Data space required for this record */ |
| @@ -68879,123 +69129,106 @@ | |
| 68879 | Mem *pData0; /* First field to be combined into the record */ |
| 68880 | Mem *pLast; /* Last field of the record */ |
| 68881 | int nField; /* Number of fields in the record */ |
| 68882 | char *zAffinity; /* The affinity string for the record */ |
| 68883 | int file_format; /* File format to use for encoding */ |
| 68884 | int i; /* Space used in zNewRecord[] header */ |
| 68885 | int j; /* Space used in zNewRecord[] content */ |
| 68886 | int len; /* Length of a field */ |
| 68887 | |
| 68888 | /* Assuming the record contains N fields, the record format looks |
| 68889 | ** like this: |
| 68890 | ** |
| 68891 | ** ------------------------------------------------------------------------ |
| 68892 | ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | |
| 68893 | ** ------------------------------------------------------------------------ |
| 68894 | ** |
| 68895 | ** Data(0) is taken from register P1. Data(1) comes from register P1+1 |
| 68896 | ** and so froth. |
| 68897 | ** |
| 68898 | ** Each type field is a varint representing the serial type of the |
| 68899 | ** corresponding data element (see sqlite3VdbeSerialType()). The |
| 68900 | ** hdr-size field is also a varint which is the offset from the beginning |
| 68901 | ** of the record to data0. |
| 68902 | */ |
| 68903 | nData = 0; /* Number of bytes of data space */ |
| 68904 | nHdr = 0; /* Number of bytes of header space */ |
| 68905 | nZero = 0; /* Number of zero bytes at the end of the record */ |
| 68906 | nField = pOp->p1; |
| 68907 | zAffinity = pOp->p4.z; |
| 68908 | assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem-p->nCursor)+1 ); |
| 68909 | pData0 = &aMem[nField]; |
| 68910 | nField = pOp->p2; |
| 68911 | pLast = &pData0[nField-1]; |
| 68912 | file_format = p->minWriteFileFormat; |
| 68913 | |
| 68914 | /* Identify the output register */ |
| 68915 | assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); |
| 68916 | pOut = &aMem[pOp->p3]; |
| 68917 | memAboutToChange(p, pOut); |
| 68918 | |
| 68919 | /* Apply the requested affinity to all inputs |
| 68920 | */ |
| 68921 | assert( pData0<=pLast ); |
| 68922 | if( zAffinity ){ |
| 68923 | pRec = pData0; |
| 68924 | do{ |
| 68925 | applyAffinity(pRec, *(zAffinity++), encoding); |
| 68926 | }while( (++pRec)<=pLast ); |
| 68927 | } |
| 68928 | |
| 68929 | /* Loop through the elements that will make up the record to figure |
| 68930 | ** out how much space is required for the new record. |
| 68931 | */ |
| 68932 | pRec = pLast; |
| 68933 | do{ |
| 68934 | assert( memIsValid(pRec) ); |
| 68935 | serial_type = sqlite3VdbeSerialType(pRec, file_format); |
| 68936 | len = sqlite3VdbeSerialTypeLen(serial_type); |
| 68937 | if( pRec->flags & MEM_Zero ){ |
| 68938 | if( nData ){ |
| 68939 | sqlite3VdbeMemExpandBlob(pRec); |
| 68940 | }else{ |
| 68941 | nZero += pRec->u.nZero; |
| 68942 | len -= pRec->u.nZero; |
| 68943 | } |
| 68944 | } |
| 68945 | nData += len; |
| 68946 | testcase( serial_type==127 ); |
| 68947 | testcase( serial_type==128 ); |
| 68948 | nHdr += serial_type<=127 ? 1 : sqlite3VarintLen(serial_type); |
| 68949 | }while( (--pRec)>=pData0 ); |
| 68950 | |
| 68951 | /* Add the initial header varint and total the size */ |
| 68952 | testcase( nHdr==126 ); |
| 68953 | testcase( nHdr==127 ); |
| 68954 | if( nHdr<=126 ){ |
| 68955 | /* The common case */ |
| 68956 | nHdr += 1; |
| 68957 | }else{ |
| 68958 | /* Rare case of a really large header */ |
| 68959 | nVarint = sqlite3VarintLen(nHdr); |
| 68960 | nHdr += nVarint; |
| 68961 | if( nVarint<sqlite3VarintLen(nHdr) ) nHdr++; |
| 68962 | } |
| 68963 | nByte = nHdr+nData; |
| 68964 | if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 68965 | goto too_big; |
| 68966 | } |
| 68967 | |
| 68968 | /* Make sure the output register has a buffer large enough to store |
| 68969 | ** the new record. The output register (pOp->p3) is not allowed to |
| 68970 | ** be one of the input registers (because the following call to |
| 68971 | ** sqlite3VdbeMemGrow() could clobber the value before it is used). |
| 68972 | */ |
| 68973 | if( sqlite3VdbeMemGrow(pOut, (int)nByte, 0) ){ |
| 68974 | goto no_mem; |
| 68975 | } |
| 68976 | zNewRecord = (u8 *)pOut->z; |
| 68977 | |
| 68978 | /* Write the record */ |
| 68979 | i = putVarint32(zNewRecord, nHdr); |
| 68980 | j = nHdr; |
| 68981 | assert( pData0<=pLast ); |
| 68982 | pRec = pData0; |
| 68983 | do{ |
| 68984 | serial_type = sqlite3VdbeSerialType(pRec, file_format); |
| 68985 | i += putVarint32(&zNewRecord[i], serial_type); /* serial type */ |
| 68986 | j += sqlite3VdbeSerialPut(&zNewRecord[j], pRec, serial_type); /* content */ |
| 68987 | }while( (++pRec)<=pLast ); |
| 68988 | assert( i==nHdr ); |
| 68989 | assert( j==nByte ); |
| 68990 | |
| 68991 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68992 | pOut->n = (int)nByte; |
| 68993 | pOut->flags = MEM_Blob | MEM_Dyn; |
| 68994 | pOut->xDel = 0; |
| 68995 | if( nZero ){ |
| 68996 | pOut->u.nZero = nZero; |
| 68997 | pOut->flags |= MEM_Zero; |
| 68998 | } |
| 68999 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ |
| 69000 | REGISTER_TRACE(pOp->p3, pOut); |
| 69001 | UPDATE_MAX_BLOBSIZE(pOut); |
| @@ -69008,18 +69241,19 @@ | |
| 69008 | ** Store the number of entries (an integer value) in the table or index |
| 69009 | ** opened by cursor P1 in register P2 |
| 69010 | */ |
| 69011 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 69012 | case OP_Count: { /* out2-prerelease */ |
| 69013 | i64 nEntry; |
| 69014 | BtCursor *pCrsr; |
| 69015 | |
| 69016 | pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 69017 | assert( pCrsr ); |
| 69018 | nEntry = 0; /* Not needed. Only used to silence a warning. */ |
| 69019 | rc = sqlite3BtreeCount(pCrsr, &nEntry); |
| 69020 | pOut->u.i = nEntry; |
| 69021 | break; |
| 69022 | } |
| 69023 | #endif |
| 69024 | |
| 69025 | /* Opcode: Savepoint P1 * * P4 * |
| @@ -69027,41 +69261,43 @@ | |
| 69027 | ** Open, release or rollback the savepoint named by parameter P4, depending |
| 69028 | ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an |
| 69029 | ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2. |
| 69030 | */ |
| 69031 | case OP_Savepoint: { |
| 69032 | int p1; /* Value of P1 operand */ |
| 69033 | char *zName; /* Name of savepoint */ |
| 69034 | int nName; |
| 69035 | Savepoint *pNew; |
| 69036 | Savepoint *pSavepoint; |
| 69037 | Savepoint *pTmp; |
| 69038 | int iSavepoint; |
| 69039 | int ii; |
| 69040 | |
| 69041 | p1 = pOp->p1; |
| 69042 | zName = pOp->p4.z; |
| 69043 | |
| 69044 | /* Assert that the p1 parameter is valid. Also that if there is no open |
| 69045 | ** transaction, then there cannot be any savepoints. |
| 69046 | */ |
| 69047 | assert( db->pSavepoint==0 || db->autoCommit==0 ); |
| 69048 | assert( p1==SAVEPOINT_BEGIN||p1==SAVEPOINT_RELEASE||p1==SAVEPOINT_ROLLBACK ); |
| 69049 | assert( db->pSavepoint || db->isTransactionSavepoint==0 ); |
| 69050 | assert( checkSavepointCount(db) ); |
| 69051 | assert( p->bIsReader ); |
| 69052 | |
| 69053 | if( p1==SAVEPOINT_BEGIN ){ |
| 69054 | if( db->nVdbeWrite>0 ){ |
| 69055 | /* A new savepoint cannot be created if there are active write |
| 69056 | ** statements (i.e. open read/write incremental blob handles). |
| 69057 | */ |
| 69058 | sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - " |
| 69059 | "SQL statements in progress"); |
| 69060 | rc = SQLITE_BUSY; |
| 69061 | }else{ |
| 69062 | nName = sqlite3Strlen30(zName); |
| 69063 | |
| 69064 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 69065 | /* This call is Ok even if this savepoint is actually a transaction |
| 69066 | ** savepoint (and therefore should not prompt xSavepoint()) callbacks. |
| 69067 | ** If this is a transaction savepoint being opened, it is guaranteed |
| @@ -69071,62 +69307,62 @@ | |
| 69071 | db->nStatement+db->nSavepoint); |
| 69072 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69073 | #endif |
| 69074 | |
| 69075 | /* Create a new savepoint structure. */ |
| 69076 | pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+nName+1); |
| 69077 | if( pNew ){ |
| 69078 | pNew->zName = (char *)&pNew[1]; |
| 69079 | memcpy(pNew->zName, zName, nName+1); |
| 69080 | |
| 69081 | /* If there is no open transaction, then mark this as a special |
| 69082 | ** "transaction savepoint". */ |
| 69083 | if( db->autoCommit ){ |
| 69084 | db->autoCommit = 0; |
| 69085 | db->isTransactionSavepoint = 1; |
| 69086 | }else{ |
| 69087 | db->nSavepoint++; |
| 69088 | } |
| 69089 | |
| 69090 | /* Link the new savepoint into the database handle's list. */ |
| 69091 | pNew->pNext = db->pSavepoint; |
| 69092 | db->pSavepoint = pNew; |
| 69093 | pNew->nDeferredCons = db->nDeferredCons; |
| 69094 | pNew->nDeferredImmCons = db->nDeferredImmCons; |
| 69095 | } |
| 69096 | } |
| 69097 | }else{ |
| 69098 | iSavepoint = 0; |
| 69099 | |
| 69100 | /* Find the named savepoint. If there is no such savepoint, then an |
| 69101 | ** an error is returned to the user. */ |
| 69102 | for( |
| 69103 | pSavepoint = db->pSavepoint; |
| 69104 | pSavepoint && sqlite3StrICmp(pSavepoint->zName, zName); |
| 69105 | pSavepoint = pSavepoint->pNext |
| 69106 | ){ |
| 69107 | iSavepoint++; |
| 69108 | } |
| 69109 | if( !pSavepoint ){ |
| 69110 | sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", zName); |
| 69111 | rc = SQLITE_ERROR; |
| 69112 | }else if( db->nVdbeWrite>0 && p1==SAVEPOINT_RELEASE ){ |
| 69113 | /* It is not possible to release (commit) a savepoint if there are |
| 69114 | ** active write statements. |
| 69115 | */ |
| 69116 | sqlite3SetString(&p->zErrMsg, db, |
| 69117 | "cannot release savepoint - SQL statements in progress" |
| 69118 | ); |
| 69119 | rc = SQLITE_BUSY; |
| 69120 | }else{ |
| 69121 | |
| 69122 | /* Determine whether or not this is a transaction savepoint. If so, |
| 69123 | ** and this is a RELEASE command, then the current transaction |
| 69124 | ** is committed. |
| 69125 | */ |
| 69126 | int isTransaction = pSavepoint->pNext==0 && db->isTransactionSavepoint; |
| 69127 | if( isTransaction && p1==SAVEPOINT_RELEASE ){ |
| 69128 | if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 69129 | goto vdbe_return; |
| 69130 | } |
| 69131 | db->autoCommit = 1; |
| 69132 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| @@ -69136,56 +69372,56 @@ | |
| 69136 | goto vdbe_return; |
| 69137 | } |
| 69138 | db->isTransactionSavepoint = 0; |
| 69139 | rc = p->rc; |
| 69140 | }else{ |
| 69141 | iSavepoint = db->nSavepoint - iSavepoint - 1; |
| 69142 | if( p1==SAVEPOINT_ROLLBACK ){ |
| 69143 | for(ii=0; ii<db->nDb; ii++){ |
| 69144 | sqlite3BtreeTripAllCursors(db->aDb[ii].pBt, SQLITE_ABORT); |
| 69145 | } |
| 69146 | } |
| 69147 | for(ii=0; ii<db->nDb; ii++){ |
| 69148 | rc = sqlite3BtreeSavepoint(db->aDb[ii].pBt, p1, iSavepoint); |
| 69149 | if( rc!=SQLITE_OK ){ |
| 69150 | goto abort_due_to_error; |
| 69151 | } |
| 69152 | } |
| 69153 | if( p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 69154 | sqlite3ExpirePreparedStatements(db); |
| 69155 | sqlite3ResetAllSchemasOfConnection(db); |
| 69156 | db->flags = (db->flags | SQLITE_InternChanges); |
| 69157 | } |
| 69158 | } |
| 69159 | |
| 69160 | /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| 69161 | ** savepoints nested inside of the savepoint being operated on. */ |
| 69162 | while( db->pSavepoint!=pSavepoint ){ |
| 69163 | pTmp = db->pSavepoint; |
| 69164 | db->pSavepoint = pTmp->pNext; |
| 69165 | sqlite3DbFree(db, pTmp); |
| 69166 | db->nSavepoint--; |
| 69167 | } |
| 69168 | |
| 69169 | /* If it is a RELEASE, then destroy the savepoint being operated on |
| 69170 | ** too. If it is a ROLLBACK TO, then set the number of deferred |
| 69171 | ** constraint violations present in the database to the value stored |
| 69172 | ** when the savepoint was created. */ |
| 69173 | if( p1==SAVEPOINT_RELEASE ){ |
| 69174 | assert( pSavepoint==db->pSavepoint ); |
| 69175 | db->pSavepoint = pSavepoint->pNext; |
| 69176 | sqlite3DbFree(db, pSavepoint); |
| 69177 | if( !isTransaction ){ |
| 69178 | db->nSavepoint--; |
| 69179 | } |
| 69180 | }else{ |
| 69181 | db->nDeferredCons = pSavepoint->nDeferredCons; |
| 69182 | db->nDeferredImmCons = pSavepoint->nDeferredImmCons; |
| 69183 | } |
| 69184 | |
| 69185 | if( !isTransaction ){ |
| 69186 | rc = sqlite3VtabSavepoint(db, p1, iSavepoint); |
| 69187 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69188 | } |
| 69189 | } |
| 69190 | } |
| 69191 | |
| @@ -69200,52 +69436,54 @@ | |
| 69200 | ** there are active writing VMs or active VMs that use shared cache. |
| 69201 | ** |
| 69202 | ** This instruction causes the VM to halt. |
| 69203 | */ |
| 69204 | case OP_AutoCommit: { |
| 69205 | int desiredAutoCommit; |
| 69206 | int iRollback; |
| 69207 | int turnOnAC; |
| 69208 | |
| 69209 | desiredAutoCommit = pOp->p1; |
| 69210 | iRollback = pOp->p2; |
| 69211 | turnOnAC = desiredAutoCommit && !db->autoCommit; |
| 69212 | assert( desiredAutoCommit==1 || desiredAutoCommit==0 ); |
| 69213 | assert( desiredAutoCommit==1 || iRollback==0 ); |
| 69214 | assert( db->nVdbeActive>0 ); /* At least this one VM is active */ |
| 69215 | assert( p->bIsReader ); |
| 69216 | |
| 69217 | #if 0 |
| 69218 | if( turnOnAC && iRollback && db->nVdbeActive>1 ){ |
| 69219 | /* If this instruction implements a ROLLBACK and other VMs are |
| 69220 | ** still running, and a transaction is active, return an error indicating |
| 69221 | ** that the other VMs must complete first. |
| 69222 | */ |
| 69223 | sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - " |
| 69224 | "SQL statements in progress"); |
| 69225 | rc = SQLITE_BUSY; |
| 69226 | }else |
| 69227 | #endif |
| 69228 | if( turnOnAC && !iRollback && db->nVdbeWrite>0 ){ |
| 69229 | /* If this instruction implements a COMMIT and other VMs are writing |
| 69230 | ** return an error indicating that the other VMs must complete first. |
| 69231 | */ |
| 69232 | sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - " |
| 69233 | "SQL statements in progress"); |
| 69234 | rc = SQLITE_BUSY; |
| 69235 | }else if( desiredAutoCommit!=db->autoCommit ){ |
| 69236 | if( iRollback ){ |
| 69237 | assert( desiredAutoCommit==1 ); |
| 69238 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 69239 | db->autoCommit = 1; |
| 69240 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 69241 | goto vdbe_return; |
| 69242 | }else{ |
| 69243 | db->autoCommit = (u8)desiredAutoCommit; |
| 69244 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 69245 | p->pc = pc; |
| 69246 | db->autoCommit = (u8)(1-desiredAutoCommit); |
| 69247 | p->rc = rc = SQLITE_BUSY; |
| 69248 | goto vdbe_return; |
| 69249 | } |
| 69250 | } |
| 69251 | assert( db->nStatement==0 ); |
| @@ -69256,14 +69494,14 @@ | |
| 69256 | rc = SQLITE_ERROR; |
| 69257 | } |
| 69258 | goto vdbe_return; |
| 69259 | }else{ |
| 69260 | sqlite3SetString(&p->zErrMsg, db, |
| 69261 | (!desiredAutoCommit)?"cannot start a transaction within a transaction":( |
| 69262 | (iRollback)?"cannot rollback - no transaction is active": |
| 69263 | "cannot commit - no transaction is active")); |
| 69264 | |
| 69265 | rc = SQLITE_ERROR; |
| 69266 | } |
| 69267 | break; |
| 69268 | } |
| 69269 | |
| @@ -69297,46 +69535,48 @@ | |
| 69297 | ** will automatically commit when the VDBE halts. |
| 69298 | ** |
| 69299 | ** If P2 is zero, then a read-lock is obtained on the database file. |
| 69300 | */ |
| 69301 | case OP_Transaction: { |
| 69302 | Btree *pBt; |
| 69303 | |
| 69304 | assert( p->bIsReader ); |
| 69305 | assert( p->readOnly==0 || pOp->p2==0 ); |
| 69306 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69307 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69308 | if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ |
| 69309 | rc = SQLITE_READONLY; |
| 69310 | goto abort_due_to_error; |
| 69311 | } |
| 69312 | pBt = db->aDb[pOp->p1].pBt; |
| 69313 | |
| 69314 | if( pBt ){ |
| 69315 | rc = sqlite3BtreeBeginTrans(pBt, pOp->p2); |
| 69316 | if( rc==SQLITE_BUSY ){ |
| 69317 | p->pc = pc; |
| 69318 | p->rc = rc = SQLITE_BUSY; |
| 69319 | goto vdbe_return; |
| 69320 | } |
| 69321 | if( rc!=SQLITE_OK ){ |
| 69322 | goto abort_due_to_error; |
| 69323 | } |
| 69324 | |
| 69325 | if( pOp->p2 && p->usesStmtJournal |
| 69326 | && (db->autoCommit==0 || db->nVdbeRead>1) |
| 69327 | ){ |
| 69328 | assert( sqlite3BtreeIsInTrans(pBt) ); |
| 69329 | if( p->iStatement==0 ){ |
| 69330 | assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 69331 | db->nStatement++; |
| 69332 | p->iStatement = db->nSavepoint + db->nStatement; |
| 69333 | } |
| 69334 | |
| 69335 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1); |
| 69336 | if( rc==SQLITE_OK ){ |
| 69337 | rc = sqlite3BtreeBeginStmt(pBt, p->iStatement); |
| 69338 | } |
| 69339 | |
| 69340 | /* Store the current value of the database handles deferred constraint |
| 69341 | ** counter. If the statement transaction needs to be rolled back, |
| 69342 | ** the value of this counter needs to be restored too. */ |
| @@ -69358,24 +69598,26 @@ | |
| 69358 | ** There must be a read-lock on the database (either a transaction |
| 69359 | ** must be started or there must be an open cursor) before |
| 69360 | ** executing this instruction. |
| 69361 | */ |
| 69362 | case OP_ReadCookie: { /* out2-prerelease */ |
| 69363 | int iMeta; |
| 69364 | int iDb; |
| 69365 | int iCookie; |
| 69366 | |
| 69367 | assert( p->bIsReader ); |
| 69368 | iDb = pOp->p1; |
| 69369 | iCookie = pOp->p3; |
| 69370 | assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 69371 | assert( iDb>=0 && iDb<db->nDb ); |
| 69372 | assert( db->aDb[iDb].pBt!=0 ); |
| 69373 | assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); |
| 69374 | |
| 69375 | sqlite3BtreeGetMeta(db->aDb[iDb].pBt, iCookie, (u32 *)&iMeta); |
| 69376 | pOut->u.i = iMeta; |
| 69377 | break; |
| 69378 | } |
| 69379 | |
| 69380 | /* Opcode: SetCookie P1 P2 P3 * * |
| 69381 | ** |
| @@ -69386,29 +69628,31 @@ | |
| 69386 | ** database file used to store temporary tables. |
| 69387 | ** |
| 69388 | ** A transaction must be started before executing this opcode. |
| 69389 | */ |
| 69390 | case OP_SetCookie: { /* in3 */ |
| 69391 | Db *pDb; |
| 69392 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 69393 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69394 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69395 | assert( p->readOnly==0 ); |
| 69396 | pDb = &db->aDb[pOp->p1]; |
| 69397 | assert( pDb->pBt!=0 ); |
| 69398 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69399 | pIn3 = &aMem[pOp->p3]; |
| 69400 | sqlite3VdbeMemIntegerify(pIn3); |
| 69401 | /* See note about index shifting on OP_ReadCookie */ |
| 69402 | rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, (int)pIn3->u.i); |
| 69403 | if( pOp->p2==BTREE_SCHEMA_VERSION ){ |
| 69404 | /* When the schema cookie changes, record the new cookie internally */ |
| 69405 | pDb->pSchema->schema_cookie = (int)pIn3->u.i; |
| 69406 | db->flags |= SQLITE_InternChanges; |
| 69407 | }else if( pOp->p2==BTREE_FILE_FORMAT ){ |
| 69408 | /* Record changes in the file format */ |
| 69409 | pDb->pSchema->file_format = (u8)pIn3->u.i; |
| 69410 | } |
| 69411 | if( pOp->p1==1 ){ |
| 69412 | /* Invalidate all prepared statements whenever the TEMP database |
| 69413 | ** schema is changed. Ticket #1644 */ |
| 69414 | sqlite3ExpirePreparedStatements(db); |
| @@ -69434,42 +69678,44 @@ | |
| 69434 | ** Either a transaction needs to have been started or an OP_Open needs |
| 69435 | ** to be executed (to establish a read lock) before this opcode is |
| 69436 | ** invoked. |
| 69437 | */ |
| 69438 | case OP_VerifyCookie: { |
| 69439 | int iMeta; |
| 69440 | int iGen; |
| 69441 | Btree *pBt; |
| 69442 | |
| 69443 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69444 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69445 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69446 | assert( p->bIsReader ); |
| 69447 | pBt = db->aDb[pOp->p1].pBt; |
| 69448 | if( pBt ){ |
| 69449 | sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta); |
| 69450 | iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 69451 | }else{ |
| 69452 | iGen = iMeta = 0; |
| 69453 | } |
| 69454 | if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){ |
| 69455 | sqlite3DbFree(db, p->zErrMsg); |
| 69456 | p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 69457 | /* If the schema-cookie from the database file matches the cookie |
| 69458 | ** stored with the in-memory representation of the schema, do |
| 69459 | ** not reload the schema from the database file. |
| 69460 | ** |
| 69461 | ** If virtual-tables are in use, this is not just an optimization. |
| 69462 | ** Often, v-tables store their data in other SQLite tables, which |
| 69463 | ** are queried from within xNext() and other v-table methods using |
| 69464 | ** prepared queries. If such a query is out-of-date, we do not want to |
| 69465 | ** discard the database schema, as the user code implementing the |
| 69466 | ** v-table would have to be ready for the sqlite3_vtab structure itself |
| 69467 | ** to be invalidated whenever sqlite3_step() is called from within |
| 69468 | ** a v-table method. |
| 69469 | */ |
| 69470 | if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){ |
| 69471 | sqlite3ResetOneSchema(db, pOp->p1); |
| 69472 | } |
| 69473 | |
| 69474 | p->expired = 1; |
| 69475 | rc = SQLITE_SCHEMA; |
| @@ -69528,18 +69774,20 @@ | |
| 69528 | ** |
| 69529 | ** See also OpenRead. |
| 69530 | */ |
| 69531 | case OP_OpenRead: |
| 69532 | case OP_OpenWrite: { |
| 69533 | int nField; |
| 69534 | KeyInfo *pKeyInfo; |
| 69535 | int p2; |
| 69536 | int iDb; |
| 69537 | int wrFlag; |
| 69538 | Btree *pX; |
| 69539 | VdbeCursor *pCur; |
| 69540 | Db *pDb; |
| 69541 | |
| 69542 | assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 ); |
| 69543 | assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 ); |
| 69544 | assert( p->bIsReader ); |
| 69545 | assert( pOp->opcode==OP_OpenRead || p->readOnly==0 ); |
| @@ -69547,74 +69795,74 @@ | |
| 69547 | if( p->expired ){ |
| 69548 | rc = SQLITE_ABORT; |
| 69549 | break; |
| 69550 | } |
| 69551 | |
| 69552 | nField = 0; |
| 69553 | pKeyInfo = 0; |
| 69554 | p2 = pOp->p2; |
| 69555 | iDb = pOp->p3; |
| 69556 | assert( iDb>=0 && iDb<db->nDb ); |
| 69557 | assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); |
| 69558 | pDb = &db->aDb[iDb]; |
| 69559 | pX = pDb->pBt; |
| 69560 | assert( pX!=0 ); |
| 69561 | if( pOp->opcode==OP_OpenWrite ){ |
| 69562 | wrFlag = 1; |
| 69563 | assert( sqlite3SchemaMutexHeld(db, iDb, 0) ); |
| 69564 | if( pDb->pSchema->file_format < p->minWriteFileFormat ){ |
| 69565 | p->minWriteFileFormat = pDb->pSchema->file_format; |
| 69566 | } |
| 69567 | }else{ |
| 69568 | wrFlag = 0; |
| 69569 | } |
| 69570 | if( pOp->p5 & OPFLAG_P2ISREG ){ |
| 69571 | assert( p2>0 ); |
| 69572 | assert( p2<=(p->nMem-p->nCursor) ); |
| 69573 | pIn2 = &aMem[p2]; |
| 69574 | assert( memIsValid(pIn2) ); |
| 69575 | assert( (pIn2->flags & MEM_Int)!=0 ); |
| 69576 | sqlite3VdbeMemIntegerify(pIn2); |
| 69577 | p2 = (int)pIn2->u.i; |
| 69578 | /* The p2 value always comes from a prior OP_CreateTable opcode and |
| 69579 | ** that opcode will always set the p2 value to 2 or more or else fail. |
| 69580 | ** If there were a failure, the prepared statement would have halted |
| 69581 | ** before reaching this instruction. */ |
| 69582 | if( NEVER(p2<2) ) { |
| 69583 | rc = SQLITE_CORRUPT_BKPT; |
| 69584 | goto abort_due_to_error; |
| 69585 | } |
| 69586 | } |
| 69587 | if( pOp->p4type==P4_KEYINFO ){ |
| 69588 | pKeyInfo = pOp->p4.pKeyInfo; |
| 69589 | assert( pKeyInfo->enc==ENC(db) ); |
| 69590 | assert( pKeyInfo->db==db ); |
| 69591 | nField = pKeyInfo->nField+pKeyInfo->nXField; |
| 69592 | }else if( pOp->p4type==P4_INT32 ){ |
| 69593 | nField = pOp->p4.i; |
| 69594 | } |
| 69595 | assert( pOp->p1>=0 ); |
| 69596 | assert( nField>=0 ); |
| 69597 | testcase( nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ |
| 69598 | pCur = allocateCursor(p, pOp->p1, nField, iDb, 1); |
| 69599 | if( pCur==0 ) goto no_mem; |
| 69600 | pCur->nullRow = 1; |
| 69601 | pCur->isOrdered = 1; |
| 69602 | rc = sqlite3BtreeCursor(pX, p2, wrFlag, pKeyInfo, pCur->pCursor); |
| 69603 | pCur->pKeyInfo = pKeyInfo; |
| 69604 | assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); |
| 69605 | sqlite3BtreeCursorHints(pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR)); |
| 69606 | |
| 69607 | /* Since it performs no memory allocation or IO, the only value that |
| 69608 | ** sqlite3BtreeCursor() may return is SQLITE_OK. */ |
| 69609 | assert( rc==SQLITE_OK ); |
| 69610 | |
| 69611 | /* Set the VdbeCursor.isTable variable. Previous versions of |
| 69612 | ** SQLite used to check if the root-page flags were sane at this point |
| 69613 | ** and report database corruption if they were not, but this check has |
| 69614 | ** since moved into the btree layer. */ |
| 69615 | pCur->isTable = pOp->p4type!=P4_KEYINFO; |
| 69616 | break; |
| 69617 | } |
| 69618 | |
| 69619 | /* Opcode: OpenEphemeral P1 P2 * P4 P5 |
| 69620 | ** Synopsis: nColumn=P2 |
| @@ -69642,53 +69890,55 @@ | |
| 69642 | ** by this opcode will be used for automatically created transient |
| 69643 | ** indices in joins. |
| 69644 | */ |
| 69645 | case OP_OpenAutoindex: |
| 69646 | case OP_OpenEphemeral: { |
| 69647 | VdbeCursor *pCx; |
| 69648 | KeyInfo *pKeyInfo; |
| 69649 | |
| 69650 | static const int vfsFlags = |
| 69651 | SQLITE_OPEN_READWRITE | |
| 69652 | SQLITE_OPEN_CREATE | |
| 69653 | SQLITE_OPEN_EXCLUSIVE | |
| 69654 | SQLITE_OPEN_DELETEONCLOSE | |
| 69655 | SQLITE_OPEN_TRANSIENT_DB; |
| 69656 | assert( pOp->p1>=0 ); |
| 69657 | assert( pOp->p2>=0 ); |
| 69658 | pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69659 | if( pCx==0 ) goto no_mem; |
| 69660 | pCx->nullRow = 1; |
| 69661 | rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt, |
| 69662 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| 69663 | if( rc==SQLITE_OK ){ |
| 69664 | rc = sqlite3BtreeBeginTrans(pCx->pBt, 1); |
| 69665 | } |
| 69666 | if( rc==SQLITE_OK ){ |
| 69667 | /* If a transient index is required, create it by calling |
| 69668 | ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before |
| 69669 | ** opening it. If a transient table is required, just use the |
| 69670 | ** automatically created table with root-page 1 (an BLOB_INTKEY table). |
| 69671 | */ |
| 69672 | if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 69673 | int pgno; |
| 69674 | assert( pOp->p4type==P4_KEYINFO ); |
| 69675 | rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); |
| 69676 | if( rc==SQLITE_OK ){ |
| 69677 | assert( pgno==MASTER_ROOT+1 ); |
| 69678 | assert( pKeyInfo->db==db ); |
| 69679 | assert( pKeyInfo->enc==ENC(db) ); |
| 69680 | pCx->pKeyInfo = pKeyInfo; |
| 69681 | rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, pKeyInfo, pCx->pCursor); |
| 69682 | } |
| 69683 | pCx->isTable = 0; |
| 69684 | }else{ |
| 69685 | rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, 1, 0, pCx->pCursor); |
| 69686 | pCx->isTable = 1; |
| 69687 | } |
| 69688 | } |
| 69689 | pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 69690 | break; |
| 69691 | } |
| 69692 | |
| 69693 | /* Opcode: SorterOpen P1 * * P4 * |
| 69694 | ** |
| @@ -69695,20 +69945,22 @@ | |
| 69695 | ** This opcode works like OP_OpenEphemeral except that it opens |
| 69696 | ** a transient index that is specifically designed to sort large |
| 69697 | ** tables using an external merge-sort algorithm. |
| 69698 | */ |
| 69699 | case OP_SorterOpen: { |
| 69700 | VdbeCursor *pCx; |
| 69701 | |
| 69702 | assert( pOp->p1>=0 ); |
| 69703 | assert( pOp->p2>=0 ); |
| 69704 | pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69705 | if( pCx==0 ) goto no_mem; |
| 69706 | pCx->pKeyInfo = pOp->p4.pKeyInfo; |
| 69707 | assert( pCx->pKeyInfo->db==db ); |
| 69708 | assert( pCx->pKeyInfo->enc==ENC(db) ); |
| 69709 | rc = sqlite3VdbeSorterInit(db, pCx); |
| 69710 | break; |
| 69711 | } |
| 69712 | |
| 69713 | /* Opcode: OpenPseudo P1 P2 P3 * P5 |
| 69714 | ** Synopsis: content in r[P2@P3] |
| @@ -69726,20 +69978,22 @@ | |
| 69726 | ** |
| 69727 | ** P3 is the number of fields in the records that will be stored by |
| 69728 | ** the pseudo-table. |
| 69729 | */ |
| 69730 | case OP_OpenPseudo: { |
| 69731 | VdbeCursor *pCx; |
| 69732 | |
| 69733 | assert( pOp->p1>=0 ); |
| 69734 | assert( pOp->p3>=0 ); |
| 69735 | pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); |
| 69736 | if( pCx==0 ) goto no_mem; |
| 69737 | pCx->nullRow = 1; |
| 69738 | pCx->pseudoTableReg = pOp->p2; |
| 69739 | pCx->isTable = 1; |
| 69740 | pCx->multiPseudo = pOp->p5; |
| 69741 | break; |
| 69742 | } |
| 69743 | |
| 69744 | /* Opcode: Close P1 * * * * |
| 69745 | ** |
| @@ -69811,37 +70065,39 @@ | |
| 69811 | */ |
| 69812 | case OP_SeekLt: /* jump, in3 */ |
| 69813 | case OP_SeekLe: /* jump, in3 */ |
| 69814 | case OP_SeekGe: /* jump, in3 */ |
| 69815 | case OP_SeekGt: { /* jump, in3 */ |
| 69816 | int res; |
| 69817 | int oc; |
| 69818 | VdbeCursor *pC; |
| 69819 | UnpackedRecord r; |
| 69820 | int nField; |
| 69821 | i64 iKey; /* The rowid we are to seek to */ |
| 69822 | |
| 69823 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 69824 | assert( pOp->p2!=0 ); |
| 69825 | pC = p->apCsr[pOp->p1]; |
| 69826 | assert( pC!=0 ); |
| 69827 | assert( pC->pseudoTableReg==0 ); |
| 69828 | assert( OP_SeekLe == OP_SeekLt+1 ); |
| 69829 | assert( OP_SeekGe == OP_SeekLt+2 ); |
| 69830 | assert( OP_SeekGt == OP_SeekLt+3 ); |
| 69831 | assert( pC->isOrdered ); |
| 69832 | assert( pC->pCursor!=0 ); |
| 69833 | oc = pOp->opcode; |
| 69834 | pC->nullRow = 0; |
| 69835 | if( pC->isTable ){ |
| 69836 | /* The input value in P3 might be of any type: integer, real, string, |
| 69837 | ** blob, or NULL. But it needs to be an integer before we can do |
| 69838 | ** the seek, so covert it. */ |
| 69839 | pIn3 = &aMem[pOp->p3]; |
| 69840 | applyNumericAffinity(pIn3); |
| 69841 | iKey = sqlite3VdbeIntValue(pIn3); |
| 69842 | pC->rowidIsValid = 0; |
| 69843 | |
| 69844 | /* If the P3 value could not be converted into an integer without |
| 69845 | ** loss of information, then special processing is required... */ |
| 69846 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 69847 | if( (pIn3->flags & MEM_Real)==0 ){ |
| @@ -69849,100 +70105,100 @@ | |
| 69849 | ** then the seek is not possible, so jump to P2 */ |
| 69850 | pc = pOp->p2 - 1; |
| 69851 | break; |
| 69852 | } |
| 69853 | |
| 69854 | /* If the approximation iKey is larger than the actual real search |
| 69855 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| 69856 | ** is 4.9 and the integer approximation 5: |
| 69857 | ** |
| 69858 | ** (x > 4.9) -> (x >= 5) |
| 69859 | ** (x <= 4.9) -> (x < 5) |
| 69860 | */ |
| 69861 | if( pIn3->r<(double)iKey ){ |
| 69862 | assert( OP_SeekGe==(OP_SeekGt-1) ); |
| 69863 | assert( OP_SeekLt==(OP_SeekLe-1) ); |
| 69864 | assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); |
| 69865 | if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--; |
| 69866 | } |
| 69867 | |
| 69868 | /* If the approximation iKey is smaller than the actual real search |
| 69869 | ** term, substitute <= for < and > for >=. */ |
| 69870 | else if( pIn3->r>(double)iKey ){ |
| 69871 | assert( OP_SeekLe==(OP_SeekLt+1) ); |
| 69872 | assert( OP_SeekGt==(OP_SeekGe+1) ); |
| 69873 | assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); |
| 69874 | if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++; |
| 69875 | } |
| 69876 | } |
| 69877 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res); |
| 69878 | if( rc!=SQLITE_OK ){ |
| 69879 | goto abort_due_to_error; |
| 69880 | } |
| 69881 | if( res==0 ){ |
| 69882 | pC->rowidIsValid = 1; |
| 69883 | pC->lastRowid = iKey; |
| 69884 | } |
| 69885 | }else{ |
| 69886 | nField = pOp->p4.i; |
| 69887 | assert( pOp->p4type==P4_INT32 ); |
| 69888 | assert( nField>0 ); |
| 69889 | r.pKeyInfo = pC->pKeyInfo; |
| 69890 | r.nField = (u16)nField; |
| 69891 | |
| 69892 | /* The next line of code computes as follows, only faster: |
| 69893 | ** if( oc==OP_SeekGt || oc==OP_SeekLe ){ |
| 69894 | ** r.flags = UNPACKED_INCRKEY; |
| 69895 | ** }else{ |
| 69896 | ** r.flags = 0; |
| 69897 | ** } |
| 69898 | */ |
| 69899 | r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt))); |
| 69900 | assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY ); |
| 69901 | assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY ); |
| 69902 | assert( oc!=OP_SeekGe || r.flags==0 ); |
| 69903 | assert( oc!=OP_SeekLt || r.flags==0 ); |
| 69904 | |
| 69905 | r.aMem = &aMem[pOp->p3]; |
| 69906 | #ifdef SQLITE_DEBUG |
| 69907 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 69908 | #endif |
| 69909 | ExpandBlob(r.aMem); |
| 69910 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, &r, 0, 0, &res); |
| 69911 | if( rc!=SQLITE_OK ){ |
| 69912 | goto abort_due_to_error; |
| 69913 | } |
| 69914 | pC->rowidIsValid = 0; |
| 69915 | } |
| 69916 | pC->deferredMoveto = 0; |
| 69917 | pC->cacheStatus = CACHE_STALE; |
| 69918 | #ifdef SQLITE_TEST |
| 69919 | sqlite3_search_count++; |
| 69920 | #endif |
| 69921 | if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt ); |
| 69922 | if( res<0 || (res==0 && oc==OP_SeekGt) ){ |
| 69923 | rc = sqlite3BtreeNext(pC->pCursor, &res); |
| 69924 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69925 | pC->rowidIsValid = 0; |
| 69926 | }else{ |
| 69927 | res = 0; |
| 69928 | } |
| 69929 | }else{ |
| 69930 | assert( oc==OP_SeekLt || oc==OP_SeekLe ); |
| 69931 | if( res>0 || (res==0 && oc==OP_SeekLt) ){ |
| 69932 | rc = sqlite3BtreePrevious(pC->pCursor, &res); |
| 69933 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69934 | pC->rowidIsValid = 0; |
| 69935 | }else{ |
| 69936 | /* res might be negative because the table is empty. Check to |
| 69937 | ** see if this is the case. |
| 69938 | */ |
| 69939 | res = sqlite3BtreeEof(pC->pCursor); |
| 69940 | } |
| 69941 | } |
| 69942 | assert( pOp->p2>0 ); |
| 69943 | if( res ){ |
| 69944 | pc = pOp->p2 - 1; |
| 69945 | } |
| 69946 | break; |
| 69947 | } |
| 69948 | |
| @@ -69955,22 +70211,24 @@ | |
| 69955 | ** This is actually a deferred seek. Nothing actually happens until |
| 69956 | ** the cursor is used to read a record. That way, if no reads |
| 69957 | ** occur, no unnecessary I/O happens. |
| 69958 | */ |
| 69959 | case OP_Seek: { /* in2 */ |
| 69960 | VdbeCursor *pC; |
| 69961 | |
| 69962 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 69963 | pC = p->apCsr[pOp->p1]; |
| 69964 | assert( pC!=0 ); |
| 69965 | assert( pC->pCursor!=0 ); |
| 69966 | assert( pC->isTable ); |
| 69967 | pC->nullRow = 0; |
| 69968 | pIn2 = &aMem[pOp->p2]; |
| 69969 | pC->movetoTarget = sqlite3VdbeIntValue(pIn2); |
| 69970 | pC->rowidIsValid = 0; |
| 69971 | pC->deferredMoveto = 1; |
| 69972 | break; |
| 69973 | } |
| 69974 | |
| 69975 | |
| 69976 | /* Opcode: Found P1 P2 P3 P4 * |
| @@ -70021,83 +70279,85 @@ | |
| 70021 | ** See also: NotFound, Found, NotExists |
| 70022 | */ |
| 70023 | case OP_NoConflict: /* jump, in3 */ |
| 70024 | case OP_NotFound: /* jump, in3 */ |
| 70025 | case OP_Found: { /* jump, in3 */ |
| 70026 | int alreadyExists; |
| 70027 | int ii; |
| 70028 | VdbeCursor *pC; |
| 70029 | int res; |
| 70030 | char *pFree; |
| 70031 | UnpackedRecord *pIdxKey; |
| 70032 | UnpackedRecord r; |
| 70033 | char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; |
| 70034 | |
| 70035 | #ifdef SQLITE_TEST |
| 70036 | if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++; |
| 70037 | #endif |
| 70038 | |
| 70039 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70040 | assert( pOp->p4type==P4_INT32 ); |
| 70041 | pC = p->apCsr[pOp->p1]; |
| 70042 | assert( pC!=0 ); |
| 70043 | pIn3 = &aMem[pOp->p3]; |
| 70044 | assert( pC->pCursor!=0 ); |
| 70045 | assert( pC->isTable==0 ); |
| 70046 | pFree = 0; /* Not needed. Only used to suppress a compiler warning. */ |
| 70047 | if( pOp->p4.i>0 ){ |
| 70048 | r.pKeyInfo = pC->pKeyInfo; |
| 70049 | r.nField = (u16)pOp->p4.i; |
| 70050 | r.aMem = pIn3; |
| 70051 | #ifdef SQLITE_DEBUG |
| 70052 | { |
| 70053 | int i; |
| 70054 | for(i=0; i<r.nField; i++){ |
| 70055 | assert( memIsValid(&r.aMem[i]) ); |
| 70056 | if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]); |
| 70057 | } |
| 70058 | } |
| 70059 | #endif |
| 70060 | r.flags = UNPACKED_PREFIX_MATCH; |
| 70061 | pIdxKey = &r; |
| 70062 | }else{ |
| 70063 | pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 70064 | pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree |
| 70065 | ); |
| 70066 | if( pIdxKey==0 ) goto no_mem; |
| 70067 | assert( pIn3->flags & MEM_Blob ); |
| 70068 | assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */ |
| 70069 | sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey); |
| 70070 | pIdxKey->flags |= UNPACKED_PREFIX_MATCH; |
| 70071 | } |
| 70072 | if( pOp->opcode==OP_NoConflict ){ |
| 70073 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 70074 | ** input fields are NULL, since any key with a NULL will not |
| 70075 | ** conflict */ |
| 70076 | for(ii=0; ii<r.nField; ii++){ |
| 70077 | if( r.aMem[ii].flags & MEM_Null ){ |
| 70078 | pc = pOp->p2 - 1; |
| 70079 | break; |
| 70080 | } |
| 70081 | } |
| 70082 | } |
| 70083 | rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res); |
| 70084 | if( pOp->p4.i==0 ){ |
| 70085 | sqlite3DbFree(db, pFree); |
| 70086 | } |
| 70087 | if( rc!=SQLITE_OK ){ |
| 70088 | break; |
| 70089 | } |
| 70090 | pC->seekResult = res; |
| 70091 | alreadyExists = (res==0); |
| 70092 | pC->nullRow = 1-alreadyExists; |
| 70093 | pC->deferredMoveto = 0; |
| 70094 | pC->cacheStatus = CACHE_STALE; |
| 70095 | if( pOp->opcode==OP_Found ){ |
| 70096 | if( alreadyExists ) pc = pOp->p2 - 1; |
| 70097 | }else{ |
| 70098 | if( !alreadyExists ) pc = pOp->p2 - 1; |
| 70099 | } |
| 70100 | break; |
| 70101 | } |
| 70102 | |
| 70103 | /* Opcode: NotExists P1 P2 P3 * * |
| @@ -70113,37 +70373,39 @@ | |
| 70113 | ** (with arbitrary multi-value keys). |
| 70114 | ** |
| 70115 | ** See also: Found, NotFound, NoConflict |
| 70116 | */ |
| 70117 | case OP_NotExists: { /* jump, in3 */ |
| 70118 | VdbeCursor *pC; |
| 70119 | BtCursor *pCrsr; |
| 70120 | int res; |
| 70121 | u64 iKey; |
| 70122 | |
| 70123 | pIn3 = &aMem[pOp->p3]; |
| 70124 | assert( pIn3->flags & MEM_Int ); |
| 70125 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70126 | pC = p->apCsr[pOp->p1]; |
| 70127 | assert( pC!=0 ); |
| 70128 | assert( pC->isTable ); |
| 70129 | assert( pC->pseudoTableReg==0 ); |
| 70130 | pCrsr = pC->pCursor; |
| 70131 | assert( pCrsr!=0 ); |
| 70132 | res = 0; |
| 70133 | iKey = pIn3->u.i; |
| 70134 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, 0, iKey, 0, &res); |
| 70135 | pC->lastRowid = pIn3->u.i; |
| 70136 | pC->rowidIsValid = res==0 ?1:0; |
| 70137 | pC->nullRow = 0; |
| 70138 | pC->cacheStatus = CACHE_STALE; |
| 70139 | pC->deferredMoveto = 0; |
| 70140 | if( res!=0 ){ |
| 70141 | pc = pOp->p2 - 1; |
| 70142 | assert( pC->rowidIsValid==0 ); |
| 70143 | } |
| 70144 | pC->seekResult = res; |
| 70145 | break; |
| 70146 | } |
| 70147 | |
| 70148 | /* Opcode: Sequence P1 P2 * * * |
| 70149 | ** Synopsis: r[P2]=rowid |
| @@ -70175,23 +70437,25 @@ | |
| 70175 | ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 70176 | ** generated record number. This P3 mechanism is used to help implement the |
| 70177 | ** AUTOINCREMENT feature. |
| 70178 | */ |
| 70179 | case OP_NewRowid: { /* out2-prerelease */ |
| 70180 | i64 v; /* The new rowid */ |
| 70181 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 70182 | int res; /* Result of an sqlite3BtreeLast() */ |
| 70183 | int cnt; /* Counter to limit the number of searches */ |
| 70184 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 70185 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 70186 | |
| 70187 | v = 0; |
| 70188 | res = 0; |
| 70189 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70190 | pC = p->apCsr[pOp->p1]; |
| 70191 | assert( pC!=0 ); |
| 70192 | if( NEVER(pC->pCursor==0) ){ |
| 70193 | /* The zero initialization above is all that is needed */ |
| 70194 | }else{ |
| 70195 | /* The next rowid or record number (different terms for the same |
| 70196 | ** thing) is obtained in a two-step algorithm. |
| 70197 | ** |
| @@ -70203,11 +70467,11 @@ | |
| 70203 | ** The second algorithm is to select a rowid at random and see if |
| 70204 | ** it already exists in the table. If it does not exist, we have |
| 70205 | ** succeeded. If the random rowid does exist, we select a new one |
| 70206 | ** and try again, up to 100 times. |
| 70207 | */ |
| 70208 | assert( pC->isTable ); |
| 70209 | |
| 70210 | #ifdef SQLITE_32BIT_ROWID |
| 70211 | # define MAX_ROWID 0x7fffffff |
| 70212 | #else |
| 70213 | /* Some compilers complain about constants of the form 0x7fffffffffffffff. |
| @@ -70215,101 +70479,101 @@ | |
| 70215 | ** to provide the constant while making all compilers happy. |
| 70216 | */ |
| 70217 | # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff ) |
| 70218 | #endif |
| 70219 | |
| 70220 | if( !pC->useRandomRowid ){ |
| 70221 | v = sqlite3BtreeGetCachedRowid(pC->pCursor); |
| 70222 | if( v==0 ){ |
| 70223 | rc = sqlite3BtreeLast(pC->pCursor, &res); |
| 70224 | if( rc!=SQLITE_OK ){ |
| 70225 | goto abort_due_to_error; |
| 70226 | } |
| 70227 | if( res ){ |
| 70228 | v = 1; /* IMP: R-61914-48074 */ |
| 70229 | }else{ |
| 70230 | assert( sqlite3BtreeCursorIsValid(pC->pCursor) ); |
| 70231 | rc = sqlite3BtreeKeySize(pC->pCursor, &v); |
| 70232 | assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ |
| 70233 | if( v>=MAX_ROWID ){ |
| 70234 | pC->useRandomRowid = 1; |
| 70235 | }else{ |
| 70236 | v++; /* IMP: R-29538-34987 */ |
| 70237 | } |
| 70238 | } |
| 70239 | } |
| 70240 | |
| 70241 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 70242 | if( pOp->p3 ){ |
| 70243 | /* Assert that P3 is a valid memory cell. */ |
| 70244 | assert( pOp->p3>0 ); |
| 70245 | if( p->pFrame ){ |
| 70246 | for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 70247 | /* Assert that P3 is a valid memory cell. */ |
| 70248 | assert( pOp->p3<=pFrame->nMem ); |
| 70249 | pMem = &pFrame->aMem[pOp->p3]; |
| 70250 | }else{ |
| 70251 | /* Assert that P3 is a valid memory cell. */ |
| 70252 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 70253 | pMem = &aMem[pOp->p3]; |
| 70254 | memAboutToChange(p, pMem); |
| 70255 | } |
| 70256 | assert( memIsValid(pMem) ); |
| 70257 | |
| 70258 | REGISTER_TRACE(pOp->p3, pMem); |
| 70259 | sqlite3VdbeMemIntegerify(pMem); |
| 70260 | assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ |
| 70261 | if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){ |
| 70262 | rc = SQLITE_FULL; /* IMP: R-12275-61338 */ |
| 70263 | goto abort_due_to_error; |
| 70264 | } |
| 70265 | if( v<pMem->u.i+1 ){ |
| 70266 | v = pMem->u.i + 1; |
| 70267 | } |
| 70268 | pMem->u.i = v; |
| 70269 | } |
| 70270 | #endif |
| 70271 | |
| 70272 | sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0); |
| 70273 | } |
| 70274 | if( pC->useRandomRowid ){ |
| 70275 | /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the |
| 70276 | ** largest possible integer (9223372036854775807) then the database |
| 70277 | ** engine starts picking positive candidate ROWIDs at random until |
| 70278 | ** it finds one that is not previously used. */ |
| 70279 | assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is |
| 70280 | ** an AUTOINCREMENT table. */ |
| 70281 | /* on the first attempt, simply do one more than previous */ |
| 70282 | v = lastRowid; |
| 70283 | v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 70284 | v++; /* ensure non-zero */ |
| 70285 | cnt = 0; |
| 70286 | while( ((rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)v, |
| 70287 | 0, &res))==SQLITE_OK) |
| 70288 | && (res==0) |
| 70289 | && (++cnt<100)){ |
| 70290 | /* collision - try another random rowid */ |
| 70291 | sqlite3_randomness(sizeof(v), &v); |
| 70292 | if( cnt<5 ){ |
| 70293 | /* try "small" random rowids for the initial attempts */ |
| 70294 | v &= 0xffffff; |
| 70295 | }else{ |
| 70296 | v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 70297 | } |
| 70298 | v++; /* ensure non-zero */ |
| 70299 | } |
| 70300 | if( rc==SQLITE_OK && res==0 ){ |
| 70301 | rc = SQLITE_FULL; /* IMP: R-38219-53002 */ |
| 70302 | goto abort_due_to_error; |
| 70303 | } |
| 70304 | assert( v>0 ); /* EV: R-40812-03570 */ |
| 70305 | } |
| 70306 | pC->rowidIsValid = 0; |
| 70307 | pC->deferredMoveto = 0; |
| 70308 | pC->cacheStatus = CACHE_STALE; |
| 70309 | } |
| 70310 | pOut->u.i = v; |
| 70311 | break; |
| 70312 | } |
| 70313 | |
| 70314 | /* Opcode: Insert P1 P2 P3 P4 P5 |
| 70315 | ** Synopsis: intkey=r[P3] data=r[P2] |
| @@ -70357,72 +70621,74 @@ | |
| 70357 | ** This works exactly like OP_Insert except that the key is the |
| 70358 | ** integer value P3, not the value of the integer stored in register P3. |
| 70359 | */ |
| 70360 | case OP_Insert: |
| 70361 | case OP_InsertInt: { |
| 70362 | Mem *pData; /* MEM cell holding data for the record to be inserted */ |
| 70363 | Mem *pKey; /* MEM cell holding key for the record */ |
| 70364 | i64 iKey; /* The integer ROWID or key for the record to be inserted */ |
| 70365 | VdbeCursor *pC; /* Cursor to table into which insert is written */ |
| 70366 | int nZero; /* Number of zero-bytes to append */ |
| 70367 | int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ |
| 70368 | const char *zDb; /* database name - used by the update hook */ |
| 70369 | const char *zTbl; /* Table name - used by the opdate hook */ |
| 70370 | int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ |
| 70371 | |
| 70372 | pData = &aMem[pOp->p2]; |
| 70373 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70374 | assert( memIsValid(pData) ); |
| 70375 | pC = p->apCsr[pOp->p1]; |
| 70376 | assert( pC!=0 ); |
| 70377 | assert( pC->pCursor!=0 ); |
| 70378 | assert( pC->pseudoTableReg==0 ); |
| 70379 | assert( pC->isTable ); |
| 70380 | REGISTER_TRACE(pOp->p2, pData); |
| 70381 | |
| 70382 | if( pOp->opcode==OP_Insert ){ |
| 70383 | pKey = &aMem[pOp->p3]; |
| 70384 | assert( pKey->flags & MEM_Int ); |
| 70385 | assert( memIsValid(pKey) ); |
| 70386 | REGISTER_TRACE(pOp->p3, pKey); |
| 70387 | iKey = pKey->u.i; |
| 70388 | }else{ |
| 70389 | assert( pOp->opcode==OP_InsertInt ); |
| 70390 | iKey = pOp->p3; |
| 70391 | } |
| 70392 | |
| 70393 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 70394 | if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = iKey; |
| 70395 | if( pData->flags & MEM_Null ){ |
| 70396 | pData->z = 0; |
| 70397 | pData->n = 0; |
| 70398 | }else{ |
| 70399 | assert( pData->flags & (MEM_Blob|MEM_Str) ); |
| 70400 | } |
| 70401 | seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0); |
| 70402 | if( pData->flags & MEM_Zero ){ |
| 70403 | nZero = pData->u.nZero; |
| 70404 | }else{ |
| 70405 | nZero = 0; |
| 70406 | } |
| 70407 | sqlite3BtreeSetCachedRowid(pC->pCursor, 0); |
| 70408 | rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey, |
| 70409 | pData->z, pData->n, nZero, |
| 70410 | (pOp->p5 & OPFLAG_APPEND)!=0, seekResult |
| 70411 | ); |
| 70412 | pC->rowidIsValid = 0; |
| 70413 | pC->deferredMoveto = 0; |
| 70414 | pC->cacheStatus = CACHE_STALE; |
| 70415 | |
| 70416 | /* Invoke the update-hook if required. */ |
| 70417 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){ |
| 70418 | zDb = db->aDb[pC->iDb].zName; |
| 70419 | zTbl = pOp->p4.z; |
| 70420 | op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); |
| 70421 | assert( pC->isTable ); |
| 70422 | db->xUpdateCallback(db->pUpdateArg, op, zDb, zTbl, iKey); |
| 70423 | assert( pC->iDb>=0 ); |
| 70424 | } |
| 70425 | break; |
| 70426 | } |
| 70427 | |
| 70428 | /* Opcode: Delete P1 P2 * P4 * |
| @@ -70444,39 +70710,41 @@ | |
| 70444 | ** pointing to. The update hook will be invoked, if it exists. |
| 70445 | ** If P4 is not NULL then the P1 cursor must have been positioned |
| 70446 | ** using OP_NotFound prior to invoking this opcode. |
| 70447 | */ |
| 70448 | case OP_Delete: { |
| 70449 | i64 iKey; |
| 70450 | VdbeCursor *pC; |
| 70451 | |
| 70452 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70453 | pC = p->apCsr[pOp->p1]; |
| 70454 | assert( pC!=0 ); |
| 70455 | assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ |
| 70456 | iKey = pC->lastRowid; /* Only used for the update hook */ |
| 70457 | |
| 70458 | /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or |
| 70459 | ** OP_Column on the same table without any intervening operations that |
| 70460 | ** might move or invalidate the cursor. Hence cursor pC is always pointing |
| 70461 | ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation |
| 70462 | ** below is always a no-op and cannot fail. We will run it anyhow, though, |
| 70463 | ** to guard against future changes to the code generator. |
| 70464 | **/ |
| 70465 | assert( pC->deferredMoveto==0 ); |
| 70466 | rc = sqlite3VdbeCursorMoveto(pC); |
| 70467 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70468 | |
| 70469 | sqlite3BtreeSetCachedRowid(pC->pCursor, 0); |
| 70470 | rc = sqlite3BtreeDelete(pC->pCursor); |
| 70471 | pC->cacheStatus = CACHE_STALE; |
| 70472 | |
| 70473 | /* Invoke the update-hook if required. */ |
| 70474 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ |
| 70475 | db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 70476 | db->aDb[pC->iDb].zName, pOp->p4.z, iKey); |
| 70477 | assert( pC->iDb>=0 ); |
| 70478 | } |
| 70479 | if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| 70480 | break; |
| 70481 | } |
| 70482 | /* Opcode: ResetCount * * * * * |
| @@ -70506,21 +70774,23 @@ | |
| 70506 | ** |
| 70507 | ** Fall through to next instruction if the two records compare equal to |
| 70508 | ** each other. Jump to P2 if they are different. |
| 70509 | */ |
| 70510 | case OP_SorterCompare: { |
| 70511 | VdbeCursor *pC; |
| 70512 | int res; |
| 70513 | int nIgnore; |
| 70514 | |
| 70515 | pC = p->apCsr[pOp->p1]; |
| 70516 | assert( isSorter(pC) ); |
| 70517 | assert( pOp->p4type==P4_INT32 ); |
| 70518 | pIn3 = &aMem[pOp->p3]; |
| 70519 | nIgnore = pOp->p4.i; |
| 70520 | rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res); |
| 70521 | if( res ){ |
| 70522 | pc = pOp->p2-1; |
| 70523 | } |
| 70524 | break; |
| 70525 | }; |
| 70526 | |
| @@ -70528,16 +70798,18 @@ | |
| 70528 | ** Synopsis: r[P2]=data |
| 70529 | ** |
| 70530 | ** Write into register P2 the current sorter data for sorter cursor P1. |
| 70531 | */ |
| 70532 | case OP_SorterData: { |
| 70533 | VdbeCursor *pC; |
| 70534 | |
| 70535 | pOut = &aMem[pOp->p2]; |
| 70536 | pC = p->apCsr[pOp->p1]; |
| 70537 | assert( isSorter(pC) ); |
| 70538 | rc = sqlite3VdbeSorterRowkey(pC, pOut); |
| 70539 | break; |
| 70540 | } |
| 70541 | |
| 70542 | /* Opcode: RowData P1 P2 * * * |
| 70543 | ** Synopsis: r[P2]=data |
| @@ -70561,64 +70833,66 @@ | |
| 70561 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 70562 | ** of a real table, not a pseudo-table. |
| 70563 | */ |
| 70564 | case OP_RowKey: |
| 70565 | case OP_RowData: { |
| 70566 | VdbeCursor *pC; |
| 70567 | BtCursor *pCrsr; |
| 70568 | u32 n; |
| 70569 | i64 n64; |
| 70570 | |
| 70571 | pOut = &aMem[pOp->p2]; |
| 70572 | memAboutToChange(p, pOut); |
| 70573 | |
| 70574 | /* Note that RowKey and RowData are really exactly the same instruction */ |
| 70575 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70576 | pC = p->apCsr[pOp->p1]; |
| 70577 | assert( isSorter(pC)==0 ); |
| 70578 | assert( pC->isTable || pOp->opcode!=OP_RowData ); |
| 70579 | assert( pC->isTable==0 || pOp->opcode==OP_RowData ); |
| 70580 | assert( pC!=0 ); |
| 70581 | assert( pC->nullRow==0 ); |
| 70582 | assert( pC->pseudoTableReg==0 ); |
| 70583 | assert( pC->pCursor!=0 ); |
| 70584 | pCrsr = pC->pCursor; |
| 70585 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 70586 | |
| 70587 | /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or |
| 70588 | ** OP_Rewind/Op_Next with no intervening instructions that might invalidate |
| 70589 | ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always |
| 70590 | ** a no-op and can never fail. But we leave it in place as a safety. |
| 70591 | */ |
| 70592 | assert( pC->deferredMoveto==0 ); |
| 70593 | rc = sqlite3VdbeCursorMoveto(pC); |
| 70594 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70595 | |
| 70596 | if( pC->isTable==0 ){ |
| 70597 | assert( !pC->isTable ); |
| 70598 | VVA_ONLY(rc =) sqlite3BtreeKeySize(pCrsr, &n64); |
| 70599 | assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 70600 | if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70601 | goto too_big; |
| 70602 | } |
| 70603 | n = (u32)n64; |
| 70604 | }else{ |
| 70605 | VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &n); |
| 70606 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 70607 | if( n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70608 | goto too_big; |
| 70609 | } |
| 70610 | } |
| 70611 | if( sqlite3VdbeMemGrow(pOut, n, 0) ){ |
| 70612 | goto no_mem; |
| 70613 | } |
| 70614 | pOut->n = n; |
| 70615 | MemSetTypeFlag(pOut, MEM_Blob); |
| 70616 | if( pC->isTable==0 ){ |
| 70617 | rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z); |
| 70618 | }else{ |
| 70619 | rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z); |
| 70620 | } |
| 70621 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ |
| 70622 | UPDATE_MAX_BLOBSIZE(pOut); |
| 70623 | REGISTER_TRACE(pOp->p2, pOut); |
| 70624 | break; |
| @@ -70633,44 +70907,46 @@ | |
| 70633 | ** P1 can be either an ordinary table or a virtual table. There used to |
| 70634 | ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 70635 | ** one opcode now works for both table types. |
| 70636 | */ |
| 70637 | case OP_Rowid: { /* out2-prerelease */ |
| 70638 | VdbeCursor *pC; |
| 70639 | i64 v; |
| 70640 | sqlite3_vtab *pVtab; |
| 70641 | const sqlite3_module *pModule; |
| 70642 | |
| 70643 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70644 | pC = p->apCsr[pOp->p1]; |
| 70645 | assert( pC!=0 ); |
| 70646 | assert( pC->pseudoTableReg==0 || pC->nullRow ); |
| 70647 | if( pC->nullRow ){ |
| 70648 | pOut->flags = MEM_Null; |
| 70649 | break; |
| 70650 | }else if( pC->deferredMoveto ){ |
| 70651 | v = pC->movetoTarget; |
| 70652 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 70653 | }else if( pC->pVtabCursor ){ |
| 70654 | pVtab = pC->pVtabCursor->pVtab; |
| 70655 | pModule = pVtab->pModule; |
| 70656 | assert( pModule->xRowid ); |
| 70657 | rc = pModule->xRowid(pC->pVtabCursor, &v); |
| 70658 | sqlite3VtabImportErrmsg(p, pVtab); |
| 70659 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 70660 | }else{ |
| 70661 | assert( pC->pCursor!=0 ); |
| 70662 | rc = sqlite3VdbeCursorMoveto(pC); |
| 70663 | if( rc ) goto abort_due_to_error; |
| 70664 | if( pC->rowidIsValid ){ |
| 70665 | v = pC->lastRowid; |
| 70666 | }else{ |
| 70667 | rc = sqlite3BtreeKeySize(pC->pCursor, &v); |
| 70668 | assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */ |
| 70669 | } |
| 70670 | } |
| 70671 | pOut->u.i = v; |
| 70672 | break; |
| 70673 | } |
| 70674 | |
| 70675 | /* Opcode: NullRow P1 * * * * |
| 70676 | ** |
| @@ -70677,21 +70953,23 @@ | |
| 70677 | ** Move the cursor P1 to a null row. Any OP_Column operations |
| 70678 | ** that occur while the cursor is on the null row will always |
| 70679 | ** write a NULL. |
| 70680 | */ |
| 70681 | case OP_NullRow: { |
| 70682 | VdbeCursor *pC; |
| 70683 | |
| 70684 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70685 | pC = p->apCsr[pOp->p1]; |
| 70686 | assert( pC!=0 ); |
| 70687 | pC->nullRow = 1; |
| 70688 | pC->rowidIsValid = 0; |
| 70689 | pC->cacheStatus = CACHE_STALE; |
| 70690 | assert( pC->pCursor || pC->pVtabCursor ); |
| 70691 | if( pC->pCursor ){ |
| 70692 | sqlite3BtreeClearCursor(pC->pCursor); |
| 70693 | } |
| 70694 | break; |
| 70695 | } |
| 70696 | |
| 70697 | /* Opcode: Last P1 P2 * * * |
| @@ -70701,26 +70979,28 @@ | |
| 70701 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 70702 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 70703 | ** to the following instruction. |
| 70704 | */ |
| 70705 | case OP_Last: { /* jump */ |
| 70706 | VdbeCursor *pC; |
| 70707 | BtCursor *pCrsr; |
| 70708 | int res; |
| 70709 | |
| 70710 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70711 | pC = p->apCsr[pOp->p1]; |
| 70712 | assert( pC!=0 ); |
| 70713 | pCrsr = pC->pCursor; |
| 70714 | res = 0; |
| 70715 | assert( pCrsr!=0 ); |
| 70716 | rc = sqlite3BtreeLast(pCrsr, &res); |
| 70717 | pC->nullRow = (u8)res; |
| 70718 | pC->deferredMoveto = 0; |
| 70719 | pC->rowidIsValid = 0; |
| 70720 | pC->cacheStatus = CACHE_STALE; |
| 70721 | if( pOp->p2>0 && res ){ |
| 70722 | pc = pOp->p2 - 1; |
| 70723 | } |
| 70724 | break; |
| 70725 | } |
| 70726 | |
| @@ -70753,32 +71033,34 @@ | |
| 70753 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 70754 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 70755 | ** to the following instruction. |
| 70756 | */ |
| 70757 | case OP_Rewind: { /* jump */ |
| 70758 | VdbeCursor *pC; |
| 70759 | BtCursor *pCrsr; |
| 70760 | int res; |
| 70761 | |
| 70762 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70763 | pC = p->apCsr[pOp->p1]; |
| 70764 | assert( pC!=0 ); |
| 70765 | assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) ); |
| 70766 | res = 1; |
| 70767 | if( isSorter(pC) ){ |
| 70768 | rc = sqlite3VdbeSorterRewind(db, pC, &res); |
| 70769 | }else{ |
| 70770 | pCrsr = pC->pCursor; |
| 70771 | assert( pCrsr ); |
| 70772 | rc = sqlite3BtreeFirst(pCrsr, &res); |
| 70773 | pC->deferredMoveto = 0; |
| 70774 | pC->cacheStatus = CACHE_STALE; |
| 70775 | pC->rowidIsValid = 0; |
| 70776 | } |
| 70777 | pC->nullRow = (u8)res; |
| 70778 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 70779 | if( res ){ |
| 70780 | pc = pOp->p2 - 1; |
| 70781 | } |
| 70782 | break; |
| 70783 | } |
| 70784 | |
| @@ -70825,47 +71107,49 @@ | |
| 70825 | ** |
| 70826 | ** This opcode works just like OP_Prev except that if cursor P1 is not |
| 70827 | ** open it behaves a no-op. |
| 70828 | */ |
| 70829 | case OP_SorterNext: { /* jump */ |
| 70830 | VdbeCursor *pC; |
| 70831 | int res; |
| 70832 | |
| 70833 | pC = p->apCsr[pOp->p1]; |
| 70834 | assert( isSorter(pC) ); |
| 70835 | rc = sqlite3VdbeSorterNext(db, pC, &res); |
| 70836 | goto next_tail; |
| 70837 | case OP_PrevIfOpen: /* jump */ |
| 70838 | case OP_NextIfOpen: /* jump */ |
| 70839 | if( p->apCsr[pOp->p1]==0 ) break; |
| 70840 | /* Fall through */ |
| 70841 | case OP_Prev: /* jump */ |
| 70842 | case OP_Next: /* jump */ |
| 70843 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70844 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 70845 | pC = p->apCsr[pOp->p1]; |
| 70846 | assert( pC!=0 ); |
| 70847 | assert( pC->deferredMoveto==0 ); |
| 70848 | assert( pC->pCursor ); |
| 70849 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70850 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 70851 | assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 70852 | assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); |
| 70853 | rc = pOp->p4.xAdvance(pC->pCursor, &res); |
| 70854 | next_tail: |
| 70855 | pC->cacheStatus = CACHE_STALE; |
| 70856 | if( res==0 ){ |
| 70857 | pC->nullRow = 0; |
| 70858 | pc = pOp->p2 - 1; |
| 70859 | p->aCounter[pOp->p5]++; |
| 70860 | #ifdef SQLITE_TEST |
| 70861 | sqlite3_search_count++; |
| 70862 | #endif |
| 70863 | }else{ |
| 70864 | pC->nullRow = 1; |
| 70865 | } |
| 70866 | pC->rowidIsValid = 0; |
| 70867 | goto check_for_interrupt; |
| 70868 | } |
| 70869 | |
| 70870 | /* Opcode: IdxInsert P1 P2 P3 * P5 |
| 70871 | ** Synopsis: key=r[P2] |
| @@ -70880,37 +71164,39 @@ | |
| 70880 | ** This instruction only works for indices. The equivalent instruction |
| 70881 | ** for tables is OP_Insert. |
| 70882 | */ |
| 70883 | case OP_SorterInsert: /* in2 */ |
| 70884 | case OP_IdxInsert: { /* in2 */ |
| 70885 | VdbeCursor *pC; |
| 70886 | BtCursor *pCrsr; |
| 70887 | int nKey; |
| 70888 | const char *zKey; |
| 70889 | |
| 70890 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70891 | pC = p->apCsr[pOp->p1]; |
| 70892 | assert( pC!=0 ); |
| 70893 | assert( isSorter(pC)==(pOp->opcode==OP_SorterInsert) ); |
| 70894 | pIn2 = &aMem[pOp->p2]; |
| 70895 | assert( pIn2->flags & MEM_Blob ); |
| 70896 | pCrsr = pC->pCursor; |
| 70897 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 70898 | assert( pCrsr!=0 ); |
| 70899 | assert( pC->isTable==0 ); |
| 70900 | rc = ExpandBlob(pIn2); |
| 70901 | if( rc==SQLITE_OK ){ |
| 70902 | if( isSorter(pC) ){ |
| 70903 | rc = sqlite3VdbeSorterWrite(db, pC, pIn2); |
| 70904 | }else{ |
| 70905 | nKey = pIn2->n; |
| 70906 | zKey = pIn2->z; |
| 70907 | rc = sqlite3BtreeInsert(pCrsr, zKey, nKey, "", 0, 0, pOp->p3, |
| 70908 | ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0) |
| 70909 | ); |
| 70910 | assert( pC->deferredMoveto==0 ); |
| 70911 | pC->cacheStatus = CACHE_STALE; |
| 70912 | } |
| 70913 | } |
| 70914 | break; |
| 70915 | } |
| 70916 | |
| @@ -70920,36 +71206,38 @@ | |
| 70920 | ** The content of P3 registers starting at register P2 form |
| 70921 | ** an unpacked index key. This opcode removes that entry from the |
| 70922 | ** index opened by cursor P1. |
| 70923 | */ |
| 70924 | case OP_IdxDelete: { |
| 70925 | VdbeCursor *pC; |
| 70926 | BtCursor *pCrsr; |
| 70927 | int res; |
| 70928 | UnpackedRecord r; |
| 70929 | |
| 70930 | assert( pOp->p3>0 ); |
| 70931 | assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 ); |
| 70932 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70933 | pC = p->apCsr[pOp->p1]; |
| 70934 | assert( pC!=0 ); |
| 70935 | pCrsr = pC->pCursor; |
| 70936 | assert( pCrsr!=0 ); |
| 70937 | assert( pOp->p5==0 ); |
| 70938 | r.pKeyInfo = pC->pKeyInfo; |
| 70939 | r.nField = (u16)pOp->p3; |
| 70940 | r.flags = UNPACKED_PREFIX_MATCH; |
| 70941 | r.aMem = &aMem[pOp->p2]; |
| 70942 | #ifdef SQLITE_DEBUG |
| 70943 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 70944 | #endif |
| 70945 | rc = sqlite3BtreeMovetoUnpacked(pCrsr, &r, 0, 0, &res); |
| 70946 | if( rc==SQLITE_OK && res==0 ){ |
| 70947 | rc = sqlite3BtreeDelete(pCrsr); |
| 70948 | } |
| 70949 | assert( pC->deferredMoveto==0 ); |
| 70950 | pC->cacheStatus = CACHE_STALE; |
| 70951 | break; |
| 70952 | } |
| 70953 | |
| 70954 | /* Opcode: IdxRowid P1 P2 * * * |
| 70955 | ** Synopsis: r[P2]=rowid |
| @@ -70959,31 +71247,32 @@ | |
| 70959 | ** the rowid of the table entry to which this index entry points. |
| 70960 | ** |
| 70961 | ** See also: Rowid, MakeRecord. |
| 70962 | */ |
| 70963 | case OP_IdxRowid: { /* out2-prerelease */ |
| 70964 | BtCursor *pCrsr; |
| 70965 | VdbeCursor *pC; |
| 70966 | i64 rowid; |
| 70967 | |
| 70968 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70969 | pC = p->apCsr[pOp->p1]; |
| 70970 | assert( pC!=0 ); |
| 70971 | pCrsr = pC->pCursor; |
| 70972 | assert( pCrsr!=0 ); |
| 70973 | pOut->flags = MEM_Null; |
| 70974 | rc = sqlite3VdbeCursorMoveto(pC); |
| 70975 | if( NEVER(rc) ) goto abort_due_to_error; |
| 70976 | assert( pC->deferredMoveto==0 ); |
| 70977 | assert( pC->isTable==0 ); |
| 70978 | if( !pC->nullRow ){ |
| 70979 | rowid = 0; /* Not needed. Only used to silence a warning. */ |
| 70980 | rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid); |
| 70981 | if( rc!=SQLITE_OK ){ |
| 70982 | goto abort_due_to_error; |
| 70983 | } |
| 70984 | pOut->u.i = rowid; |
| 70985 | pOut->flags = MEM_Int; |
| 70986 | } |
| 70987 | break; |
| 70988 | } |
| 70989 | |
| @@ -71015,42 +71304,43 @@ | |
| 71015 | ** If P5 is non-zero then the key value is increased by an epsilon prior |
| 71016 | ** to the comparison. This makes the opcode work like IdxLE. |
| 71017 | */ |
| 71018 | case OP_IdxLT: /* jump */ |
| 71019 | case OP_IdxGE: { /* jump */ |
| 71020 | VdbeCursor *pC; |
| 71021 | int res; |
| 71022 | UnpackedRecord r; |
| 71023 | |
| 71024 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71025 | pC = p->apCsr[pOp->p1]; |
| 71026 | assert( pC!=0 ); |
| 71027 | assert( pC->isOrdered ); |
| 71028 | assert( pC->pCursor!=0); |
| 71029 | assert( pC->deferredMoveto==0 ); |
| 71030 | assert( pOp->p5==0 || pOp->p5==1 ); |
| 71031 | assert( pOp->p4type==P4_INT32 ); |
| 71032 | r.pKeyInfo = pC->pKeyInfo; |
| 71033 | r.nField = (u16)pOp->p4.i; |
| 71034 | if( pOp->p5 ){ |
| 71035 | r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH; |
| 71036 | }else{ |
| 71037 | r.flags = UNPACKED_PREFIX_MATCH; |
| 71038 | } |
| 71039 | r.aMem = &aMem[pOp->p3]; |
| 71040 | #ifdef SQLITE_DEBUG |
| 71041 | { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); } |
| 71042 | #endif |
| 71043 | res = 0; /* Not needed. Only used to silence a warning. */ |
| 71044 | rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res); |
| 71045 | if( pOp->opcode==OP_IdxLT ){ |
| 71046 | res = -res; |
| 71047 | }else{ |
| 71048 | assert( pOp->opcode==OP_IdxGE ); |
| 71049 | res++; |
| 71050 | } |
| 71051 | if( res>0 ){ |
| 71052 | pc = pOp->p2 - 1 ; |
| 71053 | } |
| 71054 | break; |
| 71055 | } |
| 71056 | |
| @@ -71073,46 +71363,47 @@ | |
| 71073 | ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 71074 | ** |
| 71075 | ** See also: Clear |
| 71076 | */ |
| 71077 | case OP_Destroy: { /* out2-prerelease */ |
| 71078 | int iMoved; |
| 71079 | int iCnt; |
| 71080 | Vdbe *pVdbe; |
| 71081 | int iDb; |
| 71082 | |
| 71083 | assert( p->readOnly==0 ); |
| 71084 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 71085 | iCnt = 0; |
| 71086 | for(pVdbe=db->pVdbe; pVdbe; pVdbe = pVdbe->pNext){ |
| 71087 | if( pVdbe->magic==VDBE_MAGIC_RUN && pVdbe->bIsReader |
| 71088 | && pVdbe->inVtabMethod<2 && pVdbe->pc>=0 |
| 71089 | ){ |
| 71090 | iCnt++; |
| 71091 | } |
| 71092 | } |
| 71093 | #else |
| 71094 | iCnt = db->nVdbeRead; |
| 71095 | #endif |
| 71096 | pOut->flags = MEM_Null; |
| 71097 | if( iCnt>1 ){ |
| 71098 | rc = SQLITE_LOCKED; |
| 71099 | p->errorAction = OE_Abort; |
| 71100 | }else{ |
| 71101 | iDb = pOp->p3; |
| 71102 | assert( iCnt==1 ); |
| 71103 | assert( (p->btreeMask & (((yDbMask)1)<<iDb))!=0 ); |
| 71104 | iMoved = 0; /* Not needed. Only to silence a warning. */ |
| 71105 | rc = sqlite3BtreeDropTable(db->aDb[iDb].pBt, pOp->p1, &iMoved); |
| 71106 | pOut->flags = MEM_Int; |
| 71107 | pOut->u.i = iMoved; |
| 71108 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 71109 | if( rc==SQLITE_OK && iMoved!=0 ){ |
| 71110 | sqlite3RootPageMoved(db, iDb, iMoved, pOp->p1); |
| 71111 | /* All OP_Destroy operations occur on the same btree */ |
| 71112 | assert( resetSchemaOnFault==0 || resetSchemaOnFault==iDb+1 ); |
| 71113 | resetSchemaOnFault = iDb+1; |
| 71114 | } |
| 71115 | #endif |
| 71116 | } |
| 71117 | break; |
| 71118 | } |
| @@ -71134,25 +71425,27 @@ | |
| 71134 | ** also incremented by the number of rows in the table being cleared. |
| 71135 | ** |
| 71136 | ** See also: Destroy |
| 71137 | */ |
| 71138 | case OP_Clear: { |
| 71139 | int nChange; |
| 71140 | |
| 71141 | nChange = 0; |
| 71142 | assert( p->readOnly==0 ); |
| 71143 | assert( pOp->p1!=1 ); |
| 71144 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 ); |
| 71145 | rc = sqlite3BtreeClearTable( |
| 71146 | db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0) |
| 71147 | ); |
| 71148 | if( pOp->p3 ){ |
| 71149 | p->nChange += nChange; |
| 71150 | if( pOp->p3>0 ){ |
| 71151 | assert( memIsValid(&aMem[pOp->p3]) ); |
| 71152 | memAboutToChange(p, &aMem[pOp->p3]); |
| 71153 | aMem[pOp->p3].u.i += nChange; |
| 71154 | } |
| 71155 | } |
| 71156 | break; |
| 71157 | } |
| 71158 | |
| @@ -71180,28 +71473,30 @@ | |
| 71180 | ** |
| 71181 | ** See documentation on OP_CreateTable for additional information. |
| 71182 | */ |
| 71183 | case OP_CreateIndex: /* out2-prerelease */ |
| 71184 | case OP_CreateTable: { /* out2-prerelease */ |
| 71185 | int pgno; |
| 71186 | int flags; |
| 71187 | Db *pDb; |
| 71188 | |
| 71189 | pgno = 0; |
| 71190 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 71191 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 71192 | assert( p->readOnly==0 ); |
| 71193 | pDb = &db->aDb[pOp->p1]; |
| 71194 | assert( pDb->pBt!=0 ); |
| 71195 | if( pOp->opcode==OP_CreateTable ){ |
| 71196 | /* flags = BTREE_INTKEY; */ |
| 71197 | flags = BTREE_INTKEY; |
| 71198 | }else{ |
| 71199 | flags = BTREE_BLOBKEY; |
| 71200 | } |
| 71201 | rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags); |
| 71202 | pOut->u.i = pgno; |
| 71203 | break; |
| 71204 | } |
| 71205 | |
| 71206 | /* Opcode: ParseSchema P1 * * P4 * |
| 71207 | ** |
| @@ -71210,54 +71505,56 @@ | |
| 71210 | ** |
| 71211 | ** This opcode invokes the parser to create a new virtual machine, |
| 71212 | ** then runs the new virtual machine. It is thus a re-entrant opcode. |
| 71213 | */ |
| 71214 | case OP_ParseSchema: { |
| 71215 | int iDb; |
| 71216 | const char *zMaster; |
| 71217 | char *zSql; |
| 71218 | InitData initData; |
| 71219 | |
| 71220 | /* Any prepared statement that invokes this opcode will hold mutexes |
| 71221 | ** on every btree. This is a prerequisite for invoking |
| 71222 | ** sqlite3InitCallback(). |
| 71223 | */ |
| 71224 | #ifdef SQLITE_DEBUG |
| 71225 | for(iDb=0; iDb<db->nDb; iDb++){ |
| 71226 | assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) ); |
| 71227 | } |
| 71228 | #endif |
| 71229 | |
| 71230 | iDb = pOp->p1; |
| 71231 | assert( iDb>=0 && iDb<db->nDb ); |
| 71232 | assert( DbHasProperty(db, iDb, DB_SchemaLoaded) ); |
| 71233 | /* Used to be a conditional */ { |
| 71234 | zMaster = SCHEMA_TABLE(iDb); |
| 71235 | initData.db = db; |
| 71236 | initData.iDb = pOp->p1; |
| 71237 | initData.pzErrMsg = &p->zErrMsg; |
| 71238 | zSql = sqlite3MPrintf(db, |
| 71239 | "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid", |
| 71240 | db->aDb[iDb].zName, zMaster, pOp->p4.z); |
| 71241 | if( zSql==0 ){ |
| 71242 | rc = SQLITE_NOMEM; |
| 71243 | }else{ |
| 71244 | assert( db->init.busy==0 ); |
| 71245 | db->init.busy = 1; |
| 71246 | initData.rc = SQLITE_OK; |
| 71247 | assert( !db->mallocFailed ); |
| 71248 | rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0); |
| 71249 | if( rc==SQLITE_OK ) rc = initData.rc; |
| 71250 | sqlite3DbFree(db, zSql); |
| 71251 | db->init.busy = 0; |
| 71252 | } |
| 71253 | } |
| 71254 | if( rc ) sqlite3ResetAllSchemasOfConnection(db); |
| 71255 | if( rc==SQLITE_NOMEM ){ |
| 71256 | goto no_mem; |
| 71257 | } |
| 71258 | break; |
| 71259 | } |
| 71260 | |
| 71261 | #if !defined(SQLITE_OMIT_ANALYZE) |
| 71262 | /* Opcode: LoadAnalysis P1 * * * * |
| 71263 | ** |
| @@ -71329,44 +71626,46 @@ | |
| 71329 | ** file, not the main database file. |
| 71330 | ** |
| 71331 | ** This opcode is used to implement the integrity_check pragma. |
| 71332 | */ |
| 71333 | case OP_IntegrityCk: { |
| 71334 | int nRoot; /* Number of tables to check. (Number of root pages.) */ |
| 71335 | int *aRoot; /* Array of rootpage numbers for tables to be checked */ |
| 71336 | int j; /* Loop counter */ |
| 71337 | int nErr; /* Number of errors reported */ |
| 71338 | char *z; /* Text of the error report */ |
| 71339 | Mem *pnErr; /* Register keeping track of errors remaining */ |
| 71340 | |
| 71341 | assert( p->bIsReader ); |
| 71342 | nRoot = pOp->p2; |
| 71343 | assert( nRoot>0 ); |
| 71344 | aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(nRoot+1) ); |
| 71345 | if( aRoot==0 ) goto no_mem; |
| 71346 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 71347 | pnErr = &aMem[pOp->p3]; |
| 71348 | assert( (pnErr->flags & MEM_Int)!=0 ); |
| 71349 | assert( (pnErr->flags & (MEM_Str|MEM_Blob))==0 ); |
| 71350 | pIn1 = &aMem[pOp->p1]; |
| 71351 | for(j=0; j<nRoot; j++){ |
| 71352 | aRoot[j] = (int)sqlite3VdbeIntValue(&pIn1[j]); |
| 71353 | } |
| 71354 | aRoot[j] = 0; |
| 71355 | assert( pOp->p5<db->nDb ); |
| 71356 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 ); |
| 71357 | z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, aRoot, nRoot, |
| 71358 | (int)pnErr->u.i, &nErr); |
| 71359 | sqlite3DbFree(db, aRoot); |
| 71360 | pnErr->u.i -= nErr; |
| 71361 | sqlite3VdbeMemSetNull(pIn1); |
| 71362 | if( nErr==0 ){ |
| 71363 | assert( z==0 ); |
| 71364 | }else if( z==0 ){ |
| 71365 | goto no_mem; |
| 71366 | }else{ |
| 71367 | sqlite3VdbeMemSetStr(pIn1, z, -1, SQLITE_UTF8, sqlite3_free); |
| 71368 | } |
| 71369 | UPDATE_MAX_BLOBSIZE(pIn1); |
| 71370 | sqlite3VdbeChangeEncoding(pIn1, encoding); |
| 71371 | break; |
| 71372 | } |
| @@ -71398,22 +71697,24 @@ | |
| 71398 | ** Extract the smallest value from boolean index P1 and put that value into |
| 71399 | ** register P3. Or, if boolean index P1 is initially empty, leave P3 |
| 71400 | ** unchanged and jump to instruction P2. |
| 71401 | */ |
| 71402 | case OP_RowSetRead: { /* jump, in1, out3 */ |
| 71403 | i64 val; |
| 71404 | |
| 71405 | pIn1 = &aMem[pOp->p1]; |
| 71406 | if( (pIn1->flags & MEM_RowSet)==0 |
| 71407 | || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0 |
| 71408 | ){ |
| 71409 | /* The boolean index is empty */ |
| 71410 | sqlite3VdbeMemSetNull(pIn1); |
| 71411 | pc = pOp->p2 - 1; |
| 71412 | }else{ |
| 71413 | /* A value was pulled from the index */ |
| 71414 | sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val); |
| 71415 | } |
| 71416 | goto check_for_interrupt; |
| 71417 | } |
| 71418 | |
| 71419 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| @@ -71439,16 +71740,18 @@ | |
| 71439 | ** inserted, there is no need to search to see if the same value was |
| 71440 | ** previously inserted as part of set X (only if it was previously |
| 71441 | ** inserted as part of some other set). |
| 71442 | */ |
| 71443 | case OP_RowSetTest: { /* jump, in1, in3 */ |
| 71444 | int iSet; |
| 71445 | int exists; |
| 71446 | |
| 71447 | pIn1 = &aMem[pOp->p1]; |
| 71448 | pIn3 = &aMem[pOp->p3]; |
| 71449 | iSet = pOp->p4.i; |
| 71450 | assert( pIn3->flags&MEM_Int ); |
| 71451 | |
| 71452 | /* If there is anything other than a rowset object in memory cell P1, |
| 71453 | ** delete it now and initialize P1 with an empty rowset |
| 71454 | */ |
| @@ -71456,21 +71759,21 @@ | |
| 71456 | sqlite3VdbeMemSetRowSet(pIn1); |
| 71457 | if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem; |
| 71458 | } |
| 71459 | |
| 71460 | assert( pOp->p4type==P4_INT32 ); |
| 71461 | assert( iSet==-1 || iSet>=0 ); |
| 71462 | if( iSet ){ |
| 71463 | exists = sqlite3RowSetTest(pIn1->u.pRowSet, |
| 71464 | (u8)(iSet>=0 ? iSet & 0xf : 0xff), |
| 71465 | pIn3->u.i); |
| 71466 | if( exists ){ |
| 71467 | pc = pOp->p2 - 1; |
| 71468 | break; |
| 71469 | } |
| 71470 | } |
| 71471 | if( iSet>=0 ){ |
| 71472 | sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 71473 | } |
| 71474 | break; |
| 71475 | } |
| 71476 | |
| @@ -71489,109 +71792,111 @@ | |
| 71489 | ** memory required by the sub-vdbe at runtime. |
| 71490 | ** |
| 71491 | ** P4 is a pointer to the VM containing the trigger program. |
| 71492 | */ |
| 71493 | case OP_Program: { /* jump */ |
| 71494 | int nMem; /* Number of memory registers for sub-program */ |
| 71495 | int nByte; /* Bytes of runtime space required for sub-program */ |
| 71496 | Mem *pRt; /* Register to allocate runtime space */ |
| 71497 | Mem *pMem; /* Used to iterate through memory cells */ |
| 71498 | Mem *pEnd; /* Last memory cell in new array */ |
| 71499 | VdbeFrame *pFrame; /* New vdbe frame to execute in */ |
| 71500 | SubProgram *pProgram; /* Sub-program to execute */ |
| 71501 | void *t; /* Token identifying trigger */ |
| 71502 | |
| 71503 | pProgram = pOp->p4.pProgram; |
| 71504 | pRt = &aMem[pOp->p3]; |
| 71505 | assert( pProgram->nOp>0 ); |
| 71506 | |
| 71507 | /* If the p5 flag is clear, then recursive invocation of triggers is |
| 71508 | ** disabled for backwards compatibility (p5 is set if this sub-program |
| 71509 | ** is really a trigger, not a foreign key action, and the flag set |
| 71510 | ** and cleared by the "PRAGMA recursive_triggers" command is clear). |
| 71511 | ** |
| 71512 | ** It is recursive invocation of triggers, at the SQL level, that is |
| 71513 | ** disabled. In some cases a single trigger may generate more than one |
| 71514 | ** SubProgram (if the trigger may be executed with more than one different |
| 71515 | ** ON CONFLICT algorithm). SubProgram structures associated with a |
| 71516 | ** single trigger all have the same value for the SubProgram.token |
| 71517 | ** variable. */ |
| 71518 | if( pOp->p5 ){ |
| 71519 | t = pProgram->token; |
| 71520 | for(pFrame=p->pFrame; pFrame && pFrame->token!=t; pFrame=pFrame->pParent); |
| 71521 | if( pFrame ) break; |
| 71522 | } |
| 71523 | |
| 71524 | if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 71525 | rc = SQLITE_ERROR; |
| 71526 | sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion"); |
| 71527 | break; |
| 71528 | } |
| 71529 | |
| 71530 | /* Register pRt is used to store the memory required to save the state |
| 71531 | ** of the current program, and the memory required at runtime to execute |
| 71532 | ** the trigger program. If this trigger has been fired before, then pRt |
| 71533 | ** is already allocated. Otherwise, it must be initialized. */ |
| 71534 | if( (pRt->flags&MEM_Frame)==0 ){ |
| 71535 | /* SubProgram.nMem is set to the number of memory cells used by the |
| 71536 | ** program stored in SubProgram.aOp. As well as these, one memory |
| 71537 | ** cell is required for each cursor used by the program. Set local |
| 71538 | ** variable nMem (and later, VdbeFrame.nChildMem) to this value. |
| 71539 | */ |
| 71540 | nMem = pProgram->nMem + pProgram->nCsr; |
| 71541 | nByte = ROUND8(sizeof(VdbeFrame)) |
| 71542 | + nMem * sizeof(Mem) |
| 71543 | + pProgram->nCsr * sizeof(VdbeCursor *) |
| 71544 | + pProgram->nOnce * sizeof(u8); |
| 71545 | pFrame = sqlite3DbMallocZero(db, nByte); |
| 71546 | if( !pFrame ){ |
| 71547 | goto no_mem; |
| 71548 | } |
| 71549 | sqlite3VdbeMemRelease(pRt); |
| 71550 | pRt->flags = MEM_Frame; |
| 71551 | pRt->u.pFrame = pFrame; |
| 71552 | |
| 71553 | pFrame->v = p; |
| 71554 | pFrame->nChildMem = nMem; |
| 71555 | pFrame->nChildCsr = pProgram->nCsr; |
| 71556 | pFrame->pc = pc; |
| 71557 | pFrame->aMem = p->aMem; |
| 71558 | pFrame->nMem = p->nMem; |
| 71559 | pFrame->apCsr = p->apCsr; |
| 71560 | pFrame->nCursor = p->nCursor; |
| 71561 | pFrame->aOp = p->aOp; |
| 71562 | pFrame->nOp = p->nOp; |
| 71563 | pFrame->token = pProgram->token; |
| 71564 | pFrame->aOnceFlag = p->aOnceFlag; |
| 71565 | pFrame->nOnceFlag = p->nOnceFlag; |
| 71566 | |
| 71567 | pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem]; |
| 71568 | for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){ |
| 71569 | pMem->flags = MEM_Invalid; |
| 71570 | pMem->db = db; |
| 71571 | } |
| 71572 | }else{ |
| 71573 | pFrame = pRt->u.pFrame; |
| 71574 | assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem ); |
| 71575 | assert( pProgram->nCsr==pFrame->nChildCsr ); |
| 71576 | assert( pc==pFrame->pc ); |
| 71577 | } |
| 71578 | |
| 71579 | p->nFrame++; |
| 71580 | pFrame->pParent = p->pFrame; |
| 71581 | pFrame->lastRowid = lastRowid; |
| 71582 | pFrame->nChange = p->nChange; |
| 71583 | p->nChange = 0; |
| 71584 | p->pFrame = pFrame; |
| 71585 | p->aMem = aMem = &VdbeFrameMem(pFrame)[-1]; |
| 71586 | p->nMem = pFrame->nChildMem; |
| 71587 | p->nCursor = (u16)pFrame->nChildCsr; |
| 71588 | p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 71589 | p->aOp = aOp = pProgram->aOp; |
| 71590 | p->nOp = pProgram->nOp; |
| 71591 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 71592 | p->nOnceFlag = pProgram->nOnce; |
| 71593 | pc = -1; |
| 71594 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 71595 | |
| 71596 | break; |
| 71597 | } |
| @@ -71607,15 +71912,17 @@ | |
| 71607 | ** The address of the cell in the parent frame is determined by adding |
| 71608 | ** the value of the P1 argument to the value of the P1 argument to the |
| 71609 | ** calling OP_Program instruction. |
| 71610 | */ |
| 71611 | case OP_Param: { /* out2-prerelease */ |
| 71612 | VdbeFrame *pFrame; |
| 71613 | Mem *pIn; |
| 71614 | pFrame = p->pFrame; |
| 71615 | pIn = &pFrame->aMem[pOp->p1 + pFrame->aOp[pFrame->pc].p1]; |
| 71616 | sqlite3VdbeMemShallowCopy(pOut, pIn, MEM_Ephem); |
| 71617 | break; |
| 71618 | } |
| 71619 | |
| 71620 | #endif /* #ifndef SQLITE_OMIT_TRIGGER */ |
| 71621 | |
| @@ -71672,23 +71979,26 @@ | |
| 71672 | ** |
| 71673 | ** This instruction throws an error if the memory cell is not initially |
| 71674 | ** an integer. |
| 71675 | */ |
| 71676 | case OP_MemMax: { /* in2 */ |
| 71677 | VdbeFrame *pFrame; |
| 71678 | if( p->pFrame ){ |
| 71679 | for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent); |
| 71680 | pIn1 = &pFrame->aMem[pOp->p1]; |
| 71681 | }else{ |
| 71682 | pIn1 = &aMem[pOp->p1]; |
| 71683 | } |
| 71684 | assert( memIsValid(pIn1) ); |
| 71685 | sqlite3VdbeMemIntegerify(pIn1); |
| 71686 | pIn2 = &aMem[pOp->p2]; |
| 71687 | sqlite3VdbeMemIntegerify(pIn2); |
| 71688 | if( pIn1->u.i<pIn2->u.i){ |
| 71689 | pIn1->u.i = pIn2->u.i; |
| 71690 | } |
| 71691 | break; |
| 71692 | } |
| 71693 | #endif /* SQLITE_OMIT_AUTOINCREMENT */ |
| 71694 | |
| @@ -71755,58 +72065,60 @@ | |
| 71755 | ** |
| 71756 | ** The P5 arguments are taken from register P2 and its |
| 71757 | ** successors. |
| 71758 | */ |
| 71759 | case OP_AggStep: { |
| 71760 | int n; |
| 71761 | int i; |
| 71762 | Mem *pMem; |
| 71763 | Mem *pRec; |
| 71764 | sqlite3_context ctx; |
| 71765 | sqlite3_value **apVal; |
| 71766 | |
| 71767 | n = pOp->p5; |
| 71768 | assert( n>=0 ); |
| 71769 | pRec = &aMem[pOp->p2]; |
| 71770 | apVal = p->apArg; |
| 71771 | assert( apVal || n==0 ); |
| 71772 | for(i=0; i<n; i++, pRec++){ |
| 71773 | assert( memIsValid(pRec) ); |
| 71774 | apVal[i] = pRec; |
| 71775 | memAboutToChange(p, pRec); |
| 71776 | sqlite3VdbeMemStoreType(pRec); |
| 71777 | } |
| 71778 | ctx.pFunc = pOp->p4.pFunc; |
| 71779 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 71780 | ctx.pMem = pMem = &aMem[pOp->p3]; |
| 71781 | pMem->n++; |
| 71782 | ctx.s.flags = MEM_Null; |
| 71783 | ctx.s.z = 0; |
| 71784 | ctx.s.zMalloc = 0; |
| 71785 | ctx.s.xDel = 0; |
| 71786 | ctx.s.db = db; |
| 71787 | ctx.isError = 0; |
| 71788 | ctx.pColl = 0; |
| 71789 | ctx.skipFlag = 0; |
| 71790 | if( ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 71791 | assert( pOp>p->aOp ); |
| 71792 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 71793 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 71794 | ctx.pColl = pOp[-1].p4.pColl; |
| 71795 | } |
| 71796 | (ctx.pFunc->xStep)(&ctx, n, apVal); /* IMP: R-24505-23230 */ |
| 71797 | if( ctx.isError ){ |
| 71798 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&ctx.s)); |
| 71799 | rc = ctx.isError; |
| 71800 | } |
| 71801 | if( ctx.skipFlag ){ |
| 71802 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 71803 | i = pOp[-1].p1; |
| 71804 | if( i ) sqlite3VdbeMemSetInt64(&aMem[i], 1); |
| 71805 | } |
| 71806 | |
| 71807 | sqlite3VdbeMemRelease(&ctx.s); |
| 71808 | |
| 71809 | break; |
| 71810 | } |
| 71811 | |
| 71812 | /* Opcode: AggFinal P1 P2 * P4 * |
| @@ -71821,21 +72133,23 @@ | |
| 71821 | ** functions that can take varying numbers of arguments. The |
| 71822 | ** P4 argument is only needed for the degenerate case where |
| 71823 | ** the step function was not previously called. |
| 71824 | */ |
| 71825 | case OP_AggFinal: { |
| 71826 | Mem *pMem; |
| 71827 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 71828 | pMem = &aMem[pOp->p1]; |
| 71829 | assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 71830 | rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc); |
| 71831 | if( rc ){ |
| 71832 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(pMem)); |
| 71833 | } |
| 71834 | sqlite3VdbeChangeEncoding(pMem, encoding); |
| 71835 | UPDATE_MAX_BLOBSIZE(pMem); |
| 71836 | if( sqlite3VdbeMemTooBig(pMem) ){ |
| 71837 | goto too_big; |
| 71838 | } |
| 71839 | break; |
| 71840 | } |
| 71841 | |
| @@ -71850,29 +72164,31 @@ | |
| 71850 | ** in the WAL that have been checkpointed after the checkpoint |
| 71851 | ** completes into mem[P3+2]. However on an error, mem[P3+1] and |
| 71852 | ** mem[P3+2] are initialized to -1. |
| 71853 | */ |
| 71854 | case OP_Checkpoint: { |
| 71855 | int i; /* Loop counter */ |
| 71856 | int aRes[3]; /* Results */ |
| 71857 | Mem *pMem; /* Write results here */ |
| 71858 | |
| 71859 | assert( p->readOnly==0 ); |
| 71860 | aRes[0] = 0; |
| 71861 | aRes[1] = aRes[2] = -1; |
| 71862 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 71863 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 71864 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 71865 | ); |
| 71866 | rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &aRes[1], &aRes[2]); |
| 71867 | if( rc==SQLITE_BUSY ){ |
| 71868 | rc = SQLITE_OK; |
| 71869 | aRes[0] = 1; |
| 71870 | } |
| 71871 | for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){ |
| 71872 | sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]); |
| 71873 | } |
| 71874 | break; |
| 71875 | }; |
| 71876 | #endif |
| 71877 | |
| 71878 | #ifndef SQLITE_OMIT_PRAGMA |
| @@ -71886,96 +72202,98 @@ | |
| 71886 | ** If changing into or out of WAL mode the procedure is more complicated. |
| 71887 | ** |
| 71888 | ** Write a string containing the final journal-mode to register P2. |
| 71889 | */ |
| 71890 | case OP_JournalMode: { /* out2-prerelease */ |
| 71891 | Btree *pBt; /* Btree to change journal mode of */ |
| 71892 | Pager *pPager; /* Pager associated with pBt */ |
| 71893 | int eNew; /* New journal mode */ |
| 71894 | int eOld; /* The old journal mode */ |
| 71895 | #ifndef SQLITE_OMIT_WAL |
| 71896 | const char *zFilename; /* Name of database file for pPager */ |
| 71897 | #endif |
| 71898 | |
| 71899 | eNew = pOp->p3; |
| 71900 | assert( eNew==PAGER_JOURNALMODE_DELETE |
| 71901 | || eNew==PAGER_JOURNALMODE_TRUNCATE |
| 71902 | || eNew==PAGER_JOURNALMODE_PERSIST |
| 71903 | || eNew==PAGER_JOURNALMODE_OFF |
| 71904 | || eNew==PAGER_JOURNALMODE_MEMORY |
| 71905 | || eNew==PAGER_JOURNALMODE_WAL |
| 71906 | || eNew==PAGER_JOURNALMODE_QUERY |
| 71907 | ); |
| 71908 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 71909 | assert( p->readOnly==0 ); |
| 71910 | |
| 71911 | pBt = db->aDb[pOp->p1].pBt; |
| 71912 | pPager = sqlite3BtreePager(pBt); |
| 71913 | eOld = sqlite3PagerGetJournalMode(pPager); |
| 71914 | if( eNew==PAGER_JOURNALMODE_QUERY ) eNew = eOld; |
| 71915 | if( !sqlite3PagerOkToChangeJournalMode(pPager) ) eNew = eOld; |
| 71916 | |
| 71917 | #ifndef SQLITE_OMIT_WAL |
| 71918 | zFilename = sqlite3PagerFilename(pPager, 1); |
| 71919 | |
| 71920 | /* Do not allow a transition to journal_mode=WAL for a database |
| 71921 | ** in temporary storage or if the VFS does not support shared memory |
| 71922 | */ |
| 71923 | if( eNew==PAGER_JOURNALMODE_WAL |
| 71924 | && (sqlite3Strlen30(zFilename)==0 /* Temp file */ |
| 71925 | || !sqlite3PagerWalSupported(pPager)) /* No shared-memory support */ |
| 71926 | ){ |
| 71927 | eNew = eOld; |
| 71928 | } |
| 71929 | |
| 71930 | if( (eNew!=eOld) |
| 71931 | && (eOld==PAGER_JOURNALMODE_WAL || eNew==PAGER_JOURNALMODE_WAL) |
| 71932 | ){ |
| 71933 | if( !db->autoCommit || db->nVdbeRead>1 ){ |
| 71934 | rc = SQLITE_ERROR; |
| 71935 | sqlite3SetString(&p->zErrMsg, db, |
| 71936 | "cannot change %s wal mode from within a transaction", |
| 71937 | (eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") |
| 71938 | ); |
| 71939 | break; |
| 71940 | }else{ |
| 71941 | |
| 71942 | if( eOld==PAGER_JOURNALMODE_WAL ){ |
| 71943 | /* If leaving WAL mode, close the log file. If successful, the call |
| 71944 | ** to PagerCloseWal() checkpoints and deletes the write-ahead-log |
| 71945 | ** file. An EXCLUSIVE lock may still be held on the database file |
| 71946 | ** after a successful return. |
| 71947 | */ |
| 71948 | rc = sqlite3PagerCloseWal(pPager); |
| 71949 | if( rc==SQLITE_OK ){ |
| 71950 | sqlite3PagerSetJournalMode(pPager, eNew); |
| 71951 | } |
| 71952 | }else if( eOld==PAGER_JOURNALMODE_MEMORY ){ |
| 71953 | /* Cannot transition directly from MEMORY to WAL. Use mode OFF |
| 71954 | ** as an intermediate */ |
| 71955 | sqlite3PagerSetJournalMode(pPager, PAGER_JOURNALMODE_OFF); |
| 71956 | } |
| 71957 | |
| 71958 | /* Open a transaction on the database file. Regardless of the journal |
| 71959 | ** mode, this transaction always uses a rollback journal. |
| 71960 | */ |
| 71961 | assert( sqlite3BtreeIsInTrans(pBt)==0 ); |
| 71962 | if( rc==SQLITE_OK ){ |
| 71963 | rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1)); |
| 71964 | } |
| 71965 | } |
| 71966 | } |
| 71967 | #endif /* ifndef SQLITE_OMIT_WAL */ |
| 71968 | |
| 71969 | if( rc ){ |
| 71970 | eNew = eOld; |
| 71971 | } |
| 71972 | eNew = sqlite3PagerSetJournalMode(pPager, eNew); |
| 71973 | |
| 71974 | pOut = &aMem[pOp->p2]; |
| 71975 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 71976 | pOut->z = (char *)sqlite3JournalModename(eNew); |
| 71977 | pOut->n = sqlite3Strlen30(pOut->z); |
| 71978 | pOut->enc = SQLITE_UTF8; |
| 71979 | sqlite3VdbeChangeEncoding(pOut, encoding); |
| 71980 | break; |
| 71981 | }; |
| @@ -72001,17 +72319,19 @@ | |
| 72001 | ** Perform a single step of the incremental vacuum procedure on |
| 72002 | ** the P1 database. If the vacuum has finished, jump to instruction |
| 72003 | ** P2. Otherwise, fall through to the next instruction. |
| 72004 | */ |
| 72005 | case OP_IncrVacuum: { /* jump */ |
| 72006 | Btree *pBt; |
| 72007 | |
| 72008 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 72009 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 72010 | assert( p->readOnly==0 ); |
| 72011 | pBt = db->aDb[pOp->p1].pBt; |
| 72012 | rc = sqlite3BtreeIncrVacuum(pBt); |
| 72013 | if( rc==SQLITE_DONE ){ |
| 72014 | pc = pOp->p2 - 1; |
| 72015 | rc = SQLITE_OK; |
| 72016 | } |
| 72017 | break; |
| @@ -72078,14 +72398,16 @@ | |
| 72078 | ** Also, whether or not P4 is set, check that this is not being called from |
| 72079 | ** within a callback to a virtual table xSync() method. If it is, the error |
| 72080 | ** code will be set to SQLITE_LOCKED. |
| 72081 | */ |
| 72082 | case OP_VBegin: { |
| 72083 | VTable *pVTab; |
| 72084 | pVTab = pOp->p4.pVtab; |
| 72085 | rc = sqlite3VtabBegin(db, pVTab); |
| 72086 | if( pVTab ) sqlite3VtabImportErrmsg(p, pVTab->pVtab); |
| 72087 | break; |
| 72088 | } |
| 72089 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 72090 | |
| 72091 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -72120,34 +72442,36 @@ | |
| 72120 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72121 | ** P1 is a cursor number. This opcode opens a cursor to the virtual |
| 72122 | ** table and stores that cursor in P1. |
| 72123 | */ |
| 72124 | case OP_VOpen: { |
| 72125 | VdbeCursor *pCur; |
| 72126 | sqlite3_vtab_cursor *pVtabCursor; |
| 72127 | sqlite3_vtab *pVtab; |
| 72128 | sqlite3_module *pModule; |
| 72129 | |
| 72130 | assert( p->bIsReader ); |
| 72131 | pCur = 0; |
| 72132 | pVtabCursor = 0; |
| 72133 | pVtab = pOp->p4.pVtab->pVtab; |
| 72134 | pModule = (sqlite3_module *)pVtab->pModule; |
| 72135 | assert(pVtab && pModule); |
| 72136 | rc = pModule->xOpen(pVtab, &pVtabCursor); |
| 72137 | sqlite3VtabImportErrmsg(p, pVtab); |
| 72138 | if( SQLITE_OK==rc ){ |
| 72139 | /* Initialize sqlite3_vtab_cursor base class */ |
| 72140 | pVtabCursor->pVtab = pVtab; |
| 72141 | |
| 72142 | /* Initialize vdbe cursor object */ |
| 72143 | pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 72144 | if( pCur ){ |
| 72145 | pCur->pVtabCursor = pVtabCursor; |
| 72146 | }else{ |
| 72147 | db->mallocFailed = 1; |
| 72148 | pModule->xClose(pVtabCursor); |
| 72149 | } |
| 72150 | } |
| 72151 | break; |
| 72152 | } |
| 72153 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -72171,10 +72495,11 @@ | |
| 72171 | ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter. |
| 72172 | ** |
| 72173 | ** A jump is made to P2 if the result set after filtering would be empty. |
| 72174 | */ |
| 72175 | case OP_VFilter: { /* jump */ |
| 72176 | int nArg; |
| 72177 | int iQuery; |
| 72178 | const sqlite3_module *pModule; |
| 72179 | Mem *pQuery; |
| 72180 | Mem *pArgc; |
| @@ -72182,48 +72507,49 @@ | |
| 72182 | sqlite3_vtab *pVtab; |
| 72183 | VdbeCursor *pCur; |
| 72184 | int res; |
| 72185 | int i; |
| 72186 | Mem **apArg; |
| 72187 | |
| 72188 | pQuery = &aMem[pOp->p3]; |
| 72189 | pArgc = &pQuery[1]; |
| 72190 | pCur = p->apCsr[pOp->p1]; |
| 72191 | assert( memIsValid(pQuery) ); |
| 72192 | REGISTER_TRACE(pOp->p3, pQuery); |
| 72193 | assert( pCur->pVtabCursor ); |
| 72194 | pVtabCursor = pCur->pVtabCursor; |
| 72195 | pVtab = pVtabCursor->pVtab; |
| 72196 | pModule = pVtab->pModule; |
| 72197 | |
| 72198 | /* Grab the index number and argc parameters */ |
| 72199 | assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int ); |
| 72200 | nArg = (int)pArgc->u.i; |
| 72201 | iQuery = (int)pQuery->u.i; |
| 72202 | |
| 72203 | /* Invoke the xFilter method */ |
| 72204 | { |
| 72205 | res = 0; |
| 72206 | apArg = p->apArg; |
| 72207 | for(i = 0; i<nArg; i++){ |
| 72208 | apArg[i] = &pArgc[i+1]; |
| 72209 | sqlite3VdbeMemStoreType(apArg[i]); |
| 72210 | } |
| 72211 | |
| 72212 | p->inVtabMethod = 1; |
| 72213 | rc = pModule->xFilter(pVtabCursor, iQuery, pOp->p4.z, nArg, apArg); |
| 72214 | p->inVtabMethod = 0; |
| 72215 | sqlite3VtabImportErrmsg(p, pVtab); |
| 72216 | if( rc==SQLITE_OK ){ |
| 72217 | res = pModule->xEof(pVtabCursor); |
| 72218 | } |
| 72219 | |
| 72220 | if( res ){ |
| 72221 | pc = pOp->p2 - 1; |
| 72222 | } |
| 72223 | } |
| 72224 | pCur->nullRow = 0; |
| 72225 | |
| 72226 | break; |
| 72227 | } |
| 72228 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 72229 | |
| @@ -72234,53 +72560,55 @@ | |
| 72234 | ** Store the value of the P2-th column of |
| 72235 | ** the row of the virtual-table that the |
| 72236 | ** P1 cursor is pointing to into register P3. |
| 72237 | */ |
| 72238 | case OP_VColumn: { |
| 72239 | sqlite3_vtab *pVtab; |
| 72240 | const sqlite3_module *pModule; |
| 72241 | Mem *pDest; |
| 72242 | sqlite3_context sContext; |
| 72243 | |
| 72244 | VdbeCursor *pCur = p->apCsr[pOp->p1]; |
| 72245 | assert( pCur->pVtabCursor ); |
| 72246 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 72247 | pDest = &aMem[pOp->p3]; |
| 72248 | memAboutToChange(p, pDest); |
| 72249 | if( pCur->nullRow ){ |
| 72250 | sqlite3VdbeMemSetNull(pDest); |
| 72251 | break; |
| 72252 | } |
| 72253 | pVtab = pCur->pVtabCursor->pVtab; |
| 72254 | pModule = pVtab->pModule; |
| 72255 | assert( pModule->xColumn ); |
| 72256 | memset(&sContext, 0, sizeof(sContext)); |
| 72257 | |
| 72258 | /* The output cell may already have a buffer allocated. Move |
| 72259 | ** the current contents to sContext.s so in case the user-function |
| 72260 | ** can use the already allocated buffer instead of allocating a |
| 72261 | ** new one. |
| 72262 | */ |
| 72263 | sqlite3VdbeMemMove(&sContext.s, pDest); |
| 72264 | MemSetTypeFlag(&sContext.s, MEM_Null); |
| 72265 | |
| 72266 | rc = pModule->xColumn(pCur->pVtabCursor, &sContext, pOp->p2); |
| 72267 | sqlite3VtabImportErrmsg(p, pVtab); |
| 72268 | if( sContext.isError ){ |
| 72269 | rc = sContext.isError; |
| 72270 | } |
| 72271 | |
| 72272 | /* Copy the result of the function to the P3 register. We |
| 72273 | ** do this regardless of whether or not an error occurred to ensure any |
| 72274 | ** dynamic allocation in sContext.s (a Mem struct) is released. |
| 72275 | */ |
| 72276 | sqlite3VdbeChangeEncoding(&sContext.s, encoding); |
| 72277 | sqlite3VdbeMemMove(pDest, &sContext.s); |
| 72278 | REGISTER_TRACE(pOp->p3, pDest); |
| 72279 | UPDATE_MAX_BLOBSIZE(pDest); |
| 72280 | |
| 72281 | if( sqlite3VdbeMemTooBig(pDest) ){ |
| 72282 | goto too_big; |
| 72283 | } |
| 72284 | break; |
| 72285 | } |
| 72286 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -72291,40 +72619,42 @@ | |
| 72291 | ** Advance virtual table P1 to the next row in its result set and |
| 72292 | ** jump to instruction P2. Or, if the virtual table has reached |
| 72293 | ** the end of its result set, then fall through to the next instruction. |
| 72294 | */ |
| 72295 | case OP_VNext: { /* jump */ |
| 72296 | sqlite3_vtab *pVtab; |
| 72297 | const sqlite3_module *pModule; |
| 72298 | int res; |
| 72299 | VdbeCursor *pCur; |
| 72300 | |
| 72301 | res = 0; |
| 72302 | pCur = p->apCsr[pOp->p1]; |
| 72303 | assert( pCur->pVtabCursor ); |
| 72304 | if( pCur->nullRow ){ |
| 72305 | break; |
| 72306 | } |
| 72307 | pVtab = pCur->pVtabCursor->pVtab; |
| 72308 | pModule = pVtab->pModule; |
| 72309 | assert( pModule->xNext ); |
| 72310 | |
| 72311 | /* Invoke the xNext() method of the module. There is no way for the |
| 72312 | ** underlying implementation to return an error if one occurs during |
| 72313 | ** xNext(). Instead, if an error occurs, true is returned (indicating that |
| 72314 | ** data is available) and the error code returned when xColumn or |
| 72315 | ** some other method is next invoked on the save virtual table cursor. |
| 72316 | */ |
| 72317 | p->inVtabMethod = 1; |
| 72318 | rc = pModule->xNext(pCur->pVtabCursor); |
| 72319 | p->inVtabMethod = 0; |
| 72320 | sqlite3VtabImportErrmsg(p, pVtab); |
| 72321 | if( rc==SQLITE_OK ){ |
| 72322 | res = pModule->xEof(pCur->pVtabCursor); |
| 72323 | } |
| 72324 | |
| 72325 | if( !res ){ |
| 72326 | /* If there is data, jump to P2 */ |
| 72327 | pc = pOp->p2 - 1; |
| 72328 | } |
| 72329 | goto check_for_interrupt; |
| 72330 | } |
| @@ -72336,27 +72666,29 @@ | |
| 72336 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72337 | ** This opcode invokes the corresponding xRename method. The value |
| 72338 | ** in register P1 is passed as the zName argument to the xRename method. |
| 72339 | */ |
| 72340 | case OP_VRename: { |
| 72341 | sqlite3_vtab *pVtab; |
| 72342 | Mem *pName; |
| 72343 | |
| 72344 | pVtab = pOp->p4.pVtab->pVtab; |
| 72345 | pName = &aMem[pOp->p1]; |
| 72346 | assert( pVtab->pModule->xRename ); |
| 72347 | assert( memIsValid(pName) ); |
| 72348 | assert( p->readOnly==0 ); |
| 72349 | REGISTER_TRACE(pOp->p1, pName); |
| 72350 | assert( pName->flags & MEM_Str ); |
| 72351 | testcase( pName->enc==SQLITE_UTF8 ); |
| 72352 | testcase( pName->enc==SQLITE_UTF16BE ); |
| 72353 | testcase( pName->enc==SQLITE_UTF16LE ); |
| 72354 | rc = sqlite3VdbeChangeEncoding(pName, SQLITE_UTF8); |
| 72355 | if( rc==SQLITE_OK ){ |
| 72356 | rc = pVtab->pModule->xRename(pVtab, pName->z); |
| 72357 | sqlite3VtabImportErrmsg(p, pVtab); |
| 72358 | p->expired = 0; |
| 72359 | } |
| 72360 | break; |
| 72361 | } |
| 72362 | #endif |
| @@ -72385,44 +72717,46 @@ | |
| 72385 | ** P1 is a boolean flag. If it is set to true and the xUpdate call |
| 72386 | ** is successful, then the value returned by sqlite3_last_insert_rowid() |
| 72387 | ** is set to the value of the rowid for the row just inserted. |
| 72388 | */ |
| 72389 | case OP_VUpdate: { |
| 72390 | sqlite3_vtab *pVtab; |
| 72391 | sqlite3_module *pModule; |
| 72392 | int nArg; |
| 72393 | int i; |
| 72394 | sqlite_int64 rowid; |
| 72395 | Mem **apArg; |
| 72396 | Mem *pX; |
| 72397 | |
| 72398 | assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 72399 | || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| 72400 | ); |
| 72401 | assert( p->readOnly==0 ); |
| 72402 | pVtab = pOp->p4.pVtab->pVtab; |
| 72403 | pModule = (sqlite3_module *)pVtab->pModule; |
| 72404 | nArg = pOp->p2; |
| 72405 | assert( pOp->p4type==P4_VTAB ); |
| 72406 | if( ALWAYS(pModule->xUpdate) ){ |
| 72407 | u8 vtabOnConflict = db->vtabOnConflict; |
| 72408 | apArg = p->apArg; |
| 72409 | pX = &aMem[pOp->p3]; |
| 72410 | for(i=0; i<nArg; i++){ |
| 72411 | assert( memIsValid(pX) ); |
| 72412 | memAboutToChange(p, pX); |
| 72413 | sqlite3VdbeMemStoreType(pX); |
| 72414 | apArg[i] = pX; |
| 72415 | pX++; |
| 72416 | } |
| 72417 | db->vtabOnConflict = pOp->p5; |
| 72418 | rc = pModule->xUpdate(pVtab, nArg, apArg, &rowid); |
| 72419 | db->vtabOnConflict = vtabOnConflict; |
| 72420 | sqlite3VtabImportErrmsg(p, pVtab); |
| 72421 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 72422 | assert( nArg>1 && apArg[0] && (apArg[0]->flags&MEM_Null) ); |
| 72423 | db->lastRowid = lastRowid = rowid; |
| 72424 | } |
| 72425 | if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 72426 | if( pOp->p5==OE_Ignore ){ |
| 72427 | rc = SQLITE_OK; |
| 72428 | }else{ |
| @@ -72478,36 +72812,38 @@ | |
| 72478 | ** |
| 72479 | ** If tracing is enabled (by the sqlite3_trace()) interface, then |
| 72480 | ** the UTF-8 string contained in P4 is emitted on the trace callback. |
| 72481 | */ |
| 72482 | case OP_Trace: { |
| 72483 | char *zTrace; |
| 72484 | char *z; |
| 72485 | |
| 72486 | if( db->xTrace |
| 72487 | && !p->doingRerun |
| 72488 | && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72489 | ){ |
| 72490 | z = sqlite3VdbeExpandSql(p, zTrace); |
| 72491 | db->xTrace(db->pTraceArg, z); |
| 72492 | sqlite3DbFree(db, z); |
| 72493 | } |
| 72494 | #ifdef SQLITE_USE_FCNTL_TRACE |
| 72495 | zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); |
| 72496 | if( zTrace ){ |
| 72497 | int i; |
| 72498 | for(i=0; i<db->nDb; i++){ |
| 72499 | if( ((1<<i) & p->btreeMask)==0 ) continue; |
| 72500 | sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, zTrace); |
| 72501 | } |
| 72502 | } |
| 72503 | #endif /* SQLITE_USE_FCNTL_TRACE */ |
| 72504 | #ifdef SQLITE_DEBUG |
| 72505 | if( (db->flags & SQLITE_SqlTrace)!=0 |
| 72506 | && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72507 | ){ |
| 72508 | sqlite3DebugPrintf("SQL-trace: %s\n", zTrace); |
| 72509 | } |
| 72510 | #endif /* SQLITE_DEBUG */ |
| 72511 | break; |
| 72512 | } |
| 72513 | #endif |
| @@ -72632,11 +72968,10 @@ | |
| 72632 | rc = SQLITE_INTERRUPT; |
| 72633 | p->rc = rc; |
| 72634 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc)); |
| 72635 | goto vdbe_error_halt; |
| 72636 | } |
| 72637 | |
| 72638 | |
| 72639 | /************** End of vdbe.c ************************************************/ |
| 72640 | /************** Begin file vdbeblob.c ****************************************/ |
| 72641 | /* |
| 72642 | ** 2007 May 1 |
| @@ -72891,11 +73226,11 @@ | |
| 72891 | sqlite3BtreeLeaveAll(db); |
| 72892 | goto blob_open_out; |
| 72893 | } |
| 72894 | } |
| 72895 | |
| 72896 | pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse); |
| 72897 | assert( pBlob->pStmt || db->mallocFailed ); |
| 72898 | if( pBlob->pStmt ){ |
| 72899 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 72900 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 72901 | |
| @@ -76798,29 +77133,20 @@ | |
| 76798 | } |
| 76799 | return p; |
| 76800 | } |
| 76801 | |
| 76802 | /* |
| 76803 | ** If the expression is always either TRUE or FALSE (respectively), |
| 76804 | ** then return 1. If one cannot determine the truth value of the |
| 76805 | ** expression at compile-time return 0. |
| 76806 | ** |
| 76807 | ** This is an optimization. If is OK to return 0 here even if |
| 76808 | ** the expression really is always false or false (a false negative). |
| 76809 | ** But it is a bug to return 1 if the expression might have different |
| 76810 | ** boolean values in different circumstances (a false positive.) |
| 76811 | ** |
| 76812 | ** Note that if the expression is part of conditional for a |
| 76813 | ** LEFT JOIN, then we cannot determine at compile-time whether or not |
| 76814 | ** is it true or false, so always return 0. |
| 76815 | */ |
| 76816 | static int exprAlwaysTrue(Expr *p){ |
| 76817 | int v = 0; |
| 76818 | if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 76819 | if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 76820 | return v!=0; |
| 76821 | } |
| 76822 | static int exprAlwaysFalse(Expr *p){ |
| 76823 | int v = 0; |
| 76824 | if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 76825 | if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 76826 | return v==0; |
| @@ -78454,15 +78780,10 @@ | |
| 78454 | ** added to the column cache after this call are removed when the |
| 78455 | ** corresponding pop occurs. |
| 78456 | */ |
| 78457 | SQLITE_PRIVATE void sqlite3ExprCachePush(Parse *pParse){ |
| 78458 | pParse->iCacheLevel++; |
| 78459 | #ifdef SQLITE_DEBUG |
| 78460 | if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ |
| 78461 | printf("PUSH to %d\n", pParse->iCacheLevel); |
| 78462 | } |
| 78463 | #endif |
| 78464 | } |
| 78465 | |
| 78466 | /* |
| 78467 | ** Remove from the column cache any entries that were added since the |
| 78468 | ** the previous N Push operations. In other words, restore the cache |
| @@ -78472,15 +78793,10 @@ | |
| 78472 | int i; |
| 78473 | struct yColCache *p; |
| 78474 | assert( N>0 ); |
| 78475 | assert( pParse->iCacheLevel>=N ); |
| 78476 | pParse->iCacheLevel -= N; |
| 78477 | #ifdef SQLITE_DEBUG |
| 78478 | if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ |
| 78479 | printf("POP to %d\n", pParse->iCacheLevel); |
| 78480 | } |
| 78481 | #endif |
| 78482 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 78483 | if( p->iReg && p->iLevel>pParse->iCacheLevel ){ |
| 78484 | cacheEntryClear(pParse, p); |
| 78485 | p->iReg = 0; |
| 78486 | } |
| @@ -78571,15 +78887,10 @@ | |
| 78571 | */ |
| 78572 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){ |
| 78573 | int i; |
| 78574 | struct yColCache *p; |
| 78575 | |
| 78576 | #if SQLITE_DEBUG |
| 78577 | if( pParse->db->flags & SQLITE_VdbeAddopTrace ){ |
| 78578 | printf("CLEAR\n"); |
| 78579 | } |
| 78580 | #endif |
| 78581 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 78582 | if( p->iReg ){ |
| 78583 | cacheEntryClear(pParse, p); |
| 78584 | p->iReg = 0; |
| 78585 | } |
| @@ -79663,11 +79974,11 @@ | |
| 79663 | sqlite3ExplainPush(pOut); |
| 79664 | for(i=0; i<pList->nExpr; i++){ |
| 79665 | sqlite3ExplainPrintf(pOut, "item[%d] = ", i); |
| 79666 | sqlite3ExplainPush(pOut); |
| 79667 | sqlite3ExplainExpr(pOut, pList->a[i].pExpr); |
| 79668 | sqlite3ExplainPop(pOut, 1); |
| 79669 | if( pList->a[i].zName ){ |
| 79670 | sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName); |
| 79671 | } |
| 79672 | if( pList->a[i].bSpanIsTab ){ |
| 79673 | sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan); |
| @@ -79712,21 +80023,11 @@ | |
| 79712 | if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ |
| 79713 | sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0); |
| 79714 | }else{ |
| 79715 | int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 79716 | if( inReg!=target+i ){ |
| 79717 | VdbeOp *pOp; |
| 79718 | Vdbe *v = pParse->pVdbe; |
| 79719 | if( copyOp==OP_Copy |
| 79720 | && (pOp=sqlite3VdbeGetOp(v, -1))->opcode==OP_Copy |
| 79721 | && pOp->p1+pOp->p3+1==inReg |
| 79722 | && pOp->p2+pOp->p3+1==target+i |
| 79723 | ){ |
| 79724 | pOp->p3++; |
| 79725 | }else{ |
| 79726 | sqlite3VdbeAddOp2(v, copyOp, inReg, target+i); |
| 79727 | } |
| 79728 | } |
| 79729 | } |
| 79730 | } |
| 79731 | return n; |
| 79732 | } |
| @@ -79813,23 +80114,21 @@ | |
| 79813 | op = pExpr->op; |
| 79814 | switch( op ){ |
| 79815 | case TK_AND: { |
| 79816 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79817 | testcase( jumpIfNull==0 ); |
| 79818 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL); |
| 79819 | sqlite3ExprCachePush(pParse); |
| 79820 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79821 | sqlite3VdbeResolveLabel(v, d2); |
| 79822 | sqlite3ExprCachePop(pParse, 1); |
| 79823 | break; |
| 79824 | } |
| 79825 | case TK_OR: { |
| 79826 | testcase( jumpIfNull==0 ); |
| 79827 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79828 | sqlite3ExprCachePush(pParse); |
| 79829 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79830 | sqlite3ExprCachePop(pParse, 1); |
| 79831 | break; |
| 79832 | } |
| 79833 | case TK_NOT: { |
| 79834 | testcase( jumpIfNull==0 ); |
| 79835 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| @@ -79900,20 +80199,14 @@ | |
| 79900 | sqlite3VdbeResolveLabel(v, destIfFalse); |
| 79901 | break; |
| 79902 | } |
| 79903 | #endif |
| 79904 | default: { |
| 79905 | if( exprAlwaysTrue(pExpr) ){ |
| 79906 | sqlite3VdbeAddOp2(v, OP_Goto, 0, dest); |
| 79907 | }else if( exprAlwaysFalse(pExpr) ){ |
| 79908 | /* No-op */ |
| 79909 | }else{ |
| 79910 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 79911 | sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); |
| 79912 | testcase( regFree1==0 ); |
| 79913 | testcase( jumpIfNull==0 ); |
| 79914 | } |
| 79915 | break; |
| 79916 | } |
| 79917 | } |
| 79918 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 79919 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -79972,20 +80265,18 @@ | |
| 79972 | |
| 79973 | switch( pExpr->op ){ |
| 79974 | case TK_AND: { |
| 79975 | testcase( jumpIfNull==0 ); |
| 79976 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 79977 | sqlite3ExprCachePush(pParse); |
| 79978 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79979 | sqlite3ExprCachePop(pParse, 1); |
| 79980 | break; |
| 79981 | } |
| 79982 | case TK_OR: { |
| 79983 | int d2 = sqlite3VdbeMakeLabel(v); |
| 79984 | testcase( jumpIfNull==0 ); |
| 79985 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL); |
| 79986 | sqlite3ExprCachePush(pParse); |
| 79987 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 79988 | sqlite3VdbeResolveLabel(v, d2); |
| 79989 | sqlite3ExprCachePop(pParse, 1); |
| 79990 | break; |
| 79991 | } |
| @@ -80053,20 +80344,14 @@ | |
| 80053 | } |
| 80054 | break; |
| 80055 | } |
| 80056 | #endif |
| 80057 | default: { |
| 80058 | if( exprAlwaysFalse(pExpr) ){ |
| 80059 | sqlite3VdbeAddOp2(v, OP_Goto, 0, dest); |
| 80060 | }else if( exprAlwaysTrue(pExpr) ){ |
| 80061 | /* no-op */ |
| 80062 | }else{ |
| 80063 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 80064 | sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); |
| 80065 | testcase( regFree1==0 ); |
| 80066 | testcase( jumpIfNull==0 ); |
| 80067 | } |
| 80068 | break; |
| 80069 | } |
| 80070 | } |
| 80071 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 80072 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -83162,10 +83447,14 @@ | |
| 83162 | { |
| 83163 | int rc = SQLITE_OK; |
| 83164 | if( pExpr ){ |
| 83165 | if( pExpr->op!=TK_ID ){ |
| 83166 | rc = sqlite3ResolveExprNames(pName, pExpr); |
| 83167 | }else{ |
| 83168 | pExpr->op = TK_STRING; |
| 83169 | } |
| 83170 | } |
| 83171 | return rc; |
| @@ -87940,13 +88229,13 @@ | |
| 87940 | sqlite3StrAccumInit(&errMsg, 0, 0, 200); |
| 87941 | errMsg.db = pParse->db; |
| 87942 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 87943 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 87944 | if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); |
| 87945 | sqlite3StrAccumAppendAll(&errMsg, pTab->zName); |
| 87946 | sqlite3StrAccumAppend(&errMsg, ".", 1); |
| 87947 | sqlite3StrAccumAppendAll(&errMsg, zCol); |
| 87948 | } |
| 87949 | zErr = sqlite3StrAccumFinish(&errMsg); |
| 87950 | sqlite3HaltConstraint(pParse, |
| 87951 | (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE, |
| 87952 | onError, zErr, P4_DYNAMIC, P5_ConstraintUnique); |
| @@ -88134,13 +88423,12 @@ | |
| 88134 | } |
| 88135 | if( pKey ){ |
| 88136 | assert( sqlite3KeyInfoIsWriteable(pKey) ); |
| 88137 | for(i=0; i<nCol; i++){ |
| 88138 | char *zColl = pIdx->azColl[i]; |
| 88139 | assert( zColl!=0 ); |
| 88140 | pKey->aColl[i] = strcmp(zColl,"BINARY")==0 ? 0 : |
| 88141 | sqlite3LocateCollSeq(pParse, zColl); |
| 88142 | pKey->aSortOrder[i] = pIdx->aSortOrder[i]; |
| 88143 | } |
| 88144 | if( pParse->nErr ){ |
| 88145 | sqlite3KeyInfoUnref(pKey); |
| 88146 | }else{ |
| @@ -88509,10 +88797,11 @@ | |
| 88509 | int bestScore = 0; /* Score of best match */ |
| 88510 | int h; /* Hash value */ |
| 88511 | |
| 88512 | assert( nArg>=(-2) ); |
| 88513 | assert( nArg>=(-1) || createFlag==0 ); |
| 88514 | h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a); |
| 88515 | |
| 88516 | /* First search for a match amongst the application-defined functions. |
| 88517 | */ |
| 88518 | p = functionSearch(&db->aFunc, h, zName, nName); |
| @@ -89399,10 +89688,11 @@ | |
| 89399 | Vdbe *v = pParse->pVdbe; |
| 89400 | int j; |
| 89401 | Table *pTab = pIdx->pTable; |
| 89402 | int regBase; |
| 89403 | int nCol; |
| 89404 | |
| 89405 | if( piPartIdxLabel ){ |
| 89406 | if( pIdx->pPartIdxWhere ){ |
| 89407 | *piPartIdxLabel = sqlite3VdbeMakeLabel(v); |
| 89408 | pParse->iPartIdxTab = iDataCur; |
| @@ -89412,25 +89702,32 @@ | |
| 89412 | *piPartIdxLabel = 0; |
| 89413 | } |
| 89414 | } |
| 89415 | nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn; |
| 89416 | regBase = sqlite3GetTempRange(pParse, nCol); |
| 89417 | for(j=0; j<nCol; j++){ |
| 89418 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, pIdx->aiColumn[j], |
| 89419 | regBase+j); |
| 89420 | /* If the column affinity is REAL but the number is an integer, then it |
| 89421 | ** might be stored in the table as an integer (using a compact |
| 89422 | ** representation) then converted to REAL by an OP_RealAffinity opcode. |
| 89423 | ** But we are getting ready to store this value back into an index, where |
| 89424 | ** it should be converted by to INTEGER again. So omit the OP_RealAffinity |
| 89425 | ** opcode if it is present */ |
| 89426 | if( sqlite3VdbeGetOp(v, -1)->opcode==OP_RealAffinity ){ |
| 89427 | sqlite3VdbeDeleteLastOpcode(v); |
| 89428 | } |
| 89429 | } |
| 89430 | if( regOut ){ |
| 89431 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 89432 | } |
| 89433 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 89434 | return regBase; |
| 89435 | } |
| 89436 | |
| @@ -89652,36 +89949,10 @@ | |
| 89652 | } |
| 89653 | if( nNeedle>nHaystack ) N = 0; |
| 89654 | sqlite3_result_int(context, N); |
| 89655 | } |
| 89656 | |
| 89657 | /* |
| 89658 | ** Implementation of the printf() function. |
| 89659 | */ |
| 89660 | static void printfFunc( |
| 89661 | sqlite3_context *context, |
| 89662 | int argc, |
| 89663 | sqlite3_value **argv |
| 89664 | ){ |
| 89665 | PrintfArguments x; |
| 89666 | StrAccum str; |
| 89667 | const char *zFormat; |
| 89668 | int n; |
| 89669 | |
| 89670 | if( argc>=1 && (zFormat = (const char*)sqlite3_value_text(argv[0]))!=0 ){ |
| 89671 | x.nArg = argc-1; |
| 89672 | x.nUsed = 0; |
| 89673 | x.apArg = argv+1; |
| 89674 | sqlite3StrAccumInit(&str, 0, 0, SQLITE_MAX_LENGTH); |
| 89675 | str.db = sqlite3_context_db_handle(context); |
| 89676 | sqlite3XPrintf(&str, SQLITE_PRINTF_SQLFUNC, zFormat, &x); |
| 89677 | n = str.nChar; |
| 89678 | sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n, |
| 89679 | SQLITE_DYNAMIC); |
| 89680 | } |
| 89681 | } |
| 89682 | |
| 89683 | /* |
| 89684 | ** Implementation of the substr() function. |
| 89685 | ** |
| 89686 | ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. |
| 89687 | ** p1 is 1-indexed. So substr(x,1,1) returns the first character |
| @@ -90971,15 +91242,15 @@ | |
| 90971 | nSep = sqlite3_value_bytes(argv[1]); |
| 90972 | }else{ |
| 90973 | zSep = ","; |
| 90974 | nSep = 1; |
| 90975 | } |
| 90976 | if( nSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep); |
| 90977 | } |
| 90978 | zVal = (char*)sqlite3_value_text(argv[0]); |
| 90979 | nVal = sqlite3_value_bytes(argv[0]); |
| 90980 | if( nVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal); |
| 90981 | } |
| 90982 | } |
| 90983 | static void groupConcatFinalize(sqlite3_context *context){ |
| 90984 | StrAccum *pAccum; |
| 90985 | pAccum = sqlite3_aggregate_context(context, 0); |
| @@ -91108,11 +91379,10 @@ | |
| 91108 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 91109 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 91110 | FUNCTION(instr, 2, 0, 0, instrFunc ), |
| 91111 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 91112 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| 91113 | FUNCTION(printf, -1, 0, 0, printfFunc ), |
| 91114 | FUNCTION(unicode, 1, 0, 0, unicodeFunc ), |
| 91115 | FUNCTION(char, -1, 0, 0, charFunc ), |
| 91116 | FUNCTION(abs, 1, 0, 0, absFunc ), |
| 91117 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 91118 | FUNCTION(round, 1, 0, 0, roundFunc ), |
| @@ -93779,11 +94049,10 @@ | |
| 93779 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 93780 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 93781 | int ipkTop = 0; /* Top of the rowid change constraint check */ |
| 93782 | int ipkBottom = 0; /* Bottom of the rowid change constraint check */ |
| 93783 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| 93784 | int regRowid = -1; /* Register holding ROWID value */ |
| 93785 | |
| 93786 | isUpdate = regOldData!=0; |
| 93787 | db = pParse->db; |
| 93788 | v = sqlite3GetVdbe(pParse); |
| 93789 | assert( v!=0 ); |
| @@ -94010,13 +94279,11 @@ | |
| 94010 | regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn); |
| 94011 | for(i=0; i<pIdx->nColumn; i++){ |
| 94012 | int iField = pIdx->aiColumn[i]; |
| 94013 | int x; |
| 94014 | if( iField<0 || iField==pTab->iPKey ){ |
| 94015 | if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */ |
| 94016 | x = regNewData; |
| 94017 | regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i; |
| 94018 | }else{ |
| 94019 | x = iField + regNewData + 1; |
| 94020 | } |
| 94021 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 94022 | VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); |
| @@ -94052,53 +94319,51 @@ | |
| 94052 | sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk, |
| 94053 | regIdx, pIdx->nKeyCol); |
| 94054 | |
| 94055 | /* Generate code to handle collisions */ |
| 94056 | regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField); |
| 94057 | if( isUpdate || onError==OE_Replace ){ |
| 94058 | if( HasRowid(pTab) ){ |
| 94059 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR); |
| 94060 | /* Conflict only if the rowid of the existing index entry |
| 94061 | ** is different from old-rowid */ |
| 94062 | if( isUpdate ){ |
| 94063 | sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData); |
| 94064 | } |
| 94065 | }else{ |
| 94066 | int x; |
| 94067 | /* Extract the PRIMARY KEY from the end of the index entry and |
| 94068 | ** store it in registers regR..regR+nPk-1 */ |
| 94069 | if( pIdx!=pPk ){ |
| 94070 | for(i=0; i<pPk->nKeyCol; i++){ |
| 94071 | x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]); |
| 94072 | sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i); |
| 94073 | VdbeComment((v, "%s.%s", pTab->zName, |
| 94074 | pTab->aCol[pPk->aiColumn[i]].zName)); |
| 94075 | } |
| 94076 | } |
| 94077 | if( isUpdate ){ |
| 94078 | /* If currently processing the PRIMARY KEY of a WITHOUT ROWID |
| 94079 | ** table, only conflict if the new PRIMARY KEY values are actually |
| 94080 | ** different from the old. |
| 94081 | ** |
| 94082 | ** For a UNIQUE index, only conflict if the PRIMARY KEY values |
| 94083 | ** of the matched index row are different from the original PRIMARY |
| 94084 | ** KEY values of this row before the update. */ |
| 94085 | int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol; |
| 94086 | int op = OP_Ne; |
| 94087 | int regCmp = (pIdx->autoIndex==2 ? regIdx : regR); |
| 94088 | |
| 94089 | for(i=0; i<pPk->nKeyCol; i++){ |
| 94090 | char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]); |
| 94091 | x = pPk->aiColumn[i]; |
| 94092 | if( i==(pPk->nKeyCol-1) ){ |
| 94093 | addrJump = addrUniqueOk; |
| 94094 | op = OP_Eq; |
| 94095 | } |
| 94096 | sqlite3VdbeAddOp4(v, op, |
| 94097 | regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ |
| 94098 | ); |
| 94099 | } |
| 94100 | } |
| 94101 | } |
| 94102 | } |
| 94103 | |
| 94104 | /* Generate code that executes if the new index entry is not unique */ |
| @@ -98841,15 +99106,11 @@ | |
| 98841 | |
| 98842 | /* |
| 98843 | ** Free all memory allocations in the pParse object |
| 98844 | */ |
| 98845 | SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ |
| 98846 | if( pParse ){ |
| 98847 | sqlite3 *db = pParse->db; |
| 98848 | sqlite3DbFree(db, pParse->aLabel); |
| 98849 | sqlite3ExprListDelete(db, pParse->pConstExpr); |
| 98850 | } |
| 98851 | } |
| 98852 | |
| 98853 | /* |
| 98854 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 98855 | */ |
| @@ -99798,10 +100059,11 @@ | |
| 99798 | } |
| 99799 | }else if( eDest!=SRT_Exists ){ |
| 99800 | /* If the destination is an EXISTS(...) expression, the actual |
| 99801 | ** values returned by the SELECT are not required. |
| 99802 | */ |
| 99803 | sqlite3ExprCodeExprList(pParse, pEList, regResult, |
| 99804 | (eDest==SRT_Output)?SQLITE_ECEL_DUP:0); |
| 99805 | } |
| 99806 | nColumn = nResultCol; |
| 99807 | |
| @@ -100764,11 +101026,11 @@ | |
| 100764 | ** If an error occurs, return NULL and leave a message in pParse. |
| 100765 | */ |
| 100766 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ |
| 100767 | Vdbe *v = pParse->pVdbe; |
| 100768 | if( v==0 ){ |
| 100769 | v = pParse->pVdbe = sqlite3VdbeCreate(pParse); |
| 100770 | #ifndef SQLITE_OMIT_TRACE |
| 100771 | if( v ){ |
| 100772 | sqlite3VdbeAddOp0(v, OP_Trace); |
| 100773 | } |
| 100774 | #endif |
| @@ -103022,27 +103284,18 @@ | |
| 103022 | */ |
| 103023 | static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){ |
| 103024 | Vdbe *v = pParse->pVdbe; |
| 103025 | int i; |
| 103026 | struct AggInfo_func *pFunc; |
| 103027 | int nReg = pAggInfo->nFunc + pAggInfo->nColumn; |
| 103028 | if( nReg==0 ) return; |
| 103029 | #ifdef SQLITE_DEBUG |
| 103030 | /* Verify that all AggInfo registers are within the range specified by |
| 103031 | ** AggInfo.mnReg..AggInfo.mxReg */ |
| 103032 | assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 ); |
| 103033 | for(i=0; i<pAggInfo->nColumn; i++){ |
| 103034 | assert( pAggInfo->aCol[i].iMem>=pAggInfo->mnReg |
| 103035 | && pAggInfo->aCol[i].iMem<=pAggInfo->mxReg ); |
| 103036 | } |
| 103037 | for(i=0; i<pAggInfo->nFunc; i++){ |
| 103038 | assert( pAggInfo->aFunc[i].iMem>=pAggInfo->mnReg |
| 103039 | && pAggInfo->aFunc[i].iMem<=pAggInfo->mxReg ); |
| 103040 | } |
| 103041 | #endif |
| 103042 | sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg); |
| 103043 | for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){ |
| 103044 | if( pFunc->iDistinct>=0 ){ |
| 103045 | Expr *pE = pFunc->pExpr; |
| 103046 | assert( !ExprHasProperty(pE, EP_xIsSelect) ); |
| 103047 | if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){ |
| 103048 | sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one " |
| @@ -103084,10 +103337,11 @@ | |
| 103084 | int addrHitTest = 0; |
| 103085 | struct AggInfo_func *pF; |
| 103086 | struct AggInfo_col *pC; |
| 103087 | |
| 103088 | pAggInfo->directMode = 1; |
| 103089 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 103090 | int nArg; |
| 103091 | int addrNext = 0; |
| 103092 | int regAgg; |
| 103093 | ExprList *pList = pF->pExpr->x.pList; |
| @@ -103616,11 +103870,10 @@ | |
| 103616 | */ |
| 103617 | memset(&sNC, 0, sizeof(sNC)); |
| 103618 | sNC.pParse = pParse; |
| 103619 | sNC.pSrcList = pTabList; |
| 103620 | sNC.pAggInfo = &sAggInfo; |
| 103621 | sAggInfo.mnReg = pParse->nMem+1; |
| 103622 | sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0; |
| 103623 | sAggInfo.pGroupBy = pGroupBy; |
| 103624 | sqlite3ExprAnalyzeAggList(&sNC, pEList); |
| 103625 | sqlite3ExprAnalyzeAggList(&sNC, pOrderBy); |
| 103626 | if( pHaving ){ |
| @@ -103631,11 +103884,10 @@ | |
| 103631 | assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) ); |
| 103632 | sNC.ncFlags |= NC_InAggFunc; |
| 103633 | sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList); |
| 103634 | sNC.ncFlags &= ~NC_InAggFunc; |
| 103635 | } |
| 103636 | sAggInfo.mxReg = pParse->nMem; |
| 103637 | if( db->mallocFailed ) goto select_end; |
| 103638 | |
| 103639 | /* Processing for aggregates with GROUP BY is very different and |
| 103640 | ** much more complex than aggregates without a GROUP BY. |
| 103641 | */ |
| @@ -105536,11 +105788,11 @@ | |
| 105536 | pCol->affinity, &pValue); |
| 105537 | if( pValue ){ |
| 105538 | sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM); |
| 105539 | } |
| 105540 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 105541 | if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 105542 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 105543 | } |
| 105544 | #endif |
| 105545 | } |
| 105546 | } |
| @@ -105960,14 +106212,14 @@ | |
| 105960 | ** be used eliminates some redundant opcodes. |
| 105961 | */ |
| 105962 | newmask = sqlite3TriggerColmask( |
| 105963 | pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError |
| 105964 | ); |
| 105965 | /*sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1);*/ |
| 105966 | for(i=0; i<pTab->nCol; i++){ |
| 105967 | if( i==pTab->iPKey ){ |
| 105968 | sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i); |
| 105969 | }else{ |
| 105970 | j = aXRef[i]; |
| 105971 | if( j>=0 ){ |
| 105972 | sqlite3ExprCode(pParse, pChanges->a[j].pExpr, regNew+i); |
| 105973 | }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask&(1<<i)) ){ |
| @@ -105977,12 +106229,10 @@ | |
| 105977 | ** a new.* reference in a trigger program. |
| 105978 | */ |
| 105979 | testcase( i==31 ); |
| 105980 | testcase( i==32 ); |
| 105981 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i); |
| 105982 | }else{ |
| 105983 | sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i); |
| 105984 | } |
| 105985 | } |
| 105986 | } |
| 105987 | |
| 105988 | /* Fire any BEFORE UPDATE triggers. This happens before constraints are |
| @@ -110731,11 +110981,11 @@ | |
| 110731 | int iTerm, /* Index of this term. First is zero */ |
| 110732 | const char *zColumn, /* Name of the column */ |
| 110733 | const char *zOp /* Name of the operator */ |
| 110734 | ){ |
| 110735 | if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5); |
| 110736 | sqlite3StrAccumAppendAll(pStr, zColumn); |
| 110737 | sqlite3StrAccumAppend(pStr, zOp, 1); |
| 110738 | sqlite3StrAccumAppend(pStr, "?", 1); |
| 110739 | } |
| 110740 | |
| 110741 | /* |
| @@ -110777,11 +111027,11 @@ | |
| 110777 | if( i>=nSkip ){ |
| 110778 | explainAppendTerm(&txt, i, z, "="); |
| 110779 | }else{ |
| 110780 | if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5); |
| 110781 | sqlite3StrAccumAppend(&txt, "ANY(", 4); |
| 110782 | sqlite3StrAccumAppendAll(&txt, z); |
| 110783 | sqlite3StrAccumAppend(&txt, ")", 1); |
| 110784 | } |
| 110785 | } |
| 110786 | |
| 110787 | j = i; |
| @@ -113593,16 +113843,13 @@ | |
| 113593 | sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 113594 | |
| 113595 | /* Special case: a WHERE clause that is constant. Evaluate the |
| 113596 | ** expression and either jump over all of the code or fall thru. |
| 113597 | */ |
| 113598 | for(ii=0; ii<sWLB.pWC->nTerm; ii++){ |
| 113599 | if( nTabList==0 || sqlite3ExprIsConstantNotJoin(sWLB.pWC->a[ii].pExpr) ){ |
| 113600 | sqlite3ExprIfFalse(pParse, sWLB.pWC->a[ii].pExpr, pWInfo->iBreak, |
| 113601 | SQLITE_JUMPIFNULL); |
| 113602 | sWLB.pWC->a[ii].wtFlags |= TERM_CODED; |
| 113603 | } |
| 113604 | } |
| 113605 | |
| 113606 | /* Special case: No FROM clause |
| 113607 | */ |
| 113608 | if( nTabList==0 ){ |
| @@ -119339,12 +119586,11 @@ | |
| 119339 | } |
| 119340 | db->lookaside.pEnd = p; |
| 119341 | db->lookaside.bEnabled = 1; |
| 119342 | db->lookaside.bMalloced = pBuf==0 ?1:0; |
| 119343 | }else{ |
| 119344 | db->lookaside.pStart = db; |
| 119345 | db->lookaside.pEnd = db; |
| 119346 | db->lookaside.bEnabled = 0; |
| 119347 | db->lookaside.bMalloced = 0; |
| 119348 | } |
| 119349 | return SQLITE_OK; |
| 119350 | } |
| @@ -119738,11 +119984,13 @@ | |
| 119738 | } |
| 119739 | sqlite3HashClear(&db->aModule); |
| 119740 | #endif |
| 119741 | |
| 119742 | sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */ |
| 119743 | sqlite3ValueFree(db->pErr); |
| 119744 | sqlite3CloseExtensions(db); |
| 119745 | |
| 119746 | db->magic = SQLITE_MAGIC_ERROR; |
| 119747 | |
| 119748 | /* The temp-database schema is allocated differently from the other schema |
| @@ -119813,11 +120061,12 @@ | |
| 119813 | |
| 119814 | /* |
| 119815 | ** Return a static string containing the name corresponding to the error code |
| 119816 | ** specified in the argument. |
| 119817 | */ |
| 119818 | #if defined(SQLITE_TEST) |
| 119819 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 119820 | const char *zName = 0; |
| 119821 | int i, origRc = rc; |
| 119822 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 119823 | switch( rc ){ |
| @@ -119835,11 +120084,10 @@ | |
| 119835 | case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; |
| 119836 | case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; |
| 119837 | case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break; |
| 119838 | case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break; |
| 119839 | case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break; |
| 119840 | case SQLITE_READONLY_DBMOVED: zName = "SQLITE_READONLY_DBMOVED"; break; |
| 119841 | case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; |
| 119842 | case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; |
| 119843 | case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break; |
| 119844 | case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break; |
| 119845 | case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break; |
| @@ -120120,11 +120368,10 @@ | |
| 120120 | void (*xFinal)(sqlite3_context*), |
| 120121 | FuncDestructor *pDestructor |
| 120122 | ){ |
| 120123 | FuncDef *p; |
| 120124 | int nName; |
| 120125 | int extraFlags; |
| 120126 | |
| 120127 | assert( sqlite3_mutex_held(db->mutex) ); |
| 120128 | if( zFunctionName==0 || |
| 120129 | (xFunc && (xFinal || xStep)) || |
| 120130 | (!xFunc && (xFinal && !xStep)) || |
| @@ -120131,14 +120378,10 @@ | |
| 120131 | (!xFunc && (!xFinal && xStep)) || |
| 120132 | (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
| 120133 | (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
| 120134 | return SQLITE_MISUSE_BKPT; |
| 120135 | } |
| 120136 | |
| 120137 | assert( SQLITE_FUNC_CONSTANT==SQLITE_DETERMINISTIC ); |
| 120138 | extraFlags = enc & SQLITE_DETERMINISTIC; |
| 120139 | enc &= (SQLITE_FUNC_ENCMASK|SQLITE_ANY); |
| 120140 | |
| 120141 | #ifndef SQLITE_OMIT_UTF16 |
| 120142 | /* If SQLITE_UTF16 is specified as the encoding type, transform this |
| 120143 | ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
| 120144 | ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
| @@ -120148,14 +120391,14 @@ | |
| 120148 | */ |
| 120149 | if( enc==SQLITE_UTF16 ){ |
| 120150 | enc = SQLITE_UTF16NATIVE; |
| 120151 | }else if( enc==SQLITE_ANY ){ |
| 120152 | int rc; |
| 120153 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8|extraFlags, |
| 120154 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 120155 | if( rc==SQLITE_OK ){ |
| 120156 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE|extraFlags, |
| 120157 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 120158 | } |
| 120159 | if( rc!=SQLITE_OK ){ |
| 120160 | return rc; |
| 120161 | } |
| @@ -120194,12 +120437,11 @@ | |
| 120194 | |
| 120195 | if( pDestructor ){ |
| 120196 | pDestructor->nRef++; |
| 120197 | } |
| 120198 | p->pDestructor = pDestructor; |
| 120199 | p->funcFlags = (p->funcFlags & SQLITE_FUNC_ENCMASK) | extraFlags; |
| 120200 | testcase( p->funcFlags & SQLITE_DETERMINISTIC ); |
| 120201 | p->xFunc = xFunc; |
| 120202 | p->xStep = xStep; |
| 120203 | p->xFinalize = xFinal; |
| 120204 | p->pUserData = pUserData; |
| 120205 | p->nArg = (u16)nArg; |
| @@ -120625,11 +120867,10 @@ | |
| 120625 | } |
| 120626 | sqlite3_mutex_enter(db->mutex); |
| 120627 | if( db->mallocFailed ){ |
| 120628 | z = sqlite3ErrStr(SQLITE_NOMEM); |
| 120629 | }else{ |
| 120630 | testcase( db->pErr==0 ); |
| 120631 | z = (char*)sqlite3_value_text(db->pErr); |
| 120632 | assert( !db->mallocFailed ); |
| 120633 | if( z==0 ){ |
| 120634 | z = sqlite3ErrStr(db->errCode); |
| 120635 | } |
| @@ -120667,11 +120908,12 @@ | |
| 120667 | if( db->mallocFailed ){ |
| 120668 | z = (void *)outOfMem; |
| 120669 | }else{ |
| 120670 | z = sqlite3_value_text16(db->pErr); |
| 120671 | if( z==0 ){ |
| 120672 | sqlite3Error(db, db->errCode, sqlite3ErrStr(db->errCode)); |
| 120673 | z = sqlite3_value_text16(db->pErr); |
| 120674 | } |
| 120675 | /* A malloc() may have failed within the call to sqlite3_value_text16() |
| 120676 | ** above. If this is the case, then the db->mallocFailed flag needs to |
| 120677 | ** be cleared before returning. Do this directly, instead of via |
| @@ -121380,10 +121622,12 @@ | |
| 121380 | #ifdef SQLITE_ENABLE_RTREE |
| 121381 | if( !db->mallocFailed && rc==SQLITE_OK){ |
| 121382 | rc = sqlite3RtreeInit(db); |
| 121383 | } |
| 121384 | #endif |
| 121385 | |
| 121386 | /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking |
| 121387 | ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking |
| 121388 | ** mode. Doing nothing at all also makes NORMAL the default. |
| 121389 | */ |
| @@ -121391,12 +121635,10 @@ | |
| 121391 | db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE; |
| 121392 | sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt), |
| 121393 | SQLITE_DEFAULT_LOCKING_MODE); |
| 121394 | #endif |
| 121395 | |
| 121396 | if( rc ) sqlite3Error(db, rc, 0); |
| 121397 | |
| 121398 | /* Enable the lookaside-malloc subsystem */ |
| 121399 | setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, |
| 121400 | sqlite3GlobalConfig.nLookaside); |
| 121401 | |
| 121402 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| @@ -121852,11 +122094,11 @@ | |
| 121852 | ** Reset the PRNG back to its uninitialized state. The next call |
| 121853 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 121854 | ** to the xRandomness method of the default VFS. |
| 121855 | */ |
| 121856 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 121857 | sqlite3_randomness(0,0); |
| 121858 | break; |
| 121859 | } |
| 121860 | |
| 121861 | /* |
| 121862 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| @@ -124836,23 +125078,10 @@ | |
| 124836 | char **pzErr /* OUT: sqlite3_malloc'd error message */ |
| 124837 | ){ |
| 124838 | return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr); |
| 124839 | } |
| 124840 | |
| 124841 | /* |
| 124842 | ** Set the pIdxInfo->estimatedRows variable to nRow. Unless this |
| 124843 | ** extension is currently being used by a version of SQLite too old to |
| 124844 | ** support estimatedRows. In that case this function is a no-op. |
| 124845 | */ |
| 124846 | static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){ |
| 124847 | #if SQLITE_VERSION_NUMBER>=3008002 |
| 124848 | if( sqlite3_libversion_number()>=3008002 ){ |
| 124849 | pIdxInfo->estimatedRows = nRow; |
| 124850 | } |
| 124851 | #endif |
| 124852 | } |
| 124853 | |
| 124854 | /* |
| 124855 | ** Implementation of the xBestIndex method for FTS3 tables. There |
| 124856 | ** are three possible strategies, in order of preference: |
| 124857 | ** |
| 124858 | ** 1. Direct lookup by rowid or docid. |
| @@ -124876,24 +125105,11 @@ | |
| 124876 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 124877 | pInfo->estimatedCost = 5000000; |
| 124878 | for(i=0; i<pInfo->nConstraint; i++){ |
| 124879 | int bDocid; /* True if this constraint is on docid */ |
| 124880 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 124881 | if( pCons->usable==0 ){ |
| 124882 | if( pCons->op==SQLITE_INDEX_CONSTRAINT_MATCH ){ |
| 124883 | /* There exists an unusable MATCH constraint. This means that if |
| 124884 | ** the planner does elect to use the results of this call as part |
| 124885 | ** of the overall query plan the user will see an "unable to use |
| 124886 | ** function MATCH in the requested context" error. To discourage |
| 124887 | ** this, return a very high cost here. */ |
| 124888 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 124889 | pInfo->estimatedCost = 1e50; |
| 124890 | setEstimatedRows(pInfo, ((sqlite3_int64)1) << 50); |
| 124891 | return SQLITE_OK; |
| 124892 | } |
| 124893 | continue; |
| 124894 | } |
| 124895 | |
| 124896 | bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1); |
| 124897 | |
| 124898 | /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */ |
| 124899 | if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){ |
| @@ -131750,74 +131966,61 @@ | |
| 131750 | } |
| 131751 | |
| 131752 | /* Step 2 */ |
| 131753 | switch( z[1] ){ |
| 131754 | case 'a': |
| 131755 | if( !stem(&z, "lanoita", "ate", m_gt_0) ){ |
| 131756 | stem(&z, "lanoit", "tion", m_gt_0); |
| 131757 | } |
| 131758 | break; |
| 131759 | case 'c': |
| 131760 | if( !stem(&z, "icne", "ence", m_gt_0) ){ |
| 131761 | stem(&z, "icna", "ance", m_gt_0); |
| 131762 | } |
| 131763 | break; |
| 131764 | case 'e': |
| 131765 | stem(&z, "rezi", "ize", m_gt_0); |
| 131766 | break; |
| 131767 | case 'g': |
| 131768 | stem(&z, "igol", "log", m_gt_0); |
| 131769 | break; |
| 131770 | case 'l': |
| 131771 | if( !stem(&z, "ilb", "ble", m_gt_0) |
| 131772 | && !stem(&z, "illa", "al", m_gt_0) |
| 131773 | && !stem(&z, "iltne", "ent", m_gt_0) |
| 131774 | && !stem(&z, "ile", "e", m_gt_0) |
| 131775 | ){ |
| 131776 | stem(&z, "ilsuo", "ous", m_gt_0); |
| 131777 | } |
| 131778 | break; |
| 131779 | case 'o': |
| 131780 | if( !stem(&z, "noitazi", "ize", m_gt_0) |
| 131781 | && !stem(&z, "noita", "ate", m_gt_0) |
| 131782 | ){ |
| 131783 | stem(&z, "rota", "ate", m_gt_0); |
| 131784 | } |
| 131785 | break; |
| 131786 | case 's': |
| 131787 | if( !stem(&z, "msila", "al", m_gt_0) |
| 131788 | && !stem(&z, "ssenevi", "ive", m_gt_0) |
| 131789 | && !stem(&z, "ssenluf", "ful", m_gt_0) |
| 131790 | ){ |
| 131791 | stem(&z, "ssensuo", "ous", m_gt_0); |
| 131792 | } |
| 131793 | break; |
| 131794 | case 't': |
| 131795 | if( !stem(&z, "itila", "al", m_gt_0) |
| 131796 | && !stem(&z, "itivi", "ive", m_gt_0) |
| 131797 | ){ |
| 131798 | stem(&z, "itilib", "ble", m_gt_0); |
| 131799 | } |
| 131800 | break; |
| 131801 | } |
| 131802 | |
| 131803 | /* Step 3 */ |
| 131804 | switch( z[0] ){ |
| 131805 | case 'e': |
| 131806 | if( !stem(&z, "etaci", "ic", m_gt_0) |
| 131807 | && !stem(&z, "evita", "", m_gt_0) |
| 131808 | ){ |
| 131809 | stem(&z, "ezila", "al", m_gt_0); |
| 131810 | } |
| 131811 | break; |
| 131812 | case 'i': |
| 131813 | stem(&z, "itici", "ic", m_gt_0); |
| 131814 | break; |
| 131815 | case 'l': |
| 131816 | if( !stem(&z, "laci", "ic", m_gt_0) ){ |
| 131817 | stem(&z, "luf", "", m_gt_0); |
| 131818 | } |
| 131819 | break; |
| 131820 | case 's': |
| 131821 | stem(&z, "ssen", "", m_gt_0); |
| 131822 | break; |
| 131823 | } |
| @@ -131854,15 +132057,13 @@ | |
| 131854 | if( z[2]=='a' ){ |
| 131855 | if( m_gt_1(z+3) ){ |
| 131856 | z += 3; |
| 131857 | } |
| 131858 | }else if( z[2]=='e' ){ |
| 131859 | if( !stem(&z, "tneme", "", m_gt_1) |
| 131860 | && !stem(&z, "tnem", "", m_gt_1) |
| 131861 | ){ |
| 131862 | stem(&z, "tne", "", m_gt_1); |
| 131863 | } |
| 131864 | } |
| 131865 | } |
| 131866 | break; |
| 131867 | case 'o': |
| 131868 | if( z[0]=='u' ){ |
| @@ -131877,13 +132078,12 @@ | |
| 131877 | if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){ |
| 131878 | z += 3; |
| 131879 | } |
| 131880 | break; |
| 131881 | case 't': |
| 131882 | if( !stem(&z, "eta", "", m_gt_1) ){ |
| 131883 | stem(&z, "iti", "", m_gt_1); |
| 131884 | } |
| 131885 | break; |
| 131886 | case 'u': |
| 131887 | if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){ |
| 131888 | z += 3; |
| 131889 | } |
| 131890 |
| --- src/sqlite3.c | |
| +++ src/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.8.2. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -133,13 +133,13 @@ | |
| 133 | ** |
| 134 | ** See also: [sqlite3_libversion()], |
| 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | */ |
| 138 | #define SQLITE_VERSION "3.8.2" |
| 139 | #define SQLITE_VERSION_NUMBER 3008002 |
| 140 | #define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d" |
| 141 | |
| 142 | /* |
| 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | ** |
| @@ -517,11 +517,10 @@ | |
| 517 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 518 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 519 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 520 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 521 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 522 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 523 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 524 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 525 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 526 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -585,12 +584,11 @@ | |
| 584 | ** information is written to disk in the same order as calls |
| 585 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 586 | ** after reboot following a crash or power loss, the only bytes in a |
| 587 | ** file that were written at the application level might have changed |
| 588 | ** and that adjacent bytes, even bytes within the same sector are |
| 589 | ** guaranteed to be unchanged. |
| 590 | */ |
| 591 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 592 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 593 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 594 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| @@ -817,33 +815,19 @@ | |
| 815 | ** to the [sqlite3_file] object associated with a particular database |
| 816 | ** connection. See the [sqlite3_file_control()] documentation for |
| 817 | ** additional information. |
| 818 | ** |
| 819 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 820 | ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by |
| 821 | ** SQLite and sent to all VFSes in place of a call to the xSync method |
| 822 | ** when the database connection has [PRAGMA synchronous] set to OFF.)^ |
| 823 | ** Some specialized VFSes need this signal in order to operate correctly |
| 824 | ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most |
| 825 | ** VFSes do not need this signal and should silently ignore this opcode. |
| 826 | ** Applications should not call [sqlite3_file_control()] with this |
| 827 | ** opcode as doing so may disrupt the operation of the specialized VFSes |
| 828 | ** that do require it. |
| 829 | ** |
| 830 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 831 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 832 | ** retry counts and intervals for certain disk I/O operations for the |
| 833 | ** windows [VFS] in order to provide robustness in the presence of |
| @@ -963,16 +947,10 @@ | |
| 947 | ** This file control is used by some VFS activity tracing [shims]. |
| 948 | ** The argument is a zero-terminated string. Higher layers in the |
| 949 | ** SQLite stack may generate instances of this file control if |
| 950 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
| 951 | ** |
| 952 | ** </ul> |
| 953 | */ |
| 954 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 955 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 956 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| @@ -989,13 +967,10 @@ | |
| 967 | #define SQLITE_FCNTL_PRAGMA 14 |
| 968 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 969 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 970 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 971 | #define SQLITE_FCNTL_TRACE 19 |
| 972 | |
| 973 | /* |
| 974 | ** CAPI3REF: Mutex Handle |
| 975 | ** |
| 976 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2426,17 +2401,15 @@ | |
| 2401 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2402 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2403 | ** applications to access the same PRNG for other purposes. |
| 2404 | ** |
| 2405 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2406 | ** |
| 2407 | ** ^The first time this routine is invoked (either internally or by |
| 2408 | ** the application) the PRNG is seeded using randomness obtained |
| 2409 | ** from the xRandomness method of the default [sqlite3_vfs] object. |
| 2410 | ** ^On all subsequent invocations, the pseudo-randomness is generated |
| 2411 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2412 | ** method. |
| 2413 | */ |
| 2414 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2415 | |
| @@ -4010,28 +3983,19 @@ | |
| 3983 | ** parameter is less than -1 or greater than 127 then the behavior is |
| 3984 | ** undefined. |
| 3985 | ** |
| 3986 | ** ^The fourth parameter, eTextRep, specifies what |
| 3987 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
| 3988 | ** its parameters. Every SQL function implementation must be able to work |
| 3989 | ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be |
| 3990 | ** more efficient with one encoding than another. ^An application may |
| 3991 | ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple |
| 3992 | ** times with the same function but with different values of eTextRep. |
| 3993 | ** ^When multiple implementations of the same function are available, SQLite |
| 3994 | ** will pick the one that involves the least amount of data conversion. |
| 3995 | ** If there is only a single implementation which does not care what text |
| 3996 | ** encoding is used, then the fourth argument should be [SQLITE_ANY]. |
| 3997 | ** |
| 3998 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 3999 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 4000 | ** |
| 4001 | ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are |
| @@ -4113,23 +4077,13 @@ | |
| 4077 | */ |
| 4078 | #define SQLITE_UTF8 1 |
| 4079 | #define SQLITE_UTF16LE 2 |
| 4080 | #define SQLITE_UTF16BE 3 |
| 4081 | #define SQLITE_UTF16 4 /* Use native byte order */ |
| 4082 | #define SQLITE_ANY 5 /* sqlite3_create_function only */ |
| 4083 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
| 4084 | |
| 4085 | /* |
| 4086 | ** CAPI3REF: Deprecated Functions |
| 4087 | ** DEPRECATED |
| 4088 | ** |
| 4089 | ** These functions are [deprecated]. In order to maintain |
| @@ -8627,11 +8581,10 @@ | |
| 8581 | typedef struct Lookaside Lookaside; |
| 8582 | typedef struct LookasideSlot LookasideSlot; |
| 8583 | typedef struct Module Module; |
| 8584 | typedef struct NameContext NameContext; |
| 8585 | typedef struct Parse Parse; |
| 8586 | typedef struct RowSet RowSet; |
| 8587 | typedef struct Savepoint Savepoint; |
| 8588 | typedef struct Select Select; |
| 8589 | typedef struct SelectDest SelectDest; |
| 8590 | typedef struct SrcList SrcList; |
| @@ -9100,11 +9053,11 @@ | |
| 9053 | #define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */ |
| 9054 | #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */ |
| 9055 | #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */ |
| 9056 | #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 9057 | #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9058 | #define OP_Copy 30 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9059 | #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */ |
| 9060 | #define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */ |
| 9061 | #define OP_CollSeq 33 |
| 9062 | #define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */ |
| 9063 | #define OP_MustBeInt 35 |
| @@ -9265,11 +9218,11 @@ | |
| 9218 | |
| 9219 | /* |
| 9220 | ** Prototypes for the VDBE interface. See comments on the implementation |
| 9221 | ** for a description of what each of these routines does. |
| 9222 | */ |
| 9223 | SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3*); |
| 9224 | SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe*,int); |
| 9225 | SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int); |
| 9226 | SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int); |
| 9227 | SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int); |
| 9228 | SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int); |
| @@ -9280,11 +9233,10 @@ | |
| 9233 | SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2); |
| 9234 | SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3); |
| 9235 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 9236 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 9237 | SQLITE_PRIVATE void sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 9238 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 9239 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 9240 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 9241 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| 9242 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*); |
| @@ -9487,11 +9439,10 @@ | |
| 9439 | SQLITE_PRIVATE int sqlite3PagerAcquire(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag); |
| 9440 | #define sqlite3PagerGet(A,B,C) sqlite3PagerAcquire(A,B,C,0) |
| 9441 | SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno); |
| 9442 | SQLITE_PRIVATE void sqlite3PagerRef(DbPage*); |
| 9443 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*); |
| 9444 | |
| 9445 | /* Operations on page references. */ |
| 9446 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*); |
| 9447 | SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*); |
| 9448 | SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int); |
| @@ -9502,11 +9453,11 @@ | |
| 9453 | /* Functions used to manage pager transactions and savepoints. */ |
| 9454 | SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*); |
| 9455 | SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int); |
| 9456 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int); |
| 9457 | SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*); |
| 9458 | SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager); |
| 9459 | SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*); |
| 9460 | SQLITE_PRIVATE int sqlite3PagerRollback(Pager*); |
| 9461 | SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n); |
| 9462 | SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint); |
| 9463 | SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager); |
| @@ -10374,11 +10325,11 @@ | |
| 10325 | */ |
| 10326 | #define SQLITE_QueryFlattener 0x0001 /* Query flattening */ |
| 10327 | #define SQLITE_ColumnCache 0x0002 /* Column cache */ |
| 10328 | #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ |
| 10329 | #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ |
| 10330 | #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */ |
| 10331 | #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ |
| 10332 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10333 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10334 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10335 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| @@ -11006,11 +10957,10 @@ | |
| 10957 | u8 useSortingIdx; /* In direct mode, reference the sorting index rather |
| 10958 | ** than the source table */ |
| 10959 | int sortingIdx; /* Cursor number of the sorting index */ |
| 10960 | int sortingIdxPTab; /* Cursor number of pseudo-table */ |
| 10961 | int nSortingColumn; /* Number of columns in the sorting index */ |
| 10962 | ExprList *pGroupBy; /* The group by clause */ |
| 10963 | struct AggInfo_col { /* For each column used in source tables */ |
| 10964 | Table *pTab; /* Source table */ |
| 10965 | int iTable; /* Cursor number of the source table */ |
| 10966 | int iColumn; /* Column number within the source table */ |
| @@ -11608,13 +11558,10 @@ | |
| 11558 | int nErr; /* Number of errors seen */ |
| 11559 | int nTab; /* Number of previously allocated VDBE cursors */ |
| 11560 | int nMem; /* Number of memory cells used so far */ |
| 11561 | int nSet; /* Number of sets used so far */ |
| 11562 | int nOnce; /* Number of OP_Once instructions so far */ |
| 11563 | int ckBase; /* Base register of data during check constraints */ |
| 11564 | int iPartIdxTab; /* Table corresponding to a partial index */ |
| 11565 | int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */ |
| 11566 | int iCacheCnt; /* Counter used to generate aColCache[].lru values */ |
| 11567 | struct yColCache { |
| @@ -12087,24 +12034,14 @@ | |
| 12034 | SQLITE_PRIVATE int sqlite3IsNaN(double); |
| 12035 | #else |
| 12036 | # define sqlite3IsNaN(X) 0 |
| 12037 | #endif |
| 12038 | |
| 12039 | SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, int, const char*, va_list); |
| 12040 | #ifndef SQLITE_OMIT_TRACE |
| 12041 | SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...); |
| 12042 | #endif |
| 12043 | SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...); |
| 12044 | SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list); |
| 12045 | SQLITE_PRIVATE char *sqlite3MAppendf(sqlite3*,char*,const char*,...); |
| 12046 | #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG) |
| 12047 | SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...); |
| @@ -12290,10 +12227,11 @@ | |
| 12227 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 12228 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 12229 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 12230 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 12231 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 12232 | SQLITE_PRIVATE void sqlite3PrngResetState(void); |
| 12233 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 12234 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| 12235 | SQLITE_PRIVATE void sqlite3CodeVerifyNamedSchema(Parse*, const char *zDb); |
| 12236 | SQLITE_PRIVATE void sqlite3BeginTransaction(Parse*, int); |
| 12237 | SQLITE_PRIVATE void sqlite3CommitTransaction(Parse*); |
| @@ -12458,11 +12396,12 @@ | |
| 12396 | SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...); |
| 12397 | SQLITE_PRIVATE void *sqlite3HexToBlob(sqlite3*, const char *z, int n); |
| 12398 | SQLITE_PRIVATE u8 sqlite3HexToInt(int h); |
| 12399 | SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **); |
| 12400 | |
| 12401 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \ |
| 12402 | defined(SQLITE_DEBUG_OS_TRACE) |
| 12403 | SQLITE_PRIVATE const char *sqlite3ErrName(int); |
| 12404 | #endif |
| 12405 | |
| 12406 | SQLITE_PRIVATE const char *sqlite3ErrStr(int); |
| 12407 | SQLITE_PRIVATE int sqlite3ReadSchema(Parse *pParse); |
| @@ -12488,11 +12427,10 @@ | |
| 12427 | |
| 12428 | SQLITE_PRIVATE const void *sqlite3ValueText(sqlite3_value*, u8); |
| 12429 | SQLITE_PRIVATE int sqlite3ValueBytes(sqlite3_value*, u8); |
| 12430 | SQLITE_PRIVATE void sqlite3ValueSetStr(sqlite3_value*, int, const void *,u8, |
| 12431 | void(*)(void*)); |
| 12432 | SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value*); |
| 12433 | SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *); |
| 12434 | SQLITE_PRIVATE char *sqlite3Utf16to8(sqlite3 *, const void*, int, u8); |
| 12435 | SQLITE_PRIVATE int sqlite3ValueFromExpr(sqlite3 *, Expr *, u8, u8, sqlite3_value **); |
| 12436 | SQLITE_PRIVATE void sqlite3ValueApplyAffinity(sqlite3_value *, u8, u8); |
| @@ -12554,11 +12492,10 @@ | |
| 12492 | SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int); |
| 12493 | SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *); |
| 12494 | |
| 12495 | SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, char*, int, int); |
| 12496 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int); |
| 12497 | SQLITE_PRIVATE void sqlite3AppendSpace(StrAccum*,int); |
| 12498 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*); |
| 12499 | SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*); |
| 12500 | SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int); |
| 12501 | SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int); |
| @@ -13781,13 +13718,16 @@ | |
| 13718 | Op *aOp; /* Space to hold the virtual machine's program */ |
| 13719 | Mem *aMem; /* The memory locations */ |
| 13720 | Mem **apArg; /* Arguments to currently executing user function */ |
| 13721 | Mem *aColName; /* Column names to return */ |
| 13722 | Mem *pResultSet; /* Pointer to an array of results */ |
| 13723 | int nMem; /* Number of memory locations currently allocated */ |
| 13724 | int nOp; /* Number of instructions in the program */ |
| 13725 | int nOpAlloc; /* Number of slots allocated for aOp[] */ |
| 13726 | int nLabel; /* Number of labels used */ |
| 13727 | int *aLabel; /* Space to hold the labels */ |
| 13728 | u16 nResColumn; /* Number of columns in one row of the result set */ |
| 13729 | int nCursor; /* Number of slots in apCsr[] */ |
| 13730 | u32 magic; /* Magic number for sanity checking */ |
| 13731 | char *zErrMsg; /* Error message written here */ |
| 13732 | Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */ |
| 13733 | VdbeCursor **apCsr; /* One element of this array for each open cursor */ |
| @@ -13796,11 +13736,10 @@ | |
| 13736 | ynVar nVar; /* Number of entries in aVar[] */ |
| 13737 | ynVar nzVar; /* Number of entries in azVar[] */ |
| 13738 | u32 cacheCtr; /* VdbeCursor row cache generation counter */ |
| 13739 | int pc; /* The program counter */ |
| 13740 | int rc; /* Value to return */ |
| 13741 | u8 errorAction; /* Recovery action to do in case of an error */ |
| 13742 | u8 minWriteFileFormat; /* Minimum file format for writable database files */ |
| 13743 | bft explain:2; /* True if EXPLAIN present on SQL command */ |
| 13744 | bft inVtabMethod:2; /* See comments above */ |
| 13745 | bft changeCntOn:1; /* True to update the change-counter */ |
| @@ -13856,11 +13795,11 @@ | |
| 13795 | #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 13796 | SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, Op*); |
| 13797 | #endif |
| 13798 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 13799 | SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem*, int); |
| 13800 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, int, Mem*, int); |
| 13801 | SQLITE_PRIVATE u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| 13802 | SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(Vdbe*, int, int); |
| 13803 | |
| 13804 | int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *); |
| 13805 | SQLITE_PRIVATE int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*); |
| @@ -15446,25 +15385,11 @@ | |
| 15385 | ** really care if the VFS receives and understands the information since it |
| 15386 | ** is only a hint and can be safely ignored. The sqlite3OsFileControlHint() |
| 15387 | ** routine has no return value since the return value would be meaningless. |
| 15388 | */ |
| 15389 | SQLITE_PRIVATE int sqlite3OsFileControl(sqlite3_file *id, int op, void *pArg){ |
| 15390 | DO_OS_MALLOC_TEST(id); |
| 15391 | return id->pMethods->xFileControl(id, op, pArg); |
| 15392 | } |
| 15393 | SQLITE_PRIVATE void sqlite3OsFileControlHint(sqlite3_file *id, int op, void *pArg){ |
| 15394 | (void)id->pMethods->xFileControl(id, op, pArg); |
| 15395 | } |
| @@ -19455,11 +19380,11 @@ | |
| 19380 | /* |
| 19381 | ** TRUE if p is a lookaside memory allocation from db |
| 19382 | */ |
| 19383 | #ifndef SQLITE_OMIT_LOOKASIDE |
| 19384 | static int isLookaside(sqlite3 *db, void *p){ |
| 19385 | return p && p>=db->lookaside.pStart && p<db->lookaside.pEnd; |
| 19386 | } |
| 19387 | #else |
| 19388 | #define isLookaside(A,B) 0 |
| 19389 | #endif |
| 19390 | |
| @@ -19471,13 +19396,12 @@ | |
| 19396 | assert( sqlite3MemdebugHasType(p, MEMTYPE_HEAP) ); |
| 19397 | assert( sqlite3MemdebugNoType(p, MEMTYPE_DB) ); |
| 19398 | return sqlite3GlobalConfig.m.xSize(p); |
| 19399 | } |
| 19400 | SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3 *db, void *p){ |
| 19401 | assert( db==0 || sqlite3_mutex_held(db->mutex) ); |
| 19402 | if( db && isLookaside(db, p) ){ |
| 19403 | return db->lookaside.sz; |
| 19404 | }else{ |
| 19405 | assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); |
| 19406 | assert( sqlite3MemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP) ); |
| 19407 | assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) ); |
| @@ -19955,35 +19879,10 @@ | |
| 19879 | } |
| 19880 | if( N>0 ){ |
| 19881 | sqlite3StrAccumAppend(pAccum, zSpaces, N); |
| 19882 | } |
| 19883 | } |
| 19884 | |
| 19885 | /* |
| 19886 | ** On machines with a small stack size, you can redefine the |
| 19887 | ** SQLITE_PRINT_BUF_SIZE to be something smaller, if desired. |
| 19888 | */ |
| @@ -19994,14 +19893,14 @@ | |
| 19893 | |
| 19894 | /* |
| 19895 | ** Render a string given by "fmt" into the StrAccum object. |
| 19896 | */ |
| 19897 | SQLITE_PRIVATE void sqlite3VXPrintf( |
| 19898 | StrAccum *pAccum, /* Accumulate results here */ |
| 19899 | int useExtended, /* Allow extended %-conversions */ |
| 19900 | const char *fmt, /* Format string */ |
| 19901 | va_list ap /* arguments */ |
| 19902 | ){ |
| 19903 | int c; /* Next character in the format string */ |
| 19904 | char *bufpt; /* Pointer to the conversion buffer */ |
| 19905 | int precision; /* Precision of the current field */ |
| 19906 | int length; /* Length of the field */ |
| @@ -20015,12 +19914,10 @@ | |
| 19914 | etByte flag_zeropad; /* True if field width constant starts with zero */ |
| 19915 | etByte flag_long; /* True if "l" flag is present */ |
| 19916 | etByte flag_longlong; /* True if the "ll" flag is present */ |
| 19917 | etByte done; /* Loop termination flag */ |
| 19918 | etByte xtype = 0; /* Conversion paradigm */ |
| 19919 | char prefix; /* Prefix character. "+" or "-" or " " or '\0'. */ |
| 19920 | sqlite_uint64 longvalue; /* Value for integer types */ |
| 19921 | LONGDOUBLE_TYPE realvalue; /* Value for real types */ |
| 19922 | const et_info *infop; /* Pointer to the appropriate info structure */ |
| 19923 | char *zOut; /* Rendering buffer */ |
| @@ -20031,22 +19928,13 @@ | |
| 19928 | int nsd; /* Number of significant digits returned */ |
| 19929 | double rounder; /* Used for rounding floating point values */ |
| 19930 | etByte flag_dp; /* True if decimal point should be shown */ |
| 19931 | etByte flag_rtz; /* True if trailing zeros should be removed */ |
| 19932 | #endif |
| 19933 | char buf[etBUFSIZE]; /* Conversion buffer */ |
| 19934 | |
| 19935 | bufpt = 0; |
| 19936 | for(; (c=(*fmt))!=0; ++fmt){ |
| 19937 | if( c!='%' ){ |
| 19938 | int amt; |
| 19939 | bufpt = (char *)fmt; |
| 19940 | amt = 1; |
| @@ -20074,15 +19962,11 @@ | |
| 19962 | } |
| 19963 | }while( !done && (c=(*++fmt))!=0 ); |
| 19964 | /* Get the field width */ |
| 19965 | width = 0; |
| 19966 | if( c=='*' ){ |
| 19967 | width = va_arg(ap,int); |
| 19968 | if( width<0 ){ |
| 19969 | flag_leftjustify = 1; |
| 19970 | width = -width; |
| 19971 | } |
| 19972 | c = *++fmt; |
| @@ -20095,15 +19979,11 @@ | |
| 19979 | /* Get the precision */ |
| 19980 | if( c=='.' ){ |
| 19981 | precision = 0; |
| 19982 | c = *++fmt; |
| 19983 | if( c=='*' ){ |
| 19984 | precision = va_arg(ap,int); |
| 19985 | if( precision<0 ) precision = -precision; |
| 19986 | c = *++fmt; |
| 19987 | }else{ |
| 19988 | while( c>='0' && c<='9' ){ |
| 19989 | precision = precision*10 + c - '0'; |
| @@ -20130,11 +20010,11 @@ | |
| 20010 | infop = &fmtinfo[0]; |
| 20011 | xtype = etINVALID; |
| 20012 | for(idx=0; idx<ArraySize(fmtinfo); idx++){ |
| 20013 | if( c==fmtinfo[idx].fmttype ){ |
| 20014 | infop = &fmtinfo[idx]; |
| 20015 | if( useExtended || (infop->flags & FLAG_INTERN)==0 ){ |
| 20016 | xtype = infop->type; |
| 20017 | }else{ |
| 20018 | return; |
| 20019 | } |
| 20020 | break; |
| @@ -20170,13 +20050,11 @@ | |
| 20050 | /* Fall through into the next case */ |
| 20051 | case etORDINAL: |
| 20052 | case etRADIX: |
| 20053 | if( infop->flags & FLAG_SIGNED ){ |
| 20054 | i64 v; |
| 20055 | if( flag_longlong ){ |
| 20056 | v = va_arg(ap,i64); |
| 20057 | }else if( flag_long ){ |
| 20058 | v = va_arg(ap,long int); |
| 20059 | }else{ |
| 20060 | v = va_arg(ap,int); |
| @@ -20193,13 +20071,11 @@ | |
| 20071 | if( flag_plussign ) prefix = '+'; |
| 20072 | else if( flag_blanksign ) prefix = ' '; |
| 20073 | else prefix = 0; |
| 20074 | } |
| 20075 | }else{ |
| 20076 | if( flag_longlong ){ |
| 20077 | longvalue = va_arg(ap,u64); |
| 20078 | }else if( flag_long ){ |
| 20079 | longvalue = va_arg(ap,unsigned long int); |
| 20080 | }else{ |
| 20081 | longvalue = va_arg(ap,unsigned int); |
| @@ -20215,11 +20091,11 @@ | |
| 20091 | zOut = buf; |
| 20092 | }else{ |
| 20093 | nOut = precision + 10; |
| 20094 | zOut = zExtra = sqlite3Malloc( nOut ); |
| 20095 | if( zOut==0 ){ |
| 20096 | pAccum->accError = STRACCUM_NOMEM; |
| 20097 | return; |
| 20098 | } |
| 20099 | } |
| 20100 | bufpt = &zOut[nOut-1]; |
| 20101 | if( xtype==etORDINAL ){ |
| @@ -20255,15 +20131,11 @@ | |
| 20131 | length = (int)(&zOut[nOut-1]-bufpt); |
| 20132 | break; |
| 20133 | case etFLOAT: |
| 20134 | case etEXP: |
| 20135 | case etGENERIC: |
| 20136 | realvalue = va_arg(ap,double); |
| 20137 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 20138 | length = 0; |
| 20139 | #else |
| 20140 | if( precision<0 ) precision = 6; /* Set default precision */ |
| 20141 | if( realvalue<0.0 ){ |
| @@ -20331,11 +20203,11 @@ | |
| 20203 | e2 = exp; |
| 20204 | } |
| 20205 | if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ |
| 20206 | bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); |
| 20207 | if( bufpt==0 ){ |
| 20208 | pAccum->accError = STRACCUM_NOMEM; |
| 20209 | return; |
| 20210 | } |
| 20211 | } |
| 20212 | zOut = bufpt; |
| 20213 | nsd = 16 + flag_altform2*10; |
| @@ -20414,27 +20286,20 @@ | |
| 20286 | length = width; |
| 20287 | } |
| 20288 | #endif /* !defined(SQLITE_OMIT_FLOATING_POINT) */ |
| 20289 | break; |
| 20290 | case etSIZE: |
| 20291 | *(va_arg(ap,int*)) = pAccum->nChar; |
| 20292 | length = width = 0; |
| 20293 | break; |
| 20294 | case etPERCENT: |
| 20295 | buf[0] = '%'; |
| 20296 | bufpt = buf; |
| 20297 | length = 1; |
| 20298 | break; |
| 20299 | case etCHARX: |
| 20300 | c = va_arg(ap,int); |
| 20301 | buf[0] = (char)c; |
| 20302 | if( precision>=0 ){ |
| 20303 | for(idx=1; idx<precision; idx++) buf[idx] = (char)c; |
| 20304 | length = precision; |
| 20305 | }else{ |
| @@ -20442,18 +20307,14 @@ | |
| 20307 | } |
| 20308 | bufpt = buf; |
| 20309 | break; |
| 20310 | case etSTRING: |
| 20311 | case etDYNSTRING: |
| 20312 | bufpt = va_arg(ap,char*); |
| 20313 | if( bufpt==0 ){ |
| 20314 | bufpt = ""; |
| 20315 | }else if( xtype==etDYNSTRING ){ |
| 20316 | zExtra = bufpt; |
| 20317 | } |
| 20318 | if( precision>=0 ){ |
| 20319 | for(length=0; length<precision && bufpt[length]; length++){} |
| 20320 | }else{ |
| @@ -20465,17 +20326,11 @@ | |
| 20326 | case etSQLESCAPE3: { |
| 20327 | int i, j, k, n, isnull; |
| 20328 | int needQuote; |
| 20329 | char ch; |
| 20330 | char q = ((xtype==etSQLESCAPE3)?'"':'\''); /* Quote character */ |
| 20331 | char *escarg = va_arg(ap,char*); |
| 20332 | isnull = escarg==0; |
| 20333 | if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)"); |
| 20334 | k = precision; |
| 20335 | for(i=n=0; k!=0 && (ch=escarg[i])!=0; i++, k--){ |
| 20336 | if( ch==q ) n++; |
| @@ -20483,11 +20338,11 @@ | |
| 20338 | needQuote = !isnull && xtype==etSQLESCAPE2; |
| 20339 | n += i + 1 + needQuote*2; |
| 20340 | if( n>etBUFSIZE ){ |
| 20341 | bufpt = zExtra = sqlite3Malloc( n ); |
| 20342 | if( bufpt==0 ){ |
| 20343 | pAccum->accError = STRACCUM_NOMEM; |
| 20344 | return; |
| 20345 | } |
| 20346 | }else{ |
| 20347 | bufpt = buf; |
| 20348 | } |
| @@ -20506,28 +20361,26 @@ | |
| 20361 | ** if( precision>=0 && precision<length ) length = precision; */ |
| 20362 | break; |
| 20363 | } |
| 20364 | case etTOKEN: { |
| 20365 | Token *pToken = va_arg(ap, Token*); |
| 20366 | if( pToken ){ |
| 20367 | sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n); |
| 20368 | } |
| 20369 | length = width = 0; |
| 20370 | break; |
| 20371 | } |
| 20372 | case etSRCLIST: { |
| 20373 | SrcList *pSrc = va_arg(ap, SrcList*); |
| 20374 | int k = va_arg(ap, int); |
| 20375 | struct SrcList_item *pItem = &pSrc->a[k]; |
| 20376 | assert( k>=0 && k<pSrc->nSrc ); |
| 20377 | if( pItem->zDatabase ){ |
| 20378 | sqlite3StrAccumAppend(pAccum, pItem->zDatabase, -1); |
| 20379 | sqlite3StrAccumAppend(pAccum, ".", 1); |
| 20380 | } |
| 20381 | sqlite3StrAccumAppend(pAccum, pItem->zName, -1); |
| 20382 | length = width = 0; |
| 20383 | break; |
| 20384 | } |
| 20385 | default: { |
| 20386 | assert( xtype==etINVALID ); |
| @@ -20554,42 +20407,44 @@ | |
| 20407 | nspace = width-length; |
| 20408 | if( nspace>0 ){ |
| 20409 | sqlite3AppendSpace(pAccum, nspace); |
| 20410 | } |
| 20411 | } |
| 20412 | sqlite3_free(zExtra); |
| 20413 | }/* End for loop over the format string */ |
| 20414 | } /* End of function */ |
| 20415 | |
| 20416 | /* |
| 20417 | ** Append N bytes of text from z to the StrAccum object. |
| 20418 | */ |
| 20419 | SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ |
| 20420 | assert( z!=0 || N==0 ); |
| 20421 | if( p->accError ){ |
| 20422 | testcase(p->accError==STRACCUM_TOOBIG); |
| 20423 | testcase(p->accError==STRACCUM_NOMEM); |
| 20424 | return; |
| 20425 | } |
| 20426 | assert( p->zText!=0 || p->nChar==0 ); |
| 20427 | if( N<=0 ){ |
| 20428 | if( N==0 || z[0]==0 ) return; |
| 20429 | N = sqlite3Strlen30(z); |
| 20430 | } |
| 20431 | if( p->nChar+N >= p->nAlloc ){ |
| 20432 | char *zNew; |
| 20433 | if( !p->useMalloc ){ |
| 20434 | p->accError = STRACCUM_TOOBIG; |
| 20435 | N = p->nAlloc - p->nChar - 1; |
| 20436 | if( N<=0 ){ |
| 20437 | return; |
| 20438 | } |
| 20439 | }else{ |
| 20440 | char *zOld = (p->zText==p->zBase ? 0 : p->zText); |
| 20441 | i64 szNew = p->nChar; |
| 20442 | szNew += N + 1; |
| 20443 | if( szNew > p->mxAlloc ){ |
| 20444 | sqlite3StrAccumReset(p); |
| 20445 | p->accError = STRACCUM_TOOBIG; |
| 20446 | return; |
| 20447 | }else{ |
| 20448 | p->nAlloc = (int)szNew; |
| 20449 | } |
| 20450 | if( p->useMalloc==1 ){ |
| @@ -20599,28 +20454,20 @@ | |
| 20454 | } |
| 20455 | if( zNew ){ |
| 20456 | if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); |
| 20457 | p->zText = zNew; |
| 20458 | }else{ |
| 20459 | p->accError = STRACCUM_NOMEM; |
| 20460 | sqlite3StrAccumReset(p); |
| 20461 | return; |
| 20462 | } |
| 20463 | } |
| 20464 | } |
| 20465 | assert( p->zText ); |
| 20466 | memcpy(&p->zText[p->nChar], z, N); |
| 20467 | p->nChar += N; |
| 20468 | } |
| 20469 | |
| 20470 | /* |
| 20471 | ** Finish off a string by making sure it is zero-terminated. |
| 20472 | ** Return a pointer to the resulting string. Return a NULL |
| 20473 | ** pointer if any kind of error was encountered. |
| @@ -20635,11 +20482,11 @@ | |
| 20482 | p->zText = sqlite3_malloc(p->nChar+1); |
| 20483 | } |
| 20484 | if( p->zText ){ |
| 20485 | memcpy(p->zText, p->zBase, p->nChar+1); |
| 20486 | }else{ |
| 20487 | p->accError = STRACCUM_NOMEM; |
| 20488 | } |
| 20489 | } |
| 20490 | } |
| 20491 | return p->zText; |
| 20492 | } |
| @@ -20681,11 +20528,11 @@ | |
| 20528 | StrAccum acc; |
| 20529 | assert( db!=0 ); |
| 20530 | sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), |
| 20531 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 20532 | acc.db = db; |
| 20533 | sqlite3VXPrintf(&acc, 1, zFormat, ap); |
| 20534 | z = sqlite3StrAccumFinish(&acc); |
| 20535 | if( acc.accError==STRACCUM_NOMEM ){ |
| 20536 | db->mallocFailed = 1; |
| 20537 | } |
| 20538 | return z; |
| @@ -20837,19 +20684,21 @@ | |
| 20684 | fprintf(stdout,"%s", zBuf); |
| 20685 | fflush(stdout); |
| 20686 | } |
| 20687 | #endif |
| 20688 | |
| 20689 | #ifndef SQLITE_OMIT_TRACE |
| 20690 | /* |
| 20691 | ** variable-argument wrapper around sqlite3VXPrintf(). |
| 20692 | */ |
| 20693 | SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){ |
| 20694 | va_list ap; |
| 20695 | va_start(ap,zFormat); |
| 20696 | sqlite3VXPrintf(p, 1, zFormat, ap); |
| 20697 | va_end(ap); |
| 20698 | } |
| 20699 | #endif |
| 20700 | |
| 20701 | /************** End of printf.c **********************************************/ |
| 20702 | /************** Begin file random.c ******************************************/ |
| 20703 | /* |
| 20704 | ** 2001 September 15 |
| @@ -20902,16 +20751,10 @@ | |
| 20751 | #if SQLITE_THREADSAFE |
| 20752 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG); |
| 20753 | sqlite3_mutex_enter(mutex); |
| 20754 | #endif |
| 20755 | |
| 20756 | /* Initialize the state of the random number generator once, |
| 20757 | ** the first time this routine is called. The seed value does |
| 20758 | ** not need to contain a lot of randomness since we are not |
| 20759 | ** trying to do secure encryption or anything like that... |
| 20760 | ** |
| @@ -20935,20 +20778,19 @@ | |
| 20778 | wsdPrng.s[i] = t; |
| 20779 | } |
| 20780 | wsdPrng.isInit = 1; |
| 20781 | } |
| 20782 | |
| 20783 | while( N-- ){ |
| 20784 | wsdPrng.i++; |
| 20785 | t = wsdPrng.s[wsdPrng.i]; |
| 20786 | wsdPrng.j += t; |
| 20787 | wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j]; |
| 20788 | wsdPrng.s[wsdPrng.j] = t; |
| 20789 | t += wsdPrng.s[wsdPrng.i]; |
| 20790 | *(zBuf++) = wsdPrng.s[t]; |
| 20791 | } |
| 20792 | sqlite3_mutex_leave(mutex); |
| 20793 | } |
| 20794 | |
| 20795 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20796 | /* |
| @@ -20973,10 +20815,13 @@ | |
| 20815 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 20816 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 20817 | sizeof(sqlite3Prng) |
| 20818 | ); |
| 20819 | } |
| 20820 | SQLITE_PRIVATE void sqlite3PrngResetState(void){ |
| 20821 | GLOBAL(struct sqlite3PrngType, sqlite3Prng).isInit = 0; |
| 20822 | } |
| 20823 | #endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 20824 | |
| 20825 | /************** End of random.c **********************************************/ |
| 20826 | /************** Begin file utf.c *********************************************/ |
| 20827 | /* |
| @@ -21624,21 +21469,22 @@ | |
| 21469 | ** To clear the most recent error for sqlite handle "db", sqlite3Error |
| 21470 | ** should be called with err_code set to SQLITE_OK and zFormat set |
| 21471 | ** to NULL. |
| 21472 | */ |
| 21473 | SQLITE_PRIVATE void sqlite3Error(sqlite3 *db, int err_code, const char *zFormat, ...){ |
| 21474 | if( db && (db->pErr || (db->pErr = sqlite3ValueNew(db))!=0) ){ |
| 21475 | db->errCode = err_code; |
| 21476 | if( zFormat ){ |
| 21477 | char *z; |
| 21478 | va_list ap; |
| 21479 | va_start(ap, zFormat); |
| 21480 | z = sqlite3VMPrintf(db, zFormat, ap); |
| 21481 | va_end(ap); |
| 21482 | sqlite3ValueSetStr(db->pErr, -1, z, SQLITE_UTF8, SQLITE_DYNAMIC); |
| 21483 | }else{ |
| 21484 | sqlite3ValueSetStr(db->pErr, 0, 0, SQLITE_UTF8, SQLITE_STATIC); |
| 21485 | } |
| 21486 | } |
| 21487 | } |
| 21488 | |
| 21489 | /* |
| 21490 | ** Add an error message to pParse->zErrMsg and increment pParse->nErr. |
| @@ -23119,11 +22965,11 @@ | |
| 22965 | /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 22966 | /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 22967 | /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 22968 | /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 22969 | /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 22970 | /* 30 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 22971 | /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 22972 | /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 22973 | /* 33 */ "CollSeq" OpHelp(""), |
| 22974 | /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 22975 | /* 35 */ "MustBeInt" OpHelp(""), |
| @@ -23510,16 +23356,10 @@ | |
| 23356 | */ |
| 23357 | char aPadding[32]; |
| 23358 | #endif |
| 23359 | }; |
| 23360 | |
| 23361 | /* |
| 23362 | ** Allowed values for the unixFile.ctrlFlags bitmask: |
| 23363 | */ |
| 23364 | #define UNIXFILE_EXCL 0x01 /* Connections from one process only */ |
| 23365 | #define UNIXFILE_RDONLY 0x02 /* Connection is read only */ |
| @@ -24779,19 +24619,10 @@ | |
| 24619 | } |
| 24620 | *ppInode = pInode; |
| 24621 | return SQLITE_OK; |
| 24622 | } |
| 24623 | |
| 24624 | |
| 24625 | /* |
| 24626 | ** Check a unixFile that is a database. Verify the following: |
| 24627 | ** |
| 24628 | ** (1) There is exactly one hard link on the file |
| @@ -24822,11 +24653,14 @@ | |
| 24653 | if( buf.st_nlink>1 ){ |
| 24654 | sqlite3_log(SQLITE_WARNING, "multiple links to file: %s", pFile->zPath); |
| 24655 | pFile->ctrlFlags |= UNIXFILE_WARNED; |
| 24656 | return; |
| 24657 | } |
| 24658 | if( pFile->pInode!=0 |
| 24659 | && ((rc = osStat(pFile->zPath, &buf))!=0 |
| 24660 | || buf.st_ino!=pFile->pInode->fileId.ino) |
| 24661 | ){ |
| 24662 | sqlite3_log(SQLITE_WARNING, "file renamed while open: %s", pFile->zPath); |
| 24663 | pFile->ctrlFlags |= UNIXFILE_WARNED; |
| 24664 | return; |
| 24665 | } |
| 24666 | } |
| @@ -27271,14 +27105,10 @@ | |
| 27105 | unixGetTempname(pFile->pVfs->mxPathname, zTFile); |
| 27106 | *(char**)pArg = zTFile; |
| 27107 | } |
| 27108 | return SQLITE_OK; |
| 27109 | } |
| 27110 | #if SQLITE_MAX_MMAP_SIZE>0 |
| 27111 | case SQLITE_FCNTL_MMAP_SIZE: { |
| 27112 | i64 newLimit = *(i64*)pArg; |
| 27113 | int rc = SQLITE_OK; |
| 27114 | if( newLimit>sqlite3GlobalConfig.mxMmap ){ |
| @@ -29115,20 +28945,10 @@ | |
| 28945 | || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL |
| 28946 | || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL |
| 28947 | || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL |
| 28948 | ); |
| 28949 | |
| 28950 | memset(p, 0, sizeof(unixFile)); |
| 28951 | |
| 28952 | if( eType==SQLITE_OPEN_MAIN_DB ){ |
| 28953 | UnixUnusedFd *pUnused; |
| 28954 | pUnused = findReusableFd(zName, flags); |
| @@ -29512,22 +29332,22 @@ | |
| 29332 | ** When testing, initializing zBuf[] to zero is all we do. That means |
| 29333 | ** that we always use the same random number sequence. This makes the |
| 29334 | ** tests repeatable. |
| 29335 | */ |
| 29336 | memset(zBuf, 0, nBuf); |
| 29337 | #if !defined(SQLITE_TEST) |
| 29338 | { |
| 29339 | int pid, fd, got; |
| 29340 | fd = robust_open("/dev/urandom", O_RDONLY, 0); |
| 29341 | if( fd<0 ){ |
| 29342 | time_t t; |
| 29343 | time(&t); |
| 29344 | memcpy(zBuf, &t, sizeof(t)); |
| 29345 | pid = getpid(); |
| 29346 | memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid)); |
| 29347 | assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf ); |
| 29348 | nBuf = sizeof(t) + sizeof(pid); |
| 29349 | }else{ |
| 29350 | do{ got = osRead(fd, zBuf, nBuf); }while( got<0 && errno==EINTR ); |
| 29351 | robust_close(0, fd, __LINE__); |
| 29352 | } |
| 29353 | } |
| @@ -34261,11 +34081,11 @@ | |
| 34081 | winModeBit(pFile, WINFILE_PSOW, (int*)pArg); |
| 34082 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 34083 | return SQLITE_OK; |
| 34084 | } |
| 34085 | case SQLITE_FCNTL_VFSNAME: { |
| 34086 | *(char**)pArg = sqlite3_mprintf("win32"); |
| 34087 | OSTRACE(("FCNTL file=%p, rc=SQLITE_OK\n", pFile->h)); |
| 34088 | return SQLITE_OK; |
| 34089 | } |
| 34090 | case SQLITE_FCNTL_WIN32_AV_RETRY: { |
| 34091 | int *a = (int*)pArg; |
| @@ -37703,11 +37523,10 @@ | |
| 37523 | ** in memory. |
| 37524 | */ |
| 37525 | struct PgHdr1 { |
| 37526 | sqlite3_pcache_page page; |
| 37527 | unsigned int iKey; /* Key value (page number) */ |
| 37528 | PgHdr1 *pNext; /* Next in hash table chain */ |
| 37529 | PCache1 *pCache; /* Cache that currently owns this page */ |
| 37530 | PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */ |
| 37531 | PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */ |
| 37532 | }; |
| @@ -38032,36 +37851,38 @@ | |
| 37851 | ** This function is used internally to remove the page pPage from the |
| 37852 | ** PGroup LRU list, if is part of it. If pPage is not part of the PGroup |
| 37853 | ** LRU list, then this function is a no-op. |
| 37854 | ** |
| 37855 | ** The PGroup mutex must be held when this function is called. |
| 37856 | ** |
| 37857 | ** If pPage is NULL then this routine is a no-op. |
| 37858 | */ |
| 37859 | static void pcache1PinPage(PgHdr1 *pPage){ |
| 37860 | PCache1 *pCache; |
| 37861 | PGroup *pGroup; |
| 37862 | |
| 37863 | if( pPage==0 ) return; |
| 37864 | pCache = pPage->pCache; |
| 37865 | pGroup = pCache->pGroup; |
| 37866 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 37867 | if( pPage->pLruNext || pPage==pGroup->pLruTail ){ |
| 37868 | if( pPage->pLruPrev ){ |
| 37869 | pPage->pLruPrev->pLruNext = pPage->pLruNext; |
| 37870 | } |
| 37871 | if( pPage->pLruNext ){ |
| 37872 | pPage->pLruNext->pLruPrev = pPage->pLruPrev; |
| 37873 | } |
| 37874 | if( pGroup->pLruHead==pPage ){ |
| 37875 | pGroup->pLruHead = pPage->pLruNext; |
| 37876 | } |
| 37877 | if( pGroup->pLruTail==pPage ){ |
| 37878 | pGroup->pLruTail = pPage->pLruPrev; |
| 37879 | } |
| 37880 | pPage->pLruNext = 0; |
| 37881 | pPage->pLruPrev = 0; |
| 37882 | pPage->pCache->nRecyclable--; |
| 37883 | } |
| 37884 | } |
| 37885 | |
| 37886 | |
| 37887 | /* |
| 37888 | ** Remove the page supplied as an argument from the hash table |
| @@ -38089,11 +37910,10 @@ | |
| 37910 | static void pcache1EnforceMaxPage(PGroup *pGroup){ |
| 37911 | assert( sqlite3_mutex_held(pGroup->mutex) ); |
| 37912 | while( pGroup->nCurrentPage>pGroup->nMaxPage && pGroup->pLruTail ){ |
| 37913 | PgHdr1 *p = pGroup->pLruTail; |
| 37914 | assert( p->pCache->pGroup==pGroup ); |
| 37915 | pcache1PinPage(p); |
| 37916 | pcache1RemoveFromHash(p); |
| 37917 | pcache1FreePage(p); |
| 37918 | } |
| 37919 | } |
| @@ -38117,11 +37937,11 @@ | |
| 37937 | PgHdr1 *pPage; |
| 37938 | while( (pPage = *pp)!=0 ){ |
| 37939 | if( pPage->iKey>=iLimit ){ |
| 37940 | pCache->nPage--; |
| 37941 | *pp = pPage->pNext; |
| 37942 | pcache1PinPage(pPage); |
| 37943 | pcache1FreePage(pPage); |
| 37944 | }else{ |
| 37945 | pp = &pPage->pNext; |
| 37946 | TESTONLY( nPage++; ) |
| 37947 | } |
| @@ -38340,15 +38160,12 @@ | |
| 38160 | unsigned int h = iKey % pCache->nHash; |
| 38161 | for(pPage=pCache->apHash[h]; pPage&&pPage->iKey!=iKey; pPage=pPage->pNext); |
| 38162 | } |
| 38163 | |
| 38164 | /* Step 2: Abort if no existing page is found and createFlag is 0 */ |
| 38165 | if( pPage || createFlag==0 ){ |
| 38166 | pcache1PinPage(pPage); |
| 38167 | goto fetch_out; |
| 38168 | } |
| 38169 | |
| 38170 | /* The pGroup local variable will normally be initialized by the |
| 38171 | ** pcache1EnterMutex() macro above. But if SQLITE_MUTEX_OMIT is defined, |
| @@ -38385,11 +38202,10 @@ | |
| 38202 | || pGroup->nCurrentPage>=pGroup->nMaxPage |
| 38203 | || pcache1UnderMemoryPressure(pCache) |
| 38204 | )){ |
| 38205 | PCache1 *pOther; |
| 38206 | pPage = pGroup->pLruTail; |
| 38207 | pcache1RemoveFromHash(pPage); |
| 38208 | pcache1PinPage(pPage); |
| 38209 | pOther = pPage->pCache; |
| 38210 | |
| 38211 | /* We want to verify that szPage and szExtra are the same for pOther |
| @@ -38422,11 +38238,10 @@ | |
| 38238 | pPage->iKey = iKey; |
| 38239 | pPage->pNext = pCache->apHash[h]; |
| 38240 | pPage->pCache = pCache; |
| 38241 | pPage->pLruPrev = 0; |
| 38242 | pPage->pLruNext = 0; |
| 38243 | *(void **)pPage->page.pExtra = 0; |
| 38244 | pCache->apHash[h] = pPage; |
| 38245 | } |
| 38246 | |
| 38247 | fetch_out: |
| @@ -38458,11 +38273,10 @@ | |
| 38273 | /* It is an error to call this function if the page is already |
| 38274 | ** part of the PGroup LRU list. |
| 38275 | */ |
| 38276 | assert( pPage->pLruPrev==0 && pPage->pLruNext==0 ); |
| 38277 | assert( pGroup->pLruHead!=pPage && pGroup->pLruTail!=pPage ); |
| 38278 | |
| 38279 | if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){ |
| 38280 | pcache1RemoveFromHash(pPage); |
| 38281 | pcache1FreePage(pPage); |
| 38282 | }else{ |
| @@ -38474,11 +38288,10 @@ | |
| 38288 | }else{ |
| 38289 | pGroup->pLruTail = pPage; |
| 38290 | pGroup->pLruHead = pPage; |
| 38291 | } |
| 38292 | pCache->nRecyclable++; |
| 38293 | } |
| 38294 | |
| 38295 | pcache1LeaveMutex(pCache->pGroup); |
| 38296 | } |
| 38297 | |
| @@ -38601,11 +38414,10 @@ | |
| 38414 | while( (nReq<0 || nFree<nReq) && ((p=pcache1.grp.pLruTail)!=0) ){ |
| 38415 | nFree += pcache1MemSize(p->page.pBuf); |
| 38416 | #ifdef SQLITE_PCACHE_SEPARATE_HEADER |
| 38417 | nFree += sqlite3MemSize(p); |
| 38418 | #endif |
| 38419 | pcache1PinPage(p); |
| 38420 | pcache1RemoveFromHash(p); |
| 38421 | pcache1FreePage(p); |
| 38422 | } |
| 38423 | pcache1LeaveMutex(&pcache1.grp); |
| @@ -38626,11 +38438,10 @@ | |
| 38438 | int *pnRecyclable /* OUT: Total number of pages available for recycling */ |
| 38439 | ){ |
| 38440 | PgHdr1 *p; |
| 38441 | int nRecyclable = 0; |
| 38442 | for(p=pcache1.grp.pLruHead; p; p=p->pLruNext){ |
| 38443 | nRecyclable++; |
| 38444 | } |
| 38445 | *pnCurrent = pcache1.grp.nCurrentPage; |
| 38446 | *pnMax = (int)pcache1.grp.nMaxPage; |
| 38447 | *pnMin = (int)pcache1.grp.nMinPage; |
| @@ -40313,26 +40124,29 @@ | |
| 40124 | ** PagerSavepoint.pInSavepoint. |
| 40125 | */ |
| 40126 | static int subjRequiresPage(PgHdr *pPg){ |
| 40127 | Pager *pPager = pPg->pPager; |
| 40128 | PagerSavepoint *p; |
| 40129 | Pgno pgno; |
| 40130 | int i; |
| 40131 | if( pPager->nSavepoint ){ |
| 40132 | pgno = pPg->pgno; |
| 40133 | for(i=0; i<pPager->nSavepoint; i++){ |
| 40134 | p = &pPager->aSavepoint[i]; |
| 40135 | if( p->nOrig>=pgno && 0==sqlite3BitvecTest(p->pInSavepoint, pgno) ){ |
| 40136 | return 1; |
| 40137 | } |
| 40138 | } |
| 40139 | } |
| 40140 | return 0; |
| 40141 | } |
| 40142 | |
| 40143 | /* |
| 40144 | ** Return true if the page is already in the journal file. |
| 40145 | */ |
| 40146 | static int pageInJournal(PgHdr *pPg){ |
| 40147 | return sqlite3BitvecTest(pPg->pPager->pInJournal, pPg->pgno); |
| 40148 | } |
| 40149 | |
| 40150 | /* |
| 40151 | ** Read a 32-bit integer from the given file descriptor. Store the integer |
| 40152 | ** that is read in *pRes. Return SQLITE_OK if everything worked, or an |
| @@ -40535,11 +40349,10 @@ | |
| 40349 | |
| 40350 | if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ)) |
| 40351 | || szJ<16 |
| 40352 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len)) |
| 40353 | || len>=nMaster |
| 40354 | || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum)) |
| 40355 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8)) |
| 40356 | || memcmp(aMagic, aJournalMagic, 8) |
| 40357 | || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len)) |
| 40358 | ){ |
| @@ -41276,11 +41089,11 @@ | |
| 41089 | sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash); |
| 41090 | if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){ |
| 41091 | PgHdr *p = pager_lookup(pPager, 1); |
| 41092 | if( p ){ |
| 41093 | p->pageHash = 0; |
| 41094 | sqlite3PagerUnref(p); |
| 41095 | } |
| 41096 | } |
| 41097 | #endif |
| 41098 | |
| 41099 | sqlite3BitvecDestroy(pPager->pInJournal); |
| @@ -41305,15 +41118,10 @@ | |
| 41118 | ** required size. */ |
| 41119 | assert( pPager->eLock==EXCLUSIVE_LOCK ); |
| 41120 | rc = pager_truncate(pPager, pPager->dbSize); |
| 41121 | } |
| 41122 | |
| 41123 | if( !pPager->exclusiveMode |
| 41124 | && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0)) |
| 41125 | ){ |
| 41126 | rc2 = pagerUnlockDb(pPager, SHARED_LOCK); |
| 41127 | pPager->changeCountDone = 0; |
| @@ -42123,11 +41931,11 @@ | |
| 41931 | testcase( rc!=SQLITE_OK ); |
| 41932 | } |
| 41933 | if( rc==SQLITE_OK |
| 41934 | && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN) |
| 41935 | ){ |
| 41936 | rc = sqlite3PagerSync(pPager); |
| 41937 | } |
| 41938 | if( rc==SQLITE_OK ){ |
| 41939 | rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0); |
| 41940 | testcase( rc!=SQLITE_OK ); |
| 41941 | } |
| @@ -42269,11 +42077,11 @@ | |
| 42077 | rc = readDbPage(pPg, iFrame); |
| 42078 | } |
| 42079 | if( rc==SQLITE_OK ){ |
| 42080 | pPager->xReiniter(pPg); |
| 42081 | } |
| 42082 | sqlite3PagerUnref(pPg); |
| 42083 | } |
| 42084 | } |
| 42085 | |
| 42086 | /* Normally, if a transaction is rolled back, any backup processes are |
| 42087 | ** updated as data is copied out of the rollback journal and into the |
| @@ -43624,11 +43432,11 @@ | |
| 43432 | /* Open the sub-journal, if it has not already been opened */ |
| 43433 | assert( pPager->useJournal ); |
| 43434 | assert( isOpen(pPager->jfd) || pagerUseWal(pPager) ); |
| 43435 | assert( isOpen(pPager->sjfd) || pPager->nSubRec==0 ); |
| 43436 | assert( pagerUseWal(pPager) |
| 43437 | || pageInJournal(pPg) |
| 43438 | || pPg->pgno>pPager->dbOrigSize |
| 43439 | ); |
| 43440 | rc = openSubJournal(pPager); |
| 43441 | |
| 43442 | /* If the sub-journal was opened successfully (or was already open), |
| @@ -44089,34 +43897,10 @@ | |
| 43897 | *ppPager = pPager; |
| 43898 | return SQLITE_OK; |
| 43899 | } |
| 43900 | |
| 43901 | |
| 43902 | |
| 43903 | /* |
| 43904 | ** This function is called after transitioning from PAGER_UNLOCK to |
| 43905 | ** PAGER_SHARED state. It tests if there is a hot journal present in |
| 43906 | ** the file-system for the given pager. A hot journal is one that |
| @@ -44584,11 +44368,11 @@ | |
| 44368 | if( bMmapOk && pagerUseWal(pPager) ){ |
| 44369 | rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame); |
| 44370 | if( rc!=SQLITE_OK ) goto pager_acquire_err; |
| 44371 | } |
| 44372 | |
| 44373 | if( iFrame==0 && bMmapOk ){ |
| 44374 | void *pData = 0; |
| 44375 | |
| 44376 | rc = sqlite3OsFetch(pPager->fd, |
| 44377 | (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData |
| 44378 | ); |
| @@ -44725,23 +44509,20 @@ | |
| 44509 | ** If the number of references to the page drop to zero, then the |
| 44510 | ** page is added to the LRU list. When all references to all pages |
| 44511 | ** are released, a rollback occurs and the lock on the database is |
| 44512 | ** removed. |
| 44513 | */ |
| 44514 | SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){ |
| 44515 | if( pPg ){ |
| 44516 | Pager *pPager = pPg->pPager; |
| 44517 | if( pPg->flags & PGHDR_MMAP ){ |
| 44518 | pagerReleaseMapPage(pPg); |
| 44519 | }else{ |
| 44520 | sqlite3PcacheRelease(pPg); |
| 44521 | } |
| 44522 | pagerUnlockIfUnused(pPager); |
| 44523 | } |
| 44524 | } |
| 44525 | |
| 44526 | /* |
| 44527 | ** This function is called at the start of every write transaction. |
| 44528 | ** There must already be a RESERVED or EXCLUSIVE lock on the database |
| @@ -44792,23 +44573,17 @@ | |
| 44573 | SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE| |
| 44574 | (pPager->tempFile ? |
| 44575 | (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL): |
| 44576 | (SQLITE_OPEN_MAIN_JOURNAL) |
| 44577 | ); |
| 44578 | #ifdef SQLITE_ENABLE_ATOMIC_WRITE |
| 44579 | rc = sqlite3JournalOpen( |
| 44580 | pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager) |
| 44581 | ); |
| 44582 | #else |
| 44583 | rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0); |
| 44584 | #endif |
| 44585 | } |
| 44586 | assert( rc!=SQLITE_OK || isOpen(pPager->jfd) ); |
| 44587 | } |
| 44588 | |
| 44589 | |
| @@ -44925,13 +44700,13 @@ | |
| 44700 | ** one of the journals, the corresponding bit is set in the |
| 44701 | ** Pager.pInJournal bitvec and the PagerSavepoint.pInSavepoint bitvecs |
| 44702 | ** of any open savepoints as appropriate. |
| 44703 | */ |
| 44704 | static int pager_write(PgHdr *pPg){ |
| 44705 | void *pData = pPg->pData; |
| 44706 | Pager *pPager = pPg->pPager; |
| 44707 | int rc = SQLITE_OK; |
| 44708 | |
| 44709 | /* This routine is not called unless a write-transaction has already |
| 44710 | ** been started. The journal file may or may not be open at this point. |
| 44711 | ** It is never called in the ERROR state. |
| 44712 | */ |
| @@ -44938,12 +44713,18 @@ | |
| 44713 | assert( pPager->eState==PAGER_WRITER_LOCKED |
| 44714 | || pPager->eState==PAGER_WRITER_CACHEMOD |
| 44715 | || pPager->eState==PAGER_WRITER_DBMOD |
| 44716 | ); |
| 44717 | assert( assert_pager_state(pPager) ); |
| 44718 | |
| 44719 | /* If an error has been previously detected, report the same error |
| 44720 | ** again. This should not happen, but the check provides robustness. */ |
| 44721 | if( NEVER(pPager->errCode) ) return pPager->errCode; |
| 44722 | |
| 44723 | /* Higher-level routines never call this function if database is not |
| 44724 | ** writable. But check anyway, just for robustness. */ |
| 44725 | if( NEVER(pPager->readOnly) ) return SQLITE_PERM; |
| 44726 | |
| 44727 | CHECK_PAGE(pPg); |
| 44728 | |
| 44729 | /* The journal file needs to be opened. Higher level routines have already |
| 44730 | ** obtained the necessary locks to begin the write-transaction, but the |
| @@ -44963,20 +44744,19 @@ | |
| 44744 | |
| 44745 | /* Mark the page as dirty. If the page has already been written |
| 44746 | ** to the journal then we can return right away. |
| 44747 | */ |
| 44748 | sqlite3PcacheMakeDirty(pPg); |
| 44749 | if( pageInJournal(pPg) && !subjRequiresPage(pPg) ){ |
| 44750 | assert( !pagerUseWal(pPager) ); |
| 44751 | }else{ |
| 44752 | |
| 44753 | /* The transaction journal now exists and we have a RESERVED or an |
| 44754 | ** EXCLUSIVE lock on the main database file. Write the current page to |
| 44755 | ** the transaction journal if it is not there already. |
| 44756 | */ |
| 44757 | if( !pageInJournal(pPg) && !pagerUseWal(pPager) ){ |
| 44758 | assert( pagerUseWal(pPager)==0 ); |
| 44759 | if( pPg->pgno<=pPager->dbOrigSize && isOpen(pPager->jfd) ){ |
| 44760 | u32 cksum; |
| 44761 | char *pData2; |
| 44762 | i64 iOff = pPager->journalOff; |
| @@ -44985,11 +44765,11 @@ | |
| 44765 | ** contains the database locks. The following assert verifies |
| 44766 | ** that we do not. */ |
| 44767 | assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 44768 | |
| 44769 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 44770 | CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM, pData2); |
| 44771 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 44772 | |
| 44773 | /* Even if an IO or diskfull error occurs while journalling the |
| 44774 | ** page in the block above, set the need-sync flag for the page. |
| 44775 | ** Otherwise, when the transaction is rolled back, the logic in |
| @@ -45037,11 +44817,11 @@ | |
| 44817 | /* If the statement journal is open and the page is not in it, |
| 44818 | ** then write the current page to the statement journal. Note that |
| 44819 | ** the statement journal format differs from the standard journal format |
| 44820 | ** in that it omits the checksums and the header. |
| 44821 | */ |
| 44822 | if( subjRequiresPage(pPg) ){ |
| 44823 | rc = subjournalPage(pPg); |
| 44824 | } |
| 44825 | } |
| 44826 | |
| 44827 | /* Update the database size and return. |
| @@ -45069,23 +44849,23 @@ | |
| 44849 | SQLITE_PRIVATE int sqlite3PagerWrite(DbPage *pDbPage){ |
| 44850 | int rc = SQLITE_OK; |
| 44851 | |
| 44852 | PgHdr *pPg = pDbPage; |
| 44853 | Pager *pPager = pPg->pPager; |
| 44854 | Pgno nPagePerSector = (pPager->sectorSize/pPager->pageSize); |
| 44855 | |
| 44856 | assert( (pPg->flags & PGHDR_MMAP)==0 ); |
| 44857 | assert( pPager->eState>=PAGER_WRITER_LOCKED ); |
| 44858 | assert( pPager->eState!=PAGER_ERROR ); |
| 44859 | assert( assert_pager_state(pPager) ); |
| 44860 | |
| 44861 | if( nPagePerSector>1 ){ |
| 44862 | Pgno nPageCount; /* Total number of pages in database file */ |
| 44863 | Pgno pg1; /* First page of the sector pPg is located on. */ |
| 44864 | int nPage = 0; /* Number of pages starting at pg1 to journal */ |
| 44865 | int ii; /* Loop counter */ |
| 44866 | int needSync = 0; /* True if any page has PGHDR_NEED_SYNC */ |
| 44867 | |
| 44868 | /* Set the doNotSpill NOSYNC bit to 1. This is because we cannot allow |
| 44869 | ** a journal header to be written between the pages journaled by |
| 44870 | ** this function. |
| 44871 | */ |
| @@ -45120,18 +44900,18 @@ | |
| 44900 | if( rc==SQLITE_OK ){ |
| 44901 | rc = pager_write(pPage); |
| 44902 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 44903 | needSync = 1; |
| 44904 | } |
| 44905 | sqlite3PagerUnref(pPage); |
| 44906 | } |
| 44907 | } |
| 44908 | }else if( (pPage = pager_lookup(pPager, pg))!=0 ){ |
| 44909 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 44910 | needSync = 1; |
| 44911 | } |
| 44912 | sqlite3PagerUnref(pPage); |
| 44913 | } |
| 44914 | } |
| 44915 | |
| 44916 | /* If the PGHDR_NEED_SYNC flag is set for any of the nPage pages |
| 44917 | ** starting at pg1, then it needs to be set for all of them. Because |
| @@ -45143,11 +44923,11 @@ | |
| 44923 | assert( !MEMDB ); |
| 44924 | for(ii=0; ii<nPage; ii++){ |
| 44925 | PgHdr *pPage = pager_lookup(pPager, pg1+ii); |
| 44926 | if( pPage ){ |
| 44927 | pPage->flags |= PGHDR_NEED_SYNC; |
| 44928 | sqlite3PagerUnref(pPage); |
| 44929 | } |
| 44930 | } |
| 44931 | } |
| 44932 | |
| 44933 | assert( (pPager->doNotSpill & SPILLFLAG_NOSYNC)!=0 ); |
| @@ -45296,21 +45076,21 @@ | |
| 45076 | ** or pages with the Pager.noSync flag set. |
| 45077 | ** |
| 45078 | ** If successful, or if called on a pager for which it is a no-op, this |
| 45079 | ** function returns SQLITE_OK. Otherwise, an IO error code is returned. |
| 45080 | */ |
| 45081 | SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager){ |
| 45082 | int rc = SQLITE_OK; |
| 45083 | if( !pPager->noSync ){ |
| 45084 | assert( !MEMDB ); |
| 45085 | rc = sqlite3OsSync(pPager->fd, pPager->syncFlags); |
| 45086 | }else if( isOpen(pPager->fd) ){ |
| 45087 | assert( !MEMDB ); |
| 45088 | rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC_OMITTED, 0); |
| 45089 | if( rc==SQLITE_NOTFOUND ){ |
| 45090 | rc = SQLITE_OK; |
| 45091 | } |
| 45092 | } |
| 45093 | return rc; |
| 45094 | } |
| 45095 | |
| 45096 | /* |
| @@ -45505,11 +45285,11 @@ | |
| 45285 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 45286 | } |
| 45287 | |
| 45288 | /* Finally, sync the database file. */ |
| 45289 | if( !noSync ){ |
| 45290 | rc = sqlite3PagerSync(pPager); |
| 45291 | } |
| 45292 | IOTRACE(("DBSYNC %p\n", pPager)) |
| 45293 | } |
| 45294 | } |
| 45295 | |
| @@ -45634,13 +45414,11 @@ | |
| 45414 | rc = pager_playback(pPager, 0); |
| 45415 | } |
| 45416 | |
| 45417 | assert( pPager->eState==PAGER_READER || rc!=SQLITE_OK ); |
| 45418 | assert( rc==SQLITE_OK || rc==SQLITE_FULL || rc==SQLITE_CORRUPT |
| 45419 | || rc==SQLITE_NOMEM || (rc&0xFF)==SQLITE_IOERR ); |
| 45420 | |
| 45421 | /* If an error occurs during a ROLLBACK, we can no longer trust the pager |
| 45422 | ** cache. So call pager_error() on the way out to make any error persistent. |
| 45423 | */ |
| 45424 | return pager_error(pPager, rc); |
| @@ -46039,11 +45817,11 @@ | |
| 45817 | ** can be written to. The caller has already promised not to write to it. |
| 45818 | */ |
| 45819 | if( (pPg->flags&PGHDR_NEED_SYNC) && !isCommit ){ |
| 45820 | needSyncPgno = pPg->pgno; |
| 45821 | assert( pPager->journalMode==PAGER_JOURNALMODE_OFF || |
| 45822 | pageInJournal(pPg) || pPg->pgno>pPager->dbOrigSize ); |
| 45823 | assert( pPg->flags&PGHDR_DIRTY ); |
| 45824 | } |
| 45825 | |
| 45826 | /* If the cache contains a page with page-number pgno, remove it |
| 45827 | ** from its hash chain. Also, if the PGHDR_NEED_SYNC flag was set for |
| @@ -46073,11 +45851,11 @@ | |
| 45851 | ** as the original page since it has already been allocated. |
| 45852 | */ |
| 45853 | if( MEMDB ){ |
| 45854 | assert( pPgOld ); |
| 45855 | sqlite3PcacheMove(pPgOld, origPgno); |
| 45856 | sqlite3PagerUnref(pPgOld); |
| 45857 | } |
| 45858 | |
| 45859 | if( needSyncPgno ){ |
| 45860 | /* If needSyncPgno is non-zero, then the journal file needs to be |
| 45861 | ** sync()ed before any data is written to database file page needSyncPgno. |
| @@ -46102,11 +45880,11 @@ | |
| 45880 | } |
| 45881 | return rc; |
| 45882 | } |
| 45883 | pPgHdr->flags |= PGHDR_NEED_SYNC; |
| 45884 | sqlite3PcacheMakeDirty(pPgHdr); |
| 45885 | sqlite3PagerUnref(pPgHdr); |
| 45886 | } |
| 45887 | |
| 45888 | return SQLITE_OK; |
| 45889 | } |
| 45890 | #endif |
| @@ -52221,11 +51999,11 @@ | |
| 51999 | |
| 52000 | if( pgno>btreePagecount(pBt) ){ |
| 52001 | rc = SQLITE_CORRUPT_BKPT; |
| 52002 | }else{ |
| 52003 | rc = btreeGetPage(pBt, pgno, ppPage, bReadonly); |
| 52004 | if( rc==SQLITE_OK ){ |
| 52005 | rc = btreeInitPage(*ppPage); |
| 52006 | if( rc!=SQLITE_OK ){ |
| 52007 | releasePage(*ppPage); |
| 52008 | } |
| 52009 | } |
| @@ -52242,15 +52020,14 @@ | |
| 52020 | */ |
| 52021 | static void releasePage(MemPage *pPage){ |
| 52022 | if( pPage ){ |
| 52023 | assert( pPage->aData ); |
| 52024 | assert( pPage->pBt ); |
| 52025 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 52026 | assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData ); |
| 52027 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| 52028 | sqlite3PagerUnref(pPage->pDbPage); |
| 52029 | } |
| 52030 | } |
| 52031 | |
| 52032 | /* |
| 52033 | ** During a rollback, when the pager reloads information into the cache |
| @@ -54762,14 +54539,14 @@ | |
| 54539 | } |
| 54540 | |
| 54541 | /* |
| 54542 | ** Return a pointer to payload information from the entry that the |
| 54543 | ** pCur cursor is pointing to. The pointer is to the beginning of |
| 54544 | ** the key if skipKey==0 and it points to the beginning of data if |
| 54545 | ** skipKey==1. The number of bytes of available key/data is written |
| 54546 | ** into *pAmt. If *pAmt==0, then the value returned will not be |
| 54547 | ** a valid pointer. |
| 54548 | ** |
| 54549 | ** This routine is an optimization. It is common for the entire key |
| 54550 | ** and data to fit on the local page and for there to be no overflow |
| 54551 | ** pages. When that is so, this routine can be used to access the |
| 54552 | ** key and data without making a copy. If the key and/or data spills |
| @@ -54778,25 +54555,45 @@ | |
| 54555 | ** |
| 54556 | ** The pointer returned by this routine looks directly into the cached |
| 54557 | ** page of the database. The data might change or move the next time |
| 54558 | ** any btree routine is called. |
| 54559 | */ |
| 54560 | static const unsigned char *fetchPayload( |
| 54561 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 54562 | u32 *pAmt, /* Write the number of available bytes here */ |
| 54563 | int skipKey /* read beginning at data if this is true */ |
| 54564 | ){ |
| 54565 | unsigned char *aPayload; |
| 54566 | MemPage *pPage; |
| 54567 | u32 nKey; |
| 54568 | u32 nLocal; |
| 54569 | |
| 54570 | assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]); |
| 54571 | assert( pCur->eState==CURSOR_VALID ); |
| 54572 | assert( cursorHoldsMutex(pCur) ); |
| 54573 | pPage = pCur->apPage[pCur->iPage]; |
| 54574 | assert( pCur->aiIdx[pCur->iPage]<pPage->nCell ); |
| 54575 | if( pCur->info.nSize==0 ){ |
| 54576 | btreeParseCell(pCur->apPage[pCur->iPage], pCur->aiIdx[pCur->iPage], |
| 54577 | &pCur->info); |
| 54578 | } |
| 54579 | aPayload = pCur->info.pCell; |
| 54580 | aPayload += pCur->info.nHeader; |
| 54581 | if( pPage->intKey ){ |
| 54582 | nKey = 0; |
| 54583 | }else{ |
| 54584 | nKey = (int)pCur->info.nKey; |
| 54585 | } |
| 54586 | if( skipKey ){ |
| 54587 | aPayload += nKey; |
| 54588 | nLocal = pCur->info.nLocal - nKey; |
| 54589 | }else{ |
| 54590 | nLocal = pCur->info.nLocal; |
| 54591 | assert( nLocal<=nKey ); |
| 54592 | } |
| 54593 | *pAmt = nLocal; |
| 54594 | return aPayload; |
| 54595 | } |
| 54596 | |
| 54597 | |
| 54598 | /* |
| 54599 | ** For the entry that cursor pCur is point to, return as |
| @@ -54811,14 +54608,26 @@ | |
| 54608 | ** |
| 54609 | ** These routines is used to get quick access to key and data |
| 54610 | ** in the common case where no overflow pages are used. |
| 54611 | */ |
| 54612 | SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){ |
| 54613 | const void *p = 0; |
| 54614 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 54615 | assert( cursorHoldsMutex(pCur) ); |
| 54616 | if( ALWAYS(pCur->eState==CURSOR_VALID) ){ |
| 54617 | p = (const void*)fetchPayload(pCur, pAmt, 0); |
| 54618 | } |
| 54619 | return p; |
| 54620 | } |
| 54621 | SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){ |
| 54622 | const void *p = 0; |
| 54623 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 54624 | assert( cursorHoldsMutex(pCur) ); |
| 54625 | if( ALWAYS(pCur->eState==CURSOR_VALID) ){ |
| 54626 | p = (const void*)fetchPayload(pCur, pAmt, 1); |
| 54627 | } |
| 54628 | return p; |
| 54629 | } |
| 54630 | |
| 54631 | |
| 54632 | /* |
| 54633 | ** Move the cursor down to a new child page. The newPgno argument is the |
| @@ -54933,10 +54742,12 @@ | |
| 54742 | ** b-tree). |
| 54743 | */ |
| 54744 | static int moveToRoot(BtCursor *pCur){ |
| 54745 | MemPage *pRoot; |
| 54746 | int rc = SQLITE_OK; |
| 54747 | Btree *p = pCur->pBtree; |
| 54748 | BtShared *pBt = p->pBt; |
| 54749 | |
| 54750 | assert( cursorHoldsMutex(pCur) ); |
| 54751 | assert( CURSOR_INVALID < CURSOR_REQUIRESEEK ); |
| 54752 | assert( CURSOR_VALID < CURSOR_REQUIRESEEK ); |
| 54753 | assert( CURSOR_FAULT > CURSOR_REQUIRESEEK ); |
| @@ -54947,16 +54758,20 @@ | |
| 54758 | } |
| 54759 | sqlite3BtreeClearCursor(pCur); |
| 54760 | } |
| 54761 | |
| 54762 | if( pCur->iPage>=0 ){ |
| 54763 | int i; |
| 54764 | for(i=1; i<=pCur->iPage; i++){ |
| 54765 | releasePage(pCur->apPage[i]); |
| 54766 | } |
| 54767 | pCur->iPage = 0; |
| 54768 | }else if( pCur->pgnoRoot==0 ){ |
| 54769 | pCur->eState = CURSOR_INVALID; |
| 54770 | return SQLITE_OK; |
| 54771 | }else{ |
| 54772 | rc = getAndInitPage(pBt, pCur->pgnoRoot, &pCur->apPage[0], |
| 54773 | pCur->wrFlag==0 ? PAGER_GET_READONLY : 0); |
| 54774 | if( rc!=SQLITE_OK ){ |
| 54775 | pCur->eState = CURSOR_INVALID; |
| 54776 | return rc; |
| 54777 | } |
| @@ -54985,20 +54800,18 @@ | |
| 54800 | pCur->aiIdx[0] = 0; |
| 54801 | pCur->info.nSize = 0; |
| 54802 | pCur->atLast = 0; |
| 54803 | pCur->validNKey = 0; |
| 54804 | |
| 54805 | if( pRoot->nCell==0 && !pRoot->leaf ){ |
| 54806 | Pgno subpage; |
| 54807 | if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT; |
| 54808 | subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]); |
| 54809 | pCur->eState = CURSOR_VALID; |
| 54810 | rc = moveToChild(pCur, subpage); |
| 54811 | }else{ |
| 54812 | pCur->eState = ((pRoot->nCell>0)?CURSOR_VALID:CURSOR_INVALID); |
| 54813 | } |
| 54814 | return rc; |
| 54815 | } |
| 54816 | |
| 54817 | /* |
| @@ -55250,18 +55063,21 @@ | |
| 55063 | ** the entire cell by checking for the cases where the record is |
| 55064 | ** stored entirely within the b-tree page by inspecting the first |
| 55065 | ** 2 bytes of the cell. |
| 55066 | */ |
| 55067 | nCell = pCell[0]; |
| 55068 | if( nCell<=pPage->max1bytePayload |
| 55069 | /* && (pCell+nCell)<pPage->aDataEnd */ |
| 55070 | ){ |
| 55071 | /* This branch runs if the record-size field of the cell is a |
| 55072 | ** single byte varint and the record fits entirely on the main |
| 55073 | ** b-tree page. */ |
| 55074 | testcase( pCell+nCell+1==pPage->aDataEnd ); |
| 55075 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[1], pIdxKey); |
| 55076 | }else if( !(pCell[1] & 0x80) |
| 55077 | && (nCell = ((nCell&0x7f)<<7) + pCell[1])<=pPage->maxLocal |
| 55078 | /* && (pCell+nCell+2)<=pPage->aDataEnd */ |
| 55079 | ){ |
| 55080 | /* The record-size field is a 2 byte varint and the record |
| 55081 | ** fits entirely on the main b-tree page. */ |
| 55082 | testcase( pCell+nCell+2==pPage->aDataEnd ); |
| 55083 | c = sqlite3VdbeRecordCompare(nCell, (void*)&pCell[2], pIdxKey); |
| @@ -56081,11 +55897,11 @@ | |
| 55897 | nHeader = 0; |
| 55898 | if( !pPage->leaf ){ |
| 55899 | nHeader += 4; |
| 55900 | } |
| 55901 | if( pPage->hasData ){ |
| 55902 | nHeader += putVarint(&pCell[nHeader], nData+nZero); |
| 55903 | }else{ |
| 55904 | nData = nZero = 0; |
| 55905 | } |
| 55906 | nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey); |
| 55907 | btreeParseCellPtr(pPage, pCell, &info); |
| @@ -56209,10 +56025,11 @@ | |
| 56025 | */ |
| 56026 | static void dropCell(MemPage *pPage, int idx, int sz, int *pRC){ |
| 56027 | u32 pc; /* Offset to cell content of cell being deleted */ |
| 56028 | u8 *data; /* pPage->aData */ |
| 56029 | u8 *ptr; /* Used to move bytes around within data[] */ |
| 56030 | u8 *endPtr; /* End of loop */ |
| 56031 | int rc; /* The return code */ |
| 56032 | int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */ |
| 56033 | |
| 56034 | if( *pRC ) return; |
| 56035 | |
| @@ -56232,13 +56049,18 @@ | |
| 56049 | } |
| 56050 | rc = freeSpace(pPage, pc, sz); |
| 56051 | if( rc ){ |
| 56052 | *pRC = rc; |
| 56053 | return; |
| 56054 | } |
| 56055 | endPtr = &pPage->aCellIdx[2*pPage->nCell - 2]; |
| 56056 | assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */ |
| 56057 | while( ptr<endPtr ){ |
| 56058 | *(u16*)ptr = *(u16*)&ptr[2]; |
| 56059 | ptr += 2; |
| 56060 | } |
| 56061 | pPage->nCell--; |
| 56062 | put2byte(&data[hdr+3], pPage->nCell); |
| 56063 | pPage->nFree += 2; |
| 56064 | } |
| 56065 | |
| 56066 | /* |
| @@ -56271,10 +56093,13 @@ | |
| 56093 | int j; /* Loop counter */ |
| 56094 | int end; /* First byte past the last cell pointer in data[] */ |
| 56095 | int ins; /* Index in data[] where new cell pointer is inserted */ |
| 56096 | int cellOffset; /* Address of first cell pointer in data[] */ |
| 56097 | u8 *data; /* The content of the whole page */ |
| 56098 | u8 *ptr; /* Used for moving information around in data[] */ |
| 56099 | u8 *endPtr; /* End of the loop */ |
| 56100 | |
| 56101 | int nSkip = (iChild ? 4 : 0); |
| 56102 | |
| 56103 | if( *pRC ) return; |
| 56104 | |
| 56105 | assert( i>=0 && i<=pPage->nCell+pPage->nOverflow ); |
| @@ -56321,11 +56146,17 @@ | |
| 56146 | pPage->nFree -= (u16)(2 + sz); |
| 56147 | memcpy(&data[idx+nSkip], pCell+nSkip, sz-nSkip); |
| 56148 | if( iChild ){ |
| 56149 | put4byte(&data[idx], iChild); |
| 56150 | } |
| 56151 | ptr = &data[end]; |
| 56152 | endPtr = &data[ins]; |
| 56153 | assert( (SQLITE_PTR_TO_INT(ptr)&1)==0 ); /* ptr is always 2-byte aligned */ |
| 56154 | while( ptr>endPtr ){ |
| 56155 | *(u16*)ptr = *(u16*)&ptr[-2]; |
| 56156 | ptr -= 2; |
| 56157 | } |
| 56158 | put2byte(&data[ins], idx); |
| 56159 | put2byte(&data[pPage->hdrOffset+3], pPage->nCell); |
| 56160 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 56161 | if( pPage->pBt->autoVacuum ){ |
| 56162 | /* The cell may contain a pointer to an overflow page. If so, write |
| @@ -58283,11 +58114,11 @@ | |
| 58114 | va_start(ap, zFormat); |
| 58115 | if( pCheck->errMsg.nChar ){ |
| 58116 | sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1); |
| 58117 | } |
| 58118 | if( zMsg1 ){ |
| 58119 | sqlite3StrAccumAppend(&pCheck->errMsg, zMsg1, -1); |
| 58120 | } |
| 58121 | sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); |
| 58122 | va_end(ap); |
| 58123 | if( pCheck->errMsg.accError==STRACCUM_NOMEM ){ |
| 58124 | pCheck->mallocFailed = 1; |
| @@ -59577,11 +59408,11 @@ | |
| 59408 | rc = backupTruncateFile(pFile, iSize); |
| 59409 | } |
| 59410 | |
| 59411 | /* Sync the database file to disk. */ |
| 59412 | if( rc==SQLITE_OK ){ |
| 59413 | rc = sqlite3PagerSync(pDestPager); |
| 59414 | } |
| 59415 | }else{ |
| 59416 | sqlite3PagerTruncateImage(pDestPager, nDestTruncate); |
| 59417 | rc = sqlite3PagerCommitPhaseOne(pDestPager, 0, 0); |
| 59418 | } |
| @@ -59652,14 +59483,14 @@ | |
| 59483 | /* If a transaction is still open on the Btree, roll it back. */ |
| 59484 | sqlite3BtreeRollback(p->pDest, SQLITE_OK); |
| 59485 | |
| 59486 | /* Set the error code of the destination database handle. */ |
| 59487 | rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc; |
| 59488 | sqlite3Error(p->pDestDb, rc, 0); |
| 59489 | |
| 59490 | /* Exit the mutexes and free the backup context structure. */ |
| 59491 | if( p->pDestDb ){ |
| 59492 | sqlite3LeaveMutexAndCloseZombie(p->pDestDb); |
| 59493 | } |
| 59494 | sqlite3BtreeLeave(p->pSrc); |
| 59495 | if( p->pDestDb ){ |
| 59496 | /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a |
| @@ -59859,59 +59690,61 @@ | |
| 59690 | #endif |
| 59691 | } |
| 59692 | |
| 59693 | /* |
| 59694 | ** Make sure pMem->z points to a writable allocation of at least |
| 59695 | ** n bytes. |
| 59696 | ** |
| 59697 | ** If the third argument passed to this function is true, then memory |
| 59698 | ** cell pMem must contain a string or blob. In this case the content is |
| 59699 | ** preserved. Otherwise, if the third parameter to this function is false, |
| 59700 | ** any current string or blob value may be discarded. |
| 59701 | ** |
| 59702 | ** This function sets the MEM_Dyn flag and clears any xDel callback. |
| 59703 | ** It also clears MEM_Ephem and MEM_Static. If the preserve flag is |
| 59704 | ** not set, Mem.n is zeroed. |
| 59705 | */ |
| 59706 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ |
| 59707 | assert( 1 >= |
| 59708 | ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + |
| 59709 | (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + |
| 59710 | ((pMem->flags&MEM_Ephem) ? 1 : 0) + |
| 59711 | ((pMem->flags&MEM_Static) ? 1 : 0) |
| 59712 | ); |
| 59713 | assert( (pMem->flags&MEM_RowSet)==0 ); |
| 59714 | |
| 59715 | /* If the preserve flag is set to true, then the memory cell must already |
| 59716 | ** contain a valid string or blob value. */ |
| 59717 | assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); |
| 59718 | |
| 59719 | if( n<32 ) n = 32; |
| 59720 | if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)<n ){ |
| 59721 | if( preserve && pMem->z==pMem->zMalloc ){ |
| 59722 | pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); |
| 59723 | preserve = 0; |
| 59724 | }else{ |
| 59725 | sqlite3DbFree(pMem->db, pMem->zMalloc); |
| 59726 | pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); |
| 59727 | } |
| 59728 | } |
| 59729 | |
| 59730 | if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){ |
| 59731 | memcpy(pMem->zMalloc, pMem->z, pMem->n); |
| 59732 | } |
| 59733 | if( pMem->flags&MEM_Dyn && pMem->xDel ){ |
| 59734 | assert( pMem->xDel!=SQLITE_DYNAMIC ); |
| 59735 | pMem->xDel((void *)(pMem->z)); |
| 59736 | } |
| 59737 | |
| 59738 | pMem->z = pMem->zMalloc; |
| 59739 | if( pMem->z==0 ){ |
| 59740 | pMem->flags = MEM_Null; |
| 59741 | }else{ |
| 59742 | pMem->flags &= ~(MEM_Ephem|MEM_Static); |
| 59743 | } |
| 59744 | pMem->xDel = 0; |
| 59745 | return (pMem->z ? SQLITE_OK : SQLITE_NOMEM); |
| 59746 | } |
| 59747 | |
| 59748 | /* |
| 59749 | ** Make the given Mem object MEM_Dyn. In other words, make it so |
| 59750 | ** that any TEXT or BLOB content is stored in memory obtained from |
| @@ -60093,16 +59926,14 @@ | |
| 59926 | ** inconsistent state, for example with (Mem.z==0) and |
| 59927 | ** (Mem.type==SQLITE_TEXT). |
| 59928 | */ |
| 59929 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){ |
| 59930 | VdbeMemRelease(p); |
| 59931 | sqlite3DbFree(p->db, p->zMalloc); |
| 59932 | p->z = 0; |
| 59933 | p->zMalloc = 0; |
| 59934 | p->xDel = 0; |
| 59935 | } |
| 59936 | |
| 59937 | /* |
| 59938 | ** Convert a 64-bit IEEE double into a 64-bit signed integer. |
| 59939 | ** If the double is out of range of a 64-bit signed integer then |
| @@ -60282,13 +60113,10 @@ | |
| 60113 | sqlite3RowSetClear(pMem->u.pRowSet); |
| 60114 | } |
| 60115 | MemSetTypeFlag(pMem, MEM_Null); |
| 60116 | pMem->type = SQLITE_NULL; |
| 60117 | } |
| 60118 | |
| 60119 | /* |
| 60120 | ** Delete any previous value and set the value to be a BLOB of length |
| 60121 | ** n containing all zeros. |
| 60122 | */ |
| @@ -61022,11 +60850,11 @@ | |
| 60850 | if( aRet==0 ){ |
| 60851 | sqlite3_result_error_nomem(context); |
| 60852 | }else{ |
| 60853 | aRet[0] = nSerial+1; |
| 60854 | sqlite3PutVarint(&aRet[1], iSerial); |
| 60855 | sqlite3VdbeSerialPut(&aRet[1+nSerial], nVal, argv[0], file_format); |
| 60856 | sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT); |
| 60857 | sqlite3DbFree(db, aRet); |
| 60858 | } |
| 60859 | } |
| 60860 | |
| @@ -61207,12 +61035,11 @@ | |
| 61035 | */ |
| 61036 | |
| 61037 | /* |
| 61038 | ** Create a new virtual database engine. |
| 61039 | */ |
| 61040 | SQLITE_PRIVATE Vdbe *sqlite3VdbeCreate(sqlite3 *db){ |
| 61041 | Vdbe *p; |
| 61042 | p = sqlite3DbMallocZero(db, sizeof(Vdbe) ); |
| 61043 | if( p==0 ) return 0; |
| 61044 | p->db = db; |
| 61045 | if( db->pVdbe ){ |
| @@ -61220,14 +61047,10 @@ | |
| 61047 | } |
| 61048 | p->pNext = db->pVdbe; |
| 61049 | p->pPrev = 0; |
| 61050 | db->pVdbe = p; |
| 61051 | p->magic = VDBE_MAGIC_INIT; |
| 61052 | return p; |
| 61053 | } |
| 61054 | |
| 61055 | /* |
| 61056 | ** Remember the SQL string for a prepared statement. |
| @@ -61279,18 +61102,17 @@ | |
| 61102 | ** If an out-of-memory error occurs while resizing the array, return |
| 61103 | ** SQLITE_NOMEM. In this case Vdbe.aOp and Vdbe.nOpAlloc remain |
| 61104 | ** unchanged (this is so that any opcodes already allocated can be |
| 61105 | ** correctly deallocated along with the rest of the Vdbe). |
| 61106 | */ |
| 61107 | static int growOpArray(Vdbe *p){ |
| 61108 | VdbeOp *pNew; |
| 61109 | int nNew = (p->nOpAlloc ? p->nOpAlloc*2 : (int)(1024/sizeof(Op))); |
| 61110 | pNew = sqlite3DbRealloc(p->db, p->aOp, nNew*sizeof(Op)); |
| 61111 | if( pNew ){ |
| 61112 | p->nOpAlloc = sqlite3DbMallocSize(p->db, pNew)/sizeof(Op); |
| 61113 | p->aOp = pNew; |
| 61114 | } |
| 61115 | return (pNew ? SQLITE_OK : SQLITE_NOMEM); |
| 61116 | } |
| 61117 | |
| 61118 | #ifdef SQLITE_DEBUG |
| @@ -61325,11 +61147,11 @@ | |
| 61147 | VdbeOp *pOp; |
| 61148 | |
| 61149 | i = p->nOp; |
| 61150 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61151 | assert( op>0 && op<0xff ); |
| 61152 | if( p->nOpAlloc<=i ){ |
| 61153 | if( growOpArray(p) ){ |
| 61154 | return 1; |
| 61155 | } |
| 61156 | } |
| 61157 | p->nOp++; |
| @@ -61344,19 +61166,10 @@ | |
| 61166 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 61167 | pOp->zComment = 0; |
| 61168 | #endif |
| 61169 | #ifdef SQLITE_DEBUG |
| 61170 | if( p->db->flags & SQLITE_VdbeAddopTrace ){ |
| 61171 | sqlite3VdbePrintOp(0, i, &p->aOp[i]); |
| 61172 | test_addop_breakpoint(); |
| 61173 | } |
| 61174 | #endif |
| 61175 | #ifdef VDBE_PROFILE |
| @@ -61436,14 +61249,13 @@ | |
| 61249 | ** always negative and P2 values are suppose to be non-negative. |
| 61250 | ** Hence, a negative P2 value is a label that has yet to be resolved. |
| 61251 | ** |
| 61252 | ** Zero is returned if a malloc() fails. |
| 61253 | */ |
| 61254 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe *p){ |
| 61255 | int i = p->nLabel++; |
| 61256 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61257 | if( (i & (i-1))==0 ){ |
| 61258 | p->aLabel = sqlite3DbReallocOrFree(p->db, p->aLabel, |
| 61259 | (i*2+1)*sizeof(p->aLabel[0])); |
| 61260 | } |
| 61261 | if( p->aLabel ){ |
| @@ -61455,17 +61267,16 @@ | |
| 61267 | /* |
| 61268 | ** Resolve label "x" to be the address of the next instruction to |
| 61269 | ** be inserted. The parameter "x" must have been obtained from |
| 61270 | ** a prior call to sqlite3VdbeMakeLabel(). |
| 61271 | */ |
| 61272 | SQLITE_PRIVATE void sqlite3VdbeResolveLabel(Vdbe *p, int x){ |
| 61273 | int j = -1-x; |
| 61274 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61275 | assert( j<p->nLabel ); |
| 61276 | if( j>=0 && p->aLabel ){ |
| 61277 | p->aLabel[j] = p->nOp; |
| 61278 | } |
| 61279 | } |
| 61280 | |
| 61281 | /* |
| 61282 | ** Mark the VDBE as one that can only be run one time. |
| @@ -61610,12 +61421,11 @@ | |
| 61421 | */ |
| 61422 | static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){ |
| 61423 | int i; |
| 61424 | int nMaxArgs = *pMaxFuncArgs; |
| 61425 | Op *pOp; |
| 61426 | int *aLabel = p->aLabel; |
| 61427 | p->readOnly = 1; |
| 61428 | p->bIsReader = 0; |
| 61429 | for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ |
| 61430 | u8 opcode = pOp->opcode; |
| 61431 | |
| @@ -61674,17 +61484,16 @@ | |
| 61484 | } |
| 61485 | } |
| 61486 | |
| 61487 | pOp->opflags = sqlite3OpcodeProperty[opcode]; |
| 61488 | if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){ |
| 61489 | assert( -1-pOp->p2<p->nLabel ); |
| 61490 | pOp->p2 = aLabel[-1-pOp->p2]; |
| 61491 | } |
| 61492 | } |
| 61493 | sqlite3DbFree(p->db, p->aLabel); |
| 61494 | p->aLabel = 0; |
| 61495 | *pMaxFuncArgs = nMaxArgs; |
| 61496 | assert( p->bIsReader!=0 || p->btreeMask==0 ); |
| 61497 | } |
| 61498 | |
| 61499 | /* |
| @@ -61724,11 +61533,11 @@ | |
| 61533 | ** address of the first operation added. |
| 61534 | */ |
| 61535 | SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){ |
| 61536 | int addr; |
| 61537 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 61538 | if( p->nOp + nOp > p->nOpAlloc && growOpArray(p) ){ |
| 61539 | return 0; |
| 61540 | } |
| 61541 | addr = p->nOp; |
| 61542 | if( ALWAYS(nOp>0) ){ |
| 61543 | int i; |
| @@ -61913,17 +61722,10 @@ | |
| 61722 | pOp->opcode = OP_Noop; |
| 61723 | if( addr==p->nOp-1 ) p->nOp--; |
| 61724 | } |
| 61725 | } |
| 61726 | |
| 61727 | /* |
| 61728 | ** Change the value of the P4 operand for a specific instruction. |
| 61729 | ** This routine is useful when a large program is loaded from a |
| 61730 | ** static array using sqlite3VdbeAddOpList but we want to make a |
| 61731 | ** few minor changes to the program. |
| @@ -62085,21 +61887,11 @@ | |
| 61887 | if( c=='4' ) return pOp->p4.i; |
| 61888 | return pOp->p5; |
| 61889 | } |
| 61890 | |
| 61891 | /* |
| 61892 | ** Compute a string for the "comment" field of a VDBE opcode listing |
| 61893 | */ |
| 61894 | static int displayComment( |
| 61895 | const Op *pOp, /* The opcode to be commented */ |
| 61896 | const char *zP4, /* Previously obtained value for P4 */ |
| 61897 | char *zTemp, /* Write result here */ |
| @@ -62129,17 +61921,11 @@ | |
| 61921 | sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1); |
| 61922 | if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){ |
| 61923 | ii += 3; |
| 61924 | jj += sqlite3Strlen30(zTemp+jj); |
| 61925 | v2 = translateP(zSynopsis[ii], pOp); |
| 61926 | if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1); |
| 61927 | }else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){ |
| 61928 | ii += 4; |
| 61929 | } |
| 61930 | } |
| 61931 | jj += sqlite3Strlen30(zTemp+jj); |
| @@ -62367,13 +62153,10 @@ | |
| 62153 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 62154 | displayComment(pOp, zP4, zCom, sizeof(zCom)); |
| 62155 | #else |
| 62156 | zCom[0] = 0 |
| 62157 | #endif |
| 62158 | fprintf(pOut, zFormat1, pc, |
| 62159 | sqlite3OpcodeName(pOp->opcode), pOp->p1, pOp->p2, pOp->p3, zP4, pOp->p5, |
| 62160 | zCom |
| 62161 | ); |
| 62162 | fflush(pOut); |
| @@ -62801,11 +62584,10 @@ | |
| 62584 | |
| 62585 | assert( p!=0 ); |
| 62586 | assert( p->nOp>0 ); |
| 62587 | assert( pParse!=0 ); |
| 62588 | assert( p->magic==VDBE_MAGIC_INIT ); |
| 62589 | db = p->db; |
| 62590 | assert( db->mallocFailed==0 ); |
| 62591 | nVar = pParse->nVar; |
| 62592 | nMem = pParse->nMem; |
| 62593 | nCursor = pParse->nTab; |
| @@ -62825,12 +62607,12 @@ | |
| 62607 | nMem += nCursor; |
| 62608 | |
| 62609 | /* Allocate space for memory registers, SQL variables, VDBE cursors and |
| 62610 | ** an array to marshal SQL function arguments in. |
| 62611 | */ |
| 62612 | zCsr = (u8*)&p->aOp[p->nOp]; /* Memory avaliable for allocation */ |
| 62613 | zEnd = (u8*)&p->aOp[p->nOpAlloc]; /* First byte past end of zCsr[] */ |
| 62614 | |
| 62615 | resolveP2Values(p, &nArg); |
| 62616 | p->usesStmtJournal = (u8)(pParse->isMultiWrite && pParse->mayAbort); |
| 62617 | if( pParse->explain && nMem<10 ){ |
| 62618 | nMem = 10; |
| @@ -63653,11 +63435,10 @@ | |
| 63435 | sqlite3 *db = p->db; |
| 63436 | int rc = p->rc; |
| 63437 | if( p->zErrMsg ){ |
| 63438 | u8 mallocFailed = db->mallocFailed; |
| 63439 | sqlite3BeginBenignMalloc(); |
| 63440 | sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63441 | sqlite3EndBenignMalloc(); |
| 63442 | db->mallocFailed = mallocFailed; |
| 63443 | db->errCode = rc; |
| 63444 | }else{ |
| @@ -63722,11 +63503,12 @@ | |
| 63503 | }else if( p->rc && p->expired ){ |
| 63504 | /* The expired flag was set on the VDBE before the first call |
| 63505 | ** to sqlite3_step(). For consistency (since sqlite3_step() was |
| 63506 | ** called), set the database error in this case as well. |
| 63507 | */ |
| 63508 | sqlite3Error(db, p->rc, 0); |
| 63509 | sqlite3ValueSetStr(db->pErr, -1, p->zErrMsg, SQLITE_UTF8, SQLITE_TRANSIENT); |
| 63510 | sqlite3DbFree(db, p->zErrMsg); |
| 63511 | p->zErrMsg = 0; |
| 63512 | } |
| 63513 | |
| 63514 | /* Reclaim all memory used by the VDBE |
| @@ -63829,10 +63611,11 @@ | |
| 63611 | vdbeFreeOpArray(db, pSub->aOp, pSub->nOp); |
| 63612 | sqlite3DbFree(db, pSub); |
| 63613 | } |
| 63614 | for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]); |
| 63615 | vdbeFreeOpArray(db, p->aOp, p->nOp); |
| 63616 | sqlite3DbFree(db, p->aLabel); |
| 63617 | sqlite3DbFree(db, p->aColName); |
| 63618 | sqlite3DbFree(db, p->zSql); |
| 63619 | sqlite3DbFree(db, p->pFree); |
| 63620 | #if defined(SQLITE_ENABLE_TREE_EXPLAIN) |
| 63621 | sqlite3DbFree(db, p->zExplain); |
| @@ -64059,19 +63842,25 @@ | |
| 63842 | /* |
| 63843 | ** Write the serialized data blob for the value stored in pMem into |
| 63844 | ** buf. It is assumed that the caller has allocated sufficient space. |
| 63845 | ** Return the number of bytes written. |
| 63846 | ** |
| 63847 | ** nBuf is the amount of space left in buf[]. nBuf must always be |
| 63848 | ** large enough to hold the entire field. Except, if the field is |
| 63849 | ** a blob with a zero-filled tail, then buf[] might be just the right |
| 63850 | ** size to hold everything except for the zero-filled tail. If buf[] |
| 63851 | ** is only big enough to hold the non-zero prefix, then only write that |
| 63852 | ** prefix into buf[]. But if buf[] is large enough to hold both the |
| 63853 | ** prefix and the tail then write the prefix and set the tail to all |
| 63854 | ** zeros. |
| 63855 | ** |
| 63856 | ** Return the number of bytes actually written into buf[]. The number |
| 63857 | ** of bytes in the zero-filled tail is included in the return value only |
| 63858 | ** if those bytes were zeroed in buf[]. |
| 63859 | */ |
| 63860 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(u8 *buf, int nBuf, Mem *pMem, int file_format){ |
| 63861 | u32 serial_type = sqlite3VdbeSerialType(pMem, file_format); |
| 63862 | u32 len; |
| 63863 | |
| 63864 | /* Integer and Real */ |
| 63865 | if( serial_type<=7 && serial_type>0 ){ |
| 63866 | u64 v; |
| @@ -64082,10 +63871,11 @@ | |
| 63871 | swapMixedEndianFloat(v); |
| 63872 | }else{ |
| 63873 | v = pMem->u.i; |
| 63874 | } |
| 63875 | len = i = sqlite3VdbeSerialTypeLen(serial_type); |
| 63876 | assert( len<=(u32)nBuf ); |
| 63877 | while( i-- ){ |
| 63878 | buf[i] = (u8)(v&0xFF); |
| 63879 | v >>= 8; |
| 63880 | } |
| 63881 | return len; |
| @@ -64093,12 +63883,21 @@ | |
| 63883 | |
| 63884 | /* String or blob */ |
| 63885 | if( serial_type>=12 ){ |
| 63886 | assert( pMem->n + ((pMem->flags & MEM_Zero)?pMem->u.nZero:0) |
| 63887 | == (int)sqlite3VdbeSerialTypeLen(serial_type) ); |
| 63888 | assert( pMem->n<=nBuf ); |
| 63889 | len = pMem->n; |
| 63890 | memcpy(buf, pMem->z, len); |
| 63891 | if( pMem->flags & MEM_Zero ){ |
| 63892 | len += pMem->u.nZero; |
| 63893 | assert( nBuf>=0 ); |
| 63894 | if( len > (u32)nBuf ){ |
| 63895 | len = (u32)nBuf; |
| 63896 | } |
| 63897 | memset(&buf[pMem->n], 0, len-pMem->n); |
| 63898 | } |
| 63899 | return len; |
| 63900 | } |
| 63901 | |
| 63902 | /* NULL or constants 0 or 1 */ |
| 63903 | return 0; |
| @@ -65095,21 +64894,20 @@ | |
| 64894 | && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){ |
| 64895 | sqlite3_reset(pStmt); |
| 64896 | v->doingRerun = 1; |
| 64897 | assert( v->expired==0 ); |
| 64898 | } |
| 64899 | if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){ |
| 64900 | /* This case occurs after failing to recompile an sql statement. |
| 64901 | ** The error message from the SQL compiler has already been loaded |
| 64902 | ** into the database handle. This block copies the error message |
| 64903 | ** from the database handle into the statement and sets the statement |
| 64904 | ** program counter to 0 to ensure that when the statement is |
| 64905 | ** finalized or reset the parser error message is available via |
| 64906 | ** sqlite3_errmsg() and sqlite3_errcode(). |
| 64907 | */ |
| 64908 | const char *zErr = (const char *)sqlite3_value_text(db->pErr); |
| 64909 | sqlite3DbFree(db, v->zErrMsg); |
| 64910 | if( !db->mallocFailed ){ |
| 64911 | v->zErrMsg = sqlite3DbStrDup(db, zErr); |
| 64912 | v->rc = rc2; |
| 64913 | } else { |
| @@ -66021,11 +65819,10 @@ | |
| 65819 | if( db->nVdbeExec>1 ){ |
| 65820 | while( *zRawSql ){ |
| 65821 | const char *zStart = zRawSql; |
| 65822 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 65823 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 65824 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| 65825 | } |
| 65826 | }else{ |
| 65827 | while( zRawSql[0] ){ |
| 65828 | n = findNextHostParameter(zRawSql, &nToken); |
| @@ -66054,13 +65851,13 @@ | |
| 65851 | assert( idx>0 && idx<=p->nVar ); |
| 65852 | pVar = &p->aVar[idx-1]; |
| 65853 | if( pVar->flags & MEM_Null ){ |
| 65854 | sqlite3StrAccumAppend(&out, "NULL", 4); |
| 65855 | }else if( pVar->flags & MEM_Int ){ |
| 65856 | sqlite3XPrintf(&out, "%lld", pVar->u.i); |
| 65857 | }else if( pVar->flags & MEM_Real ){ |
| 65858 | sqlite3XPrintf(&out, "%!.15g", pVar->r); |
| 65859 | }else if( pVar->flags & MEM_Str ){ |
| 65860 | int nOut; /* Number of bytes of the string text to include in output */ |
| 65861 | #ifndef SQLITE_OMIT_UTF16 |
| 65862 | u8 enc = ENC(db); |
| 65863 | Mem utf8; |
| @@ -66077,37 +65874,33 @@ | |
| 65874 | if( nOut>SQLITE_TRACE_SIZE_LIMIT ){ |
| 65875 | nOut = SQLITE_TRACE_SIZE_LIMIT; |
| 65876 | while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; } |
| 65877 | } |
| 65878 | #endif |
| 65879 | sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z); |
| 65880 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 65881 | if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut); |
| 65882 | #endif |
| 65883 | #ifndef SQLITE_OMIT_UTF16 |
| 65884 | if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8); |
| 65885 | #endif |
| 65886 | }else if( pVar->flags & MEM_Zero ){ |
| 65887 | sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero); |
| 65888 | }else{ |
| 65889 | int nOut; /* Number of bytes of the blob to include in output */ |
| 65890 | assert( pVar->flags & MEM_Blob ); |
| 65891 | sqlite3StrAccumAppend(&out, "x'", 2); |
| 65892 | nOut = pVar->n; |
| 65893 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 65894 | if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT; |
| 65895 | #endif |
| 65896 | for(i=0; i<nOut; i++){ |
| 65897 | sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff); |
| 65898 | } |
| 65899 | sqlite3StrAccumAppend(&out, "'", 1); |
| 65900 | #ifdef SQLITE_TRACE_SIZE_LIMIT |
| 65901 | if( nOut<pVar->n ) sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut); |
| 65902 | #endif |
| 65903 | } |
| 65904 | } |
| 65905 | } |
| 65906 | return sqlite3StrAccumFinish(&out); |
| @@ -66162,11 +65955,11 @@ | |
| 65955 | int n = p->nIndent; |
| 65956 | if( n>ArraySize(p->aIndent) ) n = ArraySize(p->aIndent); |
| 65957 | sqlite3AppendSpace(&p->str, p->aIndent[n-1]); |
| 65958 | } |
| 65959 | va_start(ap, zFormat); |
| 65960 | sqlite3VXPrintf(&p->str, 1, zFormat, ap); |
| 65961 | va_end(ap); |
| 65962 | } |
| 65963 | } |
| 65964 | |
| 65965 | /* |
| @@ -66869,11 +66662,433 @@ | |
| 66662 | i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */ |
| 66663 | #ifdef VDBE_PROFILE |
| 66664 | u64 start; /* CPU clock count at start of opcode */ |
| 66665 | int origPc; /* Program counter at start of opcode */ |
| 66666 | #endif |
| 66667 | /******************************************************************** |
| 66668 | ** Automatically generated code |
| 66669 | ** |
| 66670 | ** The following union is automatically generated by the |
| 66671 | ** vdbe-compress.tcl script. The purpose of this union is to |
| 66672 | ** reduce the amount of stack space required by this function. |
| 66673 | ** See comments in the vdbe-compress.tcl script for details. |
| 66674 | */ |
| 66675 | union vdbeExecUnion { |
| 66676 | struct OP_Yield_stack_vars { |
| 66677 | int pcDest; |
| 66678 | } aa; |
| 66679 | struct OP_Halt_stack_vars { |
| 66680 | const char *zType; |
| 66681 | const char *zLogFmt; |
| 66682 | } ab; |
| 66683 | struct OP_Null_stack_vars { |
| 66684 | int cnt; |
| 66685 | u16 nullFlag; |
| 66686 | } ac; |
| 66687 | struct OP_Variable_stack_vars { |
| 66688 | Mem *pVar; /* Value being transferred */ |
| 66689 | } ad; |
| 66690 | struct OP_Move_stack_vars { |
| 66691 | char *zMalloc; /* Holding variable for allocated memory */ |
| 66692 | int n; /* Number of registers left to copy */ |
| 66693 | int p1; /* Register to copy from */ |
| 66694 | int p2; /* Register to copy to */ |
| 66695 | } ae; |
| 66696 | struct OP_Copy_stack_vars { |
| 66697 | int n; |
| 66698 | } af; |
| 66699 | struct OP_ResultRow_stack_vars { |
| 66700 | Mem *pMem; |
| 66701 | int i; |
| 66702 | } ag; |
| 66703 | struct OP_Concat_stack_vars { |
| 66704 | i64 nByte; |
| 66705 | } ah; |
| 66706 | struct OP_Remainder_stack_vars { |
| 66707 | char bIntint; /* Started out as two integer operands */ |
| 66708 | int flags; /* Combined MEM_* flags from both inputs */ |
| 66709 | i64 iA; /* Integer value of left operand */ |
| 66710 | i64 iB; /* Integer value of right operand */ |
| 66711 | double rA; /* Real value of left operand */ |
| 66712 | double rB; /* Real value of right operand */ |
| 66713 | } ai; |
| 66714 | struct OP_Function_stack_vars { |
| 66715 | int i; |
| 66716 | Mem *pArg; |
| 66717 | sqlite3_context ctx; |
| 66718 | sqlite3_value **apVal; |
| 66719 | int n; |
| 66720 | } aj; |
| 66721 | struct OP_ShiftRight_stack_vars { |
| 66722 | i64 iA; |
| 66723 | u64 uA; |
| 66724 | i64 iB; |
| 66725 | u8 op; |
| 66726 | } ak; |
| 66727 | struct OP_Ge_stack_vars { |
| 66728 | int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 66729 | char affinity; /* Affinity to use for comparison */ |
| 66730 | u16 flags1; /* Copy of initial value of pIn1->flags */ |
| 66731 | u16 flags3; /* Copy of initial value of pIn3->flags */ |
| 66732 | } al; |
| 66733 | struct OP_Compare_stack_vars { |
| 66734 | int n; |
| 66735 | int i; |
| 66736 | int p1; |
| 66737 | int p2; |
| 66738 | const KeyInfo *pKeyInfo; |
| 66739 | int idx; |
| 66740 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 66741 | int bRev; /* True for DESCENDING sort order */ |
| 66742 | } am; |
| 66743 | struct OP_Or_stack_vars { |
| 66744 | int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 66745 | int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 66746 | } an; |
| 66747 | struct OP_IfNot_stack_vars { |
| 66748 | int c; |
| 66749 | } ao; |
| 66750 | struct OP_Column_stack_vars { |
| 66751 | i64 payloadSize64; /* Number of bytes in the record */ |
| 66752 | int p2; /* column number to retrieve */ |
| 66753 | VdbeCursor *pC; /* The VDBE cursor */ |
| 66754 | BtCursor *pCrsr; /* The BTree cursor */ |
| 66755 | u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| 66756 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 66757 | int len; /* The length of the serialized data for the column */ |
| 66758 | int i; /* Loop counter */ |
| 66759 | Mem *pDest; /* Where to write the extracted value */ |
| 66760 | Mem sMem; /* For storing the record being decoded */ |
| 66761 | const u8 *zData; /* Part of the record being decoded */ |
| 66762 | const u8 *zHdr; /* Next unparsed byte of the header */ |
| 66763 | const u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 66764 | u32 offset; /* Offset into the data */ |
| 66765 | u32 szField; /* Number of bytes in the content of a field */ |
| 66766 | u32 avail; /* Number of bytes of available data */ |
| 66767 | u32 t; /* A type code from the record header */ |
| 66768 | Mem *pReg; /* PseudoTable input register */ |
| 66769 | } ap; |
| 66770 | struct OP_Affinity_stack_vars { |
| 66771 | const char *zAffinity; /* The affinity to be applied */ |
| 66772 | char cAff; /* A single character of affinity */ |
| 66773 | } aq; |
| 66774 | struct OP_MakeRecord_stack_vars { |
| 66775 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 66776 | Mem *pRec; /* The new record */ |
| 66777 | u64 nData; /* Number of bytes of data space */ |
| 66778 | int nHdr; /* Number of bytes of header space */ |
| 66779 | i64 nByte; /* Data space required for this record */ |
| 66780 | int nZero; /* Number of zero bytes at the end of the record */ |
| 66781 | int nVarint; /* Number of bytes in a varint */ |
| 66782 | u32 serial_type; /* Type field */ |
| 66783 | Mem *pData0; /* First field to be combined into the record */ |
| 66784 | Mem *pLast; /* Last field of the record */ |
| 66785 | int nField; /* Number of fields in the record */ |
| 66786 | char *zAffinity; /* The affinity string for the record */ |
| 66787 | int file_format; /* File format to use for encoding */ |
| 66788 | int i; /* Space used in zNewRecord[] */ |
| 66789 | int len; /* Length of a field */ |
| 66790 | } ar; |
| 66791 | struct OP_Count_stack_vars { |
| 66792 | i64 nEntry; |
| 66793 | BtCursor *pCrsr; |
| 66794 | } as; |
| 66795 | struct OP_Savepoint_stack_vars { |
| 66796 | int p1; /* Value of P1 operand */ |
| 66797 | char *zName; /* Name of savepoint */ |
| 66798 | int nName; |
| 66799 | Savepoint *pNew; |
| 66800 | Savepoint *pSavepoint; |
| 66801 | Savepoint *pTmp; |
| 66802 | int iSavepoint; |
| 66803 | int ii; |
| 66804 | } at; |
| 66805 | struct OP_AutoCommit_stack_vars { |
| 66806 | int desiredAutoCommit; |
| 66807 | int iRollback; |
| 66808 | int turnOnAC; |
| 66809 | } au; |
| 66810 | struct OP_Transaction_stack_vars { |
| 66811 | Btree *pBt; |
| 66812 | } av; |
| 66813 | struct OP_ReadCookie_stack_vars { |
| 66814 | int iMeta; |
| 66815 | int iDb; |
| 66816 | int iCookie; |
| 66817 | } aw; |
| 66818 | struct OP_SetCookie_stack_vars { |
| 66819 | Db *pDb; |
| 66820 | } ax; |
| 66821 | struct OP_VerifyCookie_stack_vars { |
| 66822 | int iMeta; |
| 66823 | int iGen; |
| 66824 | Btree *pBt; |
| 66825 | } ay; |
| 66826 | struct OP_OpenWrite_stack_vars { |
| 66827 | int nField; |
| 66828 | KeyInfo *pKeyInfo; |
| 66829 | int p2; |
| 66830 | int iDb; |
| 66831 | int wrFlag; |
| 66832 | Btree *pX; |
| 66833 | VdbeCursor *pCur; |
| 66834 | Db *pDb; |
| 66835 | } az; |
| 66836 | struct OP_OpenEphemeral_stack_vars { |
| 66837 | VdbeCursor *pCx; |
| 66838 | KeyInfo *pKeyInfo; |
| 66839 | } ba; |
| 66840 | struct OP_SorterOpen_stack_vars { |
| 66841 | VdbeCursor *pCx; |
| 66842 | } bb; |
| 66843 | struct OP_OpenPseudo_stack_vars { |
| 66844 | VdbeCursor *pCx; |
| 66845 | } bc; |
| 66846 | struct OP_SeekGt_stack_vars { |
| 66847 | int res; |
| 66848 | int oc; |
| 66849 | VdbeCursor *pC; |
| 66850 | UnpackedRecord r; |
| 66851 | int nField; |
| 66852 | i64 iKey; /* The rowid we are to seek to */ |
| 66853 | } bd; |
| 66854 | struct OP_Seek_stack_vars { |
| 66855 | VdbeCursor *pC; |
| 66856 | } be; |
| 66857 | struct OP_Found_stack_vars { |
| 66858 | int alreadyExists; |
| 66859 | int ii; |
| 66860 | VdbeCursor *pC; |
| 66861 | int res; |
| 66862 | char *pFree; |
| 66863 | UnpackedRecord *pIdxKey; |
| 66864 | UnpackedRecord r; |
| 66865 | char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; |
| 66866 | } bf; |
| 66867 | struct OP_NotExists_stack_vars { |
| 66868 | VdbeCursor *pC; |
| 66869 | BtCursor *pCrsr; |
| 66870 | int res; |
| 66871 | u64 iKey; |
| 66872 | } bg; |
| 66873 | struct OP_NewRowid_stack_vars { |
| 66874 | i64 v; /* The new rowid */ |
| 66875 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 66876 | int res; /* Result of an sqlite3BtreeLast() */ |
| 66877 | int cnt; /* Counter to limit the number of searches */ |
| 66878 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 66879 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 66880 | } bh; |
| 66881 | struct OP_InsertInt_stack_vars { |
| 66882 | Mem *pData; /* MEM cell holding data for the record to be inserted */ |
| 66883 | Mem *pKey; /* MEM cell holding key for the record */ |
| 66884 | i64 iKey; /* The integer ROWID or key for the record to be inserted */ |
| 66885 | VdbeCursor *pC; /* Cursor to table into which insert is written */ |
| 66886 | int nZero; /* Number of zero-bytes to append */ |
| 66887 | int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ |
| 66888 | const char *zDb; /* database name - used by the update hook */ |
| 66889 | const char *zTbl; /* Table name - used by the opdate hook */ |
| 66890 | int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ |
| 66891 | } bi; |
| 66892 | struct OP_Delete_stack_vars { |
| 66893 | i64 iKey; |
| 66894 | VdbeCursor *pC; |
| 66895 | } bj; |
| 66896 | struct OP_SorterCompare_stack_vars { |
| 66897 | VdbeCursor *pC; |
| 66898 | int res; |
| 66899 | int nIgnore; |
| 66900 | } bk; |
| 66901 | struct OP_SorterData_stack_vars { |
| 66902 | VdbeCursor *pC; |
| 66903 | } bl; |
| 66904 | struct OP_RowData_stack_vars { |
| 66905 | VdbeCursor *pC; |
| 66906 | BtCursor *pCrsr; |
| 66907 | u32 n; |
| 66908 | i64 n64; |
| 66909 | } bm; |
| 66910 | struct OP_Rowid_stack_vars { |
| 66911 | VdbeCursor *pC; |
| 66912 | i64 v; |
| 66913 | sqlite3_vtab *pVtab; |
| 66914 | const sqlite3_module *pModule; |
| 66915 | } bn; |
| 66916 | struct OP_NullRow_stack_vars { |
| 66917 | VdbeCursor *pC; |
| 66918 | } bo; |
| 66919 | struct OP_Last_stack_vars { |
| 66920 | VdbeCursor *pC; |
| 66921 | BtCursor *pCrsr; |
| 66922 | int res; |
| 66923 | } bp; |
| 66924 | struct OP_Rewind_stack_vars { |
| 66925 | VdbeCursor *pC; |
| 66926 | BtCursor *pCrsr; |
| 66927 | int res; |
| 66928 | } bq; |
| 66929 | struct OP_SorterNext_stack_vars { |
| 66930 | VdbeCursor *pC; |
| 66931 | int res; |
| 66932 | } br; |
| 66933 | struct OP_IdxInsert_stack_vars { |
| 66934 | VdbeCursor *pC; |
| 66935 | BtCursor *pCrsr; |
| 66936 | int nKey; |
| 66937 | const char *zKey; |
| 66938 | } bs; |
| 66939 | struct OP_IdxDelete_stack_vars { |
| 66940 | VdbeCursor *pC; |
| 66941 | BtCursor *pCrsr; |
| 66942 | int res; |
| 66943 | UnpackedRecord r; |
| 66944 | } bt; |
| 66945 | struct OP_IdxRowid_stack_vars { |
| 66946 | BtCursor *pCrsr; |
| 66947 | VdbeCursor *pC; |
| 66948 | i64 rowid; |
| 66949 | } bu; |
| 66950 | struct OP_IdxGE_stack_vars { |
| 66951 | VdbeCursor *pC; |
| 66952 | int res; |
| 66953 | UnpackedRecord r; |
| 66954 | } bv; |
| 66955 | struct OP_Destroy_stack_vars { |
| 66956 | int iMoved; |
| 66957 | int iCnt; |
| 66958 | Vdbe *pVdbe; |
| 66959 | int iDb; |
| 66960 | } bw; |
| 66961 | struct OP_Clear_stack_vars { |
| 66962 | int nChange; |
| 66963 | } bx; |
| 66964 | struct OP_CreateTable_stack_vars { |
| 66965 | int pgno; |
| 66966 | int flags; |
| 66967 | Db *pDb; |
| 66968 | } by; |
| 66969 | struct OP_ParseSchema_stack_vars { |
| 66970 | int iDb; |
| 66971 | const char *zMaster; |
| 66972 | char *zSql; |
| 66973 | InitData initData; |
| 66974 | } bz; |
| 66975 | struct OP_IntegrityCk_stack_vars { |
| 66976 | int nRoot; /* Number of tables to check. (Number of root pages.) */ |
| 66977 | int *aRoot; /* Array of rootpage numbers for tables to be checked */ |
| 66978 | int j; /* Loop counter */ |
| 66979 | int nErr; /* Number of errors reported */ |
| 66980 | char *z; /* Text of the error report */ |
| 66981 | Mem *pnErr; /* Register keeping track of errors remaining */ |
| 66982 | } ca; |
| 66983 | struct OP_RowSetRead_stack_vars { |
| 66984 | i64 val; |
| 66985 | } cb; |
| 66986 | struct OP_RowSetTest_stack_vars { |
| 66987 | int iSet; |
| 66988 | int exists; |
| 66989 | } cc; |
| 66990 | struct OP_Program_stack_vars { |
| 66991 | int nMem; /* Number of memory registers for sub-program */ |
| 66992 | int nByte; /* Bytes of runtime space required for sub-program */ |
| 66993 | Mem *pRt; /* Register to allocate runtime space */ |
| 66994 | Mem *pMem; /* Used to iterate through memory cells */ |
| 66995 | Mem *pEnd; /* Last memory cell in new array */ |
| 66996 | VdbeFrame *pFrame; /* New vdbe frame to execute in */ |
| 66997 | SubProgram *pProgram; /* Sub-program to execute */ |
| 66998 | void *t; /* Token identifying trigger */ |
| 66999 | } cd; |
| 67000 | struct OP_Param_stack_vars { |
| 67001 | VdbeFrame *pFrame; |
| 67002 | Mem *pIn; |
| 67003 | } ce; |
| 67004 | struct OP_MemMax_stack_vars { |
| 67005 | Mem *pIn1; |
| 67006 | VdbeFrame *pFrame; |
| 67007 | } cf; |
| 67008 | struct OP_AggStep_stack_vars { |
| 67009 | int n; |
| 67010 | int i; |
| 67011 | Mem *pMem; |
| 67012 | Mem *pRec; |
| 67013 | sqlite3_context ctx; |
| 67014 | sqlite3_value **apVal; |
| 67015 | } cg; |
| 67016 | struct OP_AggFinal_stack_vars { |
| 67017 | Mem *pMem; |
| 67018 | } ch; |
| 67019 | struct OP_Checkpoint_stack_vars { |
| 67020 | int i; /* Loop counter */ |
| 67021 | int aRes[3]; /* Results */ |
| 67022 | Mem *pMem; /* Write results here */ |
| 67023 | } ci; |
| 67024 | struct OP_JournalMode_stack_vars { |
| 67025 | Btree *pBt; /* Btree to change journal mode of */ |
| 67026 | Pager *pPager; /* Pager associated with pBt */ |
| 67027 | int eNew; /* New journal mode */ |
| 67028 | int eOld; /* The old journal mode */ |
| 67029 | #ifndef SQLITE_OMIT_WAL |
| 67030 | const char *zFilename; /* Name of database file for pPager */ |
| 67031 | #endif |
| 67032 | } cj; |
| 67033 | struct OP_IncrVacuum_stack_vars { |
| 67034 | Btree *pBt; |
| 67035 | } ck; |
| 67036 | struct OP_VBegin_stack_vars { |
| 67037 | VTable *pVTab; |
| 67038 | } cl; |
| 67039 | struct OP_VOpen_stack_vars { |
| 67040 | VdbeCursor *pCur; |
| 67041 | sqlite3_vtab_cursor *pVtabCursor; |
| 67042 | sqlite3_vtab *pVtab; |
| 67043 | sqlite3_module *pModule; |
| 67044 | } cm; |
| 67045 | struct OP_VFilter_stack_vars { |
| 67046 | int nArg; |
| 67047 | int iQuery; |
| 67048 | const sqlite3_module *pModule; |
| 67049 | Mem *pQuery; |
| 67050 | Mem *pArgc; |
| 67051 | sqlite3_vtab_cursor *pVtabCursor; |
| 67052 | sqlite3_vtab *pVtab; |
| 67053 | VdbeCursor *pCur; |
| 67054 | int res; |
| 67055 | int i; |
| 67056 | Mem **apArg; |
| 67057 | } cn; |
| 67058 | struct OP_VColumn_stack_vars { |
| 67059 | sqlite3_vtab *pVtab; |
| 67060 | const sqlite3_module *pModule; |
| 67061 | Mem *pDest; |
| 67062 | sqlite3_context sContext; |
| 67063 | } co; |
| 67064 | struct OP_VNext_stack_vars { |
| 67065 | sqlite3_vtab *pVtab; |
| 67066 | const sqlite3_module *pModule; |
| 67067 | int res; |
| 67068 | VdbeCursor *pCur; |
| 67069 | } cp; |
| 67070 | struct OP_VRename_stack_vars { |
| 67071 | sqlite3_vtab *pVtab; |
| 67072 | Mem *pName; |
| 67073 | } cq; |
| 67074 | struct OP_VUpdate_stack_vars { |
| 67075 | sqlite3_vtab *pVtab; |
| 67076 | sqlite3_module *pModule; |
| 67077 | int nArg; |
| 67078 | int i; |
| 67079 | sqlite_int64 rowid; |
| 67080 | Mem **apArg; |
| 67081 | Mem *pX; |
| 67082 | } cr; |
| 67083 | struct OP_Trace_stack_vars { |
| 67084 | char *zTrace; |
| 67085 | char *z; |
| 67086 | } cs; |
| 67087 | } u; |
| 67088 | /* End automatically generated code |
| 67089 | ********************************************************************/ |
| 67090 | |
| 67091 | assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */ |
| 67092 | sqlite3VdbeEnter(p); |
| 67093 | if( p->rc==SQLITE_NOMEM ){ |
| 67094 | /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| @@ -67115,18 +67330,20 @@ | |
| 67330 | /* Opcode: Yield P1 * * * * |
| 67331 | ** |
| 67332 | ** Swap the program counter with the value in register P1. |
| 67333 | */ |
| 67334 | case OP_Yield: { /* in1 */ |
| 67335 | #if 0 /* local variables moved into u.aa */ |
| 67336 | int pcDest; |
| 67337 | #endif /* local variables moved into u.aa */ |
| 67338 | pIn1 = &aMem[pOp->p1]; |
| 67339 | assert( (pIn1->flags & MEM_Dyn)==0 ); |
| 67340 | pIn1->flags = MEM_Int; |
| 67341 | u.aa.pcDest = (int)pIn1->u.i; |
| 67342 | pIn1->u.i = pc; |
| 67343 | REGISTER_TRACE(pOp->p1, pIn1); |
| 67344 | pc = u.aa.pcDest; |
| 67345 | break; |
| 67346 | } |
| 67347 | |
| 67348 | /* Opcode: HaltIfNull P1 P2 P3 P4 P5 |
| 67349 | ** Synopsis: if r[P3] null then halt |
| @@ -67171,12 +67388,14 @@ | |
| 67388 | ** There is an implied "Halt 0 0 0" instruction inserted at the very end of |
| 67389 | ** every program. So a jump past the last instruction of the program |
| 67390 | ** is the same as executing Halt. |
| 67391 | */ |
| 67392 | case OP_Halt: { |
| 67393 | #if 0 /* local variables moved into u.ab */ |
| 67394 | const char *zType; |
| 67395 | const char *zLogFmt; |
| 67396 | #endif /* local variables moved into u.ab */ |
| 67397 | |
| 67398 | if( pOp->p1==SQLITE_OK && p->pFrame ){ |
| 67399 | /* Halt the sub-program. Return control to the parent frame. */ |
| 67400 | VdbeFrame *pFrame = p->pFrame; |
| 67401 | p->pFrame = pFrame->pParent; |
| @@ -67183,11 +67402,11 @@ | |
| 67402 | p->nFrame--; |
| 67403 | sqlite3VdbeSetChanges(db, p->nChange); |
| 67404 | pc = sqlite3VdbeFrameRestore(pFrame); |
| 67405 | lastRowid = db->lastRowid; |
| 67406 | if( pOp->p2==OE_Ignore ){ |
| 67407 | /* Instruction pc is the OP_Program that invoked the sub-program |
| 67408 | ** currently being halted. If the p2 instruction of this OP_Halt |
| 67409 | ** instruction is set to OE_Ignore, then the sub-program is throwing |
| 67410 | ** an IGNORE exception. In this case jump to the address specified |
| 67411 | ** as the p2 of the calling OP_Program. */ |
| 67412 | pc = p->aOp[pc].p2-1; |
| @@ -67206,25 +67425,25 @@ | |
| 67425 | assert( pOp->p5>=1 && pOp->p5<=4 ); |
| 67426 | testcase( pOp->p5==1 ); |
| 67427 | testcase( pOp->p5==2 ); |
| 67428 | testcase( pOp->p5==3 ); |
| 67429 | testcase( pOp->p5==4 ); |
| 67430 | u.ab.zType = azType[pOp->p5-1]; |
| 67431 | }else{ |
| 67432 | u.ab.zType = 0; |
| 67433 | } |
| 67434 | assert( u.ab.zType!=0 || pOp->p4.z!=0 ); |
| 67435 | u.ab.zLogFmt = "abort at %d in [%s]: %s"; |
| 67436 | if( u.ab.zType && pOp->p4.z ){ |
| 67437 | sqlite3SetString(&p->zErrMsg, db, "%s constraint failed: %s", |
| 67438 | u.ab.zType, pOp->p4.z); |
| 67439 | }else if( pOp->p4.z ){ |
| 67440 | sqlite3SetString(&p->zErrMsg, db, "%s", pOp->p4.z); |
| 67441 | }else{ |
| 67442 | sqlite3SetString(&p->zErrMsg, db, "%s constraint failed", u.ab.zType); |
| 67443 | } |
| 67444 | sqlite3_log(pOp->p1, u.ab.zLogFmt, pc, p->zSql, p->zErrMsg); |
| 67445 | } |
| 67446 | rc = sqlite3VdbeHalt(p); |
| 67447 | assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR ); |
| 67448 | if( rc==SQLITE_BUSY ){ |
| 67449 | p->rc = rc = SQLITE_BUSY; |
| @@ -67334,21 +67553,23 @@ | |
| 67553 | ** If the P1 value is non-zero, then also set the MEM_Cleared flag so that |
| 67554 | ** NULL values will not compare equal even if SQLITE_NULLEQ is set on |
| 67555 | ** OP_Ne or OP_Eq. |
| 67556 | */ |
| 67557 | case OP_Null: { /* out2-prerelease */ |
| 67558 | #if 0 /* local variables moved into u.ac */ |
| 67559 | int cnt; |
| 67560 | u16 nullFlag; |
| 67561 | #endif /* local variables moved into u.ac */ |
| 67562 | u.ac.cnt = pOp->p3-pOp->p2; |
| 67563 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 67564 | pOut->flags = u.ac.nullFlag = pOp->p1 ? (MEM_Null|MEM_Cleared) : MEM_Null; |
| 67565 | while( u.ac.cnt>0 ){ |
| 67566 | pOut++; |
| 67567 | memAboutToChange(p, pOut); |
| 67568 | VdbeMemRelease(pOut); |
| 67569 | pOut->flags = u.ac.nullFlag; |
| 67570 | u.ac.cnt--; |
| 67571 | } |
| 67572 | break; |
| 67573 | } |
| 67574 | |
| 67575 | |
| @@ -67373,19 +67594,21 @@ | |
| 67594 | ** |
| 67595 | ** If the parameter is named, then its name appears in P4 and P3==1. |
| 67596 | ** The P4 value is used by sqlite3_bind_parameter_name(). |
| 67597 | */ |
| 67598 | case OP_Variable: { /* out2-prerelease */ |
| 67599 | #if 0 /* local variables moved into u.ad */ |
| 67600 | Mem *pVar; /* Value being transferred */ |
| 67601 | #endif /* local variables moved into u.ad */ |
| 67602 | |
| 67603 | assert( pOp->p1>0 && pOp->p1<=p->nVar ); |
| 67604 | assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] ); |
| 67605 | u.ad.pVar = &p->aVar[pOp->p1 - 1]; |
| 67606 | if( sqlite3VdbeMemTooBig(u.ad.pVar) ){ |
| 67607 | goto too_big; |
| 67608 | } |
| 67609 | sqlite3VdbeMemShallowCopy(pOut, u.ad.pVar, MEM_Static); |
| 67610 | UPDATE_MAX_BLOBSIZE(pOut); |
| 67611 | break; |
| 67612 | } |
| 67613 | |
| 67614 | /* Opcode: Move P1 P2 P3 * * |
| @@ -67395,67 +67618,71 @@ | |
| 67618 | ** registers P2..P2+P3. Registers P1..P1+P3 are |
| 67619 | ** left holding a NULL. It is an error for register ranges |
| 67620 | ** P1..P1+P3 and P2..P2+P3 to overlap. |
| 67621 | */ |
| 67622 | case OP_Move: { |
| 67623 | #if 0 /* local variables moved into u.ae */ |
| 67624 | char *zMalloc; /* Holding variable for allocated memory */ |
| 67625 | int n; /* Number of registers left to copy */ |
| 67626 | int p1; /* Register to copy from */ |
| 67627 | int p2; /* Register to copy to */ |
| 67628 | #endif /* local variables moved into u.ae */ |
| 67629 | |
| 67630 | u.ae.n = pOp->p3; |
| 67631 | u.ae.p1 = pOp->p1; |
| 67632 | u.ae.p2 = pOp->p2; |
| 67633 | assert( u.ae.n>=0 && u.ae.p1>0 && u.ae.p2>0 ); |
| 67634 | assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 ); |
| 67635 | |
| 67636 | pIn1 = &aMem[u.ae.p1]; |
| 67637 | pOut = &aMem[u.ae.p2]; |
| 67638 | do{ |
| 67639 | assert( pOut<=&aMem[(p->nMem-p->nCursor)] ); |
| 67640 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 67641 | assert( memIsValid(pIn1) ); |
| 67642 | memAboutToChange(p, pOut); |
| 67643 | u.ae.zMalloc = pOut->zMalloc; |
| 67644 | pOut->zMalloc = 0; |
| 67645 | sqlite3VdbeMemMove(pOut, pIn1); |
| 67646 | #ifdef SQLITE_DEBUG |
| 67647 | if( pOut->pScopyFrom>=&aMem[u.ae.p1] && pOut->pScopyFrom<&aMem[u.ae.p1+pOp->p3] ){ |
| 67648 | pOut->pScopyFrom += u.ae.p1 - pOp->p2; |
| 67649 | } |
| 67650 | #endif |
| 67651 | pIn1->zMalloc = u.ae.zMalloc; |
| 67652 | REGISTER_TRACE(u.ae.p2++, pOut); |
| 67653 | pIn1++; |
| 67654 | pOut++; |
| 67655 | }while( u.ae.n-- ); |
| 67656 | break; |
| 67657 | } |
| 67658 | |
| 67659 | /* Opcode: Copy P1 P2 P3 * * |
| 67660 | ** Synopsis: r[P2@P3]=r[P1@P3] |
| 67661 | ** |
| 67662 | ** Make a copy of registers P1..P1+P3 into registers P2..P2+P3. |
| 67663 | ** |
| 67664 | ** This instruction makes a deep copy of the value. A duplicate |
| 67665 | ** is made of any string or blob constant. See also OP_SCopy. |
| 67666 | */ |
| 67667 | case OP_Copy: { |
| 67668 | #if 0 /* local variables moved into u.af */ |
| 67669 | int n; |
| 67670 | #endif /* local variables moved into u.af */ |
| 67671 | |
| 67672 | u.af.n = pOp->p3; |
| 67673 | pIn1 = &aMem[pOp->p1]; |
| 67674 | pOut = &aMem[pOp->p2]; |
| 67675 | assert( pOut!=pIn1 ); |
| 67676 | while( 1 ){ |
| 67677 | sqlite3VdbeMemShallowCopy(pOut, pIn1, MEM_Ephem); |
| 67678 | Deephemeralize(pOut); |
| 67679 | #ifdef SQLITE_DEBUG |
| 67680 | pOut->pScopyFrom = 0; |
| 67681 | #endif |
| 67682 | REGISTER_TRACE(pOp->p2+pOp->p3-u.af.n, pOut); |
| 67683 | if( (u.af.n--)==0 ) break; |
| 67684 | pOut++; |
| 67685 | pIn1++; |
| 67686 | } |
| 67687 | break; |
| 67688 | } |
| @@ -67492,12 +67719,14 @@ | |
| 67719 | ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt |
| 67720 | ** structure to provide access to the top P1 values as the result |
| 67721 | ** row. |
| 67722 | */ |
| 67723 | case OP_ResultRow: { |
| 67724 | #if 0 /* local variables moved into u.ag */ |
| 67725 | Mem *pMem; |
| 67726 | int i; |
| 67727 | #endif /* local variables moved into u.ag */ |
| 67728 | assert( p->nResColumn==pOp->p2 ); |
| 67729 | assert( pOp->p1>0 ); |
| 67730 | assert( pOp->p1+pOp->p2<=(p->nMem-p->nCursor)+1 ); |
| 67731 | |
| 67732 | #ifndef SQLITE_OMIT_PROGRESS_CALLBACK |
| @@ -67519,12 +67748,12 @@ | |
| 67748 | assert( db->flags&SQLITE_CountRows ); |
| 67749 | assert( p->usesStmtJournal ); |
| 67750 | break; |
| 67751 | } |
| 67752 | |
| 67753 | /* If the SQLITE_CountRows flag is set in sqlite3.flags mask, then |
| 67754 | ** DML statements invoke this opcode to return the number of rows |
| 67755 | ** modified to the user. This is the only way that a VM that |
| 67756 | ** opens a statement transaction may invoke this opcode. |
| 67757 | ** |
| 67758 | ** In case this is such a statement, close any statement transaction |
| 67759 | ** opened by this VM before returning control to the user. This is to |
| @@ -67547,19 +67776,19 @@ | |
| 67776 | |
| 67777 | /* Make sure the results of the current row are \000 terminated |
| 67778 | ** and have an assigned type. The results are de-ephemeralized as |
| 67779 | ** a side effect. |
| 67780 | */ |
| 67781 | u.ag.pMem = p->pResultSet = &aMem[pOp->p1]; |
| 67782 | for(u.ag.i=0; u.ag.i<pOp->p2; u.ag.i++){ |
| 67783 | assert( memIsValid(&u.ag.pMem[u.ag.i]) ); |
| 67784 | Deephemeralize(&u.ag.pMem[u.ag.i]); |
| 67785 | assert( (u.ag.pMem[u.ag.i].flags & MEM_Ephem)==0 |
| 67786 | || (u.ag.pMem[u.ag.i].flags & (MEM_Str|MEM_Blob))==0 ); |
| 67787 | sqlite3VdbeMemNulTerminate(&u.ag.pMem[u.ag.i]); |
| 67788 | sqlite3VdbeMemStoreType(&u.ag.pMem[u.ag.i]); |
| 67789 | REGISTER_TRACE(pOp->p1+u.ag.i, &u.ag.pMem[u.ag.i]); |
| 67790 | } |
| 67791 | if( db->mallocFailed ) goto no_mem; |
| 67792 | |
| 67793 | /* Return SQLITE_ROW |
| 67794 | */ |
| @@ -67580,11 +67809,13 @@ | |
| 67809 | ** It is illegal for P1 and P3 to be the same register. Sometimes, |
| 67810 | ** if P3 is the same register as P2, the implementation is able |
| 67811 | ** to avoid a memcpy(). |
| 67812 | */ |
| 67813 | case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */ |
| 67814 | #if 0 /* local variables moved into u.ah */ |
| 67815 | i64 nByte; |
| 67816 | #endif /* local variables moved into u.ah */ |
| 67817 | |
| 67818 | pIn1 = &aMem[pOp->p1]; |
| 67819 | pIn2 = &aMem[pOp->p2]; |
| 67820 | pOut = &aMem[pOp->p3]; |
| 67821 | assert( pIn1!=pOut ); |
| @@ -67593,26 +67824,26 @@ | |
| 67824 | break; |
| 67825 | } |
| 67826 | if( ExpandBlob(pIn1) || ExpandBlob(pIn2) ) goto no_mem; |
| 67827 | Stringify(pIn1, encoding); |
| 67828 | Stringify(pIn2, encoding); |
| 67829 | u.ah.nByte = pIn1->n + pIn2->n; |
| 67830 | if( u.ah.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 67831 | goto too_big; |
| 67832 | } |
| 67833 | MemSetTypeFlag(pOut, MEM_Str); |
| 67834 | if( sqlite3VdbeMemGrow(pOut, (int)u.ah.nByte+2, pOut==pIn2) ){ |
| 67835 | goto no_mem; |
| 67836 | } |
| 67837 | if( pOut!=pIn2 ){ |
| 67838 | memcpy(pOut->z, pIn2->z, pIn2->n); |
| 67839 | } |
| 67840 | memcpy(&pOut->z[pIn2->n], pIn1->z, pIn1->n); |
| 67841 | pOut->z[u.ah.nByte]=0; |
| 67842 | pOut->z[u.ah.nByte+1] = 0; |
| 67843 | pOut->flags |= MEM_Term; |
| 67844 | pOut->n = (int)u.ah.nByte; |
| 67845 | pOut->enc = encoding; |
| 67846 | UPDATE_MAX_BLOBSIZE(pOut); |
| 67847 | break; |
| 67848 | } |
| 67849 | |
| @@ -67657,81 +67888,83 @@ | |
| 67888 | case OP_Add: /* same as TK_PLUS, in1, in2, out3 */ |
| 67889 | case OP_Subtract: /* same as TK_MINUS, in1, in2, out3 */ |
| 67890 | case OP_Multiply: /* same as TK_STAR, in1, in2, out3 */ |
| 67891 | case OP_Divide: /* same as TK_SLASH, in1, in2, out3 */ |
| 67892 | case OP_Remainder: { /* same as TK_REM, in1, in2, out3 */ |
| 67893 | #if 0 /* local variables moved into u.ai */ |
| 67894 | char bIntint; /* Started out as two integer operands */ |
| 67895 | int flags; /* Combined MEM_* flags from both inputs */ |
| 67896 | i64 iA; /* Integer value of left operand */ |
| 67897 | i64 iB; /* Integer value of right operand */ |
| 67898 | double rA; /* Real value of left operand */ |
| 67899 | double rB; /* Real value of right operand */ |
| 67900 | #endif /* local variables moved into u.ai */ |
| 67901 | |
| 67902 | pIn1 = &aMem[pOp->p1]; |
| 67903 | applyNumericAffinity(pIn1); |
| 67904 | pIn2 = &aMem[pOp->p2]; |
| 67905 | applyNumericAffinity(pIn2); |
| 67906 | pOut = &aMem[pOp->p3]; |
| 67907 | u.ai.flags = pIn1->flags | pIn2->flags; |
| 67908 | if( (u.ai.flags & MEM_Null)!=0 ) goto arithmetic_result_is_null; |
| 67909 | if( (pIn1->flags & pIn2->flags & MEM_Int)==MEM_Int ){ |
| 67910 | u.ai.iA = pIn1->u.i; |
| 67911 | u.ai.iB = pIn2->u.i; |
| 67912 | u.ai.bIntint = 1; |
| 67913 | switch( pOp->opcode ){ |
| 67914 | case OP_Add: if( sqlite3AddInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; |
| 67915 | case OP_Subtract: if( sqlite3SubInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; |
| 67916 | case OP_Multiply: if( sqlite3MulInt64(&u.ai.iB,u.ai.iA) ) goto fp_math; break; |
| 67917 | case OP_Divide: { |
| 67918 | if( u.ai.iA==0 ) goto arithmetic_result_is_null; |
| 67919 | if( u.ai.iA==-1 && u.ai.iB==SMALLEST_INT64 ) goto fp_math; |
| 67920 | u.ai.iB /= u.ai.iA; |
| 67921 | break; |
| 67922 | } |
| 67923 | default: { |
| 67924 | if( u.ai.iA==0 ) goto arithmetic_result_is_null; |
| 67925 | if( u.ai.iA==-1 ) u.ai.iA = 1; |
| 67926 | u.ai.iB %= u.ai.iA; |
| 67927 | break; |
| 67928 | } |
| 67929 | } |
| 67930 | pOut->u.i = u.ai.iB; |
| 67931 | MemSetTypeFlag(pOut, MEM_Int); |
| 67932 | }else{ |
| 67933 | u.ai.bIntint = 0; |
| 67934 | fp_math: |
| 67935 | u.ai.rA = sqlite3VdbeRealValue(pIn1); |
| 67936 | u.ai.rB = sqlite3VdbeRealValue(pIn2); |
| 67937 | switch( pOp->opcode ){ |
| 67938 | case OP_Add: u.ai.rB += u.ai.rA; break; |
| 67939 | case OP_Subtract: u.ai.rB -= u.ai.rA; break; |
| 67940 | case OP_Multiply: u.ai.rB *= u.ai.rA; break; |
| 67941 | case OP_Divide: { |
| 67942 | /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */ |
| 67943 | if( u.ai.rA==(double)0 ) goto arithmetic_result_is_null; |
| 67944 | u.ai.rB /= u.ai.rA; |
| 67945 | break; |
| 67946 | } |
| 67947 | default: { |
| 67948 | u.ai.iA = (i64)u.ai.rA; |
| 67949 | u.ai.iB = (i64)u.ai.rB; |
| 67950 | if( u.ai.iA==0 ) goto arithmetic_result_is_null; |
| 67951 | if( u.ai.iA==-1 ) u.ai.iA = 1; |
| 67952 | u.ai.rB = (double)(u.ai.iB % u.ai.iA); |
| 67953 | break; |
| 67954 | } |
| 67955 | } |
| 67956 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 67957 | pOut->u.i = u.ai.rB; |
| 67958 | MemSetTypeFlag(pOut, MEM_Int); |
| 67959 | #else |
| 67960 | if( sqlite3IsNaN(u.ai.rB) ){ |
| 67961 | goto arithmetic_result_is_null; |
| 67962 | } |
| 67963 | pOut->r = u.ai.rB; |
| 67964 | MemSetTypeFlag(pOut, MEM_Real); |
| 67965 | if( (u.ai.flags & MEM_Real)==0 && !u.ai.bIntint ){ |
| 67966 | sqlite3VdbeIntegerAffinity(pOut); |
| 67967 | } |
| 67968 | #endif |
| 67969 | } |
| 67970 | break; |
| @@ -67780,83 +68013,85 @@ | |
| 68013 | ** invocation of this opcode. |
| 68014 | ** |
| 68015 | ** See also: AggStep and AggFinal |
| 68016 | */ |
| 68017 | case OP_Function: { |
| 68018 | #if 0 /* local variables moved into u.aj */ |
| 68019 | int i; |
| 68020 | Mem *pArg; |
| 68021 | sqlite3_context ctx; |
| 68022 | sqlite3_value **apVal; |
| 68023 | int n; |
| 68024 | #endif /* local variables moved into u.aj */ |
| 68025 | |
| 68026 | u.aj.n = pOp->p5; |
| 68027 | u.aj.apVal = p->apArg; |
| 68028 | assert( u.aj.apVal || u.aj.n==0 ); |
| 68029 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68030 | pOut = &aMem[pOp->p3]; |
| 68031 | memAboutToChange(p, pOut); |
| 68032 | |
| 68033 | assert( u.aj.n==0 || (pOp->p2>0 && pOp->p2+u.aj.n<=(p->nMem-p->nCursor)+1) ); |
| 68034 | assert( pOp->p3<pOp->p2 || pOp->p3>=pOp->p2+u.aj.n ); |
| 68035 | u.aj.pArg = &aMem[pOp->p2]; |
| 68036 | for(u.aj.i=0; u.aj.i<u.aj.n; u.aj.i++, u.aj.pArg++){ |
| 68037 | assert( memIsValid(u.aj.pArg) ); |
| 68038 | u.aj.apVal[u.aj.i] = u.aj.pArg; |
| 68039 | Deephemeralize(u.aj.pArg); |
| 68040 | sqlite3VdbeMemStoreType(u.aj.pArg); |
| 68041 | REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg); |
| 68042 | } |
| 68043 | |
| 68044 | assert( pOp->p4type==P4_FUNCDEF ); |
| 68045 | u.aj.ctx.pFunc = pOp->p4.pFunc; |
| 68046 | u.aj.ctx.iOp = pc; |
| 68047 | u.aj.ctx.pVdbe = p; |
| 68048 | |
| 68049 | /* The output cell may already have a buffer allocated. Move |
| 68050 | ** the pointer to u.aj.ctx.s so in case the user-function can use |
| 68051 | ** the already allocated buffer instead of allocating a new one. |
| 68052 | */ |
| 68053 | memcpy(&u.aj.ctx.s, pOut, sizeof(Mem)); |
| 68054 | pOut->flags = MEM_Null; |
| 68055 | pOut->xDel = 0; |
| 68056 | pOut->zMalloc = 0; |
| 68057 | MemSetTypeFlag(&u.aj.ctx.s, MEM_Null); |
| 68058 | |
| 68059 | u.aj.ctx.fErrorOrAux = 0; |
| 68060 | if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 68061 | assert( pOp>aOp ); |
| 68062 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 68063 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 68064 | u.aj.ctx.pColl = pOp[-1].p4.pColl; |
| 68065 | } |
| 68066 | db->lastRowid = lastRowid; |
| 68067 | (*u.aj.ctx.pFunc->xFunc)(&u.aj.ctx, u.aj.n, u.aj.apVal); /* IMP: R-24505-23230 */ |
| 68068 | lastRowid = db->lastRowid; |
| 68069 | |
| 68070 | if( db->mallocFailed ){ |
| 68071 | /* Even though a malloc() has failed, the implementation of the |
| 68072 | ** user function may have called an sqlite3_result_XXX() function |
| 68073 | ** to return a value. The following call releases any resources |
| 68074 | ** associated with such a value. |
| 68075 | */ |
| 68076 | sqlite3VdbeMemRelease(&u.aj.ctx.s); |
| 68077 | goto no_mem; |
| 68078 | } |
| 68079 | |
| 68080 | /* If the function returned an error, throw an exception */ |
| 68081 | if( u.aj.ctx.fErrorOrAux ){ |
| 68082 | if( u.aj.ctx.isError ){ |
| 68083 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.aj.ctx.s)); |
| 68084 | rc = u.aj.ctx.isError; |
| 68085 | } |
| 68086 | sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 68087 | } |
| 68088 | |
| 68089 | /* Copy the result of the function into register P3 */ |
| 68090 | sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding); |
| 68091 | assert( pOut->flags==MEM_Null ); |
| 68092 | memcpy(pOut, &u.aj.ctx.s, sizeof(Mem)); |
| 68093 | if( sqlite3VdbeMemTooBig(pOut) ){ |
| 68094 | goto too_big; |
| 68095 | } |
| 68096 | |
| 68097 | #if 0 |
| @@ -67904,54 +68139,56 @@ | |
| 68139 | */ |
| 68140 | case OP_BitAnd: /* same as TK_BITAND, in1, in2, out3 */ |
| 68141 | case OP_BitOr: /* same as TK_BITOR, in1, in2, out3 */ |
| 68142 | case OP_ShiftLeft: /* same as TK_LSHIFT, in1, in2, out3 */ |
| 68143 | case OP_ShiftRight: { /* same as TK_RSHIFT, in1, in2, out3 */ |
| 68144 | #if 0 /* local variables moved into u.ak */ |
| 68145 | i64 iA; |
| 68146 | u64 uA; |
| 68147 | i64 iB; |
| 68148 | u8 op; |
| 68149 | #endif /* local variables moved into u.ak */ |
| 68150 | |
| 68151 | pIn1 = &aMem[pOp->p1]; |
| 68152 | pIn2 = &aMem[pOp->p2]; |
| 68153 | pOut = &aMem[pOp->p3]; |
| 68154 | if( (pIn1->flags | pIn2->flags) & MEM_Null ){ |
| 68155 | sqlite3VdbeMemSetNull(pOut); |
| 68156 | break; |
| 68157 | } |
| 68158 | u.ak.iA = sqlite3VdbeIntValue(pIn2); |
| 68159 | u.ak.iB = sqlite3VdbeIntValue(pIn1); |
| 68160 | u.ak.op = pOp->opcode; |
| 68161 | if( u.ak.op==OP_BitAnd ){ |
| 68162 | u.ak.iA &= u.ak.iB; |
| 68163 | }else if( u.ak.op==OP_BitOr ){ |
| 68164 | u.ak.iA |= u.ak.iB; |
| 68165 | }else if( u.ak.iB!=0 ){ |
| 68166 | assert( u.ak.op==OP_ShiftRight || u.ak.op==OP_ShiftLeft ); |
| 68167 | |
| 68168 | /* If shifting by a negative amount, shift in the other direction */ |
| 68169 | if( u.ak.iB<0 ){ |
| 68170 | assert( OP_ShiftRight==OP_ShiftLeft+1 ); |
| 68171 | u.ak.op = 2*OP_ShiftLeft + 1 - u.ak.op; |
| 68172 | u.ak.iB = u.ak.iB>(-64) ? -u.ak.iB : 64; |
| 68173 | } |
| 68174 | |
| 68175 | if( u.ak.iB>=64 ){ |
| 68176 | u.ak.iA = (u.ak.iA>=0 || u.ak.op==OP_ShiftLeft) ? 0 : -1; |
| 68177 | }else{ |
| 68178 | memcpy(&u.ak.uA, &u.ak.iA, sizeof(u.ak.uA)); |
| 68179 | if( u.ak.op==OP_ShiftLeft ){ |
| 68180 | u.ak.uA <<= u.ak.iB; |
| 68181 | }else{ |
| 68182 | u.ak.uA >>= u.ak.iB; |
| 68183 | /* Sign-extend on a right shift of a negative number */ |
| 68184 | if( u.ak.iA<0 ) u.ak.uA |= ((((u64)0xffffffff)<<32)|0xffffffff) << (64-u.ak.iB); |
| 68185 | } |
| 68186 | memcpy(&u.ak.iA, &u.ak.uA, sizeof(u.ak.iA)); |
| 68187 | } |
| 68188 | } |
| 68189 | pOut->u.i = u.ak.iA; |
| 68190 | MemSetTypeFlag(pOut, MEM_Int); |
| 68191 | break; |
| 68192 | } |
| 68193 | |
| 68194 | /* Opcode: AddImm P1 P2 * * * |
| @@ -68201,35 +68438,37 @@ | |
| 68438 | case OP_Ne: /* same as TK_NE, jump, in1, in3 */ |
| 68439 | case OP_Lt: /* same as TK_LT, jump, in1, in3 */ |
| 68440 | case OP_Le: /* same as TK_LE, jump, in1, in3 */ |
| 68441 | case OP_Gt: /* same as TK_GT, jump, in1, in3 */ |
| 68442 | case OP_Ge: { /* same as TK_GE, jump, in1, in3 */ |
| 68443 | #if 0 /* local variables moved into u.al */ |
| 68444 | int res; /* Result of the comparison of pIn1 against pIn3 */ |
| 68445 | char affinity; /* Affinity to use for comparison */ |
| 68446 | u16 flags1; /* Copy of initial value of pIn1->flags */ |
| 68447 | u16 flags3; /* Copy of initial value of pIn3->flags */ |
| 68448 | #endif /* local variables moved into u.al */ |
| 68449 | |
| 68450 | pIn1 = &aMem[pOp->p1]; |
| 68451 | pIn3 = &aMem[pOp->p3]; |
| 68452 | u.al.flags1 = pIn1->flags; |
| 68453 | u.al.flags3 = pIn3->flags; |
| 68454 | if( (u.al.flags1 | u.al.flags3)&MEM_Null ){ |
| 68455 | /* One or both operands are NULL */ |
| 68456 | if( pOp->p5 & SQLITE_NULLEQ ){ |
| 68457 | /* If SQLITE_NULLEQ is set (which will only happen if the operator is |
| 68458 | ** OP_Eq or OP_Ne) then take the jump or not depending on whether |
| 68459 | ** or not both operands are null. |
| 68460 | */ |
| 68461 | assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne ); |
| 68462 | assert( (u.al.flags1 & MEM_Cleared)==0 ); |
| 68463 | if( (u.al.flags1&MEM_Null)!=0 |
| 68464 | && (u.al.flags3&MEM_Null)!=0 |
| 68465 | && (u.al.flags3&MEM_Cleared)==0 |
| 68466 | ){ |
| 68467 | u.al.res = 0; /* Results are equal */ |
| 68468 | }else{ |
| 68469 | u.al.res = 1; /* Results are not equal */ |
| 68470 | } |
| 68471 | }else{ |
| 68472 | /* SQLITE_NULLEQ is clear and at least one operand is NULL, |
| 68473 | ** then the result is always NULL. |
| 68474 | ** The jump is taken if the SQLITE_JUMPIFNULL bit is set. |
| @@ -68243,44 +68482,44 @@ | |
| 68482 | } |
| 68483 | break; |
| 68484 | } |
| 68485 | }else{ |
| 68486 | /* Neither operand is NULL. Do a comparison. */ |
| 68487 | u.al.affinity = pOp->p5 & SQLITE_AFF_MASK; |
| 68488 | if( u.al.affinity ){ |
| 68489 | applyAffinity(pIn1, u.al.affinity, encoding); |
| 68490 | applyAffinity(pIn3, u.al.affinity, encoding); |
| 68491 | if( db->mallocFailed ) goto no_mem; |
| 68492 | } |
| 68493 | |
| 68494 | assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 ); |
| 68495 | ExpandBlob(pIn1); |
| 68496 | ExpandBlob(pIn3); |
| 68497 | u.al.res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl); |
| 68498 | } |
| 68499 | switch( pOp->opcode ){ |
| 68500 | case OP_Eq: u.al.res = u.al.res==0; break; |
| 68501 | case OP_Ne: u.al.res = u.al.res!=0; break; |
| 68502 | case OP_Lt: u.al.res = u.al.res<0; break; |
| 68503 | case OP_Le: u.al.res = u.al.res<=0; break; |
| 68504 | case OP_Gt: u.al.res = u.al.res>0; break; |
| 68505 | default: u.al.res = u.al.res>=0; break; |
| 68506 | } |
| 68507 | |
| 68508 | if( pOp->p5 & SQLITE_STOREP2 ){ |
| 68509 | pOut = &aMem[pOp->p2]; |
| 68510 | memAboutToChange(p, pOut); |
| 68511 | MemSetTypeFlag(pOut, MEM_Int); |
| 68512 | pOut->u.i = u.al.res; |
| 68513 | REGISTER_TRACE(pOp->p2, pOut); |
| 68514 | }else if( u.al.res ){ |
| 68515 | pc = pOp->p2-1; |
| 68516 | } |
| 68517 | |
| 68518 | /* Undo any changes made by applyAffinity() to the input registers. */ |
| 68519 | pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (u.al.flags1&MEM_TypeMask); |
| 68520 | pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (u.al.flags3&MEM_TypeMask); |
| 68521 | break; |
| 68522 | } |
| 68523 | |
| 68524 | /* Opcode: Permutation * * * P4 * |
| 68525 | ** |
| @@ -68316,49 +68555,51 @@ | |
| 68555 | ** The comparison is a sort comparison, so NULLs compare equal, |
| 68556 | ** NULLs are less than numbers, numbers are less than strings, |
| 68557 | ** and strings are less than blobs. |
| 68558 | */ |
| 68559 | case OP_Compare: { |
| 68560 | #if 0 /* local variables moved into u.am */ |
| 68561 | int n; |
| 68562 | int i; |
| 68563 | int p1; |
| 68564 | int p2; |
| 68565 | const KeyInfo *pKeyInfo; |
| 68566 | int idx; |
| 68567 | CollSeq *pColl; /* Collating sequence to use on this term */ |
| 68568 | int bRev; /* True for DESCENDING sort order */ |
| 68569 | #endif /* local variables moved into u.am */ |
| 68570 | |
| 68571 | if( (pOp->p5 & OPFLAG_PERMUTE)==0 ) aPermute = 0; |
| 68572 | u.am.n = pOp->p3; |
| 68573 | u.am.pKeyInfo = pOp->p4.pKeyInfo; |
| 68574 | assert( u.am.n>0 ); |
| 68575 | assert( u.am.pKeyInfo!=0 ); |
| 68576 | u.am.p1 = pOp->p1; |
| 68577 | u.am.p2 = pOp->p2; |
| 68578 | #if SQLITE_DEBUG |
| 68579 | if( aPermute ){ |
| 68580 | int k, mx = 0; |
| 68581 | for(k=0; k<u.am.n; k++) if( aPermute[k]>mx ) mx = aPermute[k]; |
| 68582 | assert( u.am.p1>0 && u.am.p1+mx<=(p->nMem-p->nCursor)+1 ); |
| 68583 | assert( u.am.p2>0 && u.am.p2+mx<=(p->nMem-p->nCursor)+1 ); |
| 68584 | }else{ |
| 68585 | assert( u.am.p1>0 && u.am.p1+u.am.n<=(p->nMem-p->nCursor)+1 ); |
| 68586 | assert( u.am.p2>0 && u.am.p2+u.am.n<=(p->nMem-p->nCursor)+1 ); |
| 68587 | } |
| 68588 | #endif /* SQLITE_DEBUG */ |
| 68589 | for(u.am.i=0; u.am.i<u.am.n; u.am.i++){ |
| 68590 | u.am.idx = aPermute ? aPermute[u.am.i] : u.am.i; |
| 68591 | assert( memIsValid(&aMem[u.am.p1+u.am.idx]) ); |
| 68592 | assert( memIsValid(&aMem[u.am.p2+u.am.idx]) ); |
| 68593 | REGISTER_TRACE(u.am.p1+u.am.idx, &aMem[u.am.p1+u.am.idx]); |
| 68594 | REGISTER_TRACE(u.am.p2+u.am.idx, &aMem[u.am.p2+u.am.idx]); |
| 68595 | assert( u.am.i<u.am.pKeyInfo->nField ); |
| 68596 | u.am.pColl = u.am.pKeyInfo->aColl[u.am.i]; |
| 68597 | u.am.bRev = u.am.pKeyInfo->aSortOrder[u.am.i]; |
| 68598 | iCompare = sqlite3MemCompare(&aMem[u.am.p1+u.am.idx], &aMem[u.am.p2+u.am.idx], u.am.pColl); |
| 68599 | if( iCompare ){ |
| 68600 | if( u.am.bRev ) iCompare = -iCompare; |
| 68601 | break; |
| 68602 | } |
| 68603 | } |
| 68604 | aPermute = 0; |
| 68605 | break; |
| @@ -68401,37 +68642,39 @@ | |
| 68642 | ** even if the other input is NULL. A NULL and false or two NULLs |
| 68643 | ** give a NULL output. |
| 68644 | */ |
| 68645 | case OP_And: /* same as TK_AND, in1, in2, out3 */ |
| 68646 | case OP_Or: { /* same as TK_OR, in1, in2, out3 */ |
| 68647 | #if 0 /* local variables moved into u.an */ |
| 68648 | int v1; /* Left operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 68649 | int v2; /* Right operand: 0==FALSE, 1==TRUE, 2==UNKNOWN or NULL */ |
| 68650 | #endif /* local variables moved into u.an */ |
| 68651 | |
| 68652 | pIn1 = &aMem[pOp->p1]; |
| 68653 | if( pIn1->flags & MEM_Null ){ |
| 68654 | u.an.v1 = 2; |
| 68655 | }else{ |
| 68656 | u.an.v1 = sqlite3VdbeIntValue(pIn1)!=0; |
| 68657 | } |
| 68658 | pIn2 = &aMem[pOp->p2]; |
| 68659 | if( pIn2->flags & MEM_Null ){ |
| 68660 | u.an.v2 = 2; |
| 68661 | }else{ |
| 68662 | u.an.v2 = sqlite3VdbeIntValue(pIn2)!=0; |
| 68663 | } |
| 68664 | if( pOp->opcode==OP_And ){ |
| 68665 | static const unsigned char and_logic[] = { 0, 0, 0, 0, 1, 2, 0, 2, 2 }; |
| 68666 | u.an.v1 = and_logic[u.an.v1*3+u.an.v2]; |
| 68667 | }else{ |
| 68668 | static const unsigned char or_logic[] = { 0, 1, 2, 1, 1, 1, 2, 1, 2 }; |
| 68669 | u.an.v1 = or_logic[u.an.v1*3+u.an.v2]; |
| 68670 | } |
| 68671 | pOut = &aMem[pOp->p3]; |
| 68672 | if( u.an.v1==2 ){ |
| 68673 | MemSetTypeFlag(pOut, MEM_Null); |
| 68674 | }else{ |
| 68675 | pOut->u.i = u.an.v1; |
| 68676 | MemSetTypeFlag(pOut, MEM_Int); |
| 68677 | } |
| 68678 | break; |
| 68679 | } |
| 68680 | |
| @@ -68498,23 +68741,25 @@ | |
| 68741 | ** is considered false if it has a numeric value of zero. If the value |
| 68742 | ** in P1 is NULL then take the jump if P3 is zero. |
| 68743 | */ |
| 68744 | case OP_If: /* jump, in1 */ |
| 68745 | case OP_IfNot: { /* jump, in1 */ |
| 68746 | #if 0 /* local variables moved into u.ao */ |
| 68747 | int c; |
| 68748 | #endif /* local variables moved into u.ao */ |
| 68749 | pIn1 = &aMem[pOp->p1]; |
| 68750 | if( pIn1->flags & MEM_Null ){ |
| 68751 | u.ao.c = pOp->p3; |
| 68752 | }else{ |
| 68753 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 68754 | u.ao.c = sqlite3VdbeIntValue(pIn1)!=0; |
| 68755 | #else |
| 68756 | u.ao.c = sqlite3VdbeRealValue(pIn1)!=0.0; |
| 68757 | #endif |
| 68758 | if( pOp->opcode==OP_IfNot ) u.ao.c = !u.ao.c; |
| 68759 | } |
| 68760 | if( u.ao.c ){ |
| 68761 | pc = pOp->p2-1; |
| 68762 | } |
| 68763 | break; |
| 68764 | } |
| 68765 | |
| @@ -68568,10 +68813,11 @@ | |
| 68813 | ** the result is guaranteed to only be used as the argument of a length() |
| 68814 | ** or typeof() function, respectively. The loading of large blobs can be |
| 68815 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 68816 | */ |
| 68817 | case OP_Column: { |
| 68818 | #if 0 /* local variables moved into u.ap */ |
| 68819 | i64 payloadSize64; /* Number of bytes in the record */ |
| 68820 | int p2; /* column number to retrieve */ |
| 68821 | VdbeCursor *pC; /* The VDBE cursor */ |
| 68822 | BtCursor *pCrsr; /* The BTree cursor */ |
| 68823 | u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| @@ -68586,88 +68832,89 @@ | |
| 68832 | u32 offset; /* Offset into the data */ |
| 68833 | u32 szField; /* Number of bytes in the content of a field */ |
| 68834 | u32 avail; /* Number of bytes of available data */ |
| 68835 | u32 t; /* A type code from the record header */ |
| 68836 | Mem *pReg; /* PseudoTable input register */ |
| 68837 | #endif /* local variables moved into u.ap */ |
| 68838 | |
| 68839 | u.ap.p2 = pOp->p2; |
| 68840 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68841 | u.ap.pDest = &aMem[pOp->p3]; |
| 68842 | memAboutToChange(p, u.ap.pDest); |
| 68843 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 68844 | u.ap.pC = p->apCsr[pOp->p1]; |
| 68845 | assert( u.ap.pC!=0 ); |
| 68846 | assert( u.ap.p2<u.ap.pC->nField ); |
| 68847 | u.ap.aType = u.ap.pC->aType; |
| 68848 | u.ap.aOffset = u.ap.aType + u.ap.pC->nField; |
| 68849 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 68850 | assert( u.ap.pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ |
| 68851 | #endif |
| 68852 | u.ap.pCrsr = u.ap.pC->pCursor; |
| 68853 | assert( u.ap.pCrsr!=0 || u.ap.pC->pseudoTableReg>0 ); /* u.ap.pCrsr NULL on PseudoTables */ |
| 68854 | assert( u.ap.pCrsr!=0 || u.ap.pC->nullRow ); /* u.ap.pC->nullRow on PseudoTables */ |
| 68855 | |
| 68856 | /* If the cursor cache is stale, bring it up-to-date */ |
| 68857 | rc = sqlite3VdbeCursorMoveto(u.ap.pC); |
| 68858 | if( rc ) goto abort_due_to_error; |
| 68859 | if( u.ap.pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){ |
| 68860 | if( u.ap.pC->nullRow ){ |
| 68861 | if( u.ap.pCrsr==0 ){ |
| 68862 | assert( u.ap.pC->pseudoTableReg>0 ); |
| 68863 | u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg]; |
| 68864 | if( u.ap.pC->multiPseudo ){ |
| 68865 | sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem); |
| 68866 | Deephemeralize(u.ap.pDest); |
| 68867 | goto op_column_out; |
| 68868 | } |
| 68869 | assert( u.ap.pReg->flags & MEM_Blob ); |
| 68870 | assert( memIsValid(u.ap.pReg) ); |
| 68871 | u.ap.pC->payloadSize = u.ap.pC->szRow = u.ap.avail = u.ap.pReg->n; |
| 68872 | u.ap.pC->aRow = (u8*)u.ap.pReg->z; |
| 68873 | }else{ |
| 68874 | MemSetTypeFlag(u.ap.pDest, MEM_Null); |
| 68875 | goto op_column_out; |
| 68876 | } |
| 68877 | }else{ |
| 68878 | assert( u.ap.pCrsr ); |
| 68879 | if( u.ap.pC->isTable==0 ){ |
| 68880 | assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); |
| 68881 | VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64); |
| 68882 | assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 68883 | /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the |
| 68884 | ** payload size, so it is impossible for u.ap.payloadSize64 to be |
| 68885 | ** larger than 32 bits. */ |
| 68886 | assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 ); |
| 68887 | u.ap.pC->aRow = sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail); |
| 68888 | u.ap.pC->payloadSize = (u32)u.ap.payloadSize64; |
| 68889 | }else{ |
| 68890 | assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); |
| 68891 | VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.pC->payloadSize); |
| 68892 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 68893 | u.ap.pC->aRow = sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail); |
| 68894 | } |
| 68895 | assert( u.ap.avail<=65536 ); /* Maximum page size is 64KiB */ |
| 68896 | if( u.ap.pC->payloadSize <= (u32)u.ap.avail ){ |
| 68897 | u.ap.pC->szRow = u.ap.pC->payloadSize; |
| 68898 | }else{ |
| 68899 | u.ap.pC->szRow = u.ap.avail; |
| 68900 | } |
| 68901 | if( u.ap.pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 68902 | goto too_big; |
| 68903 | } |
| 68904 | } |
| 68905 | u.ap.pC->cacheStatus = p->cacheCtr; |
| 68906 | u.ap.pC->iHdrOffset = getVarint32(u.ap.pC->aRow, u.ap.offset); |
| 68907 | u.ap.pC->nHdrParsed = 0; |
| 68908 | u.ap.aOffset[0] = u.ap.offset; |
| 68909 | if( u.ap.avail<u.ap.offset ){ |
| 68910 | /* u.ap.pC->aRow does not have to hold the entire row, but it does at least |
| 68911 | ** need to cover the header of the record. If u.ap.pC->aRow does not contain |
| 68912 | ** the complete header, then set it to zero, forcing the header to be |
| 68913 | ** dynamically allocated. */ |
| 68914 | u.ap.pC->aRow = 0; |
| 68915 | u.ap.pC->szRow = 0; |
| 68916 | } |
| 68917 | |
| 68918 | /* Make sure a corrupt database has not given us an oversize header. |
| 68919 | ** Do this now to avoid an oversize memory allocation. |
| 68920 | ** |
| @@ -68675,154 +68922,154 @@ | |
| 68922 | ** types use so much data space that there can only be 4096 and 32 of |
| 68923 | ** them, respectively. So the maximum header length results from a |
| 68924 | ** 3-byte type for each of the maximum of 32768 columns plus three |
| 68925 | ** extra bytes for the header length itself. 32768*3 + 3 = 98307. |
| 68926 | */ |
| 68927 | if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){ |
| 68928 | rc = SQLITE_CORRUPT_BKPT; |
| 68929 | goto op_column_error; |
| 68930 | } |
| 68931 | } |
| 68932 | |
| 68933 | /* Make sure at least the first u.ap.p2+1 entries of the header have been |
| 68934 | ** parsed and valid information is in u.ap.aOffset[] and u.ap.aType[]. |
| 68935 | */ |
| 68936 | if( u.ap.pC->nHdrParsed<=u.ap.p2 ){ |
| 68937 | /* If there is more header available for parsing in the record, try |
| 68938 | ** to extract additional fields up through the u.ap.p2+1-th field |
| 68939 | */ |
| 68940 | if( u.ap.pC->iHdrOffset<u.ap.aOffset[0] ){ |
| 68941 | /* Make sure u.ap.zData points to enough of the record to cover the header. */ |
| 68942 | if( u.ap.pC->aRow==0 ){ |
| 68943 | memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); |
| 68944 | rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.aOffset[0], |
| 68945 | !u.ap.pC->isTable, &u.ap.sMem); |
| 68946 | if( rc!=SQLITE_OK ){ |
| 68947 | goto op_column_error; |
| 68948 | } |
| 68949 | u.ap.zData = (u8*)u.ap.sMem.z; |
| 68950 | }else{ |
| 68951 | u.ap.zData = u.ap.pC->aRow; |
| 68952 | } |
| 68953 | |
| 68954 | /* Fill in u.ap.aType[u.ap.i] and u.ap.aOffset[u.ap.i] values through the u.ap.p2-th field. */ |
| 68955 | u.ap.i = u.ap.pC->nHdrParsed; |
| 68956 | u.ap.offset = u.ap.aOffset[u.ap.i]; |
| 68957 | u.ap.zHdr = u.ap.zData + u.ap.pC->iHdrOffset; |
| 68958 | u.ap.zEndHdr = u.ap.zData + u.ap.aOffset[0]; |
| 68959 | assert( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr ); |
| 68960 | do{ |
| 68961 | if( u.ap.zHdr[0]<0x80 ){ |
| 68962 | u.ap.t = u.ap.zHdr[0]; |
| 68963 | u.ap.zHdr++; |
| 68964 | }else{ |
| 68965 | u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t); |
| 68966 | } |
| 68967 | u.ap.aType[u.ap.i] = u.ap.t; |
| 68968 | u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t); |
| 68969 | u.ap.offset += u.ap.szField; |
| 68970 | if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */ |
| 68971 | u.ap.zHdr = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 68972 | break; |
| 68973 | } |
| 68974 | u.ap.i++; |
| 68975 | u.ap.aOffset[u.ap.i] = u.ap.offset; |
| 68976 | }while( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr ); |
| 68977 | u.ap.pC->nHdrParsed = u.ap.i; |
| 68978 | u.ap.pC->iHdrOffset = (u32)(u.ap.zHdr - u.ap.zData); |
| 68979 | if( u.ap.pC->aRow==0 ){ |
| 68980 | sqlite3VdbeMemRelease(&u.ap.sMem); |
| 68981 | u.ap.sMem.flags = MEM_Null; |
| 68982 | } |
| 68983 | |
| 68984 | /* If we have read more header data than was contained in the header, |
| 68985 | ** or if the end of the last field appears to be past the end of the |
| 68986 | ** record, or if the end of the last field appears to be before the end |
| 68987 | ** of the record (when all fields present), then we must be dealing |
| 68988 | ** with a corrupt database. |
| 68989 | */ |
| 68990 | if( (u.ap.zHdr > u.ap.zEndHdr) |
| 68991 | || (u.ap.offset > u.ap.pC->payloadSize) |
| 68992 | || (u.ap.zHdr==u.ap.zEndHdr && u.ap.offset!=u.ap.pC->payloadSize) |
| 68993 | ){ |
| 68994 | rc = SQLITE_CORRUPT_BKPT; |
| 68995 | goto op_column_error; |
| 68996 | } |
| 68997 | } |
| 68998 | |
| 68999 | /* If after trying to extra new entries from the header, nHdrParsed is |
| 69000 | ** still not up to u.ap.p2, that means that the record has fewer than u.ap.p2 |
| 69001 | ** columns. So the result will be either the default value or a NULL. |
| 69002 | */ |
| 69003 | if( u.ap.pC->nHdrParsed<=u.ap.p2 ){ |
| 69004 | if( pOp->p4type==P4_MEM ){ |
| 69005 | sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static); |
| 69006 | }else{ |
| 69007 | MemSetTypeFlag(u.ap.pDest, MEM_Null); |
| 69008 | } |
| 69009 | goto op_column_out; |
| 69010 | } |
| 69011 | } |
| 69012 | |
| 69013 | /* Extract the content for the u.ap.p2+1-th column. Control can only |
| 69014 | ** reach this point if u.ap.aOffset[u.ap.p2], u.ap.aOffset[u.ap.p2+1], and u.ap.aType[u.ap.p2] are |
| 69015 | ** all valid. |
| 69016 | */ |
| 69017 | assert( u.ap.p2<u.ap.pC->nHdrParsed ); |
| 69018 | assert( rc==SQLITE_OK ); |
| 69019 | if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){ |
| 69020 | /* This is the common case where the desired content fits on the original |
| 69021 | ** page - where the content is not on an overflow page */ |
| 69022 | VdbeMemRelease(u.ap.pDest); |
| 69023 | sqlite3VdbeSerialGet(u.ap.pC->aRow+u.ap.aOffset[u.ap.p2], u.ap.aType[u.ap.p2], u.ap.pDest); |
| 69024 | }else{ |
| 69025 | /* This branch happens only when content is on overflow pages */ |
| 69026 | u.ap.t = u.ap.aType[u.ap.p2]; |
| 69027 | if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 69028 | && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) |
| 69029 | || (u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t))==0 |
| 69030 | ){ |
| 69031 | /* Content is irrelevant for the typeof() function and for |
| 69032 | ** the length(X) function if X is a blob. So we might as well use |
| 69033 | ** bogus content rather than reading content from disk. NULL works |
| 69034 | ** for text and blob and whatever is in the u.ap.payloadSize64 variable |
| 69035 | ** will work for everything else. Content is also irrelevant if |
| 69036 | ** the content length is 0. */ |
| 69037 | u.ap.zData = u.ap.t<=13 ? (u8*)&u.ap.payloadSize64 : 0; |
| 69038 | u.ap.sMem.zMalloc = 0; |
| 69039 | }else{ |
| 69040 | memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); |
| 69041 | sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest); |
| 69042 | rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, !u.ap.pC->isTable, |
| 69043 | &u.ap.sMem); |
| 69044 | if( rc!=SQLITE_OK ){ |
| 69045 | goto op_column_error; |
| 69046 | } |
| 69047 | u.ap.zData = (u8*)u.ap.sMem.z; |
| 69048 | } |
| 69049 | sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest); |
| 69050 | /* If we dynamically allocated space to hold the data (in the |
| 69051 | ** sqlite3VdbeMemFromBtree() call above) then transfer control of that |
| 69052 | ** dynamically allocated space over to the u.ap.pDest structure. |
| 69053 | ** This prevents a memory copy. */ |
| 69054 | if( u.ap.sMem.zMalloc ){ |
| 69055 | assert( u.ap.sMem.z==u.ap.sMem.zMalloc ); |
| 69056 | assert( !(u.ap.pDest->flags & MEM_Dyn) ); |
| 69057 | assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z ); |
| 69058 | u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static); |
| 69059 | u.ap.pDest->flags |= MEM_Term; |
| 69060 | u.ap.pDest->z = u.ap.sMem.z; |
| 69061 | u.ap.pDest->zMalloc = u.ap.sMem.zMalloc; |
| 69062 | } |
| 69063 | } |
| 69064 | u.ap.pDest->enc = encoding; |
| 69065 | |
| 69066 | op_column_out: |
| 69067 | rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest); |
| 69068 | op_column_error: |
| 69069 | UPDATE_MAX_BLOBSIZE(u.ap.pDest); |
| 69070 | REGISTER_TRACE(pOp->p3, u.ap.pDest); |
| 69071 | break; |
| 69072 | } |
| 69073 | |
| 69074 | /* Opcode: Affinity P1 P2 * P4 * |
| 69075 | ** Synopsis: affinity(r[P1@P2]) |
| @@ -68832,22 +69079,24 @@ | |
| 69079 | ** P4 is a string that is P2 characters long. The nth character of the |
| 69080 | ** string indicates the column affinity that should be used for the nth |
| 69081 | ** memory cell in the range. |
| 69082 | */ |
| 69083 | case OP_Affinity: { |
| 69084 | #if 0 /* local variables moved into u.aq */ |
| 69085 | const char *zAffinity; /* The affinity to be applied */ |
| 69086 | char cAff; /* A single character of affinity */ |
| 69087 | #endif /* local variables moved into u.aq */ |
| 69088 | |
| 69089 | u.aq.zAffinity = pOp->p4.z; |
| 69090 | assert( u.aq.zAffinity!=0 ); |
| 69091 | assert( u.aq.zAffinity[pOp->p2]==0 ); |
| 69092 | pIn1 = &aMem[pOp->p1]; |
| 69093 | while( (u.aq.cAff = *(u.aq.zAffinity++))!=0 ){ |
| 69094 | assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] ); |
| 69095 | assert( memIsValid(pIn1) ); |
| 69096 | ExpandBlob(pIn1); |
| 69097 | applyAffinity(pIn1, u.aq.cAff, encoding); |
| 69098 | pIn1++; |
| 69099 | } |
| 69100 | break; |
| 69101 | } |
| 69102 | |
| @@ -68866,10 +69115,11 @@ | |
| 69115 | ** macros defined in sqliteInt.h. |
| 69116 | ** |
| 69117 | ** If P4 is NULL then all index fields have the affinity NONE. |
| 69118 | */ |
| 69119 | case OP_MakeRecord: { |
| 69120 | #if 0 /* local variables moved into u.ar */ |
| 69121 | u8 *zNewRecord; /* A buffer to hold the data for the new record */ |
| 69122 | Mem *pRec; /* The new record */ |
| 69123 | u64 nData; /* Number of bytes of data space */ |
| 69124 | int nHdr; /* Number of bytes of header space */ |
| 69125 | i64 nByte; /* Data space required for this record */ |
| @@ -68879,123 +69129,106 @@ | |
| 69129 | Mem *pData0; /* First field to be combined into the record */ |
| 69130 | Mem *pLast; /* Last field of the record */ |
| 69131 | int nField; /* Number of fields in the record */ |
| 69132 | char *zAffinity; /* The affinity string for the record */ |
| 69133 | int file_format; /* File format to use for encoding */ |
| 69134 | int i; /* Space used in zNewRecord[] */ |
| 69135 | int len; /* Length of a field */ |
| 69136 | #endif /* local variables moved into u.ar */ |
| 69137 | |
| 69138 | /* Assuming the record contains N fields, the record format looks |
| 69139 | ** like this: |
| 69140 | ** |
| 69141 | ** ------------------------------------------------------------------------ |
| 69142 | ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | |
| 69143 | ** ------------------------------------------------------------------------ |
| 69144 | ** |
| 69145 | ** Data(0) is taken from register P1. Data(1) comes from register P1+1 |
| 69146 | ** and so froth. |
| 69147 | ** |
| 69148 | ** Each type field is a varint representing the serial type of the |
| 69149 | ** corresponding data element (see sqlite3VdbeSerialType()). The |
| 69150 | ** hdr-size field is also a varint which is the offset from the beginning |
| 69151 | ** of the record to data0. |
| 69152 | */ |
| 69153 | u.ar.nData = 0; /* Number of bytes of data space */ |
| 69154 | u.ar.nHdr = 0; /* Number of bytes of header space */ |
| 69155 | u.ar.nZero = 0; /* Number of zero bytes at the end of the record */ |
| 69156 | u.ar.nField = pOp->p1; |
| 69157 | u.ar.zAffinity = pOp->p4.z; |
| 69158 | assert( u.ar.nField>0 && pOp->p2>0 && pOp->p2+u.ar.nField<=(p->nMem-p->nCursor)+1 ); |
| 69159 | u.ar.pData0 = &aMem[u.ar.nField]; |
| 69160 | u.ar.nField = pOp->p2; |
| 69161 | u.ar.pLast = &u.ar.pData0[u.ar.nField-1]; |
| 69162 | u.ar.file_format = p->minWriteFileFormat; |
| 69163 | |
| 69164 | /* Identify the output register */ |
| 69165 | assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); |
| 69166 | pOut = &aMem[pOp->p3]; |
| 69167 | memAboutToChange(p, pOut); |
| 69168 | |
| 69169 | /* Loop through the elements that will make up the record to figure |
| 69170 | ** out how much space is required for the new record. |
| 69171 | */ |
| 69172 | for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ |
| 69173 | assert( memIsValid(u.ar.pRec) ); |
| 69174 | if( u.ar.zAffinity ){ |
| 69175 | applyAffinity(u.ar.pRec, u.ar.zAffinity[u.ar.pRec-u.ar.pData0], encoding); |
| 69176 | } |
| 69177 | if( u.ar.pRec->flags&MEM_Zero && u.ar.pRec->n>0 ){ |
| 69178 | sqlite3VdbeMemExpandBlob(u.ar.pRec); |
| 69179 | } |
| 69180 | u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format); |
| 69181 | u.ar.len = sqlite3VdbeSerialTypeLen(u.ar.serial_type); |
| 69182 | u.ar.nData += u.ar.len; |
| 69183 | u.ar.nHdr += sqlite3VarintLen(u.ar.serial_type); |
| 69184 | if( u.ar.pRec->flags & MEM_Zero ){ |
| 69185 | /* Only pure zero-filled BLOBs can be input to this Opcode. |
| 69186 | ** We do not allow blobs with a prefix and a zero-filled tail. */ |
| 69187 | u.ar.nZero += u.ar.pRec->u.nZero; |
| 69188 | }else if( u.ar.len ){ |
| 69189 | u.ar.nZero = 0; |
| 69190 | } |
| 69191 | } |
| 69192 | |
| 69193 | /* Add the initial header varint and total the size */ |
| 69194 | u.ar.nHdr += u.ar.nVarint = sqlite3VarintLen(u.ar.nHdr); |
| 69195 | if( u.ar.nVarint<sqlite3VarintLen(u.ar.nHdr) ){ |
| 69196 | u.ar.nHdr++; |
| 69197 | } |
| 69198 | u.ar.nByte = u.ar.nHdr+u.ar.nData-u.ar.nZero; |
| 69199 | if( u.ar.nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 69200 | goto too_big; |
| 69201 | } |
| 69202 | |
| 69203 | /* Make sure the output register has a buffer large enough to store |
| 69204 | ** the new record. The output register (pOp->p3) is not allowed to |
| 69205 | ** be one of the input registers (because the following call to |
| 69206 | ** sqlite3VdbeMemGrow() could clobber the value before it is used). |
| 69207 | */ |
| 69208 | if( sqlite3VdbeMemGrow(pOut, (int)u.ar.nByte, 0) ){ |
| 69209 | goto no_mem; |
| 69210 | } |
| 69211 | u.ar.zNewRecord = (u8 *)pOut->z; |
| 69212 | |
| 69213 | /* Write the record */ |
| 69214 | u.ar.i = putVarint32(u.ar.zNewRecord, u.ar.nHdr); |
| 69215 | for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ |
| 69216 | u.ar.serial_type = sqlite3VdbeSerialType(u.ar.pRec, u.ar.file_format); |
| 69217 | u.ar.i += putVarint32(&u.ar.zNewRecord[u.ar.i], u.ar.serial_type); /* serial type */ |
| 69218 | } |
| 69219 | for(u.ar.pRec=u.ar.pData0; u.ar.pRec<=u.ar.pLast; u.ar.pRec++){ /* serial data */ |
| 69220 | u.ar.i += sqlite3VdbeSerialPut(&u.ar.zNewRecord[u.ar.i], (int)(u.ar.nByte-u.ar.i), u.ar.pRec,u.ar.file_format); |
| 69221 | } |
| 69222 | assert( u.ar.i==u.ar.nByte ); |
| 69223 | |
| 69224 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 69225 | pOut->n = (int)u.ar.nByte; |
| 69226 | pOut->flags = MEM_Blob | MEM_Dyn; |
| 69227 | pOut->xDel = 0; |
| 69228 | if( u.ar.nZero ){ |
| 69229 | pOut->u.nZero = u.ar.nZero; |
| 69230 | pOut->flags |= MEM_Zero; |
| 69231 | } |
| 69232 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */ |
| 69233 | REGISTER_TRACE(pOp->p3, pOut); |
| 69234 | UPDATE_MAX_BLOBSIZE(pOut); |
| @@ -69008,18 +69241,19 @@ | |
| 69241 | ** Store the number of entries (an integer value) in the table or index |
| 69242 | ** opened by cursor P1 in register P2 |
| 69243 | */ |
| 69244 | #ifndef SQLITE_OMIT_BTREECOUNT |
| 69245 | case OP_Count: { /* out2-prerelease */ |
| 69246 | #if 0 /* local variables moved into u.as */ |
| 69247 | i64 nEntry; |
| 69248 | BtCursor *pCrsr; |
| 69249 | #endif /* local variables moved into u.as */ |
| 69250 | |
| 69251 | u.as.pCrsr = p->apCsr[pOp->p1]->pCursor; |
| 69252 | assert( u.as.pCrsr ); |
| 69253 | rc = sqlite3BtreeCount(u.as.pCrsr, &u.as.nEntry); |
| 69254 | pOut->u.i = u.as.nEntry; |
| 69255 | break; |
| 69256 | } |
| 69257 | #endif |
| 69258 | |
| 69259 | /* Opcode: Savepoint P1 * * P4 * |
| @@ -69027,41 +69261,43 @@ | |
| 69261 | ** Open, release or rollback the savepoint named by parameter P4, depending |
| 69262 | ** on the value of P1. To open a new savepoint, P1==0. To release (commit) an |
| 69263 | ** existing savepoint, P1==1, or to rollback an existing savepoint P1==2. |
| 69264 | */ |
| 69265 | case OP_Savepoint: { |
| 69266 | #if 0 /* local variables moved into u.at */ |
| 69267 | int p1; /* Value of P1 operand */ |
| 69268 | char *zName; /* Name of savepoint */ |
| 69269 | int nName; |
| 69270 | Savepoint *pNew; |
| 69271 | Savepoint *pSavepoint; |
| 69272 | Savepoint *pTmp; |
| 69273 | int iSavepoint; |
| 69274 | int ii; |
| 69275 | #endif /* local variables moved into u.at */ |
| 69276 | |
| 69277 | u.at.p1 = pOp->p1; |
| 69278 | u.at.zName = pOp->p4.z; |
| 69279 | |
| 69280 | /* Assert that the u.at.p1 parameter is valid. Also that if there is no open |
| 69281 | ** transaction, then there cannot be any savepoints. |
| 69282 | */ |
| 69283 | assert( db->pSavepoint==0 || db->autoCommit==0 ); |
| 69284 | assert( u.at.p1==SAVEPOINT_BEGIN||u.at.p1==SAVEPOINT_RELEASE||u.at.p1==SAVEPOINT_ROLLBACK ); |
| 69285 | assert( db->pSavepoint || db->isTransactionSavepoint==0 ); |
| 69286 | assert( checkSavepointCount(db) ); |
| 69287 | assert( p->bIsReader ); |
| 69288 | |
| 69289 | if( u.at.p1==SAVEPOINT_BEGIN ){ |
| 69290 | if( db->nVdbeWrite>0 ){ |
| 69291 | /* A new savepoint cannot be created if there are active write |
| 69292 | ** statements (i.e. open read/write incremental blob handles). |
| 69293 | */ |
| 69294 | sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - " |
| 69295 | "SQL statements in progress"); |
| 69296 | rc = SQLITE_BUSY; |
| 69297 | }else{ |
| 69298 | u.at.nName = sqlite3Strlen30(u.at.zName); |
| 69299 | |
| 69300 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 69301 | /* This call is Ok even if this savepoint is actually a transaction |
| 69302 | ** savepoint (and therefore should not prompt xSavepoint()) callbacks. |
| 69303 | ** If this is a transaction savepoint being opened, it is guaranteed |
| @@ -69071,62 +69307,62 @@ | |
| 69307 | db->nStatement+db->nSavepoint); |
| 69308 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69309 | #endif |
| 69310 | |
| 69311 | /* Create a new savepoint structure. */ |
| 69312 | u.at.pNew = sqlite3DbMallocRaw(db, sizeof(Savepoint)+u.at.nName+1); |
| 69313 | if( u.at.pNew ){ |
| 69314 | u.at.pNew->zName = (char *)&u.at.pNew[1]; |
| 69315 | memcpy(u.at.pNew->zName, u.at.zName, u.at.nName+1); |
| 69316 | |
| 69317 | /* If there is no open transaction, then mark this as a special |
| 69318 | ** "transaction savepoint". */ |
| 69319 | if( db->autoCommit ){ |
| 69320 | db->autoCommit = 0; |
| 69321 | db->isTransactionSavepoint = 1; |
| 69322 | }else{ |
| 69323 | db->nSavepoint++; |
| 69324 | } |
| 69325 | |
| 69326 | /* Link the new savepoint into the database handle's list. */ |
| 69327 | u.at.pNew->pNext = db->pSavepoint; |
| 69328 | db->pSavepoint = u.at.pNew; |
| 69329 | u.at.pNew->nDeferredCons = db->nDeferredCons; |
| 69330 | u.at.pNew->nDeferredImmCons = db->nDeferredImmCons; |
| 69331 | } |
| 69332 | } |
| 69333 | }else{ |
| 69334 | u.at.iSavepoint = 0; |
| 69335 | |
| 69336 | /* Find the named savepoint. If there is no such savepoint, then an |
| 69337 | ** an error is returned to the user. */ |
| 69338 | for( |
| 69339 | u.at.pSavepoint = db->pSavepoint; |
| 69340 | u.at.pSavepoint && sqlite3StrICmp(u.at.pSavepoint->zName, u.at.zName); |
| 69341 | u.at.pSavepoint = u.at.pSavepoint->pNext |
| 69342 | ){ |
| 69343 | u.at.iSavepoint++; |
| 69344 | } |
| 69345 | if( !u.at.pSavepoint ){ |
| 69346 | sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.at.zName); |
| 69347 | rc = SQLITE_ERROR; |
| 69348 | }else if( db->nVdbeWrite>0 && u.at.p1==SAVEPOINT_RELEASE ){ |
| 69349 | /* It is not possible to release (commit) a savepoint if there are |
| 69350 | ** active write statements. |
| 69351 | */ |
| 69352 | sqlite3SetString(&p->zErrMsg, db, |
| 69353 | "cannot release savepoint - SQL statements in progress" |
| 69354 | ); |
| 69355 | rc = SQLITE_BUSY; |
| 69356 | }else{ |
| 69357 | |
| 69358 | /* Determine whether or not this is a transaction savepoint. If so, |
| 69359 | ** and this is a RELEASE command, then the current transaction |
| 69360 | ** is committed. |
| 69361 | */ |
| 69362 | int isTransaction = u.at.pSavepoint->pNext==0 && db->isTransactionSavepoint; |
| 69363 | if( isTransaction && u.at.p1==SAVEPOINT_RELEASE ){ |
| 69364 | if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 69365 | goto vdbe_return; |
| 69366 | } |
| 69367 | db->autoCommit = 1; |
| 69368 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| @@ -69136,56 +69372,56 @@ | |
| 69372 | goto vdbe_return; |
| 69373 | } |
| 69374 | db->isTransactionSavepoint = 0; |
| 69375 | rc = p->rc; |
| 69376 | }else{ |
| 69377 | u.at.iSavepoint = db->nSavepoint - u.at.iSavepoint - 1; |
| 69378 | if( u.at.p1==SAVEPOINT_ROLLBACK ){ |
| 69379 | for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){ |
| 69380 | sqlite3BtreeTripAllCursors(db->aDb[u.at.ii].pBt, SQLITE_ABORT); |
| 69381 | } |
| 69382 | } |
| 69383 | for(u.at.ii=0; u.at.ii<db->nDb; u.at.ii++){ |
| 69384 | rc = sqlite3BtreeSavepoint(db->aDb[u.at.ii].pBt, u.at.p1, u.at.iSavepoint); |
| 69385 | if( rc!=SQLITE_OK ){ |
| 69386 | goto abort_due_to_error; |
| 69387 | } |
| 69388 | } |
| 69389 | if( u.at.p1==SAVEPOINT_ROLLBACK && (db->flags&SQLITE_InternChanges)!=0 ){ |
| 69390 | sqlite3ExpirePreparedStatements(db); |
| 69391 | sqlite3ResetAllSchemasOfConnection(db); |
| 69392 | db->flags = (db->flags | SQLITE_InternChanges); |
| 69393 | } |
| 69394 | } |
| 69395 | |
| 69396 | /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all |
| 69397 | ** savepoints nested inside of the savepoint being operated on. */ |
| 69398 | while( db->pSavepoint!=u.at.pSavepoint ){ |
| 69399 | u.at.pTmp = db->pSavepoint; |
| 69400 | db->pSavepoint = u.at.pTmp->pNext; |
| 69401 | sqlite3DbFree(db, u.at.pTmp); |
| 69402 | db->nSavepoint--; |
| 69403 | } |
| 69404 | |
| 69405 | /* If it is a RELEASE, then destroy the savepoint being operated on |
| 69406 | ** too. If it is a ROLLBACK TO, then set the number of deferred |
| 69407 | ** constraint violations present in the database to the value stored |
| 69408 | ** when the savepoint was created. */ |
| 69409 | if( u.at.p1==SAVEPOINT_RELEASE ){ |
| 69410 | assert( u.at.pSavepoint==db->pSavepoint ); |
| 69411 | db->pSavepoint = u.at.pSavepoint->pNext; |
| 69412 | sqlite3DbFree(db, u.at.pSavepoint); |
| 69413 | if( !isTransaction ){ |
| 69414 | db->nSavepoint--; |
| 69415 | } |
| 69416 | }else{ |
| 69417 | db->nDeferredCons = u.at.pSavepoint->nDeferredCons; |
| 69418 | db->nDeferredImmCons = u.at.pSavepoint->nDeferredImmCons; |
| 69419 | } |
| 69420 | |
| 69421 | if( !isTransaction ){ |
| 69422 | rc = sqlite3VtabSavepoint(db, u.at.p1, u.at.iSavepoint); |
| 69423 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 69424 | } |
| 69425 | } |
| 69426 | } |
| 69427 | |
| @@ -69200,52 +69436,54 @@ | |
| 69436 | ** there are active writing VMs or active VMs that use shared cache. |
| 69437 | ** |
| 69438 | ** This instruction causes the VM to halt. |
| 69439 | */ |
| 69440 | case OP_AutoCommit: { |
| 69441 | #if 0 /* local variables moved into u.au */ |
| 69442 | int desiredAutoCommit; |
| 69443 | int iRollback; |
| 69444 | int turnOnAC; |
| 69445 | #endif /* local variables moved into u.au */ |
| 69446 | |
| 69447 | u.au.desiredAutoCommit = pOp->p1; |
| 69448 | u.au.iRollback = pOp->p2; |
| 69449 | u.au.turnOnAC = u.au.desiredAutoCommit && !db->autoCommit; |
| 69450 | assert( u.au.desiredAutoCommit==1 || u.au.desiredAutoCommit==0 ); |
| 69451 | assert( u.au.desiredAutoCommit==1 || u.au.iRollback==0 ); |
| 69452 | assert( db->nVdbeActive>0 ); /* At least this one VM is active */ |
| 69453 | assert( p->bIsReader ); |
| 69454 | |
| 69455 | #if 0 |
| 69456 | if( u.au.turnOnAC && u.au.iRollback && db->nVdbeActive>1 ){ |
| 69457 | /* If this instruction implements a ROLLBACK and other VMs are |
| 69458 | ** still running, and a transaction is active, return an error indicating |
| 69459 | ** that the other VMs must complete first. |
| 69460 | */ |
| 69461 | sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - " |
| 69462 | "SQL statements in progress"); |
| 69463 | rc = SQLITE_BUSY; |
| 69464 | }else |
| 69465 | #endif |
| 69466 | if( u.au.turnOnAC && !u.au.iRollback && db->nVdbeWrite>0 ){ |
| 69467 | /* If this instruction implements a COMMIT and other VMs are writing |
| 69468 | ** return an error indicating that the other VMs must complete first. |
| 69469 | */ |
| 69470 | sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - " |
| 69471 | "SQL statements in progress"); |
| 69472 | rc = SQLITE_BUSY; |
| 69473 | }else if( u.au.desiredAutoCommit!=db->autoCommit ){ |
| 69474 | if( u.au.iRollback ){ |
| 69475 | assert( u.au.desiredAutoCommit==1 ); |
| 69476 | sqlite3RollbackAll(db, SQLITE_ABORT_ROLLBACK); |
| 69477 | db->autoCommit = 1; |
| 69478 | }else if( (rc = sqlite3VdbeCheckFk(p, 1))!=SQLITE_OK ){ |
| 69479 | goto vdbe_return; |
| 69480 | }else{ |
| 69481 | db->autoCommit = (u8)u.au.desiredAutoCommit; |
| 69482 | if( sqlite3VdbeHalt(p)==SQLITE_BUSY ){ |
| 69483 | p->pc = pc; |
| 69484 | db->autoCommit = (u8)(1-u.au.desiredAutoCommit); |
| 69485 | p->rc = rc = SQLITE_BUSY; |
| 69486 | goto vdbe_return; |
| 69487 | } |
| 69488 | } |
| 69489 | assert( db->nStatement==0 ); |
| @@ -69256,14 +69494,14 @@ | |
| 69494 | rc = SQLITE_ERROR; |
| 69495 | } |
| 69496 | goto vdbe_return; |
| 69497 | }else{ |
| 69498 | sqlite3SetString(&p->zErrMsg, db, |
| 69499 | (!u.au.desiredAutoCommit)?"cannot start a transaction within a transaction":( |
| 69500 | (u.au.iRollback)?"cannot rollback - no transaction is active": |
| 69501 | "cannot commit - no transaction is active")); |
| 69502 | |
| 69503 | rc = SQLITE_ERROR; |
| 69504 | } |
| 69505 | break; |
| 69506 | } |
| 69507 | |
| @@ -69297,46 +69535,48 @@ | |
| 69535 | ** will automatically commit when the VDBE halts. |
| 69536 | ** |
| 69537 | ** If P2 is zero, then a read-lock is obtained on the database file. |
| 69538 | */ |
| 69539 | case OP_Transaction: { |
| 69540 | #if 0 /* local variables moved into u.av */ |
| 69541 | Btree *pBt; |
| 69542 | #endif /* local variables moved into u.av */ |
| 69543 | |
| 69544 | assert( p->bIsReader ); |
| 69545 | assert( p->readOnly==0 || pOp->p2==0 ); |
| 69546 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69547 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69548 | if( pOp->p2 && (db->flags & SQLITE_QueryOnly)!=0 ){ |
| 69549 | rc = SQLITE_READONLY; |
| 69550 | goto abort_due_to_error; |
| 69551 | } |
| 69552 | u.av.pBt = db->aDb[pOp->p1].pBt; |
| 69553 | |
| 69554 | if( u.av.pBt ){ |
| 69555 | rc = sqlite3BtreeBeginTrans(u.av.pBt, pOp->p2); |
| 69556 | if( rc==SQLITE_BUSY ){ |
| 69557 | p->pc = pc; |
| 69558 | p->rc = rc = SQLITE_BUSY; |
| 69559 | goto vdbe_return; |
| 69560 | } |
| 69561 | if( rc!=SQLITE_OK ){ |
| 69562 | goto abort_due_to_error; |
| 69563 | } |
| 69564 | |
| 69565 | if( pOp->p2 && p->usesStmtJournal |
| 69566 | && (db->autoCommit==0 || db->nVdbeRead>1) |
| 69567 | ){ |
| 69568 | assert( sqlite3BtreeIsInTrans(u.av.pBt) ); |
| 69569 | if( p->iStatement==0 ){ |
| 69570 | assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 69571 | db->nStatement++; |
| 69572 | p->iStatement = db->nSavepoint + db->nStatement; |
| 69573 | } |
| 69574 | |
| 69575 | rc = sqlite3VtabSavepoint(db, SAVEPOINT_BEGIN, p->iStatement-1); |
| 69576 | if( rc==SQLITE_OK ){ |
| 69577 | rc = sqlite3BtreeBeginStmt(u.av.pBt, p->iStatement); |
| 69578 | } |
| 69579 | |
| 69580 | /* Store the current value of the database handles deferred constraint |
| 69581 | ** counter. If the statement transaction needs to be rolled back, |
| 69582 | ** the value of this counter needs to be restored too. */ |
| @@ -69358,24 +69598,26 @@ | |
| 69598 | ** There must be a read-lock on the database (either a transaction |
| 69599 | ** must be started or there must be an open cursor) before |
| 69600 | ** executing this instruction. |
| 69601 | */ |
| 69602 | case OP_ReadCookie: { /* out2-prerelease */ |
| 69603 | #if 0 /* local variables moved into u.aw */ |
| 69604 | int iMeta; |
| 69605 | int iDb; |
| 69606 | int iCookie; |
| 69607 | #endif /* local variables moved into u.aw */ |
| 69608 | |
| 69609 | assert( p->bIsReader ); |
| 69610 | u.aw.iDb = pOp->p1; |
| 69611 | u.aw.iCookie = pOp->p3; |
| 69612 | assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 69613 | assert( u.aw.iDb>=0 && u.aw.iDb<db->nDb ); |
| 69614 | assert( db->aDb[u.aw.iDb].pBt!=0 ); |
| 69615 | assert( (p->btreeMask & (((yDbMask)1)<<u.aw.iDb))!=0 ); |
| 69616 | |
| 69617 | sqlite3BtreeGetMeta(db->aDb[u.aw.iDb].pBt, u.aw.iCookie, (u32 *)&u.aw.iMeta); |
| 69618 | pOut->u.i = u.aw.iMeta; |
| 69619 | break; |
| 69620 | } |
| 69621 | |
| 69622 | /* Opcode: SetCookie P1 P2 P3 * * |
| 69623 | ** |
| @@ -69386,29 +69628,31 @@ | |
| 69628 | ** database file used to store temporary tables. |
| 69629 | ** |
| 69630 | ** A transaction must be started before executing this opcode. |
| 69631 | */ |
| 69632 | case OP_SetCookie: { /* in3 */ |
| 69633 | #if 0 /* local variables moved into u.ax */ |
| 69634 | Db *pDb; |
| 69635 | #endif /* local variables moved into u.ax */ |
| 69636 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 69637 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69638 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69639 | assert( p->readOnly==0 ); |
| 69640 | u.ax.pDb = &db->aDb[pOp->p1]; |
| 69641 | assert( u.ax.pDb->pBt!=0 ); |
| 69642 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69643 | pIn3 = &aMem[pOp->p3]; |
| 69644 | sqlite3VdbeMemIntegerify(pIn3); |
| 69645 | /* See note about index shifting on OP_ReadCookie */ |
| 69646 | rc = sqlite3BtreeUpdateMeta(u.ax.pDb->pBt, pOp->p2, (int)pIn3->u.i); |
| 69647 | if( pOp->p2==BTREE_SCHEMA_VERSION ){ |
| 69648 | /* When the schema cookie changes, record the new cookie internally */ |
| 69649 | u.ax.pDb->pSchema->schema_cookie = (int)pIn3->u.i; |
| 69650 | db->flags |= SQLITE_InternChanges; |
| 69651 | }else if( pOp->p2==BTREE_FILE_FORMAT ){ |
| 69652 | /* Record changes in the file format */ |
| 69653 | u.ax.pDb->pSchema->file_format = (u8)pIn3->u.i; |
| 69654 | } |
| 69655 | if( pOp->p1==1 ){ |
| 69656 | /* Invalidate all prepared statements whenever the TEMP database |
| 69657 | ** schema is changed. Ticket #1644 */ |
| 69658 | sqlite3ExpirePreparedStatements(db); |
| @@ -69434,42 +69678,44 @@ | |
| 69678 | ** Either a transaction needs to have been started or an OP_Open needs |
| 69679 | ** to be executed (to establish a read lock) before this opcode is |
| 69680 | ** invoked. |
| 69681 | */ |
| 69682 | case OP_VerifyCookie: { |
| 69683 | #if 0 /* local variables moved into u.ay */ |
| 69684 | int iMeta; |
| 69685 | int iGen; |
| 69686 | Btree *pBt; |
| 69687 | #endif /* local variables moved into u.ay */ |
| 69688 | |
| 69689 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 69690 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 69691 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 69692 | assert( p->bIsReader ); |
| 69693 | u.ay.pBt = db->aDb[pOp->p1].pBt; |
| 69694 | if( u.ay.pBt ){ |
| 69695 | sqlite3BtreeGetMeta(u.ay.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ay.iMeta); |
| 69696 | u.ay.iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 69697 | }else{ |
| 69698 | u.ay.iGen = u.ay.iMeta = 0; |
| 69699 | } |
| 69700 | if( u.ay.iMeta!=pOp->p2 || u.ay.iGen!=pOp->p3 ){ |
| 69701 | sqlite3DbFree(db, p->zErrMsg); |
| 69702 | p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed"); |
| 69703 | /* If the schema-cookie from the database file matches the cookie |
| 69704 | ** stored with the in-memory representation of the schema, do |
| 69705 | ** not reload the schema from the database file. |
| 69706 | ** |
| 69707 | ** If virtual-tables are in use, this is not just an optimization. |
| 69708 | ** Often, v-tables store their data in other SQLite tables, which |
| 69709 | ** are queried from within xNext() and other v-table methods using |
| 69710 | ** prepared queries. If such a query is out-of-date, we do not want to |
| 69711 | ** discard the database schema, as the user code implementing the |
| 69712 | ** v-table would have to be ready for the sqlite3_vtab structure itself |
| 69713 | ** to be invalidated whenever sqlite3_step() is called from within |
| 69714 | ** a v-table method. |
| 69715 | */ |
| 69716 | if( db->aDb[pOp->p1].pSchema->schema_cookie!=u.ay.iMeta ){ |
| 69717 | sqlite3ResetOneSchema(db, pOp->p1); |
| 69718 | } |
| 69719 | |
| 69720 | p->expired = 1; |
| 69721 | rc = SQLITE_SCHEMA; |
| @@ -69528,18 +69774,20 @@ | |
| 69774 | ** |
| 69775 | ** See also OpenRead. |
| 69776 | */ |
| 69777 | case OP_OpenRead: |
| 69778 | case OP_OpenWrite: { |
| 69779 | #if 0 /* local variables moved into u.az */ |
| 69780 | int nField; |
| 69781 | KeyInfo *pKeyInfo; |
| 69782 | int p2; |
| 69783 | int iDb; |
| 69784 | int wrFlag; |
| 69785 | Btree *pX; |
| 69786 | VdbeCursor *pCur; |
| 69787 | Db *pDb; |
| 69788 | #endif /* local variables moved into u.az */ |
| 69789 | |
| 69790 | assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 ); |
| 69791 | assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 ); |
| 69792 | assert( p->bIsReader ); |
| 69793 | assert( pOp->opcode==OP_OpenRead || p->readOnly==0 ); |
| @@ -69547,74 +69795,74 @@ | |
| 69795 | if( p->expired ){ |
| 69796 | rc = SQLITE_ABORT; |
| 69797 | break; |
| 69798 | } |
| 69799 | |
| 69800 | u.az.nField = 0; |
| 69801 | u.az.pKeyInfo = 0; |
| 69802 | u.az.p2 = pOp->p2; |
| 69803 | u.az.iDb = pOp->p3; |
| 69804 | assert( u.az.iDb>=0 && u.az.iDb<db->nDb ); |
| 69805 | assert( (p->btreeMask & (((yDbMask)1)<<u.az.iDb))!=0 ); |
| 69806 | u.az.pDb = &db->aDb[u.az.iDb]; |
| 69807 | u.az.pX = u.az.pDb->pBt; |
| 69808 | assert( u.az.pX!=0 ); |
| 69809 | if( pOp->opcode==OP_OpenWrite ){ |
| 69810 | u.az.wrFlag = 1; |
| 69811 | assert( sqlite3SchemaMutexHeld(db, u.az.iDb, 0) ); |
| 69812 | if( u.az.pDb->pSchema->file_format < p->minWriteFileFormat ){ |
| 69813 | p->minWriteFileFormat = u.az.pDb->pSchema->file_format; |
| 69814 | } |
| 69815 | }else{ |
| 69816 | u.az.wrFlag = 0; |
| 69817 | } |
| 69818 | if( pOp->p5 & OPFLAG_P2ISREG ){ |
| 69819 | assert( u.az.p2>0 ); |
| 69820 | assert( u.az.p2<=(p->nMem-p->nCursor) ); |
| 69821 | pIn2 = &aMem[u.az.p2]; |
| 69822 | assert( memIsValid(pIn2) ); |
| 69823 | assert( (pIn2->flags & MEM_Int)!=0 ); |
| 69824 | sqlite3VdbeMemIntegerify(pIn2); |
| 69825 | u.az.p2 = (int)pIn2->u.i; |
| 69826 | /* The u.az.p2 value always comes from a prior OP_CreateTable opcode and |
| 69827 | ** that opcode will always set the u.az.p2 value to 2 or more or else fail. |
| 69828 | ** If there were a failure, the prepared statement would have halted |
| 69829 | ** before reaching this instruction. */ |
| 69830 | if( NEVER(u.az.p2<2) ) { |
| 69831 | rc = SQLITE_CORRUPT_BKPT; |
| 69832 | goto abort_due_to_error; |
| 69833 | } |
| 69834 | } |
| 69835 | if( pOp->p4type==P4_KEYINFO ){ |
| 69836 | u.az.pKeyInfo = pOp->p4.pKeyInfo; |
| 69837 | assert( u.az.pKeyInfo->enc==ENC(db) ); |
| 69838 | assert( u.az.pKeyInfo->db==db ); |
| 69839 | u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField; |
| 69840 | }else if( pOp->p4type==P4_INT32 ){ |
| 69841 | u.az.nField = pOp->p4.i; |
| 69842 | } |
| 69843 | assert( pOp->p1>=0 ); |
| 69844 | assert( u.az.nField>=0 ); |
| 69845 | testcase( u.az.nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ |
| 69846 | u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1); |
| 69847 | if( u.az.pCur==0 ) goto no_mem; |
| 69848 | u.az.pCur->nullRow = 1; |
| 69849 | u.az.pCur->isOrdered = 1; |
| 69850 | rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor); |
| 69851 | u.az.pCur->pKeyInfo = u.az.pKeyInfo; |
| 69852 | assert( OPFLAG_BULKCSR==BTREE_BULKLOAD ); |
| 69853 | sqlite3BtreeCursorHints(u.az.pCur->pCursor, (pOp->p5 & OPFLAG_BULKCSR)); |
| 69854 | |
| 69855 | /* Since it performs no memory allocation or IO, the only value that |
| 69856 | ** sqlite3BtreeCursor() may return is SQLITE_OK. */ |
| 69857 | assert( rc==SQLITE_OK ); |
| 69858 | |
| 69859 | /* Set the VdbeCursor.isTable variable. Previous versions of |
| 69860 | ** SQLite used to check if the root-page flags were sane at this point |
| 69861 | ** and report database corruption if they were not, but this check has |
| 69862 | ** since moved into the btree layer. */ |
| 69863 | u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO; |
| 69864 | break; |
| 69865 | } |
| 69866 | |
| 69867 | /* Opcode: OpenEphemeral P1 P2 * P4 P5 |
| 69868 | ** Synopsis: nColumn=P2 |
| @@ -69642,53 +69890,55 @@ | |
| 69890 | ** by this opcode will be used for automatically created transient |
| 69891 | ** indices in joins. |
| 69892 | */ |
| 69893 | case OP_OpenAutoindex: |
| 69894 | case OP_OpenEphemeral: { |
| 69895 | #if 0 /* local variables moved into u.ba */ |
| 69896 | VdbeCursor *pCx; |
| 69897 | KeyInfo *pKeyInfo; |
| 69898 | #endif /* local variables moved into u.ba */ |
| 69899 | |
| 69900 | static const int vfsFlags = |
| 69901 | SQLITE_OPEN_READWRITE | |
| 69902 | SQLITE_OPEN_CREATE | |
| 69903 | SQLITE_OPEN_EXCLUSIVE | |
| 69904 | SQLITE_OPEN_DELETEONCLOSE | |
| 69905 | SQLITE_OPEN_TRANSIENT_DB; |
| 69906 | assert( pOp->p1>=0 ); |
| 69907 | assert( pOp->p2>=0 ); |
| 69908 | u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69909 | if( u.ba.pCx==0 ) goto no_mem; |
| 69910 | u.ba.pCx->nullRow = 1; |
| 69911 | rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt, |
| 69912 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| 69913 | if( rc==SQLITE_OK ){ |
| 69914 | rc = sqlite3BtreeBeginTrans(u.ba.pCx->pBt, 1); |
| 69915 | } |
| 69916 | if( rc==SQLITE_OK ){ |
| 69917 | /* If a transient index is required, create it by calling |
| 69918 | ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before |
| 69919 | ** opening it. If a transient table is required, just use the |
| 69920 | ** automatically created table with root-page 1 (an BLOB_INTKEY table). |
| 69921 | */ |
| 69922 | if( (u.ba.pKeyInfo = pOp->p4.pKeyInfo)!=0 ){ |
| 69923 | int pgno; |
| 69924 | assert( pOp->p4type==P4_KEYINFO ); |
| 69925 | rc = sqlite3BtreeCreateTable(u.ba.pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5); |
| 69926 | if( rc==SQLITE_OK ){ |
| 69927 | assert( pgno==MASTER_ROOT+1 ); |
| 69928 | assert( u.ba.pKeyInfo->db==db ); |
| 69929 | assert( u.ba.pKeyInfo->enc==ENC(db) ); |
| 69930 | u.ba.pCx->pKeyInfo = u.ba.pKeyInfo; |
| 69931 | rc = sqlite3BtreeCursor(u.ba.pCx->pBt, pgno, 1, u.ba.pKeyInfo, u.ba.pCx->pCursor); |
| 69932 | } |
| 69933 | u.ba.pCx->isTable = 0; |
| 69934 | }else{ |
| 69935 | rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor); |
| 69936 | u.ba.pCx->isTable = 1; |
| 69937 | } |
| 69938 | } |
| 69939 | u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 69940 | break; |
| 69941 | } |
| 69942 | |
| 69943 | /* Opcode: SorterOpen P1 * * P4 * |
| 69944 | ** |
| @@ -69695,20 +69945,22 @@ | |
| 69945 | ** This opcode works like OP_OpenEphemeral except that it opens |
| 69946 | ** a transient index that is specifically designed to sort large |
| 69947 | ** tables using an external merge-sort algorithm. |
| 69948 | */ |
| 69949 | case OP_SorterOpen: { |
| 69950 | #if 0 /* local variables moved into u.bb */ |
| 69951 | VdbeCursor *pCx; |
| 69952 | #endif /* local variables moved into u.bb */ |
| 69953 | |
| 69954 | assert( pOp->p1>=0 ); |
| 69955 | assert( pOp->p2>=0 ); |
| 69956 | u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69957 | if( u.bb.pCx==0 ) goto no_mem; |
| 69958 | u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo; |
| 69959 | assert( u.bb.pCx->pKeyInfo->db==db ); |
| 69960 | assert( u.bb.pCx->pKeyInfo->enc==ENC(db) ); |
| 69961 | rc = sqlite3VdbeSorterInit(db, u.bb.pCx); |
| 69962 | break; |
| 69963 | } |
| 69964 | |
| 69965 | /* Opcode: OpenPseudo P1 P2 P3 * P5 |
| 69966 | ** Synopsis: content in r[P2@P3] |
| @@ -69726,20 +69978,22 @@ | |
| 69978 | ** |
| 69979 | ** P3 is the number of fields in the records that will be stored by |
| 69980 | ** the pseudo-table. |
| 69981 | */ |
| 69982 | case OP_OpenPseudo: { |
| 69983 | #if 0 /* local variables moved into u.bc */ |
| 69984 | VdbeCursor *pCx; |
| 69985 | #endif /* local variables moved into u.bc */ |
| 69986 | |
| 69987 | assert( pOp->p1>=0 ); |
| 69988 | assert( pOp->p3>=0 ); |
| 69989 | u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); |
| 69990 | if( u.bc.pCx==0 ) goto no_mem; |
| 69991 | u.bc.pCx->nullRow = 1; |
| 69992 | u.bc.pCx->pseudoTableReg = pOp->p2; |
| 69993 | u.bc.pCx->isTable = 1; |
| 69994 | u.bc.pCx->multiPseudo = pOp->p5; |
| 69995 | break; |
| 69996 | } |
| 69997 | |
| 69998 | /* Opcode: Close P1 * * * * |
| 69999 | ** |
| @@ -69811,37 +70065,39 @@ | |
| 70065 | */ |
| 70066 | case OP_SeekLt: /* jump, in3 */ |
| 70067 | case OP_SeekLe: /* jump, in3 */ |
| 70068 | case OP_SeekGe: /* jump, in3 */ |
| 70069 | case OP_SeekGt: { /* jump, in3 */ |
| 70070 | #if 0 /* local variables moved into u.bd */ |
| 70071 | int res; |
| 70072 | int oc; |
| 70073 | VdbeCursor *pC; |
| 70074 | UnpackedRecord r; |
| 70075 | int nField; |
| 70076 | i64 iKey; /* The rowid we are to seek to */ |
| 70077 | #endif /* local variables moved into u.bd */ |
| 70078 | |
| 70079 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70080 | assert( pOp->p2!=0 ); |
| 70081 | u.bd.pC = p->apCsr[pOp->p1]; |
| 70082 | assert( u.bd.pC!=0 ); |
| 70083 | assert( u.bd.pC->pseudoTableReg==0 ); |
| 70084 | assert( OP_SeekLe == OP_SeekLt+1 ); |
| 70085 | assert( OP_SeekGe == OP_SeekLt+2 ); |
| 70086 | assert( OP_SeekGt == OP_SeekLt+3 ); |
| 70087 | assert( u.bd.pC->isOrdered ); |
| 70088 | assert( u.bd.pC->pCursor!=0 ); |
| 70089 | u.bd.oc = pOp->opcode; |
| 70090 | u.bd.pC->nullRow = 0; |
| 70091 | if( u.bd.pC->isTable ){ |
| 70092 | /* The input value in P3 might be of any type: integer, real, string, |
| 70093 | ** blob, or NULL. But it needs to be an integer before we can do |
| 70094 | ** the seek, so covert it. */ |
| 70095 | pIn3 = &aMem[pOp->p3]; |
| 70096 | applyNumericAffinity(pIn3); |
| 70097 | u.bd.iKey = sqlite3VdbeIntValue(pIn3); |
| 70098 | u.bd.pC->rowidIsValid = 0; |
| 70099 | |
| 70100 | /* If the P3 value could not be converted into an integer without |
| 70101 | ** loss of information, then special processing is required... */ |
| 70102 | if( (pIn3->flags & MEM_Int)==0 ){ |
| 70103 | if( (pIn3->flags & MEM_Real)==0 ){ |
| @@ -69849,100 +70105,100 @@ | |
| 70105 | ** then the seek is not possible, so jump to P2 */ |
| 70106 | pc = pOp->p2 - 1; |
| 70107 | break; |
| 70108 | } |
| 70109 | |
| 70110 | /* If the approximation u.bd.iKey is larger than the actual real search |
| 70111 | ** term, substitute >= for > and < for <=. e.g. if the search term |
| 70112 | ** is 4.9 and the integer approximation 5: |
| 70113 | ** |
| 70114 | ** (x > 4.9) -> (x >= 5) |
| 70115 | ** (x <= 4.9) -> (x < 5) |
| 70116 | */ |
| 70117 | if( pIn3->r<(double)u.bd.iKey ){ |
| 70118 | assert( OP_SeekGe==(OP_SeekGt-1) ); |
| 70119 | assert( OP_SeekLt==(OP_SeekLe-1) ); |
| 70120 | assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); |
| 70121 | if( (u.bd.oc & 0x0001)==(OP_SeekGt & 0x0001) ) u.bd.oc--; |
| 70122 | } |
| 70123 | |
| 70124 | /* If the approximation u.bd.iKey is smaller than the actual real search |
| 70125 | ** term, substitute <= for < and > for >=. */ |
| 70126 | else if( pIn3->r>(double)u.bd.iKey ){ |
| 70127 | assert( OP_SeekLe==(OP_SeekLt+1) ); |
| 70128 | assert( OP_SeekGt==(OP_SeekGe+1) ); |
| 70129 | assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); |
| 70130 | if( (u.bd.oc & 0x0001)==(OP_SeekLt & 0x0001) ) u.bd.oc++; |
| 70131 | } |
| 70132 | } |
| 70133 | rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, 0, (u64)u.bd.iKey, 0, &u.bd.res); |
| 70134 | if( rc!=SQLITE_OK ){ |
| 70135 | goto abort_due_to_error; |
| 70136 | } |
| 70137 | if( u.bd.res==0 ){ |
| 70138 | u.bd.pC->rowidIsValid = 1; |
| 70139 | u.bd.pC->lastRowid = u.bd.iKey; |
| 70140 | } |
| 70141 | }else{ |
| 70142 | u.bd.nField = pOp->p4.i; |
| 70143 | assert( pOp->p4type==P4_INT32 ); |
| 70144 | assert( u.bd.nField>0 ); |
| 70145 | u.bd.r.pKeyInfo = u.bd.pC->pKeyInfo; |
| 70146 | u.bd.r.nField = (u16)u.bd.nField; |
| 70147 | |
| 70148 | /* The next line of code computes as follows, only faster: |
| 70149 | ** if( u.bd.oc==OP_SeekGt || u.bd.oc==OP_SeekLe ){ |
| 70150 | ** u.bd.r.flags = UNPACKED_INCRKEY; |
| 70151 | ** }else{ |
| 70152 | ** u.bd.r.flags = 0; |
| 70153 | ** } |
| 70154 | */ |
| 70155 | u.bd.r.flags = (u8)(UNPACKED_INCRKEY * (1 & (u.bd.oc - OP_SeekLt))); |
| 70156 | assert( u.bd.oc!=OP_SeekGt || u.bd.r.flags==UNPACKED_INCRKEY ); |
| 70157 | assert( u.bd.oc!=OP_SeekLe || u.bd.r.flags==UNPACKED_INCRKEY ); |
| 70158 | assert( u.bd.oc!=OP_SeekGe || u.bd.r.flags==0 ); |
| 70159 | assert( u.bd.oc!=OP_SeekLt || u.bd.r.flags==0 ); |
| 70160 | |
| 70161 | u.bd.r.aMem = &aMem[pOp->p3]; |
| 70162 | #ifdef SQLITE_DEBUG |
| 70163 | { int i; for(i=0; i<u.bd.r.nField; i++) assert( memIsValid(&u.bd.r.aMem[i]) ); } |
| 70164 | #endif |
| 70165 | ExpandBlob(u.bd.r.aMem); |
| 70166 | rc = sqlite3BtreeMovetoUnpacked(u.bd.pC->pCursor, &u.bd.r, 0, 0, &u.bd.res); |
| 70167 | if( rc!=SQLITE_OK ){ |
| 70168 | goto abort_due_to_error; |
| 70169 | } |
| 70170 | u.bd.pC->rowidIsValid = 0; |
| 70171 | } |
| 70172 | u.bd.pC->deferredMoveto = 0; |
| 70173 | u.bd.pC->cacheStatus = CACHE_STALE; |
| 70174 | #ifdef SQLITE_TEST |
| 70175 | sqlite3_search_count++; |
| 70176 | #endif |
| 70177 | if( u.bd.oc>=OP_SeekGe ){ assert( u.bd.oc==OP_SeekGe || u.bd.oc==OP_SeekGt ); |
| 70178 | if( u.bd.res<0 || (u.bd.res==0 && u.bd.oc==OP_SeekGt) ){ |
| 70179 | rc = sqlite3BtreeNext(u.bd.pC->pCursor, &u.bd.res); |
| 70180 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 70181 | u.bd.pC->rowidIsValid = 0; |
| 70182 | }else{ |
| 70183 | u.bd.res = 0; |
| 70184 | } |
| 70185 | }else{ |
| 70186 | assert( u.bd.oc==OP_SeekLt || u.bd.oc==OP_SeekLe ); |
| 70187 | if( u.bd.res>0 || (u.bd.res==0 && u.bd.oc==OP_SeekLt) ){ |
| 70188 | rc = sqlite3BtreePrevious(u.bd.pC->pCursor, &u.bd.res); |
| 70189 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 70190 | u.bd.pC->rowidIsValid = 0; |
| 70191 | }else{ |
| 70192 | /* u.bd.res might be negative because the table is empty. Check to |
| 70193 | ** see if this is the case. |
| 70194 | */ |
| 70195 | u.bd.res = sqlite3BtreeEof(u.bd.pC->pCursor); |
| 70196 | } |
| 70197 | } |
| 70198 | assert( pOp->p2>0 ); |
| 70199 | if( u.bd.res ){ |
| 70200 | pc = pOp->p2 - 1; |
| 70201 | } |
| 70202 | break; |
| 70203 | } |
| 70204 | |
| @@ -69955,22 +70211,24 @@ | |
| 70211 | ** This is actually a deferred seek. Nothing actually happens until |
| 70212 | ** the cursor is used to read a record. That way, if no reads |
| 70213 | ** occur, no unnecessary I/O happens. |
| 70214 | */ |
| 70215 | case OP_Seek: { /* in2 */ |
| 70216 | #if 0 /* local variables moved into u.be */ |
| 70217 | VdbeCursor *pC; |
| 70218 | #endif /* local variables moved into u.be */ |
| 70219 | |
| 70220 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70221 | u.be.pC = p->apCsr[pOp->p1]; |
| 70222 | assert( u.be.pC!=0 ); |
| 70223 | assert( u.be.pC->pCursor!=0 ); |
| 70224 | assert( u.be.pC->isTable ); |
| 70225 | u.be.pC->nullRow = 0; |
| 70226 | pIn2 = &aMem[pOp->p2]; |
| 70227 | u.be.pC->movetoTarget = sqlite3VdbeIntValue(pIn2); |
| 70228 | u.be.pC->rowidIsValid = 0; |
| 70229 | u.be.pC->deferredMoveto = 1; |
| 70230 | break; |
| 70231 | } |
| 70232 | |
| 70233 | |
| 70234 | /* Opcode: Found P1 P2 P3 P4 * |
| @@ -70021,83 +70279,85 @@ | |
| 70279 | ** See also: NotFound, Found, NotExists |
| 70280 | */ |
| 70281 | case OP_NoConflict: /* jump, in3 */ |
| 70282 | case OP_NotFound: /* jump, in3 */ |
| 70283 | case OP_Found: { /* jump, in3 */ |
| 70284 | #if 0 /* local variables moved into u.bf */ |
| 70285 | int alreadyExists; |
| 70286 | int ii; |
| 70287 | VdbeCursor *pC; |
| 70288 | int res; |
| 70289 | char *pFree; |
| 70290 | UnpackedRecord *pIdxKey; |
| 70291 | UnpackedRecord r; |
| 70292 | char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7]; |
| 70293 | #endif /* local variables moved into u.bf */ |
| 70294 | |
| 70295 | #ifdef SQLITE_TEST |
| 70296 | if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++; |
| 70297 | #endif |
| 70298 | |
| 70299 | u.bf.alreadyExists = 0; |
| 70300 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70301 | assert( pOp->p4type==P4_INT32 ); |
| 70302 | u.bf.pC = p->apCsr[pOp->p1]; |
| 70303 | assert( u.bf.pC!=0 ); |
| 70304 | pIn3 = &aMem[pOp->p3]; |
| 70305 | assert( u.bf.pC->pCursor!=0 ); |
| 70306 | assert( u.bf.pC->isTable==0 ); |
| 70307 | if( pOp->p4.i>0 ){ |
| 70308 | u.bf.r.pKeyInfo = u.bf.pC->pKeyInfo; |
| 70309 | u.bf.r.nField = (u16)pOp->p4.i; |
| 70310 | u.bf.r.aMem = pIn3; |
| 70311 | #ifdef SQLITE_DEBUG |
| 70312 | { |
| 70313 | int i; |
| 70314 | for(i=0; i<u.bf.r.nField; i++){ |
| 70315 | assert( memIsValid(&u.bf.r.aMem[i]) ); |
| 70316 | if( i ) REGISTER_TRACE(pOp->p3+i, &u.bf.r.aMem[i]); |
| 70317 | } |
| 70318 | } |
| 70319 | #endif |
| 70320 | u.bf.r.flags = UNPACKED_PREFIX_MATCH; |
| 70321 | u.bf.pIdxKey = &u.bf.r; |
| 70322 | }else{ |
| 70323 | u.bf.pIdxKey = sqlite3VdbeAllocUnpackedRecord( |
| 70324 | u.bf.pC->pKeyInfo, u.bf.aTempRec, sizeof(u.bf.aTempRec), &u.bf.pFree |
| 70325 | ); |
| 70326 | if( u.bf.pIdxKey==0 ) goto no_mem; |
| 70327 | assert( pIn3->flags & MEM_Blob ); |
| 70328 | assert( (pIn3->flags & MEM_Zero)==0 ); /* zeroblobs already expanded */ |
| 70329 | sqlite3VdbeRecordUnpack(u.bf.pC->pKeyInfo, pIn3->n, pIn3->z, u.bf.pIdxKey); |
| 70330 | u.bf.pIdxKey->flags |= UNPACKED_PREFIX_MATCH; |
| 70331 | } |
| 70332 | if( pOp->opcode==OP_NoConflict ){ |
| 70333 | /* For the OP_NoConflict opcode, take the jump if any of the |
| 70334 | ** input fields are NULL, since any key with a NULL will not |
| 70335 | ** conflict */ |
| 70336 | for(u.bf.ii=0; u.bf.ii<u.bf.r.nField; u.bf.ii++){ |
| 70337 | if( u.bf.r.aMem[u.bf.ii].flags & MEM_Null ){ |
| 70338 | pc = pOp->p2 - 1; |
| 70339 | break; |
| 70340 | } |
| 70341 | } |
| 70342 | } |
| 70343 | rc = sqlite3BtreeMovetoUnpacked(u.bf.pC->pCursor, u.bf.pIdxKey, 0, 0, &u.bf.res); |
| 70344 | if( pOp->p4.i==0 ){ |
| 70345 | sqlite3DbFree(db, u.bf.pFree); |
| 70346 | } |
| 70347 | if( rc!=SQLITE_OK ){ |
| 70348 | break; |
| 70349 | } |
| 70350 | u.bf.pC->seekResult = u.bf.res; |
| 70351 | u.bf.alreadyExists = (u.bf.res==0); |
| 70352 | u.bf.pC->nullRow = 1-u.bf.alreadyExists; |
| 70353 | u.bf.pC->deferredMoveto = 0; |
| 70354 | u.bf.pC->cacheStatus = CACHE_STALE; |
| 70355 | if( pOp->opcode==OP_Found ){ |
| 70356 | if( u.bf.alreadyExists ) pc = pOp->p2 - 1; |
| 70357 | }else{ |
| 70358 | if( !u.bf.alreadyExists ) pc = pOp->p2 - 1; |
| 70359 | } |
| 70360 | break; |
| 70361 | } |
| 70362 | |
| 70363 | /* Opcode: NotExists P1 P2 P3 * * |
| @@ -70113,37 +70373,39 @@ | |
| 70373 | ** (with arbitrary multi-value keys). |
| 70374 | ** |
| 70375 | ** See also: Found, NotFound, NoConflict |
| 70376 | */ |
| 70377 | case OP_NotExists: { /* jump, in3 */ |
| 70378 | #if 0 /* local variables moved into u.bg */ |
| 70379 | VdbeCursor *pC; |
| 70380 | BtCursor *pCrsr; |
| 70381 | int res; |
| 70382 | u64 iKey; |
| 70383 | #endif /* local variables moved into u.bg */ |
| 70384 | |
| 70385 | pIn3 = &aMem[pOp->p3]; |
| 70386 | assert( pIn3->flags & MEM_Int ); |
| 70387 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70388 | u.bg.pC = p->apCsr[pOp->p1]; |
| 70389 | assert( u.bg.pC!=0 ); |
| 70390 | assert( u.bg.pC->isTable ); |
| 70391 | assert( u.bg.pC->pseudoTableReg==0 ); |
| 70392 | u.bg.pCrsr = u.bg.pC->pCursor; |
| 70393 | assert( u.bg.pCrsr!=0 ); |
| 70394 | u.bg.res = 0; |
| 70395 | u.bg.iKey = pIn3->u.i; |
| 70396 | rc = sqlite3BtreeMovetoUnpacked(u.bg.pCrsr, 0, u.bg.iKey, 0, &u.bg.res); |
| 70397 | u.bg.pC->lastRowid = pIn3->u.i; |
| 70398 | u.bg.pC->rowidIsValid = u.bg.res==0 ?1:0; |
| 70399 | u.bg.pC->nullRow = 0; |
| 70400 | u.bg.pC->cacheStatus = CACHE_STALE; |
| 70401 | u.bg.pC->deferredMoveto = 0; |
| 70402 | if( u.bg.res!=0 ){ |
| 70403 | pc = pOp->p2 - 1; |
| 70404 | assert( u.bg.pC->rowidIsValid==0 ); |
| 70405 | } |
| 70406 | u.bg.pC->seekResult = u.bg.res; |
| 70407 | break; |
| 70408 | } |
| 70409 | |
| 70410 | /* Opcode: Sequence P1 P2 * * * |
| 70411 | ** Synopsis: r[P2]=rowid |
| @@ -70175,23 +70437,25 @@ | |
| 70437 | ** an SQLITE_FULL error is generated. The P3 register is updated with the ' |
| 70438 | ** generated record number. This P3 mechanism is used to help implement the |
| 70439 | ** AUTOINCREMENT feature. |
| 70440 | */ |
| 70441 | case OP_NewRowid: { /* out2-prerelease */ |
| 70442 | #if 0 /* local variables moved into u.bh */ |
| 70443 | i64 v; /* The new rowid */ |
| 70444 | VdbeCursor *pC; /* Cursor of table to get the new rowid */ |
| 70445 | int res; /* Result of an sqlite3BtreeLast() */ |
| 70446 | int cnt; /* Counter to limit the number of searches */ |
| 70447 | Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */ |
| 70448 | VdbeFrame *pFrame; /* Root frame of VDBE */ |
| 70449 | #endif /* local variables moved into u.bh */ |
| 70450 | |
| 70451 | u.bh.v = 0; |
| 70452 | u.bh.res = 0; |
| 70453 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70454 | u.bh.pC = p->apCsr[pOp->p1]; |
| 70455 | assert( u.bh.pC!=0 ); |
| 70456 | if( NEVER(u.bh.pC->pCursor==0) ){ |
| 70457 | /* The zero initialization above is all that is needed */ |
| 70458 | }else{ |
| 70459 | /* The next rowid or record number (different terms for the same |
| 70460 | ** thing) is obtained in a two-step algorithm. |
| 70461 | ** |
| @@ -70203,11 +70467,11 @@ | |
| 70467 | ** The second algorithm is to select a rowid at random and see if |
| 70468 | ** it already exists in the table. If it does not exist, we have |
| 70469 | ** succeeded. If the random rowid does exist, we select a new one |
| 70470 | ** and try again, up to 100 times. |
| 70471 | */ |
| 70472 | assert( u.bh.pC->isTable ); |
| 70473 | |
| 70474 | #ifdef SQLITE_32BIT_ROWID |
| 70475 | # define MAX_ROWID 0x7fffffff |
| 70476 | #else |
| 70477 | /* Some compilers complain about constants of the form 0x7fffffffffffffff. |
| @@ -70215,101 +70479,101 @@ | |
| 70479 | ** to provide the constant while making all compilers happy. |
| 70480 | */ |
| 70481 | # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff ) |
| 70482 | #endif |
| 70483 | |
| 70484 | if( !u.bh.pC->useRandomRowid ){ |
| 70485 | u.bh.v = sqlite3BtreeGetCachedRowid(u.bh.pC->pCursor); |
| 70486 | if( u.bh.v==0 ){ |
| 70487 | rc = sqlite3BtreeLast(u.bh.pC->pCursor, &u.bh.res); |
| 70488 | if( rc!=SQLITE_OK ){ |
| 70489 | goto abort_due_to_error; |
| 70490 | } |
| 70491 | if( u.bh.res ){ |
| 70492 | u.bh.v = 1; /* IMP: R-61914-48074 */ |
| 70493 | }else{ |
| 70494 | assert( sqlite3BtreeCursorIsValid(u.bh.pC->pCursor) ); |
| 70495 | rc = sqlite3BtreeKeySize(u.bh.pC->pCursor, &u.bh.v); |
| 70496 | assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */ |
| 70497 | if( u.bh.v>=MAX_ROWID ){ |
| 70498 | u.bh.pC->useRandomRowid = 1; |
| 70499 | }else{ |
| 70500 | u.bh.v++; /* IMP: R-29538-34987 */ |
| 70501 | } |
| 70502 | } |
| 70503 | } |
| 70504 | |
| 70505 | #ifndef SQLITE_OMIT_AUTOINCREMENT |
| 70506 | if( pOp->p3 ){ |
| 70507 | /* Assert that P3 is a valid memory cell. */ |
| 70508 | assert( pOp->p3>0 ); |
| 70509 | if( p->pFrame ){ |
| 70510 | for(u.bh.pFrame=p->pFrame; u.bh.pFrame->pParent; u.bh.pFrame=u.bh.pFrame->pParent); |
| 70511 | /* Assert that P3 is a valid memory cell. */ |
| 70512 | assert( pOp->p3<=u.bh.pFrame->nMem ); |
| 70513 | u.bh.pMem = &u.bh.pFrame->aMem[pOp->p3]; |
| 70514 | }else{ |
| 70515 | /* Assert that P3 is a valid memory cell. */ |
| 70516 | assert( pOp->p3<=(p->nMem-p->nCursor) ); |
| 70517 | u.bh.pMem = &aMem[pOp->p3]; |
| 70518 | memAboutToChange(p, u.bh.pMem); |
| 70519 | } |
| 70520 | assert( memIsValid(u.bh.pMem) ); |
| 70521 | |
| 70522 | REGISTER_TRACE(pOp->p3, u.bh.pMem); |
| 70523 | sqlite3VdbeMemIntegerify(u.bh.pMem); |
| 70524 | assert( (u.bh.pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */ |
| 70525 | if( u.bh.pMem->u.i==MAX_ROWID || u.bh.pC->useRandomRowid ){ |
| 70526 | rc = SQLITE_FULL; /* IMP: R-12275-61338 */ |
| 70527 | goto abort_due_to_error; |
| 70528 | } |
| 70529 | if( u.bh.v<u.bh.pMem->u.i+1 ){ |
| 70530 | u.bh.v = u.bh.pMem->u.i + 1; |
| 70531 | } |
| 70532 | u.bh.pMem->u.i = u.bh.v; |
| 70533 | } |
| 70534 | #endif |
| 70535 | |
| 70536 | sqlite3BtreeSetCachedRowid(u.bh.pC->pCursor, u.bh.v<MAX_ROWID ? u.bh.v+1 : 0); |
| 70537 | } |
| 70538 | if( u.bh.pC->useRandomRowid ){ |
| 70539 | /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the |
| 70540 | ** largest possible integer (9223372036854775807) then the database |
| 70541 | ** engine starts picking positive candidate ROWIDs at random until |
| 70542 | ** it finds one that is not previously used. */ |
| 70543 | assert( pOp->p3==0 ); /* We cannot be in random rowid mode if this is |
| 70544 | ** an AUTOINCREMENT table. */ |
| 70545 | /* on the first attempt, simply do one more than previous */ |
| 70546 | u.bh.v = lastRowid; |
| 70547 | u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 70548 | u.bh.v++; /* ensure non-zero */ |
| 70549 | u.bh.cnt = 0; |
| 70550 | while( ((rc = sqlite3BtreeMovetoUnpacked(u.bh.pC->pCursor, 0, (u64)u.bh.v, |
| 70551 | 0, &u.bh.res))==SQLITE_OK) |
| 70552 | && (u.bh.res==0) |
| 70553 | && (++u.bh.cnt<100)){ |
| 70554 | /* collision - try another random rowid */ |
| 70555 | sqlite3_randomness(sizeof(u.bh.v), &u.bh.v); |
| 70556 | if( u.bh.cnt<5 ){ |
| 70557 | /* try "small" random rowids for the initial attempts */ |
| 70558 | u.bh.v &= 0xffffff; |
| 70559 | }else{ |
| 70560 | u.bh.v &= (MAX_ROWID>>1); /* ensure doesn't go negative */ |
| 70561 | } |
| 70562 | u.bh.v++; /* ensure non-zero */ |
| 70563 | } |
| 70564 | if( rc==SQLITE_OK && u.bh.res==0 ){ |
| 70565 | rc = SQLITE_FULL; /* IMP: R-38219-53002 */ |
| 70566 | goto abort_due_to_error; |
| 70567 | } |
| 70568 | assert( u.bh.v>0 ); /* EV: R-40812-03570 */ |
| 70569 | } |
| 70570 | u.bh.pC->rowidIsValid = 0; |
| 70571 | u.bh.pC->deferredMoveto = 0; |
| 70572 | u.bh.pC->cacheStatus = CACHE_STALE; |
| 70573 | } |
| 70574 | pOut->u.i = u.bh.v; |
| 70575 | break; |
| 70576 | } |
| 70577 | |
| 70578 | /* Opcode: Insert P1 P2 P3 P4 P5 |
| 70579 | ** Synopsis: intkey=r[P3] data=r[P2] |
| @@ -70357,72 +70621,74 @@ | |
| 70621 | ** This works exactly like OP_Insert except that the key is the |
| 70622 | ** integer value P3, not the value of the integer stored in register P3. |
| 70623 | */ |
| 70624 | case OP_Insert: |
| 70625 | case OP_InsertInt: { |
| 70626 | #if 0 /* local variables moved into u.bi */ |
| 70627 | Mem *pData; /* MEM cell holding data for the record to be inserted */ |
| 70628 | Mem *pKey; /* MEM cell holding key for the record */ |
| 70629 | i64 iKey; /* The integer ROWID or key for the record to be inserted */ |
| 70630 | VdbeCursor *pC; /* Cursor to table into which insert is written */ |
| 70631 | int nZero; /* Number of zero-bytes to append */ |
| 70632 | int seekResult; /* Result of prior seek or 0 if no USESEEKRESULT flag */ |
| 70633 | const char *zDb; /* database name - used by the update hook */ |
| 70634 | const char *zTbl; /* Table name - used by the opdate hook */ |
| 70635 | int op; /* Opcode for update hook: SQLITE_UPDATE or SQLITE_INSERT */ |
| 70636 | #endif /* local variables moved into u.bi */ |
| 70637 | |
| 70638 | u.bi.pData = &aMem[pOp->p2]; |
| 70639 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70640 | assert( memIsValid(u.bi.pData) ); |
| 70641 | u.bi.pC = p->apCsr[pOp->p1]; |
| 70642 | assert( u.bi.pC!=0 ); |
| 70643 | assert( u.bi.pC->pCursor!=0 ); |
| 70644 | assert( u.bi.pC->pseudoTableReg==0 ); |
| 70645 | assert( u.bi.pC->isTable ); |
| 70646 | REGISTER_TRACE(pOp->p2, u.bi.pData); |
| 70647 | |
| 70648 | if( pOp->opcode==OP_Insert ){ |
| 70649 | u.bi.pKey = &aMem[pOp->p3]; |
| 70650 | assert( u.bi.pKey->flags & MEM_Int ); |
| 70651 | assert( memIsValid(u.bi.pKey) ); |
| 70652 | REGISTER_TRACE(pOp->p3, u.bi.pKey); |
| 70653 | u.bi.iKey = u.bi.pKey->u.i; |
| 70654 | }else{ |
| 70655 | assert( pOp->opcode==OP_InsertInt ); |
| 70656 | u.bi.iKey = pOp->p3; |
| 70657 | } |
| 70658 | |
| 70659 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 70660 | if( pOp->p5 & OPFLAG_LASTROWID ) db->lastRowid = lastRowid = u.bi.iKey; |
| 70661 | if( u.bi.pData->flags & MEM_Null ){ |
| 70662 | u.bi.pData->z = 0; |
| 70663 | u.bi.pData->n = 0; |
| 70664 | }else{ |
| 70665 | assert( u.bi.pData->flags & (MEM_Blob|MEM_Str) ); |
| 70666 | } |
| 70667 | u.bi.seekResult = ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bi.pC->seekResult : 0); |
| 70668 | if( u.bi.pData->flags & MEM_Zero ){ |
| 70669 | u.bi.nZero = u.bi.pData->u.nZero; |
| 70670 | }else{ |
| 70671 | u.bi.nZero = 0; |
| 70672 | } |
| 70673 | sqlite3BtreeSetCachedRowid(u.bi.pC->pCursor, 0); |
| 70674 | rc = sqlite3BtreeInsert(u.bi.pC->pCursor, 0, u.bi.iKey, |
| 70675 | u.bi.pData->z, u.bi.pData->n, u.bi.nZero, |
| 70676 | (pOp->p5 & OPFLAG_APPEND)!=0, u.bi.seekResult |
| 70677 | ); |
| 70678 | u.bi.pC->rowidIsValid = 0; |
| 70679 | u.bi.pC->deferredMoveto = 0; |
| 70680 | u.bi.pC->cacheStatus = CACHE_STALE; |
| 70681 | |
| 70682 | /* Invoke the update-hook if required. */ |
| 70683 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){ |
| 70684 | u.bi.zDb = db->aDb[u.bi.pC->iDb].zName; |
| 70685 | u.bi.zTbl = pOp->p4.z; |
| 70686 | u.bi.op = ((pOp->p5 & OPFLAG_ISUPDATE) ? SQLITE_UPDATE : SQLITE_INSERT); |
| 70687 | assert( u.bi.pC->isTable ); |
| 70688 | db->xUpdateCallback(db->pUpdateArg, u.bi.op, u.bi.zDb, u.bi.zTbl, u.bi.iKey); |
| 70689 | assert( u.bi.pC->iDb>=0 ); |
| 70690 | } |
| 70691 | break; |
| 70692 | } |
| 70693 | |
| 70694 | /* Opcode: Delete P1 P2 * P4 * |
| @@ -70444,39 +70710,41 @@ | |
| 70710 | ** pointing to. The update hook will be invoked, if it exists. |
| 70711 | ** If P4 is not NULL then the P1 cursor must have been positioned |
| 70712 | ** using OP_NotFound prior to invoking this opcode. |
| 70713 | */ |
| 70714 | case OP_Delete: { |
| 70715 | #if 0 /* local variables moved into u.bj */ |
| 70716 | i64 iKey; |
| 70717 | VdbeCursor *pC; |
| 70718 | #endif /* local variables moved into u.bj */ |
| 70719 | |
| 70720 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70721 | u.bj.pC = p->apCsr[pOp->p1]; |
| 70722 | assert( u.bj.pC!=0 ); |
| 70723 | assert( u.bj.pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ |
| 70724 | u.bj.iKey = u.bj.pC->lastRowid; /* Only used for the update hook */ |
| 70725 | |
| 70726 | /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or |
| 70727 | ** OP_Column on the same table without any intervening operations that |
| 70728 | ** might move or invalidate the cursor. Hence cursor u.bj.pC is always pointing |
| 70729 | ** to the row to be deleted and the sqlite3VdbeCursorMoveto() operation |
| 70730 | ** below is always a no-op and cannot fail. We will run it anyhow, though, |
| 70731 | ** to guard against future changes to the code generator. |
| 70732 | **/ |
| 70733 | assert( u.bj.pC->deferredMoveto==0 ); |
| 70734 | rc = sqlite3VdbeCursorMoveto(u.bj.pC); |
| 70735 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70736 | |
| 70737 | sqlite3BtreeSetCachedRowid(u.bj.pC->pCursor, 0); |
| 70738 | rc = sqlite3BtreeDelete(u.bj.pC->pCursor); |
| 70739 | u.bj.pC->cacheStatus = CACHE_STALE; |
| 70740 | |
| 70741 | /* Invoke the update-hook if required. */ |
| 70742 | if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && u.bj.pC->isTable ){ |
| 70743 | db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, |
| 70744 | db->aDb[u.bj.pC->iDb].zName, pOp->p4.z, u.bj.iKey); |
| 70745 | assert( u.bj.pC->iDb>=0 ); |
| 70746 | } |
| 70747 | if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++; |
| 70748 | break; |
| 70749 | } |
| 70750 | /* Opcode: ResetCount * * * * * |
| @@ -70506,21 +70774,23 @@ | |
| 70774 | ** |
| 70775 | ** Fall through to next instruction if the two records compare equal to |
| 70776 | ** each other. Jump to P2 if they are different. |
| 70777 | */ |
| 70778 | case OP_SorterCompare: { |
| 70779 | #if 0 /* local variables moved into u.bk */ |
| 70780 | VdbeCursor *pC; |
| 70781 | int res; |
| 70782 | int nIgnore; |
| 70783 | #endif /* local variables moved into u.bk */ |
| 70784 | |
| 70785 | u.bk.pC = p->apCsr[pOp->p1]; |
| 70786 | assert( isSorter(u.bk.pC) ); |
| 70787 | assert( pOp->p4type==P4_INT32 ); |
| 70788 | pIn3 = &aMem[pOp->p3]; |
| 70789 | u.bk.nIgnore = pOp->p4.i; |
| 70790 | rc = sqlite3VdbeSorterCompare(u.bk.pC, pIn3, u.bk.nIgnore, &u.bk.res); |
| 70791 | if( u.bk.res ){ |
| 70792 | pc = pOp->p2-1; |
| 70793 | } |
| 70794 | break; |
| 70795 | }; |
| 70796 | |
| @@ -70528,16 +70798,18 @@ | |
| 70798 | ** Synopsis: r[P2]=data |
| 70799 | ** |
| 70800 | ** Write into register P2 the current sorter data for sorter cursor P1. |
| 70801 | */ |
| 70802 | case OP_SorterData: { |
| 70803 | #if 0 /* local variables moved into u.bl */ |
| 70804 | VdbeCursor *pC; |
| 70805 | #endif /* local variables moved into u.bl */ |
| 70806 | |
| 70807 | pOut = &aMem[pOp->p2]; |
| 70808 | u.bl.pC = p->apCsr[pOp->p1]; |
| 70809 | assert( isSorter(u.bl.pC) ); |
| 70810 | rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut); |
| 70811 | break; |
| 70812 | } |
| 70813 | |
| 70814 | /* Opcode: RowData P1 P2 * * * |
| 70815 | ** Synopsis: r[P2]=data |
| @@ -70561,64 +70833,66 @@ | |
| 70833 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 70834 | ** of a real table, not a pseudo-table. |
| 70835 | */ |
| 70836 | case OP_RowKey: |
| 70837 | case OP_RowData: { |
| 70838 | #if 0 /* local variables moved into u.bm */ |
| 70839 | VdbeCursor *pC; |
| 70840 | BtCursor *pCrsr; |
| 70841 | u32 n; |
| 70842 | i64 n64; |
| 70843 | #endif /* local variables moved into u.bm */ |
| 70844 | |
| 70845 | pOut = &aMem[pOp->p2]; |
| 70846 | memAboutToChange(p, pOut); |
| 70847 | |
| 70848 | /* Note that RowKey and RowData are really exactly the same instruction */ |
| 70849 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70850 | u.bm.pC = p->apCsr[pOp->p1]; |
| 70851 | assert( isSorter(u.bm.pC)==0 ); |
| 70852 | assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData ); |
| 70853 | assert( u.bm.pC->isTable==0 || pOp->opcode==OP_RowData ); |
| 70854 | assert( u.bm.pC!=0 ); |
| 70855 | assert( u.bm.pC->nullRow==0 ); |
| 70856 | assert( u.bm.pC->pseudoTableReg==0 ); |
| 70857 | assert( u.bm.pC->pCursor!=0 ); |
| 70858 | u.bm.pCrsr = u.bm.pC->pCursor; |
| 70859 | assert( sqlite3BtreeCursorIsValid(u.bm.pCrsr) ); |
| 70860 | |
| 70861 | /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or |
| 70862 | ** OP_Rewind/Op_Next with no intervening instructions that might invalidate |
| 70863 | ** the cursor. Hence the following sqlite3VdbeCursorMoveto() call is always |
| 70864 | ** a no-op and can never fail. But we leave it in place as a safety. |
| 70865 | */ |
| 70866 | assert( u.bm.pC->deferredMoveto==0 ); |
| 70867 | rc = sqlite3VdbeCursorMoveto(u.bm.pC); |
| 70868 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70869 | |
| 70870 | if( u.bm.pC->isTable==0 ){ |
| 70871 | assert( !u.bm.pC->isTable ); |
| 70872 | VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64); |
| 70873 | assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 70874 | if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70875 | goto too_big; |
| 70876 | } |
| 70877 | u.bm.n = (u32)u.bm.n64; |
| 70878 | }else{ |
| 70879 | VVA_ONLY(rc =) sqlite3BtreeDataSize(u.bm.pCrsr, &u.bm.n); |
| 70880 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 70881 | if( u.bm.n>(u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70882 | goto too_big; |
| 70883 | } |
| 70884 | } |
| 70885 | if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){ |
| 70886 | goto no_mem; |
| 70887 | } |
| 70888 | pOut->n = u.bm.n; |
| 70889 | MemSetTypeFlag(pOut, MEM_Blob); |
| 70890 | if( u.bm.pC->isTable==0 ){ |
| 70891 | rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z); |
| 70892 | }else{ |
| 70893 | rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z); |
| 70894 | } |
| 70895 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ |
| 70896 | UPDATE_MAX_BLOBSIZE(pOut); |
| 70897 | REGISTER_TRACE(pOp->p2, pOut); |
| 70898 | break; |
| @@ -70633,44 +70907,46 @@ | |
| 70907 | ** P1 can be either an ordinary table or a virtual table. There used to |
| 70908 | ** be a separate OP_VRowid opcode for use with virtual tables, but this |
| 70909 | ** one opcode now works for both table types. |
| 70910 | */ |
| 70911 | case OP_Rowid: { /* out2-prerelease */ |
| 70912 | #if 0 /* local variables moved into u.bn */ |
| 70913 | VdbeCursor *pC; |
| 70914 | i64 v; |
| 70915 | sqlite3_vtab *pVtab; |
| 70916 | const sqlite3_module *pModule; |
| 70917 | #endif /* local variables moved into u.bn */ |
| 70918 | |
| 70919 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70920 | u.bn.pC = p->apCsr[pOp->p1]; |
| 70921 | assert( u.bn.pC!=0 ); |
| 70922 | assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow ); |
| 70923 | if( u.bn.pC->nullRow ){ |
| 70924 | pOut->flags = MEM_Null; |
| 70925 | break; |
| 70926 | }else if( u.bn.pC->deferredMoveto ){ |
| 70927 | u.bn.v = u.bn.pC->movetoTarget; |
| 70928 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 70929 | }else if( u.bn.pC->pVtabCursor ){ |
| 70930 | u.bn.pVtab = u.bn.pC->pVtabCursor->pVtab; |
| 70931 | u.bn.pModule = u.bn.pVtab->pModule; |
| 70932 | assert( u.bn.pModule->xRowid ); |
| 70933 | rc = u.bn.pModule->xRowid(u.bn.pC->pVtabCursor, &u.bn.v); |
| 70934 | sqlite3VtabImportErrmsg(p, u.bn.pVtab); |
| 70935 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 70936 | }else{ |
| 70937 | assert( u.bn.pC->pCursor!=0 ); |
| 70938 | rc = sqlite3VdbeCursorMoveto(u.bn.pC); |
| 70939 | if( rc ) goto abort_due_to_error; |
| 70940 | if( u.bn.pC->rowidIsValid ){ |
| 70941 | u.bn.v = u.bn.pC->lastRowid; |
| 70942 | }else{ |
| 70943 | rc = sqlite3BtreeKeySize(u.bn.pC->pCursor, &u.bn.v); |
| 70944 | assert( rc==SQLITE_OK ); /* Always so because of CursorMoveto() above */ |
| 70945 | } |
| 70946 | } |
| 70947 | pOut->u.i = u.bn.v; |
| 70948 | break; |
| 70949 | } |
| 70950 | |
| 70951 | /* Opcode: NullRow P1 * * * * |
| 70952 | ** |
| @@ -70677,21 +70953,23 @@ | |
| 70953 | ** Move the cursor P1 to a null row. Any OP_Column operations |
| 70954 | ** that occur while the cursor is on the null row will always |
| 70955 | ** write a NULL. |
| 70956 | */ |
| 70957 | case OP_NullRow: { |
| 70958 | #if 0 /* local variables moved into u.bo */ |
| 70959 | VdbeCursor *pC; |
| 70960 | #endif /* local variables moved into u.bo */ |
| 70961 | |
| 70962 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70963 | u.bo.pC = p->apCsr[pOp->p1]; |
| 70964 | assert( u.bo.pC!=0 ); |
| 70965 | u.bo.pC->nullRow = 1; |
| 70966 | u.bo.pC->rowidIsValid = 0; |
| 70967 | u.bo.pC->cacheStatus = CACHE_STALE; |
| 70968 | assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor ); |
| 70969 | if( u.bo.pC->pCursor ){ |
| 70970 | sqlite3BtreeClearCursor(u.bo.pC->pCursor); |
| 70971 | } |
| 70972 | break; |
| 70973 | } |
| 70974 | |
| 70975 | /* Opcode: Last P1 P2 * * * |
| @@ -70701,26 +70979,28 @@ | |
| 70979 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 70980 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 70981 | ** to the following instruction. |
| 70982 | */ |
| 70983 | case OP_Last: { /* jump */ |
| 70984 | #if 0 /* local variables moved into u.bp */ |
| 70985 | VdbeCursor *pC; |
| 70986 | BtCursor *pCrsr; |
| 70987 | int res; |
| 70988 | #endif /* local variables moved into u.bp */ |
| 70989 | |
| 70990 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70991 | u.bp.pC = p->apCsr[pOp->p1]; |
| 70992 | assert( u.bp.pC!=0 ); |
| 70993 | u.bp.pCrsr = u.bp.pC->pCursor; |
| 70994 | u.bp.res = 0; |
| 70995 | assert( u.bp.pCrsr!=0 ); |
| 70996 | rc = sqlite3BtreeLast(u.bp.pCrsr, &u.bp.res); |
| 70997 | u.bp.pC->nullRow = (u8)u.bp.res; |
| 70998 | u.bp.pC->deferredMoveto = 0; |
| 70999 | u.bp.pC->rowidIsValid = 0; |
| 71000 | u.bp.pC->cacheStatus = CACHE_STALE; |
| 71001 | if( pOp->p2>0 && u.bp.res ){ |
| 71002 | pc = pOp->p2 - 1; |
| 71003 | } |
| 71004 | break; |
| 71005 | } |
| 71006 | |
| @@ -70753,32 +71033,34 @@ | |
| 71033 | ** If the table or index is empty and P2>0, then jump immediately to P2. |
| 71034 | ** If P2 is 0 or if the table or index is not empty, fall through |
| 71035 | ** to the following instruction. |
| 71036 | */ |
| 71037 | case OP_Rewind: { /* jump */ |
| 71038 | #if 0 /* local variables moved into u.bq */ |
| 71039 | VdbeCursor *pC; |
| 71040 | BtCursor *pCrsr; |
| 71041 | int res; |
| 71042 | #endif /* local variables moved into u.bq */ |
| 71043 | |
| 71044 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71045 | u.bq.pC = p->apCsr[pOp->p1]; |
| 71046 | assert( u.bq.pC!=0 ); |
| 71047 | assert( isSorter(u.bq.pC)==(pOp->opcode==OP_SorterSort) ); |
| 71048 | u.bq.res = 1; |
| 71049 | if( isSorter(u.bq.pC) ){ |
| 71050 | rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res); |
| 71051 | }else{ |
| 71052 | u.bq.pCrsr = u.bq.pC->pCursor; |
| 71053 | assert( u.bq.pCrsr ); |
| 71054 | rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res); |
| 71055 | u.bq.pC->deferredMoveto = 0; |
| 71056 | u.bq.pC->cacheStatus = CACHE_STALE; |
| 71057 | u.bq.pC->rowidIsValid = 0; |
| 71058 | } |
| 71059 | u.bq.pC->nullRow = (u8)u.bq.res; |
| 71060 | assert( pOp->p2>0 && pOp->p2<p->nOp ); |
| 71061 | if( u.bq.res ){ |
| 71062 | pc = pOp->p2 - 1; |
| 71063 | } |
| 71064 | break; |
| 71065 | } |
| 71066 | |
| @@ -70825,47 +71107,49 @@ | |
| 71107 | ** |
| 71108 | ** This opcode works just like OP_Prev except that if cursor P1 is not |
| 71109 | ** open it behaves a no-op. |
| 71110 | */ |
| 71111 | case OP_SorterNext: { /* jump */ |
| 71112 | #if 0 /* local variables moved into u.br */ |
| 71113 | VdbeCursor *pC; |
| 71114 | int res; |
| 71115 | #endif /* local variables moved into u.br */ |
| 71116 | |
| 71117 | u.br.pC = p->apCsr[pOp->p1]; |
| 71118 | assert( isSorter(u.br.pC) ); |
| 71119 | rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res); |
| 71120 | goto next_tail; |
| 71121 | case OP_PrevIfOpen: /* jump */ |
| 71122 | case OP_NextIfOpen: /* jump */ |
| 71123 | if( p->apCsr[pOp->p1]==0 ) break; |
| 71124 | /* Fall through */ |
| 71125 | case OP_Prev: /* jump */ |
| 71126 | case OP_Next: /* jump */ |
| 71127 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71128 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 71129 | u.br.pC = p->apCsr[pOp->p1]; |
| 71130 | assert( u.br.pC!=0 ); |
| 71131 | assert( u.br.pC->deferredMoveto==0 ); |
| 71132 | assert( u.br.pC->pCursor ); |
| 71133 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 71134 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 71135 | assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 71136 | assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); |
| 71137 | rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res); |
| 71138 | next_tail: |
| 71139 | u.br.pC->cacheStatus = CACHE_STALE; |
| 71140 | if( u.br.res==0 ){ |
| 71141 | u.br.pC->nullRow = 0; |
| 71142 | pc = pOp->p2 - 1; |
| 71143 | p->aCounter[pOp->p5]++; |
| 71144 | #ifdef SQLITE_TEST |
| 71145 | sqlite3_search_count++; |
| 71146 | #endif |
| 71147 | }else{ |
| 71148 | u.br.pC->nullRow = 1; |
| 71149 | } |
| 71150 | u.br.pC->rowidIsValid = 0; |
| 71151 | goto check_for_interrupt; |
| 71152 | } |
| 71153 | |
| 71154 | /* Opcode: IdxInsert P1 P2 P3 * P5 |
| 71155 | ** Synopsis: key=r[P2] |
| @@ -70880,37 +71164,39 @@ | |
| 71164 | ** This instruction only works for indices. The equivalent instruction |
| 71165 | ** for tables is OP_Insert. |
| 71166 | */ |
| 71167 | case OP_SorterInsert: /* in2 */ |
| 71168 | case OP_IdxInsert: { /* in2 */ |
| 71169 | #if 0 /* local variables moved into u.bs */ |
| 71170 | VdbeCursor *pC; |
| 71171 | BtCursor *pCrsr; |
| 71172 | int nKey; |
| 71173 | const char *zKey; |
| 71174 | #endif /* local variables moved into u.bs */ |
| 71175 | |
| 71176 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71177 | u.bs.pC = p->apCsr[pOp->p1]; |
| 71178 | assert( u.bs.pC!=0 ); |
| 71179 | assert( isSorter(u.bs.pC)==(pOp->opcode==OP_SorterInsert) ); |
| 71180 | pIn2 = &aMem[pOp->p2]; |
| 71181 | assert( pIn2->flags & MEM_Blob ); |
| 71182 | u.bs.pCrsr = u.bs.pC->pCursor; |
| 71183 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 71184 | assert( u.bs.pCrsr!=0 ); |
| 71185 | assert( u.bs.pC->isTable==0 ); |
| 71186 | rc = ExpandBlob(pIn2); |
| 71187 | if( rc==SQLITE_OK ){ |
| 71188 | if( isSorter(u.bs.pC) ){ |
| 71189 | rc = sqlite3VdbeSorterWrite(db, u.bs.pC, pIn2); |
| 71190 | }else{ |
| 71191 | u.bs.nKey = pIn2->n; |
| 71192 | u.bs.zKey = pIn2->z; |
| 71193 | rc = sqlite3BtreeInsert(u.bs.pCrsr, u.bs.zKey, u.bs.nKey, "", 0, 0, pOp->p3, |
| 71194 | ((pOp->p5 & OPFLAG_USESEEKRESULT) ? u.bs.pC->seekResult : 0) |
| 71195 | ); |
| 71196 | assert( u.bs.pC->deferredMoveto==0 ); |
| 71197 | u.bs.pC->cacheStatus = CACHE_STALE; |
| 71198 | } |
| 71199 | } |
| 71200 | break; |
| 71201 | } |
| 71202 | |
| @@ -70920,36 +71206,38 @@ | |
| 71206 | ** The content of P3 registers starting at register P2 form |
| 71207 | ** an unpacked index key. This opcode removes that entry from the |
| 71208 | ** index opened by cursor P1. |
| 71209 | */ |
| 71210 | case OP_IdxDelete: { |
| 71211 | #if 0 /* local variables moved into u.bt */ |
| 71212 | VdbeCursor *pC; |
| 71213 | BtCursor *pCrsr; |
| 71214 | int res; |
| 71215 | UnpackedRecord r; |
| 71216 | #endif /* local variables moved into u.bt */ |
| 71217 | |
| 71218 | assert( pOp->p3>0 ); |
| 71219 | assert( pOp->p2>0 && pOp->p2+pOp->p3<=(p->nMem-p->nCursor)+1 ); |
| 71220 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71221 | u.bt.pC = p->apCsr[pOp->p1]; |
| 71222 | assert( u.bt.pC!=0 ); |
| 71223 | u.bt.pCrsr = u.bt.pC->pCursor; |
| 71224 | assert( u.bt.pCrsr!=0 ); |
| 71225 | assert( pOp->p5==0 ); |
| 71226 | u.bt.r.pKeyInfo = u.bt.pC->pKeyInfo; |
| 71227 | u.bt.r.nField = (u16)pOp->p3; |
| 71228 | u.bt.r.flags = UNPACKED_PREFIX_MATCH; |
| 71229 | u.bt.r.aMem = &aMem[pOp->p2]; |
| 71230 | #ifdef SQLITE_DEBUG |
| 71231 | { int i; for(i=0; i<u.bt.r.nField; i++) assert( memIsValid(&u.bt.r.aMem[i]) ); } |
| 71232 | #endif |
| 71233 | rc = sqlite3BtreeMovetoUnpacked(u.bt.pCrsr, &u.bt.r, 0, 0, &u.bt.res); |
| 71234 | if( rc==SQLITE_OK && u.bt.res==0 ){ |
| 71235 | rc = sqlite3BtreeDelete(u.bt.pCrsr); |
| 71236 | } |
| 71237 | assert( u.bt.pC->deferredMoveto==0 ); |
| 71238 | u.bt.pC->cacheStatus = CACHE_STALE; |
| 71239 | break; |
| 71240 | } |
| 71241 | |
| 71242 | /* Opcode: IdxRowid P1 P2 * * * |
| 71243 | ** Synopsis: r[P2]=rowid |
| @@ -70959,31 +71247,32 @@ | |
| 71247 | ** the rowid of the table entry to which this index entry points. |
| 71248 | ** |
| 71249 | ** See also: Rowid, MakeRecord. |
| 71250 | */ |
| 71251 | case OP_IdxRowid: { /* out2-prerelease */ |
| 71252 | #if 0 /* local variables moved into u.bu */ |
| 71253 | BtCursor *pCrsr; |
| 71254 | VdbeCursor *pC; |
| 71255 | i64 rowid; |
| 71256 | #endif /* local variables moved into u.bu */ |
| 71257 | |
| 71258 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71259 | u.bu.pC = p->apCsr[pOp->p1]; |
| 71260 | assert( u.bu.pC!=0 ); |
| 71261 | u.bu.pCrsr = u.bu.pC->pCursor; |
| 71262 | assert( u.bu.pCrsr!=0 ); |
| 71263 | pOut->flags = MEM_Null; |
| 71264 | rc = sqlite3VdbeCursorMoveto(u.bu.pC); |
| 71265 | if( NEVER(rc) ) goto abort_due_to_error; |
| 71266 | assert( u.bu.pC->deferredMoveto==0 ); |
| 71267 | assert( u.bu.pC->isTable==0 ); |
| 71268 | if( !u.bu.pC->nullRow ){ |
| 71269 | rc = sqlite3VdbeIdxRowid(db, u.bu.pCrsr, &u.bu.rowid); |
| 71270 | if( rc!=SQLITE_OK ){ |
| 71271 | goto abort_due_to_error; |
| 71272 | } |
| 71273 | pOut->u.i = u.bu.rowid; |
| 71274 | pOut->flags = MEM_Int; |
| 71275 | } |
| 71276 | break; |
| 71277 | } |
| 71278 | |
| @@ -71015,42 +71304,43 @@ | |
| 71304 | ** If P5 is non-zero then the key value is increased by an epsilon prior |
| 71305 | ** to the comparison. This makes the opcode work like IdxLE. |
| 71306 | */ |
| 71307 | case OP_IdxLT: /* jump */ |
| 71308 | case OP_IdxGE: { /* jump */ |
| 71309 | #if 0 /* local variables moved into u.bv */ |
| 71310 | VdbeCursor *pC; |
| 71311 | int res; |
| 71312 | UnpackedRecord r; |
| 71313 | #endif /* local variables moved into u.bv */ |
| 71314 | |
| 71315 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71316 | u.bv.pC = p->apCsr[pOp->p1]; |
| 71317 | assert( u.bv.pC!=0 ); |
| 71318 | assert( u.bv.pC->isOrdered ); |
| 71319 | assert( u.bv.pC->pCursor!=0); |
| 71320 | assert( u.bv.pC->deferredMoveto==0 ); |
| 71321 | assert( pOp->p5==0 || pOp->p5==1 ); |
| 71322 | assert( pOp->p4type==P4_INT32 ); |
| 71323 | u.bv.r.pKeyInfo = u.bv.pC->pKeyInfo; |
| 71324 | u.bv.r.nField = (u16)pOp->p4.i; |
| 71325 | if( pOp->p5 ){ |
| 71326 | u.bv.r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH; |
| 71327 | }else{ |
| 71328 | u.bv.r.flags = UNPACKED_PREFIX_MATCH; |
| 71329 | } |
| 71330 | u.bv.r.aMem = &aMem[pOp->p3]; |
| 71331 | #ifdef SQLITE_DEBUG |
| 71332 | { int i; for(i=0; i<u.bv.r.nField; i++) assert( memIsValid(&u.bv.r.aMem[i]) ); } |
| 71333 | #endif |
| 71334 | rc = sqlite3VdbeIdxKeyCompare(u.bv.pC, &u.bv.r, &u.bv.res); |
| 71335 | if( pOp->opcode==OP_IdxLT ){ |
| 71336 | u.bv.res = -u.bv.res; |
| 71337 | }else{ |
| 71338 | assert( pOp->opcode==OP_IdxGE ); |
| 71339 | u.bv.res++; |
| 71340 | } |
| 71341 | if( u.bv.res>0 ){ |
| 71342 | pc = pOp->p2 - 1 ; |
| 71343 | } |
| 71344 | break; |
| 71345 | } |
| 71346 | |
| @@ -71073,46 +71363,47 @@ | |
| 71363 | ** If AUTOVACUUM is disabled then a zero is stored in register P2. |
| 71364 | ** |
| 71365 | ** See also: Clear |
| 71366 | */ |
| 71367 | case OP_Destroy: { /* out2-prerelease */ |
| 71368 | #if 0 /* local variables moved into u.bw */ |
| 71369 | int iMoved; |
| 71370 | int iCnt; |
| 71371 | Vdbe *pVdbe; |
| 71372 | int iDb; |
| 71373 | #endif /* local variables moved into u.bw */ |
| 71374 | |
| 71375 | assert( p->readOnly==0 ); |
| 71376 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 71377 | u.bw.iCnt = 0; |
| 71378 | for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){ |
| 71379 | if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader |
| 71380 | && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0 |
| 71381 | ){ |
| 71382 | u.bw.iCnt++; |
| 71383 | } |
| 71384 | } |
| 71385 | #else |
| 71386 | u.bw.iCnt = db->nVdbeRead; |
| 71387 | #endif |
| 71388 | pOut->flags = MEM_Null; |
| 71389 | if( u.bw.iCnt>1 ){ |
| 71390 | rc = SQLITE_LOCKED; |
| 71391 | p->errorAction = OE_Abort; |
| 71392 | }else{ |
| 71393 | u.bw.iDb = pOp->p3; |
| 71394 | assert( u.bw.iCnt==1 ); |
| 71395 | assert( (p->btreeMask & (((yDbMask)1)<<u.bw.iDb))!=0 ); |
| 71396 | rc = sqlite3BtreeDropTable(db->aDb[u.bw.iDb].pBt, pOp->p1, &u.bw.iMoved); |
| 71397 | pOut->flags = MEM_Int; |
| 71398 | pOut->u.i = u.bw.iMoved; |
| 71399 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 71400 | if( rc==SQLITE_OK && u.bw.iMoved!=0 ){ |
| 71401 | sqlite3RootPageMoved(db, u.bw.iDb, u.bw.iMoved, pOp->p1); |
| 71402 | /* All OP_Destroy operations occur on the same btree */ |
| 71403 | assert( resetSchemaOnFault==0 || resetSchemaOnFault==u.bw.iDb+1 ); |
| 71404 | resetSchemaOnFault = u.bw.iDb+1; |
| 71405 | } |
| 71406 | #endif |
| 71407 | } |
| 71408 | break; |
| 71409 | } |
| @@ -71134,25 +71425,27 @@ | |
| 71425 | ** also incremented by the number of rows in the table being cleared. |
| 71426 | ** |
| 71427 | ** See also: Destroy |
| 71428 | */ |
| 71429 | case OP_Clear: { |
| 71430 | #if 0 /* local variables moved into u.bx */ |
| 71431 | int nChange; |
| 71432 | #endif /* local variables moved into u.bx */ |
| 71433 | |
| 71434 | u.bx.nChange = 0; |
| 71435 | assert( p->readOnly==0 ); |
| 71436 | assert( pOp->p1!=1 ); |
| 71437 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 ); |
| 71438 | rc = sqlite3BtreeClearTable( |
| 71439 | db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0) |
| 71440 | ); |
| 71441 | if( pOp->p3 ){ |
| 71442 | p->nChange += u.bx.nChange; |
| 71443 | if( pOp->p3>0 ){ |
| 71444 | assert( memIsValid(&aMem[pOp->p3]) ); |
| 71445 | memAboutToChange(p, &aMem[pOp->p3]); |
| 71446 | aMem[pOp->p3].u.i += u.bx.nChange; |
| 71447 | } |
| 71448 | } |
| 71449 | break; |
| 71450 | } |
| 71451 | |
| @@ -71180,28 +71473,30 @@ | |
| 71473 | ** |
| 71474 | ** See documentation on OP_CreateTable for additional information. |
| 71475 | */ |
| 71476 | case OP_CreateIndex: /* out2-prerelease */ |
| 71477 | case OP_CreateTable: { /* out2-prerelease */ |
| 71478 | #if 0 /* local variables moved into u.by */ |
| 71479 | int pgno; |
| 71480 | int flags; |
| 71481 | Db *pDb; |
| 71482 | #endif /* local variables moved into u.by */ |
| 71483 | |
| 71484 | u.by.pgno = 0; |
| 71485 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 71486 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 71487 | assert( p->readOnly==0 ); |
| 71488 | u.by.pDb = &db->aDb[pOp->p1]; |
| 71489 | assert( u.by.pDb->pBt!=0 ); |
| 71490 | if( pOp->opcode==OP_CreateTable ){ |
| 71491 | /* u.by.flags = BTREE_INTKEY; */ |
| 71492 | u.by.flags = BTREE_INTKEY; |
| 71493 | }else{ |
| 71494 | u.by.flags = BTREE_BLOBKEY; |
| 71495 | } |
| 71496 | rc = sqlite3BtreeCreateTable(u.by.pDb->pBt, &u.by.pgno, u.by.flags); |
| 71497 | pOut->u.i = u.by.pgno; |
| 71498 | break; |
| 71499 | } |
| 71500 | |
| 71501 | /* Opcode: ParseSchema P1 * * P4 * |
| 71502 | ** |
| @@ -71210,54 +71505,56 @@ | |
| 71505 | ** |
| 71506 | ** This opcode invokes the parser to create a new virtual machine, |
| 71507 | ** then runs the new virtual machine. It is thus a re-entrant opcode. |
| 71508 | */ |
| 71509 | case OP_ParseSchema: { |
| 71510 | #if 0 /* local variables moved into u.bz */ |
| 71511 | int iDb; |
| 71512 | const char *zMaster; |
| 71513 | char *zSql; |
| 71514 | InitData initData; |
| 71515 | #endif /* local variables moved into u.bz */ |
| 71516 | |
| 71517 | /* Any prepared statement that invokes this opcode will hold mutexes |
| 71518 | ** on every btree. This is a prerequisite for invoking |
| 71519 | ** sqlite3InitCallback(). |
| 71520 | */ |
| 71521 | #ifdef SQLITE_DEBUG |
| 71522 | for(u.bz.iDb=0; u.bz.iDb<db->nDb; u.bz.iDb++){ |
| 71523 | assert( u.bz.iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[u.bz.iDb].pBt) ); |
| 71524 | } |
| 71525 | #endif |
| 71526 | |
| 71527 | u.bz.iDb = pOp->p1; |
| 71528 | assert( u.bz.iDb>=0 && u.bz.iDb<db->nDb ); |
| 71529 | assert( DbHasProperty(db, u.bz.iDb, DB_SchemaLoaded) ); |
| 71530 | /* Used to be a conditional */ { |
| 71531 | u.bz.zMaster = SCHEMA_TABLE(u.bz.iDb); |
| 71532 | u.bz.initData.db = db; |
| 71533 | u.bz.initData.iDb = pOp->p1; |
| 71534 | u.bz.initData.pzErrMsg = &p->zErrMsg; |
| 71535 | u.bz.zSql = sqlite3MPrintf(db, |
| 71536 | "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid", |
| 71537 | db->aDb[u.bz.iDb].zName, u.bz.zMaster, pOp->p4.z); |
| 71538 | if( u.bz.zSql==0 ){ |
| 71539 | rc = SQLITE_NOMEM; |
| 71540 | }else{ |
| 71541 | assert( db->init.busy==0 ); |
| 71542 | db->init.busy = 1; |
| 71543 | u.bz.initData.rc = SQLITE_OK; |
| 71544 | assert( !db->mallocFailed ); |
| 71545 | rc = sqlite3_exec(db, u.bz.zSql, sqlite3InitCallback, &u.bz.initData, 0); |
| 71546 | if( rc==SQLITE_OK ) rc = u.bz.initData.rc; |
| 71547 | sqlite3DbFree(db, u.bz.zSql); |
| 71548 | db->init.busy = 0; |
| 71549 | } |
| 71550 | } |
| 71551 | if( rc ) sqlite3ResetAllSchemasOfConnection(db); |
| 71552 | if( rc==SQLITE_NOMEM ){ |
| 71553 | goto no_mem; |
| 71554 | } |
| 71555 | break; |
| 71556 | } |
| 71557 | |
| 71558 | #if !defined(SQLITE_OMIT_ANALYZE) |
| 71559 | /* Opcode: LoadAnalysis P1 * * * * |
| 71560 | ** |
| @@ -71329,44 +71626,46 @@ | |
| 71626 | ** file, not the main database file. |
| 71627 | ** |
| 71628 | ** This opcode is used to implement the integrity_check pragma. |
| 71629 | */ |
| 71630 | case OP_IntegrityCk: { |
| 71631 | #if 0 /* local variables moved into u.ca */ |
| 71632 | int nRoot; /* Number of tables to check. (Number of root pages.) */ |
| 71633 | int *aRoot; /* Array of rootpage numbers for tables to be checked */ |
| 71634 | int j; /* Loop counter */ |
| 71635 | int nErr; /* Number of errors reported */ |
| 71636 | char *z; /* Text of the error report */ |
| 71637 | Mem *pnErr; /* Register keeping track of errors remaining */ |
| 71638 | #endif /* local variables moved into u.ca */ |
| 71639 | |
| 71640 | assert( p->bIsReader ); |
| 71641 | u.ca.nRoot = pOp->p2; |
| 71642 | assert( u.ca.nRoot>0 ); |
| 71643 | u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) ); |
| 71644 | if( u.ca.aRoot==0 ) goto no_mem; |
| 71645 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 71646 | u.ca.pnErr = &aMem[pOp->p3]; |
| 71647 | assert( (u.ca.pnErr->flags & MEM_Int)!=0 ); |
| 71648 | assert( (u.ca.pnErr->flags & (MEM_Str|MEM_Blob))==0 ); |
| 71649 | pIn1 = &aMem[pOp->p1]; |
| 71650 | for(u.ca.j=0; u.ca.j<u.ca.nRoot; u.ca.j++){ |
| 71651 | u.ca.aRoot[u.ca.j] = (int)sqlite3VdbeIntValue(&pIn1[u.ca.j]); |
| 71652 | } |
| 71653 | u.ca.aRoot[u.ca.j] = 0; |
| 71654 | assert( pOp->p5<db->nDb ); |
| 71655 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p5))!=0 ); |
| 71656 | u.ca.z = sqlite3BtreeIntegrityCheck(db->aDb[pOp->p5].pBt, u.ca.aRoot, u.ca.nRoot, |
| 71657 | (int)u.ca.pnErr->u.i, &u.ca.nErr); |
| 71658 | sqlite3DbFree(db, u.ca.aRoot); |
| 71659 | u.ca.pnErr->u.i -= u.ca.nErr; |
| 71660 | sqlite3VdbeMemSetNull(pIn1); |
| 71661 | if( u.ca.nErr==0 ){ |
| 71662 | assert( u.ca.z==0 ); |
| 71663 | }else if( u.ca.z==0 ){ |
| 71664 | goto no_mem; |
| 71665 | }else{ |
| 71666 | sqlite3VdbeMemSetStr(pIn1, u.ca.z, -1, SQLITE_UTF8, sqlite3_free); |
| 71667 | } |
| 71668 | UPDATE_MAX_BLOBSIZE(pIn1); |
| 71669 | sqlite3VdbeChangeEncoding(pIn1, encoding); |
| 71670 | break; |
| 71671 | } |
| @@ -71398,22 +71697,24 @@ | |
| 71697 | ** Extract the smallest value from boolean index P1 and put that value into |
| 71698 | ** register P3. Or, if boolean index P1 is initially empty, leave P3 |
| 71699 | ** unchanged and jump to instruction P2. |
| 71700 | */ |
| 71701 | case OP_RowSetRead: { /* jump, in1, out3 */ |
| 71702 | #if 0 /* local variables moved into u.cb */ |
| 71703 | i64 val; |
| 71704 | #endif /* local variables moved into u.cb */ |
| 71705 | |
| 71706 | pIn1 = &aMem[pOp->p1]; |
| 71707 | if( (pIn1->flags & MEM_RowSet)==0 |
| 71708 | || sqlite3RowSetNext(pIn1->u.pRowSet, &u.cb.val)==0 |
| 71709 | ){ |
| 71710 | /* The boolean index is empty */ |
| 71711 | sqlite3VdbeMemSetNull(pIn1); |
| 71712 | pc = pOp->p2 - 1; |
| 71713 | }else{ |
| 71714 | /* A value was pulled from the index */ |
| 71715 | sqlite3VdbeMemSetInt64(&aMem[pOp->p3], u.cb.val); |
| 71716 | } |
| 71717 | goto check_for_interrupt; |
| 71718 | } |
| 71719 | |
| 71720 | /* Opcode: RowSetTest P1 P2 P3 P4 |
| @@ -71439,16 +71740,18 @@ | |
| 71740 | ** inserted, there is no need to search to see if the same value was |
| 71741 | ** previously inserted as part of set X (only if it was previously |
| 71742 | ** inserted as part of some other set). |
| 71743 | */ |
| 71744 | case OP_RowSetTest: { /* jump, in1, in3 */ |
| 71745 | #if 0 /* local variables moved into u.cc */ |
| 71746 | int iSet; |
| 71747 | int exists; |
| 71748 | #endif /* local variables moved into u.cc */ |
| 71749 | |
| 71750 | pIn1 = &aMem[pOp->p1]; |
| 71751 | pIn3 = &aMem[pOp->p3]; |
| 71752 | u.cc.iSet = pOp->p4.i; |
| 71753 | assert( pIn3->flags&MEM_Int ); |
| 71754 | |
| 71755 | /* If there is anything other than a rowset object in memory cell P1, |
| 71756 | ** delete it now and initialize P1 with an empty rowset |
| 71757 | */ |
| @@ -71456,21 +71759,21 @@ | |
| 71759 | sqlite3VdbeMemSetRowSet(pIn1); |
| 71760 | if( (pIn1->flags & MEM_RowSet)==0 ) goto no_mem; |
| 71761 | } |
| 71762 | |
| 71763 | assert( pOp->p4type==P4_INT32 ); |
| 71764 | assert( u.cc.iSet==-1 || u.cc.iSet>=0 ); |
| 71765 | if( u.cc.iSet ){ |
| 71766 | u.cc.exists = sqlite3RowSetTest(pIn1->u.pRowSet, |
| 71767 | (u8)(u.cc.iSet>=0 ? u.cc.iSet & 0xf : 0xff), |
| 71768 | pIn3->u.i); |
| 71769 | if( u.cc.exists ){ |
| 71770 | pc = pOp->p2 - 1; |
| 71771 | break; |
| 71772 | } |
| 71773 | } |
| 71774 | if( u.cc.iSet>=0 ){ |
| 71775 | sqlite3RowSetInsert(pIn1->u.pRowSet, pIn3->u.i); |
| 71776 | } |
| 71777 | break; |
| 71778 | } |
| 71779 | |
| @@ -71489,109 +71792,111 @@ | |
| 71792 | ** memory required by the sub-vdbe at runtime. |
| 71793 | ** |
| 71794 | ** P4 is a pointer to the VM containing the trigger program. |
| 71795 | */ |
| 71796 | case OP_Program: { /* jump */ |
| 71797 | #if 0 /* local variables moved into u.cd */ |
| 71798 | int nMem; /* Number of memory registers for sub-program */ |
| 71799 | int nByte; /* Bytes of runtime space required for sub-program */ |
| 71800 | Mem *pRt; /* Register to allocate runtime space */ |
| 71801 | Mem *pMem; /* Used to iterate through memory cells */ |
| 71802 | Mem *pEnd; /* Last memory cell in new array */ |
| 71803 | VdbeFrame *pFrame; /* New vdbe frame to execute in */ |
| 71804 | SubProgram *pProgram; /* Sub-program to execute */ |
| 71805 | void *t; /* Token identifying trigger */ |
| 71806 | #endif /* local variables moved into u.cd */ |
| 71807 | |
| 71808 | u.cd.pProgram = pOp->p4.pProgram; |
| 71809 | u.cd.pRt = &aMem[pOp->p3]; |
| 71810 | assert( u.cd.pProgram->nOp>0 ); |
| 71811 | |
| 71812 | /* If the p5 flag is clear, then recursive invocation of triggers is |
| 71813 | ** disabled for backwards compatibility (p5 is set if this sub-program |
| 71814 | ** is really a trigger, not a foreign key action, and the flag set |
| 71815 | ** and cleared by the "PRAGMA recursive_triggers" command is clear). |
| 71816 | ** |
| 71817 | ** It is recursive invocation of triggers, at the SQL level, that is |
| 71818 | ** disabled. In some cases a single trigger may generate more than one |
| 71819 | ** SubProgram (if the trigger may be executed with more than one different |
| 71820 | ** ON CONFLICT algorithm). SubProgram structures associated with a |
| 71821 | ** single trigger all have the same value for the SubProgram.token |
| 71822 | ** variable. */ |
| 71823 | if( pOp->p5 ){ |
| 71824 | u.cd.t = u.cd.pProgram->token; |
| 71825 | for(u.cd.pFrame=p->pFrame; u.cd.pFrame && u.cd.pFrame->token!=u.cd.t; u.cd.pFrame=u.cd.pFrame->pParent); |
| 71826 | if( u.cd.pFrame ) break; |
| 71827 | } |
| 71828 | |
| 71829 | if( p->nFrame>=db->aLimit[SQLITE_LIMIT_TRIGGER_DEPTH] ){ |
| 71830 | rc = SQLITE_ERROR; |
| 71831 | sqlite3SetString(&p->zErrMsg, db, "too many levels of trigger recursion"); |
| 71832 | break; |
| 71833 | } |
| 71834 | |
| 71835 | /* Register u.cd.pRt is used to store the memory required to save the state |
| 71836 | ** of the current program, and the memory required at runtime to execute |
| 71837 | ** the trigger program. If this trigger has been fired before, then u.cd.pRt |
| 71838 | ** is already allocated. Otherwise, it must be initialized. */ |
| 71839 | if( (u.cd.pRt->flags&MEM_Frame)==0 ){ |
| 71840 | /* SubProgram.nMem is set to the number of memory cells used by the |
| 71841 | ** program stored in SubProgram.aOp. As well as these, one memory |
| 71842 | ** cell is required for each cursor used by the program. Set local |
| 71843 | ** variable u.cd.nMem (and later, VdbeFrame.nChildMem) to this value. |
| 71844 | */ |
| 71845 | u.cd.nMem = u.cd.pProgram->nMem + u.cd.pProgram->nCsr; |
| 71846 | u.cd.nByte = ROUND8(sizeof(VdbeFrame)) |
| 71847 | + u.cd.nMem * sizeof(Mem) |
| 71848 | + u.cd.pProgram->nCsr * sizeof(VdbeCursor *) |
| 71849 | + u.cd.pProgram->nOnce * sizeof(u8); |
| 71850 | u.cd.pFrame = sqlite3DbMallocZero(db, u.cd.nByte); |
| 71851 | if( !u.cd.pFrame ){ |
| 71852 | goto no_mem; |
| 71853 | } |
| 71854 | sqlite3VdbeMemRelease(u.cd.pRt); |
| 71855 | u.cd.pRt->flags = MEM_Frame; |
| 71856 | u.cd.pRt->u.pFrame = u.cd.pFrame; |
| 71857 | |
| 71858 | u.cd.pFrame->v = p; |
| 71859 | u.cd.pFrame->nChildMem = u.cd.nMem; |
| 71860 | u.cd.pFrame->nChildCsr = u.cd.pProgram->nCsr; |
| 71861 | u.cd.pFrame->pc = pc; |
| 71862 | u.cd.pFrame->aMem = p->aMem; |
| 71863 | u.cd.pFrame->nMem = p->nMem; |
| 71864 | u.cd.pFrame->apCsr = p->apCsr; |
| 71865 | u.cd.pFrame->nCursor = p->nCursor; |
| 71866 | u.cd.pFrame->aOp = p->aOp; |
| 71867 | u.cd.pFrame->nOp = p->nOp; |
| 71868 | u.cd.pFrame->token = u.cd.pProgram->token; |
| 71869 | u.cd.pFrame->aOnceFlag = p->aOnceFlag; |
| 71870 | u.cd.pFrame->nOnceFlag = p->nOnceFlag; |
| 71871 | |
| 71872 | u.cd.pEnd = &VdbeFrameMem(u.cd.pFrame)[u.cd.pFrame->nChildMem]; |
| 71873 | for(u.cd.pMem=VdbeFrameMem(u.cd.pFrame); u.cd.pMem!=u.cd.pEnd; u.cd.pMem++){ |
| 71874 | u.cd.pMem->flags = MEM_Invalid; |
| 71875 | u.cd.pMem->db = db; |
| 71876 | } |
| 71877 | }else{ |
| 71878 | u.cd.pFrame = u.cd.pRt->u.pFrame; |
| 71879 | assert( u.cd.pProgram->nMem+u.cd.pProgram->nCsr==u.cd.pFrame->nChildMem ); |
| 71880 | assert( u.cd.pProgram->nCsr==u.cd.pFrame->nChildCsr ); |
| 71881 | assert( pc==u.cd.pFrame->pc ); |
| 71882 | } |
| 71883 | |
| 71884 | p->nFrame++; |
| 71885 | u.cd.pFrame->pParent = p->pFrame; |
| 71886 | u.cd.pFrame->lastRowid = lastRowid; |
| 71887 | u.cd.pFrame->nChange = p->nChange; |
| 71888 | p->nChange = 0; |
| 71889 | p->pFrame = u.cd.pFrame; |
| 71890 | p->aMem = aMem = &VdbeFrameMem(u.cd.pFrame)[-1]; |
| 71891 | p->nMem = u.cd.pFrame->nChildMem; |
| 71892 | p->nCursor = (u16)u.cd.pFrame->nChildCsr; |
| 71893 | p->apCsr = (VdbeCursor **)&aMem[p->nMem+1]; |
| 71894 | p->aOp = aOp = u.cd.pProgram->aOp; |
| 71895 | p->nOp = u.cd.pProgram->nOp; |
| 71896 | p->aOnceFlag = (u8 *)&p->apCsr[p->nCursor]; |
| 71897 | p->nOnceFlag = u.cd.pProgram->nOnce; |
| 71898 | pc = -1; |
| 71899 | memset(p->aOnceFlag, 0, p->nOnceFlag); |
| 71900 | |
| 71901 | break; |
| 71902 | } |
| @@ -71607,15 +71912,17 @@ | |
| 71912 | ** The address of the cell in the parent frame is determined by adding |
| 71913 | ** the value of the P1 argument to the value of the P1 argument to the |
| 71914 | ** calling OP_Program instruction. |
| 71915 | */ |
| 71916 | case OP_Param: { /* out2-prerelease */ |
| 71917 | #if 0 /* local variables moved into u.ce */ |
| 71918 | VdbeFrame *pFrame; |
| 71919 | Mem *pIn; |
| 71920 | #endif /* local variables moved into u.ce */ |
| 71921 | u.ce.pFrame = p->pFrame; |
| 71922 | u.ce.pIn = &u.ce.pFrame->aMem[pOp->p1 + u.ce.pFrame->aOp[u.ce.pFrame->pc].p1]; |
| 71923 | sqlite3VdbeMemShallowCopy(pOut, u.ce.pIn, MEM_Ephem); |
| 71924 | break; |
| 71925 | } |
| 71926 | |
| 71927 | #endif /* #ifndef SQLITE_OMIT_TRIGGER */ |
| 71928 | |
| @@ -71672,23 +71979,26 @@ | |
| 71979 | ** |
| 71980 | ** This instruction throws an error if the memory cell is not initially |
| 71981 | ** an integer. |
| 71982 | */ |
| 71983 | case OP_MemMax: { /* in2 */ |
| 71984 | #if 0 /* local variables moved into u.cf */ |
| 71985 | Mem *pIn1; |
| 71986 | VdbeFrame *pFrame; |
| 71987 | #endif /* local variables moved into u.cf */ |
| 71988 | if( p->pFrame ){ |
| 71989 | for(u.cf.pFrame=p->pFrame; u.cf.pFrame->pParent; u.cf.pFrame=u.cf.pFrame->pParent); |
| 71990 | u.cf.pIn1 = &u.cf.pFrame->aMem[pOp->p1]; |
| 71991 | }else{ |
| 71992 | u.cf.pIn1 = &aMem[pOp->p1]; |
| 71993 | } |
| 71994 | assert( memIsValid(u.cf.pIn1) ); |
| 71995 | sqlite3VdbeMemIntegerify(u.cf.pIn1); |
| 71996 | pIn2 = &aMem[pOp->p2]; |
| 71997 | sqlite3VdbeMemIntegerify(pIn2); |
| 71998 | if( u.cf.pIn1->u.i<pIn2->u.i){ |
| 71999 | u.cf.pIn1->u.i = pIn2->u.i; |
| 72000 | } |
| 72001 | break; |
| 72002 | } |
| 72003 | #endif /* SQLITE_OMIT_AUTOINCREMENT */ |
| 72004 | |
| @@ -71755,58 +72065,60 @@ | |
| 72065 | ** |
| 72066 | ** The P5 arguments are taken from register P2 and its |
| 72067 | ** successors. |
| 72068 | */ |
| 72069 | case OP_AggStep: { |
| 72070 | #if 0 /* local variables moved into u.cg */ |
| 72071 | int n; |
| 72072 | int i; |
| 72073 | Mem *pMem; |
| 72074 | Mem *pRec; |
| 72075 | sqlite3_context ctx; |
| 72076 | sqlite3_value **apVal; |
| 72077 | #endif /* local variables moved into u.cg */ |
| 72078 | |
| 72079 | u.cg.n = pOp->p5; |
| 72080 | assert( u.cg.n>=0 ); |
| 72081 | u.cg.pRec = &aMem[pOp->p2]; |
| 72082 | u.cg.apVal = p->apArg; |
| 72083 | assert( u.cg.apVal || u.cg.n==0 ); |
| 72084 | for(u.cg.i=0; u.cg.i<u.cg.n; u.cg.i++, u.cg.pRec++){ |
| 72085 | assert( memIsValid(u.cg.pRec) ); |
| 72086 | u.cg.apVal[u.cg.i] = u.cg.pRec; |
| 72087 | memAboutToChange(p, u.cg.pRec); |
| 72088 | sqlite3VdbeMemStoreType(u.cg.pRec); |
| 72089 | } |
| 72090 | u.cg.ctx.pFunc = pOp->p4.pFunc; |
| 72091 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 72092 | u.cg.ctx.pMem = u.cg.pMem = &aMem[pOp->p3]; |
| 72093 | u.cg.pMem->n++; |
| 72094 | u.cg.ctx.s.flags = MEM_Null; |
| 72095 | u.cg.ctx.s.z = 0; |
| 72096 | u.cg.ctx.s.zMalloc = 0; |
| 72097 | u.cg.ctx.s.xDel = 0; |
| 72098 | u.cg.ctx.s.db = db; |
| 72099 | u.cg.ctx.isError = 0; |
| 72100 | u.cg.ctx.pColl = 0; |
| 72101 | u.cg.ctx.skipFlag = 0; |
| 72102 | if( u.cg.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 72103 | assert( pOp>p->aOp ); |
| 72104 | assert( pOp[-1].p4type==P4_COLLSEQ ); |
| 72105 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 72106 | u.cg.ctx.pColl = pOp[-1].p4.pColl; |
| 72107 | } |
| 72108 | (u.cg.ctx.pFunc->xStep)(&u.cg.ctx, u.cg.n, u.cg.apVal); /* IMP: R-24505-23230 */ |
| 72109 | if( u.cg.ctx.isError ){ |
| 72110 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(&u.cg.ctx.s)); |
| 72111 | rc = u.cg.ctx.isError; |
| 72112 | } |
| 72113 | if( u.cg.ctx.skipFlag ){ |
| 72114 | assert( pOp[-1].opcode==OP_CollSeq ); |
| 72115 | u.cg.i = pOp[-1].p1; |
| 72116 | if( u.cg.i ) sqlite3VdbeMemSetInt64(&aMem[u.cg.i], 1); |
| 72117 | } |
| 72118 | |
| 72119 | sqlite3VdbeMemRelease(&u.cg.ctx.s); |
| 72120 | |
| 72121 | break; |
| 72122 | } |
| 72123 | |
| 72124 | /* Opcode: AggFinal P1 P2 * P4 * |
| @@ -71821,21 +72133,23 @@ | |
| 72133 | ** functions that can take varying numbers of arguments. The |
| 72134 | ** P4 argument is only needed for the degenerate case where |
| 72135 | ** the step function was not previously called. |
| 72136 | */ |
| 72137 | case OP_AggFinal: { |
| 72138 | #if 0 /* local variables moved into u.ch */ |
| 72139 | Mem *pMem; |
| 72140 | #endif /* local variables moved into u.ch */ |
| 72141 | assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) ); |
| 72142 | u.ch.pMem = &aMem[pOp->p1]; |
| 72143 | assert( (u.ch.pMem->flags & ~(MEM_Null|MEM_Agg))==0 ); |
| 72144 | rc = sqlite3VdbeMemFinalize(u.ch.pMem, pOp->p4.pFunc); |
| 72145 | if( rc ){ |
| 72146 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3_value_text(u.ch.pMem)); |
| 72147 | } |
| 72148 | sqlite3VdbeChangeEncoding(u.ch.pMem, encoding); |
| 72149 | UPDATE_MAX_BLOBSIZE(u.ch.pMem); |
| 72150 | if( sqlite3VdbeMemTooBig(u.ch.pMem) ){ |
| 72151 | goto too_big; |
| 72152 | } |
| 72153 | break; |
| 72154 | } |
| 72155 | |
| @@ -71850,29 +72164,31 @@ | |
| 72164 | ** in the WAL that have been checkpointed after the checkpoint |
| 72165 | ** completes into mem[P3+2]. However on an error, mem[P3+1] and |
| 72166 | ** mem[P3+2] are initialized to -1. |
| 72167 | */ |
| 72168 | case OP_Checkpoint: { |
| 72169 | #if 0 /* local variables moved into u.ci */ |
| 72170 | int i; /* Loop counter */ |
| 72171 | int aRes[3]; /* Results */ |
| 72172 | Mem *pMem; /* Write results here */ |
| 72173 | #endif /* local variables moved into u.ci */ |
| 72174 | |
| 72175 | assert( p->readOnly==0 ); |
| 72176 | u.ci.aRes[0] = 0; |
| 72177 | u.ci.aRes[1] = u.ci.aRes[2] = -1; |
| 72178 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 72179 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 72180 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| 72181 | ); |
| 72182 | rc = sqlite3Checkpoint(db, pOp->p1, pOp->p2, &u.ci.aRes[1], &u.ci.aRes[2]); |
| 72183 | if( rc==SQLITE_BUSY ){ |
| 72184 | rc = SQLITE_OK; |
| 72185 | u.ci.aRes[0] = 1; |
| 72186 | } |
| 72187 | for(u.ci.i=0, u.ci.pMem = &aMem[pOp->p3]; u.ci.i<3; u.ci.i++, u.ci.pMem++){ |
| 72188 | sqlite3VdbeMemSetInt64(u.ci.pMem, (i64)u.ci.aRes[u.ci.i]); |
| 72189 | } |
| 72190 | break; |
| 72191 | }; |
| 72192 | #endif |
| 72193 | |
| 72194 | #ifndef SQLITE_OMIT_PRAGMA |
| @@ -71886,96 +72202,98 @@ | |
| 72202 | ** If changing into or out of WAL mode the procedure is more complicated. |
| 72203 | ** |
| 72204 | ** Write a string containing the final journal-mode to register P2. |
| 72205 | */ |
| 72206 | case OP_JournalMode: { /* out2-prerelease */ |
| 72207 | #if 0 /* local variables moved into u.cj */ |
| 72208 | Btree *pBt; /* Btree to change journal mode of */ |
| 72209 | Pager *pPager; /* Pager associated with pBt */ |
| 72210 | int eNew; /* New journal mode */ |
| 72211 | int eOld; /* The old journal mode */ |
| 72212 | #ifndef SQLITE_OMIT_WAL |
| 72213 | const char *zFilename; /* Name of database file for pPager */ |
| 72214 | #endif |
| 72215 | #endif /* local variables moved into u.cj */ |
| 72216 | |
| 72217 | u.cj.eNew = pOp->p3; |
| 72218 | assert( u.cj.eNew==PAGER_JOURNALMODE_DELETE |
| 72219 | || u.cj.eNew==PAGER_JOURNALMODE_TRUNCATE |
| 72220 | || u.cj.eNew==PAGER_JOURNALMODE_PERSIST |
| 72221 | || u.cj.eNew==PAGER_JOURNALMODE_OFF |
| 72222 | || u.cj.eNew==PAGER_JOURNALMODE_MEMORY |
| 72223 | || u.cj.eNew==PAGER_JOURNALMODE_WAL |
| 72224 | || u.cj.eNew==PAGER_JOURNALMODE_QUERY |
| 72225 | ); |
| 72226 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 72227 | assert( p->readOnly==0 ); |
| 72228 | |
| 72229 | u.cj.pBt = db->aDb[pOp->p1].pBt; |
| 72230 | u.cj.pPager = sqlite3BtreePager(u.cj.pBt); |
| 72231 | u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager); |
| 72232 | if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld; |
| 72233 | if( !sqlite3PagerOkToChangeJournalMode(u.cj.pPager) ) u.cj.eNew = u.cj.eOld; |
| 72234 | |
| 72235 | #ifndef SQLITE_OMIT_WAL |
| 72236 | u.cj.zFilename = sqlite3PagerFilename(u.cj.pPager, 1); |
| 72237 | |
| 72238 | /* Do not allow a transition to journal_mode=WAL for a database |
| 72239 | ** in temporary storage or if the VFS does not support shared memory |
| 72240 | */ |
| 72241 | if( u.cj.eNew==PAGER_JOURNALMODE_WAL |
| 72242 | && (sqlite3Strlen30(u.cj.zFilename)==0 /* Temp file */ |
| 72243 | || !sqlite3PagerWalSupported(u.cj.pPager)) /* No shared-memory support */ |
| 72244 | ){ |
| 72245 | u.cj.eNew = u.cj.eOld; |
| 72246 | } |
| 72247 | |
| 72248 | if( (u.cj.eNew!=u.cj.eOld) |
| 72249 | && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL) |
| 72250 | ){ |
| 72251 | if( !db->autoCommit || db->nVdbeRead>1 ){ |
| 72252 | rc = SQLITE_ERROR; |
| 72253 | sqlite3SetString(&p->zErrMsg, db, |
| 72254 | "cannot change %s wal mode from within a transaction", |
| 72255 | (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") |
| 72256 | ); |
| 72257 | break; |
| 72258 | }else{ |
| 72259 | |
| 72260 | if( u.cj.eOld==PAGER_JOURNALMODE_WAL ){ |
| 72261 | /* If leaving WAL mode, close the log file. If successful, the call |
| 72262 | ** to PagerCloseWal() checkpoints and deletes the write-ahead-log |
| 72263 | ** file. An EXCLUSIVE lock may still be held on the database file |
| 72264 | ** after a successful return. |
| 72265 | */ |
| 72266 | rc = sqlite3PagerCloseWal(u.cj.pPager); |
| 72267 | if( rc==SQLITE_OK ){ |
| 72268 | sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew); |
| 72269 | } |
| 72270 | }else if( u.cj.eOld==PAGER_JOURNALMODE_MEMORY ){ |
| 72271 | /* Cannot transition directly from MEMORY to WAL. Use mode OFF |
| 72272 | ** as an intermediate */ |
| 72273 | sqlite3PagerSetJournalMode(u.cj.pPager, PAGER_JOURNALMODE_OFF); |
| 72274 | } |
| 72275 | |
| 72276 | /* Open a transaction on the database file. Regardless of the journal |
| 72277 | ** mode, this transaction always uses a rollback journal. |
| 72278 | */ |
| 72279 | assert( sqlite3BtreeIsInTrans(u.cj.pBt)==0 ); |
| 72280 | if( rc==SQLITE_OK ){ |
| 72281 | rc = sqlite3BtreeSetVersion(u.cj.pBt, (u.cj.eNew==PAGER_JOURNALMODE_WAL ? 2 : 1)); |
| 72282 | } |
| 72283 | } |
| 72284 | } |
| 72285 | #endif /* ifndef SQLITE_OMIT_WAL */ |
| 72286 | |
| 72287 | if( rc ){ |
| 72288 | u.cj.eNew = u.cj.eOld; |
| 72289 | } |
| 72290 | u.cj.eNew = sqlite3PagerSetJournalMode(u.cj.pPager, u.cj.eNew); |
| 72291 | |
| 72292 | pOut = &aMem[pOp->p2]; |
| 72293 | pOut->flags = MEM_Str|MEM_Static|MEM_Term; |
| 72294 | pOut->z = (char *)sqlite3JournalModename(u.cj.eNew); |
| 72295 | pOut->n = sqlite3Strlen30(pOut->z); |
| 72296 | pOut->enc = SQLITE_UTF8; |
| 72297 | sqlite3VdbeChangeEncoding(pOut, encoding); |
| 72298 | break; |
| 72299 | }; |
| @@ -72001,17 +72319,19 @@ | |
| 72319 | ** Perform a single step of the incremental vacuum procedure on |
| 72320 | ** the P1 database. If the vacuum has finished, jump to instruction |
| 72321 | ** P2. Otherwise, fall through to the next instruction. |
| 72322 | */ |
| 72323 | case OP_IncrVacuum: { /* jump */ |
| 72324 | #if 0 /* local variables moved into u.ck */ |
| 72325 | Btree *pBt; |
| 72326 | #endif /* local variables moved into u.ck */ |
| 72327 | |
| 72328 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 72329 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 72330 | assert( p->readOnly==0 ); |
| 72331 | u.ck.pBt = db->aDb[pOp->p1].pBt; |
| 72332 | rc = sqlite3BtreeIncrVacuum(u.ck.pBt); |
| 72333 | if( rc==SQLITE_DONE ){ |
| 72334 | pc = pOp->p2 - 1; |
| 72335 | rc = SQLITE_OK; |
| 72336 | } |
| 72337 | break; |
| @@ -72078,14 +72398,16 @@ | |
| 72398 | ** Also, whether or not P4 is set, check that this is not being called from |
| 72399 | ** within a callback to a virtual table xSync() method. If it is, the error |
| 72400 | ** code will be set to SQLITE_LOCKED. |
| 72401 | */ |
| 72402 | case OP_VBegin: { |
| 72403 | #if 0 /* local variables moved into u.cl */ |
| 72404 | VTable *pVTab; |
| 72405 | #endif /* local variables moved into u.cl */ |
| 72406 | u.cl.pVTab = pOp->p4.pVtab; |
| 72407 | rc = sqlite3VtabBegin(db, u.cl.pVTab); |
| 72408 | if( u.cl.pVTab ) sqlite3VtabImportErrmsg(p, u.cl.pVTab->pVtab); |
| 72409 | break; |
| 72410 | } |
| 72411 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 72412 | |
| 72413 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| @@ -72120,34 +72442,36 @@ | |
| 72442 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72443 | ** P1 is a cursor number. This opcode opens a cursor to the virtual |
| 72444 | ** table and stores that cursor in P1. |
| 72445 | */ |
| 72446 | case OP_VOpen: { |
| 72447 | #if 0 /* local variables moved into u.cm */ |
| 72448 | VdbeCursor *pCur; |
| 72449 | sqlite3_vtab_cursor *pVtabCursor; |
| 72450 | sqlite3_vtab *pVtab; |
| 72451 | sqlite3_module *pModule; |
| 72452 | #endif /* local variables moved into u.cm */ |
| 72453 | |
| 72454 | assert( p->bIsReader ); |
| 72455 | u.cm.pCur = 0; |
| 72456 | u.cm.pVtabCursor = 0; |
| 72457 | u.cm.pVtab = pOp->p4.pVtab->pVtab; |
| 72458 | u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule; |
| 72459 | assert(u.cm.pVtab && u.cm.pModule); |
| 72460 | rc = u.cm.pModule->xOpen(u.cm.pVtab, &u.cm.pVtabCursor); |
| 72461 | sqlite3VtabImportErrmsg(p, u.cm.pVtab); |
| 72462 | if( SQLITE_OK==rc ){ |
| 72463 | /* Initialize sqlite3_vtab_cursor base class */ |
| 72464 | u.cm.pVtabCursor->pVtab = u.cm.pVtab; |
| 72465 | |
| 72466 | /* Initialize vdbe cursor object */ |
| 72467 | u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 72468 | if( u.cm.pCur ){ |
| 72469 | u.cm.pCur->pVtabCursor = u.cm.pVtabCursor; |
| 72470 | }else{ |
| 72471 | db->mallocFailed = 1; |
| 72472 | u.cm.pModule->xClose(u.cm.pVtabCursor); |
| 72473 | } |
| 72474 | } |
| 72475 | break; |
| 72476 | } |
| 72477 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -72171,10 +72495,11 @@ | |
| 72495 | ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter. |
| 72496 | ** |
| 72497 | ** A jump is made to P2 if the result set after filtering would be empty. |
| 72498 | */ |
| 72499 | case OP_VFilter: { /* jump */ |
| 72500 | #if 0 /* local variables moved into u.cn */ |
| 72501 | int nArg; |
| 72502 | int iQuery; |
| 72503 | const sqlite3_module *pModule; |
| 72504 | Mem *pQuery; |
| 72505 | Mem *pArgc; |
| @@ -72182,48 +72507,49 @@ | |
| 72507 | sqlite3_vtab *pVtab; |
| 72508 | VdbeCursor *pCur; |
| 72509 | int res; |
| 72510 | int i; |
| 72511 | Mem **apArg; |
| 72512 | #endif /* local variables moved into u.cn */ |
| 72513 | |
| 72514 | u.cn.pQuery = &aMem[pOp->p3]; |
| 72515 | u.cn.pArgc = &u.cn.pQuery[1]; |
| 72516 | u.cn.pCur = p->apCsr[pOp->p1]; |
| 72517 | assert( memIsValid(u.cn.pQuery) ); |
| 72518 | REGISTER_TRACE(pOp->p3, u.cn.pQuery); |
| 72519 | assert( u.cn.pCur->pVtabCursor ); |
| 72520 | u.cn.pVtabCursor = u.cn.pCur->pVtabCursor; |
| 72521 | u.cn.pVtab = u.cn.pVtabCursor->pVtab; |
| 72522 | u.cn.pModule = u.cn.pVtab->pModule; |
| 72523 | |
| 72524 | /* Grab the index number and argc parameters */ |
| 72525 | assert( (u.cn.pQuery->flags&MEM_Int)!=0 && u.cn.pArgc->flags==MEM_Int ); |
| 72526 | u.cn.nArg = (int)u.cn.pArgc->u.i; |
| 72527 | u.cn.iQuery = (int)u.cn.pQuery->u.i; |
| 72528 | |
| 72529 | /* Invoke the xFilter method */ |
| 72530 | { |
| 72531 | u.cn.res = 0; |
| 72532 | u.cn.apArg = p->apArg; |
| 72533 | for(u.cn.i = 0; u.cn.i<u.cn.nArg; u.cn.i++){ |
| 72534 | u.cn.apArg[u.cn.i] = &u.cn.pArgc[u.cn.i+1]; |
| 72535 | sqlite3VdbeMemStoreType(u.cn.apArg[u.cn.i]); |
| 72536 | } |
| 72537 | |
| 72538 | p->inVtabMethod = 1; |
| 72539 | rc = u.cn.pModule->xFilter(u.cn.pVtabCursor, u.cn.iQuery, pOp->p4.z, u.cn.nArg, u.cn.apArg); |
| 72540 | p->inVtabMethod = 0; |
| 72541 | sqlite3VtabImportErrmsg(p, u.cn.pVtab); |
| 72542 | if( rc==SQLITE_OK ){ |
| 72543 | u.cn.res = u.cn.pModule->xEof(u.cn.pVtabCursor); |
| 72544 | } |
| 72545 | |
| 72546 | if( u.cn.res ){ |
| 72547 | pc = pOp->p2 - 1; |
| 72548 | } |
| 72549 | } |
| 72550 | u.cn.pCur->nullRow = 0; |
| 72551 | |
| 72552 | break; |
| 72553 | } |
| 72554 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| 72555 | |
| @@ -72234,53 +72560,55 @@ | |
| 72560 | ** Store the value of the P2-th column of |
| 72561 | ** the row of the virtual-table that the |
| 72562 | ** P1 cursor is pointing to into register P3. |
| 72563 | */ |
| 72564 | case OP_VColumn: { |
| 72565 | #if 0 /* local variables moved into u.co */ |
| 72566 | sqlite3_vtab *pVtab; |
| 72567 | const sqlite3_module *pModule; |
| 72568 | Mem *pDest; |
| 72569 | sqlite3_context sContext; |
| 72570 | #endif /* local variables moved into u.co */ |
| 72571 | |
| 72572 | VdbeCursor *pCur = p->apCsr[pOp->p1]; |
| 72573 | assert( pCur->pVtabCursor ); |
| 72574 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 72575 | u.co.pDest = &aMem[pOp->p3]; |
| 72576 | memAboutToChange(p, u.co.pDest); |
| 72577 | if( pCur->nullRow ){ |
| 72578 | sqlite3VdbeMemSetNull(u.co.pDest); |
| 72579 | break; |
| 72580 | } |
| 72581 | u.co.pVtab = pCur->pVtabCursor->pVtab; |
| 72582 | u.co.pModule = u.co.pVtab->pModule; |
| 72583 | assert( u.co.pModule->xColumn ); |
| 72584 | memset(&u.co.sContext, 0, sizeof(u.co.sContext)); |
| 72585 | |
| 72586 | /* The output cell may already have a buffer allocated. Move |
| 72587 | ** the current contents to u.co.sContext.s so in case the user-function |
| 72588 | ** can use the already allocated buffer instead of allocating a |
| 72589 | ** new one. |
| 72590 | */ |
| 72591 | sqlite3VdbeMemMove(&u.co.sContext.s, u.co.pDest); |
| 72592 | MemSetTypeFlag(&u.co.sContext.s, MEM_Null); |
| 72593 | |
| 72594 | rc = u.co.pModule->xColumn(pCur->pVtabCursor, &u.co.sContext, pOp->p2); |
| 72595 | sqlite3VtabImportErrmsg(p, u.co.pVtab); |
| 72596 | if( u.co.sContext.isError ){ |
| 72597 | rc = u.co.sContext.isError; |
| 72598 | } |
| 72599 | |
| 72600 | /* Copy the result of the function to the P3 register. We |
| 72601 | ** do this regardless of whether or not an error occurred to ensure any |
| 72602 | ** dynamic allocation in u.co.sContext.s (a Mem struct) is released. |
| 72603 | */ |
| 72604 | sqlite3VdbeChangeEncoding(&u.co.sContext.s, encoding); |
| 72605 | sqlite3VdbeMemMove(u.co.pDest, &u.co.sContext.s); |
| 72606 | REGISTER_TRACE(pOp->p3, u.co.pDest); |
| 72607 | UPDATE_MAX_BLOBSIZE(u.co.pDest); |
| 72608 | |
| 72609 | if( sqlite3VdbeMemTooBig(u.co.pDest) ){ |
| 72610 | goto too_big; |
| 72611 | } |
| 72612 | break; |
| 72613 | } |
| 72614 | #endif /* SQLITE_OMIT_VIRTUALTABLE */ |
| @@ -72291,40 +72619,42 @@ | |
| 72619 | ** Advance virtual table P1 to the next row in its result set and |
| 72620 | ** jump to instruction P2. Or, if the virtual table has reached |
| 72621 | ** the end of its result set, then fall through to the next instruction. |
| 72622 | */ |
| 72623 | case OP_VNext: { /* jump */ |
| 72624 | #if 0 /* local variables moved into u.cp */ |
| 72625 | sqlite3_vtab *pVtab; |
| 72626 | const sqlite3_module *pModule; |
| 72627 | int res; |
| 72628 | VdbeCursor *pCur; |
| 72629 | #endif /* local variables moved into u.cp */ |
| 72630 | |
| 72631 | u.cp.res = 0; |
| 72632 | u.cp.pCur = p->apCsr[pOp->p1]; |
| 72633 | assert( u.cp.pCur->pVtabCursor ); |
| 72634 | if( u.cp.pCur->nullRow ){ |
| 72635 | break; |
| 72636 | } |
| 72637 | u.cp.pVtab = u.cp.pCur->pVtabCursor->pVtab; |
| 72638 | u.cp.pModule = u.cp.pVtab->pModule; |
| 72639 | assert( u.cp.pModule->xNext ); |
| 72640 | |
| 72641 | /* Invoke the xNext() method of the module. There is no way for the |
| 72642 | ** underlying implementation to return an error if one occurs during |
| 72643 | ** xNext(). Instead, if an error occurs, true is returned (indicating that |
| 72644 | ** data is available) and the error code returned when xColumn or |
| 72645 | ** some other method is next invoked on the save virtual table cursor. |
| 72646 | */ |
| 72647 | p->inVtabMethod = 1; |
| 72648 | rc = u.cp.pModule->xNext(u.cp.pCur->pVtabCursor); |
| 72649 | p->inVtabMethod = 0; |
| 72650 | sqlite3VtabImportErrmsg(p, u.cp.pVtab); |
| 72651 | if( rc==SQLITE_OK ){ |
| 72652 | u.cp.res = u.cp.pModule->xEof(u.cp.pCur->pVtabCursor); |
| 72653 | } |
| 72654 | |
| 72655 | if( !u.cp.res ){ |
| 72656 | /* If there is data, jump to P2 */ |
| 72657 | pc = pOp->p2 - 1; |
| 72658 | } |
| 72659 | goto check_for_interrupt; |
| 72660 | } |
| @@ -72336,27 +72666,29 @@ | |
| 72666 | ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure. |
| 72667 | ** This opcode invokes the corresponding xRename method. The value |
| 72668 | ** in register P1 is passed as the zName argument to the xRename method. |
| 72669 | */ |
| 72670 | case OP_VRename: { |
| 72671 | #if 0 /* local variables moved into u.cq */ |
| 72672 | sqlite3_vtab *pVtab; |
| 72673 | Mem *pName; |
| 72674 | #endif /* local variables moved into u.cq */ |
| 72675 | |
| 72676 | u.cq.pVtab = pOp->p4.pVtab->pVtab; |
| 72677 | u.cq.pName = &aMem[pOp->p1]; |
| 72678 | assert( u.cq.pVtab->pModule->xRename ); |
| 72679 | assert( memIsValid(u.cq.pName) ); |
| 72680 | assert( p->readOnly==0 ); |
| 72681 | REGISTER_TRACE(pOp->p1, u.cq.pName); |
| 72682 | assert( u.cq.pName->flags & MEM_Str ); |
| 72683 | testcase( u.cq.pName->enc==SQLITE_UTF8 ); |
| 72684 | testcase( u.cq.pName->enc==SQLITE_UTF16BE ); |
| 72685 | testcase( u.cq.pName->enc==SQLITE_UTF16LE ); |
| 72686 | rc = sqlite3VdbeChangeEncoding(u.cq.pName, SQLITE_UTF8); |
| 72687 | if( rc==SQLITE_OK ){ |
| 72688 | rc = u.cq.pVtab->pModule->xRename(u.cq.pVtab, u.cq.pName->z); |
| 72689 | sqlite3VtabImportErrmsg(p, u.cq.pVtab); |
| 72690 | p->expired = 0; |
| 72691 | } |
| 72692 | break; |
| 72693 | } |
| 72694 | #endif |
| @@ -72385,44 +72717,46 @@ | |
| 72717 | ** P1 is a boolean flag. If it is set to true and the xUpdate call |
| 72718 | ** is successful, then the value returned by sqlite3_last_insert_rowid() |
| 72719 | ** is set to the value of the rowid for the row just inserted. |
| 72720 | */ |
| 72721 | case OP_VUpdate: { |
| 72722 | #if 0 /* local variables moved into u.cr */ |
| 72723 | sqlite3_vtab *pVtab; |
| 72724 | sqlite3_module *pModule; |
| 72725 | int nArg; |
| 72726 | int i; |
| 72727 | sqlite_int64 rowid; |
| 72728 | Mem **apArg; |
| 72729 | Mem *pX; |
| 72730 | #endif /* local variables moved into u.cr */ |
| 72731 | |
| 72732 | assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 72733 | || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| 72734 | ); |
| 72735 | assert( p->readOnly==0 ); |
| 72736 | u.cr.pVtab = pOp->p4.pVtab->pVtab; |
| 72737 | u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule; |
| 72738 | u.cr.nArg = pOp->p2; |
| 72739 | assert( pOp->p4type==P4_VTAB ); |
| 72740 | if( ALWAYS(u.cr.pModule->xUpdate) ){ |
| 72741 | u8 vtabOnConflict = db->vtabOnConflict; |
| 72742 | u.cr.apArg = p->apArg; |
| 72743 | u.cr.pX = &aMem[pOp->p3]; |
| 72744 | for(u.cr.i=0; u.cr.i<u.cr.nArg; u.cr.i++){ |
| 72745 | assert( memIsValid(u.cr.pX) ); |
| 72746 | memAboutToChange(p, u.cr.pX); |
| 72747 | sqlite3VdbeMemStoreType(u.cr.pX); |
| 72748 | u.cr.apArg[u.cr.i] = u.cr.pX; |
| 72749 | u.cr.pX++; |
| 72750 | } |
| 72751 | db->vtabOnConflict = pOp->p5; |
| 72752 | rc = u.cr.pModule->xUpdate(u.cr.pVtab, u.cr.nArg, u.cr.apArg, &u.cr.rowid); |
| 72753 | db->vtabOnConflict = vtabOnConflict; |
| 72754 | sqlite3VtabImportErrmsg(p, u.cr.pVtab); |
| 72755 | if( rc==SQLITE_OK && pOp->p1 ){ |
| 72756 | assert( u.cr.nArg>1 && u.cr.apArg[0] && (u.cr.apArg[0]->flags&MEM_Null) ); |
| 72757 | db->lastRowid = lastRowid = u.cr.rowid; |
| 72758 | } |
| 72759 | if( (rc&0xff)==SQLITE_CONSTRAINT && pOp->p4.pVtab->bConstraint ){ |
| 72760 | if( pOp->p5==OE_Ignore ){ |
| 72761 | rc = SQLITE_OK; |
| 72762 | }else{ |
| @@ -72478,36 +72812,38 @@ | |
| 72812 | ** |
| 72813 | ** If tracing is enabled (by the sqlite3_trace()) interface, then |
| 72814 | ** the UTF-8 string contained in P4 is emitted on the trace callback. |
| 72815 | */ |
| 72816 | case OP_Trace: { |
| 72817 | #if 0 /* local variables moved into u.cs */ |
| 72818 | char *zTrace; |
| 72819 | char *z; |
| 72820 | #endif /* local variables moved into u.cs */ |
| 72821 | |
| 72822 | if( db->xTrace |
| 72823 | && !p->doingRerun |
| 72824 | && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72825 | ){ |
| 72826 | u.cs.z = sqlite3VdbeExpandSql(p, u.cs.zTrace); |
| 72827 | db->xTrace(db->pTraceArg, u.cs.z); |
| 72828 | sqlite3DbFree(db, u.cs.z); |
| 72829 | } |
| 72830 | #ifdef SQLITE_USE_FCNTL_TRACE |
| 72831 | u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql); |
| 72832 | if( u.cs.zTrace ){ |
| 72833 | int i; |
| 72834 | for(i=0; i<db->nDb; i++){ |
| 72835 | if( ((1<<i) & p->btreeMask)==0 ) continue; |
| 72836 | sqlite3_file_control(db, db->aDb[i].zName, SQLITE_FCNTL_TRACE, u.cs.zTrace); |
| 72837 | } |
| 72838 | } |
| 72839 | #endif /* SQLITE_USE_FCNTL_TRACE */ |
| 72840 | #ifdef SQLITE_DEBUG |
| 72841 | if( (db->flags & SQLITE_SqlTrace)!=0 |
| 72842 | && (u.cs.zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0 |
| 72843 | ){ |
| 72844 | sqlite3DebugPrintf("SQL-trace: %s\n", u.cs.zTrace); |
| 72845 | } |
| 72846 | #endif /* SQLITE_DEBUG */ |
| 72847 | break; |
| 72848 | } |
| 72849 | #endif |
| @@ -72632,11 +72968,10 @@ | |
| 72968 | rc = SQLITE_INTERRUPT; |
| 72969 | p->rc = rc; |
| 72970 | sqlite3SetString(&p->zErrMsg, db, "%s", sqlite3ErrStr(rc)); |
| 72971 | goto vdbe_error_halt; |
| 72972 | } |
| 72973 | |
| 72974 | /************** End of vdbe.c ************************************************/ |
| 72975 | /************** Begin file vdbeblob.c ****************************************/ |
| 72976 | /* |
| 72977 | ** 2007 May 1 |
| @@ -72891,11 +73226,11 @@ | |
| 73226 | sqlite3BtreeLeaveAll(db); |
| 73227 | goto blob_open_out; |
| 73228 | } |
| 73229 | } |
| 73230 | |
| 73231 | pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(db); |
| 73232 | assert( pBlob->pStmt || db->mallocFailed ); |
| 73233 | if( pBlob->pStmt ){ |
| 73234 | Vdbe *v = (Vdbe *)pBlob->pStmt; |
| 73235 | int iDb = sqlite3SchemaToIndex(db, pTab->pSchema); |
| 73236 | |
| @@ -76798,29 +77133,20 @@ | |
| 77133 | } |
| 77134 | return p; |
| 77135 | } |
| 77136 | |
| 77137 | /* |
| 77138 | ** Return 1 if an expression must be FALSE in all cases and 0 if the |
| 77139 | ** expression might be true. This is an optimization. If is OK to |
| 77140 | ** return 0 here even if the expression really is always false (a |
| 77141 | ** false negative). But it is a bug to return 1 if the expression |
| 77142 | ** might be true in some rare circumstances (a false positive.) |
| 77143 | ** |
| 77144 | ** Note that if the expression is part of conditional for a |
| 77145 | ** LEFT JOIN, then we cannot determine at compile-time whether or not |
| 77146 | ** is it true or false, so always return 0. |
| 77147 | */ |
| 77148 | static int exprAlwaysFalse(Expr *p){ |
| 77149 | int v = 0; |
| 77150 | if( ExprHasProperty(p, EP_FromJoin) ) return 0; |
| 77151 | if( !sqlite3ExprIsInteger(p, &v) ) return 0; |
| 77152 | return v==0; |
| @@ -78454,15 +78780,10 @@ | |
| 78780 | ** added to the column cache after this call are removed when the |
| 78781 | ** corresponding pop occurs. |
| 78782 | */ |
| 78783 | SQLITE_PRIVATE void sqlite3ExprCachePush(Parse *pParse){ |
| 78784 | pParse->iCacheLevel++; |
| 78785 | } |
| 78786 | |
| 78787 | /* |
| 78788 | ** Remove from the column cache any entries that were added since the |
| 78789 | ** the previous N Push operations. In other words, restore the cache |
| @@ -78472,15 +78793,10 @@ | |
| 78793 | int i; |
| 78794 | struct yColCache *p; |
| 78795 | assert( N>0 ); |
| 78796 | assert( pParse->iCacheLevel>=N ); |
| 78797 | pParse->iCacheLevel -= N; |
| 78798 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 78799 | if( p->iReg && p->iLevel>pParse->iCacheLevel ){ |
| 78800 | cacheEntryClear(pParse, p); |
| 78801 | p->iReg = 0; |
| 78802 | } |
| @@ -78571,15 +78887,10 @@ | |
| 78887 | */ |
| 78888 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse *pParse){ |
| 78889 | int i; |
| 78890 | struct yColCache *p; |
| 78891 | |
| 78892 | for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){ |
| 78893 | if( p->iReg ){ |
| 78894 | cacheEntryClear(pParse, p); |
| 78895 | p->iReg = 0; |
| 78896 | } |
| @@ -79663,11 +79974,11 @@ | |
| 79974 | sqlite3ExplainPush(pOut); |
| 79975 | for(i=0; i<pList->nExpr; i++){ |
| 79976 | sqlite3ExplainPrintf(pOut, "item[%d] = ", i); |
| 79977 | sqlite3ExplainPush(pOut); |
| 79978 | sqlite3ExplainExpr(pOut, pList->a[i].pExpr); |
| 79979 | sqlite3ExplainPop(pOut); |
| 79980 | if( pList->a[i].zName ){ |
| 79981 | sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName); |
| 79982 | } |
| 79983 | if( pList->a[i].bSpanIsTab ){ |
| 79984 | sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan); |
| @@ -79712,21 +80023,11 @@ | |
| 80023 | if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ |
| 80024 | sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0); |
| 80025 | }else{ |
| 80026 | int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 80027 | if( inReg!=target+i ){ |
| 80028 | sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i); |
| 80029 | } |
| 80030 | } |
| 80031 | } |
| 80032 | return n; |
| 80033 | } |
| @@ -79813,23 +80114,21 @@ | |
| 80114 | op = pExpr->op; |
| 80115 | switch( op ){ |
| 80116 | case TK_AND: { |
| 80117 | int d2 = sqlite3VdbeMakeLabel(v); |
| 80118 | testcase( jumpIfNull==0 ); |
| 80119 | sqlite3ExprCachePush(pParse); |
| 80120 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, d2,jumpIfNull^SQLITE_JUMPIFNULL); |
| 80121 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 80122 | sqlite3VdbeResolveLabel(v, d2); |
| 80123 | sqlite3ExprCachePop(pParse, 1); |
| 80124 | break; |
| 80125 | } |
| 80126 | case TK_OR: { |
| 80127 | testcase( jumpIfNull==0 ); |
| 80128 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 80129 | sqlite3ExprIfTrue(pParse, pExpr->pRight, dest, jumpIfNull); |
| 80130 | break; |
| 80131 | } |
| 80132 | case TK_NOT: { |
| 80133 | testcase( jumpIfNull==0 ); |
| 80134 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| @@ -79900,20 +80199,14 @@ | |
| 80199 | sqlite3VdbeResolveLabel(v, destIfFalse); |
| 80200 | break; |
| 80201 | } |
| 80202 | #endif |
| 80203 | default: { |
| 80204 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 80205 | sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0); |
| 80206 | testcase( regFree1==0 ); |
| 80207 | testcase( jumpIfNull==0 ); |
| 80208 | break; |
| 80209 | } |
| 80210 | } |
| 80211 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 80212 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -79972,20 +80265,18 @@ | |
| 80265 | |
| 80266 | switch( pExpr->op ){ |
| 80267 | case TK_AND: { |
| 80268 | testcase( jumpIfNull==0 ); |
| 80269 | sqlite3ExprIfFalse(pParse, pExpr->pLeft, dest, jumpIfNull); |
| 80270 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 80271 | break; |
| 80272 | } |
| 80273 | case TK_OR: { |
| 80274 | int d2 = sqlite3VdbeMakeLabel(v); |
| 80275 | testcase( jumpIfNull==0 ); |
| 80276 | sqlite3ExprCachePush(pParse); |
| 80277 | sqlite3ExprIfTrue(pParse, pExpr->pLeft, d2, jumpIfNull^SQLITE_JUMPIFNULL); |
| 80278 | sqlite3ExprIfFalse(pParse, pExpr->pRight, dest, jumpIfNull); |
| 80279 | sqlite3VdbeResolveLabel(v, d2); |
| 80280 | sqlite3ExprCachePop(pParse, 1); |
| 80281 | break; |
| 80282 | } |
| @@ -80053,20 +80344,14 @@ | |
| 80344 | } |
| 80345 | break; |
| 80346 | } |
| 80347 | #endif |
| 80348 | default: { |
| 80349 | r1 = sqlite3ExprCodeTemp(pParse, pExpr, ®Free1); |
| 80350 | sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0); |
| 80351 | testcase( regFree1==0 ); |
| 80352 | testcase( jumpIfNull==0 ); |
| 80353 | break; |
| 80354 | } |
| 80355 | } |
| 80356 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 80357 | sqlite3ReleaseTempReg(pParse, regFree2); |
| @@ -83162,10 +83447,14 @@ | |
| 83447 | { |
| 83448 | int rc = SQLITE_OK; |
| 83449 | if( pExpr ){ |
| 83450 | if( pExpr->op!=TK_ID ){ |
| 83451 | rc = sqlite3ResolveExprNames(pName, pExpr); |
| 83452 | if( rc==SQLITE_OK && !sqlite3ExprIsConstant(pExpr) ){ |
| 83453 | sqlite3ErrorMsg(pName->pParse, "invalid name: \"%s\"", pExpr->u.zToken); |
| 83454 | return SQLITE_ERROR; |
| 83455 | } |
| 83456 | }else{ |
| 83457 | pExpr->op = TK_STRING; |
| 83458 | } |
| 83459 | } |
| 83460 | return rc; |
| @@ -87940,13 +88229,13 @@ | |
| 88229 | sqlite3StrAccumInit(&errMsg, 0, 0, 200); |
| 88230 | errMsg.db = pParse->db; |
| 88231 | for(j=0; j<pIdx->nKeyCol; j++){ |
| 88232 | char *zCol = pTab->aCol[pIdx->aiColumn[j]].zName; |
| 88233 | if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2); |
| 88234 | sqlite3StrAccumAppend(&errMsg, pTab->zName, -1); |
| 88235 | sqlite3StrAccumAppend(&errMsg, ".", 1); |
| 88236 | sqlite3StrAccumAppend(&errMsg, zCol, -1); |
| 88237 | } |
| 88238 | zErr = sqlite3StrAccumFinish(&errMsg); |
| 88239 | sqlite3HaltConstraint(pParse, |
| 88240 | (pIdx->autoIndex==2)?SQLITE_CONSTRAINT_PRIMARYKEY:SQLITE_CONSTRAINT_UNIQUE, |
| 88241 | onError, zErr, P4_DYNAMIC, P5_ConstraintUnique); |
| @@ -88134,13 +88423,12 @@ | |
| 88423 | } |
| 88424 | if( pKey ){ |
| 88425 | assert( sqlite3KeyInfoIsWriteable(pKey) ); |
| 88426 | for(i=0; i<nCol; i++){ |
| 88427 | char *zColl = pIdx->azColl[i]; |
| 88428 | if( NEVER(zColl==0) ) zColl = "BINARY"; |
| 88429 | pKey->aColl[i] = sqlite3LocateCollSeq(pParse, zColl); |
| 88430 | pKey->aSortOrder[i] = pIdx->aSortOrder[i]; |
| 88431 | } |
| 88432 | if( pParse->nErr ){ |
| 88433 | sqlite3KeyInfoUnref(pKey); |
| 88434 | }else{ |
| @@ -88509,10 +88797,11 @@ | |
| 88797 | int bestScore = 0; /* Score of best match */ |
| 88798 | int h; /* Hash value */ |
| 88799 | |
| 88800 | assert( nArg>=(-2) ); |
| 88801 | assert( nArg>=(-1) || createFlag==0 ); |
| 88802 | assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE ); |
| 88803 | h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % ArraySize(db->aFunc.a); |
| 88804 | |
| 88805 | /* First search for a match amongst the application-defined functions. |
| 88806 | */ |
| 88807 | p = functionSearch(&db->aFunc, h, zName, nName); |
| @@ -89399,10 +89688,11 @@ | |
| 89688 | Vdbe *v = pParse->pVdbe; |
| 89689 | int j; |
| 89690 | Table *pTab = pIdx->pTable; |
| 89691 | int regBase; |
| 89692 | int nCol; |
| 89693 | Index *pPk; |
| 89694 | |
| 89695 | if( piPartIdxLabel ){ |
| 89696 | if( pIdx->pPartIdxWhere ){ |
| 89697 | *piPartIdxLabel = sqlite3VdbeMakeLabel(v); |
| 89698 | pParse->iPartIdxTab = iDataCur; |
| @@ -89412,25 +89702,32 @@ | |
| 89702 | *piPartIdxLabel = 0; |
| 89703 | } |
| 89704 | } |
| 89705 | nCol = (prefixOnly && pIdx->uniqNotNull) ? pIdx->nKeyCol : pIdx->nColumn; |
| 89706 | regBase = sqlite3GetTempRange(pParse, nCol); |
| 89707 | pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab); |
| 89708 | for(j=0; j<nCol; j++){ |
| 89709 | i16 idx = pIdx->aiColumn[j]; |
| 89710 | if( pPk ) idx = sqlite3ColumnOfIndex(pPk, idx); |
| 89711 | if( idx<0 || idx==pTab->iPKey ){ |
| 89712 | sqlite3VdbeAddOp2(v, OP_Rowid, iDataCur, regBase+j); |
| 89713 | }else{ |
| 89714 | sqlite3VdbeAddOp3(v, OP_Column, iDataCur, idx, regBase+j); |
| 89715 | sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[j], -1); |
| 89716 | } |
| 89717 | } |
| 89718 | if( regOut ){ |
| 89719 | const char *zAff; |
| 89720 | if( pTab->pSelect |
| 89721 | || OptimizationDisabled(pParse->db, SQLITE_IdxRealAsInt) |
| 89722 | ){ |
| 89723 | zAff = 0; |
| 89724 | }else{ |
| 89725 | zAff = sqlite3IndexAffinityStr(v, pIdx); |
| 89726 | } |
| 89727 | sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regOut); |
| 89728 | sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT); |
| 89729 | } |
| 89730 | sqlite3ReleaseTempRange(pParse, regBase, nCol); |
| 89731 | return regBase; |
| 89732 | } |
| 89733 | |
| @@ -89652,36 +89949,10 @@ | |
| 89949 | } |
| 89950 | if( nNeedle>nHaystack ) N = 0; |
| 89951 | sqlite3_result_int(context, N); |
| 89952 | } |
| 89953 | |
| 89954 | /* |
| 89955 | ** Implementation of the substr() function. |
| 89956 | ** |
| 89957 | ** substr(x,p1,p2) returns p2 characters of x[] beginning with p1. |
| 89958 | ** p1 is 1-indexed. So substr(x,1,1) returns the first character |
| @@ -90971,15 +91242,15 @@ | |
| 91242 | nSep = sqlite3_value_bytes(argv[1]); |
| 91243 | }else{ |
| 91244 | zSep = ","; |
| 91245 | nSep = 1; |
| 91246 | } |
| 91247 | sqlite3StrAccumAppend(pAccum, zSep, nSep); |
| 91248 | } |
| 91249 | zVal = (char*)sqlite3_value_text(argv[0]); |
| 91250 | nVal = sqlite3_value_bytes(argv[0]); |
| 91251 | sqlite3StrAccumAppend(pAccum, zVal, nVal); |
| 91252 | } |
| 91253 | } |
| 91254 | static void groupConcatFinalize(sqlite3_context *context){ |
| 91255 | StrAccum *pAccum; |
| 91256 | pAccum = sqlite3_aggregate_context(context, 0); |
| @@ -91108,11 +91379,10 @@ | |
| 91379 | FUNCTION2(typeof, 1, 0, 0, typeofFunc, SQLITE_FUNC_TYPEOF), |
| 91380 | FUNCTION2(length, 1, 0, 0, lengthFunc, SQLITE_FUNC_LENGTH), |
| 91381 | FUNCTION(instr, 2, 0, 0, instrFunc ), |
| 91382 | FUNCTION(substr, 2, 0, 0, substrFunc ), |
| 91383 | FUNCTION(substr, 3, 0, 0, substrFunc ), |
| 91384 | FUNCTION(unicode, 1, 0, 0, unicodeFunc ), |
| 91385 | FUNCTION(char, -1, 0, 0, charFunc ), |
| 91386 | FUNCTION(abs, 1, 0, 0, absFunc ), |
| 91387 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 91388 | FUNCTION(round, 1, 0, 0, roundFunc ), |
| @@ -93779,11 +94049,10 @@ | |
| 94049 | int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */ |
| 94050 | int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */ |
| 94051 | int ipkTop = 0; /* Top of the rowid change constraint check */ |
| 94052 | int ipkBottom = 0; /* Bottom of the rowid change constraint check */ |
| 94053 | u8 isUpdate; /* True if this is an UPDATE operation */ |
| 94054 | |
| 94055 | isUpdate = regOldData!=0; |
| 94056 | db = pParse->db; |
| 94057 | v = sqlite3GetVdbe(pParse); |
| 94058 | assert( v!=0 ); |
| @@ -94010,13 +94279,11 @@ | |
| 94279 | regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn); |
| 94280 | for(i=0; i<pIdx->nColumn; i++){ |
| 94281 | int iField = pIdx->aiColumn[i]; |
| 94282 | int x; |
| 94283 | if( iField<0 || iField==pTab->iPKey ){ |
| 94284 | x = regNewData; |
| 94285 | }else{ |
| 94286 | x = iField + regNewData + 1; |
| 94287 | } |
| 94288 | sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i); |
| 94289 | VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName)); |
| @@ -94052,53 +94319,51 @@ | |
| 94319 | sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk, |
| 94320 | regIdx, pIdx->nKeyCol); |
| 94321 | |
| 94322 | /* Generate code to handle collisions */ |
| 94323 | regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField); |
| 94324 | if( HasRowid(pTab) ){ |
| 94325 | sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR); |
| 94326 | /* Conflict only if the rowid of the existing index entry |
| 94327 | ** is different from old-rowid */ |
| 94328 | if( isUpdate ){ |
| 94329 | sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData); |
| 94330 | } |
| 94331 | }else{ |
| 94332 | int x; |
| 94333 | /* Extract the PRIMARY KEY from the end of the index entry and |
| 94334 | ** store it in registers regR..regR+nPk-1 */ |
| 94335 | if( (isUpdate || onError==OE_Replace) && pIdx!=pPk ){ |
| 94336 | for(i=0; i<pPk->nKeyCol; i++){ |
| 94337 | x = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[i]); |
| 94338 | sqlite3VdbeAddOp3(v, OP_Column, iThisCur, x, regR+i); |
| 94339 | VdbeComment((v, "%s.%s", pTab->zName, |
| 94340 | pTab->aCol[pPk->aiColumn[i]].zName)); |
| 94341 | } |
| 94342 | } |
| 94343 | if( isUpdate ){ |
| 94344 | /* If currently processing the PRIMARY KEY of a WITHOUT ROWID |
| 94345 | ** table, only conflict if the new PRIMARY KEY values are actually |
| 94346 | ** different from the old. |
| 94347 | ** |
| 94348 | ** For a UNIQUE index, only conflict if the PRIMARY KEY values |
| 94349 | ** of the matched index row are different from the original PRIMARY |
| 94350 | ** KEY values of this row before the update. */ |
| 94351 | int addrJump = sqlite3VdbeCurrentAddr(v)+pPk->nKeyCol; |
| 94352 | int op = OP_Ne; |
| 94353 | int regCmp = (pIdx->autoIndex==2 ? regIdx : regR); |
| 94354 | |
| 94355 | for(i=0; i<pPk->nKeyCol; i++){ |
| 94356 | char *p4 = (char*)sqlite3LocateCollSeq(pParse, pPk->azColl[i]); |
| 94357 | x = pPk->aiColumn[i]; |
| 94358 | if( i==(pPk->nKeyCol-1) ){ |
| 94359 | addrJump = addrUniqueOk; |
| 94360 | op = OP_Eq; |
| 94361 | } |
| 94362 | sqlite3VdbeAddOp4(v, op, |
| 94363 | regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ |
| 94364 | ); |
| 94365 | } |
| 94366 | } |
| 94367 | } |
| 94368 | |
| 94369 | /* Generate code that executes if the new index entry is not unique */ |
| @@ -98841,15 +99106,11 @@ | |
| 99106 | |
| 99107 | /* |
| 99108 | ** Free all memory allocations in the pParse object |
| 99109 | */ |
| 99110 | SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){ |
| 99111 | if( pParse ) sqlite3ExprListDelete(pParse->db, pParse->pConstExpr); |
| 99112 | } |
| 99113 | |
| 99114 | /* |
| 99115 | ** Compile the UTF-8 encoded SQL statement zSql into a statement handle. |
| 99116 | */ |
| @@ -99798,10 +100059,11 @@ | |
| 100059 | } |
| 100060 | }else if( eDest!=SRT_Exists ){ |
| 100061 | /* If the destination is an EXISTS(...) expression, the actual |
| 100062 | ** values returned by the SELECT are not required. |
| 100063 | */ |
| 100064 | sqlite3ExprCacheClear(pParse); |
| 100065 | sqlite3ExprCodeExprList(pParse, pEList, regResult, |
| 100066 | (eDest==SRT_Output)?SQLITE_ECEL_DUP:0); |
| 100067 | } |
| 100068 | nColumn = nResultCol; |
| 100069 | |
| @@ -100764,11 +101026,11 @@ | |
| 101026 | ** If an error occurs, return NULL and leave a message in pParse. |
| 101027 | */ |
| 101028 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){ |
| 101029 | Vdbe *v = pParse->pVdbe; |
| 101030 | if( v==0 ){ |
| 101031 | v = pParse->pVdbe = sqlite3VdbeCreate(pParse->db); |
| 101032 | #ifndef SQLITE_OMIT_TRACE |
| 101033 | if( v ){ |
| 101034 | sqlite3VdbeAddOp0(v, OP_Trace); |
| 101035 | } |
| 101036 | #endif |
| @@ -103022,27 +103284,18 @@ | |
| 103284 | */ |
| 103285 | static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){ |
| 103286 | Vdbe *v = pParse->pVdbe; |
| 103287 | int i; |
| 103288 | struct AggInfo_func *pFunc; |
| 103289 | if( pAggInfo->nFunc+pAggInfo->nColumn==0 ){ |
| 103290 | return; |
| 103291 | } |
| 103292 | for(i=0; i<pAggInfo->nColumn; i++){ |
| 103293 | sqlite3VdbeAddOp2(v, OP_Null, 0, pAggInfo->aCol[i].iMem); |
| 103294 | } |
| 103295 | for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){ |
| 103296 | sqlite3VdbeAddOp2(v, OP_Null, 0, pFunc->iMem); |
| 103297 | if( pFunc->iDistinct>=0 ){ |
| 103298 | Expr *pE = pFunc->pExpr; |
| 103299 | assert( !ExprHasProperty(pE, EP_xIsSelect) ); |
| 103300 | if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){ |
| 103301 | sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one " |
| @@ -103084,10 +103337,11 @@ | |
| 103337 | int addrHitTest = 0; |
| 103338 | struct AggInfo_func *pF; |
| 103339 | struct AggInfo_col *pC; |
| 103340 | |
| 103341 | pAggInfo->directMode = 1; |
| 103342 | sqlite3ExprCacheClear(pParse); |
| 103343 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 103344 | int nArg; |
| 103345 | int addrNext = 0; |
| 103346 | int regAgg; |
| 103347 | ExprList *pList = pF->pExpr->x.pList; |
| @@ -103616,11 +103870,10 @@ | |
| 103870 | */ |
| 103871 | memset(&sNC, 0, sizeof(sNC)); |
| 103872 | sNC.pParse = pParse; |
| 103873 | sNC.pSrcList = pTabList; |
| 103874 | sNC.pAggInfo = &sAggInfo; |
| 103875 | sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr+1 : 0; |
| 103876 | sAggInfo.pGroupBy = pGroupBy; |
| 103877 | sqlite3ExprAnalyzeAggList(&sNC, pEList); |
| 103878 | sqlite3ExprAnalyzeAggList(&sNC, pOrderBy); |
| 103879 | if( pHaving ){ |
| @@ -103631,11 +103884,10 @@ | |
| 103884 | assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) ); |
| 103885 | sNC.ncFlags |= NC_InAggFunc; |
| 103886 | sqlite3ExprAnalyzeAggList(&sNC, sAggInfo.aFunc[i].pExpr->x.pList); |
| 103887 | sNC.ncFlags &= ~NC_InAggFunc; |
| 103888 | } |
| 103889 | if( db->mallocFailed ) goto select_end; |
| 103890 | |
| 103891 | /* Processing for aggregates with GROUP BY is very different and |
| 103892 | ** much more complex than aggregates without a GROUP BY. |
| 103893 | */ |
| @@ -105536,11 +105788,11 @@ | |
| 105788 | pCol->affinity, &pValue); |
| 105789 | if( pValue ){ |
| 105790 | sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM); |
| 105791 | } |
| 105792 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 105793 | if( iReg>=0 && pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 105794 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 105795 | } |
| 105796 | #endif |
| 105797 | } |
| 105798 | } |
| @@ -105960,14 +106212,14 @@ | |
| 106212 | ** be used eliminates some redundant opcodes. |
| 106213 | */ |
| 106214 | newmask = sqlite3TriggerColmask( |
| 106215 | pParse, pTrigger, pChanges, 1, TRIGGER_BEFORE, pTab, onError |
| 106216 | ); |
| 106217 | sqlite3VdbeAddOp3(v, OP_Null, 0, regNew, regNew+pTab->nCol-1); |
| 106218 | for(i=0; i<pTab->nCol; i++){ |
| 106219 | if( i==pTab->iPKey ){ |
| 106220 | /*sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);*/ |
| 106221 | }else{ |
| 106222 | j = aXRef[i]; |
| 106223 | if( j>=0 ){ |
| 106224 | sqlite3ExprCode(pParse, pChanges->a[j].pExpr, regNew+i); |
| 106225 | }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask&(1<<i)) ){ |
| @@ -105977,12 +106229,10 @@ | |
| 106229 | ** a new.* reference in a trigger program. |
| 106230 | */ |
| 106231 | testcase( i==31 ); |
| 106232 | testcase( i==32 ); |
| 106233 | sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, i, regNew+i); |
| 106234 | } |
| 106235 | } |
| 106236 | } |
| 106237 | |
| 106238 | /* Fire any BEFORE UPDATE triggers. This happens before constraints are |
| @@ -110731,11 +110981,11 @@ | |
| 110981 | int iTerm, /* Index of this term. First is zero */ |
| 110982 | const char *zColumn, /* Name of the column */ |
| 110983 | const char *zOp /* Name of the operator */ |
| 110984 | ){ |
| 110985 | if( iTerm ) sqlite3StrAccumAppend(pStr, " AND ", 5); |
| 110986 | sqlite3StrAccumAppend(pStr, zColumn, -1); |
| 110987 | sqlite3StrAccumAppend(pStr, zOp, 1); |
| 110988 | sqlite3StrAccumAppend(pStr, "?", 1); |
| 110989 | } |
| 110990 | |
| 110991 | /* |
| @@ -110777,11 +111027,11 @@ | |
| 111027 | if( i>=nSkip ){ |
| 111028 | explainAppendTerm(&txt, i, z, "="); |
| 111029 | }else{ |
| 111030 | if( i ) sqlite3StrAccumAppend(&txt, " AND ", 5); |
| 111031 | sqlite3StrAccumAppend(&txt, "ANY(", 4); |
| 111032 | sqlite3StrAccumAppend(&txt, z, -1); |
| 111033 | sqlite3StrAccumAppend(&txt, ")", 1); |
| 111034 | } |
| 111035 | } |
| 111036 | |
| 111037 | j = i; |
| @@ -113593,16 +113843,13 @@ | |
| 113843 | sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */ |
| 113844 | |
| 113845 | /* Special case: a WHERE clause that is constant. Evaluate the |
| 113846 | ** expression and either jump over all of the code or fall thru. |
| 113847 | */ |
| 113848 | if( pWhere && (nTabList==0 || sqlite3ExprIsConstantNotJoin(pWhere)) ){ |
| 113849 | sqlite3ExprIfFalse(pParse, pWhere, pWInfo->iBreak, SQLITE_JUMPIFNULL); |
| 113850 | pWhere = 0; |
| 113851 | } |
| 113852 | |
| 113853 | /* Special case: No FROM clause |
| 113854 | */ |
| 113855 | if( nTabList==0 ){ |
| @@ -119339,12 +119586,11 @@ | |
| 119586 | } |
| 119587 | db->lookaside.pEnd = p; |
| 119588 | db->lookaside.bEnabled = 1; |
| 119589 | db->lookaside.bMalloced = pBuf==0 ?1:0; |
| 119590 | }else{ |
| 119591 | db->lookaside.pEnd = 0; |
| 119592 | db->lookaside.bEnabled = 0; |
| 119593 | db->lookaside.bMalloced = 0; |
| 119594 | } |
| 119595 | return SQLITE_OK; |
| 119596 | } |
| @@ -119738,11 +119984,13 @@ | |
| 119984 | } |
| 119985 | sqlite3HashClear(&db->aModule); |
| 119986 | #endif |
| 119987 | |
| 119988 | sqlite3Error(db, SQLITE_OK, 0); /* Deallocates any cached error strings. */ |
| 119989 | if( db->pErr ){ |
| 119990 | sqlite3ValueFree(db->pErr); |
| 119991 | } |
| 119992 | sqlite3CloseExtensions(db); |
| 119993 | |
| 119994 | db->magic = SQLITE_MAGIC_ERROR; |
| 119995 | |
| 119996 | /* The temp-database schema is allocated differently from the other schema |
| @@ -119813,11 +120061,12 @@ | |
| 120061 | |
| 120062 | /* |
| 120063 | ** Return a static string containing the name corresponding to the error code |
| 120064 | ** specified in the argument. |
| 120065 | */ |
| 120066 | #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST) || \ |
| 120067 | defined(SQLITE_DEBUG_OS_TRACE) |
| 120068 | SQLITE_PRIVATE const char *sqlite3ErrName(int rc){ |
| 120069 | const char *zName = 0; |
| 120070 | int i, origRc = rc; |
| 120071 | for(i=0; i<2 && zName==0; i++, rc &= 0xff){ |
| 120072 | switch( rc ){ |
| @@ -119835,11 +120084,10 @@ | |
| 120084 | case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; |
| 120085 | case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; |
| 120086 | case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break; |
| 120087 | case SQLITE_READONLY_CANTLOCK: zName = "SQLITE_READONLY_CANTLOCK"; break; |
| 120088 | case SQLITE_READONLY_ROLLBACK: zName = "SQLITE_READONLY_ROLLBACK"; break; |
| 120089 | case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break; |
| 120090 | case SQLITE_IOERR: zName = "SQLITE_IOERR"; break; |
| 120091 | case SQLITE_IOERR_READ: zName = "SQLITE_IOERR_READ"; break; |
| 120092 | case SQLITE_IOERR_SHORT_READ: zName = "SQLITE_IOERR_SHORT_READ"; break; |
| 120093 | case SQLITE_IOERR_WRITE: zName = "SQLITE_IOERR_WRITE"; break; |
| @@ -120120,11 +120368,10 @@ | |
| 120368 | void (*xFinal)(sqlite3_context*), |
| 120369 | FuncDestructor *pDestructor |
| 120370 | ){ |
| 120371 | FuncDef *p; |
| 120372 | int nName; |
| 120373 | |
| 120374 | assert( sqlite3_mutex_held(db->mutex) ); |
| 120375 | if( zFunctionName==0 || |
| 120376 | (xFunc && (xFinal || xStep)) || |
| 120377 | (!xFunc && (xFinal && !xStep)) || |
| @@ -120131,14 +120378,10 @@ | |
| 120378 | (!xFunc && (!xFinal && xStep)) || |
| 120379 | (nArg<-1 || nArg>SQLITE_MAX_FUNCTION_ARG) || |
| 120380 | (255<(nName = sqlite3Strlen30( zFunctionName))) ){ |
| 120381 | return SQLITE_MISUSE_BKPT; |
| 120382 | } |
| 120383 | |
| 120384 | #ifndef SQLITE_OMIT_UTF16 |
| 120385 | /* If SQLITE_UTF16 is specified as the encoding type, transform this |
| 120386 | ** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the |
| 120387 | ** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally. |
| @@ -120148,14 +120391,14 @@ | |
| 120391 | */ |
| 120392 | if( enc==SQLITE_UTF16 ){ |
| 120393 | enc = SQLITE_UTF16NATIVE; |
| 120394 | }else if( enc==SQLITE_ANY ){ |
| 120395 | int rc; |
| 120396 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8, |
| 120397 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 120398 | if( rc==SQLITE_OK ){ |
| 120399 | rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE, |
| 120400 | pUserData, xFunc, xStep, xFinal, pDestructor); |
| 120401 | } |
| 120402 | if( rc!=SQLITE_OK ){ |
| 120403 | return rc; |
| 120404 | } |
| @@ -120194,12 +120437,11 @@ | |
| 120437 | |
| 120438 | if( pDestructor ){ |
| 120439 | pDestructor->nRef++; |
| 120440 | } |
| 120441 | p->pDestructor = pDestructor; |
| 120442 | p->funcFlags &= SQLITE_FUNC_ENCMASK; |
| 120443 | p->xFunc = xFunc; |
| 120444 | p->xStep = xStep; |
| 120445 | p->xFinalize = xFinal; |
| 120446 | p->pUserData = pUserData; |
| 120447 | p->nArg = (u16)nArg; |
| @@ -120625,11 +120867,10 @@ | |
| 120867 | } |
| 120868 | sqlite3_mutex_enter(db->mutex); |
| 120869 | if( db->mallocFailed ){ |
| 120870 | z = sqlite3ErrStr(SQLITE_NOMEM); |
| 120871 | }else{ |
| 120872 | z = (char*)sqlite3_value_text(db->pErr); |
| 120873 | assert( !db->mallocFailed ); |
| 120874 | if( z==0 ){ |
| 120875 | z = sqlite3ErrStr(db->errCode); |
| 120876 | } |
| @@ -120667,11 +120908,12 @@ | |
| 120908 | if( db->mallocFailed ){ |
| 120909 | z = (void *)outOfMem; |
| 120910 | }else{ |
| 120911 | z = sqlite3_value_text16(db->pErr); |
| 120912 | if( z==0 ){ |
| 120913 | sqlite3ValueSetStr(db->pErr, -1, sqlite3ErrStr(db->errCode), |
| 120914 | SQLITE_UTF8, SQLITE_STATIC); |
| 120915 | z = sqlite3_value_text16(db->pErr); |
| 120916 | } |
| 120917 | /* A malloc() may have failed within the call to sqlite3_value_text16() |
| 120918 | ** above. If this is the case, then the db->mallocFailed flag needs to |
| 120919 | ** be cleared before returning. Do this directly, instead of via |
| @@ -121380,10 +121622,12 @@ | |
| 121622 | #ifdef SQLITE_ENABLE_RTREE |
| 121623 | if( !db->mallocFailed && rc==SQLITE_OK){ |
| 121624 | rc = sqlite3RtreeInit(db); |
| 121625 | } |
| 121626 | #endif |
| 121627 | |
| 121628 | sqlite3Error(db, rc, 0); |
| 121629 | |
| 121630 | /* -DSQLITE_DEFAULT_LOCKING_MODE=1 makes EXCLUSIVE the default locking |
| 121631 | ** mode. -DSQLITE_DEFAULT_LOCKING_MODE=0 make NORMAL the default locking |
| 121632 | ** mode. Doing nothing at all also makes NORMAL the default. |
| 121633 | */ |
| @@ -121391,12 +121635,10 @@ | |
| 121635 | db->dfltLockMode = SQLITE_DEFAULT_LOCKING_MODE; |
| 121636 | sqlite3PagerLockingMode(sqlite3BtreePager(db->aDb[0].pBt), |
| 121637 | SQLITE_DEFAULT_LOCKING_MODE); |
| 121638 | #endif |
| 121639 | |
| 121640 | /* Enable the lookaside-malloc subsystem */ |
| 121641 | setupLookaside(db, 0, sqlite3GlobalConfig.szLookaside, |
| 121642 | sqlite3GlobalConfig.nLookaside); |
| 121643 | |
| 121644 | sqlite3_wal_autocheckpoint(db, SQLITE_DEFAULT_WAL_AUTOCHECKPOINT); |
| @@ -121852,11 +122094,11 @@ | |
| 122094 | ** Reset the PRNG back to its uninitialized state. The next call |
| 122095 | ** to sqlite3_randomness() will reseed the PRNG using a single call |
| 122096 | ** to the xRandomness method of the default VFS. |
| 122097 | */ |
| 122098 | case SQLITE_TESTCTRL_PRNG_RESET: { |
| 122099 | sqlite3PrngResetState(); |
| 122100 | break; |
| 122101 | } |
| 122102 | |
| 122103 | /* |
| 122104 | ** sqlite3_test_control(BITVEC_TEST, size, program) |
| @@ -124836,23 +125078,10 @@ | |
| 125078 | char **pzErr /* OUT: sqlite3_malloc'd error message */ |
| 125079 | ){ |
| 125080 | return fts3InitVtab(1, db, pAux, argc, argv, ppVtab, pzErr); |
| 125081 | } |
| 125082 | |
| 125083 | /* |
| 125084 | ** Implementation of the xBestIndex method for FTS3 tables. There |
| 125085 | ** are three possible strategies, in order of preference: |
| 125086 | ** |
| 125087 | ** 1. Direct lookup by rowid or docid. |
| @@ -124876,24 +125105,11 @@ | |
| 125105 | pInfo->idxNum = FTS3_FULLSCAN_SEARCH; |
| 125106 | pInfo->estimatedCost = 5000000; |
| 125107 | for(i=0; i<pInfo->nConstraint; i++){ |
| 125108 | int bDocid; /* True if this constraint is on docid */ |
| 125109 | struct sqlite3_index_constraint *pCons = &pInfo->aConstraint[i]; |
| 125110 | if( pCons->usable==0 ) continue; |
| 125111 | |
| 125112 | bDocid = (pCons->iColumn<0 || pCons->iColumn==p->nColumn+1); |
| 125113 | |
| 125114 | /* A direct lookup on the rowid or docid column. Assign a cost of 1.0. */ |
| 125115 | if( iCons<0 && pCons->op==SQLITE_INDEX_CONSTRAINT_EQ && bDocid ){ |
| @@ -131750,74 +131966,61 @@ | |
| 131966 | } |
| 131967 | |
| 131968 | /* Step 2 */ |
| 131969 | switch( z[1] ){ |
| 131970 | case 'a': |
| 131971 | stem(&z, "lanoita", "ate", m_gt_0) || |
| 131972 | stem(&z, "lanoit", "tion", m_gt_0); |
| 131973 | break; |
| 131974 | case 'c': |
| 131975 | stem(&z, "icne", "ence", m_gt_0) || |
| 131976 | stem(&z, "icna", "ance", m_gt_0); |
| 131977 | break; |
| 131978 | case 'e': |
| 131979 | stem(&z, "rezi", "ize", m_gt_0); |
| 131980 | break; |
| 131981 | case 'g': |
| 131982 | stem(&z, "igol", "log", m_gt_0); |
| 131983 | break; |
| 131984 | case 'l': |
| 131985 | stem(&z, "ilb", "ble", m_gt_0) || |
| 131986 | stem(&z, "illa", "al", m_gt_0) || |
| 131987 | stem(&z, "iltne", "ent", m_gt_0) || |
| 131988 | stem(&z, "ile", "e", m_gt_0) || |
| 131989 | stem(&z, "ilsuo", "ous", m_gt_0); |
| 131990 | break; |
| 131991 | case 'o': |
| 131992 | stem(&z, "noitazi", "ize", m_gt_0) || |
| 131993 | stem(&z, "noita", "ate", m_gt_0) || |
| 131994 | stem(&z, "rota", "ate", m_gt_0); |
| 131995 | break; |
| 131996 | case 's': |
| 131997 | stem(&z, "msila", "al", m_gt_0) || |
| 131998 | stem(&z, "ssenevi", "ive", m_gt_0) || |
| 131999 | stem(&z, "ssenluf", "ful", m_gt_0) || |
| 132000 | stem(&z, "ssensuo", "ous", m_gt_0); |
| 132001 | break; |
| 132002 | case 't': |
| 132003 | stem(&z, "itila", "al", m_gt_0) || |
| 132004 | stem(&z, "itivi", "ive", m_gt_0) || |
| 132005 | stem(&z, "itilib", "ble", m_gt_0); |
| 132006 | break; |
| 132007 | } |
| 132008 | |
| 132009 | /* Step 3 */ |
| 132010 | switch( z[0] ){ |
| 132011 | case 'e': |
| 132012 | stem(&z, "etaci", "ic", m_gt_0) || |
| 132013 | stem(&z, "evita", "", m_gt_0) || |
| 132014 | stem(&z, "ezila", "al", m_gt_0); |
| 132015 | break; |
| 132016 | case 'i': |
| 132017 | stem(&z, "itici", "ic", m_gt_0); |
| 132018 | break; |
| 132019 | case 'l': |
| 132020 | stem(&z, "laci", "ic", m_gt_0) || |
| 132021 | stem(&z, "luf", "", m_gt_0); |
| 132022 | break; |
| 132023 | case 's': |
| 132024 | stem(&z, "ssen", "", m_gt_0); |
| 132025 | break; |
| 132026 | } |
| @@ -131854,15 +132057,13 @@ | |
| 132057 | if( z[2]=='a' ){ |
| 132058 | if( m_gt_1(z+3) ){ |
| 132059 | z += 3; |
| 132060 | } |
| 132061 | }else if( z[2]=='e' ){ |
| 132062 | stem(&z, "tneme", "", m_gt_1) || |
| 132063 | stem(&z, "tnem", "", m_gt_1) || |
| 132064 | stem(&z, "tne", "", m_gt_1); |
| 132065 | } |
| 132066 | } |
| 132067 | break; |
| 132068 | case 'o': |
| 132069 | if( z[0]=='u' ){ |
| @@ -131877,13 +132078,12 @@ | |
| 132078 | if( z[0]=='m' && z[2]=='i' && m_gt_1(z+3) ){ |
| 132079 | z += 3; |
| 132080 | } |
| 132081 | break; |
| 132082 | case 't': |
| 132083 | stem(&z, "eta", "", m_gt_1) || |
| 132084 | stem(&z, "iti", "", m_gt_1); |
| 132085 | break; |
| 132086 | case 'u': |
| 132087 | if( z[0]=='s' && z[2]=='o' && m_gt_1(z+3) ){ |
| 132088 | z += 3; |
| 132089 | } |
| 132090 |
+25
-71
| --- src/sqlite3.h | ||
| +++ src/sqlite3.h | ||
| @@ -105,13 +105,13 @@ | ||
| 105 | 105 | ** |
| 106 | 106 | ** See also: [sqlite3_libversion()], |
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | -#define SQLITE_VERSION "3.8.3" | |
| 111 | -#define SQLITE_VERSION_NUMBER 3008003 | |
| 112 | -#define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6" | |
| 110 | +#define SQLITE_VERSION "3.8.2" | |
| 111 | +#define SQLITE_VERSION_NUMBER 3008002 | |
| 112 | +#define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| @@ -489,11 +489,10 @@ | ||
| 489 | 489 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 490 | 490 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 491 | 491 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 492 | 492 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 493 | 493 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 494 | -#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) | |
| 495 | 494 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 496 | 495 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 497 | 496 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 498 | 497 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 499 | 498 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -557,12 +556,11 @@ | ||
| 557 | 556 | ** information is written to disk in the same order as calls |
| 558 | 557 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 559 | 558 | ** after reboot following a crash or power loss, the only bytes in a |
| 560 | 559 | ** file that were written at the application level might have changed |
| 561 | 560 | ** and that adjacent bytes, even bytes within the same sector are |
| 562 | -** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN | |
| 563 | -** flag indicate that a file cannot be deleted when open. | |
| 561 | +** guaranteed to be unchanged. | |
| 564 | 562 | */ |
| 565 | 563 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 566 | 564 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 567 | 565 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 568 | 566 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| @@ -789,33 +787,19 @@ | ||
| 789 | 787 | ** to the [sqlite3_file] object associated with a particular database |
| 790 | 788 | ** connection. See the [sqlite3_file_control()] documentation for |
| 791 | 789 | ** additional information. |
| 792 | 790 | ** |
| 793 | 791 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 794 | -** No longer in use. | |
| 795 | -** | |
| 796 | -** <li>[[SQLITE_FCNTL_SYNC]] | |
| 797 | -** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and | |
| 798 | -** sent to the VFS immediately before the xSync method is invoked on a | |
| 799 | -** database file descriptor. Or, if the xSync method is not invoked | |
| 800 | -** because the user has configured SQLite with | |
| 801 | -** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place | |
| 802 | -** of the xSync method. In most cases, the pointer argument passed with | |
| 803 | -** this file-control is NULL. However, if the database file is being synced | |
| 804 | -** as part of a multi-database commit, the argument points to a nul-terminated | |
| 805 | -** string containing the transactions master-journal file name. VFSes that | |
| 806 | -** do not need this signal should silently ignore this opcode. Applications | |
| 807 | -** should not call [sqlite3_file_control()] with this opcode as doing so may | |
| 808 | -** disrupt the operation of the specialized VFSes that do require it. | |
| 809 | -** | |
| 810 | -** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] | |
| 811 | -** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite | |
| 812 | -** and sent to the VFS after a transaction has been committed immediately | |
| 813 | -** but before the database is unlocked. VFSes that do not need this signal | |
| 814 | -** should silently ignore this opcode. Applications should not call | |
| 815 | -** [sqlite3_file_control()] with this opcode as doing so may disrupt the | |
| 816 | -** operation of the specialized VFSes that do require it. | |
| 792 | +** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by | |
| 793 | +** SQLite and sent to all VFSes in place of a call to the xSync method | |
| 794 | +** when the database connection has [PRAGMA synchronous] set to OFF.)^ | |
| 795 | +** Some specialized VFSes need this signal in order to operate correctly | |
| 796 | +** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most | |
| 797 | +** VFSes do not need this signal and should silently ignore this opcode. | |
| 798 | +** Applications should not call [sqlite3_file_control()] with this | |
| 799 | +** opcode as doing so may disrupt the operation of the specialized VFSes | |
| 800 | +** that do require it. | |
| 817 | 801 | ** |
| 818 | 802 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 819 | 803 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 820 | 804 | ** retry counts and intervals for certain disk I/O operations for the |
| 821 | 805 | ** windows [VFS] in order to provide robustness in the presence of |
| @@ -935,16 +919,10 @@ | ||
| 935 | 919 | ** This file control is used by some VFS activity tracing [shims]. |
| 936 | 920 | ** The argument is a zero-terminated string. Higher layers in the |
| 937 | 921 | ** SQLite stack may generate instances of this file control if |
| 938 | 922 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
| 939 | 923 | ** |
| 940 | -** <li>[[SQLITE_FCNTL_HAS_MOVED]] | |
| 941 | -** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a | |
| 942 | -** pointer to an integer and it writes a boolean into that integer depending | |
| 943 | -** on whether or not the file has been renamed, moved, or deleted since it | |
| 944 | -** was first opened. | |
| 945 | -** | |
| 946 | 924 | ** </ul> |
| 947 | 925 | */ |
| 948 | 926 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 949 | 927 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 950 | 928 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| @@ -961,13 +939,10 @@ | ||
| 961 | 939 | #define SQLITE_FCNTL_PRAGMA 14 |
| 962 | 940 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 963 | 941 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 964 | 942 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 965 | 943 | #define SQLITE_FCNTL_TRACE 19 |
| 966 | -#define SQLITE_FCNTL_HAS_MOVED 20 | |
| 967 | -#define SQLITE_FCNTL_SYNC 21 | |
| 968 | -#define SQLITE_FCNTL_COMMIT_PHASETWO 22 | |
| 969 | 944 | |
| 970 | 945 | /* |
| 971 | 946 | ** CAPI3REF: Mutex Handle |
| 972 | 947 | ** |
| 973 | 948 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2398,17 +2373,15 @@ | ||
| 2398 | 2373 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2399 | 2374 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2400 | 2375 | ** applications to access the same PRNG for other purposes. |
| 2401 | 2376 | ** |
| 2402 | 2377 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2403 | -** ^If N is less than one, then P can be a NULL pointer. | |
| 2404 | 2378 | ** |
| 2405 | -** ^If this routine has not been previously called or if the previous | |
| 2406 | -** call had N less than one, then the PRNG is seeded using randomness | |
| 2407 | -** obtained from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2408 | -** ^If the previous call to this routine had an N of 1 or more then | |
| 2409 | -** the pseudo-randomness is generated | |
| 2379 | +** ^The first time this routine is invoked (either internally or by | |
| 2380 | +** the application) the PRNG is seeded using randomness obtained | |
| 2381 | +** from the xRandomness method of the default [sqlite3_vfs] object. | |
| 2382 | +** ^On all subsequent invocations, the pseudo-randomness is generated | |
| 2410 | 2383 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2411 | 2384 | ** method. |
| 2412 | 2385 | */ |
| 2413 | 2386 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2414 | 2387 | |
| @@ -3982,28 +3955,19 @@ | ||
| 3982 | 3955 | ** parameter is less than -1 or greater than 127 then the behavior is |
| 3983 | 3956 | ** undefined. |
| 3984 | 3957 | ** |
| 3985 | 3958 | ** ^The fourth parameter, eTextRep, specifies what |
| 3986 | 3959 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
| 3987 | -** its parameters. The application should set this parameter to | |
| 3988 | -** [SQLITE_UTF16LE] if the function implementation invokes | |
| 3989 | -** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the | |
| 3990 | -** implementation invokes [sqlite3_value_text16be()] on an input, or | |
| 3991 | -** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] | |
| 3992 | -** otherwise. ^The same SQL function may be registered multiple times using | |
| 3993 | -** different preferred text encodings, with different implementations for | |
| 3994 | -** each encoding. | |
| 3960 | +** its parameters. Every SQL function implementation must be able to work | |
| 3961 | +** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be | |
| 3962 | +** more efficient with one encoding than another. ^An application may | |
| 3963 | +** invoke sqlite3_create_function() or sqlite3_create_function16() multiple | |
| 3964 | +** times with the same function but with different values of eTextRep. | |
| 3995 | 3965 | ** ^When multiple implementations of the same function are available, SQLite |
| 3996 | 3966 | ** will pick the one that involves the least amount of data conversion. |
| 3997 | -** | |
| 3998 | -** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] | |
| 3999 | -** to signal that the function will always return the same result given | |
| 4000 | -** the same inputs within a single SQL statement. Most SQL functions are | |
| 4001 | -** deterministic. The built-in [random()] SQL function is an example of a | |
| 4002 | -** function that is not deterministic. The SQLite query planner is able to | |
| 4003 | -** perform additional optimizations on deterministic functions, so use | |
| 4004 | -** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. | |
| 3967 | +** If there is only a single implementation which does not care what text | |
| 3968 | +** encoding is used, then the fourth argument should be [SQLITE_ANY]. | |
| 4005 | 3969 | ** |
| 4006 | 3970 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 4007 | 3971 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 4008 | 3972 | ** |
| 4009 | 3973 | ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are |
| @@ -4085,23 +4049,13 @@ | ||
| 4085 | 4049 | */ |
| 4086 | 4050 | #define SQLITE_UTF8 1 |
| 4087 | 4051 | #define SQLITE_UTF16LE 2 |
| 4088 | 4052 | #define SQLITE_UTF16BE 3 |
| 4089 | 4053 | #define SQLITE_UTF16 4 /* Use native byte order */ |
| 4090 | -#define SQLITE_ANY 5 /* Deprecated */ | |
| 4054 | +#define SQLITE_ANY 5 /* sqlite3_create_function only */ | |
| 4091 | 4055 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
| 4092 | 4056 | |
| 4093 | -/* | |
| 4094 | -** CAPI3REF: Function Flags | |
| 4095 | -** | |
| 4096 | -** These constants may be ORed together with the | |
| 4097 | -** [SQLITE_UTF8 | preferred text encoding] as the fourth argument | |
| 4098 | -** to [sqlite3_create_function()], [sqlite3_create_function16()], or | |
| 4099 | -** [sqlite3_create_function_v2()]. | |
| 4100 | -*/ | |
| 4101 | -#define SQLITE_DETERMINISTIC 0x800 | |
| 4102 | - | |
| 4103 | 4057 | /* |
| 4104 | 4058 | ** CAPI3REF: Deprecated Functions |
| 4105 | 4059 | ** DEPRECATED |
| 4106 | 4060 | ** |
| 4107 | 4061 | ** These functions are [deprecated]. In order to maintain |
| 4108 | 4062 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -105,13 +105,13 @@ | |
| 105 | ** |
| 106 | ** See also: [sqlite3_libversion()], |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.3" |
| 111 | #define SQLITE_VERSION_NUMBER 3008003 |
| 112 | #define SQLITE_SOURCE_ID "2014-01-04 15:17:04 4e725f53131d3584319c710c8710a068989543c6" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -489,11 +489,10 @@ | |
| 489 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 490 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 491 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 492 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 493 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 494 | #define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8)) |
| 495 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 496 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 497 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 498 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 499 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -557,12 +556,11 @@ | |
| 557 | ** information is written to disk in the same order as calls |
| 558 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 559 | ** after reboot following a crash or power loss, the only bytes in a |
| 560 | ** file that were written at the application level might have changed |
| 561 | ** and that adjacent bytes, even bytes within the same sector are |
| 562 | ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
| 563 | ** flag indicate that a file cannot be deleted when open. |
| 564 | */ |
| 565 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 566 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 567 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 568 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| @@ -789,33 +787,19 @@ | |
| 789 | ** to the [sqlite3_file] object associated with a particular database |
| 790 | ** connection. See the [sqlite3_file_control()] documentation for |
| 791 | ** additional information. |
| 792 | ** |
| 793 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 794 | ** No longer in use. |
| 795 | ** |
| 796 | ** <li>[[SQLITE_FCNTL_SYNC]] |
| 797 | ** The [SQLITE_FCNTL_SYNC] opcode is generated internally by SQLite and |
| 798 | ** sent to the VFS immediately before the xSync method is invoked on a |
| 799 | ** database file descriptor. Or, if the xSync method is not invoked |
| 800 | ** because the user has configured SQLite with |
| 801 | ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place |
| 802 | ** of the xSync method. In most cases, the pointer argument passed with |
| 803 | ** this file-control is NULL. However, if the database file is being synced |
| 804 | ** as part of a multi-database commit, the argument points to a nul-terminated |
| 805 | ** string containing the transactions master-journal file name. VFSes that |
| 806 | ** do not need this signal should silently ignore this opcode. Applications |
| 807 | ** should not call [sqlite3_file_control()] with this opcode as doing so may |
| 808 | ** disrupt the operation of the specialized VFSes that do require it. |
| 809 | ** |
| 810 | ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]] |
| 811 | ** The [SQLITE_FCNTL_COMMIT_PHASETWO] opcode is generated internally by SQLite |
| 812 | ** and sent to the VFS after a transaction has been committed immediately |
| 813 | ** but before the database is unlocked. VFSes that do not need this signal |
| 814 | ** should silently ignore this opcode. Applications should not call |
| 815 | ** [sqlite3_file_control()] with this opcode as doing so may disrupt the |
| 816 | ** operation of the specialized VFSes that do require it. |
| 817 | ** |
| 818 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 819 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 820 | ** retry counts and intervals for certain disk I/O operations for the |
| 821 | ** windows [VFS] in order to provide robustness in the presence of |
| @@ -935,16 +919,10 @@ | |
| 935 | ** This file control is used by some VFS activity tracing [shims]. |
| 936 | ** The argument is a zero-terminated string. Higher layers in the |
| 937 | ** SQLite stack may generate instances of this file control if |
| 938 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
| 939 | ** |
| 940 | ** <li>[[SQLITE_FCNTL_HAS_MOVED]] |
| 941 | ** The [SQLITE_FCNTL_HAS_MOVED] file control interprets its argument as a |
| 942 | ** pointer to an integer and it writes a boolean into that integer depending |
| 943 | ** on whether or not the file has been renamed, moved, or deleted since it |
| 944 | ** was first opened. |
| 945 | ** |
| 946 | ** </ul> |
| 947 | */ |
| 948 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 949 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 950 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| @@ -961,13 +939,10 @@ | |
| 961 | #define SQLITE_FCNTL_PRAGMA 14 |
| 962 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 963 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 964 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 965 | #define SQLITE_FCNTL_TRACE 19 |
| 966 | #define SQLITE_FCNTL_HAS_MOVED 20 |
| 967 | #define SQLITE_FCNTL_SYNC 21 |
| 968 | #define SQLITE_FCNTL_COMMIT_PHASETWO 22 |
| 969 | |
| 970 | /* |
| 971 | ** CAPI3REF: Mutex Handle |
| 972 | ** |
| 973 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2398,17 +2373,15 @@ | |
| 2398 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2399 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2400 | ** applications to access the same PRNG for other purposes. |
| 2401 | ** |
| 2402 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2403 | ** ^If N is less than one, then P can be a NULL pointer. |
| 2404 | ** |
| 2405 | ** ^If this routine has not been previously called or if the previous |
| 2406 | ** call had N less than one, then the PRNG is seeded using randomness |
| 2407 | ** obtained from the xRandomness method of the default [sqlite3_vfs] object. |
| 2408 | ** ^If the previous call to this routine had an N of 1 or more then |
| 2409 | ** the pseudo-randomness is generated |
| 2410 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2411 | ** method. |
| 2412 | */ |
| 2413 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2414 | |
| @@ -3982,28 +3955,19 @@ | |
| 3982 | ** parameter is less than -1 or greater than 127 then the behavior is |
| 3983 | ** undefined. |
| 3984 | ** |
| 3985 | ** ^The fourth parameter, eTextRep, specifies what |
| 3986 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
| 3987 | ** its parameters. The application should set this parameter to |
| 3988 | ** [SQLITE_UTF16LE] if the function implementation invokes |
| 3989 | ** [sqlite3_value_text16le()] on an input, or [SQLITE_UTF16BE] if the |
| 3990 | ** implementation invokes [sqlite3_value_text16be()] on an input, or |
| 3991 | ** [SQLITE_UTF16] if [sqlite3_value_text16()] is used, or [SQLITE_UTF8] |
| 3992 | ** otherwise. ^The same SQL function may be registered multiple times using |
| 3993 | ** different preferred text encodings, with different implementations for |
| 3994 | ** each encoding. |
| 3995 | ** ^When multiple implementations of the same function are available, SQLite |
| 3996 | ** will pick the one that involves the least amount of data conversion. |
| 3997 | ** |
| 3998 | ** ^The fourth parameter may optionally be ORed with [SQLITE_DETERMINISTIC] |
| 3999 | ** to signal that the function will always return the same result given |
| 4000 | ** the same inputs within a single SQL statement. Most SQL functions are |
| 4001 | ** deterministic. The built-in [random()] SQL function is an example of a |
| 4002 | ** function that is not deterministic. The SQLite query planner is able to |
| 4003 | ** perform additional optimizations on deterministic functions, so use |
| 4004 | ** of the [SQLITE_DETERMINISTIC] flag is recommended where possible. |
| 4005 | ** |
| 4006 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 4007 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 4008 | ** |
| 4009 | ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are |
| @@ -4085,23 +4049,13 @@ | |
| 4085 | */ |
| 4086 | #define SQLITE_UTF8 1 |
| 4087 | #define SQLITE_UTF16LE 2 |
| 4088 | #define SQLITE_UTF16BE 3 |
| 4089 | #define SQLITE_UTF16 4 /* Use native byte order */ |
| 4090 | #define SQLITE_ANY 5 /* Deprecated */ |
| 4091 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
| 4092 | |
| 4093 | /* |
| 4094 | ** CAPI3REF: Function Flags |
| 4095 | ** |
| 4096 | ** These constants may be ORed together with the |
| 4097 | ** [SQLITE_UTF8 | preferred text encoding] as the fourth argument |
| 4098 | ** to [sqlite3_create_function()], [sqlite3_create_function16()], or |
| 4099 | ** [sqlite3_create_function_v2()]. |
| 4100 | */ |
| 4101 | #define SQLITE_DETERMINISTIC 0x800 |
| 4102 | |
| 4103 | /* |
| 4104 | ** CAPI3REF: Deprecated Functions |
| 4105 | ** DEPRECATED |
| 4106 | ** |
| 4107 | ** These functions are [deprecated]. In order to maintain |
| 4108 |
| --- src/sqlite3.h | |
| +++ src/sqlite3.h | |
| @@ -105,13 +105,13 @@ | |
| 105 | ** |
| 106 | ** See also: [sqlite3_libversion()], |
| 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | */ |
| 110 | #define SQLITE_VERSION "3.8.2" |
| 111 | #define SQLITE_VERSION_NUMBER 3008002 |
| 112 | #define SQLITE_SOURCE_ID "2013-12-06 14:53:30 27392118af4c38c5203a04b8013e1afdb1cebd0d" |
| 113 | |
| 114 | /* |
| 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | ** |
| @@ -489,11 +489,10 @@ | |
| 489 | #define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8)) |
| 490 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 491 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| 492 | #define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8)) |
| 493 | #define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8)) |
| 494 | #define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8)) |
| 495 | #define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8)) |
| 496 | #define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8)) |
| 497 | #define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8)) |
| 498 | #define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8)) |
| @@ -557,12 +556,11 @@ | |
| 556 | ** information is written to disk in the same order as calls |
| 557 | ** to xWrite(). The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that |
| 558 | ** after reboot following a crash or power loss, the only bytes in a |
| 559 | ** file that were written at the application level might have changed |
| 560 | ** and that adjacent bytes, even bytes within the same sector are |
| 561 | ** guaranteed to be unchanged. |
| 562 | */ |
| 563 | #define SQLITE_IOCAP_ATOMIC 0x00000001 |
| 564 | #define SQLITE_IOCAP_ATOMIC512 0x00000002 |
| 565 | #define SQLITE_IOCAP_ATOMIC1K 0x00000004 |
| 566 | #define SQLITE_IOCAP_ATOMIC2K 0x00000008 |
| @@ -789,33 +787,19 @@ | |
| 787 | ** to the [sqlite3_file] object associated with a particular database |
| 788 | ** connection. See the [sqlite3_file_control()] documentation for |
| 789 | ** additional information. |
| 790 | ** |
| 791 | ** <li>[[SQLITE_FCNTL_SYNC_OMITTED]] |
| 792 | ** ^(The [SQLITE_FCNTL_SYNC_OMITTED] opcode is generated internally by |
| 793 | ** SQLite and sent to all VFSes in place of a call to the xSync method |
| 794 | ** when the database connection has [PRAGMA synchronous] set to OFF.)^ |
| 795 | ** Some specialized VFSes need this signal in order to operate correctly |
| 796 | ** when [PRAGMA synchronous | PRAGMA synchronous=OFF] is set, but most |
| 797 | ** VFSes do not need this signal and should silently ignore this opcode. |
| 798 | ** Applications should not call [sqlite3_file_control()] with this |
| 799 | ** opcode as doing so may disrupt the operation of the specialized VFSes |
| 800 | ** that do require it. |
| 801 | ** |
| 802 | ** <li>[[SQLITE_FCNTL_WIN32_AV_RETRY]] |
| 803 | ** ^The [SQLITE_FCNTL_WIN32_AV_RETRY] opcode is used to configure automatic |
| 804 | ** retry counts and intervals for certain disk I/O operations for the |
| 805 | ** windows [VFS] in order to provide robustness in the presence of |
| @@ -935,16 +919,10 @@ | |
| 919 | ** This file control is used by some VFS activity tracing [shims]. |
| 920 | ** The argument is a zero-terminated string. Higher layers in the |
| 921 | ** SQLite stack may generate instances of this file control if |
| 922 | ** the [SQLITE_USE_FCNTL_TRACE] compile-time option is enabled. |
| 923 | ** |
| 924 | ** </ul> |
| 925 | */ |
| 926 | #define SQLITE_FCNTL_LOCKSTATE 1 |
| 927 | #define SQLITE_GET_LOCKPROXYFILE 2 |
| 928 | #define SQLITE_SET_LOCKPROXYFILE 3 |
| @@ -961,13 +939,10 @@ | |
| 939 | #define SQLITE_FCNTL_PRAGMA 14 |
| 940 | #define SQLITE_FCNTL_BUSYHANDLER 15 |
| 941 | #define SQLITE_FCNTL_TEMPFILENAME 16 |
| 942 | #define SQLITE_FCNTL_MMAP_SIZE 18 |
| 943 | #define SQLITE_FCNTL_TRACE 19 |
| 944 | |
| 945 | /* |
| 946 | ** CAPI3REF: Mutex Handle |
| 947 | ** |
| 948 | ** The mutex module within SQLite defines [sqlite3_mutex] to be an |
| @@ -2398,17 +2373,15 @@ | |
| 2373 | ** already uses the largest possible [ROWID]. The PRNG is also used for |
| 2374 | ** the build-in random() and randomblob() SQL functions. This interface allows |
| 2375 | ** applications to access the same PRNG for other purposes. |
| 2376 | ** |
| 2377 | ** ^A call to this routine stores N bytes of randomness into buffer P. |
| 2378 | ** |
| 2379 | ** ^The first time this routine is invoked (either internally or by |
| 2380 | ** the application) the PRNG is seeded using randomness obtained |
| 2381 | ** from the xRandomness method of the default [sqlite3_vfs] object. |
| 2382 | ** ^On all subsequent invocations, the pseudo-randomness is generated |
| 2383 | ** internally and without recourse to the [sqlite3_vfs] xRandomness |
| 2384 | ** method. |
| 2385 | */ |
| 2386 | SQLITE_API void sqlite3_randomness(int N, void *P); |
| 2387 | |
| @@ -3982,28 +3955,19 @@ | |
| 3955 | ** parameter is less than -1 or greater than 127 then the behavior is |
| 3956 | ** undefined. |
| 3957 | ** |
| 3958 | ** ^The fourth parameter, eTextRep, specifies what |
| 3959 | ** [SQLITE_UTF8 | text encoding] this SQL function prefers for |
| 3960 | ** its parameters. Every SQL function implementation must be able to work |
| 3961 | ** with UTF-8, UTF-16le, or UTF-16be. But some implementations may be |
| 3962 | ** more efficient with one encoding than another. ^An application may |
| 3963 | ** invoke sqlite3_create_function() or sqlite3_create_function16() multiple |
| 3964 | ** times with the same function but with different values of eTextRep. |
| 3965 | ** ^When multiple implementations of the same function are available, SQLite |
| 3966 | ** will pick the one that involves the least amount of data conversion. |
| 3967 | ** If there is only a single implementation which does not care what text |
| 3968 | ** encoding is used, then the fourth argument should be [SQLITE_ANY]. |
| 3969 | ** |
| 3970 | ** ^(The fifth parameter is an arbitrary pointer. The implementation of the |
| 3971 | ** function can gain access to this pointer using [sqlite3_user_data()].)^ |
| 3972 | ** |
| 3973 | ** ^The sixth, seventh and eighth parameters, xFunc, xStep and xFinal, are |
| @@ -4085,23 +4049,13 @@ | |
| 4049 | */ |
| 4050 | #define SQLITE_UTF8 1 |
| 4051 | #define SQLITE_UTF16LE 2 |
| 4052 | #define SQLITE_UTF16BE 3 |
| 4053 | #define SQLITE_UTF16 4 /* Use native byte order */ |
| 4054 | #define SQLITE_ANY 5 /* sqlite3_create_function only */ |
| 4055 | #define SQLITE_UTF16_ALIGNED 8 /* sqlite3_create_collation only */ |
| 4056 | |
| 4057 | /* |
| 4058 | ** CAPI3REF: Deprecated Functions |
| 4059 | ** DEPRECATED |
| 4060 | ** |
| 4061 | ** These functions are [deprecated]. In order to maintain |
| 4062 |