| | @@ -381,11 +381,11 @@ |
| 381 | 381 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 382 | 382 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 383 | 383 | */ |
| 384 | 384 | #define SQLITE_VERSION "3.16.0" |
| 385 | 385 | #define SQLITE_VERSION_NUMBER 3016000 |
| 386 | | -#define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9" |
| 386 | +#define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5" |
| 387 | 387 | |
| 388 | 388 | /* |
| 389 | 389 | ** CAPI3REF: Run-Time Library Version Numbers |
| 390 | 390 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 391 | 391 | ** |
| | @@ -3868,10 +3868,14 @@ |
| 3868 | 3868 | ** rather they control the timing of when other statements modify the |
| 3869 | 3869 | ** database. ^The [ATTACH] and [DETACH] statements also cause |
| 3870 | 3870 | ** sqlite3_stmt_readonly() to return true since, while those statements |
| 3871 | 3871 | ** change the configuration of a database connection, they do not make |
| 3872 | 3872 | ** changes to the content of the database files on disk. |
| 3873 | +** ^The sqlite3_stmt_readonly() interface returns true for [BEGIN] since |
| 3874 | +** [BEGIN] merely sets internal flags, but the [BEGIN|BEGIN IMMEDIATE] and |
| 3875 | +** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so |
| 3876 | +** sqlite3_stmt_readonly() returns false for those commands. |
| 3873 | 3877 | */ |
| 3874 | 3878 | SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); |
| 3875 | 3879 | |
| 3876 | 3880 | /* |
| 3877 | 3881 | ** CAPI3REF: Determine If A Prepared Statement Has Been Reset |
| | @@ -8517,11 +8521,11 @@ |
| 8517 | 8521 | */ |
| 8518 | 8522 | SQLITE_API int sqlite3_system_errno(sqlite3*); |
| 8519 | 8523 | |
| 8520 | 8524 | /* |
| 8521 | 8525 | ** CAPI3REF: Database Snapshot |
| 8522 | | -** KEYWORDS: {snapshot} |
| 8526 | +** KEYWORDS: {snapshot} {sqlite3_snapshot} |
| 8523 | 8527 | ** EXPERIMENTAL |
| 8524 | 8528 | ** |
| 8525 | 8529 | ** An instance of the snapshot object records the state of a [WAL mode] |
| 8526 | 8530 | ** database for some specific point in history. |
| 8527 | 8531 | ** |
| | @@ -8541,11 +8545,13 @@ |
| 8541 | 8545 | ** The constructor for this object is [sqlite3_snapshot_get()]. The |
| 8542 | 8546 | ** [sqlite3_snapshot_open()] method causes a fresh read transaction to refer |
| 8543 | 8547 | ** to an historical snapshot (if possible). The destructor for |
| 8544 | 8548 | ** sqlite3_snapshot objects is [sqlite3_snapshot_free()]. |
| 8545 | 8549 | */ |
| 8546 | | -typedef struct sqlite3_snapshot sqlite3_snapshot; |
| 8550 | +typedef struct sqlite3_snapshot { |
| 8551 | + unsigned char hidden[48]; |
| 8552 | +} sqlite3_snapshot; |
| 8547 | 8553 | |
| 8548 | 8554 | /* |
| 8549 | 8555 | ** CAPI3REF: Record A Database Snapshot |
| 8550 | 8556 | ** EXPERIMENTAL |
| 8551 | 8557 | ** |
| | @@ -8552,13 +8558,36 @@ |
| 8552 | 8558 | ** ^The [sqlite3_snapshot_get(D,S,P)] interface attempts to make a |
| 8553 | 8559 | ** new [sqlite3_snapshot] object that records the current state of |
| 8554 | 8560 | ** schema S in database connection D. ^On success, the |
| 8555 | 8561 | ** [sqlite3_snapshot_get(D,S,P)] interface writes a pointer to the newly |
| 8556 | 8562 | ** created [sqlite3_snapshot] object into *P and returns SQLITE_OK. |
| 8557 | | -** ^If schema S of [database connection] D is not a [WAL mode] database |
| 8558 | | -** that is in a read transaction, then [sqlite3_snapshot_get(D,S,P)] |
| 8559 | | -** leaves the *P value unchanged and returns an appropriate [error code]. |
| 8563 | +** If there is not already a read-transaction open on schema S when |
| 8564 | +** this function is called, one is opened automatically. |
| 8565 | +** |
| 8566 | +** The following must be true for this function to succeed. If any of |
| 8567 | +** the following statements are false when sqlite3_snapshot_get() is |
| 8568 | +** called, SQLITE_ERROR is returned. The final value of *P is undefined |
| 8569 | +** in this case. |
| 8570 | +** |
| 8571 | +** <ul> |
| 8572 | +** <li> The database handle must be in [autocommit mode]. |
| 8573 | +** |
| 8574 | +** <li> Schema S of [database connection] D must be a [WAL mode] database. |
| 8575 | +** |
| 8576 | +** <li> There must not be a write transaction open on schema S of database |
| 8577 | +** connection D. |
| 8578 | +** |
| 8579 | +** <li> One or more transactions must have been written to the current wal |
| 8580 | +** file since it was created on disk (by any connection). This means |
| 8581 | +** that a snapshot cannot be taken on a wal mode database with no wal |
| 8582 | +** file immediately after it is first opened. At least one transaction |
| 8583 | +** must be written to it first. |
| 8584 | +** </ul> |
| 8585 | +** |
| 8586 | +** This function may also return SQLITE_NOMEM. If it is called with the |
| 8587 | +** database handle in autocommit mode but fails for some other reason, |
| 8588 | +** whether or not a read transaction is opened on schema S is undefined. |
| 8560 | 8589 | ** |
| 8561 | 8590 | ** The [sqlite3_snapshot] object returned from a successful call to |
| 8562 | 8591 | ** [sqlite3_snapshot_get()] must be freed using [sqlite3_snapshot_free()] |
| 8563 | 8592 | ** to avoid a memory leak. |
| 8564 | 8593 | ** |
| | @@ -8647,10 +8676,32 @@ |
| 8647 | 8676 | SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_cmp( |
| 8648 | 8677 | sqlite3_snapshot *p1, |
| 8649 | 8678 | sqlite3_snapshot *p2 |
| 8650 | 8679 | ); |
| 8651 | 8680 | |
| 8681 | +/* |
| 8682 | +** CAPI3REF: Recover snapshots from a wal file |
| 8683 | +** EXPERIMENTAL |
| 8684 | +** |
| 8685 | +** If all connections disconnect from a database file but do not perform |
| 8686 | +** a checkpoint, the existing wal file is opened along with the database |
| 8687 | +** file the next time the database is opened. At this point it is only |
| 8688 | +** possible to successfully call sqlite3_snapshot_open() to open the most |
| 8689 | +** recent snapshot of the database (the one at the head of the wal file), |
| 8690 | +** even though the wal file may contain other valid snapshots for which |
| 8691 | +** clients have sqlite3_snapshot handles. |
| 8692 | +** |
| 8693 | +** This function attempts to scan the wal file associated with database zDb |
| 8694 | +** of database handle db and make all valid snapshots available to |
| 8695 | +** sqlite3_snapshot_open(). It is an error if there is already a read |
| 8696 | +** transaction open on the database, or if the database is not a wal mode |
| 8697 | +** database. |
| 8698 | +** |
| 8699 | +** SQLITE_OK is returned if successful, or an SQLite error code otherwise. |
| 8700 | +*/ |
| 8701 | +SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb); |
| 8702 | + |
| 8652 | 8703 | /* |
| 8653 | 8704 | ** Undo the hack that converts floating point types to integer for |
| 8654 | 8705 | ** builds on processors without floating point support. |
| 8655 | 8706 | */ |
| 8656 | 8707 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| | @@ -12323,19 +12374,19 @@ |
| 12323 | 12374 | SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes); |
| 12324 | 12375 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes); |
| 12325 | 12376 | SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); |
| 12326 | 12377 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes); |
| 12327 | 12378 | SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*); |
| 12328 | | -SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*); |
| 12379 | +SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor*, u32 offset, u32 amt, void*); |
| 12329 | 12380 | SQLITE_PRIVATE const void *sqlite3BtreePayloadFetch(BtCursor*, u32 *pAmt); |
| 12330 | 12381 | SQLITE_PRIVATE u32 sqlite3BtreePayloadSize(BtCursor*); |
| 12331 | | -SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*); |
| 12332 | 12382 | |
| 12333 | 12383 | SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*); |
| 12334 | 12384 | SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*); |
| 12335 | 12385 | |
| 12336 | 12386 | #ifndef SQLITE_OMIT_INCRBLOB |
| 12387 | +SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor*, u32 offset, u32 amt, void*); |
| 12337 | 12388 | SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*); |
| 12338 | 12389 | SQLITE_PRIVATE void sqlite3BtreeIncrblobCursor(BtCursor *); |
| 12339 | 12390 | #endif |
| 12340 | 12391 | SQLITE_PRIVATE void sqlite3BtreeClearCursor(BtCursor *); |
| 12341 | 12392 | SQLITE_PRIVATE int sqlite3BtreeSetVersion(Btree *pBt, int iVersion); |
| | @@ -12518,26 +12569,25 @@ |
| 12518 | 12569 | ** Allowed values of VdbeOp.p4type |
| 12519 | 12570 | */ |
| 12520 | 12571 | #define P4_NOTUSED 0 /* The P4 parameter is not used */ |
| 12521 | 12572 | #define P4_DYNAMIC (-1) /* Pointer to a string obtained from sqliteMalloc() */ |
| 12522 | 12573 | #define P4_STATIC (-2) /* Pointer to a static string */ |
| 12523 | | -#define P4_COLLSEQ (-4) /* P4 is a pointer to a CollSeq structure */ |
| 12524 | | -#define P4_FUNCDEF (-5) /* P4 is a pointer to a FuncDef structure */ |
| 12525 | | -#define P4_KEYINFO (-6) /* P4 is a pointer to a KeyInfo structure */ |
| 12526 | | -#define P4_EXPR (-7) /* P4 is a pointer to an Expr tree */ |
| 12527 | | -#define P4_MEM (-8) /* P4 is a pointer to a Mem* structure */ |
| 12574 | +#define P4_COLLSEQ (-3) /* P4 is a pointer to a CollSeq structure */ |
| 12575 | +#define P4_FUNCDEF (-4) /* P4 is a pointer to a FuncDef structure */ |
| 12576 | +#define P4_KEYINFO (-5) /* P4 is a pointer to a KeyInfo structure */ |
| 12577 | +#define P4_EXPR (-6) /* P4 is a pointer to an Expr tree */ |
| 12578 | +#define P4_MEM (-7) /* P4 is a pointer to a Mem* structure */ |
| 12528 | 12579 | #define P4_TRANSIENT 0 /* P4 is a pointer to a transient string */ |
| 12529 | | -#define P4_VTAB (-10) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 12530 | | -#define P4_MPRINTF (-11) /* P4 is a string obtained from sqlite3_mprintf() */ |
| 12531 | | -#define P4_REAL (-12) /* P4 is a 64-bit floating point value */ |
| 12532 | | -#define P4_INT64 (-13) /* P4 is a 64-bit signed integer */ |
| 12533 | | -#define P4_INT32 (-14) /* P4 is a 32-bit signed integer */ |
| 12534 | | -#define P4_INTARRAY (-15) /* P4 is a vector of 32-bit integers */ |
| 12535 | | -#define P4_SUBPROGRAM (-18) /* P4 is a pointer to a SubProgram structure */ |
| 12536 | | -#define P4_ADVANCE (-19) /* P4 is a pointer to BtreeNext() or BtreePrev() */ |
| 12537 | | -#define P4_TABLE (-20) /* P4 is a pointer to a Table structure */ |
| 12538 | | -#define P4_FUNCCTX (-21) /* P4 is a pointer to an sqlite3_context object */ |
| 12580 | +#define P4_VTAB (-8) /* P4 is a pointer to an sqlite3_vtab structure */ |
| 12581 | +#define P4_REAL (-9) /* P4 is a 64-bit floating point value */ |
| 12582 | +#define P4_INT64 (-10) /* P4 is a 64-bit signed integer */ |
| 12583 | +#define P4_INT32 (-11) /* P4 is a 32-bit signed integer */ |
| 12584 | +#define P4_INTARRAY (-12) /* P4 is a vector of 32-bit integers */ |
| 12585 | +#define P4_SUBPROGRAM (-13) /* P4 is a pointer to a SubProgram structure */ |
| 12586 | +#define P4_ADVANCE (-14) /* P4 is a pointer to BtreeNext() or BtreePrev() */ |
| 12587 | +#define P4_TABLE (-15) /* P4 is a pointer to a Table structure */ |
| 12588 | +#define P4_FUNCCTX (-16) /* P4 is a pointer to an sqlite3_context object */ |
| 12539 | 12589 | |
| 12540 | 12590 | /* Error message codes for OP_Halt */ |
| 12541 | 12591 | #define P5_ConstraintNotNull 1 |
| 12542 | 12592 | #define P5_ConstraintUnique 2 |
| 12543 | 12593 | #define P5_ConstraintCheck 3 |
| | @@ -12697,52 +12747,51 @@ |
| 12697 | 12747 | #define OP_InsertInt 116 /* synopsis: intkey=P3 data=r[P2] */ |
| 12698 | 12748 | #define OP_Delete 117 |
| 12699 | 12749 | #define OP_ResetCount 118 |
| 12700 | 12750 | #define OP_SorterCompare 119 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */ |
| 12701 | 12751 | #define OP_SorterData 120 /* synopsis: r[P2]=data */ |
| 12702 | | -#define OP_RowKey 121 /* synopsis: r[P2]=key */ |
| 12703 | | -#define OP_RowData 122 /* synopsis: r[P2]=data */ |
| 12704 | | -#define OP_Rowid 123 /* synopsis: r[P2]=rowid */ |
| 12705 | | -#define OP_NullRow 124 |
| 12706 | | -#define OP_SorterInsert 125 /* synopsis: key=r[P2] */ |
| 12707 | | -#define OP_IdxInsert 126 /* synopsis: key=r[P2] */ |
| 12708 | | -#define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */ |
| 12709 | | -#define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */ |
| 12710 | | -#define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */ |
| 12711 | | -#define OP_Destroy 130 |
| 12712 | | -#define OP_Clear 131 |
| 12752 | +#define OP_RowData 121 /* synopsis: r[P2]=data */ |
| 12753 | +#define OP_Rowid 122 /* synopsis: r[P2]=rowid */ |
| 12754 | +#define OP_NullRow 123 |
| 12755 | +#define OP_SorterInsert 124 /* synopsis: key=r[P2] */ |
| 12756 | +#define OP_IdxInsert 125 /* synopsis: key=r[P2] */ |
| 12757 | +#define OP_IdxDelete 126 /* synopsis: key=r[P2@P3] */ |
| 12758 | +#define OP_Seek 127 /* synopsis: Move P3 to P1.rowid */ |
| 12759 | +#define OP_IdxRowid 128 /* synopsis: r[P2]=rowid */ |
| 12760 | +#define OP_Destroy 129 |
| 12761 | +#define OP_Clear 130 |
| 12762 | +#define OP_ResetSorter 131 |
| 12713 | 12763 | #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 12714 | | -#define OP_ResetSorter 133 |
| 12715 | | -#define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */ |
| 12716 | | -#define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */ |
| 12717 | | -#define OP_ParseSchema 136 |
| 12718 | | -#define OP_LoadAnalysis 137 |
| 12719 | | -#define OP_DropTable 138 |
| 12720 | | -#define OP_DropIndex 139 |
| 12721 | | -#define OP_DropTrigger 140 |
| 12722 | | -#define OP_IntegrityCk 141 |
| 12723 | | -#define OP_RowSetAdd 142 /* synopsis: rowset(P1)=r[P2] */ |
| 12724 | | -#define OP_Param 143 |
| 12725 | | -#define OP_FkCounter 144 /* synopsis: fkctr[P1]+=P2 */ |
| 12726 | | -#define OP_MemMax 145 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 12727 | | -#define OP_OffsetLimit 146 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 12728 | | -#define OP_AggStep0 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12729 | | -#define OP_AggStep 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12730 | | -#define OP_AggFinal 149 /* synopsis: accum=r[P1] N=P2 */ |
| 12731 | | -#define OP_Expire 150 |
| 12732 | | -#define OP_TableLock 151 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 12733 | | -#define OP_VBegin 152 |
| 12734 | | -#define OP_VCreate 153 |
| 12735 | | -#define OP_VDestroy 154 |
| 12736 | | -#define OP_VOpen 155 |
| 12737 | | -#define OP_VColumn 156 /* synopsis: r[P3]=vcolumn(P2) */ |
| 12738 | | -#define OP_VRename 157 |
| 12739 | | -#define OP_Pagecount 158 |
| 12740 | | -#define OP_MaxPgcnt 159 |
| 12741 | | -#define OP_CursorHint 160 |
| 12742 | | -#define OP_Noop 161 |
| 12743 | | -#define OP_Explain 162 |
| 12764 | +#define OP_CreateIndex 133 /* synopsis: r[P2]=root iDb=P1 */ |
| 12765 | +#define OP_CreateTable 134 /* synopsis: r[P2]=root iDb=P1 */ |
| 12766 | +#define OP_ParseSchema 135 |
| 12767 | +#define OP_LoadAnalysis 136 |
| 12768 | +#define OP_DropTable 137 |
| 12769 | +#define OP_DropIndex 138 |
| 12770 | +#define OP_DropTrigger 139 |
| 12771 | +#define OP_IntegrityCk 140 |
| 12772 | +#define OP_RowSetAdd 141 /* synopsis: rowset(P1)=r[P2] */ |
| 12773 | +#define OP_Param 142 |
| 12774 | +#define OP_FkCounter 143 /* synopsis: fkctr[P1]+=P2 */ |
| 12775 | +#define OP_MemMax 144 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 12776 | +#define OP_OffsetLimit 145 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */ |
| 12777 | +#define OP_AggStep0 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12778 | +#define OP_AggStep 147 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 12779 | +#define OP_AggFinal 148 /* synopsis: accum=r[P1] N=P2 */ |
| 12780 | +#define OP_Expire 149 |
| 12781 | +#define OP_TableLock 150 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 12782 | +#define OP_VBegin 151 |
| 12783 | +#define OP_VCreate 152 |
| 12784 | +#define OP_VDestroy 153 |
| 12785 | +#define OP_VOpen 154 |
| 12786 | +#define OP_VColumn 155 /* synopsis: r[P3]=vcolumn(P2) */ |
| 12787 | +#define OP_VRename 156 |
| 12788 | +#define OP_Pagecount 157 |
| 12789 | +#define OP_MaxPgcnt 158 |
| 12790 | +#define OP_CursorHint 159 |
| 12791 | +#define OP_Noop 160 |
| 12792 | +#define OP_Explain 161 |
| 12744 | 12793 | |
| 12745 | 12794 | /* Properties such as "out2" or "jump" that are specified in |
| 12746 | 12795 | ** comments following the "case" for each opcode in the vdbe.c |
| 12747 | 12796 | ** are encoded into bitvectors as follows: |
| 12748 | 12797 | */ |
| | @@ -12766,16 +12815,16 @@ |
| 12766 | 12815 | /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 12767 | 12816 | /* 88 */ 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\ |
| 12768 | 12817 | /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\ |
| 12769 | 12818 | /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12770 | 12819 | /* 112 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12771 | | -/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\ |
| 12772 | | -/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\ |
| 12773 | | -/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10,\ |
| 12774 | | -/* 144 */ 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12775 | | -/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\ |
| 12776 | | -/* 160 */ 0x00, 0x00, 0x00,} |
| 12820 | +/* 120 */ 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00,\ |
| 12821 | +/* 128 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00,\ |
| 12822 | +/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00,\ |
| 12823 | +/* 144 */ 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 12824 | +/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\ |
| 12825 | +/* 160 */ 0x00, 0x00,} |
| 12777 | 12826 | |
| 12778 | 12827 | /* The sqlite3P2Values() routine is able to run faster if it knows |
| 12779 | 12828 | ** the value of the largest JUMP opcode. The smaller the maximum |
| 12780 | 12829 | ** JUMP opcode the better, so the mkopcodeh.tcl script that |
| 12781 | 12830 | ** generated this include file strives to group all JUMP opcodes |
| | @@ -12816,10 +12865,11 @@ |
| 12816 | 12865 | SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5); |
| 12817 | 12866 | SQLITE_PRIVATE void sqlite3VdbeJumpHere(Vdbe*, int addr); |
| 12818 | 12867 | SQLITE_PRIVATE int sqlite3VdbeChangeToNoop(Vdbe*, int addr); |
| 12819 | 12868 | SQLITE_PRIVATE int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op); |
| 12820 | 12869 | SQLITE_PRIVATE void sqlite3VdbeChangeP4(Vdbe*, int addr, const char *zP4, int N); |
| 12870 | +SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe*, void *pP4, int p4type); |
| 12821 | 12871 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse*, Index*); |
| 12822 | 12872 | SQLITE_PRIVATE void sqlite3VdbeUsesBtree(Vdbe*, int); |
| 12823 | 12873 | SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe*, int); |
| 12824 | 12874 | SQLITE_PRIVATE int sqlite3VdbeMakeLabel(Vdbe*); |
| 12825 | 12875 | SQLITE_PRIVATE void sqlite3VdbeRunOnlyOnce(Vdbe*); |
| | @@ -13116,10 +13166,11 @@ |
| 13116 | 13166 | SQLITE_PRIVATE int sqlite3PagerCloseWal(Pager *pPager, sqlite3*); |
| 13117 | 13167 | SQLITE_PRIVATE int sqlite3PagerUseWal(Pager *pPager); |
| 13118 | 13168 | # ifdef SQLITE_ENABLE_SNAPSHOT |
| 13119 | 13169 | SQLITE_PRIVATE int sqlite3PagerSnapshotGet(Pager *pPager, sqlite3_snapshot **ppSnapshot); |
| 13120 | 13170 | SQLITE_PRIVATE int sqlite3PagerSnapshotOpen(Pager *pPager, sqlite3_snapshot *pSnapshot); |
| 13171 | +SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager); |
| 13121 | 13172 | # endif |
| 13122 | 13173 | #else |
| 13123 | 13174 | # define sqlite3PagerUseWal(x) 0 |
| 13124 | 13175 | #endif |
| 13125 | 13176 | |
| | @@ -14115,17 +14166,12 @@ |
| 14115 | 14166 | #define SQLITE_AllOpts 0xffff /* All optimizations */ |
| 14116 | 14167 | |
| 14117 | 14168 | /* |
| 14118 | 14169 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 14119 | 14170 | */ |
| 14120 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 14121 | 14171 | #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0) |
| 14122 | 14172 | #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0) |
| 14123 | | -#else |
| 14124 | | -#define OptimizationDisabled(db, mask) 0 |
| 14125 | | -#define OptimizationEnabled(db, mask) 1 |
| 14126 | | -#endif |
| 14127 | 14173 | |
| 14128 | 14174 | /* |
| 14129 | 14175 | ** Return true if it OK to factor constant expressions into the initialization |
| 14130 | 14176 | ** code. The argument is a Parse object for the code generator. |
| 14131 | 14177 | */ |
| | @@ -15891,11 +15937,11 @@ |
| 15891 | 15937 | ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE. |
| 15892 | 15938 | */ |
| 15893 | 15939 | void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */ |
| 15894 | 15940 | void *pVdbeBranchArg; /* 1st argument */ |
| 15895 | 15941 | #endif |
| 15896 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 15942 | +#ifndef SQLITE_UNTESTABLE |
| 15897 | 15943 | int (*xTestCallback)(int); /* Invoked by sqlite3FaultSim() */ |
| 15898 | 15944 | #endif |
| 15899 | 15945 | int bLocaltimeFault; /* True to fail localtime() calls */ |
| 15900 | 15946 | int iOnceResetThreshold; /* When to reset OP_Once counters */ |
| 15901 | 15947 | }; |
| | @@ -16095,11 +16141,11 @@ |
| 16095 | 16141 | SQLITE_PRIVATE void *sqlite3ScratchMalloc(int); |
| 16096 | 16142 | SQLITE_PRIVATE void sqlite3ScratchFree(void*); |
| 16097 | 16143 | SQLITE_PRIVATE void *sqlite3PageMalloc(int); |
| 16098 | 16144 | SQLITE_PRIVATE void sqlite3PageFree(void*); |
| 16099 | 16145 | SQLITE_PRIVATE void sqlite3MemSetDefault(void); |
| 16100 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 16146 | +#ifndef SQLITE_UNTESTABLE |
| 16101 | 16147 | SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void)); |
| 16102 | 16148 | #endif |
| 16103 | 16149 | SQLITE_PRIVATE int sqlite3HeapNearlyFull(void); |
| 16104 | 16150 | |
| 16105 | 16151 | /* |
| | @@ -16206,11 +16252,11 @@ |
| 16206 | 16252 | SQLITE_PRIVATE int sqlite3NoTempsInRange(Parse*,int,int); |
| 16207 | 16253 | #endif |
| 16208 | 16254 | SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int); |
| 16209 | 16255 | SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*); |
| 16210 | 16256 | SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*); |
| 16211 | | -SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*); |
| 16257 | +SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*); |
| 16212 | 16258 | SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*); |
| 16213 | 16259 | SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*); |
| 16214 | 16260 | SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*); |
| 16215 | 16261 | SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*, u32); |
| 16216 | 16262 | SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*); |
| | @@ -16250,11 +16296,11 @@ |
| 16250 | 16296 | SQLITE_PRIVATE void sqlite3EndTable(Parse*,Token*,Token*,u8,Select*); |
| 16251 | 16297 | SQLITE_PRIVATE int sqlite3ParseUri(const char*,const char*,unsigned int*, |
| 16252 | 16298 | sqlite3_vfs**,char**,char **); |
| 16253 | 16299 | SQLITE_PRIVATE Btree *sqlite3DbNameToBtree(sqlite3*,const char*); |
| 16254 | 16300 | |
| 16255 | | -#ifdef SQLITE_OMIT_BUILTIN_TEST |
| 16301 | +#ifdef SQLITE_UNTESTABLE |
| 16256 | 16302 | # define sqlite3FaultSim(X) SQLITE_OK |
| 16257 | 16303 | #else |
| 16258 | 16304 | SQLITE_PRIVATE int sqlite3FaultSim(int); |
| 16259 | 16305 | #endif |
| 16260 | 16306 | |
| | @@ -16263,11 +16309,11 @@ |
| 16263 | 16309 | SQLITE_PRIVATE int sqlite3BitvecTestNotNull(Bitvec*, u32); |
| 16264 | 16310 | SQLITE_PRIVATE int sqlite3BitvecSet(Bitvec*, u32); |
| 16265 | 16311 | SQLITE_PRIVATE void sqlite3BitvecClear(Bitvec*, u32, void*); |
| 16266 | 16312 | SQLITE_PRIVATE void sqlite3BitvecDestroy(Bitvec*); |
| 16267 | 16313 | SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec*); |
| 16268 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 16314 | +#ifndef SQLITE_UNTESTABLE |
| 16269 | 16315 | SQLITE_PRIVATE int sqlite3BitvecBuiltinTest(int,int*); |
| 16270 | 16316 | #endif |
| 16271 | 16317 | |
| 16272 | 16318 | SQLITE_PRIVATE RowSet *sqlite3RowSetInit(sqlite3*, void*, unsigned int); |
| 16273 | 16319 | SQLITE_PRIVATE void sqlite3RowSetClear(RowSet*); |
| | @@ -16383,11 +16429,11 @@ |
| 16383 | 16429 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 16384 | 16430 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 16385 | 16431 | SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx); |
| 16386 | 16432 | SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 16387 | 16433 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 16388 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 16434 | +#ifndef SQLITE_UNTESTABLE |
| 16389 | 16435 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 16390 | 16436 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 16391 | 16437 | #endif |
| 16392 | 16438 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| 16393 | 16439 | SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse*, int); |
| | @@ -16811,14 +16857,14 @@ |
| 16811 | 16857 | #define SQLITE_FAULTINJECTOR_MALLOC 0 |
| 16812 | 16858 | #define SQLITE_FAULTINJECTOR_COUNT 1 |
| 16813 | 16859 | |
| 16814 | 16860 | /* |
| 16815 | 16861 | ** The interface to the code in fault.c used for identifying "benign" |
| 16816 | | -** malloc failures. This is only present if SQLITE_OMIT_BUILTIN_TEST |
| 16862 | +** malloc failures. This is only present if SQLITE_UNTESTABLE |
| 16817 | 16863 | ** is not defined. |
| 16818 | 16864 | */ |
| 16819 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 16865 | +#ifndef SQLITE_UNTESTABLE |
| 16820 | 16866 | SQLITE_PRIVATE void sqlite3BeginBenignMalloc(void); |
| 16821 | 16867 | SQLITE_PRIVATE void sqlite3EndBenignMalloc(void); |
| 16822 | 16868 | #else |
| 16823 | 16869 | #define sqlite3BeginBenignMalloc() |
| 16824 | 16870 | #define sqlite3EndBenignMalloc() |
| | @@ -16945,10 +16991,11 @@ |
| 16945 | 16991 | |
| 16946 | 16992 | SQLITE_PRIVATE int sqlite3ExprVectorSize(Expr *pExpr); |
| 16947 | 16993 | SQLITE_PRIVATE int sqlite3ExprIsVector(Expr *pExpr); |
| 16948 | 16994 | SQLITE_PRIVATE Expr *sqlite3VectorFieldSubexpr(Expr*, int); |
| 16949 | 16995 | SQLITE_PRIVATE Expr *sqlite3ExprForVectorField(Parse*,Expr*,int); |
| 16996 | +SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse*, Expr*); |
| 16950 | 16997 | |
| 16951 | 16998 | #endif /* SQLITEINT_H */ |
| 16952 | 16999 | |
| 16953 | 17000 | /************** End of sqliteInt.h *******************************************/ |
| 16954 | 17001 | /************** Begin file global.c ******************************************/ |
| | @@ -17171,11 +17218,11 @@ |
| 17171 | 17218 | #endif |
| 17172 | 17219 | #ifdef SQLITE_VDBE_COVERAGE |
| 17173 | 17220 | 0, /* xVdbeBranch */ |
| 17174 | 17221 | 0, /* pVbeBranchArg */ |
| 17175 | 17222 | #endif |
| 17176 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 17223 | +#ifndef SQLITE_UNTESTABLE |
| 17177 | 17224 | 0, /* xTestCallback */ |
| 17178 | 17225 | #endif |
| 17179 | 17226 | 0, /* bLocaltimeFault */ |
| 17180 | 17227 | 0x7ffffffe /* iOnceResetThreshold */ |
| 17181 | 17228 | }; |
| | @@ -17467,13 +17514,10 @@ |
| 17467 | 17514 | "OMIT_BLOB_LITERAL", |
| 17468 | 17515 | #endif |
| 17469 | 17516 | #if SQLITE_OMIT_BTREECOUNT |
| 17470 | 17517 | "OMIT_BTREECOUNT", |
| 17471 | 17518 | #endif |
| 17472 | | -#if SQLITE_OMIT_BUILTIN_TEST |
| 17473 | | - "OMIT_BUILTIN_TEST", |
| 17474 | | -#endif |
| 17475 | 17519 | #if SQLITE_OMIT_CAST |
| 17476 | 17520 | "OMIT_CAST", |
| 17477 | 17521 | #endif |
| 17478 | 17522 | #if SQLITE_OMIT_CHECK |
| 17479 | 17523 | "OMIT_CHECK", |
| | @@ -17631,10 +17675,13 @@ |
| 17631 | 17675 | #if SQLITE_TEST |
| 17632 | 17676 | "TEST", |
| 17633 | 17677 | #endif |
| 17634 | 17678 | #if defined(SQLITE_THREADSAFE) |
| 17635 | 17679 | "THREADSAFE=" CTIMEOPT_VAL(SQLITE_THREADSAFE), |
| 17680 | +#endif |
| 17681 | +#if SQLITE_UNTESTABLE |
| 17682 | + "UNTESTABLE" |
| 17636 | 17683 | #endif |
| 17637 | 17684 | #if SQLITE_USE_ALLOCA |
| 17638 | 17685 | "USE_ALLOCA", |
| 17639 | 17686 | #endif |
| 17640 | 17687 | #if SQLITE_USER_AUTHENTICATION |
| | @@ -18199,11 +18246,11 @@ |
| 18199 | 18246 | SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); |
| 18200 | 18247 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| 18201 | 18248 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 18202 | 18249 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 18203 | 18250 | SQLITE_PRIVATE void sqlite3VdbeMemCast(Mem*,u8,u8); |
| 18204 | | -SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*); |
| 18251 | +SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,Mem*); |
| 18205 | 18252 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 18206 | 18253 | SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*); |
| 18207 | 18254 | SQLITE_PRIVATE const char *sqlite3OpcodeName(int); |
| 18208 | 18255 | SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve); |
| 18209 | 18256 | SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n); |
| | @@ -18668,20 +18715,22 @@ |
| 18668 | 18715 | /* |
| 18669 | 18716 | ** A structure for holding a single date and time. |
| 18670 | 18717 | */ |
| 18671 | 18718 | typedef struct DateTime DateTime; |
| 18672 | 18719 | struct DateTime { |
| 18673 | | - sqlite3_int64 iJD; /* The julian day number times 86400000 */ |
| 18674 | | - int Y, M, D; /* Year, month, and day */ |
| 18675 | | - int h, m; /* Hour and minutes */ |
| 18676 | | - int tz; /* Timezone offset in minutes */ |
| 18677 | | - double s; /* Seconds */ |
| 18678 | | - char validYMD; /* True (1) if Y,M,D are valid */ |
| 18679 | | - char validHMS; /* True (1) if h,m,s are valid */ |
| 18680 | | - char validJD; /* True (1) if iJD is valid */ |
| 18681 | | - char validTZ; /* True (1) if tz is valid */ |
| 18682 | | - char tzSet; /* Timezone was set explicitly */ |
| 18720 | + sqlite3_int64 iJD; /* The julian day number times 86400000 */ |
| 18721 | + int Y, M, D; /* Year, month, and day */ |
| 18722 | + int h, m; /* Hour and minutes */ |
| 18723 | + int tz; /* Timezone offset in minutes */ |
| 18724 | + double s; /* Seconds */ |
| 18725 | + char validJD; /* True (1) if iJD is valid */ |
| 18726 | + char rawS; /* Raw numeric value stored in s */ |
| 18727 | + char validYMD; /* True (1) if Y,M,D are valid */ |
| 18728 | + char validHMS; /* True (1) if h,m,s are valid */ |
| 18729 | + char validTZ; /* True (1) if tz is valid */ |
| 18730 | + char tzSet; /* Timezone was set explicitly */ |
| 18731 | + char isError; /* An overflow has occurred */ |
| 18683 | 18732 | }; |
| 18684 | 18733 | |
| 18685 | 18734 | |
| 18686 | 18735 | /* |
| 18687 | 18736 | ** Convert zDate into one or more integers according to the conversion |
| | @@ -18825,18 +18874,27 @@ |
| 18825 | 18874 | } |
| 18826 | 18875 | }else{ |
| 18827 | 18876 | s = 0; |
| 18828 | 18877 | } |
| 18829 | 18878 | p->validJD = 0; |
| 18879 | + p->rawS = 0; |
| 18830 | 18880 | p->validHMS = 1; |
| 18831 | 18881 | p->h = h; |
| 18832 | 18882 | p->m = m; |
| 18833 | 18883 | p->s = s + ms; |
| 18834 | 18884 | if( parseTimezone(zDate, p) ) return 1; |
| 18835 | 18885 | p->validTZ = (p->tz!=0)?1:0; |
| 18836 | 18886 | return 0; |
| 18837 | 18887 | } |
| 18888 | + |
| 18889 | +/* |
| 18890 | +** Put the DateTime object into its error state. |
| 18891 | +*/ |
| 18892 | +static void datetimeError(DateTime *p){ |
| 18893 | + memset(p, 0, sizeof(*p)); |
| 18894 | + p->isError = 1; |
| 18895 | +} |
| 18838 | 18896 | |
| 18839 | 18897 | /* |
| 18840 | 18898 | ** Convert from YYYY-MM-DD HH:MM:SS to julian day. We always assume |
| 18841 | 18899 | ** that the YYYY-MM-DD is according to the Gregorian calendar. |
| 18842 | 18900 | ** |
| | @@ -18852,10 +18910,14 @@ |
| 18852 | 18910 | D = p->D; |
| 18853 | 18911 | }else{ |
| 18854 | 18912 | Y = 2000; /* If no YMD specified, assume 2000-Jan-01 */ |
| 18855 | 18913 | M = 1; |
| 18856 | 18914 | D = 1; |
| 18915 | + } |
| 18916 | + if( Y<-4713 || Y>9999 || p->rawS ){ |
| 18917 | + datetimeError(p); |
| 18918 | + return; |
| 18857 | 18919 | } |
| 18858 | 18920 | if( M<=2 ){ |
| 18859 | 18921 | Y--; |
| 18860 | 18922 | M += 12; |
| 18861 | 18923 | } |
| | @@ -18932,10 +18994,25 @@ |
| 18932 | 18994 | return 0; |
| 18933 | 18995 | }else{ |
| 18934 | 18996 | return 1; |
| 18935 | 18997 | } |
| 18936 | 18998 | } |
| 18999 | + |
| 19000 | +/* |
| 19001 | +** Input "r" is a numeric quantity which might be a julian day number, |
| 19002 | +** or the number of seconds since 1970. If the value if r is within |
| 19003 | +** range of a julian day number, install it as such and set validJD. |
| 19004 | +** If the value is a valid unix timestamp, put it in p->s and set p->rawS. |
| 19005 | +*/ |
| 19006 | +static void setRawDateNumber(DateTime *p, double r){ |
| 19007 | + p->s = r; |
| 19008 | + p->rawS = 1; |
| 19009 | + if( r>=0.0 && r<5373484.5 ){ |
| 19010 | + p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5); |
| 19011 | + p->validJD = 1; |
| 19012 | + } |
| 19013 | +} |
| 18937 | 19014 | |
| 18938 | 19015 | /* |
| 18939 | 19016 | ** Attempt to parse the given string into a julian day number. Return |
| 18940 | 19017 | ** the number of errors. |
| 18941 | 19018 | ** |
| | @@ -18962,16 +19039,24 @@ |
| 18962 | 19039 | }else if( parseHhMmSs(zDate, p)==0 ){ |
| 18963 | 19040 | return 0; |
| 18964 | 19041 | }else if( sqlite3StrICmp(zDate,"now")==0){ |
| 18965 | 19042 | return setDateTimeToCurrent(context, p); |
| 18966 | 19043 | }else if( sqlite3AtoF(zDate, &r, sqlite3Strlen30(zDate), SQLITE_UTF8) ){ |
| 18967 | | - p->iJD = (sqlite3_int64)(r*86400000.0 + 0.5); |
| 18968 | | - p->validJD = 1; |
| 19044 | + setRawDateNumber(p, r); |
| 18969 | 19045 | return 0; |
| 18970 | 19046 | } |
| 18971 | 19047 | return 1; |
| 18972 | 19048 | } |
| 19049 | + |
| 19050 | +/* |
| 19051 | +** Return TRUE if the given julian day number is within range. |
| 19052 | +** |
| 19053 | +** The input is the JulianDay times 86400000. |
| 19054 | +*/ |
| 19055 | +static int validJulianDay(sqlite3_int64 iJD){ |
| 19056 | + return iJD>=0 && iJD<=464269060799999; |
| 19057 | +} |
| 18973 | 19058 | |
| 18974 | 19059 | /* |
| 18975 | 19060 | ** Compute the Year, Month, and Day from the julian day number. |
| 18976 | 19061 | */ |
| 18977 | 19062 | static void computeYMD(DateTime *p){ |
| | @@ -18980,10 +19065,11 @@ |
| 18980 | 19065 | if( !p->validJD ){ |
| 18981 | 19066 | p->Y = 2000; |
| 18982 | 19067 | p->M = 1; |
| 18983 | 19068 | p->D = 1; |
| 18984 | 19069 | }else{ |
| 19070 | + assert( validJulianDay(p->iJD) ); |
| 18985 | 19071 | Z = (int)((p->iJD + 43200000)/86400000); |
| 18986 | 19072 | A = (int)((Z - 1867216.25)/36524.25); |
| 18987 | 19073 | A = Z + 1 + A - (A/4); |
| 18988 | 19074 | B = A + 1524; |
| 18989 | 19075 | C = (int)((B - 122.1)/365.25); |
| | @@ -19010,10 +19096,11 @@ |
| 19010 | 19096 | p->s -= s; |
| 19011 | 19097 | p->h = s/3600; |
| 19012 | 19098 | s -= p->h*3600; |
| 19013 | 19099 | p->m = s/60; |
| 19014 | 19100 | p->s += s - p->m*60; |
| 19101 | + p->rawS = 0; |
| 19015 | 19102 | p->validHMS = 1; |
| 19016 | 19103 | } |
| 19017 | 19104 | |
| 19018 | 19105 | /* |
| 19019 | 19106 | ** Compute both YMD and HMS |
| | @@ -19071,18 +19158,18 @@ |
| 19071 | 19158 | #if SQLITE_THREADSAFE>0 |
| 19072 | 19159 | sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); |
| 19073 | 19160 | #endif |
| 19074 | 19161 | sqlite3_mutex_enter(mutex); |
| 19075 | 19162 | pX = localtime(t); |
| 19076 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 19163 | +#ifndef SQLITE_UNTESTABLE |
| 19077 | 19164 | if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0; |
| 19078 | 19165 | #endif |
| 19079 | 19166 | if( pX ) *pTm = *pX; |
| 19080 | 19167 | sqlite3_mutex_leave(mutex); |
| 19081 | 19168 | rc = pX==0; |
| 19082 | 19169 | #else |
| 19083 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 19170 | +#ifndef SQLITE_UNTESTABLE |
| 19084 | 19171 | if( sqlite3GlobalConfig.bLocaltimeFault ) return 1; |
| 19085 | 19172 | #endif |
| 19086 | 19173 | #if HAVE_LOCALTIME_R |
| 19087 | 19174 | rc = localtime_r(t, pTm)==0; |
| 19088 | 19175 | #else |
| | @@ -19149,16 +19236,41 @@ |
| 19149 | 19236 | y.m = sLocal.tm_min; |
| 19150 | 19237 | y.s = sLocal.tm_sec; |
| 19151 | 19238 | y.validYMD = 1; |
| 19152 | 19239 | y.validHMS = 1; |
| 19153 | 19240 | y.validJD = 0; |
| 19241 | + y.rawS = 0; |
| 19154 | 19242 | y.validTZ = 0; |
| 19243 | + y.isError = 0; |
| 19155 | 19244 | computeJD(&y); |
| 19156 | 19245 | *pRc = SQLITE_OK; |
| 19157 | 19246 | return y.iJD - x.iJD; |
| 19158 | 19247 | } |
| 19159 | 19248 | #endif /* SQLITE_OMIT_LOCALTIME */ |
| 19249 | + |
| 19250 | +/* |
| 19251 | +** The following table defines various date transformations of the form |
| 19252 | +** |
| 19253 | +** 'NNN days' |
| 19254 | +** |
| 19255 | +** Where NNN is an arbitrary floating-point number and "days" can be one |
| 19256 | +** of several units of time. |
| 19257 | +*/ |
| 19258 | +static const struct { |
| 19259 | + u8 eType; /* Transformation type code */ |
| 19260 | + u8 nName; /* Length of th name */ |
| 19261 | + char *zName; /* Name of the transformation */ |
| 19262 | + double rLimit; /* Maximum NNN value for this transform */ |
| 19263 | + double rXform; /* Constant used for this transform */ |
| 19264 | +} aXformType[] = { |
| 19265 | + { 0, 6, "second", 464269060800.0, 86400000.0/(24.0*60.0*60.0) }, |
| 19266 | + { 0, 6, "minute", 7737817680.0, 86400000.0/(24.0*60.0) }, |
| 19267 | + { 0, 4, "hour", 128963628.0, 86400000.0/24.0 }, |
| 19268 | + { 0, 3, "day", 5373485.0, 86400000.0 }, |
| 19269 | + { 1, 5, "month", 176546.0, 30.0*86400000.0 }, |
| 19270 | + { 2, 4, "year", 14713.0, 365.0*86400000.0 }, |
| 19271 | +}; |
| 19160 | 19272 | |
| 19161 | 19273 | /* |
| 19162 | 19274 | ** Process a modifier to a date-time stamp. The modifiers are |
| 19163 | 19275 | ** as follows: |
| 19164 | 19276 | ** |
| | @@ -19180,29 +19292,27 @@ |
| 19180 | 19292 | ** Return 0 on success and 1 if there is any kind of error. If the error |
| 19181 | 19293 | ** is in a system call (i.e. localtime()), then an error message is written |
| 19182 | 19294 | ** to context pCtx. If the error is an unrecognized modifier, no error is |
| 19183 | 19295 | ** written to pCtx. |
| 19184 | 19296 | */ |
| 19185 | | -static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){ |
| 19297 | +static int parseModifier( |
| 19298 | + sqlite3_context *pCtx, /* Function context */ |
| 19299 | + const char *z, /* The text of the modifier */ |
| 19300 | + int n, /* Length of zMod in bytes */ |
| 19301 | + DateTime *p /* The date/time value to be modified */ |
| 19302 | +){ |
| 19186 | 19303 | int rc = 1; |
| 19187 | | - int n; |
| 19188 | 19304 | double r; |
| 19189 | | - char *z, zBuf[30]; |
| 19190 | | - z = zBuf; |
| 19191 | | - for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){ |
| 19192 | | - z[n] = (char)sqlite3UpperToLower[(u8)zMod[n]]; |
| 19193 | | - } |
| 19194 | | - z[n] = 0; |
| 19195 | | - switch( z[0] ){ |
| 19305 | + switch(sqlite3UpperToLower[(u8)z[0]] ){ |
| 19196 | 19306 | #ifndef SQLITE_OMIT_LOCALTIME |
| 19197 | 19307 | case 'l': { |
| 19198 | 19308 | /* localtime |
| 19199 | 19309 | ** |
| 19200 | 19310 | ** Assuming the current time value is UTC (a.k.a. GMT), shift it to |
| 19201 | 19311 | ** show local time. |
| 19202 | 19312 | */ |
| 19203 | | - if( strcmp(z, "localtime")==0 ){ |
| 19313 | + if( sqlite3_stricmp(z, "localtime")==0 ){ |
| 19204 | 19314 | computeJD(p); |
| 19205 | 19315 | p->iJD += localtimeOffset(p, pCtx, &rc); |
| 19206 | 19316 | clearYMD_HMS_TZ(p); |
| 19207 | 19317 | } |
| 19208 | 19318 | break; |
| | @@ -19210,20 +19320,25 @@ |
| 19210 | 19320 | #endif |
| 19211 | 19321 | case 'u': { |
| 19212 | 19322 | /* |
| 19213 | 19323 | ** unixepoch |
| 19214 | 19324 | ** |
| 19215 | | - ** Treat the current value of p->iJD as the number of |
| 19325 | + ** Treat the current value of p->s as the number of |
| 19216 | 19326 | ** seconds since 1970. Convert to a real julian day number. |
| 19217 | 19327 | */ |
| 19218 | | - if( strcmp(z, "unixepoch")==0 && p->validJD ){ |
| 19219 | | - p->iJD = (p->iJD + 43200)/86400 + 21086676*(i64)10000000; |
| 19220 | | - clearYMD_HMS_TZ(p); |
| 19221 | | - rc = 0; |
| 19328 | + if( sqlite3_stricmp(z, "unixepoch")==0 && p->rawS ){ |
| 19329 | + r = p->s*1000.0 + 210866760000000.0; |
| 19330 | + if( r>=0.0 && r<464269060800000.0 ){ |
| 19331 | + clearYMD_HMS_TZ(p); |
| 19332 | + p->iJD = (sqlite3_int64)r; |
| 19333 | + p->validJD = 1; |
| 19334 | + p->rawS = 0; |
| 19335 | + rc = 0; |
| 19336 | + } |
| 19222 | 19337 | } |
| 19223 | 19338 | #ifndef SQLITE_OMIT_LOCALTIME |
| 19224 | | - else if( strcmp(z, "utc")==0 ){ |
| 19339 | + else if( sqlite3_stricmp(z, "utc")==0 ){ |
| 19225 | 19340 | if( p->tzSet==0 ){ |
| 19226 | 19341 | sqlite3_int64 c1; |
| 19227 | 19342 | computeJD(p); |
| 19228 | 19343 | c1 = localtimeOffset(p, pCtx, &rc); |
| 19229 | 19344 | if( rc==SQLITE_OK ){ |
| | @@ -19245,11 +19360,11 @@ |
| 19245 | 19360 | ** |
| 19246 | 19361 | ** Move the date to the same time on the next occurrence of |
| 19247 | 19362 | ** weekday N where 0==Sunday, 1==Monday, and so forth. If the |
| 19248 | 19363 | ** date is already on the appropriate weekday, this is a no-op. |
| 19249 | 19364 | */ |
| 19250 | | - if( strncmp(z, "weekday ", 8)==0 |
| 19365 | + if( sqlite3_strnicmp(z, "weekday ", 8)==0 |
| 19251 | 19366 | && sqlite3AtoF(&z[8], &r, sqlite3Strlen30(&z[8]), SQLITE_UTF8) |
| 19252 | 19367 | && (n=(int)r)==r && n>=0 && r<7 ){ |
| 19253 | 19368 | sqlite3_int64 Z; |
| 19254 | 19369 | computeYMD_HMS(p); |
| 19255 | 19370 | p->validTZ = 0; |
| | @@ -19268,27 +19383,27 @@ |
| 19268 | 19383 | ** start of TTTTT |
| 19269 | 19384 | ** |
| 19270 | 19385 | ** Move the date backwards to the beginning of the current day, |
| 19271 | 19386 | ** or month or year. |
| 19272 | 19387 | */ |
| 19273 | | - if( strncmp(z, "start of ", 9)!=0 ) break; |
| 19388 | + if( sqlite3_strnicmp(z, "start of ", 9)!=0 ) break; |
| 19274 | 19389 | z += 9; |
| 19275 | 19390 | computeYMD(p); |
| 19276 | 19391 | p->validHMS = 1; |
| 19277 | 19392 | p->h = p->m = 0; |
| 19278 | 19393 | p->s = 0.0; |
| 19279 | 19394 | p->validTZ = 0; |
| 19280 | 19395 | p->validJD = 0; |
| 19281 | | - if( strcmp(z,"month")==0 ){ |
| 19396 | + if( sqlite3_stricmp(z,"month")==0 ){ |
| 19282 | 19397 | p->D = 1; |
| 19283 | 19398 | rc = 0; |
| 19284 | | - }else if( strcmp(z,"year")==0 ){ |
| 19399 | + }else if( sqlite3_stricmp(z,"year")==0 ){ |
| 19285 | 19400 | computeYMD(p); |
| 19286 | 19401 | p->M = 1; |
| 19287 | 19402 | p->D = 1; |
| 19288 | 19403 | rc = 0; |
| 19289 | | - }else if( strcmp(z,"day")==0 ){ |
| 19404 | + }else if( sqlite3_stricmp(z,"day")==0 ){ |
| 19290 | 19405 | rc = 0; |
| 19291 | 19406 | } |
| 19292 | 19407 | break; |
| 19293 | 19408 | } |
| 19294 | 19409 | case '+': |
| | @@ -19302,10 +19417,11 @@ |
| 19302 | 19417 | case '6': |
| 19303 | 19418 | case '7': |
| 19304 | 19419 | case '8': |
| 19305 | 19420 | case '9': { |
| 19306 | 19421 | double rRounder; |
| 19422 | + int i; |
| 19307 | 19423 | for(n=1; z[n] && z[n]!=':' && !sqlite3Isspace(z[n]); n++){} |
| 19308 | 19424 | if( !sqlite3AtoF(z, &r, n, SQLITE_UTF8) ){ |
| 19309 | 19425 | rc = 1; |
| 19310 | 19426 | break; |
| 19311 | 19427 | } |
| | @@ -19330,50 +19446,52 @@ |
| 19330 | 19446 | clearYMD_HMS_TZ(p); |
| 19331 | 19447 | p->iJD += tx.iJD; |
| 19332 | 19448 | rc = 0; |
| 19333 | 19449 | break; |
| 19334 | 19450 | } |
| 19451 | + |
| 19452 | + /* If control reaches this point, it means the transformation is |
| 19453 | + ** one of the forms like "+NNN days". */ |
| 19335 | 19454 | z += n; |
| 19336 | 19455 | while( sqlite3Isspace(*z) ) z++; |
| 19337 | 19456 | n = sqlite3Strlen30(z); |
| 19338 | 19457 | if( n>10 || n<3 ) break; |
| 19339 | | - if( z[n-1]=='s' ){ z[n-1] = 0; n--; } |
| 19458 | + if( sqlite3UpperToLower[(u8)z[n-1]]=='s' ) n--; |
| 19340 | 19459 | computeJD(p); |
| 19341 | | - rc = 0; |
| 19460 | + rc = 1; |
| 19342 | 19461 | rRounder = r<0 ? -0.5 : +0.5; |
| 19343 | | - if( n==3 && strcmp(z,"day")==0 ){ |
| 19344 | | - p->iJD += (sqlite3_int64)(r*86400000.0 + rRounder); |
| 19345 | | - }else if( n==4 && strcmp(z,"hour")==0 ){ |
| 19346 | | - p->iJD += (sqlite3_int64)(r*(86400000.0/24.0) + rRounder); |
| 19347 | | - }else if( n==6 && strcmp(z,"minute")==0 ){ |
| 19348 | | - p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0)) + rRounder); |
| 19349 | | - }else if( n==6 && strcmp(z,"second")==0 ){ |
| 19350 | | - p->iJD += (sqlite3_int64)(r*(86400000.0/(24.0*60.0*60.0)) + rRounder); |
| 19351 | | - }else if( n==5 && strcmp(z,"month")==0 ){ |
| 19352 | | - int x, y; |
| 19353 | | - computeYMD_HMS(p); |
| 19354 | | - p->M += (int)r; |
| 19355 | | - x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; |
| 19356 | | - p->Y += x; |
| 19357 | | - p->M -= x*12; |
| 19358 | | - p->validJD = 0; |
| 19359 | | - computeJD(p); |
| 19360 | | - y = (int)r; |
| 19361 | | - if( y!=r ){ |
| 19362 | | - p->iJD += (sqlite3_int64)((r - y)*30.0*86400000.0 + rRounder); |
| 19363 | | - } |
| 19364 | | - }else if( n==4 && strcmp(z,"year")==0 ){ |
| 19365 | | - int y = (int)r; |
| 19366 | | - computeYMD_HMS(p); |
| 19367 | | - p->Y += y; |
| 19368 | | - p->validJD = 0; |
| 19369 | | - computeJD(p); |
| 19370 | | - if( y!=r ){ |
| 19371 | | - p->iJD += (sqlite3_int64)((r - y)*365.0*86400000.0 + rRounder); |
| 19372 | | - } |
| 19373 | | - }else{ |
| 19374 | | - rc = 1; |
| 19462 | + for(i=0; i<ArraySize(aXformType); i++){ |
| 19463 | + if( aXformType[i].nName==n |
| 19464 | + && sqlite3_strnicmp(aXformType[i].zName, z, n)==0 |
| 19465 | + && r>-aXformType[i].rLimit && r<aXformType[i].rLimit |
| 19466 | + ){ |
| 19467 | + switch( aXformType[i].eType ){ |
| 19468 | + case 1: { /* Special processing to add months */ |
| 19469 | + int x; |
| 19470 | + computeYMD_HMS(p); |
| 19471 | + p->M += (int)r; |
| 19472 | + x = p->M>0 ? (p->M-1)/12 : (p->M-12)/12; |
| 19473 | + p->Y += x; |
| 19474 | + p->M -= x*12; |
| 19475 | + p->validJD = 0; |
| 19476 | + r -= (int)r; |
| 19477 | + break; |
| 19478 | + } |
| 19479 | + case 2: { /* Special processing to add years */ |
| 19480 | + int y = (int)r; |
| 19481 | + computeYMD_HMS(p); |
| 19482 | + p->Y += y; |
| 19483 | + p->validJD = 0; |
| 19484 | + r -= (int)r; |
| 19485 | + break; |
| 19486 | + } |
| 19487 | + } |
| 19488 | + computeJD(p); |
| 19489 | + p->iJD += (sqlite3_int64)(r*aXformType[i].rXform + rRounder); |
| 19490 | + rc = 0; |
| 19491 | + break; |
| 19492 | + } |
| 19375 | 19493 | } |
| 19376 | 19494 | clearYMD_HMS_TZ(p); |
| 19377 | 19495 | break; |
| 19378 | 19496 | } |
| 19379 | 19497 | default: { |
| | @@ -19396,31 +19514,33 @@ |
| 19396 | 19514 | sqlite3_context *context, |
| 19397 | 19515 | int argc, |
| 19398 | 19516 | sqlite3_value **argv, |
| 19399 | 19517 | DateTime *p |
| 19400 | 19518 | ){ |
| 19401 | | - int i; |
| 19519 | + int i, n; |
| 19402 | 19520 | const unsigned char *z; |
| 19403 | 19521 | int eType; |
| 19404 | 19522 | memset(p, 0, sizeof(*p)); |
| 19405 | 19523 | if( argc==0 ){ |
| 19406 | 19524 | return setDateTimeToCurrent(context, p); |
| 19407 | 19525 | } |
| 19408 | 19526 | if( (eType = sqlite3_value_type(argv[0]))==SQLITE_FLOAT |
| 19409 | 19527 | || eType==SQLITE_INTEGER ){ |
| 19410 | | - p->iJD = (sqlite3_int64)(sqlite3_value_double(argv[0])*86400000.0 + 0.5); |
| 19411 | | - p->validJD = 1; |
| 19528 | + setRawDateNumber(p, sqlite3_value_double(argv[0])); |
| 19412 | 19529 | }else{ |
| 19413 | 19530 | z = sqlite3_value_text(argv[0]); |
| 19414 | 19531 | if( !z || parseDateOrTime(context, (char*)z, p) ){ |
| 19415 | 19532 | return 1; |
| 19416 | 19533 | } |
| 19417 | 19534 | } |
| 19418 | 19535 | for(i=1; i<argc; i++){ |
| 19419 | 19536 | z = sqlite3_value_text(argv[i]); |
| 19420 | | - if( z==0 || parseModifier(context, (char*)z, p) ) return 1; |
| 19537 | + n = sqlite3_value_bytes(argv[i]); |
| 19538 | + if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1; |
| 19421 | 19539 | } |
| 19540 | + computeJD(p); |
| 19541 | + if( p->isError || !validJulianDay(p->iJD) ) return 1; |
| 19422 | 19542 | return 0; |
| 19423 | 19543 | } |
| 19424 | 19544 | |
| 19425 | 19545 | |
| 19426 | 19546 | /* |
| | @@ -20214,11 +20334,11 @@ |
| 20214 | 20334 | ** during a hash table resize is a benign fault. |
| 20215 | 20335 | */ |
| 20216 | 20336 | |
| 20217 | 20337 | /* #include "sqliteInt.h" */ |
| 20218 | 20338 | |
| 20219 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 20339 | +#ifndef SQLITE_UNTESTABLE |
| 20220 | 20340 | |
| 20221 | 20341 | /* |
| 20222 | 20342 | ** Global variables. |
| 20223 | 20343 | */ |
| 20224 | 20344 | typedef struct BenignMallocHooks BenignMallocHooks; |
| | @@ -20272,11 +20392,11 @@ |
| 20272 | 20392 | if( wsdHooks.xBenignEnd ){ |
| 20273 | 20393 | wsdHooks.xBenignEnd(); |
| 20274 | 20394 | } |
| 20275 | 20395 | } |
| 20276 | 20396 | |
| 20277 | | -#endif /* #ifndef SQLITE_OMIT_BUILTIN_TEST */ |
| 20397 | +#endif /* #ifndef SQLITE_UNTESTABLE */ |
| 20278 | 20398 | |
| 20279 | 20399 | /************** End of fault.c ***********************************************/ |
| 20280 | 20400 | /************** Begin file mem0.c ********************************************/ |
| 20281 | 20401 | /* |
| 20282 | 20402 | ** 2008 October 28 |
| | @@ -25599,22 +25719,27 @@ |
| 25599 | 25719 | /* |
| 25600 | 25720 | ** Finish off a string by making sure it is zero-terminated. |
| 25601 | 25721 | ** Return a pointer to the resulting string. Return a NULL |
| 25602 | 25722 | ** pointer if any kind of error was encountered. |
| 25603 | 25723 | */ |
| 25724 | +static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){ |
| 25725 | + assert( p->mxAlloc>0 && !isMalloced(p) ); |
| 25726 | + p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 25727 | + if( p->zText ){ |
| 25728 | + memcpy(p->zText, p->zBase, p->nChar+1); |
| 25729 | + p->printfFlags |= SQLITE_PRINTF_MALLOCED; |
| 25730 | + }else{ |
| 25731 | + setStrAccumError(p, STRACCUM_NOMEM); |
| 25732 | + } |
| 25733 | + return p->zText; |
| 25734 | +} |
| 25604 | 25735 | SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){ |
| 25605 | 25736 | if( p->zText ){ |
| 25606 | 25737 | assert( (p->zText==p->zBase)==!isMalloced(p) ); |
| 25607 | 25738 | p->zText[p->nChar] = 0; |
| 25608 | 25739 | if( p->mxAlloc>0 && !isMalloced(p) ){ |
| 25609 | | - p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 ); |
| 25610 | | - if( p->zText ){ |
| 25611 | | - memcpy(p->zText, p->zBase, p->nChar+1); |
| 25612 | | - p->printfFlags |= SQLITE_PRINTF_MALLOCED; |
| 25613 | | - }else{ |
| 25614 | | - setStrAccumError(p, STRACCUM_NOMEM); |
| 25615 | | - } |
| 25740 | + return strAccumFinishRealloc(p); |
| 25616 | 25741 | } |
| 25617 | 25742 | } |
| 25618 | 25743 | return p->zText; |
| 25619 | 25744 | } |
| 25620 | 25745 | |
| | @@ -25750,11 +25875,12 @@ |
| 25750 | 25875 | return zBuf; |
| 25751 | 25876 | } |
| 25752 | 25877 | #endif |
| 25753 | 25878 | sqlite3StrAccumInit(&acc, 0, zBuf, n, 0); |
| 25754 | 25879 | sqlite3VXPrintf(&acc, zFormat, ap); |
| 25755 | | - return sqlite3StrAccumFinish(&acc); |
| 25880 | + zBuf[acc.nChar] = 0; |
| 25881 | + return zBuf; |
| 25756 | 25882 | } |
| 25757 | 25883 | SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){ |
| 25758 | 25884 | char *z; |
| 25759 | 25885 | va_list ap; |
| 25760 | 25886 | va_start(ap,zFormat); |
| | @@ -26459,11 +26585,11 @@ |
| 26459 | 26585 | *(zBuf++) = wsdPrng.s[t]; |
| 26460 | 26586 | }while( --N ); |
| 26461 | 26587 | sqlite3_mutex_leave(mutex); |
| 26462 | 26588 | } |
| 26463 | 26589 | |
| 26464 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 26590 | +#ifndef SQLITE_UNTESTABLE |
| 26465 | 26591 | /* |
| 26466 | 26592 | ** For testing purposes, we sometimes want to preserve the state of |
| 26467 | 26593 | ** PRNG and restore the PRNG to its saved state at a later time, or |
| 26468 | 26594 | ** to reset the PRNG to its initial state. These routines accomplish |
| 26469 | 26595 | ** those tasks. |
| | @@ -26484,11 +26610,11 @@ |
| 26484 | 26610 | &GLOBAL(struct sqlite3PrngType, sqlite3Prng), |
| 26485 | 26611 | &GLOBAL(struct sqlite3PrngType, sqlite3SavedPrng), |
| 26486 | 26612 | sizeof(sqlite3Prng) |
| 26487 | 26613 | ); |
| 26488 | 26614 | } |
| 26489 | | -#endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 26615 | +#endif /* SQLITE_UNTESTABLE */ |
| 26490 | 26616 | |
| 26491 | 26617 | /************** End of random.c **********************************************/ |
| 26492 | 26618 | /************** Begin file threads.c *****************************************/ |
| 26493 | 26619 | /* |
| 26494 | 26620 | ** 2012 July 21 |
| | @@ -27342,11 +27468,11 @@ |
| 27342 | 27468 | ** which of multiple sqlite3FaultSim() calls has been hit. |
| 27343 | 27469 | ** |
| 27344 | 27470 | ** Return whatever integer value the test callback returns, or return |
| 27345 | 27471 | ** SQLITE_OK if no test callback is installed. |
| 27346 | 27472 | */ |
| 27347 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 27473 | +#ifndef SQLITE_UNTESTABLE |
| 27348 | 27474 | SQLITE_PRIVATE int sqlite3FaultSim(int iTest){ |
| 27349 | 27475 | int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback; |
| 27350 | 27476 | return xCallback ? xCallback(iTest) : SQLITE_OK; |
| 27351 | 27477 | } |
| 27352 | 27478 | #endif |
| | @@ -29163,52 +29289,51 @@ |
| 29163 | 29289 | /* 116 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 29164 | 29290 | /* 117 */ "Delete" OpHelp(""), |
| 29165 | 29291 | /* 118 */ "ResetCount" OpHelp(""), |
| 29166 | 29292 | /* 119 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"), |
| 29167 | 29293 | /* 120 */ "SorterData" OpHelp("r[P2]=data"), |
| 29168 | | - /* 121 */ "RowKey" OpHelp("r[P2]=key"), |
| 29169 | | - /* 122 */ "RowData" OpHelp("r[P2]=data"), |
| 29170 | | - /* 123 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 29171 | | - /* 124 */ "NullRow" OpHelp(""), |
| 29172 | | - /* 125 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 29173 | | - /* 126 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 29174 | | - /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 29175 | | - /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"), |
| 29176 | | - /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 29177 | | - /* 130 */ "Destroy" OpHelp(""), |
| 29178 | | - /* 131 */ "Clear" OpHelp(""), |
| 29294 | + /* 121 */ "RowData" OpHelp("r[P2]=data"), |
| 29295 | + /* 122 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 29296 | + /* 123 */ "NullRow" OpHelp(""), |
| 29297 | + /* 124 */ "SorterInsert" OpHelp("key=r[P2]"), |
| 29298 | + /* 125 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 29299 | + /* 126 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 29300 | + /* 127 */ "Seek" OpHelp("Move P3 to P1.rowid"), |
| 29301 | + /* 128 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 29302 | + /* 129 */ "Destroy" OpHelp(""), |
| 29303 | + /* 130 */ "Clear" OpHelp(""), |
| 29304 | + /* 131 */ "ResetSorter" OpHelp(""), |
| 29179 | 29305 | /* 132 */ "Real" OpHelp("r[P2]=P4"), |
| 29180 | | - /* 133 */ "ResetSorter" OpHelp(""), |
| 29181 | | - /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 29182 | | - /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 29183 | | - /* 136 */ "ParseSchema" OpHelp(""), |
| 29184 | | - /* 137 */ "LoadAnalysis" OpHelp(""), |
| 29185 | | - /* 138 */ "DropTable" OpHelp(""), |
| 29186 | | - /* 139 */ "DropIndex" OpHelp(""), |
| 29187 | | - /* 140 */ "DropTrigger" OpHelp(""), |
| 29188 | | - /* 141 */ "IntegrityCk" OpHelp(""), |
| 29189 | | - /* 142 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 29190 | | - /* 143 */ "Param" OpHelp(""), |
| 29191 | | - /* 144 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 29192 | | - /* 145 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 29193 | | - /* 146 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 29194 | | - /* 147 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 29195 | | - /* 148 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 29196 | | - /* 149 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 29197 | | - /* 150 */ "Expire" OpHelp(""), |
| 29198 | | - /* 151 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 29199 | | - /* 152 */ "VBegin" OpHelp(""), |
| 29200 | | - /* 153 */ "VCreate" OpHelp(""), |
| 29201 | | - /* 154 */ "VDestroy" OpHelp(""), |
| 29202 | | - /* 155 */ "VOpen" OpHelp(""), |
| 29203 | | - /* 156 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 29204 | | - /* 157 */ "VRename" OpHelp(""), |
| 29205 | | - /* 158 */ "Pagecount" OpHelp(""), |
| 29206 | | - /* 159 */ "MaxPgcnt" OpHelp(""), |
| 29207 | | - /* 160 */ "CursorHint" OpHelp(""), |
| 29208 | | - /* 161 */ "Noop" OpHelp(""), |
| 29209 | | - /* 162 */ "Explain" OpHelp(""), |
| 29306 | + /* 133 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 29307 | + /* 134 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 29308 | + /* 135 */ "ParseSchema" OpHelp(""), |
| 29309 | + /* 136 */ "LoadAnalysis" OpHelp(""), |
| 29310 | + /* 137 */ "DropTable" OpHelp(""), |
| 29311 | + /* 138 */ "DropIndex" OpHelp(""), |
| 29312 | + /* 139 */ "DropTrigger" OpHelp(""), |
| 29313 | + /* 140 */ "IntegrityCk" OpHelp(""), |
| 29314 | + /* 141 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 29315 | + /* 142 */ "Param" OpHelp(""), |
| 29316 | + /* 143 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 29317 | + /* 144 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 29318 | + /* 145 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"), |
| 29319 | + /* 146 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 29320 | + /* 147 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 29321 | + /* 148 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 29322 | + /* 149 */ "Expire" OpHelp(""), |
| 29323 | + /* 150 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 29324 | + /* 151 */ "VBegin" OpHelp(""), |
| 29325 | + /* 152 */ "VCreate" OpHelp(""), |
| 29326 | + /* 153 */ "VDestroy" OpHelp(""), |
| 29327 | + /* 154 */ "VOpen" OpHelp(""), |
| 29328 | + /* 155 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 29329 | + /* 156 */ "VRename" OpHelp(""), |
| 29330 | + /* 157 */ "Pagecount" OpHelp(""), |
| 29331 | + /* 158 */ "MaxPgcnt" OpHelp(""), |
| 29332 | + /* 159 */ "CursorHint" OpHelp(""), |
| 29333 | + /* 160 */ "Noop" OpHelp(""), |
| 29334 | + /* 161 */ "Explain" OpHelp(""), |
| 29210 | 29335 | }; |
| 29211 | 29336 | return azName[i]; |
| 29212 | 29337 | } |
| 29213 | 29338 | #endif |
| 29214 | 29339 | |
| | @@ -30473,11 +30598,18 @@ |
| 30473 | 30598 | struct unixFileId { |
| 30474 | 30599 | dev_t dev; /* Device number */ |
| 30475 | 30600 | #if OS_VXWORKS |
| 30476 | 30601 | struct vxworksFileId *pId; /* Unique file ID for vxworks. */ |
| 30477 | 30602 | #else |
| 30478 | | - ino_t ino; /* Inode number */ |
| 30603 | + /* We are told that some versions of Android contain a bug that |
| 30604 | + ** sizes ino_t at only 32-bits instead of 64-bits. (See |
| 30605 | + ** https://android-review.googlesource.com/#/c/115351/3/dist/sqlite3.c) |
| 30606 | + ** To work around this, always allocate 64-bits for the inode number. |
| 30607 | + ** On small machines that only have 32-bit inodes, this wastes 4 bytes, |
| 30608 | + ** but that should not be a big deal. */ |
| 30609 | + /* WAS: ino_t ino; */ |
| 30610 | + u64 ino; /* Inode number */ |
| 30479 | 30611 | #endif |
| 30480 | 30612 | }; |
| 30481 | 30613 | |
| 30482 | 30614 | /* |
| 30483 | 30615 | ** An instance of the following structure is allocated for each open |
| | @@ -30718,11 +30850,11 @@ |
| 30718 | 30850 | memset(&fileId, 0, sizeof(fileId)); |
| 30719 | 30851 | fileId.dev = statbuf.st_dev; |
| 30720 | 30852 | #if OS_VXWORKS |
| 30721 | 30853 | fileId.pId = pFile->pId; |
| 30722 | 30854 | #else |
| 30723 | | - fileId.ino = statbuf.st_ino; |
| 30855 | + fileId.ino = (u64)statbuf.st_ino; |
| 30724 | 30856 | #endif |
| 30725 | 30857 | pInode = inodeList; |
| 30726 | 30858 | while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){ |
| 30727 | 30859 | pInode = pInode->pNext; |
| 30728 | 30860 | } |
| | @@ -30752,11 +30884,12 @@ |
| 30752 | 30884 | #if OS_VXWORKS |
| 30753 | 30885 | return pFile->pInode!=0 && pFile->pId!=pFile->pInode->fileId.pId; |
| 30754 | 30886 | #else |
| 30755 | 30887 | struct stat buf; |
| 30756 | 30888 | return pFile->pInode!=0 && |
| 30757 | | - (osStat(pFile->zPath, &buf)!=0 || buf.st_ino!=pFile->pInode->fileId.ino); |
| 30889 | + (osStat(pFile->zPath, &buf)!=0 |
| 30890 | + || (u64)buf.st_ino!=pFile->pInode->fileId.ino); |
| 30758 | 30891 | #endif |
| 30759 | 30892 | } |
| 30760 | 30893 | |
| 30761 | 30894 | |
| 30762 | 30895 | /* |
| | @@ -34924,11 +35057,11 @@ |
| 34924 | 35057 | unixInodeInfo *pInode; |
| 34925 | 35058 | |
| 34926 | 35059 | unixEnterMutex(); |
| 34927 | 35060 | pInode = inodeList; |
| 34928 | 35061 | while( pInode && (pInode->fileId.dev!=sStat.st_dev |
| 34929 | | - || pInode->fileId.ino!=sStat.st_ino) ){ |
| 35062 | + || pInode->fileId.ino!=(u64)sStat.st_ino) ){ |
| 34930 | 35063 | pInode = pInode->pNext; |
| 34931 | 35064 | } |
| 34932 | 35065 | if( pInode ){ |
| 34933 | 35066 | UnixUnusedFd **pp; |
| 34934 | 35067 | for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext)); |
| | @@ -43485,11 +43618,11 @@ |
| 43485 | 43618 | */ |
| 43486 | 43619 | SQLITE_PRIVATE u32 sqlite3BitvecSize(Bitvec *p){ |
| 43487 | 43620 | return p->iSize; |
| 43488 | 43621 | } |
| 43489 | 43622 | |
| 43490 | | -#ifndef SQLITE_OMIT_BUILTIN_TEST |
| 43623 | +#ifndef SQLITE_UNTESTABLE |
| 43491 | 43624 | /* |
| 43492 | 43625 | ** Let V[] be an array of unsigned characters sufficient to hold |
| 43493 | 43626 | ** up to N bits. Let I be an integer between 0 and N. 0<=I<N. |
| 43494 | 43627 | ** Then the following macros can be used to set, clear, or test |
| 43495 | 43628 | ** individual bits within V. |
| | @@ -43600,11 +43733,11 @@ |
| 43600 | 43733 | sqlite3_free(pTmpSpace); |
| 43601 | 43734 | sqlite3_free(pV); |
| 43602 | 43735 | sqlite3BitvecDestroy(pBitvec); |
| 43603 | 43736 | return rc; |
| 43604 | 43737 | } |
| 43605 | | -#endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 43738 | +#endif /* SQLITE_UNTESTABLE */ |
| 43606 | 43739 | |
| 43607 | 43740 | /************** End of bitvec.c **********************************************/ |
| 43608 | 43741 | /************** Begin file pcache.c ******************************************/ |
| 43609 | 43742 | /* |
| 43610 | 43743 | ** 2008 August 05 |
| | @@ -46398,10 +46531,11 @@ |
| 46398 | 46531 | SQLITE_PRIVATE int sqlite3WalHeapMemory(Wal *pWal); |
| 46399 | 46532 | |
| 46400 | 46533 | #ifdef SQLITE_ENABLE_SNAPSHOT |
| 46401 | 46534 | SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot); |
| 46402 | 46535 | SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot); |
| 46536 | +SQLITE_PRIVATE int sqlite3WalSnapshotRecover(Wal *pWal); |
| 46403 | 46537 | #endif |
| 46404 | 46538 | |
| 46405 | 46539 | #ifdef SQLITE_ENABLE_ZIPVFS |
| 46406 | 46540 | /* If the WAL file is not empty, return the number of bytes of content |
| 46407 | 46541 | ** stored in each frame (i.e. the db page-size when the WAL was created). |
| | @@ -53799,10 +53933,24 @@ |
| 53799 | 53933 | }else{ |
| 53800 | 53934 | rc = SQLITE_ERROR; |
| 53801 | 53935 | } |
| 53802 | 53936 | return rc; |
| 53803 | 53937 | } |
| 53938 | + |
| 53939 | +/* |
| 53940 | +** If this is a WAL database, call sqlite3WalSnapshotRecover(). If this |
| 53941 | +** is not a WAL database, return an error. |
| 53942 | +*/ |
| 53943 | +SQLITE_PRIVATE int sqlite3PagerSnapshotRecover(Pager *pPager){ |
| 53944 | + int rc; |
| 53945 | + if( pPager->pWal ){ |
| 53946 | + rc = sqlite3WalSnapshotRecover(pPager->pWal); |
| 53947 | + }else{ |
| 53948 | + rc = SQLITE_ERROR; |
| 53949 | + } |
| 53950 | + return rc; |
| 53951 | +} |
| 53804 | 53952 | #endif /* SQLITE_ENABLE_SNAPSHOT */ |
| 53805 | 53953 | #endif /* !SQLITE_OMIT_WAL */ |
| 53806 | 53954 | |
| 53807 | 53955 | #ifdef SQLITE_ENABLE_ZIPVFS |
| 53808 | 53956 | /* |
| | @@ -56201,10 +56349,88 @@ |
| 56201 | 56349 | pWal->readLock = (i16)mxI; |
| 56202 | 56350 | } |
| 56203 | 56351 | return rc; |
| 56204 | 56352 | } |
| 56205 | 56353 | |
| 56354 | +#ifdef SQLITE_ENABLE_SNAPSHOT |
| 56355 | +/* |
| 56356 | +** Attempt to reduce the value of the WalCkptInfo.nBackfillAttempted |
| 56357 | +** variable so that older snapshots can be accessed. To do this, loop |
| 56358 | +** through all wal frames from nBackfillAttempted to (nBackfill+1), |
| 56359 | +** comparing their content to the corresponding page with the database |
| 56360 | +** file, if any. Set nBackfillAttempted to the frame number of the |
| 56361 | +** first frame for which the wal file content matches the db file. |
| 56362 | +** |
| 56363 | +** This is only really safe if the file-system is such that any page |
| 56364 | +** writes made by earlier checkpointers were atomic operations, which |
| 56365 | +** is not always true. It is also possible that nBackfillAttempted |
| 56366 | +** may be left set to a value larger than expected, if a wal frame |
| 56367 | +** contains content that duplicate of an earlier version of the same |
| 56368 | +** page. |
| 56369 | +** |
| 56370 | +** SQLITE_OK is returned if successful, or an SQLite error code if an |
| 56371 | +** error occurs. It is not an error if nBackfillAttempted cannot be |
| 56372 | +** decreased at all. |
| 56373 | +*/ |
| 56374 | +SQLITE_PRIVATE int sqlite3WalSnapshotRecover(Wal *pWal){ |
| 56375 | + int rc; |
| 56376 | + |
| 56377 | + assert( pWal->readLock>=0 ); |
| 56378 | + rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 56379 | + if( rc==SQLITE_OK ){ |
| 56380 | + volatile WalCkptInfo *pInfo = walCkptInfo(pWal); |
| 56381 | + int szPage = (int)pWal->szPage; |
| 56382 | + i64 szDb; /* Size of db file in bytes */ |
| 56383 | + |
| 56384 | + rc = sqlite3OsFileSize(pWal->pDbFd, &szDb); |
| 56385 | + if( rc==SQLITE_OK ){ |
| 56386 | + void *pBuf1 = sqlite3_malloc(szPage); |
| 56387 | + void *pBuf2 = sqlite3_malloc(szPage); |
| 56388 | + if( pBuf1==0 || pBuf2==0 ){ |
| 56389 | + rc = SQLITE_NOMEM; |
| 56390 | + }else{ |
| 56391 | + u32 i = pInfo->nBackfillAttempted; |
| 56392 | + for(i=pInfo->nBackfillAttempted; i>pInfo->nBackfill; i--){ |
| 56393 | + volatile ht_slot *dummy; |
| 56394 | + volatile u32 *aPgno; /* Array of page numbers */ |
| 56395 | + u32 iZero; /* Frame corresponding to aPgno[0] */ |
| 56396 | + u32 pgno; /* Page number in db file */ |
| 56397 | + i64 iDbOff; /* Offset of db file entry */ |
| 56398 | + i64 iWalOff; /* Offset of wal file entry */ |
| 56399 | + |
| 56400 | + rc = walHashGet(pWal, walFramePage(i), &dummy, &aPgno, &iZero); |
| 56401 | + if( rc!=SQLITE_OK ) break; |
| 56402 | + pgno = aPgno[i-iZero]; |
| 56403 | + iDbOff = (i64)(pgno-1) * szPage; |
| 56404 | + |
| 56405 | + if( iDbOff+szPage<=szDb ){ |
| 56406 | + iWalOff = walFrameOffset(i, szPage) + WAL_FRAME_HDRSIZE; |
| 56407 | + rc = sqlite3OsRead(pWal->pWalFd, pBuf1, szPage, iWalOff); |
| 56408 | + |
| 56409 | + if( rc==SQLITE_OK ){ |
| 56410 | + rc = sqlite3OsRead(pWal->pDbFd, pBuf2, szPage, iDbOff); |
| 56411 | + } |
| 56412 | + |
| 56413 | + if( rc!=SQLITE_OK || 0==memcmp(pBuf1, pBuf2, szPage) ){ |
| 56414 | + break; |
| 56415 | + } |
| 56416 | + } |
| 56417 | + |
| 56418 | + pInfo->nBackfillAttempted = i-1; |
| 56419 | + } |
| 56420 | + } |
| 56421 | + |
| 56422 | + sqlite3_free(pBuf1); |
| 56423 | + sqlite3_free(pBuf2); |
| 56424 | + } |
| 56425 | + walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1); |
| 56426 | + } |
| 56427 | + |
| 56428 | + return rc; |
| 56429 | +} |
| 56430 | +#endif /* SQLITE_ENABLE_SNAPSHOT */ |
| 56431 | + |
| 56206 | 56432 | /* |
| 56207 | 56433 | ** Begin a read transaction on the database. |
| 56208 | 56434 | ** |
| 56209 | 56435 | ** This routine used to be called sqlite3OpenSnapshot() and with good reason: |
| 56210 | 56436 | ** it takes a snapshot of the state of the WAL and wal-index for the current |
| | @@ -56263,11 +56489,15 @@ |
| 56263 | 56489 | ** checkpointer has already determined that it will checkpoint |
| 56264 | 56490 | ** snapshot X, where X is later in the wal file than pSnapshot, but |
| 56265 | 56491 | ** has not yet set the pInfo->nBackfillAttempted variable to indicate |
| 56266 | 56492 | ** its intent. To avoid the race condition this leads to, ensure that |
| 56267 | 56493 | ** there is no checkpointer process by taking a shared CKPT lock |
| 56268 | | - ** before checking pInfo->nBackfillAttempted. */ |
| 56494 | + ** before checking pInfo->nBackfillAttempted. |
| 56495 | + ** |
| 56496 | + ** TODO: Does the aReadMark[] lock prevent a checkpointer from doing |
| 56497 | + ** this already? |
| 56498 | + */ |
| 56269 | 56499 | rc = walLockShared(pWal, WAL_CKPT_LOCK); |
| 56270 | 56500 | |
| 56271 | 56501 | if( rc==SQLITE_OK ){ |
| 56272 | 56502 | /* Check that the wal file has not been wrapped. Assuming that it has |
| 56273 | 56503 | ** not, also check that no checkpointer has attempted to checkpoint any |
| | @@ -57215,13 +57445,18 @@ |
| 57215 | 57445 | ** in the object. |
| 57216 | 57446 | */ |
| 57217 | 57447 | SQLITE_PRIVATE int sqlite3WalSnapshotGet(Wal *pWal, sqlite3_snapshot **ppSnapshot){ |
| 57218 | 57448 | int rc = SQLITE_OK; |
| 57219 | 57449 | WalIndexHdr *pRet; |
| 57450 | + static const u32 aZero[4] = { 0, 0, 0, 0 }; |
| 57220 | 57451 | |
| 57221 | 57452 | assert( pWal->readLock>=0 && pWal->writeLock==0 ); |
| 57222 | 57453 | |
| 57454 | + if( memcmp(&pWal->hdr.aFrameCksum[0],aZero,16)==0 ){ |
| 57455 | + *ppSnapshot = 0; |
| 57456 | + return SQLITE_ERROR; |
| 57457 | + } |
| 57223 | 57458 | pRet = (WalIndexHdr*)sqlite3_malloc(sizeof(WalIndexHdr)); |
| 57224 | 57459 | if( pRet==0 ){ |
| 57225 | 57460 | rc = SQLITE_NOMEM_BKPT; |
| 57226 | 57461 | }else{ |
| 57227 | 57462 | memcpy(pRet, &pWal->hdr, sizeof(WalIndexHdr)); |
| | @@ -58922,11 +59157,11 @@ |
| 58922 | 59157 | /* For an index btree, save the complete key content */ |
| 58923 | 59158 | void *pKey; |
| 58924 | 59159 | pCur->nKey = sqlite3BtreePayloadSize(pCur); |
| 58925 | 59160 | pKey = sqlite3Malloc( pCur->nKey ); |
| 58926 | 59161 | if( pKey ){ |
| 58927 | | - rc = sqlite3BtreeKey(pCur, 0, (int)pCur->nKey, pKey); |
| 59162 | + rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey); |
| 58928 | 59163 | if( rc==SQLITE_OK ){ |
| 58929 | 59164 | pCur->pKey = pKey; |
| 58930 | 59165 | }else{ |
| 58931 | 59166 | sqlite3_free(pKey); |
| 58932 | 59167 | } |
| | @@ -62941,47 +63176,39 @@ |
| 62941 | 63176 | } |
| 62942 | 63177 | return rc; |
| 62943 | 63178 | } |
| 62944 | 63179 | |
| 62945 | 63180 | /* |
| 62946 | | -** Read part of the key associated with cursor pCur. Exactly |
| 62947 | | -** "amt" bytes will be transferred into pBuf[]. The transfer |
| 63181 | +** Read part of the payload for the row at which that cursor pCur is currently |
| 63182 | +** pointing. "amt" bytes will be transferred into pBuf[]. The transfer |
| 62948 | 63183 | ** begins at "offset". |
| 62949 | 63184 | ** |
| 62950 | | -** The caller must ensure that pCur is pointing to a valid row |
| 62951 | | -** in the table. |
| 63185 | +** pCur can be pointing to either a table or an index b-tree. |
| 63186 | +** If pointing to a table btree, then the content section is read. If |
| 63187 | +** pCur is pointing to an index b-tree then the key section is read. |
| 63188 | +** |
| 63189 | +** For sqlite3BtreePayload(), the caller must ensure that pCur is pointing |
| 63190 | +** to a valid row in the table. For sqlite3BtreePayloadChecked(), the |
| 63191 | +** cursor might be invalid or might need to be restored before being read. |
| 62952 | 63192 | ** |
| 62953 | 63193 | ** Return SQLITE_OK on success or an error code if anything goes |
| 62954 | 63194 | ** wrong. An error is returned if "offset+amt" is larger than |
| 62955 | 63195 | ** the available payload. |
| 62956 | 63196 | */ |
| 62957 | | -SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 63197 | +SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 62958 | 63198 | assert( cursorHoldsMutex(pCur) ); |
| 62959 | 63199 | assert( pCur->eState==CURSOR_VALID ); |
| 62960 | 63200 | assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] ); |
| 62961 | 63201 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 62962 | 63202 | return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0); |
| 62963 | 63203 | } |
| 62964 | | - |
| 62965 | | -/* |
| 62966 | | -** Read part of the data associated with cursor pCur. Exactly |
| 62967 | | -** "amt" bytes will be transfered into pBuf[]. The transfer |
| 62968 | | -** begins at "offset". |
| 62969 | | -** |
| 62970 | | -** Return SQLITE_OK on success or an error code if anything goes |
| 62971 | | -** wrong. An error is returned if "offset+amt" is larger than |
| 62972 | | -** the available payload. |
| 62973 | | -*/ |
| 62974 | | -SQLITE_PRIVATE int sqlite3BtreeData(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 62975 | | - int rc; |
| 62976 | | - |
| 62977 | 63204 | #ifndef SQLITE_OMIT_INCRBLOB |
| 63205 | +SQLITE_PRIVATE int sqlite3BtreePayloadChecked(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){ |
| 63206 | + int rc; |
| 62978 | 63207 | if ( pCur->eState==CURSOR_INVALID ){ |
| 62979 | 63208 | return SQLITE_ABORT; |
| 62980 | 63209 | } |
| 62981 | | -#endif |
| 62982 | | - |
| 62983 | 63210 | assert( cursorOwnsBtShared(pCur) ); |
| 62984 | 63211 | rc = restoreCursorPosition(pCur); |
| 62985 | 63212 | if( rc==SQLITE_OK ){ |
| 62986 | 63213 | assert( pCur->eState==CURSOR_VALID ); |
| 62987 | 63214 | assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] ); |
| | @@ -62988,10 +63215,11 @@ |
| 62988 | 63215 | assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell ); |
| 62989 | 63216 | rc = accessPayload(pCur, offset, amt, pBuf, 0); |
| 62990 | 63217 | } |
| 62991 | 63218 | return rc; |
| 62992 | 63219 | } |
| 63220 | +#endif /* SQLITE_OMIT_INCRBLOB */ |
| 62993 | 63221 | |
| 62994 | 63222 | /* |
| 62995 | 63223 | ** Return a pointer to payload information from the entry that the |
| 62996 | 63224 | ** pCur cursor is pointing to. The pointer is to the beginning of |
| 62997 | 63225 | ** the key if index btrees (pPage->intKey==0) and is the data for |
| | @@ -69752,14 +69980,13 @@ |
| 69752 | 69980 | return SQLITE_OK; |
| 69753 | 69981 | } |
| 69754 | 69982 | |
| 69755 | 69983 | /* |
| 69756 | 69984 | ** Move data out of a btree key or data field and into a Mem structure. |
| 69757 | | -** The data or key is taken from the entry that pCur is currently pointing |
| 69985 | +** The data is payload from the entry that pCur is currently pointing |
| 69758 | 69986 | ** to. offset and amt determine what portion of the data or key to retrieve. |
| 69759 | | -** key is true to get the key or false to get data. The result is written |
| 69760 | | -** into the pMem element. |
| 69987 | +** The result is written into the pMem element. |
| 69761 | 69988 | ** |
| 69762 | 69989 | ** The pMem object must have been initialized. This routine will use |
| 69763 | 69990 | ** pMem->zMalloc to hold the content from the btree, if possible. New |
| 69764 | 69991 | ** pMem->zMalloc space will be allocated if necessary. The calling routine |
| 69765 | 69992 | ** is responsible for making sure that the pMem object is eventually |
| | @@ -69770,21 +69997,16 @@ |
| 69770 | 69997 | */ |
| 69771 | 69998 | static SQLITE_NOINLINE int vdbeMemFromBtreeResize( |
| 69772 | 69999 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 69773 | 70000 | u32 offset, /* Offset from the start of data to return bytes from. */ |
| 69774 | 70001 | u32 amt, /* Number of bytes to return. */ |
| 69775 | | - int key, /* If true, retrieve from the btree key, not data. */ |
| 69776 | 70002 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 69777 | 70003 | ){ |
| 69778 | 70004 | int rc; |
| 69779 | 70005 | pMem->flags = MEM_Null; |
| 69780 | 70006 | if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+2)) ){ |
| 69781 | | - if( key ){ |
| 69782 | | - rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z); |
| 69783 | | - }else{ |
| 69784 | | - rc = sqlite3BtreeData(pCur, offset, amt, pMem->z); |
| 69785 | | - } |
| 70007 | + rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z); |
| 69786 | 70008 | if( rc==SQLITE_OK ){ |
| 69787 | 70009 | pMem->z[amt] = 0; |
| 69788 | 70010 | pMem->z[amt+1] = 0; |
| 69789 | 70011 | pMem->flags = MEM_Blob|MEM_Term; |
| 69790 | 70012 | pMem->n = (int)amt; |
| | @@ -69796,11 +70018,10 @@ |
| 69796 | 70018 | } |
| 69797 | 70019 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree( |
| 69798 | 70020 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 69799 | 70021 | u32 offset, /* Offset from the start of data to return bytes from. */ |
| 69800 | 70022 | u32 amt, /* Number of bytes to return. */ |
| 69801 | | - int key, /* If true, retrieve from the btree key, not data. */ |
| 69802 | 70023 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 69803 | 70024 | ){ |
| 69804 | 70025 | char *zData; /* Data from the btree layer */ |
| 69805 | 70026 | u32 available = 0; /* Number of bytes available on the local btree page */ |
| 69806 | 70027 | int rc = SQLITE_OK; /* Return code */ |
| | @@ -69817,11 +70038,11 @@ |
| 69817 | 70038 | if( offset+amt<=available ){ |
| 69818 | 70039 | pMem->z = &zData[offset]; |
| 69819 | 70040 | pMem->flags = MEM_Blob|MEM_Ephem; |
| 69820 | 70041 | pMem->n = (int)amt; |
| 69821 | 70042 | }else{ |
| 69822 | | - rc = vdbeMemFromBtreeResize(pCur, offset, amt, key, pMem); |
| 70043 | + rc = vdbeMemFromBtreeResize(pCur, offset, amt, pMem); |
| 69823 | 70044 | } |
| 69824 | 70045 | |
| 69825 | 70046 | return rc; |
| 69826 | 70047 | } |
| 69827 | 70048 | |
| | @@ -70847,11 +71068,15 @@ |
| 70847 | 71068 | int p2, /* The P2 operand */ |
| 70848 | 71069 | int p3, /* The P3 operand */ |
| 70849 | 71070 | int p4 /* The P4 operand as an integer */ |
| 70850 | 71071 | ){ |
| 70851 | 71072 | int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3); |
| 70852 | | - sqlite3VdbeChangeP4(p, addr, SQLITE_INT_TO_PTR(p4), P4_INT32); |
| 71073 | + if( p->db->mallocFailed==0 ){ |
| 71074 | + VdbeOp *pOp = &p->aOp[addr]; |
| 71075 | + pOp->p4type = P4_INT32; |
| 71076 | + pOp->p4.i = p4; |
| 71077 | + } |
| 70853 | 71078 | return addr; |
| 70854 | 71079 | } |
| 70855 | 71080 | |
| 70856 | 71081 | /* Insert the end of a co-routine |
| 70857 | 71082 | */ |
| | @@ -71358,14 +71583,10 @@ |
| 71358 | 71583 | case P4_EXPR: { |
| 71359 | 71584 | sqlite3ExprDelete(db, (Expr*)p4); |
| 71360 | 71585 | break; |
| 71361 | 71586 | } |
| 71362 | 71587 | #endif |
| 71363 | | - case P4_MPRINTF: { |
| 71364 | | - if( db->pnBytesFreed==0 ) sqlite3_free(p4); |
| 71365 | | - break; |
| 71366 | | - } |
| 71367 | 71588 | case P4_FUNCDEF: { |
| 71368 | 71589 | freeEphemeralFunction(db, (FuncDef*)p4); |
| 71369 | 71590 | break; |
| 71370 | 71591 | } |
| 71371 | 71592 | case P4_MEM: { |
| | @@ -71505,21 +71726,47 @@ |
| 71505 | 71726 | pOp->p4.p = (void*)zP4; |
| 71506 | 71727 | pOp->p4type = (signed char)n; |
| 71507 | 71728 | if( n==P4_VTAB ) sqlite3VtabLock((VTable*)zP4); |
| 71508 | 71729 | } |
| 71509 | 71730 | } |
| 71731 | + |
| 71732 | +/* |
| 71733 | +** Change the P4 operand of the most recently coded instruction |
| 71734 | +** to the value defined by the arguments. This is a high-speed |
| 71735 | +** version of sqlite3VdbeChangeP4(). |
| 71736 | +** |
| 71737 | +** The P4 operand must not have been previously defined. And the new |
| 71738 | +** P4 must not be P4_INT32. Use sqlite3VdbeChangeP4() in either of |
| 71739 | +** those cases. |
| 71740 | +*/ |
| 71741 | +SQLITE_PRIVATE void sqlite3VdbeAppendP4(Vdbe *p, void *pP4, int n){ |
| 71742 | + VdbeOp *pOp; |
| 71743 | + assert( n!=P4_INT32 && n!=P4_VTAB ); |
| 71744 | + assert( n<=0 ); |
| 71745 | + if( p->db->mallocFailed ){ |
| 71746 | + freeP4(p->db, n, pP4); |
| 71747 | + }else{ |
| 71748 | + assert( pP4!=0 ); |
| 71749 | + assert( p->nOp>0 ); |
| 71750 | + pOp = &p->aOp[p->nOp-1]; |
| 71751 | + assert( pOp->p4type==P4_NOTUSED ); |
| 71752 | + pOp->p4type = n; |
| 71753 | + pOp->p4.p = pP4; |
| 71754 | + } |
| 71755 | +} |
| 71510 | 71756 | |
| 71511 | 71757 | /* |
| 71512 | 71758 | ** Set the P4 on the most recently added opcode to the KeyInfo for the |
| 71513 | 71759 | ** index given. |
| 71514 | 71760 | */ |
| 71515 | 71761 | SQLITE_PRIVATE void sqlite3VdbeSetP4KeyInfo(Parse *pParse, Index *pIdx){ |
| 71516 | 71762 | Vdbe *v = pParse->pVdbe; |
| 71763 | + KeyInfo *pKeyInfo; |
| 71517 | 71764 | assert( v!=0 ); |
| 71518 | 71765 | assert( pIdx!=0 ); |
| 71519 | | - sqlite3VdbeChangeP4(v, -1, (char*)sqlite3KeyInfoOfIndex(pParse, pIdx), |
| 71520 | | - P4_KEYINFO); |
| 71766 | + pKeyInfo = sqlite3KeyInfoOfIndex(pParse, pIdx); |
| 71767 | + if( pKeyInfo ) sqlite3VdbeAppendP4(v, pKeyInfo, P4_KEYINFO); |
| 71521 | 71768 | } |
| 71522 | 71769 | |
| 71523 | 71770 | #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS |
| 71524 | 71771 | /* |
| 71525 | 71772 | ** Change the comment on the most recently coded instruction. Or |
| | @@ -71805,11 +72052,11 @@ |
| 71805 | 72052 | case P4_FUNCDEF: { |
| 71806 | 72053 | FuncDef *pDef = pOp->p4.pFunc; |
| 71807 | 72054 | sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg); |
| 71808 | 72055 | break; |
| 71809 | 72056 | } |
| 71810 | | -#ifdef SQLITE_DEBUG |
| 72057 | +#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE) |
| 71811 | 72058 | case P4_FUNCCTX: { |
| 71812 | 72059 | FuncDef *pDef = pOp->p4.pCtx->pFunc; |
| 71813 | 72060 | sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg); |
| 71814 | 72061 | break; |
| 71815 | 72062 | } |
| | @@ -74899,11 +75146,11 @@ |
| 74899 | 75146 | nCellKey = sqlite3BtreePayloadSize(pCur); |
| 74900 | 75147 | assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey ); |
| 74901 | 75148 | |
| 74902 | 75149 | /* Read in the complete content of the index entry */ |
| 74903 | 75150 | sqlite3VdbeMemInit(&m, db, 0); |
| 74904 | | - rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m); |
| 75151 | + rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m); |
| 74905 | 75152 | if( rc ){ |
| 74906 | 75153 | return rc; |
| 74907 | 75154 | } |
| 74908 | 75155 | |
| 74909 | 75156 | /* The index entry must begin with a header size */ |
| | @@ -74979,11 +75226,11 @@ |
| 74979 | 75226 | if( nCellKey<=0 || nCellKey>0x7fffffff ){ |
| 74980 | 75227 | *res = 0; |
| 74981 | 75228 | return SQLITE_CORRUPT_BKPT; |
| 74982 | 75229 | } |
| 74983 | 75230 | sqlite3VdbeMemInit(&m, db, 0); |
| 74984 | | - rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m); |
| 75231 | + rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, &m); |
| 74985 | 75232 | if( rc ){ |
| 74986 | 75233 | return rc; |
| 74987 | 75234 | } |
| 74988 | 75235 | *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked); |
| 74989 | 75236 | sqlite3VdbeMemRelease(&m); |
| | @@ -76868,11 +77115,11 @@ |
| 76868 | 77115 | u8 *aRec; |
| 76869 | 77116 | |
| 76870 | 77117 | nRec = sqlite3BtreePayloadSize(p->pCsr->uc.pCursor); |
| 76871 | 77118 | aRec = sqlite3DbMallocRaw(db, nRec); |
| 76872 | 77119 | if( !aRec ) goto preupdate_old_out; |
| 76873 | | - rc = sqlite3BtreeData(p->pCsr->uc.pCursor, 0, nRec, aRec); |
| 77120 | + rc = sqlite3BtreePayload(p->pCsr->uc.pCursor, 0, nRec, aRec); |
| 76874 | 77121 | if( rc==SQLITE_OK ){ |
| 76875 | 77122 | p->pUnpacked = vdbeUnpackRecord(&p->keyinfo, nRec, aRec); |
| 76876 | 77123 | if( !p->pUnpacked ) rc = SQLITE_NOMEM; |
| 76877 | 77124 | } |
| 76878 | 77125 | if( rc!=SQLITE_OK ){ |
| | @@ -77385,11 +77632,11 @@ |
| 77385 | 77632 | |
| 77386 | 77633 | /* |
| 77387 | 77634 | ** Test a register to see if it exceeds the current maximum blob size. |
| 77388 | 77635 | ** If it does, record the new maximum blob size. |
| 77389 | 77636 | */ |
| 77390 | | -#if defined(SQLITE_TEST) && !defined(SQLITE_OMIT_BUILTIN_TEST) |
| 77637 | +#if defined(SQLITE_TEST) && !defined(SQLITE_UNTESTABLE) |
| 77391 | 77638 | # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P) |
| 77392 | 77639 | #else |
| 77393 | 77640 | # define UPDATE_MAX_BLOBSIZE(P) |
| 77394 | 77641 | #endif |
| 77395 | 77642 | |
| | @@ -79833,11 +80080,10 @@ |
| 79833 | 80080 | assert( p2<pC->nField ); |
| 79834 | 80081 | aOffset = pC->aOffset; |
| 79835 | 80082 | assert( pC->eCurType!=CURTYPE_VTAB ); |
| 79836 | 80083 | assert( pC->eCurType!=CURTYPE_PSEUDO || pC->nullRow ); |
| 79837 | 80084 | assert( pC->eCurType!=CURTYPE_SORTER ); |
| 79838 | | - pCrsr = pC->uc.pCursor; |
| 79839 | 80085 | |
| 79840 | 80086 | if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/ |
| 79841 | 80087 | if( pC->nullRow ){ |
| 79842 | 80088 | if( pC->eCurType==CURTYPE_PSEUDO ){ |
| 79843 | 80089 | assert( pC->uc.pseudoTableReg>0 ); |
| | @@ -79849,10 +80095,11 @@ |
| 79849 | 80095 | }else{ |
| 79850 | 80096 | sqlite3VdbeMemSetNull(pDest); |
| 79851 | 80097 | goto op_column_out; |
| 79852 | 80098 | } |
| 79853 | 80099 | }else{ |
| 80100 | + pCrsr = pC->uc.pCursor; |
| 79854 | 80101 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 79855 | 80102 | assert( pCrsr ); |
| 79856 | 80103 | assert( sqlite3BtreeCursorIsValid(pCrsr) ); |
| 79857 | 80104 | pC->payloadSize = sqlite3BtreePayloadSize(pCrsr); |
| 79858 | 80105 | pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &avail); |
| | @@ -79912,11 +80159,11 @@ |
| 79912 | 80159 | */ |
| 79913 | 80160 | if( pC->iHdrOffset<aOffset[0] ){ |
| 79914 | 80161 | /* Make sure zData points to enough of the record to cover the header. */ |
| 79915 | 80162 | if( pC->aRow==0 ){ |
| 79916 | 80163 | memset(&sMem, 0, sizeof(sMem)); |
| 79917 | | - rc = sqlite3VdbeMemFromBtree(pCrsr, 0, aOffset[0], !pC->isTable, &sMem); |
| 80164 | + rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, 0, aOffset[0], &sMem); |
| 79918 | 80165 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 79919 | 80166 | zData = (u8*)sMem.z; |
| 79920 | 80167 | }else{ |
| 79921 | 80168 | zData = pC->aRow; |
| 79922 | 80169 | } |
| | @@ -80025,12 +80272,11 @@ |
| 80025 | 80272 | ** So we might as well use bogus content rather than reading |
| 80026 | 80273 | ** content from disk. */ |
| 80027 | 80274 | static u8 aZero[8]; /* This is the bogus content */ |
| 80028 | 80275 | sqlite3VdbeSerialGet(aZero, t, pDest); |
| 80029 | 80276 | }else{ |
| 80030 | | - rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable, |
| 80031 | | - pDest); |
| 80277 | + rc = sqlite3VdbeMemFromBtree(pC->uc.pCursor, aOffset[p2], len, pDest); |
| 80032 | 80278 | if( rc!=SQLITE_OK ) goto abort_due_to_error; |
| 80033 | 80279 | sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest); |
| 80034 | 80280 | pDest->flags &= ~MEM_Ephem; |
| 80035 | 80281 | } |
| 80036 | 80282 | } |
| | @@ -82002,51 +82248,40 @@ |
| 82002 | 82248 | } |
| 82003 | 82249 | |
| 82004 | 82250 | /* Opcode: RowData P1 P2 * * * |
| 82005 | 82251 | ** Synopsis: r[P2]=data |
| 82006 | 82252 | ** |
| 82007 | | -** Write into register P2 the complete row data for cursor P1. |
| 82253 | +** Write into register P2 the complete row content for the row at |
| 82254 | +** which cursor P1 is currently pointing. |
| 82008 | 82255 | ** There is no interpretation of the data. |
| 82009 | 82256 | ** It is just copied onto the P2 register exactly as |
| 82010 | 82257 | ** it is found in the database file. |
| 82011 | 82258 | ** |
| 82012 | | -** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 82013 | | -** of a real table, not a pseudo-table. |
| 82014 | | -*/ |
| 82015 | | -/* Opcode: RowKey P1 P2 * * * |
| 82016 | | -** Synopsis: r[P2]=key |
| 82017 | | -** |
| 82018 | | -** Write into register P2 the complete row key for cursor P1. |
| 82019 | | -** There is no interpretation of the data. |
| 82020 | | -** The key is copied onto the P2 register exactly as |
| 82021 | | -** it is found in the database file. |
| 82259 | +** If cursor P1 is an index, then the content is the key of the row. |
| 82260 | +** If cursor P2 is a table, then the content extracted is the data. |
| 82022 | 82261 | ** |
| 82023 | 82262 | ** If the P1 cursor must be pointing to a valid row (not a NULL row) |
| 82024 | 82263 | ** of a real table, not a pseudo-table. |
| 82025 | 82264 | */ |
| 82026 | | -case OP_RowKey: |
| 82027 | 82265 | case OP_RowData: { |
| 82028 | 82266 | VdbeCursor *pC; |
| 82029 | 82267 | BtCursor *pCrsr; |
| 82030 | 82268 | u32 n; |
| 82031 | 82269 | |
| 82032 | 82270 | pOut = &aMem[pOp->p2]; |
| 82033 | 82271 | memAboutToChange(p, pOut); |
| 82034 | 82272 | |
| 82035 | | - /* Note that RowKey and RowData are really exactly the same instruction */ |
| 82036 | 82273 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 82037 | 82274 | pC = p->apCsr[pOp->p1]; |
| 82038 | 82275 | assert( pC!=0 ); |
| 82039 | 82276 | assert( pC->eCurType==CURTYPE_BTREE ); |
| 82040 | 82277 | assert( isSorter(pC)==0 ); |
| 82041 | | - assert( pC->isTable || pOp->opcode!=OP_RowData ); |
| 82042 | | - assert( pC->isTable==0 || pOp->opcode==OP_RowData ); |
| 82043 | 82278 | assert( pC->nullRow==0 ); |
| 82044 | 82279 | assert( pC->uc.pCursor!=0 ); |
| 82045 | 82280 | pCrsr = pC->uc.pCursor; |
| 82046 | 82281 | |
| 82047 | | - /* The OP_RowKey and OP_RowData opcodes always follow OP_NotExists or |
| 82282 | + /* The OP_RowData opcodes always follow OP_NotExists or |
| 82048 | 82283 | ** OP_SeekRowid or OP_Rewind/Op_Next with no intervening instructions |
| 82049 | 82284 | ** that might invalidate the cursor. |
| 82050 | 82285 | ** If this where not the case, on of the following assert()s |
| 82051 | 82286 | ** would fail. Should this ever change (because of changes in the code |
| 82052 | 82287 | ** generator) then the fix would be to insert a call to |
| | @@ -82067,15 +82302,11 @@ |
| 82067 | 82302 | if( sqlite3VdbeMemClearAndResize(pOut, MAX(n,32)) ){ |
| 82068 | 82303 | goto no_mem; |
| 82069 | 82304 | } |
| 82070 | 82305 | pOut->n = n; |
| 82071 | 82306 | MemSetTypeFlag(pOut, MEM_Blob); |
| 82072 | | - if( pC->isTable==0 ){ |
| 82073 | | - rc = sqlite3BtreeKey(pCrsr, 0, n, pOut->z); |
| 82074 | | - }else{ |
| 82075 | | - rc = sqlite3BtreeData(pCrsr, 0, n, pOut->z); |
| 82076 | | - } |
| 82307 | + rc = sqlite3BtreePayload(pCrsr, 0, n, pOut->z); |
| 82077 | 82308 | if( rc ) goto abort_due_to_error; |
| 82078 | 82309 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ |
| 82079 | 82310 | UPDATE_MAX_BLOBSIZE(pOut); |
| 82080 | 82311 | REGISTER_TRACE(pOp->p2, pOut); |
| 82081 | 82312 | break; |
| | @@ -83401,17 +83632,17 @@ |
| 83401 | 83632 | } |
| 83402 | 83633 | |
| 83403 | 83634 | /* Opcode: DecrJumpZero P1 P2 * * * |
| 83404 | 83635 | ** Synopsis: if (--r[P1])==0 goto P2 |
| 83405 | 83636 | ** |
| 83406 | | -** Register P1 must hold an integer. Decrement the value in register P1 |
| 83407 | | -** then jump to P2 if the new value is exactly zero. |
| 83637 | +** Register P1 must hold an integer. Decrement the value in P1 |
| 83638 | +** and jump to P2 if the new value is exactly zero. |
| 83408 | 83639 | */ |
| 83409 | 83640 | case OP_DecrJumpZero: { /* jump, in1 */ |
| 83410 | 83641 | pIn1 = &aMem[pOp->p1]; |
| 83411 | 83642 | assert( pIn1->flags&MEM_Int ); |
| 83412 | | - pIn1->u.i--; |
| 83643 | + if( pIn1->u.i>SMALLEST_INT64 ) pIn1->u.i--; |
| 83413 | 83644 | VdbeBranchTaken(pIn1->u.i==0, 2); |
| 83414 | 83645 | if( pIn1->u.i==0 ) goto jump_to_p2; |
| 83415 | 83646 | break; |
| 83416 | 83647 | } |
| 83417 | 83648 | |
| | @@ -84854,11 +85085,11 @@ |
| 84854 | 85085 | |
| 84855 | 85086 | /* |
| 84856 | 85087 | ** Read data from a blob handle. |
| 84857 | 85088 | */ |
| 84858 | 85089 | SQLITE_API int sqlite3_blob_read(sqlite3_blob *pBlob, void *z, int n, int iOffset){ |
| 84859 | | - return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreeData); |
| 85090 | + return blobReadWrite(pBlob, z, n, iOffset, sqlite3BtreePayloadChecked); |
| 84860 | 85091 | } |
| 84861 | 85092 | |
| 84862 | 85093 | /* |
| 84863 | 85094 | ** Write data to a blob handle. |
| 84864 | 85095 | */ |
| | @@ -90235,11 +90466,11 @@ |
| 90235 | 90466 | ** can be attached to pRight to cause this node to take ownership of |
| 90236 | 90467 | ** pVector. Typically there will be multiple TK_SELECT_COLUMN nodes |
| 90237 | 90468 | ** with the same pLeft pointer to the pVector, but only one of them |
| 90238 | 90469 | ** will own the pVector. |
| 90239 | 90470 | */ |
| 90240 | | - pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0, 0); |
| 90471 | + pRet = sqlite3PExpr(pParse, TK_SELECT_COLUMN, 0, 0); |
| 90241 | 90472 | if( pRet ){ |
| 90242 | 90473 | pRet->iColumn = iField; |
| 90243 | 90474 | pRet->pLeft = pVector; |
| 90244 | 90475 | } |
| 90245 | 90476 | assert( pRet==0 || pRet->iTable==0 ); |
| | @@ -90627,19 +90858,23 @@ |
| 90627 | 90858 | */ |
| 90628 | 90859 | SQLITE_PRIVATE Expr *sqlite3PExpr( |
| 90629 | 90860 | Parse *pParse, /* Parsing context */ |
| 90630 | 90861 | int op, /* Expression opcode */ |
| 90631 | 90862 | Expr *pLeft, /* Left operand */ |
| 90632 | | - Expr *pRight, /* Right operand */ |
| 90633 | | - const Token *pToken /* Argument token */ |
| 90863 | + Expr *pRight /* Right operand */ |
| 90634 | 90864 | ){ |
| 90635 | 90865 | Expr *p; |
| 90636 | 90866 | if( op==TK_AND && pParse->nErr==0 ){ |
| 90637 | 90867 | /* Take advantage of short-circuit false optimization for AND */ |
| 90638 | 90868 | p = sqlite3ExprAnd(pParse->db, pLeft, pRight); |
| 90639 | 90869 | }else{ |
| 90640 | | - p = sqlite3ExprAlloc(pParse->db, op & TKFLG_MASK, pToken, 1); |
| 90870 | + p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)); |
| 90871 | + if( p ){ |
| 90872 | + memset(p, 0, sizeof(Expr)); |
| 90873 | + p->op = op & TKFLG_MASK; |
| 90874 | + p->iAgg = -1; |
| 90875 | + } |
| 90641 | 90876 | sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight); |
| 90642 | 90877 | } |
| 90643 | 90878 | if( p ) { |
| 90644 | 90879 | sqlite3ExprCheckHeight(pParse, p->nHeight); |
| 90645 | 90880 | } |
| | @@ -92158,10 +92393,32 @@ |
| 92158 | 92393 | SQLITE_PRIVATE void sqlite3SubselectError(Parse *pParse, int nActual, int nExpect){ |
| 92159 | 92394 | const char *zFmt = "sub-select returns %d columns - expected %d"; |
| 92160 | 92395 | sqlite3ErrorMsg(pParse, zFmt, nActual, nExpect); |
| 92161 | 92396 | } |
| 92162 | 92397 | #endif |
| 92398 | + |
| 92399 | +/* |
| 92400 | +** Expression pExpr is a vector that has been used in a context where |
| 92401 | +** it is not permitted. If pExpr is a sub-select vector, this routine |
| 92402 | +** loads the Parse object with a message of the form: |
| 92403 | +** |
| 92404 | +** "sub-select returns N columns - expected 1" |
| 92405 | +** |
| 92406 | +** Or, if it is a regular scalar vector: |
| 92407 | +** |
| 92408 | +** "row value misused" |
| 92409 | +*/ |
| 92410 | +SQLITE_PRIVATE void sqlite3VectorErrorMsg(Parse *pParse, Expr *pExpr){ |
| 92411 | +#ifndef SQLITE_OMIT_SUBQUERY |
| 92412 | + if( pExpr->flags & EP_xIsSelect ){ |
| 92413 | + sqlite3SubselectError(pParse, pExpr->x.pSelect->pEList->nExpr, 1); |
| 92414 | + }else |
| 92415 | +#endif |
| 92416 | + { |
| 92417 | + sqlite3ErrorMsg(pParse, "row value misused"); |
| 92418 | + } |
| 92419 | +} |
| 92163 | 92420 | |
| 92164 | 92421 | /* |
| 92165 | 92422 | ** Generate code for scalar subqueries used as a subquery expression, EXISTS, |
| 92166 | 92423 | ** or IN operators. Examples: |
| 92167 | 92424 | ** |
| | @@ -92441,15 +92698,11 @@ |
| 92441 | 92698 | if( nVector!=pIn->x.pSelect->pEList->nExpr ){ |
| 92442 | 92699 | sqlite3SubselectError(pParse, pIn->x.pSelect->pEList->nExpr, nVector); |
| 92443 | 92700 | return 1; |
| 92444 | 92701 | } |
| 92445 | 92702 | }else if( nVector!=1 ){ |
| 92446 | | - if( (pIn->pLeft->flags & EP_xIsSelect) ){ |
| 92447 | | - sqlite3SubselectError(pParse, nVector, 1); |
| 92448 | | - }else{ |
| 92449 | | - sqlite3ErrorMsg(pParse, "row value misused"); |
| 92450 | | - } |
| 92703 | + sqlite3VectorErrorMsg(pParse, pIn->pLeft); |
| 92451 | 92704 | return 1; |
| 92452 | 92705 | } |
| 92453 | 92706 | return 0; |
| 92454 | 92707 | } |
| 92455 | 92708 | #endif |
| | @@ -92750,26 +93003,26 @@ |
| 92750 | 93003 | int c; |
| 92751 | 93004 | i64 value; |
| 92752 | 93005 | const char *z = pExpr->u.zToken; |
| 92753 | 93006 | assert( z!=0 ); |
| 92754 | 93007 | c = sqlite3DecOrHexToI64(z, &value); |
| 92755 | | - if( c==0 || (c==2 && negFlag) ){ |
| 92756 | | - if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; } |
| 92757 | | - sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64); |
| 92758 | | - }else{ |
| 93008 | + if( c==1 || (c==2 && !negFlag) || (negFlag && value==SMALLEST_INT64)){ |
| 92759 | 93009 | #ifdef SQLITE_OMIT_FLOATING_POINT |
| 92760 | 93010 | sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z); |
| 92761 | 93011 | #else |
| 92762 | 93012 | #ifndef SQLITE_OMIT_HEX_INTEGER |
| 92763 | 93013 | if( sqlite3_strnicmp(z,"0x",2)==0 ){ |
| 92764 | | - sqlite3ErrorMsg(pParse, "hex literal too big: %s", z); |
| 93014 | + sqlite3ErrorMsg(pParse, "hex literal too big: %s%s", negFlag?"-":"",z); |
| 92765 | 93015 | }else |
| 92766 | 93016 | #endif |
| 92767 | 93017 | { |
| 92768 | 93018 | codeReal(v, z, negFlag, iMem); |
| 92769 | 93019 | } |
| 92770 | 93020 | #endif |
| 93021 | + }else{ |
| 93022 | + if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; } |
| 93023 | + sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64); |
| 92771 | 93024 | } |
| 92772 | 93025 | } |
| 92773 | 93026 | } |
| 92774 | 93027 | |
| 92775 | 93028 | /* |
| | @@ -93104,11 +93357,11 @@ |
| 93104 | 93357 | }else{ |
| 93105 | 93358 | int i; |
| 93106 | 93359 | iResult = pParse->nMem+1; |
| 93107 | 93360 | pParse->nMem += nResult; |
| 93108 | 93361 | for(i=0; i<nResult; i++){ |
| 93109 | | - sqlite3ExprCode(pParse, p->x.pList->a[i].pExpr, i+iResult); |
| 93362 | + sqlite3ExprCodeFactorable(pParse, p->x.pList->a[i].pExpr, i+iResult); |
| 93110 | 93363 | } |
| 93111 | 93364 | } |
| 93112 | 93365 | } |
| 93113 | 93366 | return iResult; |
| 93114 | 93367 | } |
| | @@ -93218,11 +93471,11 @@ |
| 93218 | 93471 | assert( pExpr->u.zToken[0]!=0 ); |
| 93219 | 93472 | sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target); |
| 93220 | 93473 | if( pExpr->u.zToken[1]!=0 ){ |
| 93221 | 93474 | assert( pExpr->u.zToken[0]=='?' |
| 93222 | 93475 | || strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 ); |
| 93223 | | - sqlite3VdbeChangeP4(v, -1, pParse->azVar[pExpr->iColumn-1], P4_STATIC); |
| 93476 | + sqlite3VdbeAppendP4(v, pParse->azVar[pExpr->iColumn-1], P4_STATIC); |
| 93224 | 93477 | } |
| 93225 | 93478 | return target; |
| 93226 | 93479 | } |
| 93227 | 93480 | case TK_REGISTER: { |
| 93228 | 93481 | return pExpr->iTable; |
| | @@ -93975,10 +94228,15 @@ |
| 93975 | 94228 | compRight.pRight = pExpr->x.pList->a[1].pExpr; |
| 93976 | 94229 | exprToRegister(&exprX, exprCodeVector(pParse, &exprX, ®Free1)); |
| 93977 | 94230 | if( xJump ){ |
| 93978 | 94231 | xJump(pParse, &exprAnd, dest, jumpIfNull); |
| 93979 | 94232 | }else{ |
| 94233 | + /* Mark the expression is being from the ON or USING clause of a join |
| 94234 | + ** so that the sqlite3ExprCodeTarget() routine will not attempt to move |
| 94235 | + ** it into the Parse.pConstExpr list. We should use a new bit for this, |
| 94236 | + ** for clarity, but we are out of bits in the Expr.flags field so we |
| 94237 | + ** have to reuse the EP_FromJoin bit. Bummer. */ |
| 93980 | 94238 | exprX.flags |= EP_FromJoin; |
| 93981 | 94239 | sqlite3ExprCodeTarget(pParse, &exprAnd, dest); |
| 93982 | 94240 | } |
| 93983 | 94241 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 93984 | 94242 | |
| | @@ -103465,11 +103723,11 @@ |
| 103465 | 103723 | ** DELETE FROM table_a WHERE rowid IN ( |
| 103466 | 103724 | ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1 |
| 103467 | 103725 | ** ); |
| 103468 | 103726 | */ |
| 103469 | 103727 | |
| 103470 | | - pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0); |
| 103728 | + pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0); |
| 103471 | 103729 | if( pSelectRowid == 0 ) goto limit_where_cleanup; |
| 103472 | 103730 | pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid); |
| 103473 | 103731 | if( pEList == 0 ) goto limit_where_cleanup; |
| 103474 | 103732 | |
| 103475 | 103733 | /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree |
| | @@ -103484,12 +103742,12 @@ |
| 103484 | 103742 | pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0, |
| 103485 | 103743 | pOrderBy,0,pLimit,pOffset); |
| 103486 | 103744 | if( pSelect == 0 ) return 0; |
| 103487 | 103745 | |
| 103488 | 103746 | /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */ |
| 103489 | | - pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0); |
| 103490 | | - pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0; |
| 103747 | + pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0); |
| 103748 | + pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0) : 0; |
| 103491 | 103749 | sqlite3PExprAddSelect(pParse, pInClause, pSelect); |
| 103492 | 103750 | return pInClause; |
| 103493 | 103751 | |
| 103494 | 103752 | limit_where_cleanup: |
| 103495 | 103753 | sqlite3ExprDelete(pParse->db, pWhere); |
| | @@ -103796,11 +104054,11 @@ |
| 103796 | 104054 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); |
| 103797 | 104055 | VdbeCoverage(v); |
| 103798 | 104056 | } |
| 103799 | 104057 | }else if( pPk ){ |
| 103800 | 104058 | addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v); |
| 103801 | | - sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey); |
| 104059 | + sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey); |
| 103802 | 104060 | assert( nKey==0 ); /* OP_Found will use a composite key */ |
| 103803 | 104061 | }else{ |
| 103804 | 104062 | addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey); |
| 103805 | 104063 | VdbeCoverage(v); |
| 103806 | 104064 | assert( nKey==1 ); |
| | @@ -104013,11 +104271,11 @@ |
| 104013 | 104271 | */ |
| 104014 | 104272 | if( pTab->pSelect==0 ){ |
| 104015 | 104273 | u8 p5 = 0; |
| 104016 | 104274 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); |
| 104017 | 104275 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0)); |
| 104018 | | - sqlite3VdbeChangeP4(v, -1, (char*)pTab, P4_TABLE); |
| 104276 | + sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE); |
| 104019 | 104277 | if( eMode!=ONEPASS_OFF ){ |
| 104020 | 104278 | sqlite3VdbeChangeP5(v, OPFLAG_AUXDELETE); |
| 104021 | 104279 | } |
| 104022 | 104280 | if( iIdxNoSeek>=0 ){ |
| 104023 | 104281 | sqlite3VdbeAddOp1(v, OP_Delete, iIdxNoSeek); |
| | @@ -104790,13 +105048,23 @@ |
| 104790 | 105048 | /* If SQLITE_CASE_SENSITIVE_LIKE is defined, then the LIKE operator |
| 104791 | 105049 | ** is case sensitive causing 'a' LIKE 'A' to be false */ |
| 104792 | 105050 | static const struct compareInfo likeInfoAlt = { '%', '_', 0, 0 }; |
| 104793 | 105051 | |
| 104794 | 105052 | /* |
| 104795 | | -** Compare two UTF-8 strings for equality where the first string can |
| 104796 | | -** potentially be a "glob" or "like" expression. Return true (1) if they |
| 104797 | | -** are the same and false (0) if they are different. |
| 105053 | +** Possible error returns from patternMatch() |
| 105054 | +*/ |
| 105055 | +#define SQLITE_MATCH 0 |
| 105056 | +#define SQLITE_NOMATCH 1 |
| 105057 | +#define SQLITE_NOWILDCARDMATCH 2 |
| 105058 | + |
| 105059 | +/* |
| 105060 | +** Compare two UTF-8 strings for equality where the first string is |
| 105061 | +** a GLOB or LIKE expression. Return values: |
| 105062 | +** |
| 105063 | +** SQLITE_MATCH: Match |
| 105064 | +** SQLITE_NOMATCH: No match |
| 105065 | +** SQLITE_NOWILDCARDMATCH: No match in spite of having * or % wildcards. |
| 104798 | 105066 | ** |
| 104799 | 105067 | ** Globbing rules: |
| 104800 | 105068 | ** |
| 104801 | 105069 | ** '*' Matches any sequence of zero or more characters. |
| 104802 | 105070 | ** |
| | @@ -104843,71 +105111,76 @@ |
| 104843 | 105111 | /* Skip over multiple "*" characters in the pattern. If there |
| 104844 | 105112 | ** are also "?" characters, skip those as well, but consume a |
| 104845 | 105113 | ** single character of the input string for each "?" skipped */ |
| 104846 | 105114 | while( (c=Utf8Read(zPattern)) == matchAll || c == matchOne ){ |
| 104847 | 105115 | if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){ |
| 104848 | | - return 0; |
| 105116 | + return SQLITE_NOWILDCARDMATCH; |
| 104849 | 105117 | } |
| 104850 | 105118 | } |
| 104851 | 105119 | if( c==0 ){ |
| 104852 | | - return 1; /* "*" at the end of the pattern matches */ |
| 105120 | + return SQLITE_MATCH; /* "*" at the end of the pattern matches */ |
| 104853 | 105121 | }else if( c==matchOther ){ |
| 104854 | 105122 | if( pInfo->matchSet==0 ){ |
| 104855 | 105123 | c = sqlite3Utf8Read(&zPattern); |
| 104856 | | - if( c==0 ) return 0; |
| 105124 | + if( c==0 ) return SQLITE_NOWILDCARDMATCH; |
| 104857 | 105125 | }else{ |
| 104858 | 105126 | /* "[...]" immediately follows the "*". We have to do a slow |
| 104859 | 105127 | ** recursive search in this case, but it is an unusual case. */ |
| 104860 | 105128 | assert( matchOther<0x80 ); /* '[' is a single-byte character */ |
| 104861 | | - while( *zString |
| 104862 | | - && patternCompare(&zPattern[-1],zString,pInfo,matchOther)==0 ){ |
| 105129 | + while( *zString ){ |
| 105130 | + int bMatch = patternCompare(&zPattern[-1],zString,pInfo,matchOther); |
| 105131 | + if( bMatch!=SQLITE_NOMATCH ) return bMatch; |
| 104863 | 105132 | SQLITE_SKIP_UTF8(zString); |
| 104864 | 105133 | } |
| 104865 | | - return *zString!=0; |
| 105134 | + return SQLITE_NOWILDCARDMATCH; |
| 104866 | 105135 | } |
| 104867 | 105136 | } |
| 104868 | 105137 | |
| 104869 | 105138 | /* At this point variable c contains the first character of the |
| 104870 | 105139 | ** pattern string past the "*". Search in the input string for the |
| 104871 | | - ** first matching character and recursively contine the match from |
| 105140 | + ** first matching character and recursively continue the match from |
| 104872 | 105141 | ** that point. |
| 104873 | 105142 | ** |
| 104874 | 105143 | ** For a case-insensitive search, set variable cx to be the same as |
| 104875 | 105144 | ** c but in the other case and search the input string for either |
| 104876 | 105145 | ** c or cx. |
| 104877 | 105146 | */ |
| 104878 | 105147 | if( c<=0x80 ){ |
| 104879 | 105148 | u32 cx; |
| 105149 | + int bMatch; |
| 104880 | 105150 | if( noCase ){ |
| 104881 | 105151 | cx = sqlite3Toupper(c); |
| 104882 | 105152 | c = sqlite3Tolower(c); |
| 104883 | 105153 | }else{ |
| 104884 | 105154 | cx = c; |
| 104885 | 105155 | } |
| 104886 | 105156 | while( (c2 = *(zString++))!=0 ){ |
| 104887 | 105157 | if( c2!=c && c2!=cx ) continue; |
| 104888 | | - if( patternCompare(zPattern,zString,pInfo,matchOther) ) return 1; |
| 105158 | + bMatch = patternCompare(zPattern,zString,pInfo,matchOther); |
| 105159 | + if( bMatch!=SQLITE_NOMATCH ) return bMatch; |
| 104889 | 105160 | } |
| 104890 | 105161 | }else{ |
| 105162 | + int bMatch; |
| 104891 | 105163 | while( (c2 = Utf8Read(zString))!=0 ){ |
| 104892 | 105164 | if( c2!=c ) continue; |
| 104893 | | - if( patternCompare(zPattern,zString,pInfo,matchOther) ) return 1; |
| 105165 | + bMatch = patternCompare(zPattern,zString,pInfo,matchOther); |
| 105166 | + if( bMatch!=SQLITE_NOMATCH ) return bMatch; |
| 104894 | 105167 | } |
| 104895 | 105168 | } |
| 104896 | | - return 0; |
| 105169 | + return SQLITE_NOWILDCARDMATCH; |
| 104897 | 105170 | } |
| 104898 | 105171 | if( c==matchOther ){ |
| 104899 | 105172 | if( pInfo->matchSet==0 ){ |
| 104900 | 105173 | c = sqlite3Utf8Read(&zPattern); |
| 104901 | | - if( c==0 ) return 0; |
| 105174 | + if( c==0 ) return SQLITE_NOMATCH; |
| 104902 | 105175 | zEscaped = zPattern; |
| 104903 | 105176 | }else{ |
| 104904 | 105177 | u32 prior_c = 0; |
| 104905 | 105178 | int seen = 0; |
| 104906 | 105179 | int invert = 0; |
| 104907 | 105180 | c = sqlite3Utf8Read(&zString); |
| 104908 | | - if( c==0 ) return 0; |
| 105181 | + if( c==0 ) return SQLITE_NOMATCH; |
| 104909 | 105182 | c2 = sqlite3Utf8Read(&zPattern); |
| 104910 | 105183 | if( c2=='^' ){ |
| 104911 | 105184 | invert = 1; |
| 104912 | 105185 | c2 = sqlite3Utf8Read(&zPattern); |
| 104913 | 105186 | } |
| | @@ -104927,11 +105200,11 @@ |
| 104927 | 105200 | prior_c = c2; |
| 104928 | 105201 | } |
| 104929 | 105202 | c2 = sqlite3Utf8Read(&zPattern); |
| 104930 | 105203 | } |
| 104931 | 105204 | if( c2==0 || (seen ^ invert)==0 ){ |
| 104932 | | - return 0; |
| 105205 | + return SQLITE_NOMATCH; |
| 104933 | 105206 | } |
| 104934 | 105207 | continue; |
| 104935 | 105208 | } |
| 104936 | 105209 | } |
| 104937 | 105210 | c2 = Utf8Read(zString); |
| | @@ -104938,27 +105211,29 @@ |
| 104938 | 105211 | if( c==c2 ) continue; |
| 104939 | 105212 | if( noCase && sqlite3Tolower(c)==sqlite3Tolower(c2) && c<0x80 && c2<0x80 ){ |
| 104940 | 105213 | continue; |
| 104941 | 105214 | } |
| 104942 | 105215 | if( c==matchOne && zPattern!=zEscaped && c2!=0 ) continue; |
| 104943 | | - return 0; |
| 105216 | + return SQLITE_NOMATCH; |
| 104944 | 105217 | } |
| 104945 | | - return *zString==0; |
| 105218 | + return *zString==0 ? SQLITE_MATCH : SQLITE_NOMATCH; |
| 104946 | 105219 | } |
| 104947 | 105220 | |
| 104948 | 105221 | /* |
| 104949 | | -** The sqlite3_strglob() interface. |
| 105222 | +** The sqlite3_strglob() interface. Return 0 on a match (like strcmp()) and |
| 105223 | +** non-zero if there is no match. |
| 104950 | 105224 | */ |
| 104951 | 105225 | SQLITE_API int sqlite3_strglob(const char *zGlobPattern, const char *zString){ |
| 104952 | | - return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '[')==0; |
| 105226 | + return patternCompare((u8*)zGlobPattern, (u8*)zString, &globInfo, '['); |
| 104953 | 105227 | } |
| 104954 | 105228 | |
| 104955 | 105229 | /* |
| 104956 | | -** The sqlite3_strlike() interface. |
| 105230 | +** The sqlite3_strlike() interface. Return 0 on a match and non-zero for |
| 105231 | +** a miss - like strcmp(). |
| 104957 | 105232 | */ |
| 104958 | 105233 | SQLITE_API int sqlite3_strlike(const char *zPattern, const char *zStr, unsigned int esc){ |
| 104959 | | - return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc)==0; |
| 105234 | + return patternCompare((u8*)zPattern, (u8*)zStr, &likeInfoNorm, esc); |
| 104960 | 105235 | } |
| 104961 | 105236 | |
| 104962 | 105237 | /* |
| 104963 | 105238 | ** Count the number of times that the LIKE operator (or GLOB which is |
| 104964 | 105239 | ** just a variation of LIKE) gets called. This is used for testing |
| | @@ -105035,11 +105310,11 @@ |
| 105035 | 105310 | } |
| 105036 | 105311 | if( zA && zB ){ |
| 105037 | 105312 | #ifdef SQLITE_TEST |
| 105038 | 105313 | sqlite3_like_count++; |
| 105039 | 105314 | #endif |
| 105040 | | - sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)); |
| 105315 | + sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH); |
| 105041 | 105316 | } |
| 105042 | 105317 | } |
| 105043 | 105318 | |
| 105044 | 105319 | /* |
| 105045 | 105320 | ** Implementation of the NULLIF(x,y) function. The result is the first |
| | @@ -106628,11 +106903,11 @@ |
| 106628 | 106903 | pLeft = exprTableRegister(pParse, pTab, regData, iCol); |
| 106629 | 106904 | iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom; |
| 106630 | 106905 | assert( iCol>=0 ); |
| 106631 | 106906 | zCol = pFKey->pFrom->aCol[iCol].zName; |
| 106632 | 106907 | pRight = sqlite3Expr(db, TK_ID, zCol); |
| 106633 | | - pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0); |
| 106908 | + pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight); |
| 106634 | 106909 | pWhere = sqlite3ExprAnd(db, pWhere, pEq); |
| 106635 | 106910 | } |
| 106636 | 106911 | |
| 106637 | 106912 | /* If the child table is the same as the parent table, then add terms |
| 106638 | 106913 | ** to the WHERE clause that prevent this entry from being scanned. |
| | @@ -106650,24 +106925,24 @@ |
| 106650 | 106925 | Expr *pLeft; /* Value from parent table row */ |
| 106651 | 106926 | Expr *pRight; /* Column ref to child table */ |
| 106652 | 106927 | if( HasRowid(pTab) ){ |
| 106653 | 106928 | pLeft = exprTableRegister(pParse, pTab, regData, -1); |
| 106654 | 106929 | pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, -1); |
| 106655 | | - pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight, 0); |
| 106930 | + pNe = sqlite3PExpr(pParse, TK_NE, pLeft, pRight); |
| 106656 | 106931 | }else{ |
| 106657 | 106932 | Expr *pEq, *pAll = 0; |
| 106658 | 106933 | Index *pPk = sqlite3PrimaryKeyIndex(pTab); |
| 106659 | 106934 | assert( pIdx!=0 ); |
| 106660 | 106935 | for(i=0; i<pPk->nKeyCol; i++){ |
| 106661 | 106936 | i16 iCol = pIdx->aiColumn[i]; |
| 106662 | 106937 | assert( iCol>=0 ); |
| 106663 | 106938 | pLeft = exprTableRegister(pParse, pTab, regData, iCol); |
| 106664 | 106939 | pRight = exprTableColumn(db, pTab, pSrc->a[0].iCursor, iCol); |
| 106665 | | - pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight, 0); |
| 106940 | + pEq = sqlite3PExpr(pParse, TK_EQ, pLeft, pRight); |
| 106666 | 106941 | pAll = sqlite3ExprAnd(db, pAll, pEq); |
| 106667 | 106942 | } |
| 106668 | | - pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0, 0); |
| 106943 | + pNe = sqlite3PExpr(pParse, TK_NOT, pAll, 0); |
| 106669 | 106944 | } |
| 106670 | 106945 | pWhere = sqlite3ExprAnd(db, pWhere, pNe); |
| 106671 | 106946 | } |
| 106672 | 106947 | |
| 106673 | 106948 | /* Resolve the references in the WHERE clause. */ |
| | @@ -107249,14 +107524,13 @@ |
| 107249 | 107524 | ** that the affinity and collation sequence associated with the |
| 107250 | 107525 | ** parent table are used for the comparison. */ |
| 107251 | 107526 | pEq = sqlite3PExpr(pParse, TK_EQ, |
| 107252 | 107527 | sqlite3PExpr(pParse, TK_DOT, |
| 107253 | 107528 | sqlite3ExprAlloc(db, TK_ID, &tOld, 0), |
| 107254 | | - sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) |
| 107255 | | - , 0), |
| 107529 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)), |
| 107256 | 107530 | sqlite3ExprAlloc(db, TK_ID, &tFromCol, 0) |
| 107257 | | - , 0); |
| 107531 | + ); |
| 107258 | 107532 | pWhere = sqlite3ExprAnd(db, pWhere, pEq); |
| 107259 | 107533 | |
| 107260 | 107534 | /* For ON UPDATE, construct the next term of the WHEN clause. |
| 107261 | 107535 | ** The final WHEN clause will be like this: |
| 107262 | 107536 | ** |
| | @@ -107264,27 +107538,24 @@ |
| 107264 | 107538 | */ |
| 107265 | 107539 | if( pChanges ){ |
| 107266 | 107540 | pEq = sqlite3PExpr(pParse, TK_IS, |
| 107267 | 107541 | sqlite3PExpr(pParse, TK_DOT, |
| 107268 | 107542 | sqlite3ExprAlloc(db, TK_ID, &tOld, 0), |
| 107269 | | - sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), |
| 107270 | | - 0), |
| 107543 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)), |
| 107271 | 107544 | sqlite3PExpr(pParse, TK_DOT, |
| 107272 | 107545 | sqlite3ExprAlloc(db, TK_ID, &tNew, 0), |
| 107273 | | - sqlite3ExprAlloc(db, TK_ID, &tToCol, 0), |
| 107274 | | - 0), |
| 107275 | | - 0); |
| 107546 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)) |
| 107547 | + ); |
| 107276 | 107548 | pWhen = sqlite3ExprAnd(db, pWhen, pEq); |
| 107277 | 107549 | } |
| 107278 | 107550 | |
| 107279 | 107551 | if( action!=OE_Restrict && (action!=OE_Cascade || pChanges) ){ |
| 107280 | 107552 | Expr *pNew; |
| 107281 | 107553 | if( action==OE_Cascade ){ |
| 107282 | 107554 | pNew = sqlite3PExpr(pParse, TK_DOT, |
| 107283 | 107555 | sqlite3ExprAlloc(db, TK_ID, &tNew, 0), |
| 107284 | | - sqlite3ExprAlloc(db, TK_ID, &tToCol, 0) |
| 107285 | | - , 0); |
| 107556 | + sqlite3ExprAlloc(db, TK_ID, &tToCol, 0)); |
| 107286 | 107557 | }else if( action==OE_SetDflt ){ |
| 107287 | 107558 | Expr *pDflt = pFKey->pFrom->aCol[iFromCol].pDflt; |
| 107288 | 107559 | if( pDflt ){ |
| 107289 | 107560 | pNew = sqlite3ExprDup(db, pDflt, 0); |
| 107290 | 107561 | }else{ |
| | @@ -107336,11 +107607,11 @@ |
| 107336 | 107607 | |
| 107337 | 107608 | pStep->pWhere = sqlite3ExprDup(db, pWhere, EXPRDUP_REDUCE); |
| 107338 | 107609 | pStep->pExprList = sqlite3ExprListDup(db, pList, EXPRDUP_REDUCE); |
| 107339 | 107610 | pStep->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); |
| 107340 | 107611 | if( pWhen ){ |
| 107341 | | - pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0, 0); |
| 107612 | + pWhen = sqlite3PExpr(pParse, TK_NOT, pWhen, 0); |
| 107342 | 107613 | pTrigger->pWhen = sqlite3ExprDup(db, pWhen, EXPRDUP_REDUCE); |
| 107343 | 107614 | } |
| 107344 | 107615 | } |
| 107345 | 107616 | |
| 107346 | 107617 | /* Re-enable the lookaside buffer, if it was disabled earlier. */ |
| | @@ -108760,12 +109031,13 @@ |
| 108760 | 109031 | /* Fall through */ |
| 108761 | 109032 | case OE_Rollback: |
| 108762 | 109033 | case OE_Fail: { |
| 108763 | 109034 | char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName, |
| 108764 | 109035 | pTab->aCol[i].zName); |
| 108765 | | - sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError, |
| 108766 | | - regNewData+1+i, zMsg, P4_DYNAMIC); |
| 109036 | + sqlite3VdbeAddOp3(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError, |
| 109037 | + regNewData+1+i); |
| 109038 | + sqlite3VdbeAppendP4(v, zMsg, P4_DYNAMIC); |
| 108767 | 109039 | sqlite3VdbeChangeP5(v, P5_ConstraintNotNull); |
| 108768 | 109040 | VdbeCoverage(v); |
| 108769 | 109041 | break; |
| 108770 | 109042 | } |
| 108771 | 109043 | case OE_Ignore: { |
| | @@ -108903,11 +109175,11 @@ |
| 108903 | 109175 | /* This OP_Delete opcode fires the pre-update-hook only. It does |
| 108904 | 109176 | ** not modify the b-tree. It is more efficient to let the coming |
| 108905 | 109177 | ** OP_Insert replace the existing entry than it is to delete the |
| 108906 | 109178 | ** existing entry and then insert a new one. */ |
| 108907 | 109179 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, OPFLAG_ISNOOP); |
| 108908 | | - sqlite3VdbeChangeP4(v, -1, (char *)pTab, P4_TABLE); |
| 109180 | + sqlite3VdbeAppendP4(v, pTab, P4_TABLE); |
| 108909 | 109181 | } |
| 108910 | 109182 | #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */ |
| 108911 | 109183 | if( pTab->pIndex ){ |
| 108912 | 109184 | sqlite3MultiWrite(pParse); |
| 108913 | 109185 | sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,-1); |
| | @@ -109180,11 +109452,11 @@ |
| 109180 | 109452 | if( useSeekResult ){ |
| 109181 | 109453 | pik_flags |= OPFLAG_USESEEKRESULT; |
| 109182 | 109454 | } |
| 109183 | 109455 | sqlite3VdbeAddOp3(v, OP_Insert, iDataCur, regRec, regNewData); |
| 109184 | 109456 | if( !pParse->nested ){ |
| 109185 | | - sqlite3VdbeChangeP4(v, -1, (char *)pTab, P4_TABLE); |
| 109457 | + sqlite3VdbeAppendP4(v, pTab, P4_TABLE); |
| 109186 | 109458 | } |
| 109187 | 109459 | sqlite3VdbeChangeP5(v, pik_flags); |
| 109188 | 109460 | } |
| 109189 | 109461 | |
| 109190 | 109462 | /* |
| | @@ -109611,11 +109883,11 @@ |
| 109611 | 109883 | sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest); |
| 109612 | 109884 | sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx); |
| 109613 | 109885 | sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR); |
| 109614 | 109886 | VdbeComment((v, "%s", pDestIdx->zName)); |
| 109615 | 109887 | addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v); |
| 109616 | | - sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData); |
| 109888 | + sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData); |
| 109617 | 109889 | if( db->flags & SQLITE_Vacuum ){ |
| 109618 | 109890 | /* This INSERT command is part of a VACUUM operation, which guarantees |
| 109619 | 109891 | ** that the destination table is empty. If all indexed columns use |
| 109620 | 109892 | ** collation sequence BINARY, then it can also be assumed that the |
| 109621 | 109893 | ** index will be populated by inserting keys in strictly sorted |
| | @@ -114820,11 +115092,11 @@ |
| 114820 | 115092 | assert( pSrc->a[iRight].pTab ); |
| 114821 | 115093 | |
| 114822 | 115094 | pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft); |
| 114823 | 115095 | pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight); |
| 114824 | 115096 | |
| 114825 | | - pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2, 0); |
| 115097 | + pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2); |
| 114826 | 115098 | if( pEq && isOuterJoin ){ |
| 114827 | 115099 | ExprSetProperty(pEq, EP_FromJoin); |
| 114828 | 115100 | assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) ); |
| 114829 | 115101 | ExprSetVVAProperty(pEq, EP_NoReduce); |
| 114830 | 115102 | pEq->iRightJoinTable = (i16)pE2->iTable; |
| | @@ -116992,11 +117264,11 @@ |
| 116992 | 117264 | iBreak = sqlite3VdbeMakeLabel(v); |
| 116993 | 117265 | iCont = sqlite3VdbeMakeLabel(v); |
| 116994 | 117266 | computeLimitRegisters(pParse, p, iBreak); |
| 116995 | 117267 | sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v); |
| 116996 | 117268 | r1 = sqlite3GetTempReg(pParse); |
| 116997 | | - iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1); |
| 117269 | + iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1); |
| 116998 | 117270 | sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v); |
| 116999 | 117271 | sqlite3ReleaseTempReg(pParse, r1); |
| 117000 | 117272 | selectInnerLoop(pParse, p, p->pEList, tab1, |
| 117001 | 117273 | 0, 0, &dest, iCont, iBreak); |
| 117002 | 117274 | sqlite3VdbeResolveLabel(v, iCont); |
| | @@ -117619,12 +117891,12 @@ |
| 117619 | 117891 | } |
| 117620 | 117892 | #endif |
| 117621 | 117893 | |
| 117622 | 117894 | #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) |
| 117623 | 117895 | /* Forward Declarations */ |
| 117624 | | -static void substExprList(sqlite3*, ExprList*, int, ExprList*); |
| 117625 | | -static void substSelect(sqlite3*, Select *, int, ExprList*, int); |
| 117896 | +static void substExprList(Parse*, ExprList*, int, ExprList*); |
| 117897 | +static void substSelect(Parse*, Select *, int, ExprList*, int); |
| 117626 | 117898 | |
| 117627 | 117899 | /* |
| 117628 | 117900 | ** Scan through the expression pExpr. Replace every reference to |
| 117629 | 117901 | ** a column in table number iTable with a copy of the iColumn-th |
| 117630 | 117902 | ** entry in pEList. (But leave references to the ROWID column |
| | @@ -117636,52 +117908,62 @@ |
| 117636 | 117908 | ** FORM clause entry is iTable. This routine make the necessary |
| 117637 | 117909 | ** changes to pExpr so that it refers directly to the source table |
| 117638 | 117910 | ** of the subquery rather the result set of the subquery. |
| 117639 | 117911 | */ |
| 117640 | 117912 | static Expr *substExpr( |
| 117641 | | - sqlite3 *db, /* Report malloc errors to this connection */ |
| 117913 | + Parse *pParse, /* Report errors here */ |
| 117642 | 117914 | Expr *pExpr, /* Expr in which substitution occurs */ |
| 117643 | 117915 | int iTable, /* Table to be substituted */ |
| 117644 | 117916 | ExprList *pEList /* Substitute expressions */ |
| 117645 | 117917 | ){ |
| 117918 | + sqlite3 *db = pParse->db; |
| 117646 | 117919 | if( pExpr==0 ) return 0; |
| 117647 | 117920 | if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){ |
| 117648 | 117921 | if( pExpr->iColumn<0 ){ |
| 117649 | 117922 | pExpr->op = TK_NULL; |
| 117650 | 117923 | }else{ |
| 117651 | 117924 | Expr *pNew; |
| 117925 | + Expr *pCopy = pEList->a[pExpr->iColumn].pExpr; |
| 117652 | 117926 | assert( pEList!=0 && pExpr->iColumn<pEList->nExpr ); |
| 117653 | 117927 | assert( pExpr->pLeft==0 && pExpr->pRight==0 ); |
| 117654 | | - pNew = sqlite3ExprDup(db, pEList->a[pExpr->iColumn].pExpr, 0); |
| 117655 | | - sqlite3ExprDelete(db, pExpr); |
| 117656 | | - pExpr = pNew; |
| 117928 | + if( sqlite3ExprIsVector(pCopy) ){ |
| 117929 | + sqlite3VectorErrorMsg(pParse, pCopy); |
| 117930 | + }else{ |
| 117931 | + pNew = sqlite3ExprDup(db, pCopy, 0); |
| 117932 | + if( pNew && (pExpr->flags & EP_FromJoin) ){ |
| 117933 | + pNew->iRightJoinTable = pExpr->iRightJoinTable; |
| 117934 | + pNew->flags |= EP_FromJoin; |
| 117935 | + } |
| 117936 | + sqlite3ExprDelete(db, pExpr); |
| 117937 | + pExpr = pNew; |
| 117938 | + } |
| 117657 | 117939 | } |
| 117658 | 117940 | }else{ |
| 117659 | | - pExpr->pLeft = substExpr(db, pExpr->pLeft, iTable, pEList); |
| 117660 | | - pExpr->pRight = substExpr(db, pExpr->pRight, iTable, pEList); |
| 117941 | + pExpr->pLeft = substExpr(pParse, pExpr->pLeft, iTable, pEList); |
| 117942 | + pExpr->pRight = substExpr(pParse, pExpr->pRight, iTable, pEList); |
| 117661 | 117943 | if( ExprHasProperty(pExpr, EP_xIsSelect) ){ |
| 117662 | | - substSelect(db, pExpr->x.pSelect, iTable, pEList, 1); |
| 117944 | + substSelect(pParse, pExpr->x.pSelect, iTable, pEList, 1); |
| 117663 | 117945 | }else{ |
| 117664 | | - substExprList(db, pExpr->x.pList, iTable, pEList); |
| 117946 | + substExprList(pParse, pExpr->x.pList, iTable, pEList); |
| 117665 | 117947 | } |
| 117666 | 117948 | } |
| 117667 | 117949 | return pExpr; |
| 117668 | 117950 | } |
| 117669 | 117951 | static void substExprList( |
| 117670 | | - sqlite3 *db, /* Report malloc errors here */ |
| 117952 | + Parse *pParse, /* Report errors here */ |
| 117671 | 117953 | ExprList *pList, /* List to scan and in which to make substitutes */ |
| 117672 | 117954 | int iTable, /* Table to be substituted */ |
| 117673 | 117955 | ExprList *pEList /* Substitute values */ |
| 117674 | 117956 | ){ |
| 117675 | 117957 | int i; |
| 117676 | 117958 | if( pList==0 ) return; |
| 117677 | 117959 | for(i=0; i<pList->nExpr; i++){ |
| 117678 | | - pList->a[i].pExpr = substExpr(db, pList->a[i].pExpr, iTable, pEList); |
| 117960 | + pList->a[i].pExpr = substExpr(pParse, pList->a[i].pExpr, iTable, pEList); |
| 117679 | 117961 | } |
| 117680 | 117962 | } |
| 117681 | 117963 | static void substSelect( |
| 117682 | | - sqlite3 *db, /* Report malloc errors here */ |
| 117964 | + Parse *pParse, /* Report errors here */ |
| 117683 | 117965 | Select *p, /* SELECT statement in which to make substitutions */ |
| 117684 | 117966 | int iTable, /* Table to be replaced */ |
| 117685 | 117967 | ExprList *pEList, /* Substitute values */ |
| 117686 | 117968 | int doPrior /* Do substitutes on p->pPrior too */ |
| 117687 | 117969 | ){ |
| | @@ -117688,21 +117970,21 @@ |
| 117688 | 117970 | SrcList *pSrc; |
| 117689 | 117971 | struct SrcList_item *pItem; |
| 117690 | 117972 | int i; |
| 117691 | 117973 | if( !p ) return; |
| 117692 | 117974 | do{ |
| 117693 | | - substExprList(db, p->pEList, iTable, pEList); |
| 117694 | | - substExprList(db, p->pGroupBy, iTable, pEList); |
| 117695 | | - substExprList(db, p->pOrderBy, iTable, pEList); |
| 117696 | | - p->pHaving = substExpr(db, p->pHaving, iTable, pEList); |
| 117697 | | - p->pWhere = substExpr(db, p->pWhere, iTable, pEList); |
| 117975 | + substExprList(pParse, p->pEList, iTable, pEList); |
| 117976 | + substExprList(pParse, p->pGroupBy, iTable, pEList); |
| 117977 | + substExprList(pParse, p->pOrderBy, iTable, pEList); |
| 117978 | + p->pHaving = substExpr(pParse, p->pHaving, iTable, pEList); |
| 117979 | + p->pWhere = substExpr(pParse, p->pWhere, iTable, pEList); |
| 117698 | 117980 | pSrc = p->pSrc; |
| 117699 | 117981 | assert( pSrc!=0 ); |
| 117700 | 117982 | for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){ |
| 117701 | | - substSelect(db, pItem->pSelect, iTable, pEList, 1); |
| 117983 | + substSelect(pParse, pItem->pSelect, iTable, pEList, 1); |
| 117702 | 117984 | if( pItem->fg.isTabFunc ){ |
| 117703 | | - substExprList(db, pItem->u1.pFuncArg, iTable, pEList); |
| 117985 | + substExprList(pParse, pItem->u1.pFuncArg, iTable, pEList); |
| 117704 | 117986 | } |
| 117705 | 117987 | } |
| 117706 | 117988 | }while( doPrior && (p = p->pPrior)!=0 ); |
| 117707 | 117989 | } |
| 117708 | 117990 | #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */ |
| | @@ -118223,11 +118505,11 @@ |
| 118223 | 118505 | assert( pParent->pGroupBy==0 ); |
| 118224 | 118506 | pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0); |
| 118225 | 118507 | }else{ |
| 118226 | 118508 | pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere); |
| 118227 | 118509 | } |
| 118228 | | - substSelect(db, pParent, iParent, pSub->pEList, 0); |
| 118510 | + substSelect(pParse, pParent, iParent, pSub->pEList, 0); |
| 118229 | 118511 | |
| 118230 | 118512 | /* The flattened query is distinct if either the inner or the |
| 118231 | 118513 | ** outer query is distinct. |
| 118232 | 118514 | */ |
| 118233 | 118515 | pParent->selFlags |= pSub->selFlags & SF_Distinct; |
| | @@ -118297,11 +118579,11 @@ |
| 118297 | 118579 | ** |
| 118298 | 118580 | ** Return 0 if no changes are made and non-zero if one or more WHERE clause |
| 118299 | 118581 | ** terms are duplicated into the subquery. |
| 118300 | 118582 | */ |
| 118301 | 118583 | static int pushDownWhereTerms( |
| 118302 | | - sqlite3 *db, /* The database connection (for malloc()) */ |
| 118584 | + Parse *pParse, /* Parse context (for malloc() and error reporting) */ |
| 118303 | 118585 | Select *pSubq, /* The subquery whose WHERE clause is to be augmented */ |
| 118304 | 118586 | Expr *pWhere, /* The WHERE clause of the outer query */ |
| 118305 | 118587 | int iCursor /* Cursor number of the subquery */ |
| 118306 | 118588 | ){ |
| 118307 | 118589 | Expr *pNew; |
| | @@ -118318,20 +118600,20 @@ |
| 118318 | 118600 | } |
| 118319 | 118601 | if( pSubq->pLimit!=0 ){ |
| 118320 | 118602 | return 0; /* restriction (3) */ |
| 118321 | 118603 | } |
| 118322 | 118604 | while( pWhere->op==TK_AND ){ |
| 118323 | | - nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor); |
| 118605 | + nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor); |
| 118324 | 118606 | pWhere = pWhere->pLeft; |
| 118325 | 118607 | } |
| 118326 | 118608 | if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */ |
| 118327 | 118609 | if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){ |
| 118328 | 118610 | nChng++; |
| 118329 | 118611 | while( pSubq ){ |
| 118330 | | - pNew = sqlite3ExprDup(db, pWhere, 0); |
| 118331 | | - pNew = substExpr(db, pNew, iCursor, pSubq->pEList); |
| 118332 | | - pSubq->pWhere = sqlite3ExprAnd(db, pSubq->pWhere, pNew); |
| 118612 | + pNew = sqlite3ExprDup(pParse->db, pWhere, 0); |
| 118613 | + pNew = substExpr(pParse, pNew, iCursor, pSubq->pEList); |
| 118614 | + pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew); |
| 118333 | 118615 | pSubq = pSubq->pPrior; |
| 118334 | 118616 | } |
| 118335 | 118617 | } |
| 118336 | 118618 | return nChng; |
| 118337 | 118619 | } |
| | @@ -118957,14 +119239,14 @@ |
| 118957 | 119239 | zColname = zName; |
| 118958 | 119240 | zToFree = 0; |
| 118959 | 119241 | if( longNames || pTabList->nSrc>1 ){ |
| 118960 | 119242 | Expr *pLeft; |
| 118961 | 119243 | pLeft = sqlite3Expr(db, TK_ID, zTabName); |
| 118962 | | - pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); |
| 119244 | + pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight); |
| 118963 | 119245 | if( zSchemaName ){ |
| 118964 | 119246 | pLeft = sqlite3Expr(db, TK_ID, zSchemaName); |
| 118965 | | - pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr, 0); |
| 119247 | + pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr); |
| 118966 | 119248 | } |
| 118967 | 119249 | if( longNames ){ |
| 118968 | 119250 | zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName); |
| 118969 | 119251 | zToFree = zColname; |
| 118970 | 119252 | } |
| | @@ -119197,12 +119479,12 @@ |
| 119197 | 119479 | int i; |
| 119198 | 119480 | struct AggInfo_func *pF; |
| 119199 | 119481 | for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){ |
| 119200 | 119482 | ExprList *pList = pF->pExpr->x.pList; |
| 119201 | 119483 | assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) ); |
| 119202 | | - sqlite3VdbeAddOp4(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0, 0, |
| 119203 | | - (void*)pF->pFunc, P4_FUNCDEF); |
| 119484 | + sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0); |
| 119485 | + sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF); |
| 119204 | 119486 | } |
| 119205 | 119487 | } |
| 119206 | 119488 | |
| 119207 | 119489 | /* |
| 119208 | 119490 | ** Update the accumulator memory cells for an aggregate based on |
| | @@ -119249,12 +119531,12 @@ |
| 119249 | 119531 | pColl = pParse->db->pDfltColl; |
| 119250 | 119532 | } |
| 119251 | 119533 | if( regHit==0 && pAggInfo->nAccumulator ) regHit = ++pParse->nMem; |
| 119252 | 119534 | sqlite3VdbeAddOp4(v, OP_CollSeq, regHit, 0, 0, (char *)pColl, P4_COLLSEQ); |
| 119253 | 119535 | } |
| 119254 | | - sqlite3VdbeAddOp4(v, OP_AggStep0, 0, regAgg, pF->iMem, |
| 119255 | | - (void*)pF->pFunc, P4_FUNCDEF); |
| 119536 | + sqlite3VdbeAddOp3(v, OP_AggStep0, 0, regAgg, pF->iMem); |
| 119537 | + sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF); |
| 119256 | 119538 | sqlite3VdbeChangeP5(v, (u8)nArg); |
| 119257 | 119539 | sqlite3ExprCacheAffinityChange(pParse, regAgg, nArg); |
| 119258 | 119540 | sqlite3ReleaseTempRange(pParse, regAgg, nArg); |
| 119259 | 119541 | if( addrNext ){ |
| 119260 | 119542 | sqlite3VdbeResolveLabel(v, addrNext); |
| | @@ -119484,11 +119766,11 @@ |
| 119484 | 119766 | |
| 119485 | 119767 | /* Make copies of constant WHERE-clause terms in the outer query down |
| 119486 | 119768 | ** inside the subquery. This can help the subquery to run more efficiently. |
| 119487 | 119769 | */ |
| 119488 | 119770 | if( (pItem->fg.jointype & JT_OUTER)==0 |
| 119489 | | - && pushDownWhereTerms(db, pSub, p->pWhere, pItem->iCursor) |
| 119771 | + && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor) |
| 119490 | 119772 | ){ |
| 119491 | 119773 | #if SELECTTRACE_ENABLED |
| 119492 | 119774 | if( sqlite3SelectTrace & 0x100 ){ |
| 119493 | 119775 | SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n")); |
| 119494 | 119776 | sqlite3TreeViewSelect(0, p, 0); |
| | @@ -121570,11 +121852,11 @@ |
| 121570 | 121852 | VdbeComment((v, "%s.%s", pTab->zName, pCol->zName)); |
| 121571 | 121853 | assert( i<pTab->nCol ); |
| 121572 | 121854 | sqlite3ValueFromExpr(sqlite3VdbeDb(v), pCol->pDflt, enc, |
| 121573 | 121855 | pCol->affinity, &pValue); |
| 121574 | 121856 | if( pValue ){ |
| 121575 | | - sqlite3VdbeChangeP4(v, -1, (const char *)pValue, P4_MEM); |
| 121857 | + sqlite3VdbeAppendP4(v, pValue, P4_MEM); |
| 121576 | 121858 | } |
| 121577 | 121859 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 121578 | 121860 | if( pTab->aCol[i].affinity==SQLITE_AFF_REAL ){ |
| 121579 | 121861 | sqlite3VdbeAddOp1(v, OP_RealAffinity, iReg); |
| 121580 | 121862 | } |
| | @@ -121953,11 +122235,11 @@ |
| 121953 | 122235 | VdbeCoverageIf(v, pPk==0); |
| 121954 | 122236 | VdbeCoverageIf(v, pPk!=0); |
| 121955 | 122237 | }else if( pPk ){ |
| 121956 | 122238 | labelContinue = sqlite3VdbeMakeLabel(v); |
| 121957 | 122239 | sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v); |
| 121958 | | - addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey); |
| 122240 | + addrTop = sqlite3VdbeAddOp2(v, OP_RowData, iEph, regKey); |
| 121959 | 122241 | sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0); |
| 121960 | 122242 | VdbeCoverage(v); |
| 121961 | 122243 | }else{ |
| 121962 | 122244 | labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak, |
| 121963 | 122245 | regOldRowid); |
| | @@ -122111,11 +122393,11 @@ |
| 122111 | 122393 | sqlite3VdbeAddOp3(v, OP_Delete, iDataCur, |
| 122112 | 122394 | OPFLAG_ISUPDATE | ((hasFK || chngKey || pPk!=0) ? 0 : OPFLAG_ISNOOP), |
| 122113 | 122395 | regNewRowid |
| 122114 | 122396 | ); |
| 122115 | 122397 | if( !pParse->nested ){ |
| 122116 | | - sqlite3VdbeChangeP4(v, -1, (char*)pTab, P4_TABLE); |
| 122398 | + sqlite3VdbeAppendP4(v, pTab, P4_TABLE); |
| 122117 | 122399 | } |
| 122118 | 122400 | #else |
| 122119 | 122401 | if( hasFK || chngKey || pPk!=0 ){ |
| 122120 | 122402 | sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0); |
| 122121 | 122403 | } |
| | @@ -125607,11 +125889,11 @@ |
| 125607 | 125889 | } |
| 125608 | 125890 | sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg); |
| 125609 | 125891 | sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1); |
| 125610 | 125892 | sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg, |
| 125611 | 125893 | pLoop->u.vtab.idxStr, |
| 125612 | | - pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC); |
| 125894 | + pLoop->u.vtab.needFree ? P4_DYNAMIC : P4_STATIC); |
| 125613 | 125895 | VdbeCoverage(v); |
| 125614 | 125896 | pLoop->u.vtab.needFree = 0; |
| 125615 | 125897 | pLevel->p1 = iCur; |
| 125616 | 125898 | pLevel->op = pWInfo->eOnePass ? OP_Noop : OP_VNext; |
| 125617 | 125899 | pLevel->p2 = sqlite3VdbeCurrentAddr(v); |
| | @@ -125640,11 +125922,11 @@ |
| 125640 | 125922 | sqlite3VdbeAddOp3(v, pOp->opcode, pOp->p1, pOp->p2, pOp->p3); |
| 125641 | 125923 | } |
| 125642 | 125924 | |
| 125643 | 125925 | /* Generate code that will continue to the next row if |
| 125644 | 125926 | ** the IN constraint is not satisfied */ |
| 125645 | | - pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0, 0); |
| 125927 | + pCompare = sqlite3PExpr(pParse, TK_EQ, 0, 0); |
| 125646 | 125928 | assert( pCompare!=0 || db->mallocFailed ); |
| 125647 | 125929 | if( pCompare ){ |
| 125648 | 125930 | pCompare->pLeft = pTerm->pExpr->pLeft; |
| 125649 | 125931 | pCompare->pRight = pRight = sqlite3Expr(db, TK_REGISTER, 0); |
| 125650 | 125932 | if( pRight ){ |
| | @@ -126239,11 +126521,11 @@ |
| 126239 | 126521 | testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); |
| 126240 | 126522 | pExpr = sqlite3ExprDup(db, pExpr, 0); |
| 126241 | 126523 | pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr); |
| 126242 | 126524 | } |
| 126243 | 126525 | if( pAndExpr ){ |
| 126244 | | - pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr, 0); |
| 126526 | + pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr); |
| 126245 | 126527 | } |
| 126246 | 126528 | } |
| 126247 | 126529 | |
| 126248 | 126530 | /* Run a separate WHERE clause for each term of the OR clause. After |
| 126249 | 126531 | ** eliminating duplicates from other WHERE clauses, the action for each |
| | @@ -127241,11 +127523,11 @@ |
| 127241 | 127523 | pList = sqlite3ExprListAppend(pWInfo->pParse, pList, pDup); |
| 127242 | 127524 | pLeft = pOrTerm->pExpr->pLeft; |
| 127243 | 127525 | } |
| 127244 | 127526 | assert( pLeft!=0 ); |
| 127245 | 127527 | pDup = sqlite3ExprDup(db, pLeft, 0); |
| 127246 | | - pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0, 0); |
| 127528 | + pNew = sqlite3PExpr(pParse, TK_IN, pDup, 0); |
| 127247 | 127529 | if( pNew ){ |
| 127248 | 127530 | int idxNew; |
| 127249 | 127531 | transferJoinMarkings(pNew, pExpr); |
| 127250 | 127532 | assert( !ExprHasProperty(pNew, EP_xIsSelect) ); |
| 127251 | 127533 | pNew->x.pList = pList; |
| | @@ -127539,11 +127821,11 @@ |
| 127539 | 127821 | for(i=0; i<2; i++){ |
| 127540 | 127822 | Expr *pNewExpr; |
| 127541 | 127823 | int idxNew; |
| 127542 | 127824 | pNewExpr = sqlite3PExpr(pParse, ops[i], |
| 127543 | 127825 | sqlite3ExprDup(db, pExpr->pLeft, 0), |
| 127544 | | - sqlite3ExprDup(db, pList->a[i].pExpr, 0), 0); |
| 127826 | + sqlite3ExprDup(db, pList->a[i].pExpr, 0)); |
| 127545 | 127827 | transferJoinMarkings(pNewExpr, pExpr); |
| 127546 | 127828 | idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 127547 | 127829 | testcase( idxNew==0 ); |
| 127548 | 127830 | exprAnalyze(pSrc, pWC, idxNew); |
| 127549 | 127831 | pTerm = &pWC->a[idxTerm]; |
| | @@ -127624,19 +127906,19 @@ |
| 127624 | 127906 | } |
| 127625 | 127907 | zCollSeqName = noCase ? "NOCASE" : "BINARY"; |
| 127626 | 127908 | pNewExpr1 = sqlite3ExprDup(db, pLeft, 0); |
| 127627 | 127909 | pNewExpr1 = sqlite3PExpr(pParse, TK_GE, |
| 127628 | 127910 | sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName), |
| 127629 | | - pStr1, 0); |
| 127911 | + pStr1); |
| 127630 | 127912 | transferJoinMarkings(pNewExpr1, pExpr); |
| 127631 | 127913 | idxNew1 = whereClauseInsert(pWC, pNewExpr1, wtFlags); |
| 127632 | 127914 | testcase( idxNew1==0 ); |
| 127633 | 127915 | exprAnalyze(pSrc, pWC, idxNew1); |
| 127634 | 127916 | pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); |
| 127635 | 127917 | pNewExpr2 = sqlite3PExpr(pParse, TK_LT, |
| 127636 | 127918 | sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName), |
| 127637 | | - pStr2, 0); |
| 127919 | + pStr2); |
| 127638 | 127920 | transferJoinMarkings(pNewExpr2, pExpr); |
| 127639 | 127921 | idxNew2 = whereClauseInsert(pWC, pNewExpr2, wtFlags); |
| 127640 | 127922 | testcase( idxNew2==0 ); |
| 127641 | 127923 | exprAnalyze(pSrc, pWC, idxNew2); |
| 127642 | 127924 | pTerm = &pWC->a[idxTerm]; |
| | @@ -127665,11 +127947,11 @@ |
| 127665 | 127947 | prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight); |
| 127666 | 127948 | prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft); |
| 127667 | 127949 | if( (prereqExpr & prereqColumn)==0 ){ |
| 127668 | 127950 | Expr *pNewExpr; |
| 127669 | 127951 | pNewExpr = sqlite3PExpr(pParse, TK_MATCH, |
| 127670 | | - 0, sqlite3ExprDup(db, pRight, 0), 0); |
| 127952 | + 0, sqlite3ExprDup(db, pRight, 0)); |
| 127671 | 127953 | idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC); |
| 127672 | 127954 | testcase( idxNew==0 ); |
| 127673 | 127955 | pNewTerm = &pWC->a[idxNew]; |
| 127674 | 127956 | pNewTerm->prereqRight = prereqExpr; |
| 127675 | 127957 | pNewTerm->leftCursor = pLeft->iTable; |
| | @@ -127704,11 +127986,11 @@ |
| 127704 | 127986 | int idxNew; |
| 127705 | 127987 | Expr *pNew; |
| 127706 | 127988 | Expr *pLeft = sqlite3ExprForVectorField(pParse, pExpr->pLeft, i); |
| 127707 | 127989 | Expr *pRight = sqlite3ExprForVectorField(pParse, pExpr->pRight, i); |
| 127708 | 127990 | |
| 127709 | | - pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight, 0); |
| 127991 | + pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight); |
| 127710 | 127992 | transferJoinMarkings(pNew, pExpr); |
| 127711 | 127993 | idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC); |
| 127712 | 127994 | exprAnalyze(pSrc, pWC, idxNew); |
| 127713 | 127995 | } |
| 127714 | 127996 | pTerm = &pWC->a[idxTerm]; |
| | @@ -127756,11 +128038,11 @@ |
| 127756 | 128038 | int idxNew; |
| 127757 | 128039 | WhereTerm *pNewTerm; |
| 127758 | 128040 | |
| 127759 | 128041 | pNewExpr = sqlite3PExpr(pParse, TK_GT, |
| 127760 | 128042 | sqlite3ExprDup(db, pLeft, 0), |
| 127761 | | - sqlite3ExprAlloc(db, TK_NULL, 0, 0), 0); |
| 128043 | + sqlite3ExprAlloc(db, TK_NULL, 0, 0)); |
| 127762 | 128044 | |
| 127763 | 128045 | idxNew = whereClauseInsert(pWC, pNewExpr, |
| 127764 | 128046 | TERM_VIRTUAL|TERM_DYNAMIC|TERM_VNULL); |
| 127765 | 128047 | if( idxNew ){ |
| 127766 | 128048 | pNewTerm = &pWC->a[idxNew]; |
| | @@ -127942,11 +128224,11 @@ |
| 127942 | 128224 | if( pColRef==0 ) return; |
| 127943 | 128225 | pColRef->iTable = pItem->iCursor; |
| 127944 | 128226 | pColRef->iColumn = k++; |
| 127945 | 128227 | pColRef->pTab = pTab; |
| 127946 | 128228 | pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, |
| 127947 | | - sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0); |
| 128229 | + sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0)); |
| 127948 | 128230 | whereClauseInsert(pWC, pTerm, TERM_DYNAMIC); |
| 127949 | 128231 | } |
| 127950 | 128232 | } |
| 127951 | 128233 | |
| 127952 | 128234 | /************** End of whereexpr.c *******************************************/ |
| | @@ -133067,20 +133349,20 @@ |
| 133067 | 133349 | Parse *pParse, /* The parsing context. Errors accumulate here */ |
| 133068 | 133350 | int op, /* The binary operation */ |
| 133069 | 133351 | ExprSpan *pLeft, /* The left operand, and output */ |
| 133070 | 133352 | ExprSpan *pRight /* The right operand */ |
| 133071 | 133353 | ){ |
| 133072 | | - pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr, 0); |
| 133354 | + pLeft->pExpr = sqlite3PExpr(pParse, op, pLeft->pExpr, pRight->pExpr); |
| 133073 | 133355 | pLeft->zEnd = pRight->zEnd; |
| 133074 | 133356 | } |
| 133075 | 133357 | |
| 133076 | 133358 | /* If doNot is true, then add a TK_NOT Expr-node wrapper around the |
| 133077 | 133359 | ** outside of *ppExpr. |
| 133078 | 133360 | */ |
| 133079 | 133361 | static void exprNot(Parse *pParse, int doNot, ExprSpan *pSpan){ |
| 133080 | 133362 | if( doNot ){ |
| 133081 | | - pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0, 0); |
| 133363 | + pSpan->pExpr = sqlite3PExpr(pParse, TK_NOT, pSpan->pExpr, 0); |
| 133082 | 133364 | } |
| 133083 | 133365 | } |
| 133084 | 133366 | |
| 133085 | 133367 | /* Construct an expression node for a unary postfix operator |
| 133086 | 133368 | */ |
| | @@ -133088,11 +133370,11 @@ |
| 133088 | 133370 | Parse *pParse, /* Parsing context to record errors */ |
| 133089 | 133371 | int op, /* The operator */ |
| 133090 | 133372 | ExprSpan *pOperand, /* The operand, and output */ |
| 133091 | 133373 | Token *pPostOp /* The operand token for setting the span */ |
| 133092 | 133374 | ){ |
| 133093 | | - pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0); |
| 133375 | + pOperand->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0); |
| 133094 | 133376 | pOperand->zEnd = &pPostOp->z[pPostOp->n]; |
| 133095 | 133377 | } |
| 133096 | 133378 | |
| 133097 | 133379 | /* A routine to convert a binary TK_IS or TK_ISNOT expression into a |
| 133098 | 133380 | ** unary TK_ISNULL or TK_NOTNULL expression. */ |
| | @@ -133113,11 +133395,11 @@ |
| 133113 | 133395 | int op, /* The operator */ |
| 133114 | 133396 | ExprSpan *pOperand, /* The operand */ |
| 133115 | 133397 | Token *pPreOp /* The operand token for setting the span */ |
| 133116 | 133398 | ){ |
| 133117 | 133399 | pOut->zStart = pPreOp->z; |
| 133118 | | - pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0, 0); |
| 133400 | + pOut->pExpr = sqlite3PExpr(pParse, op, pOperand->pExpr, 0); |
| 133119 | 133401 | pOut->zEnd = pOperand->zEnd; |
| 133120 | 133402 | } |
| 133121 | 133403 | |
| 133122 | 133404 | /* Add a single new term to an ExprList that is used to store a |
| 133123 | 133405 | ** list of identifiers. Report an error if the ID list contains |
| | @@ -134706,11 +134988,10 @@ |
| 134706 | 134988 | /* |
| 134707 | 134989 | ** The following routine is called if the stack overflows. |
| 134708 | 134990 | */ |
| 134709 | 134991 | static void yyStackOverflow(yyParser *yypParser){ |
| 134710 | 134992 | sqlite3ParserARG_FETCH; |
| 134711 | | - yypParser->yytos--; |
| 134712 | 134993 | #ifndef NDEBUG |
| 134713 | 134994 | if( yyTraceFILE ){ |
| 134714 | 134995 | fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt); |
| 134715 | 134996 | } |
| 134716 | 134997 | #endif |
| | @@ -134761,16 +135042,18 @@ |
| 134761 | 135042 | assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack) ); |
| 134762 | 135043 | } |
| 134763 | 135044 | #endif |
| 134764 | 135045 | #if YYSTACKDEPTH>0 |
| 134765 | 135046 | if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){ |
| 135047 | + yypParser->yytos--; |
| 134766 | 135048 | yyStackOverflow(yypParser); |
| 134767 | 135049 | return; |
| 134768 | 135050 | } |
| 134769 | 135051 | #else |
| 134770 | 135052 | if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){ |
| 134771 | 135053 | if( yyGrowStack(yypParser) ){ |
| 135054 | + yypParser->yytos--; |
| 134772 | 135055 | yyStackOverflow(yypParser); |
| 134773 | 135056 | return; |
| 134774 | 135057 | } |
| 134775 | 135058 | } |
| 134776 | 135059 | #endif |
| | @@ -135308,11 +135591,11 @@ |
| 135308 | 135591 | {sqlite3AddDefaultValue(pParse,&yymsp[-1].minor.yy190);} |
| 135309 | 135592 | break; |
| 135310 | 135593 | case 33: /* ccons ::= DEFAULT MINUS term */ |
| 135311 | 135594 | { |
| 135312 | 135595 | ExprSpan v; |
| 135313 | | - v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0, 0); |
| 135596 | + v.pExpr = sqlite3PExpr(pParse, TK_UMINUS, yymsp[0].minor.yy190.pExpr, 0); |
| 135314 | 135597 | v.zStart = yymsp[-1].minor.yy0.z; |
| 135315 | 135598 | v.zEnd = yymsp[0].minor.yy190.zEnd; |
| 135316 | 135599 | sqlite3AddDefaultValue(pParse,&v); |
| 135317 | 135600 | } |
| 135318 | 135601 | break; |
| | @@ -135572,13 +135855,13 @@ |
| 135572 | 135855 | yymsp[-1].minor.yy148 = sqlite3ExprListAppend(pParse, yymsp[-1].minor.yy148, p); |
| 135573 | 135856 | } |
| 135574 | 135857 | break; |
| 135575 | 135858 | case 94: /* selcollist ::= sclp nm DOT STAR */ |
| 135576 | 135859 | { |
| 135577 | | - Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0, 0); |
| 135578 | | - Expr *pLeft = sqlite3PExpr(pParse, TK_ID, 0, 0, &yymsp[-2].minor.yy0); |
| 135579 | | - Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0); |
| 135860 | + Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0); |
| 135861 | + Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); |
| 135862 | + Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight); |
| 135580 | 135863 | yymsp[-3].minor.yy148 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy148, pDot); |
| 135581 | 135864 | } |
| 135582 | 135865 | break; |
| 135583 | 135866 | case 95: /* as ::= AS nm */ |
| 135584 | 135867 | case 106: /* dbnm ::= DOT nm */ yytestcase(yyruleno==106); |
| | @@ -135800,21 +136083,21 @@ |
| 135800 | 136083 | case 154: /* expr ::= nm DOT nm */ |
| 135801 | 136084 | { |
| 135802 | 136085 | Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); |
| 135803 | 136086 | Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); |
| 135804 | 136087 | spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ |
| 135805 | | - yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2, 0); |
| 136088 | + yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp2); |
| 135806 | 136089 | } |
| 135807 | 136090 | break; |
| 135808 | 136091 | case 155: /* expr ::= nm DOT nm DOT nm */ |
| 135809 | 136092 | { |
| 135810 | 136093 | Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1); |
| 135811 | 136094 | Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1); |
| 135812 | 136095 | Expr *temp3 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1); |
| 135813 | | - Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3, 0); |
| 136096 | + Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3); |
| 135814 | 136097 | spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ |
| 135815 | | - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0); |
| 136098 | + yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4); |
| 135816 | 136099 | } |
| 135817 | 136100 | break; |
| 135818 | 136101 | case 158: /* term ::= INTEGER */ |
| 135819 | 136102 | { |
| 135820 | 136103 | yylhsminor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1); |
| | @@ -135839,11 +136122,11 @@ |
| 135839 | 136122 | spanSet(&yymsp[0].minor.yy190, &t, &t); |
| 135840 | 136123 | if( pParse->nested==0 ){ |
| 135841 | 136124 | sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t); |
| 135842 | 136125 | yymsp[0].minor.yy190.pExpr = 0; |
| 135843 | 136126 | }else{ |
| 135844 | | - yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, 0); |
| 136127 | + yymsp[0].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0); |
| 135845 | 136128 | if( yymsp[0].minor.yy190.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy190.pExpr->iTable); |
| 135846 | 136129 | } |
| 135847 | 136130 | } |
| 135848 | 136131 | } |
| 135849 | 136132 | break; |
| | @@ -135854,11 +136137,12 @@ |
| 135854 | 136137 | } |
| 135855 | 136138 | break; |
| 135856 | 136139 | case 161: /* expr ::= CAST LP expr AS typetoken RP */ |
| 135857 | 136140 | { |
| 135858 | 136141 | spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ |
| 135859 | | - yymsp[-5].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CAST, yymsp[-3].minor.yy190.pExpr, 0, &yymsp[-1].minor.yy0); |
| 136142 | + yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1); |
| 136143 | + sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy190.pExpr, yymsp[-3].minor.yy190.pExpr, 0); |
| 135860 | 136144 | } |
| 135861 | 136145 | break; |
| 135862 | 136146 | case 162: /* expr ::= ID|INDEXED LP distinct exprlist RP */ |
| 135863 | 136147 | { |
| 135864 | 136148 | if( yymsp[-1].minor.yy148 && yymsp[-1].minor.yy148->nExpr>pParse->db->aLimit[SQLITE_LIMIT_FUNCTION_ARG] ){ |
| | @@ -135887,11 +136171,11 @@ |
| 135887 | 136171 | yymsp[0].minor.yy190 = yylhsminor.yy190; |
| 135888 | 136172 | break; |
| 135889 | 136173 | case 165: /* expr ::= LP nexprlist COMMA expr RP */ |
| 135890 | 136174 | { |
| 135891 | 136175 | ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy148, yymsp[-1].minor.yy190.pExpr); |
| 135892 | | - yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0, 0); |
| 136176 | + yylhsminor.yy190.pExpr = sqlite3PExpr(pParse, TK_VECTOR, 0, 0); |
| 135893 | 136177 | if( yylhsminor.yy190.pExpr ){ |
| 135894 | 136178 | yylhsminor.yy190.pExpr->x.pList = pList; |
| 135895 | 136179 | spanSet(&yylhsminor.yy190, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0); |
| 135896 | 136180 | }else{ |
| 135897 | 136181 | sqlite3ExprListDelete(pParse->db, pList); |
| | @@ -135976,11 +136260,11 @@ |
| 135976 | 136260 | break; |
| 135977 | 136261 | case 188: /* expr ::= expr between_op expr AND expr */ |
| 135978 | 136262 | { |
| 135979 | 136263 | ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy190.pExpr); |
| 135980 | 136264 | pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy190.pExpr); |
| 135981 | | - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0, 0); |
| 136265 | + yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy190.pExpr, 0); |
| 135982 | 136266 | if( yymsp[-4].minor.yy190.pExpr ){ |
| 135983 | 136267 | yymsp[-4].minor.yy190.pExpr->x.pList = pList; |
| 135984 | 136268 | }else{ |
| 135985 | 136269 | sqlite3ExprListDelete(pParse->db, pList); |
| 135986 | 136270 | } |
| | @@ -135998,11 +136282,11 @@ |
| 135998 | 136282 | ** |
| 135999 | 136283 | ** simplify to constants 0 (false) and 1 (true), respectively, |
| 136000 | 136284 | ** regardless of the value of expr1. |
| 136001 | 136285 | */ |
| 136002 | 136286 | sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy190.pExpr); |
| 136003 | | - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_INTEGER, 0, 0, &sqlite3IntTokens[yymsp[-3].minor.yy194]); |
| 136287 | + yymsp[-4].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy194],1); |
| 136004 | 136288 | }else if( yymsp[-1].minor.yy148->nExpr==1 ){ |
| 136005 | 136289 | /* Expressions of the form: |
| 136006 | 136290 | ** |
| 136007 | 136291 | ** expr1 IN (?1) |
| 136008 | 136292 | ** expr1 NOT IN (?2) |
| | @@ -136025,13 +136309,13 @@ |
| 136025 | 136309 | ** before now and control would have never reached this point */ |
| 136026 | 136310 | if( ALWAYS(pRHS) ){ |
| 136027 | 136311 | pRHS->flags &= ~EP_Collate; |
| 136028 | 136312 | pRHS->flags |= EP_Generic; |
| 136029 | 136313 | } |
| 136030 | | - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS, 0); |
| 136314 | + yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, yymsp[-3].minor.yy194 ? TK_NE : TK_EQ, yymsp[-4].minor.yy190.pExpr, pRHS); |
| 136031 | 136315 | }else{ |
| 136032 | | - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0); |
| 136316 | + yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); |
| 136033 | 136317 | if( yymsp[-4].minor.yy190.pExpr ){ |
| 136034 | 136318 | yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy148; |
| 136035 | 136319 | sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr); |
| 136036 | 136320 | }else{ |
| 136037 | 136321 | sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy148); |
| | @@ -136042,17 +136326,17 @@ |
| 136042 | 136326 | } |
| 136043 | 136327 | break; |
| 136044 | 136328 | case 192: /* expr ::= LP select RP */ |
| 136045 | 136329 | { |
| 136046 | 136330 | spanSet(&yymsp[-2].minor.yy190,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ |
| 136047 | | - yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0); |
| 136331 | + yymsp[-2].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0); |
| 136048 | 136332 | sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy190.pExpr, yymsp[-1].minor.yy243); |
| 136049 | 136333 | } |
| 136050 | 136334 | break; |
| 136051 | 136335 | case 193: /* expr ::= expr in_op LP select RP */ |
| 136052 | 136336 | { |
| 136053 | | - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0); |
| 136337 | + yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); |
| 136054 | 136338 | sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, yymsp[-1].minor.yy243); |
| 136055 | 136339 | exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); |
| 136056 | 136340 | yymsp[-4].minor.yy190.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n]; |
| 136057 | 136341 | } |
| 136058 | 136342 | break; |
| | @@ -136059,28 +136343,28 @@ |
| 136059 | 136343 | case 194: /* expr ::= expr in_op nm dbnm paren_exprlist */ |
| 136060 | 136344 | { |
| 136061 | 136345 | SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0); |
| 136062 | 136346 | Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0); |
| 136063 | 136347 | if( yymsp[0].minor.yy148 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy148); |
| 136064 | | - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0, 0); |
| 136348 | + yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy190.pExpr, 0); |
| 136065 | 136349 | sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy190.pExpr, pSelect); |
| 136066 | 136350 | exprNot(pParse, yymsp[-3].minor.yy194, &yymsp[-4].minor.yy190); |
| 136067 | 136351 | yymsp[-4].minor.yy190.zEnd = yymsp[-1].minor.yy0.z ? &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n] : &yymsp[-2].minor.yy0.z[yymsp[-2].minor.yy0.n]; |
| 136068 | 136352 | } |
| 136069 | 136353 | break; |
| 136070 | 136354 | case 195: /* expr ::= EXISTS LP select RP */ |
| 136071 | 136355 | { |
| 136072 | 136356 | Expr *p; |
| 136073 | 136357 | spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/ |
| 136074 | | - p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0); |
| 136358 | + p = yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0); |
| 136075 | 136359 | sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy243); |
| 136076 | 136360 | } |
| 136077 | 136361 | break; |
| 136078 | 136362 | case 196: /* expr ::= CASE case_operand case_exprlist case_else END */ |
| 136079 | 136363 | { |
| 136080 | 136364 | spanSet(&yymsp[-4].minor.yy190,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/ |
| 136081 | | - yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0, 0); |
| 136365 | + yymsp[-4].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy72, 0); |
| 136082 | 136366 | if( yymsp[-4].minor.yy190.pExpr ){ |
| 136083 | 136367 | yymsp[-4].minor.yy190.pExpr->x.pList = yymsp[-1].minor.yy72 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy148,yymsp[-1].minor.yy72) : yymsp[-2].minor.yy148; |
| 136084 | 136368 | sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy190.pExpr); |
| 136085 | 136369 | }else{ |
| 136086 | 136370 | sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy148); |
| | @@ -136250,20 +136534,20 @@ |
| 136250 | 136534 | {yymsp[0].minor.yy145 = sqlite3TriggerSelectStep(pParse->db, yymsp[0].minor.yy243); /*A-overwrites-X*/} |
| 136251 | 136535 | break; |
| 136252 | 136536 | case 247: /* expr ::= RAISE LP IGNORE RP */ |
| 136253 | 136537 | { |
| 136254 | 136538 | spanSet(&yymsp[-3].minor.yy190,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ |
| 136255 | | - yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, 0); |
| 136539 | + yymsp[-3].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0); |
| 136256 | 136540 | if( yymsp[-3].minor.yy190.pExpr ){ |
| 136257 | 136541 | yymsp[-3].minor.yy190.pExpr->affinity = OE_Ignore; |
| 136258 | 136542 | } |
| 136259 | 136543 | } |
| 136260 | 136544 | break; |
| 136261 | 136545 | case 248: /* expr ::= RAISE LP raisetype COMMA nm RP */ |
| 136262 | 136546 | { |
| 136263 | 136547 | spanSet(&yymsp[-5].minor.yy190,&yymsp[-5].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/ |
| 136264 | | - yymsp[-5].minor.yy190.pExpr = sqlite3PExpr(pParse, TK_RAISE, 0, 0, &yymsp[-1].minor.yy0); |
| 136548 | + yymsp[-5].minor.yy190.pExpr = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1); |
| 136265 | 136549 | if( yymsp[-5].minor.yy190.pExpr ) { |
| 136266 | 136550 | yymsp[-5].minor.yy190.pExpr->affinity = (char)yymsp[-3].minor.yy194; |
| 136267 | 136551 | } |
| 136268 | 136552 | } |
| 136269 | 136553 | break; |
| | @@ -141491,11 +141775,11 @@ |
| 141491 | 141775 | /* |
| 141492 | 141776 | ** Interface to the testing logic. |
| 141493 | 141777 | */ |
| 141494 | 141778 | SQLITE_API int sqlite3_test_control(int op, ...){ |
| 141495 | 141779 | int rc = 0; |
| 141496 | | -#ifdef SQLITE_OMIT_BUILTIN_TEST |
| 141780 | +#ifdef SQLITE_UNTESTABLE |
| 141497 | 141781 | UNUSED_PARAMETER(op); |
| 141498 | 141782 | #else |
| 141499 | 141783 | va_list ap; |
| 141500 | 141784 | va_start(ap, op); |
| 141501 | 141785 | switch( op ){ |
| | @@ -141828,11 +142112,11 @@ |
| 141828 | 142112 | sqlite3_mutex_leave(db->mutex); |
| 141829 | 142113 | break; |
| 141830 | 142114 | } |
| 141831 | 142115 | } |
| 141832 | 142116 | va_end(ap); |
| 141833 | | -#endif /* SQLITE_OMIT_BUILTIN_TEST */ |
| 142117 | +#endif /* SQLITE_UNTESTABLE */ |
| 141834 | 142118 | return rc; |
| 141835 | 142119 | } |
| 141836 | 142120 | |
| 141837 | 142121 | /* |
| 141838 | 142122 | ** This is a utility routine, useful to VFS implementations, that checks |
| | @@ -141939,26 +142223,27 @@ |
| 141939 | 142223 | const char *zDb, |
| 141940 | 142224 | sqlite3_snapshot **ppSnapshot |
| 141941 | 142225 | ){ |
| 141942 | 142226 | int rc = SQLITE_ERROR; |
| 141943 | 142227 | #ifndef SQLITE_OMIT_WAL |
| 141944 | | - int iDb; |
| 141945 | 142228 | |
| 141946 | 142229 | #ifdef SQLITE_ENABLE_API_ARMOR |
| 141947 | 142230 | if( !sqlite3SafetyCheckOk(db) ){ |
| 141948 | 142231 | return SQLITE_MISUSE_BKPT; |
| 141949 | 142232 | } |
| 141950 | 142233 | #endif |
| 141951 | 142234 | sqlite3_mutex_enter(db->mutex); |
| 141952 | 142235 | |
| 141953 | | - iDb = sqlite3FindDbName(db, zDb); |
| 141954 | | - if( iDb==0 || iDb>1 ){ |
| 141955 | | - Btree *pBt = db->aDb[iDb].pBt; |
| 141956 | | - if( 0==sqlite3BtreeIsInTrans(pBt) ){ |
| 141957 | | - rc = sqlite3BtreeBeginTrans(pBt, 0); |
| 141958 | | - if( rc==SQLITE_OK ){ |
| 141959 | | - rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot); |
| 142236 | + if( db->autoCommit==0 ){ |
| 142237 | + int iDb = sqlite3FindDbName(db, zDb); |
| 142238 | + if( iDb==0 || iDb>1 ){ |
| 142239 | + Btree *pBt = db->aDb[iDb].pBt; |
| 142240 | + if( 0==sqlite3BtreeIsInTrans(pBt) ){ |
| 142241 | + rc = sqlite3BtreeBeginTrans(pBt, 0); |
| 142242 | + if( rc==SQLITE_OK ){ |
| 142243 | + rc = sqlite3PagerSnapshotGet(sqlite3BtreePager(pBt), ppSnapshot); |
| 142244 | + } |
| 141960 | 142245 | } |
| 141961 | 142246 | } |
| 141962 | 142247 | } |
| 141963 | 142248 | |
| 141964 | 142249 | sqlite3_mutex_leave(db->mutex); |
| | @@ -141996,10 +142281,42 @@ |
| 141996 | 142281 | } |
| 141997 | 142282 | } |
| 141998 | 142283 | } |
| 141999 | 142284 | } |
| 142000 | 142285 | |
| 142286 | + sqlite3_mutex_leave(db->mutex); |
| 142287 | +#endif /* SQLITE_OMIT_WAL */ |
| 142288 | + return rc; |
| 142289 | +} |
| 142290 | + |
| 142291 | +/* |
| 142292 | +** Recover as many snapshots as possible from the wal file associated with |
| 142293 | +** schema zDb of database db. |
| 142294 | +*/ |
| 142295 | +SQLITE_API int sqlite3_snapshot_recover(sqlite3 *db, const char *zDb){ |
| 142296 | + int rc = SQLITE_ERROR; |
| 142297 | + int iDb; |
| 142298 | +#ifndef SQLITE_OMIT_WAL |
| 142299 | + |
| 142300 | +#ifdef SQLITE_ENABLE_API_ARMOR |
| 142301 | + if( !sqlite3SafetyCheckOk(db) ){ |
| 142302 | + return SQLITE_MISUSE_BKPT; |
| 142303 | + } |
| 142304 | +#endif |
| 142305 | + |
| 142306 | + sqlite3_mutex_enter(db->mutex); |
| 142307 | + iDb = sqlite3FindDbName(db, zDb); |
| 142308 | + if( iDb==0 || iDb>1 ){ |
| 142309 | + Btree *pBt = db->aDb[iDb].pBt; |
| 142310 | + if( 0==sqlite3BtreeIsInReadTrans(pBt) ){ |
| 142311 | + rc = sqlite3BtreeBeginTrans(pBt, 0); |
| 142312 | + if( rc==SQLITE_OK ){ |
| 142313 | + rc = sqlite3PagerSnapshotRecover(sqlite3BtreePager(pBt)); |
| 142314 | + sqlite3BtreeCommit(pBt); |
| 142315 | + } |
| 142316 | + } |
| 142317 | + } |
| 142001 | 142318 | sqlite3_mutex_leave(db->mutex); |
| 142002 | 142319 | #endif /* SQLITE_OMIT_WAL */ |
| 142003 | 142320 | return rc; |
| 142004 | 142321 | } |
| 142005 | 142322 | |
| | @@ -180834,11 +181151,10 @@ |
| 180834 | 181151 | /* |
| 180835 | 181152 | ** The following routine is called if the stack overflows. |
| 180836 | 181153 | */ |
| 180837 | 181154 | static void fts5yyStackOverflow(fts5yyParser *fts5yypParser){ |
| 180838 | 181155 | sqlite3Fts5ParserARG_FETCH; |
| 180839 | | - fts5yypParser->fts5yytos--; |
| 180840 | 181156 | #ifndef NDEBUG |
| 180841 | 181157 | if( fts5yyTraceFILE ){ |
| 180842 | 181158 | fprintf(fts5yyTraceFILE,"%sStack Overflow!\n",fts5yyTracePrompt); |
| 180843 | 181159 | } |
| 180844 | 181160 | #endif |
| | @@ -180889,16 +181205,18 @@ |
| 180889 | 181205 | assert( fts5yypParser->fts5yyhwm == (int)(fts5yypParser->fts5yytos - fts5yypParser->fts5yystack) ); |
| 180890 | 181206 | } |
| 180891 | 181207 | #endif |
| 180892 | 181208 | #if fts5YYSTACKDEPTH>0 |
| 180893 | 181209 | if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5YYSTACKDEPTH] ){ |
| 181210 | + fts5yypParser->fts5yytos--; |
| 180894 | 181211 | fts5yyStackOverflow(fts5yypParser); |
| 180895 | 181212 | return; |
| 180896 | 181213 | } |
| 180897 | 181214 | #else |
| 180898 | 181215 | if( fts5yypParser->fts5yytos>=&fts5yypParser->fts5yystack[fts5yypParser->fts5yystksz] ){ |
| 180899 | 181216 | if( fts5yyGrowStack(fts5yypParser) ){ |
| 181217 | + fts5yypParser->fts5yytos--; |
| 180900 | 181218 | fts5yyStackOverflow(fts5yypParser); |
| 180901 | 181219 | return; |
| 180902 | 181220 | } |
| 180903 | 181221 | } |
| 180904 | 181222 | #endif |
| | @@ -184206,52 +184524,65 @@ |
| 184206 | 184524 | |
| 184207 | 184525 | /* |
| 184208 | 184526 | ** Initialize all term iterators in the pNear object. If any term is found |
| 184209 | 184527 | ** to match no documents at all, return immediately without initializing any |
| 184210 | 184528 | ** further iterators. |
| 184529 | +** |
| 184530 | +** If an error occurs, return an SQLite error code. Otherwise, return |
| 184531 | +** SQLITE_OK. It is not considered an error if some term matches zero |
| 184532 | +** documents. |
| 184211 | 184533 | */ |
| 184212 | 184534 | static int fts5ExprNearInitAll( |
| 184213 | 184535 | Fts5Expr *pExpr, |
| 184214 | 184536 | Fts5ExprNode *pNode |
| 184215 | 184537 | ){ |
| 184216 | 184538 | Fts5ExprNearset *pNear = pNode->pNear; |
| 184217 | | - int i, j; |
| 184218 | | - int rc = SQLITE_OK; |
| 184219 | | - int bEof = 1; |
| 184539 | + int i; |
| 184220 | 184540 | |
| 184221 | 184541 | assert( pNode->bNomatch==0 ); |
| 184222 | | - for(i=0; rc==SQLITE_OK && i<pNear->nPhrase; i++){ |
| 184542 | + for(i=0; i<pNear->nPhrase; i++){ |
| 184223 | 184543 | Fts5ExprPhrase *pPhrase = pNear->apPhrase[i]; |
| 184224 | | - for(j=0; j<pPhrase->nTerm; j++){ |
| 184225 | | - Fts5ExprTerm *pTerm = &pPhrase->aTerm[j]; |
| 184226 | | - Fts5ExprTerm *p; |
| 184227 | | - |
| 184228 | | - for(p=pTerm; p && rc==SQLITE_OK; p=p->pSynonym){ |
| 184229 | | - if( p->pIter ){ |
| 184230 | | - sqlite3Fts5IterClose(p->pIter); |
| 184231 | | - p->pIter = 0; |
| 184232 | | - } |
| 184233 | | - rc = sqlite3Fts5IndexQuery( |
| 184234 | | - pExpr->pIndex, p->zTerm, (int)strlen(p->zTerm), |
| 184235 | | - (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) | |
| 184236 | | - (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0), |
| 184237 | | - pNear->pColset, |
| 184238 | | - &p->pIter |
| 184239 | | - ); |
| 184240 | | - assert( rc==SQLITE_OK || p->pIter==0 ); |
| 184241 | | - if( p->pIter && 0==sqlite3Fts5IterEof(p->pIter) ){ |
| 184242 | | - bEof = 0; |
| 184243 | | - } |
| 184244 | | - } |
| 184245 | | - |
| 184246 | | - if( bEof ) break; |
| 184247 | | - } |
| 184248 | | - if( bEof ) break; |
| 184249 | | - } |
| 184250 | | - |
| 184251 | | - pNode->bEof = bEof; |
| 184252 | | - return rc; |
| 184544 | + if( pPhrase->nTerm==0 ){ |
| 184545 | + pNode->bEof = 1; |
| 184546 | + return SQLITE_OK; |
| 184547 | + }else{ |
| 184548 | + int j; |
| 184549 | + for(j=0; j<pPhrase->nTerm; j++){ |
| 184550 | + Fts5ExprTerm *pTerm = &pPhrase->aTerm[j]; |
| 184551 | + Fts5ExprTerm *p; |
| 184552 | + int bHit = 0; |
| 184553 | + |
| 184554 | + for(p=pTerm; p; p=p->pSynonym){ |
| 184555 | + int rc; |
| 184556 | + if( p->pIter ){ |
| 184557 | + sqlite3Fts5IterClose(p->pIter); |
| 184558 | + p->pIter = 0; |
| 184559 | + } |
| 184560 | + rc = sqlite3Fts5IndexQuery( |
| 184561 | + pExpr->pIndex, p->zTerm, (int)strlen(p->zTerm), |
| 184562 | + (pTerm->bPrefix ? FTS5INDEX_QUERY_PREFIX : 0) | |
| 184563 | + (pExpr->bDesc ? FTS5INDEX_QUERY_DESC : 0), |
| 184564 | + pNear->pColset, |
| 184565 | + &p->pIter |
| 184566 | + ); |
| 184567 | + assert( (rc==SQLITE_OK)==(p->pIter!=0) ); |
| 184568 | + if( rc!=SQLITE_OK ) return rc; |
| 184569 | + if( 0==sqlite3Fts5IterEof(p->pIter) ){ |
| 184570 | + bHit = 1; |
| 184571 | + } |
| 184572 | + } |
| 184573 | + |
| 184574 | + if( bHit==0 ){ |
| 184575 | + pNode->bEof = 1; |
| 184576 | + return SQLITE_OK; |
| 184577 | + } |
| 184578 | + } |
| 184579 | + } |
| 184580 | + } |
| 184581 | + |
| 184582 | + pNode->bEof = 0; |
| 184583 | + return SQLITE_OK; |
| 184253 | 184584 | } |
| 184254 | 184585 | |
| 184255 | 184586 | /* |
| 184256 | 184587 | ** If pExpr is an ASC iterator, this function returns a value with the |
| 184257 | 184588 | ** same sign as: |
| | @@ -195785,11 +196116,11 @@ |
| 195785 | 196116 | int nArg, /* Number of args */ |
| 195786 | 196117 | sqlite3_value **apUnused /* Function arguments */ |
| 195787 | 196118 | ){ |
| 195788 | 196119 | assert( nArg==0 ); |
| 195789 | 196120 | UNUSED_PARAM2(nArg, apUnused); |
| 195790 | | - sqlite3_result_text(pCtx, "fts5: 2016-11-19 18:31:37 28393c413cc4505b94411730e728583c5d4baaae", -1, SQLITE_TRANSIENT); |
| 196121 | + sqlite3_result_text(pCtx, "fts5: 2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5", -1, SQLITE_TRANSIENT); |
| 195791 | 196122 | } |
| 195792 | 196123 | |
| 195793 | 196124 | static int fts5Init(sqlite3 *db){ |
| 195794 | 196125 | static const sqlite3_module fts5Mod = { |
| 195795 | 196126 | /* iVersion */ 2, |
| 195796 | 196127 | |