Fossil SCM

Update to the lastest SQLite that includes the OP_Column rewrite and the constant expression factoring logic.

drh 2013-11-21 23:39 trunk
Commit 8dc9d0093581f5ac34b3d9652f7d1e7b2c829008
3 files changed +1 -1 +695 -680 +1 -1
+1 -1
--- src/shell.c
+++ src/shell.c
@@ -1305,11 +1305,11 @@
13051305
}
13061306
}
13071307
13081308
/* If the shell is currently in ".explain" mode, gather the extra
13091309
** data required to add indents to the output.*/
1310
- if( pArg->mode==MODE_Explain ){
1310
+ if( pArg && pArg->mode==MODE_Explain ){
13111311
explain_data_prepare(pArg, pStmt);
13121312
}
13131313
13141314
/* perform the first step. this will tell us if we
13151315
** have a result set or not and how wide it is.
13161316
--- src/shell.c
+++ src/shell.c
@@ -1305,11 +1305,11 @@
1305 }
1306 }
1307
1308 /* If the shell is currently in ".explain" mode, gather the extra
1309 ** data required to add indents to the output.*/
1310 if( pArg->mode==MODE_Explain ){
1311 explain_data_prepare(pArg, pStmt);
1312 }
1313
1314 /* perform the first step. this will tell us if we
1315 ** have a result set or not and how wide it is.
1316
--- src/shell.c
+++ src/shell.c
@@ -1305,11 +1305,11 @@
1305 }
1306 }
1307
1308 /* If the shell is currently in ".explain" mode, gather the extra
1309 ** data required to add indents to the output.*/
1310 if( pArg && pArg->mode==MODE_Explain ){
1311 explain_data_prepare(pArg, pStmt);
1312 }
1313
1314 /* perform the first step. this will tell us if we
1315 ** have a result set or not and how wide it is.
1316
+695 -680
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138138
#define SQLITE_VERSION "3.8.2"
139139
#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"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -8140,13 +8140,12 @@
81408140
#define TK_UNCLOSED_STRING 151
81418141
#define TK_FUNCTION 152
81428142
#define TK_COLUMN 153
81438143
#define TK_AGG_FUNCTION 154
81448144
#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
81488147
81498148
/************** End of parse.h ***********************************************/
81508149
/************** Continuing where we left off in sqliteInt.h ******************/
81518150
#include <stdio.h>
81528151
#include <stdlib.h>
@@ -8778,12 +8777,12 @@
87788777
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
87798778
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
87808779
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
87818780
SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
87828781
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);
87858784
SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
87868785
SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
87878786
SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
87888787
SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
87898788
@@ -9021,87 +9020,87 @@
90219020
#define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */
90229021
#define OP_Savepoint 2
90239022
#define OP_AutoCommit 3
90249023
#define OP_Transaction 4
90259024
#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
90399038
#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] */
90899088
#define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
90909089
#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
90949093
#define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
90959094
#define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
90969095
#define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
90979096
#define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
90989097
#define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
90999098
#define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
91009099
#define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
91019100
#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 */
91039102
#define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
91049103
#define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
91059104
#define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
91069105
#define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
91079106
#define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9108,68 +9107,70 @@
91089107
#define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
91099108
#define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
91109109
#define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
91119110
#define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
91129111
#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 */
91149113
#define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
91159114
#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 */
91519150
#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
91629161
#define OP_ToText 142 /* same as TK_TO_TEXT */
91639162
#define OP_ToBlob 143 /* same as TK_TO_BLOB */
91649163
#define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */
91659164
#define OP_ToInt 145 /* same as TK_TO_INT */
91669165
#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
91719172
91729173
91739174
/* Properties such as "out2" or "jump" that are specified in
91749175
** comments following the "case" for each opcode in the vdbe.c
91759176
** are encoded into bitvectors as follows:
@@ -9181,28 +9182,29 @@
91819182
#define OPFLG_IN3 0x0010 /* in3: P3 is an input */
91829183
#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
91839184
#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
91849185
#define OPFLG_INITIALIZER {\
91859186
/* 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,\
91949195
/* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
91959196
/* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
91969197
/* 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,}
92049206
92059207
/************** End of opcodes.h *********************************************/
92069208
/************** Continuing where we left off in vdbe.h ***********************/
92079209
92089210
/*
@@ -10336,10 +10338,17 @@
1033610338
#else
1033710339
#define OptimizationDisabled(db, mask) 0
1033810340
#define OptimizationEnabled(db, mask) 1
1033910341
#endif
1034010342
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
+
1034110350
/*
1034210351
** Possible values for the sqlite.magic field.
1034310352
** The numbers are obtained at random and have no special meaning, other
1034410353
** than being distinct from one another.
1034510354
*/
@@ -10402,10 +10411,11 @@
1040210411
#define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
1040310412
#define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
1040410413
#define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
1040510414
#define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
1040610415
#define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
10416
+#define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
1040710417
1040810418
/*
1040910419
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1041010420
** used to create the initializers for the FuncDef structures.
1041110421
**
@@ -10414,10 +10424,13 @@
1041410424
** implemented by C function xFunc that accepts nArg arguments. The
1041510425
** value passed as iArg is cast to a (void*) and made available
1041610426
** as the user-data (sqlite3_user_data()) for the function. If
1041710427
** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
1041810428
**
10429
+** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
10430
+** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
10431
+**
1041910432
** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
1042010433
** Used to create an aggregate function definition implemented by
1042110434
** the C functions xStep and xFinal. The first four parameters
1042210435
** are interpreted in the same way as the first 4 parameters to
1042310436
** FUNCTION().
@@ -10429,20 +10442,24 @@
1042910442
** available as the function user-data (sqlite3_user_data()). The
1043010443
** FuncDef.flags variable is set to the value passed as the flags
1043110444
** parameter.
1043210445
*/
1043310446
#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) \
1043410450
{nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
1043510451
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1043610452
#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,\
1043810454
SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
1043910455
#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), \
1044110457
pArg, 0, xFunc, 0, 0, #zName, 0, 0}
1044210458
#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}
1044410461
#define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
1044510462
{nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
1044610463
SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
1044710464
1044810465
/*
@@ -11098,10 +11115,11 @@
1109811115
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
1109911116
#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
1110011117
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
1110111118
#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
1110211119
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11120
+#define EP_Constant 0x080000 /* Node is a constant */
1110311121
1110411122
/*
1110511123
** These macros can be used to test, set, or clear bits in the
1110611124
** Expr.flags field.
1110711125
*/
@@ -11159,10 +11177,11 @@
1115911177
char *zName; /* Token associated with this expression */
1116011178
char *zSpan; /* Original text of the expression */
1116111179
u8 sortOrder; /* 1 for DESC or 0 for ASC */
1116211180
unsigned done :1; /* A flag to indicate when processing is finished */
1116311181
unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11182
+ unsigned reusable :1; /* Constant expression is reusable */
1116411183
union {
1116511184
struct {
1116611185
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1116711186
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1116811187
} x;
@@ -12153,14 +12172,17 @@
1215312172
SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
1215412173
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
1215512174
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
1215612175
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
1215712176
SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
12177
+SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
1215812178
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1215912179
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
1216012180
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 */
1216212184
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
1216312185
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
1216412186
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
1216512187
SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
1216612188
SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
@@ -13386,11 +13408,11 @@
1338613408
typedef struct VdbeOp Op;
1338713409
1338813410
/*
1338913411
** Boolean values
1339013412
*/
13391
-typedef unsigned char Bool;
13413
+typedef unsigned Bool;
1339213414
1339313415
/* Opaque type used by code in vdbesort.c */
1339413416
typedef struct VdbeSorter VdbeSorter;
1339513417
1339613418
/* Opaque type used by the explainer */
@@ -13403,42 +13425,39 @@
1340313425
** A cursor is a pointer into a single BTree within a database file.
1340413426
** The cursor can seek to a BTree entry with a particular key, or
1340513427
** loop over all entries of the Btree. You can also insert new BTree
1340613428
** entries or retrieve the key or data from the entry that the cursor
1340713429
** 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.
1340813433
**
1340913434
** Every cursor that the virtual machine has open is represented by an
1341013435
** instance of the following structure.
1341113436
*/
1341213437
struct VdbeCursor {
1341313438
BtCursor *pCursor; /* The cursor structure of the backend */
1341413439
Btree *pBt; /* Separate file holding temporary table */
1341513440
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() */
1341713442
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 */
1343013453
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13431
- const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
1343213454
i64 seqCount; /* Sequence counter */
1343313455
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 */
1343513457
VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
1343613458
13437
- /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists */
13438
- int seekResult;
13439
-
1344013459
/* Cached information about the header for the data record that the
1344113460
** cursor is currently pointing to. Only valid if cacheStatus matches
1344213461
** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
1344313462
** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
1344413463
** the cache is out of date.
@@ -13445,14 +13464,18 @@
1344513464
**
1344613465
** aRow might point to (ephemeral) data for the current row, or it might
1344713466
** be NULL.
1344813467
*/
1344913468
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[] */
1345413477
};
1345513478
typedef struct VdbeCursor VdbeCursor;
1345613479
1345713480
/*
1345813481
** When a sub-program is executed (OP_Program), a structure of this type
@@ -13773,11 +13796,11 @@
1377313796
SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
1377413797
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
1377513798
SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
1377613799
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
1377713800
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*);
1377913802
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
1378013803
SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
1378113804
#define VdbeMemRelease(X) \
1378213805
if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
1378313806
sqlite3VdbeMemReleaseExternal(X);
@@ -22901,87 +22924,87 @@
2290122924
/* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
2290222925
/* 2 */ "Savepoint" OpHelp(""),
2290322926
/* 3 */ "AutoCommit" OpHelp(""),
2290422927
/* 4 */ "Transaction" OpHelp(""),
2290522928
/* 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(""),
2291922942
/* 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]"),
2296922992
/* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
2297022993
/* 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(""),
2297422997
/* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
2297522998
/* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
2297622999
/* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
2297723000
/* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
2297823001
/* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
2297923002
/* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
2298023003
/* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
2298123004
/* 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"),
2298323006
/* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
2298423007
/* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
2298523008
/* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
2298623009
/* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
2298723010
/* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -22988,68 +23011,70 @@
2298823011
/* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
2298923012
/* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
2299023013
/* 90 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
2299123014
/* 91 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2299223015
/* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
22993
- /* 93 */ "RowData" OpHelp("r[P2]=data"),
23016
+ /* 93 */ "SorterData" OpHelp("r[P2]=data"),
2299423017
/* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
2299523018
/* 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"),
2303123054
/* 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(""),
2304223065
/* 142 */ "ToText" OpHelp(""),
2304323066
/* 143 */ "ToBlob" OpHelp(""),
2304423067
/* 144 */ "ToNumeric" OpHelp(""),
2304523068
/* 145 */ "ToInt" OpHelp(""),
2304623069
/* 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(""),
2305123076
};
2305223077
return azName[i];
2305323078
}
2305423079
#endif
2305523080
@@ -54458,11 +54483,11 @@
5445854483
** page of the database. The data might change or move the next time
5445954484
** any btree routine is called.
5446054485
*/
5446154486
static const unsigned char *fetchPayload(
5446254487
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 */
5446454489
int skipKey /* read beginning at data if this is true */
5446554490
){
5446654491
unsigned char *aPayload;
5446754492
MemPage *pPage;
5446854493
u32 nKey;
@@ -54508,20 +54533,20 @@
5450854533
** this routine.
5450954534
**
5451054535
** These routines is used to get quick access to key and data
5451154536
** in the common case where no overflow pages are used.
5451254537
*/
54513
-SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){
54538
+SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
5451454539
const void *p = 0;
5451554540
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5451654541
assert( cursorHoldsMutex(pCur) );
5451754542
if( ALWAYS(pCur->eState==CURSOR_VALID) ){
5451854543
p = (const void*)fetchPayload(pCur, pAmt, 0);
5451954544
}
5452054545
return p;
5452154546
}
54522
-SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){
54547
+SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
5452354548
const void *p = 0;
5452454549
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
5452554550
assert( cursorHoldsMutex(pCur) );
5452654551
if( ALWAYS(pCur->eState==CURSOR_VALID) ){
5452754552
p = (const void*)fetchPayload(pCur, pAmt, 1);
@@ -60420,17 +60445,17 @@
6042060445
** If this routine fails for any reason (malloc returns NULL or unable
6042160446
** to read from the disk) then the pMem is left in an inconsistent state.
6042260447
*/
6042360448
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
6042460449
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. */
6042760452
int key, /* If true, retrieve from the btree key, not data. */
6042860453
Mem *pMem /* OUT: Return data in this Mem structure. */
6042960454
){
6043060455
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 */
6043260457
int rc = SQLITE_OK; /* Return code */
6043360458
6043460459
assert( sqlite3BtreeCursorIsValid(pCur) );
6043560460
6043660461
/* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
@@ -60441,11 +60466,11 @@
6044160466
}else{
6044260467
zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
6044360468
}
6044460469
assert( zData!=0 );
6044560470
60446
- if( offset+amt<=available && (pMem->flags&MEM_Dyn)==0 ){
60471
+ if( offset+amt<=available ){
6044760472
sqlite3VdbeMemRelease(pMem);
6044860473
pMem->z = &zData[offset];
6044960474
pMem->flags = MEM_Blob|MEM_Ephem;
6045060475
}else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
6045160476
pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
@@ -60460,11 +60485,11 @@
6046060485
pMem->z[amt+1] = 0;
6046160486
if( rc!=SQLITE_OK ){
6046260487
sqlite3VdbeMemRelease(pMem);
6046360488
}
6046460489
}
60465
- pMem->n = amt;
60490
+ pMem->n = (int)amt;
6046660491
6046760492
return rc;
6046860493
}
6046960494
6047060495
/* This function is only available internally, it is not part of the
@@ -61391,16 +61416,18 @@
6139161416
if( n>nMaxArgs ) nMaxArgs = n;
6139261417
break;
6139361418
}
6139461419
#endif
6139561420
case OP_Next:
61421
+ case OP_NextIfOpen:
6139661422
case OP_SorterNext: {
6139761423
pOp->p4.xAdvance = sqlite3BtreeNext;
6139861424
pOp->p4type = P4_ADVANCE;
6139961425
break;
6140061426
}
61401
- case OP_Prev: {
61427
+ case OP_Prev:
61428
+ case OP_PrevIfOpen: {
6140261429
pOp->p4.xAdvance = sqlite3BtreePrevious;
6140361430
pOp->p4type = P4_ADVANCE;
6140461431
break;
6140561432
}
6140661433
}
@@ -62612,11 +62639,11 @@
6261262639
sqlite3BtreeCloseCursor(pCx->pCursor);
6261362640
}
6261462641
#ifndef SQLITE_OMIT_VIRTUALTABLE
6261562642
if( pCx->pVtabCursor ){
6261662643
sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
62617
- const sqlite3_module *pModule = pCx->pModule;
62644
+ const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
6261862645
p->inVtabMethod = 1;
6261962646
pModule->xClose(pVtabCursor);
6262062647
p->inVtabMethod = 0;
6262162648
}
6262262649
#endif
@@ -63596,11 +63623,11 @@
6359663623
#ifdef SQLITE_TEST
6359763624
sqlite3_search_count++;
6359863625
#endif
6359963626
p->deferredMoveto = 0;
6360063627
p->cacheStatus = CACHE_STALE;
63601
- }else if( ALWAYS(p->pCursor) ){
63628
+ }else if( p->pCursor ){
6360263629
int hasMoved;
6360363630
int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved);
6360463631
if( rc ) return rc;
6360563632
if( hasMoved ){
6360663633
p->cacheStatus = CACHE_STALE;
@@ -64141,11 +64168,11 @@
6414164168
assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
6414264169
assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
6414364170
6414464171
/* Read in the complete content of the index entry */
6414564172
memset(&m, 0, sizeof(m));
64146
- rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m);
64173
+ rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
6414764174
if( rc ){
6414864175
return rc;
6414964176
}
6415064177
6415164178
/* The index entry must begin with a header size */
@@ -64219,11 +64246,11 @@
6421964246
if( nCellKey<=0 || nCellKey>0x7fffffff ){
6422064247
*res = 0;
6422164248
return SQLITE_CORRUPT_BKPT;
6422264249
}
6422364250
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);
6422564252
if( rc ){
6422664253
return rc;
6422764254
}
6422864255
assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
6422964256
*res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
@@ -66154,13 +66181,12 @@
6615466181
Mem *pMem = &p->aMem[p->nMem-iCur];
6615566182
6615666183
int nByte;
6615766184
VdbeCursor *pCx = 0;
6615866185
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);
6616266188
6616366189
assert( iCur<p->nCursor );
6616466190
if( p->apCsr[iCur] ){
6616566191
sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
6616666192
p->apCsr[iCur] = 0;
@@ -66168,16 +66194,13 @@
6616866194
if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
6616966195
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
6617066196
memset(pCx, 0, sizeof(VdbeCursor));
6617166197
pCx->iDb = iDb;
6617266198
pCx->nField = nField;
66173
- if( nField ){
66174
- pCx->aType = (u32 *)&pMem->z[ROUND8(sizeof(VdbeCursor))];
66175
- }
6617666199
if( isBtreeCursor ){
6617766200
pCx->pCursor = (BtCursor*)
66178
- &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)];
66201
+ &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
6617966202
sqlite3BtreeCursorZero(pCx->pCursor);
6618066203
}
6618166204
}
6618266205
return pCx;
6618366206
}
@@ -66669,31 +66692,26 @@
6666966692
} an;
6667066693
struct OP_IfNot_stack_vars {
6667166694
int c;
6667266695
} ao;
6667366696
struct OP_Column_stack_vars {
66674
- u32 payloadSize; /* Number of bytes in the record */
6667566697
i64 payloadSize64; /* Number of bytes in the record */
66676
- int p1; /* P1 value of the opcode */
6667766698
int p2; /* column number to retrieve */
6667866699
VdbeCursor *pC; /* The VDBE cursor */
66679
- char *zRec; /* Pointer to complete record-data */
6668066700
BtCursor *pCrsr; /* The BTree cursor */
6668166701
u32 *aType; /* aType[i] holds the numeric type of the i-th column */
6668266702
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
66683
- int nField; /* number of fields in the record */
6668466703
int len; /* The length of the serialized data for the column */
6668566704
int i; /* Loop counter */
66686
- char *zData; /* Part of the record being decoded */
6668766705
Mem *pDest; /* Where to write the extracted value */
6668866706
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 */
6669166710
u32 offset; /* Offset into the data */
6669266711
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 */
6669566713
u32 t; /* A type code from the record header */
6669666714
Mem *pReg; /* PseudoTable input register */
6669766715
} ap;
6669866716
struct OP_Affinity_stack_vars {
6669966717
const char *zAffinity; /* The affinity to be applied */
@@ -66852,11 +66870,11 @@
6685266870
struct OP_Rewind_stack_vars {
6685366871
VdbeCursor *pC;
6685466872
BtCursor *pCrsr;
6685566873
int res;
6685666874
} bq;
66857
- struct OP_Next_stack_vars {
66875
+ struct OP_SorterNext_stack_vars {
6685866876
VdbeCursor *pC;
6685966877
int res;
6686066878
} br;
6686166879
struct OP_IdxInsert_stack_vars {
6686266880
VdbeCursor *pC;
@@ -67553,19 +67571,19 @@
6755367571
int n; /* Number of registers left to copy */
6755467572
int p1; /* Register to copy from */
6755567573
int p2; /* Register to copy to */
6755667574
#endif /* local variables moved into u.ae */
6755767575
67558
- u.ae.n = pOp->p3 + 1;
67576
+ u.ae.n = pOp->p3;
6755967577
u.ae.p1 = pOp->p1;
6756067578
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 );
6756267580
assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
6756367581
6756467582
pIn1 = &aMem[u.ae.p1];
6756567583
pOut = &aMem[u.ae.p2];
67566
- while( u.ae.n-- ){
67584
+ do{
6756767585
assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
6756867586
assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
6756967587
assert( memIsValid(pIn1) );
6757067588
memAboutToChange(p, pOut);
6757167589
u.ae.zMalloc = pOut->zMalloc;
@@ -67578,11 +67596,11 @@
6757867596
#endif
6757967597
pIn1->zMalloc = u.ae.zMalloc;
6758067598
REGISTER_TRACE(u.ae.p2++, pOut);
6758167599
pIn1++;
6758267600
pOut++;
67583
- }
67601
+ }while( u.ae.n-- );
6758467602
break;
6758567603
}
6758667604
6758767605
/* Opcode: Copy P1 P2 P3 * *
6758867606
** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67969,22 +67987,21 @@
6796967987
REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
6797067988
}
6797167989
6797267990
assert( pOp->p4type==P4_FUNCDEF );
6797367991
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;
6797867992
u.aj.ctx.iOp = pc;
6797967993
u.aj.ctx.pVdbe = p;
6798067994
6798167995
/* The output cell may already have a buffer allocated. Move
6798267996
** the pointer to u.aj.ctx.s so in case the user-function can use
6798367997
** the already allocated buffer instead of allocating a new one.
6798467998
*/
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;
6798668003
MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
6798768004
6798868005
u.aj.ctx.fErrorOrAux = 0;
6798968006
if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
6799068007
assert( pOp>aOp );
@@ -68015,11 +68032,12 @@
6801568032
sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
6801668033
}
6801768034
6801868035
/* Copy the result of the function into register P3 */
6801968036
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));
6802168039
if( sqlite3VdbeMemTooBig(pOut) ){
6802268040
goto too_big;
6802368041
}
6802468042
6802568043
#if 0
@@ -68142,21 +68160,23 @@
6814268160
** without data loss, then jump immediately to P2, or if P2==0
6814368161
** raise an SQLITE_MISMATCH exception.
6814468162
*/
6814568163
case OP_MustBeInt: { /* jump, in1 */
6814668164
pIn1 = &aMem[pOp->p1];
68147
- applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
6814868165
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);
6815868178
break;
6815968179
}
6816068180
6816168181
#ifndef SQLITE_OMIT_FLOATING_POINT
6816268182
/* Opcode: RealAffinity P1 * * * *
@@ -68740,156 +68760,108 @@
6874068760
** or typeof() function, respectively. The loading of large blobs can be
6874168761
** skipped for length() and all content loading can be skipped for typeof().
6874268762
*/
6874368763
case OP_Column: {
6874468764
#if 0 /* local variables moved into u.ap */
68745
- u32 payloadSize; /* Number of bytes in the record */
6874668765
i64 payloadSize64; /* Number of bytes in the record */
68747
- int p1; /* P1 value of the opcode */
6874868766
int p2; /* column number to retrieve */
6874968767
VdbeCursor *pC; /* The VDBE cursor */
68750
- char *zRec; /* Pointer to complete record-data */
6875168768
BtCursor *pCrsr; /* The BTree cursor */
6875268769
u32 *aType; /* aType[i] holds the numeric type of the i-th column */
6875368770
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
68754
- int nField; /* number of fields in the record */
6875568771
int len; /* The length of the serialized data for the column */
6875668772
int i; /* Loop counter */
68757
- char *zData; /* Part of the record being decoded */
6875868773
Mem *pDest; /* Where to write the extracted value */
6875968774
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 */
6876268778
u32 offset; /* Offset into the data */
6876368779
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 */
6876668781
u32 t; /* A type code from the record header */
6876768782
Mem *pReg; /* PseudoTable input register */
6876868783
#endif /* local variables moved into u.ap */
6876968784
68770
-
68771
- u.ap.p1 = pOp->p1;
6877268785
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 );
6877668786
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
6877768787
u.ap.pDest = &aMem[pOp->p3];
6877868788
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];
6879468791
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;
6879568795
#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 */
6879768797
#endif
6879868798
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 ){
6880368806
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
+ }
6886368851
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
+ }
6889168863
6889268864
/* Make sure a corrupt database has not given us an oversize header.
6889368865
** Do this now to avoid an oversize memory allocation.
6889468866
**
6889568867
** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68896,159 +68868,152 @@
6889668868
** types use so much data space that there can only be 4096 and 32 of
6889768869
** them, respectively. So the maximum header length results from a
6889868870
** 3-byte type for each of the maximum of 32768 columns plus three
6889968871
** extra bytes for the header length itself. 32768*3 + 3 = 98307.
6890068872
*/
68901
- if( u.ap.offset > 98307 ){
68873
+ if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){
6890268874
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++;
6895168910
}else{
68952
- u.ap.zIdx += sqlite3GetVarint32(u.ap.zIdx, &u.ap.t);
68911
+ u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t);
6895368912
}
6895468913
u.ap.aType[u.ap.i] = u.ap.t;
6895568914
u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
6895668915
u.ap.offset += u.ap.szField;
6895768916
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:
6905069015
UPDATE_MAX_BLOBSIZE(u.ap.pDest);
6905169016
REGISTER_TRACE(pOp->p3, u.ap.pDest);
6905269017
break;
6905369018
}
6905469019
@@ -69820,10 +69785,12 @@
6982069785
u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
6982169786
}else if( pOp->p4type==P4_INT32 ){
6982269787
u.az.nField = pOp->p4.i;
6982369788
}
6982469789
assert( pOp->p1>=0 );
69790
+ assert( u.az.nField>=0 );
69791
+ testcase( u.az.nField==0 ); /* Table with INTEGER PRIMARY KEY and nothing else */
6982569792
u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
6982669793
if( u.az.pCur==0 ) goto no_mem;
6982769794
u.az.pCur->nullRow = 1;
6982869795
u.az.pCur->isOrdered = 1;
6982969796
rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
@@ -69833,16 +69800,15 @@
6983369800
6983469801
/* Since it performs no memory allocation or IO, the only value that
6983569802
** sqlite3BtreeCursor() may return is SQLITE_OK. */
6983669803
assert( rc==SQLITE_OK );
6983769804
69838
- /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
69805
+ /* Set the VdbeCursor.isTable variable. Previous versions of
6983969806
** SQLite used to check if the root-page flags were sane at this point
6984069807
** and report database corruption if they were not, but this check has
6984169808
** since moved into the btree layer. */
6984269809
u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69843
- u.az.pCur->isIndex = !u.az.pCur->isTable;
6984469810
break;
6984569811
}
6984669812
6984769813
/* Opcode: OpenEphemeral P1 P2 * P4 P5
6984869814
** Synopsis: nColumn=P2
@@ -69882,10 +69848,11 @@
6988269848
SQLITE_OPEN_CREATE |
6988369849
SQLITE_OPEN_EXCLUSIVE |
6988469850
SQLITE_OPEN_DELETEONCLOSE |
6988569851
SQLITE_OPEN_TRANSIENT_DB;
6988669852
assert( pOp->p1>=0 );
69853
+ assert( pOp->p2>=0 );
6988769854
u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
6988869855
if( u.ba.pCx==0 ) goto no_mem;
6988969856
u.ba.pCx->nullRow = 1;
6989069857
rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
6989169858
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
@@ -69914,11 +69881,10 @@
6991469881
rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
6991569882
u.ba.pCx->isTable = 1;
6991669883
}
6991769884
}
6991869885
u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69919
- u.ba.pCx->isIndex = !u.ba.pCx->isTable;
6992069886
break;
6992169887
}
6992269888
6992369889
/* Opcode: SorterOpen P1 * * P4 *
6992469890
**
@@ -69929,16 +69895,17 @@
6992969895
case OP_SorterOpen: {
6993069896
#if 0 /* local variables moved into u.bb */
6993169897
VdbeCursor *pCx;
6993269898
#endif /* local variables moved into u.bb */
6993369899
69900
+ assert( pOp->p1>=0 );
69901
+ assert( pOp->p2>=0 );
6993469902
u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
6993569903
if( u.bb.pCx==0 ) goto no_mem;
6993669904
u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
6993769905
assert( u.bb.pCx->pKeyInfo->db==db );
6993869906
assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
69939
- u.bb.pCx->isSorter = 1;
6994069907
rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
6994169908
break;
6994269909
}
6994369910
6994469911
/* Opcode: OpenPseudo P1 P2 P3 * P5
@@ -69962,16 +69929,16 @@
6996269929
#if 0 /* local variables moved into u.bc */
6996369930
VdbeCursor *pCx;
6996469931
#endif /* local variables moved into u.bc */
6996569932
6996669933
assert( pOp->p1>=0 );
69934
+ assert( pOp->p3>=0 );
6996769935
u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
6996869936
if( u.bc.pCx==0 ) goto no_mem;
6996969937
u.bc.pCx->nullRow = 1;
6997069938
u.bc.pCx->pseudoTableReg = pOp->p2;
6997169939
u.bc.pCx->isTable = 1;
69972
- u.bc.pCx->isIndex = 0;
6997369940
u.bc.pCx->multiPseudo = pOp->p5;
6997469941
break;
6997569942
}
6997669943
6997769944
/* Opcode: Close P1 * * * *
@@ -70801,11 +70768,11 @@
7080170768
VdbeCursor *pC;
7080270769
#endif /* local variables moved into u.bl */
7080370770
7080470771
pOut = &aMem[pOp->p2];
7080570772
u.bl.pC = p->apCsr[pOp->p1];
70806
- assert( u.bl.pC->isSorter );
70773
+ assert( isSorter(u.bl.pC) );
7080770774
rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
7080870775
break;
7080970776
}
7081070777
7081170778
/* Opcode: RowData P1 P2 * * *
@@ -70843,13 +70810,13 @@
7084370810
memAboutToChange(p, pOut);
7084470811
7084570812
/* Note that RowKey and RowData are really exactly the same instruction */
7084670813
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7084770814
u.bm.pC = p->apCsr[pOp->p1];
70848
- assert( u.bm.pC->isSorter==0 );
70815
+ assert( isSorter(u.bm.pC)==0 );
7084970816
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 );
7085170818
assert( u.bm.pC!=0 );
7085270819
assert( u.bm.pC->nullRow==0 );
7085370820
assert( u.bm.pC->pseudoTableReg==0 );
7085470821
assert( u.bm.pC->pCursor!=0 );
7085570822
u.bm.pCrsr = u.bm.pC->pCursor;
@@ -70862,11 +70829,11 @@
7086270829
*/
7086370830
assert( u.bm.pC->deferredMoveto==0 );
7086470831
rc = sqlite3VdbeCursorMoveto(u.bm.pC);
7086570832
if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
7086670833
70867
- if( u.bm.pC->isIndex ){
70834
+ if( u.bm.pC->isTable==0 ){
7086870835
assert( !u.bm.pC->isTable );
7086970836
VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
7087070837
assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
7087170838
if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
7087270839
goto too_big;
@@ -70882,11 +70849,11 @@
7088270849
if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
7088370850
goto no_mem;
7088470851
}
7088570852
pOut->n = u.bm.n;
7088670853
MemSetTypeFlag(pOut, MEM_Blob);
70887
- if( u.bm.pC->isIndex ){
70854
+ if( u.bm.pC->isTable==0 ){
7088870855
rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
7088970856
}else{
7089070857
rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
7089170858
}
7089270859
pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
@@ -70959,10 +70926,11 @@
7095970926
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7096070927
u.bo.pC = p->apCsr[pOp->p1];
7096170928
assert( u.bo.pC!=0 );
7096270929
u.bo.pC->nullRow = 1;
7096370930
u.bo.pC->rowidIsValid = 0;
70931
+ u.bo.pC->cacheStatus = CACHE_STALE;
7096470932
assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
7096570933
if( u.bo.pC->pCursor ){
7096670934
sqlite3BtreeClearCursor(u.bo.pC->pCursor);
7096770935
}
7096870936
break;
@@ -71038,19 +71006,18 @@
7103871006
#endif /* local variables moved into u.bq */
7103971007
7104071008
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7104171009
u.bq.pC = p->apCsr[pOp->p1];
7104271010
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) );
7104471012
u.bq.res = 1;
7104571013
if( isSorter(u.bq.pC) ){
7104671014
rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
7104771015
}else{
7104871016
u.bq.pCrsr = u.bq.pC->pCursor;
7104971017
assert( u.bq.pCrsr );
7105071018
rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);
71051
- u.bq.pC->atFirst = u.bq.res==0 ?1:0;
7105271019
u.bq.pC->deferredMoveto = 0;
7105371020
u.bq.pC->cacheStatus = CACHE_STALE;
7105471021
u.bq.pC->rowidIsValid = 0;
7105571022
}
7105671023
u.bq.pC->nullRow = (u8)u.bq.res;
@@ -71066,69 +71033,85 @@
7106671033
** Advance cursor P1 so that it points to the next key/data pair in its
7106771034
** table or index. If there are no more key/value pairs then fall through
7106871035
** to the following instruction. But if the cursor advance was successful,
7106971036
** jump immediately to P2.
7107071037
**
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.
7107271040
**
7107371041
** P4 is always of type P4_ADVANCE. The function pointer points to
7107471042
** sqlite3BtreeNext().
7107571043
**
7107671044
** If P5 is positive and the jump is taken, then event counter
7107771045
** number P5-1 in the prepared statement is incremented.
7107871046
**
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.
7108071053
*/
7108171054
/* Opcode: Prev P1 P2 * * P5
7108271055
**
7108371056
** Back up cursor P1 so that it points to the previous key/data pair in its
7108471057
** table or index. If there is no previous key/value pairs then fall through
7108571058
** to the following instruction. But if the cursor backup was successful,
7108671059
** jump immediately to P2.
7108771060
**
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.
7108971063
**
7109071064
** P4 is always of type P4_ADVANCE. The function pointer points to
7109171065
** sqlite3BtreePrevious().
7109271066
**
7109371067
** If P5 is positive and the jump is taken, then event counter
7109471068
** number P5-1 in the prepared statement is incremented.
7109571069
*/
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 */
7109971076
#if 0 /* local variables moved into u.br */
7110071077
VdbeCursor *pC;
7110171078
int res;
7110271079
#endif /* local variables moved into u.br */
7110371080
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 */
7110471091
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7110571092
assert( pOp->p5<ArraySize(p->aCounter) );
7110671093
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:
7112371103
u.br.pC->cacheStatus = CACHE_STALE;
7112471104
if( u.br.res==0 ){
71105
+ u.br.pC->nullRow = 0;
7112571106
pc = pOp->p2 - 1;
7112671107
p->aCounter[pOp->p5]++;
7112771108
#ifdef SQLITE_TEST
7112871109
sqlite3_search_count++;
7112971110
#endif
71111
+ }else{
71112
+ u.br.pC->nullRow = 1;
7113071113
}
7113171114
u.br.pC->rowidIsValid = 0;
7113271115
goto check_for_interrupt;
7113371116
}
7113471117
@@ -71155,11 +71138,11 @@
7115571138
#endif /* local variables moved into u.bs */
7115671139
7115771140
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7115871141
u.bs.pC = p->apCsr[pOp->p1];
7115971142
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) );
7116171144
pIn2 = &aMem[pOp->p2];
7116271145
assert( pIn2->flags & MEM_Blob );
7116371146
u.bs.pCrsr = u.bs.pC->pCursor;
7116471147
if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
7116571148
assert( u.bs.pCrsr!=0 );
@@ -72446,11 +72429,10 @@
7244672429
7244772430
/* Initialize vdbe cursor object */
7244872431
u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
7244972432
if( u.cm.pCur ){
7245072433
u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
72451
- u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule;
7245272434
}else{
7245372435
db->mallocFailed = 1;
7245472436
u.cm.pModule->xClose(u.cm.pVtabCursor);
7245572437
}
7245672438
}
@@ -73017,22 +72999,23 @@
7301772999
assert( v->aVar[0].flags&MEM_Int );
7301873000
v->aVar[0].u.i = iRow;
7301973001
7302073002
rc = sqlite3_step(p->pStmt);
7302173003
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];
7302373006
if( type<12 ){
7302473007
zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
7302573008
type==0?"null": type==7?"real": "integer"
7302673009
);
7302773010
rc = SQLITE_ERROR;
7302873011
sqlite3_finalize(p->pStmt);
7302973012
p->pStmt = 0;
7303073013
}else{
73031
- p->iOffset = v->apCsr[0]->aOffset[p->iCol];
73014
+ p->iOffset = pC->aType[p->iCol + pC->nField];
7303273015
p->nByte = sqlite3VdbeSerialTypeLen(type);
73033
- p->pCsr = v->apCsr[0]->pCursor;
73016
+ p->pCsr = pC->pCursor;
7303473017
sqlite3BtreeEnterCursor(p->pCsr);
7303573018
sqlite3BtreeCacheOverflow(p->pCsr);
7303673019
sqlite3BtreeLeaveCursor(p->pCsr);
7303773020
}
7303873021
}
@@ -75806,11 +75789,10 @@
7580675789
return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
7580775790
}
7580875791
7580975792
/* Resolve function names
7581075793
*/
75811
- case TK_CONST_FUNC:
7581275794
case TK_FUNCTION: {
7581375795
ExprList *pList = pExpr->x.pList; /* The argument list */
7581475796
int n = pList ? pList->nExpr : 0; /* Number of arguments */
7581575797
int no_such_func = 0; /* True if no such function exists */
7581675798
int wrong_num_args = 0; /* True if wrong number of arguments */
@@ -75819,11 +75801,10 @@
7581975801
int nId; /* Number of characters in function name */
7582075802
const char *zId; /* The function name. */
7582175803
FuncDef *pDef; /* Information about the function */
7582275804
u8 enc = ENC(pParse->db); /* The database encoding */
7582375805
75824
- testcase( pExpr->op==TK_CONST_FUNC );
7582575806
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
7582675807
notValidPartIdxWhere(pParse, pNC, "functions");
7582775808
zId = pExpr->u.zToken;
7582875809
nId = sqlite3Strlen30(zId);
7582975810
pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
@@ -75864,10 +75845,11 @@
7586475845
pNC->nErr++;
7586575846
}
7586675847
pExpr->op = TK_NULL;
7586775848
return WRC_Prune;
7586875849
}
75850
+ if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
7586975851
}
7587075852
#endif
7587175853
if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
7587275854
sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
7587375855
pNC->nErr++;
@@ -77781,13 +77763,16 @@
7778177763
return WRC_Abort;
7778277764
}
7778377765
7778477766
switch( pExpr->op ){
7778577767
/* 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. */
7778777770
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
+ }
7778977774
/* Fall through */
7779077775
case TK_ID:
7779177776
case TK_COLUMN:
7779277777
case TK_AGG_FUNCTION:
7779377778
case TK_AGG_COLUMN:
@@ -79213,11 +79198,10 @@
7921379198
}else{
7921479199
inReg = pInfo->aFunc[pExpr->iAgg].iMem;
7921579200
}
7921679201
break;
7921779202
}
79218
- case TK_CONST_FUNC:
7921979203
case TK_FUNCTION: {
7922079204
ExprList *pFarg; /* List of function arguments */
7922179205
int nFarg; /* Number of function arguments */
7922279206
FuncDef *pDef; /* The function definition object */
7922379207
int nId; /* Length of the function name in bytes */
@@ -79226,12 +79210,10 @@
7922679210
int i; /* Loop counter */
7922779211
u8 enc = ENC(db); /* The text encoding used by this database */
7922879212
CollSeq *pColl = 0; /* A collating sequence */
7922979213
7923079214
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
79231
- testcase( op==TK_CONST_FUNC );
79232
- testcase( op==TK_FUNCTION );
7923379215
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
7923479216
pFarg = 0;
7923579217
}else{
7923679218
pFarg = pExpr->x.pList;
7923779219
}
@@ -79271,12 +79253,25 @@
7927179253
assert( nFarg>=1 );
7927279254
sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
7927379255
break;
7927479256
}
7927579257
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
+ }
7927679266
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
+ }
7927879273
7927979274
/* For length() and typeof() functions with a column argument,
7928079275
** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
7928179276
** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
7928279277
** loading.
@@ -79287,18 +79282,19 @@
7928779282
assert( pFarg->a[0].pExpr!=0 );
7928879283
exprOp = pFarg->a[0].pExpr->op;
7928979284
if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
7929079285
assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
7929179286
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);
7929579290
}
7929679291
}
7929779292
7929879293
sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
79299
- sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);
79294
+ sqlite3ExprCodeExprList(pParse, pFarg, r1,
79295
+ SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
7930079296
sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */
7930179297
}else{
7930279298
r1 = 0;
7930379299
}
7930479300
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -79318,26 +79314,18 @@
7931879314
pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
7931979315
}else if( nFarg>0 ){
7932079316
pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
7932179317
}
7932279318
#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
- }
7933179319
if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
7933279320
if( !pColl ) pColl = db->pDfltColl;
7933379321
sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
7933479322
}
7933579323
sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
7933679324
(char*)pDef, P4_FUNCDEF);
7933779325
sqlite3VdbeChangeP5(v, (u8)nFarg);
79338
- if( nFarg ){
79326
+ if( nFarg && constMask==0 ){
7933979327
sqlite3ReleaseTempRange(pParse, r1, nFarg);
7934079328
}
7934179329
break;
7934279330
}
7934379331
#ifndef SQLITE_OMIT_SUBQUERY
@@ -79569,10 +79557,32 @@
7956979557
}
7957079558
sqlite3ReleaseTempReg(pParse, regFree1);
7957179559
sqlite3ReleaseTempReg(pParse, regFree2);
7957279560
return inReg;
7957379561
}
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
+}
7957479584
7957579585
/*
7957679586
** Generate code to evaluate an expression and store the results
7957779587
** into a register. Return the register number where the results
7957879588
** are stored.
@@ -79586,28 +79596,27 @@
7958679596
** VDBE program, in order to factor it out of the evaluation loop.
7958779597
*/
7958879598
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
7958979599
int r2;
7959079600
pExpr = sqlite3ExprSkipCollate(pExpr);
79591
- if( pParse->cookieGoto>0
79601
+ if( ConstFactorOk(pParse)
7959279602
&& pExpr->op!=TK_REGISTER
7959379603
&& sqlite3ExprIsConstantNotJoin(pExpr)
7959479604
){
7959579605
ExprList *p = pParse->pConstExpr;
7959679606
int i;
7959779607
*pReg = 0;
7959879608
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;
7960279613
}
7960379614
}
7960479615
}
79605
- p = sqlite3ExprListAppend(pParse, p, sqlite3ExprDup(pParse->db, pExpr, 0));
79606
- pParse->pConstExpr = p;
7960779616
r2 = ++pParse->nMem;
79608
- if( p ) p->a[p->nExpr-1].u.iConstExprReg = r2;
79617
+ sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
7960979618
}else{
7961079619
int r1 = sqlite3GetTempReg(pParse);
7961179620
r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
7961279621
if( r2==r1 ){
7961379622
*pReg = r1;
@@ -79793,11 +79802,10 @@
7979379802
sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
7979479803
break;
7979579804
}
7979679805
7979779806
case TK_AGG_FUNCTION:
79798
- case TK_CONST_FUNC:
7979979807
case TK_FUNCTION: {
7980079808
ExprList *pFarg; /* List of function arguments */
7980179809
if( ExprHasProperty(pExpr, EP_TokenOnly) ){
7980279810
pFarg = 0;
7980379811
}else{
@@ -79949,29 +79957,40 @@
7994979957
/*
7995079958
** Generate code that pushes the value of every element of the given
7995179959
** expression list into a sequence of registers beginning at target.
7995279960
**
7995379961
** 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.
7995479968
*/
7995579969
SQLITE_PRIVATE int sqlite3ExprCodeExprList(
7995679970
Parse *pParse, /* Parsing context */
7995779971
ExprList *pList, /* The expression list to be coded */
7995879972
int target, /* Where to write results */
79959
- int doHardCopy /* Make a hard copy of every element */
79973
+ u8 flags /* SQLITE_ECEL_* flags */
7996079974
){
7996179975
struct ExprList_item *pItem;
7996279976
int i, n;
79977
+ u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
7996379978
assert( pList!=0 );
7996479979
assert( target>0 );
7996579980
assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
7996679981
n = pList->nExpr;
79982
+ if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
7996779983
for(pItem=pList->a, i=0; i<n; i++, pItem++){
7996879984
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
+ }
7997379992
}
7997479993
}
7997579994
return n;
7997679995
}
7997779996
@@ -91338,24 +91357,24 @@
9133891357
FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
9133991358
FUNCTION(hex, 1, 0, 0, hexFunc ),
9134091359
FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
9134191360
FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
9134291361
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 ),
9134591364
FUNCTION(nullif, 2, 0, 1, nullifFunc ),
9134691365
FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
9134791366
FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
9134891367
FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
9134991368
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
9135091369
FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
9135191370
FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
9135291371
#endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
9135391372
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 ),
9135791376
FUNCTION(replace, 3, 0, 0, replaceFunc ),
9135891377
FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
9135991378
#ifdef SQLITE_SOUNDEX
9136091379
FUNCTION(soundex, 1, 0, 0, soundexFunc ),
9136191380
#endif
@@ -100003,11 +100022,12 @@
100003100022
}else if( eDest!=SRT_Exists ){
100004100023
/* If the destination is an EXISTS(...) expression, the actual
100005100024
** values returned by the SELECT are not required.
100006100025
*/
100007100026
sqlite3ExprCacheClear(pParse);
100008
- sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Output);
100027
+ sqlite3ExprCodeExprList(pParse, pEList, regResult,
100028
+ (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100009100029
}
100010100030
nColumn = nResultCol;
100011100031
100012100032
/* If the DISTINCT keyword was present on the SELECT statement
100013100033
** and this row has been seen before, then do not make this row
@@ -103289,11 +103309,11 @@
103289103309
ExprList *pList = pF->pExpr->x.pList;
103290103310
assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
103291103311
if( pList ){
103292103312
nArg = pList->nExpr;
103293103313
regAgg = sqlite3GetTempRange(pParse, nArg);
103294
- sqlite3ExprCodeExprList(pParse, pList, regAgg, 1);
103314
+ sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
103295103315
}else{
103296103316
nArg = 0;
103297103317
regAgg = 0;
103298103318
}
103299103319
if( pF->iDistinct>=0 ){
@@ -110765,11 +110785,11 @@
110765110785
if( eType==IN_INDEX_ROWID ){
110766110786
pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
110767110787
}else{
110768110788
pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
110769110789
}
110770
- pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
110790
+ pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
110771110791
sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
110772110792
}else{
110773110793
pLevel->u.in.nIn = 0;
110774110794
}
110775110795
#endif
@@ -117027,16 +117047,11 @@
117027117047
spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
117028117048
}
117029117049
break;
117030117050
case 200: /* term ::= CTIME_KW */
117031117051
{
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);
117038117053
spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
117039117054
}
117040117055
break;
117041117056
case 201: /* expr ::= expr AND expr */
117042117057
case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
117043117058
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.2"
139 #define SQLITE_VERSION_NUMBER 3008002
140 #define SQLITE_SOURCE_ID "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -8140,13 +8140,12 @@
8140 #define TK_UNCLOSED_STRING 151
8141 #define TK_FUNCTION 152
8142 #define TK_COLUMN 153
8143 #define TK_AGG_FUNCTION 154
8144 #define TK_AGG_COLUMN 155
8145 #define TK_CONST_FUNC 156
8146 #define TK_UMINUS 157
8147 #define TK_UPLUS 158
8148
8149 /************** End of parse.h ***********************************************/
8150 /************** Continuing where we left off in sqliteInt.h ******************/
8151 #include <stdio.h>
8152 #include <stdlib.h>
@@ -8778,12 +8777,12 @@
8778 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
8779 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
8780 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
8781 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
8782 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);
8785 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
8786 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
8787 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
8788 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
8789
@@ -9021,87 +9020,87 @@
9021 #define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */
9022 #define OP_Savepoint 2
9023 #define OP_AutoCommit 3
9024 #define OP_Transaction 4
9025 #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 */
9039 #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
9089 #define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9090 #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 */
9094 #define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9095 #define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9096 #define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9097 #define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9098 #define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9099 #define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9100 #define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9101 #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 */
9103 #define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9104 #define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9105 #define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9106 #define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9107 #define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9108,68 +9107,70 @@
9108 #define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9109 #define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9110 #define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9111 #define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9112 #define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9113 #define OP_RowData 93 /* synopsis: r[P2]=data */
9114 #define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9115 #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
9151 #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
9162 #define OP_ToText 142 /* same as TK_TO_TEXT */
9163 #define OP_ToBlob 143 /* same as TK_TO_BLOB */
9164 #define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */
9165 #define OP_ToInt 145 /* same as TK_TO_INT */
9166 #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
 
 
9171
9172
9173 /* Properties such as "out2" or "jump" that are specified in
9174 ** comments following the "case" for each opcode in the vdbe.c
9175 ** are encoded into bitvectors as follows:
@@ -9181,28 +9182,29 @@
9181 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9182 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9183 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9184 #define OPFLG_INITIALIZER {\
9185 /* 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,\
9194 /* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
9195 /* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
9196 /* 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,}
 
9204
9205 /************** End of opcodes.h *********************************************/
9206 /************** Continuing where we left off in vdbe.h ***********************/
9207
9208 /*
@@ -10336,10 +10338,17 @@
10336 #else
10337 #define OptimizationDisabled(db, mask) 0
10338 #define OptimizationEnabled(db, mask) 1
10339 #endif
10340
 
 
 
 
 
 
 
10341 /*
10342 ** Possible values for the sqlite.magic field.
10343 ** The numbers are obtained at random and have no special meaning, other
10344 ** than being distinct from one another.
10345 */
@@ -10402,10 +10411,11 @@
10402 #define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
10403 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10404 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10405 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10406 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
 
10407
10408 /*
10409 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
10410 ** used to create the initializers for the FuncDef structures.
10411 **
@@ -10414,10 +10424,13 @@
10414 ** implemented by C function xFunc that accepts nArg arguments. The
10415 ** value passed as iArg is cast to a (void*) and made available
10416 ** as the user-data (sqlite3_user_data()) for the function. If
10417 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
10418 **
 
 
 
10419 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
10420 ** Used to create an aggregate function definition implemented by
10421 ** the C functions xStep and xFinal. The first four parameters
10422 ** are interpreted in the same way as the first 4 parameters to
10423 ** FUNCTION().
@@ -10429,20 +10442,24 @@
10429 ** available as the function user-data (sqlite3_user_data()). The
10430 ** FuncDef.flags variable is set to the value passed as the flags
10431 ** parameter.
10432 */
10433 #define FUNCTION(zName, nArg, iArg, bNC, xFunc) \
 
 
 
10434 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10435 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10436 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
10437 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags, \
10438 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10439 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
10440 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10441 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
10442 #define LIKEFUNC(zName, nArg, arg, flags) \
10443 {nArg, SQLITE_UTF8|flags, (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
 
10444 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10445 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
10446 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10447
10448 /*
@@ -11098,10 +11115,11 @@
11098 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
11099 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11100 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11101 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11102 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
 
11103
11104 /*
11105 ** These macros can be used to test, set, or clear bits in the
11106 ** Expr.flags field.
11107 */
@@ -11159,10 +11177,11 @@
11159 char *zName; /* Token associated with this expression */
11160 char *zSpan; /* Original text of the expression */
11161 u8 sortOrder; /* 1 for DESC or 0 for ASC */
11162 unsigned done :1; /* A flag to indicate when processing is finished */
11163 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
 
11164 union {
11165 struct {
11166 u16 iOrderByCol; /* For ORDER BY, column number in result set */
11167 u16 iAlias; /* Index into Parse.aAlias[] for zName */
11168 } x;
@@ -12153,14 +12172,17 @@
12153 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
12154 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
12155 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
12156 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12157 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
 
12158 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12159 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12160 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12161 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int);
 
 
12162 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12163 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
12164 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
12165 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
12166 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
@@ -13386,11 +13408,11 @@
13386 typedef struct VdbeOp Op;
13387
13388 /*
13389 ** Boolean values
13390 */
13391 typedef unsigned char Bool;
13392
13393 /* Opaque type used by code in vdbesort.c */
13394 typedef struct VdbeSorter VdbeSorter;
13395
13396 /* Opaque type used by the explainer */
@@ -13403,42 +13425,39 @@
13403 ** A cursor is a pointer into a single BTree within a database file.
13404 ** The cursor can seek to a BTree entry with a particular key, or
13405 ** loop over all entries of the Btree. You can also insert new BTree
13406 ** entries or retrieve the key or data from the entry that the cursor
13407 ** is currently pointing to.
 
 
 
13408 **
13409 ** Every cursor that the virtual machine has open is represented by an
13410 ** instance of the following structure.
13411 */
13412 struct VdbeCursor {
13413 BtCursor *pCursor; /* The cursor structure of the backend */
13414 Btree *pBt; /* Separate file holding temporary table */
13415 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
13416 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
13417 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 */
13430 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13431 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
13432 i64 seqCount; /* Sequence counter */
13433 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13434 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
13435 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
13436
13437 /* Result of last sqlite3BtreeMoveto() done by an OP_NotExists */
13438 int seekResult;
13439
13440 /* Cached information about the header for the data record that the
13441 ** cursor is currently pointing to. Only valid if cacheStatus matches
13442 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
13443 ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
13444 ** the cache is out of date.
@@ -13445,14 +13464,18 @@
13445 **
13446 ** aRow might point to (ephemeral) data for the current row, or it might
13447 ** be NULL.
13448 */
13449 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 */
 
 
 
 
13454 };
13455 typedef struct VdbeCursor VdbeCursor;
13456
13457 /*
13458 ** When a sub-program is executed (OP_Program), a structure of this type
@@ -13773,11 +13796,11 @@
13773 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
13774 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
13775 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
13776 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
13777 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
13778 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,int,int,int,Mem*);
13779 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
13780 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
13781 #define VdbeMemRelease(X) \
13782 if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
13783 sqlite3VdbeMemReleaseExternal(X);
@@ -22901,87 +22924,87 @@
22901 /* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
22902 /* 2 */ "Savepoint" OpHelp(""),
22903 /* 3 */ "AutoCommit" OpHelp(""),
22904 /* 4 */ "Transaction" OpHelp(""),
22905 /* 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"),
22919 /* 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(""),
22969 /* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
22970 /* 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"),
22974 /* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
22975 /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
22976 /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
22977 /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
22978 /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
22979 /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
22980 /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
22981 /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
22982 /* 82 */ "RowKey" OpHelp("r[P2]=key"),
22983 /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
22984 /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
22985 /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
22986 /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
22987 /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -22988,68 +23011,70 @@
22988 /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
22989 /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
22990 /* 90 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
22991 /* 91 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
22992 /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
22993 /* 93 */ "RowData" OpHelp("r[P2]=data"),
22994 /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
22995 /* 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(""),
23031 /* 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(""),
23042 /* 142 */ "ToText" OpHelp(""),
23043 /* 143 */ "ToBlob" OpHelp(""),
23044 /* 144 */ "ToNumeric" OpHelp(""),
23045 /* 145 */ "ToInt" OpHelp(""),
23046 /* 146 */ "ToReal" OpHelp(""),
23047 /* 147 */ "MaxPgcnt" OpHelp(""),
23048 /* 148 */ "Trace" OpHelp(""),
23049 /* 149 */ "Noop" OpHelp(""),
23050 /* 150 */ "Explain" OpHelp(""),
 
 
23051 };
23052 return azName[i];
23053 }
23054 #endif
23055
@@ -54458,11 +54483,11 @@
54458 ** page of the database. The data might change or move the next time
54459 ** any btree routine is called.
54460 */
54461 static const unsigned char *fetchPayload(
54462 BtCursor *pCur, /* Cursor pointing to entry to read from */
54463 int *pAmt, /* Write the number of available bytes here */
54464 int skipKey /* read beginning at data if this is true */
54465 ){
54466 unsigned char *aPayload;
54467 MemPage *pPage;
54468 u32 nKey;
@@ -54508,20 +54533,20 @@
54508 ** this routine.
54509 **
54510 ** These routines is used to get quick access to key and data
54511 ** in the common case where no overflow pages are used.
54512 */
54513 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, int *pAmt){
54514 const void *p = 0;
54515 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54516 assert( cursorHoldsMutex(pCur) );
54517 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54518 p = (const void*)fetchPayload(pCur, pAmt, 0);
54519 }
54520 return p;
54521 }
54522 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, int *pAmt){
54523 const void *p = 0;
54524 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54525 assert( cursorHoldsMutex(pCur) );
54526 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54527 p = (const void*)fetchPayload(pCur, pAmt, 1);
@@ -60420,17 +60445,17 @@
60420 ** If this routine fails for any reason (malloc returns NULL or unable
60421 ** to read from the disk) then the pMem is left in an inconsistent state.
60422 */
60423 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
60424 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. */
60427 int key, /* If true, retrieve from the btree key, not data. */
60428 Mem *pMem /* OUT: Return data in this Mem structure. */
60429 ){
60430 char *zData; /* Data from the btree layer */
60431 int available = 0; /* Number of bytes available on the local btree page */
60432 int rc = SQLITE_OK; /* Return code */
60433
60434 assert( sqlite3BtreeCursorIsValid(pCur) );
60435
60436 /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
@@ -60441,11 +60466,11 @@
60441 }else{
60442 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
60443 }
60444 assert( zData!=0 );
60445
60446 if( offset+amt<=available && (pMem->flags&MEM_Dyn)==0 ){
60447 sqlite3VdbeMemRelease(pMem);
60448 pMem->z = &zData[offset];
60449 pMem->flags = MEM_Blob|MEM_Ephem;
60450 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60451 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
@@ -60460,11 +60485,11 @@
60460 pMem->z[amt+1] = 0;
60461 if( rc!=SQLITE_OK ){
60462 sqlite3VdbeMemRelease(pMem);
60463 }
60464 }
60465 pMem->n = amt;
60466
60467 return rc;
60468 }
60469
60470 /* This function is only available internally, it is not part of the
@@ -61391,16 +61416,18 @@
61391 if( n>nMaxArgs ) nMaxArgs = n;
61392 break;
61393 }
61394 #endif
61395 case OP_Next:
 
61396 case OP_SorterNext: {
61397 pOp->p4.xAdvance = sqlite3BtreeNext;
61398 pOp->p4type = P4_ADVANCE;
61399 break;
61400 }
61401 case OP_Prev: {
 
61402 pOp->p4.xAdvance = sqlite3BtreePrevious;
61403 pOp->p4type = P4_ADVANCE;
61404 break;
61405 }
61406 }
@@ -62612,11 +62639,11 @@
62612 sqlite3BtreeCloseCursor(pCx->pCursor);
62613 }
62614 #ifndef SQLITE_OMIT_VIRTUALTABLE
62615 if( pCx->pVtabCursor ){
62616 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
62617 const sqlite3_module *pModule = pCx->pModule;
62618 p->inVtabMethod = 1;
62619 pModule->xClose(pVtabCursor);
62620 p->inVtabMethod = 0;
62621 }
62622 #endif
@@ -63596,11 +63623,11 @@
63596 #ifdef SQLITE_TEST
63597 sqlite3_search_count++;
63598 #endif
63599 p->deferredMoveto = 0;
63600 p->cacheStatus = CACHE_STALE;
63601 }else if( ALWAYS(p->pCursor) ){
63602 int hasMoved;
63603 int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved);
63604 if( rc ) return rc;
63605 if( hasMoved ){
63606 p->cacheStatus = CACHE_STALE;
@@ -64141,11 +64168,11 @@
64141 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
64142 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
64143
64144 /* Read in the complete content of the index entry */
64145 memset(&m, 0, sizeof(m));
64146 rc = sqlite3VdbeMemFromBtree(pCur, 0, (int)nCellKey, 1, &m);
64147 if( rc ){
64148 return rc;
64149 }
64150
64151 /* The index entry must begin with a header size */
@@ -64219,11 +64246,11 @@
64219 if( nCellKey<=0 || nCellKey>0x7fffffff ){
64220 *res = 0;
64221 return SQLITE_CORRUPT_BKPT;
64222 }
64223 memset(&m, 0, sizeof(m));
64224 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (int)nCellKey, 1, &m);
64225 if( rc ){
64226 return rc;
64227 }
64228 assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
64229 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
@@ -66154,13 +66181,12 @@
66154 Mem *pMem = &p->aMem[p->nMem-iCur];
66155
66156 int nByte;
66157 VdbeCursor *pCx = 0;
66158 nByte =
66159 ROUND8(sizeof(VdbeCursor)) +
66160 (isBtreeCursor?sqlite3BtreeCursorSize():0) +
66161 2*nField*sizeof(u32);
66162
66163 assert( iCur<p->nCursor );
66164 if( p->apCsr[iCur] ){
66165 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
66166 p->apCsr[iCur] = 0;
@@ -66168,16 +66194,13 @@
66168 if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
66169 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
66170 memset(pCx, 0, sizeof(VdbeCursor));
66171 pCx->iDb = iDb;
66172 pCx->nField = nField;
66173 if( nField ){
66174 pCx->aType = (u32 *)&pMem->z[ROUND8(sizeof(VdbeCursor))];
66175 }
66176 if( isBtreeCursor ){
66177 pCx->pCursor = (BtCursor*)
66178 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)];
66179 sqlite3BtreeCursorZero(pCx->pCursor);
66180 }
66181 }
66182 return pCx;
66183 }
@@ -66669,31 +66692,26 @@
66669 } an;
66670 struct OP_IfNot_stack_vars {
66671 int c;
66672 } ao;
66673 struct OP_Column_stack_vars {
66674 u32 payloadSize; /* Number of bytes in the record */
66675 i64 payloadSize64; /* Number of bytes in the record */
66676 int p1; /* P1 value of the opcode */
66677 int p2; /* column number to retrieve */
66678 VdbeCursor *pC; /* The VDBE cursor */
66679 char *zRec; /* Pointer to complete record-data */
66680 BtCursor *pCrsr; /* The BTree cursor */
66681 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
66682 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
66683 int nField; /* number of fields in the record */
66684 int len; /* The length of the serialized data for the column */
66685 int i; /* Loop counter */
66686 char *zData; /* Part of the record being decoded */
66687 Mem *pDest; /* Where to write the extracted value */
66688 Mem sMem; /* For storing the record being decoded */
66689 u8 *zIdx; /* Index into header */
66690 u8 *zEndHdr; /* Pointer to first byte after the header */
 
66691 u32 offset; /* Offset into the data */
66692 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 */
66695 u32 t; /* A type code from the record header */
66696 Mem *pReg; /* PseudoTable input register */
66697 } ap;
66698 struct OP_Affinity_stack_vars {
66699 const char *zAffinity; /* The affinity to be applied */
@@ -66852,11 +66870,11 @@
66852 struct OP_Rewind_stack_vars {
66853 VdbeCursor *pC;
66854 BtCursor *pCrsr;
66855 int res;
66856 } bq;
66857 struct OP_Next_stack_vars {
66858 VdbeCursor *pC;
66859 int res;
66860 } br;
66861 struct OP_IdxInsert_stack_vars {
66862 VdbeCursor *pC;
@@ -67553,19 +67571,19 @@
67553 int n; /* Number of registers left to copy */
67554 int p1; /* Register to copy from */
67555 int p2; /* Register to copy to */
67556 #endif /* local variables moved into u.ae */
67557
67558 u.ae.n = pOp->p3 + 1;
67559 u.ae.p1 = pOp->p1;
67560 u.ae.p2 = pOp->p2;
67561 assert( u.ae.n>0 && u.ae.p1>0 && u.ae.p2>0 );
67562 assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
67563
67564 pIn1 = &aMem[u.ae.p1];
67565 pOut = &aMem[u.ae.p2];
67566 while( u.ae.n-- ){
67567 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67568 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67569 assert( memIsValid(pIn1) );
67570 memAboutToChange(p, pOut);
67571 u.ae.zMalloc = pOut->zMalloc;
@@ -67578,11 +67596,11 @@
67578 #endif
67579 pIn1->zMalloc = u.ae.zMalloc;
67580 REGISTER_TRACE(u.ae.p2++, pOut);
67581 pIn1++;
67582 pOut++;
67583 }
67584 break;
67585 }
67586
67587 /* Opcode: Copy P1 P2 P3 * *
67588 ** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67969,22 +67987,21 @@
67969 REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
67970 }
67971
67972 assert( pOp->p4type==P4_FUNCDEF );
67973 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 u.aj.ctx.iOp = pc;
67979 u.aj.ctx.pVdbe = p;
67980
67981 /* The output cell may already have a buffer allocated. Move
67982 ** the pointer to u.aj.ctx.s so in case the user-function can use
67983 ** the already allocated buffer instead of allocating a new one.
67984 */
67985 sqlite3VdbeMemMove(&u.aj.ctx.s, pOut);
 
 
 
67986 MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
67987
67988 u.aj.ctx.fErrorOrAux = 0;
67989 if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
67990 assert( pOp>aOp );
@@ -68015,11 +68032,12 @@
68015 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
68016 }
68017
68018 /* Copy the result of the function into register P3 */
68019 sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
68020 sqlite3VdbeMemMove(pOut, &u.aj.ctx.s);
 
68021 if( sqlite3VdbeMemTooBig(pOut) ){
68022 goto too_big;
68023 }
68024
68025 #if 0
@@ -68142,21 +68160,23 @@
68142 ** without data loss, then jump immediately to P2, or if P2==0
68143 ** raise an SQLITE_MISMATCH exception.
68144 */
68145 case OP_MustBeInt: { /* jump, in1 */
68146 pIn1 = &aMem[pOp->p1];
68147 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
68148 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 }
 
 
 
68158 break;
68159 }
68160
68161 #ifndef SQLITE_OMIT_FLOATING_POINT
68162 /* Opcode: RealAffinity P1 * * * *
@@ -68740,156 +68760,108 @@
68740 ** or typeof() function, respectively. The loading of large blobs can be
68741 ** skipped for length() and all content loading can be skipped for typeof().
68742 */
68743 case OP_Column: {
68744 #if 0 /* local variables moved into u.ap */
68745 u32 payloadSize; /* Number of bytes in the record */
68746 i64 payloadSize64; /* Number of bytes in the record */
68747 int p1; /* P1 value of the opcode */
68748 int p2; /* column number to retrieve */
68749 VdbeCursor *pC; /* The VDBE cursor */
68750 char *zRec; /* Pointer to complete record-data */
68751 BtCursor *pCrsr; /* The BTree cursor */
68752 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
68753 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
68754 int nField; /* number of fields in the record */
68755 int len; /* The length of the serialized data for the column */
68756 int i; /* Loop counter */
68757 char *zData; /* Part of the record being decoded */
68758 Mem *pDest; /* Where to write the extracted value */
68759 Mem sMem; /* For storing the record being decoded */
68760 u8 *zIdx; /* Index into header */
68761 u8 *zEndHdr; /* Pointer to first byte after the header */
 
68762 u32 offset; /* Offset into the data */
68763 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 */
68766 u32 t; /* A type code from the record header */
68767 Mem *pReg; /* PseudoTable input register */
68768 #endif /* local variables moved into u.ap */
68769
68770
68771 u.ap.p1 = pOp->p1;
68772 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 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68777 u.ap.pDest = &aMem[pOp->p3];
68778 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];
68794 assert( u.ap.pC!=0 );
 
 
 
68795 #ifndef SQLITE_OMIT_VIRTUALTABLE
68796 assert( u.ap.pC->pVtabCursor==0 );
68797 #endif
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;
 
 
 
68803 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;
68863 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);
68891
68892 /* Make sure a corrupt database has not given us an oversize header.
68893 ** Do this now to avoid an oversize memory allocation.
68894 **
68895 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68896,159 +68868,152 @@
68896 ** types use so much data space that there can only be 4096 and 32 of
68897 ** them, respectively. So the maximum header length results from a
68898 ** 3-byte type for each of the maximum of 32768 columns plus three
68899 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68900 */
68901 if( u.ap.offset > 98307 ){
68902 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++;
68951 }else{
68952 u.ap.zIdx += sqlite3GetVarint32(u.ap.zIdx, &u.ap.t);
68953 }
68954 u.ap.aType[u.ap.i] = u.ap.t;
68955 u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
68956 u.ap.offset += u.ap.szField;
68957 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:
 
 
 
 
 
 
69050 UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69051 REGISTER_TRACE(pOp->p3, u.ap.pDest);
69052 break;
69053 }
69054
@@ -69820,10 +69785,12 @@
69820 u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
69821 }else if( pOp->p4type==P4_INT32 ){
69822 u.az.nField = pOp->p4.i;
69823 }
69824 assert( pOp->p1>=0 );
 
 
69825 u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
69826 if( u.az.pCur==0 ) goto no_mem;
69827 u.az.pCur->nullRow = 1;
69828 u.az.pCur->isOrdered = 1;
69829 rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
@@ -69833,16 +69800,15 @@
69833
69834 /* Since it performs no memory allocation or IO, the only value that
69835 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69836 assert( rc==SQLITE_OK );
69837
69838 /* Set the VdbeCursor.isTable and isIndex variables. Previous versions of
69839 ** SQLite used to check if the root-page flags were sane at this point
69840 ** and report database corruption if they were not, but this check has
69841 ** since moved into the btree layer. */
69842 u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
69843 u.az.pCur->isIndex = !u.az.pCur->isTable;
69844 break;
69845 }
69846
69847 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69848 ** Synopsis: nColumn=P2
@@ -69882,10 +69848,11 @@
69882 SQLITE_OPEN_CREATE |
69883 SQLITE_OPEN_EXCLUSIVE |
69884 SQLITE_OPEN_DELETEONCLOSE |
69885 SQLITE_OPEN_TRANSIENT_DB;
69886 assert( pOp->p1>=0 );
 
69887 u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69888 if( u.ba.pCx==0 ) goto no_mem;
69889 u.ba.pCx->nullRow = 1;
69890 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
69891 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
@@ -69914,11 +69881,10 @@
69914 rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
69915 u.ba.pCx->isTable = 1;
69916 }
69917 }
69918 u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69919 u.ba.pCx->isIndex = !u.ba.pCx->isTable;
69920 break;
69921 }
69922
69923 /* Opcode: SorterOpen P1 * * P4 *
69924 **
@@ -69929,16 +69895,17 @@
69929 case OP_SorterOpen: {
69930 #if 0 /* local variables moved into u.bb */
69931 VdbeCursor *pCx;
69932 #endif /* local variables moved into u.bb */
69933
 
 
69934 u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69935 if( u.bb.pCx==0 ) goto no_mem;
69936 u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69937 assert( u.bb.pCx->pKeyInfo->db==db );
69938 assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
69939 u.bb.pCx->isSorter = 1;
69940 rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
69941 break;
69942 }
69943
69944 /* Opcode: OpenPseudo P1 P2 P3 * P5
@@ -69962,16 +69929,16 @@
69962 #if 0 /* local variables moved into u.bc */
69963 VdbeCursor *pCx;
69964 #endif /* local variables moved into u.bc */
69965
69966 assert( pOp->p1>=0 );
 
69967 u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69968 if( u.bc.pCx==0 ) goto no_mem;
69969 u.bc.pCx->nullRow = 1;
69970 u.bc.pCx->pseudoTableReg = pOp->p2;
69971 u.bc.pCx->isTable = 1;
69972 u.bc.pCx->isIndex = 0;
69973 u.bc.pCx->multiPseudo = pOp->p5;
69974 break;
69975 }
69976
69977 /* Opcode: Close P1 * * * *
@@ -70801,11 +70768,11 @@
70801 VdbeCursor *pC;
70802 #endif /* local variables moved into u.bl */
70803
70804 pOut = &aMem[pOp->p2];
70805 u.bl.pC = p->apCsr[pOp->p1];
70806 assert( u.bl.pC->isSorter );
70807 rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
70808 break;
70809 }
70810
70811 /* Opcode: RowData P1 P2 * * *
@@ -70843,13 +70810,13 @@
70843 memAboutToChange(p, pOut);
70844
70845 /* Note that RowKey and RowData are really exactly the same instruction */
70846 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70847 u.bm.pC = p->apCsr[pOp->p1];
70848 assert( u.bm.pC->isSorter==0 );
70849 assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData );
70850 assert( u.bm.pC->isIndex || pOp->opcode==OP_RowData );
70851 assert( u.bm.pC!=0 );
70852 assert( u.bm.pC->nullRow==0 );
70853 assert( u.bm.pC->pseudoTableReg==0 );
70854 assert( u.bm.pC->pCursor!=0 );
70855 u.bm.pCrsr = u.bm.pC->pCursor;
@@ -70862,11 +70829,11 @@
70862 */
70863 assert( u.bm.pC->deferredMoveto==0 );
70864 rc = sqlite3VdbeCursorMoveto(u.bm.pC);
70865 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70866
70867 if( u.bm.pC->isIndex ){
70868 assert( !u.bm.pC->isTable );
70869 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
70870 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70871 if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70872 goto too_big;
@@ -70882,11 +70849,11 @@
70882 if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
70883 goto no_mem;
70884 }
70885 pOut->n = u.bm.n;
70886 MemSetTypeFlag(pOut, MEM_Blob);
70887 if( u.bm.pC->isIndex ){
70888 rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70889 }else{
70890 rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70891 }
70892 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
@@ -70959,10 +70926,11 @@
70959 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70960 u.bo.pC = p->apCsr[pOp->p1];
70961 assert( u.bo.pC!=0 );
70962 u.bo.pC->nullRow = 1;
70963 u.bo.pC->rowidIsValid = 0;
 
70964 assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
70965 if( u.bo.pC->pCursor ){
70966 sqlite3BtreeClearCursor(u.bo.pC->pCursor);
70967 }
70968 break;
@@ -71038,19 +71006,18 @@
71038 #endif /* local variables moved into u.bq */
71039
71040 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71041 u.bq.pC = p->apCsr[pOp->p1];
71042 assert( u.bq.pC!=0 );
71043 assert( u.bq.pC->isSorter==(pOp->opcode==OP_SorterSort) );
71044 u.bq.res = 1;
71045 if( isSorter(u.bq.pC) ){
71046 rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
71047 }else{
71048 u.bq.pCrsr = u.bq.pC->pCursor;
71049 assert( u.bq.pCrsr );
71050 rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);
71051 u.bq.pC->atFirst = u.bq.res==0 ?1:0;
71052 u.bq.pC->deferredMoveto = 0;
71053 u.bq.pC->cacheStatus = CACHE_STALE;
71054 u.bq.pC->rowidIsValid = 0;
71055 }
71056 u.bq.pC->nullRow = (u8)u.bq.res;
@@ -71066,69 +71033,85 @@
71066 ** Advance cursor P1 so that it points to the next key/data pair in its
71067 ** table or index. If there are no more key/value pairs then fall through
71068 ** to the following instruction. But if the cursor advance was successful,
71069 ** jump immediately to P2.
71070 **
71071 ** The P1 cursor must be for a real table, not a pseudo-table.
 
71072 **
71073 ** P4 is always of type P4_ADVANCE. The function pointer points to
71074 ** sqlite3BtreeNext().
71075 **
71076 ** If P5 is positive and the jump is taken, then event counter
71077 ** number P5-1 in the prepared statement is incremented.
71078 **
71079 ** See also: Prev
 
 
 
 
 
71080 */
71081 /* Opcode: Prev P1 P2 * * P5
71082 **
71083 ** Back up cursor P1 so that it points to the previous key/data pair in its
71084 ** table or index. If there is no previous key/value pairs then fall through
71085 ** to the following instruction. But if the cursor backup was successful,
71086 ** jump immediately to P2.
71087 **
71088 ** The P1 cursor must be for a real table, not a pseudo-table.
 
71089 **
71090 ** P4 is always of type P4_ADVANCE. The function pointer points to
71091 ** sqlite3BtreePrevious().
71092 **
71093 ** If P5 is positive and the jump is taken, then event counter
71094 ** number P5-1 in the prepared statement is incremented.
71095 */
71096 case OP_SorterNext: /* jump */
71097 case OP_Prev: /* jump */
71098 case OP_Next: { /* jump */
 
 
 
71099 #if 0 /* local variables moved into u.br */
71100 VdbeCursor *pC;
71101 int res;
71102 #endif /* local variables moved into u.br */
71103
 
 
 
 
 
 
 
 
 
 
71104 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71105 assert( pOp->p5<ArraySize(p->aCounter) );
71106 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;
71123 u.br.pC->cacheStatus = CACHE_STALE;
71124 if( u.br.res==0 ){
 
71125 pc = pOp->p2 - 1;
71126 p->aCounter[pOp->p5]++;
71127 #ifdef SQLITE_TEST
71128 sqlite3_search_count++;
71129 #endif
 
 
71130 }
71131 u.br.pC->rowidIsValid = 0;
71132 goto check_for_interrupt;
71133 }
71134
@@ -71155,11 +71138,11 @@
71155 #endif /* local variables moved into u.bs */
71156
71157 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71158 u.bs.pC = p->apCsr[pOp->p1];
71159 assert( u.bs.pC!=0 );
71160 assert( u.bs.pC->isSorter==(pOp->opcode==OP_SorterInsert) );
71161 pIn2 = &aMem[pOp->p2];
71162 assert( pIn2->flags & MEM_Blob );
71163 u.bs.pCrsr = u.bs.pC->pCursor;
71164 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
71165 assert( u.bs.pCrsr!=0 );
@@ -72446,11 +72429,10 @@
72446
72447 /* Initialize vdbe cursor object */
72448 u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
72449 if( u.cm.pCur ){
72450 u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
72451 u.cm.pCur->pModule = u.cm.pVtabCursor->pVtab->pModule;
72452 }else{
72453 db->mallocFailed = 1;
72454 u.cm.pModule->xClose(u.cm.pVtabCursor);
72455 }
72456 }
@@ -73017,22 +72999,23 @@
73017 assert( v->aVar[0].flags&MEM_Int );
73018 v->aVar[0].u.i = iRow;
73019
73020 rc = sqlite3_step(p->pStmt);
73021 if( rc==SQLITE_ROW ){
73022 u32 type = v->apCsr[0]->aType[p->iCol];
 
73023 if( type<12 ){
73024 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
73025 type==0?"null": type==7?"real": "integer"
73026 );
73027 rc = SQLITE_ERROR;
73028 sqlite3_finalize(p->pStmt);
73029 p->pStmt = 0;
73030 }else{
73031 p->iOffset = v->apCsr[0]->aOffset[p->iCol];
73032 p->nByte = sqlite3VdbeSerialTypeLen(type);
73033 p->pCsr = v->apCsr[0]->pCursor;
73034 sqlite3BtreeEnterCursor(p->pCsr);
73035 sqlite3BtreeCacheOverflow(p->pCsr);
73036 sqlite3BtreeLeaveCursor(p->pCsr);
73037 }
73038 }
@@ -75806,11 +75789,10 @@
75806 return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
75807 }
75808
75809 /* Resolve function names
75810 */
75811 case TK_CONST_FUNC:
75812 case TK_FUNCTION: {
75813 ExprList *pList = pExpr->x.pList; /* The argument list */
75814 int n = pList ? pList->nExpr : 0; /* Number of arguments */
75815 int no_such_func = 0; /* True if no such function exists */
75816 int wrong_num_args = 0; /* True if wrong number of arguments */
@@ -75819,11 +75801,10 @@
75819 int nId; /* Number of characters in function name */
75820 const char *zId; /* The function name. */
75821 FuncDef *pDef; /* Information about the function */
75822 u8 enc = ENC(pParse->db); /* The database encoding */
75823
75824 testcase( pExpr->op==TK_CONST_FUNC );
75825 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
75826 notValidPartIdxWhere(pParse, pNC, "functions");
75827 zId = pExpr->u.zToken;
75828 nId = sqlite3Strlen30(zId);
75829 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
@@ -75864,10 +75845,11 @@
75864 pNC->nErr++;
75865 }
75866 pExpr->op = TK_NULL;
75867 return WRC_Prune;
75868 }
 
75869 }
75870 #endif
75871 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
75872 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
75873 pNC->nErr++;
@@ -77781,13 +77763,16 @@
77781 return WRC_Abort;
77782 }
77783
77784 switch( pExpr->op ){
77785 /* Consider functions to be constant if all their arguments are constant
77786 ** and pWalker->u.i==2 */
 
77787 case TK_FUNCTION:
77788 if( pWalker->u.i==2 ) return 0;
 
 
77789 /* Fall through */
77790 case TK_ID:
77791 case TK_COLUMN:
77792 case TK_AGG_FUNCTION:
77793 case TK_AGG_COLUMN:
@@ -79213,11 +79198,10 @@
79213 }else{
79214 inReg = pInfo->aFunc[pExpr->iAgg].iMem;
79215 }
79216 break;
79217 }
79218 case TK_CONST_FUNC:
79219 case TK_FUNCTION: {
79220 ExprList *pFarg; /* List of function arguments */
79221 int nFarg; /* Number of function arguments */
79222 FuncDef *pDef; /* The function definition object */
79223 int nId; /* Length of the function name in bytes */
@@ -79226,12 +79210,10 @@
79226 int i; /* Loop counter */
79227 u8 enc = ENC(db); /* The text encoding used by this database */
79228 CollSeq *pColl = 0; /* A collating sequence */
79229
79230 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
79231 testcase( op==TK_CONST_FUNC );
79232 testcase( op==TK_FUNCTION );
79233 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
79234 pFarg = 0;
79235 }else{
79236 pFarg = pExpr->x.pList;
79237 }
@@ -79271,12 +79253,25 @@
79271 assert( nFarg>=1 );
79272 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
79273 break;
79274 }
79275
 
 
 
 
 
 
 
 
79276 if( pFarg ){
79277 r1 = sqlite3GetTempRange(pParse, nFarg);
 
 
 
 
 
79278
79279 /* For length() and typeof() functions with a column argument,
79280 ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
79281 ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
79282 ** loading.
@@ -79287,18 +79282,19 @@
79287 assert( pFarg->a[0].pExpr!=0 );
79288 exprOp = pFarg->a[0].pExpr->op;
79289 if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
79290 assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
79291 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;
79295 }
79296 }
79297
79298 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
79299 sqlite3ExprCodeExprList(pParse, pFarg, r1, 1);
 
79300 sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */
79301 }else{
79302 r1 = 0;
79303 }
79304 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -79318,26 +79314,18 @@
79318 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
79319 }else if( nFarg>0 ){
79320 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
79321 }
79322 #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 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
79332 if( !pColl ) pColl = db->pDfltColl;
79333 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
79334 }
79335 sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
79336 (char*)pDef, P4_FUNCDEF);
79337 sqlite3VdbeChangeP5(v, (u8)nFarg);
79338 if( nFarg ){
79339 sqlite3ReleaseTempRange(pParse, r1, nFarg);
79340 }
79341 break;
79342 }
79343 #ifndef SQLITE_OMIT_SUBQUERY
@@ -79569,10 +79557,32 @@
79569 }
79570 sqlite3ReleaseTempReg(pParse, regFree1);
79571 sqlite3ReleaseTempReg(pParse, regFree2);
79572 return inReg;
79573 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79574
79575 /*
79576 ** Generate code to evaluate an expression and store the results
79577 ** into a register. Return the register number where the results
79578 ** are stored.
@@ -79586,28 +79596,27 @@
79586 ** VDBE program, in order to factor it out of the evaluation loop.
79587 */
79588 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79589 int r2;
79590 pExpr = sqlite3ExprSkipCollate(pExpr);
79591 if( pParse->cookieGoto>0
79592 && pExpr->op!=TK_REGISTER
79593 && sqlite3ExprIsConstantNotJoin(pExpr)
79594 ){
79595 ExprList *p = pParse->pConstExpr;
79596 int i;
79597 *pReg = 0;
79598 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;
 
79602 }
79603 }
79604 }
79605 p = sqlite3ExprListAppend(pParse, p, sqlite3ExprDup(pParse->db, pExpr, 0));
79606 pParse->pConstExpr = p;
79607 r2 = ++pParse->nMem;
79608 if( p ) p->a[p->nExpr-1].u.iConstExprReg = r2;
79609 }else{
79610 int r1 = sqlite3GetTempReg(pParse);
79611 r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79612 if( r2==r1 ){
79613 *pReg = r1;
@@ -79793,11 +79802,10 @@
79793 sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
79794 break;
79795 }
79796
79797 case TK_AGG_FUNCTION:
79798 case TK_CONST_FUNC:
79799 case TK_FUNCTION: {
79800 ExprList *pFarg; /* List of function arguments */
79801 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
79802 pFarg = 0;
79803 }else{
@@ -79949,29 +79957,40 @@
79949 /*
79950 ** Generate code that pushes the value of every element of the given
79951 ** expression list into a sequence of registers beginning at target.
79952 **
79953 ** Return the number of elements evaluated.
 
 
 
 
 
 
79954 */
79955 SQLITE_PRIVATE int sqlite3ExprCodeExprList(
79956 Parse *pParse, /* Parsing context */
79957 ExprList *pList, /* The expression list to be coded */
79958 int target, /* Where to write results */
79959 int doHardCopy /* Make a hard copy of every element */
79960 ){
79961 struct ExprList_item *pItem;
79962 int i, n;
 
79963 assert( pList!=0 );
79964 assert( target>0 );
79965 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
79966 n = pList->nExpr;
 
79967 for(pItem=pList->a, i=0; i<n; i++, pItem++){
79968 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);
 
 
 
79973 }
79974 }
79975 return n;
79976 }
79977
@@ -91338,24 +91357,24 @@
91338 FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
91339 FUNCTION(hex, 1, 0, 0, hexFunc ),
91340 FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
91341 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
91342 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
91343 FUNCTION(random, 0, 0, 0, randomFunc ),
91344 FUNCTION(randomblob, 1, 0, 0, randomBlob ),
91345 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
91346 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
91347 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
91348 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
91349 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
91350 FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
91351 FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
91352 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
91353 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 ),
91357 FUNCTION(replace, 3, 0, 0, replaceFunc ),
91358 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
91359 #ifdef SQLITE_SOUNDEX
91360 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
91361 #endif
@@ -100003,11 +100022,12 @@
100003 }else if( eDest!=SRT_Exists ){
100004 /* If the destination is an EXISTS(...) expression, the actual
100005 ** values returned by the SELECT are not required.
100006 */
100007 sqlite3ExprCacheClear(pParse);
100008 sqlite3ExprCodeExprList(pParse, pEList, regResult, eDest==SRT_Output);
 
100009 }
100010 nColumn = nResultCol;
100011
100012 /* If the DISTINCT keyword was present on the SELECT statement
100013 ** and this row has been seen before, then do not make this row
@@ -103289,11 +103309,11 @@
103289 ExprList *pList = pF->pExpr->x.pList;
103290 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
103291 if( pList ){
103292 nArg = pList->nExpr;
103293 regAgg = sqlite3GetTempRange(pParse, nArg);
103294 sqlite3ExprCodeExprList(pParse, pList, regAgg, 1);
103295 }else{
103296 nArg = 0;
103297 regAgg = 0;
103298 }
103299 if( pF->iDistinct>=0 ){
@@ -110765,11 +110785,11 @@
110765 if( eType==IN_INDEX_ROWID ){
110766 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
110767 }else{
110768 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
110769 }
110770 pIn->eEndLoopOp = bRev ? OP_Prev : OP_Next;
110771 sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
110772 }else{
110773 pLevel->u.in.nIn = 0;
110774 }
110775 #endif
@@ -117027,16 +117047,11 @@
117027 spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
117028 }
117029 break;
117030 case 200: /* term ::= CTIME_KW */
117031 {
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 }
117038 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
117039 }
117040 break;
117041 case 201: /* expr ::= expr AND expr */
117042 case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
117043
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.2"
139 #define SQLITE_VERSION_NUMBER 3008002
140 #define SQLITE_SOURCE_ID "2013-11-21 23:37:02 3d47a556f0074e39b880186fb7661b1b8955f742"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -8140,13 +8140,12 @@
8140 #define TK_UNCLOSED_STRING 151
8141 #define TK_FUNCTION 152
8142 #define TK_COLUMN 153
8143 #define TK_AGG_FUNCTION 154
8144 #define TK_AGG_COLUMN 155
8145 #define TK_UMINUS 156
8146 #define TK_UPLUS 157
 
8147
8148 /************** End of parse.h ***********************************************/
8149 /************** Continuing where we left off in sqliteInt.h ******************/
8150 #include <stdio.h>
8151 #include <stdlib.h>
@@ -8778,12 +8777,12 @@
8777 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int *pRes);
8778 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
8779 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int *pRes);
8780 SQLITE_PRIVATE int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
8781 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
8782 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
8783 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
8784 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
8785 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
8786 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
8787 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
8788
@@ -9021,87 +9020,87 @@
9020 #define OP_Function 1 /* synopsis: r[P3]=func(r[P2@P5]) */
9021 #define OP_Savepoint 2
9022 #define OP_AutoCommit 3
9023 #define OP_Transaction 4
9024 #define OP_SorterNext 5
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
9038 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
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] */
9088 #define OP_Or 69 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9089 #define OP_And 70 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9090 #define OP_InsertInt 71 /* synopsis: intkey=P3 data=r[P2] */
9091 #define OP_Delete 72
9092 #define OP_ResetCount 73
9093 #define OP_IsNull 74 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9094 #define OP_NotNull 75 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9095 #define OP_Ne 76 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9096 #define OP_Eq 77 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9097 #define OP_Gt 78 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9098 #define OP_Le 79 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9099 #define OP_Lt 80 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9100 #define OP_Ge 81 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9101 #define OP_SorterCompare 82 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9102 #define OP_BitAnd 83 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9103 #define OP_BitOr 84 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9104 #define OP_ShiftLeft 85 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9105 #define OP_ShiftRight 86 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9106 #define OP_Add 87 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9108,68 +9107,70 @@
9107 #define OP_Subtract 88 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9108 #define OP_Multiply 89 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9109 #define OP_Divide 90 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9110 #define OP_Remainder 91 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9111 #define OP_Concat 92 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9112 #define OP_SorterData 93 /* synopsis: r[P2]=data */
9113 #define OP_BitNot 94 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9114 #define OP_String8 95 /* same as TK_STRING, synopsis: r[P2]='P4' */
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 */
9150 #define OP_Real 131 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
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
9161 #define OP_ToText 142 /* same as TK_TO_TEXT */
9162 #define OP_ToBlob 143 /* same as TK_TO_BLOB */
9163 #define OP_ToNumeric 144 /* same as TK_TO_NUMERIC */
9164 #define OP_ToInt 145 /* same as TK_TO_INT */
9165 #define OP_ToReal 146 /* same as TK_TO_REAL */
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
9172
9173
9174 /* Properties such as "out2" or "jump" that are specified in
9175 ** comments following the "case" for each opcode in the vdbe.c
9176 ** are encoded into bitvectors as follows:
@@ -9181,28 +9182,29 @@
9182 #define OPFLG_IN3 0x0010 /* in3: P3 is an input */
9183 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9184 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9185 #define OPFLG_INITIALIZER {\
9186 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
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,\
9195 /* 72 */ 0x00, 0x00, 0x05, 0x05, 0x15, 0x15, 0x15, 0x15,\
9196 /* 80 */ 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c,\
9197 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00, 0x24, 0x02,\
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,}
9206
9207 /************** End of opcodes.h *********************************************/
9208 /************** Continuing where we left off in vdbe.h ***********************/
9209
9210 /*
@@ -10336,10 +10338,17 @@
10338 #else
10339 #define OptimizationDisabled(db, mask) 0
10340 #define OptimizationEnabled(db, mask) 1
10341 #endif
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
10350 /*
10351 ** Possible values for the sqlite.magic field.
10352 ** The numbers are obtained at random and have no special meaning, other
10353 ** than being distinct from one another.
10354 */
@@ -10402,10 +10411,11 @@
10411 #define SQLITE_FUNC_LENGTH 0x040 /* Built-in length() function */
10412 #define SQLITE_FUNC_TYPEOF 0x080 /* Built-in typeof() function */
10413 #define SQLITE_FUNC_COUNT 0x100 /* Built-in count(*) aggregate */
10414 #define SQLITE_FUNC_COALESCE 0x200 /* Built-in coalesce() or ifnull() */
10415 #define SQLITE_FUNC_UNLIKELY 0x400 /* Built-in unlikely() function */
10416 #define SQLITE_FUNC_CONSTANT 0x800 /* Constant inputs give a constant output */
10417
10418 /*
10419 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
10420 ** used to create the initializers for the FuncDef structures.
10421 **
@@ -10414,10 +10424,13 @@
10424 ** implemented by C function xFunc that accepts nArg arguments. The
10425 ** value passed as iArg is cast to a (void*) and made available
10426 ** as the user-data (sqlite3_user_data()) for the function. If
10427 ** argument bNC is true, then the SQLITE_FUNC_NEEDCOLL flag is set.
10428 **
10429 ** VFUNCTION(zName, nArg, iArg, bNC, xFunc)
10430 ** Like FUNCTION except it omits the SQLITE_FUNC_CONSTANT flag.
10431 **
10432 ** AGGREGATE(zName, nArg, iArg, bNC, xStep, xFinal)
10433 ** Used to create an aggregate function definition implemented by
10434 ** the C functions xStep and xFinal. The first four parameters
10435 ** are interpreted in the same way as the first 4 parameters to
10436 ** FUNCTION().
@@ -10429,20 +10442,24 @@
10442 ** available as the function user-data (sqlite3_user_data()). The
10443 ** FuncDef.flags variable is set to the value passed as the flags
10444 ** parameter.
10445 */
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) \
10450 {nArg, SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10451 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10452 #define FUNCTION2(zName, nArg, iArg, bNC, xFunc, extraFlags) \
10453 {nArg,SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL)|extraFlags,\
10454 SQLITE_INT_TO_PTR(iArg), 0, xFunc, 0, 0, #zName, 0, 0}
10455 #define STR_FUNCTION(zName, nArg, pArg, bNC, xFunc) \
10456 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|(bNC*SQLITE_FUNC_NEEDCOLL), \
10457 pArg, 0, xFunc, 0, 0, #zName, 0, 0}
10458 #define LIKEFUNC(zName, nArg, arg, flags) \
10459 {nArg, SQLITE_FUNC_CONSTANT|SQLITE_UTF8|flags, \
10460 (void *)arg, 0, likeFunc, 0, 0, #zName, 0, 0}
10461 #define AGGREGATE(zName, nArg, arg, nc, xStep, xFinal) \
10462 {nArg, SQLITE_UTF8|(nc*SQLITE_FUNC_NEEDCOLL), \
10463 SQLITE_INT_TO_PTR(arg), 0, 0, xStep,xFinal,#zName,0,0}
10464
10465 /*
@@ -11098,10 +11115,11 @@
11115 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
11116 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
11117 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
11118 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
11119 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
11120 #define EP_Constant 0x080000 /* Node is a constant */
11121
11122 /*
11123 ** These macros can be used to test, set, or clear bits in the
11124 ** Expr.flags field.
11125 */
@@ -11159,10 +11177,11 @@
11177 char *zName; /* Token associated with this expression */
11178 char *zSpan; /* Original text of the expression */
11179 u8 sortOrder; /* 1 for DESC or 0 for ASC */
11180 unsigned done :1; /* A flag to indicate when processing is finished */
11181 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
11182 unsigned reusable :1; /* Constant expression is reusable */
11183 union {
11184 struct {
11185 u16 iOrderByCol; /* For ORDER BY, column number in result set */
11186 u16 iAlias; /* Index into Parse.aAlias[] for zName */
11187 } x;
@@ -12153,14 +12172,17 @@
12172 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
12173 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
12174 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
12175 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12176 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
12177 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
12178 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12179 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12180 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, 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 */
12184 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12185 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
12186 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
12187 SQLITE_PRIVATE Table *sqlite3LocateTable(Parse*,int isView,const char*, const char*);
12188 SQLITE_PRIVATE Table *sqlite3LocateTableItem(Parse*,int isView,struct SrcList_item *);
@@ -13386,11 +13408,11 @@
13408 typedef struct VdbeOp Op;
13409
13410 /*
13411 ** Boolean values
13412 */
13413 typedef unsigned Bool;
13414
13415 /* Opaque type used by code in vdbesort.c */
13416 typedef struct VdbeSorter VdbeSorter;
13417
13418 /* Opaque type used by the explainer */
@@ -13403,42 +13425,39 @@
13425 ** A cursor is a pointer into a single BTree within a database file.
13426 ** The cursor can seek to a BTree entry with a particular key, or
13427 ** loop over all entries of the Btree. You can also insert new BTree
13428 ** entries or retrieve the key or data from the entry that the cursor
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.
13433 **
13434 ** Every cursor that the virtual machine has open is represented by an
13435 ** instance of the following structure.
13436 */
13437 struct VdbeCursor {
13438 BtCursor *pCursor; /* The cursor structure of the backend */
13439 Btree *pBt; /* Separate file holding temporary table */
13440 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
13441 int seekResult; /* Result of previous sqlite3BtreeMoveto() */
13442 int pseudoTableReg; /* Register holding pseudotable content. */
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 */
 
 
13453 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
 
13454 i64 seqCount; /* Sequence counter */
13455 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13456 i64 lastRowid; /* Rowid being deleted by OP_Delete */
13457 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
13458
 
 
 
13459 /* Cached information about the header for the data record that the
13460 ** cursor is currently pointing to. Only valid if cacheStatus matches
13461 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
13462 ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
13463 ** the cache is out of date.
@@ -13445,14 +13464,18 @@
13464 **
13465 ** aRow might point to (ephemeral) data for the current row, or it might
13466 ** be NULL.
13467 */
13468 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
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[] */
13477 };
13478 typedef struct VdbeCursor VdbeCursor;
13479
13480 /*
13481 ** When a sub-program is executed (OP_Program), a structure of this type
@@ -13773,11 +13796,11 @@
13796 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem*);
13797 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem*);
13798 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem*);
13799 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
13800 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
13801 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
13802 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
13803 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
13804 #define VdbeMemRelease(X) \
13805 if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
13806 sqlite3VdbeMemReleaseExternal(X);
@@ -22901,87 +22924,87 @@
22924 /* 1 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
22925 /* 2 */ "Savepoint" OpHelp(""),
22926 /* 3 */ "AutoCommit" OpHelp(""),
22927 /* 4 */ "Transaction" OpHelp(""),
22928 /* 5 */ "SorterNext" OpHelp(""),
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(""),
22942 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
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]"),
22992 /* 69 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
22993 /* 70 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
22994 /* 71 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
22995 /* 72 */ "Delete" OpHelp(""),
22996 /* 73 */ "ResetCount" OpHelp(""),
22997 /* 74 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
22998 /* 75 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
22999 /* 76 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23000 /* 77 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23001 /* 78 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23002 /* 79 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23003 /* 80 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23004 /* 81 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23005 /* 82 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23006 /* 83 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23007 /* 84 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23008 /* 85 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23009 /* 86 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23010 /* 87 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -22988,68 +23011,70 @@
23011 /* 88 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23012 /* 89 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23013 /* 90 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23014 /* 91 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23015 /* 92 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23016 /* 93 */ "SorterData" OpHelp("r[P2]=data"),
23017 /* 94 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23018 /* 95 */ "String8" OpHelp("r[P2]='P4'"),
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"),
23054 /* 131 */ "Real" OpHelp("r[P2]=P4"),
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(""),
23065 /* 142 */ "ToText" OpHelp(""),
23066 /* 143 */ "ToBlob" OpHelp(""),
23067 /* 144 */ "ToNumeric" OpHelp(""),
23068 /* 145 */ "ToInt" OpHelp(""),
23069 /* 146 */ "ToReal" 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(""),
23076 };
23077 return azName[i];
23078 }
23079 #endif
23080
@@ -54458,11 +54483,11 @@
54483 ** page of the database. The data might change or move the next time
54484 ** any btree routine is called.
54485 */
54486 static const unsigned char *fetchPayload(
54487 BtCursor *pCur, /* Cursor pointing to entry to read from */
54488 u32 *pAmt, /* Write the number of available bytes here */
54489 int skipKey /* read beginning at data if this is true */
54490 ){
54491 unsigned char *aPayload;
54492 MemPage *pPage;
54493 u32 nKey;
@@ -54508,20 +54533,20 @@
54533 ** this routine.
54534 **
54535 ** These routines is used to get quick access to key and data
54536 ** in the common case where no overflow pages are used.
54537 */
54538 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor *pCur, u32 *pAmt){
54539 const void *p = 0;
54540 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54541 assert( cursorHoldsMutex(pCur) );
54542 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54543 p = (const void*)fetchPayload(pCur, pAmt, 0);
54544 }
54545 return p;
54546 }
54547 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor *pCur, u32 *pAmt){
54548 const void *p = 0;
54549 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
54550 assert( cursorHoldsMutex(pCur) );
54551 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
54552 p = (const void*)fetchPayload(pCur, pAmt, 1);
@@ -60420,17 +60445,17 @@
60445 ** If this routine fails for any reason (malloc returns NULL or unable
60446 ** to read from the disk) then the pMem is left in an inconsistent state.
60447 */
60448 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(
60449 BtCursor *pCur, /* Cursor pointing at record to retrieve. */
60450 u32 offset, /* Offset from the start of data to return bytes from. */
60451 u32 amt, /* Number of bytes to return. */
60452 int key, /* If true, retrieve from the btree key, not data. */
60453 Mem *pMem /* OUT: Return data in this Mem structure. */
60454 ){
60455 char *zData; /* Data from the btree layer */
60456 u32 available = 0; /* Number of bytes available on the local btree page */
60457 int rc = SQLITE_OK; /* Return code */
60458
60459 assert( sqlite3BtreeCursorIsValid(pCur) );
60460
60461 /* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
@@ -60441,11 +60466,11 @@
60466 }else{
60467 zData = (char *)sqlite3BtreeDataFetch(pCur, &available);
60468 }
60469 assert( zData!=0 );
60470
60471 if( offset+amt<=available ){
60472 sqlite3VdbeMemRelease(pMem);
60473 pMem->z = &zData[offset];
60474 pMem->flags = MEM_Blob|MEM_Ephem;
60475 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60476 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
@@ -60460,11 +60485,11 @@
60485 pMem->z[amt+1] = 0;
60486 if( rc!=SQLITE_OK ){
60487 sqlite3VdbeMemRelease(pMem);
60488 }
60489 }
60490 pMem->n = (int)amt;
60491
60492 return rc;
60493 }
60494
60495 /* This function is only available internally, it is not part of the
@@ -61391,16 +61416,18 @@
61416 if( n>nMaxArgs ) nMaxArgs = n;
61417 break;
61418 }
61419 #endif
61420 case OP_Next:
61421 case OP_NextIfOpen:
61422 case OP_SorterNext: {
61423 pOp->p4.xAdvance = sqlite3BtreeNext;
61424 pOp->p4type = P4_ADVANCE;
61425 break;
61426 }
61427 case OP_Prev:
61428 case OP_PrevIfOpen: {
61429 pOp->p4.xAdvance = sqlite3BtreePrevious;
61430 pOp->p4type = P4_ADVANCE;
61431 break;
61432 }
61433 }
@@ -62612,11 +62639,11 @@
62639 sqlite3BtreeCloseCursor(pCx->pCursor);
62640 }
62641 #ifndef SQLITE_OMIT_VIRTUALTABLE
62642 if( pCx->pVtabCursor ){
62643 sqlite3_vtab_cursor *pVtabCursor = pCx->pVtabCursor;
62644 const sqlite3_module *pModule = pVtabCursor->pVtab->pModule;
62645 p->inVtabMethod = 1;
62646 pModule->xClose(pVtabCursor);
62647 p->inVtabMethod = 0;
62648 }
62649 #endif
@@ -63596,11 +63623,11 @@
63623 #ifdef SQLITE_TEST
63624 sqlite3_search_count++;
63625 #endif
63626 p->deferredMoveto = 0;
63627 p->cacheStatus = CACHE_STALE;
63628 }else if( p->pCursor ){
63629 int hasMoved;
63630 int rc = sqlite3BtreeCursorHasMoved(p->pCursor, &hasMoved);
63631 if( rc ) return rc;
63632 if( hasMoved ){
63633 p->cacheStatus = CACHE_STALE;
@@ -64141,11 +64168,11 @@
64168 assert( rc==SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
64169 assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
64170
64171 /* Read in the complete content of the index entry */
64172 memset(&m, 0, sizeof(m));
64173 rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
64174 if( rc ){
64175 return rc;
64176 }
64177
64178 /* The index entry must begin with a header size */
@@ -64219,11 +64246,11 @@
64246 if( nCellKey<=0 || nCellKey>0x7fffffff ){
64247 *res = 0;
64248 return SQLITE_CORRUPT_BKPT;
64249 }
64250 memset(&m, 0, sizeof(m));
64251 rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
64252 if( rc ){
64253 return rc;
64254 }
64255 assert( pUnpacked->flags & UNPACKED_PREFIX_MATCH );
64256 *res = sqlite3VdbeRecordCompare(m.n, m.z, pUnpacked);
@@ -66154,13 +66181,12 @@
66181 Mem *pMem = &p->aMem[p->nMem-iCur];
66182
66183 int nByte;
66184 VdbeCursor *pCx = 0;
66185 nByte =
66186 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
66187 (isBtreeCursor?sqlite3BtreeCursorSize():0);
 
66188
66189 assert( iCur<p->nCursor );
66190 if( p->apCsr[iCur] ){
66191 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
66192 p->apCsr[iCur] = 0;
@@ -66168,16 +66194,13 @@
66194 if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){
66195 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
66196 memset(pCx, 0, sizeof(VdbeCursor));
66197 pCx->iDb = iDb;
66198 pCx->nField = nField;
 
 
 
66199 if( isBtreeCursor ){
66200 pCx->pCursor = (BtCursor*)
66201 &pMem->z[ROUND8(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
66202 sqlite3BtreeCursorZero(pCx->pCursor);
66203 }
66204 }
66205 return pCx;
66206 }
@@ -66669,31 +66692,26 @@
66692 } an;
66693 struct OP_IfNot_stack_vars {
66694 int c;
66695 } ao;
66696 struct OP_Column_stack_vars {
 
66697 i64 payloadSize64; /* Number of bytes in the record */
 
66698 int p2; /* column number to retrieve */
66699 VdbeCursor *pC; /* The VDBE cursor */
 
66700 BtCursor *pCrsr; /* The BTree cursor */
66701 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
66702 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
 
66703 int len; /* The length of the serialized data for the column */
66704 int i; /* Loop counter */
 
66705 Mem *pDest; /* Where to write the extracted value */
66706 Mem sMem; /* For storing the record being decoded */
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 */
66710 u32 offset; /* Offset into the data */
66711 u32 szField; /* Number of bytes in the content of a field */
66712 u32 avail; /* Number of bytes of available data */
 
66713 u32 t; /* A type code from the record header */
66714 Mem *pReg; /* PseudoTable input register */
66715 } ap;
66716 struct OP_Affinity_stack_vars {
66717 const char *zAffinity; /* The affinity to be applied */
@@ -66852,11 +66870,11 @@
66870 struct OP_Rewind_stack_vars {
66871 VdbeCursor *pC;
66872 BtCursor *pCrsr;
66873 int res;
66874 } bq;
66875 struct OP_SorterNext_stack_vars {
66876 VdbeCursor *pC;
66877 int res;
66878 } br;
66879 struct OP_IdxInsert_stack_vars {
66880 VdbeCursor *pC;
@@ -67553,19 +67571,19 @@
67571 int n; /* Number of registers left to copy */
67572 int p1; /* Register to copy from */
67573 int p2; /* Register to copy to */
67574 #endif /* local variables moved into u.ae */
67575
67576 u.ae.n = pOp->p3;
67577 u.ae.p1 = pOp->p1;
67578 u.ae.p2 = pOp->p2;
67579 assert( u.ae.n>=0 && u.ae.p1>0 && u.ae.p2>0 );
67580 assert( u.ae.p1+u.ae.n<=u.ae.p2 || u.ae.p2+u.ae.n<=u.ae.p1 );
67581
67582 pIn1 = &aMem[u.ae.p1];
67583 pOut = &aMem[u.ae.p2];
67584 do{
67585 assert( pOut<=&aMem[(p->nMem-p->nCursor)] );
67586 assert( pIn1<=&aMem[(p->nMem-p->nCursor)] );
67587 assert( memIsValid(pIn1) );
67588 memAboutToChange(p, pOut);
67589 u.ae.zMalloc = pOut->zMalloc;
@@ -67578,11 +67596,11 @@
67596 #endif
67597 pIn1->zMalloc = u.ae.zMalloc;
67598 REGISTER_TRACE(u.ae.p2++, pOut);
67599 pIn1++;
67600 pOut++;
67601 }while( u.ae.n-- );
67602 break;
67603 }
67604
67605 /* Opcode: Copy P1 P2 P3 * *
67606 ** Synopsis: r[P2@P3]=r[P1@P3]
@@ -67969,22 +67987,21 @@
67987 REGISTER_TRACE(pOp->p2+u.aj.i, u.aj.pArg);
67988 }
67989
67990 assert( pOp->p4type==P4_FUNCDEF );
67991 u.aj.ctx.pFunc = pOp->p4.pFunc;
 
 
 
 
67992 u.aj.ctx.iOp = pc;
67993 u.aj.ctx.pVdbe = p;
67994
67995 /* The output cell may already have a buffer allocated. Move
67996 ** the pointer to u.aj.ctx.s so in case the user-function can use
67997 ** the already allocated buffer instead of allocating a new one.
67998 */
67999 memcpy(&u.aj.ctx.s, pOut, sizeof(Mem));
68000 pOut->flags = MEM_Null;
68001 pOut->xDel = 0;
68002 pOut->zMalloc = 0;
68003 MemSetTypeFlag(&u.aj.ctx.s, MEM_Null);
68004
68005 u.aj.ctx.fErrorOrAux = 0;
68006 if( u.aj.ctx.pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
68007 assert( pOp>aOp );
@@ -68015,11 +68032,12 @@
68032 sqlite3VdbeDeleteAuxData(p, pc, pOp->p1);
68033 }
68034
68035 /* Copy the result of the function into register P3 */
68036 sqlite3VdbeChangeEncoding(&u.aj.ctx.s, encoding);
68037 assert( pOut->flags==MEM_Null );
68038 memcpy(pOut, &u.aj.ctx.s, sizeof(Mem));
68039 if( sqlite3VdbeMemTooBig(pOut) ){
68040 goto too_big;
68041 }
68042
68043 #if 0
@@ -68142,21 +68160,23 @@
68160 ** without data loss, then jump immediately to P2, or if P2==0
68161 ** raise an SQLITE_MISMATCH exception.
68162 */
68163 case OP_MustBeInt: { /* jump, in1 */
68164 pIn1 = &aMem[pOp->p1];
 
68165 if( (pIn1->flags & MEM_Int)==0 ){
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);
68178 break;
68179 }
68180
68181 #ifndef SQLITE_OMIT_FLOATING_POINT
68182 /* Opcode: RealAffinity P1 * * * *
@@ -68740,156 +68760,108 @@
68760 ** or typeof() function, respectively. The loading of large blobs can be
68761 ** skipped for length() and all content loading can be skipped for typeof().
68762 */
68763 case OP_Column: {
68764 #if 0 /* local variables moved into u.ap */
 
68765 i64 payloadSize64; /* Number of bytes in the record */
 
68766 int p2; /* column number to retrieve */
68767 VdbeCursor *pC; /* The VDBE cursor */
 
68768 BtCursor *pCrsr; /* The BTree cursor */
68769 u32 *aType; /* aType[i] holds the numeric type of the i-th column */
68770 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
 
68771 int len; /* The length of the serialized data for the column */
68772 int i; /* Loop counter */
 
68773 Mem *pDest; /* Where to write the extracted value */
68774 Mem sMem; /* For storing the record being decoded */
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 */
68778 u32 offset; /* Offset into the data */
68779 u32 szField; /* Number of bytes in the content of a field */
68780 u32 avail; /* Number of bytes of available data */
 
68781 u32 t; /* A type code from the record header */
68782 Mem *pReg; /* PseudoTable input register */
68783 #endif /* local variables moved into u.ap */
68784
 
 
68785 u.ap.p2 = pOp->p2;
 
 
 
68786 assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
68787 u.ap.pDest = &aMem[pOp->p3];
68788 memAboutToChange(p, u.ap.pDest);
68789 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68790 u.ap.pC = p->apCsr[pOp->p1];
 
 
 
 
 
 
 
 
 
 
 
 
 
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 #ifndef SQLITE_OMIT_VIRTUALTABLE
68796 assert( u.ap.pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
68797 #endif
68798 u.ap.pCrsr = u.ap.pC->pCursor;
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 ){
68806 if( u.ap.pC->nullRow ){
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 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68851 u.ap.pC->cacheStatus = p->cacheCtr;
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 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68863
68864 /* Make sure a corrupt database has not given us an oversize header.
68865 ** Do this now to avoid an oversize memory allocation.
68866 **
68867 ** Type entries can be between 1 and 5 bytes each. But 4 and 5 byte
@@ -68896,159 +68868,152 @@
68868 ** types use so much data space that there can only be 4096 and 32 of
68869 ** them, respectively. So the maximum header length results from a
68870 ** 3-byte type for each of the maximum of 32768 columns plus three
68871 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
68872 */
68873 if( u.ap.offset > 98307 || u.ap.offset > u.ap.pC->payloadSize ){
68874 rc = SQLITE_CORRUPT_BKPT;
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++;
 
 
 
 
 
 
 
 
 
 
 
 
 
68910 }else{
68911 u.ap.zHdr += sqlite3GetVarint32(u.ap.zHdr, &u.ap.t);
68912 }
68913 u.ap.aType[u.ap.i] = u.ap.t;
68914 u.ap.szField = sqlite3VdbeSerialTypeLen(u.ap.t);
68915 u.ap.offset += u.ap.szField;
68916 if( u.ap.offset<u.ap.szField ){ /* True if u.ap.offset overflows */
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:
69015 UPDATE_MAX_BLOBSIZE(u.ap.pDest);
69016 REGISTER_TRACE(pOp->p3, u.ap.pDest);
69017 break;
69018 }
69019
@@ -69820,10 +69785,12 @@
69785 u.az.nField = u.az.pKeyInfo->nField+u.az.pKeyInfo->nXField;
69786 }else if( pOp->p4type==P4_INT32 ){
69787 u.az.nField = pOp->p4.i;
69788 }
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 */
69792 u.az.pCur = allocateCursor(p, pOp->p1, u.az.nField, u.az.iDb, 1);
69793 if( u.az.pCur==0 ) goto no_mem;
69794 u.az.pCur->nullRow = 1;
69795 u.az.pCur->isOrdered = 1;
69796 rc = sqlite3BtreeCursor(u.az.pX, u.az.p2, u.az.wrFlag, u.az.pKeyInfo, u.az.pCur->pCursor);
@@ -69833,16 +69800,15 @@
69800
69801 /* Since it performs no memory allocation or IO, the only value that
69802 ** sqlite3BtreeCursor() may return is SQLITE_OK. */
69803 assert( rc==SQLITE_OK );
69804
69805 /* Set the VdbeCursor.isTable variable. Previous versions of
69806 ** SQLite used to check if the root-page flags were sane at this point
69807 ** and report database corruption if they were not, but this check has
69808 ** since moved into the btree layer. */
69809 u.az.pCur->isTable = pOp->p4type!=P4_KEYINFO;
 
69810 break;
69811 }
69812
69813 /* Opcode: OpenEphemeral P1 P2 * P4 P5
69814 ** Synopsis: nColumn=P2
@@ -69882,10 +69848,11 @@
69848 SQLITE_OPEN_CREATE |
69849 SQLITE_OPEN_EXCLUSIVE |
69850 SQLITE_OPEN_DELETEONCLOSE |
69851 SQLITE_OPEN_TRANSIENT_DB;
69852 assert( pOp->p1>=0 );
69853 assert( pOp->p2>=0 );
69854 u.ba.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69855 if( u.ba.pCx==0 ) goto no_mem;
69856 u.ba.pCx->nullRow = 1;
69857 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &u.ba.pCx->pBt,
69858 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
@@ -69914,11 +69881,10 @@
69881 rc = sqlite3BtreeCursor(u.ba.pCx->pBt, MASTER_ROOT, 1, 0, u.ba.pCx->pCursor);
69882 u.ba.pCx->isTable = 1;
69883 }
69884 }
69885 u.ba.pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
 
69886 break;
69887 }
69888
69889 /* Opcode: SorterOpen P1 * * P4 *
69890 **
@@ -69929,16 +69895,17 @@
69895 case OP_SorterOpen: {
69896 #if 0 /* local variables moved into u.bb */
69897 VdbeCursor *pCx;
69898 #endif /* local variables moved into u.bb */
69899
69900 assert( pOp->p1>=0 );
69901 assert( pOp->p2>=0 );
69902 u.bb.pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
69903 if( u.bb.pCx==0 ) goto no_mem;
69904 u.bb.pCx->pKeyInfo = pOp->p4.pKeyInfo;
69905 assert( u.bb.pCx->pKeyInfo->db==db );
69906 assert( u.bb.pCx->pKeyInfo->enc==ENC(db) );
 
69907 rc = sqlite3VdbeSorterInit(db, u.bb.pCx);
69908 break;
69909 }
69910
69911 /* Opcode: OpenPseudo P1 P2 P3 * P5
@@ -69962,16 +69929,16 @@
69929 #if 0 /* local variables moved into u.bc */
69930 VdbeCursor *pCx;
69931 #endif /* local variables moved into u.bc */
69932
69933 assert( pOp->p1>=0 );
69934 assert( pOp->p3>=0 );
69935 u.bc.pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69936 if( u.bc.pCx==0 ) goto no_mem;
69937 u.bc.pCx->nullRow = 1;
69938 u.bc.pCx->pseudoTableReg = pOp->p2;
69939 u.bc.pCx->isTable = 1;
 
69940 u.bc.pCx->multiPseudo = pOp->p5;
69941 break;
69942 }
69943
69944 /* Opcode: Close P1 * * * *
@@ -70801,11 +70768,11 @@
70768 VdbeCursor *pC;
70769 #endif /* local variables moved into u.bl */
70770
70771 pOut = &aMem[pOp->p2];
70772 u.bl.pC = p->apCsr[pOp->p1];
70773 assert( isSorter(u.bl.pC) );
70774 rc = sqlite3VdbeSorterRowkey(u.bl.pC, pOut);
70775 break;
70776 }
70777
70778 /* Opcode: RowData P1 P2 * * *
@@ -70843,13 +70810,13 @@
70810 memAboutToChange(p, pOut);
70811
70812 /* Note that RowKey and RowData are really exactly the same instruction */
70813 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70814 u.bm.pC = p->apCsr[pOp->p1];
70815 assert( isSorter(u.bm.pC)==0 );
70816 assert( u.bm.pC->isTable || pOp->opcode!=OP_RowData );
70817 assert( u.bm.pC->isTable==0 || pOp->opcode==OP_RowData );
70818 assert( u.bm.pC!=0 );
70819 assert( u.bm.pC->nullRow==0 );
70820 assert( u.bm.pC->pseudoTableReg==0 );
70821 assert( u.bm.pC->pCursor!=0 );
70822 u.bm.pCrsr = u.bm.pC->pCursor;
@@ -70862,11 +70829,11 @@
70829 */
70830 assert( u.bm.pC->deferredMoveto==0 );
70831 rc = sqlite3VdbeCursorMoveto(u.bm.pC);
70832 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70833
70834 if( u.bm.pC->isTable==0 ){
70835 assert( !u.bm.pC->isTable );
70836 VVA_ONLY(rc =) sqlite3BtreeKeySize(u.bm.pCrsr, &u.bm.n64);
70837 assert( rc==SQLITE_OK ); /* True because of CursorMoveto() call above */
70838 if( u.bm.n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
70839 goto too_big;
@@ -70882,11 +70849,11 @@
70849 if( sqlite3VdbeMemGrow(pOut, u.bm.n, 0) ){
70850 goto no_mem;
70851 }
70852 pOut->n = u.bm.n;
70853 MemSetTypeFlag(pOut, MEM_Blob);
70854 if( u.bm.pC->isTable==0 ){
70855 rc = sqlite3BtreeKey(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70856 }else{
70857 rc = sqlite3BtreeData(u.bm.pCrsr, 0, u.bm.n, pOut->z);
70858 }
70859 pOut->enc = SQLITE_UTF8; /* In case the blob is ever cast to text */
@@ -70959,10 +70926,11 @@
70926 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70927 u.bo.pC = p->apCsr[pOp->p1];
70928 assert( u.bo.pC!=0 );
70929 u.bo.pC->nullRow = 1;
70930 u.bo.pC->rowidIsValid = 0;
70931 u.bo.pC->cacheStatus = CACHE_STALE;
70932 assert( u.bo.pC->pCursor || u.bo.pC->pVtabCursor );
70933 if( u.bo.pC->pCursor ){
70934 sqlite3BtreeClearCursor(u.bo.pC->pCursor);
70935 }
70936 break;
@@ -71038,19 +71006,18 @@
71006 #endif /* local variables moved into u.bq */
71007
71008 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71009 u.bq.pC = p->apCsr[pOp->p1];
71010 assert( u.bq.pC!=0 );
71011 assert( isSorter(u.bq.pC)==(pOp->opcode==OP_SorterSort) );
71012 u.bq.res = 1;
71013 if( isSorter(u.bq.pC) ){
71014 rc = sqlite3VdbeSorterRewind(db, u.bq.pC, &u.bq.res);
71015 }else{
71016 u.bq.pCrsr = u.bq.pC->pCursor;
71017 assert( u.bq.pCrsr );
71018 rc = sqlite3BtreeFirst(u.bq.pCrsr, &u.bq.res);
 
71019 u.bq.pC->deferredMoveto = 0;
71020 u.bq.pC->cacheStatus = CACHE_STALE;
71021 u.bq.pC->rowidIsValid = 0;
71022 }
71023 u.bq.pC->nullRow = (u8)u.bq.res;
@@ -71066,69 +71033,85 @@
71033 ** Advance cursor P1 so that it points to the next key/data pair in its
71034 ** table or index. If there are no more key/value pairs then fall through
71035 ** to the following instruction. But if the cursor advance was successful,
71036 ** jump immediately to P2.
71037 **
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.
71040 **
71041 ** P4 is always of type P4_ADVANCE. The function pointer points to
71042 ** sqlite3BtreeNext().
71043 **
71044 ** If P5 is positive and the jump is taken, then event counter
71045 ** number P5-1 in the prepared statement is incremented.
71046 **
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.
71053 */
71054 /* Opcode: Prev P1 P2 * * P5
71055 **
71056 ** Back up cursor P1 so that it points to the previous key/data pair in its
71057 ** table or index. If there is no previous key/value pairs then fall through
71058 ** to the following instruction. But if the cursor backup was successful,
71059 ** jump immediately to P2.
71060 **
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.
71063 **
71064 ** P4 is always of type P4_ADVANCE. The function pointer points to
71065 ** sqlite3BtreePrevious().
71066 **
71067 ** If P5 is positive and the jump is taken, then event counter
71068 ** number P5-1 in the prepared statement is incremented.
71069 */
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 */
71076 #if 0 /* local variables moved into u.br */
71077 VdbeCursor *pC;
71078 int res;
71079 #endif /* local variables moved into u.br */
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 */
71091 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71092 assert( pOp->p5<ArraySize(p->aCounter) );
71093 u.br.pC = p->apCsr[pOp->p1];
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:
 
 
 
 
 
 
 
71103 u.br.pC->cacheStatus = CACHE_STALE;
71104 if( u.br.res==0 ){
71105 u.br.pC->nullRow = 0;
71106 pc = pOp->p2 - 1;
71107 p->aCounter[pOp->p5]++;
71108 #ifdef SQLITE_TEST
71109 sqlite3_search_count++;
71110 #endif
71111 }else{
71112 u.br.pC->nullRow = 1;
71113 }
71114 u.br.pC->rowidIsValid = 0;
71115 goto check_for_interrupt;
71116 }
71117
@@ -71155,11 +71138,11 @@
71138 #endif /* local variables moved into u.bs */
71139
71140 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71141 u.bs.pC = p->apCsr[pOp->p1];
71142 assert( u.bs.pC!=0 );
71143 assert( isSorter(u.bs.pC)==(pOp->opcode==OP_SorterInsert) );
71144 pIn2 = &aMem[pOp->p2];
71145 assert( pIn2->flags & MEM_Blob );
71146 u.bs.pCrsr = u.bs.pC->pCursor;
71147 if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;
71148 assert( u.bs.pCrsr!=0 );
@@ -72446,11 +72429,10 @@
72429
72430 /* Initialize vdbe cursor object */
72431 u.cm.pCur = allocateCursor(p, pOp->p1, 0, -1, 0);
72432 if( u.cm.pCur ){
72433 u.cm.pCur->pVtabCursor = u.cm.pVtabCursor;
 
72434 }else{
72435 db->mallocFailed = 1;
72436 u.cm.pModule->xClose(u.cm.pVtabCursor);
72437 }
72438 }
@@ -73017,22 +72999,23 @@
72999 assert( v->aVar[0].flags&MEM_Int );
73000 v->aVar[0].u.i = iRow;
73001
73002 rc = sqlite3_step(p->pStmt);
73003 if( rc==SQLITE_ROW ){
73004 VdbeCursor *pC = v->apCsr[0];
73005 u32 type = pC->aType[p->iCol];
73006 if( type<12 ){
73007 zErr = sqlite3MPrintf(p->db, "cannot open value of type %s",
73008 type==0?"null": type==7?"real": "integer"
73009 );
73010 rc = SQLITE_ERROR;
73011 sqlite3_finalize(p->pStmt);
73012 p->pStmt = 0;
73013 }else{
73014 p->iOffset = pC->aType[p->iCol + pC->nField];
73015 p->nByte = sqlite3VdbeSerialTypeLen(type);
73016 p->pCsr = pC->pCursor;
73017 sqlite3BtreeEnterCursor(p->pCsr);
73018 sqlite3BtreeCacheOverflow(p->pCsr);
73019 sqlite3BtreeLeaveCursor(p->pCsr);
73020 }
73021 }
@@ -75806,11 +75789,10 @@
75789 return lookupName(pParse, zDb, zTable, zColumn, pNC, pExpr);
75790 }
75791
75792 /* Resolve function names
75793 */
 
75794 case TK_FUNCTION: {
75795 ExprList *pList = pExpr->x.pList; /* The argument list */
75796 int n = pList ? pList->nExpr : 0; /* Number of arguments */
75797 int no_such_func = 0; /* True if no such function exists */
75798 int wrong_num_args = 0; /* True if wrong number of arguments */
@@ -75819,11 +75801,10 @@
75801 int nId; /* Number of characters in function name */
75802 const char *zId; /* The function name. */
75803 FuncDef *pDef; /* Information about the function */
75804 u8 enc = ENC(pParse->db); /* The database encoding */
75805
 
75806 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
75807 notValidPartIdxWhere(pParse, pNC, "functions");
75808 zId = pExpr->u.zToken;
75809 nId = sqlite3Strlen30(zId);
75810 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
@@ -75864,10 +75845,11 @@
75845 pNC->nErr++;
75846 }
75847 pExpr->op = TK_NULL;
75848 return WRC_Prune;
75849 }
75850 if( pDef->funcFlags & SQLITE_FUNC_CONSTANT ) ExprSetProperty(pExpr,EP_Constant);
75851 }
75852 #endif
75853 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
75854 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
75855 pNC->nErr++;
@@ -77781,13 +77763,16 @@
77763 return WRC_Abort;
77764 }
77765
77766 switch( pExpr->op ){
77767 /* Consider functions to be constant if all their arguments are constant
77768 ** and either pWalker->u.i==2 or the function as the SQLITE_FUNC_CONST
77769 ** flag. */
77770 case TK_FUNCTION:
77771 if( pWalker->u.i==2 || ExprHasProperty(pExpr,EP_Constant) ){
77772 return WRC_Continue;
77773 }
77774 /* Fall through */
77775 case TK_ID:
77776 case TK_COLUMN:
77777 case TK_AGG_FUNCTION:
77778 case TK_AGG_COLUMN:
@@ -79213,11 +79198,10 @@
79198 }else{
79199 inReg = pInfo->aFunc[pExpr->iAgg].iMem;
79200 }
79201 break;
79202 }
 
79203 case TK_FUNCTION: {
79204 ExprList *pFarg; /* List of function arguments */
79205 int nFarg; /* Number of function arguments */
79206 FuncDef *pDef; /* The function definition object */
79207 int nId; /* Length of the function name in bytes */
@@ -79226,12 +79210,10 @@
79210 int i; /* Loop counter */
79211 u8 enc = ENC(db); /* The text encoding used by this database */
79212 CollSeq *pColl = 0; /* A collating sequence */
79213
79214 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
 
 
79215 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
79216 pFarg = 0;
79217 }else{
79218 pFarg = pExpr->x.pList;
79219 }
@@ -79271,12 +79253,25 @@
79253 assert( nFarg>=1 );
79254 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
79255 break;
79256 }
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 }
79266 if( pFarg ){
79267 if( constMask ){
79268 r1 = pParse->nMem+1;
79269 pParse->nMem += nFarg;
79270 }else{
79271 r1 = sqlite3GetTempRange(pParse, nFarg);
79272 }
79273
79274 /* For length() and typeof() functions with a column argument,
79275 ** set the P5 parameter to the OP_Column opcode to OPFLAG_LENGTHARG
79276 ** or OPFLAG_TYPEOFARG respectively, to avoid unnecessary data
79277 ** loading.
@@ -79287,18 +79282,19 @@
79282 assert( pFarg->a[0].pExpr!=0 );
79283 exprOp = pFarg->a[0].pExpr->op;
79284 if( exprOp==TK_COLUMN || exprOp==TK_AGG_COLUMN ){
79285 assert( SQLITE_FUNC_LENGTH==OPFLAG_LENGTHARG );
79286 assert( SQLITE_FUNC_TYPEOF==OPFLAG_TYPEOFARG );
79287 testcase( pDef->funcFlags & OPFLAG_LENGTHARG );
79288 pFarg->a[0].pExpr->op2 =
79289 pDef->funcFlags & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG);
79290 }
79291 }
79292
79293 sqlite3ExprCachePush(pParse); /* Ticket 2ea2425d34be */
79294 sqlite3ExprCodeExprList(pParse, pFarg, r1,
79295 SQLITE_ECEL_DUP|SQLITE_ECEL_FACTOR);
79296 sqlite3ExprCachePop(pParse, 1); /* Ticket 2ea2425d34be */
79297 }else{
79298 r1 = 0;
79299 }
79300 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -79318,26 +79314,18 @@
79314 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[1].pExpr);
79315 }else if( nFarg>0 ){
79316 pDef = sqlite3VtabOverloadFunction(db, pDef, nFarg, pFarg->a[0].pExpr);
79317 }
79318 #endif
 
 
 
 
 
 
 
 
79319 if( pDef->funcFlags & SQLITE_FUNC_NEEDCOLL ){
79320 if( !pColl ) pColl = db->pDfltColl;
79321 sqlite3VdbeAddOp4(v, OP_CollSeq, 0, 0, 0, (char *)pColl, P4_COLLSEQ);
79322 }
79323 sqlite3VdbeAddOp4(v, OP_Function, constMask, r1, target,
79324 (char*)pDef, P4_FUNCDEF);
79325 sqlite3VdbeChangeP5(v, (u8)nFarg);
79326 if( nFarg && constMask==0 ){
79327 sqlite3ReleaseTempRange(pParse, r1, nFarg);
79328 }
79329 break;
79330 }
79331 #ifndef SQLITE_OMIT_SUBQUERY
@@ -79569,10 +79557,32 @@
79557 }
79558 sqlite3ReleaseTempReg(pParse, regFree1);
79559 sqlite3ReleaseTempReg(pParse, regFree2);
79560 return inReg;
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 }
79584
79585 /*
79586 ** Generate code to evaluate an expression and store the results
79587 ** into a register. Return the register number where the results
79588 ** are stored.
@@ -79586,28 +79596,27 @@
79596 ** VDBE program, in order to factor it out of the evaluation loop.
79597 */
79598 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79599 int r2;
79600 pExpr = sqlite3ExprSkipCollate(pExpr);
79601 if( ConstFactorOk(pParse)
79602 && pExpr->op!=TK_REGISTER
79603 && sqlite3ExprIsConstantNotJoin(pExpr)
79604 ){
79605 ExprList *p = pParse->pConstExpr;
79606 int i;
79607 *pReg = 0;
79608 if( p ){
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;
79613 }
79614 }
79615 }
 
 
79616 r2 = ++pParse->nMem;
79617 sqlite3ExprCodeAtInit(pParse, pExpr, r2, 1);
79618 }else{
79619 int r1 = sqlite3GetTempReg(pParse);
79620 r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
79621 if( r2==r1 ){
79622 *pReg = r1;
@@ -79793,11 +79802,10 @@
79802 sqlite3ExplainPrintf(pOut,".COLLATE(%s)",pExpr->u.zToken);
79803 break;
79804 }
79805
79806 case TK_AGG_FUNCTION:
 
79807 case TK_FUNCTION: {
79808 ExprList *pFarg; /* List of function arguments */
79809 if( ExprHasProperty(pExpr, EP_TokenOnly) ){
79810 pFarg = 0;
79811 }else{
@@ -79949,29 +79957,40 @@
79957 /*
79958 ** Generate code that pushes the value of every element of the given
79959 ** expression list into a sequence of registers beginning at target.
79960 **
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.
79968 */
79969 SQLITE_PRIVATE int sqlite3ExprCodeExprList(
79970 Parse *pParse, /* Parsing context */
79971 ExprList *pList, /* The expression list to be coded */
79972 int target, /* Where to write results */
79973 u8 flags /* SQLITE_ECEL_* flags */
79974 ){
79975 struct ExprList_item *pItem;
79976 int i, n;
79977 u8 copyOp = (flags & SQLITE_ECEL_DUP) ? OP_Copy : OP_SCopy;
79978 assert( pList!=0 );
79979 assert( target>0 );
79980 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
79981 n = pList->nExpr;
79982 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
79983 for(pItem=pList->a, i=0; i<n; i++, pItem++){
79984 Expr *pExpr = pItem->pExpr;
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 }
79992 }
79993 }
79994 return n;
79995 }
79996
@@ -91338,24 +91357,24 @@
91357 FUNCTION2(coalesce, -1, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
91358 FUNCTION(hex, 1, 0, 0, hexFunc ),
91359 FUNCTION2(ifnull, 2, 0, 0, noopFunc, SQLITE_FUNC_COALESCE),
91360 FUNCTION2(unlikely, 1, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
91361 FUNCTION2(likelihood, 2, 0, 0, noopFunc, SQLITE_FUNC_UNLIKELY),
91362 VFUNCTION(random, 0, 0, 0, randomFunc ),
91363 VFUNCTION(randomblob, 1, 0, 0, randomBlob ),
91364 FUNCTION(nullif, 2, 0, 1, nullifFunc ),
91365 FUNCTION(sqlite_version, 0, 0, 0, versionFunc ),
91366 FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ),
91367 FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ),
91368 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
91369 FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ),
91370 FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ),
91371 #endif /* SQLITE_OMIT_COMPILEOPTION_DIAGS */
91372 FUNCTION(quote, 1, 0, 0, quoteFunc ),
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 ),
91376 FUNCTION(replace, 3, 0, 0, replaceFunc ),
91377 FUNCTION(zeroblob, 1, 0, 0, zeroblobFunc ),
91378 #ifdef SQLITE_SOUNDEX
91379 FUNCTION(soundex, 1, 0, 0, soundexFunc ),
91380 #endif
@@ -100003,11 +100022,12 @@
100022 }else if( eDest!=SRT_Exists ){
100023 /* If the destination is an EXISTS(...) expression, the actual
100024 ** values returned by the SELECT are not required.
100025 */
100026 sqlite3ExprCacheClear(pParse);
100027 sqlite3ExprCodeExprList(pParse, pEList, regResult,
100028 (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100029 }
100030 nColumn = nResultCol;
100031
100032 /* If the DISTINCT keyword was present on the SELECT statement
100033 ** and this row has been seen before, then do not make this row
@@ -103289,11 +103309,11 @@
103309 ExprList *pList = pF->pExpr->x.pList;
103310 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
103311 if( pList ){
103312 nArg = pList->nExpr;
103313 regAgg = sqlite3GetTempRange(pParse, nArg);
103314 sqlite3ExprCodeExprList(pParse, pList, regAgg, SQLITE_ECEL_DUP);
103315 }else{
103316 nArg = 0;
103317 regAgg = 0;
103318 }
103319 if( pF->iDistinct>=0 ){
@@ -110765,11 +110785,11 @@
110785 if( eType==IN_INDEX_ROWID ){
110786 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
110787 }else{
110788 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
110789 }
110790 pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
110791 sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
110792 }else{
110793 pLevel->u.in.nIn = 0;
110794 }
110795 #endif
@@ -117027,16 +117047,11 @@
117047 spanSet(&yygotominor.yy118,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0);
117048 }
117049 break;
117050 case 200: /* term ::= CTIME_KW */
117051 {
117052 yygotominor.yy118.pExpr = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0);
 
 
 
 
 
117053 spanSet(&yygotominor.yy118, &yymsp[0].minor.yy0, &yymsp[0].minor.yy0);
117054 }
117055 break;
117056 case 201: /* expr ::= expr AND expr */
117057 case 202: /* expr ::= expr OR expr */ yytestcase(yyruleno==202);
117058
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.2"
111111
#define SQLITE_VERSION_NUMBER 3008002
112
-#define SQLITE_SOURCE_ID "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"
112
+#define SQLITE_SOURCE_ID "2013-11-21 23:37:02 3d47a556f0074e39b880186fb7661b1b8955f742"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-11-19 13:55:34 17e8524fc05aa1e6074c19a8ccccc5ab5883103a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-11-21 23:37:02 3d47a556f0074e39b880186fb7661b1b8955f742"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button