Fossil SCM
Update the built-in SQLite to the latest trunk version that includes various performance enhancements. The purpose here is to test the recent SQLite enhancements in a real-world application.
Commit
ad744440dc89d439fef4b7988fbc7d00a5c51ce74242ad2f907afbedd797305b
Parent
ab7ad2348c1a357…
2 files changed
+388
-298
+4
-4
+388
-298
| --- extsrc/sqlite3.c | ||
| +++ extsrc/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.38.0. By combining all the individual C code files into this | |
| 3 | +** version 3.39.0. 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. |
| @@ -450,13 +450,13 @@ | ||
| 450 | 450 | ** |
| 451 | 451 | ** See also: [sqlite3_libversion()], |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | -#define SQLITE_VERSION "3.38.0" | |
| 456 | -#define SQLITE_VERSION_NUMBER 3038000 | |
| 457 | -#define SQLITE_SOURCE_ID "2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab" | |
| 455 | +#define SQLITE_VERSION "3.39.0" | |
| 456 | +#define SQLITE_VERSION_NUMBER 3039000 | |
| 457 | +#define SQLITE_SOURCE_ID "2022-03-02 01:02:16 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b" | |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| @@ -10071,11 +10071,11 @@ | ||
| 10071 | 10071 | ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value |
| 10072 | 10072 | ** and remains valid for the duration of the xBestIndex method call. |
| 10073 | 10073 | ** ^When xBestIndex returns, the sqlite3_value object returned by |
| 10074 | 10074 | ** sqlite3_vtab_rhs_value() is automatically deallocated. |
| 10075 | 10075 | ** |
| 10076 | -** The "_rhs_" in the name of this routine is an appreviation for | |
| 10076 | +** The "_rhs_" in the name of this routine is an abbreviation for | |
| 10077 | 10077 | ** "Right-Hand Side". |
| 10078 | 10078 | */ |
| 10079 | 10079 | SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); |
| 10080 | 10080 | |
| 10081 | 10081 | /* |
| @@ -14709,18 +14709,19 @@ | ||
| 14709 | 14709 | ** Handle type for pages. |
| 14710 | 14710 | */ |
| 14711 | 14711 | typedef struct PgHdr DbPage; |
| 14712 | 14712 | |
| 14713 | 14713 | /* |
| 14714 | -** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is | |
| 14714 | +** Page number PAGER_SJ_PGNO is never used in an SQLite database (it is | |
| 14715 | 14715 | ** reserved for working around a windows/posix incompatibility). It is |
| 14716 | 14716 | ** used in the journal to signify that the remainder of the journal file |
| 14717 | 14717 | ** is devoted to storing a super-journal name - there are no more pages to |
| 14718 | 14718 | ** roll back. See comments for function writeSuperJournal() in pager.c |
| 14719 | 14719 | ** for details. |
| 14720 | 14720 | */ |
| 14721 | -#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) | |
| 14721 | +#define PAGER_SJ_PGNO_COMPUTED(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) | |
| 14722 | +#define PAGER_SJ_PGNO(x) ((x)->lckPgno) | |
| 14722 | 14723 | |
| 14723 | 14724 | /* |
| 14724 | 14725 | ** Allowed values for the flags parameter to sqlite3PagerOpen(). |
| 14725 | 14726 | ** |
| 14726 | 14727 | ** NOTE: These values must match the corresponding BTREE_ values in btree.h. |
| @@ -15393,11 +15394,10 @@ | ||
| 15393 | 15394 | SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ |
| 15394 | 15395 | Table *pTab; /* Used when p4type is P4_TABLE */ |
| 15395 | 15396 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 15396 | 15397 | Expr *pExpr; /* Used when p4type is P4_EXPR */ |
| 15397 | 15398 | #endif |
| 15398 | - int (*xAdvance)(BtCursor *, int); | |
| 15399 | 15399 | } p4; |
| 15400 | 15400 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 15401 | 15401 | char *zComment; /* Comment to improve readability */ |
| 15402 | 15402 | #endif |
| 15403 | 15403 | #ifdef VDBE_PROFILE |
| @@ -15444,25 +15444,23 @@ | ||
| 15444 | 15444 | #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 15445 | 15445 | #define P4_STATIC (-1) /* Pointer to a static string */ |
| 15446 | 15446 | #define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */ |
| 15447 | 15447 | #define P4_INT32 (-3) /* P4 is a 32-bit signed integer */ |
| 15448 | 15448 | #define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */ |
| 15449 | -#define P4_ADVANCE (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */ | |
| 15450 | -#define P4_TABLE (-6) /* P4 is a pointer to a Table structure */ | |
| 15449 | +#define P4_TABLE (-5) /* P4 is a pointer to a Table structure */ | |
| 15451 | 15450 | /* Above do not own any resources. Must free those below */ |
| 15452 | -#define P4_FREE_IF_LE (-7) | |
| 15453 | -#define P4_DYNAMIC (-7) /* Pointer to memory from sqliteMalloc() */ | |
| 15454 | -#define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */ | |
| 15455 | -#define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */ | |
| 15456 | -#define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */ | |
| 15457 | -#define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */ | |
| 15458 | -#define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */ | |
| 15459 | -#define P4_REAL (-13) /* P4 is a 64-bit floating point value */ | |
| 15460 | -#define P4_INT64 (-14) /* P4 is a 64-bit signed integer */ | |
| 15461 | -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ | |
| 15462 | -#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */ | |
| 15463 | -#define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */ | |
| 15451 | +#define P4_FREE_IF_LE (-6) | |
| 15452 | +#define P4_DYNAMIC (-6) /* Pointer to memory from sqliteMalloc() */ | |
| 15453 | +#define P4_FUNCDEF (-7) /* P4 is a pointer to a FuncDef structure */ | |
| 15454 | +#define P4_KEYINFO (-8) /* P4 is a pointer to a KeyInfo structure */ | |
| 15455 | +#define P4_EXPR (-9) /* P4 is a pointer to an Expr tree */ | |
| 15456 | +#define P4_MEM (-10) /* P4 is a pointer to a Mem* structure */ | |
| 15457 | +#define P4_VTAB (-11) /* P4 is a pointer to an sqlite3_vtab structure */ | |
| 15458 | +#define P4_REAL (-12) /* P4 is a 64-bit floating point value */ | |
| 15459 | +#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ | |
| 15460 | +#define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */ | |
| 15461 | +#define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */ | |
| 15464 | 15462 | |
| 15465 | 15463 | /* Error message codes for OP_Halt */ |
| 15466 | 15464 | #define P5_ConstraintNotNull 1 |
| 15467 | 15465 | #define P5_ConstraintUnique 2 |
| 15468 | 15466 | #define P5_ConstraintCheck 3 |
| @@ -15503,46 +15501,46 @@ | ||
| 15503 | 15501 | /* Automatically generated. Do not edit */ |
| 15504 | 15502 | /* See the tool/mkopcodeh.tcl script for details */ |
| 15505 | 15503 | #define OP_Savepoint 0 |
| 15506 | 15504 | #define OP_AutoCommit 1 |
| 15507 | 15505 | #define OP_Transaction 2 |
| 15508 | -#define OP_SorterNext 3 /* jump */ | |
| 15509 | -#define OP_Prev 4 /* jump */ | |
| 15510 | -#define OP_Next 5 /* jump */ | |
| 15511 | -#define OP_Checkpoint 6 | |
| 15512 | -#define OP_JournalMode 7 | |
| 15513 | -#define OP_Vacuum 8 | |
| 15514 | -#define OP_VFilter 9 /* jump, synopsis: iplan=r[P3] zplan='P4' */ | |
| 15515 | -#define OP_VUpdate 10 /* synopsis: data=r[P3@P2] */ | |
| 15516 | -#define OP_Goto 11 /* jump */ | |
| 15517 | -#define OP_Gosub 12 /* jump */ | |
| 15518 | -#define OP_InitCoroutine 13 /* jump */ | |
| 15519 | -#define OP_Yield 14 /* jump */ | |
| 15520 | -#define OP_MustBeInt 15 /* jump */ | |
| 15521 | -#define OP_Jump 16 /* jump */ | |
| 15522 | -#define OP_Once 17 /* jump */ | |
| 15523 | -#define OP_If 18 /* jump */ | |
| 15506 | +#define OP_Checkpoint 3 | |
| 15507 | +#define OP_JournalMode 4 | |
| 15508 | +#define OP_Vacuum 5 | |
| 15509 | +#define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */ | |
| 15510 | +#define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */ | |
| 15511 | +#define OP_Goto 8 /* jump */ | |
| 15512 | +#define OP_Gosub 9 /* jump */ | |
| 15513 | +#define OP_InitCoroutine 10 /* jump */ | |
| 15514 | +#define OP_Yield 11 /* jump */ | |
| 15515 | +#define OP_MustBeInt 12 /* jump */ | |
| 15516 | +#define OP_Jump 13 /* jump */ | |
| 15517 | +#define OP_Once 14 /* jump */ | |
| 15518 | +#define OP_If 15 /* jump */ | |
| 15519 | +#define OP_IfNot 16 /* jump */ | |
| 15520 | +#define OP_IsNullOrType 17 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */ | |
| 15521 | +#define OP_IfNullRow 18 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ | |
| 15524 | 15522 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 15525 | -#define OP_IfNot 20 /* jump */ | |
| 15526 | -#define OP_IsNullOrType 21 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */ | |
| 15527 | -#define OP_IfNullRow 22 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ | |
| 15528 | -#define OP_SeekLT 23 /* jump, synopsis: key=r[P3@P4] */ | |
| 15529 | -#define OP_SeekLE 24 /* jump, synopsis: key=r[P3@P4] */ | |
| 15530 | -#define OP_SeekGE 25 /* jump, synopsis: key=r[P3@P4] */ | |
| 15531 | -#define OP_SeekGT 26 /* jump, synopsis: key=r[P3@P4] */ | |
| 15532 | -#define OP_IfNotOpen 27 /* jump, synopsis: if( !csr[P1] ) goto P2 */ | |
| 15533 | -#define OP_IfNoHope 28 /* jump, synopsis: key=r[P3@P4] */ | |
| 15534 | -#define OP_NoConflict 29 /* jump, synopsis: key=r[P3@P4] */ | |
| 15535 | -#define OP_NotFound 30 /* jump, synopsis: key=r[P3@P4] */ | |
| 15536 | -#define OP_Found 31 /* jump, synopsis: key=r[P3@P4] */ | |
| 15537 | -#define OP_SeekRowid 32 /* jump, synopsis: intkey=r[P3] */ | |
| 15538 | -#define OP_NotExists 33 /* jump, synopsis: intkey=r[P3] */ | |
| 15539 | -#define OP_Last 34 /* jump */ | |
| 15540 | -#define OP_IfSmaller 35 /* jump */ | |
| 15541 | -#define OP_SorterSort 36 /* jump */ | |
| 15542 | -#define OP_Sort 37 /* jump */ | |
| 15543 | -#define OP_Rewind 38 /* jump */ | |
| 15523 | +#define OP_SeekLT 20 /* jump, synopsis: key=r[P3@P4] */ | |
| 15524 | +#define OP_SeekLE 21 /* jump, synopsis: key=r[P3@P4] */ | |
| 15525 | +#define OP_SeekGE 22 /* jump, synopsis: key=r[P3@P4] */ | |
| 15526 | +#define OP_SeekGT 23 /* jump, synopsis: key=r[P3@P4] */ | |
| 15527 | +#define OP_IfNotOpen 24 /* jump, synopsis: if( !csr[P1] ) goto P2 */ | |
| 15528 | +#define OP_IfNoHope 25 /* jump, synopsis: key=r[P3@P4] */ | |
| 15529 | +#define OP_NoConflict 26 /* jump, synopsis: key=r[P3@P4] */ | |
| 15530 | +#define OP_NotFound 27 /* jump, synopsis: key=r[P3@P4] */ | |
| 15531 | +#define OP_Found 28 /* jump, synopsis: key=r[P3@P4] */ | |
| 15532 | +#define OP_SeekRowid 29 /* jump, synopsis: intkey=r[P3] */ | |
| 15533 | +#define OP_NotExists 30 /* jump, synopsis: intkey=r[P3] */ | |
| 15534 | +#define OP_Last 31 /* jump */ | |
| 15535 | +#define OP_IfSmaller 32 /* jump */ | |
| 15536 | +#define OP_SorterSort 33 /* jump */ | |
| 15537 | +#define OP_Sort 34 /* jump */ | |
| 15538 | +#define OP_Rewind 35 /* jump */ | |
| 15539 | +#define OP_SorterNext 36 /* jump */ | |
| 15540 | +#define OP_Prev 37 /* jump */ | |
| 15541 | +#define OP_Next 38 /* jump */ | |
| 15544 | 15542 | #define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */ |
| 15545 | 15543 | #define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */ |
| 15546 | 15544 | #define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */ |
| 15547 | 15545 | #define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */ |
| 15548 | 15546 | #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| @@ -15697,15 +15695,15 @@ | ||
| 15697 | 15695 | #define OPFLG_IN2 0x04 /* in2: P2 is an input */ |
| 15698 | 15696 | #define OPFLG_IN3 0x08 /* in3: P3 is an input */ |
| 15699 | 15697 | #define OPFLG_OUT2 0x10 /* out2: P2 is an output */ |
| 15700 | 15698 | #define OPFLG_OUT3 0x20 /* out3: P3 is an output */ |
| 15701 | 15699 | #define OPFLG_INITIALIZER {\ |
| 15702 | -/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\ | |
| 15703 | -/* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\ | |
| 15704 | -/* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x03, 0x01, 0x09,\ | |
| 15705 | -/* 24 */ 0x09, 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09,\ | |
| 15706 | -/* 32 */ 0x09, 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ | |
| 15700 | +/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\ | |
| 15701 | +/* 8 */ 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x03,\ | |
| 15702 | +/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x09, 0x09, 0x09, 0x09,\ | |
| 15703 | +/* 24 */ 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x01,\ | |
| 15704 | +/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ | |
| 15707 | 15705 | /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\ |
| 15708 | 15706 | /* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 15709 | 15707 | /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\ |
| 15710 | 15708 | /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\ |
| 15711 | 15709 | /* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| @@ -17778,10 +17776,15 @@ | ||
| 17778 | 17776 | ** b-tree. |
| 17779 | 17777 | */ |
| 17780 | 17778 | struct UnpackedRecord { |
| 17781 | 17779 | KeyInfo *pKeyInfo; /* Collation and sort-order information */ |
| 17782 | 17780 | Mem *aMem; /* Values */ |
| 17781 | + union { | |
| 17782 | + char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */ | |
| 17783 | + i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */ | |
| 17784 | + } u; | |
| 17785 | + int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */ | |
| 17783 | 17786 | u16 nField; /* Number of entries in apMem[] */ |
| 17784 | 17787 | i8 default_rc; /* Comparison result if keys are equal */ |
| 17785 | 17788 | u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ |
| 17786 | 17789 | i8 r1; /* Value to return if (lhs < rhs) */ |
| 17787 | 17790 | i8 r2; /* Value to return if (lhs > rhs) */ |
| @@ -22225,20 +22228,20 @@ | ||
| 22225 | 22228 | i64 i; /* Integer value used when MEM_Int is set in flags */ |
| 22226 | 22229 | int nZero; /* Extra zero bytes when MEM_Zero and MEM_Blob set */ |
| 22227 | 22230 | const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */ |
| 22228 | 22231 | FuncDef *pDef; /* Used only when flags==MEM_Agg */ |
| 22229 | 22232 | } u; |
| 22233 | + char *z; /* String or BLOB value */ | |
| 22234 | + int n; /* Number of characters in string value, excluding '\0' */ | |
| 22230 | 22235 | u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ |
| 22231 | 22236 | u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ |
| 22232 | 22237 | u8 eSubtype; /* Subtype for this value */ |
| 22233 | - int n; /* Number of characters in string value, excluding '\0' */ | |
| 22234 | - char *z; /* String or BLOB value */ | |
| 22235 | 22238 | /* ShallowCopy only needs to copy the information above */ |
| 22236 | - char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ | |
| 22239 | + sqlite3 *db; /* The associated database connection */ | |
| 22237 | 22240 | int szMalloc; /* Size of the zMalloc allocation */ |
| 22238 | 22241 | u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */ |
| 22239 | - sqlite3 *db; /* The associated database connection */ | |
| 22242 | + char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ | |
| 22240 | 22243 | void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */ |
| 22241 | 22244 | #ifdef SQLITE_DEBUG |
| 22242 | 22245 | Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ |
| 22243 | 22246 | u16 mScopyFlags; /* flags value immediately after the shallow copy */ |
| 22244 | 22247 | #endif |
| @@ -22246,15 +22249,47 @@ | ||
| 22246 | 22249 | |
| 22247 | 22250 | /* |
| 22248 | 22251 | ** Size of struct Mem not including the Mem.zMalloc member or anything that |
| 22249 | 22252 | ** follows. |
| 22250 | 22253 | */ |
| 22251 | -#define MEMCELLSIZE offsetof(Mem,zMalloc) | |
| 22254 | +#define MEMCELLSIZE offsetof(Mem,db) | |
| 22252 | 22255 | |
| 22253 | -/* One or more of the following flags are set to indicate the validOK | |
| 22256 | +/* One or more of the following flags are set to indicate the | |
| 22254 | 22257 | ** representations of the value stored in the Mem struct. |
| 22255 | 22258 | ** |
| 22259 | +** * MEM_Null An SQL NULL value | |
| 22260 | +** | |
| 22261 | +** * MEM_Null|MEM_Zero An SQL NULL with the virtual table | |
| 22262 | +** UPDATE no-change flag set | |
| 22263 | +** | |
| 22264 | +** * MEM_Null|MEM_Term| An SQL NULL, but also contains a | |
| 22265 | +** MEM_Subtype pointer accessible using | |
| 22266 | +** sqlite3_value_pointer(). | |
| 22267 | +** | |
| 22268 | +** * MEM_Null|MEM_Cleared Special SQL NULL that compares non-equal | |
| 22269 | +** to other NULLs even using the IS operator. | |
| 22270 | +** | |
| 22271 | +** * MEM_Str A string, stored in Mem.z with | |
| 22272 | +** length Mem.n. Zero-terminated if | |
| 22273 | +** MEM_Term is set. This flag is | |
| 22274 | +** incompatible with MEM_Blob and | |
| 22275 | +** MEM_Null, but can appear with MEM_Int, | |
| 22276 | +** MEM_Real, and MEM_IntReal. | |
| 22277 | +** | |
| 22278 | +** * MEM_Blob A blob, stored in Mem.z length Mem.n. | |
| 22279 | +** Incompatible with MEM_Str, MEM_Null, | |
| 22280 | +** MEM_Int, MEM_Real, and MEM_IntReal. | |
| 22281 | +** | |
| 22282 | +** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus | |
| 22283 | +** MEM.u.i extra 0x00 bytes at the end. | |
| 22284 | +** | |
| 22285 | +** * MEM_Int Integer stored in Mem.u.i. | |
| 22286 | +** | |
| 22287 | +** * MEM_Real Real stored in Mem.u.r. | |
| 22288 | +** | |
| 22289 | +** * MEM_IntReal Real stored as an integer in Mem.u.i. | |
| 22290 | +** | |
| 22256 | 22291 | ** If the MEM_Null flag is set, then the value is an SQL NULL value. |
| 22257 | 22292 | ** For a pointer type created using sqlite3_bind_pointer() or |
| 22258 | 22293 | ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set. |
| 22259 | 22294 | ** |
| 22260 | 22295 | ** If the MEM_Str flag is set then Mem.z points at a string representation. |
| @@ -22261,39 +22296,36 @@ | ||
| 22261 | 22296 | ** Usually this is encoded in the same unicode encoding as the main |
| 22262 | 22297 | ** database (see below for exceptions). If the MEM_Term flag is also |
| 22263 | 22298 | ** set, then the string is nul terminated. The MEM_Int and MEM_Real |
| 22264 | 22299 | ** flags may coexist with the MEM_Str flag. |
| 22265 | 22300 | */ |
| 22301 | +#define MEM_Undefined 0x0000 /* Value is undefined */ | |
| 22266 | 22302 | #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */ |
| 22267 | 22303 | #define MEM_Str 0x0002 /* Value is a string */ |
| 22268 | 22304 | #define MEM_Int 0x0004 /* Value is an integer */ |
| 22269 | 22305 | #define MEM_Real 0x0008 /* Value is a real number */ |
| 22270 | 22306 | #define MEM_Blob 0x0010 /* Value is a BLOB */ |
| 22271 | 22307 | #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */ |
| 22272 | 22308 | #define MEM_AffMask 0x003f /* Mask of affinity bits */ |
| 22309 | + | |
| 22310 | +/* Extra bits that modify the meanings of the core datatypes above | |
| 22311 | +*/ | |
| 22273 | 22312 | #define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */ |
| 22274 | -#define MEM_Undefined 0x0080 /* Value is undefined */ | |
| 22313 | + /* 0x0080 // Available */ | |
| 22275 | 22314 | #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ |
| 22276 | -#define MEM_TypeMask 0xc1bf /* Mask of type bits */ | |
| 22277 | - | |
| 22278 | - | |
| 22279 | -/* Whenever Mem contains a valid string or blob representation, one of | |
| 22280 | -** the following flags must be set to determine the memory management | |
| 22281 | -** policy for Mem.z. The MEM_Term flag tells us whether or not the | |
| 22282 | -** string is \000 or \u0000 terminated | |
| 22283 | -*/ | |
| 22284 | 22315 | #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */ |
| 22285 | -#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */ | |
| 22286 | -#define MEM_Static 0x0800 /* Mem.z points to a static string */ | |
| 22287 | -#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */ | |
| 22288 | -#define MEM_Agg 0x2000 /* Mem.z points to an agg function context */ | |
| 22289 | -#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */ | |
| 22290 | -#define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */ | |
| 22291 | -#ifdef SQLITE_OMIT_INCRBLOB | |
| 22292 | - #undef MEM_Zero | |
| 22293 | - #define MEM_Zero 0x0000 | |
| 22294 | -#endif | |
| 22316 | +#define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */ | |
| 22317 | +#define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */ | |
| 22318 | +#define MEM_TypeMask 0x0dbf /* Mask of type bits */ | |
| 22319 | + | |
| 22320 | +/* Bits that determine the storage for Mem.z for a string or blob or | |
| 22321 | +** aggregate accumulator. | |
| 22322 | +*/ | |
| 22323 | +#define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */ | |
| 22324 | +#define MEM_Static 0x2000 /* Mem.z points to a static string */ | |
| 22325 | +#define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */ | |
| 22326 | +#define MEM_Agg 0x8000 /* Mem.z points to an agg function context */ | |
| 22295 | 22327 | |
| 22296 | 22328 | /* Return TRUE if Mem X contains dynamically allocated content - anything |
| 22297 | 22329 | ** that needs to be deallocated to avoid a leak. |
| 22298 | 22330 | */ |
| 22299 | 22331 | #define VdbeMemDynamic(X) \ |
| @@ -22311,15 +22343,19 @@ | ||
| 22311 | 22343 | #define MemNullNochng(X) \ |
| 22312 | 22344 | (((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \ |
| 22313 | 22345 | && (X)->n==0 && (X)->u.nZero==0) |
| 22314 | 22346 | |
| 22315 | 22347 | /* |
| 22316 | -** Return true if a memory cell is not marked as invalid. This macro | |
| 22348 | +** Return true if a memory cell has been initialized and is valid. | |
| 22317 | 22349 | ** is for use inside assert() statements only. |
| 22350 | +** | |
| 22351 | +** A Memory cell is initialized if at least one of the | |
| 22352 | +** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits | |
| 22353 | +** is set. It is "undefined" if all those bits are zero. | |
| 22318 | 22354 | */ |
| 22319 | 22355 | #ifdef SQLITE_DEBUG |
| 22320 | -#define memIsValid(M) ((M)->flags & MEM_Undefined)==0 | |
| 22356 | +#define memIsValid(M) ((M)->flags & MEM_AffMask)!=0 | |
| 22321 | 22357 | #endif |
| 22322 | 22358 | |
| 22323 | 22359 | /* |
| 22324 | 22360 | ** Each auxiliary data pointer stored by a user defined function |
| 22325 | 22361 | ** implementation calling sqlite3_set_auxdata() is stored in an instance |
| @@ -22523,12 +22559,12 @@ | ||
| 22523 | 22559 | ** Function prototypes |
| 22524 | 22560 | */ |
| 22525 | 22561 | SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); |
| 22526 | 22562 | SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); |
| 22527 | 22563 | void sqliteVdbePopStack(Vdbe*,int); |
| 22564 | +SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p); | |
| 22528 | 22565 | SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*); |
| 22529 | -SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*); | |
| 22530 | 22566 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); |
| 22531 | 22567 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 22532 | 22568 | SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); |
| 22533 | 22569 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 22534 | 22570 | SQLITE_PRIVATE void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| @@ -34579,46 +34615,46 @@ | ||
| 34579 | 34615 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){ |
| 34580 | 34616 | static const char *const azName[] = { |
| 34581 | 34617 | /* 0 */ "Savepoint" OpHelp(""), |
| 34582 | 34618 | /* 1 */ "AutoCommit" OpHelp(""), |
| 34583 | 34619 | /* 2 */ "Transaction" OpHelp(""), |
| 34584 | - /* 3 */ "SorterNext" OpHelp(""), | |
| 34585 | - /* 4 */ "Prev" OpHelp(""), | |
| 34586 | - /* 5 */ "Next" OpHelp(""), | |
| 34587 | - /* 6 */ "Checkpoint" OpHelp(""), | |
| 34588 | - /* 7 */ "JournalMode" OpHelp(""), | |
| 34589 | - /* 8 */ "Vacuum" OpHelp(""), | |
| 34590 | - /* 9 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), | |
| 34591 | - /* 10 */ "VUpdate" OpHelp("data=r[P3@P2]"), | |
| 34592 | - /* 11 */ "Goto" OpHelp(""), | |
| 34593 | - /* 12 */ "Gosub" OpHelp(""), | |
| 34594 | - /* 13 */ "InitCoroutine" OpHelp(""), | |
| 34595 | - /* 14 */ "Yield" OpHelp(""), | |
| 34596 | - /* 15 */ "MustBeInt" OpHelp(""), | |
| 34597 | - /* 16 */ "Jump" OpHelp(""), | |
| 34598 | - /* 17 */ "Once" OpHelp(""), | |
| 34599 | - /* 18 */ "If" OpHelp(""), | |
| 34620 | + /* 3 */ "Checkpoint" OpHelp(""), | |
| 34621 | + /* 4 */ "JournalMode" OpHelp(""), | |
| 34622 | + /* 5 */ "Vacuum" OpHelp(""), | |
| 34623 | + /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), | |
| 34624 | + /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"), | |
| 34625 | + /* 8 */ "Goto" OpHelp(""), | |
| 34626 | + /* 9 */ "Gosub" OpHelp(""), | |
| 34627 | + /* 10 */ "InitCoroutine" OpHelp(""), | |
| 34628 | + /* 11 */ "Yield" OpHelp(""), | |
| 34629 | + /* 12 */ "MustBeInt" OpHelp(""), | |
| 34630 | + /* 13 */ "Jump" OpHelp(""), | |
| 34631 | + /* 14 */ "Once" OpHelp(""), | |
| 34632 | + /* 15 */ "If" OpHelp(""), | |
| 34633 | + /* 16 */ "IfNot" OpHelp(""), | |
| 34634 | + /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"), | |
| 34635 | + /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), | |
| 34600 | 34636 | /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), |
| 34601 | - /* 20 */ "IfNot" OpHelp(""), | |
| 34602 | - /* 21 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"), | |
| 34603 | - /* 22 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), | |
| 34604 | - /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"), | |
| 34605 | - /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"), | |
| 34606 | - /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"), | |
| 34607 | - /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"), | |
| 34608 | - /* 27 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"), | |
| 34609 | - /* 28 */ "IfNoHope" OpHelp("key=r[P3@P4]"), | |
| 34610 | - /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"), | |
| 34611 | - /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"), | |
| 34612 | - /* 31 */ "Found" OpHelp("key=r[P3@P4]"), | |
| 34613 | - /* 32 */ "SeekRowid" OpHelp("intkey=r[P3]"), | |
| 34614 | - /* 33 */ "NotExists" OpHelp("intkey=r[P3]"), | |
| 34615 | - /* 34 */ "Last" OpHelp(""), | |
| 34616 | - /* 35 */ "IfSmaller" OpHelp(""), | |
| 34617 | - /* 36 */ "SorterSort" OpHelp(""), | |
| 34618 | - /* 37 */ "Sort" OpHelp(""), | |
| 34619 | - /* 38 */ "Rewind" OpHelp(""), | |
| 34637 | + /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"), | |
| 34638 | + /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"), | |
| 34639 | + /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"), | |
| 34640 | + /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"), | |
| 34641 | + /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"), | |
| 34642 | + /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"), | |
| 34643 | + /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"), | |
| 34644 | + /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"), | |
| 34645 | + /* 28 */ "Found" OpHelp("key=r[P3@P4]"), | |
| 34646 | + /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"), | |
| 34647 | + /* 30 */ "NotExists" OpHelp("intkey=r[P3]"), | |
| 34648 | + /* 31 */ "Last" OpHelp(""), | |
| 34649 | + /* 32 */ "IfSmaller" OpHelp(""), | |
| 34650 | + /* 33 */ "SorterSort" OpHelp(""), | |
| 34651 | + /* 34 */ "Sort" OpHelp(""), | |
| 34652 | + /* 35 */ "Rewind" OpHelp(""), | |
| 34653 | + /* 36 */ "SorterNext" OpHelp(""), | |
| 34654 | + /* 37 */ "Prev" OpHelp(""), | |
| 34655 | + /* 38 */ "Next" OpHelp(""), | |
| 34620 | 34656 | /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 34621 | 34657 | /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 34622 | 34658 | /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 34623 | 34659 | /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 34624 | 34660 | /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| @@ -50905,11 +50941,12 @@ | ||
| 50905 | 50941 | /* |
| 50906 | 50942 | ** Make sure the page is marked as dirty. If it isn't dirty already, |
| 50907 | 50943 | ** make it so. |
| 50908 | 50944 | */ |
| 50909 | 50945 | SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){ |
| 50910 | - assert( p->nRef>0 ); | |
| 50946 | + assert( p->nRef>0 || p->pCache->bPurgeable==0 ); | |
| 50947 | + testcase( p->nRef==0 ); | |
| 50911 | 50948 | assert( sqlite3PcachePageSanity(p) ); |
| 50912 | 50949 | if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/ |
| 50913 | 50950 | p->flags &= ~PGHDR_DONT_WRITE; |
| 50914 | 50951 | if( p->flags & PGHDR_CLEAN ){ |
| 50915 | 50952 | p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN); |
| @@ -53874,10 +53911,11 @@ | ||
| 53874 | 53911 | u16 nExtra; /* Add this many bytes to each in-memory page */ |
| 53875 | 53912 | i16 nReserve; /* Number of unused bytes at end of each page */ |
| 53876 | 53913 | u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ |
| 53877 | 53914 | u32 sectorSize; /* Assumed sector size during rollback */ |
| 53878 | 53915 | Pgno mxPgno; /* Maximum allowed size of the database */ |
| 53916 | + Pgno lckPgno; /* Page number for the locking page */ | |
| 53879 | 53917 | i64 pageSize; /* Number of bytes in a page */ |
| 53880 | 53918 | i64 journalSizeLimit; /* Size limit for persistent journal files */ |
| 53881 | 53919 | char *zFilename; /* Name of the database file */ |
| 53882 | 53920 | char *zJournal; /* Name of the journal file */ |
| 53883 | 53921 | int (*xBusyHandler)(void*); /* Function to call when busy */ |
| @@ -54860,11 +54898,11 @@ | ||
| 54860 | 54898 | ** pPager at the current location. The super-journal name must be the last |
| 54861 | 54899 | ** thing written to a journal file. If the pager is in full-sync mode, the |
| 54862 | 54900 | ** journal file descriptor is advanced to the next sector boundary before |
| 54863 | 54901 | ** anything is written. The format is: |
| 54864 | 54902 | ** |
| 54865 | -** + 4 bytes: PAGER_MJ_PGNO. | |
| 54903 | +** + 4 bytes: PAGER_SJ_PGNO. | |
| 54866 | 54904 | ** + N bytes: super-journal filename in utf-8. |
| 54867 | 54905 | ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). |
| 54868 | 54906 | ** + 4 bytes: super-journal name checksum. |
| 54869 | 54907 | ** + 8 bytes: aJournalMagic[]. |
| 54870 | 54908 | ** |
| @@ -54908,11 +54946,11 @@ | ||
| 54908 | 54946 | iHdrOff = pPager->journalOff; |
| 54909 | 54947 | |
| 54910 | 54948 | /* Write the super-journal data to the end of the journal file. If |
| 54911 | 54949 | ** an error occurs, return the error code to the caller. |
| 54912 | 54950 | */ |
| 54913 | - if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager)))) | |
| 54951 | + if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager)))) | |
| 54914 | 54952 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4))) |
| 54915 | 54953 | || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper))) |
| 54916 | 54954 | || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum))) |
| 54917 | 54955 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8, |
| 54918 | 54956 | iHdrOff+4+nSuper+8))) |
| @@ -55418,11 +55456,11 @@ | ||
| 55418 | 55456 | ** to the database file, then the IO error code is returned. If data |
| 55419 | 55457 | ** is successfully read from the (sub-)journal file but appears to be |
| 55420 | 55458 | ** corrupted, SQLITE_DONE is returned. Data is considered corrupted in |
| 55421 | 55459 | ** two circumstances: |
| 55422 | 55460 | ** |
| 55423 | -** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or | |
| 55461 | +** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or | |
| 55424 | 55462 | ** * If the record is being rolled back from the main journal file |
| 55425 | 55463 | ** and the checksum field does not match the record content. |
| 55426 | 55464 | ** |
| 55427 | 55465 | ** Neither of these two scenarios are possible during a savepoint rollback. |
| 55428 | 55466 | ** |
| @@ -55478,11 +55516,11 @@ | ||
| 55478 | 55516 | /* Sanity checking on the page. This is more important that I originally |
| 55479 | 55517 | ** thought. If a power failure occurs while the journal is being written, |
| 55480 | 55518 | ** it could cause invalid data to be written into the journal. We need to |
| 55481 | 55519 | ** detect this invalid data (with high probability) and ignore it. |
| 55482 | 55520 | */ |
| 55483 | - if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ | |
| 55521 | + if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){ | |
| 55484 | 55522 | assert( !isSavepnt ); |
| 55485 | 55523 | return SQLITE_DONE; |
| 55486 | 55524 | } |
| 55487 | 55525 | if( pgno>(Pgno)pPager->dbSize || sqlite3BitvecTest(pDone, pgno) ){ |
| 55488 | 55526 | return SQLITE_OK; |
| @@ -56037,10 +56075,13 @@ | ||
| 56037 | 56075 | rc = pager_truncate(pPager, mxPg); |
| 56038 | 56076 | if( rc!=SQLITE_OK ){ |
| 56039 | 56077 | goto end_playback; |
| 56040 | 56078 | } |
| 56041 | 56079 | pPager->dbSize = mxPg; |
| 56080 | + if( pPager->mxPgno<mxPg ){ | |
| 56081 | + pPager->mxPgno = mxPg; | |
| 56082 | + } | |
| 56042 | 56083 | } |
| 56043 | 56084 | |
| 56044 | 56085 | /* Copy original pages out of the journal and back into the |
| 56045 | 56086 | ** database file and/or page cache. |
| 56046 | 56087 | */ |
| @@ -56933,10 +56974,11 @@ | ||
| 56933 | 56974 | if( rc==SQLITE_OK ){ |
| 56934 | 56975 | sqlite3PageFree(pPager->pTmpSpace); |
| 56935 | 56976 | pPager->pTmpSpace = pNew; |
| 56936 | 56977 | pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); |
| 56937 | 56978 | pPager->pageSize = pageSize; |
| 56979 | + pPager->lckPgno = (Pgno)(PENDING_BYTE/pageSize) + 1; | |
| 56938 | 56980 | }else{ |
| 56939 | 56981 | sqlite3PageFree(pNew); |
| 56940 | 56982 | } |
| 56941 | 56983 | } |
| 56942 | 56984 | |
| @@ -58682,11 +58724,10 @@ | ||
| 58682 | 58724 | assert( pPager->errCode==SQLITE_OK ); |
| 58683 | 58725 | assert( pPager->eState>=PAGER_READER ); |
| 58684 | 58726 | assert( assert_pager_state(pPager) ); |
| 58685 | 58727 | assert( pPager->hasHeldSharedLock==1 ); |
| 58686 | 58728 | |
| 58687 | - if( pgno==0 ) return SQLITE_CORRUPT_BKPT; | |
| 58688 | 58729 | pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3); |
| 58689 | 58730 | if( pBase==0 ){ |
| 58690 | 58731 | pPg = 0; |
| 58691 | 58732 | rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase); |
| 58692 | 58733 | if( rc!=SQLITE_OK ) goto pager_acquire_err; |
| @@ -58702,22 +58743,22 @@ | ||
| 58702 | 58743 | |
| 58703 | 58744 | noContent = (flags & PAGER_GET_NOCONTENT)!=0; |
| 58704 | 58745 | if( pPg->pPager && !noContent ){ |
| 58705 | 58746 | /* In this case the pcache already contains an initialized copy of |
| 58706 | 58747 | ** the page. Return without further ado. */ |
| 58707 | - assert( pgno!=PAGER_MJ_PGNO(pPager) ); | |
| 58748 | + assert( pgno!=PAGER_SJ_PGNO(pPager) ); | |
| 58708 | 58749 | pPager->aStat[PAGER_STAT_HIT]++; |
| 58709 | 58750 | return SQLITE_OK; |
| 58710 | 58751 | |
| 58711 | 58752 | }else{ |
| 58712 | 58753 | /* The pager cache has created a new page. Its content needs to |
| 58713 | 58754 | ** be initialized. But first some error checks: |
| 58714 | 58755 | ** |
| 58715 | - ** (*) obsolete. Was: maximum page number is 2^31 | |
| 58716 | - ** (2) Never try to fetch the locking page | |
| 58756 | + ** (1) Never try to fetch the locking page | |
| 58757 | + ** (2) Never try to fetch page 0, which does not exist | |
| 58717 | 58758 | */ |
| 58718 | - if( pgno==PAGER_MJ_PGNO(pPager) ){ | |
| 58759 | + if( pgno==PAGER_SJ_PGNO(pPager) || pgno==0 ){ | |
| 58719 | 58760 | rc = SQLITE_CORRUPT_BKPT; |
| 58720 | 58761 | goto pager_acquire_err; |
| 58721 | 58762 | } |
| 58722 | 58763 | |
| 58723 | 58764 | pPg->pPager = pPager; |
| @@ -59112,11 +59153,11 @@ | ||
| 59112 | 59153 | i64 iOff = pPager->journalOff; |
| 59113 | 59154 | |
| 59114 | 59155 | /* We should never write to the journal file the page that |
| 59115 | 59156 | ** contains the database locks. The following assert verifies |
| 59116 | 59157 | ** that we do not. */ |
| 59117 | - assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); | |
| 59158 | + assert( pPg->pgno!=PAGER_SJ_PGNO(pPager) ); | |
| 59118 | 59159 | |
| 59119 | 59160 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 59120 | 59161 | pData2 = pPg->pData; |
| 59121 | 59162 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 59122 | 59163 | |
| @@ -59291,11 +59332,11 @@ | ||
| 59291 | 59332 | |
| 59292 | 59333 | for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){ |
| 59293 | 59334 | Pgno pg = pg1+ii; |
| 59294 | 59335 | PgHdr *pPage; |
| 59295 | 59336 | if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){ |
| 59296 | - if( pg!=PAGER_MJ_PGNO(pPager) ){ | |
| 59337 | + if( pg!=PAGER_SJ_PGNO(pPager) ){ | |
| 59297 | 59338 | rc = sqlite3PagerGet(pPager, pg, &pPage, 0); |
| 59298 | 59339 | if( rc==SQLITE_OK ){ |
| 59299 | 59340 | rc = pager_write(pPage); |
| 59300 | 59341 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 59301 | 59342 | needSync = 1; |
| @@ -59769,11 +59810,11 @@ | ||
| 59769 | 59810 | ** image was extended as part of the current transaction and then the |
| 59770 | 59811 | ** last page in the db image moved to the free-list. In this case the |
| 59771 | 59812 | ** last page is never written out to disk, leaving the database file |
| 59772 | 59813 | ** undersized. Fix this now if it is the case. */ |
| 59773 | 59814 | if( pPager->dbSize>pPager->dbFileSize ){ |
| 59774 | - Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager)); | |
| 59815 | + Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_SJ_PGNO(pPager)); | |
| 59775 | 59816 | assert( pPager->eState==PAGER_WRITER_DBMOD ); |
| 59776 | 59817 | rc = pager_truncate(pPager, nNew); |
| 59777 | 59818 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 59778 | 59819 | } |
| 59779 | 59820 | |
| @@ -65396,11 +65437,13 @@ | ||
| 65396 | 65437 | u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th |
| 65397 | 65438 | ** non-overflow cell */ |
| 65398 | 65439 | u8 *apOvfl[4]; /* Pointers to the body of overflow cells */ |
| 65399 | 65440 | BtShared *pBt; /* Pointer to BtShared that this page is part of */ |
| 65400 | 65441 | u8 *aData; /* Pointer to disk image of the page data */ |
| 65401 | - u8 *aDataEnd; /* One byte past the end of usable data */ | |
| 65442 | + u8 *aDataEnd; /* One byte past the end of the entire page - not just | |
| 65443 | + ** the usable space, the entire page. Used to prevent | |
| 65444 | + ** corruption-induced of buffer overflow. */ | |
| 65402 | 65445 | u8 *aCellIdx; /* The cell index area */ |
| 65403 | 65446 | u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ |
| 65404 | 65447 | DbPage *pDbPage; /* Pager page handle */ |
| 65405 | 65448 | u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */ |
| 65406 | 65449 | void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */ |
| @@ -65701,11 +65744,11 @@ | ||
| 65701 | 65744 | #define CURSOR_FAULT 4 |
| 65702 | 65745 | |
| 65703 | 65746 | /* |
| 65704 | 65747 | ** The database page the PENDING_BYTE occupies. This page is never used. |
| 65705 | 65748 | */ |
| 65706 | -# define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt) | |
| 65749 | +#define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/((pBt)->pageSize))+1)) | |
| 65707 | 65750 | |
| 65708 | 65751 | /* |
| 65709 | 65752 | ** These macros define the location of the pointer-map entry for a |
| 65710 | 65753 | ** database page. The first argument to each is the number of usable |
| 65711 | 65754 | ** bytes on each page of the database (often 1024). The second is the |
| @@ -67455,10 +67498,11 @@ | ||
| 67455 | 67498 | ** data area of the btree-page. The return number includes the cell |
| 67456 | 67499 | ** data header and the local payload, but not any overflow page or |
| 67457 | 67500 | ** the space used by the cell pointer. |
| 67458 | 67501 | ** |
| 67459 | 67502 | ** cellSizePtrNoPayload() => table internal nodes |
| 67503 | +** cellSizePtrTableLeaf() => table leaf nodes | |
| 67460 | 67504 | ** cellSizePtr() => all index nodes & table leaf nodes |
| 67461 | 67505 | */ |
| 67462 | 67506 | static u16 cellSizePtr(MemPage *pPage, u8 *pCell){ |
| 67463 | 67507 | u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */ |
| 67464 | 67508 | u8 *pEnd; /* End mark for a varint */ |
| @@ -67480,17 +67524,10 @@ | ||
| 67480 | 67524 | do{ |
| 67481 | 67525 | nSize = (nSize<<7) | (*++pIter & 0x7f); |
| 67482 | 67526 | }while( *(pIter)>=0x80 && pIter<pEnd ); |
| 67483 | 67527 | } |
| 67484 | 67528 | pIter++; |
| 67485 | - if( pPage->intKey ){ | |
| 67486 | - /* pIter now points at the 64-bit integer key value, a variable length | |
| 67487 | - ** integer. The following block moves pIter to point at the first byte | |
| 67488 | - ** past the end of the key value. */ | |
| 67489 | - pEnd = &pIter[9]; | |
| 67490 | - while( (*pIter++)&0x80 && pIter<pEnd ); | |
| 67491 | - } | |
| 67492 | 67529 | testcase( nSize==pPage->maxLocal ); |
| 67493 | 67530 | testcase( nSize==(u32)pPage->maxLocal+1 ); |
| 67494 | 67531 | if( nSize<=pPage->maxLocal ){ |
| 67495 | 67532 | nSize += (u32)(pIter - pCell); |
| 67496 | 67533 | if( nSize<4 ) nSize = 4; |
| @@ -67526,10 +67563,62 @@ | ||
| 67526 | 67563 | pEnd = pIter + 9; |
| 67527 | 67564 | while( (*pIter++)&0x80 && pIter<pEnd ); |
| 67528 | 67565 | assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB ); |
| 67529 | 67566 | return (u16)(pIter - pCell); |
| 67530 | 67567 | } |
| 67568 | +static u16 cellSizePtrTableLeaf(MemPage *pPage, u8 *pCell){ | |
| 67569 | + u8 *pIter = pCell; /* For looping over bytes of pCell */ | |
| 67570 | + u8 *pEnd; /* End mark for a varint */ | |
| 67571 | + u32 nSize; /* Size value to return */ | |
| 67572 | + | |
| 67573 | +#ifdef SQLITE_DEBUG | |
| 67574 | + /* The value returned by this function should always be the same as | |
| 67575 | + ** the (CellInfo.nSize) value found by doing a full parse of the | |
| 67576 | + ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of | |
| 67577 | + ** this function verifies that this invariant is not violated. */ | |
| 67578 | + CellInfo debuginfo; | |
| 67579 | + pPage->xParseCell(pPage, pCell, &debuginfo); | |
| 67580 | +#endif | |
| 67581 | + | |
| 67582 | + nSize = *pIter; | |
| 67583 | + if( nSize>=0x80 ){ | |
| 67584 | + pEnd = &pIter[8]; | |
| 67585 | + nSize &= 0x7f; | |
| 67586 | + do{ | |
| 67587 | + nSize = (nSize<<7) | (*++pIter & 0x7f); | |
| 67588 | + }while( *(pIter)>=0x80 && pIter<pEnd ); | |
| 67589 | + } | |
| 67590 | + pIter++; | |
| 67591 | + /* pIter now points at the 64-bit integer key value, a variable length | |
| 67592 | + ** integer. The following block moves pIter to point at the first byte | |
| 67593 | + ** past the end of the key value. */ | |
| 67594 | + if( (*pIter++)&0x80 | |
| 67595 | + && (*pIter++)&0x80 | |
| 67596 | + && (*pIter++)&0x80 | |
| 67597 | + && (*pIter++)&0x80 | |
| 67598 | + && (*pIter++)&0x80 | |
| 67599 | + && (*pIter++)&0x80 | |
| 67600 | + && (*pIter++)&0x80 | |
| 67601 | + && (*pIter++)&0x80 ){ pIter++; } | |
| 67602 | + testcase( nSize==pPage->maxLocal ); | |
| 67603 | + testcase( nSize==(u32)pPage->maxLocal+1 ); | |
| 67604 | + if( nSize<=pPage->maxLocal ){ | |
| 67605 | + nSize += (u32)(pIter - pCell); | |
| 67606 | + if( nSize<4 ) nSize = 4; | |
| 67607 | + }else{ | |
| 67608 | + int minLocal = pPage->minLocal; | |
| 67609 | + nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4); | |
| 67610 | + testcase( nSize==pPage->maxLocal ); | |
| 67611 | + testcase( nSize==(u32)pPage->maxLocal+1 ); | |
| 67612 | + if( nSize>pPage->maxLocal ){ | |
| 67613 | + nSize = minLocal; | |
| 67614 | + } | |
| 67615 | + nSize += 4 + (u16)(pIter - pCell); | |
| 67616 | + } | |
| 67617 | + assert( nSize==debuginfo.nSize || CORRUPT_DB ); | |
| 67618 | + return (u16)nSize; | |
| 67619 | +} | |
| 67531 | 67620 | |
| 67532 | 67621 | |
| 67533 | 67622 | #ifdef SQLITE_DEBUG |
| 67534 | 67623 | /* This variation on cellSizePtr() is used inside of assert() statements |
| 67535 | 67624 | ** only. */ |
| @@ -67539,11 +67628,11 @@ | ||
| 67539 | 67628 | #endif |
| 67540 | 67629 | |
| 67541 | 67630 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 67542 | 67631 | /* |
| 67543 | 67632 | ** The cell pCell is currently part of page pSrc but will ultimately be part |
| 67544 | -** of pPage. (pSrc and pPager are often the same.) If pCell contains a | |
| 67633 | +** of pPage. (pSrc and pPage are often the same.) If pCell contains a | |
| 67545 | 67634 | ** pointer to an overflow page, insert an entry into the pointer-map for |
| 67546 | 67635 | ** the overflow page that will be valid after pCell has been moved to pPage. |
| 67547 | 67636 | */ |
| 67548 | 67637 | static void ptrmapPutOvflPtr(MemPage *pPage, MemPage *pSrc, u8 *pCell,int *pRC){ |
| 67549 | 67638 | CellInfo info; |
| @@ -67714,21 +67803,23 @@ | ||
| 67714 | 67803 | */ |
| 67715 | 67804 | static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ |
| 67716 | 67805 | const int hdr = pPg->hdrOffset; /* Offset to page header */ |
| 67717 | 67806 | u8 * const aData = pPg->aData; /* Page data */ |
| 67718 | 67807 | int iAddr = hdr + 1; /* Address of ptr to pc */ |
| 67719 | - int pc = get2byte(&aData[iAddr]); /* Address of a free slot */ | |
| 67808 | + u8 *pTmp = &aData[iAddr]; /* Temporary ptr into aData[] */ | |
| 67809 | + int pc = get2byte(pTmp); /* Address of a free slot */ | |
| 67720 | 67810 | int x; /* Excess size of the slot */ |
| 67721 | 67811 | int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */ |
| 67722 | 67812 | int size; /* Size of the free slot */ |
| 67723 | 67813 | |
| 67724 | 67814 | assert( pc>0 ); |
| 67725 | 67815 | while( pc<=maxPC ){ |
| 67726 | 67816 | /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each |
| 67727 | 67817 | ** freeblock form a big-endian integer which is the size of the freeblock |
| 67728 | 67818 | ** in bytes, including the 4-byte header. */ |
| 67729 | - size = get2byte(&aData[pc+2]); | |
| 67819 | + pTmp = &aData[pc+2]; | |
| 67820 | + size = get2byte(pTmp); | |
| 67730 | 67821 | if( (x = size - nByte)>=0 ){ |
| 67731 | 67822 | testcase( x==4 ); |
| 67732 | 67823 | testcase( x==3 ); |
| 67733 | 67824 | if( x<4 ){ |
| 67734 | 67825 | /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total |
| @@ -67749,11 +67840,12 @@ | ||
| 67749 | 67840 | put2byte(&aData[pc+2], x); |
| 67750 | 67841 | } |
| 67751 | 67842 | return &aData[pc + x]; |
| 67752 | 67843 | } |
| 67753 | 67844 | iAddr = pc; |
| 67754 | - pc = get2byte(&aData[pc]); | |
| 67845 | + pTmp = &aData[pc]; | |
| 67846 | + pc = get2byte(pTmp); | |
| 67755 | 67847 | if( pc<=iAddr+size ){ |
| 67756 | 67848 | if( pc ){ |
| 67757 | 67849 | /* The next slot in the chain is not past the end of the current slot */ |
| 67758 | 67850 | *pRc = SQLITE_CORRUPT_PAGE(pPg); |
| 67759 | 67851 | } |
| @@ -67783,10 +67875,11 @@ | ||
| 67783 | 67875 | static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 67784 | 67876 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 67785 | 67877 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 67786 | 67878 | int top; /* First byte of cell content area */ |
| 67787 | 67879 | int rc = SQLITE_OK; /* Integer return code */ |
| 67880 | + u8 *pTmp; /* Temp ptr into data[] */ | |
| 67788 | 67881 | int gap; /* First byte of gap between cell pointers and cell content */ |
| 67789 | 67882 | |
| 67790 | 67883 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67791 | 67884 | assert( pPage->pBt ); |
| 67792 | 67885 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| @@ -67801,11 +67894,12 @@ | ||
| 67801 | 67894 | /* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size |
| 67802 | 67895 | ** and the reserved space is zero (the usual value for reserved space) |
| 67803 | 67896 | ** then the cell content offset of an empty page wants to be 65536. |
| 67804 | 67897 | ** However, that integer is too large to be stored in a 2-byte unsigned |
| 67805 | 67898 | ** integer, so a value of 0 is used in its place. */ |
| 67806 | - top = get2byte(&data[hdr+5]); | |
| 67899 | + pTmp = &data[hdr+5]; | |
| 67900 | + top = get2byte(pTmp); | |
| 67807 | 67901 | assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */ |
| 67808 | 67902 | if( gap>top ){ |
| 67809 | 67903 | if( top==0 && pPage->pBt->usableSize==65536 ){ |
| 67810 | 67904 | top = 65536; |
| 67811 | 67905 | }else{ |
| @@ -67883,10 +67977,11 @@ | ||
| 67883 | 67977 | u8 nFrag = 0; /* Reduction in fragmentation */ |
| 67884 | 67978 | u16 iOrigSize = iSize; /* Original value of iSize */ |
| 67885 | 67979 | u16 x; /* Offset to cell content area */ |
| 67886 | 67980 | u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */ |
| 67887 | 67981 | unsigned char *data = pPage->aData; /* Page content */ |
| 67982 | + u8 *pTmp; /* Temporary ptr into data[] */ | |
| 67888 | 67983 | |
| 67889 | 67984 | assert( pPage->pBt!=0 ); |
| 67890 | 67985 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67891 | 67986 | assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 67892 | 67987 | assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); |
| @@ -67945,11 +68040,12 @@ | ||
| 67945 | 68040 | } |
| 67946 | 68041 | } |
| 67947 | 68042 | if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); |
| 67948 | 68043 | data[hdr+7] -= nFrag; |
| 67949 | 68044 | } |
| 67950 | - x = get2byte(&data[hdr+5]); | |
| 68045 | + pTmp = &data[hdr+5]; | |
| 68046 | + x = get2byte(pTmp); | |
| 67951 | 68047 | if( iStart<=x ){ |
| 67952 | 68048 | /* The new freeblock is at the beginning of the cell content area, |
| 67953 | 68049 | ** so just extend the cell content area rather than create another |
| 67954 | 68050 | ** freelist entry */ |
| 67955 | 68051 | if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| @@ -68001,10 +68097,11 @@ | ||
| 68001 | 68097 | ** leaf table b-tree page. */ |
| 68002 | 68098 | assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 ); |
| 68003 | 68099 | pPage->intKey = 1; |
| 68004 | 68100 | if( pPage->leaf ){ |
| 68005 | 68101 | pPage->intKeyLeaf = 1; |
| 68102 | + pPage->xCellSize = cellSizePtrTableLeaf; | |
| 68006 | 68103 | pPage->xParseCell = btreeParseCellPtr; |
| 68007 | 68104 | }else{ |
| 68008 | 68105 | pPage->intKeyLeaf = 0; |
| 68009 | 68106 | pPage->xCellSize = cellSizePtrNoPayload; |
| 68010 | 68107 | pPage->xParseCell = btreeParseCellPtrNoPayload; |
| @@ -68181,11 +68278,11 @@ | ||
| 68181 | 68278 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 68182 | 68279 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| 68183 | 68280 | pPage->nOverflow = 0; |
| 68184 | 68281 | pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize; |
| 68185 | 68282 | pPage->aCellIdx = data + pPage->childPtrSize + 8; |
| 68186 | - pPage->aDataEnd = pPage->aData + pBt->usableSize; | |
| 68283 | + pPage->aDataEnd = pPage->aData + pBt->pageSize; | |
| 68187 | 68284 | pPage->aDataOfst = pPage->aData + pPage->childPtrSize; |
| 68188 | 68285 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 68189 | 68286 | ** number of cells on the page. */ |
| 68190 | 68287 | pPage->nCell = get2byte(&data[3]); |
| 68191 | 68288 | if( pPage->nCell>MX_CELL(pBt) ){ |
| @@ -68216,11 +68313,11 @@ | ||
| 68216 | 68313 | unsigned char *data = pPage->aData; |
| 68217 | 68314 | BtShared *pBt = pPage->pBt; |
| 68218 | 68315 | u8 hdr = pPage->hdrOffset; |
| 68219 | 68316 | u16 first; |
| 68220 | 68317 | |
| 68221 | - assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno ); | |
| 68318 | + assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB ); | |
| 68222 | 68319 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 68223 | 68320 | assert( sqlite3PagerGetData(pPage->pDbPage) == data ); |
| 68224 | 68321 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 68225 | 68322 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 68226 | 68323 | if( pBt->btsFlags & BTS_FAST_SECURE ){ |
| @@ -68232,11 +68329,11 @@ | ||
| 68232 | 68329 | data[hdr+7] = 0; |
| 68233 | 68330 | put2byte(&data[hdr+5], pBt->usableSize); |
| 68234 | 68331 | pPage->nFree = (u16)(pBt->usableSize - first); |
| 68235 | 68332 | decodeFlags(pPage, flags); |
| 68236 | 68333 | pPage->cellOffset = first; |
| 68237 | - pPage->aDataEnd = &data[pBt->usableSize]; | |
| 68334 | + pPage->aDataEnd = &data[pBt->pageSize]; | |
| 68238 | 68335 | pPage->aCellIdx = &data[first]; |
| 68239 | 68336 | pPage->aDataOfst = &data[pPage->childPtrSize]; |
| 68240 | 68337 | pPage->nOverflow = 0; |
| 68241 | 68338 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 68242 | 68339 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| @@ -68358,11 +68455,11 @@ | ||
| 68358 | 68455 | rc = btreeInitPage(*ppPage); |
| 68359 | 68456 | if( rc!=SQLITE_OK ){ |
| 68360 | 68457 | goto getAndInitPage_error2; |
| 68361 | 68458 | } |
| 68362 | 68459 | } |
| 68363 | - assert( (*ppPage)->pgno==pgno ); | |
| 68460 | + assert( (*ppPage)->pgno==pgno || CORRUPT_DB ); | |
| 68364 | 68461 | assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) ); |
| 68365 | 68462 | |
| 68366 | 68463 | /* If obtaining a child page for a cursor, we must verify that the page is |
| 68367 | 68464 | ** compatible with the root page. */ |
| 68368 | 68465 | if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){ |
| @@ -68377,11 +68474,13 @@ | ||
| 68377 | 68474 | if( pCur ){ |
| 68378 | 68475 | pCur->iPage--; |
| 68379 | 68476 | pCur->pPage = pCur->apPage[pCur->iPage]; |
| 68380 | 68477 | } |
| 68381 | 68478 | testcase( pgno==0 ); |
| 68382 | - assert( pgno!=0 || rc==SQLITE_CORRUPT ); | |
| 68479 | + assert( pgno!=0 || rc==SQLITE_CORRUPT | |
| 68480 | + || rc==SQLITE_IOERR_NOMEM | |
| 68481 | + || rc==SQLITE_NOMEM ); | |
| 68383 | 68482 | return rc; |
| 68384 | 68483 | } |
| 68385 | 68484 | |
| 68386 | 68485 | /* |
| 68387 | 68486 | ** Release a MemPage. This should be called once for each prior |
| @@ -75113,11 +75212,11 @@ | ||
| 75113 | 75212 | |
| 75114 | 75213 | pPage = pCur->pPage; |
| 75115 | 75214 | assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) ); |
| 75116 | 75215 | assert( pPage->leaf || !pPage->intKey ); |
| 75117 | 75216 | if( pPage->nFree<0 ){ |
| 75118 | - if( NEVER(pCur->eState>CURSOR_INVALID) ){ | |
| 75217 | + if( pCur->eState>CURSOR_INVALID ){ | |
| 75119 | 75218 | rc = SQLITE_CORRUPT_BKPT; |
| 75120 | 75219 | }else{ |
| 75121 | 75220 | rc = btreeComputeFreeSpace(pPage); |
| 75122 | 75221 | } |
| 75123 | 75222 | if( rc ) return rc; |
| @@ -75431,11 +75530,11 @@ | ||
| 75431 | 75530 | ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT. |
| 75432 | 75531 | */ |
| 75433 | 75532 | bPreserve = (flags & BTREE_SAVEPOSITION)!=0; |
| 75434 | 75533 | if( bPreserve ){ |
| 75435 | 75534 | if( !pPage->leaf |
| 75436 | - || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) | |
| 75535 | + || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) | |
| 75437 | 75536 | || pPage->nCell==1 /* See dbfuzz001.test for a test case */ |
| 75438 | 75537 | ){ |
| 75439 | 75538 | /* A b-tree rebalance will be required after deleting this entry. |
| 75440 | 75539 | ** Save the cursor key. */ |
| 75441 | 75540 | rc = saveCursorKey(pCur); |
| @@ -80545,11 +80644,11 @@ | ||
| 80545 | 80644 | ** and store that value in *pMaxFuncArgs. |
| 80546 | 80645 | ** |
| 80547 | 80646 | ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately |
| 80548 | 80647 | ** indicate what the prepared statement actually does. |
| 80549 | 80648 | ** |
| 80550 | -** (4) Initialize the p4.xAdvance pointer on opcodes that use it. | |
| 80649 | +** (4) (discontinued) | |
| 80551 | 80650 | ** |
| 80552 | 80651 | ** (5) Reclaim the memory allocated for storing labels. |
| 80553 | 80652 | ** |
| 80554 | 80653 | ** This routine will only function correctly if the mkopcodeh.tcl generator |
| 80555 | 80654 | ** script numbers the opcodes correctly. Changes to this routine must be |
| @@ -80591,29 +80690,10 @@ | ||
| 80591 | 80690 | case OP_JournalMode: { |
| 80592 | 80691 | p->readOnly = 0; |
| 80593 | 80692 | p->bIsReader = 1; |
| 80594 | 80693 | break; |
| 80595 | 80694 | } |
| 80596 | - case OP_Next: | |
| 80597 | - case OP_SorterNext: { | |
| 80598 | - pOp->p4.xAdvance = sqlite3BtreeNext; | |
| 80599 | - pOp->p4type = P4_ADVANCE; | |
| 80600 | - /* The code generator never codes any of these opcodes as a jump | |
| 80601 | - ** to a label. They are always coded as a jump backwards to a | |
| 80602 | - ** known address */ | |
| 80603 | - assert( pOp->p2>=0 ); | |
| 80604 | - break; | |
| 80605 | - } | |
| 80606 | - case OP_Prev: { | |
| 80607 | - pOp->p4.xAdvance = sqlite3BtreePrevious; | |
| 80608 | - pOp->p4type = P4_ADVANCE; | |
| 80609 | - /* The code generator never codes any of these opcodes as a jump | |
| 80610 | - ** to a label. They are always coded as a jump backwards to a | |
| 80611 | - ** known address */ | |
| 80612 | - assert( pOp->p2>=0 ); | |
| 80613 | - break; | |
| 80614 | - } | |
| 80615 | 80695 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 80616 | 80696 | case OP_VUpdate: { |
| 80617 | 80697 | if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; |
| 80618 | 80698 | break; |
| 80619 | 80699 | } |
| @@ -80893,11 +80973,10 @@ | ||
| 80893 | 80973 | break; |
| 80894 | 80974 | } |
| 80895 | 80975 | case P4_REAL: |
| 80896 | 80976 | case P4_INT64: |
| 80897 | 80977 | case P4_DYNAMIC: |
| 80898 | - case P4_DYNBLOB: | |
| 80899 | 80978 | case P4_INTARRAY: { |
| 80900 | 80979 | sqlite3DbFree(db, p4); |
| 80901 | 80980 | break; |
| 80902 | 80981 | } |
| 80903 | 80982 | case P4_KEYINFO: { |
| @@ -81490,14 +81569,10 @@ | ||
| 81490 | 81569 | } |
| 81491 | 81570 | case P4_SUBPROGRAM: { |
| 81492 | 81571 | zP4 = "program"; |
| 81493 | 81572 | break; |
| 81494 | 81573 | } |
| 81495 | - case P4_DYNBLOB: | |
| 81496 | - case P4_ADVANCE: { | |
| 81497 | - break; | |
| 81498 | - } | |
| 81499 | 81574 | case P4_TABLE: { |
| 81500 | 81575 | zP4 = pOp->p4.pTab->zName; |
| 81501 | 81576 | break; |
| 81502 | 81577 | } |
| 81503 | 81578 | default: { |
| @@ -81625,20 +81700,34 @@ | ||
| 81625 | 81700 | } |
| 81626 | 81701 | #endif |
| 81627 | 81702 | |
| 81628 | 81703 | /* |
| 81629 | 81704 | ** Initialize an array of N Mem element. |
| 81705 | +** | |
| 81706 | +** This is a high-runner, so only those fields that really do need to | |
| 81707 | +** be initialized are set. The Mem structure is organized so that | |
| 81708 | +** the fields that get initialized are nearby and hopefully on the same | |
| 81709 | +** cache line. | |
| 81710 | +** | |
| 81711 | +** Mem.flags = flags | |
| 81712 | +** Mem.db = db | |
| 81713 | +** Mem.szMalloc = 0 | |
| 81714 | +** | |
| 81715 | +** All other fields of Mem can safely remain uninitialized for now. They | |
| 81716 | +** will be initialized before use. | |
| 81630 | 81717 | */ |
| 81631 | 81718 | static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ |
| 81632 | - while( (N--)>0 ){ | |
| 81633 | - p->db = db; | |
| 81634 | - p->flags = flags; | |
| 81635 | - p->szMalloc = 0; | |
| 81719 | + if( N>0 ){ | |
| 81720 | + do{ | |
| 81721 | + p->flags = flags; | |
| 81722 | + p->db = db; | |
| 81723 | + p->szMalloc = 0; | |
| 81636 | 81724 | #ifdef SQLITE_DEBUG |
| 81637 | - p->pScopyFrom = 0; | |
| 81725 | + p->pScopyFrom = 0; | |
| 81638 | 81726 | #endif |
| 81639 | - p++; | |
| 81727 | + p++; | |
| 81728 | + }while( (--N)>0 ); | |
| 81640 | 81729 | } |
| 81641 | 81730 | } |
| 81642 | 81731 | |
| 81643 | 81732 | /* |
| 81644 | 81733 | ** Release an array of N Mem elements |
| @@ -83292,11 +83381,11 @@ | ||
| 83292 | 83381 | ** pointed to was deleted out from under it. Or maybe the btree was |
| 83293 | 83382 | ** rebalanced. Whatever the cause, try to restore "p" to the place it |
| 83294 | 83383 | ** is supposed to be pointing. If the row was deleted out from under the |
| 83295 | 83384 | ** cursor, set the cursor to point to a NULL row. |
| 83296 | 83385 | */ |
| 83297 | -static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){ | |
| 83386 | +SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p){ | |
| 83298 | 83387 | int isDifferentRow, rc; |
| 83299 | 83388 | assert( p->eCurType==CURTYPE_BTREE ); |
| 83300 | 83389 | assert( p->uc.pCursor!=0 ); |
| 83301 | 83390 | assert( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ); |
| 83302 | 83391 | rc = sqlite3BtreeCursorRestore(p->uc.pCursor, &isDifferentRow); |
| @@ -83310,43 +83399,11 @@ | ||
| 83310 | 83399 | ** if need be. Return any I/O error from the restore operation. |
| 83311 | 83400 | */ |
| 83312 | 83401 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){ |
| 83313 | 83402 | assert( p->eCurType==CURTYPE_BTREE ); |
| 83314 | 83403 | if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 83315 | - return handleMovedCursor(p); | |
| 83316 | - } | |
| 83317 | - return SQLITE_OK; | |
| 83318 | -} | |
| 83319 | - | |
| 83320 | -/* | |
| 83321 | -** Make sure the cursor p is ready to read or write the row to which it | |
| 83322 | -** was last positioned. Return an error code if an OOM fault or I/O error | |
| 83323 | -** prevents us from positioning the cursor to its correct position. | |
| 83324 | -** | |
| 83325 | -** If a MoveTo operation is pending on the given cursor, then do that | |
| 83326 | -** MoveTo now. If no move is pending, check to see if the row has been | |
| 83327 | -** deleted out from under the cursor and if it has, mark the row as | |
| 83328 | -** a NULL row. | |
| 83329 | -** | |
| 83330 | -** If the cursor is already pointing to the correct row and that row has | |
| 83331 | -** not been deleted out from under the cursor, then this routine is a no-op. | |
| 83332 | -*/ | |
| 83333 | -SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){ | |
| 83334 | - VdbeCursor *p = *pp; | |
| 83335 | - assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); | |
| 83336 | - if( p->deferredMoveto ){ | |
| 83337 | - u32 iMap; | |
| 83338 | - assert( !p->isEphemeral ); | |
| 83339 | - if( p->ub.aAltMap && (iMap = p->ub.aAltMap[1+*piCol])>0 && !p->nullRow ){ | |
| 83340 | - *pp = p->pAltCursor; | |
| 83341 | - *piCol = iMap - 1; | |
| 83342 | - return SQLITE_OK; | |
| 83343 | - } | |
| 83344 | - return sqlite3VdbeFinishMoveto(p); | |
| 83345 | - } | |
| 83346 | - if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ | |
| 83347 | - return handleMovedCursor(p); | |
| 83404 | + return sqlite3VdbeHandleMovedCursor(p); | |
| 83348 | 83405 | } |
| 83349 | 83406 | return SQLITE_OK; |
| 83350 | 83407 | } |
| 83351 | 83408 | |
| 83352 | 83409 | /* |
| @@ -84529,11 +84586,12 @@ | ||
| 84529 | 84586 | |
| 84530 | 84587 | default: |
| 84531 | 84588 | return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2); |
| 84532 | 84589 | } |
| 84533 | 84590 | |
| 84534 | - v = pPKey2->aMem[0].u.i; | |
| 84591 | + assert( pPKey2->u.i == pPKey2->aMem[0].u.i ); | |
| 84592 | + v = pPKey2->u.i; | |
| 84535 | 84593 | if( v>lhs ){ |
| 84536 | 84594 | res = pPKey2->r1; |
| 84537 | 84595 | }else if( v<lhs ){ |
| 84538 | 84596 | res = pPKey2->r2; |
| 84539 | 84597 | }else if( pPKey2->nField>1 ){ |
| @@ -84564,16 +84622,22 @@ | ||
| 84564 | 84622 | const u8 *aKey1 = (const u8*)pKey1; |
| 84565 | 84623 | int serial_type; |
| 84566 | 84624 | int res; |
| 84567 | 84625 | |
| 84568 | 84626 | assert( pPKey2->aMem[0].flags & MEM_Str ); |
| 84627 | + assert( pPKey2->aMem[0].n == pPKey2->n ); | |
| 84628 | + assert( pPKey2->aMem[0].z == pPKey2->u.z ); | |
| 84569 | 84629 | vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); |
| 84570 | - serial_type = (u8)(aKey1[1]); | |
| 84571 | - if( serial_type >= 0x80 ){ | |
| 84572 | - sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); | |
| 84573 | - } | |
| 84630 | + serial_type = (signed char)(aKey1[1]); | |
| 84631 | + | |
| 84632 | +vrcs_restart: | |
| 84574 | 84633 | if( serial_type<12 ){ |
| 84634 | + if( serial_type<0 ){ | |
| 84635 | + sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); | |
| 84636 | + if( serial_type>=12 ) goto vrcs_restart; | |
| 84637 | + assert( CORRUPT_DB ); | |
| 84638 | + } | |
| 84575 | 84639 | res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ |
| 84576 | 84640 | }else if( !(serial_type & 0x01) ){ |
| 84577 | 84641 | res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ |
| 84578 | 84642 | }else{ |
| 84579 | 84643 | int nCmp; |
| @@ -84583,19 +84647,19 @@ | ||
| 84583 | 84647 | nStr = (serial_type-12) / 2; |
| 84584 | 84648 | if( (szHdr + nStr) > nKey1 ){ |
| 84585 | 84649 | pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT; |
| 84586 | 84650 | return 0; /* Corruption */ |
| 84587 | 84651 | } |
| 84588 | - nCmp = MIN( pPKey2->aMem[0].n, nStr ); | |
| 84589 | - res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp); | |
| 84652 | + nCmp = MIN( pPKey2->n, nStr ); | |
| 84653 | + res = memcmp(&aKey1[szHdr], pPKey2->u.z, nCmp); | |
| 84590 | 84654 | |
| 84591 | 84655 | if( res>0 ){ |
| 84592 | 84656 | res = pPKey2->r2; |
| 84593 | 84657 | }else if( res<0 ){ |
| 84594 | 84658 | res = pPKey2->r1; |
| 84595 | 84659 | }else{ |
| 84596 | - res = nStr - pPKey2->aMem[0].n; | |
| 84660 | + res = nStr - pPKey2->n; | |
| 84597 | 84661 | if( res==0 ){ |
| 84598 | 84662 | if( pPKey2->nField>1 ){ |
| 84599 | 84663 | res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 84600 | 84664 | }else{ |
| 84601 | 84665 | res = pPKey2->default_rc; |
| @@ -84646,19 +84710,22 @@ | ||
| 84646 | 84710 | }else{ |
| 84647 | 84711 | p->r1 = -1; |
| 84648 | 84712 | p->r2 = 1; |
| 84649 | 84713 | } |
| 84650 | 84714 | if( (flags & MEM_Int) ){ |
| 84715 | + p->u.i = p->aMem[0].u.i; | |
| 84651 | 84716 | return vdbeRecordCompareInt; |
| 84652 | 84717 | } |
| 84653 | 84718 | testcase( flags & MEM_Real ); |
| 84654 | 84719 | testcase( flags & MEM_Null ); |
| 84655 | 84720 | testcase( flags & MEM_Blob ); |
| 84656 | 84721 | if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0 |
| 84657 | 84722 | && p->pKeyInfo->aColl[0]==0 |
| 84658 | 84723 | ){ |
| 84659 | 84724 | assert( flags & MEM_Str ); |
| 84725 | + p->u.z = p->aMem[0].z; | |
| 84726 | + p->n = p->aMem[0].n; | |
| 84660 | 84727 | return vdbeRecordCompareString; |
| 84661 | 84728 | } |
| 84662 | 84729 | } |
| 84663 | 84730 | |
| 84664 | 84731 | return sqlite3VdbeRecordCompare; |
| @@ -86129,19 +86196,19 @@ | ||
| 86129 | 86196 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 86130 | 86197 | __attribute__((aligned(8))) |
| 86131 | 86198 | #endif |
| 86132 | 86199 | = { |
| 86133 | 86200 | /* .u = */ {0}, |
| 86201 | + /* .z = */ (char*)0, | |
| 86202 | + /* .n = */ (int)0, | |
| 86134 | 86203 | /* .flags = */ (u16)MEM_Null, |
| 86135 | 86204 | /* .enc = */ (u8)0, |
| 86136 | 86205 | /* .eSubtype = */ (u8)0, |
| 86137 | - /* .n = */ (int)0, | |
| 86138 | - /* .z = */ (char*)0, | |
| 86139 | - /* .zMalloc = */ (char*)0, | |
| 86206 | + /* .db = */ (sqlite3*)0, | |
| 86140 | 86207 | /* .szMalloc = */ (int)0, |
| 86141 | 86208 | /* .uTemp = */ (u32)0, |
| 86142 | - /* .db = */ (sqlite3*)0, | |
| 86209 | + /* .zMalloc = */ (char*)0, | |
| 86143 | 86210 | /* .xDel = */ (void(*)(void*))0, |
| 86144 | 86211 | #ifdef SQLITE_DEBUG |
| 86145 | 86212 | /* .pScopyFrom = */ (Mem*)0, |
| 86146 | 86213 | /* .mScopyFlags= */ 0, |
| 86147 | 86214 | #endif |
| @@ -90020,11 +90087,11 @@ | ||
| 90020 | 90087 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 90021 | 90088 | */ |
| 90022 | 90089 | case OP_Column: { |
| 90023 | 90090 | u32 p2; /* column number to retrieve */ |
| 90024 | 90091 | VdbeCursor *pC; /* The VDBE cursor */ |
| 90025 | - BtCursor *pCrsr; /* The BTree cursor */ | |
| 90092 | + BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */ | |
| 90026 | 90093 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 90027 | 90094 | int len; /* The length of the serialized data for the column */ |
| 90028 | 90095 | int i; /* Loop counter */ |
| 90029 | 90096 | Mem *pDest; /* Where to write the extracted value */ |
| 90030 | 90097 | Mem sMem; /* For storing the record being decoded */ |
| @@ -90034,23 +90101,15 @@ | ||
| 90034 | 90101 | u64 offset64; /* 64-bit offset */ |
| 90035 | 90102 | u32 t; /* A type code from the record header */ |
| 90036 | 90103 | Mem *pReg; /* PseudoTable input register */ |
| 90037 | 90104 | |
| 90038 | 90105 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90106 | + assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); | |
| 90039 | 90107 | pC = p->apCsr[pOp->p1]; |
| 90040 | - assert( pC!=0 ); | |
| 90041 | 90108 | p2 = (u32)pOp->p2; |
| 90042 | 90109 | |
| 90043 | - /* If the cursor cache is stale (meaning it is not currently point at | |
| 90044 | - ** the correct row) then bring it up-to-date by doing the necessary | |
| 90045 | - ** B-Tree seek. */ | |
| 90046 | - rc = sqlite3VdbeCursorMoveto(&pC, &p2); | |
| 90047 | - if( rc ) goto abort_due_to_error; | |
| 90048 | - | |
| 90049 | - assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); | |
| 90050 | - pDest = &aMem[pOp->p3]; | |
| 90051 | - memAboutToChange(p, pDest); | |
| 90110 | +op_column_restart: | |
| 90052 | 90111 | assert( pC!=0 ); |
| 90053 | 90112 | assert( p2<(u32)pC->nField ); |
| 90054 | 90113 | aOffset = pC->aOffset; |
| 90055 | 90114 | assert( aOffset==pC->aType+pC->nField ); |
| 90056 | 90115 | assert( pC->eCurType!=CURTYPE_VTAB ); |
| @@ -90067,30 +90126,43 @@ | ||
| 90067 | 90126 | assert( pReg->flags & MEM_Blob ); |
| 90068 | 90127 | assert( memIsValid(pReg) ); |
| 90069 | 90128 | pC->payloadSize = pC->szRow = pReg->n; |
| 90070 | 90129 | pC->aRow = (u8*)pReg->z; |
| 90071 | 90130 | }else{ |
| 90131 | + pDest = &aMem[pOp->p3]; | |
| 90132 | + memAboutToChange(p, pDest); | |
| 90072 | 90133 | sqlite3VdbeMemSetNull(pDest); |
| 90073 | 90134 | goto op_column_out; |
| 90074 | 90135 | } |
| 90075 | 90136 | }else{ |
| 90076 | 90137 | pCrsr = pC->uc.pCursor; |
| 90138 | + if( pC->deferredMoveto ){ | |
| 90139 | + u32 iMap; | |
| 90140 | + assert( !pC->isEphemeral ); | |
| 90141 | + if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){ | |
| 90142 | + pC = pC->pAltCursor; | |
| 90143 | + p2 = iMap - 1; | |
| 90144 | + goto op_column_restart; | |
| 90145 | + } | |
| 90146 | + rc = sqlite3VdbeFinishMoveto(pC); | |
| 90147 | + if( rc ) goto abort_due_to_error; | |
| 90148 | + }else if( sqlite3BtreeCursorHasMoved(pCrsr) ){ | |
| 90149 | + rc = sqlite3VdbeHandleMovedCursor(pC); | |
| 90150 | + if( rc ) goto abort_due_to_error; | |
| 90151 | + goto op_column_restart; | |
| 90152 | + } | |
| 90077 | 90153 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 90078 | 90154 | assert( pCrsr ); |
| 90079 | 90155 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 90080 | 90156 | pC->payloadSize = sqlite3BtreePayloadSize(pCrsr); |
| 90081 | 90157 | pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow); |
| 90082 | 90158 | assert( pC->szRow<=pC->payloadSize ); |
| 90083 | 90159 | assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */ |
| 90084 | - if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ | |
| 90085 | - goto too_big; | |
| 90086 | - } | |
| 90087 | 90160 | } |
| 90088 | 90161 | pC->cacheStatus = p->cacheCtr; |
| 90089 | 90162 | pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]); |
| 90090 | 90163 | pC->nHdrParsed = 0; |
| 90091 | - | |
| 90092 | 90164 | |
| 90093 | 90165 | if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/ |
| 90094 | 90166 | /* pC->aRow does not have to hold the entire row, but it does at least |
| 90095 | 90167 | ** need to cover the header of the record. If pC->aRow does not contain |
| 90096 | 90168 | ** the complete header, then set it to zero, forcing the header to be |
| @@ -90127,10 +90199,14 @@ | ||
| 90127 | 90199 | zData = pC->aRow; |
| 90128 | 90200 | assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */ |
| 90129 | 90201 | testcase( aOffset[0]==0 ); |
| 90130 | 90202 | goto op_column_read_header; |
| 90131 | 90203 | } |
| 90204 | + }else if( sqlite3BtreeCursorHasMoved(pC->uc.pCursor) ){ | |
| 90205 | + rc = sqlite3VdbeHandleMovedCursor(pC); | |
| 90206 | + if( rc ) goto abort_due_to_error; | |
| 90207 | + goto op_column_restart; | |
| 90132 | 90208 | } |
| 90133 | 90209 | |
| 90134 | 90210 | /* Make sure at least the first p2+1 entries of the header have been |
| 90135 | 90211 | ** parsed and valid information is in aOffset[] and pC->aType[]. |
| 90136 | 90212 | */ |
| @@ -90195,10 +90271,12 @@ | ||
| 90195 | 90271 | /* If after trying to extract new entries from the header, nHdrParsed is |
| 90196 | 90272 | ** still not up to p2, that means that the record has fewer than p2 |
| 90197 | 90273 | ** columns. So the result will be either the default value or a NULL. |
| 90198 | 90274 | */ |
| 90199 | 90275 | if( pC->nHdrParsed<=p2 ){ |
| 90276 | + pDest = &aMem[pOp->p3]; | |
| 90277 | + memAboutToChange(p, pDest); | |
| 90200 | 90278 | if( pOp->p4type==P4_MEM ){ |
| 90201 | 90279 | sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); |
| 90202 | 90280 | }else{ |
| 90203 | 90281 | sqlite3VdbeMemSetNull(pDest); |
| 90204 | 90282 | } |
| @@ -90212,10 +90290,12 @@ | ||
| 90212 | 90290 | ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are |
| 90213 | 90291 | ** all valid. |
| 90214 | 90292 | */ |
| 90215 | 90293 | assert( p2<pC->nHdrParsed ); |
| 90216 | 90294 | assert( rc==SQLITE_OK ); |
| 90295 | + pDest = &aMem[pOp->p3]; | |
| 90296 | + memAboutToChange(p, pDest); | |
| 90217 | 90297 | assert( sqlite3VdbeCheckMemInvariants(pDest) ); |
| 90218 | 90298 | if( VdbeMemDynamic(pDest) ){ |
| 90219 | 90299 | sqlite3VdbeMemSetNull(pDest); |
| 90220 | 90300 | } |
| 90221 | 90301 | assert( t==pC->aType[p2] ); |
| @@ -90232,10 +90312,11 @@ | ||
| 90232 | 90312 | */ |
| 90233 | 90313 | static const u16 aFlag[] = { MEM_Blob, MEM_Str|MEM_Term }; |
| 90234 | 90314 | pDest->n = len = (t-12)/2; |
| 90235 | 90315 | pDest->enc = encoding; |
| 90236 | 90316 | if( pDest->szMalloc < len+2 ){ |
| 90317 | + if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big; | |
| 90237 | 90318 | pDest->flags = MEM_Null; |
| 90238 | 90319 | if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem; |
| 90239 | 90320 | }else{ |
| 90240 | 90321 | pDest->z = pDest->zMalloc; |
| 90241 | 90322 | } |
| @@ -90264,10 +90345,11 @@ | ||
| 90264 | 90345 | ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint()) |
| 90265 | 90346 | ** and it begins with a bunch of zeros. |
| 90266 | 90347 | */ |
| 90267 | 90348 | sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest); |
| 90268 | 90349 | }else{ |
| 90350 | + if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big; | |
| 90269 | 90351 | rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); |
| 90270 | 90352 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 90271 | 90353 | sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); |
| 90272 | 90354 | pDest->flags &= ~MEM_Ephem; |
| 90273 | 90355 | } |
| @@ -90476,11 +90558,10 @@ | ||
| 90476 | 90558 | u32 serial_type; /* Type field */ |
| 90477 | 90559 | Mem *pData0; /* First field to be combined into the record */ |
| 90478 | 90560 | Mem *pLast; /* Last field of the record */ |
| 90479 | 90561 | int nField; /* Number of fields in the record */ |
| 90480 | 90562 | char *zAffinity; /* The affinity string for the record */ |
| 90481 | - int file_format; /* File format to use for encoding */ | |
| 90482 | 90563 | u32 len; /* Length of a field */ |
| 90483 | 90564 | u8 *zHdr; /* Where to write next byte of the header */ |
| 90484 | 90565 | u8 *zPayload; /* Where to write next byte of the payload */ |
| 90485 | 90566 | |
| 90486 | 90567 | /* Assuming the record contains N fields, the record format looks |
| @@ -90505,11 +90586,10 @@ | ||
| 90505 | 90586 | zAffinity = pOp->p4.z; |
| 90506 | 90587 | assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem+1 - p->nCursor)+1 ); |
| 90507 | 90588 | pData0 = &aMem[nField]; |
| 90508 | 90589 | nField = pOp->p2; |
| 90509 | 90590 | pLast = &pData0[nField-1]; |
| 90510 | - file_format = p->minWriteFileFormat; | |
| 90511 | 90591 | |
| 90512 | 90592 | /* Identify the output register */ |
| 90513 | 90593 | assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); |
| 90514 | 90594 | pOut = &aMem[pOp->p3]; |
| 90515 | 90595 | memAboutToChange(p, pOut); |
| @@ -90607,11 +90687,11 @@ | ||
| 90607 | 90687 | testcase( uu==32767 ); testcase( uu==32768 ); |
| 90608 | 90688 | testcase( uu==8388607 ); testcase( uu==8388608 ); |
| 90609 | 90689 | testcase( uu==2147483647 ); testcase( uu==2147483648LL ); |
| 90610 | 90690 | testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL ); |
| 90611 | 90691 | if( uu<=127 ){ |
| 90612 | - if( (i&1)==i && file_format>=4 ){ | |
| 90692 | + if( (i&1)==i && p->minWriteFileFormat>=4 ){ | |
| 90613 | 90693 | pRec->uTemp = 8+(u32)uu; |
| 90614 | 90694 | }else{ |
| 90615 | 90695 | nData++; |
| 90616 | 90696 | pRec->uTemp = 1; |
| 90617 | 90697 | } |
| @@ -93070,10 +93150,14 @@ | ||
| 93070 | 93150 | /* Opcode: NullRow P1 * * * * |
| 93071 | 93151 | ** |
| 93072 | 93152 | ** Move the cursor P1 to a null row. Any OP_Column operations |
| 93073 | 93153 | ** that occur while the cursor is on the null row will always |
| 93074 | 93154 | ** write a NULL. |
| 93155 | +** | |
| 93156 | +** Or, if P1 is a Pseudo-Cursor (a cursor opened using OP_OpenPseudo) | |
| 93157 | +** just reset the cache for that cursor. This causes the row of | |
| 93158 | +** content held by the pseudo-cursor to be reparsed. | |
| 93075 | 93159 | */ |
| 93076 | 93160 | case OP_NullRow: { |
| 93077 | 93161 | VdbeCursor *pC; |
| 93078 | 93162 | |
| 93079 | 93163 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| @@ -93249,11 +93333,11 @@ | ||
| 93249 | 93333 | VdbeBranchTaken(res!=0,2); |
| 93250 | 93334 | if( res ) goto jump_to_p2; |
| 93251 | 93335 | break; |
| 93252 | 93336 | } |
| 93253 | 93337 | |
| 93254 | -/* Opcode: Next P1 P2 P3 P4 P5 | |
| 93338 | +/* Opcode: Next P1 P2 P3 * P5 | |
| 93255 | 93339 | ** |
| 93256 | 93340 | ** Advance cursor P1 so that it points to the next key/data pair in its |
| 93257 | 93341 | ** table or index. If there are no more key/value pairs then fall through |
| 93258 | 93342 | ** to the following instruction. But if the cursor advance was successful, |
| 93259 | 93343 | ** jump immediately to P2. |
| @@ -93268,19 +93352,16 @@ | ||
| 93268 | 93352 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 93269 | 93353 | ** means P1 is an SQL index and that this instruction could have been |
| 93270 | 93354 | ** omitted if that index had been unique. P3 is usually 0. P3 is |
| 93271 | 93355 | ** always either 0 or 1. |
| 93272 | 93356 | ** |
| 93273 | -** P4 is always of type P4_ADVANCE. The function pointer points to | |
| 93274 | -** sqlite3BtreeNext(). | |
| 93275 | -** | |
| 93276 | 93357 | ** If P5 is positive and the jump is taken, then event counter |
| 93277 | 93358 | ** number P5-1 in the prepared statement is incremented. |
| 93278 | 93359 | ** |
| 93279 | 93360 | ** See also: Prev |
| 93280 | 93361 | */ |
| 93281 | -/* Opcode: Prev P1 P2 P3 P4 P5 | |
| 93362 | +/* Opcode: Prev P1 P2 P3 * P5 | |
| 93282 | 93363 | ** |
| 93283 | 93364 | ** Back up cursor P1 so that it points to the previous key/data pair in its |
| 93284 | 93365 | ** table or index. If there is no previous key/value pairs then fall through |
| 93285 | 93366 | ** to the following instruction. But if the cursor backup was successful, |
| 93286 | 93367 | ** jump immediately to P2. |
| @@ -93296,13 +93377,10 @@ | ||
| 93296 | 93377 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 93297 | 93378 | ** means P1 is an SQL index and that this instruction could have been |
| 93298 | 93379 | ** omitted if that index had been unique. P3 is usually 0. P3 is |
| 93299 | 93380 | ** always either 0 or 1. |
| 93300 | 93381 | ** |
| 93301 | -** P4 is always of type P4_ADVANCE. The function pointer points to | |
| 93302 | -** sqlite3BtreePrevious(). | |
| 93303 | -** | |
| 93304 | 93382 | ** If P5 is positive and the jump is taken, then event counter |
| 93305 | 93383 | ** number P5-1 in the prepared statement is incremented. |
| 93306 | 93384 | */ |
| 93307 | 93385 | /* Opcode: SorterNext P1 P2 * * P5 |
| 93308 | 93386 | ** |
| @@ -93316,34 +93394,37 @@ | ||
| 93316 | 93394 | |
| 93317 | 93395 | pC = p->apCsr[pOp->p1]; |
| 93318 | 93396 | assert( isSorter(pC) ); |
| 93319 | 93397 | rc = sqlite3VdbeSorterNext(db, pC); |
| 93320 | 93398 | goto next_tail; |
| 93399 | + | |
| 93321 | 93400 | case OP_Prev: /* jump */ |
| 93401 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); | |
| 93402 | + assert( pOp->p5<ArraySize(p->aCounter) ); | |
| 93403 | + pC = p->apCsr[pOp->p1]; | |
| 93404 | + assert( pC!=0 ); | |
| 93405 | + assert( pC->deferredMoveto==0 ); | |
| 93406 | + assert( pC->eCurType==CURTYPE_BTREE ); | |
| 93407 | + assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE | |
| 93408 | + || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope | |
| 93409 | + || pC->seekOp==OP_NullRow); | |
| 93410 | + rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3); | |
| 93411 | + goto next_tail; | |
| 93412 | + | |
| 93322 | 93413 | case OP_Next: /* jump */ |
| 93323 | 93414 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 93324 | 93415 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 93325 | 93416 | pC = p->apCsr[pOp->p1]; |
| 93326 | 93417 | assert( pC!=0 ); |
| 93327 | 93418 | assert( pC->deferredMoveto==0 ); |
| 93328 | 93419 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 93329 | - assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); | |
| 93330 | - assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); | |
| 93331 | - | |
| 93332 | - /* The Next opcode is only used after SeekGT, SeekGE, Rewind, and Found. | |
| 93333 | - ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */ | |
| 93334 | - assert( pOp->opcode!=OP_Next | |
| 93335 | - || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE | |
| 93420 | + assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE | |
| 93336 | 93421 | || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found |
| 93337 | 93422 | || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid |
| 93338 | 93423 | || pC->seekOp==OP_IfNoHope); |
| 93339 | - assert( pOp->opcode!=OP_Prev | |
| 93340 | - || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE | |
| 93341 | - || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope | |
| 93342 | - || pC->seekOp==OP_NullRow); | |
| 93424 | + rc = sqlite3BtreeNext(pC->uc.pCursor, pOp->p3); | |
| 93343 | 93425 | |
| 93344 | - rc = pOp->p4.xAdvance(pC->uc.pCursor, pOp->p3); | |
| 93345 | 93426 | next_tail: |
| 93346 | 93427 | pC->cacheStatus = CACHE_STALE; |
| 93347 | 93428 | VdbeBranchTaken(rc==SQLITE_OK,2); |
| 93348 | 93429 | if( rc==SQLITE_OK ){ |
| 93349 | 93430 | pC->nullRow = 0; |
| @@ -93557,10 +93638,11 @@ | ||
| 93557 | 93638 | assert( pTabCur->uc.pCursor!=0 ); |
| 93558 | 93639 | assert( pTabCur->isTable ); |
| 93559 | 93640 | pTabCur->nullRow = 0; |
| 93560 | 93641 | pTabCur->movetoTarget = rowid; |
| 93561 | 93642 | pTabCur->deferredMoveto = 1; |
| 93643 | + pTabCur->cacheStatus = CACHE_STALE; | |
| 93562 | 93644 | assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); |
| 93563 | 93645 | assert( !pTabCur->isEphemeral ); |
| 93564 | 93646 | pTabCur->ub.aAltMap = pOp->p4.ai; |
| 93565 | 93647 | assert( !pC->isEphemeral ); |
| 93566 | 93648 | pTabCur->pAltCursor = pC; |
| @@ -112069,11 +112151,11 @@ | ||
| 112069 | 112151 | if( pStat1==0 ) return; |
| 112070 | 112152 | pStat1->zName = (char*)&pStat1[1]; |
| 112071 | 112153 | memcpy(pStat1->zName, "sqlite_stat1", 13); |
| 112072 | 112154 | pStat1->nCol = 3; |
| 112073 | 112155 | pStat1->iPKey = -1; |
| 112074 | - sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB); | |
| 112156 | + sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC); | |
| 112075 | 112157 | } |
| 112076 | 112158 | #endif |
| 112077 | 112159 | |
| 112078 | 112160 | /* Establish a read-lock on the table at the shared-cache level. |
| 112079 | 112161 | ** Open a read-only cursor on the table. Also allocate a cursor number |
| @@ -125675,11 +125757,15 @@ | ||
| 125675 | 125757 | ** Then special optimizations can be applied that make the transfer |
| 125676 | 125758 | ** very fast and which reduce fragmentation of indices. |
| 125677 | 125759 | ** |
| 125678 | 125760 | ** This is the 2nd template. |
| 125679 | 125761 | */ |
| 125680 | - if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){ | |
| 125762 | + if( pColumn==0 | |
| 125763 | + && pSelect!=0 | |
| 125764 | + && pTrigger==0 | |
| 125765 | + && xferOptimization(pParse, pTab, pSelect, onError, iDb) | |
| 125766 | + ){ | |
| 125681 | 125767 | assert( !pTrigger ); |
| 125682 | 125768 | assert( pList==0 ); |
| 125683 | 125769 | goto insert_end; |
| 125684 | 125770 | } |
| 125685 | 125771 | #endif /* SQLITE_OMIT_XFER_OPT */ |
| @@ -127646,22 +127732,17 @@ | ||
| 127646 | 127732 | Vdbe *v; /* The VDBE we are building */ |
| 127647 | 127733 | int regAutoinc; /* Memory register used by AUTOINC */ |
| 127648 | 127734 | int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */ |
| 127649 | 127735 | int regData, regRowid; /* Registers holding data and rowid */ |
| 127650 | 127736 | |
| 127651 | - if( pSelect==0 ){ | |
| 127652 | - return 0; /* Must be of the form INSERT INTO ... SELECT ... */ | |
| 127653 | - } | |
| 127737 | + assert( pSelect!=0 ); | |
| 127654 | 127738 | if( pParse->pWith || pSelect->pWith ){ |
| 127655 | 127739 | /* Do not attempt to process this query if there are an WITH clauses |
| 127656 | 127740 | ** attached to it. Proceeding may generate a false "no such table: xxx" |
| 127657 | 127741 | ** error if pSelect reads from a CTE named "xxx". */ |
| 127658 | 127742 | return 0; |
| 127659 | 127743 | } |
| 127660 | - if( sqlite3TriggerList(pParse, pDest) ){ | |
| 127661 | - return 0; /* tab1 must not have triggers */ | |
| 127662 | - } | |
| 127663 | 127744 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 127664 | 127745 | if( IsVirtual(pDest) ){ |
| 127665 | 127746 | return 0; /* tab1 must not be a virtual table */ |
| 127666 | 127747 | } |
| 127667 | 127748 | #endif |
| @@ -130011,11 +130092,11 @@ | ||
| 130011 | 130092 | /* iArg: */ BTREE_DATA_VERSION }, |
| 130012 | 130093 | #endif |
| 130013 | 130094 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 130014 | 130095 | {/* zName: */ "database_list", |
| 130015 | 130096 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 130016 | - /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, | |
| 130097 | + /* ePragFlg: */ PragFlg_Result0, | |
| 130017 | 130098 | /* ColNames: */ 47, 3, |
| 130018 | 130099 | /* iArg: */ 0 }, |
| 130019 | 130100 | #endif |
| 130020 | 130101 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 130021 | 130102 | {/* zName: */ "default_cache_size", |
| @@ -130699,19 +130780,20 @@ | ||
| 130699 | 130780 | Vdbe *v, /* The prepared statement being created */ |
| 130700 | 130781 | FuncDef *p, /* A particular function definition */ |
| 130701 | 130782 | int isBuiltin, /* True if this is a built-in function */ |
| 130702 | 130783 | int showInternFuncs /* True if showing internal functions */ |
| 130703 | 130784 | ){ |
| 130785 | + u32 mask = | |
| 130786 | + SQLITE_DETERMINISTIC | | |
| 130787 | + SQLITE_DIRECTONLY | | |
| 130788 | + SQLITE_SUBTYPE | | |
| 130789 | + SQLITE_INNOCUOUS | | |
| 130790 | + SQLITE_FUNC_INTERNAL | |
| 130791 | + ; | |
| 130792 | + if( showInternFuncs ) mask = 0xffffffff; | |
| 130704 | 130793 | for(; p; p=p->pNext){ |
| 130705 | 130794 | const char *zType; |
| 130706 | - static const u32 mask = | |
| 130707 | - SQLITE_DETERMINISTIC | | |
| 130708 | - SQLITE_DIRECTONLY | | |
| 130709 | - SQLITE_SUBTYPE | | |
| 130710 | - SQLITE_INNOCUOUS | | |
| 130711 | - SQLITE_FUNC_INTERNAL | |
| 130712 | - ; | |
| 130713 | 130795 | static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; |
| 130714 | 130796 | |
| 130715 | 130797 | assert( SQLITE_FUNC_ENCMASK==0x3 ); |
| 130716 | 130798 | assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 ); |
| 130717 | 130799 | assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 ); |
| @@ -148508,18 +148590,26 @@ | ||
| 148508 | 148590 | ** rowid stored in register iRowid. |
| 148509 | 148591 | ** |
| 148510 | 148592 | ** Normally, this is just: |
| 148511 | 148593 | ** |
| 148512 | 148594 | ** OP_DeferredSeek $iCur $iRowid |
| 148595 | +** | |
| 148596 | +** Which causes a seek on $iCur to the row with rowid $iRowid. | |
| 148513 | 148597 | ** |
| 148514 | 148598 | ** However, if the scan currently being coded is a branch of an OR-loop and |
| 148515 | -** the statement currently being coded is a SELECT, then P3 of OP_DeferredSeek | |
| 148516 | -** is set to iIdxCur and P4 is set to point to an array of integers | |
| 148517 | -** containing one entry for each column of the table cursor iCur is open | |
| 148518 | -** on. For each table column, if the column is the i'th column of the | |
| 148519 | -** index, then the corresponding array entry is set to (i+1). If the column | |
| 148520 | -** does not appear in the index at all, the array entry is set to 0. | |
| 148599 | +** the statement currently being coded is a SELECT, then additional information | |
| 148600 | +** is added that might allow OP_Column to omit the seek and instead do its | |
| 148601 | +** lookup on the index, thus avoiding an expensive seek operation. To | |
| 148602 | +** enable this optimization, the P3 of OP_DeferredSeek is set to iIdxCur | |
| 148603 | +** and P4 is set to an array of integers containing one entry for each column | |
| 148604 | +** in the table. For each table column, if the column is the i'th | |
| 148605 | +** column of the index, then the corresponding array entry is set to (i+1). | |
| 148606 | +** If the column does not appear in the index at all, the array entry is set | |
| 148607 | +** to 0. The OP_Column opcode can check this array to see if the column it | |
| 148608 | +** wants is in the index and if it is, it will substitute the index cursor | |
| 148609 | +** and column number and continue with those new values, rather than seeking | |
| 148610 | +** the table cursor. | |
| 148521 | 148611 | */ |
| 148522 | 148612 | static void codeDeferredSeek( |
| 148523 | 148613 | WhereInfo *pWInfo, /* Where clause context */ |
| 148524 | 148614 | Index *pIdx, /* Index scan is using */ |
| 148525 | 148615 | int iCur, /* Cursor for IPK b-tree */ |
| @@ -234298,11 +234388,11 @@ | ||
| 234298 | 234388 | int nArg, /* Number of args */ |
| 234299 | 234389 | sqlite3_value **apUnused /* Function arguments */ |
| 234300 | 234390 | ){ |
| 234301 | 234391 | assert( nArg==0 ); |
| 234302 | 234392 | UNUSED_PARAM2(nArg, apUnused); |
| 234303 | - sqlite3_result_text(pCtx, "fts5: 2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab", -1, SQLITE_TRANSIENT); | |
| 234393 | + sqlite3_result_text(pCtx, "fts5: 2022-03-02 01:02:16 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b", -1, SQLITE_TRANSIENT); | |
| 234304 | 234394 | } |
| 234305 | 234395 | |
| 234306 | 234396 | /* |
| 234307 | 234397 | ** Return true if zName is the extension on one of the shadow tables used |
| 234308 | 234398 | ** by this module. |
| 234309 | 234399 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.38.0. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -450,13 +450,13 @@ | |
| 450 | ** |
| 451 | ** See also: [sqlite3_libversion()], |
| 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | */ |
| 455 | #define SQLITE_VERSION "3.38.0" |
| 456 | #define SQLITE_VERSION_NUMBER 3038000 |
| 457 | #define SQLITE_SOURCE_ID "2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab" |
| 458 | |
| 459 | /* |
| 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | ** |
| @@ -10071,11 +10071,11 @@ | |
| 10071 | ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value |
| 10072 | ** and remains valid for the duration of the xBestIndex method call. |
| 10073 | ** ^When xBestIndex returns, the sqlite3_value object returned by |
| 10074 | ** sqlite3_vtab_rhs_value() is automatically deallocated. |
| 10075 | ** |
| 10076 | ** The "_rhs_" in the name of this routine is an appreviation for |
| 10077 | ** "Right-Hand Side". |
| 10078 | */ |
| 10079 | SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); |
| 10080 | |
| 10081 | /* |
| @@ -14709,18 +14709,19 @@ | |
| 14709 | ** Handle type for pages. |
| 14710 | */ |
| 14711 | typedef struct PgHdr DbPage; |
| 14712 | |
| 14713 | /* |
| 14714 | ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is |
| 14715 | ** reserved for working around a windows/posix incompatibility). It is |
| 14716 | ** used in the journal to signify that the remainder of the journal file |
| 14717 | ** is devoted to storing a super-journal name - there are no more pages to |
| 14718 | ** roll back. See comments for function writeSuperJournal() in pager.c |
| 14719 | ** for details. |
| 14720 | */ |
| 14721 | #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) |
| 14722 | |
| 14723 | /* |
| 14724 | ** Allowed values for the flags parameter to sqlite3PagerOpen(). |
| 14725 | ** |
| 14726 | ** NOTE: These values must match the corresponding BTREE_ values in btree.h. |
| @@ -15393,11 +15394,10 @@ | |
| 15393 | SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ |
| 15394 | Table *pTab; /* Used when p4type is P4_TABLE */ |
| 15395 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 15396 | Expr *pExpr; /* Used when p4type is P4_EXPR */ |
| 15397 | #endif |
| 15398 | int (*xAdvance)(BtCursor *, int); |
| 15399 | } p4; |
| 15400 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 15401 | char *zComment; /* Comment to improve readability */ |
| 15402 | #endif |
| 15403 | #ifdef VDBE_PROFILE |
| @@ -15444,25 +15444,23 @@ | |
| 15444 | #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 15445 | #define P4_STATIC (-1) /* Pointer to a static string */ |
| 15446 | #define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */ |
| 15447 | #define P4_INT32 (-3) /* P4 is a 32-bit signed integer */ |
| 15448 | #define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */ |
| 15449 | #define P4_ADVANCE (-5) /* P4 is a pointer to BtreeNext() or BtreePrev() */ |
| 15450 | #define P4_TABLE (-6) /* P4 is a pointer to a Table structure */ |
| 15451 | /* Above do not own any resources. Must free those below */ |
| 15452 | #define P4_FREE_IF_LE (-7) |
| 15453 | #define P4_DYNAMIC (-7) /* Pointer to memory from sqliteMalloc() */ |
| 15454 | #define P4_FUNCDEF (-8) /* P4 is a pointer to a FuncDef structure */ |
| 15455 | #define P4_KEYINFO (-9) /* P4 is a pointer to a KeyInfo structure */ |
| 15456 | #define P4_EXPR (-10) /* P4 is a pointer to an Expr tree */ |
| 15457 | #define P4_MEM (-11) /* P4 is a pointer to a Mem* structure */ |
| 15458 | #define P4_VTAB (-12) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 15459 | #define P4_REAL (-13) /* P4 is a 64-bit floating point value */ |
| 15460 | #define P4_INT64 (-14) /* P4 is a 64-bit signed integer */ |
| 15461 | #define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ |
| 15462 | #define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */ |
| 15463 | #define P4_DYNBLOB (-17) /* Pointer to memory from sqliteMalloc() */ |
| 15464 | |
| 15465 | /* Error message codes for OP_Halt */ |
| 15466 | #define P5_ConstraintNotNull 1 |
| 15467 | #define P5_ConstraintUnique 2 |
| 15468 | #define P5_ConstraintCheck 3 |
| @@ -15503,46 +15501,46 @@ | |
| 15503 | /* Automatically generated. Do not edit */ |
| 15504 | /* See the tool/mkopcodeh.tcl script for details */ |
| 15505 | #define OP_Savepoint 0 |
| 15506 | #define OP_AutoCommit 1 |
| 15507 | #define OP_Transaction 2 |
| 15508 | #define OP_SorterNext 3 /* jump */ |
| 15509 | #define OP_Prev 4 /* jump */ |
| 15510 | #define OP_Next 5 /* jump */ |
| 15511 | #define OP_Checkpoint 6 |
| 15512 | #define OP_JournalMode 7 |
| 15513 | #define OP_Vacuum 8 |
| 15514 | #define OP_VFilter 9 /* jump, synopsis: iplan=r[P3] zplan='P4' */ |
| 15515 | #define OP_VUpdate 10 /* synopsis: data=r[P3@P2] */ |
| 15516 | #define OP_Goto 11 /* jump */ |
| 15517 | #define OP_Gosub 12 /* jump */ |
| 15518 | #define OP_InitCoroutine 13 /* jump */ |
| 15519 | #define OP_Yield 14 /* jump */ |
| 15520 | #define OP_MustBeInt 15 /* jump */ |
| 15521 | #define OP_Jump 16 /* jump */ |
| 15522 | #define OP_Once 17 /* jump */ |
| 15523 | #define OP_If 18 /* jump */ |
| 15524 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 15525 | #define OP_IfNot 20 /* jump */ |
| 15526 | #define OP_IsNullOrType 21 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */ |
| 15527 | #define OP_IfNullRow 22 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ |
| 15528 | #define OP_SeekLT 23 /* jump, synopsis: key=r[P3@P4] */ |
| 15529 | #define OP_SeekLE 24 /* jump, synopsis: key=r[P3@P4] */ |
| 15530 | #define OP_SeekGE 25 /* jump, synopsis: key=r[P3@P4] */ |
| 15531 | #define OP_SeekGT 26 /* jump, synopsis: key=r[P3@P4] */ |
| 15532 | #define OP_IfNotOpen 27 /* jump, synopsis: if( !csr[P1] ) goto P2 */ |
| 15533 | #define OP_IfNoHope 28 /* jump, synopsis: key=r[P3@P4] */ |
| 15534 | #define OP_NoConflict 29 /* jump, synopsis: key=r[P3@P4] */ |
| 15535 | #define OP_NotFound 30 /* jump, synopsis: key=r[P3@P4] */ |
| 15536 | #define OP_Found 31 /* jump, synopsis: key=r[P3@P4] */ |
| 15537 | #define OP_SeekRowid 32 /* jump, synopsis: intkey=r[P3] */ |
| 15538 | #define OP_NotExists 33 /* jump, synopsis: intkey=r[P3] */ |
| 15539 | #define OP_Last 34 /* jump */ |
| 15540 | #define OP_IfSmaller 35 /* jump */ |
| 15541 | #define OP_SorterSort 36 /* jump */ |
| 15542 | #define OP_Sort 37 /* jump */ |
| 15543 | #define OP_Rewind 38 /* jump */ |
| 15544 | #define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */ |
| 15545 | #define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */ |
| 15546 | #define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */ |
| 15547 | #define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */ |
| 15548 | #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| @@ -15697,15 +15695,15 @@ | |
| 15697 | #define OPFLG_IN2 0x04 /* in2: P2 is an input */ |
| 15698 | #define OPFLG_IN3 0x08 /* in3: P3 is an input */ |
| 15699 | #define OPFLG_OUT2 0x10 /* out2: P2 is an output */ |
| 15700 | #define OPFLG_OUT3 0x20 /* out3: P3 is an output */ |
| 15701 | #define OPFLG_INITIALIZER {\ |
| 15702 | /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x00, 0x10,\ |
| 15703 | /* 8 */ 0x00, 0x01, 0x00, 0x01, 0x01, 0x01, 0x03, 0x03,\ |
| 15704 | /* 16 */ 0x01, 0x01, 0x03, 0x12, 0x03, 0x03, 0x01, 0x09,\ |
| 15705 | /* 24 */ 0x09, 0x09, 0x09, 0x01, 0x09, 0x09, 0x09, 0x09,\ |
| 15706 | /* 32 */ 0x09, 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 15707 | /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\ |
| 15708 | /* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 15709 | /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\ |
| 15710 | /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\ |
| 15711 | /* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| @@ -17778,10 +17776,15 @@ | |
| 17778 | ** b-tree. |
| 17779 | */ |
| 17780 | struct UnpackedRecord { |
| 17781 | KeyInfo *pKeyInfo; /* Collation and sort-order information */ |
| 17782 | Mem *aMem; /* Values */ |
| 17783 | u16 nField; /* Number of entries in apMem[] */ |
| 17784 | i8 default_rc; /* Comparison result if keys are equal */ |
| 17785 | u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ |
| 17786 | i8 r1; /* Value to return if (lhs < rhs) */ |
| 17787 | i8 r2; /* Value to return if (lhs > rhs) */ |
| @@ -22225,20 +22228,20 @@ | |
| 22225 | i64 i; /* Integer value used when MEM_Int is set in flags */ |
| 22226 | int nZero; /* Extra zero bytes when MEM_Zero and MEM_Blob set */ |
| 22227 | const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */ |
| 22228 | FuncDef *pDef; /* Used only when flags==MEM_Agg */ |
| 22229 | } u; |
| 22230 | u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ |
| 22231 | u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ |
| 22232 | u8 eSubtype; /* Subtype for this value */ |
| 22233 | int n; /* Number of characters in string value, excluding '\0' */ |
| 22234 | char *z; /* String or BLOB value */ |
| 22235 | /* ShallowCopy only needs to copy the information above */ |
| 22236 | char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ |
| 22237 | int szMalloc; /* Size of the zMalloc allocation */ |
| 22238 | u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */ |
| 22239 | sqlite3 *db; /* The associated database connection */ |
| 22240 | void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */ |
| 22241 | #ifdef SQLITE_DEBUG |
| 22242 | Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ |
| 22243 | u16 mScopyFlags; /* flags value immediately after the shallow copy */ |
| 22244 | #endif |
| @@ -22246,15 +22249,47 @@ | |
| 22246 | |
| 22247 | /* |
| 22248 | ** Size of struct Mem not including the Mem.zMalloc member or anything that |
| 22249 | ** follows. |
| 22250 | */ |
| 22251 | #define MEMCELLSIZE offsetof(Mem,zMalloc) |
| 22252 | |
| 22253 | /* One or more of the following flags are set to indicate the validOK |
| 22254 | ** representations of the value stored in the Mem struct. |
| 22255 | ** |
| 22256 | ** If the MEM_Null flag is set, then the value is an SQL NULL value. |
| 22257 | ** For a pointer type created using sqlite3_bind_pointer() or |
| 22258 | ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set. |
| 22259 | ** |
| 22260 | ** If the MEM_Str flag is set then Mem.z points at a string representation. |
| @@ -22261,39 +22296,36 @@ | |
| 22261 | ** Usually this is encoded in the same unicode encoding as the main |
| 22262 | ** database (see below for exceptions). If the MEM_Term flag is also |
| 22263 | ** set, then the string is nul terminated. The MEM_Int and MEM_Real |
| 22264 | ** flags may coexist with the MEM_Str flag. |
| 22265 | */ |
| 22266 | #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */ |
| 22267 | #define MEM_Str 0x0002 /* Value is a string */ |
| 22268 | #define MEM_Int 0x0004 /* Value is an integer */ |
| 22269 | #define MEM_Real 0x0008 /* Value is a real number */ |
| 22270 | #define MEM_Blob 0x0010 /* Value is a BLOB */ |
| 22271 | #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */ |
| 22272 | #define MEM_AffMask 0x003f /* Mask of affinity bits */ |
| 22273 | #define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */ |
| 22274 | #define MEM_Undefined 0x0080 /* Value is undefined */ |
| 22275 | #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ |
| 22276 | #define MEM_TypeMask 0xc1bf /* Mask of type bits */ |
| 22277 | |
| 22278 | |
| 22279 | /* Whenever Mem contains a valid string or blob representation, one of |
| 22280 | ** the following flags must be set to determine the memory management |
| 22281 | ** policy for Mem.z. The MEM_Term flag tells us whether or not the |
| 22282 | ** string is \000 or \u0000 terminated |
| 22283 | */ |
| 22284 | #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */ |
| 22285 | #define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */ |
| 22286 | #define MEM_Static 0x0800 /* Mem.z points to a static string */ |
| 22287 | #define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */ |
| 22288 | #define MEM_Agg 0x2000 /* Mem.z points to an agg function context */ |
| 22289 | #define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */ |
| 22290 | #define MEM_Subtype 0x8000 /* Mem.eSubtype is valid */ |
| 22291 | #ifdef SQLITE_OMIT_INCRBLOB |
| 22292 | #undef MEM_Zero |
| 22293 | #define MEM_Zero 0x0000 |
| 22294 | #endif |
| 22295 | |
| 22296 | /* Return TRUE if Mem X contains dynamically allocated content - anything |
| 22297 | ** that needs to be deallocated to avoid a leak. |
| 22298 | */ |
| 22299 | #define VdbeMemDynamic(X) \ |
| @@ -22311,15 +22343,19 @@ | |
| 22311 | #define MemNullNochng(X) \ |
| 22312 | (((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \ |
| 22313 | && (X)->n==0 && (X)->u.nZero==0) |
| 22314 | |
| 22315 | /* |
| 22316 | ** Return true if a memory cell is not marked as invalid. This macro |
| 22317 | ** is for use inside assert() statements only. |
| 22318 | */ |
| 22319 | #ifdef SQLITE_DEBUG |
| 22320 | #define memIsValid(M) ((M)->flags & MEM_Undefined)==0 |
| 22321 | #endif |
| 22322 | |
| 22323 | /* |
| 22324 | ** Each auxiliary data pointer stored by a user defined function |
| 22325 | ** implementation calling sqlite3_set_auxdata() is stored in an instance |
| @@ -22523,12 +22559,12 @@ | |
| 22523 | ** Function prototypes |
| 22524 | */ |
| 22525 | SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); |
| 22526 | SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); |
| 22527 | void sqliteVdbePopStack(Vdbe*,int); |
| 22528 | SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*); |
| 22529 | SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor**, u32*); |
| 22530 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); |
| 22531 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 22532 | SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); |
| 22533 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 22534 | SQLITE_PRIVATE void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| @@ -34579,46 +34615,46 @@ | |
| 34579 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){ |
| 34580 | static const char *const azName[] = { |
| 34581 | /* 0 */ "Savepoint" OpHelp(""), |
| 34582 | /* 1 */ "AutoCommit" OpHelp(""), |
| 34583 | /* 2 */ "Transaction" OpHelp(""), |
| 34584 | /* 3 */ "SorterNext" OpHelp(""), |
| 34585 | /* 4 */ "Prev" OpHelp(""), |
| 34586 | /* 5 */ "Next" OpHelp(""), |
| 34587 | /* 6 */ "Checkpoint" OpHelp(""), |
| 34588 | /* 7 */ "JournalMode" OpHelp(""), |
| 34589 | /* 8 */ "Vacuum" OpHelp(""), |
| 34590 | /* 9 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), |
| 34591 | /* 10 */ "VUpdate" OpHelp("data=r[P3@P2]"), |
| 34592 | /* 11 */ "Goto" OpHelp(""), |
| 34593 | /* 12 */ "Gosub" OpHelp(""), |
| 34594 | /* 13 */ "InitCoroutine" OpHelp(""), |
| 34595 | /* 14 */ "Yield" OpHelp(""), |
| 34596 | /* 15 */ "MustBeInt" OpHelp(""), |
| 34597 | /* 16 */ "Jump" OpHelp(""), |
| 34598 | /* 17 */ "Once" OpHelp(""), |
| 34599 | /* 18 */ "If" OpHelp(""), |
| 34600 | /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), |
| 34601 | /* 20 */ "IfNot" OpHelp(""), |
| 34602 | /* 21 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"), |
| 34603 | /* 22 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), |
| 34604 | /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"), |
| 34605 | /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"), |
| 34606 | /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"), |
| 34607 | /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"), |
| 34608 | /* 27 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"), |
| 34609 | /* 28 */ "IfNoHope" OpHelp("key=r[P3@P4]"), |
| 34610 | /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 34611 | /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 34612 | /* 31 */ "Found" OpHelp("key=r[P3@P4]"), |
| 34613 | /* 32 */ "SeekRowid" OpHelp("intkey=r[P3]"), |
| 34614 | /* 33 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 34615 | /* 34 */ "Last" OpHelp(""), |
| 34616 | /* 35 */ "IfSmaller" OpHelp(""), |
| 34617 | /* 36 */ "SorterSort" OpHelp(""), |
| 34618 | /* 37 */ "Sort" OpHelp(""), |
| 34619 | /* 38 */ "Rewind" OpHelp(""), |
| 34620 | /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 34621 | /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 34622 | /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 34623 | /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 34624 | /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| @@ -50905,11 +50941,12 @@ | |
| 50905 | /* |
| 50906 | ** Make sure the page is marked as dirty. If it isn't dirty already, |
| 50907 | ** make it so. |
| 50908 | */ |
| 50909 | SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){ |
| 50910 | assert( p->nRef>0 ); |
| 50911 | assert( sqlite3PcachePageSanity(p) ); |
| 50912 | if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/ |
| 50913 | p->flags &= ~PGHDR_DONT_WRITE; |
| 50914 | if( p->flags & PGHDR_CLEAN ){ |
| 50915 | p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN); |
| @@ -53874,10 +53911,11 @@ | |
| 53874 | u16 nExtra; /* Add this many bytes to each in-memory page */ |
| 53875 | i16 nReserve; /* Number of unused bytes at end of each page */ |
| 53876 | u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ |
| 53877 | u32 sectorSize; /* Assumed sector size during rollback */ |
| 53878 | Pgno mxPgno; /* Maximum allowed size of the database */ |
| 53879 | i64 pageSize; /* Number of bytes in a page */ |
| 53880 | i64 journalSizeLimit; /* Size limit for persistent journal files */ |
| 53881 | char *zFilename; /* Name of the database file */ |
| 53882 | char *zJournal; /* Name of the journal file */ |
| 53883 | int (*xBusyHandler)(void*); /* Function to call when busy */ |
| @@ -54860,11 +54898,11 @@ | |
| 54860 | ** pPager at the current location. The super-journal name must be the last |
| 54861 | ** thing written to a journal file. If the pager is in full-sync mode, the |
| 54862 | ** journal file descriptor is advanced to the next sector boundary before |
| 54863 | ** anything is written. The format is: |
| 54864 | ** |
| 54865 | ** + 4 bytes: PAGER_MJ_PGNO. |
| 54866 | ** + N bytes: super-journal filename in utf-8. |
| 54867 | ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). |
| 54868 | ** + 4 bytes: super-journal name checksum. |
| 54869 | ** + 8 bytes: aJournalMagic[]. |
| 54870 | ** |
| @@ -54908,11 +54946,11 @@ | |
| 54908 | iHdrOff = pPager->journalOff; |
| 54909 | |
| 54910 | /* Write the super-journal data to the end of the journal file. If |
| 54911 | ** an error occurs, return the error code to the caller. |
| 54912 | */ |
| 54913 | if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager)))) |
| 54914 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4))) |
| 54915 | || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper))) |
| 54916 | || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum))) |
| 54917 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8, |
| 54918 | iHdrOff+4+nSuper+8))) |
| @@ -55418,11 +55456,11 @@ | |
| 55418 | ** to the database file, then the IO error code is returned. If data |
| 55419 | ** is successfully read from the (sub-)journal file but appears to be |
| 55420 | ** corrupted, SQLITE_DONE is returned. Data is considered corrupted in |
| 55421 | ** two circumstances: |
| 55422 | ** |
| 55423 | ** * If the record page-number is illegal (0 or PAGER_MJ_PGNO), or |
| 55424 | ** * If the record is being rolled back from the main journal file |
| 55425 | ** and the checksum field does not match the record content. |
| 55426 | ** |
| 55427 | ** Neither of these two scenarios are possible during a savepoint rollback. |
| 55428 | ** |
| @@ -55478,11 +55516,11 @@ | |
| 55478 | /* Sanity checking on the page. This is more important that I originally |
| 55479 | ** thought. If a power failure occurs while the journal is being written, |
| 55480 | ** it could cause invalid data to be written into the journal. We need to |
| 55481 | ** detect this invalid data (with high probability) and ignore it. |
| 55482 | */ |
| 55483 | if( pgno==0 || pgno==PAGER_MJ_PGNO(pPager) ){ |
| 55484 | assert( !isSavepnt ); |
| 55485 | return SQLITE_DONE; |
| 55486 | } |
| 55487 | if( pgno>(Pgno)pPager->dbSize || sqlite3BitvecTest(pDone, pgno) ){ |
| 55488 | return SQLITE_OK; |
| @@ -56037,10 +56075,13 @@ | |
| 56037 | rc = pager_truncate(pPager, mxPg); |
| 56038 | if( rc!=SQLITE_OK ){ |
| 56039 | goto end_playback; |
| 56040 | } |
| 56041 | pPager->dbSize = mxPg; |
| 56042 | } |
| 56043 | |
| 56044 | /* Copy original pages out of the journal and back into the |
| 56045 | ** database file and/or page cache. |
| 56046 | */ |
| @@ -56933,10 +56974,11 @@ | |
| 56933 | if( rc==SQLITE_OK ){ |
| 56934 | sqlite3PageFree(pPager->pTmpSpace); |
| 56935 | pPager->pTmpSpace = pNew; |
| 56936 | pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); |
| 56937 | pPager->pageSize = pageSize; |
| 56938 | }else{ |
| 56939 | sqlite3PageFree(pNew); |
| 56940 | } |
| 56941 | } |
| 56942 | |
| @@ -58682,11 +58724,10 @@ | |
| 58682 | assert( pPager->errCode==SQLITE_OK ); |
| 58683 | assert( pPager->eState>=PAGER_READER ); |
| 58684 | assert( assert_pager_state(pPager) ); |
| 58685 | assert( pPager->hasHeldSharedLock==1 ); |
| 58686 | |
| 58687 | if( pgno==0 ) return SQLITE_CORRUPT_BKPT; |
| 58688 | pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3); |
| 58689 | if( pBase==0 ){ |
| 58690 | pPg = 0; |
| 58691 | rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase); |
| 58692 | if( rc!=SQLITE_OK ) goto pager_acquire_err; |
| @@ -58702,22 +58743,22 @@ | |
| 58702 | |
| 58703 | noContent = (flags & PAGER_GET_NOCONTENT)!=0; |
| 58704 | if( pPg->pPager && !noContent ){ |
| 58705 | /* In this case the pcache already contains an initialized copy of |
| 58706 | ** the page. Return without further ado. */ |
| 58707 | assert( pgno!=PAGER_MJ_PGNO(pPager) ); |
| 58708 | pPager->aStat[PAGER_STAT_HIT]++; |
| 58709 | return SQLITE_OK; |
| 58710 | |
| 58711 | }else{ |
| 58712 | /* The pager cache has created a new page. Its content needs to |
| 58713 | ** be initialized. But first some error checks: |
| 58714 | ** |
| 58715 | ** (*) obsolete. Was: maximum page number is 2^31 |
| 58716 | ** (2) Never try to fetch the locking page |
| 58717 | */ |
| 58718 | if( pgno==PAGER_MJ_PGNO(pPager) ){ |
| 58719 | rc = SQLITE_CORRUPT_BKPT; |
| 58720 | goto pager_acquire_err; |
| 58721 | } |
| 58722 | |
| 58723 | pPg->pPager = pPager; |
| @@ -59112,11 +59153,11 @@ | |
| 59112 | i64 iOff = pPager->journalOff; |
| 59113 | |
| 59114 | /* We should never write to the journal file the page that |
| 59115 | ** contains the database locks. The following assert verifies |
| 59116 | ** that we do not. */ |
| 59117 | assert( pPg->pgno!=PAGER_MJ_PGNO(pPager) ); |
| 59118 | |
| 59119 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 59120 | pData2 = pPg->pData; |
| 59121 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 59122 | |
| @@ -59291,11 +59332,11 @@ | |
| 59291 | |
| 59292 | for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){ |
| 59293 | Pgno pg = pg1+ii; |
| 59294 | PgHdr *pPage; |
| 59295 | if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){ |
| 59296 | if( pg!=PAGER_MJ_PGNO(pPager) ){ |
| 59297 | rc = sqlite3PagerGet(pPager, pg, &pPage, 0); |
| 59298 | if( rc==SQLITE_OK ){ |
| 59299 | rc = pager_write(pPage); |
| 59300 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 59301 | needSync = 1; |
| @@ -59769,11 +59810,11 @@ | |
| 59769 | ** image was extended as part of the current transaction and then the |
| 59770 | ** last page in the db image moved to the free-list. In this case the |
| 59771 | ** last page is never written out to disk, leaving the database file |
| 59772 | ** undersized. Fix this now if it is the case. */ |
| 59773 | if( pPager->dbSize>pPager->dbFileSize ){ |
| 59774 | Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_MJ_PGNO(pPager)); |
| 59775 | assert( pPager->eState==PAGER_WRITER_DBMOD ); |
| 59776 | rc = pager_truncate(pPager, nNew); |
| 59777 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 59778 | } |
| 59779 | |
| @@ -65396,11 +65437,13 @@ | |
| 65396 | u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th |
| 65397 | ** non-overflow cell */ |
| 65398 | u8 *apOvfl[4]; /* Pointers to the body of overflow cells */ |
| 65399 | BtShared *pBt; /* Pointer to BtShared that this page is part of */ |
| 65400 | u8 *aData; /* Pointer to disk image of the page data */ |
| 65401 | u8 *aDataEnd; /* One byte past the end of usable data */ |
| 65402 | u8 *aCellIdx; /* The cell index area */ |
| 65403 | u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ |
| 65404 | DbPage *pDbPage; /* Pager page handle */ |
| 65405 | u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */ |
| 65406 | void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */ |
| @@ -65701,11 +65744,11 @@ | |
| 65701 | #define CURSOR_FAULT 4 |
| 65702 | |
| 65703 | /* |
| 65704 | ** The database page the PENDING_BYTE occupies. This page is never used. |
| 65705 | */ |
| 65706 | # define PENDING_BYTE_PAGE(pBt) PAGER_MJ_PGNO(pBt) |
| 65707 | |
| 65708 | /* |
| 65709 | ** These macros define the location of the pointer-map entry for a |
| 65710 | ** database page. The first argument to each is the number of usable |
| 65711 | ** bytes on each page of the database (often 1024). The second is the |
| @@ -67455,10 +67498,11 @@ | |
| 67455 | ** data area of the btree-page. The return number includes the cell |
| 67456 | ** data header and the local payload, but not any overflow page or |
| 67457 | ** the space used by the cell pointer. |
| 67458 | ** |
| 67459 | ** cellSizePtrNoPayload() => table internal nodes |
| 67460 | ** cellSizePtr() => all index nodes & table leaf nodes |
| 67461 | */ |
| 67462 | static u16 cellSizePtr(MemPage *pPage, u8 *pCell){ |
| 67463 | u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */ |
| 67464 | u8 *pEnd; /* End mark for a varint */ |
| @@ -67480,17 +67524,10 @@ | |
| 67480 | do{ |
| 67481 | nSize = (nSize<<7) | (*++pIter & 0x7f); |
| 67482 | }while( *(pIter)>=0x80 && pIter<pEnd ); |
| 67483 | } |
| 67484 | pIter++; |
| 67485 | if( pPage->intKey ){ |
| 67486 | /* pIter now points at the 64-bit integer key value, a variable length |
| 67487 | ** integer. The following block moves pIter to point at the first byte |
| 67488 | ** past the end of the key value. */ |
| 67489 | pEnd = &pIter[9]; |
| 67490 | while( (*pIter++)&0x80 && pIter<pEnd ); |
| 67491 | } |
| 67492 | testcase( nSize==pPage->maxLocal ); |
| 67493 | testcase( nSize==(u32)pPage->maxLocal+1 ); |
| 67494 | if( nSize<=pPage->maxLocal ){ |
| 67495 | nSize += (u32)(pIter - pCell); |
| 67496 | if( nSize<4 ) nSize = 4; |
| @@ -67526,10 +67563,62 @@ | |
| 67526 | pEnd = pIter + 9; |
| 67527 | while( (*pIter++)&0x80 && pIter<pEnd ); |
| 67528 | assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB ); |
| 67529 | return (u16)(pIter - pCell); |
| 67530 | } |
| 67531 | |
| 67532 | |
| 67533 | #ifdef SQLITE_DEBUG |
| 67534 | /* This variation on cellSizePtr() is used inside of assert() statements |
| 67535 | ** only. */ |
| @@ -67539,11 +67628,11 @@ | |
| 67539 | #endif |
| 67540 | |
| 67541 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 67542 | /* |
| 67543 | ** The cell pCell is currently part of page pSrc but will ultimately be part |
| 67544 | ** of pPage. (pSrc and pPager are often the same.) If pCell contains a |
| 67545 | ** pointer to an overflow page, insert an entry into the pointer-map for |
| 67546 | ** the overflow page that will be valid after pCell has been moved to pPage. |
| 67547 | */ |
| 67548 | static void ptrmapPutOvflPtr(MemPage *pPage, MemPage *pSrc, u8 *pCell,int *pRC){ |
| 67549 | CellInfo info; |
| @@ -67714,21 +67803,23 @@ | |
| 67714 | */ |
| 67715 | static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ |
| 67716 | const int hdr = pPg->hdrOffset; /* Offset to page header */ |
| 67717 | u8 * const aData = pPg->aData; /* Page data */ |
| 67718 | int iAddr = hdr + 1; /* Address of ptr to pc */ |
| 67719 | int pc = get2byte(&aData[iAddr]); /* Address of a free slot */ |
| 67720 | int x; /* Excess size of the slot */ |
| 67721 | int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */ |
| 67722 | int size; /* Size of the free slot */ |
| 67723 | |
| 67724 | assert( pc>0 ); |
| 67725 | while( pc<=maxPC ){ |
| 67726 | /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each |
| 67727 | ** freeblock form a big-endian integer which is the size of the freeblock |
| 67728 | ** in bytes, including the 4-byte header. */ |
| 67729 | size = get2byte(&aData[pc+2]); |
| 67730 | if( (x = size - nByte)>=0 ){ |
| 67731 | testcase( x==4 ); |
| 67732 | testcase( x==3 ); |
| 67733 | if( x<4 ){ |
| 67734 | /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total |
| @@ -67749,11 +67840,12 @@ | |
| 67749 | put2byte(&aData[pc+2], x); |
| 67750 | } |
| 67751 | return &aData[pc + x]; |
| 67752 | } |
| 67753 | iAddr = pc; |
| 67754 | pc = get2byte(&aData[pc]); |
| 67755 | if( pc<=iAddr+size ){ |
| 67756 | if( pc ){ |
| 67757 | /* The next slot in the chain is not past the end of the current slot */ |
| 67758 | *pRc = SQLITE_CORRUPT_PAGE(pPg); |
| 67759 | } |
| @@ -67783,10 +67875,11 @@ | |
| 67783 | static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 67784 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 67785 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 67786 | int top; /* First byte of cell content area */ |
| 67787 | int rc = SQLITE_OK; /* Integer return code */ |
| 67788 | int gap; /* First byte of gap between cell pointers and cell content */ |
| 67789 | |
| 67790 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67791 | assert( pPage->pBt ); |
| 67792 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| @@ -67801,11 +67894,12 @@ | |
| 67801 | /* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size |
| 67802 | ** and the reserved space is zero (the usual value for reserved space) |
| 67803 | ** then the cell content offset of an empty page wants to be 65536. |
| 67804 | ** However, that integer is too large to be stored in a 2-byte unsigned |
| 67805 | ** integer, so a value of 0 is used in its place. */ |
| 67806 | top = get2byte(&data[hdr+5]); |
| 67807 | assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */ |
| 67808 | if( gap>top ){ |
| 67809 | if( top==0 && pPage->pBt->usableSize==65536 ){ |
| 67810 | top = 65536; |
| 67811 | }else{ |
| @@ -67883,10 +67977,11 @@ | |
| 67883 | u8 nFrag = 0; /* Reduction in fragmentation */ |
| 67884 | u16 iOrigSize = iSize; /* Original value of iSize */ |
| 67885 | u16 x; /* Offset to cell content area */ |
| 67886 | u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */ |
| 67887 | unsigned char *data = pPage->aData; /* Page content */ |
| 67888 | |
| 67889 | assert( pPage->pBt!=0 ); |
| 67890 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67891 | assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 67892 | assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); |
| @@ -67945,11 +68040,12 @@ | |
| 67945 | } |
| 67946 | } |
| 67947 | if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); |
| 67948 | data[hdr+7] -= nFrag; |
| 67949 | } |
| 67950 | x = get2byte(&data[hdr+5]); |
| 67951 | if( iStart<=x ){ |
| 67952 | /* The new freeblock is at the beginning of the cell content area, |
| 67953 | ** so just extend the cell content area rather than create another |
| 67954 | ** freelist entry */ |
| 67955 | if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| @@ -68001,10 +68097,11 @@ | |
| 68001 | ** leaf table b-tree page. */ |
| 68002 | assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 ); |
| 68003 | pPage->intKey = 1; |
| 68004 | if( pPage->leaf ){ |
| 68005 | pPage->intKeyLeaf = 1; |
| 68006 | pPage->xParseCell = btreeParseCellPtr; |
| 68007 | }else{ |
| 68008 | pPage->intKeyLeaf = 0; |
| 68009 | pPage->xCellSize = cellSizePtrNoPayload; |
| 68010 | pPage->xParseCell = btreeParseCellPtrNoPayload; |
| @@ -68181,11 +68278,11 @@ | |
| 68181 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 68182 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| 68183 | pPage->nOverflow = 0; |
| 68184 | pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize; |
| 68185 | pPage->aCellIdx = data + pPage->childPtrSize + 8; |
| 68186 | pPage->aDataEnd = pPage->aData + pBt->usableSize; |
| 68187 | pPage->aDataOfst = pPage->aData + pPage->childPtrSize; |
| 68188 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 68189 | ** number of cells on the page. */ |
| 68190 | pPage->nCell = get2byte(&data[3]); |
| 68191 | if( pPage->nCell>MX_CELL(pBt) ){ |
| @@ -68216,11 +68313,11 @@ | |
| 68216 | unsigned char *data = pPage->aData; |
| 68217 | BtShared *pBt = pPage->pBt; |
| 68218 | u8 hdr = pPage->hdrOffset; |
| 68219 | u16 first; |
| 68220 | |
| 68221 | assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno ); |
| 68222 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 68223 | assert( sqlite3PagerGetData(pPage->pDbPage) == data ); |
| 68224 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 68225 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 68226 | if( pBt->btsFlags & BTS_FAST_SECURE ){ |
| @@ -68232,11 +68329,11 @@ | |
| 68232 | data[hdr+7] = 0; |
| 68233 | put2byte(&data[hdr+5], pBt->usableSize); |
| 68234 | pPage->nFree = (u16)(pBt->usableSize - first); |
| 68235 | decodeFlags(pPage, flags); |
| 68236 | pPage->cellOffset = first; |
| 68237 | pPage->aDataEnd = &data[pBt->usableSize]; |
| 68238 | pPage->aCellIdx = &data[first]; |
| 68239 | pPage->aDataOfst = &data[pPage->childPtrSize]; |
| 68240 | pPage->nOverflow = 0; |
| 68241 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 68242 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| @@ -68358,11 +68455,11 @@ | |
| 68358 | rc = btreeInitPage(*ppPage); |
| 68359 | if( rc!=SQLITE_OK ){ |
| 68360 | goto getAndInitPage_error2; |
| 68361 | } |
| 68362 | } |
| 68363 | assert( (*ppPage)->pgno==pgno ); |
| 68364 | assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) ); |
| 68365 | |
| 68366 | /* If obtaining a child page for a cursor, we must verify that the page is |
| 68367 | ** compatible with the root page. */ |
| 68368 | if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){ |
| @@ -68377,11 +68474,13 @@ | |
| 68377 | if( pCur ){ |
| 68378 | pCur->iPage--; |
| 68379 | pCur->pPage = pCur->apPage[pCur->iPage]; |
| 68380 | } |
| 68381 | testcase( pgno==0 ); |
| 68382 | assert( pgno!=0 || rc==SQLITE_CORRUPT ); |
| 68383 | return rc; |
| 68384 | } |
| 68385 | |
| 68386 | /* |
| 68387 | ** Release a MemPage. This should be called once for each prior |
| @@ -75113,11 +75212,11 @@ | |
| 75113 | |
| 75114 | pPage = pCur->pPage; |
| 75115 | assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) ); |
| 75116 | assert( pPage->leaf || !pPage->intKey ); |
| 75117 | if( pPage->nFree<0 ){ |
| 75118 | if( NEVER(pCur->eState>CURSOR_INVALID) ){ |
| 75119 | rc = SQLITE_CORRUPT_BKPT; |
| 75120 | }else{ |
| 75121 | rc = btreeComputeFreeSpace(pPage); |
| 75122 | } |
| 75123 | if( rc ) return rc; |
| @@ -75431,11 +75530,11 @@ | |
| 75431 | ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT. |
| 75432 | */ |
| 75433 | bPreserve = (flags & BTREE_SAVEPOSITION)!=0; |
| 75434 | if( bPreserve ){ |
| 75435 | if( !pPage->leaf |
| 75436 | || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) |
| 75437 | || pPage->nCell==1 /* See dbfuzz001.test for a test case */ |
| 75438 | ){ |
| 75439 | /* A b-tree rebalance will be required after deleting this entry. |
| 75440 | ** Save the cursor key. */ |
| 75441 | rc = saveCursorKey(pCur); |
| @@ -80545,11 +80644,11 @@ | |
| 80545 | ** and store that value in *pMaxFuncArgs. |
| 80546 | ** |
| 80547 | ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately |
| 80548 | ** indicate what the prepared statement actually does. |
| 80549 | ** |
| 80550 | ** (4) Initialize the p4.xAdvance pointer on opcodes that use it. |
| 80551 | ** |
| 80552 | ** (5) Reclaim the memory allocated for storing labels. |
| 80553 | ** |
| 80554 | ** This routine will only function correctly if the mkopcodeh.tcl generator |
| 80555 | ** script numbers the opcodes correctly. Changes to this routine must be |
| @@ -80591,29 +80690,10 @@ | |
| 80591 | case OP_JournalMode: { |
| 80592 | p->readOnly = 0; |
| 80593 | p->bIsReader = 1; |
| 80594 | break; |
| 80595 | } |
| 80596 | case OP_Next: |
| 80597 | case OP_SorterNext: { |
| 80598 | pOp->p4.xAdvance = sqlite3BtreeNext; |
| 80599 | pOp->p4type = P4_ADVANCE; |
| 80600 | /* The code generator never codes any of these opcodes as a jump |
| 80601 | ** to a label. They are always coded as a jump backwards to a |
| 80602 | ** known address */ |
| 80603 | assert( pOp->p2>=0 ); |
| 80604 | break; |
| 80605 | } |
| 80606 | case OP_Prev: { |
| 80607 | pOp->p4.xAdvance = sqlite3BtreePrevious; |
| 80608 | pOp->p4type = P4_ADVANCE; |
| 80609 | /* The code generator never codes any of these opcodes as a jump |
| 80610 | ** to a label. They are always coded as a jump backwards to a |
| 80611 | ** known address */ |
| 80612 | assert( pOp->p2>=0 ); |
| 80613 | break; |
| 80614 | } |
| 80615 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 80616 | case OP_VUpdate: { |
| 80617 | if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; |
| 80618 | break; |
| 80619 | } |
| @@ -80893,11 +80973,10 @@ | |
| 80893 | break; |
| 80894 | } |
| 80895 | case P4_REAL: |
| 80896 | case P4_INT64: |
| 80897 | case P4_DYNAMIC: |
| 80898 | case P4_DYNBLOB: |
| 80899 | case P4_INTARRAY: { |
| 80900 | sqlite3DbFree(db, p4); |
| 80901 | break; |
| 80902 | } |
| 80903 | case P4_KEYINFO: { |
| @@ -81490,14 +81569,10 @@ | |
| 81490 | } |
| 81491 | case P4_SUBPROGRAM: { |
| 81492 | zP4 = "program"; |
| 81493 | break; |
| 81494 | } |
| 81495 | case P4_DYNBLOB: |
| 81496 | case P4_ADVANCE: { |
| 81497 | break; |
| 81498 | } |
| 81499 | case P4_TABLE: { |
| 81500 | zP4 = pOp->p4.pTab->zName; |
| 81501 | break; |
| 81502 | } |
| 81503 | default: { |
| @@ -81625,20 +81700,34 @@ | |
| 81625 | } |
| 81626 | #endif |
| 81627 | |
| 81628 | /* |
| 81629 | ** Initialize an array of N Mem element. |
| 81630 | */ |
| 81631 | static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ |
| 81632 | while( (N--)>0 ){ |
| 81633 | p->db = db; |
| 81634 | p->flags = flags; |
| 81635 | p->szMalloc = 0; |
| 81636 | #ifdef SQLITE_DEBUG |
| 81637 | p->pScopyFrom = 0; |
| 81638 | #endif |
| 81639 | p++; |
| 81640 | } |
| 81641 | } |
| 81642 | |
| 81643 | /* |
| 81644 | ** Release an array of N Mem elements |
| @@ -83292,11 +83381,11 @@ | |
| 83292 | ** pointed to was deleted out from under it. Or maybe the btree was |
| 83293 | ** rebalanced. Whatever the cause, try to restore "p" to the place it |
| 83294 | ** is supposed to be pointing. If the row was deleted out from under the |
| 83295 | ** cursor, set the cursor to point to a NULL row. |
| 83296 | */ |
| 83297 | static int SQLITE_NOINLINE handleMovedCursor(VdbeCursor *p){ |
| 83298 | int isDifferentRow, rc; |
| 83299 | assert( p->eCurType==CURTYPE_BTREE ); |
| 83300 | assert( p->uc.pCursor!=0 ); |
| 83301 | assert( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ); |
| 83302 | rc = sqlite3BtreeCursorRestore(p->uc.pCursor, &isDifferentRow); |
| @@ -83310,43 +83399,11 @@ | |
| 83310 | ** if need be. Return any I/O error from the restore operation. |
| 83311 | */ |
| 83312 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){ |
| 83313 | assert( p->eCurType==CURTYPE_BTREE ); |
| 83314 | if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 83315 | return handleMovedCursor(p); |
| 83316 | } |
| 83317 | return SQLITE_OK; |
| 83318 | } |
| 83319 | |
| 83320 | /* |
| 83321 | ** Make sure the cursor p is ready to read or write the row to which it |
| 83322 | ** was last positioned. Return an error code if an OOM fault or I/O error |
| 83323 | ** prevents us from positioning the cursor to its correct position. |
| 83324 | ** |
| 83325 | ** If a MoveTo operation is pending on the given cursor, then do that |
| 83326 | ** MoveTo now. If no move is pending, check to see if the row has been |
| 83327 | ** deleted out from under the cursor and if it has, mark the row as |
| 83328 | ** a NULL row. |
| 83329 | ** |
| 83330 | ** If the cursor is already pointing to the correct row and that row has |
| 83331 | ** not been deleted out from under the cursor, then this routine is a no-op. |
| 83332 | */ |
| 83333 | SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, u32 *piCol){ |
| 83334 | VdbeCursor *p = *pp; |
| 83335 | assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO ); |
| 83336 | if( p->deferredMoveto ){ |
| 83337 | u32 iMap; |
| 83338 | assert( !p->isEphemeral ); |
| 83339 | if( p->ub.aAltMap && (iMap = p->ub.aAltMap[1+*piCol])>0 && !p->nullRow ){ |
| 83340 | *pp = p->pAltCursor; |
| 83341 | *piCol = iMap - 1; |
| 83342 | return SQLITE_OK; |
| 83343 | } |
| 83344 | return sqlite3VdbeFinishMoveto(p); |
| 83345 | } |
| 83346 | if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 83347 | return handleMovedCursor(p); |
| 83348 | } |
| 83349 | return SQLITE_OK; |
| 83350 | } |
| 83351 | |
| 83352 | /* |
| @@ -84529,11 +84586,12 @@ | |
| 84529 | |
| 84530 | default: |
| 84531 | return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2); |
| 84532 | } |
| 84533 | |
| 84534 | v = pPKey2->aMem[0].u.i; |
| 84535 | if( v>lhs ){ |
| 84536 | res = pPKey2->r1; |
| 84537 | }else if( v<lhs ){ |
| 84538 | res = pPKey2->r2; |
| 84539 | }else if( pPKey2->nField>1 ){ |
| @@ -84564,16 +84622,22 @@ | |
| 84564 | const u8 *aKey1 = (const u8*)pKey1; |
| 84565 | int serial_type; |
| 84566 | int res; |
| 84567 | |
| 84568 | assert( pPKey2->aMem[0].flags & MEM_Str ); |
| 84569 | vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); |
| 84570 | serial_type = (u8)(aKey1[1]); |
| 84571 | if( serial_type >= 0x80 ){ |
| 84572 | sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); |
| 84573 | } |
| 84574 | if( serial_type<12 ){ |
| 84575 | res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ |
| 84576 | }else if( !(serial_type & 0x01) ){ |
| 84577 | res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ |
| 84578 | }else{ |
| 84579 | int nCmp; |
| @@ -84583,19 +84647,19 @@ | |
| 84583 | nStr = (serial_type-12) / 2; |
| 84584 | if( (szHdr + nStr) > nKey1 ){ |
| 84585 | pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT; |
| 84586 | return 0; /* Corruption */ |
| 84587 | } |
| 84588 | nCmp = MIN( pPKey2->aMem[0].n, nStr ); |
| 84589 | res = memcmp(&aKey1[szHdr], pPKey2->aMem[0].z, nCmp); |
| 84590 | |
| 84591 | if( res>0 ){ |
| 84592 | res = pPKey2->r2; |
| 84593 | }else if( res<0 ){ |
| 84594 | res = pPKey2->r1; |
| 84595 | }else{ |
| 84596 | res = nStr - pPKey2->aMem[0].n; |
| 84597 | if( res==0 ){ |
| 84598 | if( pPKey2->nField>1 ){ |
| 84599 | res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 84600 | }else{ |
| 84601 | res = pPKey2->default_rc; |
| @@ -84646,19 +84710,22 @@ | |
| 84646 | }else{ |
| 84647 | p->r1 = -1; |
| 84648 | p->r2 = 1; |
| 84649 | } |
| 84650 | if( (flags & MEM_Int) ){ |
| 84651 | return vdbeRecordCompareInt; |
| 84652 | } |
| 84653 | testcase( flags & MEM_Real ); |
| 84654 | testcase( flags & MEM_Null ); |
| 84655 | testcase( flags & MEM_Blob ); |
| 84656 | if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0 |
| 84657 | && p->pKeyInfo->aColl[0]==0 |
| 84658 | ){ |
| 84659 | assert( flags & MEM_Str ); |
| 84660 | return vdbeRecordCompareString; |
| 84661 | } |
| 84662 | } |
| 84663 | |
| 84664 | return sqlite3VdbeRecordCompare; |
| @@ -86129,19 +86196,19 @@ | |
| 86129 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 86130 | __attribute__((aligned(8))) |
| 86131 | #endif |
| 86132 | = { |
| 86133 | /* .u = */ {0}, |
| 86134 | /* .flags = */ (u16)MEM_Null, |
| 86135 | /* .enc = */ (u8)0, |
| 86136 | /* .eSubtype = */ (u8)0, |
| 86137 | /* .n = */ (int)0, |
| 86138 | /* .z = */ (char*)0, |
| 86139 | /* .zMalloc = */ (char*)0, |
| 86140 | /* .szMalloc = */ (int)0, |
| 86141 | /* .uTemp = */ (u32)0, |
| 86142 | /* .db = */ (sqlite3*)0, |
| 86143 | /* .xDel = */ (void(*)(void*))0, |
| 86144 | #ifdef SQLITE_DEBUG |
| 86145 | /* .pScopyFrom = */ (Mem*)0, |
| 86146 | /* .mScopyFlags= */ 0, |
| 86147 | #endif |
| @@ -90020,11 +90087,11 @@ | |
| 90020 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 90021 | */ |
| 90022 | case OP_Column: { |
| 90023 | u32 p2; /* column number to retrieve */ |
| 90024 | VdbeCursor *pC; /* The VDBE cursor */ |
| 90025 | BtCursor *pCrsr; /* The BTree cursor */ |
| 90026 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 90027 | int len; /* The length of the serialized data for the column */ |
| 90028 | int i; /* Loop counter */ |
| 90029 | Mem *pDest; /* Where to write the extracted value */ |
| 90030 | Mem sMem; /* For storing the record being decoded */ |
| @@ -90034,23 +90101,15 @@ | |
| 90034 | u64 offset64; /* 64-bit offset */ |
| 90035 | u32 t; /* A type code from the record header */ |
| 90036 | Mem *pReg; /* PseudoTable input register */ |
| 90037 | |
| 90038 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90039 | pC = p->apCsr[pOp->p1]; |
| 90040 | assert( pC!=0 ); |
| 90041 | p2 = (u32)pOp->p2; |
| 90042 | |
| 90043 | /* If the cursor cache is stale (meaning it is not currently point at |
| 90044 | ** the correct row) then bring it up-to-date by doing the necessary |
| 90045 | ** B-Tree seek. */ |
| 90046 | rc = sqlite3VdbeCursorMoveto(&pC, &p2); |
| 90047 | if( rc ) goto abort_due_to_error; |
| 90048 | |
| 90049 | assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 90050 | pDest = &aMem[pOp->p3]; |
| 90051 | memAboutToChange(p, pDest); |
| 90052 | assert( pC!=0 ); |
| 90053 | assert( p2<(u32)pC->nField ); |
| 90054 | aOffset = pC->aOffset; |
| 90055 | assert( aOffset==pC->aType+pC->nField ); |
| 90056 | assert( pC->eCurType!=CURTYPE_VTAB ); |
| @@ -90067,30 +90126,43 @@ | |
| 90067 | assert( pReg->flags & MEM_Blob ); |
| 90068 | assert( memIsValid(pReg) ); |
| 90069 | pC->payloadSize = pC->szRow = pReg->n; |
| 90070 | pC->aRow = (u8*)pReg->z; |
| 90071 | }else{ |
| 90072 | sqlite3VdbeMemSetNull(pDest); |
| 90073 | goto op_column_out; |
| 90074 | } |
| 90075 | }else{ |
| 90076 | pCrsr = pC->uc.pCursor; |
| 90077 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 90078 | assert( pCrsr ); |
| 90079 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 90080 | pC->payloadSize = sqlite3BtreePayloadSize(pCrsr); |
| 90081 | pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow); |
| 90082 | assert( pC->szRow<=pC->payloadSize ); |
| 90083 | assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */ |
| 90084 | if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 90085 | goto too_big; |
| 90086 | } |
| 90087 | } |
| 90088 | pC->cacheStatus = p->cacheCtr; |
| 90089 | pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]); |
| 90090 | pC->nHdrParsed = 0; |
| 90091 | |
| 90092 | |
| 90093 | if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/ |
| 90094 | /* pC->aRow does not have to hold the entire row, but it does at least |
| 90095 | ** need to cover the header of the record. If pC->aRow does not contain |
| 90096 | ** the complete header, then set it to zero, forcing the header to be |
| @@ -90127,10 +90199,14 @@ | |
| 90127 | zData = pC->aRow; |
| 90128 | assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */ |
| 90129 | testcase( aOffset[0]==0 ); |
| 90130 | goto op_column_read_header; |
| 90131 | } |
| 90132 | } |
| 90133 | |
| 90134 | /* Make sure at least the first p2+1 entries of the header have been |
| 90135 | ** parsed and valid information is in aOffset[] and pC->aType[]. |
| 90136 | */ |
| @@ -90195,10 +90271,12 @@ | |
| 90195 | /* If after trying to extract new entries from the header, nHdrParsed is |
| 90196 | ** still not up to p2, that means that the record has fewer than p2 |
| 90197 | ** columns. So the result will be either the default value or a NULL. |
| 90198 | */ |
| 90199 | if( pC->nHdrParsed<=p2 ){ |
| 90200 | if( pOp->p4type==P4_MEM ){ |
| 90201 | sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); |
| 90202 | }else{ |
| 90203 | sqlite3VdbeMemSetNull(pDest); |
| 90204 | } |
| @@ -90212,10 +90290,12 @@ | |
| 90212 | ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are |
| 90213 | ** all valid. |
| 90214 | */ |
| 90215 | assert( p2<pC->nHdrParsed ); |
| 90216 | assert( rc==SQLITE_OK ); |
| 90217 | assert( sqlite3VdbeCheckMemInvariants(pDest) ); |
| 90218 | if( VdbeMemDynamic(pDest) ){ |
| 90219 | sqlite3VdbeMemSetNull(pDest); |
| 90220 | } |
| 90221 | assert( t==pC->aType[p2] ); |
| @@ -90232,10 +90312,11 @@ | |
| 90232 | */ |
| 90233 | static const u16 aFlag[] = { MEM_Blob, MEM_Str|MEM_Term }; |
| 90234 | pDest->n = len = (t-12)/2; |
| 90235 | pDest->enc = encoding; |
| 90236 | if( pDest->szMalloc < len+2 ){ |
| 90237 | pDest->flags = MEM_Null; |
| 90238 | if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem; |
| 90239 | }else{ |
| 90240 | pDest->z = pDest->zMalloc; |
| 90241 | } |
| @@ -90264,10 +90345,11 @@ | |
| 90264 | ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint()) |
| 90265 | ** and it begins with a bunch of zeros. |
| 90266 | */ |
| 90267 | sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest); |
| 90268 | }else{ |
| 90269 | rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); |
| 90270 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 90271 | sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); |
| 90272 | pDest->flags &= ~MEM_Ephem; |
| 90273 | } |
| @@ -90476,11 +90558,10 @@ | |
| 90476 | u32 serial_type; /* Type field */ |
| 90477 | Mem *pData0; /* First field to be combined into the record */ |
| 90478 | Mem *pLast; /* Last field of the record */ |
| 90479 | int nField; /* Number of fields in the record */ |
| 90480 | char *zAffinity; /* The affinity string for the record */ |
| 90481 | int file_format; /* File format to use for encoding */ |
| 90482 | u32 len; /* Length of a field */ |
| 90483 | u8 *zHdr; /* Where to write next byte of the header */ |
| 90484 | u8 *zPayload; /* Where to write next byte of the payload */ |
| 90485 | |
| 90486 | /* Assuming the record contains N fields, the record format looks |
| @@ -90505,11 +90586,10 @@ | |
| 90505 | zAffinity = pOp->p4.z; |
| 90506 | assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem+1 - p->nCursor)+1 ); |
| 90507 | pData0 = &aMem[nField]; |
| 90508 | nField = pOp->p2; |
| 90509 | pLast = &pData0[nField-1]; |
| 90510 | file_format = p->minWriteFileFormat; |
| 90511 | |
| 90512 | /* Identify the output register */ |
| 90513 | assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); |
| 90514 | pOut = &aMem[pOp->p3]; |
| 90515 | memAboutToChange(p, pOut); |
| @@ -90607,11 +90687,11 @@ | |
| 90607 | testcase( uu==32767 ); testcase( uu==32768 ); |
| 90608 | testcase( uu==8388607 ); testcase( uu==8388608 ); |
| 90609 | testcase( uu==2147483647 ); testcase( uu==2147483648LL ); |
| 90610 | testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL ); |
| 90611 | if( uu<=127 ){ |
| 90612 | if( (i&1)==i && file_format>=4 ){ |
| 90613 | pRec->uTemp = 8+(u32)uu; |
| 90614 | }else{ |
| 90615 | nData++; |
| 90616 | pRec->uTemp = 1; |
| 90617 | } |
| @@ -93070,10 +93150,14 @@ | |
| 93070 | /* Opcode: NullRow P1 * * * * |
| 93071 | ** |
| 93072 | ** Move the cursor P1 to a null row. Any OP_Column operations |
| 93073 | ** that occur while the cursor is on the null row will always |
| 93074 | ** write a NULL. |
| 93075 | */ |
| 93076 | case OP_NullRow: { |
| 93077 | VdbeCursor *pC; |
| 93078 | |
| 93079 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| @@ -93249,11 +93333,11 @@ | |
| 93249 | VdbeBranchTaken(res!=0,2); |
| 93250 | if( res ) goto jump_to_p2; |
| 93251 | break; |
| 93252 | } |
| 93253 | |
| 93254 | /* Opcode: Next P1 P2 P3 P4 P5 |
| 93255 | ** |
| 93256 | ** Advance cursor P1 so that it points to the next key/data pair in its |
| 93257 | ** table or index. If there are no more key/value pairs then fall through |
| 93258 | ** to the following instruction. But if the cursor advance was successful, |
| 93259 | ** jump immediately to P2. |
| @@ -93268,19 +93352,16 @@ | |
| 93268 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 93269 | ** means P1 is an SQL index and that this instruction could have been |
| 93270 | ** omitted if that index had been unique. P3 is usually 0. P3 is |
| 93271 | ** always either 0 or 1. |
| 93272 | ** |
| 93273 | ** P4 is always of type P4_ADVANCE. The function pointer points to |
| 93274 | ** sqlite3BtreeNext(). |
| 93275 | ** |
| 93276 | ** If P5 is positive and the jump is taken, then event counter |
| 93277 | ** number P5-1 in the prepared statement is incremented. |
| 93278 | ** |
| 93279 | ** See also: Prev |
| 93280 | */ |
| 93281 | /* Opcode: Prev P1 P2 P3 P4 P5 |
| 93282 | ** |
| 93283 | ** Back up cursor P1 so that it points to the previous key/data pair in its |
| 93284 | ** table or index. If there is no previous key/value pairs then fall through |
| 93285 | ** to the following instruction. But if the cursor backup was successful, |
| 93286 | ** jump immediately to P2. |
| @@ -93296,13 +93377,10 @@ | |
| 93296 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 93297 | ** means P1 is an SQL index and that this instruction could have been |
| 93298 | ** omitted if that index had been unique. P3 is usually 0. P3 is |
| 93299 | ** always either 0 or 1. |
| 93300 | ** |
| 93301 | ** P4 is always of type P4_ADVANCE. The function pointer points to |
| 93302 | ** sqlite3BtreePrevious(). |
| 93303 | ** |
| 93304 | ** If P5 is positive and the jump is taken, then event counter |
| 93305 | ** number P5-1 in the prepared statement is incremented. |
| 93306 | */ |
| 93307 | /* Opcode: SorterNext P1 P2 * * P5 |
| 93308 | ** |
| @@ -93316,34 +93394,37 @@ | |
| 93316 | |
| 93317 | pC = p->apCsr[pOp->p1]; |
| 93318 | assert( isSorter(pC) ); |
| 93319 | rc = sqlite3VdbeSorterNext(db, pC); |
| 93320 | goto next_tail; |
| 93321 | case OP_Prev: /* jump */ |
| 93322 | case OP_Next: /* jump */ |
| 93323 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 93324 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 93325 | pC = p->apCsr[pOp->p1]; |
| 93326 | assert( pC!=0 ); |
| 93327 | assert( pC->deferredMoveto==0 ); |
| 93328 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 93329 | assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 93330 | assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 93331 | |
| 93332 | /* The Next opcode is only used after SeekGT, SeekGE, Rewind, and Found. |
| 93333 | ** The Prev opcode is only used after SeekLT, SeekLE, and Last. */ |
| 93334 | assert( pOp->opcode!=OP_Next |
| 93335 | || pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE |
| 93336 | || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found |
| 93337 | || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid |
| 93338 | || pC->seekOp==OP_IfNoHope); |
| 93339 | assert( pOp->opcode!=OP_Prev |
| 93340 | || pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE |
| 93341 | || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope |
| 93342 | || pC->seekOp==OP_NullRow); |
| 93343 | |
| 93344 | rc = pOp->p4.xAdvance(pC->uc.pCursor, pOp->p3); |
| 93345 | next_tail: |
| 93346 | pC->cacheStatus = CACHE_STALE; |
| 93347 | VdbeBranchTaken(rc==SQLITE_OK,2); |
| 93348 | if( rc==SQLITE_OK ){ |
| 93349 | pC->nullRow = 0; |
| @@ -93557,10 +93638,11 @@ | |
| 93557 | assert( pTabCur->uc.pCursor!=0 ); |
| 93558 | assert( pTabCur->isTable ); |
| 93559 | pTabCur->nullRow = 0; |
| 93560 | pTabCur->movetoTarget = rowid; |
| 93561 | pTabCur->deferredMoveto = 1; |
| 93562 | assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); |
| 93563 | assert( !pTabCur->isEphemeral ); |
| 93564 | pTabCur->ub.aAltMap = pOp->p4.ai; |
| 93565 | assert( !pC->isEphemeral ); |
| 93566 | pTabCur->pAltCursor = pC; |
| @@ -112069,11 +112151,11 @@ | |
| 112069 | if( pStat1==0 ) return; |
| 112070 | pStat1->zName = (char*)&pStat1[1]; |
| 112071 | memcpy(pStat1->zName, "sqlite_stat1", 13); |
| 112072 | pStat1->nCol = 3; |
| 112073 | pStat1->iPKey = -1; |
| 112074 | sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB); |
| 112075 | } |
| 112076 | #endif |
| 112077 | |
| 112078 | /* Establish a read-lock on the table at the shared-cache level. |
| 112079 | ** Open a read-only cursor on the table. Also allocate a cursor number |
| @@ -125675,11 +125757,15 @@ | |
| 125675 | ** Then special optimizations can be applied that make the transfer |
| 125676 | ** very fast and which reduce fragmentation of indices. |
| 125677 | ** |
| 125678 | ** This is the 2nd template. |
| 125679 | */ |
| 125680 | if( pColumn==0 && xferOptimization(pParse, pTab, pSelect, onError, iDb) ){ |
| 125681 | assert( !pTrigger ); |
| 125682 | assert( pList==0 ); |
| 125683 | goto insert_end; |
| 125684 | } |
| 125685 | #endif /* SQLITE_OMIT_XFER_OPT */ |
| @@ -127646,22 +127732,17 @@ | |
| 127646 | Vdbe *v; /* The VDBE we are building */ |
| 127647 | int regAutoinc; /* Memory register used by AUTOINC */ |
| 127648 | int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */ |
| 127649 | int regData, regRowid; /* Registers holding data and rowid */ |
| 127650 | |
| 127651 | if( pSelect==0 ){ |
| 127652 | return 0; /* Must be of the form INSERT INTO ... SELECT ... */ |
| 127653 | } |
| 127654 | if( pParse->pWith || pSelect->pWith ){ |
| 127655 | /* Do not attempt to process this query if there are an WITH clauses |
| 127656 | ** attached to it. Proceeding may generate a false "no such table: xxx" |
| 127657 | ** error if pSelect reads from a CTE named "xxx". */ |
| 127658 | return 0; |
| 127659 | } |
| 127660 | if( sqlite3TriggerList(pParse, pDest) ){ |
| 127661 | return 0; /* tab1 must not have triggers */ |
| 127662 | } |
| 127663 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 127664 | if( IsVirtual(pDest) ){ |
| 127665 | return 0; /* tab1 must not be a virtual table */ |
| 127666 | } |
| 127667 | #endif |
| @@ -130011,11 +130092,11 @@ | |
| 130011 | /* iArg: */ BTREE_DATA_VERSION }, |
| 130012 | #endif |
| 130013 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 130014 | {/* zName: */ "database_list", |
| 130015 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 130016 | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0, |
| 130017 | /* ColNames: */ 47, 3, |
| 130018 | /* iArg: */ 0 }, |
| 130019 | #endif |
| 130020 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 130021 | {/* zName: */ "default_cache_size", |
| @@ -130699,19 +130780,20 @@ | |
| 130699 | Vdbe *v, /* The prepared statement being created */ |
| 130700 | FuncDef *p, /* A particular function definition */ |
| 130701 | int isBuiltin, /* True if this is a built-in function */ |
| 130702 | int showInternFuncs /* True if showing internal functions */ |
| 130703 | ){ |
| 130704 | for(; p; p=p->pNext){ |
| 130705 | const char *zType; |
| 130706 | static const u32 mask = |
| 130707 | SQLITE_DETERMINISTIC | |
| 130708 | SQLITE_DIRECTONLY | |
| 130709 | SQLITE_SUBTYPE | |
| 130710 | SQLITE_INNOCUOUS | |
| 130711 | SQLITE_FUNC_INTERNAL |
| 130712 | ; |
| 130713 | static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; |
| 130714 | |
| 130715 | assert( SQLITE_FUNC_ENCMASK==0x3 ); |
| 130716 | assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 ); |
| 130717 | assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 ); |
| @@ -148508,18 +148590,26 @@ | |
| 148508 | ** rowid stored in register iRowid. |
| 148509 | ** |
| 148510 | ** Normally, this is just: |
| 148511 | ** |
| 148512 | ** OP_DeferredSeek $iCur $iRowid |
| 148513 | ** |
| 148514 | ** However, if the scan currently being coded is a branch of an OR-loop and |
| 148515 | ** the statement currently being coded is a SELECT, then P3 of OP_DeferredSeek |
| 148516 | ** is set to iIdxCur and P4 is set to point to an array of integers |
| 148517 | ** containing one entry for each column of the table cursor iCur is open |
| 148518 | ** on. For each table column, if the column is the i'th column of the |
| 148519 | ** index, then the corresponding array entry is set to (i+1). If the column |
| 148520 | ** does not appear in the index at all, the array entry is set to 0. |
| 148521 | */ |
| 148522 | static void codeDeferredSeek( |
| 148523 | WhereInfo *pWInfo, /* Where clause context */ |
| 148524 | Index *pIdx, /* Index scan is using */ |
| 148525 | int iCur, /* Cursor for IPK b-tree */ |
| @@ -234298,11 +234388,11 @@ | |
| 234298 | int nArg, /* Number of args */ |
| 234299 | sqlite3_value **apUnused /* Function arguments */ |
| 234300 | ){ |
| 234301 | assert( nArg==0 ); |
| 234302 | UNUSED_PARAM2(nArg, apUnused); |
| 234303 | sqlite3_result_text(pCtx, "fts5: 2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab", -1, SQLITE_TRANSIENT); |
| 234304 | } |
| 234305 | |
| 234306 | /* |
| 234307 | ** Return true if zName is the extension on one of the shadow tables used |
| 234308 | ** by this module. |
| 234309 |
| --- extsrc/sqlite3.c | |
| +++ extsrc/sqlite3.c | |
| @@ -1,8 +1,8 @@ | |
| 1 | /****************************************************************************** |
| 2 | ** This file is an amalgamation of many separate C source files from SQLite |
| 3 | ** version 3.39.0. By combining all the individual C code files into this |
| 4 | ** single large file, the entire code can be compiled as a single translation |
| 5 | ** unit. This allows many compilers to do optimizations that would not be |
| 6 | ** possible if the files were compiled separately. Performance improvements |
| 7 | ** of 5% or more are commonly seen when SQLite is compiled as a single |
| 8 | ** translation unit. |
| @@ -450,13 +450,13 @@ | |
| 450 | ** |
| 451 | ** See also: [sqlite3_libversion()], |
| 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | */ |
| 455 | #define SQLITE_VERSION "3.39.0" |
| 456 | #define SQLITE_VERSION_NUMBER 3039000 |
| 457 | #define SQLITE_SOURCE_ID "2022-03-02 01:02:16 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b" |
| 458 | |
| 459 | /* |
| 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | ** |
| @@ -10071,11 +10071,11 @@ | |
| 10071 | ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value |
| 10072 | ** and remains valid for the duration of the xBestIndex method call. |
| 10073 | ** ^When xBestIndex returns, the sqlite3_value object returned by |
| 10074 | ** sqlite3_vtab_rhs_value() is automatically deallocated. |
| 10075 | ** |
| 10076 | ** The "_rhs_" in the name of this routine is an abbreviation for |
| 10077 | ** "Right-Hand Side". |
| 10078 | */ |
| 10079 | SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); |
| 10080 | |
| 10081 | /* |
| @@ -14709,18 +14709,19 @@ | |
| 14709 | ** Handle type for pages. |
| 14710 | */ |
| 14711 | typedef struct PgHdr DbPage; |
| 14712 | |
| 14713 | /* |
| 14714 | ** Page number PAGER_SJ_PGNO is never used in an SQLite database (it is |
| 14715 | ** reserved for working around a windows/posix incompatibility). It is |
| 14716 | ** used in the journal to signify that the remainder of the journal file |
| 14717 | ** is devoted to storing a super-journal name - there are no more pages to |
| 14718 | ** roll back. See comments for function writeSuperJournal() in pager.c |
| 14719 | ** for details. |
| 14720 | */ |
| 14721 | #define PAGER_SJ_PGNO_COMPUTED(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1)) |
| 14722 | #define PAGER_SJ_PGNO(x) ((x)->lckPgno) |
| 14723 | |
| 14724 | /* |
| 14725 | ** Allowed values for the flags parameter to sqlite3PagerOpen(). |
| 14726 | ** |
| 14727 | ** NOTE: These values must match the corresponding BTREE_ values in btree.h. |
| @@ -15393,11 +15394,10 @@ | |
| 15394 | SubProgram *pProgram; /* Used when p4type is P4_SUBPROGRAM */ |
| 15395 | Table *pTab; /* Used when p4type is P4_TABLE */ |
| 15396 | #ifdef SQLITE_ENABLE_CURSOR_HINTS |
| 15397 | Expr *pExpr; /* Used when p4type is P4_EXPR */ |
| 15398 | #endif |
| 15399 | } p4; |
| 15400 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 15401 | char *zComment; /* Comment to improve readability */ |
| 15402 | #endif |
| 15403 | #ifdef VDBE_PROFILE |
| @@ -15444,25 +15444,23 @@ | |
| 15444 | #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 15445 | #define P4_STATIC (-1) /* Pointer to a static string */ |
| 15446 | #define P4_COLLSEQ (-2) /* P4 is a pointer to a CollSeq structure */ |
| 15447 | #define P4_INT32 (-3) /* P4 is a 32-bit signed integer */ |
| 15448 | #define P4_SUBPROGRAM (-4) /* P4 is a pointer to a SubProgram structure */ |
| 15449 | #define P4_TABLE (-5) /* P4 is a pointer to a Table structure */ |
| 15450 | /* Above do not own any resources. Must free those below */ |
| 15451 | #define P4_FREE_IF_LE (-6) |
| 15452 | #define P4_DYNAMIC (-6) /* Pointer to memory from sqliteMalloc() */ |
| 15453 | #define P4_FUNCDEF (-7) /* P4 is a pointer to a FuncDef structure */ |
| 15454 | #define P4_KEYINFO (-8) /* P4 is a pointer to a KeyInfo structure */ |
| 15455 | #define P4_EXPR (-9) /* P4 is a pointer to an Expr tree */ |
| 15456 | #define P4_MEM (-10) /* P4 is a pointer to a Mem* structure */ |
| 15457 | #define P4_VTAB (-11) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 15458 | #define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| 15459 | #define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ |
| 15460 | #define P4_INTARRAY (-14) /* P4 is a vector of 32-bit integers */ |
| 15461 | #define P4_FUNCCTX (-15) /* P4 is a pointer to an sqlite3_context object */ |
| 15462 | |
| 15463 | /* Error message codes for OP_Halt */ |
| 15464 | #define P5_ConstraintNotNull 1 |
| 15465 | #define P5_ConstraintUnique 2 |
| 15466 | #define P5_ConstraintCheck 3 |
| @@ -15503,46 +15501,46 @@ | |
| 15501 | /* Automatically generated. Do not edit */ |
| 15502 | /* See the tool/mkopcodeh.tcl script for details */ |
| 15503 | #define OP_Savepoint 0 |
| 15504 | #define OP_AutoCommit 1 |
| 15505 | #define OP_Transaction 2 |
| 15506 | #define OP_Checkpoint 3 |
| 15507 | #define OP_JournalMode 4 |
| 15508 | #define OP_Vacuum 5 |
| 15509 | #define OP_VFilter 6 /* jump, synopsis: iplan=r[P3] zplan='P4' */ |
| 15510 | #define OP_VUpdate 7 /* synopsis: data=r[P3@P2] */ |
| 15511 | #define OP_Goto 8 /* jump */ |
| 15512 | #define OP_Gosub 9 /* jump */ |
| 15513 | #define OP_InitCoroutine 10 /* jump */ |
| 15514 | #define OP_Yield 11 /* jump */ |
| 15515 | #define OP_MustBeInt 12 /* jump */ |
| 15516 | #define OP_Jump 13 /* jump */ |
| 15517 | #define OP_Once 14 /* jump */ |
| 15518 | #define OP_If 15 /* jump */ |
| 15519 | #define OP_IfNot 16 /* jump */ |
| 15520 | #define OP_IsNullOrType 17 /* jump, synopsis: if typeof(r[P1]) IN (P3,5) goto P2 */ |
| 15521 | #define OP_IfNullRow 18 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */ |
| 15522 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 15523 | #define OP_SeekLT 20 /* jump, synopsis: key=r[P3@P4] */ |
| 15524 | #define OP_SeekLE 21 /* jump, synopsis: key=r[P3@P4] */ |
| 15525 | #define OP_SeekGE 22 /* jump, synopsis: key=r[P3@P4] */ |
| 15526 | #define OP_SeekGT 23 /* jump, synopsis: key=r[P3@P4] */ |
| 15527 | #define OP_IfNotOpen 24 /* jump, synopsis: if( !csr[P1] ) goto P2 */ |
| 15528 | #define OP_IfNoHope 25 /* jump, synopsis: key=r[P3@P4] */ |
| 15529 | #define OP_NoConflict 26 /* jump, synopsis: key=r[P3@P4] */ |
| 15530 | #define OP_NotFound 27 /* jump, synopsis: key=r[P3@P4] */ |
| 15531 | #define OP_Found 28 /* jump, synopsis: key=r[P3@P4] */ |
| 15532 | #define OP_SeekRowid 29 /* jump, synopsis: intkey=r[P3] */ |
| 15533 | #define OP_NotExists 30 /* jump, synopsis: intkey=r[P3] */ |
| 15534 | #define OP_Last 31 /* jump */ |
| 15535 | #define OP_IfSmaller 32 /* jump */ |
| 15536 | #define OP_SorterSort 33 /* jump */ |
| 15537 | #define OP_Sort 34 /* jump */ |
| 15538 | #define OP_Rewind 35 /* jump */ |
| 15539 | #define OP_SorterNext 36 /* jump */ |
| 15540 | #define OP_Prev 37 /* jump */ |
| 15541 | #define OP_Next 38 /* jump */ |
| 15542 | #define OP_IdxLE 39 /* jump, synopsis: key=r[P3@P4] */ |
| 15543 | #define OP_IdxGT 40 /* jump, synopsis: key=r[P3@P4] */ |
| 15544 | #define OP_IdxLT 41 /* jump, synopsis: key=r[P3@P4] */ |
| 15545 | #define OP_IdxGE 42 /* jump, synopsis: key=r[P3@P4] */ |
| 15546 | #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| @@ -15697,15 +15695,15 @@ | |
| 15695 | #define OPFLG_IN2 0x04 /* in2: P2 is an input */ |
| 15696 | #define OPFLG_IN3 0x08 /* in3: P3 is an input */ |
| 15697 | #define OPFLG_OUT2 0x10 /* out2: P2 is an output */ |
| 15698 | #define OPFLG_OUT3 0x20 /* out3: P3 is an output */ |
| 15699 | #define OPFLG_INITIALIZER {\ |
| 15700 | /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\ |
| 15701 | /* 8 */ 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01, 0x03,\ |
| 15702 | /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x09, 0x09, 0x09, 0x09,\ |
| 15703 | /* 24 */ 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x01,\ |
| 15704 | /* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\ |
| 15705 | /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x23, 0x0b, 0x01,\ |
| 15706 | /* 48 */ 0x01, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\ |
| 15707 | /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x01, 0x01, 0x01,\ |
| 15708 | /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\ |
| 15709 | /* 72 */ 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| @@ -17778,10 +17776,15 @@ | |
| 17776 | ** b-tree. |
| 17777 | */ |
| 17778 | struct UnpackedRecord { |
| 17779 | KeyInfo *pKeyInfo; /* Collation and sort-order information */ |
| 17780 | Mem *aMem; /* Values */ |
| 17781 | union { |
| 17782 | char *z; /* Cache of aMem[0].z for vdbeRecordCompareString() */ |
| 17783 | i64 i; /* Cache of aMem[0].u.i for vdbeRecordCompareInt() */ |
| 17784 | } u; |
| 17785 | int n; /* Cache of aMem[0].n used by vdbeRecordCompareString() */ |
| 17786 | u16 nField; /* Number of entries in apMem[] */ |
| 17787 | i8 default_rc; /* Comparison result if keys are equal */ |
| 17788 | u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */ |
| 17789 | i8 r1; /* Value to return if (lhs < rhs) */ |
| 17790 | i8 r2; /* Value to return if (lhs > rhs) */ |
| @@ -22225,20 +22228,20 @@ | |
| 22228 | i64 i; /* Integer value used when MEM_Int is set in flags */ |
| 22229 | int nZero; /* Extra zero bytes when MEM_Zero and MEM_Blob set */ |
| 22230 | const char *zPType; /* Pointer type when MEM_Term|MEM_Subtype|MEM_Null */ |
| 22231 | FuncDef *pDef; /* Used only when flags==MEM_Agg */ |
| 22232 | } u; |
| 22233 | char *z; /* String or BLOB value */ |
| 22234 | int n; /* Number of characters in string value, excluding '\0' */ |
| 22235 | u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */ |
| 22236 | u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */ |
| 22237 | u8 eSubtype; /* Subtype for this value */ |
| 22238 | /* ShallowCopy only needs to copy the information above */ |
| 22239 | sqlite3 *db; /* The associated database connection */ |
| 22240 | int szMalloc; /* Size of the zMalloc allocation */ |
| 22241 | u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */ |
| 22242 | char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */ |
| 22243 | void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */ |
| 22244 | #ifdef SQLITE_DEBUG |
| 22245 | Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */ |
| 22246 | u16 mScopyFlags; /* flags value immediately after the shallow copy */ |
| 22247 | #endif |
| @@ -22246,15 +22249,47 @@ | |
| 22249 | |
| 22250 | /* |
| 22251 | ** Size of struct Mem not including the Mem.zMalloc member or anything that |
| 22252 | ** follows. |
| 22253 | */ |
| 22254 | #define MEMCELLSIZE offsetof(Mem,db) |
| 22255 | |
| 22256 | /* One or more of the following flags are set to indicate the |
| 22257 | ** representations of the value stored in the Mem struct. |
| 22258 | ** |
| 22259 | ** * MEM_Null An SQL NULL value |
| 22260 | ** |
| 22261 | ** * MEM_Null|MEM_Zero An SQL NULL with the virtual table |
| 22262 | ** UPDATE no-change flag set |
| 22263 | ** |
| 22264 | ** * MEM_Null|MEM_Term| An SQL NULL, but also contains a |
| 22265 | ** MEM_Subtype pointer accessible using |
| 22266 | ** sqlite3_value_pointer(). |
| 22267 | ** |
| 22268 | ** * MEM_Null|MEM_Cleared Special SQL NULL that compares non-equal |
| 22269 | ** to other NULLs even using the IS operator. |
| 22270 | ** |
| 22271 | ** * MEM_Str A string, stored in Mem.z with |
| 22272 | ** length Mem.n. Zero-terminated if |
| 22273 | ** MEM_Term is set. This flag is |
| 22274 | ** incompatible with MEM_Blob and |
| 22275 | ** MEM_Null, but can appear with MEM_Int, |
| 22276 | ** MEM_Real, and MEM_IntReal. |
| 22277 | ** |
| 22278 | ** * MEM_Blob A blob, stored in Mem.z length Mem.n. |
| 22279 | ** Incompatible with MEM_Str, MEM_Null, |
| 22280 | ** MEM_Int, MEM_Real, and MEM_IntReal. |
| 22281 | ** |
| 22282 | ** * MEM_Blob|MEM_Zero A blob in Mem.z of length Mem.n plus |
| 22283 | ** MEM.u.i extra 0x00 bytes at the end. |
| 22284 | ** |
| 22285 | ** * MEM_Int Integer stored in Mem.u.i. |
| 22286 | ** |
| 22287 | ** * MEM_Real Real stored in Mem.u.r. |
| 22288 | ** |
| 22289 | ** * MEM_IntReal Real stored as an integer in Mem.u.i. |
| 22290 | ** |
| 22291 | ** If the MEM_Null flag is set, then the value is an SQL NULL value. |
| 22292 | ** For a pointer type created using sqlite3_bind_pointer() or |
| 22293 | ** sqlite3_result_pointer() the MEM_Term and MEM_Subtype flags are also set. |
| 22294 | ** |
| 22295 | ** If the MEM_Str flag is set then Mem.z points at a string representation. |
| @@ -22261,39 +22296,36 @@ | |
| 22296 | ** Usually this is encoded in the same unicode encoding as the main |
| 22297 | ** database (see below for exceptions). If the MEM_Term flag is also |
| 22298 | ** set, then the string is nul terminated. The MEM_Int and MEM_Real |
| 22299 | ** flags may coexist with the MEM_Str flag. |
| 22300 | */ |
| 22301 | #define MEM_Undefined 0x0000 /* Value is undefined */ |
| 22302 | #define MEM_Null 0x0001 /* Value is NULL (or a pointer) */ |
| 22303 | #define MEM_Str 0x0002 /* Value is a string */ |
| 22304 | #define MEM_Int 0x0004 /* Value is an integer */ |
| 22305 | #define MEM_Real 0x0008 /* Value is a real number */ |
| 22306 | #define MEM_Blob 0x0010 /* Value is a BLOB */ |
| 22307 | #define MEM_IntReal 0x0020 /* MEM_Int that stringifies like MEM_Real */ |
| 22308 | #define MEM_AffMask 0x003f /* Mask of affinity bits */ |
| 22309 | |
| 22310 | /* Extra bits that modify the meanings of the core datatypes above |
| 22311 | */ |
| 22312 | #define MEM_FromBind 0x0040 /* Value originates from sqlite3_bind() */ |
| 22313 | /* 0x0080 // Available */ |
| 22314 | #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */ |
| 22315 | #define MEM_Term 0x0200 /* String in Mem.z is zero terminated */ |
| 22316 | #define MEM_Zero 0x0400 /* Mem.i contains count of 0s appended to blob */ |
| 22317 | #define MEM_Subtype 0x0800 /* Mem.eSubtype is valid */ |
| 22318 | #define MEM_TypeMask 0x0dbf /* Mask of type bits */ |
| 22319 | |
| 22320 | /* Bits that determine the storage for Mem.z for a string or blob or |
| 22321 | ** aggregate accumulator. |
| 22322 | */ |
| 22323 | #define MEM_Dyn 0x1000 /* Need to call Mem.xDel() on Mem.z */ |
| 22324 | #define MEM_Static 0x2000 /* Mem.z points to a static string */ |
| 22325 | #define MEM_Ephem 0x4000 /* Mem.z points to an ephemeral string */ |
| 22326 | #define MEM_Agg 0x8000 /* Mem.z points to an agg function context */ |
| 22327 | |
| 22328 | /* Return TRUE if Mem X contains dynamically allocated content - anything |
| 22329 | ** that needs to be deallocated to avoid a leak. |
| 22330 | */ |
| 22331 | #define VdbeMemDynamic(X) \ |
| @@ -22311,15 +22343,19 @@ | |
| 22343 | #define MemNullNochng(X) \ |
| 22344 | (((X)->flags&MEM_TypeMask)==(MEM_Null|MEM_Zero) \ |
| 22345 | && (X)->n==0 && (X)->u.nZero==0) |
| 22346 | |
| 22347 | /* |
| 22348 | ** Return true if a memory cell has been initialized and is valid. |
| 22349 | ** is for use inside assert() statements only. |
| 22350 | ** |
| 22351 | ** A Memory cell is initialized if at least one of the |
| 22352 | ** MEM_Null, MEM_Str, MEM_Int, MEM_Real, MEM_Blob, or MEM_IntReal bits |
| 22353 | ** is set. It is "undefined" if all those bits are zero. |
| 22354 | */ |
| 22355 | #ifdef SQLITE_DEBUG |
| 22356 | #define memIsValid(M) ((M)->flags & MEM_AffMask)!=0 |
| 22357 | #endif |
| 22358 | |
| 22359 | /* |
| 22360 | ** Each auxiliary data pointer stored by a user defined function |
| 22361 | ** implementation calling sqlite3_set_auxdata() is stored in an instance |
| @@ -22523,12 +22559,12 @@ | |
| 22559 | ** Function prototypes |
| 22560 | */ |
| 22561 | SQLITE_PRIVATE void sqlite3VdbeError(Vdbe*, const char *, ...); |
| 22562 | SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor*); |
| 22563 | void sqliteVdbePopStack(Vdbe*,int); |
| 22564 | SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p); |
| 22565 | SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeFinishMoveto(VdbeCursor*); |
| 22566 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor*); |
| 22567 | SQLITE_PRIVATE u32 sqlite3VdbeSerialTypeLen(u32); |
| 22568 | SQLITE_PRIVATE u8 sqlite3VdbeOneByteSerialTypeLen(u8); |
| 22569 | SQLITE_PRIVATE u32 sqlite3VdbeSerialPut(unsigned char*, Mem*, u32); |
| 22570 | SQLITE_PRIVATE void sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*); |
| @@ -34579,46 +34615,46 @@ | |
| 34615 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int i){ |
| 34616 | static const char *const azName[] = { |
| 34617 | /* 0 */ "Savepoint" OpHelp(""), |
| 34618 | /* 1 */ "AutoCommit" OpHelp(""), |
| 34619 | /* 2 */ "Transaction" OpHelp(""), |
| 34620 | /* 3 */ "Checkpoint" OpHelp(""), |
| 34621 | /* 4 */ "JournalMode" OpHelp(""), |
| 34622 | /* 5 */ "Vacuum" OpHelp(""), |
| 34623 | /* 6 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"), |
| 34624 | /* 7 */ "VUpdate" OpHelp("data=r[P3@P2]"), |
| 34625 | /* 8 */ "Goto" OpHelp(""), |
| 34626 | /* 9 */ "Gosub" OpHelp(""), |
| 34627 | /* 10 */ "InitCoroutine" OpHelp(""), |
| 34628 | /* 11 */ "Yield" OpHelp(""), |
| 34629 | /* 12 */ "MustBeInt" OpHelp(""), |
| 34630 | /* 13 */ "Jump" OpHelp(""), |
| 34631 | /* 14 */ "Once" OpHelp(""), |
| 34632 | /* 15 */ "If" OpHelp(""), |
| 34633 | /* 16 */ "IfNot" OpHelp(""), |
| 34634 | /* 17 */ "IsNullOrType" OpHelp("if typeof(r[P1]) IN (P3,5) goto P2"), |
| 34635 | /* 18 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"), |
| 34636 | /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), |
| 34637 | /* 20 */ "SeekLT" OpHelp("key=r[P3@P4]"), |
| 34638 | /* 21 */ "SeekLE" OpHelp("key=r[P3@P4]"), |
| 34639 | /* 22 */ "SeekGE" OpHelp("key=r[P3@P4]"), |
| 34640 | /* 23 */ "SeekGT" OpHelp("key=r[P3@P4]"), |
| 34641 | /* 24 */ "IfNotOpen" OpHelp("if( !csr[P1] ) goto P2"), |
| 34642 | /* 25 */ "IfNoHope" OpHelp("key=r[P3@P4]"), |
| 34643 | /* 26 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 34644 | /* 27 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 34645 | /* 28 */ "Found" OpHelp("key=r[P3@P4]"), |
| 34646 | /* 29 */ "SeekRowid" OpHelp("intkey=r[P3]"), |
| 34647 | /* 30 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 34648 | /* 31 */ "Last" OpHelp(""), |
| 34649 | /* 32 */ "IfSmaller" OpHelp(""), |
| 34650 | /* 33 */ "SorterSort" OpHelp(""), |
| 34651 | /* 34 */ "Sort" OpHelp(""), |
| 34652 | /* 35 */ "Rewind" OpHelp(""), |
| 34653 | /* 36 */ "SorterNext" OpHelp(""), |
| 34654 | /* 37 */ "Prev" OpHelp(""), |
| 34655 | /* 38 */ "Next" OpHelp(""), |
| 34656 | /* 39 */ "IdxLE" OpHelp("key=r[P3@P4]"), |
| 34657 | /* 40 */ "IdxGT" OpHelp("key=r[P3@P4]"), |
| 34658 | /* 41 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 34659 | /* 42 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 34660 | /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| @@ -50905,11 +50941,12 @@ | |
| 50941 | /* |
| 50942 | ** Make sure the page is marked as dirty. If it isn't dirty already, |
| 50943 | ** make it so. |
| 50944 | */ |
| 50945 | SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr *p){ |
| 50946 | assert( p->nRef>0 || p->pCache->bPurgeable==0 ); |
| 50947 | testcase( p->nRef==0 ); |
| 50948 | assert( sqlite3PcachePageSanity(p) ); |
| 50949 | if( p->flags & (PGHDR_CLEAN|PGHDR_DONT_WRITE) ){ /*OPTIMIZATION-IF-FALSE*/ |
| 50950 | p->flags &= ~PGHDR_DONT_WRITE; |
| 50951 | if( p->flags & PGHDR_CLEAN ){ |
| 50952 | p->flags ^= (PGHDR_DIRTY|PGHDR_CLEAN); |
| @@ -53874,10 +53911,11 @@ | |
| 53911 | u16 nExtra; /* Add this many bytes to each in-memory page */ |
| 53912 | i16 nReserve; /* Number of unused bytes at end of each page */ |
| 53913 | u32 vfsFlags; /* Flags for sqlite3_vfs.xOpen() */ |
| 53914 | u32 sectorSize; /* Assumed sector size during rollback */ |
| 53915 | Pgno mxPgno; /* Maximum allowed size of the database */ |
| 53916 | Pgno lckPgno; /* Page number for the locking page */ |
| 53917 | i64 pageSize; /* Number of bytes in a page */ |
| 53918 | i64 journalSizeLimit; /* Size limit for persistent journal files */ |
| 53919 | char *zFilename; /* Name of the database file */ |
| 53920 | char *zJournal; /* Name of the journal file */ |
| 53921 | int (*xBusyHandler)(void*); /* Function to call when busy */ |
| @@ -54860,11 +54898,11 @@ | |
| 54898 | ** pPager at the current location. The super-journal name must be the last |
| 54899 | ** thing written to a journal file. If the pager is in full-sync mode, the |
| 54900 | ** journal file descriptor is advanced to the next sector boundary before |
| 54901 | ** anything is written. The format is: |
| 54902 | ** |
| 54903 | ** + 4 bytes: PAGER_SJ_PGNO. |
| 54904 | ** + N bytes: super-journal filename in utf-8. |
| 54905 | ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator). |
| 54906 | ** + 4 bytes: super-journal name checksum. |
| 54907 | ** + 8 bytes: aJournalMagic[]. |
| 54908 | ** |
| @@ -54908,11 +54946,11 @@ | |
| 54946 | iHdrOff = pPager->journalOff; |
| 54947 | |
| 54948 | /* Write the super-journal data to the end of the journal file. If |
| 54949 | ** an error occurs, return the error code to the caller. |
| 54950 | */ |
| 54951 | if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_SJ_PGNO(pPager)))) |
| 54952 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4))) |
| 54953 | || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper))) |
| 54954 | || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum))) |
| 54955 | || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8, |
| 54956 | iHdrOff+4+nSuper+8))) |
| @@ -55418,11 +55456,11 @@ | |
| 55456 | ** to the database file, then the IO error code is returned. If data |
| 55457 | ** is successfully read from the (sub-)journal file but appears to be |
| 55458 | ** corrupted, SQLITE_DONE is returned. Data is considered corrupted in |
| 55459 | ** two circumstances: |
| 55460 | ** |
| 55461 | ** * If the record page-number is illegal (0 or PAGER_SJ_PGNO), or |
| 55462 | ** * If the record is being rolled back from the main journal file |
| 55463 | ** and the checksum field does not match the record content. |
| 55464 | ** |
| 55465 | ** Neither of these two scenarios are possible during a savepoint rollback. |
| 55466 | ** |
| @@ -55478,11 +55516,11 @@ | |
| 55516 | /* Sanity checking on the page. This is more important that I originally |
| 55517 | ** thought. If a power failure occurs while the journal is being written, |
| 55518 | ** it could cause invalid data to be written into the journal. We need to |
| 55519 | ** detect this invalid data (with high probability) and ignore it. |
| 55520 | */ |
| 55521 | if( pgno==0 || pgno==PAGER_SJ_PGNO(pPager) ){ |
| 55522 | assert( !isSavepnt ); |
| 55523 | return SQLITE_DONE; |
| 55524 | } |
| 55525 | if( pgno>(Pgno)pPager->dbSize || sqlite3BitvecTest(pDone, pgno) ){ |
| 55526 | return SQLITE_OK; |
| @@ -56037,10 +56075,13 @@ | |
| 56075 | rc = pager_truncate(pPager, mxPg); |
| 56076 | if( rc!=SQLITE_OK ){ |
| 56077 | goto end_playback; |
| 56078 | } |
| 56079 | pPager->dbSize = mxPg; |
| 56080 | if( pPager->mxPgno<mxPg ){ |
| 56081 | pPager->mxPgno = mxPg; |
| 56082 | } |
| 56083 | } |
| 56084 | |
| 56085 | /* Copy original pages out of the journal and back into the |
| 56086 | ** database file and/or page cache. |
| 56087 | */ |
| @@ -56933,10 +56974,11 @@ | |
| 56974 | if( rc==SQLITE_OK ){ |
| 56975 | sqlite3PageFree(pPager->pTmpSpace); |
| 56976 | pPager->pTmpSpace = pNew; |
| 56977 | pPager->dbSize = (Pgno)((nByte+pageSize-1)/pageSize); |
| 56978 | pPager->pageSize = pageSize; |
| 56979 | pPager->lckPgno = (Pgno)(PENDING_BYTE/pageSize) + 1; |
| 56980 | }else{ |
| 56981 | sqlite3PageFree(pNew); |
| 56982 | } |
| 56983 | } |
| 56984 | |
| @@ -58682,11 +58724,10 @@ | |
| 58724 | assert( pPager->errCode==SQLITE_OK ); |
| 58725 | assert( pPager->eState>=PAGER_READER ); |
| 58726 | assert( assert_pager_state(pPager) ); |
| 58727 | assert( pPager->hasHeldSharedLock==1 ); |
| 58728 | |
| 58729 | pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3); |
| 58730 | if( pBase==0 ){ |
| 58731 | pPg = 0; |
| 58732 | rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase); |
| 58733 | if( rc!=SQLITE_OK ) goto pager_acquire_err; |
| @@ -58702,22 +58743,22 @@ | |
| 58743 | |
| 58744 | noContent = (flags & PAGER_GET_NOCONTENT)!=0; |
| 58745 | if( pPg->pPager && !noContent ){ |
| 58746 | /* In this case the pcache already contains an initialized copy of |
| 58747 | ** the page. Return without further ado. */ |
| 58748 | assert( pgno!=PAGER_SJ_PGNO(pPager) ); |
| 58749 | pPager->aStat[PAGER_STAT_HIT]++; |
| 58750 | return SQLITE_OK; |
| 58751 | |
| 58752 | }else{ |
| 58753 | /* The pager cache has created a new page. Its content needs to |
| 58754 | ** be initialized. But first some error checks: |
| 58755 | ** |
| 58756 | ** (1) Never try to fetch the locking page |
| 58757 | ** (2) Never try to fetch page 0, which does not exist |
| 58758 | */ |
| 58759 | if( pgno==PAGER_SJ_PGNO(pPager) || pgno==0 ){ |
| 58760 | rc = SQLITE_CORRUPT_BKPT; |
| 58761 | goto pager_acquire_err; |
| 58762 | } |
| 58763 | |
| 58764 | pPg->pPager = pPager; |
| @@ -59112,11 +59153,11 @@ | |
| 59153 | i64 iOff = pPager->journalOff; |
| 59154 | |
| 59155 | /* We should never write to the journal file the page that |
| 59156 | ** contains the database locks. The following assert verifies |
| 59157 | ** that we do not. */ |
| 59158 | assert( pPg->pgno!=PAGER_SJ_PGNO(pPager) ); |
| 59159 | |
| 59160 | assert( pPager->journalHdr<=pPager->journalOff ); |
| 59161 | pData2 = pPg->pData; |
| 59162 | cksum = pager_cksum(pPager, (u8*)pData2); |
| 59163 | |
| @@ -59291,11 +59332,11 @@ | |
| 59332 | |
| 59333 | for(ii=0; ii<nPage && rc==SQLITE_OK; ii++){ |
| 59334 | Pgno pg = pg1+ii; |
| 59335 | PgHdr *pPage; |
| 59336 | if( pg==pPg->pgno || !sqlite3BitvecTest(pPager->pInJournal, pg) ){ |
| 59337 | if( pg!=PAGER_SJ_PGNO(pPager) ){ |
| 59338 | rc = sqlite3PagerGet(pPager, pg, &pPage, 0); |
| 59339 | if( rc==SQLITE_OK ){ |
| 59340 | rc = pager_write(pPage); |
| 59341 | if( pPage->flags&PGHDR_NEED_SYNC ){ |
| 59342 | needSync = 1; |
| @@ -59769,11 +59810,11 @@ | |
| 59810 | ** image was extended as part of the current transaction and then the |
| 59811 | ** last page in the db image moved to the free-list. In this case the |
| 59812 | ** last page is never written out to disk, leaving the database file |
| 59813 | ** undersized. Fix this now if it is the case. */ |
| 59814 | if( pPager->dbSize>pPager->dbFileSize ){ |
| 59815 | Pgno nNew = pPager->dbSize - (pPager->dbSize==PAGER_SJ_PGNO(pPager)); |
| 59816 | assert( pPager->eState==PAGER_WRITER_DBMOD ); |
| 59817 | rc = pager_truncate(pPager, nNew); |
| 59818 | if( rc!=SQLITE_OK ) goto commit_phase_one_exit; |
| 59819 | } |
| 59820 | |
| @@ -65396,11 +65437,13 @@ | |
| 65437 | u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th |
| 65438 | ** non-overflow cell */ |
| 65439 | u8 *apOvfl[4]; /* Pointers to the body of overflow cells */ |
| 65440 | BtShared *pBt; /* Pointer to BtShared that this page is part of */ |
| 65441 | u8 *aData; /* Pointer to disk image of the page data */ |
| 65442 | u8 *aDataEnd; /* One byte past the end of the entire page - not just |
| 65443 | ** the usable space, the entire page. Used to prevent |
| 65444 | ** corruption-induced of buffer overflow. */ |
| 65445 | u8 *aCellIdx; /* The cell index area */ |
| 65446 | u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */ |
| 65447 | DbPage *pDbPage; /* Pager page handle */ |
| 65448 | u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */ |
| 65449 | void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */ |
| @@ -65701,11 +65744,11 @@ | |
| 65744 | #define CURSOR_FAULT 4 |
| 65745 | |
| 65746 | /* |
| 65747 | ** The database page the PENDING_BYTE occupies. This page is never used. |
| 65748 | */ |
| 65749 | #define PENDING_BYTE_PAGE(pBt) ((Pgno)((PENDING_BYTE/((pBt)->pageSize))+1)) |
| 65750 | |
| 65751 | /* |
| 65752 | ** These macros define the location of the pointer-map entry for a |
| 65753 | ** database page. The first argument to each is the number of usable |
| 65754 | ** bytes on each page of the database (often 1024). The second is the |
| @@ -67455,10 +67498,11 @@ | |
| 67498 | ** data area of the btree-page. The return number includes the cell |
| 67499 | ** data header and the local payload, but not any overflow page or |
| 67500 | ** the space used by the cell pointer. |
| 67501 | ** |
| 67502 | ** cellSizePtrNoPayload() => table internal nodes |
| 67503 | ** cellSizePtrTableLeaf() => table leaf nodes |
| 67504 | ** cellSizePtr() => all index nodes & table leaf nodes |
| 67505 | */ |
| 67506 | static u16 cellSizePtr(MemPage *pPage, u8 *pCell){ |
| 67507 | u8 *pIter = pCell + pPage->childPtrSize; /* For looping over bytes of pCell */ |
| 67508 | u8 *pEnd; /* End mark for a varint */ |
| @@ -67480,17 +67524,10 @@ | |
| 67524 | do{ |
| 67525 | nSize = (nSize<<7) | (*++pIter & 0x7f); |
| 67526 | }while( *(pIter)>=0x80 && pIter<pEnd ); |
| 67527 | } |
| 67528 | pIter++; |
| 67529 | testcase( nSize==pPage->maxLocal ); |
| 67530 | testcase( nSize==(u32)pPage->maxLocal+1 ); |
| 67531 | if( nSize<=pPage->maxLocal ){ |
| 67532 | nSize += (u32)(pIter - pCell); |
| 67533 | if( nSize<4 ) nSize = 4; |
| @@ -67526,10 +67563,62 @@ | |
| 67563 | pEnd = pIter + 9; |
| 67564 | while( (*pIter++)&0x80 && pIter<pEnd ); |
| 67565 | assert( debuginfo.nSize==(u16)(pIter - pCell) || CORRUPT_DB ); |
| 67566 | return (u16)(pIter - pCell); |
| 67567 | } |
| 67568 | static u16 cellSizePtrTableLeaf(MemPage *pPage, u8 *pCell){ |
| 67569 | u8 *pIter = pCell; /* For looping over bytes of pCell */ |
| 67570 | u8 *pEnd; /* End mark for a varint */ |
| 67571 | u32 nSize; /* Size value to return */ |
| 67572 | |
| 67573 | #ifdef SQLITE_DEBUG |
| 67574 | /* The value returned by this function should always be the same as |
| 67575 | ** the (CellInfo.nSize) value found by doing a full parse of the |
| 67576 | ** cell. If SQLITE_DEBUG is defined, an assert() at the bottom of |
| 67577 | ** this function verifies that this invariant is not violated. */ |
| 67578 | CellInfo debuginfo; |
| 67579 | pPage->xParseCell(pPage, pCell, &debuginfo); |
| 67580 | #endif |
| 67581 | |
| 67582 | nSize = *pIter; |
| 67583 | if( nSize>=0x80 ){ |
| 67584 | pEnd = &pIter[8]; |
| 67585 | nSize &= 0x7f; |
| 67586 | do{ |
| 67587 | nSize = (nSize<<7) | (*++pIter & 0x7f); |
| 67588 | }while( *(pIter)>=0x80 && pIter<pEnd ); |
| 67589 | } |
| 67590 | pIter++; |
| 67591 | /* pIter now points at the 64-bit integer key value, a variable length |
| 67592 | ** integer. The following block moves pIter to point at the first byte |
| 67593 | ** past the end of the key value. */ |
| 67594 | if( (*pIter++)&0x80 |
| 67595 | && (*pIter++)&0x80 |
| 67596 | && (*pIter++)&0x80 |
| 67597 | && (*pIter++)&0x80 |
| 67598 | && (*pIter++)&0x80 |
| 67599 | && (*pIter++)&0x80 |
| 67600 | && (*pIter++)&0x80 |
| 67601 | && (*pIter++)&0x80 ){ pIter++; } |
| 67602 | testcase( nSize==pPage->maxLocal ); |
| 67603 | testcase( nSize==(u32)pPage->maxLocal+1 ); |
| 67604 | if( nSize<=pPage->maxLocal ){ |
| 67605 | nSize += (u32)(pIter - pCell); |
| 67606 | if( nSize<4 ) nSize = 4; |
| 67607 | }else{ |
| 67608 | int minLocal = pPage->minLocal; |
| 67609 | nSize = minLocal + (nSize - minLocal) % (pPage->pBt->usableSize - 4); |
| 67610 | testcase( nSize==pPage->maxLocal ); |
| 67611 | testcase( nSize==(u32)pPage->maxLocal+1 ); |
| 67612 | if( nSize>pPage->maxLocal ){ |
| 67613 | nSize = minLocal; |
| 67614 | } |
| 67615 | nSize += 4 + (u16)(pIter - pCell); |
| 67616 | } |
| 67617 | assert( nSize==debuginfo.nSize || CORRUPT_DB ); |
| 67618 | return (u16)nSize; |
| 67619 | } |
| 67620 | |
| 67621 | |
| 67622 | #ifdef SQLITE_DEBUG |
| 67623 | /* This variation on cellSizePtr() is used inside of assert() statements |
| 67624 | ** only. */ |
| @@ -67539,11 +67628,11 @@ | |
| 67628 | #endif |
| 67629 | |
| 67630 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 67631 | /* |
| 67632 | ** The cell pCell is currently part of page pSrc but will ultimately be part |
| 67633 | ** of pPage. (pSrc and pPage are often the same.) If pCell contains a |
| 67634 | ** pointer to an overflow page, insert an entry into the pointer-map for |
| 67635 | ** the overflow page that will be valid after pCell has been moved to pPage. |
| 67636 | */ |
| 67637 | static void ptrmapPutOvflPtr(MemPage *pPage, MemPage *pSrc, u8 *pCell,int *pRC){ |
| 67638 | CellInfo info; |
| @@ -67714,21 +67803,23 @@ | |
| 67803 | */ |
| 67804 | static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){ |
| 67805 | const int hdr = pPg->hdrOffset; /* Offset to page header */ |
| 67806 | u8 * const aData = pPg->aData; /* Page data */ |
| 67807 | int iAddr = hdr + 1; /* Address of ptr to pc */ |
| 67808 | u8 *pTmp = &aData[iAddr]; /* Temporary ptr into aData[] */ |
| 67809 | int pc = get2byte(pTmp); /* Address of a free slot */ |
| 67810 | int x; /* Excess size of the slot */ |
| 67811 | int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */ |
| 67812 | int size; /* Size of the free slot */ |
| 67813 | |
| 67814 | assert( pc>0 ); |
| 67815 | while( pc<=maxPC ){ |
| 67816 | /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each |
| 67817 | ** freeblock form a big-endian integer which is the size of the freeblock |
| 67818 | ** in bytes, including the 4-byte header. */ |
| 67819 | pTmp = &aData[pc+2]; |
| 67820 | size = get2byte(pTmp); |
| 67821 | if( (x = size - nByte)>=0 ){ |
| 67822 | testcase( x==4 ); |
| 67823 | testcase( x==3 ); |
| 67824 | if( x<4 ){ |
| 67825 | /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total |
| @@ -67749,11 +67840,12 @@ | |
| 67840 | put2byte(&aData[pc+2], x); |
| 67841 | } |
| 67842 | return &aData[pc + x]; |
| 67843 | } |
| 67844 | iAddr = pc; |
| 67845 | pTmp = &aData[pc]; |
| 67846 | pc = get2byte(pTmp); |
| 67847 | if( pc<=iAddr+size ){ |
| 67848 | if( pc ){ |
| 67849 | /* The next slot in the chain is not past the end of the current slot */ |
| 67850 | *pRc = SQLITE_CORRUPT_PAGE(pPg); |
| 67851 | } |
| @@ -67783,10 +67875,11 @@ | |
| 67875 | static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){ |
| 67876 | const int hdr = pPage->hdrOffset; /* Local cache of pPage->hdrOffset */ |
| 67877 | u8 * const data = pPage->aData; /* Local cache of pPage->aData */ |
| 67878 | int top; /* First byte of cell content area */ |
| 67879 | int rc = SQLITE_OK; /* Integer return code */ |
| 67880 | u8 *pTmp; /* Temp ptr into data[] */ |
| 67881 | int gap; /* First byte of gap between cell pointers and cell content */ |
| 67882 | |
| 67883 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67884 | assert( pPage->pBt ); |
| 67885 | assert( sqlite3_mutex_held(pPage->pBt->mutex) ); |
| @@ -67801,11 +67894,12 @@ | |
| 67894 | /* EVIDENCE-OF: R-29356-02391 If the database uses a 65536-byte page size |
| 67895 | ** and the reserved space is zero (the usual value for reserved space) |
| 67896 | ** then the cell content offset of an empty page wants to be 65536. |
| 67897 | ** However, that integer is too large to be stored in a 2-byte unsigned |
| 67898 | ** integer, so a value of 0 is used in its place. */ |
| 67899 | pTmp = &data[hdr+5]; |
| 67900 | top = get2byte(pTmp); |
| 67901 | assert( top<=(int)pPage->pBt->usableSize ); /* by btreeComputeFreeSpace() */ |
| 67902 | if( gap>top ){ |
| 67903 | if( top==0 && pPage->pBt->usableSize==65536 ){ |
| 67904 | top = 65536; |
| 67905 | }else{ |
| @@ -67883,10 +67977,11 @@ | |
| 67977 | u8 nFrag = 0; /* Reduction in fragmentation */ |
| 67978 | u16 iOrigSize = iSize; /* Original value of iSize */ |
| 67979 | u16 x; /* Offset to cell content area */ |
| 67980 | u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */ |
| 67981 | unsigned char *data = pPage->aData; /* Page content */ |
| 67982 | u8 *pTmp; /* Temporary ptr into data[] */ |
| 67983 | |
| 67984 | assert( pPage->pBt!=0 ); |
| 67985 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 67986 | assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize ); |
| 67987 | assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize ); |
| @@ -67945,11 +68040,12 @@ | |
| 68040 | } |
| 68041 | } |
| 68042 | if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage); |
| 68043 | data[hdr+7] -= nFrag; |
| 68044 | } |
| 68045 | pTmp = &data[hdr+5]; |
| 68046 | x = get2byte(pTmp); |
| 68047 | if( iStart<=x ){ |
| 68048 | /* The new freeblock is at the beginning of the cell content area, |
| 68049 | ** so just extend the cell content area rather than create another |
| 68050 | ** freelist entry */ |
| 68051 | if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage); |
| @@ -68001,10 +68097,11 @@ | |
| 68097 | ** leaf table b-tree page. */ |
| 68098 | assert( (PTF_LEAFDATA|PTF_INTKEY|PTF_LEAF)==13 ); |
| 68099 | pPage->intKey = 1; |
| 68100 | if( pPage->leaf ){ |
| 68101 | pPage->intKeyLeaf = 1; |
| 68102 | pPage->xCellSize = cellSizePtrTableLeaf; |
| 68103 | pPage->xParseCell = btreeParseCellPtr; |
| 68104 | }else{ |
| 68105 | pPage->intKeyLeaf = 0; |
| 68106 | pPage->xCellSize = cellSizePtrNoPayload; |
| 68107 | pPage->xParseCell = btreeParseCellPtrNoPayload; |
| @@ -68181,11 +68278,11 @@ | |
| 68278 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 68279 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| 68280 | pPage->nOverflow = 0; |
| 68281 | pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize; |
| 68282 | pPage->aCellIdx = data + pPage->childPtrSize + 8; |
| 68283 | pPage->aDataEnd = pPage->aData + pBt->pageSize; |
| 68284 | pPage->aDataOfst = pPage->aData + pPage->childPtrSize; |
| 68285 | /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the |
| 68286 | ** number of cells on the page. */ |
| 68287 | pPage->nCell = get2byte(&data[3]); |
| 68288 | if( pPage->nCell>MX_CELL(pBt) ){ |
| @@ -68216,11 +68313,11 @@ | |
| 68313 | unsigned char *data = pPage->aData; |
| 68314 | BtShared *pBt = pPage->pBt; |
| 68315 | u8 hdr = pPage->hdrOffset; |
| 68316 | u16 first; |
| 68317 | |
| 68318 | assert( sqlite3PagerPagenumber(pPage->pDbPage)==pPage->pgno || CORRUPT_DB ); |
| 68319 | assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage ); |
| 68320 | assert( sqlite3PagerGetData(pPage->pDbPage) == data ); |
| 68321 | assert( sqlite3PagerIswriteable(pPage->pDbPage) ); |
| 68322 | assert( sqlite3_mutex_held(pBt->mutex) ); |
| 68323 | if( pBt->btsFlags & BTS_FAST_SECURE ){ |
| @@ -68232,11 +68329,11 @@ | |
| 68329 | data[hdr+7] = 0; |
| 68330 | put2byte(&data[hdr+5], pBt->usableSize); |
| 68331 | pPage->nFree = (u16)(pBt->usableSize - first); |
| 68332 | decodeFlags(pPage, flags); |
| 68333 | pPage->cellOffset = first; |
| 68334 | pPage->aDataEnd = &data[pBt->pageSize]; |
| 68335 | pPage->aCellIdx = &data[first]; |
| 68336 | pPage->aDataOfst = &data[pPage->childPtrSize]; |
| 68337 | pPage->nOverflow = 0; |
| 68338 | assert( pBt->pageSize>=512 && pBt->pageSize<=65536 ); |
| 68339 | pPage->maskPage = (u16)(pBt->pageSize - 1); |
| @@ -68358,11 +68455,11 @@ | |
| 68455 | rc = btreeInitPage(*ppPage); |
| 68456 | if( rc!=SQLITE_OK ){ |
| 68457 | goto getAndInitPage_error2; |
| 68458 | } |
| 68459 | } |
| 68460 | assert( (*ppPage)->pgno==pgno || CORRUPT_DB ); |
| 68461 | assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) ); |
| 68462 | |
| 68463 | /* If obtaining a child page for a cursor, we must verify that the page is |
| 68464 | ** compatible with the root page. */ |
| 68465 | if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){ |
| @@ -68377,11 +68474,13 @@ | |
| 68474 | if( pCur ){ |
| 68475 | pCur->iPage--; |
| 68476 | pCur->pPage = pCur->apPage[pCur->iPage]; |
| 68477 | } |
| 68478 | testcase( pgno==0 ); |
| 68479 | assert( pgno!=0 || rc==SQLITE_CORRUPT |
| 68480 | || rc==SQLITE_IOERR_NOMEM |
| 68481 | || rc==SQLITE_NOMEM ); |
| 68482 | return rc; |
| 68483 | } |
| 68484 | |
| 68485 | /* |
| 68486 | ** Release a MemPage. This should be called once for each prior |
| @@ -75113,11 +75212,11 @@ | |
| 75212 | |
| 75213 | pPage = pCur->pPage; |
| 75214 | assert( pPage->intKey || pX->nKey>=0 || (flags & BTREE_PREFORMAT) ); |
| 75215 | assert( pPage->leaf || !pPage->intKey ); |
| 75216 | if( pPage->nFree<0 ){ |
| 75217 | if( pCur->eState>CURSOR_INVALID ){ |
| 75218 | rc = SQLITE_CORRUPT_BKPT; |
| 75219 | }else{ |
| 75220 | rc = btreeComputeFreeSpace(pPage); |
| 75221 | } |
| 75222 | if( rc ) return rc; |
| @@ -75431,11 +75530,11 @@ | |
| 75530 | ** bPreserve==2 Cursor won't move. Set CURSOR_SKIPNEXT. |
| 75531 | */ |
| 75532 | bPreserve = (flags & BTREE_SAVEPOSITION)!=0; |
| 75533 | if( bPreserve ){ |
| 75534 | if( !pPage->leaf |
| 75535 | || (pPage->nFree+pPage->xCellSize(pPage,pCell)+2)>(int)(pBt->usableSize*2/3) |
| 75536 | || pPage->nCell==1 /* See dbfuzz001.test for a test case */ |
| 75537 | ){ |
| 75538 | /* A b-tree rebalance will be required after deleting this entry. |
| 75539 | ** Save the cursor key. */ |
| 75540 | rc = saveCursorKey(pCur); |
| @@ -80545,11 +80644,11 @@ | |
| 80644 | ** and store that value in *pMaxFuncArgs. |
| 80645 | ** |
| 80646 | ** (3) Update the Vdbe.readOnly and Vdbe.bIsReader flags to accurately |
| 80647 | ** indicate what the prepared statement actually does. |
| 80648 | ** |
| 80649 | ** (4) (discontinued) |
| 80650 | ** |
| 80651 | ** (5) Reclaim the memory allocated for storing labels. |
| 80652 | ** |
| 80653 | ** This routine will only function correctly if the mkopcodeh.tcl generator |
| 80654 | ** script numbers the opcodes correctly. Changes to this routine must be |
| @@ -80591,29 +80690,10 @@ | |
| 80690 | case OP_JournalMode: { |
| 80691 | p->readOnly = 0; |
| 80692 | p->bIsReader = 1; |
| 80693 | break; |
| 80694 | } |
| 80695 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 80696 | case OP_VUpdate: { |
| 80697 | if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; |
| 80698 | break; |
| 80699 | } |
| @@ -80893,11 +80973,10 @@ | |
| 80973 | break; |
| 80974 | } |
| 80975 | case P4_REAL: |
| 80976 | case P4_INT64: |
| 80977 | case P4_DYNAMIC: |
| 80978 | case P4_INTARRAY: { |
| 80979 | sqlite3DbFree(db, p4); |
| 80980 | break; |
| 80981 | } |
| 80982 | case P4_KEYINFO: { |
| @@ -81490,14 +81569,10 @@ | |
| 81569 | } |
| 81570 | case P4_SUBPROGRAM: { |
| 81571 | zP4 = "program"; |
| 81572 | break; |
| 81573 | } |
| 81574 | case P4_TABLE: { |
| 81575 | zP4 = pOp->p4.pTab->zName; |
| 81576 | break; |
| 81577 | } |
| 81578 | default: { |
| @@ -81625,20 +81700,34 @@ | |
| 81700 | } |
| 81701 | #endif |
| 81702 | |
| 81703 | /* |
| 81704 | ** Initialize an array of N Mem element. |
| 81705 | ** |
| 81706 | ** This is a high-runner, so only those fields that really do need to |
| 81707 | ** be initialized are set. The Mem structure is organized so that |
| 81708 | ** the fields that get initialized are nearby and hopefully on the same |
| 81709 | ** cache line. |
| 81710 | ** |
| 81711 | ** Mem.flags = flags |
| 81712 | ** Mem.db = db |
| 81713 | ** Mem.szMalloc = 0 |
| 81714 | ** |
| 81715 | ** All other fields of Mem can safely remain uninitialized for now. They |
| 81716 | ** will be initialized before use. |
| 81717 | */ |
| 81718 | static void initMemArray(Mem *p, int N, sqlite3 *db, u16 flags){ |
| 81719 | if( N>0 ){ |
| 81720 | do{ |
| 81721 | p->flags = flags; |
| 81722 | p->db = db; |
| 81723 | p->szMalloc = 0; |
| 81724 | #ifdef SQLITE_DEBUG |
| 81725 | p->pScopyFrom = 0; |
| 81726 | #endif |
| 81727 | p++; |
| 81728 | }while( (--N)>0 ); |
| 81729 | } |
| 81730 | } |
| 81731 | |
| 81732 | /* |
| 81733 | ** Release an array of N Mem elements |
| @@ -83292,11 +83381,11 @@ | |
| 83381 | ** pointed to was deleted out from under it. Or maybe the btree was |
| 83382 | ** rebalanced. Whatever the cause, try to restore "p" to the place it |
| 83383 | ** is supposed to be pointing. If the row was deleted out from under the |
| 83384 | ** cursor, set the cursor to point to a NULL row. |
| 83385 | */ |
| 83386 | SQLITE_PRIVATE int SQLITE_NOINLINE sqlite3VdbeHandleMovedCursor(VdbeCursor *p){ |
| 83387 | int isDifferentRow, rc; |
| 83388 | assert( p->eCurType==CURTYPE_BTREE ); |
| 83389 | assert( p->uc.pCursor!=0 ); |
| 83390 | assert( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ); |
| 83391 | rc = sqlite3BtreeCursorRestore(p->uc.pCursor, &isDifferentRow); |
| @@ -83310,43 +83399,11 @@ | |
| 83399 | ** if need be. Return any I/O error from the restore operation. |
| 83400 | */ |
| 83401 | SQLITE_PRIVATE int sqlite3VdbeCursorRestore(VdbeCursor *p){ |
| 83402 | assert( p->eCurType==CURTYPE_BTREE ); |
| 83403 | if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){ |
| 83404 | return sqlite3VdbeHandleMovedCursor(p); |
| 83405 | } |
| 83406 | return SQLITE_OK; |
| 83407 | } |
| 83408 | |
| 83409 | /* |
| @@ -84529,11 +84586,12 @@ | |
| 84586 | |
| 84587 | default: |
| 84588 | return sqlite3VdbeRecordCompare(nKey1, pKey1, pPKey2); |
| 84589 | } |
| 84590 | |
| 84591 | assert( pPKey2->u.i == pPKey2->aMem[0].u.i ); |
| 84592 | v = pPKey2->u.i; |
| 84593 | if( v>lhs ){ |
| 84594 | res = pPKey2->r1; |
| 84595 | }else if( v<lhs ){ |
| 84596 | res = pPKey2->r2; |
| 84597 | }else if( pPKey2->nField>1 ){ |
| @@ -84564,16 +84622,22 @@ | |
| 84622 | const u8 *aKey1 = (const u8*)pKey1; |
| 84623 | int serial_type; |
| 84624 | int res; |
| 84625 | |
| 84626 | assert( pPKey2->aMem[0].flags & MEM_Str ); |
| 84627 | assert( pPKey2->aMem[0].n == pPKey2->n ); |
| 84628 | assert( pPKey2->aMem[0].z == pPKey2->u.z ); |
| 84629 | vdbeAssertFieldCountWithinLimits(nKey1, pKey1, pPKey2->pKeyInfo); |
| 84630 | serial_type = (signed char)(aKey1[1]); |
| 84631 | |
| 84632 | vrcs_restart: |
| 84633 | if( serial_type<12 ){ |
| 84634 | if( serial_type<0 ){ |
| 84635 | sqlite3GetVarint32(&aKey1[1], (u32*)&serial_type); |
| 84636 | if( serial_type>=12 ) goto vrcs_restart; |
| 84637 | assert( CORRUPT_DB ); |
| 84638 | } |
| 84639 | res = pPKey2->r1; /* (pKey1/nKey1) is a number or a null */ |
| 84640 | }else if( !(serial_type & 0x01) ){ |
| 84641 | res = pPKey2->r2; /* (pKey1/nKey1) is a blob */ |
| 84642 | }else{ |
| 84643 | int nCmp; |
| @@ -84583,19 +84647,19 @@ | |
| 84647 | nStr = (serial_type-12) / 2; |
| 84648 | if( (szHdr + nStr) > nKey1 ){ |
| 84649 | pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT; |
| 84650 | return 0; /* Corruption */ |
| 84651 | } |
| 84652 | nCmp = MIN( pPKey2->n, nStr ); |
| 84653 | res = memcmp(&aKey1[szHdr], pPKey2->u.z, nCmp); |
| 84654 | |
| 84655 | if( res>0 ){ |
| 84656 | res = pPKey2->r2; |
| 84657 | }else if( res<0 ){ |
| 84658 | res = pPKey2->r1; |
| 84659 | }else{ |
| 84660 | res = nStr - pPKey2->n; |
| 84661 | if( res==0 ){ |
| 84662 | if( pPKey2->nField>1 ){ |
| 84663 | res = sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 1); |
| 84664 | }else{ |
| 84665 | res = pPKey2->default_rc; |
| @@ -84646,19 +84710,22 @@ | |
| 84710 | }else{ |
| 84711 | p->r1 = -1; |
| 84712 | p->r2 = 1; |
| 84713 | } |
| 84714 | if( (flags & MEM_Int) ){ |
| 84715 | p->u.i = p->aMem[0].u.i; |
| 84716 | return vdbeRecordCompareInt; |
| 84717 | } |
| 84718 | testcase( flags & MEM_Real ); |
| 84719 | testcase( flags & MEM_Null ); |
| 84720 | testcase( flags & MEM_Blob ); |
| 84721 | if( (flags & (MEM_Real|MEM_IntReal|MEM_Null|MEM_Blob))==0 |
| 84722 | && p->pKeyInfo->aColl[0]==0 |
| 84723 | ){ |
| 84724 | assert( flags & MEM_Str ); |
| 84725 | p->u.z = p->aMem[0].z; |
| 84726 | p->n = p->aMem[0].n; |
| 84727 | return vdbeRecordCompareString; |
| 84728 | } |
| 84729 | } |
| 84730 | |
| 84731 | return sqlite3VdbeRecordCompare; |
| @@ -86129,19 +86196,19 @@ | |
| 86196 | #if defined(SQLITE_DEBUG) && defined(__GNUC__) |
| 86197 | __attribute__((aligned(8))) |
| 86198 | #endif |
| 86199 | = { |
| 86200 | /* .u = */ {0}, |
| 86201 | /* .z = */ (char*)0, |
| 86202 | /* .n = */ (int)0, |
| 86203 | /* .flags = */ (u16)MEM_Null, |
| 86204 | /* .enc = */ (u8)0, |
| 86205 | /* .eSubtype = */ (u8)0, |
| 86206 | /* .db = */ (sqlite3*)0, |
| 86207 | /* .szMalloc = */ (int)0, |
| 86208 | /* .uTemp = */ (u32)0, |
| 86209 | /* .zMalloc = */ (char*)0, |
| 86210 | /* .xDel = */ (void(*)(void*))0, |
| 86211 | #ifdef SQLITE_DEBUG |
| 86212 | /* .pScopyFrom = */ (Mem*)0, |
| 86213 | /* .mScopyFlags= */ 0, |
| 86214 | #endif |
| @@ -90020,11 +90087,11 @@ | |
| 90087 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 90088 | */ |
| 90089 | case OP_Column: { |
| 90090 | u32 p2; /* column number to retrieve */ |
| 90091 | VdbeCursor *pC; /* The VDBE cursor */ |
| 90092 | BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */ |
| 90093 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 90094 | int len; /* The length of the serialized data for the column */ |
| 90095 | int i; /* Loop counter */ |
| 90096 | Mem *pDest; /* Where to write the extracted value */ |
| 90097 | Mem sMem; /* For storing the record being decoded */ |
| @@ -90034,23 +90101,15 @@ | |
| 90101 | u64 offset64; /* 64-bit offset */ |
| 90102 | u32 t; /* A type code from the record header */ |
| 90103 | Mem *pReg; /* PseudoTable input register */ |
| 90104 | |
| 90105 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 90106 | assert( pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor) ); |
| 90107 | pC = p->apCsr[pOp->p1]; |
| 90108 | p2 = (u32)pOp->p2; |
| 90109 | |
| 90110 | op_column_restart: |
| 90111 | assert( pC!=0 ); |
| 90112 | assert( p2<(u32)pC->nField ); |
| 90113 | aOffset = pC->aOffset; |
| 90114 | assert( aOffset==pC->aType+pC->nField ); |
| 90115 | assert( pC->eCurType!=CURTYPE_VTAB ); |
| @@ -90067,30 +90126,43 @@ | |
| 90126 | assert( pReg->flags & MEM_Blob ); |
| 90127 | assert( memIsValid(pReg) ); |
| 90128 | pC->payloadSize = pC->szRow = pReg->n; |
| 90129 | pC->aRow = (u8*)pReg->z; |
| 90130 | }else{ |
| 90131 | pDest = &aMem[pOp->p3]; |
| 90132 | memAboutToChange(p, pDest); |
| 90133 | sqlite3VdbeMemSetNull(pDest); |
| 90134 | goto op_column_out; |
| 90135 | } |
| 90136 | }else{ |
| 90137 | pCrsr = pC->uc.pCursor; |
| 90138 | if( pC->deferredMoveto ){ |
| 90139 | u32 iMap; |
| 90140 | assert( !pC->isEphemeral ); |
| 90141 | if( pC->ub.aAltMap && (iMap = pC->ub.aAltMap[1+p2])>0 ){ |
| 90142 | pC = pC->pAltCursor; |
| 90143 | p2 = iMap - 1; |
| 90144 | goto op_column_restart; |
| 90145 | } |
| 90146 | rc = sqlite3VdbeFinishMoveto(pC); |
| 90147 | if( rc ) goto abort_due_to_error; |
| 90148 | }else if( sqlite3BtreeCursorHasMoved(pCrsr) ){ |
| 90149 | rc = sqlite3VdbeHandleMovedCursor(pC); |
| 90150 | if( rc ) goto abort_due_to_error; |
| 90151 | goto op_column_restart; |
| 90152 | } |
| 90153 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 90154 | assert( pCrsr ); |
| 90155 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 90156 | pC->payloadSize = sqlite3BtreePayloadSize(pCrsr); |
| 90157 | pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow); |
| 90158 | assert( pC->szRow<=pC->payloadSize ); |
| 90159 | assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */ |
| 90160 | } |
| 90161 | pC->cacheStatus = p->cacheCtr; |
| 90162 | pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]); |
| 90163 | pC->nHdrParsed = 0; |
| 90164 | |
| 90165 | if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/ |
| 90166 | /* pC->aRow does not have to hold the entire row, but it does at least |
| 90167 | ** need to cover the header of the record. If pC->aRow does not contain |
| 90168 | ** the complete header, then set it to zero, forcing the header to be |
| @@ -90127,10 +90199,14 @@ | |
| 90199 | zData = pC->aRow; |
| 90200 | assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */ |
| 90201 | testcase( aOffset[0]==0 ); |
| 90202 | goto op_column_read_header; |
| 90203 | } |
| 90204 | }else if( sqlite3BtreeCursorHasMoved(pC->uc.pCursor) ){ |
| 90205 | rc = sqlite3VdbeHandleMovedCursor(pC); |
| 90206 | if( rc ) goto abort_due_to_error; |
| 90207 | goto op_column_restart; |
| 90208 | } |
| 90209 | |
| 90210 | /* Make sure at least the first p2+1 entries of the header have been |
| 90211 | ** parsed and valid information is in aOffset[] and pC->aType[]. |
| 90212 | */ |
| @@ -90195,10 +90271,12 @@ | |
| 90271 | /* If after trying to extract new entries from the header, nHdrParsed is |
| 90272 | ** still not up to p2, that means that the record has fewer than p2 |
| 90273 | ** columns. So the result will be either the default value or a NULL. |
| 90274 | */ |
| 90275 | if( pC->nHdrParsed<=p2 ){ |
| 90276 | pDest = &aMem[pOp->p3]; |
| 90277 | memAboutToChange(p, pDest); |
| 90278 | if( pOp->p4type==P4_MEM ){ |
| 90279 | sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static); |
| 90280 | }else{ |
| 90281 | sqlite3VdbeMemSetNull(pDest); |
| 90282 | } |
| @@ -90212,10 +90290,12 @@ | |
| 90290 | ** reach this point if aOffset[p2], aOffset[p2+1], and pC->aType[p2] are |
| 90291 | ** all valid. |
| 90292 | */ |
| 90293 | assert( p2<pC->nHdrParsed ); |
| 90294 | assert( rc==SQLITE_OK ); |
| 90295 | pDest = &aMem[pOp->p3]; |
| 90296 | memAboutToChange(p, pDest); |
| 90297 | assert( sqlite3VdbeCheckMemInvariants(pDest) ); |
| 90298 | if( VdbeMemDynamic(pDest) ){ |
| 90299 | sqlite3VdbeMemSetNull(pDest); |
| 90300 | } |
| 90301 | assert( t==pC->aType[p2] ); |
| @@ -90232,10 +90312,11 @@ | |
| 90312 | */ |
| 90313 | static const u16 aFlag[] = { MEM_Blob, MEM_Str|MEM_Term }; |
| 90314 | pDest->n = len = (t-12)/2; |
| 90315 | pDest->enc = encoding; |
| 90316 | if( pDest->szMalloc < len+2 ){ |
| 90317 | if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big; |
| 90318 | pDest->flags = MEM_Null; |
| 90319 | if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem; |
| 90320 | }else{ |
| 90321 | pDest->z = pDest->zMalloc; |
| 90322 | } |
| @@ -90264,10 +90345,11 @@ | |
| 90345 | ** as that array is 256 bytes long (plenty for VdbeMemPrettyPrint()) |
| 90346 | ** and it begins with a bunch of zeros. |
| 90347 | */ |
| 90348 | sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest); |
| 90349 | }else{ |
| 90350 | if( len>db->aLimit[SQLITE_LIMIT_LENGTH] ) goto too_big; |
| 90351 | rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); |
| 90352 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 90353 | sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); |
| 90354 | pDest->flags &= ~MEM_Ephem; |
| 90355 | } |
| @@ -90476,11 +90558,10 @@ | |
| 90558 | u32 serial_type; /* Type field */ |
| 90559 | Mem *pData0; /* First field to be combined into the record */ |
| 90560 | Mem *pLast; /* Last field of the record */ |
| 90561 | int nField; /* Number of fields in the record */ |
| 90562 | char *zAffinity; /* The affinity string for the record */ |
| 90563 | u32 len; /* Length of a field */ |
| 90564 | u8 *zHdr; /* Where to write next byte of the header */ |
| 90565 | u8 *zPayload; /* Where to write next byte of the payload */ |
| 90566 | |
| 90567 | /* Assuming the record contains N fields, the record format looks |
| @@ -90505,11 +90586,10 @@ | |
| 90586 | zAffinity = pOp->p4.z; |
| 90587 | assert( nField>0 && pOp->p2>0 && pOp->p2+nField<=(p->nMem+1 - p->nCursor)+1 ); |
| 90588 | pData0 = &aMem[nField]; |
| 90589 | nField = pOp->p2; |
| 90590 | pLast = &pData0[nField-1]; |
| 90591 | |
| 90592 | /* Identify the output register */ |
| 90593 | assert( pOp->p3<pOp->p1 || pOp->p3>=pOp->p1+pOp->p2 ); |
| 90594 | pOut = &aMem[pOp->p3]; |
| 90595 | memAboutToChange(p, pOut); |
| @@ -90607,11 +90687,11 @@ | |
| 90687 | testcase( uu==32767 ); testcase( uu==32768 ); |
| 90688 | testcase( uu==8388607 ); testcase( uu==8388608 ); |
| 90689 | testcase( uu==2147483647 ); testcase( uu==2147483648LL ); |
| 90690 | testcase( uu==140737488355327LL ); testcase( uu==140737488355328LL ); |
| 90691 | if( uu<=127 ){ |
| 90692 | if( (i&1)==i && p->minWriteFileFormat>=4 ){ |
| 90693 | pRec->uTemp = 8+(u32)uu; |
| 90694 | }else{ |
| 90695 | nData++; |
| 90696 | pRec->uTemp = 1; |
| 90697 | } |
| @@ -93070,10 +93150,14 @@ | |
| 93150 | /* Opcode: NullRow P1 * * * * |
| 93151 | ** |
| 93152 | ** Move the cursor P1 to a null row. Any OP_Column operations |
| 93153 | ** that occur while the cursor is on the null row will always |
| 93154 | ** write a NULL. |
| 93155 | ** |
| 93156 | ** Or, if P1 is a Pseudo-Cursor (a cursor opened using OP_OpenPseudo) |
| 93157 | ** just reset the cache for that cursor. This causes the row of |
| 93158 | ** content held by the pseudo-cursor to be reparsed. |
| 93159 | */ |
| 93160 | case OP_NullRow: { |
| 93161 | VdbeCursor *pC; |
| 93162 | |
| 93163 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| @@ -93249,11 +93333,11 @@ | |
| 93333 | VdbeBranchTaken(res!=0,2); |
| 93334 | if( res ) goto jump_to_p2; |
| 93335 | break; |
| 93336 | } |
| 93337 | |
| 93338 | /* Opcode: Next P1 P2 P3 * P5 |
| 93339 | ** |
| 93340 | ** Advance cursor P1 so that it points to the next key/data pair in its |
| 93341 | ** table or index. If there are no more key/value pairs then fall through |
| 93342 | ** to the following instruction. But if the cursor advance was successful, |
| 93343 | ** jump immediately to P2. |
| @@ -93268,19 +93352,16 @@ | |
| 93352 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 93353 | ** means P1 is an SQL index and that this instruction could have been |
| 93354 | ** omitted if that index had been unique. P3 is usually 0. P3 is |
| 93355 | ** always either 0 or 1. |
| 93356 | ** |
| 93357 | ** If P5 is positive and the jump is taken, then event counter |
| 93358 | ** number P5-1 in the prepared statement is incremented. |
| 93359 | ** |
| 93360 | ** See also: Prev |
| 93361 | */ |
| 93362 | /* Opcode: Prev P1 P2 P3 * P5 |
| 93363 | ** |
| 93364 | ** Back up cursor P1 so that it points to the previous key/data pair in its |
| 93365 | ** table or index. If there is no previous key/value pairs then fall through |
| 93366 | ** to the following instruction. But if the cursor backup was successful, |
| 93367 | ** jump immediately to P2. |
| @@ -93296,13 +93377,10 @@ | |
| 93377 | ** The P3 value is a hint to the btree implementation. If P3==1, that |
| 93378 | ** means P1 is an SQL index and that this instruction could have been |
| 93379 | ** omitted if that index had been unique. P3 is usually 0. P3 is |
| 93380 | ** always either 0 or 1. |
| 93381 | ** |
| 93382 | ** If P5 is positive and the jump is taken, then event counter |
| 93383 | ** number P5-1 in the prepared statement is incremented. |
| 93384 | */ |
| 93385 | /* Opcode: SorterNext P1 P2 * * P5 |
| 93386 | ** |
| @@ -93316,34 +93394,37 @@ | |
| 93394 | |
| 93395 | pC = p->apCsr[pOp->p1]; |
| 93396 | assert( isSorter(pC) ); |
| 93397 | rc = sqlite3VdbeSorterNext(db, pC); |
| 93398 | goto next_tail; |
| 93399 | |
| 93400 | case OP_Prev: /* jump */ |
| 93401 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 93402 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 93403 | pC = p->apCsr[pOp->p1]; |
| 93404 | assert( pC!=0 ); |
| 93405 | assert( pC->deferredMoveto==0 ); |
| 93406 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 93407 | assert( pC->seekOp==OP_SeekLT || pC->seekOp==OP_SeekLE |
| 93408 | || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope |
| 93409 | || pC->seekOp==OP_NullRow); |
| 93410 | rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3); |
| 93411 | goto next_tail; |
| 93412 | |
| 93413 | case OP_Next: /* jump */ |
| 93414 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 93415 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 93416 | pC = p->apCsr[pOp->p1]; |
| 93417 | assert( pC!=0 ); |
| 93418 | assert( pC->deferredMoveto==0 ); |
| 93419 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 93420 | assert( pC->seekOp==OP_SeekGT || pC->seekOp==OP_SeekGE |
| 93421 | || pC->seekOp==OP_Rewind || pC->seekOp==OP_Found |
| 93422 | || pC->seekOp==OP_NullRow|| pC->seekOp==OP_SeekRowid |
| 93423 | || pC->seekOp==OP_IfNoHope); |
| 93424 | rc = sqlite3BtreeNext(pC->uc.pCursor, pOp->p3); |
| 93425 | |
| 93426 | next_tail: |
| 93427 | pC->cacheStatus = CACHE_STALE; |
| 93428 | VdbeBranchTaken(rc==SQLITE_OK,2); |
| 93429 | if( rc==SQLITE_OK ){ |
| 93430 | pC->nullRow = 0; |
| @@ -93557,10 +93638,11 @@ | |
| 93638 | assert( pTabCur->uc.pCursor!=0 ); |
| 93639 | assert( pTabCur->isTable ); |
| 93640 | pTabCur->nullRow = 0; |
| 93641 | pTabCur->movetoTarget = rowid; |
| 93642 | pTabCur->deferredMoveto = 1; |
| 93643 | pTabCur->cacheStatus = CACHE_STALE; |
| 93644 | assert( pOp->p4type==P4_INTARRAY || pOp->p4.ai==0 ); |
| 93645 | assert( !pTabCur->isEphemeral ); |
| 93646 | pTabCur->ub.aAltMap = pOp->p4.ai; |
| 93647 | assert( !pC->isEphemeral ); |
| 93648 | pTabCur->pAltCursor = pC; |
| @@ -112069,11 +112151,11 @@ | |
| 112151 | if( pStat1==0 ) return; |
| 112152 | pStat1->zName = (char*)&pStat1[1]; |
| 112153 | memcpy(pStat1->zName, "sqlite_stat1", 13); |
| 112154 | pStat1->nCol = 3; |
| 112155 | pStat1->iPKey = -1; |
| 112156 | sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNAMIC); |
| 112157 | } |
| 112158 | #endif |
| 112159 | |
| 112160 | /* Establish a read-lock on the table at the shared-cache level. |
| 112161 | ** Open a read-only cursor on the table. Also allocate a cursor number |
| @@ -125675,11 +125757,15 @@ | |
| 125757 | ** Then special optimizations can be applied that make the transfer |
| 125758 | ** very fast and which reduce fragmentation of indices. |
| 125759 | ** |
| 125760 | ** This is the 2nd template. |
| 125761 | */ |
| 125762 | if( pColumn==0 |
| 125763 | && pSelect!=0 |
| 125764 | && pTrigger==0 |
| 125765 | && xferOptimization(pParse, pTab, pSelect, onError, iDb) |
| 125766 | ){ |
| 125767 | assert( !pTrigger ); |
| 125768 | assert( pList==0 ); |
| 125769 | goto insert_end; |
| 125770 | } |
| 125771 | #endif /* SQLITE_OMIT_XFER_OPT */ |
| @@ -127646,22 +127732,17 @@ | |
| 127732 | Vdbe *v; /* The VDBE we are building */ |
| 127733 | int regAutoinc; /* Memory register used by AUTOINC */ |
| 127734 | int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */ |
| 127735 | int regData, regRowid; /* Registers holding data and rowid */ |
| 127736 | |
| 127737 | assert( pSelect!=0 ); |
| 127738 | if( pParse->pWith || pSelect->pWith ){ |
| 127739 | /* Do not attempt to process this query if there are an WITH clauses |
| 127740 | ** attached to it. Proceeding may generate a false "no such table: xxx" |
| 127741 | ** error if pSelect reads from a CTE named "xxx". */ |
| 127742 | return 0; |
| 127743 | } |
| 127744 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 127745 | if( IsVirtual(pDest) ){ |
| 127746 | return 0; /* tab1 must not be a virtual table */ |
| 127747 | } |
| 127748 | #endif |
| @@ -130011,11 +130092,11 @@ | |
| 130092 | /* iArg: */ BTREE_DATA_VERSION }, |
| 130093 | #endif |
| 130094 | #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) |
| 130095 | {/* zName: */ "database_list", |
| 130096 | /* ePragTyp: */ PragTyp_DATABASE_LIST, |
| 130097 | /* ePragFlg: */ PragFlg_Result0, |
| 130098 | /* ColNames: */ 47, 3, |
| 130099 | /* iArg: */ 0 }, |
| 130100 | #endif |
| 130101 | #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED) |
| 130102 | {/* zName: */ "default_cache_size", |
| @@ -130699,19 +130780,20 @@ | |
| 130780 | Vdbe *v, /* The prepared statement being created */ |
| 130781 | FuncDef *p, /* A particular function definition */ |
| 130782 | int isBuiltin, /* True if this is a built-in function */ |
| 130783 | int showInternFuncs /* True if showing internal functions */ |
| 130784 | ){ |
| 130785 | u32 mask = |
| 130786 | SQLITE_DETERMINISTIC | |
| 130787 | SQLITE_DIRECTONLY | |
| 130788 | SQLITE_SUBTYPE | |
| 130789 | SQLITE_INNOCUOUS | |
| 130790 | SQLITE_FUNC_INTERNAL |
| 130791 | ; |
| 130792 | if( showInternFuncs ) mask = 0xffffffff; |
| 130793 | for(; p; p=p->pNext){ |
| 130794 | const char *zType; |
| 130795 | static const char *azEnc[] = { 0, "utf8", "utf16le", "utf16be" }; |
| 130796 | |
| 130797 | assert( SQLITE_FUNC_ENCMASK==0x3 ); |
| 130798 | assert( strcmp(azEnc[SQLITE_UTF8],"utf8")==0 ); |
| 130799 | assert( strcmp(azEnc[SQLITE_UTF16LE],"utf16le")==0 ); |
| @@ -148508,18 +148590,26 @@ | |
| 148590 | ** rowid stored in register iRowid. |
| 148591 | ** |
| 148592 | ** Normally, this is just: |
| 148593 | ** |
| 148594 | ** OP_DeferredSeek $iCur $iRowid |
| 148595 | ** |
| 148596 | ** Which causes a seek on $iCur to the row with rowid $iRowid. |
| 148597 | ** |
| 148598 | ** However, if the scan currently being coded is a branch of an OR-loop and |
| 148599 | ** the statement currently being coded is a SELECT, then additional information |
| 148600 | ** is added that might allow OP_Column to omit the seek and instead do its |
| 148601 | ** lookup on the index, thus avoiding an expensive seek operation. To |
| 148602 | ** enable this optimization, the P3 of OP_DeferredSeek is set to iIdxCur |
| 148603 | ** and P4 is set to an array of integers containing one entry for each column |
| 148604 | ** in the table. For each table column, if the column is the i'th |
| 148605 | ** column of the index, then the corresponding array entry is set to (i+1). |
| 148606 | ** If the column does not appear in the index at all, the array entry is set |
| 148607 | ** to 0. The OP_Column opcode can check this array to see if the column it |
| 148608 | ** wants is in the index and if it is, it will substitute the index cursor |
| 148609 | ** and column number and continue with those new values, rather than seeking |
| 148610 | ** the table cursor. |
| 148611 | */ |
| 148612 | static void codeDeferredSeek( |
| 148613 | WhereInfo *pWInfo, /* Where clause context */ |
| 148614 | Index *pIdx, /* Index scan is using */ |
| 148615 | int iCur, /* Cursor for IPK b-tree */ |
| @@ -234298,11 +234388,11 @@ | |
| 234388 | int nArg, /* Number of args */ |
| 234389 | sqlite3_value **apUnused /* Function arguments */ |
| 234390 | ){ |
| 234391 | assert( nArg==0 ); |
| 234392 | UNUSED_PARAM2(nArg, apUnused); |
| 234393 | sqlite3_result_text(pCtx, "fts5: 2022-03-02 01:02:16 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b", -1, SQLITE_TRANSIENT); |
| 234394 | } |
| 234395 | |
| 234396 | /* |
| 234397 | ** Return true if zName is the extension on one of the shadow tables used |
| 234398 | ** by this module. |
| 234399 |
+4
-4
| --- extsrc/sqlite3.h | ||
| +++ extsrc/sqlite3.h | ||
| @@ -144,13 +144,13 @@ | ||
| 144 | 144 | ** |
| 145 | 145 | ** See also: [sqlite3_libversion()], |
| 146 | 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | 148 | */ |
| 149 | -#define SQLITE_VERSION "3.38.0" | |
| 150 | -#define SQLITE_VERSION_NUMBER 3038000 | |
| 151 | -#define SQLITE_SOURCE_ID "2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab" | |
| 149 | +#define SQLITE_VERSION "3.39.0" | |
| 150 | +#define SQLITE_VERSION_NUMBER 3039000 | |
| 151 | +#define SQLITE_SOURCE_ID "2022-03-02 01:02:16 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b" | |
| 152 | 152 | |
| 153 | 153 | /* |
| 154 | 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | 156 | ** |
| @@ -9765,11 +9765,11 @@ | ||
| 9765 | 9765 | ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value |
| 9766 | 9766 | ** and remains valid for the duration of the xBestIndex method call. |
| 9767 | 9767 | ** ^When xBestIndex returns, the sqlite3_value object returned by |
| 9768 | 9768 | ** sqlite3_vtab_rhs_value() is automatically deallocated. |
| 9769 | 9769 | ** |
| 9770 | -** The "_rhs_" in the name of this routine is an appreviation for | |
| 9770 | +** The "_rhs_" in the name of this routine is an abbreviation for | |
| 9771 | 9771 | ** "Right-Hand Side". |
| 9772 | 9772 | */ |
| 9773 | 9773 | SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); |
| 9774 | 9774 | |
| 9775 | 9775 | /* |
| 9776 | 9776 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -144,13 +144,13 @@ | |
| 144 | ** |
| 145 | ** See also: [sqlite3_libversion()], |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.38.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3038000 |
| 151 | #define SQLITE_SOURCE_ID "2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab" |
| 152 | |
| 153 | /* |
| 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | ** |
| @@ -9765,11 +9765,11 @@ | |
| 9765 | ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value |
| 9766 | ** and remains valid for the duration of the xBestIndex method call. |
| 9767 | ** ^When xBestIndex returns, the sqlite3_value object returned by |
| 9768 | ** sqlite3_vtab_rhs_value() is automatically deallocated. |
| 9769 | ** |
| 9770 | ** The "_rhs_" in the name of this routine is an appreviation for |
| 9771 | ** "Right-Hand Side". |
| 9772 | */ |
| 9773 | SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); |
| 9774 | |
| 9775 | /* |
| 9776 |
| --- extsrc/sqlite3.h | |
| +++ extsrc/sqlite3.h | |
| @@ -144,13 +144,13 @@ | |
| 144 | ** |
| 145 | ** See also: [sqlite3_libversion()], |
| 146 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 147 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 148 | */ |
| 149 | #define SQLITE_VERSION "3.39.0" |
| 150 | #define SQLITE_VERSION_NUMBER 3039000 |
| 151 | #define SQLITE_SOURCE_ID "2022-03-02 01:02:16 6497997aa80419688890ed5dbbb7d6acc26bf3732305ff4a728cba1fe4d1626b" |
| 152 | |
| 153 | /* |
| 154 | ** CAPI3REF: Run-Time Library Version Numbers |
| 155 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 156 | ** |
| @@ -9765,11 +9765,11 @@ | |
| 9765 | ** ^The [sqlite3_value] object returned in *V is a protected sqlite3_value |
| 9766 | ** and remains valid for the duration of the xBestIndex method call. |
| 9767 | ** ^When xBestIndex returns, the sqlite3_value object returned by |
| 9768 | ** sqlite3_vtab_rhs_value() is automatically deallocated. |
| 9769 | ** |
| 9770 | ** The "_rhs_" in the name of this routine is an abbreviation for |
| 9771 | ** "Right-Hand Side". |
| 9772 | */ |
| 9773 | SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal); |
| 9774 | |
| 9775 | /* |
| 9776 |