Fossil SCM

Update the built-in SQLite the latest pre-3.8.4 trunk version. Modify the way the "shell.c" source file is used so that it can be imported directly from the SQLite source tree without having to be edited.

drh 2014-02-27 15:05 trunk
Commit c92a3dda8c83206153ad7e6b762a1ea0c9fa3b7e
+3 -1
--- src/main.mk
+++ src/main.mk
@@ -385,11 +385,13 @@
385385
-DSQLITE_OMIT_DEPRECATED \
386386
-DSQLITE_ENABLE_EXPLAIN_COMMENTS
387387
388388
# Setup the options used to compile the included SQLite shell.
389389
SHELL_OPTIONS = -Dmain=sqlite3_shell \
390
- -DSQLITE_OMIT_LOAD_EXTENSION=1
390
+ -DSQLITE_OMIT_LOAD_EXTENSION=1 \
391
+ -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
392
+ -DSQLITE_SHELL_DBNAME_PROC=fossil_open
391393
392394
# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
393395
# to 1. If it is set to 1, then there is no need to build or link
394396
# the sqlite3.o object. Instead, the system sqlite will be linked
395397
# using -lsqlite3.
396398
--- src/main.mk
+++ src/main.mk
@@ -385,11 +385,13 @@
385 -DSQLITE_OMIT_DEPRECATED \
386 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
387
388 # Setup the options used to compile the included SQLite shell.
389 SHELL_OPTIONS = -Dmain=sqlite3_shell \
390 -DSQLITE_OMIT_LOAD_EXTENSION=1
 
 
391
392 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
393 # to 1. If it is set to 1, then there is no need to build or link
394 # the sqlite3.o object. Instead, the system sqlite will be linked
395 # using -lsqlite3.
396
--- src/main.mk
+++ src/main.mk
@@ -385,11 +385,13 @@
385 -DSQLITE_OMIT_DEPRECATED \
386 -DSQLITE_ENABLE_EXPLAIN_COMMENTS
387
388 # Setup the options used to compile the included SQLite shell.
389 SHELL_OPTIONS = -Dmain=sqlite3_shell \
390 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
391 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
392 -DSQLITE_SHELL_DBNAME_PROC=fossil_open
393
394 # The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
395 # to 1. If it is set to 1, then there is no need to build or link
396 # the sqlite3.o object. Instead, the system sqlite will be linked
397 # using -lsqlite3.
398
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -146,10 +146,12 @@
146146
# Options used to compile the included SQLite shell.
147147
#
148148
set SHELL_OPTIONS {
149149
-Dmain=sqlite3_shell
150150
-DSQLITE_OMIT_LOAD_EXTENSION=1
151
+ -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE)
152
+ -DSQLITE_SHELL_DBNAME_PROC=fossil_open
151153
}
152154
153155
# Options used to compile the included SQLite shell on Windows.
154156
#
155157
set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
156158
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -146,10 +146,12 @@
146 # Options used to compile the included SQLite shell.
147 #
148 set SHELL_OPTIONS {
149 -Dmain=sqlite3_shell
150 -DSQLITE_OMIT_LOAD_EXTENSION=1
 
 
151 }
152
153 # Options used to compile the included SQLite shell on Windows.
154 #
155 set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
156
--- src/makemake.tcl
+++ src/makemake.tcl
@@ -146,10 +146,12 @@
146 # Options used to compile the included SQLite shell.
147 #
148 set SHELL_OPTIONS {
149 -Dmain=sqlite3_shell
150 -DSQLITE_OMIT_LOAD_EXTENSION=1
151 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE)
152 -DSQLITE_SHELL_DBNAME_PROC=fossil_open
153 }
154
155 # Options used to compile the included SQLite shell on Windows.
156 #
157 set SHELL_WIN32_OPTIONS $SHELL_OPTIONS
158
+10 -10
--- src/shell.c
+++ src/shell.c
@@ -3546,15 +3546,17 @@
35463546
char *zFirstCmd = 0;
35473547
int i;
35483548
int rc = 0;
35493549
int warnInmemoryDb = 0;
35503550
3551
- if( sqlite3_libversion_number()<3008003 ){
3552
- fprintf(stderr, "Unsuitable SQLite version %s, must be at least 3.8.3",
3553
- sqlite3_libversion());
3551
+#if !defined(USE_SYSTEM_SQLITE) || USE_SYSTEM_SQLITE!=1
3552
+ if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
3553
+ fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
3554
+ sqlite3_sourceid(), SQLITE_SOURCE_ID);
35543555
exit(1);
35553556
}
3557
+#endif
35563558
Argv0 = argv[0];
35573559
main_init(&data);
35583560
stdin_is_interactive = isatty(0);
35593561
35603562
/* Make sure we have a valid signal handler early, before anything
@@ -3644,17 +3646,15 @@
36443646
warnInmemoryDb = argc==1;
36453647
#else
36463648
fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
36473649
return 1;
36483650
#endif
3649
- /***** Begin Fossil Patch *****/
3650
- {
3651
- extern void fossil_open(const char **);
3652
- fossil_open(&data.zDbFilename);
3653
- warnInmemoryDb = 0;
3654
- }
3655
- /***** End Fossil Patch *****/
3651
+#ifdef SQLITE_SHELL_DBNAME_PROC
3652
+ { extern void SQLITE_SHELL_DBNAME_PROC(const char**);
3653
+ SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
3654
+ warnInmemoryDb = 0; }
3655
+#endif
36563656
}
36573657
data.out = stdout;
36583658
36593659
/* Go ahead and open the database file if it already exists. If the
36603660
** file does not exist, delay opening it. This prevents empty database
36613661
--- src/shell.c
+++ src/shell.c
@@ -3546,15 +3546,17 @@
3546 char *zFirstCmd = 0;
3547 int i;
3548 int rc = 0;
3549 int warnInmemoryDb = 0;
3550
3551 if( sqlite3_libversion_number()<3008003 ){
3552 fprintf(stderr, "Unsuitable SQLite version %s, must be at least 3.8.3",
3553 sqlite3_libversion());
 
3554 exit(1);
3555 }
 
3556 Argv0 = argv[0];
3557 main_init(&data);
3558 stdin_is_interactive = isatty(0);
3559
3560 /* Make sure we have a valid signal handler early, before anything
@@ -3644,17 +3646,15 @@
3644 warnInmemoryDb = argc==1;
3645 #else
3646 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
3647 return 1;
3648 #endif
3649 /***** Begin Fossil Patch *****/
3650 {
3651 extern void fossil_open(const char **);
3652 fossil_open(&data.zDbFilename);
3653 warnInmemoryDb = 0;
3654 }
3655 /***** End Fossil Patch *****/
3656 }
3657 data.out = stdout;
3658
3659 /* Go ahead and open the database file if it already exists. If the
3660 ** file does not exist, delay opening it. This prevents empty database
3661
--- src/shell.c
+++ src/shell.c
@@ -3546,15 +3546,17 @@
3546 char *zFirstCmd = 0;
3547 int i;
3548 int rc = 0;
3549 int warnInmemoryDb = 0;
3550
3551 #if !defined(USE_SYSTEM_SQLITE) || USE_SYSTEM_SQLITE!=1
3552 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
3553 fprintf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
3554 sqlite3_sourceid(), SQLITE_SOURCE_ID);
3555 exit(1);
3556 }
3557 #endif
3558 Argv0 = argv[0];
3559 main_init(&data);
3560 stdin_is_interactive = isatty(0);
3561
3562 /* Make sure we have a valid signal handler early, before anything
@@ -3644,17 +3646,15 @@
3646 warnInmemoryDb = argc==1;
3647 #else
3648 fprintf(stderr,"%s: Error: no database filename specified\n", Argv0);
3649 return 1;
3650 #endif
3651 #ifdef SQLITE_SHELL_DBNAME_PROC
3652 { extern void SQLITE_SHELL_DBNAME_PROC(const char**);
3653 SQLITE_SHELL_DBNAME_PROC(&data.zDbFilename);
3654 warnInmemoryDb = 0; }
3655 #endif
 
 
3656 }
3657 data.out = stdout;
3658
3659 /* Go ahead and open the database file if it already exists. If the
3660 ** file does not exist, delay opening it. This prevents empty database
3661
+1631 -1506
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.8.3.1. By combining all the individual C code files into this
3
+** version 3.8.4. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -187,13 +187,13 @@
187187
**
188188
** See also: [sqlite3_libversion()],
189189
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190190
** [sqlite_version()] and [sqlite_source_id()].
191191
*/
192
-#define SQLITE_VERSION "3.8.3.1"
193
-#define SQLITE_VERSION_NUMBER 3008003
194
-#define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e"
192
+#define SQLITE_VERSION "3.8.4"
193
+#define SQLITE_VERSION_NUMBER 3008004
194
+#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
195195
196196
/*
197197
** CAPI3REF: Run-Time Library Version Numbers
198198
** KEYWORDS: sqlite3_version, sqlite3_sourceid
199199
**
@@ -6202,11 +6202,12 @@
62026202
#define SQLITE_TESTCTRL_ISKEYWORD 16
62036203
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
62046204
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
62056205
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
62066206
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6207
-#define SQLITE_TESTCTRL_LAST 20
6207
+#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6208
+#define SQLITE_TESTCTRL_LAST 21
62086209
62096210
/*
62106211
** CAPI3REF: SQLite Runtime Status
62116212
**
62126213
** ^This interface is used to retrieve runtime status information
@@ -8852,12 +8853,10 @@
88528853
SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
88538854
SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
88548855
SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
88558856
SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
88568857
SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
8857
-SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
8858
-SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
88598858
88608859
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
88618860
SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
88628861
88638862
SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
@@ -8993,13 +8992,16 @@
89938992
} p4;
89948993
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
89958994
char *zComment; /* Comment to improve readability */
89968995
#endif
89978996
#ifdef VDBE_PROFILE
8998
- int cnt; /* Number of times this instruction was executed */
8997
+ u32 cnt; /* Number of times this instruction was executed */
89998998
u64 cycles; /* Total time spent executing this instruction */
90008999
#endif
9000
+#ifdef SQLITE_VDBE_COVERAGE
9001
+ int iSrcLine; /* Source-code line that generated this opcode */
9002
+#endif
90019003
};
90029004
typedef struct VdbeOp VdbeOp;
90039005
90049006
90059007
/*
@@ -9105,75 +9107,75 @@
91059107
#define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */
91069108
#define OP_Goto 16
91079109
#define OP_Gosub 17
91089110
#define OP_Return 18
91099111
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9110
-#define OP_Yield 20
9111
-#define OP_HaltIfNull 21 /* synopsis: if r[P3] null then halt */
9112
-#define OP_Halt 22
9113
-#define OP_Integer 23 /* synopsis: r[P2]=P1 */
9114
-#define OP_Int64 24 /* synopsis: r[P2]=P4 */
9115
-#define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
9116
-#define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
9117
-#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
9118
-#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
9119
-#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9120
-#define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9121
-#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
9122
-#define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
9123
-#define OP_CollSeq 33
9124
-#define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
9125
-#define OP_MustBeInt 35
9126
-#define OP_RealAffinity 36
9127
-#define OP_Permutation 37
9128
-#define OP_Compare 38
9129
-#define OP_Jump 39
9130
-#define OP_Once 40
9131
-#define OP_If 41
9132
-#define OP_IfNot 42
9133
-#define OP_Column 43 /* synopsis: r[P3]=PX */
9134
-#define OP_Affinity 44 /* synopsis: affinity(r[P1@P2]) */
9135
-#define OP_MakeRecord 45 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9136
-#define OP_Count 46 /* synopsis: r[P2]=count() */
9137
-#define OP_ReadCookie 47
9138
-#define OP_SetCookie 48
9139
-#define OP_VerifyCookie 49
9140
-#define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
9141
-#define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
9142
-#define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
9143
-#define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9144
-#define OP_SorterOpen 54
9145
-#define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */
9146
-#define OP_Close 56
9147
-#define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */
9148
-#define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */
9149
-#define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */
9150
-#define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */
9151
-#define OP_Seek 61 /* synopsis: intkey=r[P2] */
9152
-#define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */
9153
-#define OP_NotFound 63 /* synopsis: key=r[P3@P4] */
9154
-#define OP_Found 64 /* synopsis: key=r[P3@P4] */
9155
-#define OP_NotExists 65 /* synopsis: intkey=r[P3] */
9156
-#define OP_Sequence 66 /* synopsis: r[P2]=rowid */
9157
-#define OP_NewRowid 67 /* synopsis: r[P2]=rowid */
9158
-#define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */
9159
-#define OP_InsertInt 69 /* synopsis: intkey=P3 data=r[P2] */
9160
-#define OP_Delete 70
9112
+#define OP_InitCoroutine 20
9113
+#define OP_EndCoroutine 21
9114
+#define OP_Yield 22
9115
+#define OP_HaltIfNull 23 /* synopsis: if r[P3]=null halt */
9116
+#define OP_Halt 24
9117
+#define OP_Integer 25 /* synopsis: r[P2]=P1 */
9118
+#define OP_Int64 26 /* synopsis: r[P2]=P4 */
9119
+#define OP_String 27 /* synopsis: r[P2]='P4' (len=P1) */
9120
+#define OP_Null 28 /* synopsis: r[P2..P3]=NULL */
9121
+#define OP_SoftNull 29 /* synopsis: r[P1]=NULL */
9122
+#define OP_Blob 30 /* synopsis: r[P2]=P4 (len=P1) */
9123
+#define OP_Variable 31 /* synopsis: r[P2]=parameter(P1,P4) */
9124
+#define OP_Move 32 /* synopsis: r[P2@P3]=r[P1@P3] */
9125
+#define OP_Copy 33 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9126
+#define OP_SCopy 34 /* synopsis: r[P2]=r[P1] */
9127
+#define OP_ResultRow 35 /* synopsis: output=r[P1@P2] */
9128
+#define OP_CollSeq 36
9129
+#define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */
9130
+#define OP_MustBeInt 38
9131
+#define OP_RealAffinity 39
9132
+#define OP_Permutation 40
9133
+#define OP_Compare 41
9134
+#define OP_Jump 42
9135
+#define OP_Once 43
9136
+#define OP_If 44
9137
+#define OP_IfNot 45
9138
+#define OP_Column 46 /* synopsis: r[P3]=PX */
9139
+#define OP_Affinity 47 /* synopsis: affinity(r[P1@P2]) */
9140
+#define OP_MakeRecord 48 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9141
+#define OP_Count 49 /* synopsis: r[P2]=count() */
9142
+#define OP_ReadCookie 50
9143
+#define OP_SetCookie 51
9144
+#define OP_OpenRead 52 /* synopsis: root=P2 iDb=P3 */
9145
+#define OP_OpenWrite 53 /* synopsis: root=P2 iDb=P3 */
9146
+#define OP_OpenAutoindex 54 /* synopsis: nColumn=P2 */
9147
+#define OP_OpenEphemeral 55 /* synopsis: nColumn=P2 */
9148
+#define OP_SorterOpen 56
9149
+#define OP_OpenPseudo 57 /* synopsis: P3 columns in r[P2] */
9150
+#define OP_Close 58
9151
+#define OP_SeekLT 59
9152
+#define OP_SeekLE 60
9153
+#define OP_SeekGE 61
9154
+#define OP_SeekGT 62
9155
+#define OP_Seek 63 /* synopsis: intkey=r[P2] */
9156
+#define OP_NoConflict 64 /* synopsis: key=r[P3@P4] */
9157
+#define OP_NotFound 65 /* synopsis: key=r[P3@P4] */
9158
+#define OP_Found 66 /* synopsis: key=r[P3@P4] */
9159
+#define OP_NotExists 67 /* synopsis: intkey=r[P3] */
9160
+#define OP_Sequence 68 /* synopsis: r[P2]=rowid */
9161
+#define OP_NewRowid 69 /* synopsis: r[P2]=rowid */
9162
+#define OP_Insert 70 /* synopsis: intkey=r[P3] data=r[P2] */
91619163
#define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
91629164
#define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9163
-#define OP_ResetCount 73
9164
-#define OP_SorterCompare 74 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9165
-#define OP_SorterData 75 /* synopsis: r[P2]=data */
9165
+#define OP_InsertInt 73 /* synopsis: intkey=P3 data=r[P2] */
9166
+#define OP_Delete 74
9167
+#define OP_ResetCount 75
91669168
#define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
91679169
#define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
91689170
#define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
91699171
#define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
91709172
#define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
91719173
#define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
91729174
#define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
91739175
#define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9174
-#define OP_RowKey 84 /* synopsis: r[P2]=key */
9176
+#define OP_SorterCompare 84 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
91759177
#define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
91769178
#define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
91779179
#define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
91789180
#define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
91799181
#define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9180,68 +9182,72 @@
91809182
#define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
91819183
#define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
91829184
#define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
91839185
#define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
91849186
#define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9185
-#define OP_RowData 95 /* synopsis: r[P2]=data */
9187
+#define OP_SorterData 95 /* synopsis: r[P2]=data */
91869188
#define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
91879189
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9188
-#define OP_Rowid 98 /* synopsis: r[P2]=rowid */
9189
-#define OP_NullRow 99
9190
-#define OP_Last 100
9191
-#define OP_SorterSort 101
9192
-#define OP_Sort 102
9193
-#define OP_Rewind 103
9194
-#define OP_SorterInsert 104
9195
-#define OP_IdxInsert 105 /* synopsis: key=r[P2] */
9196
-#define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */
9197
-#define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */
9198
-#define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */
9199
-#define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */
9200
-#define OP_Destroy 110
9201
-#define OP_Clear 111
9202
-#define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */
9203
-#define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */
9204
-#define OP_ParseSchema 114
9205
-#define OP_LoadAnalysis 115
9206
-#define OP_DropTable 116
9207
-#define OP_DropIndex 117
9208
-#define OP_DropTrigger 118
9209
-#define OP_IntegrityCk 119
9210
-#define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */
9211
-#define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */
9212
-#define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9213
-#define OP_Program 123
9214
-#define OP_Param 124
9215
-#define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */
9216
-#define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */
9217
-#define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9218
-#define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */
9219
-#define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */
9220
-#define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9221
-#define OP_AggFinal 131 /* synopsis: accum=r[P1] N=P2 */
9222
-#define OP_IncrVacuum 132
9190
+#define OP_RowKey 98 /* synopsis: r[P2]=key */
9191
+#define OP_RowData 99 /* synopsis: r[P2]=data */
9192
+#define OP_Rowid 100 /* synopsis: r[P2]=rowid */
9193
+#define OP_NullRow 101
9194
+#define OP_Last 102
9195
+#define OP_SorterSort 103
9196
+#define OP_Sort 104
9197
+#define OP_Rewind 105
9198
+#define OP_SorterInsert 106
9199
+#define OP_IdxInsert 107 /* synopsis: key=r[P2] */
9200
+#define OP_IdxDelete 108 /* synopsis: key=r[P2@P3] */
9201
+#define OP_IdxRowid 109 /* synopsis: r[P2]=rowid */
9202
+#define OP_IdxLE 110 /* synopsis: key=r[P3@P4] */
9203
+#define OP_IdxGT 111 /* synopsis: key=r[P3@P4] */
9204
+#define OP_IdxLT 112 /* synopsis: key=r[P3@P4] */
9205
+#define OP_IdxGE 113 /* synopsis: key=r[P3@P4] */
9206
+#define OP_Destroy 114
9207
+#define OP_Clear 115
9208
+#define OP_CreateIndex 116 /* synopsis: r[P2]=root iDb=P1 */
9209
+#define OP_CreateTable 117 /* synopsis: r[P2]=root iDb=P1 */
9210
+#define OP_ParseSchema 118
9211
+#define OP_LoadAnalysis 119
9212
+#define OP_DropTable 120
9213
+#define OP_DropIndex 121
9214
+#define OP_DropTrigger 122
9215
+#define OP_IntegrityCk 123
9216
+#define OP_RowSetAdd 124 /* synopsis: rowset(P1)=r[P2] */
9217
+#define OP_RowSetRead 125 /* synopsis: r[P3]=rowset(P1) */
9218
+#define OP_RowSetTest 126 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9219
+#define OP_Program 127
9220
+#define OP_Param 128
9221
+#define OP_FkCounter 129 /* synopsis: fkctr[P1]+=P2 */
9222
+#define OP_FkIfZero 130 /* synopsis: if fkctr[P1]==0 goto P2 */
9223
+#define OP_MemMax 131 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9224
+#define OP_IfPos 132 /* synopsis: if r[P1]>0 goto P2 */
92239225
#define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9224
-#define OP_Expire 134
9225
-#define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */
9226
-#define OP_VBegin 136
9227
-#define OP_VCreate 137
9228
-#define OP_VDestroy 138
9229
-#define OP_VOpen 139
9230
-#define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */
9231
-#define OP_VNext 141
9232
-#define OP_VRename 142
9226
+#define OP_IfNeg 134 /* synopsis: if r[P1]<0 goto P2 */
9227
+#define OP_IfZero 135 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9228
+#define OP_AggFinal 136 /* synopsis: accum=r[P1] N=P2 */
9229
+#define OP_IncrVacuum 137
9230
+#define OP_Expire 138
9231
+#define OP_TableLock 139 /* synopsis: iDb=P1 root=P2 write=P3 */
9232
+#define OP_VBegin 140
9233
+#define OP_VCreate 141
9234
+#define OP_VDestroy 142
92339235
#define OP_ToText 143 /* same as TK_TO_TEXT */
92349236
#define OP_ToBlob 144 /* same as TK_TO_BLOB */
92359237
#define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
92369238
#define OP_ToInt 146 /* same as TK_TO_INT */
92379239
#define OP_ToReal 147 /* same as TK_TO_REAL */
9238
-#define OP_Pagecount 148
9239
-#define OP_MaxPgcnt 149
9240
-#define OP_Trace 150
9241
-#define OP_Noop 151
9242
-#define OP_Explain 152
9240
+#define OP_VOpen 148
9241
+#define OP_VColumn 149 /* synopsis: r[P3]=vcolumn(P2) */
9242
+#define OP_VNext 150
9243
+#define OP_VRename 151
9244
+#define OP_Pagecount 152
9245
+#define OP_MaxPgcnt 153
9246
+#define OP_Init 154 /* synopsis: Start at P2 */
9247
+#define OP_Noop 155
9248
+#define OP_Explain 156
92439249
92449250
92459251
/* Properties such as "out2" or "jump" that are specified in
92469252
** comments following the "case" for each opcode in the vdbe.c
92479253
** are encoded into bitvectors as follows:
@@ -9254,28 +9260,28 @@
92549260
#define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
92559261
#define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
92569262
#define OPFLG_INITIALIZER {\
92579263
/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
92589264
/* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9259
-/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
9260
-/* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
9261
-/* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
9262
-/* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
9263
-/* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9264
-/* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
9265
-/* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c,\
9265
+/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9266
+/* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9267
+/* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9268
+/* 40 */ 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00,\
9269
+/* 48 */ 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,\
9270
+/* 56 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
9271
+/* 64 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c,\
92669272
/* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
92679273
/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
92689274
/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9269
-/* 96 */ 0x24, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
9270
-/* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
9271
-/* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9272
-/* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
9273
-/* 128 */ 0x05, 0x05, 0x05, 0x00, 0x01, 0x02, 0x00, 0x00,\
9274
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,\
9275
-/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00,\
9276
-/* 152 */ 0x00,}
9275
+/* 96 */ 0x24, 0x02, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
9276
+/* 104 */ 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01,\
9277
+/* 112 */ 0x01, 0x01, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00,\
9278
+/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45, 0x15, 0x01,\
9279
+/* 128 */ 0x02, 0x00, 0x01, 0x08, 0x05, 0x02, 0x05, 0x05,\
9280
+/* 136 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,\
9281
+/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x01, 0x00,\
9282
+/* 152 */ 0x02, 0x02, 0x01, 0x00, 0x00,}
92779283
92789284
/************** End of opcodes.h *********************************************/
92799285
/************** Continuing where we left off in vdbe.h ***********************/
92809286
92819287
/*
@@ -9287,11 +9293,11 @@
92879293
SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
92889294
SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
92899295
SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
92909296
SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
92919297
SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
9292
-SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
9298
+SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
92939299
SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
92949300
SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
92959301
SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
92969302
SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
92979303
SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
@@ -9358,10 +9364,45 @@
93589364
# define VdbeComment(X)
93599365
# define VdbeNoopComment(X)
93609366
# define VdbeModuleComment(X)
93619367
#endif
93629368
9369
+/*
9370
+** The VdbeCoverage macros are used to set a coverage testing point
9371
+** for VDBE branch instructions. The coverage testing points are line
9372
+** numbers in the sqlite3.c source file. VDBE branch coverage testing
9373
+** only works with an amalagmation build. That's ok since a VDBE branch
9374
+** coverage build designed for testing the test suite only. No application
9375
+** should ever ship with VDBE branch coverage measuring turned on.
9376
+**
9377
+** VdbeCoverage(v) // Mark the previously coded instruction
9378
+** // as a branch
9379
+**
9380
+** VdbeCoverageIf(v, conditional) // Mark previous if conditional true
9381
+**
9382
+** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken
9383
+**
9384
+** VdbeCoverageNeverTaken(v) // Previous branch is never taken
9385
+**
9386
+** Every VDBE branch operation must be tagged with one of the macros above.
9387
+** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
9388
+** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
9389
+** routine in vdbe.c, alerting the developer to the missed tag.
9390
+*/
9391
+#ifdef SQLITE_VDBE_COVERAGE
9392
+SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe*,int);
9393
+# define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
9394
+# define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
9395
+# define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2);
9396
+# define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1);
9397
+#else
9398
+# define VdbeCoverage(v)
9399
+# define VdbeCoverageIf(v,x)
9400
+# define VdbeCoverageAlwaysTaken(v)
9401
+# define VdbeCoverageNeverTaken(v)
9402
+#endif
9403
+
93639404
#endif
93649405
93659406
/************** End of vdbe.h ************************************************/
93669407
/************** Continuing where we left off in sqliteInt.h ******************/
93679408
/************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -10415,12 +10456,11 @@
1041510456
1041610457
/*
1041710458
** Return true if it OK to factor constant expressions into the initialization
1041810459
** code. The argument is a Parse object for the code generator.
1041910460
*/
10420
-#define ConstFactorOk(P) \
10421
- ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst))
10461
+#define ConstFactorOk(P) ((P)->okConstFactor)
1042210462
1042310463
/*
1042410464
** Possible values for the sqlite.magic field.
1042510465
** The numbers are obtained at random and have no special meaning, other
1042610466
** than being distinct from one another.
@@ -10642,14 +10682,20 @@
1064210682
#define SQLITE_AFF_MASK 0x67
1064310683
1064410684
/*
1064510685
** Additional bit values that can be ORed with an affinity without
1064610686
** changing the affinity.
10687
+**
10688
+** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
10689
+** It causes an assert() to fire if either operand to a comparison
10690
+** operator is NULL. It is added to certain comparison operators to
10691
+** prove that the operands are always NOT NULL.
1064710692
*/
1064810693
#define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
1064910694
#define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
1065010695
#define SQLITE_NULLEQ 0x80 /* NULL=NULL */
10696
+#define SQLITE_NOTNULL 0x88 /* Assert that operands are never NULL */
1065110697
1065210698
/*
1065310699
** An object of this type is created for each virtual table present in
1065410700
** the database schema.
1065510701
**
@@ -11347,10 +11393,11 @@
1134711393
char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
1134811394
Table *pTab; /* An SQL table corresponding to zName */
1134911395
Select *pSelect; /* A SELECT statement used in place of a table name */
1135011396
int addrFillSub; /* Address of subroutine to manifest a subquery */
1135111397
int regReturn; /* Register holding return address of addrFillSub */
11398
+ int regResult; /* Registers holding results of a co-routine */
1135211399
u8 jointype; /* Type of join between this able and the previous */
1135311400
unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
1135411401
unsigned isCorrelated :1; /* True if sub-query is correlated */
1135511402
unsigned viaCoroutine :1; /* Implemented as a co-routine */
1135611403
unsigned isRecursive :1; /* True for recursive reference in WITH */
@@ -11475,11 +11522,10 @@
1147511522
ExprList *pGroupBy; /* The GROUP BY clause */
1147611523
Expr *pHaving; /* The HAVING clause */
1147711524
ExprList *pOrderBy; /* The ORDER BY clause */
1147811525
Select *pPrior; /* Prior select in a compound select statement */
1147911526
Select *pNext; /* Next select to the left in a compound */
11480
- Select *pRightmost; /* Right-most select in a compound select statement */
1148111527
Expr *pLimit; /* LIMIT expression. NULL means not used. */
1148211528
Expr *pOffset; /* OFFSET expression. NULL means not used. */
1148311529
With *pWith; /* WITH clause attached to this select. Or NULL. */
1148411530
};
1148511531
@@ -11493,14 +11539,15 @@
1149311539
#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
1149411540
#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
1149511541
#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
1149611542
#define SF_UseSorter 0x0040 /* Sort using a sorter */
1149711543
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
11498
-#define SF_Materialize 0x0100 /* Force materialization of views */
11544
+#define SF_Materialize 0x0100 /* NOT USED */
1149911545
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1150011546
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1150111547
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11548
+#define SF_Compound 0x1000 /* Part of a compound query */
1150211549
1150311550
1150411551
/*
1150511552
** The results of a SELECT can be distributed in several ways, as defined
1150611553
** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -11675,49 +11722,48 @@
1167511722
int rc; /* Return code from execution */
1167611723
u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
1167711724
u8 checkSchema; /* Causes schema cookie check after an error */
1167811725
u8 nested; /* Number of nested calls to the parser/code generator */
1167911726
u8 nTempReg; /* Number of temporary registers in aTempReg[] */
11680
- u8 nTempInUse; /* Number of aTempReg[] currently checked out */
1168111727
u8 nColCache; /* Number of entries in aColCache[] */
1168211728
u8 iColCache; /* Next entry in aColCache[] to replace */
1168311729
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
1168411730
u8 mayAbort; /* True if statement may throw an ABORT exception */
1168511731
u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
11732
+ u8 okConstFactor; /* OK to factor out constants */
1168611733
int aTempReg[8]; /* Holding area for temporary registers */
1168711734
int nRangeReg; /* Size of the temporary register block */
1168811735
int iRangeReg; /* First register in temporary register block */
1168911736
int nErr; /* Number of errors seen */
1169011737
int nTab; /* Number of previously allocated VDBE cursors */
1169111738
int nMem; /* Number of memory cells used so far */
1169211739
int nSet; /* Number of sets used so far */
1169311740
int nOnce; /* Number of OP_Once instructions so far */
1169411741
int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
11695
- int nLabel; /* Number of labels used */
11696
- int *aLabel; /* Space to hold the labels */
1169711742
int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
1169811743
int ckBase; /* Base register of data during check constraints */
1169911744
int iPartIdxTab; /* Table corresponding to a partial index */
1170011745
int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
1170111746
int iCacheCnt; /* Counter used to generate aColCache[].lru values */
11747
+ int nLabel; /* Number of labels used */
11748
+ int *aLabel; /* Space to hold the labels */
1170211749
struct yColCache {
1170311750
int iTable; /* Table cursor number */
11704
- int iColumn; /* Table column number */
11751
+ i16 iColumn; /* Table column number */
1170511752
u8 tempReg; /* iReg is a temp register that needs to be freed */
1170611753
int iLevel; /* Nesting level */
1170711754
int iReg; /* Reg with value of this column. 0 means none. */
1170811755
int lru; /* Least recently used entry has the smallest value */
1170911756
} aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
1171011757
ExprList *pConstExpr;/* Constant expressions */
11758
+ Token constraintName;/* Name of the constraint currently being parsed */
1171111759
yDbMask writeMask; /* Start a write transaction on these databases */
1171211760
yDbMask cookieMask; /* Bitmask of schema verified databases */
11713
- int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
1171411761
int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
1171511762
int regRowid; /* Register holding rowid of CREATE TABLE entry */
1171611763
int regRoot; /* Register holding root page number for new objects */
1171711764
int nMaxArg; /* Max args passed to user function by sub-program */
11718
- Token constraintName;/* Name of the constraint currently being parsed */
1171911765
#ifndef SQLITE_OMIT_SHARED_CACHE
1172011766
int nTableLock; /* Number of locks in aTableLock */
1172111767
TableLock *aTableLock; /* Required table locks for shared-cache mode */
1172211768
#endif
1172311769
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -11732,16 +11778,21 @@
1173211778
u32 newmask; /* Mask of new.* columns referenced */
1173311779
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
1173411780
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
1173511781
u8 disableTriggers; /* True to disable triggers */
1173611782
11737
- /* Above is constant between recursions. Below is reset before and after
11738
- ** each recursion */
11783
+ /************************************************************************
11784
+ ** Above is constant between recursions. Below is reset before and after
11785
+ ** each recursion. The boundary between these two regions is determined
11786
+ ** using offsetof(Parse,nVar) so the nVar field must be the first field
11787
+ ** in the recursive region.
11788
+ ************************************************************************/
1173911789
1174011790
int nVar; /* Number of '?' variables seen in the SQL so far */
1174111791
int nzVar; /* Number of available slots in azVar[] */
1174211792
u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
11793
+ u8 bFreeWith; /* True if pWith should be freed with parser */
1174311794
u8 explain; /* True if the EXPLAIN flag is found on the query */
1174411795
#ifndef SQLITE_OMIT_VIRTUALTABLE
1174511796
u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
1174611797
int nVtabLock; /* Number of virtual tables to lock */
1174711798
#endif
@@ -11764,11 +11815,10 @@
1176411815
Table **apVtabLock; /* Pointer to virtual tables needing locking */
1176511816
#endif
1176611817
Table *pZombieTab; /* List of Table objects to delete after code gen */
1176711818
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
1176811819
With *pWith; /* Current WITH clause, or NULL */
11769
- u8 bFreeWith; /* True if pWith should be freed with parser */
1177011820
};
1177111821
1177211822
/*
1177311823
** Return true if currently inside an sqlite3_declare_vtab() call.
1177411824
*/
@@ -11980,10 +12030,17 @@
1198012030
int bLocaltimeFault; /* True to fail localtime() calls */
1198112031
#ifdef SQLITE_ENABLE_SQLLOG
1198212032
void(*xSqllog)(void*,sqlite3*,const char*, int);
1198312033
void *pSqllogArg;
1198412034
#endif
12035
+#ifdef SQLITE_VDBE_COVERAGE
12036
+ /* The following callback (if not NULL) is invoked on every VDBE branch
12037
+ ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
12038
+ */
12039
+ void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */
12040
+ void *pVdbeBranchArg; /* 1st argument */
12041
+#endif
1198512042
};
1198612043
1198712044
/*
1198812045
** This macro is used inside of assert() statements to indicate that
1198912046
** the assert is only valid on a well-formed database. Instead of:
@@ -12313,11 +12370,10 @@
1231312370
SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
1231412371
#else
1231512372
# define sqlite3AutoincrementBegin(X)
1231612373
# define sqlite3AutoincrementEnd(X)
1231712374
#endif
12318
-SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse*, Select*, SelectDest*);
1231912375
SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int);
1232012376
SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
1232112377
SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
1232212378
SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
1232312379
SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -12361,15 +12417,16 @@
1236112417
SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
1236212418
SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
1236312419
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
1236412420
SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
1236512421
SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12366
-SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
12422
+SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
12423
+SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
1236712424
SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
1236812425
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
1236912426
SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12370
-SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12427
+SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
1237112428
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
1237212429
#define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
1237312430
#define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
1237412431
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
1237512432
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
@@ -12403,11 +12460,10 @@
1240312460
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1240412461
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1240512462
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
1240612463
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
1240712464
SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12408
-SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
1240912465
SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
1241012466
SQLITE_PRIVATE int sqlite3IsRowid(const char*);
1241112467
SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
1241212468
SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
1241312469
SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
@@ -12547,11 +12603,11 @@
1254712603
#define getVarint sqlite3GetVarint
1254812604
#define putVarint sqlite3PutVarint
1254912605
1255012606
1255112607
SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
12552
-SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
12608
+SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
1255312609
SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
1255412610
SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
1255512611
SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
1255612612
SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
1255712613
SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
@@ -13651,11 +13707,10 @@
1365113707
u8 rowidIsValid; /* True if lastRowid is valid */
1365213708
u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1365313709
Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
1365413710
Bool isTable:1; /* True if a table requiring integer keys */
1365513711
Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13656
- Bool multiPseudo:1; /* Multi-register pseudo-cursor */
1365713712
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
1365813713
i64 seqCount; /* Sequence counter */
1365913714
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
1366013715
i64 lastRowid; /* Rowid being deleted by OP_Delete */
1366113716
VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -13745,11 +13800,11 @@
1374513800
RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
1374613801
VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
1374713802
} u;
1374813803
int n; /* Number of characters in string value, excluding '\0' */
1374913804
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
13750
- u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
13805
+ u8 memType; /* Lower 5 bits of flags */
1375113806
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
1375213807
#ifdef SQLITE_DEBUG
1375313808
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
1375413809
void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
1375513810
#endif
@@ -13774,11 +13829,11 @@
1377413829
#define MEM_Int 0x0004 /* Value is an integer */
1377513830
#define MEM_Real 0x0008 /* Value is a real number */
1377613831
#define MEM_Blob 0x0010 /* Value is a BLOB */
1377713832
#define MEM_RowSet 0x0020 /* Value is a RowSet object */
1377813833
#define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
13779
-#define MEM_Invalid 0x0080 /* Value is undefined */
13834
+#define MEM_Undefined 0x0080 /* Value is undefined */
1378013835
#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
1378113836
#define MEM_TypeMask 0x01ff /* Mask of type bits */
1378213837
1378313838
1378413839
/* Whenever Mem contains a valid string or blob representation, one of
@@ -13806,11 +13861,11 @@
1380613861
/*
1380713862
** Return true if a memory cell is not marked as invalid. This macro
1380813863
** is for use inside assert() statements only.
1380913864
*/
1381013865
#ifdef SQLITE_DEBUG
13811
-#define memIsValid(M) ((M)->flags & MEM_Invalid)==0
13866
+#define memIsValid(M) ((M)->flags & MEM_Undefined)==0
1381213867
#endif
1381313868
1381413869
/*
1381513870
** Each auxilliary data pointer stored by a user defined function
1381613871
** implementation calling sqlite3_set_auxdata() is stored in an instance
@@ -14001,20 +14056,22 @@
1400114056
SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
1400214057
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
1400314058
SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
1400414059
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
1400514060
SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
14061
+#define VdbeMemDynamic(X) \
14062
+ (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
1400614063
#define VdbeMemRelease(X) \
14007
- if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
14008
- sqlite3VdbeMemReleaseExternal(X);
14064
+ if( VdbeMemDynamic(X) ) sqlite3VdbeMemReleaseExternal(X);
1400914065
SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
1401014066
SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
1401114067
SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
1401214068
SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
1401314069
SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
1401414070
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
14015
-SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
14071
+#define sqlite3VdbeMemStoreType(X) (X)->memType = (u8)((X)->flags&0x1f)
14072
+/* void sqlite3VdbeMemStoreType(Mem *pMem); */
1401614073
SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
1401714074
1401814075
SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
1401914076
SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
1402014077
SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
@@ -17778,10 +17835,16 @@
1777817835
mem5.totalExcess += iFullSz - nByte;
1777917836
mem5.currentCount++;
1778017837
mem5.currentOut += iFullSz;
1778117838
if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
1778217839
if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
17840
+
17841
+#ifdef SQLITE_DEBUG
17842
+ /* Make sure the allocated memory does not assume that it is set to zero
17843
+ ** or retains a value from a previous allocation */
17844
+ memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz);
17845
+#endif
1778317846
1778417847
/* Return a pointer to the allocated memory. */
1778517848
return (void*)&mem5.zPool[i*mem5.szAtom];
1778617849
}
1778717850
@@ -17836,10 +17899,17 @@
1783617899
mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
1783717900
mem5.aCtrl[iBuddy] = 0;
1783817901
}
1783917902
size *= 2;
1784017903
}
17904
+
17905
+#ifdef SQLITE_DEBUG
17906
+ /* Overwrite freed memory with the 0x55 bit pattern to verify that it is
17907
+ ** not used after being freed */
17908
+ memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size);
17909
+#endif
17910
+
1784117911
memsys5Link(iBlock, iLogsize);
1784217912
}
1784317913
1784417914
/*
1784517915
** Allocate nBytes of memory.
@@ -22739,17 +22809,16 @@
2273922809
testcase( iB==-1 ); testcase( iB==0 );
2274022810
if( iB>=0 ){
2274122811
testcase( iA>0 && LARGEST_INT64 - iA == iB );
2274222812
testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
2274322813
if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
22744
- *pA += iB;
2274522814
}else{
2274622815
testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
2274722816
testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
2274822817
if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
22749
- *pA += iB;
2275022818
}
22819
+ *pA += iB;
2275122820
return 0;
2275222821
}
2275322822
SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
2275422823
testcase( iB==SMALLEST_INT64+1 );
2275522824
if( iB==SMALLEST_INT64 ){
@@ -22769,13 +22838,22 @@
2276922838
2277022839
iA1 = iA/TWOPOWER32;
2277122840
iA0 = iA % TWOPOWER32;
2277222841
iB1 = iB/TWOPOWER32;
2277322842
iB0 = iB % TWOPOWER32;
22774
- if( iA1*iB1 != 0 ) return 1;
22775
- assert( iA1*iB0==0 || iA0*iB1==0 );
22776
- r = iA1*iB0 + iA0*iB1;
22843
+ if( iA1==0 ){
22844
+ if( iB1==0 ){
22845
+ *pA *= iB;
22846
+ return 0;
22847
+ }
22848
+ r = iA0*iB1;
22849
+ }else if( iB1==0 ){
22850
+ r = iA1*iB0;
22851
+ }else{
22852
+ /* If both iA1 and iB1 are non-zero, overflow will result */
22853
+ return 1;
22854
+ }
2277722855
testcase( r==(-TWOPOWER31)-1 );
2277822856
testcase( r==(-TWOPOWER31) );
2277922857
testcase( r==TWOPOWER31 );
2278022858
testcase( r==TWOPOWER31-1 );
2278122859
if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
@@ -23217,75 +23295,75 @@
2321723295
/* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"),
2321823296
/* 16 */ "Goto" OpHelp(""),
2321923297
/* 17 */ "Gosub" OpHelp(""),
2322023298
/* 18 */ "Return" OpHelp(""),
2322123299
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
23222
- /* 20 */ "Yield" OpHelp(""),
23223
- /* 21 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
23224
- /* 22 */ "Halt" OpHelp(""),
23225
- /* 23 */ "Integer" OpHelp("r[P2]=P1"),
23226
- /* 24 */ "Int64" OpHelp("r[P2]=P4"),
23227
- /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23228
- /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
23229
- /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23230
- /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23231
- /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23232
- /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23233
- /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23234
- /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23235
- /* 33 */ "CollSeq" OpHelp(""),
23236
- /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23237
- /* 35 */ "MustBeInt" OpHelp(""),
23238
- /* 36 */ "RealAffinity" OpHelp(""),
23239
- /* 37 */ "Permutation" OpHelp(""),
23240
- /* 38 */ "Compare" OpHelp(""),
23241
- /* 39 */ "Jump" OpHelp(""),
23242
- /* 40 */ "Once" OpHelp(""),
23243
- /* 41 */ "If" OpHelp(""),
23244
- /* 42 */ "IfNot" OpHelp(""),
23245
- /* 43 */ "Column" OpHelp("r[P3]=PX"),
23246
- /* 44 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23247
- /* 45 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23248
- /* 46 */ "Count" OpHelp("r[P2]=count()"),
23249
- /* 47 */ "ReadCookie" OpHelp(""),
23250
- /* 48 */ "SetCookie" OpHelp(""),
23251
- /* 49 */ "VerifyCookie" OpHelp(""),
23252
- /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23253
- /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23254
- /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23255
- /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23256
- /* 54 */ "SorterOpen" OpHelp(""),
23257
- /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23258
- /* 56 */ "Close" OpHelp(""),
23259
- /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23260
- /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23261
- /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23262
- /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23263
- /* 61 */ "Seek" OpHelp("intkey=r[P2]"),
23264
- /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23265
- /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"),
23266
- /* 64 */ "Found" OpHelp("key=r[P3@P4]"),
23267
- /* 65 */ "NotExists" OpHelp("intkey=r[P3]"),
23268
- /* 66 */ "Sequence" OpHelp("r[P2]=rowid"),
23269
- /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"),
23270
- /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23271
- /* 69 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23272
- /* 70 */ "Delete" OpHelp(""),
23300
+ /* 20 */ "InitCoroutine" OpHelp(""),
23301
+ /* 21 */ "EndCoroutine" OpHelp(""),
23302
+ /* 22 */ "Yield" OpHelp(""),
23303
+ /* 23 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
23304
+ /* 24 */ "Halt" OpHelp(""),
23305
+ /* 25 */ "Integer" OpHelp("r[P2]=P1"),
23306
+ /* 26 */ "Int64" OpHelp("r[P2]=P4"),
23307
+ /* 27 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23308
+ /* 28 */ "Null" OpHelp("r[P2..P3]=NULL"),
23309
+ /* 29 */ "SoftNull" OpHelp("r[P1]=NULL"),
23310
+ /* 30 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23311
+ /* 31 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23312
+ /* 32 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23313
+ /* 33 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23314
+ /* 34 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23315
+ /* 35 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23316
+ /* 36 */ "CollSeq" OpHelp(""),
23317
+ /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23318
+ /* 38 */ "MustBeInt" OpHelp(""),
23319
+ /* 39 */ "RealAffinity" OpHelp(""),
23320
+ /* 40 */ "Permutation" OpHelp(""),
23321
+ /* 41 */ "Compare" OpHelp(""),
23322
+ /* 42 */ "Jump" OpHelp(""),
23323
+ /* 43 */ "Once" OpHelp(""),
23324
+ /* 44 */ "If" OpHelp(""),
23325
+ /* 45 */ "IfNot" OpHelp(""),
23326
+ /* 46 */ "Column" OpHelp("r[P3]=PX"),
23327
+ /* 47 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23328
+ /* 48 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23329
+ /* 49 */ "Count" OpHelp("r[P2]=count()"),
23330
+ /* 50 */ "ReadCookie" OpHelp(""),
23331
+ /* 51 */ "SetCookie" OpHelp(""),
23332
+ /* 52 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23333
+ /* 53 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23334
+ /* 54 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23335
+ /* 55 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23336
+ /* 56 */ "SorterOpen" OpHelp(""),
23337
+ /* 57 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23338
+ /* 58 */ "Close" OpHelp(""),
23339
+ /* 59 */ "SeekLT" OpHelp(""),
23340
+ /* 60 */ "SeekLE" OpHelp(""),
23341
+ /* 61 */ "SeekGE" OpHelp(""),
23342
+ /* 62 */ "SeekGT" OpHelp(""),
23343
+ /* 63 */ "Seek" OpHelp("intkey=r[P2]"),
23344
+ /* 64 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23345
+ /* 65 */ "NotFound" OpHelp("key=r[P3@P4]"),
23346
+ /* 66 */ "Found" OpHelp("key=r[P3@P4]"),
23347
+ /* 67 */ "NotExists" OpHelp("intkey=r[P3]"),
23348
+ /* 68 */ "Sequence" OpHelp("r[P2]=rowid"),
23349
+ /* 69 */ "NewRowid" OpHelp("r[P2]=rowid"),
23350
+ /* 70 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
2327323351
/* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
2327423352
/* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23275
- /* 73 */ "ResetCount" OpHelp(""),
23276
- /* 74 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23277
- /* 75 */ "SorterData" OpHelp("r[P2]=data"),
23353
+ /* 73 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23354
+ /* 74 */ "Delete" OpHelp(""),
23355
+ /* 75 */ "ResetCount" OpHelp(""),
2327823356
/* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
2327923357
/* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
2328023358
/* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
2328123359
/* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
2328223360
/* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
2328323361
/* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
2328423362
/* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
2328523363
/* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23286
- /* 84 */ "RowKey" OpHelp("r[P2]=key"),
23364
+ /* 84 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
2328723365
/* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
2328823366
/* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
2328923367
/* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
2329023368
/* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
2329123369
/* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23292,68 +23370,72 @@
2329223370
/* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
2329323371
/* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
2329423372
/* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
2329523373
/* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2329623374
/* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23297
- /* 95 */ "RowData" OpHelp("r[P2]=data"),
23375
+ /* 95 */ "SorterData" OpHelp("r[P2]=data"),
2329823376
/* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
2329923377
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
23300
- /* 98 */ "Rowid" OpHelp("r[P2]=rowid"),
23301
- /* 99 */ "NullRow" OpHelp(""),
23302
- /* 100 */ "Last" OpHelp(""),
23303
- /* 101 */ "SorterSort" OpHelp(""),
23304
- /* 102 */ "Sort" OpHelp(""),
23305
- /* 103 */ "Rewind" OpHelp(""),
23306
- /* 104 */ "SorterInsert" OpHelp(""),
23307
- /* 105 */ "IdxInsert" OpHelp("key=r[P2]"),
23308
- /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23309
- /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23310
- /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23311
- /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23312
- /* 110 */ "Destroy" OpHelp(""),
23313
- /* 111 */ "Clear" OpHelp(""),
23314
- /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23315
- /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23316
- /* 114 */ "ParseSchema" OpHelp(""),
23317
- /* 115 */ "LoadAnalysis" OpHelp(""),
23318
- /* 116 */ "DropTable" OpHelp(""),
23319
- /* 117 */ "DropIndex" OpHelp(""),
23320
- /* 118 */ "DropTrigger" OpHelp(""),
23321
- /* 119 */ "IntegrityCk" OpHelp(""),
23322
- /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23323
- /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23324
- /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23325
- /* 123 */ "Program" OpHelp(""),
23326
- /* 124 */ "Param" OpHelp(""),
23327
- /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23328
- /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23329
- /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23330
- /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23331
- /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23332
- /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23333
- /* 131 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23334
- /* 132 */ "IncrVacuum" OpHelp(""),
23378
+ /* 98 */ "RowKey" OpHelp("r[P2]=key"),
23379
+ /* 99 */ "RowData" OpHelp("r[P2]=data"),
23380
+ /* 100 */ "Rowid" OpHelp("r[P2]=rowid"),
23381
+ /* 101 */ "NullRow" OpHelp(""),
23382
+ /* 102 */ "Last" OpHelp(""),
23383
+ /* 103 */ "SorterSort" OpHelp(""),
23384
+ /* 104 */ "Sort" OpHelp(""),
23385
+ /* 105 */ "Rewind" OpHelp(""),
23386
+ /* 106 */ "SorterInsert" OpHelp(""),
23387
+ /* 107 */ "IdxInsert" OpHelp("key=r[P2]"),
23388
+ /* 108 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23389
+ /* 109 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23390
+ /* 110 */ "IdxLE" OpHelp("key=r[P3@P4]"),
23391
+ /* 111 */ "IdxGT" OpHelp("key=r[P3@P4]"),
23392
+ /* 112 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23393
+ /* 113 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23394
+ /* 114 */ "Destroy" OpHelp(""),
23395
+ /* 115 */ "Clear" OpHelp(""),
23396
+ /* 116 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23397
+ /* 117 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23398
+ /* 118 */ "ParseSchema" OpHelp(""),
23399
+ /* 119 */ "LoadAnalysis" OpHelp(""),
23400
+ /* 120 */ "DropTable" OpHelp(""),
23401
+ /* 121 */ "DropIndex" OpHelp(""),
23402
+ /* 122 */ "DropTrigger" OpHelp(""),
23403
+ /* 123 */ "IntegrityCk" OpHelp(""),
23404
+ /* 124 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23405
+ /* 125 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23406
+ /* 126 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23407
+ /* 127 */ "Program" OpHelp(""),
23408
+ /* 128 */ "Param" OpHelp(""),
23409
+ /* 129 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23410
+ /* 130 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23411
+ /* 131 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23412
+ /* 132 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
2333523413
/* 133 */ "Real" OpHelp("r[P2]=P4"),
23336
- /* 134 */ "Expire" OpHelp(""),
23337
- /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23338
- /* 136 */ "VBegin" OpHelp(""),
23339
- /* 137 */ "VCreate" OpHelp(""),
23340
- /* 138 */ "VDestroy" OpHelp(""),
23341
- /* 139 */ "VOpen" OpHelp(""),
23342
- /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23343
- /* 141 */ "VNext" OpHelp(""),
23344
- /* 142 */ "VRename" OpHelp(""),
23414
+ /* 134 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23415
+ /* 135 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23416
+ /* 136 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23417
+ /* 137 */ "IncrVacuum" OpHelp(""),
23418
+ /* 138 */ "Expire" OpHelp(""),
23419
+ /* 139 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23420
+ /* 140 */ "VBegin" OpHelp(""),
23421
+ /* 141 */ "VCreate" OpHelp(""),
23422
+ /* 142 */ "VDestroy" OpHelp(""),
2334523423
/* 143 */ "ToText" OpHelp(""),
2334623424
/* 144 */ "ToBlob" OpHelp(""),
2334723425
/* 145 */ "ToNumeric" OpHelp(""),
2334823426
/* 146 */ "ToInt" OpHelp(""),
2334923427
/* 147 */ "ToReal" OpHelp(""),
23350
- /* 148 */ "Pagecount" OpHelp(""),
23351
- /* 149 */ "MaxPgcnt" OpHelp(""),
23352
- /* 150 */ "Trace" OpHelp(""),
23353
- /* 151 */ "Noop" OpHelp(""),
23354
- /* 152 */ "Explain" OpHelp(""),
23428
+ /* 148 */ "VOpen" OpHelp(""),
23429
+ /* 149 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23430
+ /* 150 */ "VNext" OpHelp(""),
23431
+ /* 151 */ "VRename" OpHelp(""),
23432
+ /* 152 */ "Pagecount" OpHelp(""),
23433
+ /* 153 */ "MaxPgcnt" OpHelp(""),
23434
+ /* 154 */ "Init" OpHelp("Start at P2"),
23435
+ /* 155 */ "Noop" OpHelp(""),
23436
+ /* 156 */ "Explain" OpHelp(""),
2335523437
};
2335623438
return azName[i];
2335723439
}
2335823440
#endif
2335923441
@@ -34429,11 +34511,11 @@
3442934511
** Windows will only let you create file view mappings
3443034512
** on allocation size granularity boundaries.
3443134513
** During sqlite3_os_init() we do a GetSystemInfo()
3443234514
** to get the granularity size.
3443334515
*/
34434
-SYSTEM_INFO winSysInfo;
34516
+static SYSTEM_INFO winSysInfo;
3443534517
3443634518
#ifndef SQLITE_OMIT_WAL
3443734519
3443834520
/*
3443934521
** Helper functions to obtain and relinquish the global mutex. The
@@ -36363,19 +36445,16 @@
3636336445
#ifndef SQLITE_OMIT_LOAD_EXTENSION
3636436446
/*
3636536447
** Interfaces for opening a shared library, finding entry points
3636636448
** within the shared library, and closing the shared library.
3636736449
*/
36368
-/*
36369
-** Interfaces for opening a shared library, finding entry points
36370
-** within the shared library, and closing the shared library.
36371
-*/
3637236450
static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
3637336451
HANDLE h;
3637436452
void *zConverted = winConvertFromUtf8Filename(zFilename);
3637536453
UNUSED_PARAMETER(pVfs);
3637636454
if( zConverted==0 ){
36455
+ OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
3637736456
return 0;
3637836457
}
3637936458
if( osIsNT() ){
3638036459
#if SQLITE_OS_WINRT
3638136460
h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
@@ -36386,24 +36465,30 @@
3638636465
#ifdef SQLITE_WIN32_HAS_ANSI
3638736466
else{
3638836467
h = osLoadLibraryA((char*)zConverted);
3638936468
}
3639036469
#endif
36470
+ OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
3639136471
sqlite3_free(zConverted);
3639236472
return (void*)h;
3639336473
}
3639436474
static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
3639536475
UNUSED_PARAMETER(pVfs);
3639636476
winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
3639736477
}
3639836478
static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
36479
+ FARPROC proc;
3639936480
UNUSED_PARAMETER(pVfs);
36400
- return (void(*)(void))osGetProcAddressA((HANDLE)pH, zSym);
36481
+ proc = osGetProcAddressA((HANDLE)pH, zSym);
36482
+ OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n",
36483
+ (void*)pH, zSym, (void*)proc));
36484
+ return (void(*)(void))proc;
3640136485
}
3640236486
static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
3640336487
UNUSED_PARAMETER(pVfs);
3640436488
osFreeLibrary((HANDLE)pHandle);
36489
+ OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle));
3640536490
}
3640636491
#else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
3640736492
#define winDlOpen 0
3640836493
#define winDlError 0
3640936494
#define winDlSym 0
@@ -37095,11 +37180,12 @@
3709537180
PgHdr *pSynced; /* Last synced page in dirty page list */
3709637181
int nRef; /* Number of referenced pages */
3709737182
int szCache; /* Configured cache size */
3709837183
int szPage; /* Size of every page in this cache */
3709937184
int szExtra; /* Size of extra space for each page */
37100
- int bPurgeable; /* True if pages are on backing store */
37185
+ u8 bPurgeable; /* True if pages are on backing store */
37186
+ u8 eCreate; /* eCreate value for for xFetch() */
3710137187
int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
3710237188
void *pStress; /* Argument to xStress */
3710337189
sqlite3_pcache *pCache; /* Pluggable cache module */
3710437190
PgHdr *pPage1; /* Reference to page 1 */
3710537191
};
@@ -37162,10 +37248,14 @@
3716237248
if( pPage->pDirtyPrev ){
3716337249
pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
3716437250
}else{
3716537251
assert( pPage==p->pDirty );
3716637252
p->pDirty = pPage->pDirtyNext;
37253
+ if( p->pDirty==0 && p->bPurgeable ){
37254
+ assert( p->eCreate==1 );
37255
+ p->eCreate = 2;
37256
+ }
3716737257
}
3716837258
pPage->pDirtyNext = 0;
3716937259
pPage->pDirtyPrev = 0;
3717037260
3717137261
expensive_assert( pcacheCheckSynced(p) );
@@ -37182,10 +37272,13 @@
3718237272
3718337273
pPage->pDirtyNext = p->pDirty;
3718437274
if( pPage->pDirtyNext ){
3718537275
assert( pPage->pDirtyNext->pDirtyPrev==0 );
3718637276
pPage->pDirtyNext->pDirtyPrev = pPage;
37277
+ }else if( p->bPurgeable ){
37278
+ assert( p->eCreate==2 );
37279
+ p->eCreate = 1;
3718737280
}
3718837281
p->pDirty = pPage;
3718937282
if( !p->pDirtyTail ){
3719037283
p->pDirtyTail = pPage;
3719137284
}
@@ -37251,10 +37344,11 @@
3725137344
){
3725237345
memset(p, 0, sizeof(PCache));
3725337346
p->szPage = szPage;
3725437347
p->szExtra = szExtra;
3725537348
p->bPurgeable = bPurgeable;
37349
+ p->eCreate = 2;
3725637350
p->xStress = xStress;
3725737351
p->pStress = pStress;
3725837352
p->szCache = 100;
3725937353
}
3726037354
@@ -37290,11 +37384,11 @@
3729037384
PCache *pCache, /* Obtain the page from this cache */
3729137385
Pgno pgno, /* Page number to obtain */
3729237386
int createFlag, /* If true, create page if it does not exist already */
3729337387
PgHdr **ppPage /* Write the page here */
3729437388
){
37295
- sqlite3_pcache_page *pPage = 0;
37389
+ sqlite3_pcache_page *pPage;
3729637390
PgHdr *pPgHdr = 0;
3729737391
int eCreate;
3729837392
3729937393
assert( pCache!=0 );
3730037394
assert( createFlag==1 || createFlag==0 );
@@ -37301,12 +37395,16 @@
3730137395
assert( pgno>0 );
3730237396
3730337397
/* If the pluggable cache (sqlite3_pcache*) has not been allocated,
3730437398
** allocate it now.
3730537399
*/
37306
- if( !pCache->pCache && createFlag ){
37400
+ if( !pCache->pCache ){
3730737401
sqlite3_pcache *p;
37402
+ if( !createFlag ){
37403
+ *ppPage = 0;
37404
+ return SQLITE_OK;
37405
+ }
3730837406
p = sqlite3GlobalConfig.pcache2.xCreate(
3730937407
pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
3731037408
);
3731137409
if( !p ){
3731237410
return SQLITE_NOMEM;
@@ -37313,15 +37411,20 @@
3731337411
}
3731437412
sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
3731537413
pCache->pCache = p;
3731637414
}
3731737415
37318
- eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
37319
- if( pCache->pCache ){
37320
- pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
37321
- }
37322
-
37416
+ /* eCreate defines what to do if the page does not exist.
37417
+ ** 0 Do not allocate a new page. (createFlag==0)
37418
+ ** 1 Allocate a new page if doing so is inexpensive.
37419
+ ** (createFlag==1 AND bPurgeable AND pDirty)
37420
+ ** 2 Allocate a new page even it doing so is difficult.
37421
+ ** (createFlag==1 AND !(bPurgeable AND pDirty)
37422
+ */
37423
+ eCreate = createFlag==0 ? 0 : pCache->eCreate;
37424
+ assert( (createFlag*(1+(!pCache->bPurgeable||!pCache->pDirty)))==eCreate );
37425
+ pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
3732337426
if( !pPage && eCreate==1 ){
3732437427
PgHdr *pPg;
3732537428
3732637429
/* Find a dirty page to write-out and recycle. First try to find a
3732737430
** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
@@ -47905,11 +48008,11 @@
4790548008
if( rc!=SQLITE_OK ){
4790648009
walIndexClose(pRet, 0);
4790748010
sqlite3OsClose(pRet->pWalFd);
4790848011
sqlite3_free(pRet);
4790948012
}else{
47910
- int iDC = sqlite3OsDeviceCharacteristics(pRet->pWalFd);
48013
+ int iDC = sqlite3OsDeviceCharacteristics(pDbFd);
4791148014
if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
4791248015
if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){
4791348016
pRet->padToSectorBoundary = 0;
4791448017
}
4791548018
*ppWal = pRet;
@@ -49276,11 +49379,11 @@
4927649379
if( rc ) return rc;
4927749380
iOffset += iFirstAmt;
4927849381
iAmt -= iFirstAmt;
4927949382
pContent = (void*)(iFirstAmt + (char*)pContent);
4928049383
assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) );
49281
- rc = sqlite3OsSync(p->pFd, p->syncFlags);
49384
+ rc = sqlite3OsSync(p->pFd, p->syncFlags & SQLITE_SYNC_MASK);
4928249385
if( iAmt==0 || rc ) return rc;
4928349386
}
4928449387
rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
4928549388
return rc;
4928649389
}
@@ -50214,11 +50317,10 @@
5021450317
struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
5021550318
#ifndef SQLITE_OMIT_INCRBLOB
5021650319
Pgno *aOverflow; /* Cache of overflow page locations */
5021750320
#endif
5021850321
Pgno pgnoRoot; /* The root page of this tree */
50219
- sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */
5022050322
CellInfo info; /* A parse of the cell we are pointing at */
5022150323
i64 nKey; /* Size of pKey, or last integer key */
5022250324
void *pKey; /* Saved key that was cursor's last known position */
5022350325
int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
5022450326
u8 wrFlag; /* True if writable */
@@ -52198,17 +52300,16 @@
5219852300
assert( sqlite3_mutex_held(pBt->mutex) );
5219952301
if( pBt->btsFlags & BTS_SECURE_DELETE ){
5220052302
memset(&data[hdr], 0, pBt->usableSize - hdr);
5220152303
}
5220252304
data[hdr] = (char)flags;
52203
- first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0);
52305
+ first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
5220452306
memset(&data[hdr+1], 0, 4);
5220552307
data[hdr+7] = 0;
5220652308
put2byte(&data[hdr+5], pBt->usableSize);
5220752309
pPage->nFree = (u16)(pBt->usableSize - first);
5220852310
decodeFlags(pPage, flags);
52209
- pPage->hdrOffset = hdr;
5221052311
pPage->cellOffset = first;
5221152312
pPage->aDataEnd = &data[pBt->usableSize];
5221252313
pPage->aCellIdx = &data[first];
5221352314
pPage->nOverflow = 0;
5221452315
assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
@@ -54288,11 +54389,10 @@
5428854389
if( pCur->pNext ){
5428954390
pCur->pNext->pPrev = pCur;
5429054391
}
5429154392
pBt->pCursor = pCur;
5429254393
pCur->eState = CURSOR_INVALID;
54293
- pCur->cachedRowid = 0;
5429454394
return SQLITE_OK;
5429554395
}
5429654396
SQLITE_PRIVATE int sqlite3BtreeCursor(
5429754397
Btree *p, /* The btree */
5429854398
int iTable, /* Root page of table to open */
@@ -54329,40 +54429,10 @@
5432954429
*/
5433054430
SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){
5433154431
memset(p, 0, offsetof(BtCursor, iPage));
5433254432
}
5433354433
54334
-/*
54335
-** Set the cached rowid value of every cursor in the same database file
54336
-** as pCur and having the same root page number as pCur. The value is
54337
-** set to iRowid.
54338
-**
54339
-** Only positive rowid values are considered valid for this cache.
54340
-** The cache is initialized to zero, indicating an invalid cache.
54341
-** A btree will work fine with zero or negative rowids. We just cannot
54342
-** cache zero or negative rowids, which means tables that use zero or
54343
-** negative rowids might run a little slower. But in practice, zero
54344
-** or negative rowids are very uncommon so this should not be a problem.
54345
-*/
54346
-SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor *pCur, sqlite3_int64 iRowid){
54347
- BtCursor *p;
54348
- for(p=pCur->pBt->pCursor; p; p=p->pNext){
54349
- if( p->pgnoRoot==pCur->pgnoRoot ) p->cachedRowid = iRowid;
54350
- }
54351
- assert( pCur->cachedRowid==iRowid );
54352
-}
54353
-
54354
-/*
54355
-** Return the cached rowid for the given cursor. A negative or zero
54356
-** return value indicates that the rowid cache is invalid and should be
54357
-** ignored. If the rowid cache has never before been set, then a
54358
-** zero is returned.
54359
-*/
54360
-SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor *pCur){
54361
- return pCur->cachedRowid;
54362
-}
54363
-
5436454434
/*
5436554435
** Close a cursor. The read lock on the database file is released
5436654436
** when the last cursor is closed.
5436754437
*/
5436854438
SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
@@ -55433,18 +55503,28 @@
5543355503
/*
5543455504
** Advance the cursor to the next entry in the database. If
5543555505
** successful then set *pRes=0. If the cursor
5543655506
** was already pointing to the last entry in the database before
5543755507
** this routine was called, then set *pRes=1.
55508
+**
55509
+** The calling function will set *pRes to 0 or 1. The initial *pRes value
55510
+** will be 1 if the cursor being stepped corresponds to an SQL index and
55511
+** if this routine could have been skipped if that SQL index had been
55512
+** a unique index. Otherwise the caller will have set *pRes to zero.
55513
+** Zero is the common case. The btree implementation is free to use the
55514
+** initial *pRes value as a hint to improve performance, but the current
55515
+** SQLite btree implementation does not. (Note that the comdb2 btree
55516
+** implementation does use this hint, however.)
5543855517
*/
5543955518
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
5544055519
int rc;
5544155520
int idx;
5544255521
MemPage *pPage;
5544355522
5544455523
assert( cursorHoldsMutex(pCur) );
5544555524
assert( pRes!=0 );
55525
+ assert( *pRes==0 || *pRes==1 );
5544655526
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
5544755527
if( pCur->eState!=CURSOR_VALID ){
5544855528
rc = restoreCursorPosition(pCur);
5544955529
if( rc!=SQLITE_OK ){
5545055530
*pRes = 0;
@@ -55519,17 +55599,27 @@
5551955599
/*
5552055600
** Step the cursor to the back to the previous entry in the database. If
5552155601
** successful then set *pRes=0. If the cursor
5552255602
** was already pointing to the first entry in the database before
5552355603
** this routine was called, then set *pRes=1.
55604
+**
55605
+** The calling function will set *pRes to 0 or 1. The initial *pRes value
55606
+** will be 1 if the cursor being stepped corresponds to an SQL index and
55607
+** if this routine could have been skipped if that SQL index had been
55608
+** a unique index. Otherwise the caller will have set *pRes to zero.
55609
+** Zero is the common case. The btree implementation is free to use the
55610
+** initial *pRes value as a hint to improve performance, but the current
55611
+** SQLite btree implementation does not. (Note that the comdb2 btree
55612
+** implementation does use this hint, however.)
5552455613
*/
5552555614
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
5552655615
int rc;
5552755616
MemPage *pPage;
5552855617
5552955618
assert( cursorHoldsMutex(pCur) );
5553055619
assert( pRes!=0 );
55620
+ assert( *pRes==0 || *pRes==1 );
5553155621
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
5553255622
pCur->atLast = 0;
5553355623
if( pCur->eState!=CURSOR_VALID ){
5553455624
if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){
5553555625
rc = btreeRestoreCursorPosition(pCur);
@@ -57622,15 +57712,21 @@
5762257712
** not to clear the cursor here.
5762357713
*/
5762457714
rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
5762557715
if( rc ) return rc;
5762657716
57627
- /* If this is an insert into a table b-tree, invalidate any incrblob
57628
- ** cursors open on the row being replaced (assuming this is a replace
57629
- ** operation - if it is not, the following is a no-op). */
5763057717
if( pCur->pKeyInfo==0 ){
57718
+ /* If this is an insert into a table b-tree, invalidate any incrblob
57719
+ ** cursors open on the row being replaced */
5763157720
invalidateIncrblobCursors(p, nKey, 0);
57721
+
57722
+ /* If the cursor is currently on the last row and we are appending a
57723
+ ** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto()
57724
+ ** call */
57725
+ if( pCur->validNKey && nKey>0 && pCur->info.nKey==nKey-1 ){
57726
+ loc = -1;
57727
+ }
5763257728
}
5763357729
5763457730
if( !loc ){
5763557731
rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
5763657732
if( rc ) return rc;
@@ -57696,12 +57792,12 @@
5769657792
** entry in the table, and the next row inserted has an integer key
5769757793
** larger than the largest existing key, it is possible to insert the
5769857794
** row without seeking the cursor. This can be a big performance boost.
5769957795
*/
5770057796
pCur->info.nSize = 0;
57701
- pCur->validNKey = 0;
5770257797
if( rc==SQLITE_OK && pPage->nOverflow ){
57798
+ pCur->validNKey = 0;
5770357799
rc = balance(pCur);
5770457800
5770557801
/* Must make sure nOverflow is reset to zero even if the balance()
5770657802
** fails. Internal data structure corruption will result otherwise.
5770757803
** Also, set the cursor state to invalid. This stops saveCursorPosition()
@@ -57752,11 +57848,11 @@
5775257848
** from the internal node. The 'previous' entry is used for this instead
5775357849
** of the 'next' entry, as the previous entry is always a part of the
5775457850
** sub-tree headed by the child page of the cell being deleted. This makes
5775557851
** balancing the tree following the delete operation easier. */
5775657852
if( !pPage->leaf ){
57757
- int notUsed;
57853
+ int notUsed = 0;
5775857854
rc = sqlite3BtreePrevious(pCur, &notUsed);
5775957855
if( rc ) return rc;
5776057856
}
5776157857
5776257858
/* Save the positions of any other cursors open on this table before
@@ -60177,11 +60273,11 @@
6017760273
}
6017860274
6017960275
/*
6018060276
** Release any memory held by the Mem. This may leave the Mem in an
6018160277
** inconsistent state, for example with (Mem.z==0) and
60182
-** (Mem.type==SQLITE_TEXT).
60278
+** (Mem.memType==MEM_Str).
6018360279
*/
6018460280
SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
6018560281
VdbeMemRelease(p);
6018660282
if( p->zMalloc ){
6018760283
sqlite3DbFree(p->db, p->zMalloc);
@@ -60368,11 +60464,11 @@
6036860464
}
6036960465
if( pMem->flags & MEM_RowSet ){
6037060466
sqlite3RowSetClear(pMem->u.pRowSet);
6037160467
}
6037260468
MemSetTypeFlag(pMem, MEM_Null);
60373
- pMem->type = SQLITE_NULL;
60469
+ pMem->memType = MEM_Null;
6037460470
}
6037560471
SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
6037660472
sqlite3VdbeMemSetNull((Mem*)p);
6037760473
}
6037860474
@@ -60381,11 +60477,11 @@
6038160477
** n containing all zeros.
6038260478
*/
6038360479
SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
6038460480
sqlite3VdbeMemRelease(pMem);
6038560481
pMem->flags = MEM_Blob|MEM_Zero;
60386
- pMem->type = SQLITE_BLOB;
60482
+ pMem->memType = MEM_Blob;
6038760483
pMem->n = 0;
6038860484
if( n<0 ) n = 0;
6038960485
pMem->u.nZero = n;
6039060486
pMem->enc = SQLITE_UTF8;
6039160487
@@ -60404,11 +60500,11 @@
6040460500
*/
6040560501
SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
6040660502
sqlite3VdbeMemRelease(pMem);
6040760503
pMem->u.i = val;
6040860504
pMem->flags = MEM_Int;
60409
- pMem->type = SQLITE_INTEGER;
60505
+ pMem->memType = MEM_Int;
6041060506
}
6041160507
6041260508
#ifndef SQLITE_OMIT_FLOATING_POINT
6041360509
/*
6041460510
** Delete any previous value and set the value stored in *pMem to val,
@@ -60419,11 +60515,11 @@
6041960515
sqlite3VdbeMemSetNull(pMem);
6042060516
}else{
6042160517
sqlite3VdbeMemRelease(pMem);
6042260518
pMem->r = val;
6042360519
pMem->flags = MEM_Real;
60424
- pMem->type = SQLITE_FLOAT;
60520
+ pMem->memType = MEM_Real;
6042560521
}
6042660522
}
6042760523
#endif
6042860524
6042960525
/*
@@ -60475,11 +60571,11 @@
6047560571
SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
6047660572
int i;
6047760573
Mem *pX;
6047860574
for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){
6047960575
if( pX->pScopyFrom==pMem ){
60480
- pX->flags |= MEM_Invalid;
60576
+ pX->flags |= MEM_Undefined;
6048160577
pX->pScopyFrom = 0;
6048260578
}
6048360579
}
6048460580
pMem->pScopyFrom = 0;
6048560581
}
@@ -60627,11 +60723,11 @@
6062760723
}
6062860724
6062960725
pMem->n = nByte;
6063060726
pMem->flags = flags;
6063160727
pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
60632
- pMem->type = (enc==0 ? SQLITE_BLOB : SQLITE_TEXT);
60728
+ pMem->memType = flags&0x1f;
6063360729
6063460730
#ifndef SQLITE_OMIT_UTF16
6063560731
if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
6063660732
return SQLITE_NOMEM;
6063760733
}
@@ -60798,11 +60894,11 @@
6079860894
pMem->z = &zData[offset];
6079960895
pMem->flags = MEM_Blob|MEM_Ephem;
6080060896
}else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
6080160897
pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
6080260898
pMem->enc = 0;
60803
- pMem->type = SQLITE_BLOB;
60899
+ pMem->memType = MEM_Blob;
6080460900
if( key ){
6080560901
rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
6080660902
}else{
6080760903
rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
6080860904
}
@@ -60868,11 +60964,11 @@
6086860964
*/
6086960965
SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
6087060966
Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
6087160967
if( p ){
6087260968
p->flags = MEM_Null;
60873
- p->type = SQLITE_NULL;
60969
+ p->memType = MEM_Null;
6087460970
p->db = db;
6087560971
}
6087660972
return p;
6087760973
}
6087860974
@@ -60918,11 +61014,11 @@
6091861014
assert( pRec->pKeyInfo->enc==ENC(db) );
6091961015
pRec->flags = UNPACKED_PREFIX_MATCH;
6092061016
pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
6092161017
for(i=0; i<nCol; i++){
6092261018
pRec->aMem[i].flags = MEM_Null;
60923
- pRec->aMem[i].type = SQLITE_NULL;
61019
+ pRec->aMem[i].memType = MEM_Null;
6092461020
pRec->aMem[i].db = db;
6092561021
}
6092661022
}else{
6092761023
sqlite3DbFree(db, pRec);
6092861024
pRec = 0;
@@ -60991,11 +61087,11 @@
6099161087
sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
6099261088
}else{
6099361089
zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
6099461090
if( zVal==0 ) goto no_mem;
6099561091
sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
60996
- if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
61092
+ if( op==TK_FLOAT ) pVal->memType = MEM_Real;
6099761093
}
6099861094
if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
6099961095
sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
6100061096
}else{
6100161097
sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
@@ -61449,10 +61545,13 @@
6144961545
#endif
6145061546
#ifdef VDBE_PROFILE
6145161547
pOp->cycles = 0;
6145261548
pOp->cnt = 0;
6145361549
#endif
61550
+#ifdef SQLITE_VDBE_COVERAGE
61551
+ pOp->iSrcLine = 0;
61552
+#endif
6145461553
return i;
6145561554
}
6145661555
SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe *p, int op){
6145761556
return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
6145861557
}
@@ -61810,11 +61909,11 @@
6181061909
6181161910
/*
6181261911
** Add a whole list of operations to the operation stack. Return the
6181361912
** address of the first operation added.
6181461913
*/
61815
-SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
61914
+SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
6181661915
int addr;
6181761916
assert( p->magic==VDBE_MAGIC_INIT );
6181861917
if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
6181961918
return 0;
6182061919
}
@@ -61837,10 +61936,15 @@
6183761936
pOut->p4type = P4_NOTUSED;
6183861937
pOut->p4.p = 0;
6183961938
pOut->p5 = 0;
6184061939
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6184161940
pOut->zComment = 0;
61941
+#endif
61942
+#ifdef SQLITE_VDBE_COVERAGE
61943
+ pOut->iSrcLine = iLineno+i;
61944
+#else
61945
+ (void)iLineno;
6184261946
#endif
6184361947
#ifdef SQLITE_DEBUG
6184461948
if( p->db->flags & SQLITE_VdbeAddopTrace ){
6184561949
sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
6184661950
}
@@ -62126,10 +62230,19 @@
6212662230
va_end(ap);
6212762231
}
6212862232
}
6212962233
#endif /* NDEBUG */
6213062234
62235
+#ifdef SQLITE_VDBE_COVERAGE
62236
+/*
62237
+** Set the value if the iSrcLine field for the previously coded instruction.
62238
+*/
62239
+SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){
62240
+ sqlite3VdbeGetOp(v,-1)->iSrcLine = iLine;
62241
+}
62242
+#endif /* SQLITE_VDBE_COVERAGE */
62243
+
6213162244
/*
6213262245
** Return the opcode for a given address. If the address is -1, then
6213362246
** return the most recently inserted opcode.
6213462247
**
6213562248
** If a memory allocation error has occurred prior to the calling of this
@@ -62138,28 +62251,17 @@
6213862251
** The return of a dummy opcode allows the call to continue functioning
6213962252
** after a OOM fault without having to check to see if the return from
6214062253
** this routine is a valid pointer. But because the dummy.opcode is 0,
6214162254
** dummy will never be written to. This is verified by code inspection and
6214262255
** by running with Valgrind.
62143
-**
62144
-** About the #ifdef SQLITE_OMIT_TRACE: Normally, this routine is never called
62145
-** unless p->nOp>0. This is because in the absense of SQLITE_OMIT_TRACE,
62146
-** an OP_Trace instruction is always inserted by sqlite3VdbeGet() as soon as
62147
-** a new VDBE is created. So we are free to set addr to p->nOp-1 without
62148
-** having to double-check to make sure that the result is non-negative. But
62149
-** if SQLITE_OMIT_TRACE is defined, the OP_Trace is omitted and we do need to
62150
-** check the value of p->nOp-1 before continuing.
6215162256
*/
6215262257
SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
6215362258
/* C89 specifies that the constant "dummy" will be initialized to all
6215462259
** zeros, which is correct. MSVC generates a warning, nevertheless. */
6215562260
static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
6215662261
assert( p->magic==VDBE_MAGIC_INIT );
6215762262
if( addr<0 ){
62158
-#ifdef SQLITE_OMIT_TRACE
62159
- if( p->nOp==0 ) return (VdbeOp*)&dummy;
62160
-#endif
6216162263
addr = p->nOp - 1;
6216262264
}
6216362265
assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
6216462266
if( p->db->mallocFailed ){
6216562267
return (VdbeOp*)&dummy;
@@ -62460,11 +62562,11 @@
6246062562
if( pOut==0 ) pOut = stdout;
6246162563
zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
6246262564
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6246362565
displayComment(pOp, zP4, zCom, sizeof(zCom));
6246462566
#else
62465
- zCom[0] = 0
62567
+ zCom[0] = 0;
6246662568
#endif
6246762569
/* NB: The sqlite3OpcodeName() function is implemented by code created
6246862570
** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
6246962571
** information from the vdbe.c source text */
6247062572
fprintf(pOut, zFormat1, pc,
@@ -62509,11 +62611,11 @@
6250962611
}else if( p->zMalloc ){
6251062612
sqlite3DbFree(db, p->zMalloc);
6251162613
p->zMalloc = 0;
6251262614
}
6251362615
62514
- p->flags = MEM_Invalid;
62616
+ p->flags = MEM_Undefined;
6251562617
}
6251662618
db->mallocFailed = malloc_failed;
6251762619
}
6251862620
}
6251962621
@@ -62631,19 +62733,19 @@
6263162733
}
6263262734
pOp = &apSub[j]->aOp[i];
6263362735
}
6263462736
if( p->explain==1 ){
6263562737
pMem->flags = MEM_Int;
62636
- pMem->type = SQLITE_INTEGER;
62738
+ pMem->memType = MEM_Int;
6263762739
pMem->u.i = i; /* Program counter */
6263862740
pMem++;
6263962741
6264062742
pMem->flags = MEM_Static|MEM_Str|MEM_Term;
6264162743
pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
6264262744
assert( pMem->z!=0 );
6264362745
pMem->n = sqlite3Strlen30(pMem->z);
62644
- pMem->type = SQLITE_TEXT;
62746
+ pMem->memType = MEM_Str;
6264562747
pMem->enc = SQLITE_UTF8;
6264662748
pMem++;
6264762749
6264862750
/* When an OP_Program opcode is encounter (the only opcode that has
6264962751
** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
@@ -62665,21 +62767,21 @@
6266562767
}
6266662768
}
6266762769
6266862770
pMem->flags = MEM_Int;
6266962771
pMem->u.i = pOp->p1; /* P1 */
62670
- pMem->type = SQLITE_INTEGER;
62772
+ pMem->memType = MEM_Int;
6267162773
pMem++;
6267262774
6267362775
pMem->flags = MEM_Int;
6267462776
pMem->u.i = pOp->p2; /* P2 */
62675
- pMem->type = SQLITE_INTEGER;
62777
+ pMem->memType = MEM_Int;
6267662778
pMem++;
6267762779
6267862780
pMem->flags = MEM_Int;
6267962781
pMem->u.i = pOp->p3; /* P3 */
62680
- pMem->type = SQLITE_INTEGER;
62782
+ pMem->memType = MEM_Int;
6268162783
pMem++;
6268262784
6268362785
if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
6268462786
assert( p->db->mallocFailed );
6268562787
return SQLITE_ERROR;
@@ -62691,11 +62793,11 @@
6269162793
}else{
6269262794
assert( pMem->z!=0 );
6269362795
pMem->n = sqlite3Strlen30(pMem->z);
6269462796
pMem->enc = SQLITE_UTF8;
6269562797
}
62696
- pMem->type = SQLITE_TEXT;
62798
+ pMem->memType = MEM_Str;
6269762799
pMem++;
6269862800
6269962801
if( p->explain==1 ){
6270062802
if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
6270162803
assert( p->db->mallocFailed );
@@ -62702,11 +62804,11 @@
6270262804
return SQLITE_ERROR;
6270362805
}
6270462806
pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
6270562807
pMem->n = 2;
6270662808
sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62707
- pMem->type = SQLITE_TEXT;
62809
+ pMem->memType = MEM_Str;
6270862810
pMem->enc = SQLITE_UTF8;
6270962811
pMem++;
6271062812
6271162813
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
6271262814
if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
@@ -62713,15 +62815,15 @@
6271362815
assert( p->db->mallocFailed );
6271462816
return SQLITE_ERROR;
6271562817
}
6271662818
pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
6271762819
pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62718
- pMem->type = SQLITE_TEXT;
62820
+ pMem->memType = MEM_Str;
6271962821
pMem->enc = SQLITE_UTF8;
6272062822
#else
6272162823
pMem->flags = MEM_Null; /* Comment */
62722
- pMem->type = SQLITE_NULL;
62824
+ pMem->memType = MEM_Null;
6272362825
#endif
6272462826
}
6272562827
6272662828
p->nResColumn = 8 - 4*(p->explain-1);
6272762829
p->pResultSet = &p->aMem[1];
@@ -62740,11 +62842,11 @@
6274062842
const char *z = 0;
6274162843
if( p->zSql ){
6274262844
z = p->zSql;
6274362845
}else if( p->nOp>=1 ){
6274462846
const VdbeOp *pOp = &p->aOp[0];
62745
- if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62847
+ if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
6274662848
z = pOp->p4.z;
6274762849
while( sqlite3Isspace(*z) ) z++;
6274862850
}
6274962851
}
6275062852
if( z ) printf("SQL: [%s]\n", z);
@@ -62759,11 +62861,11 @@
6275962861
int nOp = p->nOp;
6276062862
VdbeOp *pOp;
6276162863
if( sqlite3IoTrace==0 ) return;
6276262864
if( nOp<1 ) return;
6276362865
pOp = &p->aOp[0];
62764
- if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62866
+ if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
6276562867
int i, j;
6276662868
char z[1000];
6276762869
sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z);
6276862870
for(i=0; sqlite3Isspace(z[i]); i++){}
6276962871
for(j=0; z[i]; i++){
@@ -62977,11 +63079,11 @@
6297763079
}
6297863080
if( p->aMem ){
6297963081
p->aMem--; /* aMem[] goes from 1..nMem */
6298063082
p->nMem = nMem; /* not from 0..nMem-1 */
6298163083
for(n=1; n<=nMem; n++){
62982
- p->aMem[n].flags = MEM_Invalid;
63084
+ p->aMem[n].flags = MEM_Undefined;
6298363085
p->aMem[n].db = db;
6298463086
}
6298563087
}
6298663088
p->explain = pParse->explain;
6298763089
sqlite3VdbeRewind(p);
@@ -63089,11 +63191,11 @@
6308963191
/* Execute assert() statements to ensure that the Vdbe.apCsr[] and
6309063192
** Vdbe.aMem[] arrays have already been cleaned up. */
6309163193
int i;
6309263194
if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
6309363195
if( p->aMem ){
63094
- for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Invalid );
63196
+ for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
6309563197
}
6309663198
#endif
6309763199
6309863200
sqlite3DbFree(db, p->zErrMsg);
6309963201
p->zErrMsg = 0;
@@ -63838,16 +63940,28 @@
6383863940
fprintf(out, "---- ");
6383963941
for(i=0; i<p->nOp; i++){
6384063942
fprintf(out, "%02x", p->aOp[i].opcode);
6384163943
}
6384263944
fprintf(out, "\n");
63945
+ if( p->zSql ){
63946
+ char c, pc = 0;
63947
+ fprintf(out, "-- ");
63948
+ for(i=0; (c = p->zSql[i])!=0; i++){
63949
+ if( pc=='\n' ) fprintf(out, "-- ");
63950
+ putc(c, out);
63951
+ pc = c;
63952
+ }
63953
+ if( pc!='\n' ) fprintf(out, "\n");
63954
+ }
6384363955
for(i=0; i<p->nOp; i++){
63844
- fprintf(out, "%6d %10lld %8lld ",
63956
+ char zHdr[100];
63957
+ sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
6384563958
p->aOp[i].cnt,
6384663959
p->aOp[i].cycles,
6384763960
p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
6384863961
);
63962
+ fprintf(out, "%s", zHdr);
6384963963
sqlite3VdbePrintOp(out, i, &p->aOp[i]);
6385063964
}
6385163965
fclose(out);
6385263966
}
6385363967
}
@@ -64880,11 +64994,45 @@
6488064994
SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
6488164995
return sqlite3ValueText(pVal, SQLITE_UTF16LE);
6488264996
}
6488364997
#endif /* SQLITE_OMIT_UTF16 */
6488464998
SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
64885
- return pVal->type;
64999
+ static const u8 aType[] = {
65000
+ SQLITE_BLOB, /* 0x00 */
65001
+ SQLITE_NULL, /* 0x01 */
65002
+ SQLITE_TEXT, /* 0x02 */
65003
+ SQLITE_NULL, /* 0x03 */
65004
+ SQLITE_INTEGER, /* 0x04 */
65005
+ SQLITE_NULL, /* 0x05 */
65006
+ SQLITE_INTEGER, /* 0x06 */
65007
+ SQLITE_NULL, /* 0x07 */
65008
+ SQLITE_FLOAT, /* 0x08 */
65009
+ SQLITE_NULL, /* 0x09 */
65010
+ SQLITE_FLOAT, /* 0x0a */
65011
+ SQLITE_NULL, /* 0x0b */
65012
+ SQLITE_INTEGER, /* 0x0c */
65013
+ SQLITE_NULL, /* 0x0d */
65014
+ SQLITE_INTEGER, /* 0x0e */
65015
+ SQLITE_NULL, /* 0x0f */
65016
+ SQLITE_BLOB, /* 0x10 */
65017
+ SQLITE_NULL, /* 0x11 */
65018
+ SQLITE_TEXT, /* 0x12 */
65019
+ SQLITE_NULL, /* 0x13 */
65020
+ SQLITE_INTEGER, /* 0x14 */
65021
+ SQLITE_NULL, /* 0x15 */
65022
+ SQLITE_INTEGER, /* 0x16 */
65023
+ SQLITE_NULL, /* 0x17 */
65024
+ SQLITE_FLOAT, /* 0x18 */
65025
+ SQLITE_NULL, /* 0x19 */
65026
+ SQLITE_FLOAT, /* 0x1a */
65027
+ SQLITE_NULL, /* 0x1b */
65028
+ SQLITE_INTEGER, /* 0x1c */
65029
+ SQLITE_NULL, /* 0x1d */
65030
+ SQLITE_INTEGER, /* 0x1e */
65031
+ SQLITE_NULL, /* 0x1f */
65032
+ };
65033
+ return aType[pVal->memType&0x1f];
6488665034
}
6488765035
6488865036
/**************************** sqlite3_result_ *******************************
6488965037
** The following routines are used by user-defined functions to specify
6489065038
** the function result.
@@ -65839,11 +65987,11 @@
6583965987
return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
6584065988
}
6584165989
#endif /* SQLITE_OMIT_UTF16 */
6584265990
SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
6584365991
int rc;
65844
- switch( pValue->type ){
65992
+ switch( sqlite3_value_type((sqlite3_value*)pValue) ){
6584565993
case SQLITE_INTEGER: {
6584665994
rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
6584765995
break;
6584865996
}
6584965997
case SQLITE_FLOAT: {
@@ -66340,37 +66488,12 @@
6634066488
** May you do good and not evil.
6634166489
** May you find forgiveness for yourself and forgive others.
6634266490
** May you share freely, never taking more than you give.
6634366491
**
6634466492
*************************************************************************
66345
-** The code in this file implements execution method of the
66346
-** Virtual Database Engine (VDBE). A separate file ("vdbeaux.c")
66347
-** handles housekeeping details such as creating and deleting
66348
-** VDBE instances. This file is solely interested in executing
66349
-** the VDBE program.
66350
-**
66351
-** In the external interface, an "sqlite3_stmt*" is an opaque pointer
66352
-** to a VDBE.
66353
-**
66354
-** The SQL parser generates a program which is then executed by
66355
-** the VDBE to do the work of the SQL statement. VDBE programs are
66356
-** similar in form to assembly language. The program consists of
66357
-** a linear sequence of operations. Each operation has an opcode
66358
-** and 5 operands. Operands P1, P2, and P3 are integers. Operand P4
66359
-** is a null-terminated string. Operand P5 is an unsigned character.
66360
-** Few opcodes use all 5 operands.
66361
-**
66362
-** Computation results are stored on a set of registers numbered beginning
66363
-** with 1 and going up to Vdbe.nMem. Each register can store
66364
-** either an integer, a null-terminated string, a floating point
66365
-** number, or the SQL "NULL" value. An implicit conversion from one
66366
-** type to the other occurs as necessary.
66367
-**
66368
-** Most of the code in this file is taken up by the sqlite3VdbeExec()
66369
-** function which does the work of interpreting a VDBE program.
66370
-** But other routines are also provided to help in building up
66371
-** a program instruction by instruction.
66493
+** The code in this file implements the function that runs the
66494
+** bytecode of a prepared statement.
6637266495
**
6637366496
** Various scripts scan this source file in order to generate HTML
6637466497
** documentation, headers files, or other derived files. The formatting
6637566498
** of the code in this file is, therefore, important. See other comments
6637666499
** in this file for details. If in doubt, do not deviate from existing
@@ -66378,11 +66501,15 @@
6637866501
*/
6637966502
6638066503
/*
6638166504
** Invoke this macro on memory cells just prior to changing the
6638266505
** value of the cell. This macro verifies that shallow copies are
66383
-** not misused.
66506
+** not misused. A shallow copy of a string or blob just copies a
66507
+** pointer to the string or blob, not the content. If the original
66508
+** is changed while the copy is still in use, the string or blob might
66509
+** be changed out from under the copy. This macro verifies that nothing
66510
+** like that every happens.
6638466511
*/
6638566512
#ifdef SQLITE_DEBUG
6638666513
# define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M)
6638766514
#else
6638866515
# define memAboutToChange(P,M)
@@ -66437,11 +66564,11 @@
6643766564
}
6643866565
}
6643966566
#endif
6644066567
6644166568
/*
66442
-** The next global variable is incremented each type the OP_Found opcode
66569
+** The next global variable is incremented each time the OP_Found opcode
6644366570
** is executed. This is used to test whether or not the foreign key
6644466571
** operation implemented using OP_FkIsZero is working. This variable
6644566572
** has no function other than to help verify the correct operation of the
6644666573
** library.
6644766574
*/
@@ -66457,10 +66584,38 @@
6645766584
# define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
6645866585
#else
6645966586
# define UPDATE_MAX_BLOBSIZE(P)
6646066587
#endif
6646166588
66589
+/*
66590
+** Invoke the VDBE coverage callback, if that callback is defined. This
66591
+** feature is used for test suite validation only and does not appear an
66592
+** production builds.
66593
+**
66594
+** M is an integer, 2 or 3, that indices how many different ways the
66595
+** branch can go. It is usually 2. "I" is the direction the branch
66596
+** goes. 0 means falls through. 1 means branch is taken. 2 means the
66597
+** second alternative branch is taken.
66598
+*/
66599
+#if !defined(SQLITE_VDBE_COVERAGE)
66600
+# define VdbeBranchTaken(I,M)
66601
+#else
66602
+# define VdbeBranchTaken(I,M) vdbeTakeBranch(pOp->iSrcLine,I,M)
66603
+ static void vdbeTakeBranch(int iSrcLine, u8 I, u8 M){
66604
+ if( iSrcLine<=2 && ALWAYS(iSrcLine>0) ){
66605
+ M = iSrcLine;
66606
+ /* Assert the truth of VdbeCoverageAlwaysTaken() and
66607
+ ** VdbeCoverageNeverTaken() */
66608
+ assert( (M & I)==I );
66609
+ }else{
66610
+ if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
66611
+ sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg,
66612
+ iSrcLine,I,M);
66613
+ }
66614
+ }
66615
+#endif
66616
+
6646266617
/*
6646366618
** Convert the given register into a string if it isn't one
6646466619
** already. Return non-zero if a malloc() fails.
6646566620
*/
6646666621
#define Stringify(P, enc) \
@@ -66481,35 +66636,11 @@
6648166636
#define Deephemeralize(P) \
6648266637
if( ((P)->flags&MEM_Ephem)!=0 \
6648366638
&& sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
6648466639
6648566640
/* Return true if the cursor was opened using the OP_OpenSorter opcode. */
66486
-# define isSorter(x) ((x)->pSorter!=0)
66487
-
66488
-/*
66489
-** Argument pMem points at a register that will be passed to a
66490
-** user-defined function or returned to the user as the result of a query.
66491
-** This routine sets the pMem->type variable used by the sqlite3_value_*()
66492
-** routines.
66493
-*/
66494
-SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem){
66495
- int flags = pMem->flags;
66496
- if( flags & MEM_Null ){
66497
- pMem->type = SQLITE_NULL;
66498
- }
66499
- else if( flags & MEM_Int ){
66500
- pMem->type = SQLITE_INTEGER;
66501
- }
66502
- else if( flags & MEM_Real ){
66503
- pMem->type = SQLITE_FLOAT;
66504
- }
66505
- else if( flags & MEM_Str ){
66506
- pMem->type = SQLITE_TEXT;
66507
- }else{
66508
- pMem->type = SQLITE_BLOB;
66509
- }
66510
-}
66641
+#define isSorter(x) ((x)->pSorter!=0)
6651166642
6651266643
/*
6651366644
** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
6651466645
** if we run out of memory.
6651566646
*/
@@ -66635,16 +66766,18 @@
6663566766
** into a numeric representation. Use either INTEGER or REAL whichever
6663666767
** is appropriate. But only do the conversion if it is possible without
6663766768
** loss of information and return the revised type of the argument.
6663866769
*/
6663966770
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
66640
- Mem *pMem = (Mem*)pVal;
66641
- if( pMem->type==SQLITE_TEXT ){
66771
+ int eType = sqlite3_value_type(pVal);
66772
+ if( eType==SQLITE_TEXT ){
66773
+ Mem *pMem = (Mem*)pVal;
6664266774
applyNumericAffinity(pMem);
6664366775
sqlite3VdbeMemStoreType(pMem);
66776
+ eType = sqlite3_value_type(pVal);
6664466777
}
66645
- return pMem->type;
66778
+ return eType;
6664666779
}
6664766780
6664866781
/*
6664966782
** Exported version of applyAffinity(). This one works on sqlite3_value*,
6665066783
** not the internal Mem* type.
@@ -66743,11 +66876,11 @@
6674366876
#ifdef SQLITE_DEBUG
6674466877
/*
6674566878
** Print the value of a register for tracing purposes:
6674666879
*/
6674766880
static void memTracePrint(Mem *p){
66748
- if( p->flags & MEM_Invalid ){
66881
+ if( p->flags & MEM_Undefined ){
6674966882
printf(" undefined");
6675066883
}else if( p->flags & MEM_Null ){
6675166884
printf(" NULL");
6675266885
}else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
6675366886
printf(" si:%lld", p->u.i);
@@ -66875,24 +67008,10 @@
6687567008
6687667009
/************** End of hwtime.h **********************************************/
6687767010
/************** Continuing where we left off in vdbe.c ***********************/
6687867011
6687967012
#endif
66880
-
66881
-/*
66882
-** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
66883
-** sqlite3_interrupt() routine has been called. If it has been, then
66884
-** processing of the VDBE program is interrupted.
66885
-**
66886
-** This macro added to every instruction that does a jump in order to
66887
-** implement a loop. This test used to be on every single instruction,
66888
-** but that meant we more testing than we needed. By only testing the
66889
-** flag on jump instructions, we get a (small) speed improvement.
66890
-*/
66891
-#define CHECK_FOR_INTERRUPT \
66892
- if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
66893
-
6689467013
6689567014
#ifndef NDEBUG
6689667015
/*
6689767016
** This function is only called from within an assert() expression. It
6689867017
** checks that the sqlite3.nTransaction variable is correctly set to
@@ -66912,39 +67031,12 @@
6691267031
}
6691367032
#endif
6691467033
6691567034
6691667035
/*
66917
-** Execute as much of a VDBE program as we can then return.
66918
-**
66919
-** sqlite3VdbeMakeReady() must be called before this routine in order to
66920
-** close the program with a final OP_Halt and to set up the callbacks
66921
-** and the error message pointer.
66922
-**
66923
-** Whenever a row or result data is available, this routine will either
66924
-** invoke the result callback (if there is one) or return with
66925
-** SQLITE_ROW.
66926
-**
66927
-** If an attempt is made to open a locked database, then this routine
66928
-** will either invoke the busy callback (if there is one) or it will
66929
-** return SQLITE_BUSY.
66930
-**
66931
-** If an error occurs, an error message is written to memory obtained
66932
-** from sqlite3_malloc() and p->zErrMsg is made to point to that memory.
66933
-** The error code is stored in p->rc and this routine returns SQLITE_ERROR.
66934
-**
66935
-** If the callback ever returns non-zero, then the program exits
66936
-** immediately. There will be no error message but the p->rc field is
66937
-** set to SQLITE_ABORT and this routine will return SQLITE_ERROR.
66938
-**
66939
-** A memory allocation error causes p->rc to be set to SQLITE_NOMEM and this
66940
-** routine to return SQLITE_ERROR.
66941
-**
66942
-** Other fatal errors return SQLITE_ERROR.
66943
-**
66944
-** After this routine has finished, sqlite3VdbeFinalize() should be
66945
-** used to clean up the mess that was left behind.
67036
+** Execute as much of a VDBE program as we can.
67037
+** This is the core of sqlite3_step().
6694667038
*/
6694767039
SQLITE_PRIVATE int sqlite3VdbeExec(
6694867040
Vdbe *p /* The VDBE */
6694967041
){
6695067042
int pc=0; /* The program counter */
@@ -66966,11 +67058,10 @@
6696667058
Mem *pOut = 0; /* Output operand */
6696767059
int *aPermute = 0; /* Permutation of columns for OP_Compare */
6696867060
i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
6696967061
#ifdef VDBE_PROFILE
6697067062
u64 start; /* CPU clock count at start of opcode */
66971
- int origPc; /* Program counter at start of opcode */
6697267063
#endif
6697367064
/*** INSERT STACK UNION HERE ***/
6697467065
6697567066
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
6697667067
sqlite3VdbeEnter(p);
@@ -66984,11 +67075,11 @@
6698467075
p->rc = SQLITE_OK;
6698567076
p->iCurrentTime = 0;
6698667077
assert( p->explain==0 );
6698767078
p->pResultSet = 0;
6698867079
db->busyHandler.nBusy = 0;
66989
- CHECK_FOR_INTERRUPT;
67080
+ if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
6699067081
sqlite3VdbeIOTraceSql(p);
6699167082
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
6699267083
if( db->xProgress ){
6699367084
assert( 0 < db->nProgressOps );
6699467085
nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
@@ -67028,11 +67119,10 @@
6702867119
#endif
6702967120
for(pc=p->pc; rc==SQLITE_OK; pc++){
6703067121
assert( pc>=0 && pc<p->nOp );
6703167122
if( db->mallocFailed ) goto no_mem;
6703267123
#ifdef VDBE_PROFILE
67033
- origPc = pc;
6703467124
start = sqlite3Hwtime();
6703567125
#endif
6703667126
nVmStep++;
6703767127
pOp = &aOp[pc];
6703867128
@@ -67160,11 +67250,11 @@
6716067250
** But that is not due to sloppy coding habits. The code is written this
6716167251
** way for performance, to avoid having to run the interrupt and progress
6716267252
** checks on every opcode. This helps sqlite3_step() to run about 1.5%
6716367253
** faster according to "valgrind --tool=cachegrind" */
6716467254
check_for_interrupt:
67165
- CHECK_FOR_INTERRUPT;
67255
+ if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
6716667256
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
6716767257
/* Call the progress callback if it is configured and the required number
6716867258
** of VDBE ops have been executed (either since this invocation of
6716967259
** sqlite3VdbeExec() or since last time the progress callback was called).
6717067260
** If the progress callback returns non-zero, exit the virtual machine with
@@ -67200,24 +67290,70 @@
6720067290
break;
6720167291
}
6720267292
6720367293
/* Opcode: Return P1 * * * *
6720467294
**
67205
-** Jump to the next instruction after the address in register P1.
67295
+** Jump to the next instruction after the address in register P1. After
67296
+** the jump, register P1 becomes undefined.
6720667297
*/
6720767298
case OP_Return: { /* in1 */
6720867299
pIn1 = &aMem[pOp->p1];
67209
- assert( pIn1->flags & MEM_Int );
67300
+ assert( pIn1->flags==MEM_Int );
6721067301
pc = (int)pIn1->u.i;
67302
+ pIn1->flags = MEM_Undefined;
6721167303
break;
6721267304
}
6721367305
67214
-/* Opcode: Yield P1 * * * *
67306
+/* Opcode: InitCoroutine P1 P2 P3 * *
67307
+**
67308
+** Set up register P1 so that it will OP_Yield to the co-routine
67309
+** located at address P3.
67310
+**
67311
+** If P2!=0 then the co-routine implementation immediately follows
67312
+** this opcode. So jump over the co-routine implementation to
67313
+** address P2.
67314
+*/
67315
+case OP_InitCoroutine: { /* jump */
67316
+ assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67317
+ assert( pOp->p2>=0 && pOp->p2<p->nOp );
67318
+ assert( pOp->p3>=0 && pOp->p3<p->nOp );
67319
+ pOut = &aMem[pOp->p1];
67320
+ assert( !VdbeMemDynamic(pOut) );
67321
+ pOut->u.i = pOp->p3 - 1;
67322
+ pOut->flags = MEM_Int;
67323
+ if( pOp->p2 ) pc = pOp->p2 - 1;
67324
+ break;
67325
+}
67326
+
67327
+/* Opcode: EndCoroutine P1 * * * *
67328
+**
67329
+** The instruction at the address in register P1 is an OP_Yield.
67330
+** Jump to the P2 parameter of that OP_Yield.
67331
+** After the jump, register P1 becomes undefined.
67332
+*/
67333
+case OP_EndCoroutine: { /* in1 */
67334
+ VdbeOp *pCaller;
67335
+ pIn1 = &aMem[pOp->p1];
67336
+ assert( pIn1->flags==MEM_Int );
67337
+ assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
67338
+ pCaller = &aOp[pIn1->u.i];
67339
+ assert( pCaller->opcode==OP_Yield );
67340
+ assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
67341
+ pc = pCaller->p2 - 1;
67342
+ pIn1->flags = MEM_Undefined;
67343
+ break;
67344
+}
67345
+
67346
+/* Opcode: Yield P1 P2 * * *
6721567347
**
6721667348
** Swap the program counter with the value in register P1.
67349
+**
67350
+** If the co-routine ends with OP_Yield or OP_Return then continue
67351
+** to the next instruction. But if the co-routine ends with
67352
+** OP_EndCoroutine, jump immediately to P2.
6721767353
*/
67218
-case OP_Yield: { /* in1 */
67354
+case OP_Yield: { /* in1, jump */
6721967355
int pcDest;
6722067356
pIn1 = &aMem[pOp->p1];
6722167357
assert( (pIn1->flags & MEM_Dyn)==0 );
6722267358
pIn1->flags = MEM_Int;
6722367359
pcDest = (int)pIn1->u.i;
@@ -67226,11 +67362,11 @@
6722667362
pc = pcDest;
6722767363
break;
6722867364
}
6722967365
6723067366
/* Opcode: HaltIfNull P1 P2 P3 P4 P5
67231
-** Synopsis: if r[P3] null then halt
67367
+** Synopsis: if r[P3]=null halt
6723267368
**
6723367369
** Check the value in register P3. If it is NULL then Halt using
6723467370
** parameter P1, P2, and P4 as if this were a Halt instruction. If the
6723567371
** value in register P3 is not NULL, then this routine is a no-op.
6723667372
** The P5 parameter should be 1.
@@ -67374,11 +67510,13 @@
6737467510
6737567511
/* Opcode: String8 * P2 * P4 *
6737667512
** Synopsis: r[P2]='P4'
6737767513
**
6737867514
** P4 points to a nul terminated UTF-8 string. This opcode is transformed
67379
-** into an OP_String before it is executed for the first time.
67515
+** into an OP_String before it is executed for the first time. During
67516
+** this transformation, the length of string P4 is computed and stored
67517
+** as the P1 parameter.
6738067518
*/
6738167519
case OP_String8: { /* same as TK_STRING, out2-prerelease */
6738267520
assert( pOp->p4.z!=0 );
6738367521
pOp->opcode = OP_String;
6738467522
pOp->p1 = sqlite3Strlen30(pOp->p4.z);
@@ -67448,12 +67586,26 @@
6744867586
cnt--;
6744967587
}
6745067588
break;
6745167589
}
6745267590
67591
+/* Opcode: SoftNull P1 * * * *
67592
+** Synopsis: r[P1]=NULL
67593
+**
67594
+** Set register P1 to have the value NULL as seen by the OP_MakeRecord
67595
+** instruction, but do not free any string or blob memory associated with
67596
+** the register, so that if the value was a string or blob that was
67597
+** previously copied using OP_SCopy, the copies will continue to be valid.
67598
+*/
67599
+case OP_SoftNull: {
67600
+ assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67601
+ pOut = &aMem[pOp->p1];
67602
+ pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
67603
+ break;
67604
+}
6745367605
67454
-/* Opcode: Blob P1 P2 * P4
67606
+/* Opcode: Blob P1 P2 * P4 *
6745567607
** Synopsis: r[P2]=P4 (len=P1)
6745667608
**
6745767609
** P4 points to a blob of data P1 bytes long. Store this
6745867610
** blob in register P2.
6745967611
*/
@@ -67468,11 +67620,11 @@
6746867620
/* Opcode: Variable P1 P2 * P4 *
6746967621
** Synopsis: r[P2]=parameter(P1,P4)
6747067622
**
6747167623
** Transfer the values of bound parameter P1 into register P2
6747267624
**
67473
-** If the parameter is named, then its name appears in P4 and P3==1.
67625
+** If the parameter is named, then its name appears in P4.
6747467626
** The P4 value is used by sqlite3_bind_parameter_name().
6747567627
*/
6747667628
case OP_Variable: { /* out2-prerelease */
6747767629
Mem *pVar; /* Value being transferred */
6747867630
@@ -67587,12 +67739,12 @@
6758767739
** Synopsis: output=r[P1@P2]
6758867740
**
6758967741
** The registers P1 through P1+P2-1 contain a single row of
6759067742
** results. This opcode causes the sqlite3_step() call to terminate
6759167743
** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67592
-** structure to provide access to the top P1 values as the result
67593
-** row.
67744
+** structure to provide access to the r(P1)..r(P1+P2-1) values as
67745
+** the result row.
6759467746
*/
6759567747
case OP_ResultRow: {
6759667748
Mem *pMem;
6759767749
int i;
6759867750
assert( p->nResColumn==pOp->p2 );
@@ -68078,10 +68230,11 @@
6807868230
*/
6807968231
case OP_MustBeInt: { /* jump, in1 */
6808068232
pIn1 = &aMem[pOp->p1];
6808168233
if( (pIn1->flags & MEM_Int)==0 ){
6808268234
applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
68235
+ VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
6808368236
if( (pIn1->flags & MEM_Int)==0 ){
6808468237
if( pOp->p2==0 ){
6808568238
rc = SQLITE_MISMATCH;
6808668239
goto abort_due_to_error;
6808768240
}else{
@@ -68116,11 +68269,11 @@
6811668269
#ifndef SQLITE_OMIT_CAST
6811768270
/* Opcode: ToText P1 * * * *
6811868271
**
6811968272
** Force the value in register P1 to be text.
6812068273
** If the value is numeric, convert it to a string using the
68121
-** equivalent of printf(). Blob values are unchanged and
68274
+** equivalent of sprintf(). Blob values are unchanged and
6812268275
** are afterwards simply interpreted as text.
6812368276
**
6812468277
** A NULL value is not changed by this routine. It remains NULL.
6812568278
*/
6812668279
case OP_ToText: { /* same as TK_TO_TEXT, in1 */
@@ -68318,10 +68471,11 @@
6831868471
** OP_Eq or OP_Ne) then take the jump or not depending on whether
6831968472
** or not both operands are null.
6832068473
*/
6832168474
assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
6832268475
assert( (flags1 & MEM_Cleared)==0 );
68476
+ assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 );
6832368477
if( (flags1&MEM_Null)!=0
6832468478
&& (flags3&MEM_Null)!=0
6832568479
&& (flags3&MEM_Cleared)==0
6832668480
){
6832768481
res = 0; /* Results are equal */
@@ -68331,16 +68485,19 @@
6833168485
}else{
6833268486
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
6833368487
** then the result is always NULL.
6833468488
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
6833568489
*/
68336
- if( pOp->p5 & SQLITE_JUMPIFNULL ){
68337
- pc = pOp->p2-1;
68338
- }else if( pOp->p5 & SQLITE_STOREP2 ){
68490
+ if( pOp->p5 & SQLITE_STOREP2 ){
6833968491
pOut = &aMem[pOp->p2];
6834068492
MemSetTypeFlag(pOut, MEM_Null);
6834168493
REGISTER_TRACE(pOp->p2, pOut);
68494
+ }else{
68495
+ VdbeBranchTaken(2,3);
68496
+ if( pOp->p5 & SQLITE_JUMPIFNULL ){
68497
+ pc = pOp->p2-1;
68498
+ }
6834268499
}
6834368500
break;
6834468501
}
6834568502
}else{
6834668503
/* Neither operand is NULL. Do a comparison. */
@@ -68369,14 +68526,16 @@
6836968526
pOut = &aMem[pOp->p2];
6837068527
memAboutToChange(p, pOut);
6837168528
MemSetTypeFlag(pOut, MEM_Int);
6837268529
pOut->u.i = res;
6837368530
REGISTER_TRACE(pOp->p2, pOut);
68374
- }else if( res ){
68375
- pc = pOp->p2-1;
68531
+ }else{
68532
+ VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
68533
+ if( res ){
68534
+ pc = pOp->p2-1;
68535
+ }
6837668536
}
68377
-
6837868537
/* Undo any changes made by applyAffinity() to the input registers. */
6837968538
pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
6838068539
pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
6838168540
break;
6838268541
}
@@ -68469,15 +68628,15 @@
6846968628
** in the most recent OP_Compare instruction the P1 vector was less than
6847068629
** equal to, or greater than the P2 vector, respectively.
6847168630
*/
6847268631
case OP_Jump: { /* jump */
6847368632
if( iCompare<0 ){
68474
- pc = pOp->p1 - 1;
68633
+ pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
6847568634
}else if( iCompare==0 ){
68476
- pc = pOp->p2 - 1;
68635
+ pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
6847768636
}else{
68478
- pc = pOp->p3 - 1;
68637
+ pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
6847968638
}
6848068639
break;
6848168640
}
6848268641
6848368642
/* Opcode: And P1 P2 P3 * *
@@ -68571,14 +68730,17 @@
6857168730
}
6857268731
6857368732
/* Opcode: Once P1 P2 * * *
6857468733
**
6857568734
** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
68576
-** set the flag and fall through to the next instruction.
68735
+** set the flag and fall through to the next instruction. In other words,
68736
+** this opcode causes all following up codes up through P2 (but not including
68737
+** P2) to run just once and skipped on subsequent times through the loop.
6857768738
*/
6857868739
case OP_Once: { /* jump */
6857968740
assert( pOp->p1<p->nOnceFlag );
68741
+ VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
6858068742
if( p->aOnceFlag[pOp->p1] ){
6858168743
pc = pOp->p2-1;
6858268744
}else{
6858368745
p->aOnceFlag[pOp->p1] = 1;
6858468746
}
@@ -68609,10 +68771,11 @@
6860968771
#else
6861068772
c = sqlite3VdbeRealValue(pIn1)!=0.0;
6861168773
#endif
6861268774
if( pOp->opcode==OP_IfNot ) c = !c;
6861368775
}
68776
+ VdbeBranchTaken(c!=0, 2);
6861468777
if( c ){
6861568778
pc = pOp->p2-1;
6861668779
}
6861768780
break;
6861868781
}
@@ -68622,10 +68785,11 @@
6862268785
**
6862368786
** Jump to P2 if the value in register P1 is NULL.
6862468787
*/
6862568788
case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
6862668789
pIn1 = &aMem[pOp->p1];
68790
+ VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
6862768791
if( (pIn1->flags & MEM_Null)!=0 ){
6862868792
pc = pOp->p2 - 1;
6862968793
}
6863068794
break;
6863168795
}
@@ -68635,10 +68799,11 @@
6863568799
**
6863668800
** Jump to P2 if the value in register P1 is not NULL.
6863768801
*/
6863868802
case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
6863968803
pIn1 = &aMem[pOp->p1];
68804
+ VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
6864068805
if( (pIn1->flags & MEM_Null)==0 ){
6864168806
pc = pOp->p2 - 1;
6864268807
}
6864368808
break;
6864468809
}
@@ -68711,15 +68876,10 @@
6871168876
if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
6871268877
if( pC->nullRow ){
6871368878
if( pCrsr==0 ){
6871468879
assert( pC->pseudoTableReg>0 );
6871568880
pReg = &aMem[pC->pseudoTableReg];
68716
- if( pC->multiPseudo ){
68717
- sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
68718
- Deephemeralize(pDest);
68719
- goto op_column_out;
68720
- }
6872168881
assert( pReg->flags & MEM_Blob );
6872268882
assert( memIsValid(pReg) );
6872368883
pC->payloadSize = pC->szRow = avail = pReg->n;
6872468884
pC->aRow = (u8*)pReg->z;
6872568885
}else{
@@ -68941,11 +69101,10 @@
6894169101
assert( zAffinity[pOp->p2]==0 );
6894269102
pIn1 = &aMem[pOp->p1];
6894369103
while( (cAff = *(zAffinity++))!=0 ){
6894469104
assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
6894569105
assert( memIsValid(pIn1) );
68946
- ExpandBlob(pIn1);
6894769106
applyAffinity(pIn1, cAff, encoding);
6894869107
pIn1++;
6894969108
}
6895069109
break;
6895169110
}
@@ -69019,12 +69178,13 @@
6901969178
*/
6902069179
assert( pData0<=pLast );
6902169180
if( zAffinity ){
6902269181
pRec = pData0;
6902369182
do{
69024
- applyAffinity(pRec, *(zAffinity++), encoding);
69025
- }while( (++pRec)<=pLast );
69183
+ applyAffinity(pRec++, *(zAffinity++), encoding);
69184
+ assert( zAffinity[0]==0 || pRec<=pLast );
69185
+ }while( zAffinity[0] );
6902669186
}
6902769187
6902869188
/* Loop through the elements that will make up the record to figure
6902969189
** out how much space is required for the new record.
6903069190
*/
@@ -69364,29 +69524,23 @@
6936469524
rc = SQLITE_ERROR;
6936569525
}
6936669526
break;
6936769527
}
6936869528
69369
-/* Opcode: Transaction P1 P2 * * *
69529
+/* Opcode: Transaction P1 P2 P3 P4 P5
6937069530
**
69371
-** Begin a transaction. The transaction ends when a Commit or Rollback
69372
-** opcode is encountered. Depending on the ON CONFLICT setting, the
69373
-** transaction might also be rolled back if an error is encountered.
69531
+** Begin a transaction on database P1 if a transaction is not already
69532
+** active.
69533
+** If P2 is non-zero, then a write-transaction is started, or if a
69534
+** read-transaction is already active, it is upgraded to a write-transaction.
69535
+** If P2 is zero, then a read-transaction is started.
6937469536
**
6937569537
** P1 is the index of the database file on which the transaction is
6937669538
** started. Index 0 is the main database file and index 1 is the
6937769539
** file used for temporary tables. Indices of 2 or more are used for
6937869540
** attached databases.
6937969541
**
69380
-** If P2 is non-zero, then a write-transaction is started. A RESERVED lock is
69381
-** obtained on the database file when a write-transaction is started. No
69382
-** other process can start another write transaction while this transaction is
69383
-** underway. Starting a write transaction also creates a rollback journal. A
69384
-** write transaction must be started before any changes can be made to the
69385
-** database. If P2 is greater than or equal to 2 then an EXCLUSIVE lock is
69386
-** also obtained on the file.
69387
-**
6938869542
** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
6938969543
** true (this flag is set if the Vdbe may modify more than one row and may
6939069544
** throw an ABORT exception), a statement transaction may also be opened.
6939169545
** More specifically, a statement transaction is opened iff the database
6939269546
** connection is currently not in autocommit mode, or if there are other
@@ -69393,14 +69547,25 @@
6939369547
** active statements. A statement transaction allows the changes made by this
6939469548
** VDBE to be rolled back after an error without having to roll back the
6939569549
** entire transaction. If no error is encountered, the statement transaction
6939669550
** will automatically commit when the VDBE halts.
6939769551
**
69398
-** If P2 is zero, then a read-lock is obtained on the database file.
69552
+** If P5!=0 then this opcode also checks the schema cookie against P3
69553
+** and the schema generation counter against P4.
69554
+** The cookie changes its value whenever the database schema changes.
69555
+** This operation is used to detect when that the cookie has changed
69556
+** and that the current process needs to reread the schema. If the schema
69557
+** cookie in P3 differs from the schema cookie in the database header or
69558
+** if the schema generation counter in P4 differs from the current
69559
+** generation counter, then an SQLITE_SCHEMA error is raised and execution
69560
+** halts. The sqlite3_step() wrapper function might then reprepare the
69561
+** statement and rerun it from the beginning.
6939969562
*/
6940069563
case OP_Transaction: {
6940169564
Btree *pBt;
69565
+ int iMeta;
69566
+ int iGen;
6940269567
6940369568
assert( p->bIsReader );
6940469569
assert( p->readOnly==0 || pOp->p2==0 );
6940569570
assert( pOp->p1>=0 && pOp->p1<db->nDb );
6940669571
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
@@ -69440,10 +69605,39 @@
6944069605
** counter. If the statement transaction needs to be rolled back,
6944169606
** the value of this counter needs to be restored too. */
6944269607
p->nStmtDefCons = db->nDeferredCons;
6944369608
p->nStmtDefImmCons = db->nDeferredImmCons;
6944469609
}
69610
+
69611
+ /* Gather the schema version number for checking */
69612
+ sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69613
+ iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69614
+ }else{
69615
+ iGen = iMeta = 0;
69616
+ }
69617
+ assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
69618
+ if( pOp->p5 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){
69619
+ sqlite3DbFree(db, p->zErrMsg);
69620
+ p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69621
+ /* If the schema-cookie from the database file matches the cookie
69622
+ ** stored with the in-memory representation of the schema, do
69623
+ ** not reload the schema from the database file.
69624
+ **
69625
+ ** If virtual-tables are in use, this is not just an optimization.
69626
+ ** Often, v-tables store their data in other SQLite tables, which
69627
+ ** are queried from within xNext() and other v-table methods using
69628
+ ** prepared queries. If such a query is out-of-date, we do not want to
69629
+ ** discard the database schema, as the user code implementing the
69630
+ ** v-table would have to be ready for the sqlite3_vtab structure itself
69631
+ ** to be invalidated whenever sqlite3_step() is called from within
69632
+ ** a v-table method.
69633
+ */
69634
+ if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69635
+ sqlite3ResetOneSchema(db, pOp->p1);
69636
+ }
69637
+ p->expired = 1;
69638
+ rc = SQLITE_SCHEMA;
6944569639
}
6944669640
break;
6944769641
}
6944869642
6944969643
/* Opcode: ReadCookie P1 P2 P3 * *
@@ -69511,70 +69705,10 @@
6951169705
/* Invalidate all prepared statements whenever the TEMP database
6951269706
** schema is changed. Ticket #1644 */
6951369707
sqlite3ExpirePreparedStatements(db);
6951469708
p->expired = 0;
6951569709
}
69516
- break;
69517
-}
69518
-
69519
-/* Opcode: VerifyCookie P1 P2 P3 * *
69520
-**
69521
-** Check the value of global database parameter number 0 (the
69522
-** schema version) and make sure it is equal to P2 and that the
69523
-** generation counter on the local schema parse equals P3.
69524
-**
69525
-** P1 is the database number which is 0 for the main database file
69526
-** and 1 for the file holding temporary tables and some higher number
69527
-** for auxiliary databases.
69528
-**
69529
-** The cookie changes its value whenever the database schema changes.
69530
-** This operation is used to detect when that the cookie has changed
69531
-** and that the current process needs to reread the schema.
69532
-**
69533
-** Either a transaction needs to have been started or an OP_Open needs
69534
-** to be executed (to establish a read lock) before this opcode is
69535
-** invoked.
69536
-*/
69537
-case OP_VerifyCookie: {
69538
- int iMeta;
69539
- int iGen;
69540
- Btree *pBt;
69541
-
69542
- assert( pOp->p1>=0 && pOp->p1<db->nDb );
69543
- assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69544
- assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69545
- assert( p->bIsReader );
69546
- pBt = db->aDb[pOp->p1].pBt;
69547
- if( pBt ){
69548
- sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69549
- iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69550
- }else{
69551
- iGen = iMeta = 0;
69552
- }
69553
- if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
69554
- sqlite3DbFree(db, p->zErrMsg);
69555
- p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69556
- /* If the schema-cookie from the database file matches the cookie
69557
- ** stored with the in-memory representation of the schema, do
69558
- ** not reload the schema from the database file.
69559
- **
69560
- ** If virtual-tables are in use, this is not just an optimization.
69561
- ** Often, v-tables store their data in other SQLite tables, which
69562
- ** are queried from within xNext() and other v-table methods using
69563
- ** prepared queries. If such a query is out-of-date, we do not want to
69564
- ** discard the database schema, as the user code implementing the
69565
- ** v-table would have to be ready for the sqlite3_vtab structure itself
69566
- ** to be invalidated whenever sqlite3_step() is called from within
69567
- ** a v-table method.
69568
- */
69569
- if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69570
- sqlite3ResetOneSchema(db, pOp->p1);
69571
- }
69572
-
69573
- p->expired = 1;
69574
- rc = SQLITE_SCHEMA;
69575
- }
6957669710
break;
6957769711
}
6957869712
6957969713
/* Opcode: OpenRead P1 P2 P3 P4 P5
6958069714
** Synopsis: root=P2 iDb=P3
@@ -69787,11 +69921,11 @@
6978769921
}
6978869922
pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
6978969923
break;
6979069924
}
6979169925
69792
-/* Opcode: SorterOpen P1 * * P4 *
69926
+/* Opcode: SorterOpen P1 P2 * P4 *
6979369927
**
6979469928
** This opcode works like OP_OpenEphemeral except that it opens
6979569929
** a transient index that is specifically designed to sort large
6979669930
** tables using an external merge-sort algorithm.
6979769931
*/
@@ -69807,18 +69941,17 @@
6980769941
assert( pCx->pKeyInfo->enc==ENC(db) );
6980869942
rc = sqlite3VdbeSorterInit(db, pCx);
6980969943
break;
6981069944
}
6981169945
69812
-/* Opcode: OpenPseudo P1 P2 P3 * P5
69813
-** Synopsis: content in r[P2@P3]
69946
+/* Opcode: OpenPseudo P1 P2 P3 * *
69947
+** Synopsis: P3 columns in r[P2]
6981469948
**
6981569949
** Open a new cursor that points to a fake table that contains a single
69816
-** row of data. The content of that one row in the content of memory
69817
-** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
69818
-** MEM_Blob content contained in register P2. When P5==1, then the
69819
-** row is represented by P3 consecutive registers beginning with P2.
69950
+** row of data. The content of that one row is the content of memory
69951
+** register P2. In other words, cursor P1 becomes an alias for the
69952
+** MEM_Blob content contained in register P2.
6982069953
**
6982169954
** A pseudo-table created by this opcode is used to hold a single
6982269955
** row output from the sorter so that the row can be decomposed into
6982369956
** individual columns using the OP_Column opcode. The OP_Column opcode
6982469957
** is the only cursor opcode that works with a pseudo-table.
@@ -69834,11 +69967,11 @@
6983469967
pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
6983569968
if( pCx==0 ) goto no_mem;
6983669969
pCx->nullRow = 1;
6983769970
pCx->pseudoTableReg = pOp->p2;
6983869971
pCx->isTable = 1;
69839
- pCx->multiPseudo = pOp->p5;
69972
+ assert( pOp->p5==0 );
6984069973
break;
6984169974
}
6984269975
6984369976
/* Opcode: Close P1 * * * *
6984469977
**
@@ -69906,14 +70039,14 @@
6990670039
** is less than or equal to the key value. If there are no records
6990770040
** less than or equal to the key and P2 is not zero, then jump to P2.
6990870041
**
6990970042
** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt
6991070043
*/
69911
-case OP_SeekLt: /* jump, in3 */
69912
-case OP_SeekLe: /* jump, in3 */
69913
-case OP_SeekGe: /* jump, in3 */
69914
-case OP_SeekGt: { /* jump, in3 */
70044
+case OP_SeekLT: /* jump, in3 */
70045
+case OP_SeekLE: /* jump, in3 */
70046
+case OP_SeekGE: /* jump, in3 */
70047
+case OP_SeekGT: { /* jump, in3 */
6991570048
int res;
6991670049
int oc;
6991770050
VdbeCursor *pC;
6991870051
UnpackedRecord r;
6991970052
int nField;
@@ -69922,13 +70055,13 @@
6992270055
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
6992370056
assert( pOp->p2!=0 );
6992470057
pC = p->apCsr[pOp->p1];
6992570058
assert( pC!=0 );
6992670059
assert( pC->pseudoTableReg==0 );
69927
- assert( OP_SeekLe == OP_SeekLt+1 );
69928
- assert( OP_SeekGe == OP_SeekLt+2 );
69929
- assert( OP_SeekGt == OP_SeekLt+3 );
70060
+ assert( OP_SeekLE == OP_SeekLT+1 );
70061
+ assert( OP_SeekGE == OP_SeekLT+2 );
70062
+ assert( OP_SeekGT == OP_SeekLT+3 );
6993070063
assert( pC->isOrdered );
6993170064
assert( pC->pCursor!=0 );
6993270065
oc = pOp->opcode;
6993370066
pC->nullRow = 0;
6993470067
if( pC->isTable ){
@@ -69944,11 +70077,11 @@
6994470077
** loss of information, then special processing is required... */
6994570078
if( (pIn3->flags & MEM_Int)==0 ){
6994670079
if( (pIn3->flags & MEM_Real)==0 ){
6994770080
/* If the P3 value cannot be converted into any kind of a number,
6994870081
** then the seek is not possible, so jump to P2 */
69949
- pc = pOp->p2 - 1;
70082
+ pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
6995070083
break;
6995170084
}
6995270085
6995370086
/* If the approximation iKey is larger than the actual real search
6995470087
** term, substitute >= for > and < for <=. e.g. if the search term
@@ -69956,23 +70089,23 @@
6995670089
**
6995770090
** (x > 4.9) -> (x >= 5)
6995870091
** (x <= 4.9) -> (x < 5)
6995970092
*/
6996070093
if( pIn3->r<(double)iKey ){
69961
- assert( OP_SeekGe==(OP_SeekGt-1) );
69962
- assert( OP_SeekLt==(OP_SeekLe-1) );
69963
- assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
69964
- if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--;
70094
+ assert( OP_SeekGE==(OP_SeekGT-1) );
70095
+ assert( OP_SeekLT==(OP_SeekLE-1) );
70096
+ assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
70097
+ if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
6996570098
}
6996670099
6996770100
/* If the approximation iKey is smaller than the actual real search
6996870101
** term, substitute <= for < and > for >=. */
6996970102
else if( pIn3->r>(double)iKey ){
69970
- assert( OP_SeekLe==(OP_SeekLt+1) );
69971
- assert( OP_SeekGt==(OP_SeekGe+1) );
69972
- assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
69973
- if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++;
70103
+ assert( OP_SeekLE==(OP_SeekLT+1) );
70104
+ assert( OP_SeekGT==(OP_SeekGE+1) );
70105
+ assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
70106
+ if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
6997470107
}
6997570108
}
6997670109
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
6997770110
if( rc!=SQLITE_OK ){
6997870111
goto abort_due_to_error;
@@ -69987,21 +70120,21 @@
6998770120
assert( nField>0 );
6998870121
r.pKeyInfo = pC->pKeyInfo;
6998970122
r.nField = (u16)nField;
6999070123
6999170124
/* The next line of code computes as follows, only faster:
69992
- ** if( oc==OP_SeekGt || oc==OP_SeekLe ){
70125
+ ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
6999370126
** r.flags = UNPACKED_INCRKEY;
6999470127
** }else{
6999570128
** r.flags = 0;
6999670129
** }
6999770130
*/
69998
- r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
69999
- assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
70000
- assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
70001
- assert( oc!=OP_SeekGe || r.flags==0 );
70002
- assert( oc!=OP_SeekLt || r.flags==0 );
70131
+ r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT)));
70132
+ assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY );
70133
+ assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY );
70134
+ assert( oc!=OP_SeekGE || r.flags==0 );
70135
+ assert( oc!=OP_SeekLT || r.flags==0 );
7000370136
7000470137
r.aMem = &aMem[pOp->p3];
7000570138
#ifdef SQLITE_DEBUG
7000670139
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7000770140
#endif
@@ -70015,21 +70148,23 @@
7001570148
pC->deferredMoveto = 0;
7001670149
pC->cacheStatus = CACHE_STALE;
7001770150
#ifdef SQLITE_TEST
7001870151
sqlite3_search_count++;
7001970152
#endif
70020
- if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt );
70021
- if( res<0 || (res==0 && oc==OP_SeekGt) ){
70153
+ if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
70154
+ if( res<0 || (res==0 && oc==OP_SeekGT) ){
70155
+ res = 0;
7002270156
rc = sqlite3BtreeNext(pC->pCursor, &res);
7002370157
if( rc!=SQLITE_OK ) goto abort_due_to_error;
7002470158
pC->rowidIsValid = 0;
7002570159
}else{
7002670160
res = 0;
7002770161
}
7002870162
}else{
70029
- assert( oc==OP_SeekLt || oc==OP_SeekLe );
70030
- if( res>0 || (res==0 && oc==OP_SeekLt) ){
70163
+ assert( oc==OP_SeekLT || oc==OP_SeekLE );
70164
+ if( res>0 || (res==0 && oc==OP_SeekLT) ){
70165
+ res = 0;
7003170166
rc = sqlite3BtreePrevious(pC->pCursor, &res);
7003270167
if( rc!=SQLITE_OK ) goto abort_due_to_error;
7003370168
pC->rowidIsValid = 0;
7003470169
}else{
7003570170
/* res might be negative because the table is empty. Check to
@@ -70037,10 +70172,11 @@
7003770172
*/
7003870173
res = sqlite3BtreeEof(pC->pCursor);
7003970174
}
7004070175
}
7004170176
assert( pOp->p2>0 );
70177
+ VdbeBranchTaken(res!=0,2);
7004270178
if( res ){
7004370179
pc = pOp->p2 - 1;
7004470180
}
7004570181
break;
7004670182
}
@@ -70145,19 +70281,17 @@
7014570281
pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
7014670282
if( pOp->p4.i>0 ){
7014770283
r.pKeyInfo = pC->pKeyInfo;
7014870284
r.nField = (u16)pOp->p4.i;
7014970285
r.aMem = pIn3;
70286
+ for(ii=0; ii<r.nField; ii++){
70287
+ assert( memIsValid(&r.aMem[ii]) );
70288
+ ExpandBlob(&r.aMem[ii]);
7015070289
#ifdef SQLITE_DEBUG
70151
- {
70152
- int i;
70153
- for(i=0; i<r.nField; i++){
70154
- assert( memIsValid(&r.aMem[i]) );
70155
- if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
70156
- }
70157
- }
70158
-#endif
70290
+ if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
70291
+#endif
70292
+ }
7015970293
r.flags = UNPACKED_PREFIX_MATCH;
7016070294
pIdxKey = &r;
7016170295
}else{
7016270296
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
7016370297
pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
@@ -70172,11 +70306,11 @@
7017270306
/* For the OP_NoConflict opcode, take the jump if any of the
7017370307
** input fields are NULL, since any key with a NULL will not
7017470308
** conflict */
7017570309
for(ii=0; ii<r.nField; ii++){
7017670310
if( r.aMem[ii].flags & MEM_Null ){
70177
- pc = pOp->p2 - 1;
70311
+ pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
7017870312
break;
7017970313
}
7018070314
}
7018170315
}
7018270316
rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
@@ -70190,12 +70324,14 @@
7019070324
alreadyExists = (res==0);
7019170325
pC->nullRow = 1-alreadyExists;
7019270326
pC->deferredMoveto = 0;
7019370327
pC->cacheStatus = CACHE_STALE;
7019470328
if( pOp->opcode==OP_Found ){
70329
+ VdbeBranchTaken(alreadyExists!=0,2);
7019570330
if( alreadyExists ) pc = pOp->p2 - 1;
7019670331
}else{
70332
+ VdbeBranchTaken(alreadyExists==0,2);
7019770333
if( !alreadyExists ) pc = pOp->p2 - 1;
7019870334
}
7019970335
break;
7020070336
}
7020170337
@@ -70234,10 +70370,11 @@
7023470370
pC->lastRowid = pIn3->u.i;
7023570371
pC->rowidIsValid = res==0 ?1:0;
7023670372
pC->nullRow = 0;
7023770373
pC->cacheStatus = CACHE_STALE;
7023870374
pC->deferredMoveto = 0;
70375
+ VdbeBranchTaken(res!=0,2);
7023970376
if( res!=0 ){
7024070377
pc = pOp->p2 - 1;
7024170378
assert( pC->rowidIsValid==0 );
7024270379
}
7024370380
pC->seekResult = res;
@@ -70315,63 +70452,58 @@
7031570452
*/
7031670453
# define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
7031770454
#endif
7031870455
7031970456
if( !pC->useRandomRowid ){
70320
- v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70321
- if( v==0 ){
70322
- rc = sqlite3BtreeLast(pC->pCursor, &res);
70323
- if( rc!=SQLITE_OK ){
70324
- goto abort_due_to_error;
70325
- }
70326
- if( res ){
70327
- v = 1; /* IMP: R-61914-48074 */
70328
- }else{
70329
- assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70330
- rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70331
- assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70332
- if( v>=MAX_ROWID ){
70333
- pC->useRandomRowid = 1;
70334
- }else{
70335
- v++; /* IMP: R-29538-34987 */
70336
- }
70337
- }
70338
- }
70339
-
70340
-#ifndef SQLITE_OMIT_AUTOINCREMENT
70341
- if( pOp->p3 ){
70342
- /* Assert that P3 is a valid memory cell. */
70343
- assert( pOp->p3>0 );
70344
- if( p->pFrame ){
70345
- for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70346
- /* Assert that P3 is a valid memory cell. */
70347
- assert( pOp->p3<=pFrame->nMem );
70348
- pMem = &pFrame->aMem[pOp->p3];
70349
- }else{
70350
- /* Assert that P3 is a valid memory cell. */
70351
- assert( pOp->p3<=(p->nMem-p->nCursor) );
70352
- pMem = &aMem[pOp->p3];
70353
- memAboutToChange(p, pMem);
70354
- }
70355
- assert( memIsValid(pMem) );
70356
-
70357
- REGISTER_TRACE(pOp->p3, pMem);
70358
- sqlite3VdbeMemIntegerify(pMem);
70359
- assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70360
- if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70361
- rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70362
- goto abort_due_to_error;
70363
- }
70364
- if( v<pMem->u.i+1 ){
70365
- v = pMem->u.i + 1;
70366
- }
70367
- pMem->u.i = v;
70368
- }
70369
-#endif
70370
-
70371
- sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
70372
- }
70457
+ rc = sqlite3BtreeLast(pC->pCursor, &res);
70458
+ if( rc!=SQLITE_OK ){
70459
+ goto abort_due_to_error;
70460
+ }
70461
+ if( res ){
70462
+ v = 1; /* IMP: R-61914-48074 */
70463
+ }else{
70464
+ assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70465
+ rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70466
+ assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70467
+ if( v>=MAX_ROWID ){
70468
+ pC->useRandomRowid = 1;
70469
+ }else{
70470
+ v++; /* IMP: R-29538-34987 */
70471
+ }
70472
+ }
70473
+ }
70474
+
70475
+#ifndef SQLITE_OMIT_AUTOINCREMENT
70476
+ if( pOp->p3 ){
70477
+ /* Assert that P3 is a valid memory cell. */
70478
+ assert( pOp->p3>0 );
70479
+ if( p->pFrame ){
70480
+ for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70481
+ /* Assert that P3 is a valid memory cell. */
70482
+ assert( pOp->p3<=pFrame->nMem );
70483
+ pMem = &pFrame->aMem[pOp->p3];
70484
+ }else{
70485
+ /* Assert that P3 is a valid memory cell. */
70486
+ assert( pOp->p3<=(p->nMem-p->nCursor) );
70487
+ pMem = &aMem[pOp->p3];
70488
+ memAboutToChange(p, pMem);
70489
+ }
70490
+ assert( memIsValid(pMem) );
70491
+
70492
+ REGISTER_TRACE(pOp->p3, pMem);
70493
+ sqlite3VdbeMemIntegerify(pMem);
70494
+ assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70495
+ if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70496
+ rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70497
+ goto abort_due_to_error;
70498
+ }
70499
+ if( v<pMem->u.i+1 ){
70500
+ v = pMem->u.i + 1;
70501
+ }
70502
+ pMem->u.i = v;
70503
+ }
70504
+#endif
7037370505
if( pC->useRandomRowid ){
7037470506
/* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
7037570507
** largest possible integer (9223372036854775807) then the database
7037670508
** engine starts picking positive candidate ROWIDs at random until
7037770509
** it finds one that is not previously used. */
@@ -70501,11 +70633,10 @@
7050170633
if( pData->flags & MEM_Zero ){
7050270634
nZero = pData->u.nZero;
7050370635
}else{
7050470636
nZero = 0;
7050570637
}
70506
- sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
7050770638
rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
7050870639
pData->z, pData->n, nZero,
7050970640
(pOp->p5 & OPFLAG_APPEND)!=0, seekResult
7051070641
);
7051170642
pC->rowidIsValid = 0;
@@ -70563,11 +70694,10 @@
7056370694
**/
7056470695
assert( pC->deferredMoveto==0 );
7056570696
rc = sqlite3VdbeCursorMoveto(pC);
7056670697
if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
7056770698
70568
- sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
7056970699
rc = sqlite3BtreeDelete(pC->pCursor);
7057070700
pC->cacheStatus = CACHE_STALE;
7057170701
7057270702
/* Invoke the update-hook if required. */
7057370703
if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
@@ -70615,10 +70745,11 @@
7061570745
assert( isSorter(pC) );
7061670746
assert( pOp->p4type==P4_INT32 );
7061770747
pIn3 = &aMem[pOp->p3];
7061870748
nIgnore = pOp->p4.i;
7061970749
rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70750
+ VdbeBranchTaken(res!=0,2);
7062070751
if( res ){
7062170752
pc = pOp->p2-1;
7062270753
}
7062370754
break;
7062470755
};
@@ -70652,11 +70783,11 @@
7065270783
/* Opcode: RowKey P1 P2 * * *
7065370784
** Synopsis: r[P2]=key
7065470785
**
7065570786
** Write into register P2 the complete row key for cursor P1.
7065670787
** There is no interpretation of the data.
70657
-** The key is copied onto the P3 register exactly as
70788
+** The key is copied onto the P2 register exactly as
7065870789
** it is found in the database file.
7065970790
**
7066070791
** If the P1 cursor must be pointing to a valid row (not a NULL row)
7066170792
** of a real table, not a pseudo-table.
7066270793
*/
@@ -70814,12 +70945,13 @@
7081470945
rc = sqlite3BtreeLast(pCrsr, &res);
7081570946
pC->nullRow = (u8)res;
7081670947
pC->deferredMoveto = 0;
7081770948
pC->rowidIsValid = 0;
7081870949
pC->cacheStatus = CACHE_STALE;
70819
- if( pOp->p2>0 && res ){
70820
- pc = pOp->p2 - 1;
70950
+ if( pOp->p2>0 ){
70951
+ VdbeBranchTaken(res!=0,2);
70952
+ if( res ) pc = pOp->p2 - 1;
7082170953
}
7082270954
break;
7082370955
}
7082470956
7082570957
@@ -70872,56 +71004,67 @@
7087271004
pC->cacheStatus = CACHE_STALE;
7087371005
pC->rowidIsValid = 0;
7087471006
}
7087571007
pC->nullRow = (u8)res;
7087671008
assert( pOp->p2>0 && pOp->p2<p->nOp );
71009
+ VdbeBranchTaken(res!=0,2);
7087771010
if( res ){
7087871011
pc = pOp->p2 - 1;
7087971012
}
7088071013
break;
7088171014
}
7088271015
70883
-/* Opcode: Next P1 P2 * * P5
71016
+/* Opcode: Next P1 P2 P3 P4 P5
7088471017
**
7088571018
** Advance cursor P1 so that it points to the next key/data pair in its
7088671019
** table or index. If there are no more key/value pairs then fall through
7088771020
** to the following instruction. But if the cursor advance was successful,
7088871021
** jump immediately to P2.
7088971022
**
7089071023
** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
7089171024
** been opened prior to this opcode or the program will segfault.
71025
+**
71026
+** The P3 value is a hint to the btree implementation. If P3==1, that
71027
+** means P1 is an SQL index and that this instruction could have been
71028
+** omitted if that index had been unique. P3 is usually 0. P3 is
71029
+** always either 0 or 1.
7089271030
**
7089371031
** P4 is always of type P4_ADVANCE. The function pointer points to
7089471032
** sqlite3BtreeNext().
7089571033
**
7089671034
** If P5 is positive and the jump is taken, then event counter
7089771035
** number P5-1 in the prepared statement is incremented.
7089871036
**
7089971037
** See also: Prev, NextIfOpen
7090071038
*/
70901
-/* Opcode: NextIfOpen P1 P2 * * P5
71039
+/* Opcode: NextIfOpen P1 P2 P3 P4 P5
7090271040
**
7090371041
** This opcode works just like OP_Next except that if cursor P1 is not
7090471042
** open it behaves a no-op.
7090571043
*/
70906
-/* Opcode: Prev P1 P2 * * P5
71044
+/* Opcode: Prev P1 P2 P3 P4 P5
7090771045
**
7090871046
** Back up cursor P1 so that it points to the previous key/data pair in its
7090971047
** table or index. If there is no previous key/value pairs then fall through
7091071048
** to the following instruction. But if the cursor backup was successful,
7091171049
** jump immediately to P2.
7091271050
**
7091371051
** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
7091471052
** not open then the behavior is undefined.
71053
+**
71054
+** The P3 value is a hint to the btree implementation. If P3==1, that
71055
+** means P1 is an SQL index and that this instruction could have been
71056
+** omitted if that index had been unique. P3 is usually 0. P3 is
71057
+** always either 0 or 1.
7091571058
**
7091671059
** P4 is always of type P4_ADVANCE. The function pointer points to
7091771060
** sqlite3BtreePrevious().
7091871061
**
7091971062
** If P5 is positive and the jump is taken, then event counter
7092071063
** number P5-1 in the prepared statement is incremented.
7092171064
*/
70922
-/* Opcode: PrevIfOpen P1 P2 * * P5
71065
+/* Opcode: PrevIfOpen P1 P2 P3 P4 P5
7092371066
**
7092471067
** This opcode works just like OP_Prev except that if cursor P1 is not
7092571068
** open it behaves a no-op.
7092671069
*/
7092771070
case OP_SorterNext: { /* jump */
@@ -70939,20 +71082,24 @@
7093971082
case OP_Prev: /* jump */
7094071083
case OP_Next: /* jump */
7094171084
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
7094271085
assert( pOp->p5<ArraySize(p->aCounter) );
7094371086
pC = p->apCsr[pOp->p1];
71087
+ res = pOp->p3;
7094471088
assert( pC!=0 );
7094571089
assert( pC->deferredMoveto==0 );
7094671090
assert( pC->pCursor );
71091
+ assert( res==0 || (res==1 && pC->isTable==0) );
71092
+ testcase( res==1 );
7094771093
assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
7094871094
assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
7094971095
assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
7095071096
assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
7095171097
rc = pOp->p4.xAdvance(pC->pCursor, &res);
7095271098
next_tail:
7095371099
pC->cacheStatus = CACHE_STALE;
71100
+ VdbeBranchTaken(res==0,2);
7095471101
if( res==0 ){
7095571102
pC->nullRow = 0;
7095671103
pc = pOp->p2 - 1;
7095771104
p->aCounter[pOp->p5]++;
7095871105
#ifdef SQLITE_TEST
@@ -70972,10 +71119,18 @@
7097271119
** MakeRecord instructions. This opcode writes that key
7097371120
** into the index P1. Data for the entry is nil.
7097471121
**
7097571122
** P3 is a flag that provides a hint to the b-tree layer that this
7097671123
** insert is likely to be an append.
71124
+**
71125
+** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
71126
+** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
71127
+** then the change counter is unchanged.
71128
+**
71129
+** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have
71130
+** just done a seek to the spot where the new entry is to be inserted.
71131
+** This flag avoids doing an extra seek.
7097771132
**
7097871133
** This instruction only works for indices. The equivalent instruction
7097971134
** for tables is OP_Insert.
7098071135
*/
7098171136
case OP_SorterInsert: /* in2 */
@@ -71087,36 +71242,54 @@
7108771242
7108871243
/* Opcode: IdxGE P1 P2 P3 P4 P5
7108971244
** Synopsis: key=r[P3@P4]
7109071245
**
7109171246
** The P4 register values beginning with P3 form an unpacked index
71092
-** key that omits the ROWID. Compare this key value against the index
71093
-** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
71247
+** key that omits the PRIMARY KEY. Compare this key value against the index
71248
+** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
71249
+** fields at the end.
7109471250
**
7109571251
** If the P1 index entry is greater than or equal to the key value
7109671252
** then jump to P2. Otherwise fall through to the next instruction.
71253
+*/
71254
+/* Opcode: IdxGT P1 P2 P3 P4 P5
71255
+** Synopsis: key=r[P3@P4]
7109771256
**
71098
-** If P5 is non-zero then the key value is increased by an epsilon
71099
-** prior to the comparison. This make the opcode work like IdxGT except
71100
-** that if the key from register P3 is a prefix of the key in the cursor,
71101
-** the result is false whereas it would be true with IdxGT.
71257
+** The P4 register values beginning with P3 form an unpacked index
71258
+** key that omits the PRIMARY KEY. Compare this key value against the index
71259
+** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
71260
+** fields at the end.
71261
+**
71262
+** If the P1 index entry is greater than the key value
71263
+** then jump to P2. Otherwise fall through to the next instruction.
7110271264
*/
7110371265
/* Opcode: IdxLT P1 P2 P3 P4 P5
7110471266
** Synopsis: key=r[P3@P4]
7110571267
**
7110671268
** The P4 register values beginning with P3 form an unpacked index
71107
-** key that omits the ROWID. Compare this key value against the index
71108
-** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
71269
+** key that omits the PRIMARY KEY or ROWID. Compare this key value against
71270
+** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
71271
+** ROWID on the P1 index.
7110971272
**
7111071273
** If the P1 index entry is less than the key value then jump to P2.
7111171274
** Otherwise fall through to the next instruction.
71275
+*/
71276
+/* Opcode: IdxLE P1 P2 P3 P4 P5
71277
+** Synopsis: key=r[P3@P4]
7111271278
**
71113
-** If P5 is non-zero then the key value is increased by an epsilon prior
71114
-** to the comparison. This makes the opcode work like IdxLE.
71279
+** The P4 register values beginning with P3 form an unpacked index
71280
+** key that omits the PRIMARY KEY or ROWID. Compare this key value against
71281
+** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
71282
+** ROWID on the P1 index.
71283
+**
71284
+** If the P1 index entry is less than or equal to the key value then jump
71285
+** to P2. Otherwise fall through to the next instruction.
7111571286
*/
71287
+case OP_IdxLE: /* jump */
71288
+case OP_IdxGT: /* jump */
7111671289
case OP_IdxLT: /* jump */
71117
-case OP_IdxGE: { /* jump */
71290
+case OP_IdxGE: { /* jump */
7111871291
VdbeCursor *pC;
7111971292
int res;
7112071293
UnpackedRecord r;
7112171294
7112271295
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -71127,27 +71300,32 @@
7112771300
assert( pC->deferredMoveto==0 );
7112871301
assert( pOp->p5==0 || pOp->p5==1 );
7112971302
assert( pOp->p4type==P4_INT32 );
7113071303
r.pKeyInfo = pC->pKeyInfo;
7113171304
r.nField = (u16)pOp->p4.i;
71132
- if( pOp->p5 ){
71305
+ if( pOp->opcode<OP_IdxLT ){
71306
+ assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
7113371307
r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
7113471308
}else{
71309
+ assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
7113571310
r.flags = UNPACKED_PREFIX_MATCH;
7113671311
}
7113771312
r.aMem = &aMem[pOp->p3];
7113871313
#ifdef SQLITE_DEBUG
7113971314
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
7114071315
#endif
7114171316
res = 0; /* Not needed. Only used to silence a warning. */
7114271317
rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
71143
- if( pOp->opcode==OP_IdxLT ){
71318
+ assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
71319
+ if( (pOp->opcode&1)==(OP_IdxLT&1) ){
71320
+ assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
7114471321
res = -res;
7114571322
}else{
71146
- assert( pOp->opcode==OP_IdxGE );
71323
+ assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
7114771324
res++;
7114871325
}
71326
+ VdbeBranchTaken(res>0,2);
7114971327
if( res>0 ){
7115071328
pc = pOp->p2 - 1 ;
7115171329
}
7115271330
break;
7115371331
}
@@ -71236,11 +71414,10 @@
7123671414
case OP_Clear: {
7123771415
int nChange;
7123871416
7123971417
nChange = 0;
7124071418
assert( p->readOnly==0 );
71241
- assert( pOp->p1!=1 );
7124271419
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
7124371420
rc = sqlite3BtreeClearTable(
7124471421
db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
7124571422
);
7124671423
if( pOp->p3 ){
@@ -71505,13 +71682,15 @@
7150571682
|| sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
7150671683
){
7150771684
/* The boolean index is empty */
7150871685
sqlite3VdbeMemSetNull(pIn1);
7150971686
pc = pOp->p2 - 1;
71687
+ VdbeBranchTaken(1,2);
7151071688
}else{
7151171689
/* A value was pulled from the index */
7151271690
sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
71691
+ VdbeBranchTaken(0,2);
7151371692
}
7151471693
goto check_for_interrupt;
7151571694
}
7151671695
7151771696
/* Opcode: RowSetTest P1 P2 P3 P4
@@ -71559,10 +71738,11 @@
7155971738
assert( iSet==-1 || iSet>=0 );
7156071739
if( iSet ){
7156171740
exists = sqlite3RowSetTest(pIn1->u.pRowSet,
7156271741
(u8)(iSet>=0 ? iSet & 0xf : 0xff),
7156371742
pIn3->u.i);
71743
+ VdbeBranchTaken(exists!=0,2);
7156471744
if( exists ){
7156571745
pc = pOp->p2 - 1;
7156671746
break;
7156771747
}
7156871748
}
@@ -71573,11 +71753,11 @@
7157371753
}
7157471754
7157571755
7157671756
#ifndef SQLITE_OMIT_TRIGGER
7157771757
71578
-/* Opcode: Program P1 P2 P3 P4 *
71758
+/* Opcode: Program P1 P2 P3 P4 P5
7157971759
**
7158071760
** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
7158171761
**
7158271762
** P1 contains the address of the memory cell that contains the first memory
7158371763
** cell in an array of values used as arguments to the sub-program. P2
@@ -71585,10 +71765,12 @@
7158571765
** exception using the RAISE() function. Register P3 contains the address
7158671766
** of a memory cell in this (the parent) VM that is used to allocate the
7158771767
** memory required by the sub-vdbe at runtime.
7158871768
**
7158971769
** P4 is a pointer to the VM containing the trigger program.
71770
+**
71771
+** If P5 is non-zero, then recursive program invocation is enabled.
7159071772
*/
7159171773
case OP_Program: { /* jump */
7159271774
int nMem; /* Number of memory registers for sub-program */
7159371775
int nByte; /* Bytes of runtime space required for sub-program */
7159471776
Mem *pRt; /* Register to allocate runtime space */
@@ -71662,11 +71844,11 @@
7166271844
pFrame->aOnceFlag = p->aOnceFlag;
7166371845
pFrame->nOnceFlag = p->nOnceFlag;
7166471846
7166571847
pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
7166671848
for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71667
- pMem->flags = MEM_Invalid;
71849
+ pMem->flags = MEM_Undefined;
7166871850
pMem->db = db;
7166971851
}
7167071852
}else{
7167171853
pFrame = pRt->u.pFrame;
7167271854
assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
@@ -71749,12 +71931,14 @@
7174971931
** zero, the jump is taken if the statement constraint-counter is zero
7175071932
** (immediate foreign key constraint violations).
7175171933
*/
7175271934
case OP_FkIfZero: { /* jump */
7175371935
if( pOp->p1 ){
71936
+ VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
7175471937
if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
7175571938
}else{
71939
+ VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
7175671940
if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
7175771941
}
7175871942
break;
7175971943
}
7176071944
#endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
@@ -71799,10 +71983,11 @@
7179971983
** not contain an integer. An assertion fault will result if you try.
7180071984
*/
7180171985
case OP_IfPos: { /* jump, in1 */
7180271986
pIn1 = &aMem[pOp->p1];
7180371987
assert( pIn1->flags&MEM_Int );
71988
+ VdbeBranchTaken( pIn1->u.i>0, 2);
7180471989
if( pIn1->u.i>0 ){
7180571990
pc = pOp->p2 - 1;
7180671991
}
7180771992
break;
7180871993
}
@@ -71816,10 +72001,11 @@
7181672001
** not contain an integer. An assertion fault will result if you try.
7181772002
*/
7181872003
case OP_IfNeg: { /* jump, in1 */
7181972004
pIn1 = &aMem[pOp->p1];
7182072005
assert( pIn1->flags&MEM_Int );
72006
+ VdbeBranchTaken(pIn1->u.i<0, 2);
7182172007
if( pIn1->u.i<0 ){
7182272008
pc = pOp->p2 - 1;
7182372009
}
7182472010
break;
7182572011
}
@@ -71835,10 +72021,11 @@
7183572021
*/
7183672022
case OP_IfZero: { /* jump, in1 */
7183772023
pIn1 = &aMem[pOp->p1];
7183872024
assert( pIn1->flags&MEM_Int );
7183972025
pIn1->u.i += pOp->p3;
72026
+ VdbeBranchTaken(pIn1->u.i==0, 2);
7184072027
if( pIn1->u.i==0 ){
7184172028
pc = pOp->p2 - 1;
7184272029
}
7184372030
break;
7184472031
}
@@ -71972,11 +72159,11 @@
7197272159
break;
7197372160
};
7197472161
#endif
7197572162
7197672163
#ifndef SQLITE_OMIT_PRAGMA
71977
-/* Opcode: JournalMode P1 P2 P3 * P5
72164
+/* Opcode: JournalMode P1 P2 P3 * *
7197872165
**
7197972166
** Change the journal mode of database P1 to P3. P3 must be one of the
7198072167
** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
7198172168
** modes (delete, truncate, persist, off and memory), this is a simple
7198272169
** operation. No IO is required.
@@ -72106,10 +72293,11 @@
7210672293
assert( pOp->p1>=0 && pOp->p1<db->nDb );
7210772294
assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
7210872295
assert( p->readOnly==0 );
7210972296
pBt = db->aDb[pOp->p1].pBt;
7211072297
rc = sqlite3BtreeIncrVacuum(pBt);
72298
+ VdbeBranchTaken(rc==SQLITE_DONE,2);
7211172299
if( rc==SQLITE_DONE ){
7211272300
pc = pOp->p2 - 1;
7211372301
rc = SQLITE_OK;
7211472302
}
7211572303
break;
@@ -72312,11 +72500,11 @@
7231272500
p->inVtabMethod = 0;
7231372501
sqlite3VtabImportErrmsg(p, pVtab);
7231472502
if( rc==SQLITE_OK ){
7231572503
res = pModule->xEof(pVtabCursor);
7231672504
}
72317
-
72505
+ VdbeBranchTaken(res!=0,2);
7231872506
if( res ){
7231972507
pc = pOp->p2 - 1;
7232072508
}
7232172509
}
7232272510
pCur->nullRow = 0;
@@ -72417,11 +72605,11 @@
7241772605
p->inVtabMethod = 0;
7241872606
sqlite3VtabImportErrmsg(p, pVtab);
7241972607
if( rc==SQLITE_OK ){
7242072608
res = pModule->xEof(pCur->pVtabCursor);
7242172609
}
72422
-
72610
+ VdbeBranchTaken(!res,2);
7242372611
if( !res ){
7242472612
/* If there is data, jump to P2 */
7242572613
pc = pOp->p2 - 1;
7242672614
}
7242772615
goto check_for_interrupt;
@@ -72458,11 +72646,11 @@
7245872646
break;
7245972647
}
7246072648
#endif
7246172649
7246272650
#ifndef SQLITE_OMIT_VIRTUALTABLE
72463
-/* Opcode: VUpdate P1 P2 P3 P4 *
72651
+/* Opcode: VUpdate P1 P2 P3 P4 P5
7246472652
** Synopsis: data=r[P3@P2]
7246572653
**
7246672654
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
7246772655
** This opcode invokes the corresponding xUpdate method. P2 values
7246872656
** are contiguous memory cells starting at P3 to pass to the xUpdate
@@ -72481,10 +72669,13 @@
7248172669
** a row to delete.
7248272670
**
7248372671
** P1 is a boolean flag. If it is set to true and the xUpdate call
7248472672
** is successful, then the value returned by sqlite3_last_insert_rowid()
7248572673
** is set to the value of the rowid for the row just inserted.
72674
+**
72675
+** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
72676
+** apply in the case of a constraint failure on an insert or update.
7248672677
*/
7248772678
case OP_VUpdate: {
7248872679
sqlite3_vtab *pVtab;
7248972680
sqlite3_module *pModule;
7249072681
int nArg;
@@ -72569,20 +72760,30 @@
7256972760
break;
7257072761
}
7257172762
#endif
7257272763
7257372764
72574
-#ifndef SQLITE_OMIT_TRACE
72575
-/* Opcode: Trace * * * P4 *
72765
+/* Opcode: Init * P2 * P4 *
72766
+** Synopsis: Start at P2
72767
+**
72768
+** Programs contain a single instance of this opcode as the very first
72769
+** opcode.
7257672770
**
7257772771
** If tracing is enabled (by the sqlite3_trace()) interface, then
7257872772
** the UTF-8 string contained in P4 is emitted on the trace callback.
72773
+** Or if P4 is blank, use the string returned by sqlite3_sql().
72774
+**
72775
+** If P2 is not zero, jump to instruction P2.
7257972776
*/
72580
-case OP_Trace: {
72777
+case OP_Init: { /* jump */
7258172778
char *zTrace;
7258272779
char *z;
7258372780
72781
+ if( pOp->p2 ){
72782
+ pc = pOp->p2 - 1;
72783
+ }
72784
+#ifndef SQLITE_OMIT_TRACE
7258472785
if( db->xTrace
7258572786
&& !p->doingRerun
7258672787
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7258772788
){
7258872789
z = sqlite3VdbeExpandSql(p, zTrace);
@@ -72604,13 +72805,13 @@
7260472805
&& (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
7260572806
){
7260672807
sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
7260772808
}
7260872809
#endif /* SQLITE_DEBUG */
72810
+#endif /* SQLITE_OMIT_TRACE */
7260972811
break;
7261072812
}
72611
-#endif
7261272813
7261372814
7261472815
/* Opcode: Noop * * * * *
7261572816
**
7261672817
** Do nothing. This instruction is often useful as a jump
@@ -72638,14 +72839,10 @@
7263872839
#ifdef VDBE_PROFILE
7263972840
{
7264072841
u64 elapsed = sqlite3Hwtime() - start;
7264172842
pOp->cycles += elapsed;
7264272843
pOp->cnt++;
72643
-#if 0
72644
- fprintf(stdout, "%10llu ", elapsed);
72645
- sqlite3VdbePrintOp(stdout, origPc, &aOp[origPc]);
72646
-#endif
7264772844
}
7264872845
#endif
7264972846
7265072847
/* The following code adds nothing to the actual functionality
7265172848
** of the program. It is only here for testing and debugging.
@@ -72867,26 +73064,24 @@
7286773064
**
7286873065
** The sqlite3_blob_close() function finalizes the vdbe program,
7286973066
** which closes the b-tree cursor and (possibly) commits the
7287073067
** transaction.
7287173068
*/
73069
+ static const int iLn = __LINE__+4;
7287273070
static const VdbeOpList openBlob[] = {
72873
- {OP_Transaction, 0, 0, 0}, /* 0: Start a transaction */
72874
- {OP_VerifyCookie, 0, 0, 0}, /* 1: Check the schema cookie */
72875
- {OP_TableLock, 0, 0, 0}, /* 2: Acquire a read or write lock */
72876
-
73071
+ /* {OP_Transaction, 0, 0, 0}, // 0: Inserted separately */
73072
+ {OP_TableLock, 0, 0, 0}, /* 1: Acquire a read or write lock */
7287773073
/* One of the following two instructions is replaced by an OP_Noop. */
72878
- {OP_OpenRead, 0, 0, 0}, /* 3: Open cursor 0 for reading */
72879
- {OP_OpenWrite, 0, 0, 0}, /* 4: Open cursor 0 for read/write */
72880
-
72881
- {OP_Variable, 1, 1, 1}, /* 5: Push the rowid to the stack */
72882
- {OP_NotExists, 0, 10, 1}, /* 6: Seek the cursor */
72883
- {OP_Column, 0, 0, 1}, /* 7 */
72884
- {OP_ResultRow, 1, 0, 0}, /* 8 */
72885
- {OP_Goto, 0, 5, 0}, /* 9 */
72886
- {OP_Close, 0, 0, 0}, /* 10 */
72887
- {OP_Halt, 0, 0, 0}, /* 11 */
73074
+ {OP_OpenRead, 0, 0, 0}, /* 2: Open cursor 0 for reading */
73075
+ {OP_OpenWrite, 0, 0, 0}, /* 3: Open cursor 0 for read/write */
73076
+ {OP_Variable, 1, 1, 1}, /* 4: Push the rowid to the stack */
73077
+ {OP_NotExists, 0, 10, 1}, /* 5: Seek the cursor */
73078
+ {OP_Column, 0, 0, 1}, /* 6 */
73079
+ {OP_ResultRow, 1, 0, 0}, /* 7 */
73080
+ {OP_Goto, 0, 4, 0}, /* 8 */
73081
+ {OP_Close, 0, 0, 0}, /* 9 */
73082
+ {OP_Halt, 0, 0, 0}, /* 10 */
7288873083
};
7288973084
7289073085
int rc = SQLITE_OK;
7289173086
char *zErr = 0;
7289273087
Table *pTab;
@@ -72995,50 +73190,45 @@
7299573190
assert( pBlob->pStmt || db->mallocFailed );
7299673191
if( pBlob->pStmt ){
7299773192
Vdbe *v = (Vdbe *)pBlob->pStmt;
7299873193
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7299973194
73000
- sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob);
73001
-
73002
-
73003
- /* Configure the OP_Transaction */
73004
- sqlite3VdbeChangeP1(v, 0, iDb);
73005
- sqlite3VdbeChangeP2(v, 0, flags);
73006
-
73007
- /* Configure the OP_VerifyCookie */
73008
- sqlite3VdbeChangeP1(v, 1, iDb);
73009
- sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
73010
- sqlite3VdbeChangeP3(v, 1, pTab->pSchema->iGeneration);
73195
+
73196
+ sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags,
73197
+ pTab->pSchema->schema_cookie,
73198
+ pTab->pSchema->iGeneration);
73199
+ sqlite3VdbeChangeP5(v, 1);
73200
+ sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
7301173201
7301273202
/* Make sure a mutex is held on the table to be accessed */
7301373203
sqlite3VdbeUsesBtree(v, iDb);
7301473204
7301573205
/* Configure the OP_TableLock instruction */
7301673206
#ifdef SQLITE_OMIT_SHARED_CACHE
73017
- sqlite3VdbeChangeToNoop(v, 2);
73207
+ sqlite3VdbeChangeToNoop(v, 1);
7301873208
#else
73019
- sqlite3VdbeChangeP1(v, 2, iDb);
73020
- sqlite3VdbeChangeP2(v, 2, pTab->tnum);
73021
- sqlite3VdbeChangeP3(v, 2, flags);
73022
- sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
73209
+ sqlite3VdbeChangeP1(v, 1, iDb);
73210
+ sqlite3VdbeChangeP2(v, 1, pTab->tnum);
73211
+ sqlite3VdbeChangeP3(v, 1, flags);
73212
+ sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
7302373213
#endif
7302473214
7302573215
/* Remove either the OP_OpenWrite or OpenRead. Set the P2
7302673216
** parameter of the other to pTab->tnum. */
73027
- sqlite3VdbeChangeToNoop(v, 4 - flags);
73028
- sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
73029
- sqlite3VdbeChangeP3(v, 3 + flags, iDb);
73217
+ sqlite3VdbeChangeToNoop(v, 3 - flags);
73218
+ sqlite3VdbeChangeP2(v, 2 + flags, pTab->tnum);
73219
+ sqlite3VdbeChangeP3(v, 2 + flags, iDb);
7303073220
7303173221
/* Configure the number of columns. Configure the cursor to
7303273222
** think that the table has one more column than it really
7303373223
** does. An OP_Column to retrieve this imaginary column will
7303473224
** always return an SQL NULL. This is useful because it means
7303573225
** we can invoke OP_Column to fill in the vdbe cursors type
7303673226
** and offset cache without causing any IO.
7303773227
*/
73038
- sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
73039
- sqlite3VdbeChangeP2(v, 7, pTab->nCol);
73228
+ sqlite3VdbeChangeP4(v, 2+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
73229
+ sqlite3VdbeChangeP2(v, 6, pTab->nCol);
7304073230
if( !db->mallocFailed ){
7304173231
pParse->nVar = 1;
7304273232
pParse->nMem = 1;
7304373233
pParse->nTab = 1;
7304473234
sqlite3VdbeMakeReady(v, pParse);
@@ -75302,12 +75492,12 @@
7530275492
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
7530375493
7530475494
/*
7530575495
** Perhaps the name is a reference to the ROWID
7530675496
*/
75307
- assert( pTab!=0 || cntTab==0 );
75308
- if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
75497
+ if( cnt==0 && cntTab==1 && pMatch && sqlite3IsRowid(zCol)
75498
+ && HasRowid(pMatch->pTab) ){
7530975499
cnt = 1;
7531075500
pExpr->iColumn = -1; /* IMP: R-44911-55124 */
7531175501
pExpr->affinity = SQLITE_AFF_INTEGER;
7531275502
}
7531375503
@@ -77434,11 +77624,10 @@
7743477624
pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
7743577625
pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
7743677626
pNew->iLimit = 0;
7743777627
pNew->iOffset = 0;
7743877628
pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
77439
- pNew->pRightmost = 0;
7744077629
pNew->addrOpenEphm[0] = -1;
7744177630
pNew->addrOpenEphm[1] = -1;
7744277631
pNew->addrOpenEphm[2] = -1;
7744377632
pNew->nSelectRow = p->nSelectRow;
7744477633
pNew->pWith = withDup(db, p->pWith);
@@ -77744,28 +77933,10 @@
7774477933
default:
7774577934
return 1;
7774677935
}
7774777936
}
7774877937
77749
-/*
77750
-** Generate an OP_IsNull instruction that tests register iReg and jumps
77751
-** to location iDest if the value in iReg is NULL. The value in iReg
77752
-** was computed by pExpr. If we can look at pExpr at compile-time and
77753
-** determine that it can never generate a NULL, then the OP_IsNull operation
77754
-** can be omitted.
77755
-*/
77756
-SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(
77757
- Vdbe *v, /* The VDBE under construction */
77758
- const Expr *pExpr, /* Only generate OP_IsNull if this expr can be NULL */
77759
- int iReg, /* Test the value in this register for NULL */
77760
- int iDest /* Jump here if the value is null */
77761
-){
77762
- if( sqlite3ExprCanBeNull(pExpr) ){
77763
- sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest);
77764
- }
77765
-}
77766
-
7776777938
/*
7776877939
** Return TRUE if the given expression is a constant which would be
7776977940
** unchanged by OP_Affinity with the affinity given in the second
7777077941
** argument.
7777177942
**
@@ -77958,11 +78129,11 @@
7795878129
assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
7795978130
pTab = p->pSrc->a[0].pTab;
7796078131
pExpr = p->pEList->a[0].pExpr;
7796178132
iCol = (i16)pExpr->iColumn;
7796278133
77963
- /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
78134
+ /* Code an OP_Transaction and OP_TableLock for <table>. */
7796478135
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7796578136
sqlite3CodeVerifySchema(pParse, iDb);
7796678137
sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
7796778138
7796878139
/* This function is only called from two places. In both cases the vdbe
@@ -77969,13 +78140,12 @@
7796978140
** has already been allocated. So assume sqlite3GetVdbe() is always
7797078141
** successful here.
7797178142
*/
7797278143
assert(v);
7797378144
if( iCol<0 ){
77974
- int iAddr;
77975
-
77976
- iAddr = sqlite3CodeOnce(pParse);
78145
+ int iAddr = sqlite3CodeOnce(pParse);
78146
+ VdbeCoverage(v);
7797778147
7797878148
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
7797978149
eType = IN_INDEX_ROWID;
7798078150
7798178151
sqlite3VdbeJumpHere(v, iAddr);
@@ -77996,22 +78166,22 @@
7799678166
for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
7799778167
if( (pIdx->aiColumn[0]==iCol)
7799878168
&& sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
7799978169
&& (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
7800078170
){
78001
- int iAddr = sqlite3CodeOnce(pParse);
78171
+ int iAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
7800278172
sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
7800378173
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
7800478174
VdbeComment((v, "%s", pIdx->zName));
7800578175
assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
7800678176
eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
7800778177
78008
- sqlite3VdbeJumpHere(v, iAddr);
7800978178
if( prNotFound && !pTab->aCol[iCol].notNull ){
7801078179
*prNotFound = ++pParse->nMem;
7801178180
sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
7801278181
}
78182
+ sqlite3VdbeJumpHere(v, iAddr);
7801378183
}
7801478184
}
7801578185
}
7801678186
}
7801778187
@@ -78096,11 +78266,11 @@
7809678266
**
7809778267
** If all of the above are false, then we can run this code just once
7809878268
** save the results, and reuse the same result on subsequent invocations.
7809978269
*/
7810078270
if( !ExprHasProperty(pExpr, EP_VarSelect) ){
78101
- testAddr = sqlite3CodeOnce(pParse);
78271
+ testAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
7810278272
}
7810378273
7810478274
#ifndef SQLITE_OMIT_EXPLAIN
7810578275
if( pParse->explain==2 ){
7810678276
char *zMsg = sqlite3MPrintf(
@@ -78137,11 +78307,10 @@
7813778307
** 'x' nor the SELECT... statement are columns, then numeric affinity
7813878308
** is used.
7813978309
*/
7814078310
pExpr->iTable = pParse->nTab++;
7814178311
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
78142
- if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
7814378312
pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
7814478313
7814578314
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
7814678315
/* Case 1: expr IN (SELECT ...)
7814778316
**
@@ -78213,10 +78382,11 @@
7821378382
}else{
7821478383
r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
7821578384
if( isRowid ){
7821678385
sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
7821778386
sqlite3VdbeCurrentAddr(v)+2);
78387
+ VdbeCoverage(v);
7821878388
sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
7821978389
}else{
7822078390
sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
7822178391
sqlite3ExprCacheAffinityChange(pParse, r3, 1);
7822278392
sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
@@ -78336,23 +78506,25 @@
7833678506
** on whether the RHS is empty or not, respectively.
7833778507
*/
7833878508
if( destIfNull==destIfFalse ){
7833978509
/* Shortcut for the common case where the false and NULL outcomes are
7834078510
** the same. */
78341
- sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull);
78511
+ sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
7834278512
}else{
78343
- int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1);
78513
+ int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
7834478514
sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
78515
+ VdbeCoverage(v);
7834578516
sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
7834678517
sqlite3VdbeJumpHere(v, addr1);
7834778518
}
7834878519
7834978520
if( eType==IN_INDEX_ROWID ){
7835078521
/* In this case, the RHS is the ROWID of table b-tree
7835178522
*/
78352
- sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse);
78523
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse); VdbeCoverage(v);
7835378524
sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1);
78525
+ VdbeCoverage(v);
7835478526
}else{
7835578527
/* In this case, the RHS is an index b-tree.
7835678528
*/
7835778529
sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1);
7835878530
@@ -78369,42 +78541,40 @@
7836978541
**
7837078542
** Also run this branch if NULL is equivalent to FALSE
7837178543
** for this particular IN operator.
7837278544
*/
7837378545
sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse, r1, 1);
78374
-
78546
+ VdbeCoverage(v);
7837578547
}else{
7837678548
/* In this branch, the RHS of the IN might contain a NULL and
7837778549
** the presence of a NULL on the RHS makes a difference in the
7837878550
** outcome.
7837978551
*/
78380
- int j1, j2, j3;
78552
+ int j1, j2;
7838178553
7838278554
/* First check to see if the LHS is contained in the RHS. If so,
7838378555
** then the presence of NULLs in the RHS does not matter, so jump
7838478556
** over all of the code that follows.
7838578557
*/
7838678558
j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
78559
+ VdbeCoverage(v);
7838778560
7838878561
/* Here we begin generating code that runs if the LHS is not
7838978562
** contained within the RHS. Generate additional code that
7839078563
** tests the RHS for NULLs. If the RHS contains a NULL then
7839178564
** jump to destIfNull. If there are no NULLs in the RHS then
7839278565
** jump to destIfFalse.
7839378566
*/
78394
- j2 = sqlite3VdbeAddOp1(v, OP_NotNull, rRhsHasNull);
78395
- j3 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
78396
- sqlite3VdbeAddOp2(v, OP_Integer, -1, rRhsHasNull);
78397
- sqlite3VdbeJumpHere(v, j3);
78398
- sqlite3VdbeAddOp2(v, OP_AddImm, rRhsHasNull, 1);
78567
+ sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull); VdbeCoverage(v);
78568
+ sqlite3VdbeAddOp2(v, OP_IfNot, rRhsHasNull, destIfFalse); VdbeCoverage(v);
78569
+ j2 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
78570
+ VdbeCoverage(v);
78571
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, rRhsHasNull);
78572
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
7839978573
sqlite3VdbeJumpHere(v, j2);
78400
-
78401
- /* Jump to the appropriate target depending on whether or not
78402
- ** the RHS contains a NULL
78403
- */
78404
- sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull);
78405
- sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
78574
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, rRhsHasNull);
78575
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
7840678576
7840778577
/* The OP_Found at the top of this branch jumps here when true,
7840878578
** causing the overall IN expression evaluation to fall through.
7840978579
*/
7841078580
sqlite3VdbeJumpHere(v, j1);
@@ -78921,26 +79091,20 @@
7892179091
case TK_LE:
7892279092
case TK_GT:
7892379093
case TK_GE:
7892479094
case TK_NE:
7892579095
case TK_EQ: {
78926
- assert( TK_LT==OP_Lt );
78927
- assert( TK_LE==OP_Le );
78928
- assert( TK_GT==OP_Gt );
78929
- assert( TK_GE==OP_Ge );
78930
- assert( TK_EQ==OP_Eq );
78931
- assert( TK_NE==OP_Ne );
78932
- testcase( op==TK_LT );
78933
- testcase( op==TK_LE );
78934
- testcase( op==TK_GT );
78935
- testcase( op==TK_GE );
78936
- testcase( op==TK_EQ );
78937
- testcase( op==TK_NE );
7893879096
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7893979097
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
7894079098
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
7894179099
r1, r2, inReg, SQLITE_STOREP2);
79100
+ assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
79101
+ assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
79102
+ assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
79103
+ assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
79104
+ assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
79105
+ assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
7894279106
testcase( regFree1==0 );
7894379107
testcase( regFree2==0 );
7894479108
break;
7894579109
}
7894679110
case TK_IS:
@@ -78950,10 +79114,12 @@
7895079114
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7895179115
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
7895279116
op = (op==TK_IS) ? TK_EQ : TK_NE;
7895379117
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
7895479118
r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ);
79119
+ VdbeCoverageIf(v, op==TK_EQ);
79120
+ VdbeCoverageIf(v, op==TK_NE);
7895579121
testcase( regFree1==0 );
7895679122
testcase( regFree2==0 );
7895779123
break;
7895879124
}
7895979125
case TK_AND:
@@ -78966,32 +79132,21 @@
7896679132
case TK_BITOR:
7896779133
case TK_SLASH:
7896879134
case TK_LSHIFT:
7896979135
case TK_RSHIFT:
7897079136
case TK_CONCAT: {
78971
- assert( TK_AND==OP_And );
78972
- assert( TK_OR==OP_Or );
78973
- assert( TK_PLUS==OP_Add );
78974
- assert( TK_MINUS==OP_Subtract );
78975
- assert( TK_REM==OP_Remainder );
78976
- assert( TK_BITAND==OP_BitAnd );
78977
- assert( TK_BITOR==OP_BitOr );
78978
- assert( TK_SLASH==OP_Divide );
78979
- assert( TK_LSHIFT==OP_ShiftLeft );
78980
- assert( TK_RSHIFT==OP_ShiftRight );
78981
- assert( TK_CONCAT==OP_Concat );
78982
- testcase( op==TK_AND );
78983
- testcase( op==TK_OR );
78984
- testcase( op==TK_PLUS );
78985
- testcase( op==TK_MINUS );
78986
- testcase( op==TK_REM );
78987
- testcase( op==TK_BITAND );
78988
- testcase( op==TK_BITOR );
78989
- testcase( op==TK_SLASH );
78990
- testcase( op==TK_LSHIFT );
78991
- testcase( op==TK_RSHIFT );
78992
- testcase( op==TK_CONCAT );
79137
+ assert( TK_AND==OP_And ); testcase( op==TK_AND );
79138
+ assert( TK_OR==OP_Or ); testcase( op==TK_OR );
79139
+ assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
79140
+ assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
79141
+ assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
79142
+ assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND );
79143
+ assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
79144
+ assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH );
79145
+ assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT );
79146
+ assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT );
79147
+ assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT );
7899379148
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7899479149
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
7899579150
sqlite3VdbeAddOp3(v, op, r2, r1, target);
7899679151
testcase( regFree1==0 );
7899779152
testcase( regFree2==0 );
@@ -79019,31 +79174,29 @@
7901979174
inReg = target;
7902079175
break;
7902179176
}
7902279177
case TK_BITNOT:
7902379178
case TK_NOT: {
79024
- assert( TK_BITNOT==OP_BitNot );
79025
- assert( TK_NOT==OP_Not );
79026
- testcase( op==TK_BITNOT );
79027
- testcase( op==TK_NOT );
79179
+ assert( TK_BITNOT==OP_BitNot ); testcase( op==TK_BITNOT );
79180
+ assert( TK_NOT==OP_Not ); testcase( op==TK_NOT );
7902879181
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7902979182
testcase( regFree1==0 );
7903079183
inReg = target;
7903179184
sqlite3VdbeAddOp2(v, op, r1, inReg);
7903279185
break;
7903379186
}
7903479187
case TK_ISNULL:
7903579188
case TK_NOTNULL: {
7903679189
int addr;
79037
- assert( TK_ISNULL==OP_IsNull );
79038
- assert( TK_NOTNULL==OP_NotNull );
79039
- testcase( op==TK_ISNULL );
79040
- testcase( op==TK_NOTNULL );
79190
+ assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
79191
+ assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
7904179192
sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
7904279193
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7904379194
testcase( regFree1==0 );
7904479195
addr = sqlite3VdbeAddOp1(v, op, r1);
79196
+ VdbeCoverageIf(v, op==TK_ISNULL);
79197
+ VdbeCoverageIf(v, op==TK_NOTNULL);
7904579198
sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
7904679199
sqlite3VdbeJumpHere(v, addr);
7904779200
break;
7904879201
}
7904979202
case TK_AGG_FUNCTION: {
@@ -79091,10 +79244,11 @@
7909179244
int endCoalesce = sqlite3VdbeMakeLabel(v);
7909279245
assert( nFarg>=2 );
7909379246
sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
7909479247
for(i=1; i<nFarg; i++){
7909579248
sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
79249
+ VdbeCoverage(v);
7909679250
sqlite3ExprCacheRemove(pParse, target, 1);
7909779251
sqlite3ExprCachePush(pParse);
7909879252
sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
7909979253
sqlite3ExprCachePop(pParse, 1);
7910079254
}
@@ -79228,17 +79382,18 @@
7922879382
testcase( regFree1==0 );
7922979383
testcase( regFree2==0 );
7923079384
r3 = sqlite3GetTempReg(pParse);
7923179385
r4 = sqlite3GetTempReg(pParse);
7923279386
codeCompare(pParse, pLeft, pRight, OP_Ge,
79233
- r1, r2, r3, SQLITE_STOREP2);
79387
+ r1, r2, r3, SQLITE_STOREP2); VdbeCoverage(v);
7923479388
pLItem++;
7923579389
pRight = pLItem->pExpr;
7923679390
sqlite3ReleaseTempReg(pParse, regFree2);
7923779391
r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
7923879392
testcase( regFree2==0 );
7923979393
codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2);
79394
+ VdbeCoverage(v);
7924079395
sqlite3VdbeAddOp3(v, OP_And, r3, r4, target);
7924179396
sqlite3ReleaseTempReg(pParse, r3);
7924279397
sqlite3ReleaseTempReg(pParse, r4);
7924379398
break;
7924479399
}
@@ -79401,10 +79556,11 @@
7940179556
}
7940279557
assert( !ExprHasProperty(pExpr, EP_IntValue) );
7940379558
if( pExpr->affinity==OE_Ignore ){
7940479559
sqlite3VdbeAddOp4(
7940579560
v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
79561
+ VdbeCoverage(v);
7940679562
}else{
7940779563
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
7940879564
pExpr->affinity, pExpr->u.zToken, 0, 0);
7940979565
}
7941079566
@@ -79488,11 +79644,11 @@
7948879644
/*
7948979645
** Generate code that will evaluate expression pExpr and store the
7949079646
** results in register target. The results are guaranteed to appear
7949179647
** in register target.
7949279648
*/
79493
-SQLITE_PRIVATE int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
79649
+SQLITE_PRIVATE void sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
7949479650
int inReg;
7949579651
7949679652
assert( target>0 && target<=pParse->nMem );
7949779653
if( pExpr && pExpr->op==TK_REGISTER ){
7949879654
sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
@@ -79501,11 +79657,24 @@
7950179657
assert( pParse->pVdbe || pParse->db->mallocFailed );
7950279658
if( inReg!=target && pParse->pVdbe ){
7950379659
sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
7950479660
}
7950579661
}
79506
- return target;
79662
+}
79663
+
79664
+/*
79665
+** Generate code that will evaluate expression pExpr and store the
79666
+** results in register target. The results are guaranteed to appear
79667
+** in register target. If the expression is constant, then this routine
79668
+** might choose to code the expression at initialization time.
79669
+*/
79670
+SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
79671
+ if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){
79672
+ sqlite3ExprCodeAtInit(pParse, pExpr, target, 0);
79673
+ }else{
79674
+ sqlite3ExprCode(pParse, pExpr, target);
79675
+ }
7950779676
}
7950879677
7950979678
/*
7951079679
** Generate code that evalutes the given expression and puts the result
7951179680
** in register target.
@@ -79516,29 +79685,20 @@
7951679685
**
7951779686
** This routine is used for expressions that are used multiple
7951879687
** times. They are evaluated once and the results of the expression
7951979688
** are reused.
7952079689
*/
79521
-SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79690
+SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
7952279691
Vdbe *v = pParse->pVdbe;
79523
- int inReg;
79524
- inReg = sqlite3ExprCode(pParse, pExpr, target);
79692
+ int iMem;
79693
+
7952579694
assert( target>0 );
79526
- /* The only place, other than this routine, where expressions can be
79527
- ** converted to TK_REGISTER is internal subexpressions in BETWEEN and
79528
- ** CASE operators. Neither ever calls this routine. And this routine
79529
- ** is never called twice on the same expression. Hence it is impossible
79530
- ** for the input to this routine to already be a register. Nevertheless,
79531
- ** it seems prudent to keep the ALWAYS() in case the conditions above
79532
- ** change with future modifications or enhancements. */
79533
- if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79534
- int iMem;
79535
- iMem = ++pParse->nMem;
79536
- sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79537
- exprToRegister(pExpr, iMem);
79538
- }
79539
- return inReg;
79695
+ assert( pExpr->op!=TK_REGISTER );
79696
+ sqlite3ExprCode(pParse, pExpr, target);
79697
+ iMem = ++pParse->nMem;
79698
+ sqlite3VdbeAddOp2(v, OP_Copy, target, iMem);
79699
+ exprToRegister(pExpr, iMem);
7954079700
}
7954179701
7954279702
#if defined(SQLITE_ENABLE_TREE_EXPLAIN)
7954379703
/*
7954479704
** Generate a human-readable explanation of an expression tree.
@@ -79969,27 +80129,21 @@
7996980129
case TK_LE:
7997080130
case TK_GT:
7997180131
case TK_GE:
7997280132
case TK_NE:
7997380133
case TK_EQ: {
79974
- assert( TK_LT==OP_Lt );
79975
- assert( TK_LE==OP_Le );
79976
- assert( TK_GT==OP_Gt );
79977
- assert( TK_GE==OP_Ge );
79978
- assert( TK_EQ==OP_Eq );
79979
- assert( TK_NE==OP_Ne );
79980
- testcase( op==TK_LT );
79981
- testcase( op==TK_LE );
79982
- testcase( op==TK_GT );
79983
- testcase( op==TK_GE );
79984
- testcase( op==TK_EQ );
79985
- testcase( op==TK_NE );
7998680134
testcase( jumpIfNull==0 );
7998780135
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
7998880136
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
7998980137
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
7999080138
r1, r2, dest, jumpIfNull);
80139
+ assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
80140
+ assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
80141
+ assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
80142
+ assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
80143
+ assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
80144
+ assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
7999180145
testcase( regFree1==0 );
7999280146
testcase( regFree2==0 );
7999380147
break;
7999480148
}
7999580149
case TK_IS:
@@ -79999,22 +80153,24 @@
7999980153
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8000080154
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
8000180155
op = (op==TK_IS) ? TK_EQ : TK_NE;
8000280156
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
8000380157
r1, r2, dest, SQLITE_NULLEQ);
80158
+ VdbeCoverageIf(v, op==TK_EQ);
80159
+ VdbeCoverageIf(v, op==TK_NE);
8000480160
testcase( regFree1==0 );
8000580161
testcase( regFree2==0 );
8000680162
break;
8000780163
}
8000880164
case TK_ISNULL:
8000980165
case TK_NOTNULL: {
80010
- assert( TK_ISNULL==OP_IsNull );
80011
- assert( TK_NOTNULL==OP_NotNull );
80012
- testcase( op==TK_ISNULL );
80013
- testcase( op==TK_NOTNULL );
80166
+ assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
80167
+ assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
8001480168
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8001580169
sqlite3VdbeAddOp2(v, op, r1, dest);
80170
+ VdbeCoverageIf(v, op==TK_ISNULL);
80171
+ VdbeCoverageIf(v, op==TK_NOTNULL);
8001680172
testcase( regFree1==0 );
8001780173
break;
8001880174
}
8001980175
case TK_BETWEEN: {
8002080176
testcase( jumpIfNull==0 );
@@ -80037,10 +80193,11 @@
8003780193
}else if( exprAlwaysFalse(pExpr) ){
8003880194
/* No-op */
8003980195
}else{
8004080196
r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
8004180197
sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
80198
+ VdbeCoverage(v);
8004280199
testcase( regFree1==0 );
8004380200
testcase( jumpIfNull==0 );
8004480201
}
8004580202
break;
8004680203
}
@@ -80128,21 +80285,21 @@
8012880285
case TK_LE:
8012980286
case TK_GT:
8013080287
case TK_GE:
8013180288
case TK_NE:
8013280289
case TK_EQ: {
80133
- testcase( op==TK_LT );
80134
- testcase( op==TK_LE );
80135
- testcase( op==TK_GT );
80136
- testcase( op==TK_GE );
80137
- testcase( op==TK_EQ );
80138
- testcase( op==TK_NE );
8013980290
testcase( jumpIfNull==0 );
8014080291
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8014180292
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
8014280293
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
8014380294
r1, r2, dest, jumpIfNull);
80295
+ assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
80296
+ assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
80297
+ assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
80298
+ assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
80299
+ assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
80300
+ assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
8014480301
testcase( regFree1==0 );
8014580302
testcase( regFree2==0 );
8014680303
break;
8014780304
}
8014880305
case TK_IS:
@@ -80152,20 +80309,22 @@
8015280309
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8015380310
r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
8015480311
op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
8015580312
codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
8015680313
r1, r2, dest, SQLITE_NULLEQ);
80314
+ VdbeCoverageIf(v, op==TK_EQ);
80315
+ VdbeCoverageIf(v, op==TK_NE);
8015780316
testcase( regFree1==0 );
8015880317
testcase( regFree2==0 );
8015980318
break;
8016080319
}
8016180320
case TK_ISNULL:
8016280321
case TK_NOTNULL: {
80163
- testcase( op==TK_ISNULL );
80164
- testcase( op==TK_NOTNULL );
8016580322
r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
8016680323
sqlite3VdbeAddOp2(v, op, r1, dest);
80324
+ testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
80325
+ testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL);
8016780326
testcase( regFree1==0 );
8016880327
break;
8016980328
}
8017080329
case TK_BETWEEN: {
8017180330
testcase( jumpIfNull==0 );
@@ -80190,10 +80349,11 @@
8019080349
}else if( exprAlwaysTrue(pExpr) ){
8019180350
/* no-op */
8019280351
}else{
8019380352
r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
8019480353
sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80354
+ VdbeCoverage(v);
8019580355
testcase( regFree1==0 );
8019680356
testcase( jumpIfNull==0 );
8019780357
}
8019880358
break;
8019980359
}
@@ -80736,12 +80896,12 @@
8073680896
len = sqlite3GetToken(zCsr, &token);
8073780897
} while( token==TK_SPACE );
8073880898
assert( len>0 );
8073980899
} while( token!=TK_LP && token!=TK_USING );
8074080900
80741
- zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
80742
- zTableName, tname.z+tname.n);
80901
+ zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
80902
+ zSql, zTableName, tname.z+tname.n);
8074380903
sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
8074480904
}
8074580905
}
8074680906
8074780907
/*
@@ -80789,11 +80949,11 @@
8078980949
zParent = sqlite3DbStrNDup(db, (const char *)z, n);
8079080950
if( zParent==0 ) break;
8079180951
sqlite3Dequote(zParent);
8079280952
if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
8079380953
char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
80794
- (zOutput?zOutput:""), z-zInput, zInput, (const char *)zNew
80954
+ (zOutput?zOutput:""), (int)(z-zInput), zInput, (const char *)zNew
8079580955
);
8079680956
sqlite3DbFree(db, zOutput);
8079780957
zOutput = zOut;
8079880958
zInput = &z[n];
8079980959
}
@@ -80875,12 +81035,12 @@
8087581035
} while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
8087681036
8087781037
/* Variable tname now contains the token that is the old table-name
8087881038
** in the CREATE TRIGGER statement.
8087981039
*/
80880
- zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
80881
- zTableName, tname.z+tname.n);
81040
+ zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
81041
+ zSql, zTableName, tname.z+tname.n);
8088281042
sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
8088381043
}
8088481044
}
8088581045
#endif /* !SQLITE_OMIT_TRIGGER */
8088681046
@@ -81128,11 +81288,11 @@
8112881288
pVTab = 0;
8112981289
}
8113081290
}
8113181291
#endif
8113281292
81133
- /* Begin a transaction and code the VerifyCookie for database iDb.
81293
+ /* Begin a transaction for database iDb.
8113481294
** Then modify the schema cookie (since the ALTER TABLE modifies the
8113581295
** schema). Open a statement transaction if the table is a virtual
8113681296
** table.
8113781297
*/
8113881298
v = sqlite3GetVdbe(pParse);
@@ -81264,10 +81424,11 @@
8126481424
int j1;
8126581425
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
8126681426
sqlite3VdbeUsesBtree(v, iDb);
8126781427
sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
8126881428
j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
81429
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
8126981430
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
8127081431
sqlite3VdbeJumpHere(v, j1);
8127181432
sqlite3ReleaseTempReg(pParse, r1);
8127281433
sqlite3ReleaseTempReg(pParse, r2);
8127381434
}
@@ -82564,10 +82725,11 @@
8256482725
** regChng = 0
8256582726
** goto next_push_0;
8256682727
**
8256782728
*/
8256882729
addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
82730
+ VdbeCoverage(v);
8256982731
sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
8257082732
addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
8257182733
8257282734
/*
8257382735
** next_row:
@@ -82585,10 +82747,11 @@
8258582747
sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
8258682748
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
8258782749
aGotoChng[i] =
8258882750
sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
8258982751
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
82752
+ VdbeCoverage(v);
8259082753
}
8259182754
sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
8259282755
aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
8259382756
8259482757
/*
@@ -82631,11 +82794,11 @@
8263182794
#endif
8263282795
assert( regChng==(regStat4+1) );
8263382796
sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
8263482797
sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
8263582798
sqlite3VdbeChangeP5(v, 2+IsStat34);
82636
- sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow);
82799
+ sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
8263782800
8263882801
/* Add the entry to the stat1 table. */
8263982802
callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
8264082803
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
8264182804
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
@@ -82658,14 +82821,16 @@
8265882821
pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
8265982822
8266082823
addrNext = sqlite3VdbeCurrentAddr(v);
8266182824
callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
8266282825
addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
82826
+ VdbeCoverage(v);
8266382827
callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
8266482828
callStatGet(v, regStat4, STAT_GET_NLT, regLt);
8266582829
callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
8266682830
sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
82831
+ VdbeCoverage(v);
8266782832
#ifdef SQLITE_ENABLE_STAT3
8266882833
sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
8266982834
pIdx->aiColumn[0], regSample);
8267082835
#else
8267182836
for(i=0; i<nCol; i++){
@@ -82672,11 +82837,11 @@
8267282837
i16 iCol = pIdx->aiColumn[i];
8267382838
sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
8267482839
}
8267582840
sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
8267682841
#endif
82677
- sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regTemp, "bbbbbb", 0);
82842
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
8267882843
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
8267982844
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
8268082845
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
8268182846
sqlite3VdbeJumpHere(v, addrIsNull);
8268282847
}
@@ -82692,11 +82857,11 @@
8269282857
** name and the row count as the content.
8269382858
*/
8269482859
if( pOnlyIdx==0 && needTableCnt ){
8269582860
VdbeComment((v, "%s", pTab->zName));
8269682861
sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
82697
- jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
82862
+ jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
8269882863
sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
8269982864
sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
8270082865
sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
8270182866
sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
8270282867
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -84230,24 +84395,26 @@
8423084395
** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
8423184396
** set for each database that is used. Generate code to start a
8423284397
** transaction on each used database and to verify the schema cookie
8423384398
** on each used database.
8423484399
*/
84235
- if( pParse->cookieGoto>0 ){
84400
+ if( db->mallocFailed==0 && (pParse->cookieMask || pParse->pConstExpr) ){
8423684401
yDbMask mask;
84237
- int iDb, i, addr;
84238
- sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
84402
+ int iDb, i;
84403
+ assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
84404
+ sqlite3VdbeJumpHere(v, 0);
8423984405
for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
8424084406
if( (mask & pParse->cookieMask)==0 ) continue;
8424184407
sqlite3VdbeUsesBtree(v, iDb);
84242
- sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
84243
- if( db->init.busy==0 ){
84244
- assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
84245
- sqlite3VdbeAddOp3(v, OP_VerifyCookie,
84246
- iDb, pParse->cookieValue[iDb],
84247
- db->aDb[iDb].pSchema->iGeneration);
84248
- }
84408
+ sqlite3VdbeAddOp4Int(v,
84409
+ OP_Transaction, /* Opcode */
84410
+ iDb, /* P1 */
84411
+ (mask & pParse->writeMask)!=0, /* P2 */
84412
+ pParse->cookieValue[iDb], /* P3 */
84413
+ db->aDb[iDb].pSchema->iGeneration /* P4 */
84414
+ );
84415
+ if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
8424984416
}
8425084417
#ifndef SQLITE_OMIT_VIRTUALTABLE
8425184418
for(i=0; i<pParse->nVtabLock; i++){
8425284419
char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
8425384420
sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
@@ -84264,21 +84431,20 @@
8426484431
/* Initialize any AUTOINCREMENT data structures required.
8426584432
*/
8426684433
sqlite3AutoincrementBegin(pParse);
8426784434
8426884435
/* Code constant expressions that where factored out of inner loops */
84269
- addr = pParse->cookieGoto;
8427084436
if( pParse->pConstExpr ){
8427184437
ExprList *pEL = pParse->pConstExpr;
84272
- pParse->cookieGoto = 0;
84438
+ pParse->okConstFactor = 0;
8427384439
for(i=0; i<pEL->nExpr; i++){
8427484440
sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
8427584441
}
8427684442
}
8427784443
8427884444
/* Finally, jump back to the beginning of the executable code. */
84279
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
84445
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
8428084446
}
8428184447
}
8428284448
8428384449
8428484450
/* Get the VDBE program ready for execution
@@ -84297,11 +84463,10 @@
8429784463
pParse->nTab = 0;
8429884464
pParse->nMem = 0;
8429984465
pParse->nSet = 0;
8430084466
pParse->nVar = 0;
8430184467
pParse->cookieMask = 0;
84302
- pParse->cookieGoto = 0;
8430384468
}
8430484469
8430584470
/*
8430684471
** Run the parser and code generator recursively in order to generate
8430784472
** code for the SQL statement given onto the end of the pParse context
@@ -85029,11 +85194,11 @@
8502985194
reg1 = pParse->regRowid = ++pParse->nMem;
8503085195
reg2 = pParse->regRoot = ++pParse->nMem;
8503185196
reg3 = ++pParse->nMem;
8503285197
sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
8503385198
sqlite3VdbeUsesBtree(v, iDb);
85034
- j1 = sqlite3VdbeAddOp1(v, OP_If, reg3);
85199
+ j1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
8503585200
fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
8503685201
1 : SQLITE_MAX_FILE_FORMAT;
8503785202
sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
8503885203
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
8503985204
sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
@@ -86756,40 +86921,40 @@
8675686921
sqlite3KeyInfoRef(pKey), P4_KEYINFO);
8675786922
8675886923
/* Open the table. Loop through all rows of the table, inserting index
8675986924
** records into the sorter. */
8676086925
sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
86761
- addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
86926
+ addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
8676286927
regRecord = sqlite3GetTempReg(pParse);
8676386928
8676486929
sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
8676586930
sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
8676686931
sqlite3VdbeResolveLabel(v, iPartIdxLabel);
86767
- sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
86932
+ sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
8676886933
sqlite3VdbeJumpHere(v, addr1);
8676986934
if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
8677086935
sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
8677186936
(char *)pKey, P4_KEYINFO);
8677286937
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
8677386938
86774
- addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
86939
+ addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
8677586940
assert( pKey!=0 || db->mallocFailed || pParse->nErr );
8677686941
if( pIndex->onError!=OE_None && pKey!=0 ){
8677786942
int j2 = sqlite3VdbeCurrentAddr(v) + 3;
8677886943
sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
8677986944
addr2 = sqlite3VdbeCurrentAddr(v);
8678086945
sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
86781
- pKey->nField - pIndex->nKeyCol);
86946
+ pKey->nField - pIndex->nKeyCol); VdbeCoverage(v);
8678286947
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
8678386948
}else{
8678486949
addr2 = sqlite3VdbeCurrentAddr(v);
8678586950
}
8678686951
sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
8678786952
sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
8678886953
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
8678986954
sqlite3ReleaseTempReg(pParse, regRecord);
86790
- sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
86955
+ sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
8679186956
sqlite3VdbeJumpHere(v, addr1);
8679286957
8679386958
sqlite3VdbeAddOp1(v, OP_Close, iTab);
8679486959
sqlite3VdbeAddOp1(v, OP_Close, iIdx);
8679586960
sqlite3VdbeAddOp1(v, OP_Close, iSorter);
@@ -87906,63 +88071,30 @@
8790688071
}
8790788072
return 0;
8790888073
}
8790988074
8791088075
/*
87911
-** Generate VDBE code that will verify the schema cookie and start
87912
-** a read-transaction for all named database files.
87913
-**
87914
-** It is important that all schema cookies be verified and all
87915
-** read transactions be started before anything else happens in
87916
-** the VDBE program. But this routine can be called after much other
87917
-** code has been generated. So here is what we do:
87918
-**
87919
-** The first time this routine is called, we code an OP_Goto that
87920
-** will jump to a subroutine at the end of the program. Then we
87921
-** record every database that needs its schema verified in the
87922
-** pParse->cookieMask field. Later, after all other code has been
87923
-** generated, the subroutine that does the cookie verifications and
87924
-** starts the transactions will be coded and the OP_Goto P2 value
87925
-** will be made to point to that subroutine. The generation of the
87926
-** cookie verification subroutine code happens in sqlite3FinishCoding().
87927
-**
87928
-** If iDb<0 then code the OP_Goto only - don't set flag to verify the
87929
-** schema on any databases. This can be used to position the OP_Goto
87930
-** early in the code, before we know if any database tables will be used.
88076
+** Record the fact that the schema cookie will need to be verified
88077
+** for database iDb. The code to actually verify the schema cookie
88078
+** will occur at the end of the top-level VDBE and will be generated
88079
+** later, by sqlite3FinishCoding().
8793188080
*/
8793288081
SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
8793388082
Parse *pToplevel = sqlite3ParseToplevel(pParse);
87934
-
87935
-#ifndef SQLITE_OMIT_TRIGGER
87936
- if( pToplevel!=pParse ){
87937
- /* This branch is taken if a trigger is currently being coded. In this
87938
- ** case, set cookieGoto to a non-zero value to show that this function
87939
- ** has been called. This is used by the sqlite3ExprCodeConstants()
87940
- ** function. */
87941
- pParse->cookieGoto = -1;
87942
- }
87943
-#endif
87944
- if( pToplevel->cookieGoto==0 ){
87945
- Vdbe *v = sqlite3GetVdbe(pToplevel);
87946
- if( v==0 ) return; /* This only happens if there was a prior error */
87947
- pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1;
87948
- }
87949
- if( iDb>=0 ){
87950
- sqlite3 *db = pToplevel->db;
87951
- yDbMask mask;
87952
-
87953
- assert( iDb<db->nDb );
87954
- assert( db->aDb[iDb].pBt!=0 || iDb==1 );
87955
- assert( iDb<SQLITE_MAX_ATTACHED+2 );
87956
- assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
87957
- mask = ((yDbMask)1)<<iDb;
87958
- if( (pToplevel->cookieMask & mask)==0 ){
87959
- pToplevel->cookieMask |= mask;
87960
- pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
87961
- if( !OMIT_TEMPDB && iDb==1 ){
87962
- sqlite3OpenTempDatabase(pToplevel);
87963
- }
88083
+ sqlite3 *db = pToplevel->db;
88084
+ yDbMask mask;
88085
+
88086
+ assert( iDb>=0 && iDb<db->nDb );
88087
+ assert( db->aDb[iDb].pBt!=0 || iDb==1 );
88088
+ assert( iDb<SQLITE_MAX_ATTACHED+2 );
88089
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
88090
+ mask = ((yDbMask)1)<<iDb;
88091
+ if( (pToplevel->cookieMask & mask)==0 ){
88092
+ pToplevel->cookieMask |= mask;
88093
+ pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
88094
+ if( !OMIT_TEMPDB && iDb==1 ){
88095
+ sqlite3OpenTempDatabase(pToplevel);
8796488096
}
8796588097
}
8796688098
}
8796788099
8796888100
/*
@@ -88929,25 +89061,20 @@
8892989061
SelectDest dest;
8893089062
Select *pSel;
8893189063
SrcList *pFrom;
8893289064
sqlite3 *db = pParse->db;
8893389065
int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
88934
-
8893589066
pWhere = sqlite3ExprDup(db, pWhere, 0);
8893689067
pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
88937
-
8893889068
if( pFrom ){
8893989069
assert( pFrom->nSrc==1 );
8894089070
pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
8894189071
pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
8894289072
assert( pFrom->a[0].pOn==0 );
8894389073
assert( pFrom->a[0].pUsing==0 );
8894489074
}
88945
-
8894689075
pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
88947
- if( pSel ) pSel->selFlags |= SF_Materialize;
88948
-
8894989076
sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
8895089077
sqlite3Select(pParse, pSel, &dest);
8895189078
sqlite3SelectDelete(db, pSel);
8895289079
}
8895389080
#endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -89280,11 +89407,11 @@
8928089407
}else if( pPk ){
8928189408
/* Construct a composite key for the row to be deleted and remember it */
8928289409
iKey = ++pParse->nMem;
8928389410
nKey = 0; /* Zero tells OP_Found to use a composite key */
8928489411
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89285
- sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89412
+ sqlite3IndexAffinityStr(v, pPk), nPk);
8928689413
sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
8928789414
}else{
8928889415
/* Get the rowid of the row to be deleted and remember it in the RowSet */
8928989416
nKey = 1; /* OP_Seek always uses a single rowid */
8929089417
sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -89318,17 +89445,19 @@
8931889445
/* Just one row. Hence the top-of-loop is a no-op */
8931989446
assert( nKey==nPk ); /* OP_Found will use an unpacked key */
8932089447
if( aToOpen[iDataCur-iTabCur] ){
8932189448
assert( pPk!=0 );
8932289449
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
89450
+ VdbeCoverage(v);
8932389451
}
8932489452
}else if( pPk ){
89325
- addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
89453
+ addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
8932689454
sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
8932789455
assert( nKey==0 ); /* OP_Found will use a composite key */
8932889456
}else{
8932989457
addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
89458
+ VdbeCoverage(v);
8933089459
assert( nKey==1 );
8933189460
}
8933289461
8933389462
/* Delete the row */
8933489463
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -89348,11 +89477,11 @@
8934889477
8934989478
/* End of the loop over all rowids/primary-keys. */
8935089479
if( okOnePass ){
8935189480
sqlite3VdbeResolveLabel(v, addrBypass);
8935289481
}else if( pPk ){
89353
- sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
89482
+ sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
8935489483
sqlite3VdbeJumpHere(v, addrLoop);
8935589484
}else{
8935689485
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
8935789486
sqlite3VdbeJumpHere(v, addrLoop);
8935889487
}
@@ -89446,11 +89575,15 @@
8944689575
/* Seek cursor iCur to the row to delete. If this row no longer exists
8944789576
** (this can happen if a trigger program has already deleted it), do
8944889577
** not attempt to delete it or fire any DELETE triggers. */
8944989578
iLabel = sqlite3VdbeMakeLabel(v);
8945089579
opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
89451
- if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89580
+ if( !bNoSeek ){
89581
+ sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89582
+ VdbeCoverageIf(v, opSeek==OP_NotExists);
89583
+ VdbeCoverageIf(v, opSeek==OP_NotFound);
89584
+ }
8945289585
8945389586
/* If there are any triggers to fire, allocate a range of registers to
8945489587
** use for the old.* references in the triggers. */
8945589588
if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
8945689589
u32 mask; /* Mask of OLD.* columns in use */
@@ -89488,10 +89621,12 @@
8948889621
** the cursor or of already deleted the row that the cursor was
8948989622
** pointing to.
8949089623
*/
8949189624
if( addrStart<sqlite3VdbeCurrentAddr(v) ){
8949289625
sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89626
+ VdbeCoverageIf(v, opSeek==OP_NotExists);
89627
+ VdbeCoverageIf(v, opSeek==OP_NotFound);
8949389628
}
8949489629
8949589630
/* Do FK processing. This call checks that any FK constraints that
8949689631
** refer to this table (i.e. constraints attached to other tables)
8949789632
** are not violated by deleting this row. */
@@ -91745,14 +91880,15 @@
9174591880
** Check if any of the key columns in the child table row are NULL. If
9174691881
** any are, then the constraint is considered satisfied. No need to
9174791882
** search for a matching row in the parent table. */
9174891883
if( nIncr<0 ){
9174991884
sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
91885
+ VdbeCoverage(v);
9175091886
}
9175191887
for(i=0; i<pFKey->nCol; i++){
9175291888
int iReg = aiCol[i] + regData + 1;
91753
- sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk);
91889
+ sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); VdbeCoverage(v);
9175491890
}
9175591891
9175691892
if( isIgnore==0 ){
9175791893
if( pIdx==0 ){
9175891894
/* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
@@ -91765,21 +91901,23 @@
9176591901
** is no matching parent key. Before using MustBeInt, make a copy of
9176691902
** the value. Otherwise, the value inserted into the child key column
9176791903
** will have INTEGER affinity applied to it, which may not be correct. */
9176891904
sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);
9176991905
iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
91906
+ VdbeCoverage(v);
9177091907
9177191908
/* If the parent table is the same as the child table, and we are about
9177291909
** to increment the constraint-counter (i.e. this is an INSERT operation),
9177391910
** then check if the row being inserted matches itself. If so, do not
9177491911
** increment the constraint-counter. */
9177591912
if( pTab==pFKey->pFrom && nIncr==1 ){
91776
- sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp);
91913
+ sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
91914
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
9177791915
}
9177891916
9177991917
sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
91780
- sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp);
91918
+ sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
9178191919
sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
9178291920
sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
9178391921
sqlite3VdbeJumpHere(v, iMustBeInt);
9178491922
sqlite3ReleaseTempReg(pParse, regTemp);
9178591923
}else{
@@ -91811,19 +91949,19 @@
9181191949
assert( aiCol[i]!=pTab->iPKey );
9181291950
if( pIdx->aiColumn[i]==pTab->iPKey ){
9181391951
/* The parent key is a composite key that includes the IPK column */
9181491952
iParent = regData;
9181591953
}
91816
- sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent);
91954
+ sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
9181791955
sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
9181891956
}
9181991957
sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
9182091958
}
9182191959
91822
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec);
91823
- sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
91824
- sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0);
91960
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
91961
+ sqlite3IndexAffinityStr(v,pIdx), nCol);
91962
+ sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
9182591963
9182691964
sqlite3ReleaseTempReg(pParse, regRec);
9182791965
sqlite3ReleaseTempRange(pParse, regTemp, nCol);
9182891966
}
9182991967
}
@@ -91957,10 +92095,11 @@
9195792095
assert( pIdx!=0 || pFKey->nCol==1 );
9195892096
assert( pIdx!=0 || HasRowid(pTab) );
9195992097
9196092098
if( nIncr<0 ){
9196192099
iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
92100
+ VdbeCoverage(v);
9196292101
}
9196392102
9196492103
/* Create an Expr object representing an SQL expression like:
9196592104
**
9196692105
** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
@@ -92119,11 +92258,11 @@
9211992258
for(p=pTab->pFKey; p; p=p->pNextFrom){
9212092259
if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
9212192260
}
9212292261
if( !p ) return;
9212392262
iSkip = sqlite3VdbeMakeLabel(v);
92124
- sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip);
92263
+ sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
9212592264
}
9212692265
9212792266
pParse->disableTriggers = 1;
9212892267
sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
9212992268
pParse->disableTriggers = 0;
@@ -92137,10 +92276,11 @@
9213792276
** the statement transaction will not be rolled back even if FK
9213892277
** constraints are violated.
9213992278
*/
9214092279
if( (db->flags & SQLITE_DeferFKs)==0 ){
9214192280
sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
92281
+ VdbeCoverage(v);
9214292282
sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
9214392283
OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
9214492284
}
9214592285
9214692286
if( iSkip ){
@@ -92296,11 +92436,11 @@
9229692436
*/
9229792437
Vdbe *v = sqlite3GetVdbe(pParse);
9229892438
int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;
9229992439
for(i=0; i<pFKey->nCol; i++){
9230092440
int iReg = pFKey->aCol[i].iFrom + regOld + 1;
92301
- sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump);
92441
+ sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump); VdbeCoverage(v);
9230292442
}
9230392443
sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);
9230492444
}
9230592445
continue;
9230692446
}
@@ -92863,69 +93003,74 @@
9286393003
9286493004
return pIdx->zColAff;
9286593005
}
9286693006
9286793007
/*
92868
-** Set P4 of the most recently inserted opcode to a column affinity
92869
-** string for table pTab. A column affinity string has one character
92870
-** for each column indexed by the index, according to the affinity of the
92871
-** column:
93008
+** Compute the affinity string for table pTab, if it has not already been
93009
+** computed. As an optimization, omit trailing SQLITE_AFF_NONE affinities.
93010
+**
93011
+** If the affinity exists (if it is no entirely SQLITE_AFF_NONE values and
93012
+** if iReg>0 then code an OP_Affinity opcode that will set the affinities
93013
+** for register iReg and following. Or if affinities exists and iReg==0,
93014
+** then just set the P4 operand of the previous opcode (which should be
93015
+** an OP_MakeRecord) to the affinity string.
93016
+**
93017
+** A column affinity string has one character column:
9287293018
**
9287393019
** Character Column affinity
9287493020
** ------------------------------
9287593021
** 'a' TEXT
9287693022
** 'b' NONE
9287793023
** 'c' NUMERIC
9287893024
** 'd' INTEGER
9287993025
** 'e' REAL
9288093026
*/
92881
-SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
92882
- /* The first time a column affinity string for a particular table
92883
- ** is required, it is allocated and populated here. It is then
92884
- ** stored as a member of the Table structure for subsequent use.
92885
- **
92886
- ** The column affinity string will eventually be deleted by
92887
- ** sqlite3DeleteTable() when the Table structure itself is cleaned up.
92888
- */
92889
- if( !pTab->zColAff ){
92890
- char *zColAff;
92891
- int i;
93027
+SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
93028
+ int i;
93029
+ char *zColAff = pTab->zColAff;
93030
+ if( zColAff==0 ){
9289293031
sqlite3 *db = sqlite3VdbeDb(v);
92893
-
9289493032
zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
9289593033
if( !zColAff ){
9289693034
db->mallocFailed = 1;
9289793035
return;
9289893036
}
9289993037
9290093038
for(i=0; i<pTab->nCol; i++){
9290193039
zColAff[i] = pTab->aCol[i].affinity;
9290293040
}
92903
- zColAff[pTab->nCol] = '\0';
92904
-
93041
+ do{
93042
+ zColAff[i--] = 0;
93043
+ }while( i>=0 && zColAff[i]==SQLITE_AFF_NONE );
9290593044
pTab->zColAff = zColAff;
9290693045
}
92907
-
92908
- sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT);
93046
+ i = sqlite3Strlen30(zColAff);
93047
+ if( i ){
93048
+ if( iReg ){
93049
+ sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
93050
+ }else{
93051
+ sqlite3VdbeChangeP4(v, -1, zColAff, i);
93052
+ }
93053
+ }
9290993054
}
9291093055
9291193056
/*
9291293057
** Return non-zero if the table pTab in database iDb or any of its indices
9291393058
** have been opened at any point in the VDBE program beginning at location
9291493059
** iStartAddr throught the end of the program. This is used to see if
9291593060
** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
9291693061
** run without using temporary table for the results of the SELECT.
9291793062
*/
92918
-static int readsTable(Parse *p, int iStartAddr, int iDb, Table *pTab){
93063
+static int readsTable(Parse *p, int iDb, Table *pTab){
9291993064
Vdbe *v = sqlite3GetVdbe(p);
9292093065
int i;
9292193066
int iEnd = sqlite3VdbeCurrentAddr(v);
9292293067
#ifndef SQLITE_OMIT_VIRTUALTABLE
9292393068
VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
9292493069
#endif
9292593070
92926
- for(i=iStartAddr; i<iEnd; i++){
93071
+ for(i=1; i<iEnd; i++){
9292793072
VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
9292893073
assert( pOp!=0 );
9292993074
if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
9293093075
Index *pIndex;
9293193076
int tnum = pOp->p2;
@@ -93022,18 +93167,18 @@
9302293167
assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
9302393168
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
9302493169
sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
9302593170
addr = sqlite3VdbeCurrentAddr(v);
9302693171
sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
93027
- sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9);
93172
+ sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
9302893173
sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
93029
- sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId);
93174
+ sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
9303093175
sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
9303193176
sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
9303293177
sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
9303393178
sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
93034
- sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2);
93179
+ sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
9303593180
sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
9303693181
sqlite3VdbeAddOp0(v, OP_Close);
9303793182
}
9303893183
}
9303993184
@@ -93064,29 +93209,20 @@
9306493209
sqlite3 *db = pParse->db;
9306593210
9306693211
assert( v );
9306793212
for(p = pParse->pAinc; p; p = p->pNext){
9306893213
Db *pDb = &db->aDb[p->iDb];
93069
- int j1, j2, j3, j4, j5;
93214
+ int j1;
9307093215
int iRec;
9307193216
int memId = p->regCtr;
9307293217
9307393218
iRec = sqlite3GetTempReg(pParse);
9307493219
assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
9307593220
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
93076
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1);
93077
- j2 = sqlite3VdbeAddOp0(v, OP_Rewind);
93078
- j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
93079
- j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec);
93080
- sqlite3VdbeAddOp2(v, OP_Next, 0, j3);
93081
- sqlite3VdbeJumpHere(v, j2);
93221
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); VdbeCoverage(v);
9308293222
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1);
93083
- j5 = sqlite3VdbeAddOp0(v, OP_Goto);
93084
- sqlite3VdbeJumpHere(v, j4);
93085
- sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
9308693223
sqlite3VdbeJumpHere(v, j1);
93087
- sqlite3VdbeJumpHere(v, j5);
9308893224
sqlite3VdbeAddOp3(v, OP_MakeRecord, memId-1, 2, iRec);
9308993225
sqlite3VdbeAddOp3(v, OP_Insert, 0, iRec, memId+1);
9309093226
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
9309193227
sqlite3VdbeAddOp0(v, OP_Close);
9309293228
sqlite3ReleaseTempReg(pParse, iRec);
@@ -93098,101 +93234,10 @@
9309893234
** above are all no-ops
9309993235
*/
9310093236
# define autoIncBegin(A,B,C) (0)
9310193237
# define autoIncStep(A,B,C)
9310293238
#endif /* SQLITE_OMIT_AUTOINCREMENT */
93103
-
93104
-
93105
-/*
93106
-** Generate code for a co-routine that will evaluate a subquery one
93107
-** row at a time.
93108
-**
93109
-** The pSelect parameter is the subquery that the co-routine will evaluation.
93110
-** Information about the location of co-routine and the registers it will use
93111
-** is returned by filling in the pDest object.
93112
-**
93113
-** Registers are allocated as follows:
93114
-**
93115
-** pDest->iSDParm The register holding the next entry-point of the
93116
-** co-routine. Run the co-routine to its next breakpoint
93117
-** by calling "OP_Yield $X" where $X is pDest->iSDParm.
93118
-**
93119
-** pDest->iSDParm+1 The register holding the "completed" flag for the
93120
-** co-routine. This register is 0 if the previous Yield
93121
-** generated a new result row, or 1 if the subquery
93122
-** has completed. If the Yield is called again
93123
-** after this register becomes 1, then the VDBE will
93124
-** halt with an SQLITE_INTERNAL error.
93125
-**
93126
-** pDest->iSdst First result register.
93127
-**
93128
-** pDest->nSdst Number of result registers.
93129
-**
93130
-** This routine handles all of the register allocation and fills in the
93131
-** pDest structure appropriately.
93132
-**
93133
-** Here is a schematic of the generated code assuming that X is the
93134
-** co-routine entry-point register reg[pDest->iSDParm], that EOF is the
93135
-** completed flag reg[pDest->iSDParm+1], and R and S are the range of
93136
-** registers that hold the result set, reg[pDest->iSdst] through
93137
-** reg[pDest->iSdst+pDest->nSdst-1]:
93138
-**
93139
-** X <- A
93140
-** EOF <- 0
93141
-** goto B
93142
-** A: setup for the SELECT
93143
-** loop rows in the SELECT
93144
-** load results into registers R..S
93145
-** yield X
93146
-** end loop
93147
-** cleanup after the SELECT
93148
-** EOF <- 1
93149
-** yield X
93150
-** halt-error
93151
-** B:
93152
-**
93153
-** To use this subroutine, the caller generates code as follows:
93154
-**
93155
-** [ Co-routine generated by this subroutine, shown above ]
93156
-** S: yield X
93157
-** if EOF goto E
93158
-** if skip this row, goto C
93159
-** if terminate loop, goto E
93160
-** deal with this row
93161
-** C: goto S
93162
-** E:
93163
-*/
93164
-SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse *pParse, Select *pSelect, SelectDest *pDest){
93165
- int regYield; /* Register holding co-routine entry-point */
93166
- int regEof; /* Register holding co-routine completion flag */
93167
- int addrTop; /* Top of the co-routine */
93168
- int j1; /* Jump instruction */
93169
- int rc; /* Result code */
93170
- Vdbe *v; /* VDBE under construction */
93171
-
93172
- regYield = ++pParse->nMem;
93173
- regEof = ++pParse->nMem;
93174
- v = sqlite3GetVdbe(pParse);
93175
- addrTop = sqlite3VdbeCurrentAddr(v);
93176
- sqlite3VdbeAddOp2(v, OP_Integer, addrTop+2, regYield); /* X <- A */
93177
- VdbeComment((v, "Co-routine entry point"));
93178
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */
93179
- VdbeComment((v, "Co-routine completion flag"));
93180
- sqlite3SelectDestInit(pDest, SRT_Coroutine, regYield);
93181
- j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
93182
- rc = sqlite3Select(pParse, pSelect, pDest);
93183
- assert( pParse->nErr==0 || rc );
93184
- if( pParse->db->mallocFailed && rc==SQLITE_OK ) rc = SQLITE_NOMEM;
93185
- if( rc ) return rc;
93186
- sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
93187
- sqlite3VdbeAddOp1(v, OP_Yield, regYield); /* yield X */
93188
- sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort);
93189
- VdbeComment((v, "End of coroutine"));
93190
- sqlite3VdbeJumpHere(v, j1); /* label B: */
93191
- return rc;
93192
-}
93193
-
9319493239
9319593240
9319693241
/* Forward declaration */
9319793242
static int xferOptimization(
9319893243
Parse *pParse, /* Parser context */
@@ -93253,25 +93298,21 @@
9325393298
**
9325493299
** The 3rd template is for when the second template does not apply
9325593300
** and the SELECT clause does not read from <table> at any time.
9325693301
** The generated code follows this template:
9325793302
**
93258
-** EOF <- 0
9325993303
** X <- A
9326093304
** goto B
9326193305
** A: setup for the SELECT
9326293306
** loop over the rows in the SELECT
9326393307
** load values into registers R..R+n
9326493308
** yield X
9326593309
** end loop
9326693310
** cleanup after the SELECT
93267
-** EOF <- 1
93268
-** yield X
93269
-** goto A
93311
+** end-coroutine X
9327093312
** B: open write cursor to <table> and its indices
93271
-** C: yield X
93272
-** if EOF goto D
93313
+** C: yield X, at EOF goto D
9327393314
** insert the select result into <table> from R..R+n
9327493315
** goto C
9327593316
** D: cleanup
9327693317
**
9327793318
** The 4th template is used if the insert statement takes its
@@ -93278,25 +93319,21 @@
9327893319
** values from a SELECT but the data is being inserted into a table
9327993320
** that is also read as part of the SELECT. In the third form,
9328093321
** we have to use a intermediate table to store the results of
9328193322
** the select. The template is like this:
9328293323
**
93283
-** EOF <- 0
9328493324
** X <- A
9328593325
** goto B
9328693326
** A: setup for the SELECT
9328793327
** loop over the tables in the SELECT
9328893328
** load value into register R..R+n
9328993329
** yield X
9329093330
** end loop
9329193331
** cleanup after the SELECT
93292
-** EOF <- 1
93293
-** yield X
93294
-** halt-error
93332
+** end co-routine R
9329593333
** B: open temp table
93296
-** L: yield X
93297
-** if EOF goto M
93334
+** L: yield X, at EOF goto M
9329893335
** insert row from R..R+n into temp table
9329993336
** goto L
9330093337
** M: open write cursor to <table> and its indices
9330193338
** rewind temp table
9330293339
** C: loop over rows of intermediate table
@@ -93322,30 +93359,29 @@
9332293359
int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
9332393360
int iDataCur = 0; /* VDBE cursor that is the main data repository */
9332493361
int iIdxCur = 0; /* First index cursor */
9332593362
int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
9332693363
int endOfLoop; /* Label for the end of the insertion loop */
93327
- int useTempTable = 0; /* Store SELECT results in intermediate table */
9332893364
int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
9332993365
int addrInsTop = 0; /* Jump to label "D" */
9333093366
int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
93331
- int addrSelect = 0; /* Address of coroutine that implements the SELECT */
9333293367
SelectDest dest; /* Destination for SELECT on rhs of INSERT */
9333393368
int iDb; /* Index of database holding TABLE */
9333493369
Db *pDb; /* The database containing table being inserted into */
93335
- int appendFlag = 0; /* True if the insert is likely to be an append */
93336
- int withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
93370
+ u8 useTempTable = 0; /* Store SELECT results in intermediate table */
93371
+ u8 appendFlag = 0; /* True if the insert is likely to be an append */
93372
+ u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
93373
+ u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
9333793374
ExprList *pList = 0; /* List of VALUES() to be inserted */
9333893375
9333993376
/* Register allocations */
9334093377
int regFromSelect = 0;/* Base register for data coming from SELECT */
9334193378
int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
9334293379
int regRowCount = 0; /* Memory cell used for the row counter */
9334393380
int regIns; /* Block of regs holding rowid+data being inserted */
9334493381
int regRowid; /* registers holding insert rowid */
9334593382
int regData; /* register holding first column to insert */
93346
- int regEof = 0; /* Register recording end of SELECT data */
9334793383
int *aRegIdx = 0; /* One register allocated to each index */
9334893384
9334993385
#ifndef SQLITE_OMIT_TRIGGER
9335093386
int isView; /* True if attempting to insert into a view */
9335193387
Trigger *pTrigger; /* List of triggers on pTab, if required */
@@ -93443,26 +93479,86 @@
9344393479
9344493480
/* If this is an AUTOINCREMENT table, look up the sequence number in the
9344593481
** sqlite_sequence table and store it in memory cell regAutoinc.
9344693482
*/
9344793483
regAutoinc = autoIncBegin(pParse, iDb, pTab);
93484
+
93485
+ /* Allocate registers for holding the rowid of the new row,
93486
+ ** the content of the new row, and the assemblied row record.
93487
+ */
93488
+ regRowid = regIns = pParse->nMem+1;
93489
+ pParse->nMem += pTab->nCol + 1;
93490
+ if( IsVirtual(pTab) ){
93491
+ regRowid++;
93492
+ pParse->nMem++;
93493
+ }
93494
+ regData = regRowid+1;
93495
+
93496
+ /* If the INSERT statement included an IDLIST term, then make sure
93497
+ ** all elements of the IDLIST really are columns of the table and
93498
+ ** remember the column indices.
93499
+ **
93500
+ ** If the table has an INTEGER PRIMARY KEY column and that column
93501
+ ** is named in the IDLIST, then record in the ipkColumn variable
93502
+ ** the index into IDLIST of the primary key column. ipkColumn is
93503
+ ** the index of the primary key as it appears in IDLIST, not as
93504
+ ** is appears in the original table. (The index of the INTEGER
93505
+ ** PRIMARY KEY in the original table is pTab->iPKey.)
93506
+ */
93507
+ if( pColumn ){
93508
+ for(i=0; i<pColumn->nId; i++){
93509
+ pColumn->a[i].idx = -1;
93510
+ }
93511
+ for(i=0; i<pColumn->nId; i++){
93512
+ for(j=0; j<pTab->nCol; j++){
93513
+ if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93514
+ pColumn->a[i].idx = j;
93515
+ if( i!=j ) bIdListInOrder = 0;
93516
+ if( j==pTab->iPKey ){
93517
+ ipkColumn = i; assert( !withoutRowid );
93518
+ }
93519
+ break;
93520
+ }
93521
+ }
93522
+ if( j>=pTab->nCol ){
93523
+ if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93524
+ ipkColumn = i;
93525
+ }else{
93526
+ sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93527
+ pTabList, 0, pColumn->a[i].zName);
93528
+ pParse->checkSchema = 1;
93529
+ goto insert_cleanup;
93530
+ }
93531
+ }
93532
+ }
93533
+ }
9344893534
9344993535
/* Figure out how many columns of data are supplied. If the data
9345093536
** is coming from a SELECT statement, then generate a co-routine that
9345193537
** produces a single row of the SELECT on each invocation. The
9345293538
** co-routine is the common header to the 3rd and 4th templates.
9345393539
*/
9345493540
if( pSelect ){
9345593541
/* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
93456
- int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
93457
- if( rc ) goto insert_cleanup;
93542
+ int regYield; /* Register holding co-routine entry-point */
93543
+ int addrTop; /* Top of the co-routine */
93544
+ int rc; /* Result code */
9345893545
93459
- regEof = dest.iSDParm + 1;
93546
+ regYield = ++pParse->nMem;
93547
+ addrTop = sqlite3VdbeCurrentAddr(v) + 1;
93548
+ sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
93549
+ sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
93550
+ dest.iSdst = bIdListInOrder ? regData : 0;
93551
+ dest.nSdst = pTab->nCol;
93552
+ rc = sqlite3Select(pParse, pSelect, &dest);
9346093553
regFromSelect = dest.iSdst;
93554
+ assert( pParse->nErr==0 || rc );
93555
+ if( rc || db->mallocFailed ) goto insert_cleanup;
93556
+ sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
93557
+ sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
9346193558
assert( pSelect->pEList );
9346293559
nColumn = pSelect->pEList->nExpr;
93463
- assert( dest.nSdst==nColumn );
9346493560
9346593561
/* Set useTempTable to TRUE if the result of the SELECT statement
9346693562
** should be written into a temporary table (template 4). Set to
9346793563
** FALSE if each output row of the SELECT can be written directly into
9346893564
** the destination table (template 3).
@@ -93469,42 +93565,39 @@
9346993565
**
9347093566
** A temp table must be used if the table being updated is also one
9347193567
** of the tables being read by the SELECT statement. Also use a
9347293568
** temp table in the case of row triggers.
9347393569
*/
93474
- if( pTrigger || readsTable(pParse, addrSelect, iDb, pTab) ){
93570
+ if( pTrigger || readsTable(pParse, iDb, pTab) ){
9347593571
useTempTable = 1;
9347693572
}
9347793573
9347893574
if( useTempTable ){
9347993575
/* Invoke the coroutine to extract information from the SELECT
9348093576
** and add it to a transient table srcTab. The code generated
9348193577
** here is from the 4th template:
9348293578
**
9348393579
** B: open temp table
93484
- ** L: yield X
93485
- ** if EOF goto M
93580
+ ** L: yield X, goto M at EOF
9348693581
** insert row from R..R+n into temp table
9348793582
** goto L
9348893583
** M: ...
9348993584
*/
9349093585
int regRec; /* Register to hold packed record */
9349193586
int regTempRowid; /* Register to hold temp table ROWID */
93492
- int addrTop; /* Label "L" */
93493
- int addrIf; /* Address of jump to M */
93587
+ int addrL; /* Label "L" */
9349493588
9349593589
srcTab = pParse->nTab++;
9349693590
regRec = sqlite3GetTempReg(pParse);
9349793591
regTempRowid = sqlite3GetTempReg(pParse);
9349893592
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
93499
- addrTop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93500
- addrIf = sqlite3VdbeAddOp1(v, OP_If, regEof);
93593
+ addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
9350193594
sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
9350293595
sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
9350393596
sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
93504
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
93505
- sqlite3VdbeJumpHere(v, addrIf);
93597
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL);
93598
+ sqlite3VdbeJumpHere(v, addrL);
9350693599
sqlite3ReleaseTempReg(pParse, regRec);
9350793600
sqlite3ReleaseTempReg(pParse, regTempRowid);
9350893601
}
9350993602
}else{
9351093603
/* This is the case if the data for the INSERT is coming from a VALUES
@@ -93520,10 +93613,18 @@
9352093613
if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
9352193614
goto insert_cleanup;
9352293615
}
9352393616
}
9352493617
}
93618
+
93619
+ /* If there is no IDLIST term but the table has an integer primary
93620
+ ** key, the set the ipkColumn variable to the integer primary key
93621
+ ** column index in the original table definition.
93622
+ */
93623
+ if( pColumn==0 && nColumn>0 ){
93624
+ ipkColumn = pTab->iPKey;
93625
+ }
9352593626
9352693627
/* Make sure the number of columns in the source data matches the number
9352793628
** of columns to be inserted into the table.
9352893629
*/
9352993630
if( IsVirtual(pTab) ){
@@ -93539,56 +93640,10 @@
9353993640
}
9354093641
if( pColumn!=0 && nColumn!=pColumn->nId ){
9354193642
sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
9354293643
goto insert_cleanup;
9354393644
}
93544
-
93545
- /* If the INSERT statement included an IDLIST term, then make sure
93546
- ** all elements of the IDLIST really are columns of the table and
93547
- ** remember the column indices.
93548
- **
93549
- ** If the table has an INTEGER PRIMARY KEY column and that column
93550
- ** is named in the IDLIST, then record in the ipkColumn variable
93551
- ** the index into IDLIST of the primary key column. ipkColumn is
93552
- ** the index of the primary key as it appears in IDLIST, not as
93553
- ** is appears in the original table. (The index of the INTEGER
93554
- ** PRIMARY KEY in the original table is pTab->iPKey.)
93555
- */
93556
- if( pColumn ){
93557
- for(i=0; i<pColumn->nId; i++){
93558
- pColumn->a[i].idx = -1;
93559
- }
93560
- for(i=0; i<pColumn->nId; i++){
93561
- for(j=0; j<pTab->nCol; j++){
93562
- if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93563
- pColumn->a[i].idx = j;
93564
- if( j==pTab->iPKey ){
93565
- ipkColumn = i; assert( !withoutRowid );
93566
- }
93567
- break;
93568
- }
93569
- }
93570
- if( j>=pTab->nCol ){
93571
- if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93572
- ipkColumn = i;
93573
- }else{
93574
- sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93575
- pTabList, 0, pColumn->a[i].zName);
93576
- pParse->checkSchema = 1;
93577
- goto insert_cleanup;
93578
- }
93579
- }
93580
- }
93581
- }
93582
-
93583
- /* If there is no IDLIST term but the table has an integer primary
93584
- ** key, the set the ipkColumn variable to the integer primary key
93585
- ** column index in the original table definition.
93586
- */
93587
- if( pColumn==0 && nColumn>0 ){
93588
- ipkColumn = pTab->iPKey;
93589
- }
9359093645
9359193646
/* Initialize the count of rows to be inserted
9359293647
*/
9359393648
if( db->flags & SQLITE_CountRows ){
9359493649
regRowCount = ++pParse->nMem;
@@ -93612,42 +93667,30 @@
9361293667
/* This is the top of the main insertion loop */
9361393668
if( useTempTable ){
9361493669
/* This block codes the top of loop only. The complete loop is the
9361593670
** following pseudocode (template 4):
9361693671
**
93617
- ** rewind temp table
93672
+ ** rewind temp table, if empty goto D
9361893673
** C: loop over rows of intermediate table
9361993674
** transfer values form intermediate table into <table>
9362093675
** end loop
9362193676
** D: ...
9362293677
*/
93623
- addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab);
93678
+ addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); VdbeCoverage(v);
9362493679
addrCont = sqlite3VdbeCurrentAddr(v);
9362593680
}else if( pSelect ){
9362693681
/* This block codes the top of loop only. The complete loop is the
9362793682
** following pseudocode (template 3):
9362893683
**
93629
- ** C: yield X
93630
- ** if EOF goto D
93684
+ ** C: yield X, at EOF goto D
9363193685
** insert the select result into <table> from R..R+n
9363293686
** goto C
9363393687
** D: ...
9363493688
*/
93635
- addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93636
- addrInsTop = sqlite3VdbeAddOp1(v, OP_If, regEof);
93637
- }
93638
-
93639
- /* Allocate registers for holding the rowid of the new row,
93640
- ** the content of the new row, and the assemblied row record.
93641
- */
93642
- regRowid = regIns = pParse->nMem+1;
93643
- pParse->nMem += pTab->nCol + 1;
93644
- if( IsVirtual(pTab) ){
93645
- regRowid++;
93646
- pParse->nMem++;
93647
- }
93648
- regData = regRowid+1;
93689
+ addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93690
+ VdbeCoverage(v);
93691
+ }
9364993692
9365093693
/* Run the BEFORE and INSTEAD OF triggers, if there are any
9365193694
*/
9365293695
endOfLoop = sqlite3VdbeMakeLabel(v);
9365393696
if( tmask & TRIGGER_BEFORE ){
@@ -93668,14 +93711,14 @@
9366893711
sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
9366993712
}else{
9367093713
assert( pSelect==0 ); /* Otherwise useTempTable is true */
9367193714
sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
9367293715
}
93673
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
93716
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
9367493717
sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
9367593718
sqlite3VdbeJumpHere(v, j1);
93676
- sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols);
93719
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
9367793720
}
9367893721
9367993722
/* Cannot have triggers on a virtual table. If it were possible,
9368093723
** this block would have to account for hidden column.
9368193724
*/
@@ -93705,12 +93748,11 @@
9370593748
** do not attempt any conversions before assembling the record.
9370693749
** If this is a real table, attempt conversions as required by the
9370793750
** table column affinities.
9370893751
*/
9370993752
if( !isView ){
93710
- sqlite3VdbeAddOp2(v, OP_Affinity, regCols+1, pTab->nCol);
93711
- sqlite3TableAffinityStr(v, pTab);
93753
+ sqlite3TableAffinity(v, pTab, regCols+1);
9371293754
}
9371393755
9371493756
/* Fire BEFORE or INSTEAD OF triggers */
9371593757
sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
9371693758
pTab, regCols-pTab->nCol-1, onError, endOfLoop);
@@ -93728,11 +93770,11 @@
9372893770
}
9372993771
if( ipkColumn>=0 ){
9373093772
if( useTempTable ){
9373193773
sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
9373293774
}else if( pSelect ){
93733
- sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+ipkColumn, regRowid);
93775
+ sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid);
9373493776
}else{
9373593777
VdbeOp *pOp;
9373693778
sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
9373793779
pOp = sqlite3VdbeGetOp(v, -1);
9373893780
if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
@@ -93747,18 +93789,18 @@
9374793789
** to generate a unique primary key value.
9374893790
*/
9374993791
if( !appendFlag ){
9375093792
int j1;
9375193793
if( !IsVirtual(pTab) ){
93752
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid);
93794
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); VdbeCoverage(v);
9375393795
sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
9375493796
sqlite3VdbeJumpHere(v, j1);
9375593797
}else{
9375693798
j1 = sqlite3VdbeCurrentAddr(v);
93757
- sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2);
93799
+ sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2); VdbeCoverage(v);
9375893800
}
93759
- sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
93801
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
9376093802
}
9376193803
}else if( IsVirtual(pTab) || withoutRowid ){
9376293804
sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
9376393805
}else{
9376493806
sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -93774,12 +93816,13 @@
9377493816
int iRegStore = regRowid+1+i;
9377593817
if( i==pTab->iPKey ){
9377693818
/* The value of the INTEGER PRIMARY KEY column is always a NULL.
9377793819
** Whenever this column is read, the rowid will be substituted
9377893820
** in its place. Hence, fill this column with a NULL to avoid
93779
- ** taking up data space with information that will never be used. */
93780
- sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
93821
+ ** taking up data space with information that will never be used.
93822
+ ** As there may be shallow copies of this value, make it a soft-NULL */
93823
+ sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
9378193824
continue;
9378293825
}
9378393826
if( pColumn==0 ){
9378493827
if( IsHiddenColumn(&pTab->aCol[i]) ){
9378593828
assert( IsVirtual(pTab) );
@@ -93792,15 +93835,17 @@
9379293835
for(j=0; j<pColumn->nId; j++){
9379393836
if( pColumn->a[j].idx==i ) break;
9379493837
}
9379593838
}
9379693839
if( j<0 || nColumn==0 || (pColumn && j>=pColumn->nId) ){
93797
- sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, iRegStore);
93840
+ sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
9379893841
}else if( useTempTable ){
9379993842
sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, iRegStore);
9380093843
}else if( pSelect ){
93801
- sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore);
93844
+ if( regFromSelect!=regData ){
93845
+ sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore);
93846
+ }
9380293847
}else{
9380393848
sqlite3ExprCode(pParse, pList->a[j].pExpr, iRegStore);
9380493849
}
9380593850
}
9380693851
@@ -93842,11 +93887,11 @@
9384293887
/* The bottom of the main insertion loop, if the data source
9384393888
** is a SELECT statement.
9384493889
*/
9384593890
sqlite3VdbeResolveLabel(v, endOfLoop);
9384693891
if( useTempTable ){
93847
- sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont);
93892
+ sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
9384893893
sqlite3VdbeJumpHere(v, addrInsTop);
9384993894
sqlite3VdbeAddOp1(v, OP_Close, srcTab);
9385093895
}else if( pSelect ){
9385193896
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
9385293897
sqlite3VdbeJumpHere(v, addrInsTop);
@@ -94009,10 +94054,11 @@
9400994054
int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
9401094055
int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
9401194056
int ipkTop = 0; /* Top of the rowid change constraint check */
9401294057
int ipkBottom = 0; /* Bottom of the rowid change constraint check */
9401394058
u8 isUpdate; /* True if this is an UPDATE operation */
94059
+ u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
9401494060
int regRowid = -1; /* Register holding ROWID value */
9401594061
9401694062
isUpdate = regOldData!=0;
9401794063
db = pParse->db;
9401894064
v = sqlite3GetVdbe(pParse);
@@ -94063,19 +94109,21 @@
9406394109
char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
9406494110
pTab->aCol[i].zName);
9406594111
sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
9406694112
regNewData+1+i, zMsg, P4_DYNAMIC);
9406794113
sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
94114
+ VdbeCoverage(v);
9406894115
break;
9406994116
}
9407094117
case OE_Ignore: {
9407194118
sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
94119
+ VdbeCoverage(v);
9407294120
break;
9407394121
}
9407494122
default: {
9407594123
assert( onError==OE_Replace );
94076
- j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i);
94124
+ j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i); VdbeCoverage(v);
9407794125
sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
9407894126
sqlite3VdbeJumpHere(v, j1);
9407994127
break;
9408094128
}
9408194129
}
@@ -94123,10 +94171,12 @@
9412394171
if( isUpdate ){
9412494172
/* pkChng!=0 does not mean that the rowid has change, only that
9412594173
** it might have changed. Skip the conflict logic below if the rowid
9412694174
** is unchanged. */
9412794175
sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
94176
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94177
+ VdbeCoverage(v);
9412894178
}
9412994179
9413094180
/* If the response to a rowid conflict is REPLACE but the response
9413194181
** to some other UNIQUE constraint is FAIL or IGNORE, then we need
9413294182
** to defer the running of the rowid conflict checking until after
@@ -94142,10 +94192,11 @@
9414294192
}
9414394193
9414494194
/* Check to see if the new rowid already exists in the table. Skip
9414594195
** the following conflict logic if it does not. */
9414694196
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
94197
+ VdbeCoverage(v);
9414794198
9414894199
/* Generate code that deals with a rowid collision */
9414994200
switch( onError ){
9415094201
default: {
9415194202
onError = OE_Abort;
@@ -94220,10 +94271,14 @@
9422094271
int regR; /* Range of registers holding conflicting PK */
9422194272
int iThisCur; /* Cursor for this UNIQUE index */
9422294273
int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
9422394274
9422494275
if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
94276
+ if( bAffinityDone==0 ){
94277
+ sqlite3TableAffinity(v, pTab, regNewData+1);
94278
+ bAffinityDone = 1;
94279
+ }
9422594280
iThisCur = iIdxCur+ix;
9422694281
addrUniqueOk = sqlite3VdbeMakeLabel(v);
9422794282
9422894283
/* Skip partial indices for which the WHERE clause is not true */
9422994284
if( pIdx->pPartIdxWhere ){
@@ -94250,11 +94305,10 @@
9425094305
}
9425194306
sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
9425294307
VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
9425394308
}
9425494309
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
94255
- sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
9425694310
VdbeComment((v, "for %s", pIdx->zName));
9425794311
sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
9425894312
9425994313
/* In an UPDATE operation, if this index is the PRIMARY KEY index
9426094314
** of a WITHOUT ROWID table and there has been no change the
@@ -94278,11 +94332,11 @@
9427894332
onError = OE_Abort;
9427994333
}
9428094334
9428194335
/* Check to see if the new index entry will be unique */
9428294336
sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94283
- regIdx, pIdx->nKeyCol);
94337
+ regIdx, pIdx->nKeyCol); VdbeCoverage(v);
9428494338
9428594339
/* Generate code to handle collisions */
9428694340
regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
9428794341
if( isUpdate || onError==OE_Replace ){
9428894342
if( HasRowid(pTab) ){
@@ -94289,10 +94343,12 @@
9428994343
sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
9429094344
/* Conflict only if the rowid of the existing index entry
9429194345
** is different from old-rowid */
9429294346
if( isUpdate ){
9429394347
sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94348
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94349
+ VdbeCoverage(v);
9429494350
}
9429594351
}else{
9429694352
int x;
9429794353
/* Extract the PRIMARY KEY from the end of the index entry and
9429894354
** store it in registers regR..regR+nPk-1 */
@@ -94324,10 +94380,13 @@
9432494380
op = OP_Eq;
9432594381
}
9432694382
sqlite3VdbeAddOp4(v, op,
9432794383
regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
9432894384
);
94385
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94386
+ VdbeCoverageIf(v, op==OP_Eq);
94387
+ VdbeCoverageIf(v, op==OP_Ne);
9432994388
}
9433094389
}
9433194390
}
9433294391
}
9433394392
@@ -94395,18 +94454,21 @@
9439594454
Index *pIdx; /* An index being inserted or updated */
9439694455
u8 pik_flags; /* flag values passed to the btree insert */
9439794456
int regData; /* Content registers (after the rowid) */
9439894457
int regRec; /* Register holding assemblied record for the table */
9439994458
int i; /* Loop counter */
94459
+ u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
9440094460
9440194461
v = sqlite3GetVdbe(pParse);
9440294462
assert( v!=0 );
9440394463
assert( pTab->pSelect==0 ); /* This table is not a VIEW */
9440494464
for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
9440594465
if( aRegIdx[i]==0 ) continue;
94466
+ bAffinityDone = 1;
9440694467
if( pIdx->pPartIdxWhere ){
9440794468
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
94469
+ VdbeCoverage(v);
9440894470
}
9440994471
sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
9441094472
pik_flags = 0;
9441194473
if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
9441294474
if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
@@ -94417,11 +94479,11 @@
9441794479
}
9441894480
if( !HasRowid(pTab) ) return;
9441994481
regData = regNewData + 1;
9442094482
regRec = sqlite3GetTempReg(pParse);
9442194483
sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
94422
- sqlite3TableAffinityStr(v, pTab);
94484
+ if( !bAffinityDone ) sqlite3TableAffinity(v, pTab, 0);
9442394485
sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
9442494486
if( pParse->nested ){
9442594487
pik_flags = 0;
9442694488
}else{
9442794489
pik_flags = OPFLAG_NCHANGE;
@@ -94786,20 +94848,21 @@
9478694848
** (2) The destination has a unique index. (The xfer optimization
9478794849
** is unable to test uniqueness.)
9478894850
**
9478994851
** (3) onError is something other than OE_Abort and OE_Rollback.
9479094852
*/
94791
- addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
94853
+ addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
9479294854
emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
9479394855
sqlite3VdbeJumpHere(v, addr1);
9479494856
}
9479594857
if( HasRowid(pSrc) ){
9479694858
sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
94797
- emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94859
+ emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
9479894860
if( pDest->iPKey>=0 ){
9479994861
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
9480094862
addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
94863
+ VdbeCoverage(v);
9480194864
sqlite3RowidConstraint(pParse, onError, pDest);
9480294865
sqlite3VdbeJumpHere(v, addr2);
9480394866
autoIncStep(pParse, regAutoinc, regRowid);
9480494867
}else if( pDest->pIndex==0 ){
9480594868
addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
@@ -94809,11 +94872,11 @@
9480994872
}
9481094873
sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
9481194874
sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
9481294875
sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
9481394876
sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
94814
- sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
94877
+ sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
9481594878
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
9481694879
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
9481794880
}else{
9481894881
sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
9481994882
sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
@@ -94828,19 +94891,19 @@
9482894891
VdbeComment((v, "%s", pSrcIdx->zName));
9482994892
sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
9483094893
sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
9483194894
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
9483294895
VdbeComment((v, "%s", pDestIdx->zName));
94833
- addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94896
+ addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
9483494897
sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
9483594898
sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
94836
- sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1);
94899
+ sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
9483794900
sqlite3VdbeJumpHere(v, addr1);
9483894901
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
9483994902
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
9484094903
}
94841
- sqlite3VdbeJumpHere(v, emptySrcTest);
94904
+ if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest);
9484294905
sqlite3ReleaseTempReg(pParse, regRowid);
9484394906
sqlite3ReleaseTempReg(pParse, regData);
9484494907
if( emptyDestTest ){
9484594908
sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
9484694909
sqlite3VdbeJumpHere(v, emptyDestTest);
@@ -97070,10 +97133,11 @@
9707097133
** is always on by default regardless of the sign of the default cache
9707197134
** size. But continue to take the absolute value of the default cache
9707297135
** size of historical compatibility.
9707397136
*/
9707497137
case PragTyp_DEFAULT_CACHE_SIZE: {
97138
+ static const int iLn = __LINE__+2;
9707597139
static const VdbeOpList getCacheSize[] = {
9707697140
{ OP_Transaction, 0, 0, 0}, /* 0 */
9707797141
{ OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
9707897142
{ OP_IfPos, 1, 8, 0},
9707997143
{ OP_Integer, 0, 2, 0},
@@ -97087,11 +97151,11 @@
9708797151
sqlite3VdbeUsesBtree(v, iDb);
9708897152
if( !zRight ){
9708997153
sqlite3VdbeSetNumCols(v, 1);
9709097154
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
9709197155
pParse->nMem += 2;
97092
- addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
97156
+ addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
9709397157
sqlite3VdbeChangeP1(v, addr, iDb);
9709497158
sqlite3VdbeChangeP1(v, addr+1, iDb);
9709597159
sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
9709697160
}else{
9709797161
int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
@@ -97332,20 +97396,21 @@
9733297396
/* When setting the auto_vacuum mode to either "full" or
9733397397
** "incremental", write the value of meta[6] in the database
9733497398
** file. Before writing to meta[6], check that meta[3] indicates
9733597399
** that this really is an auto-vacuum capable database.
9733697400
*/
97401
+ static const int iLn = __LINE__+2;
9733797402
static const VdbeOpList setMeta6[] = {
9733897403
{ OP_Transaction, 0, 1, 0}, /* 0 */
9733997404
{ OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
9734097405
{ OP_If, 1, 0, 0}, /* 2 */
9734197406
{ OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
9734297407
{ OP_Integer, 0, 1, 0}, /* 4 */
9734397408
{ OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
9734497409
};
9734597410
int iAddr;
97346
- iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
97411
+ iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
9734797412
sqlite3VdbeChangeP1(v, iAddr, iDb);
9734897413
sqlite3VdbeChangeP1(v, iAddr+1, iDb);
9734997414
sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
9735097415
sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
9735197416
sqlite3VdbeChangeP1(v, iAddr+5, iDb);
@@ -97367,14 +97432,14 @@
9736797432
if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
9736897433
iLimit = 0x7fffffff;
9736997434
}
9737097435
sqlite3BeginWriteOperation(pParse, 0, iDb);
9737197436
sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
97372
- addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
97437
+ addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v);
9737397438
sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
9737497439
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
97375
- sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
97440
+ sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v);
9737697441
sqlite3VdbeJumpHere(v, addr);
9737797442
break;
9737897443
}
9737997444
#endif
9738097445
@@ -97941,11 +98006,11 @@
9794198006
}
9794298007
}
9794398008
assert( pParse->nErr>0 || pFK==0 );
9794498009
if( pFK ) break;
9794598010
if( pParse->nTab<i ) pParse->nTab = i;
97946
- addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0);
98011
+ addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
9794798012
for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
9794898013
pParent = sqlite3FindTable(db, pFK->zTo, zDb);
9794998014
pIdx = 0;
9795098015
aiCols = 0;
9795198016
if( pParent ){
@@ -97957,30 +98022,30 @@
9795798022
int iKey = pFK->aCol[0].iFrom;
9795898023
assert( iKey>=0 && iKey<pTab->nCol );
9795998024
if( iKey!=pTab->iPKey ){
9796098025
sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
9796198026
sqlite3ColumnDefault(v, pTab, iKey, regRow);
97962
- sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk);
97963
- sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
97964
- sqlite3VdbeCurrentAddr(v)+3);
98027
+ sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
98028
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
98029
+ sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
9796598030
}else{
9796698031
sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
9796798032
}
97968
- sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow);
98033
+ sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
9796998034
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
9797098035
sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
9797198036
}else{
9797298037
for(j=0; j<pFK->nCol; j++){
9797398038
sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
9797498039
aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
97975
- sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk);
98040
+ sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
9797698041
}
9797798042
if( pParent ){
97978
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regRow, pFK->nCol, regKey);
97979
- sqlite3VdbeChangeP4(v, -1,
97980
- sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
98043
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
98044
+ sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
9798198045
sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
98046
+ VdbeCoverage(v);
9798298047
}
9798398048
}
9798498049
sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
9798598050
sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
9798698051
pFK->zTo, P4_TRANSIENT);
@@ -97987,11 +98052,11 @@
9798798052
sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
9798898053
sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
9798998054
sqlite3VdbeResolveLabel(v, addrOk);
9799098055
sqlite3DbFree(db, aiCols);
9799198056
}
97992
- sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
98057
+ sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
9799398058
sqlite3VdbeJumpHere(v, addrTop);
9799498059
}
9799598060
}
9799698061
break;
9799798062
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
@@ -98034,10 +98099,11 @@
9803498099
9803598100
/* Code that appears at the end of the integrity check. If no error
9803698101
** messages have been generated, output OK. Otherwise output the
9803798102
** error message
9803898103
*/
98104
+ static const int iLn = __LINE__+2;
9803998105
static const VdbeOpList endCode[] = {
9804098106
{ OP_AddImm, 1, 0, 0}, /* 0 */
9804198107
{ OP_IfNeg, 1, 0, 0}, /* 1 */
9804298108
{ OP_String8, 0, 3, 0}, /* 2 */
9804398109
{ OP_ResultRow, 3, 1, 0},
@@ -98082,10 +98148,11 @@
9808298148
if( OMIT_TEMPDB && i==1 ) continue;
9808398149
if( iDb>=0 && i!=iDb ) continue;
9808498150
9808598151
sqlite3CodeVerifySchema(pParse, i);
9808698152
addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
98153
+ VdbeCoverage(v);
9808798154
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9808898155
sqlite3VdbeJumpHere(v, addr);
9808998156
9809098157
/* Do an integrity check of the B-Tree
9809198158
**
@@ -98113,11 +98180,11 @@
9811398180
pParse->nMem = MAX( pParse->nMem, cnt+8 );
9811498181
9811598182
/* Do the b-tree integrity checks */
9811698183
sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
9811798184
sqlite3VdbeChangeP5(v, (u8)i);
98118
- addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
98185
+ addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
9811998186
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
9812098187
sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
9812198188
P4_DYNAMIC);
9812298189
sqlite3VdbeAddOp2(v, OP_Move, 2, 4);
9812398190
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
@@ -98135,10 +98202,11 @@
9813598202
int r1 = -1;
9813698203
9813798204
if( pTab->pIndex==0 ) continue;
9813898205
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
9813998206
addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
98207
+ VdbeCoverage(v);
9814098208
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9814198209
sqlite3VdbeJumpHere(v, addr);
9814298210
sqlite3ExprCacheClear(pParse);
9814398211
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
9814498212
1, 0, &iDataCur, &iIdxCur);
@@ -98145,57 +98213,58 @@
9814598213
sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
9814698214
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
9814798215
sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
9814898216
}
9814998217
pParse->nMem = MAX(pParse->nMem, 8+j);
98150
- sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0);
98218
+ sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
9815198219
loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
9815298220
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
9815398221
int jmp2, jmp3, jmp4;
9815498222
if( pPk==pIdx ) continue;
9815598223
r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
9815698224
pPrior, r1);
9815798225
pPrior = pIdx;
9815898226
sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
9815998227
jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
98160
- pIdx->nColumn);
98228
+ pIdx->nColumn); VdbeCoverage(v);
9816198229
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
9816298230
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
9816398231
sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
9816498232
sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
9816598233
P4_STATIC);
9816698234
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
9816798235
sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
9816898236
sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
9816998237
sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
98170
- jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
98238
+ jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
9817198239
sqlite3VdbeAddOp0(v, OP_Halt);
9817298240
sqlite3VdbeJumpHere(v, jmp4);
9817398241
sqlite3VdbeJumpHere(v, jmp2);
9817498242
sqlite3VdbeResolveLabel(v, jmp3);
9817598243
}
98176
- sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop);
98244
+ sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
9817798245
sqlite3VdbeJumpHere(v, loopTop-1);
9817898246
#ifndef SQLITE_OMIT_BTREECOUNT
9817998247
sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
9818098248
"wrong # of entries in index ", P4_STATIC);
9818198249
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
9818298250
if( pPk==pIdx ) continue;
9818398251
addr = sqlite3VdbeCurrentAddr(v);
98184
- sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2);
98252
+ sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
9818598253
sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
9818698254
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
98187
- sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3);
98255
+ sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
98256
+ sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
9818898257
sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
9818998258
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
9819098259
sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
9819198260
sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
9819298261
}
9819398262
#endif /* SQLITE_OMIT_BTREECOUNT */
9819498263
}
9819598264
}
98196
- addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
98265
+ addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
9819798266
sqlite3VdbeChangeP2(v, addr, -mxErr);
9819898267
sqlite3VdbeJumpHere(v, addr+1);
9819998268
sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
9820098269
}
9820198270
break;
@@ -98329,11 +98398,11 @@
9832998398
static const VdbeOpList setCookie[] = {
9833098399
{ OP_Transaction, 0, 1, 0}, /* 0 */
9833198400
{ OP_Integer, 0, 1, 0}, /* 1 */
9833298401
{ OP_SetCookie, 0, 0, 1}, /* 2 */
9833398402
};
98334
- int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
98403
+ int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
9833598404
sqlite3VdbeChangeP1(v, addr, iDb);
9833698405
sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
9833798406
sqlite3VdbeChangeP1(v, addr+2, iDb);
9833898407
sqlite3VdbeChangeP2(v, addr+2, iCookie);
9833998408
}else{
@@ -98341,11 +98410,11 @@
9834198410
static const VdbeOpList readCookie[] = {
9834298411
{ OP_Transaction, 0, 0, 0}, /* 0 */
9834398412
{ OP_ReadCookie, 0, 1, 0}, /* 1 */
9834498413
{ OP_ResultRow, 1, 1, 0}
9834598414
};
98346
- int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
98415
+ int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0);
9834798416
sqlite3VdbeChangeP1(v, addr, iDb);
9834898417
sqlite3VdbeChangeP1(v, addr+1, iDb);
9834998418
sqlite3VdbeChangeP3(v, addr+1, iCookie);
9835098419
sqlite3VdbeSetNumCols(v, 1);
9835198420
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
@@ -99547,10 +99616,18 @@
9954799616
if( p ){
9954899617
clearSelect(db, p);
9954999618
sqlite3DbFree(db, p);
9955099619
}
9955199620
}
99621
+
99622
+/*
99623
+** Return a pointer to the right-most SELECT statement in a compound.
99624
+*/
99625
+static Select *findRightmost(Select *p){
99626
+ while( p->pNext ) p = p->pNext;
99627
+ return p;
99628
+}
9955299629
9955399630
/*
9955499631
** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
9955599632
** type of join. Return an integer constant that expresses that type
9955699633
** in terms of the following bit values:
@@ -99886,11 +99963,11 @@
9988699963
if( pSelect->iOffset ){
9988799964
iLimit = pSelect->iOffset+1;
9988899965
}else{
9988999966
iLimit = pSelect->iLimit;
9989099967
}
99891
- addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit);
99968
+ addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); VdbeCoverage(v);
9989299969
sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
9989399970
addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
9989499971
sqlite3VdbeJumpHere(v, addr1);
9989599972
sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor);
9989699973
sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor);
@@ -99907,11 +99984,11 @@
9990799984
int iContinue /* Jump here to skip the current record */
9990899985
){
9990999986
if( iOffset>0 && iContinue!=0 ){
9991099987
int addr;
9991199988
sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
99912
- addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset);
99989
+ addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset); VdbeCoverage(v);
9991399990
sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
9991499991
VdbeComment((v, "skip OFFSET records"));
9991599992
sqlite3VdbeJumpHere(v, addr);
9991699993
}
9991799994
}
@@ -99935,11 +100012,11 @@
99935100012
Vdbe *v;
99936100013
int r1;
99937100014
99938100015
v = pParse->pVdbe;
99939100016
r1 = sqlite3GetTempReg(pParse);
99940
- sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N);
100017
+ sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
99941100018
sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
99942100019
sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
99943100020
sqlite3ReleaseTempReg(pParse, r1);
99944100021
}
99945100022
@@ -100016,17 +100093,23 @@
100016100093
}
100017100094
100018100095
/* Pull the requested columns.
100019100096
*/
100020100097
nResultCol = pEList->nExpr;
100098
+
100021100099
if( pDest->iSdst==0 ){
100022100100
pDest->iSdst = pParse->nMem+1;
100023
- pDest->nSdst = nResultCol;
100101
+ pParse->nMem += nResultCol;
100102
+ }else if( pDest->iSdst+nResultCol > pParse->nMem ){
100103
+ /* This is an error condition that can result, for example, when a SELECT
100104
+ ** on the right-hand side of an INSERT contains more result columns than
100105
+ ** there are columns in the table on the left. The error will be caught
100106
+ ** and reported later. But we need to make sure enough memory is allocated
100107
+ ** to avoid other spurious errors in the meantime. */
100024100108
pParse->nMem += nResultCol;
100025
- }else{
100026
- assert( pDest->nSdst==nResultCol );
100027100109
}
100110
+ pDest->nSdst = nResultCol;
100028100111
regResult = pDest->iSdst;
100029100112
if( srcTab>=0 ){
100030100113
for(i=0; i<nResultCol; i++){
100031100114
sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
100032100115
VdbeComment((v, "%s", pEList->a[i].zName));
@@ -100069,13 +100152,15 @@
100069100152
iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
100070100153
for(i=0; i<nResultCol; i++){
100071100154
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100072100155
if( i<nResultCol-1 ){
100073100156
sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
100157
+ VdbeCoverage(v);
100074100158
}else{
100075100159
sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100076
- }
100160
+ VdbeCoverage(v);
100161
+ }
100077100162
sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100078100163
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100079100164
}
100080100165
assert( sqlite3VdbeCurrentAddr(v)==iJump );
100081100166
sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
@@ -100137,11 +100222,11 @@
100137100222
** on an ephemeral index. If the current row is already present
100138100223
** in the index, do not write it to the output. If not, add the
100139100224
** current row to the index and proceed with writing it to the
100140100225
** output table as well. */
100141100226
int addr = sqlite3VdbeCurrentAddr(v) + 4;
100142
- sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
100227
+ sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0); VdbeCoverage(v);
100143100228
sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
100144100229
assert( pOrderBy==0 );
100145100230
}
100146100231
#endif
100147100232
if( pOrderBy ){
@@ -100204,16 +100289,12 @@
100204100289
}
100205100290
break;
100206100291
}
100207100292
#endif /* #ifndef SQLITE_OMIT_SUBQUERY */
100208100293
100209
- /* Send the data to the callback function or to a subroutine. In the
100210
- ** case of a subroutine, the subroutine itself is responsible for
100211
- ** popping the data from the stack.
100212
- */
100213
- case SRT_Coroutine:
100214
- case SRT_Output: {
100294
+ case SRT_Coroutine: /* Send data to a co-routine */
100295
+ case SRT_Output: { /* Return the results */
100215100296
testcase( eDest==SRT_Coroutine );
100216100297
testcase( eDest==SRT_Output );
100217100298
if( pOrderBy ){
100218100299
int r1 = sqlite3GetTempReg(pParse);
100219100300
sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
@@ -100245,17 +100326,20 @@
100245100326
assert( pSO );
100246100327
nKey = pSO->nExpr;
100247100328
r1 = sqlite3GetTempReg(pParse);
100248100329
r2 = sqlite3GetTempRange(pParse, nKey+2);
100249100330
r3 = r2+nKey+1;
100250
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100251100331
if( eDest==SRT_DistQueue ){
100252100332
/* If the destination is DistQueue, then cursor (iParm+1) is open
100253100333
** on a second ephemeral index that holds all values every previously
100254
- ** added to the queue. Only add this new value if it has never before
100255
- ** been added */
100256
- addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0);
100334
+ ** added to the queue. */
100335
+ addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0,
100336
+ regResult, nResultCol);
100337
+ VdbeCoverage(v);
100338
+ }
100339
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100340
+ if( eDest==SRT_DistQueue ){
100257100341
sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
100258100342
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
100259100343
}
100260100344
for(i=0; i<nKey; i++){
100261100345
sqlite3VdbeAddOp2(v, OP_SCopy,
@@ -100290,11 +100374,11 @@
100290100374
/* Jump to the end of the loop if the LIMIT is reached. Except, if
100291100375
** there is a sorter, in which case the sorter has already limited
100292100376
** the output for us.
100293100377
*/
100294100378
if( pOrderBy==0 && p->iLimit ){
100295
- sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
100379
+ sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
100296100380
}
100297100381
}
100298100382
100299100383
/*
100300100384
** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -100509,16 +100593,17 @@
100509100593
if( p->selFlags & SF_UseSorter ){
100510100594
int regSortOut = ++pParse->nMem;
100511100595
int ptab2 = pParse->nTab++;
100512100596
sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100513100597
addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
100598
+ VdbeCoverage(v);
100514100599
codeOffset(v, p->iOffset, addrContinue);
100515100600
sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100516100601
sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100517100602
sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100518100603
}else{
100519
- addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
100604
+ addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
100520100605
codeOffset(v, p->iOffset, addrContinue);
100521100606
sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100522100607
}
100523100608
switch( eDest ){
100524100609
case SRT_Table:
@@ -100572,13 +100657,13 @@
100572100657
100573100658
/* The bottom of the loop
100574100659
*/
100575100660
sqlite3VdbeResolveLabel(v, addrContinue);
100576100661
if( p->selFlags & SF_UseSorter ){
100577
- sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr);
100662
+ sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
100578100663
}else{
100579
- sqlite3VdbeAddOp2(v, OP_Next, iTab, addr);
100664
+ sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
100580100665
}
100581100666
sqlite3VdbeResolveLabel(v, addrBreak);
100582100667
if( eDest==SRT_Output || eDest==SRT_Coroutine ){
100583100668
sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0);
100584100669
}
@@ -101058,15 +101143,17 @@
101058101143
*/
101059101144
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
101060101145
Vdbe *v = pParse->pVdbe;
101061101146
if( v==0 ){
101062101147
v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
101063
-#ifndef SQLITE_OMIT_TRACE
101064
- if( v ){
101065
- sqlite3VdbeAddOp0(v, OP_Trace);
101148
+ if( v ) sqlite3VdbeAddOp0(v, OP_Init);
101149
+ if( pParse->pToplevel==0
101150
+ && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
101151
+ ){
101152
+ pParse->okConstFactor = 1;
101066101153
}
101067
-#endif
101154
+
101068101155
}
101069101156
return v;
101070101157
}
101071101158
101072101159
@@ -101120,26 +101207,26 @@
101120101207
}else if( n>=0 && p->nSelectRow>(u64)n ){
101121101208
p->nSelectRow = n;
101122101209
}
101123101210
}else{
101124101211
sqlite3ExprCode(pParse, p->pLimit, iLimit);
101125
- sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit);
101212
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
101126101213
VdbeComment((v, "LIMIT counter"));
101127
- sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak);
101214
+ sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); VdbeCoverage(v);
101128101215
}
101129101216
if( p->pOffset ){
101130101217
p->iOffset = iOffset = ++pParse->nMem;
101131101218
pParse->nMem++; /* Allocate an extra register for limit+offset */
101132101219
sqlite3ExprCode(pParse, p->pOffset, iOffset);
101133
- sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset);
101220
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
101134101221
VdbeComment((v, "OFFSET counter"));
101135
- addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset);
101222
+ addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); VdbeCoverage(v);
101136101223
sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
101137101224
sqlite3VdbeJumpHere(v, addr1);
101138101225
sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
101139101226
VdbeComment((v, "LIMIT+OFFSET"));
101140
- addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit);
101227
+ addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); VdbeCoverage(v);
101141101228
sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
101142101229
sqlite3VdbeJumpHere(v, addr1);
101143101230
}
101144101231
}
101145101232
}
@@ -101318,15 +101405,17 @@
101318101405
101319101406
/* Detach the ORDER BY clause from the compound SELECT */
101320101407
p->pOrderBy = 0;
101321101408
101322101409
/* Store the results of the setup-query in Queue. */
101410
+ pSetup->pNext = 0;
101323101411
rc = sqlite3Select(pParse, pSetup, &destQueue);
101412
+ pSetup->pNext = p;
101324101413
if( rc ) goto end_of_recursive_query;
101325101414
101326101415
/* Find the next row in the Queue and output that row */
101327
- addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak);
101416
+ addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak); VdbeCoverage(v);
101328101417
101329101418
/* Transfer the next row in Queue over to Current */
101330101419
sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
101331101420
if( pOrderBy ){
101332101421
sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
@@ -101338,11 +101427,14 @@
101338101427
/* Output the single row in Current */
101339101428
addrCont = sqlite3VdbeMakeLabel(v);
101340101429
codeOffset(v, regOffset, addrCont);
101341101430
selectInnerLoop(pParse, p, p->pEList, iCurrent,
101342101431
0, 0, pDest, addrCont, addrBreak);
101343
- if( regLimit ) sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
101432
+ if( regLimit ){
101433
+ sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
101434
+ VdbeCoverage(v);
101435
+ }
101344101436
sqlite3VdbeResolveLabel(v, addrCont);
101345101437
101346101438
/* Execute the recursive SELECT taking the single row in Current as
101347101439
** the value for the recursive-table. Store the results in the Queue.
101348101440
*/
@@ -101423,12 +101515,10 @@
101423101515
*/
101424101516
assert( p && p->pPrior ); /* Calling function guarantees this much */
101425101517
assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
101426101518
db = pParse->db;
101427101519
pPrior = p->pPrior;
101428
- assert( pPrior->pRightmost!=pPrior );
101429
- assert( pPrior->pRightmost==p->pRightmost );
101430101520
dest = *pDest;
101431101521
if( pPrior->pOrderBy ){
101432101522
sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
101433101523
selectOpName(p->op));
101434101524
rc = 1;
@@ -101500,11 +101590,11 @@
101500101590
}
101501101591
p->pPrior = 0;
101502101592
p->iLimit = pPrior->iLimit;
101503101593
p->iOffset = pPrior->iOffset;
101504101594
if( p->iLimit ){
101505
- addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit);
101595
+ addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); VdbeCoverage(v);
101506101596
VdbeComment((v, "Jump ahead if LIMIT reached"));
101507101597
}
101508101598
explainSetInteger(iSub2, pParse->iNextSelectId);
101509101599
rc = sqlite3Select(pParse, p, &dest);
101510101600
testcase( rc!=SQLITE_OK );
@@ -101532,16 +101622,14 @@
101532101622
SelectDest uniondest;
101533101623
101534101624
testcase( p->op==TK_EXCEPT );
101535101625
testcase( p->op==TK_UNION );
101536101626
priorOp = SRT_Union;
101537
- if( dest.eDest==priorOp && ALWAYS(!p->pLimit &&!p->pOffset) ){
101627
+ if( dest.eDest==priorOp ){
101538101628
/* We can reuse a temporary table generated by a SELECT to our
101539101629
** right.
101540101630
*/
101541
- assert( p->pRightmost!=p ); /* Can only happen for leftward elements
101542
- ** of a 3-way or more compound */
101543101631
assert( p->pLimit==0 ); /* Not allowed on leftward elements */
101544101632
assert( p->pOffset==0 ); /* Not allowed on leftward elements */
101545101633
unionTab = dest.iSDParm;
101546101634
}else{
101547101635
/* We will need to create our own temporary table to hold the
@@ -101550,11 +101638,11 @@
101550101638
unionTab = pParse->nTab++;
101551101639
assert( p->pOrderBy==0 );
101552101640
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
101553101641
assert( p->addrOpenEphm[0] == -1 );
101554101642
p->addrOpenEphm[0] = addr;
101555
- p->pRightmost->selFlags |= SF_UsesEphemeral;
101643
+ findRightmost(p)->selFlags |= SF_UsesEphemeral;
101556101644
assert( p->pEList );
101557101645
}
101558101646
101559101647
/* Code the SELECT statements to our left
101560101648
*/
@@ -101609,16 +101697,16 @@
101609101697
generateColumnNames(pParse, 0, pFirst->pEList);
101610101698
}
101611101699
iBreak = sqlite3VdbeMakeLabel(v);
101612101700
iCont = sqlite3VdbeMakeLabel(v);
101613101701
computeLimitRegisters(pParse, p, iBreak);
101614
- sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak);
101702
+ sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
101615101703
iStart = sqlite3VdbeCurrentAddr(v);
101616101704
selectInnerLoop(pParse, p, p->pEList, unionTab,
101617101705
0, 0, &dest, iCont, iBreak);
101618101706
sqlite3VdbeResolveLabel(v, iCont);
101619
- sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart);
101707
+ sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
101620101708
sqlite3VdbeResolveLabel(v, iBreak);
101621101709
sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
101622101710
}
101623101711
break;
101624101712
}
@@ -101639,11 +101727,11 @@
101639101727
assert( p->pOrderBy==0 );
101640101728
101641101729
addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
101642101730
assert( p->addrOpenEphm[0] == -1 );
101643101731
p->addrOpenEphm[0] = addr;
101644
- p->pRightmost->selFlags |= SF_UsesEphemeral;
101732
+ findRightmost(p)->selFlags |= SF_UsesEphemeral;
101645101733
assert( p->pEList );
101646101734
101647101735
/* Code the SELECTs to our left into temporary table "tab1".
101648101736
*/
101649101737
sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1);
@@ -101684,19 +101772,19 @@
101684101772
generateColumnNames(pParse, 0, pFirst->pEList);
101685101773
}
101686101774
iBreak = sqlite3VdbeMakeLabel(v);
101687101775
iCont = sqlite3VdbeMakeLabel(v);
101688101776
computeLimitRegisters(pParse, p, iBreak);
101689
- sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak);
101777
+ sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
101690101778
r1 = sqlite3GetTempReg(pParse);
101691101779
iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101692
- sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
101780
+ sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
101693101781
sqlite3ReleaseTempReg(pParse, r1);
101694101782
selectInnerLoop(pParse, p, p->pEList, tab1,
101695101783
0, 0, &dest, iCont, iBreak);
101696101784
sqlite3VdbeResolveLabel(v, iCont);
101697
- sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart);
101785
+ sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
101698101786
sqlite3VdbeResolveLabel(v, iBreak);
101699101787
sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
101700101788
sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
101701101789
break;
101702101790
}
@@ -101718,11 +101806,11 @@
101718101806
KeyInfo *pKeyInfo; /* Collating sequence for the result set */
101719101807
Select *pLoop; /* For looping through SELECT statements */
101720101808
CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
101721101809
int nCol; /* Number of columns in result set */
101722101810
101723
- assert( p->pRightmost==p );
101811
+ assert( p->pNext==0 );
101724101812
nCol = p->pEList->nExpr;
101725101813
pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
101726101814
if( !pKeyInfo ){
101727101815
rc = SQLITE_NOMEM;
101728101816
goto multi_select_end;
@@ -101799,14 +101887,14 @@
101799101887
101800101888
/* Suppress duplicates for UNION, EXCEPT, and INTERSECT
101801101889
*/
101802101890
if( regPrev ){
101803101891
int j1, j2;
101804
- j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
101892
+ j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
101805101893
j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
101806101894
(char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
101807
- sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
101895
+ sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2); VdbeCoverage(v);
101808101896
sqlite3VdbeJumpHere(v, j1);
101809101897
sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
101810101898
sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
101811101899
}
101812101900
if( pParse->db->mallocFailed ) return 0;
@@ -101903,11 +101991,11 @@
101903101991
}
101904101992
101905101993
/* Jump to the end of the loop if the LIMIT is reached.
101906101994
*/
101907101995
if( p->iLimit ){
101908
- sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
101996
+ sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
101909101997
}
101910101998
101911101999
/* Generate the subroutine return
101912102000
*/
101913102001
sqlite3VdbeResolveLabel(v, iContinue);
@@ -102011,20 +102099,19 @@
102011102099
Select *pPrior; /* Another SELECT immediately to our left */
102012102100
Vdbe *v; /* Generate code to this VDBE */
102013102101
SelectDest destA; /* Destination for coroutine A */
102014102102
SelectDest destB; /* Destination for coroutine B */
102015102103
int regAddrA; /* Address register for select-A coroutine */
102016
- int regEofA; /* Flag to indicate when select-A is complete */
102017102104
int regAddrB; /* Address register for select-B coroutine */
102018
- int regEofB; /* Flag to indicate when select-B is complete */
102019102105
int addrSelectA; /* Address of the select-A coroutine */
102020102106
int addrSelectB; /* Address of the select-B coroutine */
102021102107
int regOutA; /* Address register for the output-A subroutine */
102022102108
int regOutB; /* Address register for the output-B subroutine */
102023102109
int addrOutA; /* Address of the output-A subroutine */
102024102110
int addrOutB = 0; /* Address of the output-B subroutine */
102025102111
int addrEofA; /* Address of the select-A-exhausted subroutine */
102112
+ int addrEofA_noB; /* Alternate addrEofA if B is uninitialized */
102026102113
int addrEofB; /* Address of the select-B-exhausted subroutine */
102027102114
int addrAltB; /* Address of the A<B subroutine */
102028102115
int addrAeqB; /* Address of the A==B subroutine */
102029102116
int addrAgtB; /* Address of the A>B subroutine */
102030102117
int regLimitA; /* Limit register for select-A */
@@ -102135,10 +102222,11 @@
102135102222
}
102136102223
102137102224
/* Separate the left and the right query from one another
102138102225
*/
102139102226
p->pPrior = 0;
102227
+ pPrior->pNext = 0;
102140102228
sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
102141102229
if( pPrior->pPrior==0 ){
102142102230
sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
102143102231
}
102144102232
@@ -102157,52 +102245,43 @@
102157102245
p->pLimit = 0;
102158102246
sqlite3ExprDelete(db, p->pOffset);
102159102247
p->pOffset = 0;
102160102248
102161102249
regAddrA = ++pParse->nMem;
102162
- regEofA = ++pParse->nMem;
102163102250
regAddrB = ++pParse->nMem;
102164
- regEofB = ++pParse->nMem;
102165102251
regOutA = ++pParse->nMem;
102166102252
regOutB = ++pParse->nMem;
102167102253
sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
102168102254
sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
102169
-
102170
- /* Jump past the various subroutines and coroutines to the main
102171
- ** merge loop
102172
- */
102173
- j1 = sqlite3VdbeAddOp0(v, OP_Goto);
102174
- addrSelectA = sqlite3VdbeCurrentAddr(v);
102175
-
102176102255
102177102256
/* Generate a coroutine to evaluate the SELECT statement to the
102178102257
** left of the compound operator - the "A" select.
102179102258
*/
102180
- VdbeNoopComment((v, "Begin coroutine for left SELECT"));
102259
+ addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
102260
+ j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
102261
+ VdbeComment((v, "left SELECT"));
102181102262
pPrior->iLimit = regLimitA;
102182102263
explainSetInteger(iSub1, pParse->iNextSelectId);
102183102264
sqlite3Select(pParse, pPrior, &destA);
102184
- sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofA);
102185
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102186
- VdbeNoopComment((v, "End coroutine for left SELECT"));
102265
+ sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrA);
102266
+ sqlite3VdbeJumpHere(v, j1);
102187102267
102188102268
/* Generate a coroutine to evaluate the SELECT statement on
102189102269
** the right - the "B" select
102190102270
*/
102191
- addrSelectB = sqlite3VdbeCurrentAddr(v);
102192
- VdbeNoopComment((v, "Begin coroutine for right SELECT"));
102271
+ addrSelectB = sqlite3VdbeCurrentAddr(v) + 1;
102272
+ j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
102273
+ VdbeComment((v, "right SELECT"));
102193102274
savedLimit = p->iLimit;
102194102275
savedOffset = p->iOffset;
102195102276
p->iLimit = regLimitB;
102196102277
p->iOffset = 0;
102197102278
explainSetInteger(iSub2, pParse->iNextSelectId);
102198102279
sqlite3Select(pParse, p, &destB);
102199102280
p->iLimit = savedLimit;
102200102281
p->iOffset = savedOffset;
102201
- sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofB);
102202
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102203
- VdbeNoopComment((v, "End coroutine for right SELECT"));
102282
+ sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrB);
102204102283
102205102284
/* Generate a subroutine that outputs the current row of the A
102206102285
** select as the next output row of the compound select.
102207102286
*/
102208102287
VdbeNoopComment((v, "Output routine for A"));
@@ -102222,17 +102301,17 @@
102222102301
sqlite3KeyInfoUnref(pKeyDup);
102223102302
102224102303
/* Generate a subroutine to run when the results from select A
102225102304
** are exhausted and only data in select B remains.
102226102305
*/
102227
- VdbeNoopComment((v, "eof-A subroutine"));
102228102306
if( op==TK_EXCEPT || op==TK_INTERSECT ){
102229
- addrEofA = sqlite3VdbeAddOp2(v, OP_Goto, 0, labelEnd);
102307
+ addrEofA_noB = addrEofA = labelEnd;
102230102308
}else{
102231
- addrEofA = sqlite3VdbeAddOp2(v, OP_If, regEofB, labelEnd);
102232
- sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102233
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102309
+ VdbeNoopComment((v, "eof-A subroutine"));
102310
+ addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102311
+ addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
102312
+ VdbeCoverage(v);
102234102313
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
102235102314
p->nSelectRow += pPrior->nSelectRow;
102236102315
}
102237102316
102238102317
/* Generate a subroutine to run when the results from select B
@@ -102241,22 +102320,20 @@
102241102320
if( op==TK_INTERSECT ){
102242102321
addrEofB = addrEofA;
102243102322
if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
102244102323
}else{
102245102324
VdbeNoopComment((v, "eof-B subroutine"));
102246
- addrEofB = sqlite3VdbeAddOp2(v, OP_If, regEofA, labelEnd);
102247
- sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102248
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102325
+ addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102326
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
102249102327
sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
102250102328
}
102251102329
102252102330
/* Generate code to handle the case of A<B
102253102331
*/
102254102332
VdbeNoopComment((v, "A-lt-B subroutine"));
102255102333
addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102256
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102257
- sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102334
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
102258102335
sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102259102336
102260102337
/* Generate code to handle the case of A==B
102261102338
*/
102262102339
if( op==TK_ALL ){
@@ -102265,12 +102342,11 @@
102265102342
addrAeqB = addrAltB;
102266102343
addrAltB++;
102267102344
}else{
102268102345
VdbeNoopComment((v, "A-eq-B subroutine"));
102269102346
addrAeqB =
102270
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102271
- sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102347
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
102272102348
sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102273102349
}
102274102350
102275102351
/* Generate code to handle the case of A>B
102276102352
*/
@@ -102277,32 +102353,27 @@
102277102353
VdbeNoopComment((v, "A-gt-B subroutine"));
102278102354
addrAgtB = sqlite3VdbeCurrentAddr(v);
102279102355
if( op==TK_ALL || op==TK_UNION ){
102280102356
sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102281102357
}
102282
- sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102283
- sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB);
102358
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
102284102359
sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102285102360
102286102361
/* This code runs once to initialize everything.
102287102362
*/
102288102363
sqlite3VdbeJumpHere(v, j1);
102289
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofA);
102290
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofB);
102291
- sqlite3VdbeAddOp2(v, OP_Gosub, regAddrA, addrSelectA);
102292
- sqlite3VdbeAddOp2(v, OP_Gosub, regAddrB, addrSelectB);
102293
- sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102294
- sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB);
102364
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
102365
+ sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
102295102366
102296102367
/* Implement the main merge loop
102297102368
*/
102298102369
sqlite3VdbeResolveLabel(v, labelCmpr);
102299102370
sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
102300102371
sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
102301102372
(char*)pKeyMerge, P4_KEYINFO);
102302102373
sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
102303
- sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
102374
+ sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v);
102304102375
102305102376
/* Jump to the this point in order to terminate the query.
102306102377
*/
102307102378
sqlite3VdbeResolveLabel(v, labelEnd);
102308102379
@@ -102318,10 +102389,11 @@
102318102389
** by the calling function */
102319102390
if( p->pPrior ){
102320102391
sqlite3SelectDelete(db, p->pPrior);
102321102392
}
102322102393
p->pPrior = pPrior;
102394
+ pPrior->pNext = p;
102323102395
102324102396
/*** TBD: Insert subroutine calls to close cursors on incomplete
102325102397
**** subqueries ****/
102326102398
explainComposite(pParse, p->op, iSub1, iSub2, 0);
102327102399
return SQLITE_OK;
@@ -102583,11 +102655,11 @@
102583102655
** because they could be computed at compile-time. But when LIMIT and OFFSET
102584102656
** became arbitrary expressions, we were forced to add restrictions (13)
102585102657
** and (14). */
102586102658
if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
102587102659
if( pSub->pOffset ) return 0; /* Restriction (14) */
102588
- if( p->pRightmost && pSub->pLimit ){
102660
+ if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
102589102661
return 0; /* Restriction (15) */
102590102662
}
102591102663
if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
102592102664
if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (5) */
102593102665
if( pSub->pLimit && (pSrc->nSrc>1 || isAgg) ){
@@ -102734,18 +102806,18 @@
102734102806
p->pOffset = pOffset;
102735102807
p->pLimit = pLimit;
102736102808
p->pOrderBy = pOrderBy;
102737102809
p->pSrc = pSrc;
102738102810
p->op = TK_ALL;
102739
- p->pRightmost = 0;
102740102811
if( pNew==0 ){
102741
- pNew = pPrior;
102812
+ p->pPrior = pPrior;
102742102813
}else{
102743102814
pNew->pPrior = pPrior;
102744
- pNew->pRightmost = 0;
102815
+ if( pPrior ) pPrior->pNext = pNew;
102816
+ pNew->pNext = p;
102817
+ p->pPrior = pNew;
102745102818
}
102746
- p->pPrior = pNew;
102747102819
if( db->mallocFailed ) return 1;
102748102820
}
102749102821
102750102822
/* Begin flattening the iFrom-th entry of the FROM clause
102751102823
** in the outer query.
@@ -103080,10 +103152,14 @@
103080103152
p->pWhere = 0;
103081103153
pNew->pGroupBy = 0;
103082103154
pNew->pHaving = 0;
103083103155
pNew->pOrderBy = 0;
103084103156
p->pPrior = 0;
103157
+ p->pNext = 0;
103158
+ p->selFlags &= ~SF_Compound;
103159
+ assert( pNew->pPrior!=0 );
103160
+ pNew->pPrior->pNext = pNew;
103085103161
pNew->pLimit = 0;
103086103162
pNew->pOffset = 0;
103087103163
return WRC_Continue;
103088103164
}
103089103165
@@ -103267,13 +103343,14 @@
103267103343
** sqlite3SelectExpand() when walking a SELECT tree to resolve table
103268103344
** names and other FROM clause elements.
103269103345
*/
103270103346
static void selectPopWith(Walker *pWalker, Select *p){
103271103347
Parse *pParse = pWalker->pParse;
103272
- if( p->pWith ){
103273
- assert( pParse->pWith==p->pWith );
103274
- pParse->pWith = p->pWith->pOuter;
103348
+ With *pWith = findRightmost(p)->pWith;
103349
+ if( pWith!=0 ){
103350
+ assert( pParse->pWith==pWith );
103351
+ pParse->pWith = pWith->pOuter;
103275103352
}
103276103353
}
103277103354
#else
103278103355
#define selectPopWith 0
103279103356
#endif
@@ -103319,11 +103396,11 @@
103319103396
if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
103320103397
return WRC_Prune;
103321103398
}
103322103399
pTabList = p->pSrc;
103323103400
pEList = p->pEList;
103324
- sqlite3WithPush(pParse, p->pWith, 0);
103401
+ sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
103325103402
103326103403
/* Make sure cursor numbers have been assigned to all entries in
103327103404
** the FROM clause of the SELECT statement.
103328103405
*/
103329103406
sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -103832,11 +103909,11 @@
103832103909
**
103833103910
** Another solution would be to change the OP_SCopy used to copy cached
103834103911
** values to an OP_Copy.
103835103912
*/
103836103913
if( regHit ){
103837
- addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit);
103914
+ addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
103838103915
}
103839103916
sqlite3ExprCacheClear(pParse);
103840103917
for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
103841103918
sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
103842103919
}
@@ -103991,46 +104068,28 @@
103991104068
if( isAggSub ){
103992104069
isAgg = 1;
103993104070
p->selFlags |= SF_Aggregate;
103994104071
}
103995104072
i = -1;
103996
- }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0
103997
- && OptimizationEnabled(db, SQLITE_SubqCoroutine)
104073
+ }else if( pTabList->nSrc==1
104074
+ && OptimizationEnabled(db, SQLITE_SubqCoroutine)
103998104075
){
103999104076
/* Implement a co-routine that will return a single row of the result
104000104077
** set on each invocation.
104001104078
*/
104002
- int addrTop;
104003
- int addrEof;
104079
+ int addrTop = sqlite3VdbeCurrentAddr(v)+1;
104004104080
pItem->regReturn = ++pParse->nMem;
104005
- addrEof = ++pParse->nMem;
104006
- /* Before coding the OP_Goto to jump to the start of the main routine,
104007
- ** ensure that the jump to the verify-schema routine has already
104008
- ** been coded. Otherwise, the verify-schema would likely be coded as
104009
- ** part of the co-routine. If the main routine then accessed the
104010
- ** database before invoking the co-routine for the first time (for
104011
- ** example to initialize a LIMIT register from a sub-select), it would
104012
- ** be doing so without having verified the schema version and obtained
104013
- ** the required db locks. See ticket d6b36be38. */
104014
- sqlite3CodeVerifySchema(pParse, -1);
104015
- sqlite3VdbeAddOp0(v, OP_Goto);
104016
- addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor);
104017
- sqlite3VdbeChangeP5(v, 1);
104018
- VdbeComment((v, "coroutine for %s", pItem->pTab->zName));
104081
+ sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
104082
+ VdbeComment((v, "%s", pItem->pTab->zName));
104019104083
pItem->addrFillSub = addrTop;
104020
- sqlite3VdbeAddOp2(v, OP_Integer, 0, addrEof);
104021
- sqlite3VdbeChangeP5(v, 1);
104022104084
sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
104023104085
explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104024104086
sqlite3Select(pParse, pSub, &dest);
104025104087
pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
104026104088
pItem->viaCoroutine = 1;
104027
- sqlite3VdbeChangeP2(v, addrTop, dest.iSdst);
104028
- sqlite3VdbeChangeP3(v, addrTop, dest.nSdst);
104029
- sqlite3VdbeAddOp2(v, OP_Integer, 1, addrEof);
104030
- sqlite3VdbeAddOp1(v, OP_Yield, pItem->regReturn);
104031
- VdbeComment((v, "end %s", pItem->pTab->zName));
104089
+ pItem->regResult = dest.iSdst;
104090
+ sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
104032104091
sqlite3VdbeJumpHere(v, addrTop-1);
104033104092
sqlite3ClearTempRegCache(pParse);
104034104093
}else{
104035104094
/* Generate a subroutine that will fill an ephemeral table with
104036104095
** the content of this subquery. pItem->addrFillSub will point
@@ -104042,16 +104101,18 @@
104042104101
int retAddr;
104043104102
assert( pItem->addrFillSub==0 );
104044104103
pItem->regReturn = ++pParse->nMem;
104045104104
topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
104046104105
pItem->addrFillSub = topAddr+1;
104047
- VdbeNoopComment((v, "materialize %s", pItem->pTab->zName));
104048104106
if( pItem->isCorrelated==0 ){
104049104107
/* If the subquery is not correlated and if we are not inside of
104050104108
** a trigger, then we only need to compute the value of the subquery
104051104109
** once. */
104052
- onceAddr = sqlite3CodeOnce(pParse);
104110
+ onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
104111
+ VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
104112
+ }else{
104113
+ VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
104053104114
}
104054104115
sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
104055104116
explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104056104117
sqlite3Select(pParse, pSub, &dest);
104057104118
pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
@@ -104079,25 +104140,10 @@
104079104140
104080104141
#ifndef SQLITE_OMIT_COMPOUND_SELECT
104081104142
/* If there is are a sequence of queries, do the earlier ones first.
104082104143
*/
104083104144
if( p->pPrior ){
104084
- if( p->pRightmost==0 ){
104085
- Select *pLoop, *pRight = 0;
104086
- int cnt = 0;
104087
- int mxSelect;
104088
- for(pLoop=p; pLoop; pLoop=pLoop->pPrior, cnt++){
104089
- pLoop->pRightmost = p;
104090
- pLoop->pNext = pRight;
104091
- pRight = pLoop;
104092
- }
104093
- mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
104094
- if( mxSelect && cnt>mxSelect ){
104095
- sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
104096
- goto select_end;
104097
- }
104098
- }
104099104145
rc = multiSelect(pParse, p, pDest);
104100104146
explainSetInteger(pParse->iSelectId, iRestoreSelectId);
104101104147
return rc;
104102104148
}
104103104149
#endif
@@ -104397,11 +104443,11 @@
104397104443
sqlite3WhereEnd(pWInfo);
104398104444
sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
104399104445
sortOut = sqlite3GetTempReg(pParse);
104400104446
sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
104401104447
sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
104402
- VdbeComment((v, "GROUP BY sort"));
104448
+ VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
104403104449
sAggInfo.useSortingIdx = 1;
104404104450
sqlite3ExprCacheClear(pParse);
104405104451
}
104406104452
104407104453
/* Evaluate the current GROUP BY terms and store in b0, b1, b2...
@@ -104424,11 +104470,11 @@
104424104470
}
104425104471
}
104426104472
sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
104427104473
(char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
104428104474
j1 = sqlite3VdbeCurrentAddr(v);
104429
- sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1);
104475
+ sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1); VdbeCoverage(v);
104430104476
104431104477
/* Generate code that runs whenever the GROUP BY changes.
104432104478
** Changes in the GROUP BY are detected by the previous code
104433104479
** block. If there were no changes, this block is skipped.
104434104480
**
@@ -104438,11 +104484,11 @@
104438104484
** for the next GROUP BY batch.
104439104485
*/
104440104486
sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
104441104487
sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
104442104488
VdbeComment((v, "output one row"));
104443
- sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd);
104489
+ sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
104444104490
VdbeComment((v, "check abort flag"));
104445104491
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
104446104492
VdbeComment((v, "reset accumulator"));
104447104493
104448104494
/* Update the aggregate accumulators based on the content of
@@ -104455,10 +104501,11 @@
104455104501
104456104502
/* End of the loop
104457104503
*/
104458104504
if( groupBySort ){
104459104505
sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
104506
+ VdbeCoverage(v);
104460104507
}else{
104461104508
sqlite3WhereEnd(pWInfo);
104462104509
sqlite3VdbeChangeToNoop(v, addrSortingIdx);
104463104510
}
104464104511
@@ -104482,11 +104529,11 @@
104482104529
sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag);
104483104530
VdbeComment((v, "set abort flag"));
104484104531
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104485104532
sqlite3VdbeResolveLabel(v, addrOutputRow);
104486104533
addrOutputRow = sqlite3VdbeCurrentAddr(v);
104487
- sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
104534
+ sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); VdbeCoverage(v);
104488104535
VdbeComment((v, "Groupby result generator entry point"));
104489104536
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104490104537
finalizeAggFunctions(pParse, &sAggInfo);
104491104538
sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104492104539
selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
@@ -104755,14 +104802,10 @@
104755104802
SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){
104756104803
if( p==0 ){
104757104804
sqlite3ExplainPrintf(pVdbe, "(null-select)");
104758104805
return;
104759104806
}
104760
- while( p->pPrior ){
104761
- p->pPrior->pNext = p;
104762
- p = p->pPrior;
104763
- }
104764104807
sqlite3ExplainPush(pVdbe);
104765104808
while( p ){
104766104809
explainOneSelect(pVdbe, p);
104767104810
p = p->pNext;
104768104811
if( p==0 ) break;
@@ -105543,10 +105586,11 @@
105543105586
/* Generate code to destroy the database record of the trigger.
105544105587
*/
105545105588
assert( pTable!=0 );
105546105589
if( (v = sqlite3GetVdbe(pParse))!=0 ){
105547105590
int base;
105591
+ static const int iLn = __LINE__+2;
105548105592
static const VdbeOpList dropTrigger[] = {
105549105593
{ OP_Rewind, 0, ADDR(9), 0},
105550105594
{ OP_String8, 0, 1, 0}, /* 1 */
105551105595
{ OP_Column, 0, 1, 2},
105552105596
{ OP_Ne, 2, ADDR(8), 1},
@@ -105557,11 +105601,11 @@
105557105601
{ OP_Next, 0, ADDR(1), 0}, /* 8 */
105558105602
};
105559105603
105560105604
sqlite3BeginWriteOperation(pParse, 0, iDb);
105561105605
sqlite3OpenMasterTable(pParse, iDb);
105562
- base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
105606
+ base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger, iLn);
105563105607
sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
105564105608
sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
105565105609
sqlite3ChangeCookie(pParse, iDb);
105566105610
sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
105567105611
sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
@@ -105703,19 +105747,11 @@
105703105747
**
105704105748
** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
105705105749
** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
105706105750
*/
105707105751
pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
105708
-
105709
- /* Clear the cookieGoto flag. When coding triggers, the cookieGoto
105710
- ** variable is used as a flag to indicate to sqlite3ExprCodeConstants()
105711
- ** that it is not safe to refactor constants (this happens after the
105712
- ** start of the first loop in the SQL statement is coded - at that
105713
- ** point code may be conditionally executed, so it is no longer safe to
105714
- ** initialize constant register values). */
105715
- assert( pParse->cookieGoto==0 || pParse->cookieGoto==-1 );
105716
- pParse->cookieGoto = 0;
105752
+ assert( pParse->okConstFactor==0 );
105717105753
105718105754
switch( pStep->op ){
105719105755
case TK_UPDATE: {
105720105756
sqlite3Update(pParse,
105721105757
targetSrcList(pParse, pStep),
@@ -106500,11 +106536,11 @@
106500106536
sqlite3VdbeChangeToNoop(v, addrOpen);
106501106537
nKey = nPk;
106502106538
regKey = iPk;
106503106539
}else{
106504106540
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
106505
- sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
106541
+ sqlite3IndexAffinityStr(v, pPk), nPk);
106506106542
sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
106507106543
}
106508106544
sqlite3WhereEnd(pWInfo);
106509106545
}
106510106546
@@ -106544,32 +106580,37 @@
106544106580
/* Top of the update loop */
106545106581
if( okOnePass ){
106546106582
if( aToOpen[iDataCur-iBaseCur] ){
106547106583
assert( pPk!=0 );
106548106584
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
106585
+ VdbeCoverageNeverTaken(v);
106549106586
}
106550106587
labelContinue = labelBreak;
106551106588
sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106589
+ VdbeCoverage(v);
106552106590
}else if( pPk ){
106553106591
labelContinue = sqlite3VdbeMakeLabel(v);
106554
- sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
106592
+ sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
106555106593
addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
106556106594
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
106595
+ VdbeCoverage(v);
106557106596
}else{
106558106597
labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
106559106598
regOldRowid);
106599
+ VdbeCoverage(v);
106560106600
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106601
+ VdbeCoverage(v);
106561106602
}
106562106603
106563106604
/* If the record number will change, set register regNewRowid to
106564106605
** contain the new value. If the record number is not being modified,
106565106606
** then regNewRowid is the same register as regOldRowid, which is
106566106607
** already populated. */
106567106608
assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
106568106609
if( chngRowid ){
106569106610
sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
106570
- sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);
106611
+ sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
106571106612
}
106572106613
106573106614
/* Compute the old pre-UPDATE content of the row being changed, if that
106574106615
** information is needed */
106575106616
if( chngPk || hasFK || pTrigger ){
@@ -106634,12 +106675,11 @@
106634106675
106635106676
/* Fire any BEFORE UPDATE triggers. This happens before constraints are
106636106677
** verified. One could argue that this is wrong.
106637106678
*/
106638106679
if( tmask&TRIGGER_BEFORE ){
106639
- sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
106640
- sqlite3TableAffinityStr(v, pTab);
106680
+ sqlite3TableAffinity(v, pTab, regNew);
106641106681
sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
106642106682
TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
106643106683
106644106684
/* The row-trigger may have deleted the row being updated. In this
106645106685
** case, jump to the next row. No updates or AFTER triggers are
@@ -106647,12 +106687,14 @@
106647106687
** is deleted or renamed by a BEFORE trigger - is left undefined in the
106648106688
** documentation.
106649106689
*/
106650106690
if( pPk ){
106651106691
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
106692
+ VdbeCoverage(v);
106652106693
}else{
106653106694
sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106695
+ VdbeCoverage(v);
106654106696
}
106655106697
106656106698
/* If it did not delete it, the row-trigger may still have modified
106657106699
** some of the columns of the row being updated. Load the values for
106658106700
** all columns not modified by the update statement into their
@@ -106684,10 +106726,11 @@
106684106726
if( pPk ){
106685106727
j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
106686106728
}else{
106687106729
j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
106688106730
}
106731
+ VdbeCoverageNeverTaken(v);
106689106732
}
106690106733
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
106691106734
106692106735
/* If changing the record number, delete the old record. */
106693106736
if( hasFK || chngKey || pPk!=0 ){
@@ -106727,11 +106770,11 @@
106727106770
*/
106728106771
if( okOnePass ){
106729106772
/* Nothing to do at end-of-loop for a single-pass */
106730106773
}else if( pPk ){
106731106774
sqlite3VdbeResolveLabel(v, labelContinue);
106732
- sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop);
106775
+ sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
106733106776
}else{
106734106777
sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
106735106778
}
106736106779
sqlite3VdbeResolveLabel(v, labelBreak);
106737106780
@@ -106856,21 +106899,21 @@
106856106899
sqlite3Select(pParse, pSelect, &dest);
106857106900
106858106901
/* Generate code to scan the ephemeral table and call VUpdate. */
106859106902
iReg = ++pParse->nMem;
106860106903
pParse->nMem += pTab->nCol+1;
106861
- addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0);
106904
+ addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0); VdbeCoverage(v);
106862106905
sqlite3VdbeAddOp3(v, OP_Column, ephemTab, 0, iReg);
106863106906
sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);
106864106907
for(i=0; i<pTab->nCol; i++){
106865106908
sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
106866106909
}
106867106910
sqlite3VtabMakeWritable(pParse, pTab);
106868106911
sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
106869106912
sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
106870106913
sqlite3MayAbort(pParse);
106871
- sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
106914
+ sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v);
106872106915
sqlite3VdbeJumpHere(v, addr);
106873106916
sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
106874106917
106875106918
/* Cleanup */
106876106919
sqlite3SelectDelete(db, pSelect);
@@ -108438,11 +108481,11 @@
108438108481
int addrSkip; /* Jump here for next iteration of skip-scan */
108439108482
int addrCont; /* Jump here to continue with the next loop cycle */
108440108483
int addrFirst; /* First instruction of interior of the loop */
108441108484
int addrBody; /* Beginning of the body of this loop */
108442108485
u8 iFrom; /* Which entry in the FROM clause */
108443
- u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
108486
+ u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
108444108487
int p1, p2; /* Operands of the opcode used to ends the loop */
108445108488
union { /* Information that depends on pWLoop->wsFlags */
108446108489
struct {
108447108490
int nIn; /* Number of entries in aInLoop[] */
108448108491
struct InLoop {
@@ -108825,10 +108868,11 @@
108825108868
#define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108826108869
#define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108827108870
#define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108828108871
#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
108829108872
#define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
108873
+#define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
108830108874
108831108875
/************** End of whereInt.h ********************************************/
108832108876
/************** Continuing where we left off in where.c **********************/
108833108877
108834108878
/*
@@ -110411,11 +110455,11 @@
110411110455
110412110456
/* Generate code to skip over the creation and initialization of the
110413110457
** transient index on 2nd and subsequent iterations of the loop. */
110414110458
v = pParse->pVdbe;
110415110459
assert( v!=0 );
110416
- addrInit = sqlite3CodeOnce(pParse);
110460
+ addrInit = sqlite3CodeOnce(pParse); VdbeCoverage(v);
110417110461
110418110462
/* Count the number of columns that will be added to the index
110419110463
** and used to match WHERE clause constraints */
110420110464
nKeyCol = 0;
110421110465
pTable = pSrc->pTab;
@@ -110518,16 +110562,16 @@
110518110562
sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
110519110563
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
110520110564
VdbeComment((v, "for %s", pTable->zName));
110521110565
110522110566
/* Fill the automatic index with content */
110523
- addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
110567
+ addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
110524110568
regRecord = sqlite3GetTempReg(pParse);
110525110569
sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
110526110570
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
110527110571
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
110528
- sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
110572
+ sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
110529110573
sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
110530110574
sqlite3VdbeJumpHere(v, addrTop);
110531110575
sqlite3ReleaseTempReg(pParse, regRecord);
110532110576
110533110577
/* Jump here when skipping the initialization */
@@ -111199,10 +111243,12 @@
111199111243
testcase( bRev );
111200111244
bRev = !bRev;
111201111245
}
111202111246
iTab = pX->iTable;
111203111247
sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
111248
+ VdbeCoverageIf(v, bRev);
111249
+ VdbeCoverageIf(v, !bRev);
111204111250
assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
111205111251
pLoop->wsFlags |= WHERE_IN_ABLE;
111206111252
if( pLevel->u.in.nIn==0 ){
111207111253
pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
111208111254
}
@@ -111218,11 +111264,11 @@
111218111264
pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
111219111265
}else{
111220111266
pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
111221111267
}
111222111268
pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
111223
- sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
111269
+ sqlite3VdbeAddOp1(v, OP_IsNull, iReg); VdbeCoverage(v);
111224111270
}else{
111225111271
pLevel->u.in.nIn = 0;
111226111272
}
111227111273
#endif
111228111274
}
@@ -111313,14 +111359,18 @@
111313111359
}
111314111360
111315111361
if( nSkip ){
111316111362
int iIdxCur = pLevel->iIdxCur;
111317111363
sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
111364
+ VdbeCoverageIf(v, bRev==0);
111365
+ VdbeCoverageIf(v, bRev!=0);
111318111366
VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
111319111367
j = sqlite3VdbeAddOp0(v, OP_Goto);
111320
- pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
111368
+ pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT),
111321111369
iIdxCur, 0, regBase, nSkip);
111370
+ VdbeCoverageIf(v, bRev==0);
111371
+ VdbeCoverageIf(v, bRev!=0);
111322111372
sqlite3VdbeJumpHere(v, j);
111323111373
for(j=0; j<nSkip; j++){
111324111374
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
111325111375
assert( pIdx->aiColumn[j]>=0 );
111326111376
VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
@@ -111349,11 +111399,14 @@
111349111399
}
111350111400
testcase( pTerm->eOperator & WO_ISNULL );
111351111401
testcase( pTerm->eOperator & WO_IN );
111352111402
if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
111353111403
Expr *pRight = pTerm->pExpr->pRight;
111354
- sqlite3ExprCodeIsNullJump(v, pRight, regBase+j, pLevel->addrBrk);
111404
+ if( sqlite3ExprCanBeNull(pRight) ){
111405
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
111406
+ VdbeCoverage(v);
111407
+ }
111355111408
if( zAff ){
111356111409
if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
111357111410
zAff[j] = SQLITE_AFF_NONE;
111358111411
}
111359111412
if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
@@ -111595,14 +111648,14 @@
111595111648
}
111596111649
111597111650
/* Special case of a FROM clause subquery implemented as a co-routine */
111598111651
if( pTabItem->viaCoroutine ){
111599111652
int regYield = pTabItem->regReturn;
111600
- sqlite3VdbeAddOp2(v, OP_Integer, pTabItem->addrFillSub-1, regYield);
111601
- pLevel->p2 = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
111602
- VdbeComment((v, "next row of co-routine %s", pTabItem->pTab->zName));
111603
- sqlite3VdbeAddOp2(v, OP_If, regYield+1, addrBrk);
111653
+ sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
111654
+ pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
111655
+ VdbeCoverage(v);
111656
+ VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
111604111657
pLevel->op = OP_Goto;
111605111658
}else
111606111659
111607111660
#ifndef SQLITE_OMIT_VIRTUALTABLE
111608111661
if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -111630,10 +111683,11 @@
111630111683
sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
111631111684
sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
111632111685
sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
111633111686
pLoop->u.vtab.idxStr,
111634111687
pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
111688
+ VdbeCoverage(v);
111635111689
pLoop->u.vtab.needFree = 0;
111636111690
for(j=0; j<nConstraint && j<16; j++){
111637111691
if( (pLoop->u.vtab.omitMask>>j)&1 ){
111638111692
disableTerm(pLevel, pLoop->aLTerm[j]);
111639111693
}
@@ -111653,20 +111707,22 @@
111653111707
** equality comparison against the ROWID field. Or
111654111708
** we reference multiple rows using a "rowid IN (...)"
111655111709
** construct.
111656111710
*/
111657111711
assert( pLoop->u.btree.nEq==1 );
111658
- iReleaseReg = sqlite3GetTempReg(pParse);
111659111712
pTerm = pLoop->aLTerm[0];
111660111713
assert( pTerm!=0 );
111661111714
assert( pTerm->pExpr!=0 );
111662111715
assert( omitTable==0 );
111663111716
testcase( pTerm->wtFlags & TERM_VIRTUAL );
111717
+ iReleaseReg = ++pParse->nMem;
111664111718
iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
111719
+ if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
111665111720
addrNxt = pLevel->addrNxt;
111666
- sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
111721
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); VdbeCoverage(v);
111667111722
sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
111723
+ VdbeCoverage(v);
111668111724
sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
111669111725
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111670111726
VdbeComment((v, "pk"));
111671111727
pLevel->op = OP_Noop;
111672111728
}else if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -111696,14 +111752,14 @@
111696111752
111697111753
/* The following constant maps TK_xx codes into corresponding
111698111754
** seek opcodes. It depends on a particular ordering of TK_xx
111699111755
*/
111700111756
const u8 aMoveOp[] = {
111701
- /* TK_GT */ OP_SeekGt,
111702
- /* TK_LE */ OP_SeekLe,
111703
- /* TK_LT */ OP_SeekLt,
111704
- /* TK_GE */ OP_SeekGe
111757
+ /* TK_GT */ OP_SeekGT,
111758
+ /* TK_LE */ OP_SeekLE,
111759
+ /* TK_LT */ OP_SeekLT,
111760
+ /* TK_GE */ OP_SeekGE
111705111761
};
111706111762
assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
111707111763
assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
111708111764
assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
111709111765
@@ -111713,15 +111769,21 @@
111713111769
assert( pX!=0 );
111714111770
testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
111715111771
r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
111716111772
sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
111717111773
VdbeComment((v, "pk"));
111774
+ VdbeCoverageIf(v, pX->op==TK_GT);
111775
+ VdbeCoverageIf(v, pX->op==TK_LE);
111776
+ VdbeCoverageIf(v, pX->op==TK_LT);
111777
+ VdbeCoverageIf(v, pX->op==TK_GE);
111718111778
sqlite3ExprCacheAffinityChange(pParse, r1, 1);
111719111779
sqlite3ReleaseTempReg(pParse, rTemp);
111720111780
disableTerm(pLevel, pStart);
111721111781
}else{
111722111782
sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
111783
+ VdbeCoverageIf(v, bRev==0);
111784
+ VdbeCoverageIf(v, bRev!=0);
111723111785
}
111724111786
if( pEnd ){
111725111787
Expr *pX;
111726111788
pX = pEnd->pExpr;
111727111789
assert( pX!=0 );
@@ -111741,14 +111803,18 @@
111741111803
pLevel->op = bRev ? OP_Prev : OP_Next;
111742111804
pLevel->p1 = iCur;
111743111805
pLevel->p2 = start;
111744111806
assert( pLevel->p5==0 );
111745111807
if( testOp!=OP_Noop ){
111746
- iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
111808
+ iRowidReg = ++pParse->nMem;
111747111809
sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
111748111810
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111749111811
sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
111812
+ VdbeCoverageIf(v, testOp==OP_Le);
111813
+ VdbeCoverageIf(v, testOp==OP_Lt);
111814
+ VdbeCoverageIf(v, testOp==OP_Ge);
111815
+ VdbeCoverageIf(v, testOp==OP_Gt);
111750111816
sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
111751111817
}
111752111818
}else if( pLoop->wsFlags & WHERE_INDEXED ){
111753111819
/* Case 4: A scan using an index.
111754111820
**
@@ -111784,24 +111850,23 @@
111784111850
static const u8 aStartOp[] = {
111785111851
0,
111786111852
0,
111787111853
OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
111788111854
OP_Last, /* 3: (!start_constraints && startEq && bRev) */
111789
- OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */
111790
- OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */
111791
- OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */
111792
- OP_SeekLe /* 7: (start_constraints && startEq && bRev) */
111855
+ OP_SeekGT, /* 4: (start_constraints && !startEq && !bRev) */
111856
+ OP_SeekLT, /* 5: (start_constraints && !startEq && bRev) */
111857
+ OP_SeekGE, /* 6: (start_constraints && startEq && !bRev) */
111858
+ OP_SeekLE /* 7: (start_constraints && startEq && bRev) */
111793111859
};
111794111860
static const u8 aEndOp[] = {
111795
- OP_Noop, /* 0: (!end_constraints) */
111796
- OP_IdxGE, /* 1: (end_constraints && !bRev) */
111797
- OP_IdxLT /* 2: (end_constraints && bRev) */
111861
+ OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */
111862
+ OP_IdxGT, /* 1: (end_constraints && !bRev && endEq) */
111863
+ OP_IdxLE, /* 2: (end_constraints && bRev && !endEq) */
111864
+ OP_IdxLT, /* 3: (end_constraints && bRev && endEq) */
111798111865
};
111799111866
u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111800
- int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111801111867
int regBase; /* Base register holding constraint values */
111802
- int r1; /* Temp register */
111803111868
WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111804111869
WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111805111870
int startEq; /* True if range start uses ==, >= or <= */
111806111871
int endEq; /* True if range end uses ==, >= or <= */
111807111872
int start_constraints; /* Start of range is constrained */
@@ -111810,10 +111875,12 @@
111810111875
int iIdxCur; /* The VDBE cursor for the index */
111811111876
int nExtraReg = 0; /* Number of extra registers needed */
111812111877
int op; /* Instruction opcode */
111813111878
char *zStartAff; /* Affinity for start of range constraint */
111814111879
char cEndAff = 0; /* Affinity for end of range constraint */
111880
+ u8 bSeekPastNull = 0; /* True to seek past initial nulls */
111881
+ u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
111815111882
111816111883
pIdx = pLoop->u.btree.pIndex;
111817111884
iIdxCur = pLevel->iIdxCur;
111818111885
assert( nEq>=pLoop->u.btree.nSkip );
111819111886
@@ -111828,11 +111895,11 @@
111828111895
if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111829111896
&& (pWInfo->bOBSat!=0)
111830111897
&& (pIdx->nKeyCol>nEq)
111831111898
){
111832111899
assert( pLoop->u.btree.nSkip==0 );
111833
- isMinQuery = 1;
111900
+ bSeekPastNull = 1;
111834111901
nExtraReg = 1;
111835111902
}
111836111903
111837111904
/* Find any inequality constraint terms for the start and end
111838111905
** of the range.
@@ -111843,10 +111910,17 @@
111843111910
nExtraReg = 1;
111844111911
}
111845111912
if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
111846111913
pRangeEnd = pLoop->aLTerm[j++];
111847111914
nExtraReg = 1;
111915
+ if( pRangeStart==0
111916
+ && (pRangeEnd->wtFlags & TERM_VNULL)==0
111917
+ && (j = pIdx->aiColumn[nEq])>=0
111918
+ && pIdx->pTable->aCol[j].notNull==0
111919
+ ){
111920
+ bSeekPastNull = 1;
111921
+ }
111848111922
}
111849111923
111850111924
/* Generate code to evaluate all constraint terms using == or IN
111851111925
** and store the values of those terms in an array of registers
111852111926
** starting at regBase.
@@ -111862,10 +111936,11 @@
111862111936
*/
111863111937
if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
111864111938
|| (bRev && pIdx->nKeyCol==nEq)
111865111939
){
111866111940
SWAP(WhereTerm *, pRangeEnd, pRangeStart);
111941
+ SWAP(u8, bSeekPastNull, bStopAtNull);
111867111942
}
111868111943
111869111944
testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
111870111945
testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
111871111946
testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
@@ -111877,12 +111952,15 @@
111877111952
/* Seek the index cursor to the start of the range. */
111878111953
nConstraint = nEq;
111879111954
if( pRangeStart ){
111880111955
Expr *pRight = pRangeStart->pExpr->pRight;
111881111956
sqlite3ExprCode(pParse, pRight, regBase+nEq);
111882
- if( (pRangeStart->wtFlags & TERM_VNULL)==0 ){
111883
- sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
111957
+ if( (pRangeStart->wtFlags & TERM_VNULL)==0
111958
+ && sqlite3ExprCanBeNull(pRight)
111959
+ ){
111960
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
111961
+ VdbeCoverage(v);
111884111962
}
111885111963
if( zStartAff ){
111886111964
if( sqlite3CompareAffinity(pRight, zStartAff[nEq])==SQLITE_AFF_NONE){
111887111965
/* Since the comparison is to be performed with no conversions
111888111966
** applied to the operands, set the affinity to apply to pRight to
@@ -111893,86 +111971,76 @@
111893111971
zStartAff[nEq] = SQLITE_AFF_NONE;
111894111972
}
111895111973
}
111896111974
nConstraint++;
111897111975
testcase( pRangeStart->wtFlags & TERM_VIRTUAL );
111898
- }else if( isMinQuery ){
111976
+ }else if( bSeekPastNull ){
111899111977
sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
111900111978
nConstraint++;
111901111979
startEq = 0;
111902111980
start_constraints = 1;
111903111981
}
111904
- codeApplyAffinity(pParse, regBase, nConstraint, zStartAff);
111982
+ codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
111905111983
op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
111906111984
assert( op!=0 );
111907
- testcase( op==OP_Rewind );
111908
- testcase( op==OP_Last );
111909
- testcase( op==OP_SeekGt );
111910
- testcase( op==OP_SeekGe );
111911
- testcase( op==OP_SeekLe );
111912
- testcase( op==OP_SeekLt );
111913111985
sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
111986
+ VdbeCoverage(v);
111987
+ VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
111988
+ VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
111989
+ VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT );
111990
+ VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
111991
+ VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE );
111992
+ VdbeCoverageIf(v, op==OP_SeekLT); testcase( op==OP_SeekLT );
111914111993
111915111994
/* Load the value for the inequality constraint at the end of the
111916111995
** range (if any).
111917111996
*/
111918111997
nConstraint = nEq;
111919111998
if( pRangeEnd ){
111920111999
Expr *pRight = pRangeEnd->pExpr->pRight;
111921112000
sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111922112001
sqlite3ExprCode(pParse, pRight, regBase+nEq);
111923
- if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111924
- sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
112002
+ if( (pRangeEnd->wtFlags & TERM_VNULL)==0
112003
+ && sqlite3ExprCanBeNull(pRight)
112004
+ ){
112005
+ sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
112006
+ VdbeCoverage(v);
111925112007
}
111926112008
if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
111927112009
&& !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
111928112010
){
111929112011
codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
111930112012
}
111931112013
nConstraint++;
111932112014
testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
112015
+ }else if( bStopAtNull ){
112016
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
112017
+ endEq = 0;
112018
+ nConstraint++;
111933112019
}
111934112020
sqlite3DbFree(db, zStartAff);
111935112021
111936112022
/* Top of the loop body */
111937112023
pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111938112024
111939112025
/* Check if the index cursor is past the end of the range. */
111940
- op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)];
111941
- testcase( op==OP_Noop );
111942
- testcase( op==OP_IdxGE );
111943
- testcase( op==OP_IdxLT );
111944
- if( op!=OP_Noop ){
112026
+ if( nConstraint ){
112027
+ op = aEndOp[bRev*2 + endEq];
111945112028
sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
111946
- sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
111947
- }
111948
-
111949
- /* If there are inequality constraints, check that the value
111950
- ** of the table column that the inequality contrains is not NULL.
111951
- ** If it is, jump to the next iteration of the loop.
111952
- */
111953
- r1 = sqlite3GetTempReg(pParse);
111954
- testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111955
- testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111956
- if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
111957
- && (j = pIdx->aiColumn[nEq])>=0
111958
- && pIdx->pTable->aCol[j].notNull==0
111959
- && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0)
111960
- ){
111961
- sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
111962
- VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName));
111963
- sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111964
- }
111965
- sqlite3ReleaseTempReg(pParse, r1);
112029
+ testcase( op==OP_IdxGT ); VdbeCoverageIf(v, op==OP_IdxGT );
112030
+ testcase( op==OP_IdxGE ); VdbeCoverageIf(v, op==OP_IdxGE );
112031
+ testcase( op==OP_IdxLT ); VdbeCoverageIf(v, op==OP_IdxLT );
112032
+ testcase( op==OP_IdxLE ); VdbeCoverageIf(v, op==OP_IdxLE );
112033
+ }
111966112034
111967112035
/* Seek the table cursor, if required */
111968112036
disableTerm(pLevel, pRangeStart);
111969112037
disableTerm(pLevel, pRangeEnd);
111970112038
if( omitTable ){
111971112039
/* pIdx is a covering index. No need to access the main table. */
111972112040
}else if( HasRowid(pIdx->pTable) ){
111973
- iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
112041
+ iRowidReg = ++pParse->nMem;
111974112042
sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
111975112043
sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111976112044
sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
111977112045
}else{
111978112046
Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
@@ -111980,11 +112048,11 @@
111980112048
for(j=0; j<pPk->nKeyCol; j++){
111981112049
k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
111982112050
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
111983112051
}
111984112052
sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
111985
- iRowidReg, pPk->nKeyCol);
112053
+ iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
111986112054
}
111987112055
111988112056
/* Record the instruction used to terminate the loop. Disable
111989112057
** WHERE clause terms made redundant by the index range scan.
111990112058
*/
@@ -111994,10 +112062,12 @@
111994112062
pLevel->op = OP_Prev;
111995112063
}else{
111996112064
pLevel->op = OP_Next;
111997112065
}
111998112066
pLevel->p1 = iIdxCur;
112067
+ assert( (WHERE_UNQ_WANTED>>16)==1 );
112068
+ pLevel->p3 = (pLoop->wsFlags>>16)&1;
111999112069
if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
112000112070
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112001112071
}else{
112002112072
assert( pLevel->p5==0 );
112003112073
}
@@ -112162,10 +112232,11 @@
112162112232
int r;
112163112233
r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
112164112234
regRowid, 0);
112165112235
sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
112166112236
sqlite3VdbeCurrentAddr(v)+2, r, iSet);
112237
+ VdbeCoverage(v);
112167112238
}
112168112239
sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
112169112240
112170112241
/* The pSubWInfo->untestedTerms flag means that this OR term
112171112242
** contained one or more AND term from a notReady table. The
@@ -112230,10 +112301,12 @@
112230112301
pLevel->op = OP_Noop;
112231112302
}else{
112232112303
pLevel->op = aStep[bRev];
112233112304
pLevel->p1 = iCur;
112234112305
pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
112306
+ VdbeCoverageIf(v, bRev==0);
112307
+ VdbeCoverageIf(v, bRev!=0);
112235112308
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112236112309
}
112237112310
}
112238112311
112239112312
/* Insert code to test every subexpression that can be completely
@@ -112311,11 +112384,10 @@
112311112384
assert( pTerm->pExpr );
112312112385
sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
112313112386
pTerm->wtFlags |= TERM_CODED;
112314112387
}
112315112388
}
112316
- sqlite3ReleaseTempReg(pParse, iReleaseReg);
112317112389
112318112390
return pLevel->notReady;
112319112391
}
112320112392
112321112393
#if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -112798,16 +112870,17 @@
112798112870
assert(
112799112871
(pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
112800112872
|| nInMul==0
112801112873
);
112802112874
pNew->wsFlags |= WHERE_COLUMN_EQ;
112803
- if( iCol<0
112804
- || (pProbe->onError!=OE_None && nInMul==0
112805
- && pNew->u.btree.nEq==pProbe->nKeyCol-1)
112806
- ){
112875
+ if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1)){
112807112876
assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
112808
- pNew->wsFlags |= WHERE_ONEROW;
112877
+ if( iCol>=0 && pProbe->onError==OE_None ){
112878
+ pNew->wsFlags |= WHERE_UNQ_WANTED;
112879
+ }else{
112880
+ pNew->wsFlags |= WHERE_ONEROW;
112881
+ }
112809112882
}
112810112883
pNew->u.btree.nEq++;
112811112884
pNew->nOut = nRowEst + nInMul;
112812112885
}else if( pTerm->eOperator & (WO_ISNULL) ){
112813112886
pNew->wsFlags |= WHERE_COLUMN_NULL;
@@ -113682,13 +113755,16 @@
113682113755
/* Mark off any other ORDER BY terms that reference pLoop */
113683113756
if( isOrderDistinct ){
113684113757
orderDistinctMask |= pLoop->maskSelf;
113685113758
for(i=0; i<nOrderBy; i++){
113686113759
Expr *p;
113760
+ Bitmask mTerm;
113687113761
if( MASKBIT(i) & obSat ) continue;
113688113762
p = pOrderBy->a[i].pExpr;
113689
- if( (exprTableUsage(&pWInfo->sMaskSet, p)&~orderDistinctMask)==0 ){
113763
+ mTerm = exprTableUsage(&pWInfo->sMaskSet,p);
113764
+ if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue;
113765
+ if( (mTerm&~orderDistinctMask)==0 ){
113690113766
obSat |= MASKBIT(i);
113691113767
}
113692113768
}
113693113769
}
113694113770
} /* End the loop over all WhereLoops from outer-most down to inner-most */
@@ -114246,11 +114322,10 @@
114246114322
** subexpression is separated by an AND operator.
114247114323
*/
114248114324
initMaskSet(pMaskSet);
114249114325
whereClauseInit(&pWInfo->sWC, pWInfo);
114250114326
whereSplit(&pWInfo->sWC, pWhere, TK_AND);
114251
- sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
114252114327
114253114328
/* Special case: a WHERE clause that is constant. Evaluate the
114254114329
** expression and either jump over all of the code or fall thru.
114255114330
*/
114256114331
for(ii=0; ii<sWLB.pWC->nTerm; ii++){
@@ -114308,26 +114383,10 @@
114308114383
exprAnalyzeAll(pTabList, &pWInfo->sWC);
114309114384
if( db->mallocFailed ){
114310114385
goto whereBeginError;
114311114386
}
114312114387
114313
- /* If the ORDER BY (or GROUP BY) clause contains references to general
114314
- ** expressions, then we won't be able to satisfy it using indices, so
114315
- ** go ahead and disable it now.
114316
- */
114317
- if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
114318
- for(ii=0; ii<pOrderBy->nExpr; ii++){
114319
- Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
114320
- if( pExpr->op!=TK_COLUMN ){
114321
- pWInfo->pOrderBy = pOrderBy = 0;
114322
- break;
114323
- }else if( pExpr->iColumn<0 ){
114324
- break;
114325
- }
114326
- }
114327
- }
114328
-
114329114388
if( wctrlFlags & WHERE_WANT_DISTINCT ){
114330114389
if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
114331114390
/* The DISTINCT marking is pointless. Ignore it. */
114332114391
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
114333114392
}else if( pOrderBy==0 ){
@@ -114535,11 +114594,11 @@
114535114594
assert( iIndexCur>=0 );
114536114595
sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
114537114596
sqlite3VdbeSetP4KeyInfo(pParse, pIx);
114538114597
VdbeComment((v, "%s", pIx->zName));
114539114598
}
114540
- sqlite3CodeVerifySchema(pParse, iDb);
114599
+ if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
114541114600
notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
114542114601
}
114543114602
pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
114544114603
if( db->mallocFailed ) goto whereBeginError;
114545114604
@@ -114597,20 +114656,27 @@
114597114656
int addr;
114598114657
pLevel = &pWInfo->a[i];
114599114658
pLoop = pLevel->pWLoop;
114600114659
sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114601114660
if( pLevel->op!=OP_Noop ){
114602
- sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
114661
+ sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
114603114662
sqlite3VdbeChangeP5(v, pLevel->p5);
114663
+ VdbeCoverage(v);
114664
+ VdbeCoverageIf(v, pLevel->op==OP_Next);
114665
+ VdbeCoverageIf(v, pLevel->op==OP_Prev);
114666
+ VdbeCoverageIf(v, pLevel->op==OP_VNext);
114604114667
}
114605114668
if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
114606114669
struct InLoop *pIn;
114607114670
int j;
114608114671
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
114609114672
for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
114610114673
sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
114611114674
sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
114675
+ VdbeCoverage(v);
114676
+ VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
114677
+ VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
114612114678
sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114613114679
}
114614114680
sqlite3DbFree(db, pLevel->u.in.aInLoop);
114615114681
}
114616114682
sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
@@ -114619,11 +114685,11 @@
114619114685
VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
114620114686
sqlite3VdbeJumpHere(v, pLevel->addrSkip);
114621114687
sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
114622114688
}
114623114689
if( pLevel->iLeftJoin ){
114624
- addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114690
+ addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
114625114691
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114626114692
|| (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114627114693
if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114628114694
sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
114629114695
}
@@ -114646,15 +114712,41 @@
114646114712
*/
114647114713
sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
114648114714
114649114715
assert( pWInfo->nLevel<=pTabList->nSrc );
114650114716
for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
114717
+ int k, last;
114718
+ VdbeOp *pOp;
114651114719
Index *pIdx = 0;
114652114720
struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
114653114721
Table *pTab = pTabItem->pTab;
114654114722
assert( pTab!=0 );
114655114723
pLoop = pLevel->pWLoop;
114724
+
114725
+ /* For a co-routine, change all OP_Column references to the table of
114726
+ ** the co-routine into OP_SCopy of result contained in a register.
114727
+ ** OP_Rowid becomes OP_Null.
114728
+ */
114729
+ if( pTabItem->viaCoroutine ){
114730
+ last = sqlite3VdbeCurrentAddr(v);
114731
+ k = pLevel->addrBody;
114732
+ pOp = sqlite3VdbeGetOp(v, k);
114733
+ for(; k<last; k++, pOp++){
114734
+ if( pOp->p1!=pLevel->iTabCur ) continue;
114735
+ if( pOp->opcode==OP_Column ){
114736
+ pOp->opcode = OP_SCopy;
114737
+ pOp->p1 = pOp->p2 + pTabItem->regResult;
114738
+ pOp->p2 = pOp->p3;
114739
+ pOp->p3 = 0;
114740
+ }else if( pOp->opcode==OP_Rowid ){
114741
+ pOp->opcode = OP_Null;
114742
+ pOp->p1 = 0;
114743
+ pOp->p3 = 0;
114744
+ }
114745
+ }
114746
+ continue;
114747
+ }
114656114748
114657114749
/* Close all of the cursors that were opened by sqlite3WhereBegin.
114658114750
** Except, do not close cursors that will be reused by the OR optimization
114659114751
** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors
114660114752
** created for the ONEPASS optimization.
@@ -114690,13 +114782,10 @@
114690114782
pIdx = pLoop->u.btree.pIndex;
114691114783
}else if( pLoop->wsFlags & WHERE_MULTI_OR ){
114692114784
pIdx = pLevel->u.pCovidx;
114693114785
}
114694114786
if( pIdx && !db->mallocFailed ){
114695
- int k, last;
114696
- VdbeOp *pOp;
114697
-
114698114787
last = sqlite3VdbeCurrentAddr(v);
114699114788
k = pLevel->addrBody;
114700114789
pOp = sqlite3VdbeGetOp(v, k);
114701114790
for(; k<last; k++, pOp++){
114702114791
if( pOp->p1!=pLevel->iTabCur ) continue;
@@ -117106,33 +117195,54 @@
117106117195
sqlite3ExplainFinish(pParse->pVdbe);
117107117196
sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
117108117197
}
117109117198
break;
117110117199
case 112: /* select ::= with selectnowith */
117111
-{
117112
- if( yymsp[0].minor.yy3 ){
117113
- yymsp[0].minor.yy3->pWith = yymsp[-1].minor.yy59;
117200
+{
117201
+ Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
117202
+ if( p ){
117203
+ int cnt = 0, mxSelect;
117204
+ p->pWith = yymsp[-1].minor.yy59;
117205
+ if( p->pPrior ){
117206
+ pNext = 0;
117207
+ for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
117208
+ pLoop->pNext = pNext;
117209
+ pLoop->selFlags |= SF_Compound;
117210
+ }
117211
+ mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
117212
+ if( mxSelect && cnt>mxSelect ){
117213
+ sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
117214
+ }
117215
+ }
117114117216
}else{
117115117217
sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
117116117218
}
117117
- yygotominor.yy3 = yymsp[0].minor.yy3;
117219
+ yygotominor.yy3 = p;
117118117220
}
117119117221
break;
117120117222
case 113: /* selectnowith ::= oneselect */
117121117223
case 119: /* oneselect ::= values */ yytestcase(yyruleno==119);
117122117224
{yygotominor.yy3 = yymsp[0].minor.yy3;}
117123117225
break;
117124117226
case 114: /* selectnowith ::= selectnowith multiselect_op oneselect */
117125117227
{
117126
- if( yymsp[0].minor.yy3 ){
117127
- yymsp[0].minor.yy3->op = (u8)yymsp[-1].minor.yy328;
117128
- yymsp[0].minor.yy3->pPrior = yymsp[-2].minor.yy3;
117228
+ Select *pRhs = yymsp[0].minor.yy3;
117229
+ if( pRhs && pRhs->pPrior ){
117230
+ SrcList *pFrom;
117231
+ Token x;
117232
+ x.n = 0;
117233
+ pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
117234
+ pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
117235
+ }
117236
+ if( pRhs ){
117237
+ pRhs->op = (u8)yymsp[-1].minor.yy328;
117238
+ pRhs->pPrior = yymsp[-2].minor.yy3;
117129117239
if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
117130117240
}else{
117131117241
sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
117132117242
}
117133
- yygotominor.yy3 = yymsp[0].minor.yy3;
117243
+ yygotominor.yy3 = pRhs;
117134117244
}
117135117245
break;
117136117246
case 116: /* multiselect_op ::= UNION ALL */
117137117247
{yygotominor.yy328 = TK_ALL;}
117138117248
break;
@@ -122696,10 +122806,25 @@
122696122806
case SQLITE_TESTCTRL_NEVER_CORRUPT: {
122697122807
sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
122698122808
break;
122699122809
}
122700122810
122811
+
122812
+ /* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
122813
+ **
122814
+ ** Set the VDBE coverage callback function to xCallback with context
122815
+ ** pointer ptr.
122816
+ */
122817
+ case SQLITE_TESTCTRL_VDBE_COVERAGE: {
122818
+#ifdef SQLITE_VDBE_COVERAGE
122819
+ typedef void (*branch_callback)(void*,int,u8,u8);
122820
+ sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
122821
+ sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
122822
+#endif
122823
+ break;
122824
+ }
122825
+
122701122826
}
122702122827
va_end(ap);
122703122828
#endif /* SQLITE_OMIT_BUILTIN_TEST */
122704122829
return rc;
122705122830
}
122706122831
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.3.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -187,13 +187,13 @@
187 **
188 ** See also: [sqlite3_libversion()],
189 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190 ** [sqlite_version()] and [sqlite_source_id()].
191 */
192 #define SQLITE_VERSION "3.8.3.1"
193 #define SQLITE_VERSION_NUMBER 3008003
194 #define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e"
195
196 /*
197 ** CAPI3REF: Run-Time Library Version Numbers
198 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
199 **
@@ -6202,11 +6202,12 @@
6202 #define SQLITE_TESTCTRL_ISKEYWORD 16
6203 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6204 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6205 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6206 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6207 #define SQLITE_TESTCTRL_LAST 20
 
6208
6209 /*
6210 ** CAPI3REF: SQLite Runtime Status
6211 **
6212 ** ^This interface is used to retrieve runtime status information
@@ -8852,12 +8853,10 @@
8852 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
8853 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
8854 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
8855 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
8856 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
8857 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor*, sqlite3_int64);
8858 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor*);
8859
8860 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
8861 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
8862
8863 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
@@ -8993,13 +8992,16 @@
8993 } p4;
8994 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
8995 char *zComment; /* Comment to improve readability */
8996 #endif
8997 #ifdef VDBE_PROFILE
8998 int cnt; /* Number of times this instruction was executed */
8999 u64 cycles; /* Total time spent executing this instruction */
9000 #endif
 
 
 
9001 };
9002 typedef struct VdbeOp VdbeOp;
9003
9004
9005 /*
@@ -9105,75 +9107,75 @@
9105 #define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */
9106 #define OP_Goto 16
9107 #define OP_Gosub 17
9108 #define OP_Return 18
9109 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9110 #define OP_Yield 20
9111 #define OP_HaltIfNull 21 /* synopsis: if r[P3] null then halt */
9112 #define OP_Halt 22
9113 #define OP_Integer 23 /* synopsis: r[P2]=P1 */
9114 #define OP_Int64 24 /* synopsis: r[P2]=P4 */
9115 #define OP_String 25 /* synopsis: r[P2]='P4' (len=P1) */
9116 #define OP_Null 26 /* synopsis: r[P2..P3]=NULL */
9117 #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
9118 #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
9119 #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
9120 #define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9121 #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
9122 #define OP_ResultRow 32 /* synopsis: output=r[P1@P2] */
9123 #define OP_CollSeq 33
9124 #define OP_AddImm 34 /* synopsis: r[P1]=r[P1]+P2 */
9125 #define OP_MustBeInt 35
9126 #define OP_RealAffinity 36
9127 #define OP_Permutation 37
9128 #define OP_Compare 38
9129 #define OP_Jump 39
9130 #define OP_Once 40
9131 #define OP_If 41
9132 #define OP_IfNot 42
9133 #define OP_Column 43 /* synopsis: r[P3]=PX */
9134 #define OP_Affinity 44 /* synopsis: affinity(r[P1@P2]) */
9135 #define OP_MakeRecord 45 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9136 #define OP_Count 46 /* synopsis: r[P2]=count() */
9137 #define OP_ReadCookie 47
9138 #define OP_SetCookie 48
9139 #define OP_VerifyCookie 49
9140 #define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
9141 #define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
9142 #define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
9143 #define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9144 #define OP_SorterOpen 54
9145 #define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */
9146 #define OP_Close 56
9147 #define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */
9148 #define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */
9149 #define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */
9150 #define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */
9151 #define OP_Seek 61 /* synopsis: intkey=r[P2] */
9152 #define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */
9153 #define OP_NotFound 63 /* synopsis: key=r[P3@P4] */
9154 #define OP_Found 64 /* synopsis: key=r[P3@P4] */
9155 #define OP_NotExists 65 /* synopsis: intkey=r[P3] */
9156 #define OP_Sequence 66 /* synopsis: r[P2]=rowid */
9157 #define OP_NewRowid 67 /* synopsis: r[P2]=rowid */
9158 #define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */
9159 #define OP_InsertInt 69 /* synopsis: intkey=P3 data=r[P2] */
9160 #define OP_Delete 70
9161 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9162 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9163 #define OP_ResetCount 73
9164 #define OP_SorterCompare 74 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9165 #define OP_SorterData 75 /* synopsis: r[P2]=data */
9166 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9167 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9168 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9169 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9170 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9171 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9172 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9173 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9174 #define OP_RowKey 84 /* synopsis: r[P2]=key */
9175 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9176 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9177 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9178 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9179 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9180,68 +9182,72 @@
9180 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9181 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9182 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9183 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9184 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9185 #define OP_RowData 95 /* synopsis: r[P2]=data */
9186 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9187 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9188 #define OP_Rowid 98 /* synopsis: r[P2]=rowid */
9189 #define OP_NullRow 99
9190 #define OP_Last 100
9191 #define OP_SorterSort 101
9192 #define OP_Sort 102
9193 #define OP_Rewind 103
9194 #define OP_SorterInsert 104
9195 #define OP_IdxInsert 105 /* synopsis: key=r[P2] */
9196 #define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */
9197 #define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */
9198 #define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */
9199 #define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */
9200 #define OP_Destroy 110
9201 #define OP_Clear 111
9202 #define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */
9203 #define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */
9204 #define OP_ParseSchema 114
9205 #define OP_LoadAnalysis 115
9206 #define OP_DropTable 116
9207 #define OP_DropIndex 117
9208 #define OP_DropTrigger 118
9209 #define OP_IntegrityCk 119
9210 #define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */
9211 #define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */
9212 #define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9213 #define OP_Program 123
9214 #define OP_Param 124
9215 #define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */
9216 #define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */
9217 #define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9218 #define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */
9219 #define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */
9220 #define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9221 #define OP_AggFinal 131 /* synopsis: accum=r[P1] N=P2 */
9222 #define OP_IncrVacuum 132
9223 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9224 #define OP_Expire 134
9225 #define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */
9226 #define OP_VBegin 136
9227 #define OP_VCreate 137
9228 #define OP_VDestroy 138
9229 #define OP_VOpen 139
9230 #define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */
9231 #define OP_VNext 141
9232 #define OP_VRename 142
9233 #define OP_ToText 143 /* same as TK_TO_TEXT */
9234 #define OP_ToBlob 144 /* same as TK_TO_BLOB */
9235 #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
9236 #define OP_ToInt 146 /* same as TK_TO_INT */
9237 #define OP_ToReal 147 /* same as TK_TO_REAL */
9238 #define OP_Pagecount 148
9239 #define OP_MaxPgcnt 149
9240 #define OP_Trace 150
9241 #define OP_Noop 151
9242 #define OP_Explain 152
 
 
 
 
9243
9244
9245 /* Properties such as "out2" or "jump" that are specified in
9246 ** comments following the "case" for each opcode in the vdbe.c
9247 ** are encoded into bitvectors as follows:
@@ -9254,28 +9260,28 @@
9254 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9255 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9256 #define OPFLG_INITIALIZER {\
9257 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9258 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9259 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
9260 /* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
9261 /* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
9262 /* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
9263 /* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9264 /* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
9265 /* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c,\
9266 /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
9267 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9268 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9269 /* 96 */ 0x24, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
9270 /* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
9271 /* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9272 /* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
9273 /* 128 */ 0x05, 0x05, 0x05, 0x00, 0x01, 0x02, 0x00, 0x00,\
9274 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,\
9275 /* 144 */ 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00,\
9276 /* 152 */ 0x00,}
9277
9278 /************** End of opcodes.h *********************************************/
9279 /************** Continuing where we left off in vdbe.h ***********************/
9280
9281 /*
@@ -9287,11 +9293,11 @@
9287 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
9288 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
9289 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
9290 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
9291 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
9292 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp);
9293 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
9294 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
9295 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
9296 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9297 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
@@ -9358,10 +9364,45 @@
9358 # define VdbeComment(X)
9359 # define VdbeNoopComment(X)
9360 # define VdbeModuleComment(X)
9361 #endif
9362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9363 #endif
9364
9365 /************** End of vdbe.h ************************************************/
9366 /************** Continuing where we left off in sqliteInt.h ******************/
9367 /************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -10415,12 +10456,11 @@
10415
10416 /*
10417 ** Return true if it OK to factor constant expressions into the initialization
10418 ** code. The argument is a Parse object for the code generator.
10419 */
10420 #define ConstFactorOk(P) \
10421 ((P)->cookieGoto>0 && OptimizationEnabled((P)->db,SQLITE_FactorOutConst))
10422
10423 /*
10424 ** Possible values for the sqlite.magic field.
10425 ** The numbers are obtained at random and have no special meaning, other
10426 ** than being distinct from one another.
@@ -10642,14 +10682,20 @@
10642 #define SQLITE_AFF_MASK 0x67
10643
10644 /*
10645 ** Additional bit values that can be ORed with an affinity without
10646 ** changing the affinity.
 
 
 
 
 
10647 */
10648 #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
10649 #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
10650 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
 
10651
10652 /*
10653 ** An object of this type is created for each virtual table present in
10654 ** the database schema.
10655 **
@@ -11347,10 +11393,11 @@
11347 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
11348 Table *pTab; /* An SQL table corresponding to zName */
11349 Select *pSelect; /* A SELECT statement used in place of a table name */
11350 int addrFillSub; /* Address of subroutine to manifest a subquery */
11351 int regReturn; /* Register holding return address of addrFillSub */
 
11352 u8 jointype; /* Type of join between this able and the previous */
11353 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
11354 unsigned isCorrelated :1; /* True if sub-query is correlated */
11355 unsigned viaCoroutine :1; /* Implemented as a co-routine */
11356 unsigned isRecursive :1; /* True for recursive reference in WITH */
@@ -11475,11 +11522,10 @@
11475 ExprList *pGroupBy; /* The GROUP BY clause */
11476 Expr *pHaving; /* The HAVING clause */
11477 ExprList *pOrderBy; /* The ORDER BY clause */
11478 Select *pPrior; /* Prior select in a compound select statement */
11479 Select *pNext; /* Next select to the left in a compound */
11480 Select *pRightmost; /* Right-most select in a compound select statement */
11481 Expr *pLimit; /* LIMIT expression. NULL means not used. */
11482 Expr *pOffset; /* OFFSET expression. NULL means not used. */
11483 With *pWith; /* WITH clause attached to this select. Or NULL. */
11484 };
11485
@@ -11493,14 +11539,15 @@
11493 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
11494 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
11495 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11496 #define SF_UseSorter 0x0040 /* Sort using a sorter */
11497 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11498 #define SF_Materialize 0x0100 /* Force materialization of views */
11499 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11500 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11501 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
 
11502
11503
11504 /*
11505 ** The results of a SELECT can be distributed in several ways, as defined
11506 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -11675,49 +11722,48 @@
11675 int rc; /* Return code from execution */
11676 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
11677 u8 checkSchema; /* Causes schema cookie check after an error */
11678 u8 nested; /* Number of nested calls to the parser/code generator */
11679 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
11680 u8 nTempInUse; /* Number of aTempReg[] currently checked out */
11681 u8 nColCache; /* Number of entries in aColCache[] */
11682 u8 iColCache; /* Next entry in aColCache[] to replace */
11683 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
11684 u8 mayAbort; /* True if statement may throw an ABORT exception */
11685 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
 
11686 int aTempReg[8]; /* Holding area for temporary registers */
11687 int nRangeReg; /* Size of the temporary register block */
11688 int iRangeReg; /* First register in temporary register block */
11689 int nErr; /* Number of errors seen */
11690 int nTab; /* Number of previously allocated VDBE cursors */
11691 int nMem; /* Number of memory cells used so far */
11692 int nSet; /* Number of sets used so far */
11693 int nOnce; /* Number of OP_Once instructions so far */
11694 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
11695 int nLabel; /* Number of labels used */
11696 int *aLabel; /* Space to hold the labels */
11697 int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
11698 int ckBase; /* Base register of data during check constraints */
11699 int iPartIdxTab; /* Table corresponding to a partial index */
11700 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
11701 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
 
 
11702 struct yColCache {
11703 int iTable; /* Table cursor number */
11704 int iColumn; /* Table column number */
11705 u8 tempReg; /* iReg is a temp register that needs to be freed */
11706 int iLevel; /* Nesting level */
11707 int iReg; /* Reg with value of this column. 0 means none. */
11708 int lru; /* Least recently used entry has the smallest value */
11709 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
11710 ExprList *pConstExpr;/* Constant expressions */
 
11711 yDbMask writeMask; /* Start a write transaction on these databases */
11712 yDbMask cookieMask; /* Bitmask of schema verified databases */
11713 int cookieGoto; /* Address of OP_Goto to cookie verifier subroutine */
11714 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
11715 int regRowid; /* Register holding rowid of CREATE TABLE entry */
11716 int regRoot; /* Register holding root page number for new objects */
11717 int nMaxArg; /* Max args passed to user function by sub-program */
11718 Token constraintName;/* Name of the constraint currently being parsed */
11719 #ifndef SQLITE_OMIT_SHARED_CACHE
11720 int nTableLock; /* Number of locks in aTableLock */
11721 TableLock *aTableLock; /* Required table locks for shared-cache mode */
11722 #endif
11723 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -11732,16 +11778,21 @@
11732 u32 newmask; /* Mask of new.* columns referenced */
11733 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
11734 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
11735 u8 disableTriggers; /* True to disable triggers */
11736
11737 /* Above is constant between recursions. Below is reset before and after
11738 ** each recursion */
 
 
 
 
11739
11740 int nVar; /* Number of '?' variables seen in the SQL so far */
11741 int nzVar; /* Number of available slots in azVar[] */
11742 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
 
11743 u8 explain; /* True if the EXPLAIN flag is found on the query */
11744 #ifndef SQLITE_OMIT_VIRTUALTABLE
11745 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
11746 int nVtabLock; /* Number of virtual tables to lock */
11747 #endif
@@ -11764,11 +11815,10 @@
11764 Table **apVtabLock; /* Pointer to virtual tables needing locking */
11765 #endif
11766 Table *pZombieTab; /* List of Table objects to delete after code gen */
11767 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
11768 With *pWith; /* Current WITH clause, or NULL */
11769 u8 bFreeWith; /* True if pWith should be freed with parser */
11770 };
11771
11772 /*
11773 ** Return true if currently inside an sqlite3_declare_vtab() call.
11774 */
@@ -11980,10 +12030,17 @@
11980 int bLocaltimeFault; /* True to fail localtime() calls */
11981 #ifdef SQLITE_ENABLE_SQLLOG
11982 void(*xSqllog)(void*,sqlite3*,const char*, int);
11983 void *pSqllogArg;
11984 #endif
 
 
 
 
 
 
 
11985 };
11986
11987 /*
11988 ** This macro is used inside of assert() statements to indicate that
11989 ** the assert is only valid on a well-formed database. Instead of:
@@ -12313,11 +12370,10 @@
12313 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
12314 #else
12315 # define sqlite3AutoincrementBegin(X)
12316 # define sqlite3AutoincrementEnd(X)
12317 #endif
12318 SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse*, Select*, SelectDest*);
12319 SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int);
12320 SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
12321 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
12322 SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
12323 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -12361,15 +12417,16 @@
12361 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
12362 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
12363 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
12364 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
12365 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12366 SQLITE_PRIVATE int sqlite3ExprCode(Parse*, Expr*, int);
 
12367 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
12368 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12369 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12370 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12371 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
12372 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
12373 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
12374 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12375 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
@@ -12403,11 +12460,10 @@
12403 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12404 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12405 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
12406 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12407 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
12408 SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(Vdbe*, const Expr*, int, int);
12409 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12410 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12411 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
12412 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12413 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
@@ -12547,11 +12603,11 @@
12547 #define getVarint sqlite3GetVarint
12548 #define putVarint sqlite3PutVarint
12549
12550
12551 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
12552 SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *, Table *);
12553 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
12554 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
12555 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
12556 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
12557 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
@@ -13651,11 +13707,10 @@
13651 u8 rowidIsValid; /* True if lastRowid is valid */
13652 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13653 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
13654 Bool isTable:1; /* True if a table requiring integer keys */
13655 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
13656 Bool multiPseudo:1; /* Multi-register pseudo-cursor */
13657 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13658 i64 seqCount; /* Sequence counter */
13659 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13660 i64 lastRowid; /* Rowid being deleted by OP_Delete */
13661 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -13745,11 +13800,11 @@
13745 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
13746 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
13747 } u;
13748 int n; /* Number of characters in string value, excluding '\0' */
13749 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
13750 u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
13751 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
13752 #ifdef SQLITE_DEBUG
13753 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
13754 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
13755 #endif
@@ -13774,11 +13829,11 @@
13774 #define MEM_Int 0x0004 /* Value is an integer */
13775 #define MEM_Real 0x0008 /* Value is a real number */
13776 #define MEM_Blob 0x0010 /* Value is a BLOB */
13777 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
13778 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
13779 #define MEM_Invalid 0x0080 /* Value is undefined */
13780 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
13781 #define MEM_TypeMask 0x01ff /* Mask of type bits */
13782
13783
13784 /* Whenever Mem contains a valid string or blob representation, one of
@@ -13806,11 +13861,11 @@
13806 /*
13807 ** Return true if a memory cell is not marked as invalid. This macro
13808 ** is for use inside assert() statements only.
13809 */
13810 #ifdef SQLITE_DEBUG
13811 #define memIsValid(M) ((M)->flags & MEM_Invalid)==0
13812 #endif
13813
13814 /*
13815 ** Each auxilliary data pointer stored by a user defined function
13816 ** implementation calling sqlite3_set_auxdata() is stored in an instance
@@ -14001,20 +14056,22 @@
14001 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
14002 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
14003 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
14004 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
14005 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
 
 
14006 #define VdbeMemRelease(X) \
14007 if((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame)) \
14008 sqlite3VdbeMemReleaseExternal(X);
14009 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
14010 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
14011 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
14012 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
14013 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
14014 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
14015 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem);
 
14016 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
14017
14018 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
14019 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
14020 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
@@ -17778,10 +17835,16 @@
17778 mem5.totalExcess += iFullSz - nByte;
17779 mem5.currentCount++;
17780 mem5.currentOut += iFullSz;
17781 if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
17782 if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
 
 
 
 
 
 
17783
17784 /* Return a pointer to the allocated memory. */
17785 return (void*)&mem5.zPool[i*mem5.szAtom];
17786 }
17787
@@ -17836,10 +17899,17 @@
17836 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
17837 mem5.aCtrl[iBuddy] = 0;
17838 }
17839 size *= 2;
17840 }
 
 
 
 
 
 
 
17841 memsys5Link(iBlock, iLogsize);
17842 }
17843
17844 /*
17845 ** Allocate nBytes of memory.
@@ -22739,17 +22809,16 @@
22739 testcase( iB==-1 ); testcase( iB==0 );
22740 if( iB>=0 ){
22741 testcase( iA>0 && LARGEST_INT64 - iA == iB );
22742 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
22743 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
22744 *pA += iB;
22745 }else{
22746 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
22747 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
22748 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
22749 *pA += iB;
22750 }
 
22751 return 0;
22752 }
22753 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
22754 testcase( iB==SMALLEST_INT64+1 );
22755 if( iB==SMALLEST_INT64 ){
@@ -22769,13 +22838,22 @@
22769
22770 iA1 = iA/TWOPOWER32;
22771 iA0 = iA % TWOPOWER32;
22772 iB1 = iB/TWOPOWER32;
22773 iB0 = iB % TWOPOWER32;
22774 if( iA1*iB1 != 0 ) return 1;
22775 assert( iA1*iB0==0 || iA0*iB1==0 );
22776 r = iA1*iB0 + iA0*iB1;
 
 
 
 
 
 
 
 
 
22777 testcase( r==(-TWOPOWER31)-1 );
22778 testcase( r==(-TWOPOWER31) );
22779 testcase( r==TWOPOWER31 );
22780 testcase( r==TWOPOWER31-1 );
22781 if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
@@ -23217,75 +23295,75 @@
23217 /* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"),
23218 /* 16 */ "Goto" OpHelp(""),
23219 /* 17 */ "Gosub" OpHelp(""),
23220 /* 18 */ "Return" OpHelp(""),
23221 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
23222 /* 20 */ "Yield" OpHelp(""),
23223 /* 21 */ "HaltIfNull" OpHelp("if r[P3] null then halt"),
23224 /* 22 */ "Halt" OpHelp(""),
23225 /* 23 */ "Integer" OpHelp("r[P2]=P1"),
23226 /* 24 */ "Int64" OpHelp("r[P2]=P4"),
23227 /* 25 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23228 /* 26 */ "Null" OpHelp("r[P2..P3]=NULL"),
23229 /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23230 /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23231 /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23232 /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23233 /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23234 /* 32 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23235 /* 33 */ "CollSeq" OpHelp(""),
23236 /* 34 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23237 /* 35 */ "MustBeInt" OpHelp(""),
23238 /* 36 */ "RealAffinity" OpHelp(""),
23239 /* 37 */ "Permutation" OpHelp(""),
23240 /* 38 */ "Compare" OpHelp(""),
23241 /* 39 */ "Jump" OpHelp(""),
23242 /* 40 */ "Once" OpHelp(""),
23243 /* 41 */ "If" OpHelp(""),
23244 /* 42 */ "IfNot" OpHelp(""),
23245 /* 43 */ "Column" OpHelp("r[P3]=PX"),
23246 /* 44 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23247 /* 45 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23248 /* 46 */ "Count" OpHelp("r[P2]=count()"),
23249 /* 47 */ "ReadCookie" OpHelp(""),
23250 /* 48 */ "SetCookie" OpHelp(""),
23251 /* 49 */ "VerifyCookie" OpHelp(""),
23252 /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23253 /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23254 /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23255 /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23256 /* 54 */ "SorterOpen" OpHelp(""),
23257 /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23258 /* 56 */ "Close" OpHelp(""),
23259 /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23260 /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23261 /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23262 /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23263 /* 61 */ "Seek" OpHelp("intkey=r[P2]"),
23264 /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23265 /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"),
23266 /* 64 */ "Found" OpHelp("key=r[P3@P4]"),
23267 /* 65 */ "NotExists" OpHelp("intkey=r[P3]"),
23268 /* 66 */ "Sequence" OpHelp("r[P2]=rowid"),
23269 /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"),
23270 /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23271 /* 69 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23272 /* 70 */ "Delete" OpHelp(""),
23273 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23274 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23275 /* 73 */ "ResetCount" OpHelp(""),
23276 /* 74 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23277 /* 75 */ "SorterData" OpHelp("r[P2]=data"),
23278 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23279 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23280 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23281 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23282 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23283 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23284 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23285 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23286 /* 84 */ "RowKey" OpHelp("r[P2]=key"),
23287 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23288 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23289 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23290 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23291 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23292,68 +23370,72 @@
23292 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23293 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23294 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23295 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23296 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23297 /* 95 */ "RowData" OpHelp("r[P2]=data"),
23298 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23299 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23300 /* 98 */ "Rowid" OpHelp("r[P2]=rowid"),
23301 /* 99 */ "NullRow" OpHelp(""),
23302 /* 100 */ "Last" OpHelp(""),
23303 /* 101 */ "SorterSort" OpHelp(""),
23304 /* 102 */ "Sort" OpHelp(""),
23305 /* 103 */ "Rewind" OpHelp(""),
23306 /* 104 */ "SorterInsert" OpHelp(""),
23307 /* 105 */ "IdxInsert" OpHelp("key=r[P2]"),
23308 /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23309 /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23310 /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23311 /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23312 /* 110 */ "Destroy" OpHelp(""),
23313 /* 111 */ "Clear" OpHelp(""),
23314 /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23315 /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23316 /* 114 */ "ParseSchema" OpHelp(""),
23317 /* 115 */ "LoadAnalysis" OpHelp(""),
23318 /* 116 */ "DropTable" OpHelp(""),
23319 /* 117 */ "DropIndex" OpHelp(""),
23320 /* 118 */ "DropTrigger" OpHelp(""),
23321 /* 119 */ "IntegrityCk" OpHelp(""),
23322 /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23323 /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23324 /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23325 /* 123 */ "Program" OpHelp(""),
23326 /* 124 */ "Param" OpHelp(""),
23327 /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23328 /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23329 /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23330 /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23331 /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23332 /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23333 /* 131 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23334 /* 132 */ "IncrVacuum" OpHelp(""),
23335 /* 133 */ "Real" OpHelp("r[P2]=P4"),
23336 /* 134 */ "Expire" OpHelp(""),
23337 /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23338 /* 136 */ "VBegin" OpHelp(""),
23339 /* 137 */ "VCreate" OpHelp(""),
23340 /* 138 */ "VDestroy" OpHelp(""),
23341 /* 139 */ "VOpen" OpHelp(""),
23342 /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23343 /* 141 */ "VNext" OpHelp(""),
23344 /* 142 */ "VRename" OpHelp(""),
23345 /* 143 */ "ToText" OpHelp(""),
23346 /* 144 */ "ToBlob" OpHelp(""),
23347 /* 145 */ "ToNumeric" OpHelp(""),
23348 /* 146 */ "ToInt" OpHelp(""),
23349 /* 147 */ "ToReal" OpHelp(""),
23350 /* 148 */ "Pagecount" OpHelp(""),
23351 /* 149 */ "MaxPgcnt" OpHelp(""),
23352 /* 150 */ "Trace" OpHelp(""),
23353 /* 151 */ "Noop" OpHelp(""),
23354 /* 152 */ "Explain" OpHelp(""),
 
 
 
 
23355 };
23356 return azName[i];
23357 }
23358 #endif
23359
@@ -34429,11 +34511,11 @@
34429 ** Windows will only let you create file view mappings
34430 ** on allocation size granularity boundaries.
34431 ** During sqlite3_os_init() we do a GetSystemInfo()
34432 ** to get the granularity size.
34433 */
34434 SYSTEM_INFO winSysInfo;
34435
34436 #ifndef SQLITE_OMIT_WAL
34437
34438 /*
34439 ** Helper functions to obtain and relinquish the global mutex. The
@@ -36363,19 +36445,16 @@
36363 #ifndef SQLITE_OMIT_LOAD_EXTENSION
36364 /*
36365 ** Interfaces for opening a shared library, finding entry points
36366 ** within the shared library, and closing the shared library.
36367 */
36368 /*
36369 ** Interfaces for opening a shared library, finding entry points
36370 ** within the shared library, and closing the shared library.
36371 */
36372 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
36373 HANDLE h;
36374 void *zConverted = winConvertFromUtf8Filename(zFilename);
36375 UNUSED_PARAMETER(pVfs);
36376 if( zConverted==0 ){
 
36377 return 0;
36378 }
36379 if( osIsNT() ){
36380 #if SQLITE_OS_WINRT
36381 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
@@ -36386,24 +36465,30 @@
36386 #ifdef SQLITE_WIN32_HAS_ANSI
36387 else{
36388 h = osLoadLibraryA((char*)zConverted);
36389 }
36390 #endif
 
36391 sqlite3_free(zConverted);
36392 return (void*)h;
36393 }
36394 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
36395 UNUSED_PARAMETER(pVfs);
36396 winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
36397 }
36398 static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
 
36399 UNUSED_PARAMETER(pVfs);
36400 return (void(*)(void))osGetProcAddressA((HANDLE)pH, zSym);
 
 
 
36401 }
36402 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
36403 UNUSED_PARAMETER(pVfs);
36404 osFreeLibrary((HANDLE)pHandle);
 
36405 }
36406 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
36407 #define winDlOpen 0
36408 #define winDlError 0
36409 #define winDlSym 0
@@ -37095,11 +37180,12 @@
37095 PgHdr *pSynced; /* Last synced page in dirty page list */
37096 int nRef; /* Number of referenced pages */
37097 int szCache; /* Configured cache size */
37098 int szPage; /* Size of every page in this cache */
37099 int szExtra; /* Size of extra space for each page */
37100 int bPurgeable; /* True if pages are on backing store */
 
37101 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
37102 void *pStress; /* Argument to xStress */
37103 sqlite3_pcache *pCache; /* Pluggable cache module */
37104 PgHdr *pPage1; /* Reference to page 1 */
37105 };
@@ -37162,10 +37248,14 @@
37162 if( pPage->pDirtyPrev ){
37163 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
37164 }else{
37165 assert( pPage==p->pDirty );
37166 p->pDirty = pPage->pDirtyNext;
 
 
 
 
37167 }
37168 pPage->pDirtyNext = 0;
37169 pPage->pDirtyPrev = 0;
37170
37171 expensive_assert( pcacheCheckSynced(p) );
@@ -37182,10 +37272,13 @@
37182
37183 pPage->pDirtyNext = p->pDirty;
37184 if( pPage->pDirtyNext ){
37185 assert( pPage->pDirtyNext->pDirtyPrev==0 );
37186 pPage->pDirtyNext->pDirtyPrev = pPage;
 
 
 
37187 }
37188 p->pDirty = pPage;
37189 if( !p->pDirtyTail ){
37190 p->pDirtyTail = pPage;
37191 }
@@ -37251,10 +37344,11 @@
37251 ){
37252 memset(p, 0, sizeof(PCache));
37253 p->szPage = szPage;
37254 p->szExtra = szExtra;
37255 p->bPurgeable = bPurgeable;
 
37256 p->xStress = xStress;
37257 p->pStress = pStress;
37258 p->szCache = 100;
37259 }
37260
@@ -37290,11 +37384,11 @@
37290 PCache *pCache, /* Obtain the page from this cache */
37291 Pgno pgno, /* Page number to obtain */
37292 int createFlag, /* If true, create page if it does not exist already */
37293 PgHdr **ppPage /* Write the page here */
37294 ){
37295 sqlite3_pcache_page *pPage = 0;
37296 PgHdr *pPgHdr = 0;
37297 int eCreate;
37298
37299 assert( pCache!=0 );
37300 assert( createFlag==1 || createFlag==0 );
@@ -37301,12 +37395,16 @@
37301 assert( pgno>0 );
37302
37303 /* If the pluggable cache (sqlite3_pcache*) has not been allocated,
37304 ** allocate it now.
37305 */
37306 if( !pCache->pCache && createFlag ){
37307 sqlite3_pcache *p;
 
 
 
 
37308 p = sqlite3GlobalConfig.pcache2.xCreate(
37309 pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
37310 );
37311 if( !p ){
37312 return SQLITE_NOMEM;
@@ -37313,15 +37411,20 @@
37313 }
37314 sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
37315 pCache->pCache = p;
37316 }
37317
37318 eCreate = createFlag * (1 + (!pCache->bPurgeable || !pCache->pDirty));
37319 if( pCache->pCache ){
37320 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
37321 }
37322
 
 
 
 
 
37323 if( !pPage && eCreate==1 ){
37324 PgHdr *pPg;
37325
37326 /* Find a dirty page to write-out and recycle. First try to find a
37327 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
@@ -47905,11 +48008,11 @@
47905 if( rc!=SQLITE_OK ){
47906 walIndexClose(pRet, 0);
47907 sqlite3OsClose(pRet->pWalFd);
47908 sqlite3_free(pRet);
47909 }else{
47910 int iDC = sqlite3OsDeviceCharacteristics(pRet->pWalFd);
47911 if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
47912 if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){
47913 pRet->padToSectorBoundary = 0;
47914 }
47915 *ppWal = pRet;
@@ -49276,11 +49379,11 @@
49276 if( rc ) return rc;
49277 iOffset += iFirstAmt;
49278 iAmt -= iFirstAmt;
49279 pContent = (void*)(iFirstAmt + (char*)pContent);
49280 assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) );
49281 rc = sqlite3OsSync(p->pFd, p->syncFlags);
49282 if( iAmt==0 || rc ) return rc;
49283 }
49284 rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
49285 return rc;
49286 }
@@ -50214,11 +50317,10 @@
50214 struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
50215 #ifndef SQLITE_OMIT_INCRBLOB
50216 Pgno *aOverflow; /* Cache of overflow page locations */
50217 #endif
50218 Pgno pgnoRoot; /* The root page of this tree */
50219 sqlite3_int64 cachedRowid; /* Next rowid cache. 0 means not valid */
50220 CellInfo info; /* A parse of the cell we are pointing at */
50221 i64 nKey; /* Size of pKey, or last integer key */
50222 void *pKey; /* Saved key that was cursor's last known position */
50223 int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
50224 u8 wrFlag; /* True if writable */
@@ -52198,17 +52300,16 @@
52198 assert( sqlite3_mutex_held(pBt->mutex) );
52199 if( pBt->btsFlags & BTS_SECURE_DELETE ){
52200 memset(&data[hdr], 0, pBt->usableSize - hdr);
52201 }
52202 data[hdr] = (char)flags;
52203 first = hdr + 8 + 4*((flags&PTF_LEAF)==0 ?1:0);
52204 memset(&data[hdr+1], 0, 4);
52205 data[hdr+7] = 0;
52206 put2byte(&data[hdr+5], pBt->usableSize);
52207 pPage->nFree = (u16)(pBt->usableSize - first);
52208 decodeFlags(pPage, flags);
52209 pPage->hdrOffset = hdr;
52210 pPage->cellOffset = first;
52211 pPage->aDataEnd = &data[pBt->usableSize];
52212 pPage->aCellIdx = &data[first];
52213 pPage->nOverflow = 0;
52214 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
@@ -54288,11 +54389,10 @@
54288 if( pCur->pNext ){
54289 pCur->pNext->pPrev = pCur;
54290 }
54291 pBt->pCursor = pCur;
54292 pCur->eState = CURSOR_INVALID;
54293 pCur->cachedRowid = 0;
54294 return SQLITE_OK;
54295 }
54296 SQLITE_PRIVATE int sqlite3BtreeCursor(
54297 Btree *p, /* The btree */
54298 int iTable, /* Root page of table to open */
@@ -54329,40 +54429,10 @@
54329 */
54330 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){
54331 memset(p, 0, offsetof(BtCursor, iPage));
54332 }
54333
54334 /*
54335 ** Set the cached rowid value of every cursor in the same database file
54336 ** as pCur and having the same root page number as pCur. The value is
54337 ** set to iRowid.
54338 **
54339 ** Only positive rowid values are considered valid for this cache.
54340 ** The cache is initialized to zero, indicating an invalid cache.
54341 ** A btree will work fine with zero or negative rowids. We just cannot
54342 ** cache zero or negative rowids, which means tables that use zero or
54343 ** negative rowids might run a little slower. But in practice, zero
54344 ** or negative rowids are very uncommon so this should not be a problem.
54345 */
54346 SQLITE_PRIVATE void sqlite3BtreeSetCachedRowid(BtCursor *pCur, sqlite3_int64 iRowid){
54347 BtCursor *p;
54348 for(p=pCur->pBt->pCursor; p; p=p->pNext){
54349 if( p->pgnoRoot==pCur->pgnoRoot ) p->cachedRowid = iRowid;
54350 }
54351 assert( pCur->cachedRowid==iRowid );
54352 }
54353
54354 /*
54355 ** Return the cached rowid for the given cursor. A negative or zero
54356 ** return value indicates that the rowid cache is invalid and should be
54357 ** ignored. If the rowid cache has never before been set, then a
54358 ** zero is returned.
54359 */
54360 SQLITE_PRIVATE sqlite3_int64 sqlite3BtreeGetCachedRowid(BtCursor *pCur){
54361 return pCur->cachedRowid;
54362 }
54363
54364 /*
54365 ** Close a cursor. The read lock on the database file is released
54366 ** when the last cursor is closed.
54367 */
54368 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
@@ -55433,18 +55503,28 @@
55433 /*
55434 ** Advance the cursor to the next entry in the database. If
55435 ** successful then set *pRes=0. If the cursor
55436 ** was already pointing to the last entry in the database before
55437 ** this routine was called, then set *pRes=1.
 
 
 
 
 
 
 
 
 
55438 */
55439 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
55440 int rc;
55441 int idx;
55442 MemPage *pPage;
55443
55444 assert( cursorHoldsMutex(pCur) );
55445 assert( pRes!=0 );
 
55446 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
55447 if( pCur->eState!=CURSOR_VALID ){
55448 rc = restoreCursorPosition(pCur);
55449 if( rc!=SQLITE_OK ){
55450 *pRes = 0;
@@ -55519,17 +55599,27 @@
55519 /*
55520 ** Step the cursor to the back to the previous entry in the database. If
55521 ** successful then set *pRes=0. If the cursor
55522 ** was already pointing to the first entry in the database before
55523 ** this routine was called, then set *pRes=1.
 
 
 
 
 
 
 
 
 
55524 */
55525 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
55526 int rc;
55527 MemPage *pPage;
55528
55529 assert( cursorHoldsMutex(pCur) );
55530 assert( pRes!=0 );
 
55531 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
55532 pCur->atLast = 0;
55533 if( pCur->eState!=CURSOR_VALID ){
55534 if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){
55535 rc = btreeRestoreCursorPosition(pCur);
@@ -57622,15 +57712,21 @@
57622 ** not to clear the cursor here.
57623 */
57624 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
57625 if( rc ) return rc;
57626
57627 /* If this is an insert into a table b-tree, invalidate any incrblob
57628 ** cursors open on the row being replaced (assuming this is a replace
57629 ** operation - if it is not, the following is a no-op). */
57630 if( pCur->pKeyInfo==0 ){
 
 
57631 invalidateIncrblobCursors(p, nKey, 0);
 
 
 
 
 
 
 
57632 }
57633
57634 if( !loc ){
57635 rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
57636 if( rc ) return rc;
@@ -57696,12 +57792,12 @@
57696 ** entry in the table, and the next row inserted has an integer key
57697 ** larger than the largest existing key, it is possible to insert the
57698 ** row without seeking the cursor. This can be a big performance boost.
57699 */
57700 pCur->info.nSize = 0;
57701 pCur->validNKey = 0;
57702 if( rc==SQLITE_OK && pPage->nOverflow ){
 
57703 rc = balance(pCur);
57704
57705 /* Must make sure nOverflow is reset to zero even if the balance()
57706 ** fails. Internal data structure corruption will result otherwise.
57707 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
@@ -57752,11 +57848,11 @@
57752 ** from the internal node. The 'previous' entry is used for this instead
57753 ** of the 'next' entry, as the previous entry is always a part of the
57754 ** sub-tree headed by the child page of the cell being deleted. This makes
57755 ** balancing the tree following the delete operation easier. */
57756 if( !pPage->leaf ){
57757 int notUsed;
57758 rc = sqlite3BtreePrevious(pCur, &notUsed);
57759 if( rc ) return rc;
57760 }
57761
57762 /* Save the positions of any other cursors open on this table before
@@ -60177,11 +60273,11 @@
60177 }
60178
60179 /*
60180 ** Release any memory held by the Mem. This may leave the Mem in an
60181 ** inconsistent state, for example with (Mem.z==0) and
60182 ** (Mem.type==SQLITE_TEXT).
60183 */
60184 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60185 VdbeMemRelease(p);
60186 if( p->zMalloc ){
60187 sqlite3DbFree(p->db, p->zMalloc);
@@ -60368,11 +60464,11 @@
60368 }
60369 if( pMem->flags & MEM_RowSet ){
60370 sqlite3RowSetClear(pMem->u.pRowSet);
60371 }
60372 MemSetTypeFlag(pMem, MEM_Null);
60373 pMem->type = SQLITE_NULL;
60374 }
60375 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
60376 sqlite3VdbeMemSetNull((Mem*)p);
60377 }
60378
@@ -60381,11 +60477,11 @@
60381 ** n containing all zeros.
60382 */
60383 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
60384 sqlite3VdbeMemRelease(pMem);
60385 pMem->flags = MEM_Blob|MEM_Zero;
60386 pMem->type = SQLITE_BLOB;
60387 pMem->n = 0;
60388 if( n<0 ) n = 0;
60389 pMem->u.nZero = n;
60390 pMem->enc = SQLITE_UTF8;
60391
@@ -60404,11 +60500,11 @@
60404 */
60405 SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
60406 sqlite3VdbeMemRelease(pMem);
60407 pMem->u.i = val;
60408 pMem->flags = MEM_Int;
60409 pMem->type = SQLITE_INTEGER;
60410 }
60411
60412 #ifndef SQLITE_OMIT_FLOATING_POINT
60413 /*
60414 ** Delete any previous value and set the value stored in *pMem to val,
@@ -60419,11 +60515,11 @@
60419 sqlite3VdbeMemSetNull(pMem);
60420 }else{
60421 sqlite3VdbeMemRelease(pMem);
60422 pMem->r = val;
60423 pMem->flags = MEM_Real;
60424 pMem->type = SQLITE_FLOAT;
60425 }
60426 }
60427 #endif
60428
60429 /*
@@ -60475,11 +60571,11 @@
60475 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
60476 int i;
60477 Mem *pX;
60478 for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){
60479 if( pX->pScopyFrom==pMem ){
60480 pX->flags |= MEM_Invalid;
60481 pX->pScopyFrom = 0;
60482 }
60483 }
60484 pMem->pScopyFrom = 0;
60485 }
@@ -60627,11 +60723,11 @@
60627 }
60628
60629 pMem->n = nByte;
60630 pMem->flags = flags;
60631 pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
60632 pMem->type = (enc==0 ? SQLITE_BLOB : SQLITE_TEXT);
60633
60634 #ifndef SQLITE_OMIT_UTF16
60635 if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
60636 return SQLITE_NOMEM;
60637 }
@@ -60798,11 +60894,11 @@
60798 pMem->z = &zData[offset];
60799 pMem->flags = MEM_Blob|MEM_Ephem;
60800 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60801 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
60802 pMem->enc = 0;
60803 pMem->type = SQLITE_BLOB;
60804 if( key ){
60805 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
60806 }else{
60807 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
60808 }
@@ -60868,11 +60964,11 @@
60868 */
60869 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
60870 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
60871 if( p ){
60872 p->flags = MEM_Null;
60873 p->type = SQLITE_NULL;
60874 p->db = db;
60875 }
60876 return p;
60877 }
60878
@@ -60918,11 +61014,11 @@
60918 assert( pRec->pKeyInfo->enc==ENC(db) );
60919 pRec->flags = UNPACKED_PREFIX_MATCH;
60920 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
60921 for(i=0; i<nCol; i++){
60922 pRec->aMem[i].flags = MEM_Null;
60923 pRec->aMem[i].type = SQLITE_NULL;
60924 pRec->aMem[i].db = db;
60925 }
60926 }else{
60927 sqlite3DbFree(db, pRec);
60928 pRec = 0;
@@ -60991,11 +61087,11 @@
60991 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
60992 }else{
60993 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
60994 if( zVal==0 ) goto no_mem;
60995 sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
60996 if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
60997 }
60998 if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
60999 sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
61000 }else{
61001 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
@@ -61449,10 +61545,13 @@
61449 #endif
61450 #ifdef VDBE_PROFILE
61451 pOp->cycles = 0;
61452 pOp->cnt = 0;
61453 #endif
 
 
 
61454 return i;
61455 }
61456 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe *p, int op){
61457 return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
61458 }
@@ -61810,11 +61909,11 @@
61810
61811 /*
61812 ** Add a whole list of operations to the operation stack. Return the
61813 ** address of the first operation added.
61814 */
61815 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp){
61816 int addr;
61817 assert( p->magic==VDBE_MAGIC_INIT );
61818 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
61819 return 0;
61820 }
@@ -61837,10 +61936,15 @@
61837 pOut->p4type = P4_NOTUSED;
61838 pOut->p4.p = 0;
61839 pOut->p5 = 0;
61840 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61841 pOut->zComment = 0;
 
 
 
 
 
61842 #endif
61843 #ifdef SQLITE_DEBUG
61844 if( p->db->flags & SQLITE_VdbeAddopTrace ){
61845 sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
61846 }
@@ -62126,10 +62230,19 @@
62126 va_end(ap);
62127 }
62128 }
62129 #endif /* NDEBUG */
62130
 
 
 
 
 
 
 
 
 
62131 /*
62132 ** Return the opcode for a given address. If the address is -1, then
62133 ** return the most recently inserted opcode.
62134 **
62135 ** If a memory allocation error has occurred prior to the calling of this
@@ -62138,28 +62251,17 @@
62138 ** The return of a dummy opcode allows the call to continue functioning
62139 ** after a OOM fault without having to check to see if the return from
62140 ** this routine is a valid pointer. But because the dummy.opcode is 0,
62141 ** dummy will never be written to. This is verified by code inspection and
62142 ** by running with Valgrind.
62143 **
62144 ** About the #ifdef SQLITE_OMIT_TRACE: Normally, this routine is never called
62145 ** unless p->nOp>0. This is because in the absense of SQLITE_OMIT_TRACE,
62146 ** an OP_Trace instruction is always inserted by sqlite3VdbeGet() as soon as
62147 ** a new VDBE is created. So we are free to set addr to p->nOp-1 without
62148 ** having to double-check to make sure that the result is non-negative. But
62149 ** if SQLITE_OMIT_TRACE is defined, the OP_Trace is omitted and we do need to
62150 ** check the value of p->nOp-1 before continuing.
62151 */
62152 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
62153 /* C89 specifies that the constant "dummy" will be initialized to all
62154 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
62155 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
62156 assert( p->magic==VDBE_MAGIC_INIT );
62157 if( addr<0 ){
62158 #ifdef SQLITE_OMIT_TRACE
62159 if( p->nOp==0 ) return (VdbeOp*)&dummy;
62160 #endif
62161 addr = p->nOp - 1;
62162 }
62163 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
62164 if( p->db->mallocFailed ){
62165 return (VdbeOp*)&dummy;
@@ -62460,11 +62562,11 @@
62460 if( pOut==0 ) pOut = stdout;
62461 zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
62462 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62463 displayComment(pOp, zP4, zCom, sizeof(zCom));
62464 #else
62465 zCom[0] = 0
62466 #endif
62467 /* NB: The sqlite3OpcodeName() function is implemented by code created
62468 ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
62469 ** information from the vdbe.c source text */
62470 fprintf(pOut, zFormat1, pc,
@@ -62509,11 +62611,11 @@
62509 }else if( p->zMalloc ){
62510 sqlite3DbFree(db, p->zMalloc);
62511 p->zMalloc = 0;
62512 }
62513
62514 p->flags = MEM_Invalid;
62515 }
62516 db->mallocFailed = malloc_failed;
62517 }
62518 }
62519
@@ -62631,19 +62733,19 @@
62631 }
62632 pOp = &apSub[j]->aOp[i];
62633 }
62634 if( p->explain==1 ){
62635 pMem->flags = MEM_Int;
62636 pMem->type = SQLITE_INTEGER;
62637 pMem->u.i = i; /* Program counter */
62638 pMem++;
62639
62640 pMem->flags = MEM_Static|MEM_Str|MEM_Term;
62641 pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
62642 assert( pMem->z!=0 );
62643 pMem->n = sqlite3Strlen30(pMem->z);
62644 pMem->type = SQLITE_TEXT;
62645 pMem->enc = SQLITE_UTF8;
62646 pMem++;
62647
62648 /* When an OP_Program opcode is encounter (the only opcode that has
62649 ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
@@ -62665,21 +62767,21 @@
62665 }
62666 }
62667
62668 pMem->flags = MEM_Int;
62669 pMem->u.i = pOp->p1; /* P1 */
62670 pMem->type = SQLITE_INTEGER;
62671 pMem++;
62672
62673 pMem->flags = MEM_Int;
62674 pMem->u.i = pOp->p2; /* P2 */
62675 pMem->type = SQLITE_INTEGER;
62676 pMem++;
62677
62678 pMem->flags = MEM_Int;
62679 pMem->u.i = pOp->p3; /* P3 */
62680 pMem->type = SQLITE_INTEGER;
62681 pMem++;
62682
62683 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62684 assert( p->db->mallocFailed );
62685 return SQLITE_ERROR;
@@ -62691,11 +62793,11 @@
62691 }else{
62692 assert( pMem->z!=0 );
62693 pMem->n = sqlite3Strlen30(pMem->z);
62694 pMem->enc = SQLITE_UTF8;
62695 }
62696 pMem->type = SQLITE_TEXT;
62697 pMem++;
62698
62699 if( p->explain==1 ){
62700 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
62701 assert( p->db->mallocFailed );
@@ -62702,11 +62804,11 @@
62702 return SQLITE_ERROR;
62703 }
62704 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62705 pMem->n = 2;
62706 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62707 pMem->type = SQLITE_TEXT;
62708 pMem->enc = SQLITE_UTF8;
62709 pMem++;
62710
62711 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62712 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
@@ -62713,15 +62815,15 @@
62713 assert( p->db->mallocFailed );
62714 return SQLITE_ERROR;
62715 }
62716 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62717 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62718 pMem->type = SQLITE_TEXT;
62719 pMem->enc = SQLITE_UTF8;
62720 #else
62721 pMem->flags = MEM_Null; /* Comment */
62722 pMem->type = SQLITE_NULL;
62723 #endif
62724 }
62725
62726 p->nResColumn = 8 - 4*(p->explain-1);
62727 p->pResultSet = &p->aMem[1];
@@ -62740,11 +62842,11 @@
62740 const char *z = 0;
62741 if( p->zSql ){
62742 z = p->zSql;
62743 }else if( p->nOp>=1 ){
62744 const VdbeOp *pOp = &p->aOp[0];
62745 if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62746 z = pOp->p4.z;
62747 while( sqlite3Isspace(*z) ) z++;
62748 }
62749 }
62750 if( z ) printf("SQL: [%s]\n", z);
@@ -62759,11 +62861,11 @@
62759 int nOp = p->nOp;
62760 VdbeOp *pOp;
62761 if( sqlite3IoTrace==0 ) return;
62762 if( nOp<1 ) return;
62763 pOp = &p->aOp[0];
62764 if( pOp->opcode==OP_Trace && pOp->p4.z!=0 ){
62765 int i, j;
62766 char z[1000];
62767 sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z);
62768 for(i=0; sqlite3Isspace(z[i]); i++){}
62769 for(j=0; z[i]; i++){
@@ -62977,11 +63079,11 @@
62977 }
62978 if( p->aMem ){
62979 p->aMem--; /* aMem[] goes from 1..nMem */
62980 p->nMem = nMem; /* not from 0..nMem-1 */
62981 for(n=1; n<=nMem; n++){
62982 p->aMem[n].flags = MEM_Invalid;
62983 p->aMem[n].db = db;
62984 }
62985 }
62986 p->explain = pParse->explain;
62987 sqlite3VdbeRewind(p);
@@ -63089,11 +63191,11 @@
63089 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
63090 ** Vdbe.aMem[] arrays have already been cleaned up. */
63091 int i;
63092 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
63093 if( p->aMem ){
63094 for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Invalid );
63095 }
63096 #endif
63097
63098 sqlite3DbFree(db, p->zErrMsg);
63099 p->zErrMsg = 0;
@@ -63838,16 +63940,28 @@
63838 fprintf(out, "---- ");
63839 for(i=0; i<p->nOp; i++){
63840 fprintf(out, "%02x", p->aOp[i].opcode);
63841 }
63842 fprintf(out, "\n");
 
 
 
 
 
 
 
 
 
 
63843 for(i=0; i<p->nOp; i++){
63844 fprintf(out, "%6d %10lld %8lld ",
 
63845 p->aOp[i].cnt,
63846 p->aOp[i].cycles,
63847 p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
63848 );
 
63849 sqlite3VdbePrintOp(out, i, &p->aOp[i]);
63850 }
63851 fclose(out);
63852 }
63853 }
@@ -64880,11 +64994,45 @@
64880 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
64881 return sqlite3ValueText(pVal, SQLITE_UTF16LE);
64882 }
64883 #endif /* SQLITE_OMIT_UTF16 */
64884 SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
64885 return pVal->type;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64886 }
64887
64888 /**************************** sqlite3_result_ *******************************
64889 ** The following routines are used by user-defined functions to specify
64890 ** the function result.
@@ -65839,11 +65987,11 @@
65839 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
65840 }
65841 #endif /* SQLITE_OMIT_UTF16 */
65842 SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
65843 int rc;
65844 switch( pValue->type ){
65845 case SQLITE_INTEGER: {
65846 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
65847 break;
65848 }
65849 case SQLITE_FLOAT: {
@@ -66340,37 +66488,12 @@
66340 ** May you do good and not evil.
66341 ** May you find forgiveness for yourself and forgive others.
66342 ** May you share freely, never taking more than you give.
66343 **
66344 *************************************************************************
66345 ** The code in this file implements execution method of the
66346 ** Virtual Database Engine (VDBE). A separate file ("vdbeaux.c")
66347 ** handles housekeeping details such as creating and deleting
66348 ** VDBE instances. This file is solely interested in executing
66349 ** the VDBE program.
66350 **
66351 ** In the external interface, an "sqlite3_stmt*" is an opaque pointer
66352 ** to a VDBE.
66353 **
66354 ** The SQL parser generates a program which is then executed by
66355 ** the VDBE to do the work of the SQL statement. VDBE programs are
66356 ** similar in form to assembly language. The program consists of
66357 ** a linear sequence of operations. Each operation has an opcode
66358 ** and 5 operands. Operands P1, P2, and P3 are integers. Operand P4
66359 ** is a null-terminated string. Operand P5 is an unsigned character.
66360 ** Few opcodes use all 5 operands.
66361 **
66362 ** Computation results are stored on a set of registers numbered beginning
66363 ** with 1 and going up to Vdbe.nMem. Each register can store
66364 ** either an integer, a null-terminated string, a floating point
66365 ** number, or the SQL "NULL" value. An implicit conversion from one
66366 ** type to the other occurs as necessary.
66367 **
66368 ** Most of the code in this file is taken up by the sqlite3VdbeExec()
66369 ** function which does the work of interpreting a VDBE program.
66370 ** But other routines are also provided to help in building up
66371 ** a program instruction by instruction.
66372 **
66373 ** Various scripts scan this source file in order to generate HTML
66374 ** documentation, headers files, or other derived files. The formatting
66375 ** of the code in this file is, therefore, important. See other comments
66376 ** in this file for details. If in doubt, do not deviate from existing
@@ -66378,11 +66501,15 @@
66378 */
66379
66380 /*
66381 ** Invoke this macro on memory cells just prior to changing the
66382 ** value of the cell. This macro verifies that shallow copies are
66383 ** not misused.
 
 
 
 
66384 */
66385 #ifdef SQLITE_DEBUG
66386 # define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M)
66387 #else
66388 # define memAboutToChange(P,M)
@@ -66437,11 +66564,11 @@
66437 }
66438 }
66439 #endif
66440
66441 /*
66442 ** The next global variable is incremented each type the OP_Found opcode
66443 ** is executed. This is used to test whether or not the foreign key
66444 ** operation implemented using OP_FkIsZero is working. This variable
66445 ** has no function other than to help verify the correct operation of the
66446 ** library.
66447 */
@@ -66457,10 +66584,38 @@
66457 # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
66458 #else
66459 # define UPDATE_MAX_BLOBSIZE(P)
66460 #endif
66461
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66462 /*
66463 ** Convert the given register into a string if it isn't one
66464 ** already. Return non-zero if a malloc() fails.
66465 */
66466 #define Stringify(P, enc) \
@@ -66481,35 +66636,11 @@
66481 #define Deephemeralize(P) \
66482 if( ((P)->flags&MEM_Ephem)!=0 \
66483 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
66484
66485 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
66486 # define isSorter(x) ((x)->pSorter!=0)
66487
66488 /*
66489 ** Argument pMem points at a register that will be passed to a
66490 ** user-defined function or returned to the user as the result of a query.
66491 ** This routine sets the pMem->type variable used by the sqlite3_value_*()
66492 ** routines.
66493 */
66494 SQLITE_PRIVATE void sqlite3VdbeMemStoreType(Mem *pMem){
66495 int flags = pMem->flags;
66496 if( flags & MEM_Null ){
66497 pMem->type = SQLITE_NULL;
66498 }
66499 else if( flags & MEM_Int ){
66500 pMem->type = SQLITE_INTEGER;
66501 }
66502 else if( flags & MEM_Real ){
66503 pMem->type = SQLITE_FLOAT;
66504 }
66505 else if( flags & MEM_Str ){
66506 pMem->type = SQLITE_TEXT;
66507 }else{
66508 pMem->type = SQLITE_BLOB;
66509 }
66510 }
66511
66512 /*
66513 ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
66514 ** if we run out of memory.
66515 */
@@ -66635,16 +66766,18 @@
66635 ** into a numeric representation. Use either INTEGER or REAL whichever
66636 ** is appropriate. But only do the conversion if it is possible without
66637 ** loss of information and return the revised type of the argument.
66638 */
66639 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
66640 Mem *pMem = (Mem*)pVal;
66641 if( pMem->type==SQLITE_TEXT ){
 
66642 applyNumericAffinity(pMem);
66643 sqlite3VdbeMemStoreType(pMem);
 
66644 }
66645 return pMem->type;
66646 }
66647
66648 /*
66649 ** Exported version of applyAffinity(). This one works on sqlite3_value*,
66650 ** not the internal Mem* type.
@@ -66743,11 +66876,11 @@
66743 #ifdef SQLITE_DEBUG
66744 /*
66745 ** Print the value of a register for tracing purposes:
66746 */
66747 static void memTracePrint(Mem *p){
66748 if( p->flags & MEM_Invalid ){
66749 printf(" undefined");
66750 }else if( p->flags & MEM_Null ){
66751 printf(" NULL");
66752 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66753 printf(" si:%lld", p->u.i);
@@ -66875,24 +67008,10 @@
66875
66876 /************** End of hwtime.h **********************************************/
66877 /************** Continuing where we left off in vdbe.c ***********************/
66878
66879 #endif
66880
66881 /*
66882 ** The CHECK_FOR_INTERRUPT macro defined here looks to see if the
66883 ** sqlite3_interrupt() routine has been called. If it has been, then
66884 ** processing of the VDBE program is interrupted.
66885 **
66886 ** This macro added to every instruction that does a jump in order to
66887 ** implement a loop. This test used to be on every single instruction,
66888 ** but that meant we more testing than we needed. By only testing the
66889 ** flag on jump instructions, we get a (small) speed improvement.
66890 */
66891 #define CHECK_FOR_INTERRUPT \
66892 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
66893
66894
66895 #ifndef NDEBUG
66896 /*
66897 ** This function is only called from within an assert() expression. It
66898 ** checks that the sqlite3.nTransaction variable is correctly set to
@@ -66912,39 +67031,12 @@
66912 }
66913 #endif
66914
66915
66916 /*
66917 ** Execute as much of a VDBE program as we can then return.
66918 **
66919 ** sqlite3VdbeMakeReady() must be called before this routine in order to
66920 ** close the program with a final OP_Halt and to set up the callbacks
66921 ** and the error message pointer.
66922 **
66923 ** Whenever a row or result data is available, this routine will either
66924 ** invoke the result callback (if there is one) or return with
66925 ** SQLITE_ROW.
66926 **
66927 ** If an attempt is made to open a locked database, then this routine
66928 ** will either invoke the busy callback (if there is one) or it will
66929 ** return SQLITE_BUSY.
66930 **
66931 ** If an error occurs, an error message is written to memory obtained
66932 ** from sqlite3_malloc() and p->zErrMsg is made to point to that memory.
66933 ** The error code is stored in p->rc and this routine returns SQLITE_ERROR.
66934 **
66935 ** If the callback ever returns non-zero, then the program exits
66936 ** immediately. There will be no error message but the p->rc field is
66937 ** set to SQLITE_ABORT and this routine will return SQLITE_ERROR.
66938 **
66939 ** A memory allocation error causes p->rc to be set to SQLITE_NOMEM and this
66940 ** routine to return SQLITE_ERROR.
66941 **
66942 ** Other fatal errors return SQLITE_ERROR.
66943 **
66944 ** After this routine has finished, sqlite3VdbeFinalize() should be
66945 ** used to clean up the mess that was left behind.
66946 */
66947 SQLITE_PRIVATE int sqlite3VdbeExec(
66948 Vdbe *p /* The VDBE */
66949 ){
66950 int pc=0; /* The program counter */
@@ -66966,11 +67058,10 @@
66966 Mem *pOut = 0; /* Output operand */
66967 int *aPermute = 0; /* Permutation of columns for OP_Compare */
66968 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
66969 #ifdef VDBE_PROFILE
66970 u64 start; /* CPU clock count at start of opcode */
66971 int origPc; /* Program counter at start of opcode */
66972 #endif
66973 /*** INSERT STACK UNION HERE ***/
66974
66975 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
66976 sqlite3VdbeEnter(p);
@@ -66984,11 +67075,11 @@
66984 p->rc = SQLITE_OK;
66985 p->iCurrentTime = 0;
66986 assert( p->explain==0 );
66987 p->pResultSet = 0;
66988 db->busyHandler.nBusy = 0;
66989 CHECK_FOR_INTERRUPT;
66990 sqlite3VdbeIOTraceSql(p);
66991 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
66992 if( db->xProgress ){
66993 assert( 0 < db->nProgressOps );
66994 nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
@@ -67028,11 +67119,10 @@
67028 #endif
67029 for(pc=p->pc; rc==SQLITE_OK; pc++){
67030 assert( pc>=0 && pc<p->nOp );
67031 if( db->mallocFailed ) goto no_mem;
67032 #ifdef VDBE_PROFILE
67033 origPc = pc;
67034 start = sqlite3Hwtime();
67035 #endif
67036 nVmStep++;
67037 pOp = &aOp[pc];
67038
@@ -67160,11 +67250,11 @@
67160 ** But that is not due to sloppy coding habits. The code is written this
67161 ** way for performance, to avoid having to run the interrupt and progress
67162 ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
67163 ** faster according to "valgrind --tool=cachegrind" */
67164 check_for_interrupt:
67165 CHECK_FOR_INTERRUPT;
67166 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67167 /* Call the progress callback if it is configured and the required number
67168 ** of VDBE ops have been executed (either since this invocation of
67169 ** sqlite3VdbeExec() or since last time the progress callback was called).
67170 ** If the progress callback returns non-zero, exit the virtual machine with
@@ -67200,24 +67290,70 @@
67200 break;
67201 }
67202
67203 /* Opcode: Return P1 * * * *
67204 **
67205 ** Jump to the next instruction after the address in register P1.
 
67206 */
67207 case OP_Return: { /* in1 */
67208 pIn1 = &aMem[pOp->p1];
67209 assert( pIn1->flags & MEM_Int );
67210 pc = (int)pIn1->u.i;
 
67211 break;
67212 }
67213
67214 /* Opcode: Yield P1 * * * *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67215 **
67216 ** Swap the program counter with the value in register P1.
 
 
 
 
67217 */
67218 case OP_Yield: { /* in1 */
67219 int pcDest;
67220 pIn1 = &aMem[pOp->p1];
67221 assert( (pIn1->flags & MEM_Dyn)==0 );
67222 pIn1->flags = MEM_Int;
67223 pcDest = (int)pIn1->u.i;
@@ -67226,11 +67362,11 @@
67226 pc = pcDest;
67227 break;
67228 }
67229
67230 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67231 ** Synopsis: if r[P3] null then halt
67232 **
67233 ** Check the value in register P3. If it is NULL then Halt using
67234 ** parameter P1, P2, and P4 as if this were a Halt instruction. If the
67235 ** value in register P3 is not NULL, then this routine is a no-op.
67236 ** The P5 parameter should be 1.
@@ -67374,11 +67510,13 @@
67374
67375 /* Opcode: String8 * P2 * P4 *
67376 ** Synopsis: r[P2]='P4'
67377 **
67378 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
67379 ** into an OP_String before it is executed for the first time.
 
 
67380 */
67381 case OP_String8: { /* same as TK_STRING, out2-prerelease */
67382 assert( pOp->p4.z!=0 );
67383 pOp->opcode = OP_String;
67384 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
@@ -67448,12 +67586,26 @@
67448 cnt--;
67449 }
67450 break;
67451 }
67452
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67453
67454 /* Opcode: Blob P1 P2 * P4
67455 ** Synopsis: r[P2]=P4 (len=P1)
67456 **
67457 ** P4 points to a blob of data P1 bytes long. Store this
67458 ** blob in register P2.
67459 */
@@ -67468,11 +67620,11 @@
67468 /* Opcode: Variable P1 P2 * P4 *
67469 ** Synopsis: r[P2]=parameter(P1,P4)
67470 **
67471 ** Transfer the values of bound parameter P1 into register P2
67472 **
67473 ** If the parameter is named, then its name appears in P4 and P3==1.
67474 ** The P4 value is used by sqlite3_bind_parameter_name().
67475 */
67476 case OP_Variable: { /* out2-prerelease */
67477 Mem *pVar; /* Value being transferred */
67478
@@ -67587,12 +67739,12 @@
67587 ** Synopsis: output=r[P1@P2]
67588 **
67589 ** The registers P1 through P1+P2-1 contain a single row of
67590 ** results. This opcode causes the sqlite3_step() call to terminate
67591 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67592 ** structure to provide access to the top P1 values as the result
67593 ** row.
67594 */
67595 case OP_ResultRow: {
67596 Mem *pMem;
67597 int i;
67598 assert( p->nResColumn==pOp->p2 );
@@ -68078,10 +68230,11 @@
68078 */
68079 case OP_MustBeInt: { /* jump, in1 */
68080 pIn1 = &aMem[pOp->p1];
68081 if( (pIn1->flags & MEM_Int)==0 ){
68082 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
 
68083 if( (pIn1->flags & MEM_Int)==0 ){
68084 if( pOp->p2==0 ){
68085 rc = SQLITE_MISMATCH;
68086 goto abort_due_to_error;
68087 }else{
@@ -68116,11 +68269,11 @@
68116 #ifndef SQLITE_OMIT_CAST
68117 /* Opcode: ToText P1 * * * *
68118 **
68119 ** Force the value in register P1 to be text.
68120 ** If the value is numeric, convert it to a string using the
68121 ** equivalent of printf(). Blob values are unchanged and
68122 ** are afterwards simply interpreted as text.
68123 **
68124 ** A NULL value is not changed by this routine. It remains NULL.
68125 */
68126 case OP_ToText: { /* same as TK_TO_TEXT, in1 */
@@ -68318,10 +68471,11 @@
68318 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68319 ** or not both operands are null.
68320 */
68321 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68322 assert( (flags1 & MEM_Cleared)==0 );
 
68323 if( (flags1&MEM_Null)!=0
68324 && (flags3&MEM_Null)!=0
68325 && (flags3&MEM_Cleared)==0
68326 ){
68327 res = 0; /* Results are equal */
@@ -68331,16 +68485,19 @@
68331 }else{
68332 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68333 ** then the result is always NULL.
68334 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
68335 */
68336 if( pOp->p5 & SQLITE_JUMPIFNULL ){
68337 pc = pOp->p2-1;
68338 }else if( pOp->p5 & SQLITE_STOREP2 ){
68339 pOut = &aMem[pOp->p2];
68340 MemSetTypeFlag(pOut, MEM_Null);
68341 REGISTER_TRACE(pOp->p2, pOut);
 
 
 
 
 
68342 }
68343 break;
68344 }
68345 }else{
68346 /* Neither operand is NULL. Do a comparison. */
@@ -68369,14 +68526,16 @@
68369 pOut = &aMem[pOp->p2];
68370 memAboutToChange(p, pOut);
68371 MemSetTypeFlag(pOut, MEM_Int);
68372 pOut->u.i = res;
68373 REGISTER_TRACE(pOp->p2, pOut);
68374 }else if( res ){
68375 pc = pOp->p2-1;
 
 
 
68376 }
68377
68378 /* Undo any changes made by applyAffinity() to the input registers. */
68379 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68380 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
68381 break;
68382 }
@@ -68469,15 +68628,15 @@
68469 ** in the most recent OP_Compare instruction the P1 vector was less than
68470 ** equal to, or greater than the P2 vector, respectively.
68471 */
68472 case OP_Jump: { /* jump */
68473 if( iCompare<0 ){
68474 pc = pOp->p1 - 1;
68475 }else if( iCompare==0 ){
68476 pc = pOp->p2 - 1;
68477 }else{
68478 pc = pOp->p3 - 1;
68479 }
68480 break;
68481 }
68482
68483 /* Opcode: And P1 P2 P3 * *
@@ -68571,14 +68730,17 @@
68571 }
68572
68573 /* Opcode: Once P1 P2 * * *
68574 **
68575 ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
68576 ** set the flag and fall through to the next instruction.
 
 
68577 */
68578 case OP_Once: { /* jump */
68579 assert( pOp->p1<p->nOnceFlag );
 
68580 if( p->aOnceFlag[pOp->p1] ){
68581 pc = pOp->p2-1;
68582 }else{
68583 p->aOnceFlag[pOp->p1] = 1;
68584 }
@@ -68609,10 +68771,11 @@
68609 #else
68610 c = sqlite3VdbeRealValue(pIn1)!=0.0;
68611 #endif
68612 if( pOp->opcode==OP_IfNot ) c = !c;
68613 }
 
68614 if( c ){
68615 pc = pOp->p2-1;
68616 }
68617 break;
68618 }
@@ -68622,10 +68785,11 @@
68622 **
68623 ** Jump to P2 if the value in register P1 is NULL.
68624 */
68625 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
68626 pIn1 = &aMem[pOp->p1];
 
68627 if( (pIn1->flags & MEM_Null)!=0 ){
68628 pc = pOp->p2 - 1;
68629 }
68630 break;
68631 }
@@ -68635,10 +68799,11 @@
68635 **
68636 ** Jump to P2 if the value in register P1 is not NULL.
68637 */
68638 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
68639 pIn1 = &aMem[pOp->p1];
 
68640 if( (pIn1->flags & MEM_Null)==0 ){
68641 pc = pOp->p2 - 1;
68642 }
68643 break;
68644 }
@@ -68711,15 +68876,10 @@
68711 if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68712 if( pC->nullRow ){
68713 if( pCrsr==0 ){
68714 assert( pC->pseudoTableReg>0 );
68715 pReg = &aMem[pC->pseudoTableReg];
68716 if( pC->multiPseudo ){
68717 sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem);
68718 Deephemeralize(pDest);
68719 goto op_column_out;
68720 }
68721 assert( pReg->flags & MEM_Blob );
68722 assert( memIsValid(pReg) );
68723 pC->payloadSize = pC->szRow = avail = pReg->n;
68724 pC->aRow = (u8*)pReg->z;
68725 }else{
@@ -68941,11 +69101,10 @@
68941 assert( zAffinity[pOp->p2]==0 );
68942 pIn1 = &aMem[pOp->p1];
68943 while( (cAff = *(zAffinity++))!=0 ){
68944 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
68945 assert( memIsValid(pIn1) );
68946 ExpandBlob(pIn1);
68947 applyAffinity(pIn1, cAff, encoding);
68948 pIn1++;
68949 }
68950 break;
68951 }
@@ -69019,12 +69178,13 @@
69019 */
69020 assert( pData0<=pLast );
69021 if( zAffinity ){
69022 pRec = pData0;
69023 do{
69024 applyAffinity(pRec, *(zAffinity++), encoding);
69025 }while( (++pRec)<=pLast );
 
69026 }
69027
69028 /* Loop through the elements that will make up the record to figure
69029 ** out how much space is required for the new record.
69030 */
@@ -69364,29 +69524,23 @@
69364 rc = SQLITE_ERROR;
69365 }
69366 break;
69367 }
69368
69369 /* Opcode: Transaction P1 P2 * * *
69370 **
69371 ** Begin a transaction. The transaction ends when a Commit or Rollback
69372 ** opcode is encountered. Depending on the ON CONFLICT setting, the
69373 ** transaction might also be rolled back if an error is encountered.
 
 
69374 **
69375 ** P1 is the index of the database file on which the transaction is
69376 ** started. Index 0 is the main database file and index 1 is the
69377 ** file used for temporary tables. Indices of 2 or more are used for
69378 ** attached databases.
69379 **
69380 ** If P2 is non-zero, then a write-transaction is started. A RESERVED lock is
69381 ** obtained on the database file when a write-transaction is started. No
69382 ** other process can start another write transaction while this transaction is
69383 ** underway. Starting a write transaction also creates a rollback journal. A
69384 ** write transaction must be started before any changes can be made to the
69385 ** database. If P2 is greater than or equal to 2 then an EXCLUSIVE lock is
69386 ** also obtained on the file.
69387 **
69388 ** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
69389 ** true (this flag is set if the Vdbe may modify more than one row and may
69390 ** throw an ABORT exception), a statement transaction may also be opened.
69391 ** More specifically, a statement transaction is opened iff the database
69392 ** connection is currently not in autocommit mode, or if there are other
@@ -69393,14 +69547,25 @@
69393 ** active statements. A statement transaction allows the changes made by this
69394 ** VDBE to be rolled back after an error without having to roll back the
69395 ** entire transaction. If no error is encountered, the statement transaction
69396 ** will automatically commit when the VDBE halts.
69397 **
69398 ** If P2 is zero, then a read-lock is obtained on the database file.
 
 
 
 
 
 
 
 
 
69399 */
69400 case OP_Transaction: {
69401 Btree *pBt;
 
 
69402
69403 assert( p->bIsReader );
69404 assert( p->readOnly==0 || pOp->p2==0 );
69405 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69406 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
@@ -69440,10 +69605,39 @@
69440 ** counter. If the statement transaction needs to be rolled back,
69441 ** the value of this counter needs to be restored too. */
69442 p->nStmtDefCons = db->nDeferredCons;
69443 p->nStmtDefImmCons = db->nDeferredImmCons;
69444 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69445 }
69446 break;
69447 }
69448
69449 /* Opcode: ReadCookie P1 P2 P3 * *
@@ -69511,70 +69705,10 @@
69511 /* Invalidate all prepared statements whenever the TEMP database
69512 ** schema is changed. Ticket #1644 */
69513 sqlite3ExpirePreparedStatements(db);
69514 p->expired = 0;
69515 }
69516 break;
69517 }
69518
69519 /* Opcode: VerifyCookie P1 P2 P3 * *
69520 **
69521 ** Check the value of global database parameter number 0 (the
69522 ** schema version) and make sure it is equal to P2 and that the
69523 ** generation counter on the local schema parse equals P3.
69524 **
69525 ** P1 is the database number which is 0 for the main database file
69526 ** and 1 for the file holding temporary tables and some higher number
69527 ** for auxiliary databases.
69528 **
69529 ** The cookie changes its value whenever the database schema changes.
69530 ** This operation is used to detect when that the cookie has changed
69531 ** and that the current process needs to reread the schema.
69532 **
69533 ** Either a transaction needs to have been started or an OP_Open needs
69534 ** to be executed (to establish a read lock) before this opcode is
69535 ** invoked.
69536 */
69537 case OP_VerifyCookie: {
69538 int iMeta;
69539 int iGen;
69540 Btree *pBt;
69541
69542 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69543 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
69544 assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) );
69545 assert( p->bIsReader );
69546 pBt = db->aDb[pOp->p1].pBt;
69547 if( pBt ){
69548 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69549 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69550 }else{
69551 iGen = iMeta = 0;
69552 }
69553 if( iMeta!=pOp->p2 || iGen!=pOp->p3 ){
69554 sqlite3DbFree(db, p->zErrMsg);
69555 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69556 /* If the schema-cookie from the database file matches the cookie
69557 ** stored with the in-memory representation of the schema, do
69558 ** not reload the schema from the database file.
69559 **
69560 ** If virtual-tables are in use, this is not just an optimization.
69561 ** Often, v-tables store their data in other SQLite tables, which
69562 ** are queried from within xNext() and other v-table methods using
69563 ** prepared queries. If such a query is out-of-date, we do not want to
69564 ** discard the database schema, as the user code implementing the
69565 ** v-table would have to be ready for the sqlite3_vtab structure itself
69566 ** to be invalidated whenever sqlite3_step() is called from within
69567 ** a v-table method.
69568 */
69569 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69570 sqlite3ResetOneSchema(db, pOp->p1);
69571 }
69572
69573 p->expired = 1;
69574 rc = SQLITE_SCHEMA;
69575 }
69576 break;
69577 }
69578
69579 /* Opcode: OpenRead P1 P2 P3 P4 P5
69580 ** Synopsis: root=P2 iDb=P3
@@ -69787,11 +69921,11 @@
69787 }
69788 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69789 break;
69790 }
69791
69792 /* Opcode: SorterOpen P1 * * P4 *
69793 **
69794 ** This opcode works like OP_OpenEphemeral except that it opens
69795 ** a transient index that is specifically designed to sort large
69796 ** tables using an external merge-sort algorithm.
69797 */
@@ -69807,18 +69941,17 @@
69807 assert( pCx->pKeyInfo->enc==ENC(db) );
69808 rc = sqlite3VdbeSorterInit(db, pCx);
69809 break;
69810 }
69811
69812 /* Opcode: OpenPseudo P1 P2 P3 * P5
69813 ** Synopsis: content in r[P2@P3]
69814 **
69815 ** Open a new cursor that points to a fake table that contains a single
69816 ** row of data. The content of that one row in the content of memory
69817 ** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
69818 ** MEM_Blob content contained in register P2. When P5==1, then the
69819 ** row is represented by P3 consecutive registers beginning with P2.
69820 **
69821 ** A pseudo-table created by this opcode is used to hold a single
69822 ** row output from the sorter so that the row can be decomposed into
69823 ** individual columns using the OP_Column opcode. The OP_Column opcode
69824 ** is the only cursor opcode that works with a pseudo-table.
@@ -69834,11 +69967,11 @@
69834 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69835 if( pCx==0 ) goto no_mem;
69836 pCx->nullRow = 1;
69837 pCx->pseudoTableReg = pOp->p2;
69838 pCx->isTable = 1;
69839 pCx->multiPseudo = pOp->p5;
69840 break;
69841 }
69842
69843 /* Opcode: Close P1 * * * *
69844 **
@@ -69906,14 +70039,14 @@
69906 ** is less than or equal to the key value. If there are no records
69907 ** less than or equal to the key and P2 is not zero, then jump to P2.
69908 **
69909 ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt
69910 */
69911 case OP_SeekLt: /* jump, in3 */
69912 case OP_SeekLe: /* jump, in3 */
69913 case OP_SeekGe: /* jump, in3 */
69914 case OP_SeekGt: { /* jump, in3 */
69915 int res;
69916 int oc;
69917 VdbeCursor *pC;
69918 UnpackedRecord r;
69919 int nField;
@@ -69922,13 +70055,13 @@
69922 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
69923 assert( pOp->p2!=0 );
69924 pC = p->apCsr[pOp->p1];
69925 assert( pC!=0 );
69926 assert( pC->pseudoTableReg==0 );
69927 assert( OP_SeekLe == OP_SeekLt+1 );
69928 assert( OP_SeekGe == OP_SeekLt+2 );
69929 assert( OP_SeekGt == OP_SeekLt+3 );
69930 assert( pC->isOrdered );
69931 assert( pC->pCursor!=0 );
69932 oc = pOp->opcode;
69933 pC->nullRow = 0;
69934 if( pC->isTable ){
@@ -69944,11 +70077,11 @@
69944 ** loss of information, then special processing is required... */
69945 if( (pIn3->flags & MEM_Int)==0 ){
69946 if( (pIn3->flags & MEM_Real)==0 ){
69947 /* If the P3 value cannot be converted into any kind of a number,
69948 ** then the seek is not possible, so jump to P2 */
69949 pc = pOp->p2 - 1;
69950 break;
69951 }
69952
69953 /* If the approximation iKey is larger than the actual real search
69954 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -69956,23 +70089,23 @@
69956 **
69957 ** (x > 4.9) -> (x >= 5)
69958 ** (x <= 4.9) -> (x < 5)
69959 */
69960 if( pIn3->r<(double)iKey ){
69961 assert( OP_SeekGe==(OP_SeekGt-1) );
69962 assert( OP_SeekLt==(OP_SeekLe-1) );
69963 assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) );
69964 if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--;
69965 }
69966
69967 /* If the approximation iKey is smaller than the actual real search
69968 ** term, substitute <= for < and > for >=. */
69969 else if( pIn3->r>(double)iKey ){
69970 assert( OP_SeekLe==(OP_SeekLt+1) );
69971 assert( OP_SeekGt==(OP_SeekGe+1) );
69972 assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) );
69973 if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++;
69974 }
69975 }
69976 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
69977 if( rc!=SQLITE_OK ){
69978 goto abort_due_to_error;
@@ -69987,21 +70120,21 @@
69987 assert( nField>0 );
69988 r.pKeyInfo = pC->pKeyInfo;
69989 r.nField = (u16)nField;
69990
69991 /* The next line of code computes as follows, only faster:
69992 ** if( oc==OP_SeekGt || oc==OP_SeekLe ){
69993 ** r.flags = UNPACKED_INCRKEY;
69994 ** }else{
69995 ** r.flags = 0;
69996 ** }
69997 */
69998 r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLt)));
69999 assert( oc!=OP_SeekGt || r.flags==UNPACKED_INCRKEY );
70000 assert( oc!=OP_SeekLe || r.flags==UNPACKED_INCRKEY );
70001 assert( oc!=OP_SeekGe || r.flags==0 );
70002 assert( oc!=OP_SeekLt || r.flags==0 );
70003
70004 r.aMem = &aMem[pOp->p3];
70005 #ifdef SQLITE_DEBUG
70006 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70007 #endif
@@ -70015,21 +70148,23 @@
70015 pC->deferredMoveto = 0;
70016 pC->cacheStatus = CACHE_STALE;
70017 #ifdef SQLITE_TEST
70018 sqlite3_search_count++;
70019 #endif
70020 if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt );
70021 if( res<0 || (res==0 && oc==OP_SeekGt) ){
 
70022 rc = sqlite3BtreeNext(pC->pCursor, &res);
70023 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70024 pC->rowidIsValid = 0;
70025 }else{
70026 res = 0;
70027 }
70028 }else{
70029 assert( oc==OP_SeekLt || oc==OP_SeekLe );
70030 if( res>0 || (res==0 && oc==OP_SeekLt) ){
 
70031 rc = sqlite3BtreePrevious(pC->pCursor, &res);
70032 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70033 pC->rowidIsValid = 0;
70034 }else{
70035 /* res might be negative because the table is empty. Check to
@@ -70037,10 +70172,11 @@
70037 */
70038 res = sqlite3BtreeEof(pC->pCursor);
70039 }
70040 }
70041 assert( pOp->p2>0 );
 
70042 if( res ){
70043 pc = pOp->p2 - 1;
70044 }
70045 break;
70046 }
@@ -70145,19 +70281,17 @@
70145 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
70146 if( pOp->p4.i>0 ){
70147 r.pKeyInfo = pC->pKeyInfo;
70148 r.nField = (u16)pOp->p4.i;
70149 r.aMem = pIn3;
 
 
 
70150 #ifdef SQLITE_DEBUG
70151 {
70152 int i;
70153 for(i=0; i<r.nField; i++){
70154 assert( memIsValid(&r.aMem[i]) );
70155 if( i ) REGISTER_TRACE(pOp->p3+i, &r.aMem[i]);
70156 }
70157 }
70158 #endif
70159 r.flags = UNPACKED_PREFIX_MATCH;
70160 pIdxKey = &r;
70161 }else{
70162 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70163 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
@@ -70172,11 +70306,11 @@
70172 /* For the OP_NoConflict opcode, take the jump if any of the
70173 ** input fields are NULL, since any key with a NULL will not
70174 ** conflict */
70175 for(ii=0; ii<r.nField; ii++){
70176 if( r.aMem[ii].flags & MEM_Null ){
70177 pc = pOp->p2 - 1;
70178 break;
70179 }
70180 }
70181 }
70182 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
@@ -70190,12 +70324,14 @@
70190 alreadyExists = (res==0);
70191 pC->nullRow = 1-alreadyExists;
70192 pC->deferredMoveto = 0;
70193 pC->cacheStatus = CACHE_STALE;
70194 if( pOp->opcode==OP_Found ){
 
70195 if( alreadyExists ) pc = pOp->p2 - 1;
70196 }else{
 
70197 if( !alreadyExists ) pc = pOp->p2 - 1;
70198 }
70199 break;
70200 }
70201
@@ -70234,10 +70370,11 @@
70234 pC->lastRowid = pIn3->u.i;
70235 pC->rowidIsValid = res==0 ?1:0;
70236 pC->nullRow = 0;
70237 pC->cacheStatus = CACHE_STALE;
70238 pC->deferredMoveto = 0;
 
70239 if( res!=0 ){
70240 pc = pOp->p2 - 1;
70241 assert( pC->rowidIsValid==0 );
70242 }
70243 pC->seekResult = res;
@@ -70315,63 +70452,58 @@
70315 */
70316 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70317 #endif
70318
70319 if( !pC->useRandomRowid ){
70320 v = sqlite3BtreeGetCachedRowid(pC->pCursor);
70321 if( v==0 ){
70322 rc = sqlite3BtreeLast(pC->pCursor, &res);
70323 if( rc!=SQLITE_OK ){
70324 goto abort_due_to_error;
70325 }
70326 if( res ){
70327 v = 1; /* IMP: R-61914-48074 */
70328 }else{
70329 assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70330 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70331 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70332 if( v>=MAX_ROWID ){
70333 pC->useRandomRowid = 1;
70334 }else{
70335 v++; /* IMP: R-29538-34987 */
70336 }
70337 }
70338 }
70339
70340 #ifndef SQLITE_OMIT_AUTOINCREMENT
70341 if( pOp->p3 ){
70342 /* Assert that P3 is a valid memory cell. */
70343 assert( pOp->p3>0 );
70344 if( p->pFrame ){
70345 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70346 /* Assert that P3 is a valid memory cell. */
70347 assert( pOp->p3<=pFrame->nMem );
70348 pMem = &pFrame->aMem[pOp->p3];
70349 }else{
70350 /* Assert that P3 is a valid memory cell. */
70351 assert( pOp->p3<=(p->nMem-p->nCursor) );
70352 pMem = &aMem[pOp->p3];
70353 memAboutToChange(p, pMem);
70354 }
70355 assert( memIsValid(pMem) );
70356
70357 REGISTER_TRACE(pOp->p3, pMem);
70358 sqlite3VdbeMemIntegerify(pMem);
70359 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70360 if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70361 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70362 goto abort_due_to_error;
70363 }
70364 if( v<pMem->u.i+1 ){
70365 v = pMem->u.i + 1;
70366 }
70367 pMem->u.i = v;
70368 }
70369 #endif
70370
70371 sqlite3BtreeSetCachedRowid(pC->pCursor, v<MAX_ROWID ? v+1 : 0);
70372 }
70373 if( pC->useRandomRowid ){
70374 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70375 ** largest possible integer (9223372036854775807) then the database
70376 ** engine starts picking positive candidate ROWIDs at random until
70377 ** it finds one that is not previously used. */
@@ -70501,11 +70633,10 @@
70501 if( pData->flags & MEM_Zero ){
70502 nZero = pData->u.nZero;
70503 }else{
70504 nZero = 0;
70505 }
70506 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70507 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
70508 pData->z, pData->n, nZero,
70509 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
70510 );
70511 pC->rowidIsValid = 0;
@@ -70563,11 +70694,10 @@
70563 **/
70564 assert( pC->deferredMoveto==0 );
70565 rc = sqlite3VdbeCursorMoveto(pC);
70566 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70567
70568 sqlite3BtreeSetCachedRowid(pC->pCursor, 0);
70569 rc = sqlite3BtreeDelete(pC->pCursor);
70570 pC->cacheStatus = CACHE_STALE;
70571
70572 /* Invoke the update-hook if required. */
70573 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
@@ -70615,10 +70745,11 @@
70615 assert( isSorter(pC) );
70616 assert( pOp->p4type==P4_INT32 );
70617 pIn3 = &aMem[pOp->p3];
70618 nIgnore = pOp->p4.i;
70619 rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
 
70620 if( res ){
70621 pc = pOp->p2-1;
70622 }
70623 break;
70624 };
@@ -70652,11 +70783,11 @@
70652 /* Opcode: RowKey P1 P2 * * *
70653 ** Synopsis: r[P2]=key
70654 **
70655 ** Write into register P2 the complete row key for cursor P1.
70656 ** There is no interpretation of the data.
70657 ** The key is copied onto the P3 register exactly as
70658 ** it is found in the database file.
70659 **
70660 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70661 ** of a real table, not a pseudo-table.
70662 */
@@ -70814,12 +70945,13 @@
70814 rc = sqlite3BtreeLast(pCrsr, &res);
70815 pC->nullRow = (u8)res;
70816 pC->deferredMoveto = 0;
70817 pC->rowidIsValid = 0;
70818 pC->cacheStatus = CACHE_STALE;
70819 if( pOp->p2>0 && res ){
70820 pc = pOp->p2 - 1;
 
70821 }
70822 break;
70823 }
70824
70825
@@ -70872,56 +71004,67 @@
70872 pC->cacheStatus = CACHE_STALE;
70873 pC->rowidIsValid = 0;
70874 }
70875 pC->nullRow = (u8)res;
70876 assert( pOp->p2>0 && pOp->p2<p->nOp );
 
70877 if( res ){
70878 pc = pOp->p2 - 1;
70879 }
70880 break;
70881 }
70882
70883 /* Opcode: Next P1 P2 * * P5
70884 **
70885 ** Advance cursor P1 so that it points to the next key/data pair in its
70886 ** table or index. If there are no more key/value pairs then fall through
70887 ** to the following instruction. But if the cursor advance was successful,
70888 ** jump immediately to P2.
70889 **
70890 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
70891 ** been opened prior to this opcode or the program will segfault.
 
 
 
 
 
70892 **
70893 ** P4 is always of type P4_ADVANCE. The function pointer points to
70894 ** sqlite3BtreeNext().
70895 **
70896 ** If P5 is positive and the jump is taken, then event counter
70897 ** number P5-1 in the prepared statement is incremented.
70898 **
70899 ** See also: Prev, NextIfOpen
70900 */
70901 /* Opcode: NextIfOpen P1 P2 * * P5
70902 **
70903 ** This opcode works just like OP_Next except that if cursor P1 is not
70904 ** open it behaves a no-op.
70905 */
70906 /* Opcode: Prev P1 P2 * * P5
70907 **
70908 ** Back up cursor P1 so that it points to the previous key/data pair in its
70909 ** table or index. If there is no previous key/value pairs then fall through
70910 ** to the following instruction. But if the cursor backup was successful,
70911 ** jump immediately to P2.
70912 **
70913 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
70914 ** not open then the behavior is undefined.
 
 
 
 
 
70915 **
70916 ** P4 is always of type P4_ADVANCE. The function pointer points to
70917 ** sqlite3BtreePrevious().
70918 **
70919 ** If P5 is positive and the jump is taken, then event counter
70920 ** number P5-1 in the prepared statement is incremented.
70921 */
70922 /* Opcode: PrevIfOpen P1 P2 * * P5
70923 **
70924 ** This opcode works just like OP_Prev except that if cursor P1 is not
70925 ** open it behaves a no-op.
70926 */
70927 case OP_SorterNext: { /* jump */
@@ -70939,20 +71082,24 @@
70939 case OP_Prev: /* jump */
70940 case OP_Next: /* jump */
70941 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70942 assert( pOp->p5<ArraySize(p->aCounter) );
70943 pC = p->apCsr[pOp->p1];
 
70944 assert( pC!=0 );
70945 assert( pC->deferredMoveto==0 );
70946 assert( pC->pCursor );
 
 
70947 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
70948 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
70949 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
70950 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
70951 rc = pOp->p4.xAdvance(pC->pCursor, &res);
70952 next_tail:
70953 pC->cacheStatus = CACHE_STALE;
 
70954 if( res==0 ){
70955 pC->nullRow = 0;
70956 pc = pOp->p2 - 1;
70957 p->aCounter[pOp->p5]++;
70958 #ifdef SQLITE_TEST
@@ -70972,10 +71119,18 @@
70972 ** MakeRecord instructions. This opcode writes that key
70973 ** into the index P1. Data for the entry is nil.
70974 **
70975 ** P3 is a flag that provides a hint to the b-tree layer that this
70976 ** insert is likely to be an append.
 
 
 
 
 
 
 
 
70977 **
70978 ** This instruction only works for indices. The equivalent instruction
70979 ** for tables is OP_Insert.
70980 */
70981 case OP_SorterInsert: /* in2 */
@@ -71087,36 +71242,54 @@
71087
71088 /* Opcode: IdxGE P1 P2 P3 P4 P5
71089 ** Synopsis: key=r[P3@P4]
71090 **
71091 ** The P4 register values beginning with P3 form an unpacked index
71092 ** key that omits the ROWID. Compare this key value against the index
71093 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
 
71094 **
71095 ** If the P1 index entry is greater than or equal to the key value
71096 ** then jump to P2. Otherwise fall through to the next instruction.
 
 
 
71097 **
71098 ** If P5 is non-zero then the key value is increased by an epsilon
71099 ** prior to the comparison. This make the opcode work like IdxGT except
71100 ** that if the key from register P3 is a prefix of the key in the cursor,
71101 ** the result is false whereas it would be true with IdxGT.
 
 
 
71102 */
71103 /* Opcode: IdxLT P1 P2 P3 P4 P5
71104 ** Synopsis: key=r[P3@P4]
71105 **
71106 ** The P4 register values beginning with P3 form an unpacked index
71107 ** key that omits the ROWID. Compare this key value against the index
71108 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
 
71109 **
71110 ** If the P1 index entry is less than the key value then jump to P2.
71111 ** Otherwise fall through to the next instruction.
 
 
 
71112 **
71113 ** If P5 is non-zero then the key value is increased by an epsilon prior
71114 ** to the comparison. This makes the opcode work like IdxLE.
 
 
 
 
 
71115 */
 
 
71116 case OP_IdxLT: /* jump */
71117 case OP_IdxGE: { /* jump */
71118 VdbeCursor *pC;
71119 int res;
71120 UnpackedRecord r;
71121
71122 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -71127,27 +71300,32 @@
71127 assert( pC->deferredMoveto==0 );
71128 assert( pOp->p5==0 || pOp->p5==1 );
71129 assert( pOp->p4type==P4_INT32 );
71130 r.pKeyInfo = pC->pKeyInfo;
71131 r.nField = (u16)pOp->p4.i;
71132 if( pOp->p5 ){
 
71133 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71134 }else{
 
71135 r.flags = UNPACKED_PREFIX_MATCH;
71136 }
71137 r.aMem = &aMem[pOp->p3];
71138 #ifdef SQLITE_DEBUG
71139 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71140 #endif
71141 res = 0; /* Not needed. Only used to silence a warning. */
71142 rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
71143 if( pOp->opcode==OP_IdxLT ){
 
 
71144 res = -res;
71145 }else{
71146 assert( pOp->opcode==OP_IdxGE );
71147 res++;
71148 }
 
71149 if( res>0 ){
71150 pc = pOp->p2 - 1 ;
71151 }
71152 break;
71153 }
@@ -71236,11 +71414,10 @@
71236 case OP_Clear: {
71237 int nChange;
71238
71239 nChange = 0;
71240 assert( p->readOnly==0 );
71241 assert( pOp->p1!=1 );
71242 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
71243 rc = sqlite3BtreeClearTable(
71244 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
71245 );
71246 if( pOp->p3 ){
@@ -71505,13 +71682,15 @@
71505 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
71506 ){
71507 /* The boolean index is empty */
71508 sqlite3VdbeMemSetNull(pIn1);
71509 pc = pOp->p2 - 1;
 
71510 }else{
71511 /* A value was pulled from the index */
71512 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
 
71513 }
71514 goto check_for_interrupt;
71515 }
71516
71517 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71559,10 +71738,11 @@
71559 assert( iSet==-1 || iSet>=0 );
71560 if( iSet ){
71561 exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71562 (u8)(iSet>=0 ? iSet & 0xf : 0xff),
71563 pIn3->u.i);
 
71564 if( exists ){
71565 pc = pOp->p2 - 1;
71566 break;
71567 }
71568 }
@@ -71573,11 +71753,11 @@
71573 }
71574
71575
71576 #ifndef SQLITE_OMIT_TRIGGER
71577
71578 /* Opcode: Program P1 P2 P3 P4 *
71579 **
71580 ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
71581 **
71582 ** P1 contains the address of the memory cell that contains the first memory
71583 ** cell in an array of values used as arguments to the sub-program. P2
@@ -71585,10 +71765,12 @@
71585 ** exception using the RAISE() function. Register P3 contains the address
71586 ** of a memory cell in this (the parent) VM that is used to allocate the
71587 ** memory required by the sub-vdbe at runtime.
71588 **
71589 ** P4 is a pointer to the VM containing the trigger program.
 
 
71590 */
71591 case OP_Program: { /* jump */
71592 int nMem; /* Number of memory registers for sub-program */
71593 int nByte; /* Bytes of runtime space required for sub-program */
71594 Mem *pRt; /* Register to allocate runtime space */
@@ -71662,11 +71844,11 @@
71662 pFrame->aOnceFlag = p->aOnceFlag;
71663 pFrame->nOnceFlag = p->nOnceFlag;
71664
71665 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
71666 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71667 pMem->flags = MEM_Invalid;
71668 pMem->db = db;
71669 }
71670 }else{
71671 pFrame = pRt->u.pFrame;
71672 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
@@ -71749,12 +71931,14 @@
71749 ** zero, the jump is taken if the statement constraint-counter is zero
71750 ** (immediate foreign key constraint violations).
71751 */
71752 case OP_FkIfZero: { /* jump */
71753 if( pOp->p1 ){
 
71754 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
71755 }else{
 
71756 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
71757 }
71758 break;
71759 }
71760 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
@@ -71799,10 +71983,11 @@
71799 ** not contain an integer. An assertion fault will result if you try.
71800 */
71801 case OP_IfPos: { /* jump, in1 */
71802 pIn1 = &aMem[pOp->p1];
71803 assert( pIn1->flags&MEM_Int );
 
71804 if( pIn1->u.i>0 ){
71805 pc = pOp->p2 - 1;
71806 }
71807 break;
71808 }
@@ -71816,10 +72001,11 @@
71816 ** not contain an integer. An assertion fault will result if you try.
71817 */
71818 case OP_IfNeg: { /* jump, in1 */
71819 pIn1 = &aMem[pOp->p1];
71820 assert( pIn1->flags&MEM_Int );
 
71821 if( pIn1->u.i<0 ){
71822 pc = pOp->p2 - 1;
71823 }
71824 break;
71825 }
@@ -71835,10 +72021,11 @@
71835 */
71836 case OP_IfZero: { /* jump, in1 */
71837 pIn1 = &aMem[pOp->p1];
71838 assert( pIn1->flags&MEM_Int );
71839 pIn1->u.i += pOp->p3;
 
71840 if( pIn1->u.i==0 ){
71841 pc = pOp->p2 - 1;
71842 }
71843 break;
71844 }
@@ -71972,11 +72159,11 @@
71972 break;
71973 };
71974 #endif
71975
71976 #ifndef SQLITE_OMIT_PRAGMA
71977 /* Opcode: JournalMode P1 P2 P3 * P5
71978 **
71979 ** Change the journal mode of database P1 to P3. P3 must be one of the
71980 ** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
71981 ** modes (delete, truncate, persist, off and memory), this is a simple
71982 ** operation. No IO is required.
@@ -72106,10 +72293,11 @@
72106 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72107 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72108 assert( p->readOnly==0 );
72109 pBt = db->aDb[pOp->p1].pBt;
72110 rc = sqlite3BtreeIncrVacuum(pBt);
 
72111 if( rc==SQLITE_DONE ){
72112 pc = pOp->p2 - 1;
72113 rc = SQLITE_OK;
72114 }
72115 break;
@@ -72312,11 +72500,11 @@
72312 p->inVtabMethod = 0;
72313 sqlite3VtabImportErrmsg(p, pVtab);
72314 if( rc==SQLITE_OK ){
72315 res = pModule->xEof(pVtabCursor);
72316 }
72317
72318 if( res ){
72319 pc = pOp->p2 - 1;
72320 }
72321 }
72322 pCur->nullRow = 0;
@@ -72417,11 +72605,11 @@
72417 p->inVtabMethod = 0;
72418 sqlite3VtabImportErrmsg(p, pVtab);
72419 if( rc==SQLITE_OK ){
72420 res = pModule->xEof(pCur->pVtabCursor);
72421 }
72422
72423 if( !res ){
72424 /* If there is data, jump to P2 */
72425 pc = pOp->p2 - 1;
72426 }
72427 goto check_for_interrupt;
@@ -72458,11 +72646,11 @@
72458 break;
72459 }
72460 #endif
72461
72462 #ifndef SQLITE_OMIT_VIRTUALTABLE
72463 /* Opcode: VUpdate P1 P2 P3 P4 *
72464 ** Synopsis: data=r[P3@P2]
72465 **
72466 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72467 ** This opcode invokes the corresponding xUpdate method. P2 values
72468 ** are contiguous memory cells starting at P3 to pass to the xUpdate
@@ -72481,10 +72669,13 @@
72481 ** a row to delete.
72482 **
72483 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72484 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72485 ** is set to the value of the rowid for the row just inserted.
 
 
 
72486 */
72487 case OP_VUpdate: {
72488 sqlite3_vtab *pVtab;
72489 sqlite3_module *pModule;
72490 int nArg;
@@ -72569,20 +72760,30 @@
72569 break;
72570 }
72571 #endif
72572
72573
72574 #ifndef SQLITE_OMIT_TRACE
72575 /* Opcode: Trace * * * P4 *
 
 
 
72576 **
72577 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72578 ** the UTF-8 string contained in P4 is emitted on the trace callback.
 
 
 
72579 */
72580 case OP_Trace: {
72581 char *zTrace;
72582 char *z;
72583
 
 
 
 
72584 if( db->xTrace
72585 && !p->doingRerun
72586 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72587 ){
72588 z = sqlite3VdbeExpandSql(p, zTrace);
@@ -72604,13 +72805,13 @@
72604 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72605 ){
72606 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
72607 }
72608 #endif /* SQLITE_DEBUG */
 
72609 break;
72610 }
72611 #endif
72612
72613
72614 /* Opcode: Noop * * * * *
72615 **
72616 ** Do nothing. This instruction is often useful as a jump
@@ -72638,14 +72839,10 @@
72638 #ifdef VDBE_PROFILE
72639 {
72640 u64 elapsed = sqlite3Hwtime() - start;
72641 pOp->cycles += elapsed;
72642 pOp->cnt++;
72643 #if 0
72644 fprintf(stdout, "%10llu ", elapsed);
72645 sqlite3VdbePrintOp(stdout, origPc, &aOp[origPc]);
72646 #endif
72647 }
72648 #endif
72649
72650 /* The following code adds nothing to the actual functionality
72651 ** of the program. It is only here for testing and debugging.
@@ -72867,26 +73064,24 @@
72867 **
72868 ** The sqlite3_blob_close() function finalizes the vdbe program,
72869 ** which closes the b-tree cursor and (possibly) commits the
72870 ** transaction.
72871 */
 
72872 static const VdbeOpList openBlob[] = {
72873 {OP_Transaction, 0, 0, 0}, /* 0: Start a transaction */
72874 {OP_VerifyCookie, 0, 0, 0}, /* 1: Check the schema cookie */
72875 {OP_TableLock, 0, 0, 0}, /* 2: Acquire a read or write lock */
72876
72877 /* One of the following two instructions is replaced by an OP_Noop. */
72878 {OP_OpenRead, 0, 0, 0}, /* 3: Open cursor 0 for reading */
72879 {OP_OpenWrite, 0, 0, 0}, /* 4: Open cursor 0 for read/write */
72880
72881 {OP_Variable, 1, 1, 1}, /* 5: Push the rowid to the stack */
72882 {OP_NotExists, 0, 10, 1}, /* 6: Seek the cursor */
72883 {OP_Column, 0, 0, 1}, /* 7 */
72884 {OP_ResultRow, 1, 0, 0}, /* 8 */
72885 {OP_Goto, 0, 5, 0}, /* 9 */
72886 {OP_Close, 0, 0, 0}, /* 10 */
72887 {OP_Halt, 0, 0, 0}, /* 11 */
72888 };
72889
72890 int rc = SQLITE_OK;
72891 char *zErr = 0;
72892 Table *pTab;
@@ -72995,50 +73190,45 @@
72995 assert( pBlob->pStmt || db->mallocFailed );
72996 if( pBlob->pStmt ){
72997 Vdbe *v = (Vdbe *)pBlob->pStmt;
72998 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
72999
73000 sqlite3VdbeAddOpList(v, sizeof(openBlob)/sizeof(VdbeOpList), openBlob);
73001
73002
73003 /* Configure the OP_Transaction */
73004 sqlite3VdbeChangeP1(v, 0, iDb);
73005 sqlite3VdbeChangeP2(v, 0, flags);
73006
73007 /* Configure the OP_VerifyCookie */
73008 sqlite3VdbeChangeP1(v, 1, iDb);
73009 sqlite3VdbeChangeP2(v, 1, pTab->pSchema->schema_cookie);
73010 sqlite3VdbeChangeP3(v, 1, pTab->pSchema->iGeneration);
73011
73012 /* Make sure a mutex is held on the table to be accessed */
73013 sqlite3VdbeUsesBtree(v, iDb);
73014
73015 /* Configure the OP_TableLock instruction */
73016 #ifdef SQLITE_OMIT_SHARED_CACHE
73017 sqlite3VdbeChangeToNoop(v, 2);
73018 #else
73019 sqlite3VdbeChangeP1(v, 2, iDb);
73020 sqlite3VdbeChangeP2(v, 2, pTab->tnum);
73021 sqlite3VdbeChangeP3(v, 2, flags);
73022 sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
73023 #endif
73024
73025 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
73026 ** parameter of the other to pTab->tnum. */
73027 sqlite3VdbeChangeToNoop(v, 4 - flags);
73028 sqlite3VdbeChangeP2(v, 3 + flags, pTab->tnum);
73029 sqlite3VdbeChangeP3(v, 3 + flags, iDb);
73030
73031 /* Configure the number of columns. Configure the cursor to
73032 ** think that the table has one more column than it really
73033 ** does. An OP_Column to retrieve this imaginary column will
73034 ** always return an SQL NULL. This is useful because it means
73035 ** we can invoke OP_Column to fill in the vdbe cursors type
73036 ** and offset cache without causing any IO.
73037 */
73038 sqlite3VdbeChangeP4(v, 3+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
73039 sqlite3VdbeChangeP2(v, 7, pTab->nCol);
73040 if( !db->mallocFailed ){
73041 pParse->nVar = 1;
73042 pParse->nMem = 1;
73043 pParse->nTab = 1;
73044 sqlite3VdbeMakeReady(v, pParse);
@@ -75302,12 +75492,12 @@
75302 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75303
75304 /*
75305 ** Perhaps the name is a reference to the ROWID
75306 */
75307 assert( pTab!=0 || cntTab==0 );
75308 if( cnt==0 && cntTab==1 && sqlite3IsRowid(zCol) && HasRowid(pTab) ){
75309 cnt = 1;
75310 pExpr->iColumn = -1; /* IMP: R-44911-55124 */
75311 pExpr->affinity = SQLITE_AFF_INTEGER;
75312 }
75313
@@ -77434,11 +77624,10 @@
77434 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
77435 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
77436 pNew->iLimit = 0;
77437 pNew->iOffset = 0;
77438 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
77439 pNew->pRightmost = 0;
77440 pNew->addrOpenEphm[0] = -1;
77441 pNew->addrOpenEphm[1] = -1;
77442 pNew->addrOpenEphm[2] = -1;
77443 pNew->nSelectRow = p->nSelectRow;
77444 pNew->pWith = withDup(db, p->pWith);
@@ -77744,28 +77933,10 @@
77744 default:
77745 return 1;
77746 }
77747 }
77748
77749 /*
77750 ** Generate an OP_IsNull instruction that tests register iReg and jumps
77751 ** to location iDest if the value in iReg is NULL. The value in iReg
77752 ** was computed by pExpr. If we can look at pExpr at compile-time and
77753 ** determine that it can never generate a NULL, then the OP_IsNull operation
77754 ** can be omitted.
77755 */
77756 SQLITE_PRIVATE void sqlite3ExprCodeIsNullJump(
77757 Vdbe *v, /* The VDBE under construction */
77758 const Expr *pExpr, /* Only generate OP_IsNull if this expr can be NULL */
77759 int iReg, /* Test the value in this register for NULL */
77760 int iDest /* Jump here if the value is null */
77761 ){
77762 if( sqlite3ExprCanBeNull(pExpr) ){
77763 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iDest);
77764 }
77765 }
77766
77767 /*
77768 ** Return TRUE if the given expression is a constant which would be
77769 ** unchanged by OP_Affinity with the affinity given in the second
77770 ** argument.
77771 **
@@ -77958,11 +78129,11 @@
77958 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
77959 pTab = p->pSrc->a[0].pTab;
77960 pExpr = p->pEList->a[0].pExpr;
77961 iCol = (i16)pExpr->iColumn;
77962
77963 /* Code an OP_VerifyCookie and OP_TableLock for <table>. */
77964 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
77965 sqlite3CodeVerifySchema(pParse, iDb);
77966 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
77967
77968 /* This function is only called from two places. In both cases the vdbe
@@ -77969,13 +78140,12 @@
77969 ** has already been allocated. So assume sqlite3GetVdbe() is always
77970 ** successful here.
77971 */
77972 assert(v);
77973 if( iCol<0 ){
77974 int iAddr;
77975
77976 iAddr = sqlite3CodeOnce(pParse);
77977
77978 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
77979 eType = IN_INDEX_ROWID;
77980
77981 sqlite3VdbeJumpHere(v, iAddr);
@@ -77996,22 +78166,22 @@
77996 for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
77997 if( (pIdx->aiColumn[0]==iCol)
77998 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
77999 && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
78000 ){
78001 int iAddr = sqlite3CodeOnce(pParse);
78002 sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
78003 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
78004 VdbeComment((v, "%s", pIdx->zName));
78005 assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
78006 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
78007
78008 sqlite3VdbeJumpHere(v, iAddr);
78009 if( prNotFound && !pTab->aCol[iCol].notNull ){
78010 *prNotFound = ++pParse->nMem;
78011 sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
78012 }
 
78013 }
78014 }
78015 }
78016 }
78017
@@ -78096,11 +78266,11 @@
78096 **
78097 ** If all of the above are false, then we can run this code just once
78098 ** save the results, and reuse the same result on subsequent invocations.
78099 */
78100 if( !ExprHasProperty(pExpr, EP_VarSelect) ){
78101 testAddr = sqlite3CodeOnce(pParse);
78102 }
78103
78104 #ifndef SQLITE_OMIT_EXPLAIN
78105 if( pParse->explain==2 ){
78106 char *zMsg = sqlite3MPrintf(
@@ -78137,11 +78307,10 @@
78137 ** 'x' nor the SELECT... statement are columns, then numeric affinity
78138 ** is used.
78139 */
78140 pExpr->iTable = pParse->nTab++;
78141 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
78142 if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
78143 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
78144
78145 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
78146 /* Case 1: expr IN (SELECT ...)
78147 **
@@ -78213,10 +78382,11 @@
78213 }else{
78214 r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
78215 if( isRowid ){
78216 sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
78217 sqlite3VdbeCurrentAddr(v)+2);
 
78218 sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
78219 }else{
78220 sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
78221 sqlite3ExprCacheAffinityChange(pParse, r3, 1);
78222 sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
@@ -78336,23 +78506,25 @@
78336 ** on whether the RHS is empty or not, respectively.
78337 */
78338 if( destIfNull==destIfFalse ){
78339 /* Shortcut for the common case where the false and NULL outcomes are
78340 ** the same. */
78341 sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull);
78342 }else{
78343 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1);
78344 sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
 
78345 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
78346 sqlite3VdbeJumpHere(v, addr1);
78347 }
78348
78349 if( eType==IN_INDEX_ROWID ){
78350 /* In this case, the RHS is the ROWID of table b-tree
78351 */
78352 sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse);
78353 sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1);
 
78354 }else{
78355 /* In this case, the RHS is an index b-tree.
78356 */
78357 sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1);
78358
@@ -78369,42 +78541,40 @@
78369 **
78370 ** Also run this branch if NULL is equivalent to FALSE
78371 ** for this particular IN operator.
78372 */
78373 sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse, r1, 1);
78374
78375 }else{
78376 /* In this branch, the RHS of the IN might contain a NULL and
78377 ** the presence of a NULL on the RHS makes a difference in the
78378 ** outcome.
78379 */
78380 int j1, j2, j3;
78381
78382 /* First check to see if the LHS is contained in the RHS. If so,
78383 ** then the presence of NULLs in the RHS does not matter, so jump
78384 ** over all of the code that follows.
78385 */
78386 j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
 
78387
78388 /* Here we begin generating code that runs if the LHS is not
78389 ** contained within the RHS. Generate additional code that
78390 ** tests the RHS for NULLs. If the RHS contains a NULL then
78391 ** jump to destIfNull. If there are no NULLs in the RHS then
78392 ** jump to destIfFalse.
78393 */
78394 j2 = sqlite3VdbeAddOp1(v, OP_NotNull, rRhsHasNull);
78395 j3 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
78396 sqlite3VdbeAddOp2(v, OP_Integer, -1, rRhsHasNull);
78397 sqlite3VdbeJumpHere(v, j3);
78398 sqlite3VdbeAddOp2(v, OP_AddImm, rRhsHasNull, 1);
 
78399 sqlite3VdbeJumpHere(v, j2);
78400
78401 /* Jump to the appropriate target depending on whether or not
78402 ** the RHS contains a NULL
78403 */
78404 sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull);
78405 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
78406
78407 /* The OP_Found at the top of this branch jumps here when true,
78408 ** causing the overall IN expression evaluation to fall through.
78409 */
78410 sqlite3VdbeJumpHere(v, j1);
@@ -78921,26 +79091,20 @@
78921 case TK_LE:
78922 case TK_GT:
78923 case TK_GE:
78924 case TK_NE:
78925 case TK_EQ: {
78926 assert( TK_LT==OP_Lt );
78927 assert( TK_LE==OP_Le );
78928 assert( TK_GT==OP_Gt );
78929 assert( TK_GE==OP_Ge );
78930 assert( TK_EQ==OP_Eq );
78931 assert( TK_NE==OP_Ne );
78932 testcase( op==TK_LT );
78933 testcase( op==TK_LE );
78934 testcase( op==TK_GT );
78935 testcase( op==TK_GE );
78936 testcase( op==TK_EQ );
78937 testcase( op==TK_NE );
78938 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
78939 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
78940 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
78941 r1, r2, inReg, SQLITE_STOREP2);
 
 
 
 
 
 
78942 testcase( regFree1==0 );
78943 testcase( regFree2==0 );
78944 break;
78945 }
78946 case TK_IS:
@@ -78950,10 +79114,12 @@
78950 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
78951 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
78952 op = (op==TK_IS) ? TK_EQ : TK_NE;
78953 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
78954 r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ);
 
 
78955 testcase( regFree1==0 );
78956 testcase( regFree2==0 );
78957 break;
78958 }
78959 case TK_AND:
@@ -78966,32 +79132,21 @@
78966 case TK_BITOR:
78967 case TK_SLASH:
78968 case TK_LSHIFT:
78969 case TK_RSHIFT:
78970 case TK_CONCAT: {
78971 assert( TK_AND==OP_And );
78972 assert( TK_OR==OP_Or );
78973 assert( TK_PLUS==OP_Add );
78974 assert( TK_MINUS==OP_Subtract );
78975 assert( TK_REM==OP_Remainder );
78976 assert( TK_BITAND==OP_BitAnd );
78977 assert( TK_BITOR==OP_BitOr );
78978 assert( TK_SLASH==OP_Divide );
78979 assert( TK_LSHIFT==OP_ShiftLeft );
78980 assert( TK_RSHIFT==OP_ShiftRight );
78981 assert( TK_CONCAT==OP_Concat );
78982 testcase( op==TK_AND );
78983 testcase( op==TK_OR );
78984 testcase( op==TK_PLUS );
78985 testcase( op==TK_MINUS );
78986 testcase( op==TK_REM );
78987 testcase( op==TK_BITAND );
78988 testcase( op==TK_BITOR );
78989 testcase( op==TK_SLASH );
78990 testcase( op==TK_LSHIFT );
78991 testcase( op==TK_RSHIFT );
78992 testcase( op==TK_CONCAT );
78993 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
78994 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
78995 sqlite3VdbeAddOp3(v, op, r2, r1, target);
78996 testcase( regFree1==0 );
78997 testcase( regFree2==0 );
@@ -79019,31 +79174,29 @@
79019 inReg = target;
79020 break;
79021 }
79022 case TK_BITNOT:
79023 case TK_NOT: {
79024 assert( TK_BITNOT==OP_BitNot );
79025 assert( TK_NOT==OP_Not );
79026 testcase( op==TK_BITNOT );
79027 testcase( op==TK_NOT );
79028 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79029 testcase( regFree1==0 );
79030 inReg = target;
79031 sqlite3VdbeAddOp2(v, op, r1, inReg);
79032 break;
79033 }
79034 case TK_ISNULL:
79035 case TK_NOTNULL: {
79036 int addr;
79037 assert( TK_ISNULL==OP_IsNull );
79038 assert( TK_NOTNULL==OP_NotNull );
79039 testcase( op==TK_ISNULL );
79040 testcase( op==TK_NOTNULL );
79041 sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
79042 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79043 testcase( regFree1==0 );
79044 addr = sqlite3VdbeAddOp1(v, op, r1);
 
 
79045 sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
79046 sqlite3VdbeJumpHere(v, addr);
79047 break;
79048 }
79049 case TK_AGG_FUNCTION: {
@@ -79091,10 +79244,11 @@
79091 int endCoalesce = sqlite3VdbeMakeLabel(v);
79092 assert( nFarg>=2 );
79093 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
79094 for(i=1; i<nFarg; i++){
79095 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
 
79096 sqlite3ExprCacheRemove(pParse, target, 1);
79097 sqlite3ExprCachePush(pParse);
79098 sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
79099 sqlite3ExprCachePop(pParse, 1);
79100 }
@@ -79228,17 +79382,18 @@
79228 testcase( regFree1==0 );
79229 testcase( regFree2==0 );
79230 r3 = sqlite3GetTempReg(pParse);
79231 r4 = sqlite3GetTempReg(pParse);
79232 codeCompare(pParse, pLeft, pRight, OP_Ge,
79233 r1, r2, r3, SQLITE_STOREP2);
79234 pLItem++;
79235 pRight = pLItem->pExpr;
79236 sqlite3ReleaseTempReg(pParse, regFree2);
79237 r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
79238 testcase( regFree2==0 );
79239 codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2);
 
79240 sqlite3VdbeAddOp3(v, OP_And, r3, r4, target);
79241 sqlite3ReleaseTempReg(pParse, r3);
79242 sqlite3ReleaseTempReg(pParse, r4);
79243 break;
79244 }
@@ -79401,10 +79556,11 @@
79401 }
79402 assert( !ExprHasProperty(pExpr, EP_IntValue) );
79403 if( pExpr->affinity==OE_Ignore ){
79404 sqlite3VdbeAddOp4(
79405 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
 
79406 }else{
79407 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
79408 pExpr->affinity, pExpr->u.zToken, 0, 0);
79409 }
79410
@@ -79488,11 +79644,11 @@
79488 /*
79489 ** Generate code that will evaluate expression pExpr and store the
79490 ** results in register target. The results are guaranteed to appear
79491 ** in register target.
79492 */
79493 SQLITE_PRIVATE int sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
79494 int inReg;
79495
79496 assert( target>0 && target<=pParse->nMem );
79497 if( pExpr && pExpr->op==TK_REGISTER ){
79498 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
@@ -79501,11 +79657,24 @@
79501 assert( pParse->pVdbe || pParse->db->mallocFailed );
79502 if( inReg!=target && pParse->pVdbe ){
79503 sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
79504 }
79505 }
79506 return target;
 
 
 
 
 
 
 
 
 
 
 
 
 
79507 }
79508
79509 /*
79510 ** Generate code that evalutes the given expression and puts the result
79511 ** in register target.
@@ -79516,29 +79685,20 @@
79516 **
79517 ** This routine is used for expressions that are used multiple
79518 ** times. They are evaluated once and the results of the expression
79519 ** are reused.
79520 */
79521 SQLITE_PRIVATE int sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79522 Vdbe *v = pParse->pVdbe;
79523 int inReg;
79524 inReg = sqlite3ExprCode(pParse, pExpr, target);
79525 assert( target>0 );
79526 /* The only place, other than this routine, where expressions can be
79527 ** converted to TK_REGISTER is internal subexpressions in BETWEEN and
79528 ** CASE operators. Neither ever calls this routine. And this routine
79529 ** is never called twice on the same expression. Hence it is impossible
79530 ** for the input to this routine to already be a register. Nevertheless,
79531 ** it seems prudent to keep the ALWAYS() in case the conditions above
79532 ** change with future modifications or enhancements. */
79533 if( ALWAYS(pExpr->op!=TK_REGISTER) ){
79534 int iMem;
79535 iMem = ++pParse->nMem;
79536 sqlite3VdbeAddOp2(v, OP_Copy, inReg, iMem);
79537 exprToRegister(pExpr, iMem);
79538 }
79539 return inReg;
79540 }
79541
79542 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
79543 /*
79544 ** Generate a human-readable explanation of an expression tree.
@@ -79969,27 +80129,21 @@
79969 case TK_LE:
79970 case TK_GT:
79971 case TK_GE:
79972 case TK_NE:
79973 case TK_EQ: {
79974 assert( TK_LT==OP_Lt );
79975 assert( TK_LE==OP_Le );
79976 assert( TK_GT==OP_Gt );
79977 assert( TK_GE==OP_Ge );
79978 assert( TK_EQ==OP_Eq );
79979 assert( TK_NE==OP_Ne );
79980 testcase( op==TK_LT );
79981 testcase( op==TK_LE );
79982 testcase( op==TK_GT );
79983 testcase( op==TK_GE );
79984 testcase( op==TK_EQ );
79985 testcase( op==TK_NE );
79986 testcase( jumpIfNull==0 );
79987 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79988 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
79989 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
79990 r1, r2, dest, jumpIfNull);
 
 
 
 
 
 
79991 testcase( regFree1==0 );
79992 testcase( regFree2==0 );
79993 break;
79994 }
79995 case TK_IS:
@@ -79999,22 +80153,24 @@
79999 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80000 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80001 op = (op==TK_IS) ? TK_EQ : TK_NE;
80002 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80003 r1, r2, dest, SQLITE_NULLEQ);
 
 
80004 testcase( regFree1==0 );
80005 testcase( regFree2==0 );
80006 break;
80007 }
80008 case TK_ISNULL:
80009 case TK_NOTNULL: {
80010 assert( TK_ISNULL==OP_IsNull );
80011 assert( TK_NOTNULL==OP_NotNull );
80012 testcase( op==TK_ISNULL );
80013 testcase( op==TK_NOTNULL );
80014 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80015 sqlite3VdbeAddOp2(v, op, r1, dest);
 
 
80016 testcase( regFree1==0 );
80017 break;
80018 }
80019 case TK_BETWEEN: {
80020 testcase( jumpIfNull==0 );
@@ -80037,10 +80193,11 @@
80037 }else if( exprAlwaysFalse(pExpr) ){
80038 /* No-op */
80039 }else{
80040 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80041 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
 
80042 testcase( regFree1==0 );
80043 testcase( jumpIfNull==0 );
80044 }
80045 break;
80046 }
@@ -80128,21 +80285,21 @@
80128 case TK_LE:
80129 case TK_GT:
80130 case TK_GE:
80131 case TK_NE:
80132 case TK_EQ: {
80133 testcase( op==TK_LT );
80134 testcase( op==TK_LE );
80135 testcase( op==TK_GT );
80136 testcase( op==TK_GE );
80137 testcase( op==TK_EQ );
80138 testcase( op==TK_NE );
80139 testcase( jumpIfNull==0 );
80140 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80141 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80142 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80143 r1, r2, dest, jumpIfNull);
 
 
 
 
 
 
80144 testcase( regFree1==0 );
80145 testcase( regFree2==0 );
80146 break;
80147 }
80148 case TK_IS:
@@ -80152,20 +80309,22 @@
80152 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80153 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80154 op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
80155 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80156 r1, r2, dest, SQLITE_NULLEQ);
 
 
80157 testcase( regFree1==0 );
80158 testcase( regFree2==0 );
80159 break;
80160 }
80161 case TK_ISNULL:
80162 case TK_NOTNULL: {
80163 testcase( op==TK_ISNULL );
80164 testcase( op==TK_NOTNULL );
80165 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80166 sqlite3VdbeAddOp2(v, op, r1, dest);
 
 
80167 testcase( regFree1==0 );
80168 break;
80169 }
80170 case TK_BETWEEN: {
80171 testcase( jumpIfNull==0 );
@@ -80190,10 +80349,11 @@
80190 }else if( exprAlwaysTrue(pExpr) ){
80191 /* no-op */
80192 }else{
80193 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80194 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
 
80195 testcase( regFree1==0 );
80196 testcase( jumpIfNull==0 );
80197 }
80198 break;
80199 }
@@ -80736,12 +80896,12 @@
80736 len = sqlite3GetToken(zCsr, &token);
80737 } while( token==TK_SPACE );
80738 assert( len>0 );
80739 } while( token!=TK_LP && token!=TK_USING );
80740
80741 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
80742 zTableName, tname.z+tname.n);
80743 sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
80744 }
80745 }
80746
80747 /*
@@ -80789,11 +80949,11 @@
80789 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
80790 if( zParent==0 ) break;
80791 sqlite3Dequote(zParent);
80792 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
80793 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
80794 (zOutput?zOutput:""), z-zInput, zInput, (const char *)zNew
80795 );
80796 sqlite3DbFree(db, zOutput);
80797 zOutput = zOut;
80798 zInput = &z[n];
80799 }
@@ -80875,12 +81035,12 @@
80875 } while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
80876
80877 /* Variable tname now contains the token that is the old table-name
80878 ** in the CREATE TRIGGER statement.
80879 */
80880 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", ((u8*)tname.z) - zSql, zSql,
80881 zTableName, tname.z+tname.n);
80882 sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
80883 }
80884 }
80885 #endif /* !SQLITE_OMIT_TRIGGER */
80886
@@ -81128,11 +81288,11 @@
81128 pVTab = 0;
81129 }
81130 }
81131 #endif
81132
81133 /* Begin a transaction and code the VerifyCookie for database iDb.
81134 ** Then modify the schema cookie (since the ALTER TABLE modifies the
81135 ** schema). Open a statement transaction if the table is a virtual
81136 ** table.
81137 */
81138 v = sqlite3GetVdbe(pParse);
@@ -81264,10 +81424,11 @@
81264 int j1;
81265 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
81266 sqlite3VdbeUsesBtree(v, iDb);
81267 sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
81268 j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
 
81269 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
81270 sqlite3VdbeJumpHere(v, j1);
81271 sqlite3ReleaseTempReg(pParse, r1);
81272 sqlite3ReleaseTempReg(pParse, r2);
81273 }
@@ -82564,10 +82725,11 @@
82564 ** regChng = 0
82565 ** goto next_push_0;
82566 **
82567 */
82568 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
 
82569 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
82570 addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
82571
82572 /*
82573 ** next_row:
@@ -82585,10 +82747,11 @@
82585 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
82586 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
82587 aGotoChng[i] =
82588 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
82589 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
 
82590 }
82591 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
82592 aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
82593
82594 /*
@@ -82631,11 +82794,11 @@
82631 #endif
82632 assert( regChng==(regStat4+1) );
82633 sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
82634 sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
82635 sqlite3VdbeChangeP5(v, 2+IsStat34);
82636 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow);
82637
82638 /* Add the entry to the stat1 table. */
82639 callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
82640 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
82641 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
@@ -82658,14 +82821,16 @@
82658 pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
82659
82660 addrNext = sqlite3VdbeCurrentAddr(v);
82661 callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
82662 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
 
82663 callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
82664 callStatGet(v, regStat4, STAT_GET_NLT, regLt);
82665 callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
82666 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
 
82667 #ifdef SQLITE_ENABLE_STAT3
82668 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
82669 pIdx->aiColumn[0], regSample);
82670 #else
82671 for(i=0; i<nCol; i++){
@@ -82672,11 +82837,11 @@
82672 i16 iCol = pIdx->aiColumn[i];
82673 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
82674 }
82675 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
82676 #endif
82677 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 6, regTemp, "bbbbbb", 0);
82678 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
82679 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
82680 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
82681 sqlite3VdbeJumpHere(v, addrIsNull);
82682 }
@@ -82692,11 +82857,11 @@
82692 ** name and the row count as the content.
82693 */
82694 if( pOnlyIdx==0 && needTableCnt ){
82695 VdbeComment((v, "%s", pTab->zName));
82696 sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
82697 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
82698 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
82699 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
82700 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
82701 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
82702 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -84230,24 +84395,26 @@
84230 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
84231 ** set for each database that is used. Generate code to start a
84232 ** transaction on each used database and to verify the schema cookie
84233 ** on each used database.
84234 */
84235 if( pParse->cookieGoto>0 ){
84236 yDbMask mask;
84237 int iDb, i, addr;
84238 sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
 
84239 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
84240 if( (mask & pParse->cookieMask)==0 ) continue;
84241 sqlite3VdbeUsesBtree(v, iDb);
84242 sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
84243 if( db->init.busy==0 ){
84244 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
84245 sqlite3VdbeAddOp3(v, OP_VerifyCookie,
84246 iDb, pParse->cookieValue[iDb],
84247 db->aDb[iDb].pSchema->iGeneration);
84248 }
 
84249 }
84250 #ifndef SQLITE_OMIT_VIRTUALTABLE
84251 for(i=0; i<pParse->nVtabLock; i++){
84252 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84253 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
@@ -84264,21 +84431,20 @@
84264 /* Initialize any AUTOINCREMENT data structures required.
84265 */
84266 sqlite3AutoincrementBegin(pParse);
84267
84268 /* Code constant expressions that where factored out of inner loops */
84269 addr = pParse->cookieGoto;
84270 if( pParse->pConstExpr ){
84271 ExprList *pEL = pParse->pConstExpr;
84272 pParse->cookieGoto = 0;
84273 for(i=0; i<pEL->nExpr; i++){
84274 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
84275 }
84276 }
84277
84278 /* Finally, jump back to the beginning of the executable code. */
84279 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
84280 }
84281 }
84282
84283
84284 /* Get the VDBE program ready for execution
@@ -84297,11 +84463,10 @@
84297 pParse->nTab = 0;
84298 pParse->nMem = 0;
84299 pParse->nSet = 0;
84300 pParse->nVar = 0;
84301 pParse->cookieMask = 0;
84302 pParse->cookieGoto = 0;
84303 }
84304
84305 /*
84306 ** Run the parser and code generator recursively in order to generate
84307 ** code for the SQL statement given onto the end of the pParse context
@@ -85029,11 +85194,11 @@
85029 reg1 = pParse->regRowid = ++pParse->nMem;
85030 reg2 = pParse->regRoot = ++pParse->nMem;
85031 reg3 = ++pParse->nMem;
85032 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
85033 sqlite3VdbeUsesBtree(v, iDb);
85034 j1 = sqlite3VdbeAddOp1(v, OP_If, reg3);
85035 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
85036 1 : SQLITE_MAX_FILE_FORMAT;
85037 sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
85038 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
85039 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
@@ -86756,40 +86921,40 @@
86756 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
86757
86758 /* Open the table. Loop through all rows of the table, inserting index
86759 ** records into the sorter. */
86760 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
86761 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0);
86762 regRecord = sqlite3GetTempReg(pParse);
86763
86764 sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
86765 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
86766 sqlite3VdbeResolveLabel(v, iPartIdxLabel);
86767 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1);
86768 sqlite3VdbeJumpHere(v, addr1);
86769 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
86770 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
86771 (char *)pKey, P4_KEYINFO);
86772 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
86773
86774 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0);
86775 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
86776 if( pIndex->onError!=OE_None && pKey!=0 ){
86777 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
86778 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
86779 addr2 = sqlite3VdbeCurrentAddr(v);
86780 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
86781 pKey->nField - pIndex->nKeyCol);
86782 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
86783 }else{
86784 addr2 = sqlite3VdbeCurrentAddr(v);
86785 }
86786 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
86787 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
86788 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
86789 sqlite3ReleaseTempReg(pParse, regRecord);
86790 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2);
86791 sqlite3VdbeJumpHere(v, addr1);
86792
86793 sqlite3VdbeAddOp1(v, OP_Close, iTab);
86794 sqlite3VdbeAddOp1(v, OP_Close, iIdx);
86795 sqlite3VdbeAddOp1(v, OP_Close, iSorter);
@@ -87906,63 +88071,30 @@
87906 }
87907 return 0;
87908 }
87909
87910 /*
87911 ** Generate VDBE code that will verify the schema cookie and start
87912 ** a read-transaction for all named database files.
87913 **
87914 ** It is important that all schema cookies be verified and all
87915 ** read transactions be started before anything else happens in
87916 ** the VDBE program. But this routine can be called after much other
87917 ** code has been generated. So here is what we do:
87918 **
87919 ** The first time this routine is called, we code an OP_Goto that
87920 ** will jump to a subroutine at the end of the program. Then we
87921 ** record every database that needs its schema verified in the
87922 ** pParse->cookieMask field. Later, after all other code has been
87923 ** generated, the subroutine that does the cookie verifications and
87924 ** starts the transactions will be coded and the OP_Goto P2 value
87925 ** will be made to point to that subroutine. The generation of the
87926 ** cookie verification subroutine code happens in sqlite3FinishCoding().
87927 **
87928 ** If iDb<0 then code the OP_Goto only - don't set flag to verify the
87929 ** schema on any databases. This can be used to position the OP_Goto
87930 ** early in the code, before we know if any database tables will be used.
87931 */
87932 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
87933 Parse *pToplevel = sqlite3ParseToplevel(pParse);
87934
87935 #ifndef SQLITE_OMIT_TRIGGER
87936 if( pToplevel!=pParse ){
87937 /* This branch is taken if a trigger is currently being coded. In this
87938 ** case, set cookieGoto to a non-zero value to show that this function
87939 ** has been called. This is used by the sqlite3ExprCodeConstants()
87940 ** function. */
87941 pParse->cookieGoto = -1;
87942 }
87943 #endif
87944 if( pToplevel->cookieGoto==0 ){
87945 Vdbe *v = sqlite3GetVdbe(pToplevel);
87946 if( v==0 ) return; /* This only happens if there was a prior error */
87947 pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1;
87948 }
87949 if( iDb>=0 ){
87950 sqlite3 *db = pToplevel->db;
87951 yDbMask mask;
87952
87953 assert( iDb<db->nDb );
87954 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
87955 assert( iDb<SQLITE_MAX_ATTACHED+2 );
87956 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
87957 mask = ((yDbMask)1)<<iDb;
87958 if( (pToplevel->cookieMask & mask)==0 ){
87959 pToplevel->cookieMask |= mask;
87960 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
87961 if( !OMIT_TEMPDB && iDb==1 ){
87962 sqlite3OpenTempDatabase(pToplevel);
87963 }
87964 }
87965 }
87966 }
87967
87968 /*
@@ -88929,25 +89061,20 @@
88929 SelectDest dest;
88930 Select *pSel;
88931 SrcList *pFrom;
88932 sqlite3 *db = pParse->db;
88933 int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
88934
88935 pWhere = sqlite3ExprDup(db, pWhere, 0);
88936 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
88937
88938 if( pFrom ){
88939 assert( pFrom->nSrc==1 );
88940 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
88941 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
88942 assert( pFrom->a[0].pOn==0 );
88943 assert( pFrom->a[0].pUsing==0 );
88944 }
88945
88946 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
88947 if( pSel ) pSel->selFlags |= SF_Materialize;
88948
88949 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
88950 sqlite3Select(pParse, pSel, &dest);
88951 sqlite3SelectDelete(db, pSel);
88952 }
88953 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -89280,11 +89407,11 @@
89280 }else if( pPk ){
89281 /* Construct a composite key for the row to be deleted and remember it */
89282 iKey = ++pParse->nMem;
89283 nKey = 0; /* Zero tells OP_Found to use a composite key */
89284 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89285 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
89286 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
89287 }else{
89288 /* Get the rowid of the row to be deleted and remember it in the RowSet */
89289 nKey = 1; /* OP_Seek always uses a single rowid */
89290 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -89318,17 +89445,19 @@
89318 /* Just one row. Hence the top-of-loop is a no-op */
89319 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
89320 if( aToOpen[iDataCur-iTabCur] ){
89321 assert( pPk!=0 );
89322 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
 
89323 }
89324 }else if( pPk ){
89325 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur);
89326 sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
89327 assert( nKey==0 ); /* OP_Found will use a composite key */
89328 }else{
89329 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
 
89330 assert( nKey==1 );
89331 }
89332
89333 /* Delete the row */
89334 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -89348,11 +89477,11 @@
89348
89349 /* End of the loop over all rowids/primary-keys. */
89350 if( okOnePass ){
89351 sqlite3VdbeResolveLabel(v, addrBypass);
89352 }else if( pPk ){
89353 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1);
89354 sqlite3VdbeJumpHere(v, addrLoop);
89355 }else{
89356 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
89357 sqlite3VdbeJumpHere(v, addrLoop);
89358 }
@@ -89446,11 +89575,15 @@
89446 /* Seek cursor iCur to the row to delete. If this row no longer exists
89447 ** (this can happen if a trigger program has already deleted it), do
89448 ** not attempt to delete it or fire any DELETE triggers. */
89449 iLabel = sqlite3VdbeMakeLabel(v);
89450 opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
89451 if( !bNoSeek ) sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
 
 
 
 
89452
89453 /* If there are any triggers to fire, allocate a range of registers to
89454 ** use for the old.* references in the triggers. */
89455 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
89456 u32 mask; /* Mask of OLD.* columns in use */
@@ -89488,10 +89621,12 @@
89488 ** the cursor or of already deleted the row that the cursor was
89489 ** pointing to.
89490 */
89491 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
89492 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
 
 
89493 }
89494
89495 /* Do FK processing. This call checks that any FK constraints that
89496 ** refer to this table (i.e. constraints attached to other tables)
89497 ** are not violated by deleting this row. */
@@ -91745,14 +91880,15 @@
91745 ** Check if any of the key columns in the child table row are NULL. If
91746 ** any are, then the constraint is considered satisfied. No need to
91747 ** search for a matching row in the parent table. */
91748 if( nIncr<0 ){
91749 sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
 
91750 }
91751 for(i=0; i<pFKey->nCol; i++){
91752 int iReg = aiCol[i] + regData + 1;
91753 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk);
91754 }
91755
91756 if( isIgnore==0 ){
91757 if( pIdx==0 ){
91758 /* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
@@ -91765,21 +91901,23 @@
91765 ** is no matching parent key. Before using MustBeInt, make a copy of
91766 ** the value. Otherwise, the value inserted into the child key column
91767 ** will have INTEGER affinity applied to it, which may not be correct. */
91768 sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);
91769 iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
 
91770
91771 /* If the parent table is the same as the child table, and we are about
91772 ** to increment the constraint-counter (i.e. this is an INSERT operation),
91773 ** then check if the row being inserted matches itself. If so, do not
91774 ** increment the constraint-counter. */
91775 if( pTab==pFKey->pFrom && nIncr==1 ){
91776 sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp);
 
91777 }
91778
91779 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
91780 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp);
91781 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
91782 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
91783 sqlite3VdbeJumpHere(v, iMustBeInt);
91784 sqlite3ReleaseTempReg(pParse, regTemp);
91785 }else{
@@ -91811,19 +91949,19 @@
91811 assert( aiCol[i]!=pTab->iPKey );
91812 if( pIdx->aiColumn[i]==pTab->iPKey ){
91813 /* The parent key is a composite key that includes the IPK column */
91814 iParent = regData;
91815 }
91816 sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent);
91817 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
91818 }
91819 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
91820 }
91821
91822 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTemp, nCol, regRec);
91823 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
91824 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0);
91825
91826 sqlite3ReleaseTempReg(pParse, regRec);
91827 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
91828 }
91829 }
@@ -91957,10 +92095,11 @@
91957 assert( pIdx!=0 || pFKey->nCol==1 );
91958 assert( pIdx!=0 || HasRowid(pTab) );
91959
91960 if( nIncr<0 ){
91961 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
 
91962 }
91963
91964 /* Create an Expr object representing an SQL expression like:
91965 **
91966 ** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
@@ -92119,11 +92258,11 @@
92119 for(p=pTab->pFKey; p; p=p->pNextFrom){
92120 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
92121 }
92122 if( !p ) return;
92123 iSkip = sqlite3VdbeMakeLabel(v);
92124 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip);
92125 }
92126
92127 pParse->disableTriggers = 1;
92128 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
92129 pParse->disableTriggers = 0;
@@ -92137,10 +92276,11 @@
92137 ** the statement transaction will not be rolled back even if FK
92138 ** constraints are violated.
92139 */
92140 if( (db->flags & SQLITE_DeferFKs)==0 ){
92141 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
 
92142 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
92143 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
92144 }
92145
92146 if( iSkip ){
@@ -92296,11 +92436,11 @@
92296 */
92297 Vdbe *v = sqlite3GetVdbe(pParse);
92298 int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;
92299 for(i=0; i<pFKey->nCol; i++){
92300 int iReg = pFKey->aCol[i].iFrom + regOld + 1;
92301 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump);
92302 }
92303 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);
92304 }
92305 continue;
92306 }
@@ -92863,69 +93003,74 @@
92863
92864 return pIdx->zColAff;
92865 }
92866
92867 /*
92868 ** Set P4 of the most recently inserted opcode to a column affinity
92869 ** string for table pTab. A column affinity string has one character
92870 ** for each column indexed by the index, according to the affinity of the
92871 ** column:
 
 
 
 
 
 
92872 **
92873 ** Character Column affinity
92874 ** ------------------------------
92875 ** 'a' TEXT
92876 ** 'b' NONE
92877 ** 'c' NUMERIC
92878 ** 'd' INTEGER
92879 ** 'e' REAL
92880 */
92881 SQLITE_PRIVATE void sqlite3TableAffinityStr(Vdbe *v, Table *pTab){
92882 /* The first time a column affinity string for a particular table
92883 ** is required, it is allocated and populated here. It is then
92884 ** stored as a member of the Table structure for subsequent use.
92885 **
92886 ** The column affinity string will eventually be deleted by
92887 ** sqlite3DeleteTable() when the Table structure itself is cleaned up.
92888 */
92889 if( !pTab->zColAff ){
92890 char *zColAff;
92891 int i;
92892 sqlite3 *db = sqlite3VdbeDb(v);
92893
92894 zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
92895 if( !zColAff ){
92896 db->mallocFailed = 1;
92897 return;
92898 }
92899
92900 for(i=0; i<pTab->nCol; i++){
92901 zColAff[i] = pTab->aCol[i].affinity;
92902 }
92903 zColAff[pTab->nCol] = '\0';
92904
 
92905 pTab->zColAff = zColAff;
92906 }
92907
92908 sqlite3VdbeChangeP4(v, -1, pTab->zColAff, P4_TRANSIENT);
 
 
 
 
 
 
92909 }
92910
92911 /*
92912 ** Return non-zero if the table pTab in database iDb or any of its indices
92913 ** have been opened at any point in the VDBE program beginning at location
92914 ** iStartAddr throught the end of the program. This is used to see if
92915 ** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
92916 ** run without using temporary table for the results of the SELECT.
92917 */
92918 static int readsTable(Parse *p, int iStartAddr, int iDb, Table *pTab){
92919 Vdbe *v = sqlite3GetVdbe(p);
92920 int i;
92921 int iEnd = sqlite3VdbeCurrentAddr(v);
92922 #ifndef SQLITE_OMIT_VIRTUALTABLE
92923 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
92924 #endif
92925
92926 for(i=iStartAddr; i<iEnd; i++){
92927 VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
92928 assert( pOp!=0 );
92929 if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
92930 Index *pIndex;
92931 int tnum = pOp->p2;
@@ -93022,18 +93167,18 @@
93022 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
93023 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
93024 sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
93025 addr = sqlite3VdbeCurrentAddr(v);
93026 sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
93027 sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9);
93028 sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
93029 sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId);
93030 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
93031 sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
93032 sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
93033 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
93034 sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2);
93035 sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
93036 sqlite3VdbeAddOp0(v, OP_Close);
93037 }
93038 }
93039
@@ -93064,29 +93209,20 @@
93064 sqlite3 *db = pParse->db;
93065
93066 assert( v );
93067 for(p = pParse->pAinc; p; p = p->pNext){
93068 Db *pDb = &db->aDb[p->iDb];
93069 int j1, j2, j3, j4, j5;
93070 int iRec;
93071 int memId = p->regCtr;
93072
93073 iRec = sqlite3GetTempReg(pParse);
93074 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
93075 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
93076 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1);
93077 j2 = sqlite3VdbeAddOp0(v, OP_Rewind);
93078 j3 = sqlite3VdbeAddOp3(v, OP_Column, 0, 0, iRec);
93079 j4 = sqlite3VdbeAddOp3(v, OP_Eq, memId-1, 0, iRec);
93080 sqlite3VdbeAddOp2(v, OP_Next, 0, j3);
93081 sqlite3VdbeJumpHere(v, j2);
93082 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1);
93083 j5 = sqlite3VdbeAddOp0(v, OP_Goto);
93084 sqlite3VdbeJumpHere(v, j4);
93085 sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
93086 sqlite3VdbeJumpHere(v, j1);
93087 sqlite3VdbeJumpHere(v, j5);
93088 sqlite3VdbeAddOp3(v, OP_MakeRecord, memId-1, 2, iRec);
93089 sqlite3VdbeAddOp3(v, OP_Insert, 0, iRec, memId+1);
93090 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
93091 sqlite3VdbeAddOp0(v, OP_Close);
93092 sqlite3ReleaseTempReg(pParse, iRec);
@@ -93098,101 +93234,10 @@
93098 ** above are all no-ops
93099 */
93100 # define autoIncBegin(A,B,C) (0)
93101 # define autoIncStep(A,B,C)
93102 #endif /* SQLITE_OMIT_AUTOINCREMENT */
93103
93104
93105 /*
93106 ** Generate code for a co-routine that will evaluate a subquery one
93107 ** row at a time.
93108 **
93109 ** The pSelect parameter is the subquery that the co-routine will evaluation.
93110 ** Information about the location of co-routine and the registers it will use
93111 ** is returned by filling in the pDest object.
93112 **
93113 ** Registers are allocated as follows:
93114 **
93115 ** pDest->iSDParm The register holding the next entry-point of the
93116 ** co-routine. Run the co-routine to its next breakpoint
93117 ** by calling "OP_Yield $X" where $X is pDest->iSDParm.
93118 **
93119 ** pDest->iSDParm+1 The register holding the "completed" flag for the
93120 ** co-routine. This register is 0 if the previous Yield
93121 ** generated a new result row, or 1 if the subquery
93122 ** has completed. If the Yield is called again
93123 ** after this register becomes 1, then the VDBE will
93124 ** halt with an SQLITE_INTERNAL error.
93125 **
93126 ** pDest->iSdst First result register.
93127 **
93128 ** pDest->nSdst Number of result registers.
93129 **
93130 ** This routine handles all of the register allocation and fills in the
93131 ** pDest structure appropriately.
93132 **
93133 ** Here is a schematic of the generated code assuming that X is the
93134 ** co-routine entry-point register reg[pDest->iSDParm], that EOF is the
93135 ** completed flag reg[pDest->iSDParm+1], and R and S are the range of
93136 ** registers that hold the result set, reg[pDest->iSdst] through
93137 ** reg[pDest->iSdst+pDest->nSdst-1]:
93138 **
93139 ** X <- A
93140 ** EOF <- 0
93141 ** goto B
93142 ** A: setup for the SELECT
93143 ** loop rows in the SELECT
93144 ** load results into registers R..S
93145 ** yield X
93146 ** end loop
93147 ** cleanup after the SELECT
93148 ** EOF <- 1
93149 ** yield X
93150 ** halt-error
93151 ** B:
93152 **
93153 ** To use this subroutine, the caller generates code as follows:
93154 **
93155 ** [ Co-routine generated by this subroutine, shown above ]
93156 ** S: yield X
93157 ** if EOF goto E
93158 ** if skip this row, goto C
93159 ** if terminate loop, goto E
93160 ** deal with this row
93161 ** C: goto S
93162 ** E:
93163 */
93164 SQLITE_PRIVATE int sqlite3CodeCoroutine(Parse *pParse, Select *pSelect, SelectDest *pDest){
93165 int regYield; /* Register holding co-routine entry-point */
93166 int regEof; /* Register holding co-routine completion flag */
93167 int addrTop; /* Top of the co-routine */
93168 int j1; /* Jump instruction */
93169 int rc; /* Result code */
93170 Vdbe *v; /* VDBE under construction */
93171
93172 regYield = ++pParse->nMem;
93173 regEof = ++pParse->nMem;
93174 v = sqlite3GetVdbe(pParse);
93175 addrTop = sqlite3VdbeCurrentAddr(v);
93176 sqlite3VdbeAddOp2(v, OP_Integer, addrTop+2, regYield); /* X <- A */
93177 VdbeComment((v, "Co-routine entry point"));
93178 sqlite3VdbeAddOp2(v, OP_Integer, 0, regEof); /* EOF <- 0 */
93179 VdbeComment((v, "Co-routine completion flag"));
93180 sqlite3SelectDestInit(pDest, SRT_Coroutine, regYield);
93181 j1 = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
93182 rc = sqlite3Select(pParse, pSelect, pDest);
93183 assert( pParse->nErr==0 || rc );
93184 if( pParse->db->mallocFailed && rc==SQLITE_OK ) rc = SQLITE_NOMEM;
93185 if( rc ) return rc;
93186 sqlite3VdbeAddOp2(v, OP_Integer, 1, regEof); /* EOF <- 1 */
93187 sqlite3VdbeAddOp1(v, OP_Yield, regYield); /* yield X */
93188 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_INTERNAL, OE_Abort);
93189 VdbeComment((v, "End of coroutine"));
93190 sqlite3VdbeJumpHere(v, j1); /* label B: */
93191 return rc;
93192 }
93193
93194
93195
93196 /* Forward declaration */
93197 static int xferOptimization(
93198 Parse *pParse, /* Parser context */
@@ -93253,25 +93298,21 @@
93253 **
93254 ** The 3rd template is for when the second template does not apply
93255 ** and the SELECT clause does not read from <table> at any time.
93256 ** The generated code follows this template:
93257 **
93258 ** EOF <- 0
93259 ** X <- A
93260 ** goto B
93261 ** A: setup for the SELECT
93262 ** loop over the rows in the SELECT
93263 ** load values into registers R..R+n
93264 ** yield X
93265 ** end loop
93266 ** cleanup after the SELECT
93267 ** EOF <- 1
93268 ** yield X
93269 ** goto A
93270 ** B: open write cursor to <table> and its indices
93271 ** C: yield X
93272 ** if EOF goto D
93273 ** insert the select result into <table> from R..R+n
93274 ** goto C
93275 ** D: cleanup
93276 **
93277 ** The 4th template is used if the insert statement takes its
@@ -93278,25 +93319,21 @@
93278 ** values from a SELECT but the data is being inserted into a table
93279 ** that is also read as part of the SELECT. In the third form,
93280 ** we have to use a intermediate table to store the results of
93281 ** the select. The template is like this:
93282 **
93283 ** EOF <- 0
93284 ** X <- A
93285 ** goto B
93286 ** A: setup for the SELECT
93287 ** loop over the tables in the SELECT
93288 ** load value into register R..R+n
93289 ** yield X
93290 ** end loop
93291 ** cleanup after the SELECT
93292 ** EOF <- 1
93293 ** yield X
93294 ** halt-error
93295 ** B: open temp table
93296 ** L: yield X
93297 ** if EOF goto M
93298 ** insert row from R..R+n into temp table
93299 ** goto L
93300 ** M: open write cursor to <table> and its indices
93301 ** rewind temp table
93302 ** C: loop over rows of intermediate table
@@ -93322,30 +93359,29 @@
93322 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
93323 int iDataCur = 0; /* VDBE cursor that is the main data repository */
93324 int iIdxCur = 0; /* First index cursor */
93325 int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
93326 int endOfLoop; /* Label for the end of the insertion loop */
93327 int useTempTable = 0; /* Store SELECT results in intermediate table */
93328 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
93329 int addrInsTop = 0; /* Jump to label "D" */
93330 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
93331 int addrSelect = 0; /* Address of coroutine that implements the SELECT */
93332 SelectDest dest; /* Destination for SELECT on rhs of INSERT */
93333 int iDb; /* Index of database holding TABLE */
93334 Db *pDb; /* The database containing table being inserted into */
93335 int appendFlag = 0; /* True if the insert is likely to be an append */
93336 int withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
 
 
93337 ExprList *pList = 0; /* List of VALUES() to be inserted */
93338
93339 /* Register allocations */
93340 int regFromSelect = 0;/* Base register for data coming from SELECT */
93341 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
93342 int regRowCount = 0; /* Memory cell used for the row counter */
93343 int regIns; /* Block of regs holding rowid+data being inserted */
93344 int regRowid; /* registers holding insert rowid */
93345 int regData; /* register holding first column to insert */
93346 int regEof = 0; /* Register recording end of SELECT data */
93347 int *aRegIdx = 0; /* One register allocated to each index */
93348
93349 #ifndef SQLITE_OMIT_TRIGGER
93350 int isView; /* True if attempting to insert into a view */
93351 Trigger *pTrigger; /* List of triggers on pTab, if required */
@@ -93443,26 +93479,86 @@
93443
93444 /* If this is an AUTOINCREMENT table, look up the sequence number in the
93445 ** sqlite_sequence table and store it in memory cell regAutoinc.
93446 */
93447 regAutoinc = autoIncBegin(pParse, iDb, pTab);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93448
93449 /* Figure out how many columns of data are supplied. If the data
93450 ** is coming from a SELECT statement, then generate a co-routine that
93451 ** produces a single row of the SELECT on each invocation. The
93452 ** co-routine is the common header to the 3rd and 4th templates.
93453 */
93454 if( pSelect ){
93455 /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
93456 int rc = sqlite3CodeCoroutine(pParse, pSelect, &dest);
93457 if( rc ) goto insert_cleanup;
 
93458
93459 regEof = dest.iSDParm + 1;
 
 
 
 
 
 
93460 regFromSelect = dest.iSdst;
 
 
 
 
93461 assert( pSelect->pEList );
93462 nColumn = pSelect->pEList->nExpr;
93463 assert( dest.nSdst==nColumn );
93464
93465 /* Set useTempTable to TRUE if the result of the SELECT statement
93466 ** should be written into a temporary table (template 4). Set to
93467 ** FALSE if each output row of the SELECT can be written directly into
93468 ** the destination table (template 3).
@@ -93469,42 +93565,39 @@
93469 **
93470 ** A temp table must be used if the table being updated is also one
93471 ** of the tables being read by the SELECT statement. Also use a
93472 ** temp table in the case of row triggers.
93473 */
93474 if( pTrigger || readsTable(pParse, addrSelect, iDb, pTab) ){
93475 useTempTable = 1;
93476 }
93477
93478 if( useTempTable ){
93479 /* Invoke the coroutine to extract information from the SELECT
93480 ** and add it to a transient table srcTab. The code generated
93481 ** here is from the 4th template:
93482 **
93483 ** B: open temp table
93484 ** L: yield X
93485 ** if EOF goto M
93486 ** insert row from R..R+n into temp table
93487 ** goto L
93488 ** M: ...
93489 */
93490 int regRec; /* Register to hold packed record */
93491 int regTempRowid; /* Register to hold temp table ROWID */
93492 int addrTop; /* Label "L" */
93493 int addrIf; /* Address of jump to M */
93494
93495 srcTab = pParse->nTab++;
93496 regRec = sqlite3GetTempReg(pParse);
93497 regTempRowid = sqlite3GetTempReg(pParse);
93498 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
93499 addrTop = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93500 addrIf = sqlite3VdbeAddOp1(v, OP_If, regEof);
93501 sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
93502 sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
93503 sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
93504 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
93505 sqlite3VdbeJumpHere(v, addrIf);
93506 sqlite3ReleaseTempReg(pParse, regRec);
93507 sqlite3ReleaseTempReg(pParse, regTempRowid);
93508 }
93509 }else{
93510 /* This is the case if the data for the INSERT is coming from a VALUES
@@ -93520,10 +93613,18 @@
93520 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
93521 goto insert_cleanup;
93522 }
93523 }
93524 }
 
 
 
 
 
 
 
 
93525
93526 /* Make sure the number of columns in the source data matches the number
93527 ** of columns to be inserted into the table.
93528 */
93529 if( IsVirtual(pTab) ){
@@ -93539,56 +93640,10 @@
93539 }
93540 if( pColumn!=0 && nColumn!=pColumn->nId ){
93541 sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
93542 goto insert_cleanup;
93543 }
93544
93545 /* If the INSERT statement included an IDLIST term, then make sure
93546 ** all elements of the IDLIST really are columns of the table and
93547 ** remember the column indices.
93548 **
93549 ** If the table has an INTEGER PRIMARY KEY column and that column
93550 ** is named in the IDLIST, then record in the ipkColumn variable
93551 ** the index into IDLIST of the primary key column. ipkColumn is
93552 ** the index of the primary key as it appears in IDLIST, not as
93553 ** is appears in the original table. (The index of the INTEGER
93554 ** PRIMARY KEY in the original table is pTab->iPKey.)
93555 */
93556 if( pColumn ){
93557 for(i=0; i<pColumn->nId; i++){
93558 pColumn->a[i].idx = -1;
93559 }
93560 for(i=0; i<pColumn->nId; i++){
93561 for(j=0; j<pTab->nCol; j++){
93562 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93563 pColumn->a[i].idx = j;
93564 if( j==pTab->iPKey ){
93565 ipkColumn = i; assert( !withoutRowid );
93566 }
93567 break;
93568 }
93569 }
93570 if( j>=pTab->nCol ){
93571 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93572 ipkColumn = i;
93573 }else{
93574 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93575 pTabList, 0, pColumn->a[i].zName);
93576 pParse->checkSchema = 1;
93577 goto insert_cleanup;
93578 }
93579 }
93580 }
93581 }
93582
93583 /* If there is no IDLIST term but the table has an integer primary
93584 ** key, the set the ipkColumn variable to the integer primary key
93585 ** column index in the original table definition.
93586 */
93587 if( pColumn==0 && nColumn>0 ){
93588 ipkColumn = pTab->iPKey;
93589 }
93590
93591 /* Initialize the count of rows to be inserted
93592 */
93593 if( db->flags & SQLITE_CountRows ){
93594 regRowCount = ++pParse->nMem;
@@ -93612,42 +93667,30 @@
93612 /* This is the top of the main insertion loop */
93613 if( useTempTable ){
93614 /* This block codes the top of loop only. The complete loop is the
93615 ** following pseudocode (template 4):
93616 **
93617 ** rewind temp table
93618 ** C: loop over rows of intermediate table
93619 ** transfer values form intermediate table into <table>
93620 ** end loop
93621 ** D: ...
93622 */
93623 addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab);
93624 addrCont = sqlite3VdbeCurrentAddr(v);
93625 }else if( pSelect ){
93626 /* This block codes the top of loop only. The complete loop is the
93627 ** following pseudocode (template 3):
93628 **
93629 ** C: yield X
93630 ** if EOF goto D
93631 ** insert the select result into <table> from R..R+n
93632 ** goto C
93633 ** D: ...
93634 */
93635 addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93636 addrInsTop = sqlite3VdbeAddOp1(v, OP_If, regEof);
93637 }
93638
93639 /* Allocate registers for holding the rowid of the new row,
93640 ** the content of the new row, and the assemblied row record.
93641 */
93642 regRowid = regIns = pParse->nMem+1;
93643 pParse->nMem += pTab->nCol + 1;
93644 if( IsVirtual(pTab) ){
93645 regRowid++;
93646 pParse->nMem++;
93647 }
93648 regData = regRowid+1;
93649
93650 /* Run the BEFORE and INSTEAD OF triggers, if there are any
93651 */
93652 endOfLoop = sqlite3VdbeMakeLabel(v);
93653 if( tmask & TRIGGER_BEFORE ){
@@ -93668,14 +93711,14 @@
93668 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
93669 }else{
93670 assert( pSelect==0 ); /* Otherwise useTempTable is true */
93671 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
93672 }
93673 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols);
93674 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
93675 sqlite3VdbeJumpHere(v, j1);
93676 sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols);
93677 }
93678
93679 /* Cannot have triggers on a virtual table. If it were possible,
93680 ** this block would have to account for hidden column.
93681 */
@@ -93705,12 +93748,11 @@
93705 ** do not attempt any conversions before assembling the record.
93706 ** If this is a real table, attempt conversions as required by the
93707 ** table column affinities.
93708 */
93709 if( !isView ){
93710 sqlite3VdbeAddOp2(v, OP_Affinity, regCols+1, pTab->nCol);
93711 sqlite3TableAffinityStr(v, pTab);
93712 }
93713
93714 /* Fire BEFORE or INSTEAD OF triggers */
93715 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
93716 pTab, regCols-pTab->nCol-1, onError, endOfLoop);
@@ -93728,11 +93770,11 @@
93728 }
93729 if( ipkColumn>=0 ){
93730 if( useTempTable ){
93731 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
93732 }else if( pSelect ){
93733 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+ipkColumn, regRowid);
93734 }else{
93735 VdbeOp *pOp;
93736 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
93737 pOp = sqlite3VdbeGetOp(v, -1);
93738 if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
@@ -93747,18 +93789,18 @@
93747 ** to generate a unique primary key value.
93748 */
93749 if( !appendFlag ){
93750 int j1;
93751 if( !IsVirtual(pTab) ){
93752 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid);
93753 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
93754 sqlite3VdbeJumpHere(v, j1);
93755 }else{
93756 j1 = sqlite3VdbeCurrentAddr(v);
93757 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2);
93758 }
93759 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid);
93760 }
93761 }else if( IsVirtual(pTab) || withoutRowid ){
93762 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
93763 }else{
93764 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -93774,12 +93816,13 @@
93774 int iRegStore = regRowid+1+i;
93775 if( i==pTab->iPKey ){
93776 /* The value of the INTEGER PRIMARY KEY column is always a NULL.
93777 ** Whenever this column is read, the rowid will be substituted
93778 ** in its place. Hence, fill this column with a NULL to avoid
93779 ** taking up data space with information that will never be used. */
93780 sqlite3VdbeAddOp2(v, OP_Null, 0, iRegStore);
 
93781 continue;
93782 }
93783 if( pColumn==0 ){
93784 if( IsHiddenColumn(&pTab->aCol[i]) ){
93785 assert( IsVirtual(pTab) );
@@ -93792,15 +93835,17 @@
93792 for(j=0; j<pColumn->nId; j++){
93793 if( pColumn->a[j].idx==i ) break;
93794 }
93795 }
93796 if( j<0 || nColumn==0 || (pColumn && j>=pColumn->nId) ){
93797 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, iRegStore);
93798 }else if( useTempTable ){
93799 sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, iRegStore);
93800 }else if( pSelect ){
93801 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore);
 
 
93802 }else{
93803 sqlite3ExprCode(pParse, pList->a[j].pExpr, iRegStore);
93804 }
93805 }
93806
@@ -93842,11 +93887,11 @@
93842 /* The bottom of the main insertion loop, if the data source
93843 ** is a SELECT statement.
93844 */
93845 sqlite3VdbeResolveLabel(v, endOfLoop);
93846 if( useTempTable ){
93847 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont);
93848 sqlite3VdbeJumpHere(v, addrInsTop);
93849 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
93850 }else if( pSelect ){
93851 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
93852 sqlite3VdbeJumpHere(v, addrInsTop);
@@ -94009,10 +94054,11 @@
94009 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
94010 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
94011 int ipkTop = 0; /* Top of the rowid change constraint check */
94012 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
94013 u8 isUpdate; /* True if this is an UPDATE operation */
 
94014 int regRowid = -1; /* Register holding ROWID value */
94015
94016 isUpdate = regOldData!=0;
94017 db = pParse->db;
94018 v = sqlite3GetVdbe(pParse);
@@ -94063,19 +94109,21 @@
94063 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
94064 pTab->aCol[i].zName);
94065 sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
94066 regNewData+1+i, zMsg, P4_DYNAMIC);
94067 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
 
94068 break;
94069 }
94070 case OE_Ignore: {
94071 sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
 
94072 break;
94073 }
94074 default: {
94075 assert( onError==OE_Replace );
94076 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i);
94077 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
94078 sqlite3VdbeJumpHere(v, j1);
94079 break;
94080 }
94081 }
@@ -94123,10 +94171,12 @@
94123 if( isUpdate ){
94124 /* pkChng!=0 does not mean that the rowid has change, only that
94125 ** it might have changed. Skip the conflict logic below if the rowid
94126 ** is unchanged. */
94127 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
 
 
94128 }
94129
94130 /* If the response to a rowid conflict is REPLACE but the response
94131 ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
94132 ** to defer the running of the rowid conflict checking until after
@@ -94142,10 +94192,11 @@
94142 }
94143
94144 /* Check to see if the new rowid already exists in the table. Skip
94145 ** the following conflict logic if it does not. */
94146 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
 
94147
94148 /* Generate code that deals with a rowid collision */
94149 switch( onError ){
94150 default: {
94151 onError = OE_Abort;
@@ -94220,10 +94271,14 @@
94220 int regR; /* Range of registers holding conflicting PK */
94221 int iThisCur; /* Cursor for this UNIQUE index */
94222 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
94223
94224 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
 
 
 
 
94225 iThisCur = iIdxCur+ix;
94226 addrUniqueOk = sqlite3VdbeMakeLabel(v);
94227
94228 /* Skip partial indices for which the WHERE clause is not true */
94229 if( pIdx->pPartIdxWhere ){
@@ -94250,11 +94305,10 @@
94250 }
94251 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94252 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
94253 }
94254 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
94255 sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
94256 VdbeComment((v, "for %s", pIdx->zName));
94257 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
94258
94259 /* In an UPDATE operation, if this index is the PRIMARY KEY index
94260 ** of a WITHOUT ROWID table and there has been no change the
@@ -94278,11 +94332,11 @@
94278 onError = OE_Abort;
94279 }
94280
94281 /* Check to see if the new index entry will be unique */
94282 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94283 regIdx, pIdx->nKeyCol);
94284
94285 /* Generate code to handle collisions */
94286 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94287 if( isUpdate || onError==OE_Replace ){
94288 if( HasRowid(pTab) ){
@@ -94289,10 +94343,12 @@
94289 sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94290 /* Conflict only if the rowid of the existing index entry
94291 ** is different from old-rowid */
94292 if( isUpdate ){
94293 sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
 
 
94294 }
94295 }else{
94296 int x;
94297 /* Extract the PRIMARY KEY from the end of the index entry and
94298 ** store it in registers regR..regR+nPk-1 */
@@ -94324,10 +94380,13 @@
94324 op = OP_Eq;
94325 }
94326 sqlite3VdbeAddOp4(v, op,
94327 regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94328 );
 
 
 
94329 }
94330 }
94331 }
94332 }
94333
@@ -94395,18 +94454,21 @@
94395 Index *pIdx; /* An index being inserted or updated */
94396 u8 pik_flags; /* flag values passed to the btree insert */
94397 int regData; /* Content registers (after the rowid) */
94398 int regRec; /* Register holding assemblied record for the table */
94399 int i; /* Loop counter */
 
94400
94401 v = sqlite3GetVdbe(pParse);
94402 assert( v!=0 );
94403 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
94404 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94405 if( aRegIdx[i]==0 ) continue;
 
94406 if( pIdx->pPartIdxWhere ){
94407 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
 
94408 }
94409 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
94410 pik_flags = 0;
94411 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
94412 if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
@@ -94417,11 +94479,11 @@
94417 }
94418 if( !HasRowid(pTab) ) return;
94419 regData = regNewData + 1;
94420 regRec = sqlite3GetTempReg(pParse);
94421 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
94422 sqlite3TableAffinityStr(v, pTab);
94423 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
94424 if( pParse->nested ){
94425 pik_flags = 0;
94426 }else{
94427 pik_flags = OPFLAG_NCHANGE;
@@ -94786,20 +94848,21 @@
94786 ** (2) The destination has a unique index. (The xfer optimization
94787 ** is unable to test uniqueness.)
94788 **
94789 ** (3) onError is something other than OE_Abort and OE_Rollback.
94790 */
94791 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0);
94792 emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
94793 sqlite3VdbeJumpHere(v, addr1);
94794 }
94795 if( HasRowid(pSrc) ){
94796 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
94797 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94798 if( pDest->iPKey>=0 ){
94799 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
94800 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
 
94801 sqlite3RowidConstraint(pParse, onError, pDest);
94802 sqlite3VdbeJumpHere(v, addr2);
94803 autoIncStep(pParse, regAutoinc, regRowid);
94804 }else if( pDest->pIndex==0 ){
94805 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
@@ -94809,11 +94872,11 @@
94809 }
94810 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
94811 sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
94812 sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
94813 sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
94814 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1);
94815 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94816 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94817 }else{
94818 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
94819 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
@@ -94828,19 +94891,19 @@
94828 VdbeComment((v, "%s", pSrcIdx->zName));
94829 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
94830 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
94831 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
94832 VdbeComment((v, "%s", pDestIdx->zName));
94833 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0);
94834 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
94835 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
94836 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1);
94837 sqlite3VdbeJumpHere(v, addr1);
94838 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94839 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94840 }
94841 sqlite3VdbeJumpHere(v, emptySrcTest);
94842 sqlite3ReleaseTempReg(pParse, regRowid);
94843 sqlite3ReleaseTempReg(pParse, regData);
94844 if( emptyDestTest ){
94845 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
94846 sqlite3VdbeJumpHere(v, emptyDestTest);
@@ -97070,10 +97133,11 @@
97070 ** is always on by default regardless of the sign of the default cache
97071 ** size. But continue to take the absolute value of the default cache
97072 ** size of historical compatibility.
97073 */
97074 case PragTyp_DEFAULT_CACHE_SIZE: {
 
97075 static const VdbeOpList getCacheSize[] = {
97076 { OP_Transaction, 0, 0, 0}, /* 0 */
97077 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
97078 { OP_IfPos, 1, 8, 0},
97079 { OP_Integer, 0, 2, 0},
@@ -97087,11 +97151,11 @@
97087 sqlite3VdbeUsesBtree(v, iDb);
97088 if( !zRight ){
97089 sqlite3VdbeSetNumCols(v, 1);
97090 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
97091 pParse->nMem += 2;
97092 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
97093 sqlite3VdbeChangeP1(v, addr, iDb);
97094 sqlite3VdbeChangeP1(v, addr+1, iDb);
97095 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
97096 }else{
97097 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
@@ -97332,20 +97396,21 @@
97332 /* When setting the auto_vacuum mode to either "full" or
97333 ** "incremental", write the value of meta[6] in the database
97334 ** file. Before writing to meta[6], check that meta[3] indicates
97335 ** that this really is an auto-vacuum capable database.
97336 */
 
97337 static const VdbeOpList setMeta6[] = {
97338 { OP_Transaction, 0, 1, 0}, /* 0 */
97339 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
97340 { OP_If, 1, 0, 0}, /* 2 */
97341 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
97342 { OP_Integer, 0, 1, 0}, /* 4 */
97343 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
97344 };
97345 int iAddr;
97346 iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
97347 sqlite3VdbeChangeP1(v, iAddr, iDb);
97348 sqlite3VdbeChangeP1(v, iAddr+1, iDb);
97349 sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
97350 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
97351 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
@@ -97367,14 +97432,14 @@
97367 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
97368 iLimit = 0x7fffffff;
97369 }
97370 sqlite3BeginWriteOperation(pParse, 0, iDb);
97371 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
97372 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb);
97373 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
97374 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
97375 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr);
97376 sqlite3VdbeJumpHere(v, addr);
97377 break;
97378 }
97379 #endif
97380
@@ -97941,11 +98006,11 @@
97941 }
97942 }
97943 assert( pParse->nErr>0 || pFK==0 );
97944 if( pFK ) break;
97945 if( pParse->nTab<i ) pParse->nTab = i;
97946 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0);
97947 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
97948 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
97949 pIdx = 0;
97950 aiCols = 0;
97951 if( pParent ){
@@ -97957,30 +98022,30 @@
97957 int iKey = pFK->aCol[0].iFrom;
97958 assert( iKey>=0 && iKey<pTab->nCol );
97959 if( iKey!=pTab->iPKey ){
97960 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
97961 sqlite3ColumnDefault(v, pTab, iKey, regRow);
97962 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk);
97963 sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
97964 sqlite3VdbeCurrentAddr(v)+3);
97965 }else{
97966 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
97967 }
97968 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow);
97969 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
97970 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
97971 }else{
97972 for(j=0; j<pFK->nCol; j++){
97973 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
97974 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
97975 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk);
97976 }
97977 if( pParent ){
97978 sqlite3VdbeAddOp3(v, OP_MakeRecord, regRow, pFK->nCol, regKey);
97979 sqlite3VdbeChangeP4(v, -1,
97980 sqlite3IndexAffinityStr(v,pIdx), P4_TRANSIENT);
97981 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
 
97982 }
97983 }
97984 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
97985 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
97986 pFK->zTo, P4_TRANSIENT);
@@ -97987,11 +98052,11 @@
97987 sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
97988 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
97989 sqlite3VdbeResolveLabel(v, addrOk);
97990 sqlite3DbFree(db, aiCols);
97991 }
97992 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1);
97993 sqlite3VdbeJumpHere(v, addrTop);
97994 }
97995 }
97996 break;
97997 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
@@ -98034,10 +98099,11 @@
98034
98035 /* Code that appears at the end of the integrity check. If no error
98036 ** messages have been generated, output OK. Otherwise output the
98037 ** error message
98038 */
 
98039 static const VdbeOpList endCode[] = {
98040 { OP_AddImm, 1, 0, 0}, /* 0 */
98041 { OP_IfNeg, 1, 0, 0}, /* 1 */
98042 { OP_String8, 0, 3, 0}, /* 2 */
98043 { OP_ResultRow, 3, 1, 0},
@@ -98082,10 +98148,11 @@
98082 if( OMIT_TEMPDB && i==1 ) continue;
98083 if( iDb>=0 && i!=iDb ) continue;
98084
98085 sqlite3CodeVerifySchema(pParse, i);
98086 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
 
98087 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98088 sqlite3VdbeJumpHere(v, addr);
98089
98090 /* Do an integrity check of the B-Tree
98091 **
@@ -98113,11 +98180,11 @@
98113 pParse->nMem = MAX( pParse->nMem, cnt+8 );
98114
98115 /* Do the b-tree integrity checks */
98116 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
98117 sqlite3VdbeChangeP5(v, (u8)i);
98118 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2);
98119 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
98120 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
98121 P4_DYNAMIC);
98122 sqlite3VdbeAddOp2(v, OP_Move, 2, 4);
98123 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
@@ -98135,10 +98202,11 @@
98135 int r1 = -1;
98136
98137 if( pTab->pIndex==0 ) continue;
98138 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
98139 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
 
98140 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98141 sqlite3VdbeJumpHere(v, addr);
98142 sqlite3ExprCacheClear(pParse);
98143 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98144 1, 0, &iDataCur, &iIdxCur);
@@ -98145,57 +98213,58 @@
98145 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98146 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98147 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98148 }
98149 pParse->nMem = MAX(pParse->nMem, 8+j);
98150 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0);
98151 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
98152 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98153 int jmp2, jmp3, jmp4;
98154 if( pPk==pIdx ) continue;
98155 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
98156 pPrior, r1);
98157 pPrior = pIdx;
98158 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
98159 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
98160 pIdx->nColumn);
98161 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
98162 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
98163 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
98164 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
98165 P4_STATIC);
98166 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98167 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
98168 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98169 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
98170 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1);
98171 sqlite3VdbeAddOp0(v, OP_Halt);
98172 sqlite3VdbeJumpHere(v, jmp4);
98173 sqlite3VdbeJumpHere(v, jmp2);
98174 sqlite3VdbeResolveLabel(v, jmp3);
98175 }
98176 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop);
98177 sqlite3VdbeJumpHere(v, loopTop-1);
98178 #ifndef SQLITE_OMIT_BTREECOUNT
98179 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
98180 "wrong # of entries in index ", P4_STATIC);
98181 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98182 if( pPk==pIdx ) continue;
98183 addr = sqlite3VdbeCurrentAddr(v);
98184 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2);
98185 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98186 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
98187 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3);
 
98188 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
98189 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
98190 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
98191 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
98192 }
98193 #endif /* SQLITE_OMIT_BTREECOUNT */
98194 }
98195 }
98196 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
98197 sqlite3VdbeChangeP2(v, addr, -mxErr);
98198 sqlite3VdbeJumpHere(v, addr+1);
98199 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
98200 }
98201 break;
@@ -98329,11 +98398,11 @@
98329 static const VdbeOpList setCookie[] = {
98330 { OP_Transaction, 0, 1, 0}, /* 0 */
98331 { OP_Integer, 0, 1, 0}, /* 1 */
98332 { OP_SetCookie, 0, 0, 1}, /* 2 */
98333 };
98334 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
98335 sqlite3VdbeChangeP1(v, addr, iDb);
98336 sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
98337 sqlite3VdbeChangeP1(v, addr+2, iDb);
98338 sqlite3VdbeChangeP2(v, addr+2, iCookie);
98339 }else{
@@ -98341,11 +98410,11 @@
98341 static const VdbeOpList readCookie[] = {
98342 { OP_Transaction, 0, 0, 0}, /* 0 */
98343 { OP_ReadCookie, 0, 1, 0}, /* 1 */
98344 { OP_ResultRow, 1, 1, 0}
98345 };
98346 int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
98347 sqlite3VdbeChangeP1(v, addr, iDb);
98348 sqlite3VdbeChangeP1(v, addr+1, iDb);
98349 sqlite3VdbeChangeP3(v, addr+1, iCookie);
98350 sqlite3VdbeSetNumCols(v, 1);
98351 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
@@ -99547,10 +99616,18 @@
99547 if( p ){
99548 clearSelect(db, p);
99549 sqlite3DbFree(db, p);
99550 }
99551 }
 
 
 
 
 
 
 
 
99552
99553 /*
99554 ** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
99555 ** type of join. Return an integer constant that expresses that type
99556 ** in terms of the following bit values:
@@ -99886,11 +99963,11 @@
99886 if( pSelect->iOffset ){
99887 iLimit = pSelect->iOffset+1;
99888 }else{
99889 iLimit = pSelect->iLimit;
99890 }
99891 addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit);
99892 sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
99893 addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
99894 sqlite3VdbeJumpHere(v, addr1);
99895 sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor);
99896 sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor);
@@ -99907,11 +99984,11 @@
99907 int iContinue /* Jump here to skip the current record */
99908 ){
99909 if( iOffset>0 && iContinue!=0 ){
99910 int addr;
99911 sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
99912 addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset);
99913 sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
99914 VdbeComment((v, "skip OFFSET records"));
99915 sqlite3VdbeJumpHere(v, addr);
99916 }
99917 }
@@ -99935,11 +100012,11 @@
99935 Vdbe *v;
99936 int r1;
99937
99938 v = pParse->pVdbe;
99939 r1 = sqlite3GetTempReg(pParse);
99940 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N);
99941 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
99942 sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
99943 sqlite3ReleaseTempReg(pParse, r1);
99944 }
99945
@@ -100016,17 +100093,23 @@
100016 }
100017
100018 /* Pull the requested columns.
100019 */
100020 nResultCol = pEList->nExpr;
 
100021 if( pDest->iSdst==0 ){
100022 pDest->iSdst = pParse->nMem+1;
100023 pDest->nSdst = nResultCol;
 
 
 
 
 
 
100024 pParse->nMem += nResultCol;
100025 }else{
100026 assert( pDest->nSdst==nResultCol );
100027 }
 
100028 regResult = pDest->iSdst;
100029 if( srcTab>=0 ){
100030 for(i=0; i<nResultCol; i++){
100031 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
100032 VdbeComment((v, "%s", pEList->a[i].zName));
@@ -100069,13 +100152,15 @@
100069 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
100070 for(i=0; i<nResultCol; i++){
100071 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100072 if( i<nResultCol-1 ){
100073 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
 
100074 }else{
100075 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100076 }
 
100077 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100078 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100079 }
100080 assert( sqlite3VdbeCurrentAddr(v)==iJump );
100081 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
@@ -100137,11 +100222,11 @@
100137 ** on an ephemeral index. If the current row is already present
100138 ** in the index, do not write it to the output. If not, add the
100139 ** current row to the index and proceed with writing it to the
100140 ** output table as well. */
100141 int addr = sqlite3VdbeCurrentAddr(v) + 4;
100142 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
100143 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
100144 assert( pOrderBy==0 );
100145 }
100146 #endif
100147 if( pOrderBy ){
@@ -100204,16 +100289,12 @@
100204 }
100205 break;
100206 }
100207 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
100208
100209 /* Send the data to the callback function or to a subroutine. In the
100210 ** case of a subroutine, the subroutine itself is responsible for
100211 ** popping the data from the stack.
100212 */
100213 case SRT_Coroutine:
100214 case SRT_Output: {
100215 testcase( eDest==SRT_Coroutine );
100216 testcase( eDest==SRT_Output );
100217 if( pOrderBy ){
100218 int r1 = sqlite3GetTempReg(pParse);
100219 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
@@ -100245,17 +100326,20 @@
100245 assert( pSO );
100246 nKey = pSO->nExpr;
100247 r1 = sqlite3GetTempReg(pParse);
100248 r2 = sqlite3GetTempRange(pParse, nKey+2);
100249 r3 = r2+nKey+1;
100250 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100251 if( eDest==SRT_DistQueue ){
100252 /* If the destination is DistQueue, then cursor (iParm+1) is open
100253 ** on a second ephemeral index that holds all values every previously
100254 ** added to the queue. Only add this new value if it has never before
100255 ** been added */
100256 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0);
 
 
 
 
100257 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
100258 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
100259 }
100260 for(i=0; i<nKey; i++){
100261 sqlite3VdbeAddOp2(v, OP_SCopy,
@@ -100290,11 +100374,11 @@
100290 /* Jump to the end of the loop if the LIMIT is reached. Except, if
100291 ** there is a sorter, in which case the sorter has already limited
100292 ** the output for us.
100293 */
100294 if( pOrderBy==0 && p->iLimit ){
100295 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
100296 }
100297 }
100298
100299 /*
100300 ** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -100509,16 +100593,17 @@
100509 if( p->selFlags & SF_UseSorter ){
100510 int regSortOut = ++pParse->nMem;
100511 int ptab2 = pParse->nTab++;
100512 sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100513 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
 
100514 codeOffset(v, p->iOffset, addrContinue);
100515 sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100516 sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100517 sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100518 }else{
100519 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
100520 codeOffset(v, p->iOffset, addrContinue);
100521 sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100522 }
100523 switch( eDest ){
100524 case SRT_Table:
@@ -100572,13 +100657,13 @@
100572
100573 /* The bottom of the loop
100574 */
100575 sqlite3VdbeResolveLabel(v, addrContinue);
100576 if( p->selFlags & SF_UseSorter ){
100577 sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr);
100578 }else{
100579 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr);
100580 }
100581 sqlite3VdbeResolveLabel(v, addrBreak);
100582 if( eDest==SRT_Output || eDest==SRT_Coroutine ){
100583 sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0);
100584 }
@@ -101058,15 +101143,17 @@
101058 */
101059 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
101060 Vdbe *v = pParse->pVdbe;
101061 if( v==0 ){
101062 v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
101063 #ifndef SQLITE_OMIT_TRACE
101064 if( v ){
101065 sqlite3VdbeAddOp0(v, OP_Trace);
 
 
101066 }
101067 #endif
101068 }
101069 return v;
101070 }
101071
101072
@@ -101120,26 +101207,26 @@
101120 }else if( n>=0 && p->nSelectRow>(u64)n ){
101121 p->nSelectRow = n;
101122 }
101123 }else{
101124 sqlite3ExprCode(pParse, p->pLimit, iLimit);
101125 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit);
101126 VdbeComment((v, "LIMIT counter"));
101127 sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak);
101128 }
101129 if( p->pOffset ){
101130 p->iOffset = iOffset = ++pParse->nMem;
101131 pParse->nMem++; /* Allocate an extra register for limit+offset */
101132 sqlite3ExprCode(pParse, p->pOffset, iOffset);
101133 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset);
101134 VdbeComment((v, "OFFSET counter"));
101135 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset);
101136 sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
101137 sqlite3VdbeJumpHere(v, addr1);
101138 sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
101139 VdbeComment((v, "LIMIT+OFFSET"));
101140 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit);
101141 sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
101142 sqlite3VdbeJumpHere(v, addr1);
101143 }
101144 }
101145 }
@@ -101318,15 +101405,17 @@
101318
101319 /* Detach the ORDER BY clause from the compound SELECT */
101320 p->pOrderBy = 0;
101321
101322 /* Store the results of the setup-query in Queue. */
 
101323 rc = sqlite3Select(pParse, pSetup, &destQueue);
 
101324 if( rc ) goto end_of_recursive_query;
101325
101326 /* Find the next row in the Queue and output that row */
101327 addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak);
101328
101329 /* Transfer the next row in Queue over to Current */
101330 sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
101331 if( pOrderBy ){
101332 sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
@@ -101338,11 +101427,14 @@
101338 /* Output the single row in Current */
101339 addrCont = sqlite3VdbeMakeLabel(v);
101340 codeOffset(v, regOffset, addrCont);
101341 selectInnerLoop(pParse, p, p->pEList, iCurrent,
101342 0, 0, pDest, addrCont, addrBreak);
101343 if( regLimit ) sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
 
 
 
101344 sqlite3VdbeResolveLabel(v, addrCont);
101345
101346 /* Execute the recursive SELECT taking the single row in Current as
101347 ** the value for the recursive-table. Store the results in the Queue.
101348 */
@@ -101423,12 +101515,10 @@
101423 */
101424 assert( p && p->pPrior ); /* Calling function guarantees this much */
101425 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
101426 db = pParse->db;
101427 pPrior = p->pPrior;
101428 assert( pPrior->pRightmost!=pPrior );
101429 assert( pPrior->pRightmost==p->pRightmost );
101430 dest = *pDest;
101431 if( pPrior->pOrderBy ){
101432 sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
101433 selectOpName(p->op));
101434 rc = 1;
@@ -101500,11 +101590,11 @@
101500 }
101501 p->pPrior = 0;
101502 p->iLimit = pPrior->iLimit;
101503 p->iOffset = pPrior->iOffset;
101504 if( p->iLimit ){
101505 addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit);
101506 VdbeComment((v, "Jump ahead if LIMIT reached"));
101507 }
101508 explainSetInteger(iSub2, pParse->iNextSelectId);
101509 rc = sqlite3Select(pParse, p, &dest);
101510 testcase( rc!=SQLITE_OK );
@@ -101532,16 +101622,14 @@
101532 SelectDest uniondest;
101533
101534 testcase( p->op==TK_EXCEPT );
101535 testcase( p->op==TK_UNION );
101536 priorOp = SRT_Union;
101537 if( dest.eDest==priorOp && ALWAYS(!p->pLimit &&!p->pOffset) ){
101538 /* We can reuse a temporary table generated by a SELECT to our
101539 ** right.
101540 */
101541 assert( p->pRightmost!=p ); /* Can only happen for leftward elements
101542 ** of a 3-way or more compound */
101543 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
101544 assert( p->pOffset==0 ); /* Not allowed on leftward elements */
101545 unionTab = dest.iSDParm;
101546 }else{
101547 /* We will need to create our own temporary table to hold the
@@ -101550,11 +101638,11 @@
101550 unionTab = pParse->nTab++;
101551 assert( p->pOrderBy==0 );
101552 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
101553 assert( p->addrOpenEphm[0] == -1 );
101554 p->addrOpenEphm[0] = addr;
101555 p->pRightmost->selFlags |= SF_UsesEphemeral;
101556 assert( p->pEList );
101557 }
101558
101559 /* Code the SELECT statements to our left
101560 */
@@ -101609,16 +101697,16 @@
101609 generateColumnNames(pParse, 0, pFirst->pEList);
101610 }
101611 iBreak = sqlite3VdbeMakeLabel(v);
101612 iCont = sqlite3VdbeMakeLabel(v);
101613 computeLimitRegisters(pParse, p, iBreak);
101614 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak);
101615 iStart = sqlite3VdbeCurrentAddr(v);
101616 selectInnerLoop(pParse, p, p->pEList, unionTab,
101617 0, 0, &dest, iCont, iBreak);
101618 sqlite3VdbeResolveLabel(v, iCont);
101619 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart);
101620 sqlite3VdbeResolveLabel(v, iBreak);
101621 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
101622 }
101623 break;
101624 }
@@ -101639,11 +101727,11 @@
101639 assert( p->pOrderBy==0 );
101640
101641 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
101642 assert( p->addrOpenEphm[0] == -1 );
101643 p->addrOpenEphm[0] = addr;
101644 p->pRightmost->selFlags |= SF_UsesEphemeral;
101645 assert( p->pEList );
101646
101647 /* Code the SELECTs to our left into temporary table "tab1".
101648 */
101649 sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1);
@@ -101684,19 +101772,19 @@
101684 generateColumnNames(pParse, 0, pFirst->pEList);
101685 }
101686 iBreak = sqlite3VdbeMakeLabel(v);
101687 iCont = sqlite3VdbeMakeLabel(v);
101688 computeLimitRegisters(pParse, p, iBreak);
101689 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak);
101690 r1 = sqlite3GetTempReg(pParse);
101691 iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101692 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
101693 sqlite3ReleaseTempReg(pParse, r1);
101694 selectInnerLoop(pParse, p, p->pEList, tab1,
101695 0, 0, &dest, iCont, iBreak);
101696 sqlite3VdbeResolveLabel(v, iCont);
101697 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart);
101698 sqlite3VdbeResolveLabel(v, iBreak);
101699 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
101700 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
101701 break;
101702 }
@@ -101718,11 +101806,11 @@
101718 KeyInfo *pKeyInfo; /* Collating sequence for the result set */
101719 Select *pLoop; /* For looping through SELECT statements */
101720 CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
101721 int nCol; /* Number of columns in result set */
101722
101723 assert( p->pRightmost==p );
101724 nCol = p->pEList->nExpr;
101725 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
101726 if( !pKeyInfo ){
101727 rc = SQLITE_NOMEM;
101728 goto multi_select_end;
@@ -101799,14 +101887,14 @@
101799
101800 /* Suppress duplicates for UNION, EXCEPT, and INTERSECT
101801 */
101802 if( regPrev ){
101803 int j1, j2;
101804 j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev);
101805 j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
101806 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
101807 sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2);
101808 sqlite3VdbeJumpHere(v, j1);
101809 sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
101810 sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
101811 }
101812 if( pParse->db->mallocFailed ) return 0;
@@ -101903,11 +101991,11 @@
101903 }
101904
101905 /* Jump to the end of the loop if the LIMIT is reached.
101906 */
101907 if( p->iLimit ){
101908 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1);
101909 }
101910
101911 /* Generate the subroutine return
101912 */
101913 sqlite3VdbeResolveLabel(v, iContinue);
@@ -102011,20 +102099,19 @@
102011 Select *pPrior; /* Another SELECT immediately to our left */
102012 Vdbe *v; /* Generate code to this VDBE */
102013 SelectDest destA; /* Destination for coroutine A */
102014 SelectDest destB; /* Destination for coroutine B */
102015 int regAddrA; /* Address register for select-A coroutine */
102016 int regEofA; /* Flag to indicate when select-A is complete */
102017 int regAddrB; /* Address register for select-B coroutine */
102018 int regEofB; /* Flag to indicate when select-B is complete */
102019 int addrSelectA; /* Address of the select-A coroutine */
102020 int addrSelectB; /* Address of the select-B coroutine */
102021 int regOutA; /* Address register for the output-A subroutine */
102022 int regOutB; /* Address register for the output-B subroutine */
102023 int addrOutA; /* Address of the output-A subroutine */
102024 int addrOutB = 0; /* Address of the output-B subroutine */
102025 int addrEofA; /* Address of the select-A-exhausted subroutine */
 
102026 int addrEofB; /* Address of the select-B-exhausted subroutine */
102027 int addrAltB; /* Address of the A<B subroutine */
102028 int addrAeqB; /* Address of the A==B subroutine */
102029 int addrAgtB; /* Address of the A>B subroutine */
102030 int regLimitA; /* Limit register for select-A */
@@ -102135,10 +102222,11 @@
102135 }
102136
102137 /* Separate the left and the right query from one another
102138 */
102139 p->pPrior = 0;
 
102140 sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
102141 if( pPrior->pPrior==0 ){
102142 sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
102143 }
102144
@@ -102157,52 +102245,43 @@
102157 p->pLimit = 0;
102158 sqlite3ExprDelete(db, p->pOffset);
102159 p->pOffset = 0;
102160
102161 regAddrA = ++pParse->nMem;
102162 regEofA = ++pParse->nMem;
102163 regAddrB = ++pParse->nMem;
102164 regEofB = ++pParse->nMem;
102165 regOutA = ++pParse->nMem;
102166 regOutB = ++pParse->nMem;
102167 sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
102168 sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
102169
102170 /* Jump past the various subroutines and coroutines to the main
102171 ** merge loop
102172 */
102173 j1 = sqlite3VdbeAddOp0(v, OP_Goto);
102174 addrSelectA = sqlite3VdbeCurrentAddr(v);
102175
102176
102177 /* Generate a coroutine to evaluate the SELECT statement to the
102178 ** left of the compound operator - the "A" select.
102179 */
102180 VdbeNoopComment((v, "Begin coroutine for left SELECT"));
 
 
102181 pPrior->iLimit = regLimitA;
102182 explainSetInteger(iSub1, pParse->iNextSelectId);
102183 sqlite3Select(pParse, pPrior, &destA);
102184 sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofA);
102185 sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102186 VdbeNoopComment((v, "End coroutine for left SELECT"));
102187
102188 /* Generate a coroutine to evaluate the SELECT statement on
102189 ** the right - the "B" select
102190 */
102191 addrSelectB = sqlite3VdbeCurrentAddr(v);
102192 VdbeNoopComment((v, "Begin coroutine for right SELECT"));
 
102193 savedLimit = p->iLimit;
102194 savedOffset = p->iOffset;
102195 p->iLimit = regLimitB;
102196 p->iOffset = 0;
102197 explainSetInteger(iSub2, pParse->iNextSelectId);
102198 sqlite3Select(pParse, p, &destB);
102199 p->iLimit = savedLimit;
102200 p->iOffset = savedOffset;
102201 sqlite3VdbeAddOp2(v, OP_Integer, 1, regEofB);
102202 sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102203 VdbeNoopComment((v, "End coroutine for right SELECT"));
102204
102205 /* Generate a subroutine that outputs the current row of the A
102206 ** select as the next output row of the compound select.
102207 */
102208 VdbeNoopComment((v, "Output routine for A"));
@@ -102222,17 +102301,17 @@
102222 sqlite3KeyInfoUnref(pKeyDup);
102223
102224 /* Generate a subroutine to run when the results from select A
102225 ** are exhausted and only data in select B remains.
102226 */
102227 VdbeNoopComment((v, "eof-A subroutine"));
102228 if( op==TK_EXCEPT || op==TK_INTERSECT ){
102229 addrEofA = sqlite3VdbeAddOp2(v, OP_Goto, 0, labelEnd);
102230 }else{
102231 addrEofA = sqlite3VdbeAddOp2(v, OP_If, regEofB, labelEnd);
102232 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102233 sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
 
102234 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
102235 p->nSelectRow += pPrior->nSelectRow;
102236 }
102237
102238 /* Generate a subroutine to run when the results from select B
@@ -102241,22 +102320,20 @@
102241 if( op==TK_INTERSECT ){
102242 addrEofB = addrEofA;
102243 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
102244 }else{
102245 VdbeNoopComment((v, "eof-B subroutine"));
102246 addrEofB = sqlite3VdbeAddOp2(v, OP_If, regEofA, labelEnd);
102247 sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102248 sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102249 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
102250 }
102251
102252 /* Generate code to handle the case of A<B
102253 */
102254 VdbeNoopComment((v, "A-lt-B subroutine"));
102255 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102256 sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102257 sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102258 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102259
102260 /* Generate code to handle the case of A==B
102261 */
102262 if( op==TK_ALL ){
@@ -102265,12 +102342,11 @@
102265 addrAeqB = addrAltB;
102266 addrAltB++;
102267 }else{
102268 VdbeNoopComment((v, "A-eq-B subroutine"));
102269 addrAeqB =
102270 sqlite3VdbeAddOp1(v, OP_Yield, regAddrA);
102271 sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102272 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102273 }
102274
102275 /* Generate code to handle the case of A>B
102276 */
@@ -102277,32 +102353,27 @@
102277 VdbeNoopComment((v, "A-gt-B subroutine"));
102278 addrAgtB = sqlite3VdbeCurrentAddr(v);
102279 if( op==TK_ALL || op==TK_UNION ){
102280 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102281 }
102282 sqlite3VdbeAddOp1(v, OP_Yield, regAddrB);
102283 sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB);
102284 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102285
102286 /* This code runs once to initialize everything.
102287 */
102288 sqlite3VdbeJumpHere(v, j1);
102289 sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofA);
102290 sqlite3VdbeAddOp2(v, OP_Integer, 0, regEofB);
102291 sqlite3VdbeAddOp2(v, OP_Gosub, regAddrA, addrSelectA);
102292 sqlite3VdbeAddOp2(v, OP_Gosub, regAddrB, addrSelectB);
102293 sqlite3VdbeAddOp2(v, OP_If, regEofA, addrEofA);
102294 sqlite3VdbeAddOp2(v, OP_If, regEofB, addrEofB);
102295
102296 /* Implement the main merge loop
102297 */
102298 sqlite3VdbeResolveLabel(v, labelCmpr);
102299 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
102300 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
102301 (char*)pKeyMerge, P4_KEYINFO);
102302 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
102303 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB);
102304
102305 /* Jump to the this point in order to terminate the query.
102306 */
102307 sqlite3VdbeResolveLabel(v, labelEnd);
102308
@@ -102318,10 +102389,11 @@
102318 ** by the calling function */
102319 if( p->pPrior ){
102320 sqlite3SelectDelete(db, p->pPrior);
102321 }
102322 p->pPrior = pPrior;
 
102323
102324 /*** TBD: Insert subroutine calls to close cursors on incomplete
102325 **** subqueries ****/
102326 explainComposite(pParse, p->op, iSub1, iSub2, 0);
102327 return SQLITE_OK;
@@ -102583,11 +102655,11 @@
102583 ** because they could be computed at compile-time. But when LIMIT and OFFSET
102584 ** became arbitrary expressions, we were forced to add restrictions (13)
102585 ** and (14). */
102586 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
102587 if( pSub->pOffset ) return 0; /* Restriction (14) */
102588 if( p->pRightmost && pSub->pLimit ){
102589 return 0; /* Restriction (15) */
102590 }
102591 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
102592 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (5) */
102593 if( pSub->pLimit && (pSrc->nSrc>1 || isAgg) ){
@@ -102734,18 +102806,18 @@
102734 p->pOffset = pOffset;
102735 p->pLimit = pLimit;
102736 p->pOrderBy = pOrderBy;
102737 p->pSrc = pSrc;
102738 p->op = TK_ALL;
102739 p->pRightmost = 0;
102740 if( pNew==0 ){
102741 pNew = pPrior;
102742 }else{
102743 pNew->pPrior = pPrior;
102744 pNew->pRightmost = 0;
 
 
102745 }
102746 p->pPrior = pNew;
102747 if( db->mallocFailed ) return 1;
102748 }
102749
102750 /* Begin flattening the iFrom-th entry of the FROM clause
102751 ** in the outer query.
@@ -103080,10 +103152,14 @@
103080 p->pWhere = 0;
103081 pNew->pGroupBy = 0;
103082 pNew->pHaving = 0;
103083 pNew->pOrderBy = 0;
103084 p->pPrior = 0;
 
 
 
 
103085 pNew->pLimit = 0;
103086 pNew->pOffset = 0;
103087 return WRC_Continue;
103088 }
103089
@@ -103267,13 +103343,14 @@
103267 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
103268 ** names and other FROM clause elements.
103269 */
103270 static void selectPopWith(Walker *pWalker, Select *p){
103271 Parse *pParse = pWalker->pParse;
103272 if( p->pWith ){
103273 assert( pParse->pWith==p->pWith );
103274 pParse->pWith = p->pWith->pOuter;
 
103275 }
103276 }
103277 #else
103278 #define selectPopWith 0
103279 #endif
@@ -103319,11 +103396,11 @@
103319 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
103320 return WRC_Prune;
103321 }
103322 pTabList = p->pSrc;
103323 pEList = p->pEList;
103324 sqlite3WithPush(pParse, p->pWith, 0);
103325
103326 /* Make sure cursor numbers have been assigned to all entries in
103327 ** the FROM clause of the SELECT statement.
103328 */
103329 sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -103832,11 +103909,11 @@
103832 **
103833 ** Another solution would be to change the OP_SCopy used to copy cached
103834 ** values to an OP_Copy.
103835 */
103836 if( regHit ){
103837 addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit);
103838 }
103839 sqlite3ExprCacheClear(pParse);
103840 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
103841 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
103842 }
@@ -103991,46 +104068,28 @@
103991 if( isAggSub ){
103992 isAgg = 1;
103993 p->selFlags |= SF_Aggregate;
103994 }
103995 i = -1;
103996 }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0
103997 && OptimizationEnabled(db, SQLITE_SubqCoroutine)
103998 ){
103999 /* Implement a co-routine that will return a single row of the result
104000 ** set on each invocation.
104001 */
104002 int addrTop;
104003 int addrEof;
104004 pItem->regReturn = ++pParse->nMem;
104005 addrEof = ++pParse->nMem;
104006 /* Before coding the OP_Goto to jump to the start of the main routine,
104007 ** ensure that the jump to the verify-schema routine has already
104008 ** been coded. Otherwise, the verify-schema would likely be coded as
104009 ** part of the co-routine. If the main routine then accessed the
104010 ** database before invoking the co-routine for the first time (for
104011 ** example to initialize a LIMIT register from a sub-select), it would
104012 ** be doing so without having verified the schema version and obtained
104013 ** the required db locks. See ticket d6b36be38. */
104014 sqlite3CodeVerifySchema(pParse, -1);
104015 sqlite3VdbeAddOp0(v, OP_Goto);
104016 addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor);
104017 sqlite3VdbeChangeP5(v, 1);
104018 VdbeComment((v, "coroutine for %s", pItem->pTab->zName));
104019 pItem->addrFillSub = addrTop;
104020 sqlite3VdbeAddOp2(v, OP_Integer, 0, addrEof);
104021 sqlite3VdbeChangeP5(v, 1);
104022 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
104023 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104024 sqlite3Select(pParse, pSub, &dest);
104025 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
104026 pItem->viaCoroutine = 1;
104027 sqlite3VdbeChangeP2(v, addrTop, dest.iSdst);
104028 sqlite3VdbeChangeP3(v, addrTop, dest.nSdst);
104029 sqlite3VdbeAddOp2(v, OP_Integer, 1, addrEof);
104030 sqlite3VdbeAddOp1(v, OP_Yield, pItem->regReturn);
104031 VdbeComment((v, "end %s", pItem->pTab->zName));
104032 sqlite3VdbeJumpHere(v, addrTop-1);
104033 sqlite3ClearTempRegCache(pParse);
104034 }else{
104035 /* Generate a subroutine that will fill an ephemeral table with
104036 ** the content of this subquery. pItem->addrFillSub will point
@@ -104042,16 +104101,18 @@
104042 int retAddr;
104043 assert( pItem->addrFillSub==0 );
104044 pItem->regReturn = ++pParse->nMem;
104045 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
104046 pItem->addrFillSub = topAddr+1;
104047 VdbeNoopComment((v, "materialize %s", pItem->pTab->zName));
104048 if( pItem->isCorrelated==0 ){
104049 /* If the subquery is not correlated and if we are not inside of
104050 ** a trigger, then we only need to compute the value of the subquery
104051 ** once. */
104052 onceAddr = sqlite3CodeOnce(pParse);
 
 
 
104053 }
104054 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
104055 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104056 sqlite3Select(pParse, pSub, &dest);
104057 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
@@ -104079,25 +104140,10 @@
104079
104080 #ifndef SQLITE_OMIT_COMPOUND_SELECT
104081 /* If there is are a sequence of queries, do the earlier ones first.
104082 */
104083 if( p->pPrior ){
104084 if( p->pRightmost==0 ){
104085 Select *pLoop, *pRight = 0;
104086 int cnt = 0;
104087 int mxSelect;
104088 for(pLoop=p; pLoop; pLoop=pLoop->pPrior, cnt++){
104089 pLoop->pRightmost = p;
104090 pLoop->pNext = pRight;
104091 pRight = pLoop;
104092 }
104093 mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
104094 if( mxSelect && cnt>mxSelect ){
104095 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
104096 goto select_end;
104097 }
104098 }
104099 rc = multiSelect(pParse, p, pDest);
104100 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
104101 return rc;
104102 }
104103 #endif
@@ -104397,11 +104443,11 @@
104397 sqlite3WhereEnd(pWInfo);
104398 sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
104399 sortOut = sqlite3GetTempReg(pParse);
104400 sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
104401 sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
104402 VdbeComment((v, "GROUP BY sort"));
104403 sAggInfo.useSortingIdx = 1;
104404 sqlite3ExprCacheClear(pParse);
104405 }
104406
104407 /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
@@ -104424,11 +104470,11 @@
104424 }
104425 }
104426 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
104427 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
104428 j1 = sqlite3VdbeCurrentAddr(v);
104429 sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1);
104430
104431 /* Generate code that runs whenever the GROUP BY changes.
104432 ** Changes in the GROUP BY are detected by the previous code
104433 ** block. If there were no changes, this block is skipped.
104434 **
@@ -104438,11 +104484,11 @@
104438 ** for the next GROUP BY batch.
104439 */
104440 sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
104441 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
104442 VdbeComment((v, "output one row"));
104443 sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd);
104444 VdbeComment((v, "check abort flag"));
104445 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
104446 VdbeComment((v, "reset accumulator"));
104447
104448 /* Update the aggregate accumulators based on the content of
@@ -104455,10 +104501,11 @@
104455
104456 /* End of the loop
104457 */
104458 if( groupBySort ){
104459 sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
 
104460 }else{
104461 sqlite3WhereEnd(pWInfo);
104462 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
104463 }
104464
@@ -104482,11 +104529,11 @@
104482 sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag);
104483 VdbeComment((v, "set abort flag"));
104484 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104485 sqlite3VdbeResolveLabel(v, addrOutputRow);
104486 addrOutputRow = sqlite3VdbeCurrentAddr(v);
104487 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
104488 VdbeComment((v, "Groupby result generator entry point"));
104489 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104490 finalizeAggFunctions(pParse, &sAggInfo);
104491 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104492 selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
@@ -104755,14 +104802,10 @@
104755 SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){
104756 if( p==0 ){
104757 sqlite3ExplainPrintf(pVdbe, "(null-select)");
104758 return;
104759 }
104760 while( p->pPrior ){
104761 p->pPrior->pNext = p;
104762 p = p->pPrior;
104763 }
104764 sqlite3ExplainPush(pVdbe);
104765 while( p ){
104766 explainOneSelect(pVdbe, p);
104767 p = p->pNext;
104768 if( p==0 ) break;
@@ -105543,10 +105586,11 @@
105543 /* Generate code to destroy the database record of the trigger.
105544 */
105545 assert( pTable!=0 );
105546 if( (v = sqlite3GetVdbe(pParse))!=0 ){
105547 int base;
 
105548 static const VdbeOpList dropTrigger[] = {
105549 { OP_Rewind, 0, ADDR(9), 0},
105550 { OP_String8, 0, 1, 0}, /* 1 */
105551 { OP_Column, 0, 1, 2},
105552 { OP_Ne, 2, ADDR(8), 1},
@@ -105557,11 +105601,11 @@
105557 { OP_Next, 0, ADDR(1), 0}, /* 8 */
105558 };
105559
105560 sqlite3BeginWriteOperation(pParse, 0, iDb);
105561 sqlite3OpenMasterTable(pParse, iDb);
105562 base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger);
105563 sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
105564 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
105565 sqlite3ChangeCookie(pParse, iDb);
105566 sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
105567 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
@@ -105703,19 +105747,11 @@
105703 **
105704 ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
105705 ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
105706 */
105707 pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
105708
105709 /* Clear the cookieGoto flag. When coding triggers, the cookieGoto
105710 ** variable is used as a flag to indicate to sqlite3ExprCodeConstants()
105711 ** that it is not safe to refactor constants (this happens after the
105712 ** start of the first loop in the SQL statement is coded - at that
105713 ** point code may be conditionally executed, so it is no longer safe to
105714 ** initialize constant register values). */
105715 assert( pParse->cookieGoto==0 || pParse->cookieGoto==-1 );
105716 pParse->cookieGoto = 0;
105717
105718 switch( pStep->op ){
105719 case TK_UPDATE: {
105720 sqlite3Update(pParse,
105721 targetSrcList(pParse, pStep),
@@ -106500,11 +106536,11 @@
106500 sqlite3VdbeChangeToNoop(v, addrOpen);
106501 nKey = nPk;
106502 regKey = iPk;
106503 }else{
106504 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
106505 sqlite3IndexAffinityStr(v, pPk), P4_TRANSIENT);
106506 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
106507 }
106508 sqlite3WhereEnd(pWInfo);
106509 }
106510
@@ -106544,32 +106580,37 @@
106544 /* Top of the update loop */
106545 if( okOnePass ){
106546 if( aToOpen[iDataCur-iBaseCur] ){
106547 assert( pPk!=0 );
106548 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
 
106549 }
106550 labelContinue = labelBreak;
106551 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
 
106552 }else if( pPk ){
106553 labelContinue = sqlite3VdbeMakeLabel(v);
106554 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak);
106555 addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
106556 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
 
106557 }else{
106558 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
106559 regOldRowid);
 
106560 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
 
106561 }
106562
106563 /* If the record number will change, set register regNewRowid to
106564 ** contain the new value. If the record number is not being modified,
106565 ** then regNewRowid is the same register as regOldRowid, which is
106566 ** already populated. */
106567 assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
106568 if( chngRowid ){
106569 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
106570 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid);
106571 }
106572
106573 /* Compute the old pre-UPDATE content of the row being changed, if that
106574 ** information is needed */
106575 if( chngPk || hasFK || pTrigger ){
@@ -106634,12 +106675,11 @@
106634
106635 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
106636 ** verified. One could argue that this is wrong.
106637 */
106638 if( tmask&TRIGGER_BEFORE ){
106639 sqlite3VdbeAddOp2(v, OP_Affinity, regNew, pTab->nCol);
106640 sqlite3TableAffinityStr(v, pTab);
106641 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
106642 TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
106643
106644 /* The row-trigger may have deleted the row being updated. In this
106645 ** case, jump to the next row. No updates or AFTER triggers are
@@ -106647,12 +106687,14 @@
106647 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
106648 ** documentation.
106649 */
106650 if( pPk ){
106651 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
 
106652 }else{
106653 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
 
106654 }
106655
106656 /* If it did not delete it, the row-trigger may still have modified
106657 ** some of the columns of the row being updated. Load the values for
106658 ** all columns not modified by the update statement into their
@@ -106684,10 +106726,11 @@
106684 if( pPk ){
106685 j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
106686 }else{
106687 j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
106688 }
 
106689 }
106690 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
106691
106692 /* If changing the record number, delete the old record. */
106693 if( hasFK || chngKey || pPk!=0 ){
@@ -106727,11 +106770,11 @@
106727 */
106728 if( okOnePass ){
106729 /* Nothing to do at end-of-loop for a single-pass */
106730 }else if( pPk ){
106731 sqlite3VdbeResolveLabel(v, labelContinue);
106732 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop);
106733 }else{
106734 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
106735 }
106736 sqlite3VdbeResolveLabel(v, labelBreak);
106737
@@ -106856,21 +106899,21 @@
106856 sqlite3Select(pParse, pSelect, &dest);
106857
106858 /* Generate code to scan the ephemeral table and call VUpdate. */
106859 iReg = ++pParse->nMem;
106860 pParse->nMem += pTab->nCol+1;
106861 addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0);
106862 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, 0, iReg);
106863 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);
106864 for(i=0; i<pTab->nCol; i++){
106865 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
106866 }
106867 sqlite3VtabMakeWritable(pParse, pTab);
106868 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
106869 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
106870 sqlite3MayAbort(pParse);
106871 sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1);
106872 sqlite3VdbeJumpHere(v, addr);
106873 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
106874
106875 /* Cleanup */
106876 sqlite3SelectDelete(db, pSelect);
@@ -108438,11 +108481,11 @@
108438 int addrSkip; /* Jump here for next iteration of skip-scan */
108439 int addrCont; /* Jump here to continue with the next loop cycle */
108440 int addrFirst; /* First instruction of interior of the loop */
108441 int addrBody; /* Beginning of the body of this loop */
108442 u8 iFrom; /* Which entry in the FROM clause */
108443 u8 op, p5; /* Opcode and P5 of the opcode that ends the loop */
108444 int p1, p2; /* Operands of the opcode used to ends the loop */
108445 union { /* Information that depends on pWLoop->wsFlags */
108446 struct {
108447 int nIn; /* Number of entries in aInLoop[] */
108448 struct InLoop {
@@ -108825,10 +108868,11 @@
108825 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108826 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108827 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108828 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
108829 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
 
108830
108831 /************** End of whereInt.h ********************************************/
108832 /************** Continuing where we left off in where.c **********************/
108833
108834 /*
@@ -110411,11 +110455,11 @@
110411
110412 /* Generate code to skip over the creation and initialization of the
110413 ** transient index on 2nd and subsequent iterations of the loop. */
110414 v = pParse->pVdbe;
110415 assert( v!=0 );
110416 addrInit = sqlite3CodeOnce(pParse);
110417
110418 /* Count the number of columns that will be added to the index
110419 ** and used to match WHERE clause constraints */
110420 nKeyCol = 0;
110421 pTable = pSrc->pTab;
@@ -110518,16 +110562,16 @@
110518 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
110519 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
110520 VdbeComment((v, "for %s", pTable->zName));
110521
110522 /* Fill the automatic index with content */
110523 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur);
110524 regRecord = sqlite3GetTempReg(pParse);
110525 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
110526 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
110527 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
110528 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1);
110529 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
110530 sqlite3VdbeJumpHere(v, addrTop);
110531 sqlite3ReleaseTempReg(pParse, regRecord);
110532
110533 /* Jump here when skipping the initialization */
@@ -111199,10 +111243,12 @@
111199 testcase( bRev );
111200 bRev = !bRev;
111201 }
111202 iTab = pX->iTable;
111203 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
 
 
111204 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
111205 pLoop->wsFlags |= WHERE_IN_ABLE;
111206 if( pLevel->u.in.nIn==0 ){
111207 pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
111208 }
@@ -111218,11 +111264,11 @@
111218 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
111219 }else{
111220 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
111221 }
111222 pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
111223 sqlite3VdbeAddOp1(v, OP_IsNull, iReg);
111224 }else{
111225 pLevel->u.in.nIn = 0;
111226 }
111227 #endif
111228 }
@@ -111313,14 +111359,18 @@
111313 }
111314
111315 if( nSkip ){
111316 int iIdxCur = pLevel->iIdxCur;
111317 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
 
 
111318 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
111319 j = sqlite3VdbeAddOp0(v, OP_Goto);
111320 pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLt:OP_SeekGt),
111321 iIdxCur, 0, regBase, nSkip);
 
 
111322 sqlite3VdbeJumpHere(v, j);
111323 for(j=0; j<nSkip; j++){
111324 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
111325 assert( pIdx->aiColumn[j]>=0 );
111326 VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
@@ -111349,11 +111399,14 @@
111349 }
111350 testcase( pTerm->eOperator & WO_ISNULL );
111351 testcase( pTerm->eOperator & WO_IN );
111352 if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
111353 Expr *pRight = pTerm->pExpr->pRight;
111354 sqlite3ExprCodeIsNullJump(v, pRight, regBase+j, pLevel->addrBrk);
 
 
 
111355 if( zAff ){
111356 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
111357 zAff[j] = SQLITE_AFF_NONE;
111358 }
111359 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
@@ -111595,14 +111648,14 @@
111595 }
111596
111597 /* Special case of a FROM clause subquery implemented as a co-routine */
111598 if( pTabItem->viaCoroutine ){
111599 int regYield = pTabItem->regReturn;
111600 sqlite3VdbeAddOp2(v, OP_Integer, pTabItem->addrFillSub-1, regYield);
111601 pLevel->p2 = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
111602 VdbeComment((v, "next row of co-routine %s", pTabItem->pTab->zName));
111603 sqlite3VdbeAddOp2(v, OP_If, regYield+1, addrBrk);
111604 pLevel->op = OP_Goto;
111605 }else
111606
111607 #ifndef SQLITE_OMIT_VIRTUALTABLE
111608 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -111630,10 +111683,11 @@
111630 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
111631 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
111632 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
111633 pLoop->u.vtab.idxStr,
111634 pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
 
111635 pLoop->u.vtab.needFree = 0;
111636 for(j=0; j<nConstraint && j<16; j++){
111637 if( (pLoop->u.vtab.omitMask>>j)&1 ){
111638 disableTerm(pLevel, pLoop->aLTerm[j]);
111639 }
@@ -111653,20 +111707,22 @@
111653 ** equality comparison against the ROWID field. Or
111654 ** we reference multiple rows using a "rowid IN (...)"
111655 ** construct.
111656 */
111657 assert( pLoop->u.btree.nEq==1 );
111658 iReleaseReg = sqlite3GetTempReg(pParse);
111659 pTerm = pLoop->aLTerm[0];
111660 assert( pTerm!=0 );
111661 assert( pTerm->pExpr!=0 );
111662 assert( omitTable==0 );
111663 testcase( pTerm->wtFlags & TERM_VIRTUAL );
 
111664 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
 
111665 addrNxt = pLevel->addrNxt;
111666 sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt);
111667 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
 
111668 sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
111669 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111670 VdbeComment((v, "pk"));
111671 pLevel->op = OP_Noop;
111672 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -111696,14 +111752,14 @@
111696
111697 /* The following constant maps TK_xx codes into corresponding
111698 ** seek opcodes. It depends on a particular ordering of TK_xx
111699 */
111700 const u8 aMoveOp[] = {
111701 /* TK_GT */ OP_SeekGt,
111702 /* TK_LE */ OP_SeekLe,
111703 /* TK_LT */ OP_SeekLt,
111704 /* TK_GE */ OP_SeekGe
111705 };
111706 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
111707 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
111708 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
111709
@@ -111713,15 +111769,21 @@
111713 assert( pX!=0 );
111714 testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
111715 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
111716 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
111717 VdbeComment((v, "pk"));
 
 
 
 
111718 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
111719 sqlite3ReleaseTempReg(pParse, rTemp);
111720 disableTerm(pLevel, pStart);
111721 }else{
111722 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
 
 
111723 }
111724 if( pEnd ){
111725 Expr *pX;
111726 pX = pEnd->pExpr;
111727 assert( pX!=0 );
@@ -111741,14 +111803,18 @@
111741 pLevel->op = bRev ? OP_Prev : OP_Next;
111742 pLevel->p1 = iCur;
111743 pLevel->p2 = start;
111744 assert( pLevel->p5==0 );
111745 if( testOp!=OP_Noop ){
111746 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
111747 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
111748 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111749 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
 
 
 
 
111750 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
111751 }
111752 }else if( pLoop->wsFlags & WHERE_INDEXED ){
111753 /* Case 4: A scan using an index.
111754 **
@@ -111784,24 +111850,23 @@
111784 static const u8 aStartOp[] = {
111785 0,
111786 0,
111787 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
111788 OP_Last, /* 3: (!start_constraints && startEq && bRev) */
111789 OP_SeekGt, /* 4: (start_constraints && !startEq && !bRev) */
111790 OP_SeekLt, /* 5: (start_constraints && !startEq && bRev) */
111791 OP_SeekGe, /* 6: (start_constraints && startEq && !bRev) */
111792 OP_SeekLe /* 7: (start_constraints && startEq && bRev) */
111793 };
111794 static const u8 aEndOp[] = {
111795 OP_Noop, /* 0: (!end_constraints) */
111796 OP_IdxGE, /* 1: (end_constraints && !bRev) */
111797 OP_IdxLT /* 2: (end_constraints && bRev) */
 
111798 };
111799 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
111800 int isMinQuery = 0; /* If this is an optimized SELECT min(x).. */
111801 int regBase; /* Base register holding constraint values */
111802 int r1; /* Temp register */
111803 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111804 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111805 int startEq; /* True if range start uses ==, >= or <= */
111806 int endEq; /* True if range end uses ==, >= or <= */
111807 int start_constraints; /* Start of range is constrained */
@@ -111810,10 +111875,12 @@
111810 int iIdxCur; /* The VDBE cursor for the index */
111811 int nExtraReg = 0; /* Number of extra registers needed */
111812 int op; /* Instruction opcode */
111813 char *zStartAff; /* Affinity for start of range constraint */
111814 char cEndAff = 0; /* Affinity for end of range constraint */
 
 
111815
111816 pIdx = pLoop->u.btree.pIndex;
111817 iIdxCur = pLevel->iIdxCur;
111818 assert( nEq>=pLoop->u.btree.nSkip );
111819
@@ -111828,11 +111895,11 @@
111828 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111829 && (pWInfo->bOBSat!=0)
111830 && (pIdx->nKeyCol>nEq)
111831 ){
111832 assert( pLoop->u.btree.nSkip==0 );
111833 isMinQuery = 1;
111834 nExtraReg = 1;
111835 }
111836
111837 /* Find any inequality constraint terms for the start and end
111838 ** of the range.
@@ -111843,10 +111910,17 @@
111843 nExtraReg = 1;
111844 }
111845 if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
111846 pRangeEnd = pLoop->aLTerm[j++];
111847 nExtraReg = 1;
 
 
 
 
 
 
 
111848 }
111849
111850 /* Generate code to evaluate all constraint terms using == or IN
111851 ** and store the values of those terms in an array of registers
111852 ** starting at regBase.
@@ -111862,10 +111936,11 @@
111862 */
111863 if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
111864 || (bRev && pIdx->nKeyCol==nEq)
111865 ){
111866 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
 
111867 }
111868
111869 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
111870 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
111871 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
@@ -111877,12 +111952,15 @@
111877 /* Seek the index cursor to the start of the range. */
111878 nConstraint = nEq;
111879 if( pRangeStart ){
111880 Expr *pRight = pRangeStart->pExpr->pRight;
111881 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111882 if( (pRangeStart->wtFlags & TERM_VNULL)==0 ){
111883 sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
 
 
 
111884 }
111885 if( zStartAff ){
111886 if( sqlite3CompareAffinity(pRight, zStartAff[nEq])==SQLITE_AFF_NONE){
111887 /* Since the comparison is to be performed with no conversions
111888 ** applied to the operands, set the affinity to apply to pRight to
@@ -111893,86 +111971,76 @@
111893 zStartAff[nEq] = SQLITE_AFF_NONE;
111894 }
111895 }
111896 nConstraint++;
111897 testcase( pRangeStart->wtFlags & TERM_VIRTUAL );
111898 }else if( isMinQuery ){
111899 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
111900 nConstraint++;
111901 startEq = 0;
111902 start_constraints = 1;
111903 }
111904 codeApplyAffinity(pParse, regBase, nConstraint, zStartAff);
111905 op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
111906 assert( op!=0 );
111907 testcase( op==OP_Rewind );
111908 testcase( op==OP_Last );
111909 testcase( op==OP_SeekGt );
111910 testcase( op==OP_SeekGe );
111911 testcase( op==OP_SeekLe );
111912 testcase( op==OP_SeekLt );
111913 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
 
 
 
 
 
 
 
111914
111915 /* Load the value for the inequality constraint at the end of the
111916 ** range (if any).
111917 */
111918 nConstraint = nEq;
111919 if( pRangeEnd ){
111920 Expr *pRight = pRangeEnd->pExpr->pRight;
111921 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
111922 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111923 if( (pRangeEnd->wtFlags & TERM_VNULL)==0 ){
111924 sqlite3ExprCodeIsNullJump(v, pRight, regBase+nEq, addrNxt);
 
 
 
111925 }
111926 if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
111927 && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
111928 ){
111929 codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
111930 }
111931 nConstraint++;
111932 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
 
 
 
 
111933 }
111934 sqlite3DbFree(db, zStartAff);
111935
111936 /* Top of the loop body */
111937 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
111938
111939 /* Check if the index cursor is past the end of the range. */
111940 op = aEndOp[(pRangeEnd || nEq) * (1 + bRev)];
111941 testcase( op==OP_Noop );
111942 testcase( op==OP_IdxGE );
111943 testcase( op==OP_IdxLT );
111944 if( op!=OP_Noop ){
111945 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
111946 sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
111947 }
111948
111949 /* If there are inequality constraints, check that the value
111950 ** of the table column that the inequality contrains is not NULL.
111951 ** If it is, jump to the next iteration of the loop.
111952 */
111953 r1 = sqlite3GetTempReg(pParse);
111954 testcase( pLoop->wsFlags & WHERE_BTM_LIMIT );
111955 testcase( pLoop->wsFlags & WHERE_TOP_LIMIT );
111956 if( (pLoop->wsFlags & (WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
111957 && (j = pIdx->aiColumn[nEq])>=0
111958 && pIdx->pTable->aCol[j].notNull==0
111959 && (nEq || (pLoop->wsFlags & WHERE_BTM_LIMIT)==0)
111960 ){
111961 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, nEq, r1);
111962 VdbeComment((v, "%s", pIdx->pTable->aCol[j].zName));
111963 sqlite3VdbeAddOp2(v, OP_IsNull, r1, addrCont);
111964 }
111965 sqlite3ReleaseTempReg(pParse, r1);
111966
111967 /* Seek the table cursor, if required */
111968 disableTerm(pLevel, pRangeStart);
111969 disableTerm(pLevel, pRangeEnd);
111970 if( omitTable ){
111971 /* pIdx is a covering index. No need to access the main table. */
111972 }else if( HasRowid(pIdx->pTable) ){
111973 iRowidReg = iReleaseReg = sqlite3GetTempReg(pParse);
111974 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
111975 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111976 sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
111977 }else{
111978 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
@@ -111980,11 +112048,11 @@
111980 for(j=0; j<pPk->nKeyCol; j++){
111981 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
111982 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
111983 }
111984 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
111985 iRowidReg, pPk->nKeyCol);
111986 }
111987
111988 /* Record the instruction used to terminate the loop. Disable
111989 ** WHERE clause terms made redundant by the index range scan.
111990 */
@@ -111994,10 +112062,12 @@
111994 pLevel->op = OP_Prev;
111995 }else{
111996 pLevel->op = OP_Next;
111997 }
111998 pLevel->p1 = iIdxCur;
 
 
111999 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
112000 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112001 }else{
112002 assert( pLevel->p5==0 );
112003 }
@@ -112162,10 +112232,11 @@
112162 int r;
112163 r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
112164 regRowid, 0);
112165 sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
112166 sqlite3VdbeCurrentAddr(v)+2, r, iSet);
 
112167 }
112168 sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
112169
112170 /* The pSubWInfo->untestedTerms flag means that this OR term
112171 ** contained one or more AND term from a notReady table. The
@@ -112230,10 +112301,12 @@
112230 pLevel->op = OP_Noop;
112231 }else{
112232 pLevel->op = aStep[bRev];
112233 pLevel->p1 = iCur;
112234 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
 
 
112235 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112236 }
112237 }
112238
112239 /* Insert code to test every subexpression that can be completely
@@ -112311,11 +112384,10 @@
112311 assert( pTerm->pExpr );
112312 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
112313 pTerm->wtFlags |= TERM_CODED;
112314 }
112315 }
112316 sqlite3ReleaseTempReg(pParse, iReleaseReg);
112317
112318 return pLevel->notReady;
112319 }
112320
112321 #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -112798,16 +112870,17 @@
112798 assert(
112799 (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
112800 || nInMul==0
112801 );
112802 pNew->wsFlags |= WHERE_COLUMN_EQ;
112803 if( iCol<0
112804 || (pProbe->onError!=OE_None && nInMul==0
112805 && pNew->u.btree.nEq==pProbe->nKeyCol-1)
112806 ){
112807 assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
112808 pNew->wsFlags |= WHERE_ONEROW;
 
 
 
 
112809 }
112810 pNew->u.btree.nEq++;
112811 pNew->nOut = nRowEst + nInMul;
112812 }else if( pTerm->eOperator & (WO_ISNULL) ){
112813 pNew->wsFlags |= WHERE_COLUMN_NULL;
@@ -113682,13 +113755,16 @@
113682 /* Mark off any other ORDER BY terms that reference pLoop */
113683 if( isOrderDistinct ){
113684 orderDistinctMask |= pLoop->maskSelf;
113685 for(i=0; i<nOrderBy; i++){
113686 Expr *p;
 
113687 if( MASKBIT(i) & obSat ) continue;
113688 p = pOrderBy->a[i].pExpr;
113689 if( (exprTableUsage(&pWInfo->sMaskSet, p)&~orderDistinctMask)==0 ){
 
 
113690 obSat |= MASKBIT(i);
113691 }
113692 }
113693 }
113694 } /* End the loop over all WhereLoops from outer-most down to inner-most */
@@ -114246,11 +114322,10 @@
114246 ** subexpression is separated by an AND operator.
114247 */
114248 initMaskSet(pMaskSet);
114249 whereClauseInit(&pWInfo->sWC, pWInfo);
114250 whereSplit(&pWInfo->sWC, pWhere, TK_AND);
114251 sqlite3CodeVerifySchema(pParse, -1); /* Insert the cookie verifier Goto */
114252
114253 /* Special case: a WHERE clause that is constant. Evaluate the
114254 ** expression and either jump over all of the code or fall thru.
114255 */
114256 for(ii=0; ii<sWLB.pWC->nTerm; ii++){
@@ -114308,26 +114383,10 @@
114308 exprAnalyzeAll(pTabList, &pWInfo->sWC);
114309 if( db->mallocFailed ){
114310 goto whereBeginError;
114311 }
114312
114313 /* If the ORDER BY (or GROUP BY) clause contains references to general
114314 ** expressions, then we won't be able to satisfy it using indices, so
114315 ** go ahead and disable it now.
114316 */
114317 if( pOrderBy && (wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
114318 for(ii=0; ii<pOrderBy->nExpr; ii++){
114319 Expr *pExpr = sqlite3ExprSkipCollate(pOrderBy->a[ii].pExpr);
114320 if( pExpr->op!=TK_COLUMN ){
114321 pWInfo->pOrderBy = pOrderBy = 0;
114322 break;
114323 }else if( pExpr->iColumn<0 ){
114324 break;
114325 }
114326 }
114327 }
114328
114329 if( wctrlFlags & WHERE_WANT_DISTINCT ){
114330 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
114331 /* The DISTINCT marking is pointless. Ignore it. */
114332 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
114333 }else if( pOrderBy==0 ){
@@ -114535,11 +114594,11 @@
114535 assert( iIndexCur>=0 );
114536 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
114537 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
114538 VdbeComment((v, "%s", pIx->zName));
114539 }
114540 sqlite3CodeVerifySchema(pParse, iDb);
114541 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
114542 }
114543 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
114544 if( db->mallocFailed ) goto whereBeginError;
114545
@@ -114597,20 +114656,27 @@
114597 int addr;
114598 pLevel = &pWInfo->a[i];
114599 pLoop = pLevel->pWLoop;
114600 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114601 if( pLevel->op!=OP_Noop ){
114602 sqlite3VdbeAddOp2(v, pLevel->op, pLevel->p1, pLevel->p2);
114603 sqlite3VdbeChangeP5(v, pLevel->p5);
 
 
 
 
114604 }
114605 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
114606 struct InLoop *pIn;
114607 int j;
114608 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
114609 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
114610 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
114611 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
 
 
 
114612 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114613 }
114614 sqlite3DbFree(db, pLevel->u.in.aInLoop);
114615 }
114616 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
@@ -114619,11 +114685,11 @@
114619 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
114620 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
114621 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
114622 }
114623 if( pLevel->iLeftJoin ){
114624 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin);
114625 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114626 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114627 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114628 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
114629 }
@@ -114646,15 +114712,41 @@
114646 */
114647 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
114648
114649 assert( pWInfo->nLevel<=pTabList->nSrc );
114650 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
 
 
114651 Index *pIdx = 0;
114652 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
114653 Table *pTab = pTabItem->pTab;
114654 assert( pTab!=0 );
114655 pLoop = pLevel->pWLoop;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114656
114657 /* Close all of the cursors that were opened by sqlite3WhereBegin.
114658 ** Except, do not close cursors that will be reused by the OR optimization
114659 ** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors
114660 ** created for the ONEPASS optimization.
@@ -114690,13 +114782,10 @@
114690 pIdx = pLoop->u.btree.pIndex;
114691 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
114692 pIdx = pLevel->u.pCovidx;
114693 }
114694 if( pIdx && !db->mallocFailed ){
114695 int k, last;
114696 VdbeOp *pOp;
114697
114698 last = sqlite3VdbeCurrentAddr(v);
114699 k = pLevel->addrBody;
114700 pOp = sqlite3VdbeGetOp(v, k);
114701 for(; k<last; k++, pOp++){
114702 if( pOp->p1!=pLevel->iTabCur ) continue;
@@ -117106,33 +117195,54 @@
117106 sqlite3ExplainFinish(pParse->pVdbe);
117107 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
117108 }
117109 break;
117110 case 112: /* select ::= with selectnowith */
117111 {
117112 if( yymsp[0].minor.yy3 ){
117113 yymsp[0].minor.yy3->pWith = yymsp[-1].minor.yy59;
 
 
 
 
 
 
 
 
 
 
 
 
 
117114 }else{
117115 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
117116 }
117117 yygotominor.yy3 = yymsp[0].minor.yy3;
117118 }
117119 break;
117120 case 113: /* selectnowith ::= oneselect */
117121 case 119: /* oneselect ::= values */ yytestcase(yyruleno==119);
117122 {yygotominor.yy3 = yymsp[0].minor.yy3;}
117123 break;
117124 case 114: /* selectnowith ::= selectnowith multiselect_op oneselect */
117125 {
117126 if( yymsp[0].minor.yy3 ){
117127 yymsp[0].minor.yy3->op = (u8)yymsp[-1].minor.yy328;
117128 yymsp[0].minor.yy3->pPrior = yymsp[-2].minor.yy3;
 
 
 
 
 
 
 
 
117129 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
117130 }else{
117131 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
117132 }
117133 yygotominor.yy3 = yymsp[0].minor.yy3;
117134 }
117135 break;
117136 case 116: /* multiselect_op ::= UNION ALL */
117137 {yygotominor.yy328 = TK_ALL;}
117138 break;
@@ -122696,10 +122806,25 @@
122696 case SQLITE_TESTCTRL_NEVER_CORRUPT: {
122697 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
122698 break;
122699 }
122700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122701 }
122702 va_end(ap);
122703 #endif /* SQLITE_OMIT_BUILTIN_TEST */
122704 return rc;
122705 }
122706
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.8.4. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -187,13 +187,13 @@
187 **
188 ** See also: [sqlite3_libversion()],
189 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
190 ** [sqlite_version()] and [sqlite_source_id()].
191 */
192 #define SQLITE_VERSION "3.8.4"
193 #define SQLITE_VERSION_NUMBER 3008004
194 #define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
195
196 /*
197 ** CAPI3REF: Run-Time Library Version Numbers
198 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
199 **
@@ -6202,11 +6202,12 @@
6202 #define SQLITE_TESTCTRL_ISKEYWORD 16
6203 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6204 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6205 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6206 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6207 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6208 #define SQLITE_TESTCTRL_LAST 21
6209
6210 /*
6211 ** CAPI3REF: SQLite Runtime Status
6212 **
6213 ** ^This interface is used to retrieve runtime status information
@@ -8852,12 +8853,10 @@
8853 SQLITE_PRIVATE int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
8854 SQLITE_PRIVATE const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
8855 SQLITE_PRIVATE const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
8856 SQLITE_PRIVATE int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
8857 SQLITE_PRIVATE int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
 
 
8858
8859 SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
8860 SQLITE_PRIVATE struct Pager *sqlite3BtreePager(Btree*);
8861
8862 SQLITE_PRIVATE int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
@@ -8993,13 +8992,16 @@
8992 } p4;
8993 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
8994 char *zComment; /* Comment to improve readability */
8995 #endif
8996 #ifdef VDBE_PROFILE
8997 u32 cnt; /* Number of times this instruction was executed */
8998 u64 cycles; /* Total time spent executing this instruction */
8999 #endif
9000 #ifdef SQLITE_VDBE_COVERAGE
9001 int iSrcLine; /* Source-code line that generated this opcode */
9002 #endif
9003 };
9004 typedef struct VdbeOp VdbeOp;
9005
9006
9007 /*
@@ -9105,75 +9107,75 @@
9107 #define OP_VUpdate 15 /* synopsis: data=r[P3@P2] */
9108 #define OP_Goto 16
9109 #define OP_Gosub 17
9110 #define OP_Return 18
9111 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
9112 #define OP_InitCoroutine 20
9113 #define OP_EndCoroutine 21
9114 #define OP_Yield 22
9115 #define OP_HaltIfNull 23 /* synopsis: if r[P3]=null halt */
9116 #define OP_Halt 24
9117 #define OP_Integer 25 /* synopsis: r[P2]=P1 */
9118 #define OP_Int64 26 /* synopsis: r[P2]=P4 */
9119 #define OP_String 27 /* synopsis: r[P2]='P4' (len=P1) */
9120 #define OP_Null 28 /* synopsis: r[P2..P3]=NULL */
9121 #define OP_SoftNull 29 /* synopsis: r[P1]=NULL */
9122 #define OP_Blob 30 /* synopsis: r[P2]=P4 (len=P1) */
9123 #define OP_Variable 31 /* synopsis: r[P2]=parameter(P1,P4) */
9124 #define OP_Move 32 /* synopsis: r[P2@P3]=r[P1@P3] */
9125 #define OP_Copy 33 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
9126 #define OP_SCopy 34 /* synopsis: r[P2]=r[P1] */
9127 #define OP_ResultRow 35 /* synopsis: output=r[P1@P2] */
9128 #define OP_CollSeq 36
9129 #define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */
9130 #define OP_MustBeInt 38
9131 #define OP_RealAffinity 39
9132 #define OP_Permutation 40
9133 #define OP_Compare 41
9134 #define OP_Jump 42
9135 #define OP_Once 43
9136 #define OP_If 44
9137 #define OP_IfNot 45
9138 #define OP_Column 46 /* synopsis: r[P3]=PX */
9139 #define OP_Affinity 47 /* synopsis: affinity(r[P1@P2]) */
9140 #define OP_MakeRecord 48 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
9141 #define OP_Count 49 /* synopsis: r[P2]=count() */
9142 #define OP_ReadCookie 50
9143 #define OP_SetCookie 51
9144 #define OP_OpenRead 52 /* synopsis: root=P2 iDb=P3 */
9145 #define OP_OpenWrite 53 /* synopsis: root=P2 iDb=P3 */
9146 #define OP_OpenAutoindex 54 /* synopsis: nColumn=P2 */
9147 #define OP_OpenEphemeral 55 /* synopsis: nColumn=P2 */
9148 #define OP_SorterOpen 56
9149 #define OP_OpenPseudo 57 /* synopsis: P3 columns in r[P2] */
9150 #define OP_Close 58
9151 #define OP_SeekLT 59
9152 #define OP_SeekLE 60
9153 #define OP_SeekGE 61
9154 #define OP_SeekGT 62
9155 #define OP_Seek 63 /* synopsis: intkey=r[P2] */
9156 #define OP_NoConflict 64 /* synopsis: key=r[P3@P4] */
9157 #define OP_NotFound 65 /* synopsis: key=r[P3@P4] */
9158 #define OP_Found 66 /* synopsis: key=r[P3@P4] */
9159 #define OP_NotExists 67 /* synopsis: intkey=r[P3] */
9160 #define OP_Sequence 68 /* synopsis: r[P2]=rowid */
9161 #define OP_NewRowid 69 /* synopsis: r[P2]=rowid */
9162 #define OP_Insert 70 /* synopsis: intkey=r[P3] data=r[P2] */
9163 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9164 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9165 #define OP_InsertInt 73 /* synopsis: intkey=P3 data=r[P2] */
9166 #define OP_Delete 74
9167 #define OP_ResetCount 75
9168 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9169 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9170 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9171 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9172 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9173 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9174 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9175 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9176 #define OP_SorterCompare 84 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9177 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9178 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9179 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9180 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9181 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9180,68 +9182,72 @@
9182 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9183 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9184 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9185 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9186 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9187 #define OP_SorterData 95 /* synopsis: r[P2]=data */
9188 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9189 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9190 #define OP_RowKey 98 /* synopsis: r[P2]=key */
9191 #define OP_RowData 99 /* synopsis: r[P2]=data */
9192 #define OP_Rowid 100 /* synopsis: r[P2]=rowid */
9193 #define OP_NullRow 101
9194 #define OP_Last 102
9195 #define OP_SorterSort 103
9196 #define OP_Sort 104
9197 #define OP_Rewind 105
9198 #define OP_SorterInsert 106
9199 #define OP_IdxInsert 107 /* synopsis: key=r[P2] */
9200 #define OP_IdxDelete 108 /* synopsis: key=r[P2@P3] */
9201 #define OP_IdxRowid 109 /* synopsis: r[P2]=rowid */
9202 #define OP_IdxLE 110 /* synopsis: key=r[P3@P4] */
9203 #define OP_IdxGT 111 /* synopsis: key=r[P3@P4] */
9204 #define OP_IdxLT 112 /* synopsis: key=r[P3@P4] */
9205 #define OP_IdxGE 113 /* synopsis: key=r[P3@P4] */
9206 #define OP_Destroy 114
9207 #define OP_Clear 115
9208 #define OP_CreateIndex 116 /* synopsis: r[P2]=root iDb=P1 */
9209 #define OP_CreateTable 117 /* synopsis: r[P2]=root iDb=P1 */
9210 #define OP_ParseSchema 118
9211 #define OP_LoadAnalysis 119
9212 #define OP_DropTable 120
9213 #define OP_DropIndex 121
9214 #define OP_DropTrigger 122
9215 #define OP_IntegrityCk 123
9216 #define OP_RowSetAdd 124 /* synopsis: rowset(P1)=r[P2] */
9217 #define OP_RowSetRead 125 /* synopsis: r[P3]=rowset(P1) */
9218 #define OP_RowSetTest 126 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9219 #define OP_Program 127
9220 #define OP_Param 128
9221 #define OP_FkCounter 129 /* synopsis: fkctr[P1]+=P2 */
9222 #define OP_FkIfZero 130 /* synopsis: if fkctr[P1]==0 goto P2 */
9223 #define OP_MemMax 131 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9224 #define OP_IfPos 132 /* synopsis: if r[P1]>0 goto P2 */
9225 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9226 #define OP_IfNeg 134 /* synopsis: if r[P1]<0 goto P2 */
9227 #define OP_IfZero 135 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9228 #define OP_AggFinal 136 /* synopsis: accum=r[P1] N=P2 */
9229 #define OP_IncrVacuum 137
9230 #define OP_Expire 138
9231 #define OP_TableLock 139 /* synopsis: iDb=P1 root=P2 write=P3 */
9232 #define OP_VBegin 140
9233 #define OP_VCreate 141
9234 #define OP_VDestroy 142
9235 #define OP_ToText 143 /* same as TK_TO_TEXT */
9236 #define OP_ToBlob 144 /* same as TK_TO_BLOB */
9237 #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
9238 #define OP_ToInt 146 /* same as TK_TO_INT */
9239 #define OP_ToReal 147 /* same as TK_TO_REAL */
9240 #define OP_VOpen 148
9241 #define OP_VColumn 149 /* synopsis: r[P3]=vcolumn(P2) */
9242 #define OP_VNext 150
9243 #define OP_VRename 151
9244 #define OP_Pagecount 152
9245 #define OP_MaxPgcnt 153
9246 #define OP_Init 154 /* synopsis: Start at P2 */
9247 #define OP_Noop 155
9248 #define OP_Explain 156
9249
9250
9251 /* Properties such as "out2" or "jump" that are specified in
9252 ** comments following the "case" for each opcode in the vdbe.c
9253 ** are encoded into bitvectors as follows:
@@ -9254,28 +9260,28 @@
9260 #define OPFLG_OUT2 0x0020 /* out2: P2 is an output */
9261 #define OPFLG_OUT3 0x0040 /* out3: P3 is an output */
9262 #define OPFLG_INITIALIZER {\
9263 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01,\
9264 /* 8 */ 0x01, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00,\
9265 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x01, 0x04, 0x05, 0x10,\
9266 /* 24 */ 0x00, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x02,\
9267 /* 32 */ 0x00, 0x00, 0x20, 0x00, 0x00, 0x04, 0x05, 0x04,\
9268 /* 40 */ 0x00, 0x00, 0x01, 0x01, 0x05, 0x05, 0x00, 0x00,\
9269 /* 48 */ 0x00, 0x02, 0x02, 0x10, 0x00, 0x00, 0x00, 0x00,\
9270 /* 56 */ 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08,\
9271 /* 64 */ 0x11, 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x4c,\
9272 /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
9273 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9274 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9275 /* 96 */ 0x24, 0x02, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01,\
9276 /* 104 */ 0x01, 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01,\
9277 /* 112 */ 0x01, 0x01, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00,\
9278 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x0c, 0x45, 0x15, 0x01,\
9279 /* 128 */ 0x02, 0x00, 0x01, 0x08, 0x05, 0x02, 0x05, 0x05,\
9280 /* 136 */ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,\
9281 /* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x01, 0x00,\
9282 /* 152 */ 0x02, 0x02, 0x01, 0x00, 0x00,}
9283
9284 /************** End of opcodes.h *********************************************/
9285 /************** Continuing where we left off in vdbe.h ***********************/
9286
9287 /*
@@ -9287,11 +9293,11 @@
9293 SQLITE_PRIVATE int sqlite3VdbeAddOp1(Vdbe*,int,int);
9294 SQLITE_PRIVATE int sqlite3VdbeAddOp2(Vdbe*,int,int,int);
9295 SQLITE_PRIVATE int sqlite3VdbeAddOp3(Vdbe*,int,int,int,int);
9296 SQLITE_PRIVATE int sqlite3VdbeAddOp4(Vdbe*,int,int,int,int,const char *zP4,int);
9297 SQLITE_PRIVATE int sqlite3VdbeAddOp4Int(Vdbe*,int,int,int,int,int);
9298 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
9299 SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
9300 SQLITE_PRIVATE void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
9301 SQLITE_PRIVATE void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
9302 SQLITE_PRIVATE void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
9303 SQLITE_PRIVATE void sqlite3VdbeChangeP5(Vdbe*, u8 P5);
@@ -9358,10 +9364,45 @@
9364 # define VdbeComment(X)
9365 # define VdbeNoopComment(X)
9366 # define VdbeModuleComment(X)
9367 #endif
9368
9369 /*
9370 ** The VdbeCoverage macros are used to set a coverage testing point
9371 ** for VDBE branch instructions. The coverage testing points are line
9372 ** numbers in the sqlite3.c source file. VDBE branch coverage testing
9373 ** only works with an amalagmation build. That's ok since a VDBE branch
9374 ** coverage build designed for testing the test suite only. No application
9375 ** should ever ship with VDBE branch coverage measuring turned on.
9376 **
9377 ** VdbeCoverage(v) // Mark the previously coded instruction
9378 ** // as a branch
9379 **
9380 ** VdbeCoverageIf(v, conditional) // Mark previous if conditional true
9381 **
9382 ** VdbeCoverageAlwaysTaken(v) // Previous branch is always taken
9383 **
9384 ** VdbeCoverageNeverTaken(v) // Previous branch is never taken
9385 **
9386 ** Every VDBE branch operation must be tagged with one of the macros above.
9387 ** If not, then when "make test" is run with -DSQLITE_VDBE_COVERAGE and
9388 ** -DSQLITE_DEBUG then an ALWAYS() will fail in the vdbeTakeBranch()
9389 ** routine in vdbe.c, alerting the developer to the missed tag.
9390 */
9391 #ifdef SQLITE_VDBE_COVERAGE
9392 SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe*,int);
9393 # define VdbeCoverage(v) sqlite3VdbeSetLineNumber(v,__LINE__)
9394 # define VdbeCoverageIf(v,x) if(x)sqlite3VdbeSetLineNumber(v,__LINE__)
9395 # define VdbeCoverageAlwaysTaken(v) sqlite3VdbeSetLineNumber(v,2);
9396 # define VdbeCoverageNeverTaken(v) sqlite3VdbeSetLineNumber(v,1);
9397 #else
9398 # define VdbeCoverage(v)
9399 # define VdbeCoverageIf(v,x)
9400 # define VdbeCoverageAlwaysTaken(v)
9401 # define VdbeCoverageNeverTaken(v)
9402 #endif
9403
9404 #endif
9405
9406 /************** End of vdbe.h ************************************************/
9407 /************** Continuing where we left off in sqliteInt.h ******************/
9408 /************** Include pager.h in the middle of sqliteInt.h *****************/
@@ -10415,12 +10456,11 @@
10456
10457 /*
10458 ** Return true if it OK to factor constant expressions into the initialization
10459 ** code. The argument is a Parse object for the code generator.
10460 */
10461 #define ConstFactorOk(P) ((P)->okConstFactor)
 
10462
10463 /*
10464 ** Possible values for the sqlite.magic field.
10465 ** The numbers are obtained at random and have no special meaning, other
10466 ** than being distinct from one another.
@@ -10642,14 +10682,20 @@
10682 #define SQLITE_AFF_MASK 0x67
10683
10684 /*
10685 ** Additional bit values that can be ORed with an affinity without
10686 ** changing the affinity.
10687 **
10688 ** The SQLITE_NOTNULL flag is a combination of NULLEQ and JUMPIFNULL.
10689 ** It causes an assert() to fire if either operand to a comparison
10690 ** operator is NULL. It is added to certain comparison operators to
10691 ** prove that the operands are always NOT NULL.
10692 */
10693 #define SQLITE_JUMPIFNULL 0x08 /* jumps if either operand is NULL */
10694 #define SQLITE_STOREP2 0x10 /* Store result in reg[P2] rather than jump */
10695 #define SQLITE_NULLEQ 0x80 /* NULL=NULL */
10696 #define SQLITE_NOTNULL 0x88 /* Assert that operands are never NULL */
10697
10698 /*
10699 ** An object of this type is created for each virtual table present in
10700 ** the database schema.
10701 **
@@ -11347,10 +11393,11 @@
11393 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */
11394 Table *pTab; /* An SQL table corresponding to zName */
11395 Select *pSelect; /* A SELECT statement used in place of a table name */
11396 int addrFillSub; /* Address of subroutine to manifest a subquery */
11397 int regReturn; /* Register holding return address of addrFillSub */
11398 int regResult; /* Registers holding results of a co-routine */
11399 u8 jointype; /* Type of join between this able and the previous */
11400 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
11401 unsigned isCorrelated :1; /* True if sub-query is correlated */
11402 unsigned viaCoroutine :1; /* Implemented as a co-routine */
11403 unsigned isRecursive :1; /* True for recursive reference in WITH */
@@ -11475,11 +11522,10 @@
11522 ExprList *pGroupBy; /* The GROUP BY clause */
11523 Expr *pHaving; /* The HAVING clause */
11524 ExprList *pOrderBy; /* The ORDER BY clause */
11525 Select *pPrior; /* Prior select in a compound select statement */
11526 Select *pNext; /* Next select to the left in a compound */
 
11527 Expr *pLimit; /* LIMIT expression. NULL means not used. */
11528 Expr *pOffset; /* OFFSET expression. NULL means not used. */
11529 With *pWith; /* WITH clause attached to this select. Or NULL. */
11530 };
11531
@@ -11493,14 +11539,15 @@
11539 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
11540 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
11541 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11542 #define SF_UseSorter 0x0040 /* Sort using a sorter */
11543 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11544 #define SF_Materialize 0x0100 /* NOT USED */
11545 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11546 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11547 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11548 #define SF_Compound 0x1000 /* Part of a compound query */
11549
11550
11551 /*
11552 ** The results of a SELECT can be distributed in several ways, as defined
11553 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -11675,49 +11722,48 @@
11722 int rc; /* Return code from execution */
11723 u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */
11724 u8 checkSchema; /* Causes schema cookie check after an error */
11725 u8 nested; /* Number of nested calls to the parser/code generator */
11726 u8 nTempReg; /* Number of temporary registers in aTempReg[] */
 
11727 u8 nColCache; /* Number of entries in aColCache[] */
11728 u8 iColCache; /* Next entry in aColCache[] to replace */
11729 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
11730 u8 mayAbort; /* True if statement may throw an ABORT exception */
11731 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
11732 u8 okConstFactor; /* OK to factor out constants */
11733 int aTempReg[8]; /* Holding area for temporary registers */
11734 int nRangeReg; /* Size of the temporary register block */
11735 int iRangeReg; /* First register in temporary register block */
11736 int nErr; /* Number of errors seen */
11737 int nTab; /* Number of previously allocated VDBE cursors */
11738 int nMem; /* Number of memory cells used so far */
11739 int nSet; /* Number of sets used so far */
11740 int nOnce; /* Number of OP_Once instructions so far */
11741 int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */
 
 
11742 int iFixedOp; /* Never back out opcodes iFixedOp-1 or earlier */
11743 int ckBase; /* Base register of data during check constraints */
11744 int iPartIdxTab; /* Table corresponding to a partial index */
11745 int iCacheLevel; /* ColCache valid when aColCache[].iLevel<=iCacheLevel */
11746 int iCacheCnt; /* Counter used to generate aColCache[].lru values */
11747 int nLabel; /* Number of labels used */
11748 int *aLabel; /* Space to hold the labels */
11749 struct yColCache {
11750 int iTable; /* Table cursor number */
11751 i16 iColumn; /* Table column number */
11752 u8 tempReg; /* iReg is a temp register that needs to be freed */
11753 int iLevel; /* Nesting level */
11754 int iReg; /* Reg with value of this column. 0 means none. */
11755 int lru; /* Least recently used entry has the smallest value */
11756 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
11757 ExprList *pConstExpr;/* Constant expressions */
11758 Token constraintName;/* Name of the constraint currently being parsed */
11759 yDbMask writeMask; /* Start a write transaction on these databases */
11760 yDbMask cookieMask; /* Bitmask of schema verified databases */
 
11761 int cookieValue[SQLITE_MAX_ATTACHED+2]; /* Values of cookies to verify */
11762 int regRowid; /* Register holding rowid of CREATE TABLE entry */
11763 int regRoot; /* Register holding root page number for new objects */
11764 int nMaxArg; /* Max args passed to user function by sub-program */
 
11765 #ifndef SQLITE_OMIT_SHARED_CACHE
11766 int nTableLock; /* Number of locks in aTableLock */
11767 TableLock *aTableLock; /* Required table locks for shared-cache mode */
11768 #endif
11769 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
@@ -11732,16 +11778,21 @@
11778 u32 newmask; /* Mask of new.* columns referenced */
11779 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
11780 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
11781 u8 disableTriggers; /* True to disable triggers */
11782
11783 /************************************************************************
11784 ** Above is constant between recursions. Below is reset before and after
11785 ** each recursion. The boundary between these two regions is determined
11786 ** using offsetof(Parse,nVar) so the nVar field must be the first field
11787 ** in the recursive region.
11788 ************************************************************************/
11789
11790 int nVar; /* Number of '?' variables seen in the SQL so far */
11791 int nzVar; /* Number of available slots in azVar[] */
11792 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
11793 u8 bFreeWith; /* True if pWith should be freed with parser */
11794 u8 explain; /* True if the EXPLAIN flag is found on the query */
11795 #ifndef SQLITE_OMIT_VIRTUALTABLE
11796 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
11797 int nVtabLock; /* Number of virtual tables to lock */
11798 #endif
@@ -11764,11 +11815,10 @@
11815 Table **apVtabLock; /* Pointer to virtual tables needing locking */
11816 #endif
11817 Table *pZombieTab; /* List of Table objects to delete after code gen */
11818 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
11819 With *pWith; /* Current WITH clause, or NULL */
 
11820 };
11821
11822 /*
11823 ** Return true if currently inside an sqlite3_declare_vtab() call.
11824 */
@@ -11980,10 +12030,17 @@
12030 int bLocaltimeFault; /* True to fail localtime() calls */
12031 #ifdef SQLITE_ENABLE_SQLLOG
12032 void(*xSqllog)(void*,sqlite3*,const char*, int);
12033 void *pSqllogArg;
12034 #endif
12035 #ifdef SQLITE_VDBE_COVERAGE
12036 /* The following callback (if not NULL) is invoked on every VDBE branch
12037 ** operation. Set the callback using SQLITE_TESTCTRL_VDBE_COVERAGE.
12038 */
12039 void (*xVdbeBranch)(void*,int iSrcLine,u8 eThis,u8 eMx); /* Callback */
12040 void *pVdbeBranchArg; /* 1st argument */
12041 #endif
12042 };
12043
12044 /*
12045 ** This macro is used inside of assert() statements to indicate that
12046 ** the assert is only valid on a well-formed database. Instead of:
@@ -12313,11 +12370,10 @@
12370 SQLITE_PRIVATE void sqlite3AutoincrementEnd(Parse *pParse);
12371 #else
12372 # define sqlite3AutoincrementBegin(X)
12373 # define sqlite3AutoincrementEnd(X)
12374 #endif
 
12375 SQLITE_PRIVATE void sqlite3Insert(Parse*, SrcList*, Select*, IdList*, int);
12376 SQLITE_PRIVATE void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*);
12377 SQLITE_PRIVATE IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*);
12378 SQLITE_PRIVATE int sqlite3IdListIndex(IdList*,const char*);
12379 SQLITE_PRIVATE SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);
@@ -12361,15 +12417,16 @@
12417 SQLITE_PRIVATE void sqlite3ExprCachePush(Parse*);
12418 SQLITE_PRIVATE void sqlite3ExprCachePop(Parse*, int);
12419 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse*, int, int);
12420 SQLITE_PRIVATE void sqlite3ExprCacheClear(Parse*);
12421 SQLITE_PRIVATE void sqlite3ExprCacheAffinityChange(Parse*, int, int);
12422 SQLITE_PRIVATE void sqlite3ExprCode(Parse*, Expr*, int);
12423 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse*, Expr*, int);
12424 SQLITE_PRIVATE void sqlite3ExprCodeAtInit(Parse*, Expr*, int, u8);
12425 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse*, Expr*, int*);
12426 SQLITE_PRIVATE int sqlite3ExprCodeTarget(Parse*, Expr*, int);
12427 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
12428 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, u8);
12429 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
12430 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
12431 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
12432 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
@@ -12403,11 +12460,10 @@
12460 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
12461 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
12462 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*);
12463 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
12464 SQLITE_PRIVATE int sqlite3ExprCanBeNull(const Expr*);
 
12465 SQLITE_PRIVATE int sqlite3ExprNeedsNoAffinityChange(const Expr*, char);
12466 SQLITE_PRIVATE int sqlite3IsRowid(const char*);
12467 SQLITE_PRIVATE void sqlite3GenerateRowDelete(Parse*,Table*,Trigger*,int,int,int,i16,u8,u8,u8);
12468 SQLITE_PRIVATE void sqlite3GenerateRowIndexDelete(Parse*, Table*, int, int, int*);
12469 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int, int*,Index*,int);
@@ -12547,11 +12603,11 @@
12603 #define getVarint sqlite3GetVarint
12604 #define putVarint sqlite3PutVarint
12605
12606
12607 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
12608 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
12609 SQLITE_PRIVATE char sqlite3CompareAffinity(Expr *pExpr, char aff2);
12610 SQLITE_PRIVATE int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
12611 SQLITE_PRIVATE char sqlite3ExprAffinity(Expr *pExpr);
12612 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
12613 SQLITE_PRIVATE void sqlite3Error(sqlite3*, int, const char*,...);
@@ -13651,11 +13707,10 @@
13707 u8 rowidIsValid; /* True if lastRowid is valid */
13708 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13709 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
13710 Bool isTable:1; /* True if a table requiring integer keys */
13711 Bool isOrdered:1; /* True if the underlying table is BTREE_UNORDERED */
 
13712 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13713 i64 seqCount; /* Sequence counter */
13714 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13715 i64 lastRowid; /* Rowid being deleted by OP_Delete */
13716 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */
@@ -13745,11 +13800,11 @@
13800 RowSet *pRowSet; /* Used only when flags==MEM_RowSet */
13801 VdbeFrame *pFrame; /* Used when flags==MEM_Frame */
13802 } u;
13803 int n; /* Number of characters in string value, excluding '\0' */
13804 u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
13805 u8 memType; /* Lower 5 bits of flags */
13806 u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
13807 #ifdef SQLITE_DEBUG
13808 Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
13809 void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
13810 #endif
@@ -13774,11 +13829,11 @@
13829 #define MEM_Int 0x0004 /* Value is an integer */
13830 #define MEM_Real 0x0008 /* Value is a real number */
13831 #define MEM_Blob 0x0010 /* Value is a BLOB */
13832 #define MEM_RowSet 0x0020 /* Value is a RowSet object */
13833 #define MEM_Frame 0x0040 /* Value is a VdbeFrame object */
13834 #define MEM_Undefined 0x0080 /* Value is undefined */
13835 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
13836 #define MEM_TypeMask 0x01ff /* Mask of type bits */
13837
13838
13839 /* Whenever Mem contains a valid string or blob representation, one of
@@ -13806,11 +13861,11 @@
13861 /*
13862 ** Return true if a memory cell is not marked as invalid. This macro
13863 ** is for use inside assert() statements only.
13864 */
13865 #ifdef SQLITE_DEBUG
13866 #define memIsValid(M) ((M)->flags & MEM_Undefined)==0
13867 #endif
13868
13869 /*
13870 ** Each auxilliary data pointer stored by a user defined function
13871 ** implementation calling sqlite3_set_auxdata() is stored in an instance
@@ -14001,20 +14056,22 @@
14056 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem*);
14057 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem*);
14058 SQLITE_PRIVATE int sqlite3VdbeMemFromBtree(BtCursor*,u32,u32,int,Mem*);
14059 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p);
14060 SQLITE_PRIVATE void sqlite3VdbeMemReleaseExternal(Mem *p);
14061 #define VdbeMemDynamic(X) \
14062 (((X)->flags&(MEM_Agg|MEM_Dyn|MEM_RowSet|MEM_Frame))!=0)
14063 #define VdbeMemRelease(X) \
14064 if( VdbeMemDynamic(X) ) sqlite3VdbeMemReleaseExternal(X);
 
14065 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem*, FuncDef*);
14066 SQLITE_PRIVATE const char *sqlite3OpcodeName(int);
14067 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
14068 SQLITE_PRIVATE int sqlite3VdbeCloseStatement(Vdbe *, int);
14069 SQLITE_PRIVATE void sqlite3VdbeFrameDelete(VdbeFrame*);
14070 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *);
14071 #define sqlite3VdbeMemStoreType(X) (X)->memType = (u8)((X)->flags&0x1f)
14072 /* void sqlite3VdbeMemStoreType(Mem *pMem); */
14073 SQLITE_PRIVATE int sqlite3VdbeTransferError(Vdbe *p);
14074
14075 SQLITE_PRIVATE int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
14076 SQLITE_PRIVATE void sqlite3VdbeSorterClose(sqlite3 *, VdbeCursor *);
14077 SQLITE_PRIVATE int sqlite3VdbeSorterRowkey(const VdbeCursor *, Mem *);
@@ -17778,10 +17835,16 @@
17835 mem5.totalExcess += iFullSz - nByte;
17836 mem5.currentCount++;
17837 mem5.currentOut += iFullSz;
17838 if( mem5.maxCount<mem5.currentCount ) mem5.maxCount = mem5.currentCount;
17839 if( mem5.maxOut<mem5.currentOut ) mem5.maxOut = mem5.currentOut;
17840
17841 #ifdef SQLITE_DEBUG
17842 /* Make sure the allocated memory does not assume that it is set to zero
17843 ** or retains a value from a previous allocation */
17844 memset(&mem5.zPool[i*mem5.szAtom], 0xAA, iFullSz);
17845 #endif
17846
17847 /* Return a pointer to the allocated memory. */
17848 return (void*)&mem5.zPool[i*mem5.szAtom];
17849 }
17850
@@ -17836,10 +17899,17 @@
17899 mem5.aCtrl[iBlock] = CTRL_FREE | iLogsize;
17900 mem5.aCtrl[iBuddy] = 0;
17901 }
17902 size *= 2;
17903 }
17904
17905 #ifdef SQLITE_DEBUG
17906 /* Overwrite freed memory with the 0x55 bit pattern to verify that it is
17907 ** not used after being freed */
17908 memset(&mem5.zPool[iBlock*mem5.szAtom], 0x55, size);
17909 #endif
17910
17911 memsys5Link(iBlock, iLogsize);
17912 }
17913
17914 /*
17915 ** Allocate nBytes of memory.
@@ -22739,17 +22809,16 @@
22809 testcase( iB==-1 ); testcase( iB==0 );
22810 if( iB>=0 ){
22811 testcase( iA>0 && LARGEST_INT64 - iA == iB );
22812 testcase( iA>0 && LARGEST_INT64 - iA == iB - 1 );
22813 if( iA>0 && LARGEST_INT64 - iA < iB ) return 1;
 
22814 }else{
22815 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 1 );
22816 testcase( iA<0 && -(iA + LARGEST_INT64) == iB + 2 );
22817 if( iA<0 && -(iA + LARGEST_INT64) > iB + 1 ) return 1;
 
22818 }
22819 *pA += iB;
22820 return 0;
22821 }
22822 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
22823 testcase( iB==SMALLEST_INT64+1 );
22824 if( iB==SMALLEST_INT64 ){
@@ -22769,13 +22838,22 @@
22838
22839 iA1 = iA/TWOPOWER32;
22840 iA0 = iA % TWOPOWER32;
22841 iB1 = iB/TWOPOWER32;
22842 iB0 = iB % TWOPOWER32;
22843 if( iA1==0 ){
22844 if( iB1==0 ){
22845 *pA *= iB;
22846 return 0;
22847 }
22848 r = iA0*iB1;
22849 }else if( iB1==0 ){
22850 r = iA1*iB0;
22851 }else{
22852 /* If both iA1 and iB1 are non-zero, overflow will result */
22853 return 1;
22854 }
22855 testcase( r==(-TWOPOWER31)-1 );
22856 testcase( r==(-TWOPOWER31) );
22857 testcase( r==TWOPOWER31 );
22858 testcase( r==TWOPOWER31-1 );
22859 if( r<(-TWOPOWER31) || r>=TWOPOWER31 ) return 1;
@@ -23217,75 +23295,75 @@
23295 /* 15 */ "VUpdate" OpHelp("data=r[P3@P2]"),
23296 /* 16 */ "Goto" OpHelp(""),
23297 /* 17 */ "Gosub" OpHelp(""),
23298 /* 18 */ "Return" OpHelp(""),
23299 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
23300 /* 20 */ "InitCoroutine" OpHelp(""),
23301 /* 21 */ "EndCoroutine" OpHelp(""),
23302 /* 22 */ "Yield" OpHelp(""),
23303 /* 23 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
23304 /* 24 */ "Halt" OpHelp(""),
23305 /* 25 */ "Integer" OpHelp("r[P2]=P1"),
23306 /* 26 */ "Int64" OpHelp("r[P2]=P4"),
23307 /* 27 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
23308 /* 28 */ "Null" OpHelp("r[P2..P3]=NULL"),
23309 /* 29 */ "SoftNull" OpHelp("r[P1]=NULL"),
23310 /* 30 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
23311 /* 31 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
23312 /* 32 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
23313 /* 33 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
23314 /* 34 */ "SCopy" OpHelp("r[P2]=r[P1]"),
23315 /* 35 */ "ResultRow" OpHelp("output=r[P1@P2]"),
23316 /* 36 */ "CollSeq" OpHelp(""),
23317 /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
23318 /* 38 */ "MustBeInt" OpHelp(""),
23319 /* 39 */ "RealAffinity" OpHelp(""),
23320 /* 40 */ "Permutation" OpHelp(""),
23321 /* 41 */ "Compare" OpHelp(""),
23322 /* 42 */ "Jump" OpHelp(""),
23323 /* 43 */ "Once" OpHelp(""),
23324 /* 44 */ "If" OpHelp(""),
23325 /* 45 */ "IfNot" OpHelp(""),
23326 /* 46 */ "Column" OpHelp("r[P3]=PX"),
23327 /* 47 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
23328 /* 48 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
23329 /* 49 */ "Count" OpHelp("r[P2]=count()"),
23330 /* 50 */ "ReadCookie" OpHelp(""),
23331 /* 51 */ "SetCookie" OpHelp(""),
23332 /* 52 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23333 /* 53 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23334 /* 54 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23335 /* 55 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23336 /* 56 */ "SorterOpen" OpHelp(""),
23337 /* 57 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
23338 /* 58 */ "Close" OpHelp(""),
23339 /* 59 */ "SeekLT" OpHelp(""),
23340 /* 60 */ "SeekLE" OpHelp(""),
23341 /* 61 */ "SeekGE" OpHelp(""),
23342 /* 62 */ "SeekGT" OpHelp(""),
23343 /* 63 */ "Seek" OpHelp("intkey=r[P2]"),
23344 /* 64 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23345 /* 65 */ "NotFound" OpHelp("key=r[P3@P4]"),
23346 /* 66 */ "Found" OpHelp("key=r[P3@P4]"),
23347 /* 67 */ "NotExists" OpHelp("intkey=r[P3]"),
23348 /* 68 */ "Sequence" OpHelp("r[P2]=rowid"),
23349 /* 69 */ "NewRowid" OpHelp("r[P2]=rowid"),
23350 /* 70 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23351 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23352 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23353 /* 73 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23354 /* 74 */ "Delete" OpHelp(""),
23355 /* 75 */ "ResetCount" OpHelp(""),
23356 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23357 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23358 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23359 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23360 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23361 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23362 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23363 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23364 /* 84 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23365 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23366 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23367 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23368 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23369 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23292,68 +23370,72 @@
23370 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23371 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23372 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23373 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23374 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23375 /* 95 */ "SorterData" OpHelp("r[P2]=data"),
23376 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23377 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23378 /* 98 */ "RowKey" OpHelp("r[P2]=key"),
23379 /* 99 */ "RowData" OpHelp("r[P2]=data"),
23380 /* 100 */ "Rowid" OpHelp("r[P2]=rowid"),
23381 /* 101 */ "NullRow" OpHelp(""),
23382 /* 102 */ "Last" OpHelp(""),
23383 /* 103 */ "SorterSort" OpHelp(""),
23384 /* 104 */ "Sort" OpHelp(""),
23385 /* 105 */ "Rewind" OpHelp(""),
23386 /* 106 */ "SorterInsert" OpHelp(""),
23387 /* 107 */ "IdxInsert" OpHelp("key=r[P2]"),
23388 /* 108 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23389 /* 109 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23390 /* 110 */ "IdxLE" OpHelp("key=r[P3@P4]"),
23391 /* 111 */ "IdxGT" OpHelp("key=r[P3@P4]"),
23392 /* 112 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23393 /* 113 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23394 /* 114 */ "Destroy" OpHelp(""),
23395 /* 115 */ "Clear" OpHelp(""),
23396 /* 116 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23397 /* 117 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23398 /* 118 */ "ParseSchema" OpHelp(""),
23399 /* 119 */ "LoadAnalysis" OpHelp(""),
23400 /* 120 */ "DropTable" OpHelp(""),
23401 /* 121 */ "DropIndex" OpHelp(""),
23402 /* 122 */ "DropTrigger" OpHelp(""),
23403 /* 123 */ "IntegrityCk" OpHelp(""),
23404 /* 124 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23405 /* 125 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23406 /* 126 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23407 /* 127 */ "Program" OpHelp(""),
23408 /* 128 */ "Param" OpHelp(""),
23409 /* 129 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23410 /* 130 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23411 /* 131 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23412 /* 132 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23413 /* 133 */ "Real" OpHelp("r[P2]=P4"),
23414 /* 134 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23415 /* 135 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23416 /* 136 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23417 /* 137 */ "IncrVacuum" OpHelp(""),
23418 /* 138 */ "Expire" OpHelp(""),
23419 /* 139 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23420 /* 140 */ "VBegin" OpHelp(""),
23421 /* 141 */ "VCreate" OpHelp(""),
23422 /* 142 */ "VDestroy" OpHelp(""),
23423 /* 143 */ "ToText" OpHelp(""),
23424 /* 144 */ "ToBlob" OpHelp(""),
23425 /* 145 */ "ToNumeric" OpHelp(""),
23426 /* 146 */ "ToInt" OpHelp(""),
23427 /* 147 */ "ToReal" OpHelp(""),
23428 /* 148 */ "VOpen" OpHelp(""),
23429 /* 149 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23430 /* 150 */ "VNext" OpHelp(""),
23431 /* 151 */ "VRename" OpHelp(""),
23432 /* 152 */ "Pagecount" OpHelp(""),
23433 /* 153 */ "MaxPgcnt" OpHelp(""),
23434 /* 154 */ "Init" OpHelp("Start at P2"),
23435 /* 155 */ "Noop" OpHelp(""),
23436 /* 156 */ "Explain" OpHelp(""),
23437 };
23438 return azName[i];
23439 }
23440 #endif
23441
@@ -34429,11 +34511,11 @@
34511 ** Windows will only let you create file view mappings
34512 ** on allocation size granularity boundaries.
34513 ** During sqlite3_os_init() we do a GetSystemInfo()
34514 ** to get the granularity size.
34515 */
34516 static SYSTEM_INFO winSysInfo;
34517
34518 #ifndef SQLITE_OMIT_WAL
34519
34520 /*
34521 ** Helper functions to obtain and relinquish the global mutex. The
@@ -36363,19 +36445,16 @@
36445 #ifndef SQLITE_OMIT_LOAD_EXTENSION
36446 /*
36447 ** Interfaces for opening a shared library, finding entry points
36448 ** within the shared library, and closing the shared library.
36449 */
 
 
 
 
36450 static void *winDlOpen(sqlite3_vfs *pVfs, const char *zFilename){
36451 HANDLE h;
36452 void *zConverted = winConvertFromUtf8Filename(zFilename);
36453 UNUSED_PARAMETER(pVfs);
36454 if( zConverted==0 ){
36455 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)0));
36456 return 0;
36457 }
36458 if( osIsNT() ){
36459 #if SQLITE_OS_WINRT
36460 h = osLoadPackagedLibrary((LPCWSTR)zConverted, 0);
@@ -36386,24 +36465,30 @@
36465 #ifdef SQLITE_WIN32_HAS_ANSI
36466 else{
36467 h = osLoadLibraryA((char*)zConverted);
36468 }
36469 #endif
36470 OSTRACE(("DLOPEN name=%s, handle=%p\n", zFilename, (void*)h));
36471 sqlite3_free(zConverted);
36472 return (void*)h;
36473 }
36474 static void winDlError(sqlite3_vfs *pVfs, int nBuf, char *zBufOut){
36475 UNUSED_PARAMETER(pVfs);
36476 winGetLastErrorMsg(osGetLastError(), nBuf, zBufOut);
36477 }
36478 static void (*winDlSym(sqlite3_vfs *pVfs,void *pH,const char *zSym))(void){
36479 FARPROC proc;
36480 UNUSED_PARAMETER(pVfs);
36481 proc = osGetProcAddressA((HANDLE)pH, zSym);
36482 OSTRACE(("DLSYM handle=%p, symbol=%s, address=%p\n",
36483 (void*)pH, zSym, (void*)proc));
36484 return (void(*)(void))proc;
36485 }
36486 static void winDlClose(sqlite3_vfs *pVfs, void *pHandle){
36487 UNUSED_PARAMETER(pVfs);
36488 osFreeLibrary((HANDLE)pHandle);
36489 OSTRACE(("DLCLOSE handle=%p\n", (void*)pHandle));
36490 }
36491 #else /* if SQLITE_OMIT_LOAD_EXTENSION is defined: */
36492 #define winDlOpen 0
36493 #define winDlError 0
36494 #define winDlSym 0
@@ -37095,11 +37180,12 @@
37180 PgHdr *pSynced; /* Last synced page in dirty page list */
37181 int nRef; /* Number of referenced pages */
37182 int szCache; /* Configured cache size */
37183 int szPage; /* Size of every page in this cache */
37184 int szExtra; /* Size of extra space for each page */
37185 u8 bPurgeable; /* True if pages are on backing store */
37186 u8 eCreate; /* eCreate value for for xFetch() */
37187 int (*xStress)(void*,PgHdr*); /* Call to try make a page clean */
37188 void *pStress; /* Argument to xStress */
37189 sqlite3_pcache *pCache; /* Pluggable cache module */
37190 PgHdr *pPage1; /* Reference to page 1 */
37191 };
@@ -37162,10 +37248,14 @@
37248 if( pPage->pDirtyPrev ){
37249 pPage->pDirtyPrev->pDirtyNext = pPage->pDirtyNext;
37250 }else{
37251 assert( pPage==p->pDirty );
37252 p->pDirty = pPage->pDirtyNext;
37253 if( p->pDirty==0 && p->bPurgeable ){
37254 assert( p->eCreate==1 );
37255 p->eCreate = 2;
37256 }
37257 }
37258 pPage->pDirtyNext = 0;
37259 pPage->pDirtyPrev = 0;
37260
37261 expensive_assert( pcacheCheckSynced(p) );
@@ -37182,10 +37272,13 @@
37272
37273 pPage->pDirtyNext = p->pDirty;
37274 if( pPage->pDirtyNext ){
37275 assert( pPage->pDirtyNext->pDirtyPrev==0 );
37276 pPage->pDirtyNext->pDirtyPrev = pPage;
37277 }else if( p->bPurgeable ){
37278 assert( p->eCreate==2 );
37279 p->eCreate = 1;
37280 }
37281 p->pDirty = pPage;
37282 if( !p->pDirtyTail ){
37283 p->pDirtyTail = pPage;
37284 }
@@ -37251,10 +37344,11 @@
37344 ){
37345 memset(p, 0, sizeof(PCache));
37346 p->szPage = szPage;
37347 p->szExtra = szExtra;
37348 p->bPurgeable = bPurgeable;
37349 p->eCreate = 2;
37350 p->xStress = xStress;
37351 p->pStress = pStress;
37352 p->szCache = 100;
37353 }
37354
@@ -37290,11 +37384,11 @@
37384 PCache *pCache, /* Obtain the page from this cache */
37385 Pgno pgno, /* Page number to obtain */
37386 int createFlag, /* If true, create page if it does not exist already */
37387 PgHdr **ppPage /* Write the page here */
37388 ){
37389 sqlite3_pcache_page *pPage;
37390 PgHdr *pPgHdr = 0;
37391 int eCreate;
37392
37393 assert( pCache!=0 );
37394 assert( createFlag==1 || createFlag==0 );
@@ -37301,12 +37395,16 @@
37395 assert( pgno>0 );
37396
37397 /* If the pluggable cache (sqlite3_pcache*) has not been allocated,
37398 ** allocate it now.
37399 */
37400 if( !pCache->pCache ){
37401 sqlite3_pcache *p;
37402 if( !createFlag ){
37403 *ppPage = 0;
37404 return SQLITE_OK;
37405 }
37406 p = sqlite3GlobalConfig.pcache2.xCreate(
37407 pCache->szPage, pCache->szExtra + sizeof(PgHdr), pCache->bPurgeable
37408 );
37409 if( !p ){
37410 return SQLITE_NOMEM;
@@ -37313,15 +37411,20 @@
37411 }
37412 sqlite3GlobalConfig.pcache2.xCachesize(p, numberOfCachePages(pCache));
37413 pCache->pCache = p;
37414 }
37415
37416 /* eCreate defines what to do if the page does not exist.
37417 ** 0 Do not allocate a new page. (createFlag==0)
37418 ** 1 Allocate a new page if doing so is inexpensive.
37419 ** (createFlag==1 AND bPurgeable AND pDirty)
37420 ** 2 Allocate a new page even it doing so is difficult.
37421 ** (createFlag==1 AND !(bPurgeable AND pDirty)
37422 */
37423 eCreate = createFlag==0 ? 0 : pCache->eCreate;
37424 assert( (createFlag*(1+(!pCache->bPurgeable||!pCache->pDirty)))==eCreate );
37425 pPage = sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
37426 if( !pPage && eCreate==1 ){
37427 PgHdr *pPg;
37428
37429 /* Find a dirty page to write-out and recycle. First try to find a
37430 ** page that does not require a journal-sync (one with PGHDR_NEED_SYNC
@@ -47905,11 +48008,11 @@
48008 if( rc!=SQLITE_OK ){
48009 walIndexClose(pRet, 0);
48010 sqlite3OsClose(pRet->pWalFd);
48011 sqlite3_free(pRet);
48012 }else{
48013 int iDC = sqlite3OsDeviceCharacteristics(pDbFd);
48014 if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
48015 if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){
48016 pRet->padToSectorBoundary = 0;
48017 }
48018 *ppWal = pRet;
@@ -49276,11 +49379,11 @@
49379 if( rc ) return rc;
49380 iOffset += iFirstAmt;
49381 iAmt -= iFirstAmt;
49382 pContent = (void*)(iFirstAmt + (char*)pContent);
49383 assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) );
49384 rc = sqlite3OsSync(p->pFd, p->syncFlags & SQLITE_SYNC_MASK);
49385 if( iAmt==0 || rc ) return rc;
49386 }
49387 rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
49388 return rc;
49389 }
@@ -50214,11 +50317,10 @@
50317 struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
50318 #ifndef SQLITE_OMIT_INCRBLOB
50319 Pgno *aOverflow; /* Cache of overflow page locations */
50320 #endif
50321 Pgno pgnoRoot; /* The root page of this tree */
 
50322 CellInfo info; /* A parse of the cell we are pointing at */
50323 i64 nKey; /* Size of pKey, or last integer key */
50324 void *pKey; /* Saved key that was cursor's last known position */
50325 int skipNext; /* Prev() is noop if negative. Next() is noop if positive */
50326 u8 wrFlag; /* True if writable */
@@ -52198,17 +52300,16 @@
52300 assert( sqlite3_mutex_held(pBt->mutex) );
52301 if( pBt->btsFlags & BTS_SECURE_DELETE ){
52302 memset(&data[hdr], 0, pBt->usableSize - hdr);
52303 }
52304 data[hdr] = (char)flags;
52305 first = hdr + ((flags&PTF_LEAF)==0 ? 12 : 8);
52306 memset(&data[hdr+1], 0, 4);
52307 data[hdr+7] = 0;
52308 put2byte(&data[hdr+5], pBt->usableSize);
52309 pPage->nFree = (u16)(pBt->usableSize - first);
52310 decodeFlags(pPage, flags);
 
52311 pPage->cellOffset = first;
52312 pPage->aDataEnd = &data[pBt->usableSize];
52313 pPage->aCellIdx = &data[first];
52314 pPage->nOverflow = 0;
52315 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
@@ -54288,11 +54389,10 @@
54389 if( pCur->pNext ){
54390 pCur->pNext->pPrev = pCur;
54391 }
54392 pBt->pCursor = pCur;
54393 pCur->eState = CURSOR_INVALID;
 
54394 return SQLITE_OK;
54395 }
54396 SQLITE_PRIVATE int sqlite3BtreeCursor(
54397 Btree *p, /* The btree */
54398 int iTable, /* Root page of table to open */
@@ -54329,40 +54429,10 @@
54429 */
54430 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor *p){
54431 memset(p, 0, offsetof(BtCursor, iPage));
54432 }
54433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54434 /*
54435 ** Close a cursor. The read lock on the database file is released
54436 ** when the last cursor is closed.
54437 */
54438 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
@@ -55433,18 +55503,28 @@
55503 /*
55504 ** Advance the cursor to the next entry in the database. If
55505 ** successful then set *pRes=0. If the cursor
55506 ** was already pointing to the last entry in the database before
55507 ** this routine was called, then set *pRes=1.
55508 **
55509 ** The calling function will set *pRes to 0 or 1. The initial *pRes value
55510 ** will be 1 if the cursor being stepped corresponds to an SQL index and
55511 ** if this routine could have been skipped if that SQL index had been
55512 ** a unique index. Otherwise the caller will have set *pRes to zero.
55513 ** Zero is the common case. The btree implementation is free to use the
55514 ** initial *pRes value as a hint to improve performance, but the current
55515 ** SQLite btree implementation does not. (Note that the comdb2 btree
55516 ** implementation does use this hint, however.)
55517 */
55518 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor *pCur, int *pRes){
55519 int rc;
55520 int idx;
55521 MemPage *pPage;
55522
55523 assert( cursorHoldsMutex(pCur) );
55524 assert( pRes!=0 );
55525 assert( *pRes==0 || *pRes==1 );
55526 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
55527 if( pCur->eState!=CURSOR_VALID ){
55528 rc = restoreCursorPosition(pCur);
55529 if( rc!=SQLITE_OK ){
55530 *pRes = 0;
@@ -55519,17 +55599,27 @@
55599 /*
55600 ** Step the cursor to the back to the previous entry in the database. If
55601 ** successful then set *pRes=0. If the cursor
55602 ** was already pointing to the first entry in the database before
55603 ** this routine was called, then set *pRes=1.
55604 **
55605 ** The calling function will set *pRes to 0 or 1. The initial *pRes value
55606 ** will be 1 if the cursor being stepped corresponds to an SQL index and
55607 ** if this routine could have been skipped if that SQL index had been
55608 ** a unique index. Otherwise the caller will have set *pRes to zero.
55609 ** Zero is the common case. The btree implementation is free to use the
55610 ** initial *pRes value as a hint to improve performance, but the current
55611 ** SQLite btree implementation does not. (Note that the comdb2 btree
55612 ** implementation does use this hint, however.)
55613 */
55614 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){
55615 int rc;
55616 MemPage *pPage;
55617
55618 assert( cursorHoldsMutex(pCur) );
55619 assert( pRes!=0 );
55620 assert( *pRes==0 || *pRes==1 );
55621 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
55622 pCur->atLast = 0;
55623 if( pCur->eState!=CURSOR_VALID ){
55624 if( ALWAYS(pCur->eState>=CURSOR_REQUIRESEEK) ){
55625 rc = btreeRestoreCursorPosition(pCur);
@@ -57622,15 +57712,21 @@
57712 ** not to clear the cursor here.
57713 */
57714 rc = saveAllCursors(pBt, pCur->pgnoRoot, pCur);
57715 if( rc ) return rc;
57716
 
 
 
57717 if( pCur->pKeyInfo==0 ){
57718 /* If this is an insert into a table b-tree, invalidate any incrblob
57719 ** cursors open on the row being replaced */
57720 invalidateIncrblobCursors(p, nKey, 0);
57721
57722 /* If the cursor is currently on the last row and we are appending a
57723 ** new row onto the end, set the "loc" to avoid an unnecessary btreeMoveto()
57724 ** call */
57725 if( pCur->validNKey && nKey>0 && pCur->info.nKey==nKey-1 ){
57726 loc = -1;
57727 }
57728 }
57729
57730 if( !loc ){
57731 rc = btreeMoveto(pCur, pKey, nKey, appendBias, &loc);
57732 if( rc ) return rc;
@@ -57696,12 +57792,12 @@
57792 ** entry in the table, and the next row inserted has an integer key
57793 ** larger than the largest existing key, it is possible to insert the
57794 ** row without seeking the cursor. This can be a big performance boost.
57795 */
57796 pCur->info.nSize = 0;
 
57797 if( rc==SQLITE_OK && pPage->nOverflow ){
57798 pCur->validNKey = 0;
57799 rc = balance(pCur);
57800
57801 /* Must make sure nOverflow is reset to zero even if the balance()
57802 ** fails. Internal data structure corruption will result otherwise.
57803 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
@@ -57752,11 +57848,11 @@
57848 ** from the internal node. The 'previous' entry is used for this instead
57849 ** of the 'next' entry, as the previous entry is always a part of the
57850 ** sub-tree headed by the child page of the cell being deleted. This makes
57851 ** balancing the tree following the delete operation easier. */
57852 if( !pPage->leaf ){
57853 int notUsed = 0;
57854 rc = sqlite3BtreePrevious(pCur, &notUsed);
57855 if( rc ) return rc;
57856 }
57857
57858 /* Save the positions of any other cursors open on this table before
@@ -60177,11 +60273,11 @@
60273 }
60274
60275 /*
60276 ** Release any memory held by the Mem. This may leave the Mem in an
60277 ** inconsistent state, for example with (Mem.z==0) and
60278 ** (Mem.memType==MEM_Str).
60279 */
60280 SQLITE_PRIVATE void sqlite3VdbeMemRelease(Mem *p){
60281 VdbeMemRelease(p);
60282 if( p->zMalloc ){
60283 sqlite3DbFree(p->db, p->zMalloc);
@@ -60368,11 +60464,11 @@
60464 }
60465 if( pMem->flags & MEM_RowSet ){
60466 sqlite3RowSetClear(pMem->u.pRowSet);
60467 }
60468 MemSetTypeFlag(pMem, MEM_Null);
60469 pMem->memType = MEM_Null;
60470 }
60471 SQLITE_PRIVATE void sqlite3ValueSetNull(sqlite3_value *p){
60472 sqlite3VdbeMemSetNull((Mem*)p);
60473 }
60474
@@ -60381,11 +60477,11 @@
60477 ** n containing all zeros.
60478 */
60479 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
60480 sqlite3VdbeMemRelease(pMem);
60481 pMem->flags = MEM_Blob|MEM_Zero;
60482 pMem->memType = MEM_Blob;
60483 pMem->n = 0;
60484 if( n<0 ) n = 0;
60485 pMem->u.nZero = n;
60486 pMem->enc = SQLITE_UTF8;
60487
@@ -60404,11 +60500,11 @@
60500 */
60501 SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
60502 sqlite3VdbeMemRelease(pMem);
60503 pMem->u.i = val;
60504 pMem->flags = MEM_Int;
60505 pMem->memType = MEM_Int;
60506 }
60507
60508 #ifndef SQLITE_OMIT_FLOATING_POINT
60509 /*
60510 ** Delete any previous value and set the value stored in *pMem to val,
@@ -60419,11 +60515,11 @@
60515 sqlite3VdbeMemSetNull(pMem);
60516 }else{
60517 sqlite3VdbeMemRelease(pMem);
60518 pMem->r = val;
60519 pMem->flags = MEM_Real;
60520 pMem->memType = MEM_Real;
60521 }
60522 }
60523 #endif
60524
60525 /*
@@ -60475,11 +60571,11 @@
60571 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
60572 int i;
60573 Mem *pX;
60574 for(i=1, pX=&pVdbe->aMem[1]; i<=pVdbe->nMem; i++, pX++){
60575 if( pX->pScopyFrom==pMem ){
60576 pX->flags |= MEM_Undefined;
60577 pX->pScopyFrom = 0;
60578 }
60579 }
60580 pMem->pScopyFrom = 0;
60581 }
@@ -60627,11 +60723,11 @@
60723 }
60724
60725 pMem->n = nByte;
60726 pMem->flags = flags;
60727 pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
60728 pMem->memType = flags&0x1f;
60729
60730 #ifndef SQLITE_OMIT_UTF16
60731 if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
60732 return SQLITE_NOMEM;
60733 }
@@ -60798,11 +60894,11 @@
60894 pMem->z = &zData[offset];
60895 pMem->flags = MEM_Blob|MEM_Ephem;
60896 }else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
60897 pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
60898 pMem->enc = 0;
60899 pMem->memType = MEM_Blob;
60900 if( key ){
60901 rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
60902 }else{
60903 rc = sqlite3BtreeData(pCur, offset, amt, pMem->z);
60904 }
@@ -60868,11 +60964,11 @@
60964 */
60965 SQLITE_PRIVATE sqlite3_value *sqlite3ValueNew(sqlite3 *db){
60966 Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
60967 if( p ){
60968 p->flags = MEM_Null;
60969 p->memType = MEM_Null;
60970 p->db = db;
60971 }
60972 return p;
60973 }
60974
@@ -60918,11 +61014,11 @@
61014 assert( pRec->pKeyInfo->enc==ENC(db) );
61015 pRec->flags = UNPACKED_PREFIX_MATCH;
61016 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
61017 for(i=0; i<nCol; i++){
61018 pRec->aMem[i].flags = MEM_Null;
61019 pRec->aMem[i].memType = MEM_Null;
61020 pRec->aMem[i].db = db;
61021 }
61022 }else{
61023 sqlite3DbFree(db, pRec);
61024 pRec = 0;
@@ -60991,11 +61087,11 @@
61087 sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt);
61088 }else{
61089 zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
61090 if( zVal==0 ) goto no_mem;
61091 sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
61092 if( op==TK_FLOAT ) pVal->memType = MEM_Real;
61093 }
61094 if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
61095 sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
61096 }else{
61097 sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8);
@@ -61449,10 +61545,13 @@
61545 #endif
61546 #ifdef VDBE_PROFILE
61547 pOp->cycles = 0;
61548 pOp->cnt = 0;
61549 #endif
61550 #ifdef SQLITE_VDBE_COVERAGE
61551 pOp->iSrcLine = 0;
61552 #endif
61553 return i;
61554 }
61555 SQLITE_PRIVATE int sqlite3VdbeAddOp0(Vdbe *p, int op){
61556 return sqlite3VdbeAddOp3(p, op, 0, 0, 0);
61557 }
@@ -61810,11 +61909,11 @@
61909
61910 /*
61911 ** Add a whole list of operations to the operation stack. Return the
61912 ** address of the first operation added.
61913 */
61914 SQLITE_PRIVATE int sqlite3VdbeAddOpList(Vdbe *p, int nOp, VdbeOpList const *aOp, int iLineno){
61915 int addr;
61916 assert( p->magic==VDBE_MAGIC_INIT );
61917 if( p->nOp + nOp > p->pParse->nOpAlloc && growOpArray(p) ){
61918 return 0;
61919 }
@@ -61837,10 +61936,15 @@
61936 pOut->p4type = P4_NOTUSED;
61937 pOut->p4.p = 0;
61938 pOut->p5 = 0;
61939 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
61940 pOut->zComment = 0;
61941 #endif
61942 #ifdef SQLITE_VDBE_COVERAGE
61943 pOut->iSrcLine = iLineno+i;
61944 #else
61945 (void)iLineno;
61946 #endif
61947 #ifdef SQLITE_DEBUG
61948 if( p->db->flags & SQLITE_VdbeAddopTrace ){
61949 sqlite3VdbePrintOp(0, i+addr, &p->aOp[i+addr]);
61950 }
@@ -62126,10 +62230,19 @@
62230 va_end(ap);
62231 }
62232 }
62233 #endif /* NDEBUG */
62234
62235 #ifdef SQLITE_VDBE_COVERAGE
62236 /*
62237 ** Set the value if the iSrcLine field for the previously coded instruction.
62238 */
62239 SQLITE_PRIVATE void sqlite3VdbeSetLineNumber(Vdbe *v, int iLine){
62240 sqlite3VdbeGetOp(v,-1)->iSrcLine = iLine;
62241 }
62242 #endif /* SQLITE_VDBE_COVERAGE */
62243
62244 /*
62245 ** Return the opcode for a given address. If the address is -1, then
62246 ** return the most recently inserted opcode.
62247 **
62248 ** If a memory allocation error has occurred prior to the calling of this
@@ -62138,28 +62251,17 @@
62251 ** The return of a dummy opcode allows the call to continue functioning
62252 ** after a OOM fault without having to check to see if the return from
62253 ** this routine is a valid pointer. But because the dummy.opcode is 0,
62254 ** dummy will never be written to. This is verified by code inspection and
62255 ** by running with Valgrind.
 
 
 
 
 
 
 
 
62256 */
62257 SQLITE_PRIVATE VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
62258 /* C89 specifies that the constant "dummy" will be initialized to all
62259 ** zeros, which is correct. MSVC generates a warning, nevertheless. */
62260 static VdbeOp dummy; /* Ignore the MSVC warning about no initializer */
62261 assert( p->magic==VDBE_MAGIC_INIT );
62262 if( addr<0 ){
 
 
 
62263 addr = p->nOp - 1;
62264 }
62265 assert( (addr>=0 && addr<p->nOp) || p->db->mallocFailed );
62266 if( p->db->mallocFailed ){
62267 return (VdbeOp*)&dummy;
@@ -62460,11 +62562,11 @@
62562 if( pOut==0 ) pOut = stdout;
62563 zP4 = displayP4(pOp, zPtr, sizeof(zPtr));
62564 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62565 displayComment(pOp, zP4, zCom, sizeof(zCom));
62566 #else
62567 zCom[0] = 0;
62568 #endif
62569 /* NB: The sqlite3OpcodeName() function is implemented by code created
62570 ** by the mkopcodeh.awk and mkopcodec.awk scripts which extract the
62571 ** information from the vdbe.c source text */
62572 fprintf(pOut, zFormat1, pc,
@@ -62509,11 +62611,11 @@
62611 }else if( p->zMalloc ){
62612 sqlite3DbFree(db, p->zMalloc);
62613 p->zMalloc = 0;
62614 }
62615
62616 p->flags = MEM_Undefined;
62617 }
62618 db->mallocFailed = malloc_failed;
62619 }
62620 }
62621
@@ -62631,19 +62733,19 @@
62733 }
62734 pOp = &apSub[j]->aOp[i];
62735 }
62736 if( p->explain==1 ){
62737 pMem->flags = MEM_Int;
62738 pMem->memType = MEM_Int;
62739 pMem->u.i = i; /* Program counter */
62740 pMem++;
62741
62742 pMem->flags = MEM_Static|MEM_Str|MEM_Term;
62743 pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
62744 assert( pMem->z!=0 );
62745 pMem->n = sqlite3Strlen30(pMem->z);
62746 pMem->memType = MEM_Str;
62747 pMem->enc = SQLITE_UTF8;
62748 pMem++;
62749
62750 /* When an OP_Program opcode is encounter (the only opcode that has
62751 ** a P4_SUBPROGRAM argument), expand the size of the array of subprograms
@@ -62665,21 +62767,21 @@
62767 }
62768 }
62769
62770 pMem->flags = MEM_Int;
62771 pMem->u.i = pOp->p1; /* P1 */
62772 pMem->memType = MEM_Int;
62773 pMem++;
62774
62775 pMem->flags = MEM_Int;
62776 pMem->u.i = pOp->p2; /* P2 */
62777 pMem->memType = MEM_Int;
62778 pMem++;
62779
62780 pMem->flags = MEM_Int;
62781 pMem->u.i = pOp->p3; /* P3 */
62782 pMem->memType = MEM_Int;
62783 pMem++;
62784
62785 if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
62786 assert( p->db->mallocFailed );
62787 return SQLITE_ERROR;
@@ -62691,11 +62793,11 @@
62793 }else{
62794 assert( pMem->z!=0 );
62795 pMem->n = sqlite3Strlen30(pMem->z);
62796 pMem->enc = SQLITE_UTF8;
62797 }
62798 pMem->memType = MEM_Str;
62799 pMem++;
62800
62801 if( p->explain==1 ){
62802 if( sqlite3VdbeMemGrow(pMem, 4, 0) ){
62803 assert( p->db->mallocFailed );
@@ -62702,11 +62804,11 @@
62804 return SQLITE_ERROR;
62805 }
62806 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62807 pMem->n = 2;
62808 sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
62809 pMem->memType = MEM_Str;
62810 pMem->enc = SQLITE_UTF8;
62811 pMem++;
62812
62813 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
62814 if( sqlite3VdbeMemGrow(pMem, 500, 0) ){
@@ -62713,15 +62815,15 @@
62815 assert( p->db->mallocFailed );
62816 return SQLITE_ERROR;
62817 }
62818 pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
62819 pMem->n = displayComment(pOp, zP4, pMem->z, 500);
62820 pMem->memType = MEM_Str;
62821 pMem->enc = SQLITE_UTF8;
62822 #else
62823 pMem->flags = MEM_Null; /* Comment */
62824 pMem->memType = MEM_Null;
62825 #endif
62826 }
62827
62828 p->nResColumn = 8 - 4*(p->explain-1);
62829 p->pResultSet = &p->aMem[1];
@@ -62740,11 +62842,11 @@
62842 const char *z = 0;
62843 if( p->zSql ){
62844 z = p->zSql;
62845 }else if( p->nOp>=1 ){
62846 const VdbeOp *pOp = &p->aOp[0];
62847 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
62848 z = pOp->p4.z;
62849 while( sqlite3Isspace(*z) ) z++;
62850 }
62851 }
62852 if( z ) printf("SQL: [%s]\n", z);
@@ -62759,11 +62861,11 @@
62861 int nOp = p->nOp;
62862 VdbeOp *pOp;
62863 if( sqlite3IoTrace==0 ) return;
62864 if( nOp<1 ) return;
62865 pOp = &p->aOp[0];
62866 if( pOp->opcode==OP_Init && pOp->p4.z!=0 ){
62867 int i, j;
62868 char z[1000];
62869 sqlite3_snprintf(sizeof(z), z, "%s", pOp->p4.z);
62870 for(i=0; sqlite3Isspace(z[i]); i++){}
62871 for(j=0; z[i]; i++){
@@ -62977,11 +63079,11 @@
63079 }
63080 if( p->aMem ){
63081 p->aMem--; /* aMem[] goes from 1..nMem */
63082 p->nMem = nMem; /* not from 0..nMem-1 */
63083 for(n=1; n<=nMem; n++){
63084 p->aMem[n].flags = MEM_Undefined;
63085 p->aMem[n].db = db;
63086 }
63087 }
63088 p->explain = pParse->explain;
63089 sqlite3VdbeRewind(p);
@@ -63089,11 +63191,11 @@
63191 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
63192 ** Vdbe.aMem[] arrays have already been cleaned up. */
63193 int i;
63194 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
63195 if( p->aMem ){
63196 for(i=1; i<=p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
63197 }
63198 #endif
63199
63200 sqlite3DbFree(db, p->zErrMsg);
63201 p->zErrMsg = 0;
@@ -63838,16 +63940,28 @@
63940 fprintf(out, "---- ");
63941 for(i=0; i<p->nOp; i++){
63942 fprintf(out, "%02x", p->aOp[i].opcode);
63943 }
63944 fprintf(out, "\n");
63945 if( p->zSql ){
63946 char c, pc = 0;
63947 fprintf(out, "-- ");
63948 for(i=0; (c = p->zSql[i])!=0; i++){
63949 if( pc=='\n' ) fprintf(out, "-- ");
63950 putc(c, out);
63951 pc = c;
63952 }
63953 if( pc!='\n' ) fprintf(out, "\n");
63954 }
63955 for(i=0; i<p->nOp; i++){
63956 char zHdr[100];
63957 sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
63958 p->aOp[i].cnt,
63959 p->aOp[i].cycles,
63960 p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
63961 );
63962 fprintf(out, "%s", zHdr);
63963 sqlite3VdbePrintOp(out, i, &p->aOp[i]);
63964 }
63965 fclose(out);
63966 }
63967 }
@@ -64880,11 +64994,45 @@
64994 SQLITE_API const void *sqlite3_value_text16le(sqlite3_value *pVal){
64995 return sqlite3ValueText(pVal, SQLITE_UTF16LE);
64996 }
64997 #endif /* SQLITE_OMIT_UTF16 */
64998 SQLITE_API int sqlite3_value_type(sqlite3_value* pVal){
64999 static const u8 aType[] = {
65000 SQLITE_BLOB, /* 0x00 */
65001 SQLITE_NULL, /* 0x01 */
65002 SQLITE_TEXT, /* 0x02 */
65003 SQLITE_NULL, /* 0x03 */
65004 SQLITE_INTEGER, /* 0x04 */
65005 SQLITE_NULL, /* 0x05 */
65006 SQLITE_INTEGER, /* 0x06 */
65007 SQLITE_NULL, /* 0x07 */
65008 SQLITE_FLOAT, /* 0x08 */
65009 SQLITE_NULL, /* 0x09 */
65010 SQLITE_FLOAT, /* 0x0a */
65011 SQLITE_NULL, /* 0x0b */
65012 SQLITE_INTEGER, /* 0x0c */
65013 SQLITE_NULL, /* 0x0d */
65014 SQLITE_INTEGER, /* 0x0e */
65015 SQLITE_NULL, /* 0x0f */
65016 SQLITE_BLOB, /* 0x10 */
65017 SQLITE_NULL, /* 0x11 */
65018 SQLITE_TEXT, /* 0x12 */
65019 SQLITE_NULL, /* 0x13 */
65020 SQLITE_INTEGER, /* 0x14 */
65021 SQLITE_NULL, /* 0x15 */
65022 SQLITE_INTEGER, /* 0x16 */
65023 SQLITE_NULL, /* 0x17 */
65024 SQLITE_FLOAT, /* 0x18 */
65025 SQLITE_NULL, /* 0x19 */
65026 SQLITE_FLOAT, /* 0x1a */
65027 SQLITE_NULL, /* 0x1b */
65028 SQLITE_INTEGER, /* 0x1c */
65029 SQLITE_NULL, /* 0x1d */
65030 SQLITE_INTEGER, /* 0x1e */
65031 SQLITE_NULL, /* 0x1f */
65032 };
65033 return aType[pVal->memType&0x1f];
65034 }
65035
65036 /**************************** sqlite3_result_ *******************************
65037 ** The following routines are used by user-defined functions to specify
65038 ** the function result.
@@ -65839,11 +65987,11 @@
65987 return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
65988 }
65989 #endif /* SQLITE_OMIT_UTF16 */
65990 SQLITE_API int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
65991 int rc;
65992 switch( sqlite3_value_type((sqlite3_value*)pValue) ){
65993 case SQLITE_INTEGER: {
65994 rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
65995 break;
65996 }
65997 case SQLITE_FLOAT: {
@@ -66340,37 +66488,12 @@
66488 ** May you do good and not evil.
66489 ** May you find forgiveness for yourself and forgive others.
66490 ** May you share freely, never taking more than you give.
66491 **
66492 *************************************************************************
66493 ** The code in this file implements the function that runs the
66494 ** bytecode of a prepared statement.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66495 **
66496 ** Various scripts scan this source file in order to generate HTML
66497 ** documentation, headers files, or other derived files. The formatting
66498 ** of the code in this file is, therefore, important. See other comments
66499 ** in this file for details. If in doubt, do not deviate from existing
@@ -66378,11 +66501,15 @@
66501 */
66502
66503 /*
66504 ** Invoke this macro on memory cells just prior to changing the
66505 ** value of the cell. This macro verifies that shallow copies are
66506 ** not misused. A shallow copy of a string or blob just copies a
66507 ** pointer to the string or blob, not the content. If the original
66508 ** is changed while the copy is still in use, the string or blob might
66509 ** be changed out from under the copy. This macro verifies that nothing
66510 ** like that every happens.
66511 */
66512 #ifdef SQLITE_DEBUG
66513 # define memAboutToChange(P,M) sqlite3VdbeMemAboutToChange(P,M)
66514 #else
66515 # define memAboutToChange(P,M)
@@ -66437,11 +66564,11 @@
66564 }
66565 }
66566 #endif
66567
66568 /*
66569 ** The next global variable is incremented each time the OP_Found opcode
66570 ** is executed. This is used to test whether or not the foreign key
66571 ** operation implemented using OP_FkIsZero is working. This variable
66572 ** has no function other than to help verify the correct operation of the
66573 ** library.
66574 */
@@ -66457,10 +66584,38 @@
66584 # define UPDATE_MAX_BLOBSIZE(P) updateMaxBlobsize(P)
66585 #else
66586 # define UPDATE_MAX_BLOBSIZE(P)
66587 #endif
66588
66589 /*
66590 ** Invoke the VDBE coverage callback, if that callback is defined. This
66591 ** feature is used for test suite validation only and does not appear an
66592 ** production builds.
66593 **
66594 ** M is an integer, 2 or 3, that indices how many different ways the
66595 ** branch can go. It is usually 2. "I" is the direction the branch
66596 ** goes. 0 means falls through. 1 means branch is taken. 2 means the
66597 ** second alternative branch is taken.
66598 */
66599 #if !defined(SQLITE_VDBE_COVERAGE)
66600 # define VdbeBranchTaken(I,M)
66601 #else
66602 # define VdbeBranchTaken(I,M) vdbeTakeBranch(pOp->iSrcLine,I,M)
66603 static void vdbeTakeBranch(int iSrcLine, u8 I, u8 M){
66604 if( iSrcLine<=2 && ALWAYS(iSrcLine>0) ){
66605 M = iSrcLine;
66606 /* Assert the truth of VdbeCoverageAlwaysTaken() and
66607 ** VdbeCoverageNeverTaken() */
66608 assert( (M & I)==I );
66609 }else{
66610 if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
66611 sqlite3GlobalConfig.xVdbeBranch(sqlite3GlobalConfig.pVdbeBranchArg,
66612 iSrcLine,I,M);
66613 }
66614 }
66615 #endif
66616
66617 /*
66618 ** Convert the given register into a string if it isn't one
66619 ** already. Return non-zero if a malloc() fails.
66620 */
66621 #define Stringify(P, enc) \
@@ -66481,35 +66636,11 @@
66636 #define Deephemeralize(P) \
66637 if( ((P)->flags&MEM_Ephem)!=0 \
66638 && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;}
66639
66640 /* Return true if the cursor was opened using the OP_OpenSorter opcode. */
66641 #define isSorter(x) ((x)->pSorter!=0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66642
66643 /*
66644 ** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
66645 ** if we run out of memory.
66646 */
@@ -66635,16 +66766,18 @@
66766 ** into a numeric representation. Use either INTEGER or REAL whichever
66767 ** is appropriate. But only do the conversion if it is possible without
66768 ** loss of information and return the revised type of the argument.
66769 */
66770 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value *pVal){
66771 int eType = sqlite3_value_type(pVal);
66772 if( eType==SQLITE_TEXT ){
66773 Mem *pMem = (Mem*)pVal;
66774 applyNumericAffinity(pMem);
66775 sqlite3VdbeMemStoreType(pMem);
66776 eType = sqlite3_value_type(pVal);
66777 }
66778 return eType;
66779 }
66780
66781 /*
66782 ** Exported version of applyAffinity(). This one works on sqlite3_value*,
66783 ** not the internal Mem* type.
@@ -66743,11 +66876,11 @@
66876 #ifdef SQLITE_DEBUG
66877 /*
66878 ** Print the value of a register for tracing purposes:
66879 */
66880 static void memTracePrint(Mem *p){
66881 if( p->flags & MEM_Undefined ){
66882 printf(" undefined");
66883 }else if( p->flags & MEM_Null ){
66884 printf(" NULL");
66885 }else if( (p->flags & (MEM_Int|MEM_Str))==(MEM_Int|MEM_Str) ){
66886 printf(" si:%lld", p->u.i);
@@ -66875,24 +67008,10 @@
67008
67009 /************** End of hwtime.h **********************************************/
67010 /************** Continuing where we left off in vdbe.c ***********************/
67011
67012 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67013
67014 #ifndef NDEBUG
67015 /*
67016 ** This function is only called from within an assert() expression. It
67017 ** checks that the sqlite3.nTransaction variable is correctly set to
@@ -66912,39 +67031,12 @@
67031 }
67032 #endif
67033
67034
67035 /*
67036 ** Execute as much of a VDBE program as we can.
67037 ** This is the core of sqlite3_step().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67038 */
67039 SQLITE_PRIVATE int sqlite3VdbeExec(
67040 Vdbe *p /* The VDBE */
67041 ){
67042 int pc=0; /* The program counter */
@@ -66966,11 +67058,10 @@
67058 Mem *pOut = 0; /* Output operand */
67059 int *aPermute = 0; /* Permutation of columns for OP_Compare */
67060 i64 lastRowid = db->lastRowid; /* Saved value of the last insert ROWID */
67061 #ifdef VDBE_PROFILE
67062 u64 start; /* CPU clock count at start of opcode */
 
67063 #endif
67064 /*** INSERT STACK UNION HERE ***/
67065
67066 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
67067 sqlite3VdbeEnter(p);
@@ -66984,11 +67075,11 @@
67075 p->rc = SQLITE_OK;
67076 p->iCurrentTime = 0;
67077 assert( p->explain==0 );
67078 p->pResultSet = 0;
67079 db->busyHandler.nBusy = 0;
67080 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
67081 sqlite3VdbeIOTraceSql(p);
67082 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67083 if( db->xProgress ){
67084 assert( 0 < db->nProgressOps );
67085 nProgressLimit = (unsigned)p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
@@ -67028,11 +67119,10 @@
67119 #endif
67120 for(pc=p->pc; rc==SQLITE_OK; pc++){
67121 assert( pc>=0 && pc<p->nOp );
67122 if( db->mallocFailed ) goto no_mem;
67123 #ifdef VDBE_PROFILE
 
67124 start = sqlite3Hwtime();
67125 #endif
67126 nVmStep++;
67127 pOp = &aOp[pc];
67128
@@ -67160,11 +67250,11 @@
67250 ** But that is not due to sloppy coding habits. The code is written this
67251 ** way for performance, to avoid having to run the interrupt and progress
67252 ** checks on every opcode. This helps sqlite3_step() to run about 1.5%
67253 ** faster according to "valgrind --tool=cachegrind" */
67254 check_for_interrupt:
67255 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
67256 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
67257 /* Call the progress callback if it is configured and the required number
67258 ** of VDBE ops have been executed (either since this invocation of
67259 ** sqlite3VdbeExec() or since last time the progress callback was called).
67260 ** If the progress callback returns non-zero, exit the virtual machine with
@@ -67200,24 +67290,70 @@
67290 break;
67291 }
67292
67293 /* Opcode: Return P1 * * * *
67294 **
67295 ** Jump to the next instruction after the address in register P1. After
67296 ** the jump, register P1 becomes undefined.
67297 */
67298 case OP_Return: { /* in1 */
67299 pIn1 = &aMem[pOp->p1];
67300 assert( pIn1->flags==MEM_Int );
67301 pc = (int)pIn1->u.i;
67302 pIn1->flags = MEM_Undefined;
67303 break;
67304 }
67305
67306 /* Opcode: InitCoroutine P1 P2 P3 * *
67307 **
67308 ** Set up register P1 so that it will OP_Yield to the co-routine
67309 ** located at address P3.
67310 **
67311 ** If P2!=0 then the co-routine implementation immediately follows
67312 ** this opcode. So jump over the co-routine implementation to
67313 ** address P2.
67314 */
67315 case OP_InitCoroutine: { /* jump */
67316 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67317 assert( pOp->p2>=0 && pOp->p2<p->nOp );
67318 assert( pOp->p3>=0 && pOp->p3<p->nOp );
67319 pOut = &aMem[pOp->p1];
67320 assert( !VdbeMemDynamic(pOut) );
67321 pOut->u.i = pOp->p3 - 1;
67322 pOut->flags = MEM_Int;
67323 if( pOp->p2 ) pc = pOp->p2 - 1;
67324 break;
67325 }
67326
67327 /* Opcode: EndCoroutine P1 * * * *
67328 **
67329 ** The instruction at the address in register P1 is an OP_Yield.
67330 ** Jump to the P2 parameter of that OP_Yield.
67331 ** After the jump, register P1 becomes undefined.
67332 */
67333 case OP_EndCoroutine: { /* in1 */
67334 VdbeOp *pCaller;
67335 pIn1 = &aMem[pOp->p1];
67336 assert( pIn1->flags==MEM_Int );
67337 assert( pIn1->u.i>=0 && pIn1->u.i<p->nOp );
67338 pCaller = &aOp[pIn1->u.i];
67339 assert( pCaller->opcode==OP_Yield );
67340 assert( pCaller->p2>=0 && pCaller->p2<p->nOp );
67341 pc = pCaller->p2 - 1;
67342 pIn1->flags = MEM_Undefined;
67343 break;
67344 }
67345
67346 /* Opcode: Yield P1 P2 * * *
67347 **
67348 ** Swap the program counter with the value in register P1.
67349 **
67350 ** If the co-routine ends with OP_Yield or OP_Return then continue
67351 ** to the next instruction. But if the co-routine ends with
67352 ** OP_EndCoroutine, jump immediately to P2.
67353 */
67354 case OP_Yield: { /* in1, jump */
67355 int pcDest;
67356 pIn1 = &aMem[pOp->p1];
67357 assert( (pIn1->flags & MEM_Dyn)==0 );
67358 pIn1->flags = MEM_Int;
67359 pcDest = (int)pIn1->u.i;
@@ -67226,11 +67362,11 @@
67362 pc = pcDest;
67363 break;
67364 }
67365
67366 /* Opcode: HaltIfNull P1 P2 P3 P4 P5
67367 ** Synopsis: if r[P3]=null halt
67368 **
67369 ** Check the value in register P3. If it is NULL then Halt using
67370 ** parameter P1, P2, and P4 as if this were a Halt instruction. If the
67371 ** value in register P3 is not NULL, then this routine is a no-op.
67372 ** The P5 parameter should be 1.
@@ -67374,11 +67510,13 @@
67510
67511 /* Opcode: String8 * P2 * P4 *
67512 ** Synopsis: r[P2]='P4'
67513 **
67514 ** P4 points to a nul terminated UTF-8 string. This opcode is transformed
67515 ** into an OP_String before it is executed for the first time. During
67516 ** this transformation, the length of string P4 is computed and stored
67517 ** as the P1 parameter.
67518 */
67519 case OP_String8: { /* same as TK_STRING, out2-prerelease */
67520 assert( pOp->p4.z!=0 );
67521 pOp->opcode = OP_String;
67522 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
@@ -67448,12 +67586,26 @@
67586 cnt--;
67587 }
67588 break;
67589 }
67590
67591 /* Opcode: SoftNull P1 * * * *
67592 ** Synopsis: r[P1]=NULL
67593 **
67594 ** Set register P1 to have the value NULL as seen by the OP_MakeRecord
67595 ** instruction, but do not free any string or blob memory associated with
67596 ** the register, so that if the value was a string or blob that was
67597 ** previously copied using OP_SCopy, the copies will continue to be valid.
67598 */
67599 case OP_SoftNull: {
67600 assert( pOp->p1>0 && pOp->p1<=(p->nMem-p->nCursor) );
67601 pOut = &aMem[pOp->p1];
67602 pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
67603 break;
67604 }
67605
67606 /* Opcode: Blob P1 P2 * P4 *
67607 ** Synopsis: r[P2]=P4 (len=P1)
67608 **
67609 ** P4 points to a blob of data P1 bytes long. Store this
67610 ** blob in register P2.
67611 */
@@ -67468,11 +67620,11 @@
67620 /* Opcode: Variable P1 P2 * P4 *
67621 ** Synopsis: r[P2]=parameter(P1,P4)
67622 **
67623 ** Transfer the values of bound parameter P1 into register P2
67624 **
67625 ** If the parameter is named, then its name appears in P4.
67626 ** The P4 value is used by sqlite3_bind_parameter_name().
67627 */
67628 case OP_Variable: { /* out2-prerelease */
67629 Mem *pVar; /* Value being transferred */
67630
@@ -67587,12 +67739,12 @@
67739 ** Synopsis: output=r[P1@P2]
67740 **
67741 ** The registers P1 through P1+P2-1 contain a single row of
67742 ** results. This opcode causes the sqlite3_step() call to terminate
67743 ** with an SQLITE_ROW return code and it sets up the sqlite3_stmt
67744 ** structure to provide access to the r(P1)..r(P1+P2-1) values as
67745 ** the result row.
67746 */
67747 case OP_ResultRow: {
67748 Mem *pMem;
67749 int i;
67750 assert( p->nResColumn==pOp->p2 );
@@ -68078,10 +68230,11 @@
68230 */
68231 case OP_MustBeInt: { /* jump, in1 */
68232 pIn1 = &aMem[pOp->p1];
68233 if( (pIn1->flags & MEM_Int)==0 ){
68234 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
68235 VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
68236 if( (pIn1->flags & MEM_Int)==0 ){
68237 if( pOp->p2==0 ){
68238 rc = SQLITE_MISMATCH;
68239 goto abort_due_to_error;
68240 }else{
@@ -68116,11 +68269,11 @@
68269 #ifndef SQLITE_OMIT_CAST
68270 /* Opcode: ToText P1 * * * *
68271 **
68272 ** Force the value in register P1 to be text.
68273 ** If the value is numeric, convert it to a string using the
68274 ** equivalent of sprintf(). Blob values are unchanged and
68275 ** are afterwards simply interpreted as text.
68276 **
68277 ** A NULL value is not changed by this routine. It remains NULL.
68278 */
68279 case OP_ToText: { /* same as TK_TO_TEXT, in1 */
@@ -68318,10 +68471,11 @@
68471 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
68472 ** or not both operands are null.
68473 */
68474 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
68475 assert( (flags1 & MEM_Cleared)==0 );
68476 assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 );
68477 if( (flags1&MEM_Null)!=0
68478 && (flags3&MEM_Null)!=0
68479 && (flags3&MEM_Cleared)==0
68480 ){
68481 res = 0; /* Results are equal */
@@ -68331,16 +68485,19 @@
68485 }else{
68486 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
68487 ** then the result is always NULL.
68488 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
68489 */
68490 if( pOp->p5 & SQLITE_STOREP2 ){
 
 
68491 pOut = &aMem[pOp->p2];
68492 MemSetTypeFlag(pOut, MEM_Null);
68493 REGISTER_TRACE(pOp->p2, pOut);
68494 }else{
68495 VdbeBranchTaken(2,3);
68496 if( pOp->p5 & SQLITE_JUMPIFNULL ){
68497 pc = pOp->p2-1;
68498 }
68499 }
68500 break;
68501 }
68502 }else{
68503 /* Neither operand is NULL. Do a comparison. */
@@ -68369,14 +68526,16 @@
68526 pOut = &aMem[pOp->p2];
68527 memAboutToChange(p, pOut);
68528 MemSetTypeFlag(pOut, MEM_Int);
68529 pOut->u.i = res;
68530 REGISTER_TRACE(pOp->p2, pOut);
68531 }else{
68532 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
68533 if( res ){
68534 pc = pOp->p2-1;
68535 }
68536 }
 
68537 /* Undo any changes made by applyAffinity() to the input registers. */
68538 pIn1->flags = (pIn1->flags&~MEM_TypeMask) | (flags1&MEM_TypeMask);
68539 pIn3->flags = (pIn3->flags&~MEM_TypeMask) | (flags3&MEM_TypeMask);
68540 break;
68541 }
@@ -68469,15 +68628,15 @@
68628 ** in the most recent OP_Compare instruction the P1 vector was less than
68629 ** equal to, or greater than the P2 vector, respectively.
68630 */
68631 case OP_Jump: { /* jump */
68632 if( iCompare<0 ){
68633 pc = pOp->p1 - 1; VdbeBranchTaken(0,3);
68634 }else if( iCompare==0 ){
68635 pc = pOp->p2 - 1; VdbeBranchTaken(1,3);
68636 }else{
68637 pc = pOp->p3 - 1; VdbeBranchTaken(2,3);
68638 }
68639 break;
68640 }
68641
68642 /* Opcode: And P1 P2 P3 * *
@@ -68571,14 +68730,17 @@
68730 }
68731
68732 /* Opcode: Once P1 P2 * * *
68733 **
68734 ** Check if OP_Once flag P1 is set. If so, jump to instruction P2. Otherwise,
68735 ** set the flag and fall through to the next instruction. In other words,
68736 ** this opcode causes all following up codes up through P2 (but not including
68737 ** P2) to run just once and skipped on subsequent times through the loop.
68738 */
68739 case OP_Once: { /* jump */
68740 assert( pOp->p1<p->nOnceFlag );
68741 VdbeBranchTaken(p->aOnceFlag[pOp->p1]!=0, 2);
68742 if( p->aOnceFlag[pOp->p1] ){
68743 pc = pOp->p2-1;
68744 }else{
68745 p->aOnceFlag[pOp->p1] = 1;
68746 }
@@ -68609,10 +68771,11 @@
68771 #else
68772 c = sqlite3VdbeRealValue(pIn1)!=0.0;
68773 #endif
68774 if( pOp->opcode==OP_IfNot ) c = !c;
68775 }
68776 VdbeBranchTaken(c!=0, 2);
68777 if( c ){
68778 pc = pOp->p2-1;
68779 }
68780 break;
68781 }
@@ -68622,10 +68785,11 @@
68785 **
68786 ** Jump to P2 if the value in register P1 is NULL.
68787 */
68788 case OP_IsNull: { /* same as TK_ISNULL, jump, in1 */
68789 pIn1 = &aMem[pOp->p1];
68790 VdbeBranchTaken( (pIn1->flags & MEM_Null)!=0, 2);
68791 if( (pIn1->flags & MEM_Null)!=0 ){
68792 pc = pOp->p2 - 1;
68793 }
68794 break;
68795 }
@@ -68635,10 +68799,11 @@
68799 **
68800 ** Jump to P2 if the value in register P1 is not NULL.
68801 */
68802 case OP_NotNull: { /* same as TK_NOTNULL, jump, in1 */
68803 pIn1 = &aMem[pOp->p1];
68804 VdbeBranchTaken( (pIn1->flags & MEM_Null)==0, 2);
68805 if( (pIn1->flags & MEM_Null)==0 ){
68806 pc = pOp->p2 - 1;
68807 }
68808 break;
68809 }
@@ -68711,15 +68876,10 @@
68876 if( pC->cacheStatus!=p->cacheCtr || (pOp->p5&OPFLAG_CLEARCACHE)!=0 ){
68877 if( pC->nullRow ){
68878 if( pCrsr==0 ){
68879 assert( pC->pseudoTableReg>0 );
68880 pReg = &aMem[pC->pseudoTableReg];
 
 
 
 
 
68881 assert( pReg->flags & MEM_Blob );
68882 assert( memIsValid(pReg) );
68883 pC->payloadSize = pC->szRow = avail = pReg->n;
68884 pC->aRow = (u8*)pReg->z;
68885 }else{
@@ -68941,11 +69101,10 @@
69101 assert( zAffinity[pOp->p2]==0 );
69102 pIn1 = &aMem[pOp->p1];
69103 while( (cAff = *(zAffinity++))!=0 ){
69104 assert( pIn1 <= &p->aMem[(p->nMem-p->nCursor)] );
69105 assert( memIsValid(pIn1) );
 
69106 applyAffinity(pIn1, cAff, encoding);
69107 pIn1++;
69108 }
69109 break;
69110 }
@@ -69019,12 +69178,13 @@
69178 */
69179 assert( pData0<=pLast );
69180 if( zAffinity ){
69181 pRec = pData0;
69182 do{
69183 applyAffinity(pRec++, *(zAffinity++), encoding);
69184 assert( zAffinity[0]==0 || pRec<=pLast );
69185 }while( zAffinity[0] );
69186 }
69187
69188 /* Loop through the elements that will make up the record to figure
69189 ** out how much space is required for the new record.
69190 */
@@ -69364,29 +69524,23 @@
69524 rc = SQLITE_ERROR;
69525 }
69526 break;
69527 }
69528
69529 /* Opcode: Transaction P1 P2 P3 P4 P5
69530 **
69531 ** Begin a transaction on database P1 if a transaction is not already
69532 ** active.
69533 ** If P2 is non-zero, then a write-transaction is started, or if a
69534 ** read-transaction is already active, it is upgraded to a write-transaction.
69535 ** If P2 is zero, then a read-transaction is started.
69536 **
69537 ** P1 is the index of the database file on which the transaction is
69538 ** started. Index 0 is the main database file and index 1 is the
69539 ** file used for temporary tables. Indices of 2 or more are used for
69540 ** attached databases.
69541 **
 
 
 
 
 
 
 
 
69542 ** If a write-transaction is started and the Vdbe.usesStmtJournal flag is
69543 ** true (this flag is set if the Vdbe may modify more than one row and may
69544 ** throw an ABORT exception), a statement transaction may also be opened.
69545 ** More specifically, a statement transaction is opened iff the database
69546 ** connection is currently not in autocommit mode, or if there are other
@@ -69393,14 +69547,25 @@
69547 ** active statements. A statement transaction allows the changes made by this
69548 ** VDBE to be rolled back after an error without having to roll back the
69549 ** entire transaction. If no error is encountered, the statement transaction
69550 ** will automatically commit when the VDBE halts.
69551 **
69552 ** If P5!=0 then this opcode also checks the schema cookie against P3
69553 ** and the schema generation counter against P4.
69554 ** The cookie changes its value whenever the database schema changes.
69555 ** This operation is used to detect when that the cookie has changed
69556 ** and that the current process needs to reread the schema. If the schema
69557 ** cookie in P3 differs from the schema cookie in the database header or
69558 ** if the schema generation counter in P4 differs from the current
69559 ** generation counter, then an SQLITE_SCHEMA error is raised and execution
69560 ** halts. The sqlite3_step() wrapper function might then reprepare the
69561 ** statement and rerun it from the beginning.
69562 */
69563 case OP_Transaction: {
69564 Btree *pBt;
69565 int iMeta;
69566 int iGen;
69567
69568 assert( p->bIsReader );
69569 assert( p->readOnly==0 || pOp->p2==0 );
69570 assert( pOp->p1>=0 && pOp->p1<db->nDb );
69571 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
@@ -69440,10 +69605,39 @@
69605 ** counter. If the statement transaction needs to be rolled back,
69606 ** the value of this counter needs to be restored too. */
69607 p->nStmtDefCons = db->nDeferredCons;
69608 p->nStmtDefImmCons = db->nDeferredImmCons;
69609 }
69610
69611 /* Gather the schema version number for checking */
69612 sqlite3BtreeGetMeta(pBt, BTREE_SCHEMA_VERSION, (u32 *)&iMeta);
69613 iGen = db->aDb[pOp->p1].pSchema->iGeneration;
69614 }else{
69615 iGen = iMeta = 0;
69616 }
69617 assert( pOp->p5==0 || pOp->p4type==P4_INT32 );
69618 if( pOp->p5 && (iMeta!=pOp->p3 || iGen!=pOp->p4.i) ){
69619 sqlite3DbFree(db, p->zErrMsg);
69620 p->zErrMsg = sqlite3DbStrDup(db, "database schema has changed");
69621 /* If the schema-cookie from the database file matches the cookie
69622 ** stored with the in-memory representation of the schema, do
69623 ** not reload the schema from the database file.
69624 **
69625 ** If virtual-tables are in use, this is not just an optimization.
69626 ** Often, v-tables store their data in other SQLite tables, which
69627 ** are queried from within xNext() and other v-table methods using
69628 ** prepared queries. If such a query is out-of-date, we do not want to
69629 ** discard the database schema, as the user code implementing the
69630 ** v-table would have to be ready for the sqlite3_vtab structure itself
69631 ** to be invalidated whenever sqlite3_step() is called from within
69632 ** a v-table method.
69633 */
69634 if( db->aDb[pOp->p1].pSchema->schema_cookie!=iMeta ){
69635 sqlite3ResetOneSchema(db, pOp->p1);
69636 }
69637 p->expired = 1;
69638 rc = SQLITE_SCHEMA;
69639 }
69640 break;
69641 }
69642
69643 /* Opcode: ReadCookie P1 P2 P3 * *
@@ -69511,70 +69705,10 @@
69705 /* Invalidate all prepared statements whenever the TEMP database
69706 ** schema is changed. Ticket #1644 */
69707 sqlite3ExpirePreparedStatements(db);
69708 p->expired = 0;
69709 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69710 break;
69711 }
69712
69713 /* Opcode: OpenRead P1 P2 P3 P4 P5
69714 ** Synopsis: root=P2 iDb=P3
@@ -69787,11 +69921,11 @@
69921 }
69922 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69923 break;
69924 }
69925
69926 /* Opcode: SorterOpen P1 P2 * P4 *
69927 **
69928 ** This opcode works like OP_OpenEphemeral except that it opens
69929 ** a transient index that is specifically designed to sort large
69930 ** tables using an external merge-sort algorithm.
69931 */
@@ -69807,18 +69941,17 @@
69941 assert( pCx->pKeyInfo->enc==ENC(db) );
69942 rc = sqlite3VdbeSorterInit(db, pCx);
69943 break;
69944 }
69945
69946 /* Opcode: OpenPseudo P1 P2 P3 * *
69947 ** Synopsis: P3 columns in r[P2]
69948 **
69949 ** Open a new cursor that points to a fake table that contains a single
69950 ** row of data. The content of that one row is the content of memory
69951 ** register P2. In other words, cursor P1 becomes an alias for the
69952 ** MEM_Blob content contained in register P2.
 
69953 **
69954 ** A pseudo-table created by this opcode is used to hold a single
69955 ** row output from the sorter so that the row can be decomposed into
69956 ** individual columns using the OP_Column opcode. The OP_Column opcode
69957 ** is the only cursor opcode that works with a pseudo-table.
@@ -69834,11 +69967,11 @@
69967 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0);
69968 if( pCx==0 ) goto no_mem;
69969 pCx->nullRow = 1;
69970 pCx->pseudoTableReg = pOp->p2;
69971 pCx->isTable = 1;
69972 assert( pOp->p5==0 );
69973 break;
69974 }
69975
69976 /* Opcode: Close P1 * * * *
69977 **
@@ -69906,14 +70039,14 @@
70039 ** is less than or equal to the key value. If there are no records
70040 ** less than or equal to the key and P2 is not zero, then jump to P2.
70041 **
70042 ** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt
70043 */
70044 case OP_SeekLT: /* jump, in3 */
70045 case OP_SeekLE: /* jump, in3 */
70046 case OP_SeekGE: /* jump, in3 */
70047 case OP_SeekGT: { /* jump, in3 */
70048 int res;
70049 int oc;
70050 VdbeCursor *pC;
70051 UnpackedRecord r;
70052 int nField;
@@ -69922,13 +70055,13 @@
70055 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
70056 assert( pOp->p2!=0 );
70057 pC = p->apCsr[pOp->p1];
70058 assert( pC!=0 );
70059 assert( pC->pseudoTableReg==0 );
70060 assert( OP_SeekLE == OP_SeekLT+1 );
70061 assert( OP_SeekGE == OP_SeekLT+2 );
70062 assert( OP_SeekGT == OP_SeekLT+3 );
70063 assert( pC->isOrdered );
70064 assert( pC->pCursor!=0 );
70065 oc = pOp->opcode;
70066 pC->nullRow = 0;
70067 if( pC->isTable ){
@@ -69944,11 +70077,11 @@
70077 ** loss of information, then special processing is required... */
70078 if( (pIn3->flags & MEM_Int)==0 ){
70079 if( (pIn3->flags & MEM_Real)==0 ){
70080 /* If the P3 value cannot be converted into any kind of a number,
70081 ** then the seek is not possible, so jump to P2 */
70082 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
70083 break;
70084 }
70085
70086 /* If the approximation iKey is larger than the actual real search
70087 ** term, substitute >= for > and < for <=. e.g. if the search term
@@ -69956,23 +70089,23 @@
70089 **
70090 ** (x > 4.9) -> (x >= 5)
70091 ** (x <= 4.9) -> (x < 5)
70092 */
70093 if( pIn3->r<(double)iKey ){
70094 assert( OP_SeekGE==(OP_SeekGT-1) );
70095 assert( OP_SeekLT==(OP_SeekLE-1) );
70096 assert( (OP_SeekLE & 0x0001)==(OP_SeekGT & 0x0001) );
70097 if( (oc & 0x0001)==(OP_SeekGT & 0x0001) ) oc--;
70098 }
70099
70100 /* If the approximation iKey is smaller than the actual real search
70101 ** term, substitute <= for < and > for >=. */
70102 else if( pIn3->r>(double)iKey ){
70103 assert( OP_SeekLE==(OP_SeekLT+1) );
70104 assert( OP_SeekGT==(OP_SeekGE+1) );
70105 assert( (OP_SeekLT & 0x0001)==(OP_SeekGE & 0x0001) );
70106 if( (oc & 0x0001)==(OP_SeekLT & 0x0001) ) oc++;
70107 }
70108 }
70109 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res);
70110 if( rc!=SQLITE_OK ){
70111 goto abort_due_to_error;
@@ -69987,21 +70120,21 @@
70120 assert( nField>0 );
70121 r.pKeyInfo = pC->pKeyInfo;
70122 r.nField = (u16)nField;
70123
70124 /* The next line of code computes as follows, only faster:
70125 ** if( oc==OP_SeekGT || oc==OP_SeekLE ){
70126 ** r.flags = UNPACKED_INCRKEY;
70127 ** }else{
70128 ** r.flags = 0;
70129 ** }
70130 */
70131 r.flags = (u8)(UNPACKED_INCRKEY * (1 & (oc - OP_SeekLT)));
70132 assert( oc!=OP_SeekGT || r.flags==UNPACKED_INCRKEY );
70133 assert( oc!=OP_SeekLE || r.flags==UNPACKED_INCRKEY );
70134 assert( oc!=OP_SeekGE || r.flags==0 );
70135 assert( oc!=OP_SeekLT || r.flags==0 );
70136
70137 r.aMem = &aMem[pOp->p3];
70138 #ifdef SQLITE_DEBUG
70139 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
70140 #endif
@@ -70015,21 +70148,23 @@
70148 pC->deferredMoveto = 0;
70149 pC->cacheStatus = CACHE_STALE;
70150 #ifdef SQLITE_TEST
70151 sqlite3_search_count++;
70152 #endif
70153 if( oc>=OP_SeekGE ){ assert( oc==OP_SeekGE || oc==OP_SeekGT );
70154 if( res<0 || (res==0 && oc==OP_SeekGT) ){
70155 res = 0;
70156 rc = sqlite3BtreeNext(pC->pCursor, &res);
70157 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70158 pC->rowidIsValid = 0;
70159 }else{
70160 res = 0;
70161 }
70162 }else{
70163 assert( oc==OP_SeekLT || oc==OP_SeekLE );
70164 if( res>0 || (res==0 && oc==OP_SeekLT) ){
70165 res = 0;
70166 rc = sqlite3BtreePrevious(pC->pCursor, &res);
70167 if( rc!=SQLITE_OK ) goto abort_due_to_error;
70168 pC->rowidIsValid = 0;
70169 }else{
70170 /* res might be negative because the table is empty. Check to
@@ -70037,10 +70172,11 @@
70172 */
70173 res = sqlite3BtreeEof(pC->pCursor);
70174 }
70175 }
70176 assert( pOp->p2>0 );
70177 VdbeBranchTaken(res!=0,2);
70178 if( res ){
70179 pc = pOp->p2 - 1;
70180 }
70181 break;
70182 }
@@ -70145,19 +70281,17 @@
70281 pFree = 0; /* Not needed. Only used to suppress a compiler warning. */
70282 if( pOp->p4.i>0 ){
70283 r.pKeyInfo = pC->pKeyInfo;
70284 r.nField = (u16)pOp->p4.i;
70285 r.aMem = pIn3;
70286 for(ii=0; ii<r.nField; ii++){
70287 assert( memIsValid(&r.aMem[ii]) );
70288 ExpandBlob(&r.aMem[ii]);
70289 #ifdef SQLITE_DEBUG
70290 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
70291 #endif
70292 }
 
 
 
 
 
70293 r.flags = UNPACKED_PREFIX_MATCH;
70294 pIdxKey = &r;
70295 }else{
70296 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
70297 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
@@ -70172,11 +70306,11 @@
70306 /* For the OP_NoConflict opcode, take the jump if any of the
70307 ** input fields are NULL, since any key with a NULL will not
70308 ** conflict */
70309 for(ii=0; ii<r.nField; ii++){
70310 if( r.aMem[ii].flags & MEM_Null ){
70311 pc = pOp->p2 - 1; VdbeBranchTaken(1,2);
70312 break;
70313 }
70314 }
70315 }
70316 rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, pIdxKey, 0, 0, &res);
@@ -70190,12 +70324,14 @@
70324 alreadyExists = (res==0);
70325 pC->nullRow = 1-alreadyExists;
70326 pC->deferredMoveto = 0;
70327 pC->cacheStatus = CACHE_STALE;
70328 if( pOp->opcode==OP_Found ){
70329 VdbeBranchTaken(alreadyExists!=0,2);
70330 if( alreadyExists ) pc = pOp->p2 - 1;
70331 }else{
70332 VdbeBranchTaken(alreadyExists==0,2);
70333 if( !alreadyExists ) pc = pOp->p2 - 1;
70334 }
70335 break;
70336 }
70337
@@ -70234,10 +70370,11 @@
70370 pC->lastRowid = pIn3->u.i;
70371 pC->rowidIsValid = res==0 ?1:0;
70372 pC->nullRow = 0;
70373 pC->cacheStatus = CACHE_STALE;
70374 pC->deferredMoveto = 0;
70375 VdbeBranchTaken(res!=0,2);
70376 if( res!=0 ){
70377 pc = pOp->p2 - 1;
70378 assert( pC->rowidIsValid==0 );
70379 }
70380 pC->seekResult = res;
@@ -70315,63 +70452,58 @@
70452 */
70453 # define MAX_ROWID (i64)( (((u64)0x7fffffff)<<32) | (u64)0xffffffff )
70454 #endif
70455
70456 if( !pC->useRandomRowid ){
70457 rc = sqlite3BtreeLast(pC->pCursor, &res);
70458 if( rc!=SQLITE_OK ){
70459 goto abort_due_to_error;
70460 }
70461 if( res ){
70462 v = 1; /* IMP: R-61914-48074 */
70463 }else{
70464 assert( sqlite3BtreeCursorIsValid(pC->pCursor) );
70465 rc = sqlite3BtreeKeySize(pC->pCursor, &v);
70466 assert( rc==SQLITE_OK ); /* Cannot fail following BtreeLast() */
70467 if( v>=MAX_ROWID ){
70468 pC->useRandomRowid = 1;
70469 }else{
70470 v++; /* IMP: R-29538-34987 */
70471 }
70472 }
70473 }
70474
70475 #ifndef SQLITE_OMIT_AUTOINCREMENT
70476 if( pOp->p3 ){
70477 /* Assert that P3 is a valid memory cell. */
70478 assert( pOp->p3>0 );
70479 if( p->pFrame ){
70480 for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
70481 /* Assert that P3 is a valid memory cell. */
70482 assert( pOp->p3<=pFrame->nMem );
70483 pMem = &pFrame->aMem[pOp->p3];
70484 }else{
70485 /* Assert that P3 is a valid memory cell. */
70486 assert( pOp->p3<=(p->nMem-p->nCursor) );
70487 pMem = &aMem[pOp->p3];
70488 memAboutToChange(p, pMem);
70489 }
70490 assert( memIsValid(pMem) );
70491
70492 REGISTER_TRACE(pOp->p3, pMem);
70493 sqlite3VdbeMemIntegerify(pMem);
70494 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
70495 if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
70496 rc = SQLITE_FULL; /* IMP: R-12275-61338 */
70497 goto abort_due_to_error;
70498 }
70499 if( v<pMem->u.i+1 ){
70500 v = pMem->u.i + 1;
70501 }
70502 pMem->u.i = v;
70503 }
70504 #endif
 
 
 
 
 
70505 if( pC->useRandomRowid ){
70506 /* IMPLEMENTATION-OF: R-07677-41881 If the largest ROWID is equal to the
70507 ** largest possible integer (9223372036854775807) then the database
70508 ** engine starts picking positive candidate ROWIDs at random until
70509 ** it finds one that is not previously used. */
@@ -70501,11 +70633,10 @@
70633 if( pData->flags & MEM_Zero ){
70634 nZero = pData->u.nZero;
70635 }else{
70636 nZero = 0;
70637 }
 
70638 rc = sqlite3BtreeInsert(pC->pCursor, 0, iKey,
70639 pData->z, pData->n, nZero,
70640 (pOp->p5 & OPFLAG_APPEND)!=0, seekResult
70641 );
70642 pC->rowidIsValid = 0;
@@ -70563,11 +70694,10 @@
70694 **/
70695 assert( pC->deferredMoveto==0 );
70696 rc = sqlite3VdbeCursorMoveto(pC);
70697 if( NEVER(rc!=SQLITE_OK) ) goto abort_due_to_error;
70698
 
70699 rc = sqlite3BtreeDelete(pC->pCursor);
70700 pC->cacheStatus = CACHE_STALE;
70701
70702 /* Invoke the update-hook if required. */
70703 if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){
@@ -70615,10 +70745,11 @@
70745 assert( isSorter(pC) );
70746 assert( pOp->p4type==P4_INT32 );
70747 pIn3 = &aMem[pOp->p3];
70748 nIgnore = pOp->p4.i;
70749 rc = sqlite3VdbeSorterCompare(pC, pIn3, nIgnore, &res);
70750 VdbeBranchTaken(res!=0,2);
70751 if( res ){
70752 pc = pOp->p2-1;
70753 }
70754 break;
70755 };
@@ -70652,11 +70783,11 @@
70783 /* Opcode: RowKey P1 P2 * * *
70784 ** Synopsis: r[P2]=key
70785 **
70786 ** Write into register P2 the complete row key for cursor P1.
70787 ** There is no interpretation of the data.
70788 ** The key is copied onto the P2 register exactly as
70789 ** it is found in the database file.
70790 **
70791 ** If the P1 cursor must be pointing to a valid row (not a NULL row)
70792 ** of a real table, not a pseudo-table.
70793 */
@@ -70814,12 +70945,13 @@
70945 rc = sqlite3BtreeLast(pCrsr, &res);
70946 pC->nullRow = (u8)res;
70947 pC->deferredMoveto = 0;
70948 pC->rowidIsValid = 0;
70949 pC->cacheStatus = CACHE_STALE;
70950 if( pOp->p2>0 ){
70951 VdbeBranchTaken(res!=0,2);
70952 if( res ) pc = pOp->p2 - 1;
70953 }
70954 break;
70955 }
70956
70957
@@ -70872,56 +71004,67 @@
71004 pC->cacheStatus = CACHE_STALE;
71005 pC->rowidIsValid = 0;
71006 }
71007 pC->nullRow = (u8)res;
71008 assert( pOp->p2>0 && pOp->p2<p->nOp );
71009 VdbeBranchTaken(res!=0,2);
71010 if( res ){
71011 pc = pOp->p2 - 1;
71012 }
71013 break;
71014 }
71015
71016 /* Opcode: Next P1 P2 P3 P4 P5
71017 **
71018 ** Advance cursor P1 so that it points to the next key/data pair in its
71019 ** table or index. If there are no more key/value pairs then fall through
71020 ** to the following instruction. But if the cursor advance was successful,
71021 ** jump immediately to P2.
71022 **
71023 ** The P1 cursor must be for a real table, not a pseudo-table. P1 must have
71024 ** been opened prior to this opcode or the program will segfault.
71025 **
71026 ** The P3 value is a hint to the btree implementation. If P3==1, that
71027 ** means P1 is an SQL index and that this instruction could have been
71028 ** omitted if that index had been unique. P3 is usually 0. P3 is
71029 ** always either 0 or 1.
71030 **
71031 ** P4 is always of type P4_ADVANCE. The function pointer points to
71032 ** sqlite3BtreeNext().
71033 **
71034 ** If P5 is positive and the jump is taken, then event counter
71035 ** number P5-1 in the prepared statement is incremented.
71036 **
71037 ** See also: Prev, NextIfOpen
71038 */
71039 /* Opcode: NextIfOpen P1 P2 P3 P4 P5
71040 **
71041 ** This opcode works just like OP_Next except that if cursor P1 is not
71042 ** open it behaves a no-op.
71043 */
71044 /* Opcode: Prev P1 P2 P3 P4 P5
71045 **
71046 ** Back up cursor P1 so that it points to the previous key/data pair in its
71047 ** table or index. If there is no previous key/value pairs then fall through
71048 ** to the following instruction. But if the cursor backup was successful,
71049 ** jump immediately to P2.
71050 **
71051 ** The P1 cursor must be for a real table, not a pseudo-table. If P1 is
71052 ** not open then the behavior is undefined.
71053 **
71054 ** The P3 value is a hint to the btree implementation. If P3==1, that
71055 ** means P1 is an SQL index and that this instruction could have been
71056 ** omitted if that index had been unique. P3 is usually 0. P3 is
71057 ** always either 0 or 1.
71058 **
71059 ** P4 is always of type P4_ADVANCE. The function pointer points to
71060 ** sqlite3BtreePrevious().
71061 **
71062 ** If P5 is positive and the jump is taken, then event counter
71063 ** number P5-1 in the prepared statement is incremented.
71064 */
71065 /* Opcode: PrevIfOpen P1 P2 P3 P4 P5
71066 **
71067 ** This opcode works just like OP_Prev except that if cursor P1 is not
71068 ** open it behaves a no-op.
71069 */
71070 case OP_SorterNext: { /* jump */
@@ -70939,20 +71082,24 @@
71082 case OP_Prev: /* jump */
71083 case OP_Next: /* jump */
71084 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
71085 assert( pOp->p5<ArraySize(p->aCounter) );
71086 pC = p->apCsr[pOp->p1];
71087 res = pOp->p3;
71088 assert( pC!=0 );
71089 assert( pC->deferredMoveto==0 );
71090 assert( pC->pCursor );
71091 assert( res==0 || (res==1 && pC->isTable==0) );
71092 testcase( res==1 );
71093 assert( pOp->opcode!=OP_Next || pOp->p4.xAdvance==sqlite3BtreeNext );
71094 assert( pOp->opcode!=OP_Prev || pOp->p4.xAdvance==sqlite3BtreePrevious );
71095 assert( pOp->opcode!=OP_NextIfOpen || pOp->p4.xAdvance==sqlite3BtreeNext );
71096 assert( pOp->opcode!=OP_PrevIfOpen || pOp->p4.xAdvance==sqlite3BtreePrevious);
71097 rc = pOp->p4.xAdvance(pC->pCursor, &res);
71098 next_tail:
71099 pC->cacheStatus = CACHE_STALE;
71100 VdbeBranchTaken(res==0,2);
71101 if( res==0 ){
71102 pC->nullRow = 0;
71103 pc = pOp->p2 - 1;
71104 p->aCounter[pOp->p5]++;
71105 #ifdef SQLITE_TEST
@@ -70972,10 +71119,18 @@
71119 ** MakeRecord instructions. This opcode writes that key
71120 ** into the index P1. Data for the entry is nil.
71121 **
71122 ** P3 is a flag that provides a hint to the b-tree layer that this
71123 ** insert is likely to be an append.
71124 **
71125 ** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
71126 ** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
71127 ** then the change counter is unchanged.
71128 **
71129 ** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have
71130 ** just done a seek to the spot where the new entry is to be inserted.
71131 ** This flag avoids doing an extra seek.
71132 **
71133 ** This instruction only works for indices. The equivalent instruction
71134 ** for tables is OP_Insert.
71135 */
71136 case OP_SorterInsert: /* in2 */
@@ -71087,36 +71242,54 @@
71242
71243 /* Opcode: IdxGE P1 P2 P3 P4 P5
71244 ** Synopsis: key=r[P3@P4]
71245 **
71246 ** The P4 register values beginning with P3 form an unpacked index
71247 ** key that omits the PRIMARY KEY. Compare this key value against the index
71248 ** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
71249 ** fields at the end.
71250 **
71251 ** If the P1 index entry is greater than or equal to the key value
71252 ** then jump to P2. Otherwise fall through to the next instruction.
71253 */
71254 /* Opcode: IdxGT P1 P2 P3 P4 P5
71255 ** Synopsis: key=r[P3@P4]
71256 **
71257 ** The P4 register values beginning with P3 form an unpacked index
71258 ** key that omits the PRIMARY KEY. Compare this key value against the index
71259 ** that P1 is currently pointing to, ignoring the PRIMARY KEY or ROWID
71260 ** fields at the end.
71261 **
71262 ** If the P1 index entry is greater than the key value
71263 ** then jump to P2. Otherwise fall through to the next instruction.
71264 */
71265 /* Opcode: IdxLT P1 P2 P3 P4 P5
71266 ** Synopsis: key=r[P3@P4]
71267 **
71268 ** The P4 register values beginning with P3 form an unpacked index
71269 ** key that omits the PRIMARY KEY or ROWID. Compare this key value against
71270 ** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
71271 ** ROWID on the P1 index.
71272 **
71273 ** If the P1 index entry is less than the key value then jump to P2.
71274 ** Otherwise fall through to the next instruction.
71275 */
71276 /* Opcode: IdxLE P1 P2 P3 P4 P5
71277 ** Synopsis: key=r[P3@P4]
71278 **
71279 ** The P4 register values beginning with P3 form an unpacked index
71280 ** key that omits the PRIMARY KEY or ROWID. Compare this key value against
71281 ** the index that P1 is currently pointing to, ignoring the PRIMARY KEY or
71282 ** ROWID on the P1 index.
71283 **
71284 ** If the P1 index entry is less than or equal to the key value then jump
71285 ** to P2. Otherwise fall through to the next instruction.
71286 */
71287 case OP_IdxLE: /* jump */
71288 case OP_IdxGT: /* jump */
71289 case OP_IdxLT: /* jump */
71290 case OP_IdxGE: { /* jump */
71291 VdbeCursor *pC;
71292 int res;
71293 UnpackedRecord r;
71294
71295 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -71127,27 +71300,32 @@
71300 assert( pC->deferredMoveto==0 );
71301 assert( pOp->p5==0 || pOp->p5==1 );
71302 assert( pOp->p4type==P4_INT32 );
71303 r.pKeyInfo = pC->pKeyInfo;
71304 r.nField = (u16)pOp->p4.i;
71305 if( pOp->opcode<OP_IdxLT ){
71306 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxGT );
71307 r.flags = UNPACKED_INCRKEY | UNPACKED_PREFIX_MATCH;
71308 }else{
71309 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxLT );
71310 r.flags = UNPACKED_PREFIX_MATCH;
71311 }
71312 r.aMem = &aMem[pOp->p3];
71313 #ifdef SQLITE_DEBUG
71314 { int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
71315 #endif
71316 res = 0; /* Not needed. Only used to silence a warning. */
71317 rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
71318 assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
71319 if( (pOp->opcode&1)==(OP_IdxLT&1) ){
71320 assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
71321 res = -res;
71322 }else{
71323 assert( pOp->opcode==OP_IdxGE || pOp->opcode==OP_IdxGT );
71324 res++;
71325 }
71326 VdbeBranchTaken(res>0,2);
71327 if( res>0 ){
71328 pc = pOp->p2 - 1 ;
71329 }
71330 break;
71331 }
@@ -71236,11 +71414,10 @@
71414 case OP_Clear: {
71415 int nChange;
71416
71417 nChange = 0;
71418 assert( p->readOnly==0 );
 
71419 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 );
71420 rc = sqlite3BtreeClearTable(
71421 db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &nChange : 0)
71422 );
71423 if( pOp->p3 ){
@@ -71505,13 +71682,15 @@
71682 || sqlite3RowSetNext(pIn1->u.pRowSet, &val)==0
71683 ){
71684 /* The boolean index is empty */
71685 sqlite3VdbeMemSetNull(pIn1);
71686 pc = pOp->p2 - 1;
71687 VdbeBranchTaken(1,2);
71688 }else{
71689 /* A value was pulled from the index */
71690 sqlite3VdbeMemSetInt64(&aMem[pOp->p3], val);
71691 VdbeBranchTaken(0,2);
71692 }
71693 goto check_for_interrupt;
71694 }
71695
71696 /* Opcode: RowSetTest P1 P2 P3 P4
@@ -71559,10 +71738,11 @@
71738 assert( iSet==-1 || iSet>=0 );
71739 if( iSet ){
71740 exists = sqlite3RowSetTest(pIn1->u.pRowSet,
71741 (u8)(iSet>=0 ? iSet & 0xf : 0xff),
71742 pIn3->u.i);
71743 VdbeBranchTaken(exists!=0,2);
71744 if( exists ){
71745 pc = pOp->p2 - 1;
71746 break;
71747 }
71748 }
@@ -71573,11 +71753,11 @@
71753 }
71754
71755
71756 #ifndef SQLITE_OMIT_TRIGGER
71757
71758 /* Opcode: Program P1 P2 P3 P4 P5
71759 **
71760 ** Execute the trigger program passed as P4 (type P4_SUBPROGRAM).
71761 **
71762 ** P1 contains the address of the memory cell that contains the first memory
71763 ** cell in an array of values used as arguments to the sub-program. P2
@@ -71585,10 +71765,12 @@
71765 ** exception using the RAISE() function. Register P3 contains the address
71766 ** of a memory cell in this (the parent) VM that is used to allocate the
71767 ** memory required by the sub-vdbe at runtime.
71768 **
71769 ** P4 is a pointer to the VM containing the trigger program.
71770 **
71771 ** If P5 is non-zero, then recursive program invocation is enabled.
71772 */
71773 case OP_Program: { /* jump */
71774 int nMem; /* Number of memory registers for sub-program */
71775 int nByte; /* Bytes of runtime space required for sub-program */
71776 Mem *pRt; /* Register to allocate runtime space */
@@ -71662,11 +71844,11 @@
71844 pFrame->aOnceFlag = p->aOnceFlag;
71845 pFrame->nOnceFlag = p->nOnceFlag;
71846
71847 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
71848 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
71849 pMem->flags = MEM_Undefined;
71850 pMem->db = db;
71851 }
71852 }else{
71853 pFrame = pRt->u.pFrame;
71854 assert( pProgram->nMem+pProgram->nCsr==pFrame->nChildMem );
@@ -71749,12 +71931,14 @@
71931 ** zero, the jump is taken if the statement constraint-counter is zero
71932 ** (immediate foreign key constraint violations).
71933 */
71934 case OP_FkIfZero: { /* jump */
71935 if( pOp->p1 ){
71936 VdbeBranchTaken(db->nDeferredCons==0 && db->nDeferredImmCons==0, 2);
71937 if( db->nDeferredCons==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
71938 }else{
71939 VdbeBranchTaken(p->nFkConstraint==0 && db->nDeferredImmCons==0, 2);
71940 if( p->nFkConstraint==0 && db->nDeferredImmCons==0 ) pc = pOp->p2-1;
71941 }
71942 break;
71943 }
71944 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
@@ -71799,10 +71983,11 @@
71983 ** not contain an integer. An assertion fault will result if you try.
71984 */
71985 case OP_IfPos: { /* jump, in1 */
71986 pIn1 = &aMem[pOp->p1];
71987 assert( pIn1->flags&MEM_Int );
71988 VdbeBranchTaken( pIn1->u.i>0, 2);
71989 if( pIn1->u.i>0 ){
71990 pc = pOp->p2 - 1;
71991 }
71992 break;
71993 }
@@ -71816,10 +72001,11 @@
72001 ** not contain an integer. An assertion fault will result if you try.
72002 */
72003 case OP_IfNeg: { /* jump, in1 */
72004 pIn1 = &aMem[pOp->p1];
72005 assert( pIn1->flags&MEM_Int );
72006 VdbeBranchTaken(pIn1->u.i<0, 2);
72007 if( pIn1->u.i<0 ){
72008 pc = pOp->p2 - 1;
72009 }
72010 break;
72011 }
@@ -71835,10 +72021,11 @@
72021 */
72022 case OP_IfZero: { /* jump, in1 */
72023 pIn1 = &aMem[pOp->p1];
72024 assert( pIn1->flags&MEM_Int );
72025 pIn1->u.i += pOp->p3;
72026 VdbeBranchTaken(pIn1->u.i==0, 2);
72027 if( pIn1->u.i==0 ){
72028 pc = pOp->p2 - 1;
72029 }
72030 break;
72031 }
@@ -71972,11 +72159,11 @@
72159 break;
72160 };
72161 #endif
72162
72163 #ifndef SQLITE_OMIT_PRAGMA
72164 /* Opcode: JournalMode P1 P2 P3 * *
72165 **
72166 ** Change the journal mode of database P1 to P3. P3 must be one of the
72167 ** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
72168 ** modes (delete, truncate, persist, off and memory), this is a simple
72169 ** operation. No IO is required.
@@ -72106,10 +72293,11 @@
72293 assert( pOp->p1>=0 && pOp->p1<db->nDb );
72294 assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 );
72295 assert( p->readOnly==0 );
72296 pBt = db->aDb[pOp->p1].pBt;
72297 rc = sqlite3BtreeIncrVacuum(pBt);
72298 VdbeBranchTaken(rc==SQLITE_DONE,2);
72299 if( rc==SQLITE_DONE ){
72300 pc = pOp->p2 - 1;
72301 rc = SQLITE_OK;
72302 }
72303 break;
@@ -72312,11 +72500,11 @@
72500 p->inVtabMethod = 0;
72501 sqlite3VtabImportErrmsg(p, pVtab);
72502 if( rc==SQLITE_OK ){
72503 res = pModule->xEof(pVtabCursor);
72504 }
72505 VdbeBranchTaken(res!=0,2);
72506 if( res ){
72507 pc = pOp->p2 - 1;
72508 }
72509 }
72510 pCur->nullRow = 0;
@@ -72417,11 +72605,11 @@
72605 p->inVtabMethod = 0;
72606 sqlite3VtabImportErrmsg(p, pVtab);
72607 if( rc==SQLITE_OK ){
72608 res = pModule->xEof(pCur->pVtabCursor);
72609 }
72610 VdbeBranchTaken(!res,2);
72611 if( !res ){
72612 /* If there is data, jump to P2 */
72613 pc = pOp->p2 - 1;
72614 }
72615 goto check_for_interrupt;
@@ -72458,11 +72646,11 @@
72646 break;
72647 }
72648 #endif
72649
72650 #ifndef SQLITE_OMIT_VIRTUALTABLE
72651 /* Opcode: VUpdate P1 P2 P3 P4 P5
72652 ** Synopsis: data=r[P3@P2]
72653 **
72654 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
72655 ** This opcode invokes the corresponding xUpdate method. P2 values
72656 ** are contiguous memory cells starting at P3 to pass to the xUpdate
@@ -72481,10 +72669,13 @@
72669 ** a row to delete.
72670 **
72671 ** P1 is a boolean flag. If it is set to true and the xUpdate call
72672 ** is successful, then the value returned by sqlite3_last_insert_rowid()
72673 ** is set to the value of the rowid for the row just inserted.
72674 **
72675 ** P5 is the error actions (OE_Replace, OE_Fail, OE_Ignore, etc) to
72676 ** apply in the case of a constraint failure on an insert or update.
72677 */
72678 case OP_VUpdate: {
72679 sqlite3_vtab *pVtab;
72680 sqlite3_module *pModule;
72681 int nArg;
@@ -72569,20 +72760,30 @@
72760 break;
72761 }
72762 #endif
72763
72764
72765 /* Opcode: Init * P2 * P4 *
72766 ** Synopsis: Start at P2
72767 **
72768 ** Programs contain a single instance of this opcode as the very first
72769 ** opcode.
72770 **
72771 ** If tracing is enabled (by the sqlite3_trace()) interface, then
72772 ** the UTF-8 string contained in P4 is emitted on the trace callback.
72773 ** Or if P4 is blank, use the string returned by sqlite3_sql().
72774 **
72775 ** If P2 is not zero, jump to instruction P2.
72776 */
72777 case OP_Init: { /* jump */
72778 char *zTrace;
72779 char *z;
72780
72781 if( pOp->p2 ){
72782 pc = pOp->p2 - 1;
72783 }
72784 #ifndef SQLITE_OMIT_TRACE
72785 if( db->xTrace
72786 && !p->doingRerun
72787 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72788 ){
72789 z = sqlite3VdbeExpandSql(p, zTrace);
@@ -72604,13 +72805,13 @@
72805 && (zTrace = (pOp->p4.z ? pOp->p4.z : p->zSql))!=0
72806 ){
72807 sqlite3DebugPrintf("SQL-trace: %s\n", zTrace);
72808 }
72809 #endif /* SQLITE_DEBUG */
72810 #endif /* SQLITE_OMIT_TRACE */
72811 break;
72812 }
 
72813
72814
72815 /* Opcode: Noop * * * * *
72816 **
72817 ** Do nothing. This instruction is often useful as a jump
@@ -72638,14 +72839,10 @@
72839 #ifdef VDBE_PROFILE
72840 {
72841 u64 elapsed = sqlite3Hwtime() - start;
72842 pOp->cycles += elapsed;
72843 pOp->cnt++;
 
 
 
 
72844 }
72845 #endif
72846
72847 /* The following code adds nothing to the actual functionality
72848 ** of the program. It is only here for testing and debugging.
@@ -72867,26 +73064,24 @@
73064 **
73065 ** The sqlite3_blob_close() function finalizes the vdbe program,
73066 ** which closes the b-tree cursor and (possibly) commits the
73067 ** transaction.
73068 */
73069 static const int iLn = __LINE__+4;
73070 static const VdbeOpList openBlob[] = {
73071 /* {OP_Transaction, 0, 0, 0}, // 0: Inserted separately */
73072 {OP_TableLock, 0, 0, 0}, /* 1: Acquire a read or write lock */
 
 
73073 /* One of the following two instructions is replaced by an OP_Noop. */
73074 {OP_OpenRead, 0, 0, 0}, /* 2: Open cursor 0 for reading */
73075 {OP_OpenWrite, 0, 0, 0}, /* 3: Open cursor 0 for read/write */
73076 {OP_Variable, 1, 1, 1}, /* 4: Push the rowid to the stack */
73077 {OP_NotExists, 0, 10, 1}, /* 5: Seek the cursor */
73078 {OP_Column, 0, 0, 1}, /* 6 */
73079 {OP_ResultRow, 1, 0, 0}, /* 7 */
73080 {OP_Goto, 0, 4, 0}, /* 8 */
73081 {OP_Close, 0, 0, 0}, /* 9 */
73082 {OP_Halt, 0, 0, 0}, /* 10 */
 
73083 };
73084
73085 int rc = SQLITE_OK;
73086 char *zErr = 0;
73087 Table *pTab;
@@ -72995,50 +73190,45 @@
73190 assert( pBlob->pStmt || db->mallocFailed );
73191 if( pBlob->pStmt ){
73192 Vdbe *v = (Vdbe *)pBlob->pStmt;
73193 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
73194
73195
73196 sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, flags,
73197 pTab->pSchema->schema_cookie,
73198 pTab->pSchema->iGeneration);
73199 sqlite3VdbeChangeP5(v, 1);
73200 sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
 
 
 
 
 
73201
73202 /* Make sure a mutex is held on the table to be accessed */
73203 sqlite3VdbeUsesBtree(v, iDb);
73204
73205 /* Configure the OP_TableLock instruction */
73206 #ifdef SQLITE_OMIT_SHARED_CACHE
73207 sqlite3VdbeChangeToNoop(v, 1);
73208 #else
73209 sqlite3VdbeChangeP1(v, 1, iDb);
73210 sqlite3VdbeChangeP2(v, 1, pTab->tnum);
73211 sqlite3VdbeChangeP3(v, 1, flags);
73212 sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
73213 #endif
73214
73215 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
73216 ** parameter of the other to pTab->tnum. */
73217 sqlite3VdbeChangeToNoop(v, 3 - flags);
73218 sqlite3VdbeChangeP2(v, 2 + flags, pTab->tnum);
73219 sqlite3VdbeChangeP3(v, 2 + flags, iDb);
73220
73221 /* Configure the number of columns. Configure the cursor to
73222 ** think that the table has one more column than it really
73223 ** does. An OP_Column to retrieve this imaginary column will
73224 ** always return an SQL NULL. This is useful because it means
73225 ** we can invoke OP_Column to fill in the vdbe cursors type
73226 ** and offset cache without causing any IO.
73227 */
73228 sqlite3VdbeChangeP4(v, 2+flags, SQLITE_INT_TO_PTR(pTab->nCol+1),P4_INT32);
73229 sqlite3VdbeChangeP2(v, 6, pTab->nCol);
73230 if( !db->mallocFailed ){
73231 pParse->nVar = 1;
73232 pParse->nMem = 1;
73233 pParse->nTab = 1;
73234 sqlite3VdbeMakeReady(v, pParse);
@@ -75302,12 +75492,12 @@
75492 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75493
75494 /*
75495 ** Perhaps the name is a reference to the ROWID
75496 */
75497 if( cnt==0 && cntTab==1 && pMatch && sqlite3IsRowid(zCol)
75498 && HasRowid(pMatch->pTab) ){
75499 cnt = 1;
75500 pExpr->iColumn = -1; /* IMP: R-44911-55124 */
75501 pExpr->affinity = SQLITE_AFF_INTEGER;
75502 }
75503
@@ -77434,11 +77624,10 @@
77624 pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
77625 pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
77626 pNew->iLimit = 0;
77627 pNew->iOffset = 0;
77628 pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
 
77629 pNew->addrOpenEphm[0] = -1;
77630 pNew->addrOpenEphm[1] = -1;
77631 pNew->addrOpenEphm[2] = -1;
77632 pNew->nSelectRow = p->nSelectRow;
77633 pNew->pWith = withDup(db, p->pWith);
@@ -77744,28 +77933,10 @@
77933 default:
77934 return 1;
77935 }
77936 }
77937
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77938 /*
77939 ** Return TRUE if the given expression is a constant which would be
77940 ** unchanged by OP_Affinity with the affinity given in the second
77941 ** argument.
77942 **
@@ -77958,11 +78129,11 @@
78129 assert( p->pSrc!=0 ); /* Because of isCandidateForInOpt(p) */
78130 pTab = p->pSrc->a[0].pTab;
78131 pExpr = p->pEList->a[0].pExpr;
78132 iCol = (i16)pExpr->iColumn;
78133
78134 /* Code an OP_Transaction and OP_TableLock for <table>. */
78135 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
78136 sqlite3CodeVerifySchema(pParse, iDb);
78137 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
78138
78139 /* This function is only called from two places. In both cases the vdbe
@@ -77969,13 +78140,12 @@
78140 ** has already been allocated. So assume sqlite3GetVdbe() is always
78141 ** successful here.
78142 */
78143 assert(v);
78144 if( iCol<0 ){
78145 int iAddr = sqlite3CodeOnce(pParse);
78146 VdbeCoverage(v);
 
78147
78148 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
78149 eType = IN_INDEX_ROWID;
78150
78151 sqlite3VdbeJumpHere(v, iAddr);
@@ -77996,22 +78166,22 @@
78166 for(pIdx=pTab->pIndex; pIdx && eType==0 && affinity_ok; pIdx=pIdx->pNext){
78167 if( (pIdx->aiColumn[0]==iCol)
78168 && sqlite3FindCollSeq(db, ENC(db), pIdx->azColl[0], 0)==pReq
78169 && (!mustBeUnique || (pIdx->nKeyCol==1 && pIdx->onError!=OE_None))
78170 ){
78171 int iAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
78172 sqlite3VdbeAddOp3(v, OP_OpenRead, iTab, pIdx->tnum, iDb);
78173 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
78174 VdbeComment((v, "%s", pIdx->zName));
78175 assert( IN_INDEX_INDEX_DESC == IN_INDEX_INDEX_ASC+1 );
78176 eType = IN_INDEX_INDEX_ASC + pIdx->aSortOrder[0];
78177
 
78178 if( prNotFound && !pTab->aCol[iCol].notNull ){
78179 *prNotFound = ++pParse->nMem;
78180 sqlite3VdbeAddOp2(v, OP_Null, 0, *prNotFound);
78181 }
78182 sqlite3VdbeJumpHere(v, iAddr);
78183 }
78184 }
78185 }
78186 }
78187
@@ -78096,11 +78266,11 @@
78266 **
78267 ** If all of the above are false, then we can run this code just once
78268 ** save the results, and reuse the same result on subsequent invocations.
78269 */
78270 if( !ExprHasProperty(pExpr, EP_VarSelect) ){
78271 testAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
78272 }
78273
78274 #ifndef SQLITE_OMIT_EXPLAIN
78275 if( pParse->explain==2 ){
78276 char *zMsg = sqlite3MPrintf(
@@ -78137,11 +78307,10 @@
78307 ** 'x' nor the SELECT... statement are columns, then numeric affinity
78308 ** is used.
78309 */
78310 pExpr->iTable = pParse->nTab++;
78311 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
 
78312 pKeyInfo = isRowid ? 0 : sqlite3KeyInfoAlloc(pParse->db, 1, 1);
78313
78314 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
78315 /* Case 1: expr IN (SELECT ...)
78316 **
@@ -78213,10 +78382,11 @@
78382 }else{
78383 r3 = sqlite3ExprCodeTarget(pParse, pE2, r1);
78384 if( isRowid ){
78385 sqlite3VdbeAddOp2(v, OP_MustBeInt, r3,
78386 sqlite3VdbeCurrentAddr(v)+2);
78387 VdbeCoverage(v);
78388 sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
78389 }else{
78390 sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
78391 sqlite3ExprCacheAffinityChange(pParse, r3, 1);
78392 sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
@@ -78336,23 +78506,25 @@
78506 ** on whether the RHS is empty or not, respectively.
78507 */
78508 if( destIfNull==destIfFalse ){
78509 /* Shortcut for the common case where the false and NULL outcomes are
78510 ** the same. */
78511 sqlite3VdbeAddOp2(v, OP_IsNull, r1, destIfNull); VdbeCoverage(v);
78512 }else{
78513 int addr1 = sqlite3VdbeAddOp1(v, OP_NotNull, r1); VdbeCoverage(v);
78514 sqlite3VdbeAddOp2(v, OP_Rewind, pExpr->iTable, destIfFalse);
78515 VdbeCoverage(v);
78516 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
78517 sqlite3VdbeJumpHere(v, addr1);
78518 }
78519
78520 if( eType==IN_INDEX_ROWID ){
78521 /* In this case, the RHS is the ROWID of table b-tree
78522 */
78523 sqlite3VdbeAddOp2(v, OP_MustBeInt, r1, destIfFalse); VdbeCoverage(v);
78524 sqlite3VdbeAddOp3(v, OP_NotExists, pExpr->iTable, destIfFalse, r1);
78525 VdbeCoverage(v);
78526 }else{
78527 /* In this case, the RHS is an index b-tree.
78528 */
78529 sqlite3VdbeAddOp4(v, OP_Affinity, r1, 1, 0, &affinity, 1);
78530
@@ -78369,42 +78541,40 @@
78541 **
78542 ** Also run this branch if NULL is equivalent to FALSE
78543 ** for this particular IN operator.
78544 */
78545 sqlite3VdbeAddOp4Int(v, OP_NotFound, pExpr->iTable, destIfFalse, r1, 1);
78546 VdbeCoverage(v);
78547 }else{
78548 /* In this branch, the RHS of the IN might contain a NULL and
78549 ** the presence of a NULL on the RHS makes a difference in the
78550 ** outcome.
78551 */
78552 int j1, j2;
78553
78554 /* First check to see if the LHS is contained in the RHS. If so,
78555 ** then the presence of NULLs in the RHS does not matter, so jump
78556 ** over all of the code that follows.
78557 */
78558 j1 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, r1, 1);
78559 VdbeCoverage(v);
78560
78561 /* Here we begin generating code that runs if the LHS is not
78562 ** contained within the RHS. Generate additional code that
78563 ** tests the RHS for NULLs. If the RHS contains a NULL then
78564 ** jump to destIfNull. If there are no NULLs in the RHS then
78565 ** jump to destIfFalse.
78566 */
78567 sqlite3VdbeAddOp2(v, OP_If, rRhsHasNull, destIfNull); VdbeCoverage(v);
78568 sqlite3VdbeAddOp2(v, OP_IfNot, rRhsHasNull, destIfFalse); VdbeCoverage(v);
78569 j2 = sqlite3VdbeAddOp4Int(v, OP_Found, pExpr->iTable, 0, rRhsHasNull, 1);
78570 VdbeCoverage(v);
78571 sqlite3VdbeAddOp2(v, OP_Integer, 0, rRhsHasNull);
78572 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfFalse);
78573 sqlite3VdbeJumpHere(v, j2);
78574 sqlite3VdbeAddOp2(v, OP_Integer, 1, rRhsHasNull);
78575 sqlite3VdbeAddOp2(v, OP_Goto, 0, destIfNull);
 
 
 
 
78576
78577 /* The OP_Found at the top of this branch jumps here when true,
78578 ** causing the overall IN expression evaluation to fall through.
78579 */
78580 sqlite3VdbeJumpHere(v, j1);
@@ -78921,26 +79091,20 @@
79091 case TK_LE:
79092 case TK_GT:
79093 case TK_GE:
79094 case TK_NE:
79095 case TK_EQ: {
 
 
 
 
 
 
 
 
 
 
 
 
79096 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79097 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
79098 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
79099 r1, r2, inReg, SQLITE_STOREP2);
79100 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
79101 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
79102 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
79103 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
79104 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
79105 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
79106 testcase( regFree1==0 );
79107 testcase( regFree2==0 );
79108 break;
79109 }
79110 case TK_IS:
@@ -78950,10 +79114,12 @@
79114 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79115 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
79116 op = (op==TK_IS) ? TK_EQ : TK_NE;
79117 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
79118 r1, r2, inReg, SQLITE_STOREP2 | SQLITE_NULLEQ);
79119 VdbeCoverageIf(v, op==TK_EQ);
79120 VdbeCoverageIf(v, op==TK_NE);
79121 testcase( regFree1==0 );
79122 testcase( regFree2==0 );
79123 break;
79124 }
79125 case TK_AND:
@@ -78966,32 +79132,21 @@
79132 case TK_BITOR:
79133 case TK_SLASH:
79134 case TK_LSHIFT:
79135 case TK_RSHIFT:
79136 case TK_CONCAT: {
79137 assert( TK_AND==OP_And ); testcase( op==TK_AND );
79138 assert( TK_OR==OP_Or ); testcase( op==TK_OR );
79139 assert( TK_PLUS==OP_Add ); testcase( op==TK_PLUS );
79140 assert( TK_MINUS==OP_Subtract ); testcase( op==TK_MINUS );
79141 assert( TK_REM==OP_Remainder ); testcase( op==TK_REM );
79142 assert( TK_BITAND==OP_BitAnd ); testcase( op==TK_BITAND );
79143 assert( TK_BITOR==OP_BitOr ); testcase( op==TK_BITOR );
79144 assert( TK_SLASH==OP_Divide ); testcase( op==TK_SLASH );
79145 assert( TK_LSHIFT==OP_ShiftLeft ); testcase( op==TK_LSHIFT );
79146 assert( TK_RSHIFT==OP_ShiftRight ); testcase( op==TK_RSHIFT );
79147 assert( TK_CONCAT==OP_Concat ); testcase( op==TK_CONCAT );
 
 
 
 
 
 
 
 
 
 
 
79148 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79149 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
79150 sqlite3VdbeAddOp3(v, op, r2, r1, target);
79151 testcase( regFree1==0 );
79152 testcase( regFree2==0 );
@@ -79019,31 +79174,29 @@
79174 inReg = target;
79175 break;
79176 }
79177 case TK_BITNOT:
79178 case TK_NOT: {
79179 assert( TK_BITNOT==OP_BitNot ); testcase( op==TK_BITNOT );
79180 assert( TK_NOT==OP_Not ); testcase( op==TK_NOT );
 
 
79181 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79182 testcase( regFree1==0 );
79183 inReg = target;
79184 sqlite3VdbeAddOp2(v, op, r1, inReg);
79185 break;
79186 }
79187 case TK_ISNULL:
79188 case TK_NOTNULL: {
79189 int addr;
79190 assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
79191 assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
 
 
79192 sqlite3VdbeAddOp2(v, OP_Integer, 1, target);
79193 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
79194 testcase( regFree1==0 );
79195 addr = sqlite3VdbeAddOp1(v, op, r1);
79196 VdbeCoverageIf(v, op==TK_ISNULL);
79197 VdbeCoverageIf(v, op==TK_NOTNULL);
79198 sqlite3VdbeAddOp2(v, OP_AddImm, target, -1);
79199 sqlite3VdbeJumpHere(v, addr);
79200 break;
79201 }
79202 case TK_AGG_FUNCTION: {
@@ -79091,10 +79244,11 @@
79244 int endCoalesce = sqlite3VdbeMakeLabel(v);
79245 assert( nFarg>=2 );
79246 sqlite3ExprCode(pParse, pFarg->a[0].pExpr, target);
79247 for(i=1; i<nFarg; i++){
79248 sqlite3VdbeAddOp2(v, OP_NotNull, target, endCoalesce);
79249 VdbeCoverage(v);
79250 sqlite3ExprCacheRemove(pParse, target, 1);
79251 sqlite3ExprCachePush(pParse);
79252 sqlite3ExprCode(pParse, pFarg->a[i].pExpr, target);
79253 sqlite3ExprCachePop(pParse, 1);
79254 }
@@ -79228,17 +79382,18 @@
79382 testcase( regFree1==0 );
79383 testcase( regFree2==0 );
79384 r3 = sqlite3GetTempReg(pParse);
79385 r4 = sqlite3GetTempReg(pParse);
79386 codeCompare(pParse, pLeft, pRight, OP_Ge,
79387 r1, r2, r3, SQLITE_STOREP2); VdbeCoverage(v);
79388 pLItem++;
79389 pRight = pLItem->pExpr;
79390 sqlite3ReleaseTempReg(pParse, regFree2);
79391 r2 = sqlite3ExprCodeTemp(pParse, pRight, &regFree2);
79392 testcase( regFree2==0 );
79393 codeCompare(pParse, pLeft, pRight, OP_Le, r1, r2, r4, SQLITE_STOREP2);
79394 VdbeCoverage(v);
79395 sqlite3VdbeAddOp3(v, OP_And, r3, r4, target);
79396 sqlite3ReleaseTempReg(pParse, r3);
79397 sqlite3ReleaseTempReg(pParse, r4);
79398 break;
79399 }
@@ -79401,10 +79556,11 @@
79556 }
79557 assert( !ExprHasProperty(pExpr, EP_IntValue) );
79558 if( pExpr->affinity==OE_Ignore ){
79559 sqlite3VdbeAddOp4(
79560 v, OP_Halt, SQLITE_OK, OE_Ignore, 0, pExpr->u.zToken,0);
79561 VdbeCoverage(v);
79562 }else{
79563 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_TRIGGER,
79564 pExpr->affinity, pExpr->u.zToken, 0, 0);
79565 }
79566
@@ -79488,11 +79644,11 @@
79644 /*
79645 ** Generate code that will evaluate expression pExpr and store the
79646 ** results in register target. The results are guaranteed to appear
79647 ** in register target.
79648 */
79649 SQLITE_PRIVATE void sqlite3ExprCode(Parse *pParse, Expr *pExpr, int target){
79650 int inReg;
79651
79652 assert( target>0 && target<=pParse->nMem );
79653 if( pExpr && pExpr->op==TK_REGISTER ){
79654 sqlite3VdbeAddOp2(pParse->pVdbe, OP_Copy, pExpr->iTable, target);
@@ -79501,11 +79657,24 @@
79657 assert( pParse->pVdbe || pParse->db->mallocFailed );
79658 if( inReg!=target && pParse->pVdbe ){
79659 sqlite3VdbeAddOp2(pParse->pVdbe, OP_SCopy, inReg, target);
79660 }
79661 }
79662 }
79663
79664 /*
79665 ** Generate code that will evaluate expression pExpr and store the
79666 ** results in register target. The results are guaranteed to appear
79667 ** in register target. If the expression is constant, then this routine
79668 ** might choose to code the expression at initialization time.
79669 */
79670 SQLITE_PRIVATE void sqlite3ExprCodeFactorable(Parse *pParse, Expr *pExpr, int target){
79671 if( pParse->okConstFactor && sqlite3ExprIsConstant(pExpr) ){
79672 sqlite3ExprCodeAtInit(pParse, pExpr, target, 0);
79673 }else{
79674 sqlite3ExprCode(pParse, pExpr, target);
79675 }
79676 }
79677
79678 /*
79679 ** Generate code that evalutes the given expression and puts the result
79680 ** in register target.
@@ -79516,29 +79685,20 @@
79685 **
79686 ** This routine is used for expressions that are used multiple
79687 ** times. They are evaluated once and the results of the expression
79688 ** are reused.
79689 */
79690 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse *pParse, Expr *pExpr, int target){
79691 Vdbe *v = pParse->pVdbe;
79692 int iMem;
79693
79694 assert( target>0 );
79695 assert( pExpr->op!=TK_REGISTER );
79696 sqlite3ExprCode(pParse, pExpr, target);
79697 iMem = ++pParse->nMem;
79698 sqlite3VdbeAddOp2(v, OP_Copy, target, iMem);
79699 exprToRegister(pExpr, iMem);
 
 
 
 
 
 
 
 
 
79700 }
79701
79702 #if defined(SQLITE_ENABLE_TREE_EXPLAIN)
79703 /*
79704 ** Generate a human-readable explanation of an expression tree.
@@ -79969,27 +80129,21 @@
80129 case TK_LE:
80130 case TK_GT:
80131 case TK_GE:
80132 case TK_NE:
80133 case TK_EQ: {
 
 
 
 
 
 
 
 
 
 
 
 
80134 testcase( jumpIfNull==0 );
80135 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80136 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80137 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80138 r1, r2, dest, jumpIfNull);
80139 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
80140 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
80141 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
80142 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
80143 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
80144 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
80145 testcase( regFree1==0 );
80146 testcase( regFree2==0 );
80147 break;
80148 }
80149 case TK_IS:
@@ -79999,22 +80153,24 @@
80153 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80154 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80155 op = (op==TK_IS) ? TK_EQ : TK_NE;
80156 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80157 r1, r2, dest, SQLITE_NULLEQ);
80158 VdbeCoverageIf(v, op==TK_EQ);
80159 VdbeCoverageIf(v, op==TK_NE);
80160 testcase( regFree1==0 );
80161 testcase( regFree2==0 );
80162 break;
80163 }
80164 case TK_ISNULL:
80165 case TK_NOTNULL: {
80166 assert( TK_ISNULL==OP_IsNull ); testcase( op==TK_ISNULL );
80167 assert( TK_NOTNULL==OP_NotNull ); testcase( op==TK_NOTNULL );
 
 
80168 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80169 sqlite3VdbeAddOp2(v, op, r1, dest);
80170 VdbeCoverageIf(v, op==TK_ISNULL);
80171 VdbeCoverageIf(v, op==TK_NOTNULL);
80172 testcase( regFree1==0 );
80173 break;
80174 }
80175 case TK_BETWEEN: {
80176 testcase( jumpIfNull==0 );
@@ -80037,10 +80193,11 @@
80193 }else if( exprAlwaysFalse(pExpr) ){
80194 /* No-op */
80195 }else{
80196 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80197 sqlite3VdbeAddOp3(v, OP_If, r1, dest, jumpIfNull!=0);
80198 VdbeCoverage(v);
80199 testcase( regFree1==0 );
80200 testcase( jumpIfNull==0 );
80201 }
80202 break;
80203 }
@@ -80128,21 +80285,21 @@
80285 case TK_LE:
80286 case TK_GT:
80287 case TK_GE:
80288 case TK_NE:
80289 case TK_EQ: {
 
 
 
 
 
 
80290 testcase( jumpIfNull==0 );
80291 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80292 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80293 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80294 r1, r2, dest, jumpIfNull);
80295 assert(TK_LT==OP_Lt); testcase(op==OP_Lt); VdbeCoverageIf(v,op==OP_Lt);
80296 assert(TK_LE==OP_Le); testcase(op==OP_Le); VdbeCoverageIf(v,op==OP_Le);
80297 assert(TK_GT==OP_Gt); testcase(op==OP_Gt); VdbeCoverageIf(v,op==OP_Gt);
80298 assert(TK_GE==OP_Ge); testcase(op==OP_Ge); VdbeCoverageIf(v,op==OP_Ge);
80299 assert(TK_EQ==OP_Eq); testcase(op==OP_Eq); VdbeCoverageIf(v,op==OP_Eq);
80300 assert(TK_NE==OP_Ne); testcase(op==OP_Ne); VdbeCoverageIf(v,op==OP_Ne);
80301 testcase( regFree1==0 );
80302 testcase( regFree2==0 );
80303 break;
80304 }
80305 case TK_IS:
@@ -80152,20 +80309,22 @@
80309 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80310 r2 = sqlite3ExprCodeTemp(pParse, pExpr->pRight, &regFree2);
80311 op = (pExpr->op==TK_IS) ? TK_NE : TK_EQ;
80312 codeCompare(pParse, pExpr->pLeft, pExpr->pRight, op,
80313 r1, r2, dest, SQLITE_NULLEQ);
80314 VdbeCoverageIf(v, op==TK_EQ);
80315 VdbeCoverageIf(v, op==TK_NE);
80316 testcase( regFree1==0 );
80317 testcase( regFree2==0 );
80318 break;
80319 }
80320 case TK_ISNULL:
80321 case TK_NOTNULL: {
 
 
80322 r1 = sqlite3ExprCodeTemp(pParse, pExpr->pLeft, &regFree1);
80323 sqlite3VdbeAddOp2(v, op, r1, dest);
80324 testcase( op==TK_ISNULL ); VdbeCoverageIf(v, op==TK_ISNULL);
80325 testcase( op==TK_NOTNULL ); VdbeCoverageIf(v, op==TK_NOTNULL);
80326 testcase( regFree1==0 );
80327 break;
80328 }
80329 case TK_BETWEEN: {
80330 testcase( jumpIfNull==0 );
@@ -80190,10 +80349,11 @@
80349 }else if( exprAlwaysTrue(pExpr) ){
80350 /* no-op */
80351 }else{
80352 r1 = sqlite3ExprCodeTemp(pParse, pExpr, &regFree1);
80353 sqlite3VdbeAddOp3(v, OP_IfNot, r1, dest, jumpIfNull!=0);
80354 VdbeCoverage(v);
80355 testcase( regFree1==0 );
80356 testcase( jumpIfNull==0 );
80357 }
80358 break;
80359 }
@@ -80736,12 +80896,12 @@
80896 len = sqlite3GetToken(zCsr, &token);
80897 } while( token==TK_SPACE );
80898 assert( len>0 );
80899 } while( token!=TK_LP && token!=TK_USING );
80900
80901 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
80902 zSql, zTableName, tname.z+tname.n);
80903 sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
80904 }
80905 }
80906
80907 /*
@@ -80789,11 +80949,11 @@
80949 zParent = sqlite3DbStrNDup(db, (const char *)z, n);
80950 if( zParent==0 ) break;
80951 sqlite3Dequote(zParent);
80952 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){
80953 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"",
80954 (zOutput?zOutput:""), (int)(z-zInput), zInput, (const char *)zNew
80955 );
80956 sqlite3DbFree(db, zOutput);
80957 zOutput = zOut;
80958 zInput = &z[n];
80959 }
@@ -80875,12 +81035,12 @@
81035 } while( dist!=2 || (token!=TK_WHEN && token!=TK_FOR && token!=TK_BEGIN) );
81036
81037 /* Variable tname now contains the token that is the old table-name
81038 ** in the CREATE TRIGGER statement.
81039 */
81040 zRet = sqlite3MPrintf(db, "%.*s\"%w\"%s", (int)(((u8*)tname.z) - zSql),
81041 zSql, zTableName, tname.z+tname.n);
81042 sqlite3_result_text(context, zRet, -1, SQLITE_DYNAMIC);
81043 }
81044 }
81045 #endif /* !SQLITE_OMIT_TRIGGER */
81046
@@ -81128,11 +81288,11 @@
81288 pVTab = 0;
81289 }
81290 }
81291 #endif
81292
81293 /* Begin a transaction for database iDb.
81294 ** Then modify the schema cookie (since the ALTER TABLE modifies the
81295 ** schema). Open a statement transaction if the table is a virtual
81296 ** table.
81297 */
81298 v = sqlite3GetVdbe(pParse);
@@ -81264,10 +81424,11 @@
81424 int j1;
81425 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT);
81426 sqlite3VdbeUsesBtree(v, iDb);
81427 sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2);
81428 j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1);
81429 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v);
81430 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2);
81431 sqlite3VdbeJumpHere(v, j1);
81432 sqlite3ReleaseTempReg(pParse, r1);
81433 sqlite3ReleaseTempReg(pParse, r2);
81434 }
@@ -82564,10 +82725,11 @@
82725 ** regChng = 0
82726 ** goto next_push_0;
82727 **
82728 */
82729 addrRewind = sqlite3VdbeAddOp1(v, OP_Rewind, iIdxCur);
82730 VdbeCoverage(v);
82731 sqlite3VdbeAddOp2(v, OP_Integer, 0, regChng);
82732 addrGotoChng0 = sqlite3VdbeAddOp0(v, OP_Goto);
82733
82734 /*
82735 ** next_row:
@@ -82585,10 +82747,11 @@
82747 sqlite3VdbeAddOp2(v, OP_Integer, i, regChng);
82748 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, regTemp);
82749 aGotoChng[i] =
82750 sqlite3VdbeAddOp4(v, OP_Ne, regTemp, 0, regPrev+i, pColl, P4_COLLSEQ);
82751 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
82752 VdbeCoverage(v);
82753 }
82754 sqlite3VdbeAddOp2(v, OP_Integer, nCol, regChng);
82755 aGotoChng[nCol] = sqlite3VdbeAddOp0(v, OP_Goto);
82756
82757 /*
@@ -82631,11 +82794,11 @@
82794 #endif
82795 assert( regChng==(regStat4+1) );
82796 sqlite3VdbeAddOp3(v, OP_Function, 1, regStat4, regTemp);
82797 sqlite3VdbeChangeP4(v, -1, (char*)&statPushFuncdef, P4_FUNCDEF);
82798 sqlite3VdbeChangeP5(v, 2+IsStat34);
82799 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, addrNextRow); VdbeCoverage(v);
82800
82801 /* Add the entry to the stat1 table. */
82802 callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
82803 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
82804 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
@@ -82658,14 +82821,16 @@
82821 pParse->nMem = MAX(pParse->nMem, regCol+nCol+1);
82822
82823 addrNext = sqlite3VdbeCurrentAddr(v);
82824 callStatGet(v, regStat4, STAT_GET_ROWID, regSampleRowid);
82825 addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regSampleRowid);
82826 VdbeCoverage(v);
82827 callStatGet(v, regStat4, STAT_GET_NEQ, regEq);
82828 callStatGet(v, regStat4, STAT_GET_NLT, regLt);
82829 callStatGet(v, regStat4, STAT_GET_NDLT, regDLt);
82830 sqlite3VdbeAddOp4Int(v, seekOp, iTabCur, addrNext, regSampleRowid, 0);
82831 VdbeCoverage(v);
82832 #ifdef SQLITE_ENABLE_STAT3
82833 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur,
82834 pIdx->aiColumn[0], regSample);
82835 #else
82836 for(i=0; i<nCol; i++){
@@ -82672,11 +82837,11 @@
82837 i16 iCol = pIdx->aiColumn[i];
82838 sqlite3ExprCodeGetColumnOfTable(v, pTab, iTabCur, iCol, regCol+i);
82839 }
82840 sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, nCol+1, regSample);
82841 #endif
82842 sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
82843 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
82844 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regTemp, regNewRowid);
82845 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
82846 sqlite3VdbeJumpHere(v, addrIsNull);
82847 }
@@ -82692,11 +82857,11 @@
82857 ** name and the row count as the content.
82858 */
82859 if( pOnlyIdx==0 && needTableCnt ){
82860 VdbeComment((v, "%s", pTab->zName));
82861 sqlite3VdbeAddOp2(v, OP_Count, iTabCur, regStat1);
82862 jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1); VdbeCoverage(v);
82863 sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
82864 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp, "aaa", 0);
82865 sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
82866 sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regTemp, regNewRowid);
82867 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
@@ -84230,24 +84395,26 @@
84395 ** (Bit 0 is for main, bit 1 is for temp, and so forth.) Bits are
84396 ** set for each database that is used. Generate code to start a
84397 ** transaction on each used database and to verify the schema cookie
84398 ** on each used database.
84399 */
84400 if( db->mallocFailed==0 && (pParse->cookieMask || pParse->pConstExpr) ){
84401 yDbMask mask;
84402 int iDb, i;
84403 assert( sqlite3VdbeGetOp(v, 0)->opcode==OP_Init );
84404 sqlite3VdbeJumpHere(v, 0);
84405 for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
84406 if( (mask & pParse->cookieMask)==0 ) continue;
84407 sqlite3VdbeUsesBtree(v, iDb);
84408 sqlite3VdbeAddOp4Int(v,
84409 OP_Transaction, /* Opcode */
84410 iDb, /* P1 */
84411 (mask & pParse->writeMask)!=0, /* P2 */
84412 pParse->cookieValue[iDb], /* P3 */
84413 db->aDb[iDb].pSchema->iGeneration /* P4 */
84414 );
84415 if( db->init.busy==0 ) sqlite3VdbeChangeP5(v, 1);
84416 }
84417 #ifndef SQLITE_OMIT_VIRTUALTABLE
84418 for(i=0; i<pParse->nVtabLock; i++){
84419 char *vtab = (char *)sqlite3GetVTable(db, pParse->apVtabLock[i]);
84420 sqlite3VdbeAddOp4(v, OP_VBegin, 0, 0, 0, vtab, P4_VTAB);
@@ -84264,21 +84431,20 @@
84431 /* Initialize any AUTOINCREMENT data structures required.
84432 */
84433 sqlite3AutoincrementBegin(pParse);
84434
84435 /* Code constant expressions that where factored out of inner loops */
 
84436 if( pParse->pConstExpr ){
84437 ExprList *pEL = pParse->pConstExpr;
84438 pParse->okConstFactor = 0;
84439 for(i=0; i<pEL->nExpr; i++){
84440 sqlite3ExprCode(pParse, pEL->a[i].pExpr, pEL->a[i].u.iConstExprReg);
84441 }
84442 }
84443
84444 /* Finally, jump back to the beginning of the executable code. */
84445 sqlite3VdbeAddOp2(v, OP_Goto, 0, 1);
84446 }
84447 }
84448
84449
84450 /* Get the VDBE program ready for execution
@@ -84297,11 +84463,10 @@
84463 pParse->nTab = 0;
84464 pParse->nMem = 0;
84465 pParse->nSet = 0;
84466 pParse->nVar = 0;
84467 pParse->cookieMask = 0;
 
84468 }
84469
84470 /*
84471 ** Run the parser and code generator recursively in order to generate
84472 ** code for the SQL statement given onto the end of the pParse context
@@ -85029,11 +85194,11 @@
85194 reg1 = pParse->regRowid = ++pParse->nMem;
85195 reg2 = pParse->regRoot = ++pParse->nMem;
85196 reg3 = ++pParse->nMem;
85197 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, reg3, BTREE_FILE_FORMAT);
85198 sqlite3VdbeUsesBtree(v, iDb);
85199 j1 = sqlite3VdbeAddOp1(v, OP_If, reg3); VdbeCoverage(v);
85200 fileFormat = (db->flags & SQLITE_LegacyFileFmt)!=0 ?
85201 1 : SQLITE_MAX_FILE_FORMAT;
85202 sqlite3VdbeAddOp2(v, OP_Integer, fileFormat, reg3);
85203 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, reg3);
85204 sqlite3VdbeAddOp2(v, OP_Integer, ENC(db), reg3);
@@ -86756,40 +86921,40 @@
86921 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
86922
86923 /* Open the table. Loop through all rows of the table, inserting index
86924 ** records into the sorter. */
86925 sqlite3OpenTable(pParse, iTab, iDb, pTab, OP_OpenRead);
86926 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iTab, 0); VdbeCoverage(v);
86927 regRecord = sqlite3GetTempReg(pParse);
86928
86929 sqlite3GenerateIndexKey(pParse,pIndex,iTab,regRecord,0,&iPartIdxLabel,0,0);
86930 sqlite3VdbeAddOp2(v, OP_SorterInsert, iSorter, regRecord);
86931 sqlite3VdbeResolveLabel(v, iPartIdxLabel);
86932 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr1+1); VdbeCoverage(v);
86933 sqlite3VdbeJumpHere(v, addr1);
86934 if( memRootPage<0 ) sqlite3VdbeAddOp2(v, OP_Clear, tnum, iDb);
86935 sqlite3VdbeAddOp4(v, OP_OpenWrite, iIdx, tnum, iDb,
86936 (char *)pKey, P4_KEYINFO);
86937 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR|((memRootPage>=0)?OPFLAG_P2ISREG:0));
86938
86939 addr1 = sqlite3VdbeAddOp2(v, OP_SorterSort, iSorter, 0); VdbeCoverage(v);
86940 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
86941 if( pIndex->onError!=OE_None && pKey!=0 ){
86942 int j2 = sqlite3VdbeCurrentAddr(v) + 3;
86943 sqlite3VdbeAddOp2(v, OP_Goto, 0, j2);
86944 addr2 = sqlite3VdbeCurrentAddr(v);
86945 sqlite3VdbeAddOp4Int(v, OP_SorterCompare, iSorter, j2, regRecord,
86946 pKey->nField - pIndex->nKeyCol); VdbeCoverage(v);
86947 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
86948 }else{
86949 addr2 = sqlite3VdbeCurrentAddr(v);
86950 }
86951 sqlite3VdbeAddOp2(v, OP_SorterData, iSorter, regRecord);
86952 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 1);
86953 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
86954 sqlite3ReleaseTempReg(pParse, regRecord);
86955 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
86956 sqlite3VdbeJumpHere(v, addr1);
86957
86958 sqlite3VdbeAddOp1(v, OP_Close, iTab);
86959 sqlite3VdbeAddOp1(v, OP_Close, iIdx);
86960 sqlite3VdbeAddOp1(v, OP_Close, iSorter);
@@ -87906,63 +88071,30 @@
88071 }
88072 return 0;
88073 }
88074
88075 /*
88076 ** Record the fact that the schema cookie will need to be verified
88077 ** for database iDb. The code to actually verify the schema cookie
88078 ** will occur at the end of the top-level VDBE and will be generated
88079 ** later, by sqlite3FinishCoding().
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88080 */
88081 SQLITE_PRIVATE void sqlite3CodeVerifySchema(Parse *pParse, int iDb){
88082 Parse *pToplevel = sqlite3ParseToplevel(pParse);
88083 sqlite3 *db = pToplevel->db;
88084 yDbMask mask;
88085
88086 assert( iDb>=0 && iDb<db->nDb );
88087 assert( db->aDb[iDb].pBt!=0 || iDb==1 );
88088 assert( iDb<SQLITE_MAX_ATTACHED+2 );
88089 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
88090 mask = ((yDbMask)1)<<iDb;
88091 if( (pToplevel->cookieMask & mask)==0 ){
88092 pToplevel->cookieMask |= mask;
88093 pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
88094 if( !OMIT_TEMPDB && iDb==1 ){
88095 sqlite3OpenTempDatabase(pToplevel);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88096 }
88097 }
88098 }
88099
88100 /*
@@ -88929,25 +89061,20 @@
89061 SelectDest dest;
89062 Select *pSel;
89063 SrcList *pFrom;
89064 sqlite3 *db = pParse->db;
89065 int iDb = sqlite3SchemaToIndex(db, pView->pSchema);
 
89066 pWhere = sqlite3ExprDup(db, pWhere, 0);
89067 pFrom = sqlite3SrcListAppend(db, 0, 0, 0);
 
89068 if( pFrom ){
89069 assert( pFrom->nSrc==1 );
89070 pFrom->a[0].zName = sqlite3DbStrDup(db, pView->zName);
89071 pFrom->a[0].zDatabase = sqlite3DbStrDup(db, db->aDb[iDb].zName);
89072 assert( pFrom->a[0].pOn==0 );
89073 assert( pFrom->a[0].pUsing==0 );
89074 }
 
89075 pSel = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
 
 
89076 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
89077 sqlite3Select(pParse, pSel, &dest);
89078 sqlite3SelectDelete(db, pSel);
89079 }
89080 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */
@@ -89280,11 +89407,11 @@
89407 }else if( pPk ){
89408 /* Construct a composite key for the row to be deleted and remember it */
89409 iKey = ++pParse->nMem;
89410 nKey = 0; /* Zero tells OP_Found to use a composite key */
89411 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
89412 sqlite3IndexAffinityStr(v, pPk), nPk);
89413 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
89414 }else{
89415 /* Get the rowid of the row to be deleted and remember it in the RowSet */
89416 nKey = 1; /* OP_Seek always uses a single rowid */
89417 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
@@ -89318,17 +89445,19 @@
89445 /* Just one row. Hence the top-of-loop is a no-op */
89446 assert( nKey==nPk ); /* OP_Found will use an unpacked key */
89447 if( aToOpen[iDataCur-iTabCur] ){
89448 assert( pPk!=0 );
89449 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
89450 VdbeCoverage(v);
89451 }
89452 }else if( pPk ){
89453 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
89454 sqlite3VdbeAddOp2(v, OP_RowKey, iEphCur, iKey);
89455 assert( nKey==0 ); /* OP_Found will use a composite key */
89456 }else{
89457 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
89458 VdbeCoverage(v);
89459 assert( nKey==1 );
89460 }
89461
89462 /* Delete the row */
89463 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -89348,11 +89477,11 @@
89477
89478 /* End of the loop over all rowids/primary-keys. */
89479 if( okOnePass ){
89480 sqlite3VdbeResolveLabel(v, addrBypass);
89481 }else if( pPk ){
89482 sqlite3VdbeAddOp2(v, OP_Next, iEphCur, addrLoop+1); VdbeCoverage(v);
89483 sqlite3VdbeJumpHere(v, addrLoop);
89484 }else{
89485 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrLoop);
89486 sqlite3VdbeJumpHere(v, addrLoop);
89487 }
@@ -89446,11 +89575,15 @@
89575 /* Seek cursor iCur to the row to delete. If this row no longer exists
89576 ** (this can happen if a trigger program has already deleted it), do
89577 ** not attempt to delete it or fire any DELETE triggers. */
89578 iLabel = sqlite3VdbeMakeLabel(v);
89579 opSeek = HasRowid(pTab) ? OP_NotExists : OP_NotFound;
89580 if( !bNoSeek ){
89581 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89582 VdbeCoverageIf(v, opSeek==OP_NotExists);
89583 VdbeCoverageIf(v, opSeek==OP_NotFound);
89584 }
89585
89586 /* If there are any triggers to fire, allocate a range of registers to
89587 ** use for the old.* references in the triggers. */
89588 if( sqlite3FkRequired(pParse, pTab, 0, 0) || pTrigger ){
89589 u32 mask; /* Mask of OLD.* columns in use */
@@ -89488,10 +89621,12 @@
89621 ** the cursor or of already deleted the row that the cursor was
89622 ** pointing to.
89623 */
89624 if( addrStart<sqlite3VdbeCurrentAddr(v) ){
89625 sqlite3VdbeAddOp4Int(v, opSeek, iDataCur, iLabel, iPk, nPk);
89626 VdbeCoverageIf(v, opSeek==OP_NotExists);
89627 VdbeCoverageIf(v, opSeek==OP_NotFound);
89628 }
89629
89630 /* Do FK processing. This call checks that any FK constraints that
89631 ** refer to this table (i.e. constraints attached to other tables)
89632 ** are not violated by deleting this row. */
@@ -91745,14 +91880,15 @@
91880 ** Check if any of the key columns in the child table row are NULL. If
91881 ** any are, then the constraint is considered satisfied. No need to
91882 ** search for a matching row in the parent table. */
91883 if( nIncr<0 ){
91884 sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, iOk);
91885 VdbeCoverage(v);
91886 }
91887 for(i=0; i<pFKey->nCol; i++){
91888 int iReg = aiCol[i] + regData + 1;
91889 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iOk); VdbeCoverage(v);
91890 }
91891
91892 if( isIgnore==0 ){
91893 if( pIdx==0 ){
91894 /* If pIdx is NULL, then the parent key is the INTEGER PRIMARY KEY
@@ -91765,21 +91901,23 @@
91901 ** is no matching parent key. Before using MustBeInt, make a copy of
91902 ** the value. Otherwise, the value inserted into the child key column
91903 ** will have INTEGER affinity applied to it, which may not be correct. */
91904 sqlite3VdbeAddOp2(v, OP_SCopy, aiCol[0]+1+regData, regTemp);
91905 iMustBeInt = sqlite3VdbeAddOp2(v, OP_MustBeInt, regTemp, 0);
91906 VdbeCoverage(v);
91907
91908 /* If the parent table is the same as the child table, and we are about
91909 ** to increment the constraint-counter (i.e. this is an INSERT operation),
91910 ** then check if the row being inserted matches itself. If so, do not
91911 ** increment the constraint-counter. */
91912 if( pTab==pFKey->pFrom && nIncr==1 ){
91913 sqlite3VdbeAddOp3(v, OP_Eq, regData, iOk, regTemp); VdbeCoverage(v);
91914 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
91915 }
91916
91917 sqlite3OpenTable(pParse, iCur, iDb, pTab, OP_OpenRead);
91918 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, 0, regTemp); VdbeCoverage(v);
91919 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
91920 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
91921 sqlite3VdbeJumpHere(v, iMustBeInt);
91922 sqlite3ReleaseTempReg(pParse, regTemp);
91923 }else{
@@ -91811,19 +91949,19 @@
91949 assert( aiCol[i]!=pTab->iPKey );
91950 if( pIdx->aiColumn[i]==pTab->iPKey ){
91951 /* The parent key is a composite key that includes the IPK column */
91952 iParent = regData;
91953 }
91954 sqlite3VdbeAddOp3(v, OP_Ne, iChild, iJump, iParent); VdbeCoverage(v);
91955 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
91956 }
91957 sqlite3VdbeAddOp2(v, OP_Goto, 0, iOk);
91958 }
91959
91960 sqlite3VdbeAddOp4(v, OP_MakeRecord, regTemp, nCol, regRec,
91961 sqlite3IndexAffinityStr(v,pIdx), nCol);
91962 sqlite3VdbeAddOp4Int(v, OP_Found, iCur, iOk, regRec, 0); VdbeCoverage(v);
91963
91964 sqlite3ReleaseTempReg(pParse, regRec);
91965 sqlite3ReleaseTempRange(pParse, regTemp, nCol);
91966 }
91967 }
@@ -91957,10 +92095,11 @@
92095 assert( pIdx!=0 || pFKey->nCol==1 );
92096 assert( pIdx!=0 || HasRowid(pTab) );
92097
92098 if( nIncr<0 ){
92099 iFkIfZero = sqlite3VdbeAddOp2(v, OP_FkIfZero, pFKey->isDeferred, 0);
92100 VdbeCoverage(v);
92101 }
92102
92103 /* Create an Expr object representing an SQL expression like:
92104 **
92105 ** <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
@@ -92119,11 +92258,11 @@
92258 for(p=pTab->pFKey; p; p=p->pNextFrom){
92259 if( p->isDeferred || (db->flags & SQLITE_DeferFKs) ) break;
92260 }
92261 if( !p ) return;
92262 iSkip = sqlite3VdbeMakeLabel(v);
92263 sqlite3VdbeAddOp2(v, OP_FkIfZero, 1, iSkip); VdbeCoverage(v);
92264 }
92265
92266 pParse->disableTriggers = 1;
92267 sqlite3DeleteFrom(pParse, sqlite3SrcListDup(db, pName, 0), 0);
92268 pParse->disableTriggers = 0;
@@ -92137,10 +92276,11 @@
92276 ** the statement transaction will not be rolled back even if FK
92277 ** constraints are violated.
92278 */
92279 if( (db->flags & SQLITE_DeferFKs)==0 ){
92280 sqlite3VdbeAddOp2(v, OP_FkIfZero, 0, sqlite3VdbeCurrentAddr(v)+2);
92281 VdbeCoverage(v);
92282 sqlite3HaltConstraint(pParse, SQLITE_CONSTRAINT_FOREIGNKEY,
92283 OE_Abort, 0, P4_STATIC, P5_ConstraintFK);
92284 }
92285
92286 if( iSkip ){
@@ -92296,11 +92436,11 @@
92436 */
92437 Vdbe *v = sqlite3GetVdbe(pParse);
92438 int iJump = sqlite3VdbeCurrentAddr(v) + pFKey->nCol + 1;
92439 for(i=0; i<pFKey->nCol; i++){
92440 int iReg = pFKey->aCol[i].iFrom + regOld + 1;
92441 sqlite3VdbeAddOp2(v, OP_IsNull, iReg, iJump); VdbeCoverage(v);
92442 }
92443 sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, -1);
92444 }
92445 continue;
92446 }
@@ -92863,69 +93003,74 @@
93003
93004 return pIdx->zColAff;
93005 }
93006
93007 /*
93008 ** Compute the affinity string for table pTab, if it has not already been
93009 ** computed. As an optimization, omit trailing SQLITE_AFF_NONE affinities.
93010 **
93011 ** If the affinity exists (if it is no entirely SQLITE_AFF_NONE values and
93012 ** if iReg>0 then code an OP_Affinity opcode that will set the affinities
93013 ** for register iReg and following. Or if affinities exists and iReg==0,
93014 ** then just set the P4 operand of the previous opcode (which should be
93015 ** an OP_MakeRecord) to the affinity string.
93016 **
93017 ** A column affinity string has one character column:
93018 **
93019 ** Character Column affinity
93020 ** ------------------------------
93021 ** 'a' TEXT
93022 ** 'b' NONE
93023 ** 'c' NUMERIC
93024 ** 'd' INTEGER
93025 ** 'e' REAL
93026 */
93027 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe *v, Table *pTab, int iReg){
93028 int i;
93029 char *zColAff = pTab->zColAff;
93030 if( zColAff==0 ){
 
 
 
 
 
 
 
93031 sqlite3 *db = sqlite3VdbeDb(v);
 
93032 zColAff = (char *)sqlite3DbMallocRaw(0, pTab->nCol+1);
93033 if( !zColAff ){
93034 db->mallocFailed = 1;
93035 return;
93036 }
93037
93038 for(i=0; i<pTab->nCol; i++){
93039 zColAff[i] = pTab->aCol[i].affinity;
93040 }
93041 do{
93042 zColAff[i--] = 0;
93043 }while( i>=0 && zColAff[i]==SQLITE_AFF_NONE );
93044 pTab->zColAff = zColAff;
93045 }
93046 i = sqlite3Strlen30(zColAff);
93047 if( i ){
93048 if( iReg ){
93049 sqlite3VdbeAddOp4(v, OP_Affinity, iReg, i, 0, zColAff, i);
93050 }else{
93051 sqlite3VdbeChangeP4(v, -1, zColAff, i);
93052 }
93053 }
93054 }
93055
93056 /*
93057 ** Return non-zero if the table pTab in database iDb or any of its indices
93058 ** have been opened at any point in the VDBE program beginning at location
93059 ** iStartAddr throught the end of the program. This is used to see if
93060 ** a statement of the form "INSERT INTO <iDb, pTab> SELECT ..." can
93061 ** run without using temporary table for the results of the SELECT.
93062 */
93063 static int readsTable(Parse *p, int iDb, Table *pTab){
93064 Vdbe *v = sqlite3GetVdbe(p);
93065 int i;
93066 int iEnd = sqlite3VdbeCurrentAddr(v);
93067 #ifndef SQLITE_OMIT_VIRTUALTABLE
93068 VTable *pVTab = IsVirtual(pTab) ? sqlite3GetVTable(p->db, pTab) : 0;
93069 #endif
93070
93071 for(i=1; i<iEnd; i++){
93072 VdbeOp *pOp = sqlite3VdbeGetOp(v, i);
93073 assert( pOp!=0 );
93074 if( pOp->opcode==OP_OpenRead && pOp->p3==iDb ){
93075 Index *pIndex;
93076 int tnum = pOp->p2;
@@ -93022,18 +93167,18 @@
93167 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
93168 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
93169 sqlite3VdbeAddOp3(v, OP_Null, 0, memId, memId+1);
93170 addr = sqlite3VdbeCurrentAddr(v);
93171 sqlite3VdbeAddOp4(v, OP_String8, 0, memId-1, 0, p->pTab->zName, 0);
93172 sqlite3VdbeAddOp2(v, OP_Rewind, 0, addr+9); VdbeCoverage(v);
93173 sqlite3VdbeAddOp3(v, OP_Column, 0, 0, memId);
93174 sqlite3VdbeAddOp3(v, OP_Ne, memId-1, addr+7, memId); VdbeCoverage(v);
93175 sqlite3VdbeChangeP5(v, SQLITE_JUMPIFNULL);
93176 sqlite3VdbeAddOp2(v, OP_Rowid, 0, memId+1);
93177 sqlite3VdbeAddOp3(v, OP_Column, 0, 1, memId);
93178 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr+9);
93179 sqlite3VdbeAddOp2(v, OP_Next, 0, addr+2); VdbeCoverage(v);
93180 sqlite3VdbeAddOp2(v, OP_Integer, 0, memId);
93181 sqlite3VdbeAddOp0(v, OP_Close);
93182 }
93183 }
93184
@@ -93064,29 +93209,20 @@
93209 sqlite3 *db = pParse->db;
93210
93211 assert( v );
93212 for(p = pParse->pAinc; p; p = p->pNext){
93213 Db *pDb = &db->aDb[p->iDb];
93214 int j1;
93215 int iRec;
93216 int memId = p->regCtr;
93217
93218 iRec = sqlite3GetTempReg(pParse);
93219 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
93220 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
93221 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, memId+1); VdbeCoverage(v);
 
 
 
 
 
93222 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, memId+1);
 
 
 
93223 sqlite3VdbeJumpHere(v, j1);
 
93224 sqlite3VdbeAddOp3(v, OP_MakeRecord, memId-1, 2, iRec);
93225 sqlite3VdbeAddOp3(v, OP_Insert, 0, iRec, memId+1);
93226 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
93227 sqlite3VdbeAddOp0(v, OP_Close);
93228 sqlite3ReleaseTempReg(pParse, iRec);
@@ -93098,101 +93234,10 @@
93234 ** above are all no-ops
93235 */
93236 # define autoIncBegin(A,B,C) (0)
93237 # define autoIncStep(A,B,C)
93238 #endif /* SQLITE_OMIT_AUTOINCREMENT */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93239
93240
93241 /* Forward declaration */
93242 static int xferOptimization(
93243 Parse *pParse, /* Parser context */
@@ -93253,25 +93298,21 @@
93298 **
93299 ** The 3rd template is for when the second template does not apply
93300 ** and the SELECT clause does not read from <table> at any time.
93301 ** The generated code follows this template:
93302 **
 
93303 ** X <- A
93304 ** goto B
93305 ** A: setup for the SELECT
93306 ** loop over the rows in the SELECT
93307 ** load values into registers R..R+n
93308 ** yield X
93309 ** end loop
93310 ** cleanup after the SELECT
93311 ** end-coroutine X
 
 
93312 ** B: open write cursor to <table> and its indices
93313 ** C: yield X, at EOF goto D
 
93314 ** insert the select result into <table> from R..R+n
93315 ** goto C
93316 ** D: cleanup
93317 **
93318 ** The 4th template is used if the insert statement takes its
@@ -93278,25 +93319,21 @@
93319 ** values from a SELECT but the data is being inserted into a table
93320 ** that is also read as part of the SELECT. In the third form,
93321 ** we have to use a intermediate table to store the results of
93322 ** the select. The template is like this:
93323 **
 
93324 ** X <- A
93325 ** goto B
93326 ** A: setup for the SELECT
93327 ** loop over the tables in the SELECT
93328 ** load value into register R..R+n
93329 ** yield X
93330 ** end loop
93331 ** cleanup after the SELECT
93332 ** end co-routine R
 
 
93333 ** B: open temp table
93334 ** L: yield X, at EOF goto M
 
93335 ** insert row from R..R+n into temp table
93336 ** goto L
93337 ** M: open write cursor to <table> and its indices
93338 ** rewind temp table
93339 ** C: loop over rows of intermediate table
@@ -93322,30 +93359,29 @@
93359 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
93360 int iDataCur = 0; /* VDBE cursor that is the main data repository */
93361 int iIdxCur = 0; /* First index cursor */
93362 int ipkColumn = -1; /* Column that is the INTEGER PRIMARY KEY */
93363 int endOfLoop; /* Label for the end of the insertion loop */
 
93364 int srcTab = 0; /* Data comes from this temporary cursor if >=0 */
93365 int addrInsTop = 0; /* Jump to label "D" */
93366 int addrCont = 0; /* Top of insert loop. Label "C" in templates 3 and 4 */
 
93367 SelectDest dest; /* Destination for SELECT on rhs of INSERT */
93368 int iDb; /* Index of database holding TABLE */
93369 Db *pDb; /* The database containing table being inserted into */
93370 u8 useTempTable = 0; /* Store SELECT results in intermediate table */
93371 u8 appendFlag = 0; /* True if the insert is likely to be an append */
93372 u8 withoutRowid; /* 0 for normal table. 1 for WITHOUT ROWID table */
93373 u8 bIdListInOrder = 1; /* True if IDLIST is in table order */
93374 ExprList *pList = 0; /* List of VALUES() to be inserted */
93375
93376 /* Register allocations */
93377 int regFromSelect = 0;/* Base register for data coming from SELECT */
93378 int regAutoinc = 0; /* Register holding the AUTOINCREMENT counter */
93379 int regRowCount = 0; /* Memory cell used for the row counter */
93380 int regIns; /* Block of regs holding rowid+data being inserted */
93381 int regRowid; /* registers holding insert rowid */
93382 int regData; /* register holding first column to insert */
 
93383 int *aRegIdx = 0; /* One register allocated to each index */
93384
93385 #ifndef SQLITE_OMIT_TRIGGER
93386 int isView; /* True if attempting to insert into a view */
93387 Trigger *pTrigger; /* List of triggers on pTab, if required */
@@ -93443,26 +93479,86 @@
93479
93480 /* If this is an AUTOINCREMENT table, look up the sequence number in the
93481 ** sqlite_sequence table and store it in memory cell regAutoinc.
93482 */
93483 regAutoinc = autoIncBegin(pParse, iDb, pTab);
93484
93485 /* Allocate registers for holding the rowid of the new row,
93486 ** the content of the new row, and the assemblied row record.
93487 */
93488 regRowid = regIns = pParse->nMem+1;
93489 pParse->nMem += pTab->nCol + 1;
93490 if( IsVirtual(pTab) ){
93491 regRowid++;
93492 pParse->nMem++;
93493 }
93494 regData = regRowid+1;
93495
93496 /* If the INSERT statement included an IDLIST term, then make sure
93497 ** all elements of the IDLIST really are columns of the table and
93498 ** remember the column indices.
93499 **
93500 ** If the table has an INTEGER PRIMARY KEY column and that column
93501 ** is named in the IDLIST, then record in the ipkColumn variable
93502 ** the index into IDLIST of the primary key column. ipkColumn is
93503 ** the index of the primary key as it appears in IDLIST, not as
93504 ** is appears in the original table. (The index of the INTEGER
93505 ** PRIMARY KEY in the original table is pTab->iPKey.)
93506 */
93507 if( pColumn ){
93508 for(i=0; i<pColumn->nId; i++){
93509 pColumn->a[i].idx = -1;
93510 }
93511 for(i=0; i<pColumn->nId; i++){
93512 for(j=0; j<pTab->nCol; j++){
93513 if( sqlite3StrICmp(pColumn->a[i].zName, pTab->aCol[j].zName)==0 ){
93514 pColumn->a[i].idx = j;
93515 if( i!=j ) bIdListInOrder = 0;
93516 if( j==pTab->iPKey ){
93517 ipkColumn = i; assert( !withoutRowid );
93518 }
93519 break;
93520 }
93521 }
93522 if( j>=pTab->nCol ){
93523 if( sqlite3IsRowid(pColumn->a[i].zName) && !withoutRowid ){
93524 ipkColumn = i;
93525 }else{
93526 sqlite3ErrorMsg(pParse, "table %S has no column named %s",
93527 pTabList, 0, pColumn->a[i].zName);
93528 pParse->checkSchema = 1;
93529 goto insert_cleanup;
93530 }
93531 }
93532 }
93533 }
93534
93535 /* Figure out how many columns of data are supplied. If the data
93536 ** is coming from a SELECT statement, then generate a co-routine that
93537 ** produces a single row of the SELECT on each invocation. The
93538 ** co-routine is the common header to the 3rd and 4th templates.
93539 */
93540 if( pSelect ){
93541 /* Data is coming from a SELECT. Generate a co-routine to run the SELECT */
93542 int regYield; /* Register holding co-routine entry-point */
93543 int addrTop; /* Top of the co-routine */
93544 int rc; /* Result code */
93545
93546 regYield = ++pParse->nMem;
93547 addrTop = sqlite3VdbeCurrentAddr(v) + 1;
93548 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, addrTop);
93549 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
93550 dest.iSdst = bIdListInOrder ? regData : 0;
93551 dest.nSdst = pTab->nCol;
93552 rc = sqlite3Select(pParse, pSelect, &dest);
93553 regFromSelect = dest.iSdst;
93554 assert( pParse->nErr==0 || rc );
93555 if( rc || db->mallocFailed ) goto insert_cleanup;
93556 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regYield);
93557 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
93558 assert( pSelect->pEList );
93559 nColumn = pSelect->pEList->nExpr;
 
93560
93561 /* Set useTempTable to TRUE if the result of the SELECT statement
93562 ** should be written into a temporary table (template 4). Set to
93563 ** FALSE if each output row of the SELECT can be written directly into
93564 ** the destination table (template 3).
@@ -93469,42 +93565,39 @@
93565 **
93566 ** A temp table must be used if the table being updated is also one
93567 ** of the tables being read by the SELECT statement. Also use a
93568 ** temp table in the case of row triggers.
93569 */
93570 if( pTrigger || readsTable(pParse, iDb, pTab) ){
93571 useTempTable = 1;
93572 }
93573
93574 if( useTempTable ){
93575 /* Invoke the coroutine to extract information from the SELECT
93576 ** and add it to a transient table srcTab. The code generated
93577 ** here is from the 4th template:
93578 **
93579 ** B: open temp table
93580 ** L: yield X, goto M at EOF
 
93581 ** insert row from R..R+n into temp table
93582 ** goto L
93583 ** M: ...
93584 */
93585 int regRec; /* Register to hold packed record */
93586 int regTempRowid; /* Register to hold temp table ROWID */
93587 int addrL; /* Label "L" */
 
93588
93589 srcTab = pParse->nTab++;
93590 regRec = sqlite3GetTempReg(pParse);
93591 regTempRowid = sqlite3GetTempReg(pParse);
93592 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, srcTab, nColumn);
93593 addrL = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm); VdbeCoverage(v);
 
93594 sqlite3VdbeAddOp3(v, OP_MakeRecord, regFromSelect, nColumn, regRec);
93595 sqlite3VdbeAddOp2(v, OP_NewRowid, srcTab, regTempRowid);
93596 sqlite3VdbeAddOp3(v, OP_Insert, srcTab, regRec, regTempRowid);
93597 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrL);
93598 sqlite3VdbeJumpHere(v, addrL);
93599 sqlite3ReleaseTempReg(pParse, regRec);
93600 sqlite3ReleaseTempReg(pParse, regTempRowid);
93601 }
93602 }else{
93603 /* This is the case if the data for the INSERT is coming from a VALUES
@@ -93520,10 +93613,18 @@
93613 if( sqlite3ResolveExprNames(&sNC, pList->a[i].pExpr) ){
93614 goto insert_cleanup;
93615 }
93616 }
93617 }
93618
93619 /* If there is no IDLIST term but the table has an integer primary
93620 ** key, the set the ipkColumn variable to the integer primary key
93621 ** column index in the original table definition.
93622 */
93623 if( pColumn==0 && nColumn>0 ){
93624 ipkColumn = pTab->iPKey;
93625 }
93626
93627 /* Make sure the number of columns in the source data matches the number
93628 ** of columns to be inserted into the table.
93629 */
93630 if( IsVirtual(pTab) ){
@@ -93539,56 +93640,10 @@
93640 }
93641 if( pColumn!=0 && nColumn!=pColumn->nId ){
93642 sqlite3ErrorMsg(pParse, "%d values for %d columns", nColumn, pColumn->nId);
93643 goto insert_cleanup;
93644 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93645
93646 /* Initialize the count of rows to be inserted
93647 */
93648 if( db->flags & SQLITE_CountRows ){
93649 regRowCount = ++pParse->nMem;
@@ -93612,42 +93667,30 @@
93667 /* This is the top of the main insertion loop */
93668 if( useTempTable ){
93669 /* This block codes the top of loop only. The complete loop is the
93670 ** following pseudocode (template 4):
93671 **
93672 ** rewind temp table, if empty goto D
93673 ** C: loop over rows of intermediate table
93674 ** transfer values form intermediate table into <table>
93675 ** end loop
93676 ** D: ...
93677 */
93678 addrInsTop = sqlite3VdbeAddOp1(v, OP_Rewind, srcTab); VdbeCoverage(v);
93679 addrCont = sqlite3VdbeCurrentAddr(v);
93680 }else if( pSelect ){
93681 /* This block codes the top of loop only. The complete loop is the
93682 ** following pseudocode (template 3):
93683 **
93684 ** C: yield X, at EOF goto D
 
93685 ** insert the select result into <table> from R..R+n
93686 ** goto C
93687 ** D: ...
93688 */
93689 addrInsTop = addrCont = sqlite3VdbeAddOp1(v, OP_Yield, dest.iSDParm);
93690 VdbeCoverage(v);
93691 }
 
 
 
 
 
 
 
 
 
 
 
93692
93693 /* Run the BEFORE and INSTEAD OF triggers, if there are any
93694 */
93695 endOfLoop = sqlite3VdbeMakeLabel(v);
93696 if( tmask & TRIGGER_BEFORE ){
@@ -93668,14 +93711,14 @@
93711 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regCols);
93712 }else{
93713 assert( pSelect==0 ); /* Otherwise useTempTable is true */
93714 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regCols);
93715 }
93716 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regCols); VdbeCoverage(v);
93717 sqlite3VdbeAddOp2(v, OP_Integer, -1, regCols);
93718 sqlite3VdbeJumpHere(v, j1);
93719 sqlite3VdbeAddOp1(v, OP_MustBeInt, regCols); VdbeCoverage(v);
93720 }
93721
93722 /* Cannot have triggers on a virtual table. If it were possible,
93723 ** this block would have to account for hidden column.
93724 */
@@ -93705,12 +93748,11 @@
93748 ** do not attempt any conversions before assembling the record.
93749 ** If this is a real table, attempt conversions as required by the
93750 ** table column affinities.
93751 */
93752 if( !isView ){
93753 sqlite3TableAffinity(v, pTab, regCols+1);
 
93754 }
93755
93756 /* Fire BEFORE or INSTEAD OF triggers */
93757 sqlite3CodeRowTrigger(pParse, pTrigger, TK_INSERT, 0, TRIGGER_BEFORE,
93758 pTab, regCols-pTab->nCol-1, onError, endOfLoop);
@@ -93728,11 +93770,11 @@
93770 }
93771 if( ipkColumn>=0 ){
93772 if( useTempTable ){
93773 sqlite3VdbeAddOp3(v, OP_Column, srcTab, ipkColumn, regRowid);
93774 }else if( pSelect ){
93775 sqlite3VdbeAddOp2(v, OP_Copy, regFromSelect+ipkColumn, regRowid);
93776 }else{
93777 VdbeOp *pOp;
93778 sqlite3ExprCode(pParse, pList->a[ipkColumn].pExpr, regRowid);
93779 pOp = sqlite3VdbeGetOp(v, -1);
93780 if( ALWAYS(pOp) && pOp->opcode==OP_Null && !IsVirtual(pTab) ){
@@ -93747,18 +93789,18 @@
93789 ** to generate a unique primary key value.
93790 */
93791 if( !appendFlag ){
93792 int j1;
93793 if( !IsVirtual(pTab) ){
93794 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regRowid); VdbeCoverage(v);
93795 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
93796 sqlite3VdbeJumpHere(v, j1);
93797 }else{
93798 j1 = sqlite3VdbeCurrentAddr(v);
93799 sqlite3VdbeAddOp2(v, OP_IsNull, regRowid, j1+2); VdbeCoverage(v);
93800 }
93801 sqlite3VdbeAddOp1(v, OP_MustBeInt, regRowid); VdbeCoverage(v);
93802 }
93803 }else if( IsVirtual(pTab) || withoutRowid ){
93804 sqlite3VdbeAddOp2(v, OP_Null, 0, regRowid);
93805 }else{
93806 sqlite3VdbeAddOp3(v, OP_NewRowid, iDataCur, regRowid, regAutoinc);
@@ -93774,12 +93816,13 @@
93816 int iRegStore = regRowid+1+i;
93817 if( i==pTab->iPKey ){
93818 /* The value of the INTEGER PRIMARY KEY column is always a NULL.
93819 ** Whenever this column is read, the rowid will be substituted
93820 ** in its place. Hence, fill this column with a NULL to avoid
93821 ** taking up data space with information that will never be used.
93822 ** As there may be shallow copies of this value, make it a soft-NULL */
93823 sqlite3VdbeAddOp1(v, OP_SoftNull, iRegStore);
93824 continue;
93825 }
93826 if( pColumn==0 ){
93827 if( IsHiddenColumn(&pTab->aCol[i]) ){
93828 assert( IsVirtual(pTab) );
@@ -93792,15 +93835,17 @@
93835 for(j=0; j<pColumn->nId; j++){
93836 if( pColumn->a[j].idx==i ) break;
93837 }
93838 }
93839 if( j<0 || nColumn==0 || (pColumn && j>=pColumn->nId) ){
93840 sqlite3ExprCodeFactorable(pParse, pTab->aCol[i].pDflt, iRegStore);
93841 }else if( useTempTable ){
93842 sqlite3VdbeAddOp3(v, OP_Column, srcTab, j, iRegStore);
93843 }else if( pSelect ){
93844 if( regFromSelect!=regData ){
93845 sqlite3VdbeAddOp2(v, OP_SCopy, regFromSelect+j, iRegStore);
93846 }
93847 }else{
93848 sqlite3ExprCode(pParse, pList->a[j].pExpr, iRegStore);
93849 }
93850 }
93851
@@ -93842,11 +93887,11 @@
93887 /* The bottom of the main insertion loop, if the data source
93888 ** is a SELECT statement.
93889 */
93890 sqlite3VdbeResolveLabel(v, endOfLoop);
93891 if( useTempTable ){
93892 sqlite3VdbeAddOp2(v, OP_Next, srcTab, addrCont); VdbeCoverage(v);
93893 sqlite3VdbeJumpHere(v, addrInsTop);
93894 sqlite3VdbeAddOp1(v, OP_Close, srcTab);
93895 }else if( pSelect ){
93896 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrCont);
93897 sqlite3VdbeJumpHere(v, addrInsTop);
@@ -94009,10 +94054,11 @@
94054 int seenReplace = 0; /* True if REPLACE is used to resolve INT PK conflict */
94055 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
94056 int ipkTop = 0; /* Top of the rowid change constraint check */
94057 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
94058 u8 isUpdate; /* True if this is an UPDATE operation */
94059 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
94060 int regRowid = -1; /* Register holding ROWID value */
94061
94062 isUpdate = regOldData!=0;
94063 db = pParse->db;
94064 v = sqlite3GetVdbe(pParse);
@@ -94063,19 +94109,21 @@
94109 char *zMsg = sqlite3MPrintf(db, "%s.%s", pTab->zName,
94110 pTab->aCol[i].zName);
94111 sqlite3VdbeAddOp4(v, OP_HaltIfNull, SQLITE_CONSTRAINT_NOTNULL, onError,
94112 regNewData+1+i, zMsg, P4_DYNAMIC);
94113 sqlite3VdbeChangeP5(v, P5_ConstraintNotNull);
94114 VdbeCoverage(v);
94115 break;
94116 }
94117 case OE_Ignore: {
94118 sqlite3VdbeAddOp2(v, OP_IsNull, regNewData+1+i, ignoreDest);
94119 VdbeCoverage(v);
94120 break;
94121 }
94122 default: {
94123 assert( onError==OE_Replace );
94124 j1 = sqlite3VdbeAddOp1(v, OP_NotNull, regNewData+1+i); VdbeCoverage(v);
94125 sqlite3ExprCode(pParse, pTab->aCol[i].pDflt, regNewData+1+i);
94126 sqlite3VdbeJumpHere(v, j1);
94127 break;
94128 }
94129 }
@@ -94123,10 +94171,12 @@
94171 if( isUpdate ){
94172 /* pkChng!=0 does not mean that the rowid has change, only that
94173 ** it might have changed. Skip the conflict logic below if the rowid
94174 ** is unchanged. */
94175 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
94176 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94177 VdbeCoverage(v);
94178 }
94179
94180 /* If the response to a rowid conflict is REPLACE but the response
94181 ** to some other UNIQUE constraint is FAIL or IGNORE, then we need
94182 ** to defer the running of the rowid conflict checking until after
@@ -94142,10 +94192,11 @@
94192 }
94193
94194 /* Check to see if the new rowid already exists in the table. Skip
94195 ** the following conflict logic if it does not. */
94196 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, addrRowidOk, regNewData);
94197 VdbeCoverage(v);
94198
94199 /* Generate code that deals with a rowid collision */
94200 switch( onError ){
94201 default: {
94202 onError = OE_Abort;
@@ -94220,10 +94271,14 @@
94271 int regR; /* Range of registers holding conflicting PK */
94272 int iThisCur; /* Cursor for this UNIQUE index */
94273 int addrUniqueOk; /* Jump here if the UNIQUE constraint is satisfied */
94274
94275 if( aRegIdx[ix]==0 ) continue; /* Skip indices that do not change */
94276 if( bAffinityDone==0 ){
94277 sqlite3TableAffinity(v, pTab, regNewData+1);
94278 bAffinityDone = 1;
94279 }
94280 iThisCur = iIdxCur+ix;
94281 addrUniqueOk = sqlite3VdbeMakeLabel(v);
94282
94283 /* Skip partial indices for which the WHERE clause is not true */
94284 if( pIdx->pPartIdxWhere ){
@@ -94250,11 +94305,10 @@
94305 }
94306 sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx+i);
94307 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
94308 }
94309 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
 
94310 VdbeComment((v, "for %s", pIdx->zName));
94311 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
94312
94313 /* In an UPDATE operation, if this index is the PRIMARY KEY index
94314 ** of a WITHOUT ROWID table and there has been no change the
@@ -94278,11 +94332,11 @@
94332 onError = OE_Abort;
94333 }
94334
94335 /* Check to see if the new index entry will be unique */
94336 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
94337 regIdx, pIdx->nKeyCol); VdbeCoverage(v);
94338
94339 /* Generate code to handle collisions */
94340 regR = (pIdx==pPk) ? regIdx : sqlite3GetTempRange(pParse, nPkField);
94341 if( isUpdate || onError==OE_Replace ){
94342 if( HasRowid(pTab) ){
@@ -94289,10 +94343,12 @@
94343 sqlite3VdbeAddOp2(v, OP_IdxRowid, iThisCur, regR);
94344 /* Conflict only if the rowid of the existing index entry
94345 ** is different from old-rowid */
94346 if( isUpdate ){
94347 sqlite3VdbeAddOp3(v, OP_Eq, regR, addrUniqueOk, regOldData);
94348 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94349 VdbeCoverage(v);
94350 }
94351 }else{
94352 int x;
94353 /* Extract the PRIMARY KEY from the end of the index entry and
94354 ** store it in registers regR..regR+nPk-1 */
@@ -94324,10 +94380,13 @@
94380 op = OP_Eq;
94381 }
94382 sqlite3VdbeAddOp4(v, op,
94383 regOldData+1+x, addrJump, regCmp+i, p4, P4_COLLSEQ
94384 );
94385 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
94386 VdbeCoverageIf(v, op==OP_Eq);
94387 VdbeCoverageIf(v, op==OP_Ne);
94388 }
94389 }
94390 }
94391 }
94392
@@ -94395,18 +94454,21 @@
94454 Index *pIdx; /* An index being inserted or updated */
94455 u8 pik_flags; /* flag values passed to the btree insert */
94456 int regData; /* Content registers (after the rowid) */
94457 int regRec; /* Register holding assemblied record for the table */
94458 int i; /* Loop counter */
94459 u8 bAffinityDone = 0; /* True if OP_Affinity has been run already */
94460
94461 v = sqlite3GetVdbe(pParse);
94462 assert( v!=0 );
94463 assert( pTab->pSelect==0 ); /* This table is not a VIEW */
94464 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
94465 if( aRegIdx[i]==0 ) continue;
94466 bAffinityDone = 1;
94467 if( pIdx->pPartIdxWhere ){
94468 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
94469 VdbeCoverage(v);
94470 }
94471 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
94472 pik_flags = 0;
94473 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
94474 if( pIdx->autoIndex==2 && !HasRowid(pTab) ){
@@ -94417,11 +94479,11 @@
94479 }
94480 if( !HasRowid(pTab) ) return;
94481 regData = regNewData + 1;
94482 regRec = sqlite3GetTempReg(pParse);
94483 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
94484 if( !bAffinityDone ) sqlite3TableAffinity(v, pTab, 0);
94485 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
94486 if( pParse->nested ){
94487 pik_flags = 0;
94488 }else{
94489 pik_flags = OPFLAG_NCHANGE;
@@ -94786,20 +94848,21 @@
94848 ** (2) The destination has a unique index. (The xfer optimization
94849 ** is unable to test uniqueness.)
94850 **
94851 ** (3) onError is something other than OE_Abort and OE_Rollback.
94852 */
94853 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
94854 emptyDestTest = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
94855 sqlite3VdbeJumpHere(v, addr1);
94856 }
94857 if( HasRowid(pSrc) ){
94858 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
94859 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
94860 if( pDest->iPKey>=0 ){
94861 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
94862 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
94863 VdbeCoverage(v);
94864 sqlite3RowidConstraint(pParse, onError, pDest);
94865 sqlite3VdbeJumpHere(v, addr2);
94866 autoIncStep(pParse, regAutoinc, regRowid);
94867 }else if( pDest->pIndex==0 ){
94868 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
@@ -94809,11 +94872,11 @@
94872 }
94873 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
94874 sqlite3VdbeAddOp3(v, OP_Insert, iDest, regData, regRowid);
94875 sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
94876 sqlite3VdbeChangeP4(v, -1, pDest->zName, 0);
94877 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
94878 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94879 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94880 }else{
94881 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
94882 sqlite3TableLock(pParse, iDbSrc, pSrc->tnum, 0, pSrc->zName);
@@ -94828,19 +94891,19 @@
94891 VdbeComment((v, "%s", pSrcIdx->zName));
94892 sqlite3VdbeAddOp3(v, OP_OpenWrite, iDest, pDestIdx->tnum, iDbDest);
94893 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
94894 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
94895 VdbeComment((v, "%s", pDestIdx->zName));
94896 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
94897 sqlite3VdbeAddOp2(v, OP_RowKey, iSrc, regData);
94898 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
94899 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
94900 sqlite3VdbeJumpHere(v, addr1);
94901 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
94902 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
94903 }
94904 if( emptySrcTest ) sqlite3VdbeJumpHere(v, emptySrcTest);
94905 sqlite3ReleaseTempReg(pParse, regRowid);
94906 sqlite3ReleaseTempReg(pParse, regData);
94907 if( emptyDestTest ){
94908 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_OK, 0);
94909 sqlite3VdbeJumpHere(v, emptyDestTest);
@@ -97070,10 +97133,11 @@
97133 ** is always on by default regardless of the sign of the default cache
97134 ** size. But continue to take the absolute value of the default cache
97135 ** size of historical compatibility.
97136 */
97137 case PragTyp_DEFAULT_CACHE_SIZE: {
97138 static const int iLn = __LINE__+2;
97139 static const VdbeOpList getCacheSize[] = {
97140 { OP_Transaction, 0, 0, 0}, /* 0 */
97141 { OP_ReadCookie, 0, 1, BTREE_DEFAULT_CACHE_SIZE}, /* 1 */
97142 { OP_IfPos, 1, 8, 0},
97143 { OP_Integer, 0, 2, 0},
@@ -97087,11 +97151,11 @@
97151 sqlite3VdbeUsesBtree(v, iDb);
97152 if( !zRight ){
97153 sqlite3VdbeSetNumCols(v, 1);
97154 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", SQLITE_STATIC);
97155 pParse->nMem += 2;
97156 addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize,iLn);
97157 sqlite3VdbeChangeP1(v, addr, iDb);
97158 sqlite3VdbeChangeP1(v, addr+1, iDb);
97159 sqlite3VdbeChangeP1(v, addr+6, SQLITE_DEFAULT_CACHE_SIZE);
97160 }else{
97161 int size = sqlite3AbsInt32(sqlite3Atoi(zRight));
@@ -97332,20 +97396,21 @@
97396 /* When setting the auto_vacuum mode to either "full" or
97397 ** "incremental", write the value of meta[6] in the database
97398 ** file. Before writing to meta[6], check that meta[3] indicates
97399 ** that this really is an auto-vacuum capable database.
97400 */
97401 static const int iLn = __LINE__+2;
97402 static const VdbeOpList setMeta6[] = {
97403 { OP_Transaction, 0, 1, 0}, /* 0 */
97404 { OP_ReadCookie, 0, 1, BTREE_LARGEST_ROOT_PAGE},
97405 { OP_If, 1, 0, 0}, /* 2 */
97406 { OP_Halt, SQLITE_OK, OE_Abort, 0}, /* 3 */
97407 { OP_Integer, 0, 1, 0}, /* 4 */
97408 { OP_SetCookie, 0, BTREE_INCR_VACUUM, 1}, /* 5 */
97409 };
97410 int iAddr;
97411 iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6, iLn);
97412 sqlite3VdbeChangeP1(v, iAddr, iDb);
97413 sqlite3VdbeChangeP1(v, iAddr+1, iDb);
97414 sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
97415 sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
97416 sqlite3VdbeChangeP1(v, iAddr+5, iDb);
@@ -97367,14 +97432,14 @@
97432 if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
97433 iLimit = 0x7fffffff;
97434 }
97435 sqlite3BeginWriteOperation(pParse, 0, iDb);
97436 sqlite3VdbeAddOp2(v, OP_Integer, iLimit, 1);
97437 addr = sqlite3VdbeAddOp1(v, OP_IncrVacuum, iDb); VdbeCoverage(v);
97438 sqlite3VdbeAddOp1(v, OP_ResultRow, 1);
97439 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
97440 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr); VdbeCoverage(v);
97441 sqlite3VdbeJumpHere(v, addr);
97442 break;
97443 }
97444 #endif
97445
@@ -97941,11 +98006,11 @@
98006 }
98007 }
98008 assert( pParse->nErr>0 || pFK==0 );
98009 if( pFK ) break;
98010 if( pParse->nTab<i ) pParse->nTab = i;
98011 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, 0); VdbeCoverage(v);
98012 for(i=1, pFK=pTab->pFKey; pFK; i++, pFK=pFK->pNextFrom){
98013 pParent = sqlite3FindTable(db, pFK->zTo, zDb);
98014 pIdx = 0;
98015 aiCols = 0;
98016 if( pParent ){
@@ -97957,30 +98022,30 @@
98022 int iKey = pFK->aCol[0].iFrom;
98023 assert( iKey>=0 && iKey<pTab->nCol );
98024 if( iKey!=pTab->iPKey ){
98025 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
98026 sqlite3ColumnDefault(v, pTab, iKey, regRow);
98027 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
98028 sqlite3VdbeAddOp2(v, OP_MustBeInt, regRow,
98029 sqlite3VdbeCurrentAddr(v)+3); VdbeCoverage(v);
98030 }else{
98031 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
98032 }
98033 sqlite3VdbeAddOp3(v, OP_NotExists, i, 0, regRow); VdbeCoverage(v);
98034 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrOk);
98035 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
98036 }else{
98037 for(j=0; j<pFK->nCol; j++){
98038 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
98039 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
98040 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
98041 }
98042 if( pParent ){
98043 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
98044 sqlite3IndexAffinityStr(v,pIdx), pFK->nCol);
 
98045 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
98046 VdbeCoverage(v);
98047 }
98048 }
98049 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
98050 sqlite3VdbeAddOp4(v, OP_String8, 0, regResult+2, 0,
98051 pFK->zTo, P4_TRANSIENT);
@@ -97987,11 +98052,11 @@
98052 sqlite3VdbeAddOp2(v, OP_Integer, i-1, regResult+3);
98053 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
98054 sqlite3VdbeResolveLabel(v, addrOk);
98055 sqlite3DbFree(db, aiCols);
98056 }
98057 sqlite3VdbeAddOp2(v, OP_Next, 0, addrTop+1); VdbeCoverage(v);
98058 sqlite3VdbeJumpHere(v, addrTop);
98059 }
98060 }
98061 break;
98062 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
@@ -98034,10 +98099,11 @@
98099
98100 /* Code that appears at the end of the integrity check. If no error
98101 ** messages have been generated, output OK. Otherwise output the
98102 ** error message
98103 */
98104 static const int iLn = __LINE__+2;
98105 static const VdbeOpList endCode[] = {
98106 { OP_AddImm, 1, 0, 0}, /* 0 */
98107 { OP_IfNeg, 1, 0, 0}, /* 1 */
98108 { OP_String8, 0, 3, 0}, /* 2 */
98109 { OP_ResultRow, 3, 1, 0},
@@ -98082,10 +98148,11 @@
98148 if( OMIT_TEMPDB && i==1 ) continue;
98149 if( iDb>=0 && i!=iDb ) continue;
98150
98151 sqlite3CodeVerifySchema(pParse, i);
98152 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Halt if out of errors */
98153 VdbeCoverage(v);
98154 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98155 sqlite3VdbeJumpHere(v, addr);
98156
98157 /* Do an integrity check of the B-Tree
98158 **
@@ -98113,11 +98180,11 @@
98180 pParse->nMem = MAX( pParse->nMem, cnt+8 );
98181
98182 /* Do the b-tree integrity checks */
98183 sqlite3VdbeAddOp3(v, OP_IntegrityCk, 2, cnt, 1);
98184 sqlite3VdbeChangeP5(v, (u8)i);
98185 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
98186 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
98187 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
98188 P4_DYNAMIC);
98189 sqlite3VdbeAddOp2(v, OP_Move, 2, 4);
98190 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
@@ -98135,10 +98202,11 @@
98202 int r1 = -1;
98203
98204 if( pTab->pIndex==0 ) continue;
98205 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
98206 addr = sqlite3VdbeAddOp1(v, OP_IfPos, 1); /* Stop if out of errors */
98207 VdbeCoverage(v);
98208 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98209 sqlite3VdbeJumpHere(v, addr);
98210 sqlite3ExprCacheClear(pParse);
98211 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead,
98212 1, 0, &iDataCur, &iIdxCur);
@@ -98145,57 +98213,58 @@
98213 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
98214 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98215 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
98216 }
98217 pParse->nMem = MAX(pParse->nMem, 8+j);
98218 sqlite3VdbeAddOp2(v, OP_Rewind, iDataCur, 0); VdbeCoverage(v);
98219 loopTop = sqlite3VdbeAddOp2(v, OP_AddImm, 7, 1);
98220 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98221 int jmp2, jmp3, jmp4;
98222 if( pPk==pIdx ) continue;
98223 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
98224 pPrior, r1);
98225 pPrior = pIdx;
98226 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
98227 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, 0, r1,
98228 pIdx->nColumn); VdbeCoverage(v);
98229 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1); /* Decrement error limit */
98230 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, "row ", P4_STATIC);
98231 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
98232 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, " missing from index ",
98233 P4_STATIC);
98234 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98235 sqlite3VdbeAddOp4(v, OP_String8, 0, 4, 0, pIdx->zName, P4_TRANSIENT);
98236 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
98237 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
98238 jmp4 = sqlite3VdbeAddOp1(v, OP_IfPos, 1); VdbeCoverage(v);
98239 sqlite3VdbeAddOp0(v, OP_Halt);
98240 sqlite3VdbeJumpHere(v, jmp4);
98241 sqlite3VdbeJumpHere(v, jmp2);
98242 sqlite3VdbeResolveLabel(v, jmp3);
98243 }
98244 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
98245 sqlite3VdbeJumpHere(v, loopTop-1);
98246 #ifndef SQLITE_OMIT_BTREECOUNT
98247 sqlite3VdbeAddOp4(v, OP_String8, 0, 2, 0,
98248 "wrong # of entries in index ", P4_STATIC);
98249 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
98250 if( pPk==pIdx ) continue;
98251 addr = sqlite3VdbeCurrentAddr(v);
98252 sqlite3VdbeAddOp2(v, OP_IfPos, 1, addr+2); VdbeCoverage(v);
98253 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
98254 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
98255 sqlite3VdbeAddOp3(v, OP_Eq, 8+j, addr+8, 3); VdbeCoverage(v);
98256 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
98257 sqlite3VdbeAddOp2(v, OP_AddImm, 1, -1);
98258 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, pIdx->zName, P4_TRANSIENT);
98259 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
98260 sqlite3VdbeAddOp2(v, OP_ResultRow, 7, 1);
98261 }
98262 #endif /* SQLITE_OMIT_BTREECOUNT */
98263 }
98264 }
98265 addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
98266 sqlite3VdbeChangeP2(v, addr, -mxErr);
98267 sqlite3VdbeJumpHere(v, addr+1);
98268 sqlite3VdbeChangeP4(v, addr+2, "ok", P4_STATIC);
98269 }
98270 break;
@@ -98329,11 +98398,11 @@
98398 static const VdbeOpList setCookie[] = {
98399 { OP_Transaction, 0, 1, 0}, /* 0 */
98400 { OP_Integer, 0, 1, 0}, /* 1 */
98401 { OP_SetCookie, 0, 0, 1}, /* 2 */
98402 };
98403 int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie, 0);
98404 sqlite3VdbeChangeP1(v, addr, iDb);
98405 sqlite3VdbeChangeP1(v, addr+1, sqlite3Atoi(zRight));
98406 sqlite3VdbeChangeP1(v, addr+2, iDb);
98407 sqlite3VdbeChangeP2(v, addr+2, iCookie);
98408 }else{
@@ -98341,11 +98410,11 @@
98410 static const VdbeOpList readCookie[] = {
98411 { OP_Transaction, 0, 0, 0}, /* 0 */
98412 { OP_ReadCookie, 0, 1, 0}, /* 1 */
98413 { OP_ResultRow, 1, 1, 0}
98414 };
98415 int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie, 0);
98416 sqlite3VdbeChangeP1(v, addr, iDb);
98417 sqlite3VdbeChangeP1(v, addr+1, iDb);
98418 sqlite3VdbeChangeP3(v, addr+1, iCookie);
98419 sqlite3VdbeSetNumCols(v, 1);
98420 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
@@ -99547,10 +99616,18 @@
99616 if( p ){
99617 clearSelect(db, p);
99618 sqlite3DbFree(db, p);
99619 }
99620 }
99621
99622 /*
99623 ** Return a pointer to the right-most SELECT statement in a compound.
99624 */
99625 static Select *findRightmost(Select *p){
99626 while( p->pNext ) p = p->pNext;
99627 return p;
99628 }
99629
99630 /*
99631 ** Given 1 to 3 identifiers preceding the JOIN keyword, determine the
99632 ** type of join. Return an integer constant that expresses that type
99633 ** in terms of the following bit values:
@@ -99886,11 +99963,11 @@
99963 if( pSelect->iOffset ){
99964 iLimit = pSelect->iOffset+1;
99965 }else{
99966 iLimit = pSelect->iLimit;
99967 }
99968 addr1 = sqlite3VdbeAddOp1(v, OP_IfZero, iLimit); VdbeCoverage(v);
99969 sqlite3VdbeAddOp2(v, OP_AddImm, iLimit, -1);
99970 addr2 = sqlite3VdbeAddOp0(v, OP_Goto);
99971 sqlite3VdbeJumpHere(v, addr1);
99972 sqlite3VdbeAddOp1(v, OP_Last, pOrderBy->iECursor);
99973 sqlite3VdbeAddOp1(v, OP_Delete, pOrderBy->iECursor);
@@ -99907,11 +99984,11 @@
99984 int iContinue /* Jump here to skip the current record */
99985 ){
99986 if( iOffset>0 && iContinue!=0 ){
99987 int addr;
99988 sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
99989 addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset); VdbeCoverage(v);
99990 sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
99991 VdbeComment((v, "skip OFFSET records"));
99992 sqlite3VdbeJumpHere(v, addr);
99993 }
99994 }
@@ -99935,11 +100012,11 @@
100012 Vdbe *v;
100013 int r1;
100014
100015 v = pParse->pVdbe;
100016 r1 = sqlite3GetTempReg(pParse);
100017 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
100018 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
100019 sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
100020 sqlite3ReleaseTempReg(pParse, r1);
100021 }
100022
@@ -100016,17 +100093,23 @@
100093 }
100094
100095 /* Pull the requested columns.
100096 */
100097 nResultCol = pEList->nExpr;
100098
100099 if( pDest->iSdst==0 ){
100100 pDest->iSdst = pParse->nMem+1;
100101 pParse->nMem += nResultCol;
100102 }else if( pDest->iSdst+nResultCol > pParse->nMem ){
100103 /* This is an error condition that can result, for example, when a SELECT
100104 ** on the right-hand side of an INSERT contains more result columns than
100105 ** there are columns in the table on the left. The error will be caught
100106 ** and reported later. But we need to make sure enough memory is allocated
100107 ** to avoid other spurious errors in the meantime. */
100108 pParse->nMem += nResultCol;
 
 
100109 }
100110 pDest->nSdst = nResultCol;
100111 regResult = pDest->iSdst;
100112 if( srcTab>=0 ){
100113 for(i=0; i<nResultCol; i++){
100114 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
100115 VdbeComment((v, "%s", pEList->a[i].zName));
@@ -100069,13 +100152,15 @@
100152 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
100153 for(i=0; i<nResultCol; i++){
100154 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100155 if( i<nResultCol-1 ){
100156 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
100157 VdbeCoverage(v);
100158 }else{
100159 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100160 VdbeCoverage(v);
100161 }
100162 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100163 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100164 }
100165 assert( sqlite3VdbeCurrentAddr(v)==iJump );
100166 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
@@ -100137,11 +100222,11 @@
100222 ** on an ephemeral index. If the current row is already present
100223 ** in the index, do not write it to the output. If not, add the
100224 ** current row to the index and proceed with writing it to the
100225 ** output table as well. */
100226 int addr = sqlite3VdbeCurrentAddr(v) + 4;
100227 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0); VdbeCoverage(v);
100228 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
100229 assert( pOrderBy==0 );
100230 }
100231 #endif
100232 if( pOrderBy ){
@@ -100204,16 +100289,12 @@
100289 }
100290 break;
100291 }
100292 #endif /* #ifndef SQLITE_OMIT_SUBQUERY */
100293
100294 case SRT_Coroutine: /* Send data to a co-routine */
100295 case SRT_Output: { /* Return the results */
 
 
 
 
100296 testcase( eDest==SRT_Coroutine );
100297 testcase( eDest==SRT_Output );
100298 if( pOrderBy ){
100299 int r1 = sqlite3GetTempReg(pParse);
100300 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
@@ -100245,17 +100326,20 @@
100326 assert( pSO );
100327 nKey = pSO->nExpr;
100328 r1 = sqlite3GetTempReg(pParse);
100329 r2 = sqlite3GetTempRange(pParse, nKey+2);
100330 r3 = r2+nKey+1;
 
100331 if( eDest==SRT_DistQueue ){
100332 /* If the destination is DistQueue, then cursor (iParm+1) is open
100333 ** on a second ephemeral index that holds all values every previously
100334 ** added to the queue. */
100335 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0,
100336 regResult, nResultCol);
100337 VdbeCoverage(v);
100338 }
100339 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100340 if( eDest==SRT_DistQueue ){
100341 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
100342 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
100343 }
100344 for(i=0; i<nKey; i++){
100345 sqlite3VdbeAddOp2(v, OP_SCopy,
@@ -100290,11 +100374,11 @@
100374 /* Jump to the end of the loop if the LIMIT is reached. Except, if
100375 ** there is a sorter, in which case the sorter has already limited
100376 ** the output for us.
100377 */
100378 if( pOrderBy==0 && p->iLimit ){
100379 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
100380 }
100381 }
100382
100383 /*
100384 ** Allocate a KeyInfo object sufficient for an index of N key columns and
@@ -100509,16 +100593,17 @@
100593 if( p->selFlags & SF_UseSorter ){
100594 int regSortOut = ++pParse->nMem;
100595 int ptab2 = pParse->nTab++;
100596 sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100597 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
100598 VdbeCoverage(v);
100599 codeOffset(v, p->iOffset, addrContinue);
100600 sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100601 sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100602 sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100603 }else{
100604 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
100605 codeOffset(v, p->iOffset, addrContinue);
100606 sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100607 }
100608 switch( eDest ){
100609 case SRT_Table:
@@ -100572,13 +100657,13 @@
100657
100658 /* The bottom of the loop
100659 */
100660 sqlite3VdbeResolveLabel(v, addrContinue);
100661 if( p->selFlags & SF_UseSorter ){
100662 sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
100663 }else{
100664 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
100665 }
100666 sqlite3VdbeResolveLabel(v, addrBreak);
100667 if( eDest==SRT_Output || eDest==SRT_Coroutine ){
100668 sqlite3VdbeAddOp2(v, OP_Close, pseudoTab, 0);
100669 }
@@ -101058,15 +101143,17 @@
101143 */
101144 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
101145 Vdbe *v = pParse->pVdbe;
101146 if( v==0 ){
101147 v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
101148 if( v ) sqlite3VdbeAddOp0(v, OP_Init);
101149 if( pParse->pToplevel==0
101150 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
101151 ){
101152 pParse->okConstFactor = 1;
101153 }
101154
101155 }
101156 return v;
101157 }
101158
101159
@@ -101120,26 +101207,26 @@
101207 }else if( n>=0 && p->nSelectRow>(u64)n ){
101208 p->nSelectRow = n;
101209 }
101210 }else{
101211 sqlite3ExprCode(pParse, p->pLimit, iLimit);
101212 sqlite3VdbeAddOp1(v, OP_MustBeInt, iLimit); VdbeCoverage(v);
101213 VdbeComment((v, "LIMIT counter"));
101214 sqlite3VdbeAddOp2(v, OP_IfZero, iLimit, iBreak); VdbeCoverage(v);
101215 }
101216 if( p->pOffset ){
101217 p->iOffset = iOffset = ++pParse->nMem;
101218 pParse->nMem++; /* Allocate an extra register for limit+offset */
101219 sqlite3ExprCode(pParse, p->pOffset, iOffset);
101220 sqlite3VdbeAddOp1(v, OP_MustBeInt, iOffset); VdbeCoverage(v);
101221 VdbeComment((v, "OFFSET counter"));
101222 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iOffset); VdbeCoverage(v);
101223 sqlite3VdbeAddOp2(v, OP_Integer, 0, iOffset);
101224 sqlite3VdbeJumpHere(v, addr1);
101225 sqlite3VdbeAddOp3(v, OP_Add, iLimit, iOffset, iOffset+1);
101226 VdbeComment((v, "LIMIT+OFFSET"));
101227 addr1 = sqlite3VdbeAddOp1(v, OP_IfPos, iLimit); VdbeCoverage(v);
101228 sqlite3VdbeAddOp2(v, OP_Integer, -1, iOffset+1);
101229 sqlite3VdbeJumpHere(v, addr1);
101230 }
101231 }
101232 }
@@ -101318,15 +101405,17 @@
101405
101406 /* Detach the ORDER BY clause from the compound SELECT */
101407 p->pOrderBy = 0;
101408
101409 /* Store the results of the setup-query in Queue. */
101410 pSetup->pNext = 0;
101411 rc = sqlite3Select(pParse, pSetup, &destQueue);
101412 pSetup->pNext = p;
101413 if( rc ) goto end_of_recursive_query;
101414
101415 /* Find the next row in the Queue and output that row */
101416 addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak); VdbeCoverage(v);
101417
101418 /* Transfer the next row in Queue over to Current */
101419 sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
101420 if( pOrderBy ){
101421 sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
@@ -101338,11 +101427,14 @@
101427 /* Output the single row in Current */
101428 addrCont = sqlite3VdbeMakeLabel(v);
101429 codeOffset(v, regOffset, addrCont);
101430 selectInnerLoop(pParse, p, p->pEList, iCurrent,
101431 0, 0, pDest, addrCont, addrBreak);
101432 if( regLimit ){
101433 sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
101434 VdbeCoverage(v);
101435 }
101436 sqlite3VdbeResolveLabel(v, addrCont);
101437
101438 /* Execute the recursive SELECT taking the single row in Current as
101439 ** the value for the recursive-table. Store the results in the Queue.
101440 */
@@ -101423,12 +101515,10 @@
101515 */
101516 assert( p && p->pPrior ); /* Calling function guarantees this much */
101517 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
101518 db = pParse->db;
101519 pPrior = p->pPrior;
 
 
101520 dest = *pDest;
101521 if( pPrior->pOrderBy ){
101522 sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
101523 selectOpName(p->op));
101524 rc = 1;
@@ -101500,11 +101590,11 @@
101590 }
101591 p->pPrior = 0;
101592 p->iLimit = pPrior->iLimit;
101593 p->iOffset = pPrior->iOffset;
101594 if( p->iLimit ){
101595 addr = sqlite3VdbeAddOp1(v, OP_IfZero, p->iLimit); VdbeCoverage(v);
101596 VdbeComment((v, "Jump ahead if LIMIT reached"));
101597 }
101598 explainSetInteger(iSub2, pParse->iNextSelectId);
101599 rc = sqlite3Select(pParse, p, &dest);
101600 testcase( rc!=SQLITE_OK );
@@ -101532,16 +101622,14 @@
101622 SelectDest uniondest;
101623
101624 testcase( p->op==TK_EXCEPT );
101625 testcase( p->op==TK_UNION );
101626 priorOp = SRT_Union;
101627 if( dest.eDest==priorOp ){
101628 /* We can reuse a temporary table generated by a SELECT to our
101629 ** right.
101630 */
 
 
101631 assert( p->pLimit==0 ); /* Not allowed on leftward elements */
101632 assert( p->pOffset==0 ); /* Not allowed on leftward elements */
101633 unionTab = dest.iSDParm;
101634 }else{
101635 /* We will need to create our own temporary table to hold the
@@ -101550,11 +101638,11 @@
101638 unionTab = pParse->nTab++;
101639 assert( p->pOrderBy==0 );
101640 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, unionTab, 0);
101641 assert( p->addrOpenEphm[0] == -1 );
101642 p->addrOpenEphm[0] = addr;
101643 findRightmost(p)->selFlags |= SF_UsesEphemeral;
101644 assert( p->pEList );
101645 }
101646
101647 /* Code the SELECT statements to our left
101648 */
@@ -101609,16 +101697,16 @@
101697 generateColumnNames(pParse, 0, pFirst->pEList);
101698 }
101699 iBreak = sqlite3VdbeMakeLabel(v);
101700 iCont = sqlite3VdbeMakeLabel(v);
101701 computeLimitRegisters(pParse, p, iBreak);
101702 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
101703 iStart = sqlite3VdbeCurrentAddr(v);
101704 selectInnerLoop(pParse, p, p->pEList, unionTab,
101705 0, 0, &dest, iCont, iBreak);
101706 sqlite3VdbeResolveLabel(v, iCont);
101707 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
101708 sqlite3VdbeResolveLabel(v, iBreak);
101709 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
101710 }
101711 break;
101712 }
@@ -101639,11 +101727,11 @@
101727 assert( p->pOrderBy==0 );
101728
101729 addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tab1, 0);
101730 assert( p->addrOpenEphm[0] == -1 );
101731 p->addrOpenEphm[0] = addr;
101732 findRightmost(p)->selFlags |= SF_UsesEphemeral;
101733 assert( p->pEList );
101734
101735 /* Code the SELECTs to our left into temporary table "tab1".
101736 */
101737 sqlite3SelectDestInit(&intersectdest, SRT_Union, tab1);
@@ -101684,19 +101772,19 @@
101772 generateColumnNames(pParse, 0, pFirst->pEList);
101773 }
101774 iBreak = sqlite3VdbeMakeLabel(v);
101775 iCont = sqlite3VdbeMakeLabel(v);
101776 computeLimitRegisters(pParse, p, iBreak);
101777 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
101778 r1 = sqlite3GetTempReg(pParse);
101779 iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101780 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
101781 sqlite3ReleaseTempReg(pParse, r1);
101782 selectInnerLoop(pParse, p, p->pEList, tab1,
101783 0, 0, &dest, iCont, iBreak);
101784 sqlite3VdbeResolveLabel(v, iCont);
101785 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
101786 sqlite3VdbeResolveLabel(v, iBreak);
101787 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
101788 sqlite3VdbeAddOp2(v, OP_Close, tab1, 0);
101789 break;
101790 }
@@ -101718,11 +101806,11 @@
101806 KeyInfo *pKeyInfo; /* Collating sequence for the result set */
101807 Select *pLoop; /* For looping through SELECT statements */
101808 CollSeq **apColl; /* For looping through pKeyInfo->aColl[] */
101809 int nCol; /* Number of columns in result set */
101810
101811 assert( p->pNext==0 );
101812 nCol = p->pEList->nExpr;
101813 pKeyInfo = sqlite3KeyInfoAlloc(db, nCol, 1);
101814 if( !pKeyInfo ){
101815 rc = SQLITE_NOMEM;
101816 goto multi_select_end;
@@ -101799,14 +101887,14 @@
101887
101888 /* Suppress duplicates for UNION, EXCEPT, and INTERSECT
101889 */
101890 if( regPrev ){
101891 int j1, j2;
101892 j1 = sqlite3VdbeAddOp1(v, OP_IfNot, regPrev); VdbeCoverage(v);
101893 j2 = sqlite3VdbeAddOp4(v, OP_Compare, pIn->iSdst, regPrev+1, pIn->nSdst,
101894 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
101895 sqlite3VdbeAddOp3(v, OP_Jump, j2+2, iContinue, j2+2); VdbeCoverage(v);
101896 sqlite3VdbeJumpHere(v, j1);
101897 sqlite3VdbeAddOp3(v, OP_Copy, pIn->iSdst, regPrev+1, pIn->nSdst-1);
101898 sqlite3VdbeAddOp2(v, OP_Integer, 1, regPrev);
101899 }
101900 if( pParse->db->mallocFailed ) return 0;
@@ -101903,11 +101991,11 @@
101991 }
101992
101993 /* Jump to the end of the loop if the LIMIT is reached.
101994 */
101995 if( p->iLimit ){
101996 sqlite3VdbeAddOp3(v, OP_IfZero, p->iLimit, iBreak, -1); VdbeCoverage(v);
101997 }
101998
101999 /* Generate the subroutine return
102000 */
102001 sqlite3VdbeResolveLabel(v, iContinue);
@@ -102011,20 +102099,19 @@
102099 Select *pPrior; /* Another SELECT immediately to our left */
102100 Vdbe *v; /* Generate code to this VDBE */
102101 SelectDest destA; /* Destination for coroutine A */
102102 SelectDest destB; /* Destination for coroutine B */
102103 int regAddrA; /* Address register for select-A coroutine */
 
102104 int regAddrB; /* Address register for select-B coroutine */
 
102105 int addrSelectA; /* Address of the select-A coroutine */
102106 int addrSelectB; /* Address of the select-B coroutine */
102107 int regOutA; /* Address register for the output-A subroutine */
102108 int regOutB; /* Address register for the output-B subroutine */
102109 int addrOutA; /* Address of the output-A subroutine */
102110 int addrOutB = 0; /* Address of the output-B subroutine */
102111 int addrEofA; /* Address of the select-A-exhausted subroutine */
102112 int addrEofA_noB; /* Alternate addrEofA if B is uninitialized */
102113 int addrEofB; /* Address of the select-B-exhausted subroutine */
102114 int addrAltB; /* Address of the A<B subroutine */
102115 int addrAeqB; /* Address of the A==B subroutine */
102116 int addrAgtB; /* Address of the A>B subroutine */
102117 int regLimitA; /* Limit register for select-A */
@@ -102135,10 +102222,11 @@
102222 }
102223
102224 /* Separate the left and the right query from one another
102225 */
102226 p->pPrior = 0;
102227 pPrior->pNext = 0;
102228 sqlite3ResolveOrderGroupBy(pParse, p, p->pOrderBy, "ORDER");
102229 if( pPrior->pPrior==0 ){
102230 sqlite3ResolveOrderGroupBy(pParse, pPrior, pPrior->pOrderBy, "ORDER");
102231 }
102232
@@ -102157,52 +102245,43 @@
102245 p->pLimit = 0;
102246 sqlite3ExprDelete(db, p->pOffset);
102247 p->pOffset = 0;
102248
102249 regAddrA = ++pParse->nMem;
 
102250 regAddrB = ++pParse->nMem;
 
102251 regOutA = ++pParse->nMem;
102252 regOutB = ++pParse->nMem;
102253 sqlite3SelectDestInit(&destA, SRT_Coroutine, regAddrA);
102254 sqlite3SelectDestInit(&destB, SRT_Coroutine, regAddrB);
 
 
 
 
 
 
 
102255
102256 /* Generate a coroutine to evaluate the SELECT statement to the
102257 ** left of the compound operator - the "A" select.
102258 */
102259 addrSelectA = sqlite3VdbeCurrentAddr(v) + 1;
102260 j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrA, 0, addrSelectA);
102261 VdbeComment((v, "left SELECT"));
102262 pPrior->iLimit = regLimitA;
102263 explainSetInteger(iSub1, pParse->iNextSelectId);
102264 sqlite3Select(pParse, pPrior, &destA);
102265 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrA);
102266 sqlite3VdbeJumpHere(v, j1);
 
102267
102268 /* Generate a coroutine to evaluate the SELECT statement on
102269 ** the right - the "B" select
102270 */
102271 addrSelectB = sqlite3VdbeCurrentAddr(v) + 1;
102272 j1 = sqlite3VdbeAddOp3(v, OP_InitCoroutine, regAddrB, 0, addrSelectB);
102273 VdbeComment((v, "right SELECT"));
102274 savedLimit = p->iLimit;
102275 savedOffset = p->iOffset;
102276 p->iLimit = regLimitB;
102277 p->iOffset = 0;
102278 explainSetInteger(iSub2, pParse->iNextSelectId);
102279 sqlite3Select(pParse, p, &destB);
102280 p->iLimit = savedLimit;
102281 p->iOffset = savedOffset;
102282 sqlite3VdbeAddOp1(v, OP_EndCoroutine, regAddrB);
 
 
102283
102284 /* Generate a subroutine that outputs the current row of the A
102285 ** select as the next output row of the compound select.
102286 */
102287 VdbeNoopComment((v, "Output routine for A"));
@@ -102222,17 +102301,17 @@
102301 sqlite3KeyInfoUnref(pKeyDup);
102302
102303 /* Generate a subroutine to run when the results from select A
102304 ** are exhausted and only data in select B remains.
102305 */
 
102306 if( op==TK_EXCEPT || op==TK_INTERSECT ){
102307 addrEofA_noB = addrEofA = labelEnd;
102308 }else{
102309 VdbeNoopComment((v, "eof-A subroutine"));
102310 addrEofA = sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102311 addrEofA_noB = sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, labelEnd);
102312 VdbeCoverage(v);
102313 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofA);
102314 p->nSelectRow += pPrior->nSelectRow;
102315 }
102316
102317 /* Generate a subroutine to run when the results from select B
@@ -102241,22 +102320,20 @@
102320 if( op==TK_INTERSECT ){
102321 addrEofB = addrEofA;
102322 if( p->nSelectRow > pPrior->nSelectRow ) p->nSelectRow = pPrior->nSelectRow;
102323 }else{
102324 VdbeNoopComment((v, "eof-B subroutine"));
102325 addrEofB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102326 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, labelEnd); VdbeCoverage(v);
 
102327 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrEofB);
102328 }
102329
102330 /* Generate code to handle the case of A<B
102331 */
102332 VdbeNoopComment((v, "A-lt-B subroutine"));
102333 addrAltB = sqlite3VdbeAddOp2(v, OP_Gosub, regOutA, addrOutA);
102334 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
 
102335 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102336
102337 /* Generate code to handle the case of A==B
102338 */
102339 if( op==TK_ALL ){
@@ -102265,12 +102342,11 @@
102342 addrAeqB = addrAltB;
102343 addrAltB++;
102344 }else{
102345 VdbeNoopComment((v, "A-eq-B subroutine"));
102346 addrAeqB =
102347 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA); VdbeCoverage(v);
 
102348 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102349 }
102350
102351 /* Generate code to handle the case of A>B
102352 */
@@ -102277,32 +102353,27 @@
102353 VdbeNoopComment((v, "A-gt-B subroutine"));
102354 addrAgtB = sqlite3VdbeCurrentAddr(v);
102355 if( op==TK_ALL || op==TK_UNION ){
102356 sqlite3VdbeAddOp2(v, OP_Gosub, regOutB, addrOutB);
102357 }
102358 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
 
102359 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelCmpr);
102360
102361 /* This code runs once to initialize everything.
102362 */
102363 sqlite3VdbeJumpHere(v, j1);
102364 sqlite3VdbeAddOp2(v, OP_Yield, regAddrA, addrEofA_noB); VdbeCoverage(v);
102365 sqlite3VdbeAddOp2(v, OP_Yield, regAddrB, addrEofB); VdbeCoverage(v);
 
 
 
 
102366
102367 /* Implement the main merge loop
102368 */
102369 sqlite3VdbeResolveLabel(v, labelCmpr);
102370 sqlite3VdbeAddOp4(v, OP_Permutation, 0, 0, 0, (char*)aPermute, P4_INTARRAY);
102371 sqlite3VdbeAddOp4(v, OP_Compare, destA.iSdst, destB.iSdst, nOrderBy,
102372 (char*)pKeyMerge, P4_KEYINFO);
102373 sqlite3VdbeChangeP5(v, OPFLAG_PERMUTE);
102374 sqlite3VdbeAddOp3(v, OP_Jump, addrAltB, addrAeqB, addrAgtB); VdbeCoverage(v);
102375
102376 /* Jump to the this point in order to terminate the query.
102377 */
102378 sqlite3VdbeResolveLabel(v, labelEnd);
102379
@@ -102318,10 +102389,11 @@
102389 ** by the calling function */
102390 if( p->pPrior ){
102391 sqlite3SelectDelete(db, p->pPrior);
102392 }
102393 p->pPrior = pPrior;
102394 pPrior->pNext = p;
102395
102396 /*** TBD: Insert subroutine calls to close cursors on incomplete
102397 **** subqueries ****/
102398 explainComposite(pParse, p->op, iSub1, iSub2, 0);
102399 return SQLITE_OK;
@@ -102583,11 +102655,11 @@
102655 ** because they could be computed at compile-time. But when LIMIT and OFFSET
102656 ** became arbitrary expressions, we were forced to add restrictions (13)
102657 ** and (14). */
102658 if( pSub->pLimit && p->pLimit ) return 0; /* Restriction (13) */
102659 if( pSub->pOffset ) return 0; /* Restriction (14) */
102660 if( (p->selFlags & SF_Compound)!=0 && pSub->pLimit ){
102661 return 0; /* Restriction (15) */
102662 }
102663 if( pSubSrc->nSrc==0 ) return 0; /* Restriction (7) */
102664 if( pSub->selFlags & SF_Distinct ) return 0; /* Restriction (5) */
102665 if( pSub->pLimit && (pSrc->nSrc>1 || isAgg) ){
@@ -102734,18 +102806,18 @@
102806 p->pOffset = pOffset;
102807 p->pLimit = pLimit;
102808 p->pOrderBy = pOrderBy;
102809 p->pSrc = pSrc;
102810 p->op = TK_ALL;
 
102811 if( pNew==0 ){
102812 p->pPrior = pPrior;
102813 }else{
102814 pNew->pPrior = pPrior;
102815 if( pPrior ) pPrior->pNext = pNew;
102816 pNew->pNext = p;
102817 p->pPrior = pNew;
102818 }
 
102819 if( db->mallocFailed ) return 1;
102820 }
102821
102822 /* Begin flattening the iFrom-th entry of the FROM clause
102823 ** in the outer query.
@@ -103080,10 +103152,14 @@
103152 p->pWhere = 0;
103153 pNew->pGroupBy = 0;
103154 pNew->pHaving = 0;
103155 pNew->pOrderBy = 0;
103156 p->pPrior = 0;
103157 p->pNext = 0;
103158 p->selFlags &= ~SF_Compound;
103159 assert( pNew->pPrior!=0 );
103160 pNew->pPrior->pNext = pNew;
103161 pNew->pLimit = 0;
103162 pNew->pOffset = 0;
103163 return WRC_Continue;
103164 }
103165
@@ -103267,13 +103343,14 @@
103343 ** sqlite3SelectExpand() when walking a SELECT tree to resolve table
103344 ** names and other FROM clause elements.
103345 */
103346 static void selectPopWith(Walker *pWalker, Select *p){
103347 Parse *pParse = pWalker->pParse;
103348 With *pWith = findRightmost(p)->pWith;
103349 if( pWith!=0 ){
103350 assert( pParse->pWith==pWith );
103351 pParse->pWith = pWith->pOuter;
103352 }
103353 }
103354 #else
103355 #define selectPopWith 0
103356 #endif
@@ -103319,11 +103396,11 @@
103396 if( NEVER(p->pSrc==0) || (selFlags & SF_Expanded)!=0 ){
103397 return WRC_Prune;
103398 }
103399 pTabList = p->pSrc;
103400 pEList = p->pEList;
103401 sqlite3WithPush(pParse, findRightmost(p)->pWith, 0);
103402
103403 /* Make sure cursor numbers have been assigned to all entries in
103404 ** the FROM clause of the SELECT statement.
103405 */
103406 sqlite3SrcListAssignCursors(pParse, pTabList);
@@ -103832,11 +103909,11 @@
103909 **
103910 ** Another solution would be to change the OP_SCopy used to copy cached
103911 ** values to an OP_Copy.
103912 */
103913 if( regHit ){
103914 addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
103915 }
103916 sqlite3ExprCacheClear(pParse);
103917 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
103918 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
103919 }
@@ -103991,46 +104068,28 @@
104068 if( isAggSub ){
104069 isAgg = 1;
104070 p->selFlags |= SF_Aggregate;
104071 }
104072 i = -1;
104073 }else if( pTabList->nSrc==1
104074 && OptimizationEnabled(db, SQLITE_SubqCoroutine)
104075 ){
104076 /* Implement a co-routine that will return a single row of the result
104077 ** set on each invocation.
104078 */
104079 int addrTop = sqlite3VdbeCurrentAddr(v)+1;
 
104080 pItem->regReturn = ++pParse->nMem;
104081 sqlite3VdbeAddOp3(v, OP_InitCoroutine, pItem->regReturn, 0, addrTop);
104082 VdbeComment((v, "%s", pItem->pTab->zName));
 
 
 
 
 
 
 
 
 
 
 
 
104083 pItem->addrFillSub = addrTop;
 
 
104084 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
104085 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104086 sqlite3Select(pParse, pSub, &dest);
104087 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
104088 pItem->viaCoroutine = 1;
104089 pItem->regResult = dest.iSdst;
104090 sqlite3VdbeAddOp1(v, OP_EndCoroutine, pItem->regReturn);
 
 
 
104091 sqlite3VdbeJumpHere(v, addrTop-1);
104092 sqlite3ClearTempRegCache(pParse);
104093 }else{
104094 /* Generate a subroutine that will fill an ephemeral table with
104095 ** the content of this subquery. pItem->addrFillSub will point
@@ -104042,16 +104101,18 @@
104101 int retAddr;
104102 assert( pItem->addrFillSub==0 );
104103 pItem->regReturn = ++pParse->nMem;
104104 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
104105 pItem->addrFillSub = topAddr+1;
 
104106 if( pItem->isCorrelated==0 ){
104107 /* If the subquery is not correlated and if we are not inside of
104108 ** a trigger, then we only need to compute the value of the subquery
104109 ** once. */
104110 onceAddr = sqlite3CodeOnce(pParse); VdbeCoverage(v);
104111 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
104112 }else{
104113 VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
104114 }
104115 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
104116 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
104117 sqlite3Select(pParse, pSub, &dest);
104118 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
@@ -104079,25 +104140,10 @@
104140
104141 #ifndef SQLITE_OMIT_COMPOUND_SELECT
104142 /* If there is are a sequence of queries, do the earlier ones first.
104143 */
104144 if( p->pPrior ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104145 rc = multiSelect(pParse, p, pDest);
104146 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
104147 return rc;
104148 }
104149 #endif
@@ -104397,11 +104443,11 @@
104443 sqlite3WhereEnd(pWInfo);
104444 sAggInfo.sortingIdxPTab = sortPTab = pParse->nTab++;
104445 sortOut = sqlite3GetTempReg(pParse);
104446 sqlite3VdbeAddOp3(v, OP_OpenPseudo, sortPTab, sortOut, nCol);
104447 sqlite3VdbeAddOp2(v, OP_SorterSort, sAggInfo.sortingIdx, addrEnd);
104448 VdbeComment((v, "GROUP BY sort")); VdbeCoverage(v);
104449 sAggInfo.useSortingIdx = 1;
104450 sqlite3ExprCacheClear(pParse);
104451 }
104452
104453 /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
@@ -104424,11 +104470,11 @@
104470 }
104471 }
104472 sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
104473 (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
104474 j1 = sqlite3VdbeCurrentAddr(v);
104475 sqlite3VdbeAddOp3(v, OP_Jump, j1+1, 0, j1+1); VdbeCoverage(v);
104476
104477 /* Generate code that runs whenever the GROUP BY changes.
104478 ** Changes in the GROUP BY are detected by the previous code
104479 ** block. If there were no changes, this block is skipped.
104480 **
@@ -104438,11 +104484,11 @@
104484 ** for the next GROUP BY batch.
104485 */
104486 sqlite3ExprCodeMove(pParse, iBMem, iAMem, pGroupBy->nExpr);
104487 sqlite3VdbeAddOp2(v, OP_Gosub, regOutputRow, addrOutputRow);
104488 VdbeComment((v, "output one row"));
104489 sqlite3VdbeAddOp2(v, OP_IfPos, iAbortFlag, addrEnd); VdbeCoverage(v);
104490 VdbeComment((v, "check abort flag"));
104491 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
104492 VdbeComment((v, "reset accumulator"));
104493
104494 /* Update the aggregate accumulators based on the content of
@@ -104455,10 +104501,11 @@
104501
104502 /* End of the loop
104503 */
104504 if( groupBySort ){
104505 sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
104506 VdbeCoverage(v);
104507 }else{
104508 sqlite3WhereEnd(pWInfo);
104509 sqlite3VdbeChangeToNoop(v, addrSortingIdx);
104510 }
104511
@@ -104482,11 +104529,11 @@
104529 sqlite3VdbeAddOp2(v, OP_Integer, 1, iAbortFlag);
104530 VdbeComment((v, "set abort flag"));
104531 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104532 sqlite3VdbeResolveLabel(v, addrOutputRow);
104533 addrOutputRow = sqlite3VdbeCurrentAddr(v);
104534 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2); VdbeCoverage(v);
104535 VdbeComment((v, "Groupby result generator entry point"));
104536 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104537 finalizeAggFunctions(pParse, &sAggInfo);
104538 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104539 selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
@@ -104755,14 +104802,10 @@
104802 SQLITE_PRIVATE void sqlite3ExplainSelect(Vdbe *pVdbe, Select *p){
104803 if( p==0 ){
104804 sqlite3ExplainPrintf(pVdbe, "(null-select)");
104805 return;
104806 }
 
 
 
 
104807 sqlite3ExplainPush(pVdbe);
104808 while( p ){
104809 explainOneSelect(pVdbe, p);
104810 p = p->pNext;
104811 if( p==0 ) break;
@@ -105543,10 +105586,11 @@
105586 /* Generate code to destroy the database record of the trigger.
105587 */
105588 assert( pTable!=0 );
105589 if( (v = sqlite3GetVdbe(pParse))!=0 ){
105590 int base;
105591 static const int iLn = __LINE__+2;
105592 static const VdbeOpList dropTrigger[] = {
105593 { OP_Rewind, 0, ADDR(9), 0},
105594 { OP_String8, 0, 1, 0}, /* 1 */
105595 { OP_Column, 0, 1, 2},
105596 { OP_Ne, 2, ADDR(8), 1},
@@ -105557,11 +105601,11 @@
105601 { OP_Next, 0, ADDR(1), 0}, /* 8 */
105602 };
105603
105604 sqlite3BeginWriteOperation(pParse, 0, iDb);
105605 sqlite3OpenMasterTable(pParse, iDb);
105606 base = sqlite3VdbeAddOpList(v, ArraySize(dropTrigger), dropTrigger, iLn);
105607 sqlite3VdbeChangeP4(v, base+1, pTrigger->zName, P4_TRANSIENT);
105608 sqlite3VdbeChangeP4(v, base+4, "trigger", P4_STATIC);
105609 sqlite3ChangeCookie(pParse, iDb);
105610 sqlite3VdbeAddOp2(v, OP_Close, 0, 0);
105611 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
@@ -105703,19 +105747,11 @@
105747 **
105748 ** INSERT INTO t1 ... ; -- insert into t2 uses REPLACE policy
105749 ** INSERT OR IGNORE INTO t1 ... ; -- insert into t2 uses IGNORE policy
105750 */
105751 pParse->eOrconf = (orconf==OE_Default)?pStep->orconf:(u8)orconf;
105752 assert( pParse->okConstFactor==0 );
 
 
 
 
 
 
 
 
105753
105754 switch( pStep->op ){
105755 case TK_UPDATE: {
105756 sqlite3Update(pParse,
105757 targetSrcList(pParse, pStep),
@@ -106500,11 +106536,11 @@
106536 sqlite3VdbeChangeToNoop(v, addrOpen);
106537 nKey = nPk;
106538 regKey = iPk;
106539 }else{
106540 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
106541 sqlite3IndexAffinityStr(v, pPk), nPk);
106542 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
106543 }
106544 sqlite3WhereEnd(pWInfo);
106545 }
106546
@@ -106544,32 +106580,37 @@
106580 /* Top of the update loop */
106581 if( okOnePass ){
106582 if( aToOpen[iDataCur-iBaseCur] ){
106583 assert( pPk!=0 );
106584 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelBreak, regKey, nKey);
106585 VdbeCoverageNeverTaken(v);
106586 }
106587 labelContinue = labelBreak;
106588 sqlite3VdbeAddOp2(v, OP_IsNull, pPk ? regKey : regOldRowid, labelBreak);
106589 VdbeCoverage(v);
106590 }else if( pPk ){
106591 labelContinue = sqlite3VdbeMakeLabel(v);
106592 sqlite3VdbeAddOp2(v, OP_Rewind, iEph, labelBreak); VdbeCoverage(v);
106593 addrTop = sqlite3VdbeAddOp2(v, OP_RowKey, iEph, regKey);
106594 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue, regKey, 0);
106595 VdbeCoverage(v);
106596 }else{
106597 labelContinue = sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowSet, labelBreak,
106598 regOldRowid);
106599 VdbeCoverage(v);
106600 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106601 VdbeCoverage(v);
106602 }
106603
106604 /* If the record number will change, set register regNewRowid to
106605 ** contain the new value. If the record number is not being modified,
106606 ** then regNewRowid is the same register as regOldRowid, which is
106607 ** already populated. */
106608 assert( chngKey || pTrigger || hasFK || regOldRowid==regNewRowid );
106609 if( chngRowid ){
106610 sqlite3ExprCode(pParse, pRowidExpr, regNewRowid);
106611 sqlite3VdbeAddOp1(v, OP_MustBeInt, regNewRowid); VdbeCoverage(v);
106612 }
106613
106614 /* Compute the old pre-UPDATE content of the row being changed, if that
106615 ** information is needed */
106616 if( chngPk || hasFK || pTrigger ){
@@ -106634,12 +106675,11 @@
106675
106676 /* Fire any BEFORE UPDATE triggers. This happens before constraints are
106677 ** verified. One could argue that this is wrong.
106678 */
106679 if( tmask&TRIGGER_BEFORE ){
106680 sqlite3TableAffinity(v, pTab, regNew);
 
106681 sqlite3CodeRowTrigger(pParse, pTrigger, TK_UPDATE, pChanges,
106682 TRIGGER_BEFORE, pTab, regOldRowid, onError, labelContinue);
106683
106684 /* The row-trigger may have deleted the row being updated. In this
106685 ** case, jump to the next row. No updates or AFTER triggers are
@@ -106647,12 +106687,14 @@
106687 ** is deleted or renamed by a BEFORE trigger - is left undefined in the
106688 ** documentation.
106689 */
106690 if( pPk ){
106691 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, labelContinue,regKey,nKey);
106692 VdbeCoverage(v);
106693 }else{
106694 sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, labelContinue, regOldRowid);
106695 VdbeCoverage(v);
106696 }
106697
106698 /* If it did not delete it, the row-trigger may still have modified
106699 ** some of the columns of the row being updated. Load the values for
106700 ** all columns not modified by the update statement into their
@@ -106684,10 +106726,11 @@
106726 if( pPk ){
106727 j1 = sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, 0, regKey, nKey);
106728 }else{
106729 j1 = sqlite3VdbeAddOp3(v, OP_NotExists, iDataCur, 0, regOldRowid);
106730 }
106731 VdbeCoverageNeverTaken(v);
106732 }
106733 sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur, aRegIdx);
106734
106735 /* If changing the record number, delete the old record. */
106736 if( hasFK || chngKey || pPk!=0 ){
@@ -106727,11 +106770,11 @@
106770 */
106771 if( okOnePass ){
106772 /* Nothing to do at end-of-loop for a single-pass */
106773 }else if( pPk ){
106774 sqlite3VdbeResolveLabel(v, labelContinue);
106775 sqlite3VdbeAddOp2(v, OP_Next, iEph, addrTop); VdbeCoverage(v);
106776 }else{
106777 sqlite3VdbeAddOp2(v, OP_Goto, 0, labelContinue);
106778 }
106779 sqlite3VdbeResolveLabel(v, labelBreak);
106780
@@ -106856,21 +106899,21 @@
106899 sqlite3Select(pParse, pSelect, &dest);
106900
106901 /* Generate code to scan the ephemeral table and call VUpdate. */
106902 iReg = ++pParse->nMem;
106903 pParse->nMem += pTab->nCol+1;
106904 addr = sqlite3VdbeAddOp2(v, OP_Rewind, ephemTab, 0); VdbeCoverage(v);
106905 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, 0, iReg);
106906 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, (pRowid?1:0), iReg+1);
106907 for(i=0; i<pTab->nCol; i++){
106908 sqlite3VdbeAddOp3(v, OP_Column, ephemTab, i+1+(pRowid!=0), iReg+2+i);
106909 }
106910 sqlite3VtabMakeWritable(pParse, pTab);
106911 sqlite3VdbeAddOp4(v, OP_VUpdate, 0, pTab->nCol+2, iReg, pVTab, P4_VTAB);
106912 sqlite3VdbeChangeP5(v, onError==OE_Default ? OE_Abort : onError);
106913 sqlite3MayAbort(pParse);
106914 sqlite3VdbeAddOp2(v, OP_Next, ephemTab, addr+1); VdbeCoverage(v);
106915 sqlite3VdbeJumpHere(v, addr);
106916 sqlite3VdbeAddOp2(v, OP_Close, ephemTab, 0);
106917
106918 /* Cleanup */
106919 sqlite3SelectDelete(db, pSelect);
@@ -108438,11 +108481,11 @@
108481 int addrSkip; /* Jump here for next iteration of skip-scan */
108482 int addrCont; /* Jump here to continue with the next loop cycle */
108483 int addrFirst; /* First instruction of interior of the loop */
108484 int addrBody; /* Beginning of the body of this loop */
108485 u8 iFrom; /* Which entry in the FROM clause */
108486 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
108487 int p1, p2; /* Operands of the opcode used to ends the loop */
108488 union { /* Information that depends on pWLoop->wsFlags */
108489 struct {
108490 int nIn; /* Number of entries in aInLoop[] */
108491 struct InLoop {
@@ -108825,10 +108868,11 @@
108868 #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */
108869 #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */
108870 #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */
108871 #define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */
108872 #define WHERE_SKIPSCAN 0x00008000 /* Uses the skip-scan algorithm */
108873 #define WHERE_UNQ_WANTED 0x00010000 /* WHERE_ONEROW would have been helpful*/
108874
108875 /************** End of whereInt.h ********************************************/
108876 /************** Continuing where we left off in where.c **********************/
108877
108878 /*
@@ -110411,11 +110455,11 @@
110455
110456 /* Generate code to skip over the creation and initialization of the
110457 ** transient index on 2nd and subsequent iterations of the loop. */
110458 v = pParse->pVdbe;
110459 assert( v!=0 );
110460 addrInit = sqlite3CodeOnce(pParse); VdbeCoverage(v);
110461
110462 /* Count the number of columns that will be added to the index
110463 ** and used to match WHERE clause constraints */
110464 nKeyCol = 0;
110465 pTable = pSrc->pTab;
@@ -110518,16 +110562,16 @@
110562 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
110563 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
110564 VdbeComment((v, "for %s", pTable->zName));
110565
110566 /* Fill the automatic index with content */
110567 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);
110568 regRecord = sqlite3GetTempReg(pParse);
110569 sqlite3GenerateIndexKey(pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0);
110570 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
110571 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
110572 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);
110573 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);
110574 sqlite3VdbeJumpHere(v, addrTop);
110575 sqlite3ReleaseTempReg(pParse, regRecord);
110576
110577 /* Jump here when skipping the initialization */
@@ -111199,10 +111243,12 @@
111243 testcase( bRev );
111244 bRev = !bRev;
111245 }
111246 iTab = pX->iTable;
111247 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iTab, 0);
111248 VdbeCoverageIf(v, bRev);
111249 VdbeCoverageIf(v, !bRev);
111250 assert( (pLoop->wsFlags & WHERE_MULTI_OR)==0 );
111251 pLoop->wsFlags |= WHERE_IN_ABLE;
111252 if( pLevel->u.in.nIn==0 ){
111253 pLevel->addrNxt = sqlite3VdbeMakeLabel(v);
111254 }
@@ -111218,11 +111264,11 @@
111264 pIn->addrInTop = sqlite3VdbeAddOp2(v, OP_Rowid, iTab, iReg);
111265 }else{
111266 pIn->addrInTop = sqlite3VdbeAddOp3(v, OP_Column, iTab, 0, iReg);
111267 }
111268 pIn->eEndLoopOp = bRev ? OP_PrevIfOpen : OP_NextIfOpen;
111269 sqlite3VdbeAddOp1(v, OP_IsNull, iReg); VdbeCoverage(v);
111270 }else{
111271 pLevel->u.in.nIn = 0;
111272 }
111273 #endif
111274 }
@@ -111313,14 +111359,18 @@
111359 }
111360
111361 if( nSkip ){
111362 int iIdxCur = pLevel->iIdxCur;
111363 sqlite3VdbeAddOp1(v, (bRev?OP_Last:OP_Rewind), iIdxCur);
111364 VdbeCoverageIf(v, bRev==0);
111365 VdbeCoverageIf(v, bRev!=0);
111366 VdbeComment((v, "begin skip-scan on %s", pIdx->zName));
111367 j = sqlite3VdbeAddOp0(v, OP_Goto);
111368 pLevel->addrSkip = sqlite3VdbeAddOp4Int(v, (bRev?OP_SeekLT:OP_SeekGT),
111369 iIdxCur, 0, regBase, nSkip);
111370 VdbeCoverageIf(v, bRev==0);
111371 VdbeCoverageIf(v, bRev!=0);
111372 sqlite3VdbeJumpHere(v, j);
111373 for(j=0; j<nSkip; j++){
111374 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, j, regBase+j);
111375 assert( pIdx->aiColumn[j]>=0 );
111376 VdbeComment((v, "%s", pIdx->pTable->aCol[pIdx->aiColumn[j]].zName));
@@ -111349,11 +111399,14 @@
111399 }
111400 testcase( pTerm->eOperator & WO_ISNULL );
111401 testcase( pTerm->eOperator & WO_IN );
111402 if( (pTerm->eOperator & (WO_ISNULL|WO_IN))==0 ){
111403 Expr *pRight = pTerm->pExpr->pRight;
111404 if( sqlite3ExprCanBeNull(pRight) ){
111405 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
111406 VdbeCoverage(v);
111407 }
111408 if( zAff ){
111409 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_NONE ){
111410 zAff[j] = SQLITE_AFF_NONE;
111411 }
111412 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
@@ -111595,14 +111648,14 @@
111648 }
111649
111650 /* Special case of a FROM clause subquery implemented as a co-routine */
111651 if( pTabItem->viaCoroutine ){
111652 int regYield = pTabItem->regReturn;
111653 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);
111654 pLevel->p2 = sqlite3VdbeAddOp2(v, OP_Yield, regYield, addrBrk);
111655 VdbeCoverage(v);
111656 VdbeComment((v, "next row of \"%s\"", pTabItem->pTab->zName));
111657 pLevel->op = OP_Goto;
111658 }else
111659
111660 #ifndef SQLITE_OMIT_VIRTUALTABLE
111661 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)!=0 ){
@@ -111630,10 +111683,11 @@
111683 sqlite3VdbeAddOp2(v, OP_Integer, pLoop->u.vtab.idxNum, iReg);
111684 sqlite3VdbeAddOp2(v, OP_Integer, nConstraint, iReg+1);
111685 sqlite3VdbeAddOp4(v, OP_VFilter, iCur, addrNotFound, iReg,
111686 pLoop->u.vtab.idxStr,
111687 pLoop->u.vtab.needFree ? P4_MPRINTF : P4_STATIC);
111688 VdbeCoverage(v);
111689 pLoop->u.vtab.needFree = 0;
111690 for(j=0; j<nConstraint && j<16; j++){
111691 if( (pLoop->u.vtab.omitMask>>j)&1 ){
111692 disableTerm(pLevel, pLoop->aLTerm[j]);
111693 }
@@ -111653,20 +111707,22 @@
111707 ** equality comparison against the ROWID field. Or
111708 ** we reference multiple rows using a "rowid IN (...)"
111709 ** construct.
111710 */
111711 assert( pLoop->u.btree.nEq==1 );
 
111712 pTerm = pLoop->aLTerm[0];
111713 assert( pTerm!=0 );
111714 assert( pTerm->pExpr!=0 );
111715 assert( omitTable==0 );
111716 testcase( pTerm->wtFlags & TERM_VIRTUAL );
111717 iReleaseReg = ++pParse->nMem;
111718 iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, bRev, iReleaseReg);
111719 if( iRowidReg!=iReleaseReg ) sqlite3ReleaseTempReg(pParse, iReleaseReg);
111720 addrNxt = pLevel->addrNxt;
111721 sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); VdbeCoverage(v);
111722 sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);
111723 VdbeCoverage(v);
111724 sqlite3ExprCacheAffinityChange(pParse, iRowidReg, 1);
111725 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111726 VdbeComment((v, "pk"));
111727 pLevel->op = OP_Noop;
111728 }else if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -111696,14 +111752,14 @@
111752
111753 /* The following constant maps TK_xx codes into corresponding
111754 ** seek opcodes. It depends on a particular ordering of TK_xx
111755 */
111756 const u8 aMoveOp[] = {
111757 /* TK_GT */ OP_SeekGT,
111758 /* TK_LE */ OP_SeekLE,
111759 /* TK_LT */ OP_SeekLT,
111760 /* TK_GE */ OP_SeekGE
111761 };
111762 assert( TK_LE==TK_GT+1 ); /* Make sure the ordering.. */
111763 assert( TK_LT==TK_GT+2 ); /* ... of the TK_xx values... */
111764 assert( TK_GE==TK_GT+3 ); /* ... is correcct. */
111765
@@ -111713,15 +111769,21 @@
111769 assert( pX!=0 );
111770 testcase( pStart->leftCursor!=iCur ); /* transitive constraints */
111771 r1 = sqlite3ExprCodeTemp(pParse, pX->pRight, &rTemp);
111772 sqlite3VdbeAddOp3(v, aMoveOp[pX->op-TK_GT], iCur, addrBrk, r1);
111773 VdbeComment((v, "pk"));
111774 VdbeCoverageIf(v, pX->op==TK_GT);
111775 VdbeCoverageIf(v, pX->op==TK_LE);
111776 VdbeCoverageIf(v, pX->op==TK_LT);
111777 VdbeCoverageIf(v, pX->op==TK_GE);
111778 sqlite3ExprCacheAffinityChange(pParse, r1, 1);
111779 sqlite3ReleaseTempReg(pParse, rTemp);
111780 disableTerm(pLevel, pStart);
111781 }else{
111782 sqlite3VdbeAddOp2(v, bRev ? OP_Last : OP_Rewind, iCur, addrBrk);
111783 VdbeCoverageIf(v, bRev==0);
111784 VdbeCoverageIf(v, bRev!=0);
111785 }
111786 if( pEnd ){
111787 Expr *pX;
111788 pX = pEnd->pExpr;
111789 assert( pX!=0 );
@@ -111741,14 +111803,18 @@
111803 pLevel->op = bRev ? OP_Prev : OP_Next;
111804 pLevel->p1 = iCur;
111805 pLevel->p2 = start;
111806 assert( pLevel->p5==0 );
111807 if( testOp!=OP_Noop ){
111808 iRowidReg = ++pParse->nMem;
111809 sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
111810 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
111811 sqlite3VdbeAddOp3(v, testOp, memEndValue, addrBrk, iRowidReg);
111812 VdbeCoverageIf(v, testOp==OP_Le);
111813 VdbeCoverageIf(v, testOp==OP_Lt);
111814 VdbeCoverageIf(v, testOp==OP_Ge);
111815 VdbeCoverageIf(v, testOp==OP_Gt);
111816 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC | SQLITE_JUMPIFNULL);
111817 }
111818 }else if( pLoop->wsFlags & WHERE_INDEXED ){
111819 /* Case 4: A scan using an index.
111820 **
@@ -111784,24 +111850,23 @@
111850 static const u8 aStartOp[] = {
111851 0,
111852 0,
111853 OP_Rewind, /* 2: (!start_constraints && startEq && !bRev) */
111854 OP_Last, /* 3: (!start_constraints && startEq && bRev) */
111855 OP_SeekGT, /* 4: (start_constraints && !startEq && !bRev) */
111856 OP_SeekLT, /* 5: (start_constraints && !startEq && bRev) */
111857 OP_SeekGE, /* 6: (start_constraints && startEq && !bRev) */
111858 OP_SeekLE /* 7: (start_constraints && startEq && bRev) */
111859 };
111860 static const u8 aEndOp[] = {
111861 OP_IdxGE, /* 0: (end_constraints && !bRev && !endEq) */
111862 OP_IdxGT, /* 1: (end_constraints && !bRev && endEq) */
111863 OP_IdxLE, /* 2: (end_constraints && bRev && !endEq) */
111864 OP_IdxLT, /* 3: (end_constraints && bRev && endEq) */
111865 };
111866 u16 nEq = pLoop->u.btree.nEq; /* Number of == or IN terms */
 
111867 int regBase; /* Base register holding constraint values */
 
111868 WhereTerm *pRangeStart = 0; /* Inequality constraint at range start */
111869 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
111870 int startEq; /* True if range start uses ==, >= or <= */
111871 int endEq; /* True if range end uses ==, >= or <= */
111872 int start_constraints; /* Start of range is constrained */
@@ -111810,10 +111875,12 @@
111875 int iIdxCur; /* The VDBE cursor for the index */
111876 int nExtraReg = 0; /* Number of extra registers needed */
111877 int op; /* Instruction opcode */
111878 char *zStartAff; /* Affinity for start of range constraint */
111879 char cEndAff = 0; /* Affinity for end of range constraint */
111880 u8 bSeekPastNull = 0; /* True to seek past initial nulls */
111881 u8 bStopAtNull = 0; /* Add condition to terminate at NULLs */
111882
111883 pIdx = pLoop->u.btree.pIndex;
111884 iIdxCur = pLevel->iIdxCur;
111885 assert( nEq>=pLoop->u.btree.nSkip );
111886
@@ -111828,11 +111895,11 @@
111895 if( (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)!=0
111896 && (pWInfo->bOBSat!=0)
111897 && (pIdx->nKeyCol>nEq)
111898 ){
111899 assert( pLoop->u.btree.nSkip==0 );
111900 bSeekPastNull = 1;
111901 nExtraReg = 1;
111902 }
111903
111904 /* Find any inequality constraint terms for the start and end
111905 ** of the range.
@@ -111843,10 +111910,17 @@
111910 nExtraReg = 1;
111911 }
111912 if( pLoop->wsFlags & WHERE_TOP_LIMIT ){
111913 pRangeEnd = pLoop->aLTerm[j++];
111914 nExtraReg = 1;
111915 if( pRangeStart==0
111916 && (pRangeEnd->wtFlags & TERM_VNULL)==0
111917 && (j = pIdx->aiColumn[nEq])>=0
111918 && pIdx->pTable->aCol[j].notNull==0
111919 ){
111920 bSeekPastNull = 1;
111921 }
111922 }
111923
111924 /* Generate code to evaluate all constraint terms using == or IN
111925 ** and store the values of those terms in an array of registers
111926 ** starting at regBase.
@@ -111862,10 +111936,11 @@
111936 */
111937 if( (nEq<pIdx->nKeyCol && bRev==(pIdx->aSortOrder[nEq]==SQLITE_SO_ASC))
111938 || (bRev && pIdx->nKeyCol==nEq)
111939 ){
111940 SWAP(WhereTerm *, pRangeEnd, pRangeStart);
111941 SWAP(u8, bSeekPastNull, bStopAtNull);
111942 }
111943
111944 testcase( pRangeStart && (pRangeStart->eOperator & WO_LE)!=0 );
111945 testcase( pRangeStart && (pRangeStart->eOperator & WO_GE)!=0 );
111946 testcase( pRangeEnd && (pRangeEnd->eOperator & WO_LE)!=0 );
@@ -111877,12 +111952,15 @@
111952 /* Seek the index cursor to the start of the range. */
111953 nConstraint = nEq;
111954 if( pRangeStart ){
111955 Expr *pRight = pRangeStart->pExpr->pRight;
111956 sqlite3ExprCode(pParse, pRight, regBase+nEq);
111957 if( (pRangeStart->wtFlags & TERM_VNULL)==0
111958 && sqlite3ExprCanBeNull(pRight)
111959 ){
111960 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
111961 VdbeCoverage(v);
111962 }
111963 if( zStartAff ){
111964 if( sqlite3CompareAffinity(pRight, zStartAff[nEq])==SQLITE_AFF_NONE){
111965 /* Since the comparison is to be performed with no conversions
111966 ** applied to the operands, set the affinity to apply to pRight to
@@ -111893,86 +111971,76 @@
111971 zStartAff[nEq] = SQLITE_AFF_NONE;
111972 }
111973 }
111974 nConstraint++;
111975 testcase( pRangeStart->wtFlags & TERM_VIRTUAL );
111976 }else if( bSeekPastNull ){
111977 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
111978 nConstraint++;
111979 startEq = 0;
111980 start_constraints = 1;
111981 }
111982 codeApplyAffinity(pParse, regBase, nConstraint - bSeekPastNull, zStartAff);
111983 op = aStartOp[(start_constraints<<2) + (startEq<<1) + bRev];
111984 assert( op!=0 );
 
 
 
 
 
 
111985 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
111986 VdbeCoverage(v);
111987 VdbeCoverageIf(v, op==OP_Rewind); testcase( op==OP_Rewind );
111988 VdbeCoverageIf(v, op==OP_Last); testcase( op==OP_Last );
111989 VdbeCoverageIf(v, op==OP_SeekGT); testcase( op==OP_SeekGT );
111990 VdbeCoverageIf(v, op==OP_SeekGE); testcase( op==OP_SeekGE );
111991 VdbeCoverageIf(v, op==OP_SeekLE); testcase( op==OP_SeekLE );
111992 VdbeCoverageIf(v, op==OP_SeekLT); testcase( op==OP_SeekLT );
111993
111994 /* Load the value for the inequality constraint at the end of the
111995 ** range (if any).
111996 */
111997 nConstraint = nEq;
111998 if( pRangeEnd ){
111999 Expr *pRight = pRangeEnd->pExpr->pRight;
112000 sqlite3ExprCacheRemove(pParse, regBase+nEq, 1);
112001 sqlite3ExprCode(pParse, pRight, regBase+nEq);
112002 if( (pRangeEnd->wtFlags & TERM_VNULL)==0
112003 && sqlite3ExprCanBeNull(pRight)
112004 ){
112005 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+nEq, addrNxt);
112006 VdbeCoverage(v);
112007 }
112008 if( sqlite3CompareAffinity(pRight, cEndAff)!=SQLITE_AFF_NONE
112009 && !sqlite3ExprNeedsNoAffinityChange(pRight, cEndAff)
112010 ){
112011 codeApplyAffinity(pParse, regBase+nEq, 1, &cEndAff);
112012 }
112013 nConstraint++;
112014 testcase( pRangeEnd->wtFlags & TERM_VIRTUAL );
112015 }else if( bStopAtNull ){
112016 sqlite3VdbeAddOp2(v, OP_Null, 0, regBase+nEq);
112017 endEq = 0;
112018 nConstraint++;
112019 }
112020 sqlite3DbFree(db, zStartAff);
112021
112022 /* Top of the loop body */
112023 pLevel->p2 = sqlite3VdbeCurrentAddr(v);
112024
112025 /* Check if the index cursor is past the end of the range. */
112026 if( nConstraint ){
112027 op = aEndOp[bRev*2 + endEq];
 
 
 
112028 sqlite3VdbeAddOp4Int(v, op, iIdxCur, addrNxt, regBase, nConstraint);
112029 testcase( op==OP_IdxGT ); VdbeCoverageIf(v, op==OP_IdxGT );
112030 testcase( op==OP_IdxGE ); VdbeCoverageIf(v, op==OP_IdxGE );
112031 testcase( op==OP_IdxLT ); VdbeCoverageIf(v, op==OP_IdxLT );
112032 testcase( op==OP_IdxLE ); VdbeCoverageIf(v, op==OP_IdxLE );
112033 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112034
112035 /* Seek the table cursor, if required */
112036 disableTerm(pLevel, pRangeStart);
112037 disableTerm(pLevel, pRangeEnd);
112038 if( omitTable ){
112039 /* pIdx is a covering index. No need to access the main table. */
112040 }else if( HasRowid(pIdx->pTable) ){
112041 iRowidReg = ++pParse->nMem;
112042 sqlite3VdbeAddOp2(v, OP_IdxRowid, iIdxCur, iRowidReg);
112043 sqlite3ExprCacheStore(pParse, iCur, -1, iRowidReg);
112044 sqlite3VdbeAddOp2(v, OP_Seek, iCur, iRowidReg); /* Deferred seek */
112045 }else{
112046 Index *pPk = sqlite3PrimaryKeyIndex(pIdx->pTable);
@@ -111980,11 +112048,11 @@
112048 for(j=0; j<pPk->nKeyCol; j++){
112049 k = sqlite3ColumnOfIndex(pIdx, pPk->aiColumn[j]);
112050 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
112051 }
112052 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
112053 iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
112054 }
112055
112056 /* Record the instruction used to terminate the loop. Disable
112057 ** WHERE clause terms made redundant by the index range scan.
112058 */
@@ -111994,10 +112062,12 @@
112062 pLevel->op = OP_Prev;
112063 }else{
112064 pLevel->op = OP_Next;
112065 }
112066 pLevel->p1 = iIdxCur;
112067 assert( (WHERE_UNQ_WANTED>>16)==1 );
112068 pLevel->p3 = (pLoop->wsFlags>>16)&1;
112069 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
112070 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112071 }else{
112072 assert( pLevel->p5==0 );
112073 }
@@ -112162,10 +112232,11 @@
112232 int r;
112233 r = sqlite3ExprCodeGetColumn(pParse, pTabItem->pTab, -1, iCur,
112234 regRowid, 0);
112235 sqlite3VdbeAddOp4Int(v, OP_RowSetTest, regRowset,
112236 sqlite3VdbeCurrentAddr(v)+2, r, iSet);
112237 VdbeCoverage(v);
112238 }
112239 sqlite3VdbeAddOp2(v, OP_Gosub, regReturn, iLoopBody);
112240
112241 /* The pSubWInfo->untestedTerms flag means that this OR term
112242 ** contained one or more AND term from a notReady table. The
@@ -112230,10 +112301,12 @@
112301 pLevel->op = OP_Noop;
112302 }else{
112303 pLevel->op = aStep[bRev];
112304 pLevel->p1 = iCur;
112305 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
112306 VdbeCoverageIf(v, bRev==0);
112307 VdbeCoverageIf(v, bRev!=0);
112308 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112309 }
112310 }
112311
112312 /* Insert code to test every subexpression that can be completely
@@ -112311,11 +112384,10 @@
112384 assert( pTerm->pExpr );
112385 sqlite3ExprIfFalse(pParse, pTerm->pExpr, addrCont, SQLITE_JUMPIFNULL);
112386 pTerm->wtFlags |= TERM_CODED;
112387 }
112388 }
 
112389
112390 return pLevel->notReady;
112391 }
112392
112393 #if defined(WHERETRACE_ENABLED) && defined(SQLITE_ENABLE_TREE_EXPLAIN)
@@ -112798,16 +112870,17 @@
112870 assert(
112871 (pNew->wsFlags & (WHERE_COLUMN_NULL|WHERE_COLUMN_IN|WHERE_SKIPSCAN))!=0
112872 || nInMul==0
112873 );
112874 pNew->wsFlags |= WHERE_COLUMN_EQ;
112875 if( iCol<0 || (nInMul==0 && pNew->u.btree.nEq==pProbe->nKeyCol-1)){
 
 
 
112876 assert( (pNew->wsFlags & WHERE_COLUMN_IN)==0 || iCol<0 );
112877 if( iCol>=0 && pProbe->onError==OE_None ){
112878 pNew->wsFlags |= WHERE_UNQ_WANTED;
112879 }else{
112880 pNew->wsFlags |= WHERE_ONEROW;
112881 }
112882 }
112883 pNew->u.btree.nEq++;
112884 pNew->nOut = nRowEst + nInMul;
112885 }else if( pTerm->eOperator & (WO_ISNULL) ){
112886 pNew->wsFlags |= WHERE_COLUMN_NULL;
@@ -113682,13 +113755,16 @@
113755 /* Mark off any other ORDER BY terms that reference pLoop */
113756 if( isOrderDistinct ){
113757 orderDistinctMask |= pLoop->maskSelf;
113758 for(i=0; i<nOrderBy; i++){
113759 Expr *p;
113760 Bitmask mTerm;
113761 if( MASKBIT(i) & obSat ) continue;
113762 p = pOrderBy->a[i].pExpr;
113763 mTerm = exprTableUsage(&pWInfo->sMaskSet,p);
113764 if( mTerm==0 && !sqlite3ExprIsConstant(p) ) continue;
113765 if( (mTerm&~orderDistinctMask)==0 ){
113766 obSat |= MASKBIT(i);
113767 }
113768 }
113769 }
113770 } /* End the loop over all WhereLoops from outer-most down to inner-most */
@@ -114246,11 +114322,10 @@
114322 ** subexpression is separated by an AND operator.
114323 */
114324 initMaskSet(pMaskSet);
114325 whereClauseInit(&pWInfo->sWC, pWInfo);
114326 whereSplit(&pWInfo->sWC, pWhere, TK_AND);
 
114327
114328 /* Special case: a WHERE clause that is constant. Evaluate the
114329 ** expression and either jump over all of the code or fall thru.
114330 */
114331 for(ii=0; ii<sWLB.pWC->nTerm; ii++){
@@ -114308,26 +114383,10 @@
114383 exprAnalyzeAll(pTabList, &pWInfo->sWC);
114384 if( db->mallocFailed ){
114385 goto whereBeginError;
114386 }
114387
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114388 if( wctrlFlags & WHERE_WANT_DISTINCT ){
114389 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
114390 /* The DISTINCT marking is pointless. Ignore it. */
114391 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
114392 }else if( pOrderBy==0 ){
@@ -114535,11 +114594,11 @@
114594 assert( iIndexCur>=0 );
114595 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
114596 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
114597 VdbeComment((v, "%s", pIx->zName));
114598 }
114599 if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
114600 notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
114601 }
114602 pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
114603 if( db->mallocFailed ) goto whereBeginError;
114604
@@ -114597,20 +114656,27 @@
114656 int addr;
114657 pLevel = &pWInfo->a[i];
114658 pLoop = pLevel->pWLoop;
114659 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
114660 if( pLevel->op!=OP_Noop ){
114661 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
114662 sqlite3VdbeChangeP5(v, pLevel->p5);
114663 VdbeCoverage(v);
114664 VdbeCoverageIf(v, pLevel->op==OP_Next);
114665 VdbeCoverageIf(v, pLevel->op==OP_Prev);
114666 VdbeCoverageIf(v, pLevel->op==OP_VNext);
114667 }
114668 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
114669 struct InLoop *pIn;
114670 int j;
114671 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
114672 for(j=pLevel->u.in.nIn, pIn=&pLevel->u.in.aInLoop[j-1]; j>0; j--, pIn--){
114673 sqlite3VdbeJumpHere(v, pIn->addrInTop+1);
114674 sqlite3VdbeAddOp2(v, pIn->eEndLoopOp, pIn->iCur, pIn->addrInTop);
114675 VdbeCoverage(v);
114676 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_PrevIfOpen);
114677 VdbeCoverageIf(v, pIn->eEndLoopOp==OP_NextIfOpen);
114678 sqlite3VdbeJumpHere(v, pIn->addrInTop-1);
114679 }
114680 sqlite3DbFree(db, pLevel->u.in.aInLoop);
114681 }
114682 sqlite3VdbeResolveLabel(v, pLevel->addrBrk);
@@ -114619,11 +114685,11 @@
114685 VdbeComment((v, "next skip-scan on %s", pLoop->u.btree.pIndex->zName));
114686 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
114687 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
114688 }
114689 if( pLevel->iLeftJoin ){
114690 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
114691 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
114692 || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
114693 if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
114694 sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
114695 }
@@ -114646,15 +114712,41 @@
114712 */
114713 sqlite3VdbeResolveLabel(v, pWInfo->iBreak);
114714
114715 assert( pWInfo->nLevel<=pTabList->nSrc );
114716 for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){
114717 int k, last;
114718 VdbeOp *pOp;
114719 Index *pIdx = 0;
114720 struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom];
114721 Table *pTab = pTabItem->pTab;
114722 assert( pTab!=0 );
114723 pLoop = pLevel->pWLoop;
114724
114725 /* For a co-routine, change all OP_Column references to the table of
114726 ** the co-routine into OP_SCopy of result contained in a register.
114727 ** OP_Rowid becomes OP_Null.
114728 */
114729 if( pTabItem->viaCoroutine ){
114730 last = sqlite3VdbeCurrentAddr(v);
114731 k = pLevel->addrBody;
114732 pOp = sqlite3VdbeGetOp(v, k);
114733 for(; k<last; k++, pOp++){
114734 if( pOp->p1!=pLevel->iTabCur ) continue;
114735 if( pOp->opcode==OP_Column ){
114736 pOp->opcode = OP_SCopy;
114737 pOp->p1 = pOp->p2 + pTabItem->regResult;
114738 pOp->p2 = pOp->p3;
114739 pOp->p3 = 0;
114740 }else if( pOp->opcode==OP_Rowid ){
114741 pOp->opcode = OP_Null;
114742 pOp->p1 = 0;
114743 pOp->p3 = 0;
114744 }
114745 }
114746 continue;
114747 }
114748
114749 /* Close all of the cursors that were opened by sqlite3WhereBegin.
114750 ** Except, do not close cursors that will be reused by the OR optimization
114751 ** (WHERE_OMIT_OPEN_CLOSE). And do not close the OP_OpenWrite cursors
114752 ** created for the ONEPASS optimization.
@@ -114690,13 +114782,10 @@
114782 pIdx = pLoop->u.btree.pIndex;
114783 }else if( pLoop->wsFlags & WHERE_MULTI_OR ){
114784 pIdx = pLevel->u.pCovidx;
114785 }
114786 if( pIdx && !db->mallocFailed ){
 
 
 
114787 last = sqlite3VdbeCurrentAddr(v);
114788 k = pLevel->addrBody;
114789 pOp = sqlite3VdbeGetOp(v, k);
114790 for(; k<last; k++, pOp++){
114791 if( pOp->p1!=pLevel->iTabCur ) continue;
@@ -117106,33 +117195,54 @@
117195 sqlite3ExplainFinish(pParse->pVdbe);
117196 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy3);
117197 }
117198 break;
117199 case 112: /* select ::= with selectnowith */
117200 {
117201 Select *p = yymsp[0].minor.yy3, *pNext, *pLoop;
117202 if( p ){
117203 int cnt = 0, mxSelect;
117204 p->pWith = yymsp[-1].minor.yy59;
117205 if( p->pPrior ){
117206 pNext = 0;
117207 for(pLoop=p; pLoop; pNext=pLoop, pLoop=pLoop->pPrior, cnt++){
117208 pLoop->pNext = pNext;
117209 pLoop->selFlags |= SF_Compound;
117210 }
117211 mxSelect = pParse->db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
117212 if( mxSelect && cnt>mxSelect ){
117213 sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
117214 }
117215 }
117216 }else{
117217 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
117218 }
117219 yygotominor.yy3 = p;
117220 }
117221 break;
117222 case 113: /* selectnowith ::= oneselect */
117223 case 119: /* oneselect ::= values */ yytestcase(yyruleno==119);
117224 {yygotominor.yy3 = yymsp[0].minor.yy3;}
117225 break;
117226 case 114: /* selectnowith ::= selectnowith multiselect_op oneselect */
117227 {
117228 Select *pRhs = yymsp[0].minor.yy3;
117229 if( pRhs && pRhs->pPrior ){
117230 SrcList *pFrom;
117231 Token x;
117232 x.n = 0;
117233 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
117234 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0,0);
117235 }
117236 if( pRhs ){
117237 pRhs->op = (u8)yymsp[-1].minor.yy328;
117238 pRhs->pPrior = yymsp[-2].minor.yy3;
117239 if( yymsp[-1].minor.yy328!=TK_ALL ) pParse->hasCompound = 1;
117240 }else{
117241 sqlite3SelectDelete(pParse->db, yymsp[-2].minor.yy3);
117242 }
117243 yygotominor.yy3 = pRhs;
117244 }
117245 break;
117246 case 116: /* multiselect_op ::= UNION ALL */
117247 {yygotominor.yy328 = TK_ALL;}
117248 break;
@@ -122696,10 +122806,25 @@
122806 case SQLITE_TESTCTRL_NEVER_CORRUPT: {
122807 sqlite3GlobalConfig.neverCorrupt = va_arg(ap, int);
122808 break;
122809 }
122810
122811
122812 /* sqlite3_test_control(SQLITE_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
122813 **
122814 ** Set the VDBE coverage callback function to xCallback with context
122815 ** pointer ptr.
122816 */
122817 case SQLITE_TESTCTRL_VDBE_COVERAGE: {
122818 #ifdef SQLITE_VDBE_COVERAGE
122819 typedef void (*branch_callback)(void*,int,u8,u8);
122820 sqlite3GlobalConfig.xVdbeBranch = va_arg(ap,branch_callback);
122821 sqlite3GlobalConfig.pVdbeBranchArg = va_arg(ap,void*);
122822 #endif
122823 break;
122824 }
122825
122826 }
122827 va_end(ap);
122828 #endif /* SQLITE_OMIT_BUILTIN_TEST */
122829 return rc;
122830 }
122831
+5 -4
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105105
**
106106
** See also: [sqlite3_libversion()],
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110
-#define SQLITE_VERSION "3.8.3.1"
111
-#define SQLITE_VERSION_NUMBER 3008003
112
-#define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e"
110
+#define SQLITE_VERSION "3.8.4"
111
+#define SQLITE_VERSION_NUMBER 3008004
112
+#define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -6120,11 +6120,12 @@
61206120
#define SQLITE_TESTCTRL_ISKEYWORD 16
61216121
#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
61226122
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
61236123
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19
61246124
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6125
-#define SQLITE_TESTCTRL_LAST 20
6125
+#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6126
+#define SQLITE_TESTCTRL_LAST 21
61266127
61276128
/*
61286129
** CAPI3REF: SQLite Runtime Status
61296130
**
61306131
** ^This interface is used to retrieve runtime status information
61316132
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3.1"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2014-02-11 14:52:19 ea3317a4803d71d88183b29f1d3086f46d68a00e"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -6120,11 +6120,12 @@
6120 #define SQLITE_TESTCTRL_ISKEYWORD 16
6121 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6122 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6123 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6124 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6125 #define SQLITE_TESTCTRL_LAST 20
 
6126
6127 /*
6128 ** CAPI3REF: SQLite Runtime Status
6129 **
6130 ** ^This interface is used to retrieve runtime status information
6131
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -105,13 +105,13 @@
105 **
106 ** See also: [sqlite3_libversion()],
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.4"
111 #define SQLITE_VERSION_NUMBER 3008004
112 #define SQLITE_SOURCE_ID "2014-02-27 15:04:13 a6690400235705ecc0d1a60dacff6ad5fb1f944a"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -6120,11 +6120,12 @@
6120 #define SQLITE_TESTCTRL_ISKEYWORD 16
6121 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6122 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6123 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19
6124 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6125 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
6126 #define SQLITE_TESTCTRL_LAST 21
6127
6128 /*
6129 ** CAPI3REF: SQLite Runtime Status
6130 **
6131 ** ^This interface is used to retrieve runtime status information
6132
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -89,11 +89,11 @@
8989
9090
# define the sqlite shell files, which need special flags on compile
9191
SQLITESHELLSRC=shell.c
9292
ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
9393
SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94
-SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
94
+SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
9595
9696
# define the th scripting files, which need special flags on compile
9797
THSRC=th.c th_lang.c
9898
ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
9999
THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
100100
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -89,11 +89,11 @@
89
90 # define the sqlite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
95
96 # define the th scripting files, which need special flags on compile
97 THSRC=th.c th_lang.c
98 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
99 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
100
--- win/Makefile.PellesCGMake
+++ win/Makefile.PellesCGMake
@@ -89,11 +89,11 @@
89
90 # define the sqlite shell files, which need special flags on compile
91 SQLITESHELLSRC=shell.c
92 ORIGSQLITESHELLSRC=$(foreach sf,$(SQLITESHELLSRC),$(SRCDIR)$(sf))
93 SQLITESHELLOBJ=$(foreach sf,$(SQLITESHELLSRC),$(sf:.c=.obj))
94 SQLITESHELLDEFINES=-Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
95
96 # define the th scripting files, which need special flags on compile
97 THSRC=th.c th_lang.c
98 ORIGTHSRC=$(foreach sf,$(THSRC),$(SRCDIR)$(sf))
99 THOBJ=$(foreach sf,$(THSRC),$(sf:.c=.obj))
100
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,11 +26,11 @@
2626
TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
2727
LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
2828
2929
SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
3030
31
-SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
31
+SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
3232
3333
SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
3434
3535
OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
3636
3737
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,11 +26,11 @@
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
36
37
--- win/Makefile.dmc
+++ win/Makefile.dmc
@@ -26,11 +26,11 @@
26 TCC = $(DMDIR)\bin\dmc $(CFLAGS) $(DMCDEF) $(SSL) $(INCL)
27 LIBS = $(DMDIR)\extra\lib\ zlib wsock32 advapi32
28
29 SQLITE_OPTIONS = -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_ENABLE_LOCKING_STYLE=0 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_OMIT_DEPRECATED -DSQLITE_ENABLE_EXPLAIN_COMMENTS
30
31 SHELL_OPTIONS = -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) -DSQLITE_SHELL_DBNAME_PROC=fossil_open -Dgetenv=fossil_getenv -Dfopen=fossil_fopen
32
33 SRC = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c json_.c json_artifact_.c json_branch_.c json_config_.c json_diff_.c json_dir_.c json_finfo_.c json_login_.c json_query_.c json_report_.c json_status_.c json_tag_.c json_timeline_.c json_user_.c json_wiki_.c leaf_.c login_.c lookslike_.c main_.c manifest_.c markdown_.c markdown_html_.c md5_.c merge_.c merge3_.c moderate_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c regexp_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c unicode_.c update_.c url_.c user_.c utf8_.c util_.c verify_.c vfile_.c wiki_.c wikiformat_.c winfile_.c winhttp_.c wysiwyg_.c xfer_.c xfersetup_.c zip_.c
34
35 OBJ = $(OBJDIR)\add$O $(OBJDIR)\allrepo$O $(OBJDIR)\attach$O $(OBJDIR)\bag$O $(OBJDIR)\bisect$O $(OBJDIR)\blob$O $(OBJDIR)\branch$O $(OBJDIR)\browse$O $(OBJDIR)\captcha$O $(OBJDIR)\cgi$O $(OBJDIR)\checkin$O $(OBJDIR)\checkout$O $(OBJDIR)\clearsign$O $(OBJDIR)\clone$O $(OBJDIR)\comformat$O $(OBJDIR)\configure$O $(OBJDIR)\content$O $(OBJDIR)\db$O $(OBJDIR)\delta$O $(OBJDIR)\deltacmd$O $(OBJDIR)\descendants$O $(OBJDIR)\diff$O $(OBJDIR)\diffcmd$O $(OBJDIR)\doc$O $(OBJDIR)\encode$O $(OBJDIR)\event$O $(OBJDIR)\export$O $(OBJDIR)\file$O $(OBJDIR)\finfo$O $(OBJDIR)\glob$O $(OBJDIR)\graph$O $(OBJDIR)\gzip$O $(OBJDIR)\http$O $(OBJDIR)\http_socket$O $(OBJDIR)\http_ssl$O $(OBJDIR)\http_transport$O $(OBJDIR)\import$O $(OBJDIR)\info$O $(OBJDIR)\json$O $(OBJDIR)\json_artifact$O $(OBJDIR)\json_branch$O $(OBJDIR)\json_config$O $(OBJDIR)\json_diff$O $(OBJDIR)\json_dir$O $(OBJDIR)\json_finfo$O $(OBJDIR)\json_login$O $(OBJDIR)\json_query$O $(OBJDIR)\json_report$O $(OBJDIR)\json_status$O $(OBJDIR)\json_tag$O $(OBJDIR)\json_timeline$O $(OBJDIR)\json_user$O $(OBJDIR)\json_wiki$O $(OBJDIR)\leaf$O $(OBJDIR)\login$O $(OBJDIR)\lookslike$O $(OBJDIR)\main$O $(OBJDIR)\manifest$O $(OBJDIR)\markdown$O $(OBJDIR)\markdown_html$O $(OBJDIR)\md5$O $(OBJDIR)\merge$O $(OBJDIR)\merge3$O $(OBJDIR)\moderate$O $(OBJDIR)\name$O $(OBJDIR)\path$O $(OBJDIR)\pivot$O $(OBJDIR)\popen$O $(OBJDIR)\pqueue$O $(OBJDIR)\printf$O $(OBJDIR)\rebuild$O $(OBJDIR)\regexp$O $(OBJDIR)\report$O $(OBJDIR)\rss$O $(OBJDIR)\schema$O $(OBJDIR)\search$O $(OBJDIR)\setup$O $(OBJDIR)\sha1$O $(OBJDIR)\shun$O $(OBJDIR)\skins$O $(OBJDIR)\sqlcmd$O $(OBJDIR)\stash$O $(OBJDIR)\stat$O $(OBJDIR)\style$O $(OBJDIR)\sync$O $(OBJDIR)\tag$O $(OBJDIR)\tar$O $(OBJDIR)\th_main$O $(OBJDIR)\timeline$O $(OBJDIR)\tkt$O $(OBJDIR)\tktsetup$O $(OBJDIR)\undo$O $(OBJDIR)\unicode$O $(OBJDIR)\update$O $(OBJDIR)\url$O $(OBJDIR)\user$O $(OBJDIR)\utf8$O $(OBJDIR)\util$O $(OBJDIR)\verify$O $(OBJDIR)\vfile$O $(OBJDIR)\wiki$O $(OBJDIR)\wikiformat$O $(OBJDIR)\winfile$O $(OBJDIR)\winhttp$O $(OBJDIR)\wysiwyg$O $(OBJDIR)\xfer$O $(OBJDIR)\xfersetup$O $(OBJDIR)\zip$O $(OBJDIR)\shell$O $(OBJDIR)\sqlite3$O $(OBJDIR)\th$O $(OBJDIR)\th_lang$O
36
37
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1710,10 +1710,12 @@
17101710
-DSQLITE_USE_MALLOC_H \
17111711
-DSQLITE_USE_MSIZE
17121712
17131713
SHELL_OPTIONS = -Dmain=sqlite3_shell \
17141714
-DSQLITE_OMIT_LOAD_EXTENSION=1 \
1715
+ -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
1716
+ -DSQLITE_SHELL_DBNAME_PROC=fossil_open \
17151717
-Dgetenv=fossil_getenv \
17161718
-Dfopen=fossil_fopen
17171719
17181720
$(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
17191721
$(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
17201722
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1710,10 +1710,12 @@
1710 -DSQLITE_USE_MALLOC_H \
1711 -DSQLITE_USE_MSIZE
1712
1713 SHELL_OPTIONS = -Dmain=sqlite3_shell \
1714 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
 
 
1715 -Dgetenv=fossil_getenv \
1716 -Dfopen=fossil_fopen
1717
1718 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
1719 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1720
--- win/Makefile.mingw
+++ win/Makefile.mingw
@@ -1710,10 +1710,12 @@
1710 -DSQLITE_USE_MALLOC_H \
1711 -DSQLITE_USE_MSIZE
1712
1713 SHELL_OPTIONS = -Dmain=sqlite3_shell \
1714 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
1715 -DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
1716 -DSQLITE_SHELL_DBNAME_PROC=fossil_open \
1717 -Dgetenv=fossil_getenv \
1718 -Dfopen=fossil_fopen
1719
1720 $(OBJDIR)/sqlite3.o: $(SRCDIR)/sqlite3.c $(SRCDIR)/../win/Makefile.mingw
1721 $(XTCC) $(SQLITE_OPTIONS) $(SQLITE_CFLAGS) -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
1722
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -100,10 +100,12 @@
100100
/DSQLITE_OMIT_DEPRECATED \
101101
/DSQLITE_ENABLE_EXPLAIN_COMMENTS
102102
103103
SHELL_OPTIONS = /Dmain=sqlite3_shell \
104104
/DSQLITE_OMIT_LOAD_EXTENSION=1 \
105
+ /DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
106
+ /DSQLITE_SHELL_DBNAME_PROC=fossil_open \
105107
/Dgetenv=fossil_getenv \
106108
/Dfopen=fossil_fopen
107109
108110
SRC = add_.c \
109111
allrepo_.c \
110112
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -100,10 +100,12 @@
100 /DSQLITE_OMIT_DEPRECATED \
101 /DSQLITE_ENABLE_EXPLAIN_COMMENTS
102
103 SHELL_OPTIONS = /Dmain=sqlite3_shell \
104 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
 
 
105 /Dgetenv=fossil_getenv \
106 /Dfopen=fossil_fopen
107
108 SRC = add_.c \
109 allrepo_.c \
110
--- win/Makefile.msc
+++ win/Makefile.msc
@@ -100,10 +100,12 @@
100 /DSQLITE_OMIT_DEPRECATED \
101 /DSQLITE_ENABLE_EXPLAIN_COMMENTS
102
103 SHELL_OPTIONS = /Dmain=sqlite3_shell \
104 /DSQLITE_OMIT_LOAD_EXTENSION=1 \
105 /DUSE_SYSTEM_SQLITE=$(USE_SYSTEM_SQLITE) \
106 /DSQLITE_SHELL_DBNAME_PROC=fossil_open \
107 /Dgetenv=fossil_getenv \
108 /Dfopen=fossil_fopen
109
110 SRC = add_.c \
111 allrepo_.c \
112

Keyboard Shortcuts

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