| | @@ -135,11 +135,11 @@ |
| 135 | 135 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 136 | 136 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 137 | 137 | */ |
| 138 | 138 | #define SQLITE_VERSION "3.8.2" |
| 139 | 139 | #define SQLITE_VERSION_NUMBER 3008002 |
| 140 | | -#define SQLITE_SOURCE_ID "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a" |
| 140 | +#define SQLITE_SOURCE_ID "2013-11-21 23:37:02 3d47a556f0074e39b880186fb7661b1b8955f742" |
| 141 | 141 | |
| 142 | 142 | /* |
| 143 | 143 | ** CAPI3REF: Run-Time Library Version Numbers |
| 144 | 144 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 145 | 145 | ** |
| | @@ -8140,13 +8140,12 @@ |
| 8140 | 8140 | #define TK_UNCLOSED_STRING 151 |
| 8141 | 8141 | #define TK_FUNCTION 152 |
| 8142 | 8142 | #define TK_COLUMN 153 |
| 8143 | 8143 | #define TK_AGG_FUNCTION 154 |
| 8144 | 8144 | #define TK_AGG_COLUMN 155 |
| 8145 | | -#define TK_CONST_FUNC 156 |
| 8146 | | -#define TK_UMINUS 157 |
| 8147 | | -#define TK_UPLUS 158 |
| 8145 | +#define TK_UMINUS 156 |
| 8146 | +#define TK_UPLUS 157 |
| 8148 | 8147 | |
| 8149 | 8148 | /************** End of parse.h ***********************************************/ |
| 8150 | 8149 | /************** Continuing where we left off in sqliteInt.h ******************/ |
| 8151 | 8150 | #include <stdio.h> |
| 8152 | 8151 | #include <stdlib.h> |
| | @@ -8778,12 +8777,12 @@ |
| 8778 | 8777 | SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes); |
| 8779 | 8778 | SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*); |
| 8780 | 8779 | SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes); |
| 8781 | 8780 | SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize); |
| 8782 | 8781 | SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*); |
| 8783 | | -SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, int *pAmt); |
| 8784 | | -SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, int *pAmt); |
| 8782 | +SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt); |
| 8783 | +SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt); |
| 8785 | 8784 | SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize); |
| 8786 | 8785 | SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*); |
| 8787 | 8786 | SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64); |
| 8788 | 8787 | SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*); |
| 8789 | 8788 | |
| | @@ -9021,87 +9020,87 @@ |
| 9021 | 9020 | #define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */ |
| 9022 | 9021 | #define OP_Savepoint 2 |
| 9023 | 9022 | #define OP_AutoCommit 3 |
| 9024 | 9023 | #define OP_Transaction 4 |
| 9025 | 9024 | #define OP_SorterNext 5 |
| 9026 | | -#define OP_Prev 6 |
| 9027 | | -#define OP_Next 7 |
| 9028 | | -#define OP_AggStep 8 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 9029 | | -#define OP_Checkpoint 9 |
| 9030 | | -#define OP_JournalMode 10 |
| 9031 | | -#define OP_Vacuum 11 |
| 9032 | | -#define OP_VFilter 12 /* synopsis: iPlan=r[P3] zPlan='P4' */ |
| 9033 | | -#define OP_VUpdate 13 /* synopsis: data=r[P3@P2] */ |
| 9034 | | -#define OP_Goto 14 |
| 9035 | | -#define OP_Gosub 15 |
| 9036 | | -#define OP_Return 16 |
| 9037 | | -#define OP_Yield 17 |
| 9038 | | -#define OP_HaltIfNull 18 /* synopsis: if r[P3] null then halt */ |
| 9025 | +#define OP_PrevIfOpen 6 |
| 9026 | +#define OP_NextIfOpen 7 |
| 9027 | +#define OP_Prev 8 |
| 9028 | +#define OP_Next 9 |
| 9029 | +#define OP_AggStep 10 /* synopsis: accum=r[P3] step(r[P2@P5]) */ |
| 9030 | +#define OP_Checkpoint 11 |
| 9031 | +#define OP_JournalMode 12 |
| 9032 | +#define OP_Vacuum 13 |
| 9033 | +#define OP_VFilter 14 /* synopsis: iPlan=r[P3] zPlan='P4' */ |
| 9034 | +#define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */ |
| 9035 | +#define OP_Goto 16 |
| 9036 | +#define OP_Gosub 17 |
| 9037 | +#define OP_Return 18 |
| 9039 | 9038 | #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */ |
| 9040 | | -#define OP_Halt 20 |
| 9041 | | -#define OP_Integer 21 /* synopsis: r[P2]=P1 */ |
| 9042 | | -#define OP_Int64 22 /* synopsis: r[P2]=P4 */ |
| 9043 | | -#define OP_String 23 /* synopsis: r[P2]='P4' (len=P1) */ |
| 9044 | | -#define OP_Null 24 /* synopsis: r[P2..P3]=NULL */ |
| 9045 | | -#define OP_Blob 25 /* synopsis: r[P2]=P4 (len=P1) */ |
| 9046 | | -#define OP_Variable 26 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 9047 | | -#define OP_Move 27 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9048 | | -#define OP_Copy 28 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9049 | | -#define OP_SCopy 29 /* synopsis: r[P2]=r[P1] */ |
| 9050 | | -#define OP_ResultRow 30 /* synopsis: output=r[P1@P2] */ |
| 9051 | | -#define OP_CollSeq 31 |
| 9052 | | -#define OP_AddImm 32 /* synopsis: r[P1]=r[P1]+P2 */ |
| 9053 | | -#define OP_MustBeInt 33 |
| 9054 | | -#define OP_RealAffinity 34 |
| 9055 | | -#define OP_Permutation 35 |
| 9056 | | -#define OP_Compare 36 |
| 9057 | | -#define OP_Jump 37 |
| 9058 | | -#define OP_Once 38 |
| 9059 | | -#define OP_If 39 |
| 9060 | | -#define OP_IfNot 40 |
| 9061 | | -#define OP_Column 41 /* synopsis: r[P3]=PX */ |
| 9062 | | -#define OP_Affinity 42 /* synopsis: affinity(r[P1@P2]) */ |
| 9063 | | -#define OP_MakeRecord 43 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 9064 | | -#define OP_Count 44 /* synopsis: r[P2]=count() */ |
| 9065 | | -#define OP_ReadCookie 45 |
| 9066 | | -#define OP_SetCookie 46 |
| 9067 | | -#define OP_VerifyCookie 47 |
| 9068 | | -#define OP_OpenRead 48 /* synopsis: root=P2 iDb=P3 */ |
| 9069 | | -#define OP_OpenWrite 49 /* synopsis: root=P2 iDb=P3 */ |
| 9070 | | -#define OP_OpenAutoindex 50 /* synopsis: nColumn=P2 */ |
| 9071 | | -#define OP_OpenEphemeral 51 /* synopsis: nColumn=P2 */ |
| 9072 | | -#define OP_SorterOpen 52 |
| 9073 | | -#define OP_OpenPseudo 53 /* synopsis: content in r[P2@P3] */ |
| 9074 | | -#define OP_Close 54 |
| 9075 | | -#define OP_SeekLt 55 /* synopsis: key=r[P3@P4] */ |
| 9076 | | -#define OP_SeekLe 56 /* synopsis: key=r[P3@P4] */ |
| 9077 | | -#define OP_SeekGe 57 /* synopsis: key=r[P3@P4] */ |
| 9078 | | -#define OP_SeekGt 58 /* synopsis: key=r[P3@P4] */ |
| 9079 | | -#define OP_Seek 59 /* synopsis: intkey=r[P2] */ |
| 9080 | | -#define OP_NoConflict 60 /* synopsis: key=r[P3@P4] */ |
| 9081 | | -#define OP_NotFound 61 /* synopsis: key=r[P3@P4] */ |
| 9082 | | -#define OP_Found 62 /* synopsis: key=r[P3@P4] */ |
| 9083 | | -#define OP_NotExists 63 /* synopsis: intkey=r[P3] */ |
| 9084 | | -#define OP_Sequence 64 /* synopsis: r[P2]=rowid */ |
| 9085 | | -#define OP_NewRowid 65 /* synopsis: r[P2]=rowid */ |
| 9086 | | -#define OP_Insert 66 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 9087 | | -#define OP_InsertInt 67 /* synopsis: intkey=P3 data=r[P2] */ |
| 9088 | | -#define OP_Delete 68 |
| 9039 | +#define OP_Yield 20 |
| 9040 | +#define OP_HaltIfNull 21 /* synopsis: if r[P3] null then halt */ |
| 9041 | +#define OP_Halt 22 |
| 9042 | +#define OP_Integer 23 /* synopsis: r[P2]=P1 */ |
| 9043 | +#define OP_Int64 24 /* synopsis: r[P2]=P4 */ |
| 9044 | +#define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */ |
| 9045 | +#define OP_Null 26 /* synopsis: r[P2..P3]=NULL */ |
| 9046 | +#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */ |
| 9047 | +#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */ |
| 9048 | +#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9049 | +#define OP_Copy 30 /* synopsis: r[P2@P3]=r[P1@P3] */ |
| 9050 | +#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */ |
| 9051 | +#define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */ |
| 9052 | +#define OP_CollSeq 33 |
| 9053 | +#define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */ |
| 9054 | +#define OP_MustBeInt 35 |
| 9055 | +#define OP_RealAffinity 36 |
| 9056 | +#define OP_Permutation 37 |
| 9057 | +#define OP_Compare 38 |
| 9058 | +#define OP_Jump 39 |
| 9059 | +#define OP_Once 40 |
| 9060 | +#define OP_If 41 |
| 9061 | +#define OP_IfNot 42 |
| 9062 | +#define OP_Column 43 /* synopsis: r[P3]=PX */ |
| 9063 | +#define OP_Affinity 44 /* synopsis: affinity(r[P1@P2]) */ |
| 9064 | +#define OP_MakeRecord 45 /* synopsis: r[P3]=mkrec(r[P1@P2]) */ |
| 9065 | +#define OP_Count 46 /* synopsis: r[P2]=count() */ |
| 9066 | +#define OP_ReadCookie 47 |
| 9067 | +#define OP_SetCookie 48 |
| 9068 | +#define OP_VerifyCookie 49 |
| 9069 | +#define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */ |
| 9070 | +#define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */ |
| 9071 | +#define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */ |
| 9072 | +#define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */ |
| 9073 | +#define OP_SorterOpen 54 |
| 9074 | +#define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */ |
| 9075 | +#define OP_Close 56 |
| 9076 | +#define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */ |
| 9077 | +#define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */ |
| 9078 | +#define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */ |
| 9079 | +#define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */ |
| 9080 | +#define OP_Seek 61 /* synopsis: intkey=r[P2] */ |
| 9081 | +#define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */ |
| 9082 | +#define OP_NotFound 63 /* synopsis: key=r[P3@P4] */ |
| 9083 | +#define OP_Found 64 /* synopsis: key=r[P3@P4] */ |
| 9084 | +#define OP_NotExists 65 /* synopsis: intkey=r[P3] */ |
| 9085 | +#define OP_Sequence 66 /* synopsis: r[P2]=rowid */ |
| 9086 | +#define OP_NewRowid 67 /* synopsis: r[P2]=rowid */ |
| 9087 | +#define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */ |
| 9089 | 9088 | #define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */ |
| 9090 | 9089 | #define OP_And 70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */ |
| 9091 | | -#define OP_ResetCount 71 |
| 9092 | | -#define OP_SorterCompare 72 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */ |
| 9093 | | -#define OP_SorterData 73 /* synopsis: r[P2]=data */ |
| 9090 | +#define OP_InsertInt 71 /* synopsis: intkey=P3 data=r[P2] */ |
| 9091 | +#define OP_Delete 72 |
| 9092 | +#define OP_ResetCount 73 |
| 9094 | 9093 | #define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */ |
| 9095 | 9094 | #define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */ |
| 9096 | 9095 | #define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */ |
| 9097 | 9096 | #define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */ |
| 9098 | 9097 | #define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */ |
| 9099 | 9098 | #define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */ |
| 9100 | 9099 | #define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */ |
| 9101 | 9100 | #define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */ |
| 9102 | | -#define OP_RowKey 82 /* synopsis: r[P2]=key */ |
| 9101 | +#define OP_SorterCompare 82 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */ |
| 9103 | 9102 | #define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */ |
| 9104 | 9103 | #define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */ |
| 9105 | 9104 | #define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */ |
| 9106 | 9105 | #define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */ |
| 9107 | 9106 | #define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */ |
| | @@ -9108,68 +9107,70 @@ |
| 9108 | 9107 | #define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */ |
| 9109 | 9108 | #define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */ |
| 9110 | 9109 | #define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */ |
| 9111 | 9110 | #define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */ |
| 9112 | 9111 | #define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */ |
| 9113 | | -#define OP_RowData 93 /* synopsis: r[P2]=data */ |
| 9112 | +#define OP_SorterData 93 /* synopsis: r[P2]=data */ |
| 9114 | 9113 | #define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */ |
| 9115 | 9114 | #define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */ |
| 9116 | | -#define OP_Rowid 96 /* synopsis: r[P2]=rowid */ |
| 9117 | | -#define OP_NullRow 97 |
| 9118 | | -#define OP_Last 98 |
| 9119 | | -#define OP_SorterSort 99 |
| 9120 | | -#define OP_Sort 100 |
| 9121 | | -#define OP_Rewind 101 |
| 9122 | | -#define OP_SorterInsert 102 |
| 9123 | | -#define OP_IdxInsert 103 /* synopsis: key=r[P2] */ |
| 9124 | | -#define OP_IdxDelete 104 /* synopsis: key=r[P2@P3] */ |
| 9125 | | -#define OP_IdxRowid 105 /* synopsis: r[P2]=rowid */ |
| 9126 | | -#define OP_IdxLT 106 /* synopsis: key=r[P3@P4] */ |
| 9127 | | -#define OP_IdxGE 107 /* synopsis: key=r[P3@P4] */ |
| 9128 | | -#define OP_Destroy 108 |
| 9129 | | -#define OP_Clear 109 |
| 9130 | | -#define OP_CreateIndex 110 /* synopsis: r[P2]=root iDb=P1 */ |
| 9131 | | -#define OP_CreateTable 111 /* synopsis: r[P2]=root iDb=P1 */ |
| 9132 | | -#define OP_ParseSchema 112 |
| 9133 | | -#define OP_LoadAnalysis 113 |
| 9134 | | -#define OP_DropTable 114 |
| 9135 | | -#define OP_DropIndex 115 |
| 9136 | | -#define OP_DropTrigger 116 |
| 9137 | | -#define OP_IntegrityCk 117 |
| 9138 | | -#define OP_RowSetAdd 118 /* synopsis: rowset(P1)=r[P2] */ |
| 9139 | | -#define OP_RowSetRead 119 /* synopsis: r[P3]=rowset(P1) */ |
| 9140 | | -#define OP_RowSetTest 120 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 9141 | | -#define OP_Program 121 |
| 9142 | | -#define OP_Param 122 |
| 9143 | | -#define OP_FkCounter 123 /* synopsis: fkctr[P1]+=P2 */ |
| 9144 | | -#define OP_FkIfZero 124 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 9145 | | -#define OP_MemMax 125 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 9146 | | -#define OP_IfPos 126 /* synopsis: if r[P1]>0 goto P2 */ |
| 9147 | | -#define OP_IfNeg 127 /* synopsis: if r[P1]<0 goto P2 */ |
| 9148 | | -#define OP_IfZero 128 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */ |
| 9149 | | -#define OP_AggFinal 129 /* synopsis: accum=r[P1] N=P2 */ |
| 9150 | | -#define OP_IncrVacuum 130 |
| 9115 | +#define OP_RowKey 96 /* synopsis: r[P2]=key */ |
| 9116 | +#define OP_RowData 97 /* synopsis: r[P2]=data */ |
| 9117 | +#define OP_Rowid 98 /* synopsis: r[P2]=rowid */ |
| 9118 | +#define OP_NullRow 99 |
| 9119 | +#define OP_Last 100 |
| 9120 | +#define OP_SorterSort 101 |
| 9121 | +#define OP_Sort 102 |
| 9122 | +#define OP_Rewind 103 |
| 9123 | +#define OP_SorterInsert 104 |
| 9124 | +#define OP_IdxInsert 105 /* synopsis: key=r[P2] */ |
| 9125 | +#define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */ |
| 9126 | +#define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */ |
| 9127 | +#define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */ |
| 9128 | +#define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */ |
| 9129 | +#define OP_Destroy 110 |
| 9130 | +#define OP_Clear 111 |
| 9131 | +#define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */ |
| 9132 | +#define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */ |
| 9133 | +#define OP_ParseSchema 114 |
| 9134 | +#define OP_LoadAnalysis 115 |
| 9135 | +#define OP_DropTable 116 |
| 9136 | +#define OP_DropIndex 117 |
| 9137 | +#define OP_DropTrigger 118 |
| 9138 | +#define OP_IntegrityCk 119 |
| 9139 | +#define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */ |
| 9140 | +#define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */ |
| 9141 | +#define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */ |
| 9142 | +#define OP_Program 123 |
| 9143 | +#define OP_Param 124 |
| 9144 | +#define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */ |
| 9145 | +#define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */ |
| 9146 | +#define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */ |
| 9147 | +#define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */ |
| 9148 | +#define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */ |
| 9149 | +#define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */ |
| 9151 | 9150 | #define OP_Real 131 /* same as TK_FLOAT, synopsis: r[P2]=P4 */ |
| 9152 | | -#define OP_Expire 132 |
| 9153 | | -#define OP_TableLock 133 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 9154 | | -#define OP_VBegin 134 |
| 9155 | | -#define OP_VCreate 135 |
| 9156 | | -#define OP_VDestroy 136 |
| 9157 | | -#define OP_VOpen 137 |
| 9158 | | -#define OP_VColumn 138 /* synopsis: r[P3]=vcolumn(P2) */ |
| 9159 | | -#define OP_VNext 139 |
| 9160 | | -#define OP_VRename 140 |
| 9161 | | -#define OP_Pagecount 141 |
| 9151 | +#define OP_AggFinal 132 /* synopsis: accum=r[P1] N=P2 */ |
| 9152 | +#define OP_IncrVacuum 133 |
| 9153 | +#define OP_Expire 134 |
| 9154 | +#define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */ |
| 9155 | +#define OP_VBegin 136 |
| 9156 | +#define OP_VCreate 137 |
| 9157 | +#define OP_VDestroy 138 |
| 9158 | +#define OP_VOpen 139 |
| 9159 | +#define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */ |
| 9160 | +#define OP_VNext 141 |
| 9162 | 9161 | #define OP_ToText 142 /* same as TK_TO_TEXT */ |
| 9163 | 9162 | #define OP_ToBlob 143 /* same as TK_TO_BLOB */ |
| 9164 | 9163 | #define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */ |
| 9165 | 9164 | #define OP_ToInt 145 /* same as TK_TO_INT */ |
| 9166 | 9165 | #define OP_ToReal 146 /* same as TK_TO_REAL */ |
| 9167 | | -#define OP_MaxPgcnt 147 |
| 9168 | | -#define OP_Trace 148 |
| 9169 | | -#define OP_Noop 149 |
| 9170 | | -#define OP_Explain 150 |
| 9166 | +#define OP_VRename 147 |
| 9167 | +#define OP_Pagecount 148 |
| 9168 | +#define OP_MaxPgcnt 149 |
| 9169 | +#define OP_Trace 150 |
| 9170 | +#define OP_Noop 151 |
| 9171 | +#define OP_Explain 152 |
| 9171 | 9172 | |
| 9172 | 9173 | |
| 9173 | 9174 | /* Properties such as "out2" or "jump" that are specified in |
| 9174 | 9175 | ** comments following the "case" for each opcode in the vdbe.c |
| 9175 | 9176 | ** are encoded into bitvectors as follows: |
| | @@ -9181,28 +9182,29 @@ |
| 9181 | 9182 | #define OPFLG_IN3 0x0010 /* in3: P3 is an input */ |
| 9182 | 9183 | #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */ |
| 9183 | 9184 | #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */ |
| 9184 | 9185 | #define OPFLG_INITIALIZER {\ |
| 9185 | 9186 | /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\ |
| 9186 | | -/* 8 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x01,\ |
| 9187 | | -/* 16 */ 0x04, 0x04, 0x10, 0x24, 0x00, 0x02, 0x02, 0x02,\ |
| 9188 | | -/* 24 */ 0x02, 0x02, 0x02, 0x00, 0x00, 0x20, 0x00, 0x00,\ |
| 9189 | | -/* 32 */ 0x04, 0x05, 0x04, 0x00, 0x00, 0x01, 0x01, 0x05,\ |
| 9190 | | -/* 40 */ 0x05, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00,\ |
| 9191 | | -/* 48 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11,\ |
| 9192 | | -/* 56 */ 0x11, 0x11, 0x11, 0x08, 0x11, 0x11, 0x11, 0x11,\ |
| 9193 | | -/* 64 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c, 0x4c, 0x00,\ |
| 9187 | +/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\ |
| 9188 | +/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\ |
| 9189 | +/* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\ |
| 9190 | +/* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\ |
| 9191 | +/* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\ |
| 9192 | +/* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 9193 | +/* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\ |
| 9194 | +/* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c, 0x4c, 0x00,\ |
| 9194 | 9195 | /* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\ |
| 9195 | 9196 | /* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\ |
| 9196 | 9197 | /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\ |
| 9197 | | -/* 96 */ 0x02, 0x00, 0x01, 0x01, 0x01, 0x01, 0x08, 0x08,\ |
| 9198 | | -/* 104 */ 0x00, 0x02, 0x01, 0x01, 0x02, 0x00, 0x02, 0x02,\ |
| 9199 | | -/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45,\ |
| 9200 | | -/* 120 */ 0x15, 0x01, 0x02, 0x00, 0x01, 0x08, 0x05, 0x05,\ |
| 9201 | | -/* 128 */ 0x05, 0x00, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00,\ |
| 9202 | | -/* 136 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x04, 0x04,\ |
| 9203 | | -/* 144 */ 0x04, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00,} |
| 9198 | +/* 96 */ 0x00, 0x00, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\ |
| 9199 | +/* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\ |
| 9200 | +/* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ |
| 9201 | +/* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\ |
| 9202 | +/* 128 */ 0x05, 0x05, 0x05, 0x02, 0x00, 0x01, 0x00, 0x00,\ |
| 9203 | +/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04, 0x04,\ |
| 9204 | +/* 144 */ 0x04, 0x04, 0x04, 0x00, 0x02, 0x02, 0x00, 0x00,\ |
| 9205 | +/* 152 */ 0x00,} |
| 9204 | 9206 | |
| 9205 | 9207 | /************** End of opcodes.h *********************************************/ |
| 9206 | 9208 | /************** Continuing where we left off in vdbe.h ***********************/ |
| 9207 | 9209 | |
| 9208 | 9210 | /* |
| | @@ -10336,10 +10338,17 @@ |
| 10336 | 10338 | #else |
| 10337 | 10339 | #define OptimizationDisabled(db, mask) 0 |
| 10338 | 10340 | #define OptimizationEnabled(db, mask) 1 |
| 10339 | 10341 | #endif |
| 10340 | 10342 | |
| 10343 | +/* |
| 10344 | +** Return true if it OK to factor constant expressions into the initialization |
| 10345 | +** code. The argument is a Parse object for the code generator. |
| 10346 | +*/ |
| 10347 | +#define ConstFactorOk(P) \ |
| 10348 | + ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst)) |
| 10349 | + |
| 10341 | 10350 | /* |
| 10342 | 10351 | ** Possible values for the sqlite.magic field. |
| 10343 | 10352 | ** The numbers are obtained at random and have no special meaning, other |
| 10344 | 10353 | ** than being distinct from one another. |
| 10345 | 10354 | */ |
| | @@ -10402,10 +10411,11 @@ |
| 10402 | 10411 | #define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */ |
| 10403 | 10412 | #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */ |
| 10404 | 10413 | #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */ |
| 10405 | 10414 | #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */ |
| 10406 | 10415 | #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */ |
| 10416 | +#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */ |
| 10407 | 10417 | |
| 10408 | 10418 | /* |
| 10409 | 10419 | ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are |
| 10410 | 10420 | ** used to create the initializers for the FuncDef structures. |
| 10411 | 10421 | ** |
| | @@ -10414,10 +10424,13 @@ |
| 10414 | 10424 | ** implemented by C function xFunc that accepts nArg arguments. The |
| 10415 | 10425 | ** value passed as iArg is cast to a (void*) and made available |
| 10416 | 10426 | ** as the user-data (sqlite3_user_data()) for the function. If |
| 10417 | 10427 | ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set. |
| 10418 | 10428 | ** |
| 10429 | +** VFUNCTION(zName, nArg, iArg, bNC, xFunc) |
| 10430 | +** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag. |
| 10431 | +** |
| 10419 | 10432 | ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal) |
| 10420 | 10433 | ** Used to create an aggregate function definition implemented by |
| 10421 | 10434 | ** the C functions xStep and xFinal. The first four parameters |
| 10422 | 10435 | ** are interpreted in the same way as the first 4 parameters to |
| 10423 | 10436 | ** FUNCTION(). |
| | @@ -10429,20 +10442,24 @@ |
| 10429 | 10442 | ** available as the function user-data (sqlite3_user_data()). The |
| 10430 | 10443 | ** FuncDef.flags variable is set to the value passed as the flags |
| 10431 | 10444 | ** parameter. |
| 10432 | 10445 | */ |
| 10433 | 10446 | #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 10447 | + {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 10448 | + SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 10449 | +#define VFUNCTION(zName, nArg, iArg, bNC, xFunc) \ |
| 10434 | 10450 | {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 10435 | 10451 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 10436 | 10452 | #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \ |
| 10437 | | - {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \ |
| 10453 | + {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\ |
| 10438 | 10454 | SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0} |
| 10439 | 10455 | #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \ |
| 10440 | | - {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 10456 | + {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \ |
| 10441 | 10457 | pArg, 0, xFunc, 0, 0, #zName, 0, 0} |
| 10442 | 10458 | #define LIKEFUNC(zName, nArg, arg, flags) \ |
| 10443 | | - {nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} |
| 10459 | + {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \ |
| 10460 | + (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0} |
| 10444 | 10461 | #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \ |
| 10445 | 10462 | {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \ |
| 10446 | 10463 | SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0} |
| 10447 | 10464 | |
| 10448 | 10465 | /* |
| | @@ -11098,10 +11115,11 @@ |
| 11098 | 11115 | #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ |
| 11099 | 11116 | #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */ |
| 11100 | 11117 | #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ |
| 11101 | 11118 | #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */ |
| 11102 | 11119 | #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ |
| 11120 | +#define EP_Constant 0x080000 /* Node is a constant */ |
| 11103 | 11121 | |
| 11104 | 11122 | /* |
| 11105 | 11123 | ** These macros can be used to test, set, or clear bits in the |
| 11106 | 11124 | ** Expr.flags field. |
| 11107 | 11125 | */ |
| | @@ -11159,10 +11177,11 @@ |
| 11159 | 11177 | char *zName; /* Token associated with this expression */ |
| 11160 | 11178 | char *zSpan; /* Original text of the expression */ |
| 11161 | 11179 | u8 sortOrder; /* 1 for DESC or 0 for ASC */ |
| 11162 | 11180 | unsigned done :1; /* A flag to indicate when processing is finished */ |
| 11163 | 11181 | unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */ |
| 11182 | + unsigned reusable :1; /* Constant expression is reusable */ |
| 11164 | 11183 | union { |
| 11165 | 11184 | struct { |
| 11166 | 11185 | u16 iOrderByCol; /* For ORDER BY, column number in result set */ |
| 11167 | 11186 | u16 iAlias; /* Index into Parse.aAlias[] for zName */ |
| 11168 | 11187 | } x; |
| | @@ -12153,14 +12172,17 @@ |
| 12153 | 12172 | SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int); |
| 12154 | 12173 | SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int); |
| 12155 | 12174 | SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*); |
| 12156 | 12175 | SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int); |
| 12157 | 12176 | SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int); |
| 12177 | +SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8); |
| 12158 | 12178 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*); |
| 12159 | 12179 | SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int); |
| 12160 | 12180 | SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int); |
| 12161 | | -SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int); |
| 12181 | +SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8); |
| 12182 | +#define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */ |
| 12183 | +#define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */ |
| 12162 | 12184 | SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int); |
| 12163 | 12185 | SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int); |
| 12164 | 12186 | SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*); |
| 12165 | 12187 | SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*); |
| 12166 | 12188 | SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *); |
| | @@ -13386,11 +13408,11 @@ |
| 13386 | 13408 | typedef struct VdbeOp Op; |
| 13387 | 13409 | |
| 13388 | 13410 | /* |
| 13389 | 13411 | ** Boolean values |
| 13390 | 13412 | */ |
| 13391 | | -typedef unsigned char Bool; |
| 13413 | +typedef unsigned Bool; |
| 13392 | 13414 | |
| 13393 | 13415 | /* Opaque type used by code in vdbesort.c */ |
| 13394 | 13416 | typedef struct VdbeSorter VdbeSorter; |
| 13395 | 13417 | |
| 13396 | 13418 | /* Opaque type used by the explainer */ |
| | @@ -13403,42 +13425,39 @@ |
| 13403 | 13425 | ** A cursor is a pointer into a single BTree within a database file. |
| 13404 | 13426 | ** The cursor can seek to a BTree entry with a particular key, or |
| 13405 | 13427 | ** loop over all entries of the Btree. You can also insert new BTree |
| 13406 | 13428 | ** entries or retrieve the key or data from the entry that the cursor |
| 13407 | 13429 | ** is currently pointing to. |
| 13430 | +** |
| 13431 | +** Cursors can also point to virtual tables, sorters, or "pseudo-tables". |
| 13432 | +** A pseudo-table is a single-row table implemented by registers. |
| 13408 | 13433 | ** |
| 13409 | 13434 | ** Every cursor that the virtual machine has open is represented by an |
| 13410 | 13435 | ** instance of the following structure. |
| 13411 | 13436 | */ |
| 13412 | 13437 | struct VdbeCursor { |
| 13413 | 13438 | BtCursor *pCursor; /* The cursor structure of the backend */ |
| 13414 | 13439 | Btree *pBt; /* Separate file holding temporary table */ |
| 13415 | 13440 | KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */ |
| 13416 | | - int iDb; /* Index of cursor database in db->aDb[] (or -1) */ |
| 13441 | + int seekResult; /* Result of previous sqlite3BtreeMoveto() */ |
| 13417 | 13442 | int pseudoTableReg; /* Register holding pseudotable content. */ |
| 13418 | | - int nField; /* Number of fields in the header */ |
| 13419 | | - Bool zeroed; /* True if zeroed out and ready for reuse */ |
| 13420 | | - Bool rowidIsValid; /* True if lastRowid is valid */ |
| 13421 | | - Bool atFirst; /* True if pointing to first entry */ |
| 13422 | | - Bool useRandomRowid; /* Generate new record numbers semi-randomly */ |
| 13423 | | - Bool nullRow; /* True if pointing to a row with no data */ |
| 13424 | | - Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ |
| 13425 | | - Bool isTable; /* True if a table requiring integer keys */ |
| 13426 | | - Bool isIndex; /* True if an index containing keys only - no data */ |
| 13427 | | - Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */ |
| 13428 | | - Bool isSorter; /* True if a new-style sorter */ |
| 13429 | | - Bool multiPseudo; /* Multi-register pseudo-cursor */ |
| 13443 | + i16 nField; /* Number of fields in the header */ |
| 13444 | + u16 nHdrParsed; /* Number of header fields parsed so far */ |
| 13445 | + i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */ |
| 13446 | + u8 nullRow; /* True if pointing to a row with no data */ |
| 13447 | + u8 rowidIsValid; /* True if lastRowid is valid */ |
| 13448 | + u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ |
| 13449 | + Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */ |
| 13450 | + Bool isTable:1; /* True if a table requiring integer keys */ |
| 13451 | + Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */ |
| 13452 | + Bool multiPseudo:1; /* Multi-register pseudo-cursor */ |
| 13430 | 13453 | sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ |
| 13431 | | - const sqlite3_module *pModule; /* Module for cursor pVtabCursor */ |
| 13432 | 13454 | i64 seqCount; /* Sequence counter */ |
| 13433 | 13455 | i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ |
| 13434 | | - i64 lastRowid; /* Last rowid from a Next or NextIdx operation */ |
| 13456 | + i64 lastRowid; /* Rowid being deleted by OP_Delete */ |
| 13435 | 13457 | VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */ |
| 13436 | 13458 | |
| 13437 | | - /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists */ |
| 13438 | | - int seekResult; |
| 13439 | | - |
| 13440 | 13459 | /* Cached information about the header for the data record that the |
| 13441 | 13460 | ** cursor is currently pointing to. Only valid if cacheStatus matches |
| 13442 | 13461 | ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of |
| 13443 | 13462 | ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that |
| 13444 | 13463 | ** the cache is out of date. |
| | @@ -13445,14 +13464,18 @@ |
| 13445 | 13464 | ** |
| 13446 | 13465 | ** aRow might point to (ephemeral) data for the current row, or it might |
| 13447 | 13466 | ** be NULL. |
| 13448 | 13467 | */ |
| 13449 | 13468 | u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */ |
| 13450 | | - int payloadSize; /* Total number of bytes in the record */ |
| 13451 | | - u32 *aType; /* Type values for all entries in the record */ |
| 13452 | | - u32 *aOffset; /* Cached offsets to the start of each columns data */ |
| 13453 | | - u8 *aRow; /* Data for the current row, if all on one page */ |
| 13469 | + u32 payloadSize; /* Total number of bytes in the record */ |
| 13470 | + u32 szRow; /* Byte available in aRow */ |
| 13471 | + u32 iHdrOffset; /* Offset to next unparsed byte of the header */ |
| 13472 | + const u8 *aRow; /* Data for the current row, if all on one page */ |
| 13473 | + u32 aType[1]; /* Type values for all entries in the record */ |
| 13474 | + /* 2*nField extra array elements allocated for aType[], beyond the one |
| 13475 | + ** static element declared in the structure. nField total array slots for |
| 13476 | + ** aType[] and nField+1 array slots for aOffset[] */ |
| 13454 | 13477 | }; |
| 13455 | 13478 | typedef struct VdbeCursor VdbeCursor; |
| 13456 | 13479 | |
| 13457 | 13480 | /* |
| 13458 | 13481 | ** When a sub-program is executed (OP_Program), a structure of this type |
| | @@ -13773,11 +13796,11 @@ |
| 13773 | 13796 | SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*); |
| 13774 | 13797 | SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*); |
| 13775 | 13798 | SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*); |
| 13776 | 13799 | SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*); |
| 13777 | 13800 | SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*); |
| 13778 | | -SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*); |
| 13801 | +SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*); |
| 13779 | 13802 | SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p); |
| 13780 | 13803 | SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p); |
| 13781 | 13804 | #define VdbeMemRelease(X) \ |
| 13782 | 13805 | if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \ |
| 13783 | 13806 | sqlite3VdbeMemReleaseExternal(X); |
| | @@ -22901,87 +22924,87 @@ |
| 22901 | 22924 | /* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"), |
| 22902 | 22925 | /* 2 */ "Savepoint" OpHelp(""), |
| 22903 | 22926 | /* 3 */ "AutoCommit" OpHelp(""), |
| 22904 | 22927 | /* 4 */ "Transaction" OpHelp(""), |
| 22905 | 22928 | /* 5 */ "SorterNext" OpHelp(""), |
| 22906 | | - /* 6 */ "Prev" OpHelp(""), |
| 22907 | | - /* 7 */ "Next" OpHelp(""), |
| 22908 | | - /* 8 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 22909 | | - /* 9 */ "Checkpoint" OpHelp(""), |
| 22910 | | - /* 10 */ "JournalMode" OpHelp(""), |
| 22911 | | - /* 11 */ "Vacuum" OpHelp(""), |
| 22912 | | - /* 12 */ "VFilter" OpHelp("iPlan=r[P3] zPlan='P4'"), |
| 22913 | | - /* 13 */ "VUpdate" OpHelp("data=r[P3@P2]"), |
| 22914 | | - /* 14 */ "Goto" OpHelp(""), |
| 22915 | | - /* 15 */ "Gosub" OpHelp(""), |
| 22916 | | - /* 16 */ "Return" OpHelp(""), |
| 22917 | | - /* 17 */ "Yield" OpHelp(""), |
| 22918 | | - /* 18 */ "HaltIfNull" OpHelp("if r[P3] null then halt"), |
| 22929 | + /* 6 */ "PrevIfOpen" OpHelp(""), |
| 22930 | + /* 7 */ "NextIfOpen" OpHelp(""), |
| 22931 | + /* 8 */ "Prev" OpHelp(""), |
| 22932 | + /* 9 */ "Next" OpHelp(""), |
| 22933 | + /* 10 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"), |
| 22934 | + /* 11 */ "Checkpoint" OpHelp(""), |
| 22935 | + /* 12 */ "JournalMode" OpHelp(""), |
| 22936 | + /* 13 */ "Vacuum" OpHelp(""), |
| 22937 | + /* 14 */ "VFilter" OpHelp("iPlan=r[P3] zPlan='P4'"), |
| 22938 | + /* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"), |
| 22939 | + /* 16 */ "Goto" OpHelp(""), |
| 22940 | + /* 17 */ "Gosub" OpHelp(""), |
| 22941 | + /* 18 */ "Return" OpHelp(""), |
| 22919 | 22942 | /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"), |
| 22920 | | - /* 20 */ "Halt" OpHelp(""), |
| 22921 | | - /* 21 */ "Integer" OpHelp("r[P2]=P1"), |
| 22922 | | - /* 22 */ "Int64" OpHelp("r[P2]=P4"), |
| 22923 | | - /* 23 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 22924 | | - /* 24 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 22925 | | - /* 25 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 22926 | | - /* 26 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 22927 | | - /* 27 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 22928 | | - /* 28 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 22929 | | - /* 29 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 22930 | | - /* 30 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 22931 | | - /* 31 */ "CollSeq" OpHelp(""), |
| 22932 | | - /* 32 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 22933 | | - /* 33 */ "MustBeInt" OpHelp(""), |
| 22934 | | - /* 34 */ "RealAffinity" OpHelp(""), |
| 22935 | | - /* 35 */ "Permutation" OpHelp(""), |
| 22936 | | - /* 36 */ "Compare" OpHelp(""), |
| 22937 | | - /* 37 */ "Jump" OpHelp(""), |
| 22938 | | - /* 38 */ "Once" OpHelp(""), |
| 22939 | | - /* 39 */ "If" OpHelp(""), |
| 22940 | | - /* 40 */ "IfNot" OpHelp(""), |
| 22941 | | - /* 41 */ "Column" OpHelp("r[P3]=PX"), |
| 22942 | | - /* 42 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 22943 | | - /* 43 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 22944 | | - /* 44 */ "Count" OpHelp("r[P2]=count()"), |
| 22945 | | - /* 45 */ "ReadCookie" OpHelp(""), |
| 22946 | | - /* 46 */ "SetCookie" OpHelp(""), |
| 22947 | | - /* 47 */ "VerifyCookie" OpHelp(""), |
| 22948 | | - /* 48 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 22949 | | - /* 49 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 22950 | | - /* 50 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 22951 | | - /* 51 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 22952 | | - /* 52 */ "SorterOpen" OpHelp(""), |
| 22953 | | - /* 53 */ "OpenPseudo" OpHelp("content in r[P2@P3]"), |
| 22954 | | - /* 54 */ "Close" OpHelp(""), |
| 22955 | | - /* 55 */ "SeekLt" OpHelp("key=r[P3@P4]"), |
| 22956 | | - /* 56 */ "SeekLe" OpHelp("key=r[P3@P4]"), |
| 22957 | | - /* 57 */ "SeekGe" OpHelp("key=r[P3@P4]"), |
| 22958 | | - /* 58 */ "SeekGt" OpHelp("key=r[P3@P4]"), |
| 22959 | | - /* 59 */ "Seek" OpHelp("intkey=r[P2]"), |
| 22960 | | - /* 60 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 22961 | | - /* 61 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 22962 | | - /* 62 */ "Found" OpHelp("key=r[P3@P4]"), |
| 22963 | | - /* 63 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 22964 | | - /* 64 */ "Sequence" OpHelp("r[P2]=rowid"), |
| 22965 | | - /* 65 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 22966 | | - /* 66 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 22967 | | - /* 67 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 22968 | | - /* 68 */ "Delete" OpHelp(""), |
| 22943 | + /* 20 */ "Yield" OpHelp(""), |
| 22944 | + /* 21 */ "HaltIfNull" OpHelp("if r[P3] null then halt"), |
| 22945 | + /* 22 */ "Halt" OpHelp(""), |
| 22946 | + /* 23 */ "Integer" OpHelp("r[P2]=P1"), |
| 22947 | + /* 24 */ "Int64" OpHelp("r[P2]=P4"), |
| 22948 | + /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"), |
| 22949 | + /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"), |
| 22950 | + /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"), |
| 22951 | + /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"), |
| 22952 | + /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 22953 | + /* 30 */ "Copy" OpHelp("r[P2@P3]=r[P1@P3]"), |
| 22954 | + /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"), |
| 22955 | + /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"), |
| 22956 | + /* 33 */ "CollSeq" OpHelp(""), |
| 22957 | + /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"), |
| 22958 | + /* 35 */ "MustBeInt" OpHelp(""), |
| 22959 | + /* 36 */ "RealAffinity" OpHelp(""), |
| 22960 | + /* 37 */ "Permutation" OpHelp(""), |
| 22961 | + /* 38 */ "Compare" OpHelp(""), |
| 22962 | + /* 39 */ "Jump" OpHelp(""), |
| 22963 | + /* 40 */ "Once" OpHelp(""), |
| 22964 | + /* 41 */ "If" OpHelp(""), |
| 22965 | + /* 42 */ "IfNot" OpHelp(""), |
| 22966 | + /* 43 */ "Column" OpHelp("r[P3]=PX"), |
| 22967 | + /* 44 */ "Affinity" OpHelp("affinity(r[P1@P2])"), |
| 22968 | + /* 45 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"), |
| 22969 | + /* 46 */ "Count" OpHelp("r[P2]=count()"), |
| 22970 | + /* 47 */ "ReadCookie" OpHelp(""), |
| 22971 | + /* 48 */ "SetCookie" OpHelp(""), |
| 22972 | + /* 49 */ "VerifyCookie" OpHelp(""), |
| 22973 | + /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"), |
| 22974 | + /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"), |
| 22975 | + /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"), |
| 22976 | + /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"), |
| 22977 | + /* 54 */ "SorterOpen" OpHelp(""), |
| 22978 | + /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"), |
| 22979 | + /* 56 */ "Close" OpHelp(""), |
| 22980 | + /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"), |
| 22981 | + /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"), |
| 22982 | + /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"), |
| 22983 | + /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"), |
| 22984 | + /* 61 */ "Seek" OpHelp("intkey=r[P2]"), |
| 22985 | + /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"), |
| 22986 | + /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"), |
| 22987 | + /* 64 */ "Found" OpHelp("key=r[P3@P4]"), |
| 22988 | + /* 65 */ "NotExists" OpHelp("intkey=r[P3]"), |
| 22989 | + /* 66 */ "Sequence" OpHelp("r[P2]=rowid"), |
| 22990 | + /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"), |
| 22991 | + /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"), |
| 22969 | 22992 | /* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"), |
| 22970 | 22993 | /* 70 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"), |
| 22971 | | - /* 71 */ "ResetCount" OpHelp(""), |
| 22972 | | - /* 72 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"), |
| 22973 | | - /* 73 */ "SorterData" OpHelp("r[P2]=data"), |
| 22994 | + /* 71 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"), |
| 22995 | + /* 72 */ "Delete" OpHelp(""), |
| 22996 | + /* 73 */ "ResetCount" OpHelp(""), |
| 22974 | 22997 | /* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"), |
| 22975 | 22998 | /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"), |
| 22976 | 22999 | /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"), |
| 22977 | 23000 | /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"), |
| 22978 | 23001 | /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"), |
| 22979 | 23002 | /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"), |
| 22980 | 23003 | /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"), |
| 22981 | 23004 | /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"), |
| 22982 | | - /* 82 */ "RowKey" OpHelp("r[P2]=key"), |
| 23005 | + /* 82 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"), |
| 22983 | 23006 | /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"), |
| 22984 | 23007 | /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"), |
| 22985 | 23008 | /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"), |
| 22986 | 23009 | /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"), |
| 22987 | 23010 | /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"), |
| | @@ -22988,68 +23011,70 @@ |
| 22988 | 23011 | /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"), |
| 22989 | 23012 | /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"), |
| 22990 | 23013 | /* 90 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"), |
| 22991 | 23014 | /* 91 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"), |
| 22992 | 23015 | /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"), |
| 22993 | | - /* 93 */ "RowData" OpHelp("r[P2]=data"), |
| 23016 | + /* 93 */ "SorterData" OpHelp("r[P2]=data"), |
| 22994 | 23017 | /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"), |
| 22995 | 23018 | /* 95 */ "String8" OpHelp("r[P2]='P4'"), |
| 22996 | | - /* 96 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 22997 | | - /* 97 */ "NullRow" OpHelp(""), |
| 22998 | | - /* 98 */ "Last" OpHelp(""), |
| 22999 | | - /* 99 */ "SorterSort" OpHelp(""), |
| 23000 | | - /* 100 */ "Sort" OpHelp(""), |
| 23001 | | - /* 101 */ "Rewind" OpHelp(""), |
| 23002 | | - /* 102 */ "SorterInsert" OpHelp(""), |
| 23003 | | - /* 103 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 23004 | | - /* 104 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 23005 | | - /* 105 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 23006 | | - /* 106 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 23007 | | - /* 107 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 23008 | | - /* 108 */ "Destroy" OpHelp(""), |
| 23009 | | - /* 109 */ "Clear" OpHelp(""), |
| 23010 | | - /* 110 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 23011 | | - /* 111 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 23012 | | - /* 112 */ "ParseSchema" OpHelp(""), |
| 23013 | | - /* 113 */ "LoadAnalysis" OpHelp(""), |
| 23014 | | - /* 114 */ "DropTable" OpHelp(""), |
| 23015 | | - /* 115 */ "DropIndex" OpHelp(""), |
| 23016 | | - /* 116 */ "DropTrigger" OpHelp(""), |
| 23017 | | - /* 117 */ "IntegrityCk" OpHelp(""), |
| 23018 | | - /* 118 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 23019 | | - /* 119 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 23020 | | - /* 120 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 23021 | | - /* 121 */ "Program" OpHelp(""), |
| 23022 | | - /* 122 */ "Param" OpHelp(""), |
| 23023 | | - /* 123 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 23024 | | - /* 124 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 23025 | | - /* 125 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 23026 | | - /* 126 */ "IfPos" OpHelp("if r[P1]>0 goto P2"), |
| 23027 | | - /* 127 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"), |
| 23028 | | - /* 128 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"), |
| 23029 | | - /* 129 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 23030 | | - /* 130 */ "IncrVacuum" OpHelp(""), |
| 23019 | + /* 96 */ "RowKey" OpHelp("r[P2]=key"), |
| 23020 | + /* 97 */ "RowData" OpHelp("r[P2]=data"), |
| 23021 | + /* 98 */ "Rowid" OpHelp("r[P2]=rowid"), |
| 23022 | + /* 99 */ "NullRow" OpHelp(""), |
| 23023 | + /* 100 */ "Last" OpHelp(""), |
| 23024 | + /* 101 */ "SorterSort" OpHelp(""), |
| 23025 | + /* 102 */ "Sort" OpHelp(""), |
| 23026 | + /* 103 */ "Rewind" OpHelp(""), |
| 23027 | + /* 104 */ "SorterInsert" OpHelp(""), |
| 23028 | + /* 105 */ "IdxInsert" OpHelp("key=r[P2]"), |
| 23029 | + /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"), |
| 23030 | + /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"), |
| 23031 | + /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"), |
| 23032 | + /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"), |
| 23033 | + /* 110 */ "Destroy" OpHelp(""), |
| 23034 | + /* 111 */ "Clear" OpHelp(""), |
| 23035 | + /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"), |
| 23036 | + /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"), |
| 23037 | + /* 114 */ "ParseSchema" OpHelp(""), |
| 23038 | + /* 115 */ "LoadAnalysis" OpHelp(""), |
| 23039 | + /* 116 */ "DropTable" OpHelp(""), |
| 23040 | + /* 117 */ "DropIndex" OpHelp(""), |
| 23041 | + /* 118 */ "DropTrigger" OpHelp(""), |
| 23042 | + /* 119 */ "IntegrityCk" OpHelp(""), |
| 23043 | + /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"), |
| 23044 | + /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"), |
| 23045 | + /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"), |
| 23046 | + /* 123 */ "Program" OpHelp(""), |
| 23047 | + /* 124 */ "Param" OpHelp(""), |
| 23048 | + /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"), |
| 23049 | + /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"), |
| 23050 | + /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"), |
| 23051 | + /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"), |
| 23052 | + /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"), |
| 23053 | + /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"), |
| 23031 | 23054 | /* 131 */ "Real" OpHelp("r[P2]=P4"), |
| 23032 | | - /* 132 */ "Expire" OpHelp(""), |
| 23033 | | - /* 133 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 23034 | | - /* 134 */ "VBegin" OpHelp(""), |
| 23035 | | - /* 135 */ "VCreate" OpHelp(""), |
| 23036 | | - /* 136 */ "VDestroy" OpHelp(""), |
| 23037 | | - /* 137 */ "VOpen" OpHelp(""), |
| 23038 | | - /* 138 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 23039 | | - /* 139 */ "VNext" OpHelp(""), |
| 23040 | | - /* 140 */ "VRename" OpHelp(""), |
| 23041 | | - /* 141 */ "Pagecount" OpHelp(""), |
| 23055 | + /* 132 */ "AggFinal" OpHelp("accum=r[P1] N=P2"), |
| 23056 | + /* 133 */ "IncrVacuum" OpHelp(""), |
| 23057 | + /* 134 */ "Expire" OpHelp(""), |
| 23058 | + /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"), |
| 23059 | + /* 136 */ "VBegin" OpHelp(""), |
| 23060 | + /* 137 */ "VCreate" OpHelp(""), |
| 23061 | + /* 138 */ "VDestroy" OpHelp(""), |
| 23062 | + /* 139 */ "VOpen" OpHelp(""), |
| 23063 | + /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"), |
| 23064 | + /* 141 */ "VNext" OpHelp(""), |
| 23042 | 23065 | /* 142 */ "ToText" OpHelp(""), |
| 23043 | 23066 | /* 143 */ "ToBlob" OpHelp(""), |
| 23044 | 23067 | /* 144 */ "ToNumeric" OpHelp(""), |
| 23045 | 23068 | /* 145 */ "ToInt" OpHelp(""), |
| 23046 | 23069 | /* 146 */ "ToReal" OpHelp(""), |
| 23047 | | - /* 147 */ "MaxPgcnt" OpHelp(""), |
| 23048 | | - /* 148 */ "Trace" OpHelp(""), |
| 23049 | | - /* 149 */ "Noop" OpHelp(""), |
| 23050 | | - /* 150 */ "Explain" OpHelp(""), |
| 23070 | + /* 147 */ "VRename" OpHelp(""), |
| 23071 | + /* 148 */ "Pagecount" OpHelp(""), |
| 23072 | + /* 149 */ "MaxPgcnt" OpHelp(""), |
| 23073 | + /* 150 */ "Trace" OpHelp(""), |
| 23074 | + /* 151 */ "Noop" OpHelp(""), |
| 23075 | + /* 152 */ "Explain" OpHelp(""), |
| 23051 | 23076 | }; |
| 23052 | 23077 | return azName[i]; |
| 23053 | 23078 | } |
| 23054 | 23079 | #endif |
| 23055 | 23080 | |
| | @@ -54458,11 +54483,11 @@ |
| 54458 | 54483 | ** page of the database. The data might change or move the next time |
| 54459 | 54484 | ** any btree routine is called. |
| 54460 | 54485 | */ |
| 54461 | 54486 | static const unsigned char *fetchPayload( |
| 54462 | 54487 | BtCursor *pCur, /* Cursor pointing to entry to read from */ |
| 54463 | | - int *pAmt, /* Write the number of available bytes here */ |
| 54488 | + u32 *pAmt, /* Write the number of available bytes here */ |
| 54464 | 54489 | int skipKey /* read beginning at data if this is true */ |
| 54465 | 54490 | ){ |
| 54466 | 54491 | unsigned char *aPayload; |
| 54467 | 54492 | MemPage *pPage; |
| 54468 | 54493 | u32 nKey; |
| | @@ -54508,20 +54533,20 @@ |
| 54508 | 54533 | ** this routine. |
| 54509 | 54534 | ** |
| 54510 | 54535 | ** These routines is used to get quick access to key and data |
| 54511 | 54536 | ** in the common case where no overflow pages are used. |
| 54512 | 54537 | */ |
| 54513 | | -SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){ |
| 54538 | +SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){ |
| 54514 | 54539 | const void *p = 0; |
| 54515 | 54540 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 54516 | 54541 | assert( cursorHoldsMutex(pCur) ); |
| 54517 | 54542 | if( ALWAYS(pCur->eState==CURSOR_VALID) ){ |
| 54518 | 54543 | p = (const void*)fetchPayload(pCur, pAmt, 0); |
| 54519 | 54544 | } |
| 54520 | 54545 | return p; |
| 54521 | 54546 | } |
| 54522 | | -SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){ |
| 54547 | +SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){ |
| 54523 | 54548 | const void *p = 0; |
| 54524 | 54549 | assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) ); |
| 54525 | 54550 | assert( cursorHoldsMutex(pCur) ); |
| 54526 | 54551 | if( ALWAYS(pCur->eState==CURSOR_VALID) ){ |
| 54527 | 54552 | p = (const void*)fetchPayload(pCur, pAmt, 1); |
| | @@ -60420,17 +60445,17 @@ |
| 60420 | 60445 | ** If this routine fails for any reason (malloc returns NULL or unable |
| 60421 | 60446 | ** to read from the disk) then the pMem is left in an inconsistent state. |
| 60422 | 60447 | */ |
| 60423 | 60448 | SQLITE_PRIVATE int sqlite3VdbeMemFromBtree( |
| 60424 | 60449 | BtCursor *pCur, /* Cursor pointing at record to retrieve. */ |
| 60425 | | - int offset, /* Offset from the start of data to return bytes from. */ |
| 60426 | | - int amt, /* Number of bytes to return. */ |
| 60450 | + u32 offset, /* Offset from the start of data to return bytes from. */ |
| 60451 | + u32 amt, /* Number of bytes to return. */ |
| 60427 | 60452 | int key, /* If true, retrieve from the btree key, not data. */ |
| 60428 | 60453 | Mem *pMem /* OUT: Return data in this Mem structure. */ |
| 60429 | 60454 | ){ |
| 60430 | 60455 | char *zData; /* Data from the btree layer */ |
| 60431 | | - int available = 0; /* Number of bytes available on the local btree page */ |
| 60456 | + u32 available = 0; /* Number of bytes available on the local btree page */ |
| 60432 | 60457 | int rc = SQLITE_OK; /* Return code */ |
| 60433 | 60458 | |
| 60434 | 60459 | assert( sqlite3BtreeCursorIsValid(pCur) ); |
| 60435 | 60460 | |
| 60436 | 60461 | /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert() |
| | @@ -60441,11 +60466,11 @@ |
| 60441 | 60466 | }else{ |
| 60442 | 60467 | zData = (char *)sqlite3BtreeDataFetch(pCur, &available); |
| 60443 | 60468 | } |
| 60444 | 60469 | assert( zData!=0 ); |
| 60445 | 60470 | |
| 60446 | | - if( offset+amt<=available && (pMem->flags&MEM_Dyn)==0 ){ |
| 60471 | + if( offset+amt<=available ){ |
| 60447 | 60472 | sqlite3VdbeMemRelease(pMem); |
| 60448 | 60473 | pMem->z = &zData[offset]; |
| 60449 | 60474 | pMem->flags = MEM_Blob|MEM_Ephem; |
| 60450 | 60475 | }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){ |
| 60451 | 60476 | pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term; |
| | @@ -60460,11 +60485,11 @@ |
| 60460 | 60485 | pMem->z[amt+1] = 0; |
| 60461 | 60486 | if( rc!=SQLITE_OK ){ |
| 60462 | 60487 | sqlite3VdbeMemRelease(pMem); |
| 60463 | 60488 | } |
| 60464 | 60489 | } |
| 60465 | | - pMem->n = amt; |
| 60490 | + pMem->n = (int)amt; |
| 60466 | 60491 | |
| 60467 | 60492 | return rc; |
| 60468 | 60493 | } |
| 60469 | 60494 | |
| 60470 | 60495 | /* This function is only available internally, it is not part of the |
| | @@ -61391,16 +61416,18 @@ |
| 61391 | 61416 | if( n>nMaxArgs ) nMaxArgs = n; |
| 61392 | 61417 | break; |
| 61393 | 61418 | } |
| 61394 | 61419 | #endif |
| 61395 | 61420 | case OP_Next: |
| 61421 | + case OP_NextIfOpen: |
| 61396 | 61422 | case OP_SorterNext: { |
| 61397 | 61423 | pOp->p4.xAdvance = sqlite3BtreeNext; |
| 61398 | 61424 | pOp->p4type = P4_ADVANCE; |
| 61399 | 61425 | break; |
| 61400 | 61426 | } |
| 61401 | | - case OP_Prev: { |
| 61427 | + case OP_Prev: |
| 61428 | + case OP_PrevIfOpen: { |
| 61402 | 61429 | pOp->p4.xAdvance = sqlite3BtreePrevious; |
| 61403 | 61430 | pOp->p4type = P4_ADVANCE; |
| 61404 | 61431 | break; |
| 61405 | 61432 | } |
| 61406 | 61433 | } |
| | @@ -62612,11 +62639,11 @@ |
| 62612 | 62639 | sqlite3BtreeCloseCursor(pCx->pCursor); |
| 62613 | 62640 | } |
| 62614 | 62641 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 62615 | 62642 | if( pCx->pVtabCursor ){ |
| 62616 | 62643 | sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor; |
| 62617 | | - const sqlite3_module *pModule = pCx->pModule; |
| 62644 | + const sqlite3_module *pModule = pVtabCursor->pVtab->pModule; |
| 62618 | 62645 | p->inVtabMethod = 1; |
| 62619 | 62646 | pModule->xClose(pVtabCursor); |
| 62620 | 62647 | p->inVtabMethod = 0; |
| 62621 | 62648 | } |
| 62622 | 62649 | #endif |
| | @@ -63596,11 +63623,11 @@ |
| 63596 | 63623 | #ifdef SQLITE_TEST |
| 63597 | 63624 | sqlite3_search_count++; |
| 63598 | 63625 | #endif |
| 63599 | 63626 | p->deferredMoveto = 0; |
| 63600 | 63627 | p->cacheStatus = CACHE_STALE; |
| 63601 | | - }else if( ALWAYS(p->pCursor) ){ |
| 63628 | + }else if( p->pCursor ){ |
| 63602 | 63629 | int hasMoved; |
| 63603 | 63630 | int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved); |
| 63604 | 63631 | if( rc ) return rc; |
| 63605 | 63632 | if( hasMoved ){ |
| 63606 | 63633 | p->cacheStatus = CACHE_STALE; |
| | @@ -64141,11 +64168,11 @@ |
| 64141 | 64168 | assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */ |
| 64142 | 64169 | assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey ); |
| 64143 | 64170 | |
| 64144 | 64171 | /* Read in the complete content of the index entry */ |
| 64145 | 64172 | memset(&m, 0, sizeof(m)); |
| 64146 | | - rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m); |
| 64173 | + rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m); |
| 64147 | 64174 | if( rc ){ |
| 64148 | 64175 | return rc; |
| 64149 | 64176 | } |
| 64150 | 64177 | |
| 64151 | 64178 | /* The index entry must begin with a header size */ |
| | @@ -64219,11 +64246,11 @@ |
| 64219 | 64246 | if( nCellKey<=0 || nCellKey>0x7fffffff ){ |
| 64220 | 64247 | *res = 0; |
| 64221 | 64248 | return SQLITE_CORRUPT_BKPT; |
| 64222 | 64249 | } |
| 64223 | 64250 | memset(&m, 0, sizeof(m)); |
| 64224 | | - rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (int)nCellKey, 1, &m); |
| 64251 | + rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m); |
| 64225 | 64252 | if( rc ){ |
| 64226 | 64253 | return rc; |
| 64227 | 64254 | } |
| 64228 | 64255 | assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH ); |
| 64229 | 64256 | *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked); |
| | @@ -66154,13 +66181,12 @@ |
| 66154 | 66181 | Mem *pMem = &p->aMem[p->nMem-iCur]; |
| 66155 | 66182 | |
| 66156 | 66183 | int nByte; |
| 66157 | 66184 | VdbeCursor *pCx = 0; |
| 66158 | 66185 | nByte = |
| 66159 | | - ROUND8(sizeof(VdbeCursor)) + |
| 66160 | | - (isBtreeCursor?sqlite3BtreeCursorSize():0) + |
| 66161 | | - 2*nField*sizeof(u32); |
| 66186 | + ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField + |
| 66187 | + (isBtreeCursor?sqlite3BtreeCursorSize():0); |
| 66162 | 66188 | |
| 66163 | 66189 | assert( iCur<p->nCursor ); |
| 66164 | 66190 | if( p->apCsr[iCur] ){ |
| 66165 | 66191 | sqlite3VdbeFreeCursor(p, p->apCsr[iCur]); |
| 66166 | 66192 | p->apCsr[iCur] = 0; |
| | @@ -66168,16 +66194,13 @@ |
| 66168 | 66194 | if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){ |
| 66169 | 66195 | p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; |
| 66170 | 66196 | memset(pCx, 0, sizeof(VdbeCursor)); |
| 66171 | 66197 | pCx->iDb = iDb; |
| 66172 | 66198 | pCx->nField = nField; |
| 66173 | | - if( nField ){ |
| 66174 | | - pCx->aType = (u32 *)&pMem->z[ROUND8(sizeof(VdbeCursor))]; |
| 66175 | | - } |
| 66176 | 66199 | if( isBtreeCursor ){ |
| 66177 | 66200 | pCx->pCursor = (BtCursor*) |
| 66178 | | - &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)]; |
| 66201 | + &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField]; |
| 66179 | 66202 | sqlite3BtreeCursorZero(pCx->pCursor); |
| 66180 | 66203 | } |
| 66181 | 66204 | } |
| 66182 | 66205 | return pCx; |
| 66183 | 66206 | } |
| | @@ -66669,31 +66692,26 @@ |
| 66669 | 66692 | } an; |
| 66670 | 66693 | struct OP_IfNot_stack_vars { |
| 66671 | 66694 | int c; |
| 66672 | 66695 | } ao; |
| 66673 | 66696 | struct OP_Column_stack_vars { |
| 66674 | | - u32 payloadSize; /* Number of bytes in the record */ |
| 66675 | 66697 | i64 payloadSize64; /* Number of bytes in the record */ |
| 66676 | | - int p1; /* P1 value of the opcode */ |
| 66677 | 66698 | int p2; /* column number to retrieve */ |
| 66678 | 66699 | VdbeCursor *pC; /* The VDBE cursor */ |
| 66679 | | - char *zRec; /* Pointer to complete record-data */ |
| 66680 | 66700 | BtCursor *pCrsr; /* The BTree cursor */ |
| 66681 | 66701 | u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| 66682 | 66702 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 66683 | | - int nField; /* number of fields in the record */ |
| 66684 | 66703 | int len; /* The length of the serialized data for the column */ |
| 66685 | 66704 | int i; /* Loop counter */ |
| 66686 | | - char *zData; /* Part of the record being decoded */ |
| 66687 | 66705 | Mem *pDest; /* Where to write the extracted value */ |
| 66688 | 66706 | Mem sMem; /* For storing the record being decoded */ |
| 66689 | | - u8 *zIdx; /* Index into header */ |
| 66690 | | - u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 66707 | + const u8 *zData; /* Part of the record being decoded */ |
| 66708 | + const u8 *zHdr; /* Next unparsed byte of the header */ |
| 66709 | + const u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 66691 | 66710 | u32 offset; /* Offset into the data */ |
| 66692 | 66711 | u32 szField; /* Number of bytes in the content of a field */ |
| 66693 | | - int szHdr; /* Size of the header size field at start of record */ |
| 66694 | | - int avail; /* Number of bytes of available data */ |
| 66712 | + u32 avail; /* Number of bytes of available data */ |
| 66695 | 66713 | u32 t; /* A type code from the record header */ |
| 66696 | 66714 | Mem *pReg; /* PseudoTable input register */ |
| 66697 | 66715 | } ap; |
| 66698 | 66716 | struct OP_Affinity_stack_vars { |
| 66699 | 66717 | const char *zAffinity; /* The affinity to be applied */ |
| | @@ -66852,11 +66870,11 @@ |
| 66852 | 66870 | struct OP_Rewind_stack_vars { |
| 66853 | 66871 | VdbeCursor *pC; |
| 66854 | 66872 | BtCursor *pCrsr; |
| 66855 | 66873 | int res; |
| 66856 | 66874 | } bq; |
| 66857 | | - struct OP_Next_stack_vars { |
| 66875 | + struct OP_SorterNext_stack_vars { |
| 66858 | 66876 | VdbeCursor *pC; |
| 66859 | 66877 | int res; |
| 66860 | 66878 | } br; |
| 66861 | 66879 | struct OP_IdxInsert_stack_vars { |
| 66862 | 66880 | VdbeCursor *pC; |
| | @@ -67553,19 +67571,19 @@ |
| 67553 | 67571 | int n; /* Number of registers left to copy */ |
| 67554 | 67572 | int p1; /* Register to copy from */ |
| 67555 | 67573 | int p2; /* Register to copy to */ |
| 67556 | 67574 | #endif /* local variables moved into u.ae */ |
| 67557 | 67575 | |
| 67558 | | - u.ae.n = pOp->p3 + 1; |
| 67576 | + u.ae.n = pOp->p3; |
| 67559 | 67577 | u.ae.p1 = pOp->p1; |
| 67560 | 67578 | u.ae.p2 = pOp->p2; |
| 67561 | | - assert( u.ae.n>0 && u.ae.p1>0 && u.ae.p2>0 ); |
| 67579 | + assert( u.ae.n>=0 && u.ae.p1>0 && u.ae.p2>0 ); |
| 67562 | 67580 | assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 ); |
| 67563 | 67581 | |
| 67564 | 67582 | pIn1 = &aMem[u.ae.p1]; |
| 67565 | 67583 | pOut = &aMem[u.ae.p2]; |
| 67566 | | - while( u.ae.n-- ){ |
| 67584 | + do{ |
| 67567 | 67585 | assert( pOut<=&aMem[(p->nMem-p->nCursor)] ); |
| 67568 | 67586 | assert( pIn1<=&aMem[(p->nMem-p->nCursor)] ); |
| 67569 | 67587 | assert( memIsValid(pIn1) ); |
| 67570 | 67588 | memAboutToChange(p, pOut); |
| 67571 | 67589 | u.ae.zMalloc = pOut->zMalloc; |
| | @@ -67578,11 +67596,11 @@ |
| 67578 | 67596 | #endif |
| 67579 | 67597 | pIn1->zMalloc = u.ae.zMalloc; |
| 67580 | 67598 | REGISTER_TRACE(u.ae.p2++, pOut); |
| 67581 | 67599 | pIn1++; |
| 67582 | 67600 | pOut++; |
| 67583 | | - } |
| 67601 | + }while( u.ae.n-- ); |
| 67584 | 67602 | break; |
| 67585 | 67603 | } |
| 67586 | 67604 | |
| 67587 | 67605 | /* Opcode: Copy P1 P2 P3 * * |
| 67588 | 67606 | ** Synopsis: r[P2@P3]=r[P1@P3] |
| | @@ -67969,22 +67987,21 @@ |
| 67969 | 67987 | REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg); |
| 67970 | 67988 | } |
| 67971 | 67989 | |
| 67972 | 67990 | assert( pOp->p4type==P4_FUNCDEF ); |
| 67973 | 67991 | u.aj.ctx.pFunc = pOp->p4.pFunc; |
| 67974 | | - u.aj.ctx.s.flags = MEM_Null; |
| 67975 | | - u.aj.ctx.s.db = db; |
| 67976 | | - u.aj.ctx.s.xDel = 0; |
| 67977 | | - u.aj.ctx.s.zMalloc = 0; |
| 67978 | 67992 | u.aj.ctx.iOp = pc; |
| 67979 | 67993 | u.aj.ctx.pVdbe = p; |
| 67980 | 67994 | |
| 67981 | 67995 | /* The output cell may already have a buffer allocated. Move |
| 67982 | 67996 | ** the pointer to u.aj.ctx.s so in case the user-function can use |
| 67983 | 67997 | ** the already allocated buffer instead of allocating a new one. |
| 67984 | 67998 | */ |
| 67985 | | - sqlite3VdbeMemMove(&u.aj.ctx.s, pOut); |
| 67999 | + memcpy(&u.aj.ctx.s, pOut, sizeof(Mem)); |
| 68000 | + pOut->flags = MEM_Null; |
| 68001 | + pOut->xDel = 0; |
| 68002 | + pOut->zMalloc = 0; |
| 67986 | 68003 | MemSetTypeFlag(&u.aj.ctx.s, MEM_Null); |
| 67987 | 68004 | |
| 67988 | 68005 | u.aj.ctx.fErrorOrAux = 0; |
| 67989 | 68006 | if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 67990 | 68007 | assert( pOp>aOp ); |
| | @@ -68015,11 +68032,12 @@ |
| 68015 | 68032 | sqlite3VdbeDeleteAuxData(p, pc, pOp->p1); |
| 68016 | 68033 | } |
| 68017 | 68034 | |
| 68018 | 68035 | /* Copy the result of the function into register P3 */ |
| 68019 | 68036 | sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding); |
| 68020 | | - sqlite3VdbeMemMove(pOut, &u.aj.ctx.s); |
| 68037 | + assert( pOut->flags==MEM_Null ); |
| 68038 | + memcpy(pOut, &u.aj.ctx.s, sizeof(Mem)); |
| 68021 | 68039 | if( sqlite3VdbeMemTooBig(pOut) ){ |
| 68022 | 68040 | goto too_big; |
| 68023 | 68041 | } |
| 68024 | 68042 | |
| 68025 | 68043 | #if 0 |
| | @@ -68142,21 +68160,23 @@ |
| 68142 | 68160 | ** without data loss, then jump immediately to P2, or if P2==0 |
| 68143 | 68161 | ** raise an SQLITE_MISMATCH exception. |
| 68144 | 68162 | */ |
| 68145 | 68163 | case OP_MustBeInt: { /* jump, in1 */ |
| 68146 | 68164 | pIn1 = &aMem[pOp->p1]; |
| 68147 | | - applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding); |
| 68148 | 68165 | if( (pIn1->flags & MEM_Int)==0 ){ |
| 68149 | | - if( pOp->p2==0 ){ |
| 68150 | | - rc = SQLITE_MISMATCH; |
| 68151 | | - goto abort_due_to_error; |
| 68152 | | - }else{ |
| 68153 | | - pc = pOp->p2 - 1; |
| 68154 | | - } |
| 68155 | | - }else{ |
| 68156 | | - MemSetTypeFlag(pIn1, MEM_Int); |
| 68157 | | - } |
| 68166 | + applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding); |
| 68167 | + if( (pIn1->flags & MEM_Int)==0 ){ |
| 68168 | + if( pOp->p2==0 ){ |
| 68169 | + rc = SQLITE_MISMATCH; |
| 68170 | + goto abort_due_to_error; |
| 68171 | + }else{ |
| 68172 | + pc = pOp->p2 - 1; |
| 68173 | + break; |
| 68174 | + } |
| 68175 | + } |
| 68176 | + } |
| 68177 | + MemSetTypeFlag(pIn1, MEM_Int); |
| 68158 | 68178 | break; |
| 68159 | 68179 | } |
| 68160 | 68180 | |
| 68161 | 68181 | #ifndef SQLITE_OMIT_FLOATING_POINT |
| 68162 | 68182 | /* Opcode: RealAffinity P1 * * * * |
| | @@ -68740,156 +68760,108 @@ |
| 68740 | 68760 | ** or typeof() function, respectively. The loading of large blobs can be |
| 68741 | 68761 | ** skipped for length() and all content loading can be skipped for typeof(). |
| 68742 | 68762 | */ |
| 68743 | 68763 | case OP_Column: { |
| 68744 | 68764 | #if 0 /* local variables moved into u.ap */ |
| 68745 | | - u32 payloadSize; /* Number of bytes in the record */ |
| 68746 | 68765 | i64 payloadSize64; /* Number of bytes in the record */ |
| 68747 | | - int p1; /* P1 value of the opcode */ |
| 68748 | 68766 | int p2; /* column number to retrieve */ |
| 68749 | 68767 | VdbeCursor *pC; /* The VDBE cursor */ |
| 68750 | | - char *zRec; /* Pointer to complete record-data */ |
| 68751 | 68768 | BtCursor *pCrsr; /* The BTree cursor */ |
| 68752 | 68769 | u32 *aType; /* aType[i] holds the numeric type of the i-th column */ |
| 68753 | 68770 | u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */ |
| 68754 | | - int nField; /* number of fields in the record */ |
| 68755 | 68771 | int len; /* The length of the serialized data for the column */ |
| 68756 | 68772 | int i; /* Loop counter */ |
| 68757 | | - char *zData; /* Part of the record being decoded */ |
| 68758 | 68773 | Mem *pDest; /* Where to write the extracted value */ |
| 68759 | 68774 | Mem sMem; /* For storing the record being decoded */ |
| 68760 | | - u8 *zIdx; /* Index into header */ |
| 68761 | | - u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 68775 | + const u8 *zData; /* Part of the record being decoded */ |
| 68776 | + const u8 *zHdr; /* Next unparsed byte of the header */ |
| 68777 | + const u8 *zEndHdr; /* Pointer to first byte after the header */ |
| 68762 | 68778 | u32 offset; /* Offset into the data */ |
| 68763 | 68779 | u32 szField; /* Number of bytes in the content of a field */ |
| 68764 | | - int szHdr; /* Size of the header size field at start of record */ |
| 68765 | | - int avail; /* Number of bytes of available data */ |
| 68780 | + u32 avail; /* Number of bytes of available data */ |
| 68766 | 68781 | u32 t; /* A type code from the record header */ |
| 68767 | 68782 | Mem *pReg; /* PseudoTable input register */ |
| 68768 | 68783 | #endif /* local variables moved into u.ap */ |
| 68769 | 68784 | |
| 68770 | | - |
| 68771 | | - u.ap.p1 = pOp->p1; |
| 68772 | 68785 | u.ap.p2 = pOp->p2; |
| 68773 | | - u.ap.pC = 0; |
| 68774 | | - memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); |
| 68775 | | - assert( u.ap.p1<p->nCursor ); |
| 68776 | 68786 | assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) ); |
| 68777 | 68787 | u.ap.pDest = &aMem[pOp->p3]; |
| 68778 | 68788 | memAboutToChange(p, u.ap.pDest); |
| 68779 | | - u.ap.zRec = 0; |
| 68780 | | - |
| 68781 | | - /* This block sets the variable u.ap.payloadSize to be the total number of |
| 68782 | | - ** bytes in the record. |
| 68783 | | - ** |
| 68784 | | - ** u.ap.zRec is set to be the complete text of the record if it is available. |
| 68785 | | - ** The complete record text is always available for pseudo-tables |
| 68786 | | - ** If the record is stored in a cursor, the complete record text |
| 68787 | | - ** might be available in the u.ap.pC->aRow cache. Or it might not be. |
| 68788 | | - ** If the data is unavailable, u.ap.zRec is set to NULL. |
| 68789 | | - ** |
| 68790 | | - ** We also compute the number of columns in the record. For cursors, |
| 68791 | | - ** the number of columns is stored in the VdbeCursor.nField element. |
| 68792 | | - */ |
| 68793 | | - u.ap.pC = p->apCsr[u.ap.p1]; |
| 68789 | + assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 68790 | + u.ap.pC = p->apCsr[pOp->p1]; |
| 68794 | 68791 | assert( u.ap.pC!=0 ); |
| 68792 | + assert( u.ap.p2<u.ap.pC->nField ); |
| 68793 | + u.ap.aType = u.ap.pC->aType; |
| 68794 | + u.ap.aOffset = u.ap.aType + u.ap.pC->nField; |
| 68795 | 68795 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 68796 | | - assert( u.ap.pC->pVtabCursor==0 ); |
| 68796 | + assert( u.ap.pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */ |
| 68797 | 68797 | #endif |
| 68798 | 68798 | u.ap.pCrsr = u.ap.pC->pCursor; |
| 68799 | | - if( u.ap.pCrsr!=0 ){ |
| 68800 | | - /* The record is stored in a B-Tree */ |
| 68801 | | - rc = sqlite3VdbeCursorMoveto(u.ap.pC); |
| 68802 | | - if( rc ) goto abort_due_to_error; |
| 68799 | + assert( u.ap.pCrsr!=0 || u.ap.pC->pseudoTableReg>0 ); /* u.ap.pCrsr NULL on PseudoTables */ |
| 68800 | + assert( u.ap.pCrsr!=0 || u.ap.pC->nullRow ); /* u.ap.pC->nullRow on PseudoTables */ |
| 68801 | + |
| 68802 | + /* If the cursor cache is stale, bring it up-to-date */ |
| 68803 | + rc = sqlite3VdbeCursorMoveto(u.ap.pC); |
| 68804 | + if( rc ) goto abort_due_to_error; |
| 68805 | + if( u.ap.pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){ |
| 68803 | 68806 | if( u.ap.pC->nullRow ){ |
| 68804 | | - u.ap.payloadSize = 0; |
| 68805 | | - }else if( u.ap.pC->cacheStatus==p->cacheCtr ){ |
| 68806 | | - u.ap.payloadSize = u.ap.pC->payloadSize; |
| 68807 | | - u.ap.zRec = (char*)u.ap.pC->aRow; |
| 68808 | | - }else if( u.ap.pC->isIndex ){ |
| 68809 | | - assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); |
| 68810 | | - VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64); |
| 68811 | | - assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 68812 | | - /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the |
| 68813 | | - ** payload size, so it is impossible for u.ap.payloadSize64 to be |
| 68814 | | - ** larger than 32 bits. */ |
| 68815 | | - assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 ); |
| 68816 | | - u.ap.payloadSize = (u32)u.ap.payloadSize64; |
| 68817 | | - }else{ |
| 68818 | | - assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); |
| 68819 | | - VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.payloadSize); |
| 68820 | | - assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 68821 | | - } |
| 68822 | | - }else{ |
| 68823 | | - assert( u.ap.pC->pseudoTableReg>0 ); |
| 68824 | | - u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg]; |
| 68825 | | - if( u.ap.pC->multiPseudo ){ |
| 68826 | | - sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem); |
| 68827 | | - Deephemeralize(u.ap.pDest); |
| 68828 | | - goto op_column_out; |
| 68829 | | - } |
| 68830 | | - assert( u.ap.pReg->flags & MEM_Blob ); |
| 68831 | | - assert( memIsValid(u.ap.pReg) ); |
| 68832 | | - u.ap.payloadSize = u.ap.pReg->n; |
| 68833 | | - u.ap.zRec = u.ap.pReg->z; |
| 68834 | | - u.ap.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr; |
| 68835 | | - assert( u.ap.payloadSize==0 || u.ap.zRec!=0 ); |
| 68836 | | - } |
| 68837 | | - |
| 68838 | | - /* If u.ap.payloadSize is 0, then just store a NULL. This can happen because of |
| 68839 | | - ** nullRow or because of a corrupt database. */ |
| 68840 | | - if( u.ap.payloadSize==0 ){ |
| 68841 | | - MemSetTypeFlag(u.ap.pDest, MEM_Null); |
| 68842 | | - goto op_column_out; |
| 68843 | | - } |
| 68844 | | - assert( db->aLimit[SQLITE_LIMIT_LENGTH]>=0 ); |
| 68845 | | - if( u.ap.payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 68846 | | - goto too_big; |
| 68847 | | - } |
| 68848 | | - |
| 68849 | | - u.ap.nField = u.ap.pC->nField; |
| 68850 | | - assert( u.ap.p2<u.ap.nField ); |
| 68851 | | - |
| 68852 | | - /* Read and parse the table header. Store the results of the parse |
| 68853 | | - ** into the record header cache fields of the cursor. |
| 68854 | | - */ |
| 68855 | | - u.ap.aType = u.ap.pC->aType; |
| 68856 | | - if( u.ap.pC->cacheStatus==p->cacheCtr ){ |
| 68857 | | - u.ap.aOffset = u.ap.pC->aOffset; |
| 68858 | | - }else{ |
| 68859 | | - assert(u.ap.aType); |
| 68860 | | - u.ap.avail = 0; |
| 68861 | | - u.ap.pC->aOffset = u.ap.aOffset = &u.ap.aType[u.ap.nField]; |
| 68862 | | - u.ap.pC->payloadSize = u.ap.payloadSize; |
| 68807 | + if( u.ap.pCrsr==0 ){ |
| 68808 | + assert( u.ap.pC->pseudoTableReg>0 ); |
| 68809 | + u.ap.pReg = &aMem[u.ap.pC->pseudoTableReg]; |
| 68810 | + if( u.ap.pC->multiPseudo ){ |
| 68811 | + sqlite3VdbeMemShallowCopy(u.ap.pDest, u.ap.pReg+u.ap.p2, MEM_Ephem); |
| 68812 | + Deephemeralize(u.ap.pDest); |
| 68813 | + goto op_column_out; |
| 68814 | + } |
| 68815 | + assert( u.ap.pReg->flags & MEM_Blob ); |
| 68816 | + assert( memIsValid(u.ap.pReg) ); |
| 68817 | + u.ap.pC->payloadSize = u.ap.pC->szRow = u.ap.avail = u.ap.pReg->n; |
| 68818 | + u.ap.pC->aRow = (u8*)u.ap.pReg->z; |
| 68819 | + }else{ |
| 68820 | + MemSetTypeFlag(u.ap.pDest, MEM_Null); |
| 68821 | + goto op_column_out; |
| 68822 | + } |
| 68823 | + }else{ |
| 68824 | + assert( u.ap.pCrsr ); |
| 68825 | + if( u.ap.pC->isTable==0 ){ |
| 68826 | + assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); |
| 68827 | + VVA_ONLY(rc =) sqlite3BtreeKeySize(u.ap.pCrsr, &u.ap.payloadSize64); |
| 68828 | + assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 68829 | + /* sqlite3BtreeParseCellPtr() uses getVarint32() to extract the |
| 68830 | + ** payload size, so it is impossible for u.ap.payloadSize64 to be |
| 68831 | + ** larger than 32 bits. */ |
| 68832 | + assert( (u.ap.payloadSize64 & SQLITE_MAX_U32)==(u64)u.ap.payloadSize64 ); |
| 68833 | + u.ap.pC->aRow = sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail); |
| 68834 | + u.ap.pC->payloadSize = (u32)u.ap.payloadSize64; |
| 68835 | + }else{ |
| 68836 | + assert( sqlite3BtreeCursorIsValid(u.ap.pCrsr) ); |
| 68837 | + VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ap.pCrsr, &u.ap.pC->payloadSize); |
| 68838 | + assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 68839 | + u.ap.pC->aRow = sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail); |
| 68840 | + } |
| 68841 | + assert( u.ap.avail<=65536 ); /* Maximum page size is 64KiB */ |
| 68842 | + if( u.ap.pC->payloadSize <= (u32)u.ap.avail ){ |
| 68843 | + u.ap.pC->szRow = u.ap.pC->payloadSize; |
| 68844 | + }else{ |
| 68845 | + u.ap.pC->szRow = u.ap.avail; |
| 68846 | + } |
| 68847 | + if( u.ap.pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 68848 | + goto too_big; |
| 68849 | + } |
| 68850 | + } |
| 68863 | 68851 | u.ap.pC->cacheStatus = p->cacheCtr; |
| 68864 | | - |
| 68865 | | - /* Figure out how many bytes are in the header */ |
| 68866 | | - if( u.ap.zRec ){ |
| 68867 | | - u.ap.zData = u.ap.zRec; |
| 68868 | | - }else{ |
| 68869 | | - if( u.ap.pC->isIndex ){ |
| 68870 | | - u.ap.zData = (char*)sqlite3BtreeKeyFetch(u.ap.pCrsr, &u.ap.avail); |
| 68871 | | - }else{ |
| 68872 | | - u.ap.zData = (char*)sqlite3BtreeDataFetch(u.ap.pCrsr, &u.ap.avail); |
| 68873 | | - } |
| 68874 | | - /* If KeyFetch()/DataFetch() managed to get the entire payload, |
| 68875 | | - ** save the payload in the u.ap.pC->aRow cache. That will save us from |
| 68876 | | - ** having to make additional calls to fetch the content portion of |
| 68877 | | - ** the record. |
| 68878 | | - */ |
| 68879 | | - assert( u.ap.avail>=0 ); |
| 68880 | | - if( u.ap.payloadSize <= (u32)u.ap.avail ){ |
| 68881 | | - u.ap.zRec = u.ap.zData; |
| 68882 | | - u.ap.pC->aRow = (u8*)u.ap.zData; |
| 68883 | | - }else{ |
| 68884 | | - u.ap.pC->aRow = 0; |
| 68885 | | - } |
| 68886 | | - } |
| 68887 | | - /* The following assert is true in all cases except when |
| 68888 | | - ** the database file has been corrupted externally. |
| 68889 | | - ** assert( u.ap.zRec!=0 || u.ap.avail>=u.ap.payloadSize || u.ap.avail>=9 ); */ |
| 68890 | | - u.ap.szHdr = getVarint32((u8*)u.ap.zData, u.ap.offset); |
| 68852 | + u.ap.pC->iHdrOffset = getVarint32(u.ap.pC->aRow, u.ap.offset); |
| 68853 | + u.ap.pC->nHdrParsed = 0; |
| 68854 | + u.ap.aOffset[0] = u.ap.offset; |
| 68855 | + if( u.ap.avail<u.ap.offset ){ |
| 68856 | + /* u.ap.pC->aRow does not have to hold the entire row, but it does at least |
| 68857 | + ** need to cover the header of the record. If u.ap.pC->aRow does not contain |
| 68858 | + ** the complete header, then set it to zero, forcing the header to be |
| 68859 | + ** dynamically allocated. */ |
| 68860 | + u.ap.pC->aRow = 0; |
| 68861 | + u.ap.pC->szRow = 0; |
| 68862 | + } |
| 68891 | 68863 | |
| 68892 | 68864 | /* Make sure a corrupt database has not given us an oversize header. |
| 68893 | 68865 | ** Do this now to avoid an oversize memory allocation. |
| 68894 | 68866 | ** |
| 68895 | 68867 | ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte |
| | @@ -68896,159 +68868,152 @@ |
| 68896 | 68868 | ** types use so much data space that there can only be 4096 and 32 of |
| 68897 | 68869 | ** them, respectively. So the maximum header length results from a |
| 68898 | 68870 | ** 3-byte type for each of the maximum of 32768 columns plus three |
| 68899 | 68871 | ** extra bytes for the header length itself. 32768*3 + 3 = 98307. |
| 68900 | 68872 | */ |
| 68901 | | - if( u.ap.offset > 98307 ){ |
| 68873 | + if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){ |
| 68902 | 68874 | rc = SQLITE_CORRUPT_BKPT; |
| 68903 | | - goto op_column_out; |
| 68904 | | - } |
| 68905 | | - |
| 68906 | | - /* Compute in u.ap.len the number of bytes of data we need to read in order |
| 68907 | | - ** to get u.ap.nField type values. u.ap.offset is an upper bound on this. But |
| 68908 | | - ** u.ap.nField might be significantly less than the true number of columns |
| 68909 | | - ** in the table, and in that case, 5*u.ap.nField+3 might be smaller than u.ap.offset. |
| 68910 | | - ** We want to minimize u.ap.len in order to limit the size of the memory |
| 68911 | | - ** allocation, especially if a corrupt database file has caused u.ap.offset |
| 68912 | | - ** to be oversized. Offset is limited to 98307 above. But 98307 might |
| 68913 | | - ** still exceed Robson memory allocation limits on some configurations. |
| 68914 | | - ** On systems that cannot tolerate large memory allocations, u.ap.nField*5+3 |
| 68915 | | - ** will likely be much smaller since u.ap.nField will likely be less than |
| 68916 | | - ** 20 or so. This insures that Robson memory allocation limits are |
| 68917 | | - ** not exceeded even for corrupt database files. |
| 68918 | | - */ |
| 68919 | | - u.ap.len = u.ap.nField*5 + 3; |
| 68920 | | - if( u.ap.len > (int)u.ap.offset ) u.ap.len = (int)u.ap.offset; |
| 68921 | | - |
| 68922 | | - /* The KeyFetch() or DataFetch() above are fast and will get the entire |
| 68923 | | - ** record header in most cases. But they will fail to get the complete |
| 68924 | | - ** record header if the record header does not fit on a single page |
| 68925 | | - ** in the B-Tree. When that happens, use sqlite3VdbeMemFromBtree() to |
| 68926 | | - ** acquire the complete header text. |
| 68927 | | - */ |
| 68928 | | - if( !u.ap.zRec && u.ap.avail<u.ap.len ){ |
| 68929 | | - u.ap.sMem.flags = 0; |
| 68930 | | - u.ap.sMem.db = 0; |
| 68931 | | - rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.len, u.ap.pC->isIndex, &u.ap.sMem); |
| 68932 | | - if( rc!=SQLITE_OK ){ |
| 68933 | | - goto op_column_out; |
| 68934 | | - } |
| 68935 | | - u.ap.zData = u.ap.sMem.z; |
| 68936 | | - } |
| 68937 | | - u.ap.zEndHdr = (u8 *)&u.ap.zData[u.ap.len]; |
| 68938 | | - u.ap.zIdx = (u8 *)&u.ap.zData[u.ap.szHdr]; |
| 68939 | | - |
| 68940 | | - /* Scan the header and use it to fill in the u.ap.aType[] and u.ap.aOffset[] |
| 68941 | | - ** arrays. u.ap.aType[u.ap.i] will contain the type integer for the u.ap.i-th |
| 68942 | | - ** column and u.ap.aOffset[u.ap.i] will contain the u.ap.offset from the beginning |
| 68943 | | - ** of the record to the start of the data for the u.ap.i-th column |
| 68944 | | - */ |
| 68945 | | - for(u.ap.i=0; u.ap.i<u.ap.nField; u.ap.i++){ |
| 68946 | | - if( u.ap.zIdx<u.ap.zEndHdr ){ |
| 68947 | | - u.ap.aOffset[u.ap.i] = u.ap.offset; |
| 68948 | | - if( u.ap.zIdx[0]<0x80 ){ |
| 68949 | | - u.ap.t = u.ap.zIdx[0]; |
| 68950 | | - u.ap.zIdx++; |
| 68875 | + goto op_column_error; |
| 68876 | + } |
| 68877 | + } |
| 68878 | + |
| 68879 | + /* Make sure at least the first u.ap.p2+1 entries of the header have been |
| 68880 | + ** parsed and valid information is in u.ap.aOffset[] and u.ap.aType[]. |
| 68881 | + */ |
| 68882 | + if( u.ap.pC->nHdrParsed<=u.ap.p2 ){ |
| 68883 | + /* If there is more header available for parsing in the record, try |
| 68884 | + ** to extract additional fields up through the u.ap.p2+1-th field |
| 68885 | + */ |
| 68886 | + if( u.ap.pC->iHdrOffset<u.ap.aOffset[0] ){ |
| 68887 | + /* Make sure u.ap.zData points to enough of the record to cover the header. */ |
| 68888 | + if( u.ap.pC->aRow==0 ){ |
| 68889 | + memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); |
| 68890 | + rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, 0, u.ap.aOffset[0], |
| 68891 | + !u.ap.pC->isTable, &u.ap.sMem); |
| 68892 | + if( rc!=SQLITE_OK ){ |
| 68893 | + goto op_column_error; |
| 68894 | + } |
| 68895 | + u.ap.zData = (u8*)u.ap.sMem.z; |
| 68896 | + }else{ |
| 68897 | + u.ap.zData = u.ap.pC->aRow; |
| 68898 | + } |
| 68899 | + |
| 68900 | + /* Fill in u.ap.aType[u.ap.i] and u.ap.aOffset[u.ap.i] values through the u.ap.p2-th field. */ |
| 68901 | + u.ap.i = u.ap.pC->nHdrParsed; |
| 68902 | + u.ap.offset = u.ap.aOffset[u.ap.i]; |
| 68903 | + u.ap.zHdr = u.ap.zData + u.ap.pC->iHdrOffset; |
| 68904 | + u.ap.zEndHdr = u.ap.zData + u.ap.aOffset[0]; |
| 68905 | + assert( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr ); |
| 68906 | + do{ |
| 68907 | + if( u.ap.zHdr[0]<0x80 ){ |
| 68908 | + u.ap.t = u.ap.zHdr[0]; |
| 68909 | + u.ap.zHdr++; |
| 68951 | 68910 | }else{ |
| 68952 | | - u.ap.zIdx += sqlite3GetVarint32(u.ap.zIdx, &u.ap.t); |
| 68911 | + u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t); |
| 68953 | 68912 | } |
| 68954 | 68913 | u.ap.aType[u.ap.i] = u.ap.t; |
| 68955 | 68914 | u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t); |
| 68956 | 68915 | u.ap.offset += u.ap.szField; |
| 68957 | 68916 | if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */ |
| 68958 | | - u.ap.zIdx = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 68959 | | - break; |
| 68960 | | - } |
| 68961 | | - }else{ |
| 68962 | | - /* If u.ap.i is less that u.ap.nField, then there are fewer fields in this |
| 68963 | | - ** record than SetNumColumns indicated there are columns in the |
| 68964 | | - ** table. Set the u.ap.offset for any extra columns not present in |
| 68965 | | - ** the record to 0. This tells code below to store the default value |
| 68966 | | - ** for the column instead of deserializing a value from the record. |
| 68967 | | - */ |
| 68968 | | - u.ap.aOffset[u.ap.i] = 0; |
| 68969 | | - } |
| 68970 | | - } |
| 68971 | | - sqlite3VdbeMemRelease(&u.ap.sMem); |
| 68972 | | - u.ap.sMem.flags = MEM_Null; |
| 68973 | | - |
| 68974 | | - /* If we have read more header data than was contained in the header, |
| 68975 | | - ** or if the end of the last field appears to be past the end of the |
| 68976 | | - ** record, or if the end of the last field appears to be before the end |
| 68977 | | - ** of the record (when all fields present), then we must be dealing |
| 68978 | | - ** with a corrupt database. |
| 68979 | | - */ |
| 68980 | | - if( (u.ap.zIdx > u.ap.zEndHdr) || (u.ap.offset > u.ap.payloadSize) |
| 68981 | | - || (u.ap.zIdx==u.ap.zEndHdr && u.ap.offset!=u.ap.payloadSize) ){ |
| 68982 | | - rc = SQLITE_CORRUPT_BKPT; |
| 68983 | | - goto op_column_out; |
| 68984 | | - } |
| 68985 | | - } |
| 68986 | | - |
| 68987 | | - /* Get the column information. If u.ap.aOffset[u.ap.p2] is non-zero, then |
| 68988 | | - ** deserialize the value from the record. If u.ap.aOffset[u.ap.p2] is zero, |
| 68989 | | - ** then there are not enough fields in the record to satisfy the |
| 68990 | | - ** request. In this case, set the value NULL or to P4 if P4 is |
| 68991 | | - ** a pointer to a Mem object. |
| 68992 | | - */ |
| 68993 | | - if( u.ap.aOffset[u.ap.p2] ){ |
| 68994 | | - assert( rc==SQLITE_OK ); |
| 68995 | | - if( u.ap.zRec ){ |
| 68996 | | - /* This is the common case where the whole row fits on a single page */ |
| 68997 | | - VdbeMemRelease(u.ap.pDest); |
| 68998 | | - sqlite3VdbeSerialGet((u8 *)&u.ap.zRec[u.ap.aOffset[u.ap.p2]], u.ap.aType[u.ap.p2], u.ap.pDest); |
| 68999 | | - }else{ |
| 69000 | | - /* This branch happens only when the row overflows onto multiple pages */ |
| 69001 | | - u.ap.t = u.ap.aType[u.ap.p2]; |
| 69002 | | - if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 69003 | | - && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0) |
| 69004 | | - ){ |
| 69005 | | - /* Content is irrelevant for the typeof() function and for |
| 69006 | | - ** the length(X) function if X is a blob. So we might as well use |
| 69007 | | - ** bogus content rather than reading content from disk. NULL works |
| 69008 | | - ** for text and blob and whatever is in the u.ap.payloadSize64 variable |
| 69009 | | - ** will work for everything else. */ |
| 69010 | | - u.ap.zData = u.ap.t<12 ? (char*)&u.ap.payloadSize64 : 0; |
| 69011 | | - }else{ |
| 69012 | | - u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t); |
| 69013 | | - sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest); |
| 69014 | | - rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, u.ap.pC->isIndex, |
| 69015 | | - &u.ap.sMem); |
| 69016 | | - if( rc!=SQLITE_OK ){ |
| 69017 | | - goto op_column_out; |
| 69018 | | - } |
| 69019 | | - u.ap.zData = u.ap.sMem.z; |
| 69020 | | - } |
| 69021 | | - sqlite3VdbeSerialGet((u8*)u.ap.zData, u.ap.t, u.ap.pDest); |
| 69022 | | - } |
| 69023 | | - u.ap.pDest->enc = encoding; |
| 69024 | | - }else{ |
| 69025 | | - if( pOp->p4type==P4_MEM ){ |
| 69026 | | - sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static); |
| 69027 | | - }else{ |
| 69028 | | - MemSetTypeFlag(u.ap.pDest, MEM_Null); |
| 69029 | | - } |
| 69030 | | - } |
| 69031 | | - |
| 69032 | | - /* If we dynamically allocated space to hold the data (in the |
| 69033 | | - ** sqlite3VdbeMemFromBtree() call above) then transfer control of that |
| 69034 | | - ** dynamically allocated space over to the u.ap.pDest structure. |
| 69035 | | - ** This prevents a memory copy. |
| 69036 | | - */ |
| 69037 | | - if( u.ap.sMem.zMalloc ){ |
| 69038 | | - assert( u.ap.sMem.z==u.ap.sMem.zMalloc ); |
| 69039 | | - assert( !(u.ap.pDest->flags & MEM_Dyn) ); |
| 69040 | | - assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z ); |
| 69041 | | - u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static); |
| 69042 | | - u.ap.pDest->flags |= MEM_Term; |
| 69043 | | - u.ap.pDest->z = u.ap.sMem.z; |
| 69044 | | - u.ap.pDest->zMalloc = u.ap.sMem.zMalloc; |
| 69045 | | - } |
| 69046 | | - |
| 69047 | | - rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest); |
| 69048 | | - |
| 69049 | | -op_column_out: |
| 68917 | + u.ap.zHdr = &u.ap.zEndHdr[1]; /* Forces SQLITE_CORRUPT return below */ |
| 68918 | + break; |
| 68919 | + } |
| 68920 | + u.ap.i++; |
| 68921 | + u.ap.aOffset[u.ap.i] = u.ap.offset; |
| 68922 | + }while( u.ap.i<=u.ap.p2 && u.ap.zHdr<u.ap.zEndHdr ); |
| 68923 | + u.ap.pC->nHdrParsed = u.ap.i; |
| 68924 | + u.ap.pC->iHdrOffset = (u32)(u.ap.zHdr - u.ap.zData); |
| 68925 | + if( u.ap.pC->aRow==0 ){ |
| 68926 | + sqlite3VdbeMemRelease(&u.ap.sMem); |
| 68927 | + u.ap.sMem.flags = MEM_Null; |
| 68928 | + } |
| 68929 | + |
| 68930 | + /* If we have read more header data than was contained in the header, |
| 68931 | + ** or if the end of the last field appears to be past the end of the |
| 68932 | + ** record, or if the end of the last field appears to be before the end |
| 68933 | + ** of the record (when all fields present), then we must be dealing |
| 68934 | + ** with a corrupt database. |
| 68935 | + */ |
| 68936 | + if( (u.ap.zHdr > u.ap.zEndHdr) |
| 68937 | + || (u.ap.offset > u.ap.pC->payloadSize) |
| 68938 | + || (u.ap.zHdr==u.ap.zEndHdr && u.ap.offset!=u.ap.pC->payloadSize) |
| 68939 | + ){ |
| 68940 | + rc = SQLITE_CORRUPT_BKPT; |
| 68941 | + goto op_column_error; |
| 68942 | + } |
| 68943 | + } |
| 68944 | + |
| 68945 | + /* If after trying to extra new entries from the header, nHdrParsed is |
| 68946 | + ** still not up to u.ap.p2, that means that the record has fewer than u.ap.p2 |
| 68947 | + ** columns. So the result will be either the default value or a NULL. |
| 68948 | + */ |
| 68949 | + if( u.ap.pC->nHdrParsed<=u.ap.p2 ){ |
| 68950 | + if( pOp->p4type==P4_MEM ){ |
| 68951 | + sqlite3VdbeMemShallowCopy(u.ap.pDest, pOp->p4.pMem, MEM_Static); |
| 68952 | + }else{ |
| 68953 | + MemSetTypeFlag(u.ap.pDest, MEM_Null); |
| 68954 | + } |
| 68955 | + goto op_column_out; |
| 68956 | + } |
| 68957 | + } |
| 68958 | + |
| 68959 | + /* Extract the content for the u.ap.p2+1-th column. Control can only |
| 68960 | + ** reach this point if u.ap.aOffset[u.ap.p2], u.ap.aOffset[u.ap.p2+1], and u.ap.aType[u.ap.p2] are |
| 68961 | + ** all valid. |
| 68962 | + */ |
| 68963 | + assert( u.ap.p2<u.ap.pC->nHdrParsed ); |
| 68964 | + assert( rc==SQLITE_OK ); |
| 68965 | + if( u.ap.pC->szRow>=u.ap.aOffset[u.ap.p2+1] ){ |
| 68966 | + /* This is the common case where the desired content fits on the original |
| 68967 | + ** page - where the content is not on an overflow page */ |
| 68968 | + VdbeMemRelease(u.ap.pDest); |
| 68969 | + sqlite3VdbeSerialGet(u.ap.pC->aRow+u.ap.aOffset[u.ap.p2], u.ap.aType[u.ap.p2], u.ap.pDest); |
| 68970 | + }else{ |
| 68971 | + /* This branch happens only when content is on overflow pages */ |
| 68972 | + u.ap.t = u.ap.aType[u.ap.p2]; |
| 68973 | + if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0 |
| 68974 | + && ((u.ap.t>=12 && (u.ap.t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)) |
| 68975 | + || (u.ap.len = sqlite3VdbeSerialTypeLen(u.ap.t))==0 |
| 68976 | + ){ |
| 68977 | + /* Content is irrelevant for the typeof() function and for |
| 68978 | + ** the length(X) function if X is a blob. So we might as well use |
| 68979 | + ** bogus content rather than reading content from disk. NULL works |
| 68980 | + ** for text and blob and whatever is in the u.ap.payloadSize64 variable |
| 68981 | + ** will work for everything else. Content is also irrelevant if |
| 68982 | + ** the content length is 0. */ |
| 68983 | + u.ap.zData = u.ap.t<=13 ? (u8*)&u.ap.payloadSize64 : 0; |
| 68984 | + u.ap.sMem.zMalloc = 0; |
| 68985 | + }else{ |
| 68986 | + memset(&u.ap.sMem, 0, sizeof(u.ap.sMem)); |
| 68987 | + sqlite3VdbeMemMove(&u.ap.sMem, u.ap.pDest); |
| 68988 | + rc = sqlite3VdbeMemFromBtree(u.ap.pCrsr, u.ap.aOffset[u.ap.p2], u.ap.len, !u.ap.pC->isTable, |
| 68989 | + &u.ap.sMem); |
| 68990 | + if( rc!=SQLITE_OK ){ |
| 68991 | + goto op_column_error; |
| 68992 | + } |
| 68993 | + u.ap.zData = (u8*)u.ap.sMem.z; |
| 68994 | + } |
| 68995 | + sqlite3VdbeSerialGet(u.ap.zData, u.ap.t, u.ap.pDest); |
| 68996 | + /* If we dynamically allocated space to hold the data (in the |
| 68997 | + ** sqlite3VdbeMemFromBtree() call above) then transfer control of that |
| 68998 | + ** dynamically allocated space over to the u.ap.pDest structure. |
| 68999 | + ** This prevents a memory copy. */ |
| 69000 | + if( u.ap.sMem.zMalloc ){ |
| 69001 | + assert( u.ap.sMem.z==u.ap.sMem.zMalloc ); |
| 69002 | + assert( !(u.ap.pDest->flags & MEM_Dyn) ); |
| 69003 | + assert( !(u.ap.pDest->flags & (MEM_Blob|MEM_Str)) || u.ap.pDest->z==u.ap.sMem.z ); |
| 69004 | + u.ap.pDest->flags &= ~(MEM_Ephem|MEM_Static); |
| 69005 | + u.ap.pDest->flags |= MEM_Term; |
| 69006 | + u.ap.pDest->z = u.ap.sMem.z; |
| 69007 | + u.ap.pDest->zMalloc = u.ap.sMem.zMalloc; |
| 69008 | + } |
| 69009 | + } |
| 69010 | + u.ap.pDest->enc = encoding; |
| 69011 | + |
| 69012 | +op_column_out: |
| 69013 | + rc = sqlite3VdbeMemMakeWriteable(u.ap.pDest); |
| 69014 | +op_column_error: |
| 69050 | 69015 | UPDATE_MAX_BLOBSIZE(u.ap.pDest); |
| 69051 | 69016 | REGISTER_TRACE(pOp->p3, u.ap.pDest); |
| 69052 | 69017 | break; |
| 69053 | 69018 | } |
| 69054 | 69019 | |
| | @@ -69820,10 +69785,12 @@ |
| 69820 | 69785 | u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField; |
| 69821 | 69786 | }else if( pOp->p4type==P4_INT32 ){ |
| 69822 | 69787 | u.az.nField = pOp->p4.i; |
| 69823 | 69788 | } |
| 69824 | 69789 | assert( pOp->p1>=0 ); |
| 69790 | + assert( u.az.nField>=0 ); |
| 69791 | + testcase( u.az.nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */ |
| 69825 | 69792 | u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1); |
| 69826 | 69793 | if( u.az.pCur==0 ) goto no_mem; |
| 69827 | 69794 | u.az.pCur->nullRow = 1; |
| 69828 | 69795 | u.az.pCur->isOrdered = 1; |
| 69829 | 69796 | rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor); |
| | @@ -69833,16 +69800,15 @@ |
| 69833 | 69800 | |
| 69834 | 69801 | /* Since it performs no memory allocation or IO, the only value that |
| 69835 | 69802 | ** sqlite3BtreeCursor() may return is SQLITE_OK. */ |
| 69836 | 69803 | assert( rc==SQLITE_OK ); |
| 69837 | 69804 | |
| 69838 | | - /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of |
| 69805 | + /* Set the VdbeCursor.isTable variable. Previous versions of |
| 69839 | 69806 | ** SQLite used to check if the root-page flags were sane at this point |
| 69840 | 69807 | ** and report database corruption if they were not, but this check has |
| 69841 | 69808 | ** since moved into the btree layer. */ |
| 69842 | 69809 | u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO; |
| 69843 | | - u.az.pCur->isIndex = !u.az.pCur->isTable; |
| 69844 | 69810 | break; |
| 69845 | 69811 | } |
| 69846 | 69812 | |
| 69847 | 69813 | /* Opcode: OpenEphemeral P1 P2 * P4 P5 |
| 69848 | 69814 | ** Synopsis: nColumn=P2 |
| | @@ -69882,10 +69848,11 @@ |
| 69882 | 69848 | SQLITE_OPEN_CREATE | |
| 69883 | 69849 | SQLITE_OPEN_EXCLUSIVE | |
| 69884 | 69850 | SQLITE_OPEN_DELETEONCLOSE | |
| 69885 | 69851 | SQLITE_OPEN_TRANSIENT_DB; |
| 69886 | 69852 | assert( pOp->p1>=0 ); |
| 69853 | + assert( pOp->p2>=0 ); |
| 69887 | 69854 | u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69888 | 69855 | if( u.ba.pCx==0 ) goto no_mem; |
| 69889 | 69856 | u.ba.pCx->nullRow = 1; |
| 69890 | 69857 | rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt, |
| 69891 | 69858 | BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags); |
| | @@ -69914,11 +69881,10 @@ |
| 69914 | 69881 | rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor); |
| 69915 | 69882 | u.ba.pCx->isTable = 1; |
| 69916 | 69883 | } |
| 69917 | 69884 | } |
| 69918 | 69885 | u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED); |
| 69919 | | - u.ba.pCx->isIndex = !u.ba.pCx->isTable; |
| 69920 | 69886 | break; |
| 69921 | 69887 | } |
| 69922 | 69888 | |
| 69923 | 69889 | /* Opcode: SorterOpen P1 * * P4 * |
| 69924 | 69890 | ** |
| | @@ -69929,16 +69895,17 @@ |
| 69929 | 69895 | case OP_SorterOpen: { |
| 69930 | 69896 | #if 0 /* local variables moved into u.bb */ |
| 69931 | 69897 | VdbeCursor *pCx; |
| 69932 | 69898 | #endif /* local variables moved into u.bb */ |
| 69933 | 69899 | |
| 69900 | + assert( pOp->p1>=0 ); |
| 69901 | + assert( pOp->p2>=0 ); |
| 69934 | 69902 | u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1); |
| 69935 | 69903 | if( u.bb.pCx==0 ) goto no_mem; |
| 69936 | 69904 | u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo; |
| 69937 | 69905 | assert( u.bb.pCx->pKeyInfo->db==db ); |
| 69938 | 69906 | assert( u.bb.pCx->pKeyInfo->enc==ENC(db) ); |
| 69939 | | - u.bb.pCx->isSorter = 1; |
| 69940 | 69907 | rc = sqlite3VdbeSorterInit(db, u.bb.pCx); |
| 69941 | 69908 | break; |
| 69942 | 69909 | } |
| 69943 | 69910 | |
| 69944 | 69911 | /* Opcode: OpenPseudo P1 P2 P3 * P5 |
| | @@ -69962,16 +69929,16 @@ |
| 69962 | 69929 | #if 0 /* local variables moved into u.bc */ |
| 69963 | 69930 | VdbeCursor *pCx; |
| 69964 | 69931 | #endif /* local variables moved into u.bc */ |
| 69965 | 69932 | |
| 69966 | 69933 | assert( pOp->p1>=0 ); |
| 69934 | + assert( pOp->p3>=0 ); |
| 69967 | 69935 | u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); |
| 69968 | 69936 | if( u.bc.pCx==0 ) goto no_mem; |
| 69969 | 69937 | u.bc.pCx->nullRow = 1; |
| 69970 | 69938 | u.bc.pCx->pseudoTableReg = pOp->p2; |
| 69971 | 69939 | u.bc.pCx->isTable = 1; |
| 69972 | | - u.bc.pCx->isIndex = 0; |
| 69973 | 69940 | u.bc.pCx->multiPseudo = pOp->p5; |
| 69974 | 69941 | break; |
| 69975 | 69942 | } |
| 69976 | 69943 | |
| 69977 | 69944 | /* Opcode: Close P1 * * * * |
| | @@ -70801,11 +70768,11 @@ |
| 70801 | 70768 | VdbeCursor *pC; |
| 70802 | 70769 | #endif /* local variables moved into u.bl */ |
| 70803 | 70770 | |
| 70804 | 70771 | pOut = &aMem[pOp->p2]; |
| 70805 | 70772 | u.bl.pC = p->apCsr[pOp->p1]; |
| 70806 | | - assert( u.bl.pC->isSorter ); |
| 70773 | + assert( isSorter(u.bl.pC) ); |
| 70807 | 70774 | rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut); |
| 70808 | 70775 | break; |
| 70809 | 70776 | } |
| 70810 | 70777 | |
| 70811 | 70778 | /* Opcode: RowData P1 P2 * * * |
| | @@ -70843,13 +70810,13 @@ |
| 70843 | 70810 | memAboutToChange(p, pOut); |
| 70844 | 70811 | |
| 70845 | 70812 | /* Note that RowKey and RowData are really exactly the same instruction */ |
| 70846 | 70813 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70847 | 70814 | u.bm.pC = p->apCsr[pOp->p1]; |
| 70848 | | - assert( u.bm.pC->isSorter==0 ); |
| 70815 | + assert( isSorter(u.bm.pC)==0 ); |
| 70849 | 70816 | assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData ); |
| 70850 | | - assert( u.bm.pC->isIndex || pOp->opcode==OP_RowData ); |
| 70817 | + assert( u.bm.pC->isTable==0 || pOp->opcode==OP_RowData ); |
| 70851 | 70818 | assert( u.bm.pC!=0 ); |
| 70852 | 70819 | assert( u.bm.pC->nullRow==0 ); |
| 70853 | 70820 | assert( u.bm.pC->pseudoTableReg==0 ); |
| 70854 | 70821 | assert( u.bm.pC->pCursor!=0 ); |
| 70855 | 70822 | u.bm.pCrsr = u.bm.pC->pCursor; |
| | @@ -70862,11 +70829,11 @@ |
| 70862 | 70829 | */ |
| 70863 | 70830 | assert( u.bm.pC->deferredMoveto==0 ); |
| 70864 | 70831 | rc = sqlite3VdbeCursorMoveto(u.bm.pC); |
| 70865 | 70832 | if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error; |
| 70866 | 70833 | |
| 70867 | | - if( u.bm.pC->isIndex ){ |
| 70834 | + if( u.bm.pC->isTable==0 ){ |
| 70868 | 70835 | assert( !u.bm.pC->isTable ); |
| 70869 | 70836 | VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64); |
| 70870 | 70837 | assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */ |
| 70871 | 70838 | if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){ |
| 70872 | 70839 | goto too_big; |
| | @@ -70882,11 +70849,11 @@ |
| 70882 | 70849 | if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){ |
| 70883 | 70850 | goto no_mem; |
| 70884 | 70851 | } |
| 70885 | 70852 | pOut->n = u.bm.n; |
| 70886 | 70853 | MemSetTypeFlag(pOut, MEM_Blob); |
| 70887 | | - if( u.bm.pC->isIndex ){ |
| 70854 | + if( u.bm.pC->isTable==0 ){ |
| 70888 | 70855 | rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z); |
| 70889 | 70856 | }else{ |
| 70890 | 70857 | rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z); |
| 70891 | 70858 | } |
| 70892 | 70859 | pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */ |
| | @@ -70959,10 +70926,11 @@ |
| 70959 | 70926 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 70960 | 70927 | u.bo.pC = p->apCsr[pOp->p1]; |
| 70961 | 70928 | assert( u.bo.pC!=0 ); |
| 70962 | 70929 | u.bo.pC->nullRow = 1; |
| 70963 | 70930 | u.bo.pC->rowidIsValid = 0; |
| 70931 | + u.bo.pC->cacheStatus = CACHE_STALE; |
| 70964 | 70932 | assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor ); |
| 70965 | 70933 | if( u.bo.pC->pCursor ){ |
| 70966 | 70934 | sqlite3BtreeClearCursor(u.bo.pC->pCursor); |
| 70967 | 70935 | } |
| 70968 | 70936 | break; |
| | @@ -71038,19 +71006,18 @@ |
| 71038 | 71006 | #endif /* local variables moved into u.bq */ |
| 71039 | 71007 | |
| 71040 | 71008 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71041 | 71009 | u.bq.pC = p->apCsr[pOp->p1]; |
| 71042 | 71010 | assert( u.bq.pC!=0 ); |
| 71043 | | - assert( u.bq.pC->isSorter==(pOp->opcode==OP_SorterSort) ); |
| 71011 | + assert( isSorter(u.bq.pC)==(pOp->opcode==OP_SorterSort) ); |
| 71044 | 71012 | u.bq.res = 1; |
| 71045 | 71013 | if( isSorter(u.bq.pC) ){ |
| 71046 | 71014 | rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res); |
| 71047 | 71015 | }else{ |
| 71048 | 71016 | u.bq.pCrsr = u.bq.pC->pCursor; |
| 71049 | 71017 | assert( u.bq.pCrsr ); |
| 71050 | 71018 | rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res); |
| 71051 | | - u.bq.pC->atFirst = u.bq.res==0 ?1:0; |
| 71052 | 71019 | u.bq.pC->deferredMoveto = 0; |
| 71053 | 71020 | u.bq.pC->cacheStatus = CACHE_STALE; |
| 71054 | 71021 | u.bq.pC->rowidIsValid = 0; |
| 71055 | 71022 | } |
| 71056 | 71023 | u.bq.pC->nullRow = (u8)u.bq.res; |
| | @@ -71066,69 +71033,85 @@ |
| 71066 | 71033 | ** Advance cursor P1 so that it points to the next key/data pair in its |
| 71067 | 71034 | ** table or index. If there are no more key/value pairs then fall through |
| 71068 | 71035 | ** to the following instruction. But if the cursor advance was successful, |
| 71069 | 71036 | ** jump immediately to P2. |
| 71070 | 71037 | ** |
| 71071 | | -** The P1 cursor must be for a real table, not a pseudo-table. |
| 71038 | +** The P1 cursor must be for a real table, not a pseudo-table. P1 must have |
| 71039 | +** been opened prior to this opcode or the program will segfault. |
| 71072 | 71040 | ** |
| 71073 | 71041 | ** P4 is always of type P4_ADVANCE. The function pointer points to |
| 71074 | 71042 | ** sqlite3BtreeNext(). |
| 71075 | 71043 | ** |
| 71076 | 71044 | ** If P5 is positive and the jump is taken, then event counter |
| 71077 | 71045 | ** number P5-1 in the prepared statement is incremented. |
| 71078 | 71046 | ** |
| 71079 | | -** See also: Prev |
| 71047 | +** See also: Prev, NextIfOpen |
| 71048 | +*/ |
| 71049 | +/* Opcode: NextIfOpen P1 P2 * * P5 |
| 71050 | +** |
| 71051 | +** This opcode works just like OP_Next except that if cursor P1 is not |
| 71052 | +** open it behaves a no-op. |
| 71080 | 71053 | */ |
| 71081 | 71054 | /* Opcode: Prev P1 P2 * * P5 |
| 71082 | 71055 | ** |
| 71083 | 71056 | ** Back up cursor P1 so that it points to the previous key/data pair in its |
| 71084 | 71057 | ** table or index. If there is no previous key/value pairs then fall through |
| 71085 | 71058 | ** to the following instruction. But if the cursor backup was successful, |
| 71086 | 71059 | ** jump immediately to P2. |
| 71087 | 71060 | ** |
| 71088 | | -** The P1 cursor must be for a real table, not a pseudo-table. |
| 71061 | +** The P1 cursor must be for a real table, not a pseudo-table. If P1 is |
| 71062 | +** not open then the behavior is undefined. |
| 71089 | 71063 | ** |
| 71090 | 71064 | ** P4 is always of type P4_ADVANCE. The function pointer points to |
| 71091 | 71065 | ** sqlite3BtreePrevious(). |
| 71092 | 71066 | ** |
| 71093 | 71067 | ** If P5 is positive and the jump is taken, then event counter |
| 71094 | 71068 | ** number P5-1 in the prepared statement is incremented. |
| 71095 | 71069 | */ |
| 71096 | | -case OP_SorterNext: /* jump */ |
| 71097 | | -case OP_Prev: /* jump */ |
| 71098 | | -case OP_Next: { /* jump */ |
| 71070 | +/* Opcode: PrevIfOpen P1 P2 * * P5 |
| 71071 | +** |
| 71072 | +** This opcode works just like OP_Prev except that if cursor P1 is not |
| 71073 | +** open it behaves a no-op. |
| 71074 | +*/ |
| 71075 | +case OP_SorterNext: { /* jump */ |
| 71099 | 71076 | #if 0 /* local variables moved into u.br */ |
| 71100 | 71077 | VdbeCursor *pC; |
| 71101 | 71078 | int res; |
| 71102 | 71079 | #endif /* local variables moved into u.br */ |
| 71103 | 71080 | |
| 71081 | + u.br.pC = p->apCsr[pOp->p1]; |
| 71082 | + assert( isSorter(u.br.pC) ); |
| 71083 | + rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res); |
| 71084 | + goto next_tail; |
| 71085 | +case OP_PrevIfOpen: /* jump */ |
| 71086 | +case OP_NextIfOpen: /* jump */ |
| 71087 | + if( p->apCsr[pOp->p1]==0 ) break; |
| 71088 | + /* Fall through */ |
| 71089 | +case OP_Prev: /* jump */ |
| 71090 | +case OP_Next: /* jump */ |
| 71104 | 71091 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71105 | 71092 | assert( pOp->p5<ArraySize(p->aCounter) ); |
| 71106 | 71093 | u.br.pC = p->apCsr[pOp->p1]; |
| 71107 | | - if( u.br.pC==0 ){ |
| 71108 | | - break; /* See ticket #2273 */ |
| 71109 | | - } |
| 71110 | | - assert( u.br.pC->isSorter==(pOp->opcode==OP_SorterNext) ); |
| 71111 | | - if( isSorter(u.br.pC) ){ |
| 71112 | | - assert( pOp->opcode==OP_SorterNext ); |
| 71113 | | - rc = sqlite3VdbeSorterNext(db, u.br.pC, &u.br.res); |
| 71114 | | - }else{ |
| 71115 | | - /* u.br.res = 1; // Always initialized by the xAdvance() call */ |
| 71116 | | - assert( u.br.pC->deferredMoveto==0 ); |
| 71117 | | - assert( u.br.pC->pCursor ); |
| 71118 | | - assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 71119 | | - assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 71120 | | - rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res); |
| 71121 | | - } |
| 71122 | | - u.br.pC->nullRow = (u8)u.br.res; |
| 71094 | + assert( u.br.pC!=0 ); |
| 71095 | + assert( u.br.pC->deferredMoveto==0 ); |
| 71096 | + assert( u.br.pC->pCursor ); |
| 71097 | + assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 71098 | + assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious ); |
| 71099 | + assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext ); |
| 71100 | + assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious); |
| 71101 | + rc = pOp->p4.xAdvance(u.br.pC->pCursor, &u.br.res); |
| 71102 | +next_tail: |
| 71123 | 71103 | u.br.pC->cacheStatus = CACHE_STALE; |
| 71124 | 71104 | if( u.br.res==0 ){ |
| 71105 | + u.br.pC->nullRow = 0; |
| 71125 | 71106 | pc = pOp->p2 - 1; |
| 71126 | 71107 | p->aCounter[pOp->p5]++; |
| 71127 | 71108 | #ifdef SQLITE_TEST |
| 71128 | 71109 | sqlite3_search_count++; |
| 71129 | 71110 | #endif |
| 71111 | + }else{ |
| 71112 | + u.br.pC->nullRow = 1; |
| 71130 | 71113 | } |
| 71131 | 71114 | u.br.pC->rowidIsValid = 0; |
| 71132 | 71115 | goto check_for_interrupt; |
| 71133 | 71116 | } |
| 71134 | 71117 | |
| | @@ -71155,11 +71138,11 @@ |
| 71155 | 71138 | #endif /* local variables moved into u.bs */ |
| 71156 | 71139 | |
| 71157 | 71140 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 71158 | 71141 | u.bs.pC = p->apCsr[pOp->p1]; |
| 71159 | 71142 | assert( u.bs.pC!=0 ); |
| 71160 | | - assert( u.bs.pC->isSorter==(pOp->opcode==OP_SorterInsert) ); |
| 71143 | + assert( isSorter(u.bs.pC)==(pOp->opcode==OP_SorterInsert) ); |
| 71161 | 71144 | pIn2 = &aMem[pOp->p2]; |
| 71162 | 71145 | assert( pIn2->flags & MEM_Blob ); |
| 71163 | 71146 | u.bs.pCrsr = u.bs.pC->pCursor; |
| 71164 | 71147 | if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++; |
| 71165 | 71148 | assert( u.bs.pCrsr!=0 ); |
| | @@ -72446,11 +72429,10 @@ |
| 72446 | 72429 | |
| 72447 | 72430 | /* Initialize vdbe cursor object */ |
| 72448 | 72431 | u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0); |
| 72449 | 72432 | if( u.cm.pCur ){ |
| 72450 | 72433 | u.cm.pCur->pVtabCursor = u.cm.pVtabCursor; |
| 72451 | | - u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule; |
| 72452 | 72434 | }else{ |
| 72453 | 72435 | db->mallocFailed = 1; |
| 72454 | 72436 | u.cm.pModule->xClose(u.cm.pVtabCursor); |
| 72455 | 72437 | } |
| 72456 | 72438 | } |
| | @@ -73017,22 +72999,23 @@ |
| 73017 | 72999 | assert( v->aVar[0].flags&MEM_Int ); |
| 73018 | 73000 | v->aVar[0].u.i = iRow; |
| 73019 | 73001 | |
| 73020 | 73002 | rc = sqlite3_step(p->pStmt); |
| 73021 | 73003 | if( rc==SQLITE_ROW ){ |
| 73022 | | - u32 type = v->apCsr[0]->aType[p->iCol]; |
| 73004 | + VdbeCursor *pC = v->apCsr[0]; |
| 73005 | + u32 type = pC->aType[p->iCol]; |
| 73023 | 73006 | if( type<12 ){ |
| 73024 | 73007 | zErr = sqlite3MPrintf(p->db, "cannot open value of type %s", |
| 73025 | 73008 | type==0?"null": type==7?"real": "integer" |
| 73026 | 73009 | ); |
| 73027 | 73010 | rc = SQLITE_ERROR; |
| 73028 | 73011 | sqlite3_finalize(p->pStmt); |
| 73029 | 73012 | p->pStmt = 0; |
| 73030 | 73013 | }else{ |
| 73031 | | - p->iOffset = v->apCsr[0]->aOffset[p->iCol]; |
| 73014 | + p->iOffset = pC->aType[p->iCol + pC->nField]; |
| 73032 | 73015 | p->nByte = sqlite3VdbeSerialTypeLen(type); |
| 73033 | | - p->pCsr = v->apCsr[0]->pCursor; |
| 73016 | + p->pCsr = pC->pCursor; |
| 73034 | 73017 | sqlite3BtreeEnterCursor(p->pCsr); |
| 73035 | 73018 | sqlite3BtreeCacheOverflow(p->pCsr); |
| 73036 | 73019 | sqlite3BtreeLeaveCursor(p->pCsr); |
| 73037 | 73020 | } |
| 73038 | 73021 | } |
| | @@ -75806,11 +75789,10 @@ |
| 75806 | 75789 | return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr); |
| 75807 | 75790 | } |
| 75808 | 75791 | |
| 75809 | 75792 | /* Resolve function names |
| 75810 | 75793 | */ |
| 75811 | | - case TK_CONST_FUNC: |
| 75812 | 75794 | case TK_FUNCTION: { |
| 75813 | 75795 | ExprList *pList = pExpr->x.pList; /* The argument list */ |
| 75814 | 75796 | int n = pList ? pList->nExpr : 0; /* Number of arguments */ |
| 75815 | 75797 | int no_such_func = 0; /* True if no such function exists */ |
| 75816 | 75798 | int wrong_num_args = 0; /* True if wrong number of arguments */ |
| | @@ -75819,11 +75801,10 @@ |
| 75819 | 75801 | int nId; /* Number of characters in function name */ |
| 75820 | 75802 | const char *zId; /* The function name. */ |
| 75821 | 75803 | FuncDef *pDef; /* Information about the function */ |
| 75822 | 75804 | u8 enc = ENC(pParse->db); /* The database encoding */ |
| 75823 | 75805 | |
| 75824 | | - testcase( pExpr->op==TK_CONST_FUNC ); |
| 75825 | 75806 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 75826 | 75807 | notValidPartIdxWhere(pParse, pNC, "functions"); |
| 75827 | 75808 | zId = pExpr->u.zToken; |
| 75828 | 75809 | nId = sqlite3Strlen30(zId); |
| 75829 | 75810 | pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0); |
| | @@ -75864,10 +75845,11 @@ |
| 75864 | 75845 | pNC->nErr++; |
| 75865 | 75846 | } |
| 75866 | 75847 | pExpr->op = TK_NULL; |
| 75867 | 75848 | return WRC_Prune; |
| 75868 | 75849 | } |
| 75850 | + if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant); |
| 75869 | 75851 | } |
| 75870 | 75852 | #endif |
| 75871 | 75853 | if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){ |
| 75872 | 75854 | sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId); |
| 75873 | 75855 | pNC->nErr++; |
| | @@ -77781,13 +77763,16 @@ |
| 77781 | 77763 | return WRC_Abort; |
| 77782 | 77764 | } |
| 77783 | 77765 | |
| 77784 | 77766 | switch( pExpr->op ){ |
| 77785 | 77767 | /* Consider functions to be constant if all their arguments are constant |
| 77786 | | - ** and pWalker->u.i==2 */ |
| 77768 | + ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST |
| 77769 | + ** flag. */ |
| 77787 | 77770 | case TK_FUNCTION: |
| 77788 | | - if( pWalker->u.i==2 ) return 0; |
| 77771 | + if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){ |
| 77772 | + return WRC_Continue; |
| 77773 | + } |
| 77789 | 77774 | /* Fall through */ |
| 77790 | 77775 | case TK_ID: |
| 77791 | 77776 | case TK_COLUMN: |
| 77792 | 77777 | case TK_AGG_FUNCTION: |
| 77793 | 77778 | case TK_AGG_COLUMN: |
| | @@ -79213,11 +79198,10 @@ |
| 79213 | 79198 | }else{ |
| 79214 | 79199 | inReg = pInfo->aFunc[pExpr->iAgg].iMem; |
| 79215 | 79200 | } |
| 79216 | 79201 | break; |
| 79217 | 79202 | } |
| 79218 | | - case TK_CONST_FUNC: |
| 79219 | 79203 | case TK_FUNCTION: { |
| 79220 | 79204 | ExprList *pFarg; /* List of function arguments */ |
| 79221 | 79205 | int nFarg; /* Number of function arguments */ |
| 79222 | 79206 | FuncDef *pDef; /* The function definition object */ |
| 79223 | 79207 | int nId; /* Length of the function name in bytes */ |
| | @@ -79226,12 +79210,10 @@ |
| 79226 | 79210 | int i; /* Loop counter */ |
| 79227 | 79211 | u8 enc = ENC(db); /* The text encoding used by this database */ |
| 79228 | 79212 | CollSeq *pColl = 0; /* A collating sequence */ |
| 79229 | 79213 | |
| 79230 | 79214 | assert( !ExprHasProperty(pExpr, EP_xIsSelect) ); |
| 79231 | | - testcase( op==TK_CONST_FUNC ); |
| 79232 | | - testcase( op==TK_FUNCTION ); |
| 79233 | 79215 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 79234 | 79216 | pFarg = 0; |
| 79235 | 79217 | }else{ |
| 79236 | 79218 | pFarg = pExpr->x.pList; |
| 79237 | 79219 | } |
| | @@ -79271,12 +79253,25 @@ |
| 79271 | 79253 | assert( nFarg>=1 ); |
| 79272 | 79254 | sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target); |
| 79273 | 79255 | break; |
| 79274 | 79256 | } |
| 79275 | 79257 | |
| 79258 | + for(i=0; i<nFarg; i++){ |
| 79259 | + if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){ |
| 79260 | + constMask |= (1<<i); |
| 79261 | + } |
| 79262 | + if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){ |
| 79263 | + pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr); |
| 79264 | + } |
| 79265 | + } |
| 79276 | 79266 | if( pFarg ){ |
| 79277 | | - r1 = sqlite3GetTempRange(pParse, nFarg); |
| 79267 | + if( constMask ){ |
| 79268 | + r1 = pParse->nMem+1; |
| 79269 | + pParse->nMem += nFarg; |
| 79270 | + }else{ |
| 79271 | + r1 = sqlite3GetTempRange(pParse, nFarg); |
| 79272 | + } |
| 79278 | 79273 | |
| 79279 | 79274 | /* For length() and typeof() functions with a column argument, |
| 79280 | 79275 | ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG |
| 79281 | 79276 | ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data |
| 79282 | 79277 | ** loading. |
| | @@ -79287,18 +79282,19 @@ |
| 79287 | 79282 | assert( pFarg->a[0].pExpr!=0 ); |
| 79288 | 79283 | exprOp = pFarg->a[0].pExpr->op; |
| 79289 | 79284 | if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){ |
| 79290 | 79285 | assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG ); |
| 79291 | 79286 | assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG ); |
| 79292 | | - testcase( (pDef->funcFlags&~SQLITE_FUNC_ENCMASK) |
| 79293 | | - ==SQLITE_FUNC_LENGTH ); |
| 79294 | | - pFarg->a[0].pExpr->op2 = pDef->funcFlags&~SQLITE_FUNC_ENCMASK; |
| 79287 | + testcase( pDef->funcFlags & OPFLAG_LENGTHARG ); |
| 79288 | + pFarg->a[0].pExpr->op2 = |
| 79289 | + pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG); |
| 79295 | 79290 | } |
| 79296 | 79291 | } |
| 79297 | 79292 | |
| 79298 | 79293 | sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */ |
| 79299 | | - sqlite3ExprCodeExprList(pParse, pFarg, r1, 1); |
| 79294 | + sqlite3ExprCodeExprList(pParse, pFarg, r1, |
| 79295 | + SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR); |
| 79300 | 79296 | sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */ |
| 79301 | 79297 | }else{ |
| 79302 | 79298 | r1 = 0; |
| 79303 | 79299 | } |
| 79304 | 79300 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| | @@ -79318,26 +79314,18 @@ |
| 79318 | 79314 | pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr); |
| 79319 | 79315 | }else if( nFarg>0 ){ |
| 79320 | 79316 | pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr); |
| 79321 | 79317 | } |
| 79322 | 79318 | #endif |
| 79323 | | - for(i=0; i<nFarg; i++){ |
| 79324 | | - if( i<32 && sqlite3ExprIsConstant(pFarg->a[i].pExpr) ){ |
| 79325 | | - constMask |= (1<<i); |
| 79326 | | - } |
| 79327 | | - if( (pDef->funcFlags & SQLITE_FUNC_NEEDCOLL)!=0 && !pColl ){ |
| 79328 | | - pColl = sqlite3ExprCollSeq(pParse, pFarg->a[i].pExpr); |
| 79329 | | - } |
| 79330 | | - } |
| 79331 | 79319 | if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){ |
| 79332 | 79320 | if( !pColl ) pColl = db->pDfltColl; |
| 79333 | 79321 | sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ); |
| 79334 | 79322 | } |
| 79335 | 79323 | sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target, |
| 79336 | 79324 | (char*)pDef, P4_FUNCDEF); |
| 79337 | 79325 | sqlite3VdbeChangeP5(v, (u8)nFarg); |
| 79338 | | - if( nFarg ){ |
| 79326 | + if( nFarg && constMask==0 ){ |
| 79339 | 79327 | sqlite3ReleaseTempRange(pParse, r1, nFarg); |
| 79340 | 79328 | } |
| 79341 | 79329 | break; |
| 79342 | 79330 | } |
| 79343 | 79331 | #ifndef SQLITE_OMIT_SUBQUERY |
| | @@ -79569,10 +79557,32 @@ |
| 79569 | 79557 | } |
| 79570 | 79558 | sqlite3ReleaseTempReg(pParse, regFree1); |
| 79571 | 79559 | sqlite3ReleaseTempReg(pParse, regFree2); |
| 79572 | 79560 | return inReg; |
| 79573 | 79561 | } |
| 79562 | + |
| 79563 | +/* |
| 79564 | +** Factor out the code of the given expression to initialization time. |
| 79565 | +*/ |
| 79566 | +SQLITE_PRIVATE void sqlite3ExprCodeAtInit( |
| 79567 | + Parse *pParse, /* Parsing context */ |
| 79568 | + Expr *pExpr, /* The expression to code when the VDBE initializes */ |
| 79569 | + int regDest, /* Store the value in this register */ |
| 79570 | + u8 reusable /* True if this expression is reusable */ |
| 79571 | +){ |
| 79572 | + ExprList *p; |
| 79573 | + assert( ConstFactorOk(pParse) ); |
| 79574 | + p = pParse->pConstExpr; |
| 79575 | + pExpr = sqlite3ExprDup(pParse->db, pExpr, 0); |
| 79576 | + p = sqlite3ExprListAppend(pParse, p, pExpr); |
| 79577 | + if( p ){ |
| 79578 | + struct ExprList_item *pItem = &p->a[p->nExpr-1]; |
| 79579 | + pItem->u.iConstExprReg = regDest; |
| 79580 | + pItem->reusable = reusable; |
| 79581 | + } |
| 79582 | + pParse->pConstExpr = p; |
| 79583 | +} |
| 79574 | 79584 | |
| 79575 | 79585 | /* |
| 79576 | 79586 | ** Generate code to evaluate an expression and store the results |
| 79577 | 79587 | ** into a register. Return the register number where the results |
| 79578 | 79588 | ** are stored. |
| | @@ -79586,28 +79596,27 @@ |
| 79586 | 79596 | ** VDBE program, in order to factor it out of the evaluation loop. |
| 79587 | 79597 | */ |
| 79588 | 79598 | SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){ |
| 79589 | 79599 | int r2; |
| 79590 | 79600 | pExpr = sqlite3ExprSkipCollate(pExpr); |
| 79591 | | - if( pParse->cookieGoto>0 |
| 79601 | + if( ConstFactorOk(pParse) |
| 79592 | 79602 | && pExpr->op!=TK_REGISTER |
| 79593 | 79603 | && sqlite3ExprIsConstantNotJoin(pExpr) |
| 79594 | 79604 | ){ |
| 79595 | 79605 | ExprList *p = pParse->pConstExpr; |
| 79596 | 79606 | int i; |
| 79597 | 79607 | *pReg = 0; |
| 79598 | 79608 | if( p ){ |
| 79599 | | - for(i=0; i<p->nExpr; i++){ |
| 79600 | | - if( sqlite3ExprCompare(p->a[i].pExpr, pExpr, -1)==0 ){ |
| 79601 | | - return p->a[i].u.iConstExprReg; |
| 79609 | + struct ExprList_item *pItem; |
| 79610 | + for(pItem=p->a, i=p->nExpr; i>0; pItem++, i--){ |
| 79611 | + if( pItem->reusable && sqlite3ExprCompare(pItem->pExpr,pExpr,-1)==0 ){ |
| 79612 | + return pItem->u.iConstExprReg; |
| 79602 | 79613 | } |
| 79603 | 79614 | } |
| 79604 | 79615 | } |
| 79605 | | - p = sqlite3ExprListAppend(pParse, p, sqlite3ExprDup(pParse->db, pExpr, 0)); |
| 79606 | | - pParse->pConstExpr = p; |
| 79607 | 79616 | r2 = ++pParse->nMem; |
| 79608 | | - if( p ) p->a[p->nExpr-1].u.iConstExprReg = r2; |
| 79617 | + sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1); |
| 79609 | 79618 | }else{ |
| 79610 | 79619 | int r1 = sqlite3GetTempReg(pParse); |
| 79611 | 79620 | r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1); |
| 79612 | 79621 | if( r2==r1 ){ |
| 79613 | 79622 | *pReg = r1; |
| | @@ -79793,11 +79802,10 @@ |
| 79793 | 79802 | sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken); |
| 79794 | 79803 | break; |
| 79795 | 79804 | } |
| 79796 | 79805 | |
| 79797 | 79806 | case TK_AGG_FUNCTION: |
| 79798 | | - case TK_CONST_FUNC: |
| 79799 | 79807 | case TK_FUNCTION: { |
| 79800 | 79808 | ExprList *pFarg; /* List of function arguments */ |
| 79801 | 79809 | if( ExprHasProperty(pExpr, EP_TokenOnly) ){ |
| 79802 | 79810 | pFarg = 0; |
| 79803 | 79811 | }else{ |
| | @@ -79949,29 +79957,40 @@ |
| 79949 | 79957 | /* |
| 79950 | 79958 | ** Generate code that pushes the value of every element of the given |
| 79951 | 79959 | ** expression list into a sequence of registers beginning at target. |
| 79952 | 79960 | ** |
| 79953 | 79961 | ** Return the number of elements evaluated. |
| 79962 | +** |
| 79963 | +** The SQLITE_ECEL_DUP flag prevents the arguments from being |
| 79964 | +** filled using OP_SCopy. OP_Copy must be used instead. |
| 79965 | +** |
| 79966 | +** The SQLITE_ECEL_FACTOR argument allows constant arguments to be |
| 79967 | +** factored out into initialization code. |
| 79954 | 79968 | */ |
| 79955 | 79969 | SQLITE_PRIVATE int sqlite3ExprCodeExprList( |
| 79956 | 79970 | Parse *pParse, /* Parsing context */ |
| 79957 | 79971 | ExprList *pList, /* The expression list to be coded */ |
| 79958 | 79972 | int target, /* Where to write results */ |
| 79959 | | - int doHardCopy /* Make a hard copy of every element */ |
| 79973 | + u8 flags /* SQLITE_ECEL_* flags */ |
| 79960 | 79974 | ){ |
| 79961 | 79975 | struct ExprList_item *pItem; |
| 79962 | 79976 | int i, n; |
| 79977 | + u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy; |
| 79963 | 79978 | assert( pList!=0 ); |
| 79964 | 79979 | assert( target>0 ); |
| 79965 | 79980 | assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */ |
| 79966 | 79981 | n = pList->nExpr; |
| 79982 | + if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR; |
| 79967 | 79983 | for(pItem=pList->a, i=0; i<n; i++, pItem++){ |
| 79968 | 79984 | Expr *pExpr = pItem->pExpr; |
| 79969 | | - int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 79970 | | - if( inReg!=target+i ){ |
| 79971 | | - sqlite3VdbeAddOp2(pParse->pVdbe, doHardCopy ? OP_Copy : OP_SCopy, |
| 79972 | | - inReg, target+i); |
| 79985 | + if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){ |
| 79986 | + sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0); |
| 79987 | + }else{ |
| 79988 | + int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i); |
| 79989 | + if( inReg!=target+i ){ |
| 79990 | + sqlite3VdbeAddOp2(pParse->pVdbe, copyOp, inReg, target+i); |
| 79991 | + } |
| 79973 | 79992 | } |
| 79974 | 79993 | } |
| 79975 | 79994 | return n; |
| 79976 | 79995 | } |
| 79977 | 79996 | |
| | @@ -91338,24 +91357,24 @@ |
| 91338 | 91357 | FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), |
| 91339 | 91358 | FUNCTION(hex, 1, 0, 0, hexFunc ), |
| 91340 | 91359 | FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE), |
| 91341 | 91360 | FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 91342 | 91361 | FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY), |
| 91343 | | - FUNCTION(random, 0, 0, 0, randomFunc ), |
| 91344 | | - FUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 91362 | + VFUNCTION(random, 0, 0, 0, randomFunc ), |
| 91363 | + VFUNCTION(randomblob, 1, 0, 0, randomBlob ), |
| 91345 | 91364 | FUNCTION(nullif, 2, 0, 1, nullifFunc ), |
| 91346 | 91365 | FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), |
| 91347 | 91366 | FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), |
| 91348 | 91367 | FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), |
| 91349 | 91368 | #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS |
| 91350 | 91369 | FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), |
| 91351 | 91370 | FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), |
| 91352 | 91371 | #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */ |
| 91353 | 91372 | FUNCTION(quote, 1, 0, 0, quoteFunc ), |
| 91354 | | - FUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid), |
| 91355 | | - FUNCTION(changes, 0, 0, 0, changes ), |
| 91356 | | - FUNCTION(total_changes, 0, 0, 0, total_changes ), |
| 91373 | + VFUNCTION(last_insert_rowid, 0, 0, 0, last_insert_rowid), |
| 91374 | + VFUNCTION(changes, 0, 0, 0, changes ), |
| 91375 | + VFUNCTION(total_changes, 0, 0, 0, total_changes ), |
| 91357 | 91376 | FUNCTION(replace, 3, 0, 0, replaceFunc ), |
| 91358 | 91377 | FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ), |
| 91359 | 91378 | #ifdef SQLITE_SOUNDEX |
| 91360 | 91379 | FUNCTION(soundex, 1, 0, 0, soundexFunc ), |
| 91361 | 91380 | #endif |
| | @@ -100003,11 +100022,12 @@ |
| 100003 | 100022 | }else if( eDest!=SRT_Exists ){ |
| 100004 | 100023 | /* If the destination is an EXISTS(...) expression, the actual |
| 100005 | 100024 | ** values returned by the SELECT are not required. |
| 100006 | 100025 | */ |
| 100007 | 100026 | sqlite3ExprCacheClear(pParse); |
| 100008 | | - sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Output); |
| 100027 | + sqlite3ExprCodeExprList(pParse, pEList, regResult, |
| 100028 | + (eDest==SRT_Output)?SQLITE_ECEL_DUP:0); |
| 100009 | 100029 | } |
| 100010 | 100030 | nColumn = nResultCol; |
| 100011 | 100031 | |
| 100012 | 100032 | /* If the DISTINCT keyword was present on the SELECT statement |
| 100013 | 100033 | ** and this row has been seen before, then do not make this row |
| | @@ -103289,11 +103309,11 @@ |
| 103289 | 103309 | ExprList *pList = pF->pExpr->x.pList; |
| 103290 | 103310 | assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) ); |
| 103291 | 103311 | if( pList ){ |
| 103292 | 103312 | nArg = pList->nExpr; |
| 103293 | 103313 | regAgg = sqlite3GetTempRange(pParse, nArg); |
| 103294 | | - sqlite3ExprCodeExprList(pParse, pList, regAgg, 1); |
| 103314 | + sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP); |
| 103295 | 103315 | }else{ |
| 103296 | 103316 | nArg = 0; |
| 103297 | 103317 | regAgg = 0; |
| 103298 | 103318 | } |
| 103299 | 103319 | if( pF->iDistinct>=0 ){ |
| | @@ -110765,11 +110785,11 @@ |
| 110765 | 110785 | if( eType==IN_INDEX_ROWID ){ |
| 110766 | 110786 | pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg); |
| 110767 | 110787 | }else{ |
| 110768 | 110788 | pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg); |
| 110769 | 110789 | } |
| 110770 | | - pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next; |
| 110790 | + pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen; |
| 110771 | 110791 | sqlite3VdbeAddOp1(v, OP_IsNull, iReg); |
| 110772 | 110792 | }else{ |
| 110773 | 110793 | pLevel->u.in.nIn = 0; |
| 110774 | 110794 | } |
| 110775 | 110795 | #endif |
| | @@ -117027,16 +117047,11 @@ |
| 117027 | 117047 | spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); |
| 117028 | 117048 | } |
| 117029 | 117049 | break; |
| 117030 | 117050 | case 200: /* term ::= CTIME_KW */ |
| 117031 | 117051 | { |
| 117032 | | - /* The CURRENT_TIME, CURRENT_DATE, and CURRENT_TIMESTAMP values are |
| 117033 | | - ** treated as functions that return constants */ |
| 117034 | | - yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0,&yymsp[0].minor.yy0); |
| 117035 | | - if( yygotominor.yy118.pExpr ){ |
| 117036 | | - yygotominor.yy118.pExpr->op = TK_CONST_FUNC; |
| 117037 | | - } |
| 117052 | + yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0); |
| 117038 | 117053 | spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0); |
| 117039 | 117054 | } |
| 117040 | 117055 | break; |
| 117041 | 117056 | case 201: /* expr ::= expr AND expr */ |
| 117042 | 117057 | case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202); |
| 117043 | 117058 | |