Fossil SCM

Update the built-in SQLite to 3.16.0 alpha for testing.

drh 2016-11-22 22:26 trunk
Commit 31ae6022aaa98410f41cedef8e9dbffe50aa1f54
3 files changed +131 -34 +299 -207 +9 -7
+131 -34
--- src/shell.c
+++ src/shell.c
@@ -1200,11 +1200,10 @@
12001200
setTextMode(p->out, 1);
12011201
break;
12021202
}
12031203
case MODE_Quote:
12041204
case MODE_Insert: {
1205
- p->cnt++;
12061205
if( azArg==0 ) break;
12071206
if( p->cMode==MODE_Insert ){
12081207
utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
12091208
if( p->showHeader ){
12101209
raw_printf(p->out,"(");
@@ -1213,11 +1212,18 @@
12131212
utf8_printf(p->out, "%s%s", zSep, azCol[i]);
12141213
}
12151214
raw_printf(p->out,")");
12161215
}
12171216
raw_printf(p->out," VALUES(");
1217
+ }else if( p->cnt==0 && p->showHeader ){
1218
+ for(i=0; i<nArg; i++){
1219
+ if( i>0 ) raw_printf(p->out, ",");
1220
+ output_quoted_string(p->out, azCol[i]);
1221
+ }
1222
+ raw_printf(p->out,"\n");
12181223
}
1224
+ p->cnt++;
12191225
for(i=0; i<nArg; i++){
12201226
char *zSep = i>0 ? ",": "";
12211227
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
12221228
utf8_printf(p->out,"%sNULL",zSep);
12231229
}else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1899,10 +1905,11 @@
18991905
zSql = zLeftover;
19001906
while( IsSpace(zSql[0]) ) zSql++;
19011907
continue;
19021908
}
19031909
zStmtSql = sqlite3_sql(pStmt);
1910
+ if( zStmtSql==0 ) zStmtSql = "";
19041911
while( IsSpace(zStmtSql[0]) ) zStmtSql++;
19051912
19061913
/* save off the prepared statment handle and reset row count */
19071914
if( pArg ){
19081915
pArg->pStmt = pStmt;
@@ -2161,10 +2168,13 @@
21612168
".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
21622169
".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
21632170
".headers on|off Turn display of headers on or off\n"
21642171
".help Show this message\n"
21652172
".import FILE TABLE Import data from FILE into TABLE\n"
2173
+#ifndef SQLITE_OMIT_TEST_CONTROL
2174
+ ".imposter INDEX TABLE Create imposter table TABLE on index INDEX\n"
2175
+#endif
21662176
".indexes ?TABLE? Show names of all indexes\n"
21672177
" If TABLE specified, only show indexes for tables\n"
21682178
" matching LIKE pattern TABLE.\n"
21692179
#ifdef SQLITE_ENABLE_IOTRACE
21702180
".iotrace FILE Enable I/O diagnostic logging to FILE\n"
@@ -2571,10 +2581,12 @@
25712581
}
25722582
}
25732583
return f;
25742584
}
25752585
2586
+#if !defined(SQLITE_OMIT_BUILTIN_TEST)
2587
+#if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
25762588
/*
25772589
** A routine for handling output from sqlite3_trace().
25782590
*/
25792591
static int sql_trace_callback(
25802592
unsigned mType,
@@ -2591,10 +2603,12 @@
25912603
while( i>0 && z[i-1]==';' ){ i--; }
25922604
utf8_printf(f, "%.*s;\n", i, z);
25932605
}
25942606
return 0;
25952607
}
2608
+#endif
2609
+#endif
25962610
25972611
/*
25982612
** A no-op routine that runs with the ".breakpoint" doc-command. This is
25992613
** a useful spot to set a debugger breakpoint.
26002614
*/
@@ -3843,10 +3857,83 @@
38433857
"Error: querying sqlite_master and sqlite_temp_master\n");
38443858
rc = 1;
38453859
}
38463860
}else
38473861
3862
+#ifndef SQLITE_OMIT_BUILTIN_TEST
3863
+ if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
3864
+ char *zSql;
3865
+ char *zCollist = 0;
3866
+ sqlite3_stmt *pStmt;
3867
+ int tnum = 0;
3868
+ int i;
3869
+ if( nArg!=3 ){
3870
+ utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n");
3871
+ rc = 1;
3872
+ goto meta_command_exit;
3873
+ }
3874
+ open_db(p, 0);
3875
+ zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_master"
3876
+ " WHERE name='%q' AND type='index'", azArg[1]);
3877
+ sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3878
+ sqlite3_free(zSql);
3879
+ if( sqlite3_step(pStmt)==SQLITE_ROW ){
3880
+ tnum = sqlite3_column_int(pStmt, 0);
3881
+ }
3882
+ sqlite3_finalize(pStmt);
3883
+ if( tnum==0 ){
3884
+ utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
3885
+ rc = 1;
3886
+ goto meta_command_exit;
3887
+ }
3888
+ zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
3889
+ rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3890
+ sqlite3_free(zSql);
3891
+ i = 0;
3892
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
3893
+ char zLabel[20];
3894
+ const char *zCol = (const char*)sqlite3_column_text(pStmt,2);
3895
+ i++;
3896
+ if( zCol==0 ){
3897
+ if( sqlite3_column_int(pStmt,1)==-1 ){
3898
+ zCol = "_ROWID_";
3899
+ }else{
3900
+ sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
3901
+ zCol = zLabel;
3902
+ }
3903
+ }
3904
+ if( zCollist==0 ){
3905
+ zCollist = sqlite3_mprintf("\"%w\"", zCol);
3906
+ }else{
3907
+ zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
3908
+ }
3909
+ }
3910
+ sqlite3_finalize(pStmt);
3911
+ zSql = sqlite3_mprintf(
3912
+ "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%s))WITHOUT ROWID",
3913
+ azArg[2], zCollist, zCollist);
3914
+ sqlite3_free(zCollist);
3915
+ rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
3916
+ if( rc==SQLITE_OK ){
3917
+ rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
3918
+ sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
3919
+ if( rc ){
3920
+ utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
3921
+ }else{
3922
+ utf8_printf(stdout, "%s;\n", zSql);
3923
+ raw_printf(stdout,
3924
+ "WARNING: writing to an imposter table will corrupt the index!\n"
3925
+ );
3926
+ }
3927
+ }else{
3928
+ raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
3929
+ rc = 1;
3930
+ }
3931
+ sqlite3_free(zSql);
3932
+ }else
3933
+#endif /* !defined(SQLITE_OMIT_TEST_CONTROL) */
3934
+
38483935
#ifdef SQLITE_ENABLE_IOTRACE
38493936
if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){
38503937
SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...);
38513938
if( iotrace && iotrace!=stdout ) fclose(iotrace);
38523939
iotrace = 0;
@@ -3865,10 +3952,11 @@
38653952
sqlite3IoTrace = iotracePrintf;
38663953
}
38673954
}
38683955
}else
38693956
#endif
3957
+
38703958
if( c=='l' && n>=5 && strncmp(azArg[0], "limits", n)==0 ){
38713959
static const struct {
38723960
const char *zLimitName; /* Name of a limit */
38733961
int limitCode; /* Integer code for that limit */
38743962
} aLimit[] = {
@@ -4696,19 +4784,20 @@
46964784
/* Begin redirecting output to the file "testcase-out.txt" */
46974785
if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
46984786
output_reset(p);
46994787
p->out = output_file_open("testcase-out.txt");
47004788
if( p->out==0 ){
4701
- utf8_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
4789
+ raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
47024790
}
47034791
if( nArg>=2 ){
47044792
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
47054793
}else{
47064794
sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
47074795
}
47084796
}else
47094797
4798
+#ifndef SQLITE_OMIT_BUILTIN_TEST
47104799
if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
47114800
static const struct {
47124801
const char *zCtrlName; /* Name of a test-control option */
47134802
int ctrlCode; /* Integer code for that option */
47144803
} aCtrl[] = {
@@ -4880,10 +4969,11 @@
48804969
}else{
48814970
sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
48824971
}
48834972
#endif
48844973
}else
4974
+#endif /* !defined(SQLITE_OMIT_BUILTIN_TEST) */
48854975
48864976
#if SQLITE_USER_AUTHENTICATION
48874977
if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
48884978
if( nArg<2 ){
48894979
raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
@@ -5087,10 +5177,46 @@
50875177
zSql[nSql+1] = 0;
50885178
rc = sqlite3_complete(zSql);
50895179
zSql[nSql] = 0;
50905180
return rc;
50915181
}
5182
+
5183
+/*
5184
+** Run a single line of SQL
5185
+*/
5186
+static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
5187
+ int rc;
5188
+ char *zErrMsg = 0;
5189
+
5190
+ open_db(p, 0);
5191
+ if( p->backslashOn ) resolve_backslashes(zSql);
5192
+ BEGIN_TIMER;
5193
+ rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
5194
+ END_TIMER;
5195
+ if( rc || zErrMsg ){
5196
+ char zPrefix[100];
5197
+ if( in!=0 || !stdin_is_interactive ){
5198
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix,
5199
+ "Error: near line %d:", startline);
5200
+ }else{
5201
+ sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
5202
+ }
5203
+ if( zErrMsg!=0 ){
5204
+ utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
5205
+ sqlite3_free(zErrMsg);
5206
+ zErrMsg = 0;
5207
+ }else{
5208
+ utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
5209
+ }
5210
+ return 1;
5211
+ }else if( p->countChanges ){
5212
+ raw_printf(p->out, "changes: %3d total_changes: %d\n",
5213
+ sqlite3_changes(p->db), sqlite3_total_changes(p->db));
5214
+ }
5215
+ return 0;
5216
+}
5217
+
50925218
50935219
/*
50945220
** Read input from *in and process it. If *in==0 then input
50955221
** is interactive - the user is typing it it. Otherwise, input
50965222
** is coming from a file or device. A prompt is issued and history
@@ -5104,11 +5230,10 @@
51045230
char *zSql = 0; /* Accumulated SQL text */
51055231
int nLine; /* Length of current line */
51065232
int nSql = 0; /* Bytes of zSql[] used */
51075233
int nAlloc = 0; /* Allocated zSql[] space */
51085234
int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
5109
- char *zErrMsg; /* Error message returned */
51105235
int rc; /* Error code */
51115236
int errCnt = 0; /* Number of errors seen */
51125237
int lineno = 0; /* Current line number */
51135238
int startline = 0; /* Line number for start of current input */
51145239
@@ -5164,36 +5289,11 @@
51645289
memcpy(zSql+nSql, zLine, nLine+1);
51655290
nSql += nLine;
51665291
}
51675292
if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
51685293
&& sqlite3_complete(zSql) ){
5169
- p->cnt = 0;
5170
- open_db(p, 0);
5171
- if( p->backslashOn ) resolve_backslashes(zSql);
5172
- BEGIN_TIMER;
5173
- rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
5174
- END_TIMER;
5175
- if( rc || zErrMsg ){
5176
- char zPrefix[100];
5177
- if( in!=0 || !stdin_is_interactive ){
5178
- sqlite3_snprintf(sizeof(zPrefix), zPrefix,
5179
- "Error: near line %d:", startline);
5180
- }else{
5181
- sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
5182
- }
5183
- if( zErrMsg!=0 ){
5184
- utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
5185
- sqlite3_free(zErrMsg);
5186
- zErrMsg = 0;
5187
- }else{
5188
- utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
5189
- }
5190
- errCnt++;
5191
- }else if( p->countChanges ){
5192
- raw_printf(p->out, "changes: %3d total_changes: %d\n",
5193
- sqlite3_changes(p->db), sqlite3_total_changes(p->db));
5194
- }
5294
+ errCnt += runOneSqlLine(p, zSql, in, startline);
51955295
nSql = 0;
51965296
if( p->outCount ){
51975297
output_reset(p);
51985298
p->outCount = 0;
51995299
}
@@ -5200,15 +5300,12 @@
52005300
}else if( nSql && _all_whitespace(zSql) ){
52015301
if( p->echoOn ) printf("%s\n", zSql);
52025302
nSql = 0;
52035303
}
52045304
}
5205
- if( nSql ){
5206
- if( !_all_whitespace(zSql) ){
5207
- utf8_printf(stderr, "Error: incomplete SQL: %s\n", zSql);
5208
- errCnt++;
5209
- }
5305
+ if( nSql && !_all_whitespace(zSql) ){
5306
+ runOneSqlLine(p, zSql, in, startline);
52105307
}
52115308
free(zSql);
52125309
free(zLine);
52135310
return errCnt>0;
52145311
}
52155312
--- src/shell.c
+++ src/shell.c
@@ -1200,11 +1200,10 @@
1200 setTextMode(p->out, 1);
1201 break;
1202 }
1203 case MODE_Quote:
1204 case MODE_Insert: {
1205 p->cnt++;
1206 if( azArg==0 ) break;
1207 if( p->cMode==MODE_Insert ){
1208 utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
1209 if( p->showHeader ){
1210 raw_printf(p->out,"(");
@@ -1213,11 +1212,18 @@
1213 utf8_printf(p->out, "%s%s", zSep, azCol[i]);
1214 }
1215 raw_printf(p->out,")");
1216 }
1217 raw_printf(p->out," VALUES(");
 
 
 
 
 
 
1218 }
 
1219 for(i=0; i<nArg; i++){
1220 char *zSep = i>0 ? ",": "";
1221 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
1222 utf8_printf(p->out,"%sNULL",zSep);
1223 }else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1899,10 +1905,11 @@
1899 zSql = zLeftover;
1900 while( IsSpace(zSql[0]) ) zSql++;
1901 continue;
1902 }
1903 zStmtSql = sqlite3_sql(pStmt);
 
1904 while( IsSpace(zStmtSql[0]) ) zStmtSql++;
1905
1906 /* save off the prepared statment handle and reset row count */
1907 if( pArg ){
1908 pArg->pStmt = pStmt;
@@ -2161,10 +2168,13 @@
2161 ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
2162 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
2163 ".headers on|off Turn display of headers on or off\n"
2164 ".help Show this message\n"
2165 ".import FILE TABLE Import data from FILE into TABLE\n"
 
 
 
2166 ".indexes ?TABLE? Show names of all indexes\n"
2167 " If TABLE specified, only show indexes for tables\n"
2168 " matching LIKE pattern TABLE.\n"
2169 #ifdef SQLITE_ENABLE_IOTRACE
2170 ".iotrace FILE Enable I/O diagnostic logging to FILE\n"
@@ -2571,10 +2581,12 @@
2571 }
2572 }
2573 return f;
2574 }
2575
 
 
2576 /*
2577 ** A routine for handling output from sqlite3_trace().
2578 */
2579 static int sql_trace_callback(
2580 unsigned mType,
@@ -2591,10 +2603,12 @@
2591 while( i>0 && z[i-1]==';' ){ i--; }
2592 utf8_printf(f, "%.*s;\n", i, z);
2593 }
2594 return 0;
2595 }
 
 
2596
2597 /*
2598 ** A no-op routine that runs with the ".breakpoint" doc-command. This is
2599 ** a useful spot to set a debugger breakpoint.
2600 */
@@ -3843,10 +3857,83 @@
3843 "Error: querying sqlite_master and sqlite_temp_master\n");
3844 rc = 1;
3845 }
3846 }else
3847
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3848 #ifdef SQLITE_ENABLE_IOTRACE
3849 if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){
3850 SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...);
3851 if( iotrace && iotrace!=stdout ) fclose(iotrace);
3852 iotrace = 0;
@@ -3865,10 +3952,11 @@
3865 sqlite3IoTrace = iotracePrintf;
3866 }
3867 }
3868 }else
3869 #endif
 
3870 if( c=='l' && n>=5 && strncmp(azArg[0], "limits", n)==0 ){
3871 static const struct {
3872 const char *zLimitName; /* Name of a limit */
3873 int limitCode; /* Integer code for that limit */
3874 } aLimit[] = {
@@ -4696,19 +4784,20 @@
4696 /* Begin redirecting output to the file "testcase-out.txt" */
4697 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
4698 output_reset(p);
4699 p->out = output_file_open("testcase-out.txt");
4700 if( p->out==0 ){
4701 utf8_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
4702 }
4703 if( nArg>=2 ){
4704 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
4705 }else{
4706 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
4707 }
4708 }else
4709
 
4710 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
4711 static const struct {
4712 const char *zCtrlName; /* Name of a test-control option */
4713 int ctrlCode; /* Integer code for that option */
4714 } aCtrl[] = {
@@ -4880,10 +4969,11 @@
4880 }else{
4881 sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
4882 }
4883 #endif
4884 }else
 
4885
4886 #if SQLITE_USER_AUTHENTICATION
4887 if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
4888 if( nArg<2 ){
4889 raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
@@ -5087,10 +5177,46 @@
5087 zSql[nSql+1] = 0;
5088 rc = sqlite3_complete(zSql);
5089 zSql[nSql] = 0;
5090 return rc;
5091 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5092
5093 /*
5094 ** Read input from *in and process it. If *in==0 then input
5095 ** is interactive - the user is typing it it. Otherwise, input
5096 ** is coming from a file or device. A prompt is issued and history
@@ -5104,11 +5230,10 @@
5104 char *zSql = 0; /* Accumulated SQL text */
5105 int nLine; /* Length of current line */
5106 int nSql = 0; /* Bytes of zSql[] used */
5107 int nAlloc = 0; /* Allocated zSql[] space */
5108 int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
5109 char *zErrMsg; /* Error message returned */
5110 int rc; /* Error code */
5111 int errCnt = 0; /* Number of errors seen */
5112 int lineno = 0; /* Current line number */
5113 int startline = 0; /* Line number for start of current input */
5114
@@ -5164,36 +5289,11 @@
5164 memcpy(zSql+nSql, zLine, nLine+1);
5165 nSql += nLine;
5166 }
5167 if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
5168 && sqlite3_complete(zSql) ){
5169 p->cnt = 0;
5170 open_db(p, 0);
5171 if( p->backslashOn ) resolve_backslashes(zSql);
5172 BEGIN_TIMER;
5173 rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
5174 END_TIMER;
5175 if( rc || zErrMsg ){
5176 char zPrefix[100];
5177 if( in!=0 || !stdin_is_interactive ){
5178 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
5179 "Error: near line %d:", startline);
5180 }else{
5181 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
5182 }
5183 if( zErrMsg!=0 ){
5184 utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
5185 sqlite3_free(zErrMsg);
5186 zErrMsg = 0;
5187 }else{
5188 utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
5189 }
5190 errCnt++;
5191 }else if( p->countChanges ){
5192 raw_printf(p->out, "changes: %3d total_changes: %d\n",
5193 sqlite3_changes(p->db), sqlite3_total_changes(p->db));
5194 }
5195 nSql = 0;
5196 if( p->outCount ){
5197 output_reset(p);
5198 p->outCount = 0;
5199 }
@@ -5200,15 +5300,12 @@
5200 }else if( nSql && _all_whitespace(zSql) ){
5201 if( p->echoOn ) printf("%s\n", zSql);
5202 nSql = 0;
5203 }
5204 }
5205 if( nSql ){
5206 if( !_all_whitespace(zSql) ){
5207 utf8_printf(stderr, "Error: incomplete SQL: %s\n", zSql);
5208 errCnt++;
5209 }
5210 }
5211 free(zSql);
5212 free(zLine);
5213 return errCnt>0;
5214 }
5215
--- src/shell.c
+++ src/shell.c
@@ -1200,11 +1200,10 @@
1200 setTextMode(p->out, 1);
1201 break;
1202 }
1203 case MODE_Quote:
1204 case MODE_Insert: {
 
1205 if( azArg==0 ) break;
1206 if( p->cMode==MODE_Insert ){
1207 utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
1208 if( p->showHeader ){
1209 raw_printf(p->out,"(");
@@ -1213,11 +1212,18 @@
1212 utf8_printf(p->out, "%s%s", zSep, azCol[i]);
1213 }
1214 raw_printf(p->out,")");
1215 }
1216 raw_printf(p->out," VALUES(");
1217 }else if( p->cnt==0 && p->showHeader ){
1218 for(i=0; i<nArg; i++){
1219 if( i>0 ) raw_printf(p->out, ",");
1220 output_quoted_string(p->out, azCol[i]);
1221 }
1222 raw_printf(p->out,"\n");
1223 }
1224 p->cnt++;
1225 for(i=0; i<nArg; i++){
1226 char *zSep = i>0 ? ",": "";
1227 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
1228 utf8_printf(p->out,"%sNULL",zSep);
1229 }else if( aiType && aiType[i]==SQLITE_TEXT ){
@@ -1899,10 +1905,11 @@
1905 zSql = zLeftover;
1906 while( IsSpace(zSql[0]) ) zSql++;
1907 continue;
1908 }
1909 zStmtSql = sqlite3_sql(pStmt);
1910 if( zStmtSql==0 ) zStmtSql = "";
1911 while( IsSpace(zStmtSql[0]) ) zStmtSql++;
1912
1913 /* save off the prepared statment handle and reset row count */
1914 if( pArg ){
1915 pArg->pStmt = pStmt;
@@ -2161,10 +2168,13 @@
2168 ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
2169 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
2170 ".headers on|off Turn display of headers on or off\n"
2171 ".help Show this message\n"
2172 ".import FILE TABLE Import data from FILE into TABLE\n"
2173 #ifndef SQLITE_OMIT_TEST_CONTROL
2174 ".imposter INDEX TABLE Create imposter table TABLE on index INDEX\n"
2175 #endif
2176 ".indexes ?TABLE? Show names of all indexes\n"
2177 " If TABLE specified, only show indexes for tables\n"
2178 " matching LIKE pattern TABLE.\n"
2179 #ifdef SQLITE_ENABLE_IOTRACE
2180 ".iotrace FILE Enable I/O diagnostic logging to FILE\n"
@@ -2571,10 +2581,12 @@
2581 }
2582 }
2583 return f;
2584 }
2585
2586 #if !defined(SQLITE_OMIT_BUILTIN_TEST)
2587 #if !defined(SQLITE_OMIT_TRACE) && !defined(SQLITE_OMIT_FLOATING_POINT)
2588 /*
2589 ** A routine for handling output from sqlite3_trace().
2590 */
2591 static int sql_trace_callback(
2592 unsigned mType,
@@ -2591,10 +2603,12 @@
2603 while( i>0 && z[i-1]==';' ){ i--; }
2604 utf8_printf(f, "%.*s;\n", i, z);
2605 }
2606 return 0;
2607 }
2608 #endif
2609 #endif
2610
2611 /*
2612 ** A no-op routine that runs with the ".breakpoint" doc-command. This is
2613 ** a useful spot to set a debugger breakpoint.
2614 */
@@ -3843,10 +3857,83 @@
3857 "Error: querying sqlite_master and sqlite_temp_master\n");
3858 rc = 1;
3859 }
3860 }else
3861
3862 #ifndef SQLITE_OMIT_BUILTIN_TEST
3863 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
3864 char *zSql;
3865 char *zCollist = 0;
3866 sqlite3_stmt *pStmt;
3867 int tnum = 0;
3868 int i;
3869 if( nArg!=3 ){
3870 utf8_printf(stderr, "Usage: .imposter INDEX IMPOSTER\n");
3871 rc = 1;
3872 goto meta_command_exit;
3873 }
3874 open_db(p, 0);
3875 zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_master"
3876 " WHERE name='%q' AND type='index'", azArg[1]);
3877 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3878 sqlite3_free(zSql);
3879 if( sqlite3_step(pStmt)==SQLITE_ROW ){
3880 tnum = sqlite3_column_int(pStmt, 0);
3881 }
3882 sqlite3_finalize(pStmt);
3883 if( tnum==0 ){
3884 utf8_printf(stderr, "no such index: \"%s\"\n", azArg[1]);
3885 rc = 1;
3886 goto meta_command_exit;
3887 }
3888 zSql = sqlite3_mprintf("PRAGMA index_xinfo='%q'", azArg[1]);
3889 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
3890 sqlite3_free(zSql);
3891 i = 0;
3892 while( sqlite3_step(pStmt)==SQLITE_ROW ){
3893 char zLabel[20];
3894 const char *zCol = (const char*)sqlite3_column_text(pStmt,2);
3895 i++;
3896 if( zCol==0 ){
3897 if( sqlite3_column_int(pStmt,1)==-1 ){
3898 zCol = "_ROWID_";
3899 }else{
3900 sqlite3_snprintf(sizeof(zLabel),zLabel,"expr%d",i);
3901 zCol = zLabel;
3902 }
3903 }
3904 if( zCollist==0 ){
3905 zCollist = sqlite3_mprintf("\"%w\"", zCol);
3906 }else{
3907 zCollist = sqlite3_mprintf("%z,\"%w\"", zCollist, zCol);
3908 }
3909 }
3910 sqlite3_finalize(pStmt);
3911 zSql = sqlite3_mprintf(
3912 "CREATE TABLE \"%w\"(%s,PRIMARY KEY(%s))WITHOUT ROWID",
3913 azArg[2], zCollist, zCollist);
3914 sqlite3_free(zCollist);
3915 rc = sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 1, tnum);
3916 if( rc==SQLITE_OK ){
3917 rc = sqlite3_exec(p->db, zSql, 0, 0, 0);
3918 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 0);
3919 if( rc ){
3920 utf8_printf(stderr, "Error in [%s]: %s\n", zSql, sqlite3_errmsg(p->db));
3921 }else{
3922 utf8_printf(stdout, "%s;\n", zSql);
3923 raw_printf(stdout,
3924 "WARNING: writing to an imposter table will corrupt the index!\n"
3925 );
3926 }
3927 }else{
3928 raw_printf(stderr, "SQLITE_TESTCTRL_IMPOSTER returns %d\n", rc);
3929 rc = 1;
3930 }
3931 sqlite3_free(zSql);
3932 }else
3933 #endif /* !defined(SQLITE_OMIT_TEST_CONTROL) */
3934
3935 #ifdef SQLITE_ENABLE_IOTRACE
3936 if( c=='i' && strncmp(azArg[0], "iotrace", n)==0 ){
3937 SQLITE_API extern void (SQLITE_CDECL *sqlite3IoTrace)(const char*, ...);
3938 if( iotrace && iotrace!=stdout ) fclose(iotrace);
3939 iotrace = 0;
@@ -3865,10 +3952,11 @@
3952 sqlite3IoTrace = iotracePrintf;
3953 }
3954 }
3955 }else
3956 #endif
3957
3958 if( c=='l' && n>=5 && strncmp(azArg[0], "limits", n)==0 ){
3959 static const struct {
3960 const char *zLimitName; /* Name of a limit */
3961 int limitCode; /* Integer code for that limit */
3962 } aLimit[] = {
@@ -4696,19 +4784,20 @@
4784 /* Begin redirecting output to the file "testcase-out.txt" */
4785 if( c=='t' && strcmp(azArg[0],"testcase")==0 ){
4786 output_reset(p);
4787 p->out = output_file_open("testcase-out.txt");
4788 if( p->out==0 ){
4789 raw_printf(stderr, "Error: cannot open 'testcase-out.txt'\n");
4790 }
4791 if( nArg>=2 ){
4792 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "%s", azArg[1]);
4793 }else{
4794 sqlite3_snprintf(sizeof(p->zTestcase), p->zTestcase, "?");
4795 }
4796 }else
4797
4798 #ifndef SQLITE_OMIT_BUILTIN_TEST
4799 if( c=='t' && n>=8 && strncmp(azArg[0], "testctrl", n)==0 && nArg>=2 ){
4800 static const struct {
4801 const char *zCtrlName; /* Name of a test-control option */
4802 int ctrlCode; /* Integer code for that option */
4803 } aCtrl[] = {
@@ -4880,10 +4969,11 @@
4969 }else{
4970 sqlite3_trace_v2(p->db, SQLITE_TRACE_STMT, sql_trace_callback,p->traceOut);
4971 }
4972 #endif
4973 }else
4974 #endif /* !defined(SQLITE_OMIT_BUILTIN_TEST) */
4975
4976 #if SQLITE_USER_AUTHENTICATION
4977 if( c=='u' && strncmp(azArg[0], "user", n)==0 ){
4978 if( nArg<2 ){
4979 raw_printf(stderr, "Usage: .user SUBCOMMAND ...\n");
@@ -5087,10 +5177,46 @@
5177 zSql[nSql+1] = 0;
5178 rc = sqlite3_complete(zSql);
5179 zSql[nSql] = 0;
5180 return rc;
5181 }
5182
5183 /*
5184 ** Run a single line of SQL
5185 */
5186 static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
5187 int rc;
5188 char *zErrMsg = 0;
5189
5190 open_db(p, 0);
5191 if( p->backslashOn ) resolve_backslashes(zSql);
5192 BEGIN_TIMER;
5193 rc = shell_exec(p->db, zSql, shell_callback, p, &zErrMsg);
5194 END_TIMER;
5195 if( rc || zErrMsg ){
5196 char zPrefix[100];
5197 if( in!=0 || !stdin_is_interactive ){
5198 sqlite3_snprintf(sizeof(zPrefix), zPrefix,
5199 "Error: near line %d:", startline);
5200 }else{
5201 sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
5202 }
5203 if( zErrMsg!=0 ){
5204 utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
5205 sqlite3_free(zErrMsg);
5206 zErrMsg = 0;
5207 }else{
5208 utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
5209 }
5210 return 1;
5211 }else if( p->countChanges ){
5212 raw_printf(p->out, "changes: %3d total_changes: %d\n",
5213 sqlite3_changes(p->db), sqlite3_total_changes(p->db));
5214 }
5215 return 0;
5216 }
5217
5218
5219 /*
5220 ** Read input from *in and process it. If *in==0 then input
5221 ** is interactive - the user is typing it it. Otherwise, input
5222 ** is coming from a file or device. A prompt is issued and history
@@ -5104,11 +5230,10 @@
5230 char *zSql = 0; /* Accumulated SQL text */
5231 int nLine; /* Length of current line */
5232 int nSql = 0; /* Bytes of zSql[] used */
5233 int nAlloc = 0; /* Allocated zSql[] space */
5234 int nSqlPrior = 0; /* Bytes of zSql[] used by prior line */
 
5235 int rc; /* Error code */
5236 int errCnt = 0; /* Number of errors seen */
5237 int lineno = 0; /* Current line number */
5238 int startline = 0; /* Line number for start of current input */
5239
@@ -5164,36 +5289,11 @@
5289 memcpy(zSql+nSql, zLine, nLine+1);
5290 nSql += nLine;
5291 }
5292 if( nSql && line_contains_semicolon(&zSql[nSqlPrior], nSql-nSqlPrior)
5293 && sqlite3_complete(zSql) ){
5294 errCnt += runOneSqlLine(p, zSql, in, startline);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5295 nSql = 0;
5296 if( p->outCount ){
5297 output_reset(p);
5298 p->outCount = 0;
5299 }
@@ -5200,15 +5300,12 @@
5300 }else if( nSql && _all_whitespace(zSql) ){
5301 if( p->echoOn ) printf("%s\n", zSql);
5302 nSql = 0;
5303 }
5304 }
5305 if( nSql && !_all_whitespace(zSql) ){
5306 runOneSqlLine(p, zSql, in, startline);
 
 
 
5307 }
5308 free(zSql);
5309 free(zLine);
5310 return errCnt>0;
5311 }
5312
+299 -207
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,15 +381,15 @@
381381
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382382
** [sqlite_version()] and [sqlite_source_id()].
383383
*/
384384
#define SQLITE_VERSION "3.16.0"
385385
#define SQLITE_VERSION_NUMBER 3016000
386
-#define SQLITE_SOURCE_ID "2016-11-02 14:50:19 3028845329c9b7acdec2ec8b01d00d782347454c"
386
+#define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9"
387387
388388
/*
389389
** CAPI3REF: Run-Time Library Version Numbers
390
-** KEYWORDS: sqlite3_version, sqlite3_sourceid
390
+** KEYWORDS: sqlite3_version sqlite3_sourceid
391391
**
392392
** These interfaces provide the same information as the [SQLITE_VERSION],
393393
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
394394
** but are associated with the library instead of the header file. ^(Cautious
395395
** programmers might include assert() statements in their application to
@@ -8483,11 +8483,12 @@
84838483
** triggers; or 2 for changes resulting from triggers called by top-level
84848484
** triggers; and so forth.
84858485
**
84868486
** See also: [sqlite3_update_hook()]
84878487
*/
8488
-SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_preupdate_hook(
8488
+#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
8489
+SQLITE_API void *sqlite3_preupdate_hook(
84898490
sqlite3 *db,
84908491
void(*xPreUpdate)(
84918492
void *pCtx, /* Copy of third arg to preupdate_hook() */
84928493
sqlite3 *db, /* Database handle */
84938494
int op, /* SQLITE_UPDATE, DELETE or INSERT */
@@ -8496,14 +8497,15 @@
84968497
sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
84978498
sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
84988499
),
84998500
void*
85008501
);
8501
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8502
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_count(sqlite3 *);
8503
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_depth(sqlite3 *);
8504
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
8502
+SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8503
+SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
8504
+SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
8505
+SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
8506
+#endif
85058507
85068508
/*
85078509
** CAPI3REF: Low-level system error code
85088510
**
85098511
** ^Attempt to return the underlying operating system error code or error
@@ -12307,10 +12309,12 @@
1230712309
*/
1230812310
struct BtreePayload {
1230912311
const void *pKey; /* Key content for indexes. NULL for tables */
1231012312
sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
1231112313
const void *pData; /* Data for tables. NULL for indexes */
12314
+ struct Mem *aMem; /* First of nMem value in the unpacked pKey */
12315
+ u16 nMem; /* Number of aMem[] value. Might be zero */
1231212316
int nData; /* Size of pData. 0 if none. */
1231312317
int nZero; /* Extra zero data appended after pData,nData */
1231412318
};
1231512319
1231612320
SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
@@ -12340,10 +12344,11 @@
1234012344
SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
1234112345
1234212346
#ifndef NDEBUG
1234312347
SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
1234412348
#endif
12349
+SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*);
1234512350
1234612351
#ifndef SQLITE_OMIT_BTREECOUNT
1234712352
SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *);
1234812353
#endif
1234912354
@@ -15596,19 +15601,19 @@
1559615601
int iReg; /* Reg with value of this column. 0 means none. */
1559715602
int lru; /* Least recently used entry has the smallest value */
1559815603
} aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
1559915604
int aTempReg[8]; /* Holding area for temporary registers */
1560015605
Token sNameToken; /* Token with unqualified schema object name */
15601
- Token sLastToken; /* The last token parsed */
1560215606
1560315607
/************************************************************************
1560415608
** Above is constant between recursions. Below is reset before and after
1560515609
** each recursion. The boundary between these two regions is determined
15606
- ** using offsetof(Parse,nVar) so the nVar field must be the first field
15607
- ** in the recursive region.
15610
+ ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
15611
+ ** first field in the recursive region.
1560815612
************************************************************************/
1560915613
15614
+ Token sLastToken; /* The last token parsed */
1561015615
ynVar nVar; /* Number of '?' variables seen in the SQL so far */
1561115616
int nzVar; /* Number of available slots in azVar[] */
1561215617
u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
1561315618
u8 explain; /* True if the EXPLAIN flag is found on the query */
1561415619
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -15638,11 +15643,11 @@
1563815643
1563915644
/*
1564015645
** Sizes and pointers of various parts of the Parse object.
1564115646
*/
1564215647
#define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
15643
-#define PARSE_RECURSE_SZ offsetof(Parse,nVar) /* Recursive part */
15648
+#define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
1564415649
#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
1564515650
#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
1564615651
1564715652
/*
1564815653
** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -16355,10 +16360,11 @@
1635516360
SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
1635616361
SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
1635716362
#define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
1635816363
#define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
1635916364
#define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
16365
+#define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */
1636016366
SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
1636116367
SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
1636216368
SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
1636316369
SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
1636416370
#define LOCATE_VIEW 0x01
@@ -17802,11 +17808,14 @@
1780217808
int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
1780317809
VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
1780417810
} uc;
1780517811
Btree *pBt; /* Separate file holding temporary table */
1780617812
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
17807
- int seekResult; /* Result of previous sqlite3BtreeMoveto() */
17813
+ int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
17814
+ ** if there have been no prior seeks on the cursor. */
17815
+ /* NB: seekResult does not distinguish between "no seeks have ever occurred
17816
+ ** on this cursor" and "the most recent seek was an exact match". */
1780817817
i64 seqCount; /* Sequence counter */
1780917818
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
1781017819
VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
1781117820
int *aAltMap; /* Mapping from table to index column numbers */
1781217821
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
@@ -25889,10 +25898,11 @@
2588925898
sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
2589025899
}
2589125900
va_start(ap, zFormat);
2589225901
sqlite3VXPrintf(&acc, zFormat, ap);
2589325902
va_end(ap);
25903
+ assert( acc.nChar>0 );
2589425904
if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
2589525905
sqlite3StrAccumFinish(&acc);
2589625906
fprintf(stdout,"%s", zBuf);
2589725907
fflush(stdout);
2589825908
}
@@ -50417,11 +50427,14 @@
5041750427
sqlite3BeginBenignMalloc();
5041850428
pagerFreeMapHdrs(pPager);
5041950429
/* pPager->errCode = 0; */
5042050430
pPager->exclusiveMode = 0;
5042150431
#ifndef SQLITE_OMIT_WAL
50422
- sqlite3WalClose(pPager->pWal,db,pPager->ckptSyncFlags,pPager->pageSize,pTmp);
50432
+ assert( db || pPager->pWal==0 );
50433
+ sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, pPager->pageSize,
50434
+ (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp)
50435
+ );
5042350436
pPager->pWal = 0;
5042450437
#endif
5042550438
pager_reset(pPager);
5042650439
if( MEMDB ){
5042750440
pager_unlock(pPager);
@@ -55752,11 +55765,11 @@
5575255765
** the database. In this case checkpoint the database and unlink both
5575355766
** the wal and wal-index files.
5575455767
**
5575555768
** The EXCLUSIVE lock is not released before returning.
5575655769
*/
55757
- if( (db->flags & SQLITE_NoCkptOnClose)==0
55770
+ if( zBuf!=0
5575855771
&& SQLITE_OK==(rc = sqlite3OsLock(pWal->pDbFd, SQLITE_LOCK_EXCLUSIVE))
5575955772
){
5576055773
if( pWal->exclusiveMode==WAL_NORMAL_MODE ){
5576155774
pWal->exclusiveMode = WAL_EXCLUSIVE_MODE;
5576255775
}
@@ -62555,10 +62568,14 @@
6255562568
*/
6255662569
SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor *pCur){
6255762570
return pCur && pCur->eState==CURSOR_VALID;
6255862571
}
6255962572
#endif /* NDEBUG */
62573
+SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor *pCur){
62574
+ assert( pCur!=0 );
62575
+ return pCur->eState==CURSOR_VALID;
62576
+}
6256062577
6256162578
/*
6256262579
** Return the value of the integer key or "rowid" for a table btree.
6256362580
** This routine is only valid for a cursor that is pointing into a
6256462581
** ordinary table btree. If the cursor points to an index btree or
@@ -63442,20 +63459,20 @@
6344263459
}else if( nCellKey>intKey ){
6344363460
upr = idx-1;
6344463461
if( lwr>upr ){ c = +1; break; }
6344563462
}else{
6344663463
assert( nCellKey==intKey );
63447
- pCur->curFlags |= BTCF_ValidNKey;
63448
- pCur->info.nKey = nCellKey;
6344963464
pCur->aiIdx[pCur->iPage] = (u16)idx;
6345063465
if( !pPage->leaf ){
6345163466
lwr = idx;
6345263467
goto moveto_next_layer;
6345363468
}else{
63469
+ pCur->curFlags |= BTCF_ValidNKey;
63470
+ pCur->info.nKey = nCellKey;
63471
+ pCur->info.nSize = 0;
6345463472
*pRes = 0;
63455
- rc = SQLITE_OK;
63456
- goto moveto_finish;
63473
+ return SQLITE_OK;
6345763474
}
6345863475
}
6345963476
assert( lwr+upr>=0 );
6346063477
idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */
6346163478
}
@@ -63562,11 +63579,11 @@
6356263579
rc = moveToChild(pCur, chldPg);
6356363580
if( rc ) break;
6356463581
}
6356563582
moveto_finish:
6356663583
pCur->info.nSize = 0;
63567
- pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63584
+ assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
6356863585
return rc;
6356963586
}
6357063587
6357163588
6357263589
/*
@@ -63760,11 +63777,11 @@
6376063777
return SQLITE_OK;
6376163778
}
6376263779
moveToParent(pCur);
6376363780
}
6376463781
assert( pCur->info.nSize==0 );
63765
- assert( (pCur->curFlags & (BTCF_ValidNKey|BTCF_ValidOvfl))==0 );
63782
+ assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
6376663783
6376763784
pCur->aiIdx[pCur->iPage]--;
6376863785
pPage = pCur->apPage[pCur->iPage];
6376963786
if( pPage->intKey && !pPage->leaf ){
6377063787
rc = sqlite3BtreePrevious(pCur, pRes);
@@ -66217,21 +66234,23 @@
6621766234
** For an index btree (used for indexes and WITHOUT ROWID tables), the
6621866235
** key is an arbitrary byte sequence stored in pX.pKey,nKey. The
6621966236
** pX.pData,nData,nZero fields must be zero.
6622066237
**
6622166238
** If the seekResult parameter is non-zero, then a successful call to
66222
-** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
66223
-** been performed. seekResult is the search result returned (a negative
66224
-** number if pCur points at an entry that is smaller than (pKey, nKey), or
66225
-** a positive value if pCur points at an entry that is larger than
66226
-** (pKey, nKey)).
66239
+** MovetoUnpacked() to seek cursor pCur to (pKey,nKey) has already
66240
+** been performed. In other words, if seekResult!=0 then the cursor
66241
+** is currently pointing to a cell that will be adjacent to the cell
66242
+** to be inserted. If seekResult<0 then pCur points to a cell that is
66243
+** smaller then (pKey,nKey). If seekResult>0 then pCur points to a cell
66244
+** that is larger than (pKey,nKey).
6622766245
**
66228
-** If the seekResult parameter is non-zero, then the caller guarantees that
66229
-** cursor pCur is pointing at the existing copy of a row that is to be
66230
-** overwritten. If the seekResult parameter is 0, then cursor pCur may
66231
-** point to any entry or to no entry at all and so this function has to seek
66232
-** the cursor before the new key can be inserted.
66246
+** If seekResult==0, that means pCur is pointing at some unknown location.
66247
+** In that case, this routine must seek the cursor to the correct insertion
66248
+** point for (pKey,nKey) before doing the insertion. For index btrees,
66249
+** if pX->nMem is non-zero, then pX->aMem contains pointers to the unpacked
66250
+** key values and pX->aMem can be used instead of pX->pKey to avoid having
66251
+** to decode the key.
6623366252
*/
6623466253
SQLITE_PRIVATE int sqlite3BtreeInsert(
6623566254
BtCursor *pCur, /* Insert data into the table of this cursor */
6623666255
const BtreePayload *pX, /* Content of the row to be inserted */
6623766256
int appendBias, /* True if this is likely an append */
@@ -66288,19 +66307,30 @@
6628866307
invalidateIncrblobCursors(p, pX->nKey, 0);
6628966308
6629066309
/* If the cursor is currently on the last row and we are appending a
6629166310
** new row onto the end, set the "loc" to avoid an unnecessary
6629266311
** btreeMoveto() call */
66293
- if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
66294
- && pCur->info.nKey==pX->nKey-1 ){
66295
- loc = -1;
66312
+ if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
66313
+ loc = 0;
66314
+ }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
66315
+ && pCur->info.nKey==pX->nKey-1 ){
66316
+ loc = -1;
6629666317
}else if( loc==0 ){
6629766318
rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc);
6629866319
if( rc ) return rc;
6629966320
}
6630066321
}else if( loc==0 ){
66301
- rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
66322
+ if( pX->nMem ){
66323
+ UnpackedRecord r;
66324
+ memset(&r, 0, sizeof(r));
66325
+ r.pKeyInfo = pCur->pKeyInfo;
66326
+ r.aMem = pX->aMem;
66327
+ r.nField = pX->nMem;
66328
+ rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc);
66329
+ }else{
66330
+ rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
66331
+ }
6630266332
if( rc ) return rc;
6630366333
}
6630466334
assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
6630566335
6630666336
pPage = pCur->apPage[pCur->iPage];
@@ -66838,31 +66868,11 @@
6683866868
MemPage *pPage = 0;
6683966869
BtShared *pBt = p->pBt;
6684066870
6684166871
assert( sqlite3BtreeHoldsMutex(p) );
6684266872
assert( p->inTrans==TRANS_WRITE );
66843
-
66844
- /* It is illegal to drop a table if any cursors are open on the
66845
- ** database. This is because in auto-vacuum mode the backend may
66846
- ** need to move another root-page to fill a gap left by the deleted
66847
- ** root page. If an open cursor was using this page a problem would
66848
- ** occur.
66849
- **
66850
- ** This error is caught long before control reaches this point.
66851
- */
66852
- if( NEVER(pBt->pCursor) ){
66853
- sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
66854
- return SQLITE_LOCKED_SHAREDCACHE;
66855
- }
66856
-
66857
- /*
66858
- ** It is illegal to drop the sqlite_master table on page 1. But again,
66859
- ** this error is caught long before reaching this point.
66860
- */
66861
- if( NEVER(iTable<2) ){
66862
- return SQLITE_CORRUPT_BKPT;
66863
- }
66873
+ assert( iTable>=2 );
6686466874
6686566875
rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
6686666876
if( rc ) return rc;
6686766877
rc = sqlite3BtreeClearTable(p, iTable, 0);
6686866878
if( rc ){
@@ -81675,19 +81685,14 @@
8167581685
** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
8167681686
** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set,
8167781687
** then rowid is stored for subsequent return by the
8167881688
** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
8167981689
**
81680
-** If the OPFLAG_USESEEKRESULT flag of P5 is set and if the result of
81681
-** the last seek operation (OP_NotExists or OP_SeekRowid) was a success,
81682
-** then this
81683
-** operation will not attempt to find the appropriate row before doing
81684
-** the insert but will instead overwrite the row that the cursor is
81685
-** currently pointing to. Presumably, the prior OP_NotExists or
81686
-** OP_SeekRowid opcode
81687
-** has already positioned the cursor correctly. This is an optimization
81688
-** that boosts performance by avoiding redundant seeks.
81690
+** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
81691
+** run faster by avoiding an unnecessary seek on cursor P1. However,
81692
+** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
81693
+** seeks on the cursor or if the most recent seek used a key equal to P3.
8168981694
**
8169081695
** If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
8169181696
** UPDATE operation. Otherwise (if the flag is clear) then this opcode
8169281697
** is part of an INSERT operation. The difference is only important to
8169381698
** the update hook.
@@ -81907,10 +81912,11 @@
8190781912
}
8190881913
#endif
8190981914
8191081915
rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5);
8191181916
pC->cacheStatus = CACHE_STALE;
81917
+ pC->seekResult = 0;
8191281918
if( rc ) goto abort_due_to_error;
8191381919
8191481920
/* Invoke the update-hook if required. */
8191581921
if( opflags & OPFLAG_NCHANGE ){
8191681922
p->nChange++;
@@ -82156,10 +82162,17 @@
8215682162
** to the following instruction.
8215782163
**
8215882164
** This opcode leaves the cursor configured to move in reverse order,
8215982165
** from the end toward the beginning. In other words, the cursor is
8216082166
** configured to use Prev, not Next.
82167
+**
82168
+** If P3 is -1, then the cursor is positioned at the end of the btree
82169
+** for the purpose of appending a new entry onto the btree. In that
82170
+** case P2 must be 0. It is assumed that the cursor is used only for
82171
+** appending and so if the cursor is valid, then the cursor must already
82172
+** be pointing at the end of the btree and so no changes are made to
82173
+** the cursor.
8216182174
*/
8216282175
case OP_Last: { /* jump */
8216382176
VdbeCursor *pC;
8216482177
BtCursor *pCrsr;
8216582178
int res;
@@ -82169,22 +82182,26 @@
8216982182
assert( pC!=0 );
8217082183
assert( pC->eCurType==CURTYPE_BTREE );
8217182184
pCrsr = pC->uc.pCursor;
8217282185
res = 0;
8217382186
assert( pCrsr!=0 );
82174
- rc = sqlite3BtreeLast(pCrsr, &res);
82175
- pC->nullRow = (u8)res;
82176
- pC->deferredMoveto = 0;
82177
- pC->cacheStatus = CACHE_STALE;
8217882187
pC->seekResult = pOp->p3;
8217982188
#ifdef SQLITE_DEBUG
8218082189
pC->seekOp = OP_Last;
8218182190
#endif
82182
- if( rc ) goto abort_due_to_error;
82183
- if( pOp->p2>0 ){
82184
- VdbeBranchTaken(res!=0,2);
82185
- if( res ) goto jump_to_p2;
82191
+ if( pOp->p3==0 || !sqlite3BtreeCursorIsValidNN(pCrsr) ){
82192
+ rc = sqlite3BtreeLast(pCrsr, &res);
82193
+ pC->nullRow = (u8)res;
82194
+ pC->deferredMoveto = 0;
82195
+ pC->cacheStatus = CACHE_STALE;
82196
+ if( rc ) goto abort_due_to_error;
82197
+ if( pOp->p2>0 ){
82198
+ VdbeBranchTaken(res!=0,2);
82199
+ if( res ) goto jump_to_p2;
82200
+ }
82201
+ }else{
82202
+ assert( pOp->p2==0 );
8218682203
}
8218782204
break;
8218882205
}
8218982206
8219082207
@@ -82369,27 +82386,34 @@
8236982386
pC->nullRow = 1;
8237082387
}
8237182388
goto check_for_interrupt;
8237282389
}
8237382390
82374
-/* Opcode: IdxInsert P1 P2 P3 * P5
82391
+/* Opcode: IdxInsert P1 P2 P3 P4 P5
8237582392
** Synopsis: key=r[P2]
8237682393
**
8237782394
** Register P2 holds an SQL index key made using the
8237882395
** MakeRecord instructions. This opcode writes that key
8237982396
** into the index P1. Data for the entry is nil.
8238082397
**
82381
-** P3 is a flag that provides a hint to the b-tree layer that this
82382
-** insert is likely to be an append.
82398
+** If P4 is not zero, then it is the number of values in the unpacked
82399
+** key of reg(P2). In that case, P3 is the index of the first register
82400
+** for the unpacked key. The availability of the unpacked key can sometimes
82401
+** be an optimization.
82402
+**
82403
+** If P5 has the OPFLAG_APPEND bit set, that is a hint to the b-tree layer
82404
+** that this insert is likely to be an append.
8238382405
**
8238482406
** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
8238582407
** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
8238682408
** then the change counter is unchanged.
8238782409
**
82388
-** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have
82389
-** just done a seek to the spot where the new entry is to be inserted.
82390
-** This flag avoids doing an extra seek.
82410
+** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
82411
+** run faster by avoiding an unnecessary seek on cursor P1. However,
82412
+** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
82413
+** seeks on the cursor or if the most recent seek used a key equivalent
82414
+** to P2.
8239182415
**
8239282416
** This instruction only works for indices. The equivalent instruction
8239382417
** for tables is OP_Insert.
8239482418
*/
8239582419
/* Opcode: SorterInsert P1 P2 * * *
@@ -82418,11 +82442,14 @@
8241882442
if( pOp->opcode==OP_SorterInsert ){
8241982443
rc = sqlite3VdbeSorterWrite(pC, pIn2);
8242082444
}else{
8242182445
x.nKey = pIn2->n;
8242282446
x.pKey = pIn2->z;
82423
- rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, pOp->p3,
82447
+ x.aMem = aMem + pOp->p3;
82448
+ x.nMem = (u16)pOp->p4.i;
82449
+ rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
82450
+ (pOp->p5 & OPFLAG_APPEND)!=0,
8242482451
((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
8242582452
);
8242682453
assert( pC->deferredMoveto==0 );
8242782454
pC->cacheStatus = CACHE_STALE;
8242882455
}
@@ -82462,10 +82489,11 @@
8246282489
rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE);
8246382490
if( rc ) goto abort_due_to_error;
8246482491
}
8246582492
assert( pC->deferredMoveto==0 );
8246682493
pC->cacheStatus = CACHE_STALE;
82494
+ pC->seekResult = 0;
8246782495
break;
8246882496
}
8246982497
8247082498
/* Opcode: Seek P1 * P3 P4 *
8247182499
** Synopsis: Move P3 to P1.rowid
@@ -84648,12 +84676,11 @@
8464884676
{OP_Variable, 1, 1, 0}, /* 2: Move ?1 into reg[1] */
8464984677
{OP_NotExists, 0, 7, 1}, /* 3: Seek the cursor */
8465084678
{OP_Column, 0, 0, 1}, /* 4 */
8465184679
{OP_ResultRow, 1, 0, 0}, /* 5 */
8465284680
{OP_Goto, 0, 2, 0}, /* 6 */
84653
- {OP_Close, 0, 0, 0}, /* 7 */
84654
- {OP_Halt, 0, 0, 0}, /* 8 */
84681
+ {OP_Halt, 0, 0, 0}, /* 7 */
8465584682
};
8465684683
Vdbe *v = (Vdbe *)pBlob->pStmt;
8465784684
int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
8465884685
VdbeOp *aOp;
8465984686
@@ -88636,10 +88663,14 @@
8863688663
assert( pExpr->x.pSelect==0 );
8863788664
pOrig = pEList->a[j].pExpr;
8863888665
if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
8863988666
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
8864088667
return WRC_Abort;
88668
+ }
88669
+ if( sqlite3ExprVectorSize(pOrig)!=1 ){
88670
+ sqlite3ErrorMsg(pParse, "row value misused");
88671
+ return WRC_Abort;
8864188672
}
8864288673
resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
8864388674
cnt = 1;
8864488675
pMatch = 0;
8864588676
assert( zTab==0 && zDb==0 );
@@ -89013,10 +89044,11 @@
8901389044
}
8901489045
case TK_VARIABLE: {
8901589046
notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
8901689047
break;
8901789048
}
89049
+ case TK_BETWEEN:
8901889050
case TK_EQ:
8901989051
case TK_NE:
8902089052
case TK_LT:
8902189053
case TK_LE:
8902289054
case TK_GT:
@@ -89023,23 +89055,31 @@
8902389055
case TK_GE:
8902489056
case TK_IS:
8902589057
case TK_ISNOT: {
8902689058
int nLeft, nRight;
8902789059
if( pParse->db->mallocFailed ) break;
89028
- assert( pExpr->pRight!=0 );
8902989060
assert( pExpr->pLeft!=0 );
8903089061
nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
89031
- nRight = sqlite3ExprVectorSize(pExpr->pRight);
89062
+ if( pExpr->op==TK_BETWEEN ){
89063
+ nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
89064
+ if( nRight==nLeft ){
89065
+ nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
89066
+ }
89067
+ }else{
89068
+ assert( pExpr->pRight!=0 );
89069
+ nRight = sqlite3ExprVectorSize(pExpr->pRight);
89070
+ }
8903289071
if( nLeft!=nRight ){
8903389072
testcase( pExpr->op==TK_EQ );
8903489073
testcase( pExpr->op==TK_NE );
8903589074
testcase( pExpr->op==TK_LT );
8903689075
testcase( pExpr->op==TK_LE );
8903789076
testcase( pExpr->op==TK_GT );
8903889077
testcase( pExpr->op==TK_GE );
8903989078
testcase( pExpr->op==TK_IS );
8904089079
testcase( pExpr->op==TK_ISNOT );
89080
+ testcase( pExpr->op==TK_BETWEEN );
8904189081
sqlite3ErrorMsg(pParse, "row value misused");
8904289082
}
8904389083
break;
8904489084
}
8904589085
}
@@ -92306,11 +92346,11 @@
9230692346
VdbeCoverage(v);
9230792347
sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
9230892348
}else{
9230992349
sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
9231092350
sqlite3ExprCacheAffinityChange(pParse, r3, 1);
92311
- sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
92351
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pExpr->iTable, r2, r3, 1);
9231292352
}
9231392353
}
9231492354
}
9231592355
sqlite3ReleaseTempReg(pParse, r1);
9231692356
sqlite3ReleaseTempReg(pParse, r2);
@@ -93854,12 +93894,17 @@
9385493894
assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
9385593895
n = pList->nExpr;
9385693896
if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
9385793897
for(pItem=pList->a, i=0; i<n; i++, pItem++){
9385893898
Expr *pExpr = pItem->pExpr;
93859
- if( (flags & SQLITE_ECEL_REF)!=0 && (j = pList->a[i].u.x.iOrderByCol)>0 ){
93860
- sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
93899
+ if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
93900
+ if( flags & SQLITE_ECEL_OMITREF ){
93901
+ i--;
93902
+ n--;
93903
+ }else{
93904
+ sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
93905
+ }
9386193906
}else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
9386293907
sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
9386393908
}else{
9386493909
int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
9386593910
if( inReg!=target+i ){
@@ -97815,10 +97860,11 @@
9781597860
NameContext sName;
9781697861
Vdbe *v;
9781797862
sqlite3* db = pParse->db;
9781897863
int regArgs;
9781997864
97865
+ if( pParse->nErr ) goto attach_end;
9782097866
memset(&sName, 0, sizeof(NameContext));
9782197867
sName.pParse = pParse;
9782297868
9782397869
if(
9782497870
SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
@@ -98397,10 +98443,12 @@
9839798443
int i;
9839898444
int nBytes;
9839998445
TableLock *p;
9840098446
assert( iDb>=0 );
9840198447
98448
+ if( iDb==1 ) return;
98449
+ if( !sqlite3BtreeSharable(pParse->db->aDb[iDb].pBt) ) return;
9840298450
for(i=0; i<pToplevel->nTableLock; i++){
9840398451
p = &pToplevel->aTableLock[i];
9840498452
if( p->iDb==iDb && p->iTab==iTab ){
9840598453
p->isWriteLock = (p->isWriteLock || isWriteLock);
9840698454
return;
@@ -101154,11 +101202,11 @@
101154101202
}else{
101155101203
addr2 = sqlite3VdbeCurrentAddr(v);
101156101204
}
101157101205
sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
101158101206
sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
101159
- sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
101207
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, regRecord);
101160101208
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
101161101209
sqlite3ReleaseTempReg(pParse, regRecord);
101162101210
sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
101163101211
sqlite3VdbeJumpHere(v, addr1);
101164101212
@@ -103702,11 +103750,11 @@
103702103750
/* Add the PK key for this row to the temporary table */
103703103751
iKey = ++pParse->nMem;
103704103752
nKey = 0; /* Zero tells OP_Found to use a composite key */
103705103753
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
103706103754
sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
103707
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
103755
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEphCur, iKey, iPk, nPk);
103708103756
}else{
103709103757
/* Add the rowid of the row to be deleted to the RowSet */
103710103758
nKey = 1; /* OP_Seek always uses a single rowid */
103711103759
sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
103712103760
}
@@ -103791,18 +103839,10 @@
103791103839
sqlite3VdbeJumpHere(v, addrLoop);
103792103840
}else{
103793103841
sqlite3VdbeGoto(v, addrLoop);
103794103842
sqlite3VdbeJumpHere(v, addrLoop);
103795103843
}
103796
-
103797
- /* Close the cursors open on the table and its indexes. */
103798
- if( !isView && !IsVirtual(pTab) ){
103799
- if( !pPk ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
103800
- for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
103801
- sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
103802
- }
103803
- }
103804103844
} /* End non-truncate path */
103805103845
103806103846
/* Update the sqlite_sequence table by storing the content of the
103807103847
** maximum rowid counter values recorded while inserting into
103808103848
** autoincrement tables.
@@ -104360,10 +104400,12 @@
104360104400
isText = 0;
104361104401
}else{
104362104402
zHaystack = sqlite3_value_text(argv[0]);
104363104403
zNeedle = sqlite3_value_text(argv[1]);
104364104404
isText = 1;
104405
+ if( zNeedle==0 ) return;
104406
+ assert( zHaystack );
104365104407
}
104366104408
while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
104367104409
N++;
104368104410
do{
104369104411
nHaystack--;
@@ -107898,11 +107940,11 @@
107898107940
int onError /* How to handle constraint errors */
107899107941
){
107900107942
sqlite3 *db; /* The main database structure */
107901107943
Table *pTab; /* The table to insert into. aka TABLE */
107902107944
char *zTab; /* Name of the table into which we are inserting */
107903
- int i, j, idx; /* Loop counters */
107945
+ int i, j; /* Loop counters */
107904107946
Vdbe *v; /* Generate code into this virtual machine */
107905107947
Index *pIdx; /* For looping over indices of the table */
107906107948
int nColumn; /* Number of columns in the data */
107907107949
int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
107908107950
int iDataCur = 0; /* VDBE cursor that is the main data repository */
@@ -108205,12 +108247,14 @@
108205108247
&iDataCur, &iIdxCur);
108206108248
aRegIdx = sqlite3DbMallocRawNN(db, sizeof(int)*(nIdx+1));
108207108249
if( aRegIdx==0 ){
108208108250
goto insert_cleanup;
108209108251
}
108210
- for(i=0; i<nIdx; i++){
108252
+ for(i=0, pIdx=pTab->pIndex; i<nIdx; pIdx=pIdx->pNext, i++){
108253
+ assert( pIdx );
108211108254
aRegIdx[i] = ++pParse->nMem;
108255
+ pParse->nMem += pIdx->nColumn;
108212108256
}
108213108257
}
108214108258
108215108259
/* This is the top of the main insertion loop */
108216108260
if( useTempTable ){
@@ -108408,16 +108452,30 @@
108408108452
sqlite3MayAbort(pParse);
108409108453
}else
108410108454
#endif
108411108455
{
108412108456
int isReplace; /* Set to true if constraints may cause a replace */
108457
+ int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
108413108458
sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
108414108459
regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0
108415108460
);
108416108461
sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
108462
+
108463
+ /* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
108464
+ ** constraints or (b) there are no triggers and this table is not a
108465
+ ** parent table in a foreign key constraint. It is safe to set the
108466
+ ** flag in the second case as if any REPLACE constraint is hit, an
108467
+ ** OP_Delete or OP_IdxDelete instruction will be executed on each
108468
+ ** cursor that is disturbed. And these instructions both clear the
108469
+ ** VdbeCursor.seekResult variable, disabling the OPFLAG_USESEEKRESULT
108470
+ ** functionality. */
108471
+ bUseSeek = (isReplace==0 || (pTrigger==0 &&
108472
+ ((db->flags & SQLITE_ForeignKeys)==0 || sqlite3FkReferences(pTab)==0)
108473
+ ));
108417108474
sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
108418
- regIns, aRegIdx, 0, appendFlag, isReplace==0);
108475
+ regIns, aRegIdx, 0, appendFlag, bUseSeek
108476
+ );
108419108477
}
108420108478
}
108421108479
108422108480
/* Update the count of rows that are inserted
108423108481
*/
@@ -108442,18 +108500,10 @@
108442108500
}else if( pSelect ){
108443108501
sqlite3VdbeGoto(v, addrCont);
108444108502
sqlite3VdbeJumpHere(v, addrInsTop);
108445108503
}
108446108504
108447
- if( !IsVirtual(pTab) && !isView ){
108448
- /* Close all tables opened */
108449
- if( iDataCur<iIdxCur ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
108450
- for(idx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
108451
- sqlite3VdbeAddOp1(v, OP_Close, idx+iIdxCur);
108452
- }
108453
- }
108454
-
108455108505
insert_end:
108456108506
/* Update the sqlite_sequence table by storing the content of the
108457108507
** maximum rowid counter values recorded while inserting into
108458108508
** autoincrement tables.
108459108509
*/
@@ -108656,11 +108706,10 @@
108656108706
int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
108657108707
int ipkTop = 0; /* Top of the rowid change constraint check */
108658108708
int ipkBottom = 0; /* Bottom of the rowid change constraint check */
108659108709
u8 isUpdate; /* True if this is an UPDATE operation */
108660108710
u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
108661
- int regRowid = -1; /* Register holding ROWID value */
108662108711
108663108712
isUpdate = regOldData!=0;
108664108713
db = pParse->db;
108665108714
v = sqlite3GetVdbe(pParse);
108666108715
assert( v!=0 );
@@ -108776,11 +108825,11 @@
108776108825
}else if( onError==OE_Default ){
108777108826
onError = OE_Abort;
108778108827
}
108779108828
108780108829
if( isUpdate ){
108781
- /* pkChng!=0 does not mean that the rowid has change, only that
108830
+ /* pkChng!=0 does not mean that the rowid has changed, only that
108782108831
** it might have changed. Skip the conflict logic below if the rowid
108783108832
** is unchanged. */
108784108833
sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
108785108834
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
108786108835
VdbeCoverage(v);
@@ -108911,11 +108960,11 @@
108911108960
}
108912108961
108913108962
/* Create a record for this index entry as it should appear after
108914108963
** the insert or update. Store that record in the aRegIdx[ix] register
108915108964
*/
108916
- regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
108965
+ regIdx = aRegIdx[ix]+1;
108917108966
for(i=0; i<pIdx->nColumn; i++){
108918108967
int iField = pIdx->aiColumn[i];
108919108968
int x;
108920108969
if( iField==XN_EXPR ){
108921108970
pParse->ckBase = regNewData+1;
@@ -108922,23 +108971,20 @@
108922108971
sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
108923108972
pParse->ckBase = 0;
108924108973
VdbeComment((v, "%s column %d", pIdx->zName, i));
108925108974
}else{
108926108975
if( iField==XN_ROWID || iField==pTab->iPKey ){
108927
- if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
108928108976
x = regNewData;
108929
- regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
108930108977
}else{
108931108978
x = iField + regNewData + 1;
108932108979
}
108933108980
sqlite3VdbeAddOp2(v, iField<0 ? OP_IntCopy : OP_SCopy, x, regIdx+i);
108934108981
VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
108935108982
}
108936108983
}
108937108984
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
108938108985
VdbeComment((v, "for %s", pIdx->zName));
108939
- sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
108940108986
108941108987
/* In an UPDATE operation, if this index is the PRIMARY KEY index
108942108988
** of a WITHOUT ROWID table and there has been no change the
108943108989
** primary key, then no collision is possible. The collision detection
108944108990
** logic below can all be skipped. */
@@ -108948,19 +108994,24 @@
108948108994
}
108949108995
108950108996
/* Find out what action to take in case there is a uniqueness conflict */
108951108997
onError = pIdx->onError;
108952108998
if( onError==OE_None ){
108953
- sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
108954108999
sqlite3VdbeResolveLabel(v, addrUniqueOk);
108955109000
continue; /* pIdx is not a UNIQUE index */
108956109001
}
108957109002
if( overrideError!=OE_Default ){
108958109003
onError = overrideError;
108959109004
}else if( onError==OE_Default ){
108960109005
onError = OE_Abort;
108961109006
}
109007
+
109008
+ if( ix==0 && pPk==pIdx && onError==OE_Replace && pPk->pNext==0 ){
109009
+ sqlite3VdbeResolveLabel(v, addrUniqueOk);
109010
+ continue;
109011
+ }
109012
+
108962109013
108963109014
/* Check to see if the new index entry will be unique */
108964109015
sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
108965109016
regIdx, pIdx->nKeyCol); VdbeCoverage(v);
108966109017
@@ -109047,11 +109098,10 @@
109047109098
seenReplace = 1;
109048109099
break;
109049109100
}
109050109101
}
109051109102
sqlite3VdbeResolveLabel(v, addrUniqueOk);
109052
- sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
109053109103
if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
109054109104
}
109055109105
if( ipkTop ){
109056109106
sqlite3VdbeGoto(v, ipkTop+1);
109057109107
sqlite3VdbeJumpHere(v, ipkBottom);
@@ -109097,11 +109147,13 @@
109097109147
bAffinityDone = 1;
109098109148
if( pIdx->pPartIdxWhere ){
109099109149
sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
109100109150
VdbeCoverage(v);
109101109151
}
109102
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
109152
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
109153
+ aRegIdx[i]+1,
109154
+ pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
109103109155
pik_flags = 0;
109104109156
if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
109105109157
if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
109106109158
assert( pParse->nested==0 );
109107109159
pik_flags |= OPFLAG_NCHANGE;
@@ -109110,12 +109162,14 @@
109110109162
}
109111109163
if( !HasRowid(pTab) ) return;
109112109164
regData = regNewData + 1;
109113109165
regRec = sqlite3GetTempReg(pParse);
109114109166
sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
109115
- if( !bAffinityDone ) sqlite3TableAffinity(v, pTab, 0);
109116
- sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
109167
+ if( !bAffinityDone ){
109168
+ sqlite3TableAffinity(v, pTab, 0);
109169
+ sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
109170
+ }
109117109171
if( pParse->nested ){
109118109172
pik_flags = 0;
109119109173
}else{
109120109174
pik_flags = OPFLAG_NCHANGE;
109121109175
pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID);
@@ -109509,10 +109563,11 @@
109509109563
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
109510109564
emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
109511109565
sqlite3VdbeJumpHere(v, addr1);
109512109566
}
109513109567
if( HasRowid(pSrc) ){
109568
+ u8 insFlags;
109514109569
sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
109515109570
emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
109516109571
if( pDest->iPKey>=0 ){
109517109572
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
109518109573
addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
@@ -109525,13 +109580,20 @@
109525109580
}else{
109526109581
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
109527109582
assert( (pDest->tabFlags & TF_Autoincrement)==0 );
109528109583
}
109529109584
sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
109585
+ if( db->flags & SQLITE_Vacuum ){
109586
+ sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
109587
+ insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
109588
+ OPFLAG_APPEND|OPFLAG_USESEEKRESULT;
109589
+ }else{
109590
+ insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND;
109591
+ }
109530109592
sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid,
109531109593
(char*)pDest, P4_TABLE);
109532
- sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
109594
+ sqlite3VdbeChangeP5(v, insFlags);
109533109595
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
109534109596
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
109535109597
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
109536109598
}else{
109537109599
sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
@@ -109579,12 +109641,12 @@
109579109641
}
109580109642
}
109581109643
if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
109582109644
idxInsFlags |= OPFLAG_NCHANGE;
109583109645
}
109584
- sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
109585
- sqlite3VdbeChangeP5(v, idxInsFlags);
109646
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
109647
+ sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
109586109648
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
109587109649
sqlite3VdbeJumpHere(v, addr1);
109588109650
sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
109589109651
sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
109590109652
}
@@ -114945,11 +115007,11 @@
114945115007
int nOBSat = pSort->nOBSat; /* ORDER BY terms to skip */
114946115008
int op; /* Opcode to add sorter record to sorter */
114947115009
int iLimit; /* LIMIT counter */
114948115010
114949115011
assert( bSeq==0 || bSeq==1 );
114950
- assert( nData==1 || regData==regOrigData );
115012
+ assert( nData==1 || regData==regOrigData || regOrigData==0 );
114951115013
if( nPrefixReg ){
114952115014
assert( nPrefixReg==nExpr+bSeq );
114953115015
regBase = regData - nExpr - bSeq;
114954115016
}else{
114955115017
regBase = pParse->nMem + 1;
@@ -114957,15 +115019,15 @@
114957115019
}
114958115020
assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
114959115021
iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
114960115022
pSort->labelDone = sqlite3VdbeMakeLabel(v);
114961115023
sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
114962
- SQLITE_ECEL_DUP|SQLITE_ECEL_REF);
115024
+ SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
114963115025
if( bSeq ){
114964115026
sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
114965115027
}
114966
- if( nPrefixReg==0 ){
115028
+ if( nPrefixReg==0 && nData>0 ){
114967115029
sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
114968115030
}
114969115031
sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord);
114970115032
if( nOBSat>0 ){
114971115033
int regPrevKey; /* The first nOBSat columns of the previous row */
@@ -115011,11 +115073,12 @@
115011115073
if( pSort->sortFlags & SORTFLAG_UseSorter ){
115012115074
op = OP_SorterInsert;
115013115075
}else{
115014115076
op = OP_IdxInsert;
115015115077
}
115016
- sqlite3VdbeAddOp2(v, op, pSort->iECursor, regRecord);
115078
+ sqlite3VdbeAddOp4Int(v, op, pSort->iECursor, regRecord,
115079
+ regBase+nOBSat, nBase-nOBSat);
115017115080
if( iLimit ){
115018115081
int addr;
115019115082
int r1 = 0;
115020115083
/* Fill the sorter until it contains LIMIT+OFFSET entries. (The iLimit
115021115084
** register is initialized with value of LIMIT+OFFSET.) After the sorter
@@ -115079,11 +115142,11 @@
115079115142
115080115143
v = pParse->pVdbe;
115081115144
r1 = sqlite3GetTempReg(pParse);
115082115145
sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
115083115146
sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
115084
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
115147
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N);
115085115148
sqlite3ReleaseTempReg(pParse, r1);
115086115149
}
115087115150
115088115151
/*
115089115152
** This routine generates the code for the inside of the inner loop
@@ -115090,11 +115153,11 @@
115090115153
** of a SELECT.
115091115154
**
115092115155
** If srcTab is negative, then the pEList expressions
115093115156
** are evaluated in order to get the data for this row. If srcTab is
115094115157
** zero or more, then data is pulled from srcTab and pEList is used only
115095
-** to get number columns and the datatype for each column.
115158
+** to get the number of columns and the collation sequence for each column.
115096115159
*/
115097115160
static void selectInnerLoop(
115098115161
Parse *pParse, /* The parser context */
115099115162
Select *p, /* The complete select statement being coded */
115100115163
ExprList *pEList, /* List of values being extracted */
@@ -115105,17 +115168,24 @@
115105115168
int iContinue, /* Jump here to continue with next row */
115106115169
int iBreak /* Jump here to break out of the inner loop */
115107115170
){
115108115171
Vdbe *v = pParse->pVdbe;
115109115172
int i;
115110
- int hasDistinct; /* True if the DISTINCT keyword is present */
115111
- int regResult; /* Start of memory holding result set */
115173
+ int hasDistinct; /* True if the DISTINCT keyword is present */
115112115174
int eDest = pDest->eDest; /* How to dispose of results */
115113115175
int iParm = pDest->iSDParm; /* First argument to disposal method */
115114115176
int nResultCol; /* Number of result columns */
115115115177
int nPrefixReg = 0; /* Number of extra registers before regResult */
115116115178
115179
+ /* Usually, regResult is the first cell in an array of memory cells
115180
+ ** containing the current result row. In this case regOrig is set to the
115181
+ ** same value. However, if the results are being sent to the sorter, the
115182
+ ** values for any expressions that are also part of the sort-key are omitted
115183
+ ** from this array. In this case regOrig is set to zero. */
115184
+ int regResult; /* Start of memory holding current results */
115185
+ int regOrig; /* Start of memory holding full result (or 0) */
115186
+
115117115187
assert( v );
115118115188
assert( pEList!=0 );
115119115189
hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
115120115190
if( pSort && pSort->pOrderBy==0 ) pSort = 0;
115121115191
if( pSort==0 && !hasDistinct ){
@@ -115142,11 +115212,11 @@
115142115212
** and reported later. But we need to make sure enough memory is allocated
115143115213
** to avoid other spurious errors in the meantime. */
115144115214
pParse->nMem += nResultCol;
115145115215
}
115146115216
pDest->nSdst = nResultCol;
115147
- regResult = pDest->iSdst;
115217
+ regOrig = regResult = pDest->iSdst;
115148115218
if( srcTab>=0 ){
115149115219
for(i=0; i<nResultCol; i++){
115150115220
sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
115151115221
VdbeComment((v, "%s", pEList->a[i].zName));
115152115222
}
@@ -115158,11 +115228,30 @@
115158115228
if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
115159115229
ecelFlags = SQLITE_ECEL_DUP;
115160115230
}else{
115161115231
ecelFlags = 0;
115162115232
}
115163
- sqlite3ExprCodeExprList(pParse, pEList, regResult, 0, ecelFlags);
115233
+ assert( eDest!=SRT_Table || pSort==0 );
115234
+ if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab ){
115235
+ /* For each expression in pEList that is a copy of an expression in
115236
+ ** the ORDER BY clause (pSort->pOrderBy), set the associated
115237
+ ** iOrderByCol value to one more than the index of the ORDER BY
115238
+ ** expression within the sort-key that pushOntoSorter() will generate.
115239
+ ** This allows the pEList field to be omitted from the sorted record,
115240
+ ** saving space and CPU cycles. */
115241
+ ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF);
115242
+ for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){
115243
+ int j;
115244
+ if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
115245
+ pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
115246
+ }
115247
+ }
115248
+ regOrig = 0;
115249
+ assert( eDest==SRT_Set || eDest==SRT_Mem
115250
+ || eDest==SRT_Coroutine || eDest==SRT_Output );
115251
+ }
115252
+ nResultCol = sqlite3ExprCodeExprList(pParse,pEList,regResult,0,ecelFlags);
115164115253
}
115165115254
115166115255
/* If the DISTINCT keyword was present on the SELECT statement
115167115256
** and this row has been seen before, then do not make this row
115168115257
** part of the result.
@@ -115232,11 +115321,11 @@
115232115321
#ifndef SQLITE_OMIT_COMPOUND_SELECT
115233115322
case SRT_Union: {
115234115323
int r1;
115235115324
r1 = sqlite3GetTempReg(pParse);
115236115325
sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
115237
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
115326
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
115238115327
sqlite3ReleaseTempReg(pParse, r1);
115239115328
break;
115240115329
}
115241115330
115242115331
/* Construct a record from the query result, but instead of
@@ -115269,11 +115358,11 @@
115269115358
** current row to the index and proceed with writing it to the
115270115359
** output table as well. */
115271115360
int addr = sqlite3VdbeCurrentAddr(v) + 4;
115272115361
sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
115273115362
VdbeCoverage(v);
115274
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
115363
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm+1, r1,regResult,nResultCol);
115275115364
assert( pSort==0 );
115276115365
}
115277115366
#endif
115278115367
if( pSort ){
115279115368
pushOntoSorter(pParse, pSort, p, r1+nPrefixReg,regResult,1,nPrefixReg);
@@ -115298,18 +115387,18 @@
115298115387
/* At first glance you would think we could optimize out the
115299115388
** ORDER BY in this case since the order of entries in the set
115300115389
** does not matter. But there might be a LIMIT clause, in which
115301115390
** case the order does matter */
115302115391
pushOntoSorter(
115303
- pParse, pSort, p, regResult, regResult, nResultCol, nPrefixReg);
115392
+ pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
115304115393
}else{
115305115394
int r1 = sqlite3GetTempReg(pParse);
115306115395
assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
115307115396
sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
115308115397
r1, pDest->zAffSdst, nResultCol);
115309115398
sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
115310
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
115399
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
115311115400
sqlite3ReleaseTempReg(pParse, r1);
115312115401
}
115313115402
break;
115314115403
}
115315115404
@@ -115324,15 +115413,16 @@
115324115413
/* If this is a scalar select that is part of an expression, then
115325115414
** store the results in the appropriate memory cell or array of
115326115415
** memory cells and break out of the scan loop.
115327115416
*/
115328115417
case SRT_Mem: {
115329
- assert( nResultCol==pDest->nSdst );
115330115418
if( pSort ){
115419
+ assert( nResultCol<=pDest->nSdst );
115331115420
pushOntoSorter(
115332
- pParse, pSort, p, regResult, regResult, nResultCol, nPrefixReg);
115421
+ pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
115333115422
}else{
115423
+ assert( nResultCol==pDest->nSdst );
115334115424
assert( regResult==iParm );
115335115425
/* The LIMIT clause will jump out of the loop for us */
115336115426
}
115337115427
break;
115338115428
}
@@ -115341,11 +115431,11 @@
115341115431
case SRT_Coroutine: /* Send data to a co-routine */
115342115432
case SRT_Output: { /* Return the results */
115343115433
testcase( eDest==SRT_Coroutine );
115344115434
testcase( eDest==SRT_Output );
115345115435
if( pSort ){
115346
- pushOntoSorter(pParse, pSort, p, regResult, regResult, nResultCol,
115436
+ pushOntoSorter(pParse, pSort, p, regResult, regOrig, nResultCol,
115347115437
nPrefixReg);
115348115438
}else if( eDest==SRT_Coroutine ){
115349115439
sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
115350115440
}else{
115351115441
sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
@@ -115391,11 +115481,11 @@
115391115481
regResult + pSO->a[i].u.x.iOrderByCol - 1,
115392115482
r2+i);
115393115483
}
115394115484
sqlite3VdbeAddOp2(v, OP_Sequence, iParm, r2+nKey);
115395115485
sqlite3VdbeAddOp3(v, OP_MakeRecord, r2, nKey+2, r1);
115396
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
115486
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, r2, nKey+2);
115397115487
if( addrTest ) sqlite3VdbeJumpHere(v, addrTest);
115398115488
sqlite3ReleaseTempReg(pParse, r1);
115399115489
sqlite3ReleaseTempRange(pParse, r2, nKey+2);
115400115490
break;
115401115491
}
@@ -115626,18 +115716,17 @@
115626115716
ExprList *pOrderBy = pSort->pOrderBy;
115627115717
int eDest = pDest->eDest;
115628115718
int iParm = pDest->iSDParm;
115629115719
int regRow;
115630115720
int regRowid;
115721
+ int iCol;
115631115722
int nKey;
115632115723
int iSortTab; /* Sorter cursor to read from */
115633115724
int nSortData; /* Trailing values to read from sorter */
115634115725
int i;
115635115726
int bSeq; /* True if sorter record includes seq. no. */
115636
-#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
115637115727
struct ExprList_item *aOutEx = p->pEList->a;
115638
-#endif
115639115728
115640115729
assert( addrBreak<0 );
115641115730
if( pSort->labelBkOut ){
115642115731
sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
115643115732
sqlite3VdbeGoto(v, addrBreak);
@@ -115671,12 +115760,18 @@
115671115760
addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
115672115761
codeOffset(v, p->iOffset, addrContinue);
115673115762
iSortTab = iTab;
115674115763
bSeq = 1;
115675115764
}
115676
- for(i=0; i<nSortData; i++){
115677
- sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
115765
+ for(i=0, iCol=nKey+bSeq; i<nSortData; i++){
115766
+ int iRead;
115767
+ if( aOutEx[i].u.x.iOrderByCol ){
115768
+ iRead = aOutEx[i].u.x.iOrderByCol-1;
115769
+ }else{
115770
+ iRead = iCol++;
115771
+ }
115772
+ sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
115678115773
VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
115679115774
}
115680115775
switch( eDest ){
115681115776
case SRT_EphemTab: {
115682115777
sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
@@ -115688,11 +115783,11 @@
115688115783
case SRT_Set: {
115689115784
assert( nColumn==sqlite3Strlen30(pDest->zAffSdst) );
115690115785
sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, nColumn, regRowid,
115691115786
pDest->zAffSdst, nColumn);
115692115787
sqlite3ExprCacheAffinityChange(pParse, regRow, nColumn);
115693
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, regRowid);
115788
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, regRowid, regRow, nColumn);
115694115789
break;
115695115790
}
115696115791
case SRT_Mem: {
115697115792
/* The LIMIT clause will terminate the loop for us */
115698115793
break;
@@ -117064,11 +117159,12 @@
117064117159
testcase( pIn->nSdst>1 );
117065117160
r1 = sqlite3GetTempReg(pParse);
117066117161
sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
117067117162
r1, pDest->zAffSdst, pIn->nSdst);
117068117163
sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, pIn->nSdst);
117069
- sqlite3VdbeAddOp2(v, OP_IdxInsert, pDest->iSDParm, r1);
117164
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
117165
+ pIn->iSdst, pIn->nSdst);
117070117166
sqlite3ReleaseTempReg(pParse, r1);
117071117167
break;
117072117168
}
117073117169
117074117170
/* If this is a scalar select that is part of an expression, then
@@ -121687,16 +121783,18 @@
121687121783
*/
121688121784
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
121689121785
int reg;
121690121786
if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
121691121787
reg = ++pParse->nMem;
121788
+ pParse->nMem += pIdx->nColumn;
121692121789
}else{
121693121790
reg = 0;
121694121791
for(i=0; i<pIdx->nKeyCol; i++){
121695121792
i16 iIdxCol = pIdx->aiColumn[i];
121696121793
if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
121697121794
reg = ++pParse->nMem;
121795
+ pParse->nMem += pIdx->nColumn;
121698121796
break;
121699121797
}
121700121798
}
121701121799
}
121702121800
if( reg==0 ) aToOpen[j+1] = 0;
@@ -121803,11 +121901,11 @@
121803121901
nKey = nPk;
121804121902
regKey = iPk;
121805121903
}else{
121806121904
sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
121807121905
sqlite3IndexAffinityStr(db, pPk), nPk);
121808
- sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
121906
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk);
121809121907
}
121810121908
sqlite3WhereEnd(pWInfo);
121811121909
}
121812121910
121813121911
/* Initialize the count of updated rows
@@ -122062,19 +122160,10 @@
122062122160
}else{
122063122161
sqlite3VdbeGoto(v, labelContinue);
122064122162
}
122065122163
sqlite3VdbeResolveLabel(v, labelBreak);
122066122164
122067
- /* Close all tables */
122068
- for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
122069
- assert( aRegIdx );
122070
- if( aToOpen[i+1] ){
122071
- sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
122072
- }
122073
- }
122074
- if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
122075
-
122076122165
/* Update the sqlite_sequence table by storing the content of the
122077122166
** maximum rowid counter values recorded while inserting into
122078122167
** autoincrement tables.
122079122168
*/
122080122169
if( pParse->nested==0 && pParse->pTriggerTab==0 ){
@@ -124822,10 +124911,11 @@
124822124911
if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
124823124912
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
124824124913
}else{
124825124914
Select *pSelect = pX->x.pSelect;
124826124915
sqlite3 *db = pParse->db;
124916
+ u16 savedDbOptFlags = db->dbOptFlags;
124827124917
ExprList *pOrigRhs = pSelect->pEList;
124828124918
ExprList *pOrigLhs = pX->pLeft->x.pList;
124829124919
ExprList *pRhs = 0; /* New Select.pEList for RHS */
124830124920
ExprList *pLhs = 0; /* New pX->pLeft vector */
124831124921
@@ -124865,11 +124955,13 @@
124865124955
pLeft->x.pList = pLhs;
124866124956
aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * nEq);
124867124957
testcase( aiMap==0 );
124868124958
}
124869124959
pSelect->pEList = pRhs;
124960
+ db->dbOptFlags |= SQLITE_QueryFlattener;
124870124961
eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
124962
+ db->dbOptFlags = savedDbOptFlags;
124871124963
testcase( aiMap!=0 && aiMap[0]!=0 );
124872124964
pSelect->pEList = pOrigRhs;
124873124965
pLeft->x.pList = pOrigLhs;
124874124966
pX->pLeft = pLeft;
124875124967
}
@@ -126220,11 +126312,12 @@
126220126312
jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
126221126313
VdbeCoverage(v);
126222126314
}
126223126315
if( iSet>=0 ){
126224126316
sqlite3VdbeAddOp3(v, OP_MakeRecord, r, nPk, regRowid);
126225
- sqlite3VdbeAddOp3(v, OP_IdxInsert, regRowset, regRowid, 0);
126317
+ sqlite3VdbeAddOp4Int(v, OP_IdxInsert, regRowset, regRowid,
126318
+ r, nPk);
126226126319
if( iSet ) sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
126227126320
}
126228126321
126229126322
/* Release the array of temp registers */
126230126323
sqlite3ReleaseTempRange(pParse, r, nPk);
@@ -127684,10 +127777,12 @@
127684127777
#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
127685127778
127686127779
/* Prevent ON clause terms of a LEFT JOIN from being used to drive
127687127780
** an index for tables to the left of the join.
127688127781
*/
127782
+ testcase( pTerm!=&pWC->a[idxTerm] );
127783
+ pTerm = &pWC->a[idxTerm];
127689127784
pTerm->prereqRight |= extraRight;
127690127785
}
127691127786
127692127787
/***************************************************************************
127693127788
** Routines with file scope above. Interface to the rest of the where.c
@@ -132767,31 +132862,10 @@
132767132862
translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
132768132863
pTabItem->regResult, 0);
132769132864
continue;
132770132865
}
132771132866
132772
- /* Close all of the cursors that were opened by sqlite3WhereBegin.
132773
- ** Except, do not close cursors that will be reused by the OR optimization
132774
- ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors
132775
- ** created for the ONEPASS optimization.
132776
- */
132777
- if( (pTab->tabFlags & TF_Ephemeral)==0
132778
- && pTab->pSelect==0
132779
- && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
132780
- ){
132781
- int ws = pLoop->wsFlags;
132782
- if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
132783
- sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
132784
- }
132785
- if( (ws & WHERE_INDEXED)!=0
132786
- && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0
132787
- && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
132788
- ){
132789
- sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
132790
- }
132791
- }
132792
-
132793132867
/* If this scan uses an index, make VDBE code substitutions to read data
132794132868
** from the index instead of from the table where possible. In some cases
132795132869
** this optimization prevents the table from ever being read, which can
132796132870
** yield a significant performance boost.
132797132871
**
@@ -165455,24 +165529,24 @@
165455165529
int nArg; /* Number of arguments */
165456165530
int enc; /* Optimal text encoding */
165457165531
void *pContext; /* sqlite3_user_data() context */
165458165532
void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
165459165533
} scalars[] = {
165460
- {"regexp", 2, SQLITE_ANY, 0, icuRegexpFunc},
165461
-
165462
- {"lower", 1, SQLITE_UTF16, 0, icuCaseFunc16},
165463
- {"lower", 2, SQLITE_UTF16, 0, icuCaseFunc16},
165464
- {"upper", 1, SQLITE_UTF16, (void*)1, icuCaseFunc16},
165465
- {"upper", 2, SQLITE_UTF16, (void*)1, icuCaseFunc16},
165466
-
165467
- {"lower", 1, SQLITE_UTF8, 0, icuCaseFunc16},
165468
- {"lower", 2, SQLITE_UTF8, 0, icuCaseFunc16},
165469
- {"upper", 1, SQLITE_UTF8, (void*)1, icuCaseFunc16},
165470
- {"upper", 2, SQLITE_UTF8, (void*)1, icuCaseFunc16},
165471
-
165472
- {"like", 2, SQLITE_UTF8, 0, icuLikeFunc},
165473
- {"like", 3, SQLITE_UTF8, 0, icuLikeFunc},
165534
+ {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
165535
+
165536
+ {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
165537
+ {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
165538
+ {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
165539
+ {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
165540
+
165541
+ {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
165542
+ {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
165543
+ {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
165544
+ {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
165545
+
165546
+ {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
165547
+ {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
165474165548
165475165549
{"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
165476165550
};
165477165551
165478165552
int rc = SQLITE_OK;
@@ -176486,17 +176560,19 @@
176486176560
** to pass signed char values.
176487176561
*/
176488176562
#ifdef sqlite3Isdigit
176489176563
/* Use the SQLite core versions if this routine is part of the
176490176564
** SQLite amalgamation */
176491
-# define safe_isdigit(x) sqlite3Isdigit(x)
176492
-# define safe_isalnum(x) sqlite3Isalnum(x)
176565
+# define safe_isdigit(x) sqlite3Isdigit(x)
176566
+# define safe_isalnum(x) sqlite3Isalnum(x)
176567
+# define safe_isxdigit(x) sqlite3Isxdigit(x)
176493176568
#else
176494176569
/* Use the standard library for separate compilation */
176495176570
#include <ctype.h> /* amalgamator: keep */
176496
-# define safe_isdigit(x) isdigit((unsigned char)(x))
176497
-# define safe_isalnum(x) isalnum((unsigned char)(x))
176571
+# define safe_isdigit(x) isdigit((unsigned char)(x))
176572
+# define safe_isalnum(x) isalnum((unsigned char)(x))
176573
+# define safe_isxdigit(x) isxdigit((unsigned char)(x))
176498176574
#endif
176499176575
176500176576
/*
176501176577
** Growing our own isspace() routine this way is twice as fast as
176502176578
** the library isspace() function, resulting in a 7% overall performance
@@ -177030,16 +177106,17 @@
177030177106
zOut[j++] = c;
177031177107
}else{
177032177108
c = z[++i];
177033177109
if( c=='u' ){
177034177110
u32 v = 0, k;
177035
- for(k=0; k<4 && i<n-2; i++, k++){
177111
+ for(k=0; k<4; i++, k++){
177112
+ assert( i<n-2 );
177036177113
c = z[i+1];
177037
- if( c>='0' && c<='9' ) v = v*16 + c - '0';
177038
- else if( c>='A' && c<='F' ) v = v*16 + c - 'A' + 10;
177039
- else if( c>='a' && c<='f' ) v = v*16 + c - 'a' + 10;
177040
- else break;
177114
+ assert( safe_isxdigit(c) );
177115
+ if( c<='9' ) v = v*16 + c - '0';
177116
+ else if( c<='F' ) v = v*16 + c - 'A' + 10;
177117
+ else v = v*16 + c - 'a' + 10;
177041177118
}
177042177119
if( v==0 ) break;
177043177120
if( v<=0x7f ){
177044177121
zOut[j++] = (char)v;
177045177122
}else if( v<=0x7ff ){
@@ -177138,10 +177215,19 @@
177138177215
p->iVal = 0;
177139177216
p->n = n;
177140177217
p->u.zJContent = zContent;
177141177218
return pParse->nNode++;
177142177219
}
177220
+
177221
+/*
177222
+** Return true if z[] begins with 4 (or more) hexadecimal digits
177223
+*/
177224
+static int jsonIs4Hex(const char *z){
177225
+ int i;
177226
+ for(i=0; i<4; i++) if( !safe_isxdigit(z[i]) ) return 0;
177227
+ return 1;
177228
+}
177143177229
177144177230
/*
177145177231
** Parse a single JSON value which begins at pParse->zJson[i]. Return the
177146177232
** index of the first character past the end of the value parsed.
177147177233
**
@@ -177213,12 +177299,17 @@
177213177299
for(;;){
177214177300
c = pParse->zJson[j];
177215177301
if( c==0 ) return -1;
177216177302
if( c=='\\' ){
177217177303
c = pParse->zJson[++j];
177218
- if( c==0 ) return -1;
177219
- jnFlags = JNODE_ESCAPE;
177304
+ if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
177305
+ || c=='n' || c=='r' || c=='t'
177306
+ || (c=='u' && jsonIs4Hex(pParse->zJson+j+1)) ){
177307
+ jnFlags = JNODE_ESCAPE;
177308
+ }else{
177309
+ return -1;
177310
+ }
177220177311
}else if( c=='"' ){
177221177312
break;
177222177313
}
177223177314
j++;
177224177315
}
@@ -178082,11 +178173,11 @@
178082178173
JsonString *pStr;
178083178174
pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
178084178175
if( pStr ){
178085178176
jsonAppendChar(pStr, '}');
178086178177
if( pStr->bErr ){
178087
- if( pStr->bErr==0 ) sqlite3_result_error_nomem(ctx);
178178
+ if( pStr->bErr==1 ) sqlite3_result_error_nomem(ctx);
178088178179
assert( pStr->bStatic );
178089178180
}else{
178090178181
sqlite3_result_text(ctx, pStr->zBuf, pStr->nUsed,
178091178182
pStr->bStatic ? SQLITE_TRANSIENT : sqlite3_free);
178092178183
pStr->bStatic = 1;
@@ -178360,13 +178451,13 @@
178360178451
break;
178361178452
}
178362178453
/* For json_each() path and root are the same so fall through
178363178454
** into the root case */
178364178455
}
178365
- case JEACH_ROOT: {
178456
+ default: {
178366178457
const char *zRoot = p->zRoot;
178367
- if( zRoot==0 ) zRoot = "$";
178458
+ if( zRoot==0 ) zRoot = "$";
178368178459
sqlite3_result_text(ctx, zRoot, -1, SQLITE_STATIC);
178369178460
break;
178370178461
}
178371178462
case JEACH_JSON: {
178372178463
assert( i==JEACH_JSON );
@@ -184289,11 +184380,11 @@
184289184380
pNode->bEof = 1;
184290184381
return rc;
184291184382
}
184292184383
}else{
184293184384
Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
184294
- if( pIter->iRowid==iLast ) continue;
184385
+ if( pIter->iRowid==iLast || pIter->bEof ) continue;
184295184386
bMatch = 0;
184296184387
if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
184297184388
return rc;
184298184389
}
184299184390
}
@@ -189429,10 +189520,11 @@
189429189520
Fts5Iter *pIter,
189430189521
int bFrom, /* True if argument iFrom is valid */
189431189522
i64 iFrom /* Advance at least as far as this */
189432189523
){
189433189524
int bUseFrom = bFrom;
189525
+ assert( pIter->base.bEof==0 );
189434189526
while( p->rc==SQLITE_OK ){
189435189527
int iFirst = pIter->aFirst[1].iFirst;
189436189528
int bNewTerm = 0;
189437189529
Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
189438189530
assert( p->rc==SQLITE_OK );
@@ -195693,11 +195785,11 @@
195693195785
int nArg, /* Number of args */
195694195786
sqlite3_value **apUnused /* Function arguments */
195695195787
){
195696195788
assert( nArg==0 );
195697195789
UNUSED_PARAM2(nArg, apUnused);
195698
- sqlite3_result_text(pCtx, "fts5: 2016-10-26 16:05:10 ec9dab8054c71d112c68f58a45821b38c2a45677", -1, SQLITE_TRANSIENT);
195790
+ sqlite3_result_text(pCtx, "fts5: 2016-11-19 18:31:37 28393c413cc4505b94411730e728583c5d4baaae", -1, SQLITE_TRANSIENT);
195699195791
}
195700195792
195701195793
static int fts5Init(sqlite3 *db){
195702195794
static const sqlite3_module fts5Mod = {
195703195795
/* iVersion */ 2,
195704195796
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,15 +381,15 @@
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.0"
385 #define SQLITE_VERSION_NUMBER 3016000
386 #define SQLITE_SOURCE_ID "2016-11-02 14:50:19 3028845329c9b7acdec2ec8b01d00d782347454c"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
391 **
392 ** These interfaces provide the same information as the [SQLITE_VERSION],
393 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
394 ** but are associated with the library instead of the header file. ^(Cautious
395 ** programmers might include assert() statements in their application to
@@ -8483,11 +8483,12 @@
8483 ** triggers; or 2 for changes resulting from triggers called by top-level
8484 ** triggers; and so forth.
8485 **
8486 ** See also: [sqlite3_update_hook()]
8487 */
8488 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_preupdate_hook(
 
8489 sqlite3 *db,
8490 void(*xPreUpdate)(
8491 void *pCtx, /* Copy of third arg to preupdate_hook() */
8492 sqlite3 *db, /* Database handle */
8493 int op, /* SQLITE_UPDATE, DELETE or INSERT */
@@ -8496,14 +8497,15 @@
8496 sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
8497 sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
8498 ),
8499 void*
8500 );
8501 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8502 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_count(sqlite3 *);
8503 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_depth(sqlite3 *);
8504 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 
8505
8506 /*
8507 ** CAPI3REF: Low-level system error code
8508 **
8509 ** ^Attempt to return the underlying operating system error code or error
@@ -12307,10 +12309,12 @@
12307 */
12308 struct BtreePayload {
12309 const void *pKey; /* Key content for indexes. NULL for tables */
12310 sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
12311 const void *pData; /* Data for tables. NULL for indexes */
 
 
12312 int nData; /* Size of pData. 0 if none. */
12313 int nZero; /* Extra zero data appended after pData,nData */
12314 };
12315
12316 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
@@ -12340,10 +12344,11 @@
12340 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
12341
12342 #ifndef NDEBUG
12343 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
12344 #endif
 
12345
12346 #ifndef SQLITE_OMIT_BTREECOUNT
12347 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *);
12348 #endif
12349
@@ -15596,19 +15601,19 @@
15596 int iReg; /* Reg with value of this column. 0 means none. */
15597 int lru; /* Least recently used entry has the smallest value */
15598 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
15599 int aTempReg[8]; /* Holding area for temporary registers */
15600 Token sNameToken; /* Token with unqualified schema object name */
15601 Token sLastToken; /* The last token parsed */
15602
15603 /************************************************************************
15604 ** Above is constant between recursions. Below is reset before and after
15605 ** each recursion. The boundary between these two regions is determined
15606 ** using offsetof(Parse,nVar) so the nVar field must be the first field
15607 ** in the recursive region.
15608 ************************************************************************/
15609
 
15610 ynVar nVar; /* Number of '?' variables seen in the SQL so far */
15611 int nzVar; /* Number of available slots in azVar[] */
15612 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
15613 u8 explain; /* True if the EXPLAIN flag is found on the query */
15614 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -15638,11 +15643,11 @@
15638
15639 /*
15640 ** Sizes and pointers of various parts of the Parse object.
15641 */
15642 #define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
15643 #define PARSE_RECURSE_SZ offsetof(Parse,nVar) /* Recursive part */
15644 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
15645 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
15646
15647 /*
15648 ** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -16355,10 +16360,11 @@
16355 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
16356 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
16357 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
16358 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
16359 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
 
16360 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
16361 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
16362 SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
16363 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
16364 #define LOCATE_VIEW 0x01
@@ -17802,11 +17808,14 @@
17802 int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
17803 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
17804 } uc;
17805 Btree *pBt; /* Separate file holding temporary table */
17806 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
17807 int seekResult; /* Result of previous sqlite3BtreeMoveto() */
 
 
 
17808 i64 seqCount; /* Sequence counter */
17809 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
17810 VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
17811 int *aAltMap; /* Mapping from table to index column numbers */
17812 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
@@ -25889,10 +25898,11 @@
25889 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
25890 }
25891 va_start(ap, zFormat);
25892 sqlite3VXPrintf(&acc, zFormat, ap);
25893 va_end(ap);
 
25894 if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
25895 sqlite3StrAccumFinish(&acc);
25896 fprintf(stdout,"%s", zBuf);
25897 fflush(stdout);
25898 }
@@ -50417,11 +50427,14 @@
50417 sqlite3BeginBenignMalloc();
50418 pagerFreeMapHdrs(pPager);
50419 /* pPager->errCode = 0; */
50420 pPager->exclusiveMode = 0;
50421 #ifndef SQLITE_OMIT_WAL
50422 sqlite3WalClose(pPager->pWal,db,pPager->ckptSyncFlags,pPager->pageSize,pTmp);
 
 
 
50423 pPager->pWal = 0;
50424 #endif
50425 pager_reset(pPager);
50426 if( MEMDB ){
50427 pager_unlock(pPager);
@@ -55752,11 +55765,11 @@
55752 ** the database. In this case checkpoint the database and unlink both
55753 ** the wal and wal-index files.
55754 **
55755 ** The EXCLUSIVE lock is not released before returning.
55756 */
55757 if( (db->flags & SQLITE_NoCkptOnClose)==0
55758 && SQLITE_OK==(rc = sqlite3OsLock(pWal->pDbFd, SQLITE_LOCK_EXCLUSIVE))
55759 ){
55760 if( pWal->exclusiveMode==WAL_NORMAL_MODE ){
55761 pWal->exclusiveMode = WAL_EXCLUSIVE_MODE;
55762 }
@@ -62555,10 +62568,14 @@
62555 */
62556 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor *pCur){
62557 return pCur && pCur->eState==CURSOR_VALID;
62558 }
62559 #endif /* NDEBUG */
 
 
 
 
62560
62561 /*
62562 ** Return the value of the integer key or "rowid" for a table btree.
62563 ** This routine is only valid for a cursor that is pointing into a
62564 ** ordinary table btree. If the cursor points to an index btree or
@@ -63442,20 +63459,20 @@
63442 }else if( nCellKey>intKey ){
63443 upr = idx-1;
63444 if( lwr>upr ){ c = +1; break; }
63445 }else{
63446 assert( nCellKey==intKey );
63447 pCur->curFlags |= BTCF_ValidNKey;
63448 pCur->info.nKey = nCellKey;
63449 pCur->aiIdx[pCur->iPage] = (u16)idx;
63450 if( !pPage->leaf ){
63451 lwr = idx;
63452 goto moveto_next_layer;
63453 }else{
 
 
 
63454 *pRes = 0;
63455 rc = SQLITE_OK;
63456 goto moveto_finish;
63457 }
63458 }
63459 assert( lwr+upr>=0 );
63460 idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */
63461 }
@@ -63562,11 +63579,11 @@
63562 rc = moveToChild(pCur, chldPg);
63563 if( rc ) break;
63564 }
63565 moveto_finish:
63566 pCur->info.nSize = 0;
63567 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63568 return rc;
63569 }
63570
63571
63572 /*
@@ -63760,11 +63777,11 @@
63760 return SQLITE_OK;
63761 }
63762 moveToParent(pCur);
63763 }
63764 assert( pCur->info.nSize==0 );
63765 assert( (pCur->curFlags & (BTCF_ValidNKey|BTCF_ValidOvfl))==0 );
63766
63767 pCur->aiIdx[pCur->iPage]--;
63768 pPage = pCur->apPage[pCur->iPage];
63769 if( pPage->intKey && !pPage->leaf ){
63770 rc = sqlite3BtreePrevious(pCur, pRes);
@@ -66217,21 +66234,23 @@
66217 ** For an index btree (used for indexes and WITHOUT ROWID tables), the
66218 ** key is an arbitrary byte sequence stored in pX.pKey,nKey. The
66219 ** pX.pData,nData,nZero fields must be zero.
66220 **
66221 ** If the seekResult parameter is non-zero, then a successful call to
66222 ** MovetoUnpacked() to seek cursor pCur to (pKey, nKey) has already
66223 ** been performed. seekResult is the search result returned (a negative
66224 ** number if pCur points at an entry that is smaller than (pKey, nKey), or
66225 ** a positive value if pCur points at an entry that is larger than
66226 ** (pKey, nKey)).
 
66227 **
66228 ** If the seekResult parameter is non-zero, then the caller guarantees that
66229 ** cursor pCur is pointing at the existing copy of a row that is to be
66230 ** overwritten. If the seekResult parameter is 0, then cursor pCur may
66231 ** point to any entry or to no entry at all and so this function has to seek
66232 ** the cursor before the new key can be inserted.
 
66233 */
66234 SQLITE_PRIVATE int sqlite3BtreeInsert(
66235 BtCursor *pCur, /* Insert data into the table of this cursor */
66236 const BtreePayload *pX, /* Content of the row to be inserted */
66237 int appendBias, /* True if this is likely an append */
@@ -66288,19 +66307,30 @@
66288 invalidateIncrblobCursors(p, pX->nKey, 0);
66289
66290 /* If the cursor is currently on the last row and we are appending a
66291 ** new row onto the end, set the "loc" to avoid an unnecessary
66292 ** btreeMoveto() call */
66293 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
66294 && pCur->info.nKey==pX->nKey-1 ){
66295 loc = -1;
 
 
66296 }else if( loc==0 ){
66297 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc);
66298 if( rc ) return rc;
66299 }
66300 }else if( loc==0 ){
66301 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
 
 
 
 
 
 
 
 
 
66302 if( rc ) return rc;
66303 }
66304 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
66305
66306 pPage = pCur->apPage[pCur->iPage];
@@ -66838,31 +66868,11 @@
66838 MemPage *pPage = 0;
66839 BtShared *pBt = p->pBt;
66840
66841 assert( sqlite3BtreeHoldsMutex(p) );
66842 assert( p->inTrans==TRANS_WRITE );
66843
66844 /* It is illegal to drop a table if any cursors are open on the
66845 ** database. This is because in auto-vacuum mode the backend may
66846 ** need to move another root-page to fill a gap left by the deleted
66847 ** root page. If an open cursor was using this page a problem would
66848 ** occur.
66849 **
66850 ** This error is caught long before control reaches this point.
66851 */
66852 if( NEVER(pBt->pCursor) ){
66853 sqlite3ConnectionBlocked(p->db, pBt->pCursor->pBtree->db);
66854 return SQLITE_LOCKED_SHAREDCACHE;
66855 }
66856
66857 /*
66858 ** It is illegal to drop the sqlite_master table on page 1. But again,
66859 ** this error is caught long before reaching this point.
66860 */
66861 if( NEVER(iTable<2) ){
66862 return SQLITE_CORRUPT_BKPT;
66863 }
66864
66865 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
66866 if( rc ) return rc;
66867 rc = sqlite3BtreeClearTable(p, iTable, 0);
66868 if( rc ){
@@ -81675,19 +81685,14 @@
81675 ** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
81676 ** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set,
81677 ** then rowid is stored for subsequent return by the
81678 ** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
81679 **
81680 ** If the OPFLAG_USESEEKRESULT flag of P5 is set and if the result of
81681 ** the last seek operation (OP_NotExists or OP_SeekRowid) was a success,
81682 ** then this
81683 ** operation will not attempt to find the appropriate row before doing
81684 ** the insert but will instead overwrite the row that the cursor is
81685 ** currently pointing to. Presumably, the prior OP_NotExists or
81686 ** OP_SeekRowid opcode
81687 ** has already positioned the cursor correctly. This is an optimization
81688 ** that boosts performance by avoiding redundant seeks.
81689 **
81690 ** If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
81691 ** UPDATE operation. Otherwise (if the flag is clear) then this opcode
81692 ** is part of an INSERT operation. The difference is only important to
81693 ** the update hook.
@@ -81907,10 +81912,11 @@
81907 }
81908 #endif
81909
81910 rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5);
81911 pC->cacheStatus = CACHE_STALE;
 
81912 if( rc ) goto abort_due_to_error;
81913
81914 /* Invoke the update-hook if required. */
81915 if( opflags & OPFLAG_NCHANGE ){
81916 p->nChange++;
@@ -82156,10 +82162,17 @@
82156 ** to the following instruction.
82157 **
82158 ** This opcode leaves the cursor configured to move in reverse order,
82159 ** from the end toward the beginning. In other words, the cursor is
82160 ** configured to use Prev, not Next.
 
 
 
 
 
 
 
82161 */
82162 case OP_Last: { /* jump */
82163 VdbeCursor *pC;
82164 BtCursor *pCrsr;
82165 int res;
@@ -82169,22 +82182,26 @@
82169 assert( pC!=0 );
82170 assert( pC->eCurType==CURTYPE_BTREE );
82171 pCrsr = pC->uc.pCursor;
82172 res = 0;
82173 assert( pCrsr!=0 );
82174 rc = sqlite3BtreeLast(pCrsr, &res);
82175 pC->nullRow = (u8)res;
82176 pC->deferredMoveto = 0;
82177 pC->cacheStatus = CACHE_STALE;
82178 pC->seekResult = pOp->p3;
82179 #ifdef SQLITE_DEBUG
82180 pC->seekOp = OP_Last;
82181 #endif
82182 if( rc ) goto abort_due_to_error;
82183 if( pOp->p2>0 ){
82184 VdbeBranchTaken(res!=0,2);
82185 if( res ) goto jump_to_p2;
 
 
 
 
 
 
 
 
82186 }
82187 break;
82188 }
82189
82190
@@ -82369,27 +82386,34 @@
82369 pC->nullRow = 1;
82370 }
82371 goto check_for_interrupt;
82372 }
82373
82374 /* Opcode: IdxInsert P1 P2 P3 * P5
82375 ** Synopsis: key=r[P2]
82376 **
82377 ** Register P2 holds an SQL index key made using the
82378 ** MakeRecord instructions. This opcode writes that key
82379 ** into the index P1. Data for the entry is nil.
82380 **
82381 ** P3 is a flag that provides a hint to the b-tree layer that this
82382 ** insert is likely to be an append.
 
 
 
 
 
82383 **
82384 ** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
82385 ** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
82386 ** then the change counter is unchanged.
82387 **
82388 ** If P5 has the OPFLAG_USESEEKRESULT bit set, then the cursor must have
82389 ** just done a seek to the spot where the new entry is to be inserted.
82390 ** This flag avoids doing an extra seek.
 
 
82391 **
82392 ** This instruction only works for indices. The equivalent instruction
82393 ** for tables is OP_Insert.
82394 */
82395 /* Opcode: SorterInsert P1 P2 * * *
@@ -82418,11 +82442,14 @@
82418 if( pOp->opcode==OP_SorterInsert ){
82419 rc = sqlite3VdbeSorterWrite(pC, pIn2);
82420 }else{
82421 x.nKey = pIn2->n;
82422 x.pKey = pIn2->z;
82423 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x, pOp->p3,
 
 
 
82424 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
82425 );
82426 assert( pC->deferredMoveto==0 );
82427 pC->cacheStatus = CACHE_STALE;
82428 }
@@ -82462,10 +82489,11 @@
82462 rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE);
82463 if( rc ) goto abort_due_to_error;
82464 }
82465 assert( pC->deferredMoveto==0 );
82466 pC->cacheStatus = CACHE_STALE;
 
82467 break;
82468 }
82469
82470 /* Opcode: Seek P1 * P3 P4 *
82471 ** Synopsis: Move P3 to P1.rowid
@@ -84648,12 +84676,11 @@
84648 {OP_Variable, 1, 1, 0}, /* 2: Move ?1 into reg[1] */
84649 {OP_NotExists, 0, 7, 1}, /* 3: Seek the cursor */
84650 {OP_Column, 0, 0, 1}, /* 4 */
84651 {OP_ResultRow, 1, 0, 0}, /* 5 */
84652 {OP_Goto, 0, 2, 0}, /* 6 */
84653 {OP_Close, 0, 0, 0}, /* 7 */
84654 {OP_Halt, 0, 0, 0}, /* 8 */
84655 };
84656 Vdbe *v = (Vdbe *)pBlob->pStmt;
84657 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
84658 VdbeOp *aOp;
84659
@@ -88636,10 +88663,14 @@
88636 assert( pExpr->x.pSelect==0 );
88637 pOrig = pEList->a[j].pExpr;
88638 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
88639 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
88640 return WRC_Abort;
 
 
 
 
88641 }
88642 resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
88643 cnt = 1;
88644 pMatch = 0;
88645 assert( zTab==0 && zDb==0 );
@@ -89013,10 +89044,11 @@
89013 }
89014 case TK_VARIABLE: {
89015 notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
89016 break;
89017 }
 
89018 case TK_EQ:
89019 case TK_NE:
89020 case TK_LT:
89021 case TK_LE:
89022 case TK_GT:
@@ -89023,23 +89055,31 @@
89023 case TK_GE:
89024 case TK_IS:
89025 case TK_ISNOT: {
89026 int nLeft, nRight;
89027 if( pParse->db->mallocFailed ) break;
89028 assert( pExpr->pRight!=0 );
89029 assert( pExpr->pLeft!=0 );
89030 nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
89031 nRight = sqlite3ExprVectorSize(pExpr->pRight);
 
 
 
 
 
 
 
 
89032 if( nLeft!=nRight ){
89033 testcase( pExpr->op==TK_EQ );
89034 testcase( pExpr->op==TK_NE );
89035 testcase( pExpr->op==TK_LT );
89036 testcase( pExpr->op==TK_LE );
89037 testcase( pExpr->op==TK_GT );
89038 testcase( pExpr->op==TK_GE );
89039 testcase( pExpr->op==TK_IS );
89040 testcase( pExpr->op==TK_ISNOT );
 
89041 sqlite3ErrorMsg(pParse, "row value misused");
89042 }
89043 break;
89044 }
89045 }
@@ -92306,11 +92346,11 @@
92306 VdbeCoverage(v);
92307 sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
92308 }else{
92309 sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
92310 sqlite3ExprCacheAffinityChange(pParse, r3, 1);
92311 sqlite3VdbeAddOp2(v, OP_IdxInsert, pExpr->iTable, r2);
92312 }
92313 }
92314 }
92315 sqlite3ReleaseTempReg(pParse, r1);
92316 sqlite3ReleaseTempReg(pParse, r2);
@@ -93854,12 +93894,17 @@
93854 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
93855 n = pList->nExpr;
93856 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
93857 for(pItem=pList->a, i=0; i<n; i++, pItem++){
93858 Expr *pExpr = pItem->pExpr;
93859 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pList->a[i].u.x.iOrderByCol)>0 ){
93860 sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
 
 
 
 
 
93861 }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
93862 sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
93863 }else{
93864 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
93865 if( inReg!=target+i ){
@@ -97815,10 +97860,11 @@
97815 NameContext sName;
97816 Vdbe *v;
97817 sqlite3* db = pParse->db;
97818 int regArgs;
97819
 
97820 memset(&sName, 0, sizeof(NameContext));
97821 sName.pParse = pParse;
97822
97823 if(
97824 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
@@ -98397,10 +98443,12 @@
98397 int i;
98398 int nBytes;
98399 TableLock *p;
98400 assert( iDb>=0 );
98401
 
 
98402 for(i=0; i<pToplevel->nTableLock; i++){
98403 p = &pToplevel->aTableLock[i];
98404 if( p->iDb==iDb && p->iTab==iTab ){
98405 p->isWriteLock = (p->isWriteLock || isWriteLock);
98406 return;
@@ -101154,11 +101202,11 @@
101154 }else{
101155 addr2 = sqlite3VdbeCurrentAddr(v);
101156 }
101157 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
101158 sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
101159 sqlite3VdbeAddOp3(v, OP_IdxInsert, iIdx, regRecord, 0);
101160 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
101161 sqlite3ReleaseTempReg(pParse, regRecord);
101162 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
101163 sqlite3VdbeJumpHere(v, addr1);
101164
@@ -103702,11 +103750,11 @@
103702 /* Add the PK key for this row to the temporary table */
103703 iKey = ++pParse->nMem;
103704 nKey = 0; /* Zero tells OP_Found to use a composite key */
103705 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
103706 sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
103707 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEphCur, iKey);
103708 }else{
103709 /* Add the rowid of the row to be deleted to the RowSet */
103710 nKey = 1; /* OP_Seek always uses a single rowid */
103711 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
103712 }
@@ -103791,18 +103839,10 @@
103791 sqlite3VdbeJumpHere(v, addrLoop);
103792 }else{
103793 sqlite3VdbeGoto(v, addrLoop);
103794 sqlite3VdbeJumpHere(v, addrLoop);
103795 }
103796
103797 /* Close the cursors open on the table and its indexes. */
103798 if( !isView && !IsVirtual(pTab) ){
103799 if( !pPk ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
103800 for(i=0, pIdx=pTab->pIndex; pIdx; i++, pIdx=pIdx->pNext){
103801 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur + i);
103802 }
103803 }
103804 } /* End non-truncate path */
103805
103806 /* Update the sqlite_sequence table by storing the content of the
103807 ** maximum rowid counter values recorded while inserting into
103808 ** autoincrement tables.
@@ -104360,10 +104400,12 @@
104360 isText = 0;
104361 }else{
104362 zHaystack = sqlite3_value_text(argv[0]);
104363 zNeedle = sqlite3_value_text(argv[1]);
104364 isText = 1;
 
 
104365 }
104366 while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
104367 N++;
104368 do{
104369 nHaystack--;
@@ -107898,11 +107940,11 @@
107898 int onError /* How to handle constraint errors */
107899 ){
107900 sqlite3 *db; /* The main database structure */
107901 Table *pTab; /* The table to insert into. aka TABLE */
107902 char *zTab; /* Name of the table into which we are inserting */
107903 int i, j, idx; /* Loop counters */
107904 Vdbe *v; /* Generate code into this virtual machine */
107905 Index *pIdx; /* For looping over indices of the table */
107906 int nColumn; /* Number of columns in the data */
107907 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
107908 int iDataCur = 0; /* VDBE cursor that is the main data repository */
@@ -108205,12 +108247,14 @@
108205 &iDataCur, &iIdxCur);
108206 aRegIdx = sqlite3DbMallocRawNN(db, sizeof(int)*(nIdx+1));
108207 if( aRegIdx==0 ){
108208 goto insert_cleanup;
108209 }
108210 for(i=0; i<nIdx; i++){
 
108211 aRegIdx[i] = ++pParse->nMem;
 
108212 }
108213 }
108214
108215 /* This is the top of the main insertion loop */
108216 if( useTempTable ){
@@ -108408,16 +108452,30 @@
108408 sqlite3MayAbort(pParse);
108409 }else
108410 #endif
108411 {
108412 int isReplace; /* Set to true if constraints may cause a replace */
 
108413 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
108414 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0
108415 );
108416 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
 
 
 
 
 
 
 
 
 
 
 
 
108417 sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
108418 regIns, aRegIdx, 0, appendFlag, isReplace==0);
 
108419 }
108420 }
108421
108422 /* Update the count of rows that are inserted
108423 */
@@ -108442,18 +108500,10 @@
108442 }else if( pSelect ){
108443 sqlite3VdbeGoto(v, addrCont);
108444 sqlite3VdbeJumpHere(v, addrInsTop);
108445 }
108446
108447 if( !IsVirtual(pTab) && !isView ){
108448 /* Close all tables opened */
108449 if( iDataCur<iIdxCur ) sqlite3VdbeAddOp1(v, OP_Close, iDataCur);
108450 for(idx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, idx++){
108451 sqlite3VdbeAddOp1(v, OP_Close, idx+iIdxCur);
108452 }
108453 }
108454
108455 insert_end:
108456 /* Update the sqlite_sequence table by storing the content of the
108457 ** maximum rowid counter values recorded while inserting into
108458 ** autoincrement tables.
108459 */
@@ -108656,11 +108706,10 @@
108656 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
108657 int ipkTop = 0; /* Top of the rowid change constraint check */
108658 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
108659 u8 isUpdate; /* True if this is an UPDATE operation */
108660 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
108661 int regRowid = -1; /* Register holding ROWID value */
108662
108663 isUpdate = regOldData!=0;
108664 db = pParse->db;
108665 v = sqlite3GetVdbe(pParse);
108666 assert( v!=0 );
@@ -108776,11 +108825,11 @@
108776 }else if( onError==OE_Default ){
108777 onError = OE_Abort;
108778 }
108779
108780 if( isUpdate ){
108781 /* pkChng!=0 does not mean that the rowid has change, only that
108782 ** it might have changed. Skip the conflict logic below if the rowid
108783 ** is unchanged. */
108784 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
108785 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
108786 VdbeCoverage(v);
@@ -108911,11 +108960,11 @@
108911 }
108912
108913 /* Create a record for this index entry as it should appear after
108914 ** the insert or update. Store that record in the aRegIdx[ix] register
108915 */
108916 regIdx = sqlite3GetTempRange(pParse, pIdx->nColumn);
108917 for(i=0; i<pIdx->nColumn; i++){
108918 int iField = pIdx->aiColumn[i];
108919 int x;
108920 if( iField==XN_EXPR ){
108921 pParse->ckBase = regNewData+1;
@@ -108922,23 +108971,20 @@
108922 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
108923 pParse->ckBase = 0;
108924 VdbeComment((v, "%s column %d", pIdx->zName, i));
108925 }else{
108926 if( iField==XN_ROWID || iField==pTab->iPKey ){
108927 if( regRowid==regIdx+i ) continue; /* ROWID already in regIdx+i */
108928 x = regNewData;
108929 regRowid = pIdx->pPartIdxWhere ? -1 : regIdx+i;
108930 }else{
108931 x = iField + regNewData + 1;
108932 }
108933 sqlite3VdbeAddOp2(v, iField<0 ? OP_IntCopy : OP_SCopy, x, regIdx+i);
108934 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
108935 }
108936 }
108937 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
108938 VdbeComment((v, "for %s", pIdx->zName));
108939 sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn);
108940
108941 /* In an UPDATE operation, if this index is the PRIMARY KEY index
108942 ** of a WITHOUT ROWID table and there has been no change the
108943 ** primary key, then no collision is possible. The collision detection
108944 ** logic below can all be skipped. */
@@ -108948,19 +108994,24 @@
108948 }
108949
108950 /* Find out what action to take in case there is a uniqueness conflict */
108951 onError = pIdx->onError;
108952 if( onError==OE_None ){
108953 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
108954 sqlite3VdbeResolveLabel(v, addrUniqueOk);
108955 continue; /* pIdx is not a UNIQUE index */
108956 }
108957 if( overrideError!=OE_Default ){
108958 onError = overrideError;
108959 }else if( onError==OE_Default ){
108960 onError = OE_Abort;
108961 }
 
 
 
 
 
 
108962
108963 /* Check to see if the new index entry will be unique */
108964 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
108965 regIdx, pIdx->nKeyCol); VdbeCoverage(v);
108966
@@ -109047,11 +109098,10 @@
109047 seenReplace = 1;
109048 break;
109049 }
109050 }
109051 sqlite3VdbeResolveLabel(v, addrUniqueOk);
109052 sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn);
109053 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
109054 }
109055 if( ipkTop ){
109056 sqlite3VdbeGoto(v, ipkTop+1);
109057 sqlite3VdbeJumpHere(v, ipkBottom);
@@ -109097,11 +109147,13 @@
109097 bAffinityDone = 1;
109098 if( pIdx->pPartIdxWhere ){
109099 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
109100 VdbeCoverage(v);
109101 }
109102 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i]);
 
 
109103 pik_flags = 0;
109104 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
109105 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
109106 assert( pParse->nested==0 );
109107 pik_flags |= OPFLAG_NCHANGE;
@@ -109110,12 +109162,14 @@
109110 }
109111 if( !HasRowid(pTab) ) return;
109112 regData = regNewData + 1;
109113 regRec = sqlite3GetTempReg(pParse);
109114 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
109115 if( !bAffinityDone ) sqlite3TableAffinity(v, pTab, 0);
109116 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
 
 
109117 if( pParse->nested ){
109118 pik_flags = 0;
109119 }else{
109120 pik_flags = OPFLAG_NCHANGE;
109121 pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID);
@@ -109509,10 +109563,11 @@
109509 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
109510 emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
109511 sqlite3VdbeJumpHere(v, addr1);
109512 }
109513 if( HasRowid(pSrc) ){
 
109514 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
109515 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
109516 if( pDest->iPKey>=0 ){
109517 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
109518 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
@@ -109525,13 +109580,20 @@
109525 }else{
109526 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
109527 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
109528 }
109529 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
 
 
 
 
 
 
 
109530 sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid,
109531 (char*)pDest, P4_TABLE);
109532 sqlite3VdbeChangeP5(v, OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND);
109533 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
109534 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
109535 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
109536 }else{
109537 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
@@ -109579,12 +109641,12 @@
109579 }
109580 }
109581 if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
109582 idxInsFlags |= OPFLAG_NCHANGE;
109583 }
109584 sqlite3VdbeAddOp3(v, OP_IdxInsert, iDest, regData, 1);
109585 sqlite3VdbeChangeP5(v, idxInsFlags);
109586 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
109587 sqlite3VdbeJumpHere(v, addr1);
109588 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
109589 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
109590 }
@@ -114945,11 +115007,11 @@
114945 int nOBSat = pSort->nOBSat; /* ORDER BY terms to skip */
114946 int op; /* Opcode to add sorter record to sorter */
114947 int iLimit; /* LIMIT counter */
114948
114949 assert( bSeq==0 || bSeq==1 );
114950 assert( nData==1 || regData==regOrigData );
114951 if( nPrefixReg ){
114952 assert( nPrefixReg==nExpr+bSeq );
114953 regBase = regData - nExpr - bSeq;
114954 }else{
114955 regBase = pParse->nMem + 1;
@@ -114957,15 +115019,15 @@
114957 }
114958 assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
114959 iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
114960 pSort->labelDone = sqlite3VdbeMakeLabel(v);
114961 sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
114962 SQLITE_ECEL_DUP|SQLITE_ECEL_REF);
114963 if( bSeq ){
114964 sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
114965 }
114966 if( nPrefixReg==0 ){
114967 sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
114968 }
114969 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord);
114970 if( nOBSat>0 ){
114971 int regPrevKey; /* The first nOBSat columns of the previous row */
@@ -115011,11 +115073,12 @@
115011 if( pSort->sortFlags & SORTFLAG_UseSorter ){
115012 op = OP_SorterInsert;
115013 }else{
115014 op = OP_IdxInsert;
115015 }
115016 sqlite3VdbeAddOp2(v, op, pSort->iECursor, regRecord);
 
115017 if( iLimit ){
115018 int addr;
115019 int r1 = 0;
115020 /* Fill the sorter until it contains LIMIT+OFFSET entries. (The iLimit
115021 ** register is initialized with value of LIMIT+OFFSET.) After the sorter
@@ -115079,11 +115142,11 @@
115079
115080 v = pParse->pVdbe;
115081 r1 = sqlite3GetTempReg(pParse);
115082 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
115083 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
115084 sqlite3VdbeAddOp2(v, OP_IdxInsert, iTab, r1);
115085 sqlite3ReleaseTempReg(pParse, r1);
115086 }
115087
115088 /*
115089 ** This routine generates the code for the inside of the inner loop
@@ -115090,11 +115153,11 @@
115090 ** of a SELECT.
115091 **
115092 ** If srcTab is negative, then the pEList expressions
115093 ** are evaluated in order to get the data for this row. If srcTab is
115094 ** zero or more, then data is pulled from srcTab and pEList is used only
115095 ** to get number columns and the datatype for each column.
115096 */
115097 static void selectInnerLoop(
115098 Parse *pParse, /* The parser context */
115099 Select *p, /* The complete select statement being coded */
115100 ExprList *pEList, /* List of values being extracted */
@@ -115105,17 +115168,24 @@
115105 int iContinue, /* Jump here to continue with next row */
115106 int iBreak /* Jump here to break out of the inner loop */
115107 ){
115108 Vdbe *v = pParse->pVdbe;
115109 int i;
115110 int hasDistinct; /* True if the DISTINCT keyword is present */
115111 int regResult; /* Start of memory holding result set */
115112 int eDest = pDest->eDest; /* How to dispose of results */
115113 int iParm = pDest->iSDParm; /* First argument to disposal method */
115114 int nResultCol; /* Number of result columns */
115115 int nPrefixReg = 0; /* Number of extra registers before regResult */
115116
 
 
 
 
 
 
 
 
115117 assert( v );
115118 assert( pEList!=0 );
115119 hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
115120 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
115121 if( pSort==0 && !hasDistinct ){
@@ -115142,11 +115212,11 @@
115142 ** and reported later. But we need to make sure enough memory is allocated
115143 ** to avoid other spurious errors in the meantime. */
115144 pParse->nMem += nResultCol;
115145 }
115146 pDest->nSdst = nResultCol;
115147 regResult = pDest->iSdst;
115148 if( srcTab>=0 ){
115149 for(i=0; i<nResultCol; i++){
115150 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
115151 VdbeComment((v, "%s", pEList->a[i].zName));
115152 }
@@ -115158,11 +115228,30 @@
115158 if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
115159 ecelFlags = SQLITE_ECEL_DUP;
115160 }else{
115161 ecelFlags = 0;
115162 }
115163 sqlite3ExprCodeExprList(pParse, pEList, regResult, 0, ecelFlags);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115164 }
115165
115166 /* If the DISTINCT keyword was present on the SELECT statement
115167 ** and this row has been seen before, then do not make this row
115168 ** part of the result.
@@ -115232,11 +115321,11 @@
115232 #ifndef SQLITE_OMIT_COMPOUND_SELECT
115233 case SRT_Union: {
115234 int r1;
115235 r1 = sqlite3GetTempReg(pParse);
115236 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
115237 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
115238 sqlite3ReleaseTempReg(pParse, r1);
115239 break;
115240 }
115241
115242 /* Construct a record from the query result, but instead of
@@ -115269,11 +115358,11 @@
115269 ** current row to the index and proceed with writing it to the
115270 ** output table as well. */
115271 int addr = sqlite3VdbeCurrentAddr(v) + 4;
115272 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
115273 VdbeCoverage(v);
115274 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r1);
115275 assert( pSort==0 );
115276 }
115277 #endif
115278 if( pSort ){
115279 pushOntoSorter(pParse, pSort, p, r1+nPrefixReg,regResult,1,nPrefixReg);
@@ -115298,18 +115387,18 @@
115298 /* At first glance you would think we could optimize out the
115299 ** ORDER BY in this case since the order of entries in the set
115300 ** does not matter. But there might be a LIMIT clause, in which
115301 ** case the order does matter */
115302 pushOntoSorter(
115303 pParse, pSort, p, regResult, regResult, nResultCol, nPrefixReg);
115304 }else{
115305 int r1 = sqlite3GetTempReg(pParse);
115306 assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
115307 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
115308 r1, pDest->zAffSdst, nResultCol);
115309 sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
115310 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
115311 sqlite3ReleaseTempReg(pParse, r1);
115312 }
115313 break;
115314 }
115315
@@ -115324,15 +115413,16 @@
115324 /* If this is a scalar select that is part of an expression, then
115325 ** store the results in the appropriate memory cell or array of
115326 ** memory cells and break out of the scan loop.
115327 */
115328 case SRT_Mem: {
115329 assert( nResultCol==pDest->nSdst );
115330 if( pSort ){
 
115331 pushOntoSorter(
115332 pParse, pSort, p, regResult, regResult, nResultCol, nPrefixReg);
115333 }else{
 
115334 assert( regResult==iParm );
115335 /* The LIMIT clause will jump out of the loop for us */
115336 }
115337 break;
115338 }
@@ -115341,11 +115431,11 @@
115341 case SRT_Coroutine: /* Send data to a co-routine */
115342 case SRT_Output: { /* Return the results */
115343 testcase( eDest==SRT_Coroutine );
115344 testcase( eDest==SRT_Output );
115345 if( pSort ){
115346 pushOntoSorter(pParse, pSort, p, regResult, regResult, nResultCol,
115347 nPrefixReg);
115348 }else if( eDest==SRT_Coroutine ){
115349 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
115350 }else{
115351 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
@@ -115391,11 +115481,11 @@
115391 regResult + pSO->a[i].u.x.iOrderByCol - 1,
115392 r2+i);
115393 }
115394 sqlite3VdbeAddOp2(v, OP_Sequence, iParm, r2+nKey);
115395 sqlite3VdbeAddOp3(v, OP_MakeRecord, r2, nKey+2, r1);
115396 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
115397 if( addrTest ) sqlite3VdbeJumpHere(v, addrTest);
115398 sqlite3ReleaseTempReg(pParse, r1);
115399 sqlite3ReleaseTempRange(pParse, r2, nKey+2);
115400 break;
115401 }
@@ -115626,18 +115716,17 @@
115626 ExprList *pOrderBy = pSort->pOrderBy;
115627 int eDest = pDest->eDest;
115628 int iParm = pDest->iSDParm;
115629 int regRow;
115630 int regRowid;
 
115631 int nKey;
115632 int iSortTab; /* Sorter cursor to read from */
115633 int nSortData; /* Trailing values to read from sorter */
115634 int i;
115635 int bSeq; /* True if sorter record includes seq. no. */
115636 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
115637 struct ExprList_item *aOutEx = p->pEList->a;
115638 #endif
115639
115640 assert( addrBreak<0 );
115641 if( pSort->labelBkOut ){
115642 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
115643 sqlite3VdbeGoto(v, addrBreak);
@@ -115671,12 +115760,18 @@
115671 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
115672 codeOffset(v, p->iOffset, addrContinue);
115673 iSortTab = iTab;
115674 bSeq = 1;
115675 }
115676 for(i=0; i<nSortData; i++){
115677 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
 
 
 
 
 
 
115678 VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
115679 }
115680 switch( eDest ){
115681 case SRT_EphemTab: {
115682 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
@@ -115688,11 +115783,11 @@
115688 case SRT_Set: {
115689 assert( nColumn==sqlite3Strlen30(pDest->zAffSdst) );
115690 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, nColumn, regRowid,
115691 pDest->zAffSdst, nColumn);
115692 sqlite3ExprCacheAffinityChange(pParse, regRow, nColumn);
115693 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, regRowid);
115694 break;
115695 }
115696 case SRT_Mem: {
115697 /* The LIMIT clause will terminate the loop for us */
115698 break;
@@ -117064,11 +117159,12 @@
117064 testcase( pIn->nSdst>1 );
117065 r1 = sqlite3GetTempReg(pParse);
117066 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
117067 r1, pDest->zAffSdst, pIn->nSdst);
117068 sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, pIn->nSdst);
117069 sqlite3VdbeAddOp2(v, OP_IdxInsert, pDest->iSDParm, r1);
 
117070 sqlite3ReleaseTempReg(pParse, r1);
117071 break;
117072 }
117073
117074 /* If this is a scalar select that is part of an expression, then
@@ -121687,16 +121783,18 @@
121687 */
121688 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
121689 int reg;
121690 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
121691 reg = ++pParse->nMem;
 
121692 }else{
121693 reg = 0;
121694 for(i=0; i<pIdx->nKeyCol; i++){
121695 i16 iIdxCol = pIdx->aiColumn[i];
121696 if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
121697 reg = ++pParse->nMem;
 
121698 break;
121699 }
121700 }
121701 }
121702 if( reg==0 ) aToOpen[j+1] = 0;
@@ -121803,11 +121901,11 @@
121803 nKey = nPk;
121804 regKey = iPk;
121805 }else{
121806 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
121807 sqlite3IndexAffinityStr(db, pPk), nPk);
121808 sqlite3VdbeAddOp2(v, OP_IdxInsert, iEph, regKey);
121809 }
121810 sqlite3WhereEnd(pWInfo);
121811 }
121812
121813 /* Initialize the count of updated rows
@@ -122062,19 +122160,10 @@
122062 }else{
122063 sqlite3VdbeGoto(v, labelContinue);
122064 }
122065 sqlite3VdbeResolveLabel(v, labelBreak);
122066
122067 /* Close all tables */
122068 for(i=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, i++){
122069 assert( aRegIdx );
122070 if( aToOpen[i+1] ){
122071 sqlite3VdbeAddOp2(v, OP_Close, iIdxCur+i, 0);
122072 }
122073 }
122074 if( iDataCur<iIdxCur ) sqlite3VdbeAddOp2(v, OP_Close, iDataCur, 0);
122075
122076 /* Update the sqlite_sequence table by storing the content of the
122077 ** maximum rowid counter values recorded while inserting into
122078 ** autoincrement tables.
122079 */
122080 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
@@ -124822,10 +124911,11 @@
124822 if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
124823 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
124824 }else{
124825 Select *pSelect = pX->x.pSelect;
124826 sqlite3 *db = pParse->db;
 
124827 ExprList *pOrigRhs = pSelect->pEList;
124828 ExprList *pOrigLhs = pX->pLeft->x.pList;
124829 ExprList *pRhs = 0; /* New Select.pEList for RHS */
124830 ExprList *pLhs = 0; /* New pX->pLeft vector */
124831
@@ -124865,11 +124955,13 @@
124865 pLeft->x.pList = pLhs;
124866 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * nEq);
124867 testcase( aiMap==0 );
124868 }
124869 pSelect->pEList = pRhs;
 
124870 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
 
124871 testcase( aiMap!=0 && aiMap[0]!=0 );
124872 pSelect->pEList = pOrigRhs;
124873 pLeft->x.pList = pOrigLhs;
124874 pX->pLeft = pLeft;
124875 }
@@ -126220,11 +126312,12 @@
126220 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
126221 VdbeCoverage(v);
126222 }
126223 if( iSet>=0 ){
126224 sqlite3VdbeAddOp3(v, OP_MakeRecord, r, nPk, regRowid);
126225 sqlite3VdbeAddOp3(v, OP_IdxInsert, regRowset, regRowid, 0);
 
126226 if( iSet ) sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
126227 }
126228
126229 /* Release the array of temp registers */
126230 sqlite3ReleaseTempRange(pParse, r, nPk);
@@ -127684,10 +127777,12 @@
127684 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
127685
127686 /* Prevent ON clause terms of a LEFT JOIN from being used to drive
127687 ** an index for tables to the left of the join.
127688 */
 
 
127689 pTerm->prereqRight |= extraRight;
127690 }
127691
127692 /***************************************************************************
127693 ** Routines with file scope above. Interface to the rest of the where.c
@@ -132767,31 +132862,10 @@
132767 translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
132768 pTabItem->regResult, 0);
132769 continue;
132770 }
132771
132772 /* Close all of the cursors that were opened by sqlite3WhereBegin.
132773 ** Except, do not close cursors that will be reused by the OR optimization
132774 ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors
132775 ** created for the ONEPASS optimization.
132776 */
132777 if( (pTab->tabFlags & TF_Ephemeral)==0
132778 && pTab->pSelect==0
132779 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
132780 ){
132781 int ws = pLoop->wsFlags;
132782 if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
132783 sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
132784 }
132785 if( (ws & WHERE_INDEXED)!=0
132786 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0
132787 && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
132788 ){
132789 sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
132790 }
132791 }
132792
132793 /* If this scan uses an index, make VDBE code substitutions to read data
132794 ** from the index instead of from the table where possible. In some cases
132795 ** this optimization prevents the table from ever being read, which can
132796 ** yield a significant performance boost.
132797 **
@@ -165455,24 +165529,24 @@
165455 int nArg; /* Number of arguments */
165456 int enc; /* Optimal text encoding */
165457 void *pContext; /* sqlite3_user_data() context */
165458 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
165459 } scalars[] = {
165460 {"regexp", 2, SQLITE_ANY, 0, icuRegexpFunc},
165461
165462 {"lower", 1, SQLITE_UTF16, 0, icuCaseFunc16},
165463 {"lower", 2, SQLITE_UTF16, 0, icuCaseFunc16},
165464 {"upper", 1, SQLITE_UTF16, (void*)1, icuCaseFunc16},
165465 {"upper", 2, SQLITE_UTF16, (void*)1, icuCaseFunc16},
165466
165467 {"lower", 1, SQLITE_UTF8, 0, icuCaseFunc16},
165468 {"lower", 2, SQLITE_UTF8, 0, icuCaseFunc16},
165469 {"upper", 1, SQLITE_UTF8, (void*)1, icuCaseFunc16},
165470 {"upper", 2, SQLITE_UTF8, (void*)1, icuCaseFunc16},
165471
165472 {"like", 2, SQLITE_UTF8, 0, icuLikeFunc},
165473 {"like", 3, SQLITE_UTF8, 0, icuLikeFunc},
165474
165475 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
165476 };
165477
165478 int rc = SQLITE_OK;
@@ -176486,17 +176560,19 @@
176486 ** to pass signed char values.
176487 */
176488 #ifdef sqlite3Isdigit
176489 /* Use the SQLite core versions if this routine is part of the
176490 ** SQLite amalgamation */
176491 # define safe_isdigit(x) sqlite3Isdigit(x)
176492 # define safe_isalnum(x) sqlite3Isalnum(x)
 
176493 #else
176494 /* Use the standard library for separate compilation */
176495 #include <ctype.h> /* amalgamator: keep */
176496 # define safe_isdigit(x) isdigit((unsigned char)(x))
176497 # define safe_isalnum(x) isalnum((unsigned char)(x))
 
176498 #endif
176499
176500 /*
176501 ** Growing our own isspace() routine this way is twice as fast as
176502 ** the library isspace() function, resulting in a 7% overall performance
@@ -177030,16 +177106,17 @@
177030 zOut[j++] = c;
177031 }else{
177032 c = z[++i];
177033 if( c=='u' ){
177034 u32 v = 0, k;
177035 for(k=0; k<4 && i<n-2; i++, k++){
 
177036 c = z[i+1];
177037 if( c>='0' && c<='9' ) v = v*16 + c - '0';
177038 else if( c>='A' && c<='F' ) v = v*16 + c - 'A' + 10;
177039 else if( c>='a' && c<='f' ) v = v*16 + c - 'a' + 10;
177040 else break;
177041 }
177042 if( v==0 ) break;
177043 if( v<=0x7f ){
177044 zOut[j++] = (char)v;
177045 }else if( v<=0x7ff ){
@@ -177138,10 +177215,19 @@
177138 p->iVal = 0;
177139 p->n = n;
177140 p->u.zJContent = zContent;
177141 return pParse->nNode++;
177142 }
 
 
 
 
 
 
 
 
 
177143
177144 /*
177145 ** Parse a single JSON value which begins at pParse->zJson[i]. Return the
177146 ** index of the first character past the end of the value parsed.
177147 **
@@ -177213,12 +177299,17 @@
177213 for(;;){
177214 c = pParse->zJson[j];
177215 if( c==0 ) return -1;
177216 if( c=='\\' ){
177217 c = pParse->zJson[++j];
177218 if( c==0 ) return -1;
177219 jnFlags = JNODE_ESCAPE;
 
 
 
 
 
177220 }else if( c=='"' ){
177221 break;
177222 }
177223 j++;
177224 }
@@ -178082,11 +178173,11 @@
178082 JsonString *pStr;
178083 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
178084 if( pStr ){
178085 jsonAppendChar(pStr, '}');
178086 if( pStr->bErr ){
178087 if( pStr->bErr==0 ) sqlite3_result_error_nomem(ctx);
178088 assert( pStr->bStatic );
178089 }else{
178090 sqlite3_result_text(ctx, pStr->zBuf, pStr->nUsed,
178091 pStr->bStatic ? SQLITE_TRANSIENT : sqlite3_free);
178092 pStr->bStatic = 1;
@@ -178360,13 +178451,13 @@
178360 break;
178361 }
178362 /* For json_each() path and root are the same so fall through
178363 ** into the root case */
178364 }
178365 case JEACH_ROOT: {
178366 const char *zRoot = p->zRoot;
178367 if( zRoot==0 ) zRoot = "$";
178368 sqlite3_result_text(ctx, zRoot, -1, SQLITE_STATIC);
178369 break;
178370 }
178371 case JEACH_JSON: {
178372 assert( i==JEACH_JSON );
@@ -184289,11 +184380,11 @@
184289 pNode->bEof = 1;
184290 return rc;
184291 }
184292 }else{
184293 Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
184294 if( pIter->iRowid==iLast ) continue;
184295 bMatch = 0;
184296 if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
184297 return rc;
184298 }
184299 }
@@ -189429,10 +189520,11 @@
189429 Fts5Iter *pIter,
189430 int bFrom, /* True if argument iFrom is valid */
189431 i64 iFrom /* Advance at least as far as this */
189432 ){
189433 int bUseFrom = bFrom;
 
189434 while( p->rc==SQLITE_OK ){
189435 int iFirst = pIter->aFirst[1].iFirst;
189436 int bNewTerm = 0;
189437 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
189438 assert( p->rc==SQLITE_OK );
@@ -195693,11 +195785,11 @@
195693 int nArg, /* Number of args */
195694 sqlite3_value **apUnused /* Function arguments */
195695 ){
195696 assert( nArg==0 );
195697 UNUSED_PARAM2(nArg, apUnused);
195698 sqlite3_result_text(pCtx, "fts5: 2016-10-26 16:05:10 ec9dab8054c71d112c68f58a45821b38c2a45677", -1, SQLITE_TRANSIENT);
195699 }
195700
195701 static int fts5Init(sqlite3 *db){
195702 static const sqlite3_module fts5Mod = {
195703 /* iVersion */ 2,
195704
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,15 +381,15 @@
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.0"
385 #define SQLITE_VERSION_NUMBER 3016000
386 #define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version sqlite3_sourceid
391 **
392 ** These interfaces provide the same information as the [SQLITE_VERSION],
393 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
394 ** but are associated with the library instead of the header file. ^(Cautious
395 ** programmers might include assert() statements in their application to
@@ -8483,11 +8483,12 @@
8483 ** triggers; or 2 for changes resulting from triggers called by top-level
8484 ** triggers; and so forth.
8485 **
8486 ** See also: [sqlite3_update_hook()]
8487 */
8488 #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
8489 SQLITE_API void *sqlite3_preupdate_hook(
8490 sqlite3 *db,
8491 void(*xPreUpdate)(
8492 void *pCtx, /* Copy of third arg to preupdate_hook() */
8493 sqlite3 *db, /* Database handle */
8494 int op, /* SQLITE_UPDATE, DELETE or INSERT */
@@ -8496,14 +8497,15 @@
8497 sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
8498 sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
8499 ),
8500 void*
8501 );
8502 SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8503 SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
8504 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
8505 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
8506 #endif
8507
8508 /*
8509 ** CAPI3REF: Low-level system error code
8510 **
8511 ** ^Attempt to return the underlying operating system error code or error
@@ -12307,10 +12309,12 @@
12309 */
12310 struct BtreePayload {
12311 const void *pKey; /* Key content for indexes. NULL for tables */
12312 sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
12313 const void *pData; /* Data for tables. NULL for indexes */
12314 struct Mem *aMem; /* First of nMem value in the unpacked pKey */
12315 u16 nMem; /* Number of aMem[] value. Might be zero */
12316 int nData; /* Size of pData. 0 if none. */
12317 int nZero; /* Extra zero data appended after pData,nData */
12318 };
12319
12320 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
@@ -12340,10 +12344,11 @@
12344 SQLITE_PRIVATE int sqlite3HeaderSizeBtree(void);
12345
12346 #ifndef NDEBUG
12347 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor*);
12348 #endif
12349 SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor*);
12350
12351 #ifndef SQLITE_OMIT_BTREECOUNT
12352 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *, i64 *);
12353 #endif
12354
@@ -15596,19 +15601,19 @@
15601 int iReg; /* Reg with value of this column. 0 means none. */
15602 int lru; /* Least recently used entry has the smallest value */
15603 } aColCache[SQLITE_N_COLCACHE]; /* One for each column cache entry */
15604 int aTempReg[8]; /* Holding area for temporary registers */
15605 Token sNameToken; /* Token with unqualified schema object name */
 
15606
15607 /************************************************************************
15608 ** Above is constant between recursions. Below is reset before and after
15609 ** each recursion. The boundary between these two regions is determined
15610 ** using offsetof(Parse,sLastToken) so the sLastToken field must be the
15611 ** first field in the recursive region.
15612 ************************************************************************/
15613
15614 Token sLastToken; /* The last token parsed */
15615 ynVar nVar; /* Number of '?' variables seen in the SQL so far */
15616 int nzVar; /* Number of available slots in azVar[] */
15617 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
15618 u8 explain; /* True if the EXPLAIN flag is found on the query */
15619 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -15638,11 +15643,11 @@
15643
15644 /*
15645 ** Sizes and pointers of various parts of the Parse object.
15646 */
15647 #define PARSE_HDR_SZ offsetof(Parse,aColCache) /* Recursive part w/o aColCache*/
15648 #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
15649 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
15650 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
15651
15652 /*
15653 ** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -16355,10 +16360,11 @@
16360 SQLITE_PRIVATE void sqlite3ExprCodeAndCache(Parse*, Expr*, int);
16361 SQLITE_PRIVATE int sqlite3ExprCodeExprList(Parse*, ExprList*, int, int, u8);
16362 #define SQLITE_ECEL_DUP 0x01 /* Deep, not shallow copies */
16363 #define SQLITE_ECEL_FACTOR 0x02 /* Factor out constant terms */
16364 #define SQLITE_ECEL_REF 0x04 /* Use ExprList.u.x.iOrderByCol */
16365 #define SQLITE_ECEL_OMITREF 0x08 /* Omit if ExprList.u.x.iOrderByCol */
16366 SQLITE_PRIVATE void sqlite3ExprIfTrue(Parse*, Expr*, int, int);
16367 SQLITE_PRIVATE void sqlite3ExprIfFalse(Parse*, Expr*, int, int);
16368 SQLITE_PRIVATE void sqlite3ExprIfFalseDup(Parse*, Expr*, int, int);
16369 SQLITE_PRIVATE Table *sqlite3FindTable(sqlite3*,const char*, const char*);
16370 #define LOCATE_VIEW 0x01
@@ -17802,11 +17808,14 @@
17808 int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
17809 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
17810 } uc;
17811 Btree *pBt; /* Separate file holding temporary table */
17812 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
17813 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
17814 ** if there have been no prior seeks on the cursor. */
17815 /* NB: seekResult does not distinguish between "no seeks have ever occurred
17816 ** on this cursor" and "the most recent seek was an exact match". */
17817 i64 seqCount; /* Sequence counter */
17818 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
17819 VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
17820 int *aAltMap; /* Mapping from table to index column numbers */
17821 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
@@ -25889,10 +25898,11 @@
25898 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
25899 }
25900 va_start(ap, zFormat);
25901 sqlite3VXPrintf(&acc, zFormat, ap);
25902 va_end(ap);
25903 assert( acc.nChar>0 );
25904 if( zBuf[acc.nChar-1]!='\n' ) sqlite3StrAccumAppend(&acc, "\n", 1);
25905 sqlite3StrAccumFinish(&acc);
25906 fprintf(stdout,"%s", zBuf);
25907 fflush(stdout);
25908 }
@@ -50417,11 +50427,14 @@
50427 sqlite3BeginBenignMalloc();
50428 pagerFreeMapHdrs(pPager);
50429 /* pPager->errCode = 0; */
50430 pPager->exclusiveMode = 0;
50431 #ifndef SQLITE_OMIT_WAL
50432 assert( db || pPager->pWal==0 );
50433 sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, pPager->pageSize,
50434 (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp)
50435 );
50436 pPager->pWal = 0;
50437 #endif
50438 pager_reset(pPager);
50439 if( MEMDB ){
50440 pager_unlock(pPager);
@@ -55752,11 +55765,11 @@
55765 ** the database. In this case checkpoint the database and unlink both
55766 ** the wal and wal-index files.
55767 **
55768 ** The EXCLUSIVE lock is not released before returning.
55769 */
55770 if( zBuf!=0
55771 && SQLITE_OK==(rc = sqlite3OsLock(pWal->pDbFd, SQLITE_LOCK_EXCLUSIVE))
55772 ){
55773 if( pWal->exclusiveMode==WAL_NORMAL_MODE ){
55774 pWal->exclusiveMode = WAL_EXCLUSIVE_MODE;
55775 }
@@ -62555,10 +62568,14 @@
62568 */
62569 SQLITE_PRIVATE int sqlite3BtreeCursorIsValid(BtCursor *pCur){
62570 return pCur && pCur->eState==CURSOR_VALID;
62571 }
62572 #endif /* NDEBUG */
62573 SQLITE_PRIVATE int sqlite3BtreeCursorIsValidNN(BtCursor *pCur){
62574 assert( pCur!=0 );
62575 return pCur->eState==CURSOR_VALID;
62576 }
62577
62578 /*
62579 ** Return the value of the integer key or "rowid" for a table btree.
62580 ** This routine is only valid for a cursor that is pointing into a
62581 ** ordinary table btree. If the cursor points to an index btree or
@@ -63442,20 +63459,20 @@
63459 }else if( nCellKey>intKey ){
63460 upr = idx-1;
63461 if( lwr>upr ){ c = +1; break; }
63462 }else{
63463 assert( nCellKey==intKey );
 
 
63464 pCur->aiIdx[pCur->iPage] = (u16)idx;
63465 if( !pPage->leaf ){
63466 lwr = idx;
63467 goto moveto_next_layer;
63468 }else{
63469 pCur->curFlags |= BTCF_ValidNKey;
63470 pCur->info.nKey = nCellKey;
63471 pCur->info.nSize = 0;
63472 *pRes = 0;
63473 return SQLITE_OK;
 
63474 }
63475 }
63476 assert( lwr+upr>=0 );
63477 idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2; */
63478 }
@@ -63562,11 +63579,11 @@
63579 rc = moveToChild(pCur, chldPg);
63580 if( rc ) break;
63581 }
63582 moveto_finish:
63583 pCur->info.nSize = 0;
63584 assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
63585 return rc;
63586 }
63587
63588
63589 /*
@@ -63760,11 +63777,11 @@
63777 return SQLITE_OK;
63778 }
63779 moveToParent(pCur);
63780 }
63781 assert( pCur->info.nSize==0 );
63782 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
63783
63784 pCur->aiIdx[pCur->iPage]--;
63785 pPage = pCur->apPage[pCur->iPage];
63786 if( pPage->intKey && !pPage->leaf ){
63787 rc = sqlite3BtreePrevious(pCur, pRes);
@@ -66217,21 +66234,23 @@
66234 ** For an index btree (used for indexes and WITHOUT ROWID tables), the
66235 ** key is an arbitrary byte sequence stored in pX.pKey,nKey. The
66236 ** pX.pData,nData,nZero fields must be zero.
66237 **
66238 ** If the seekResult parameter is non-zero, then a successful call to
66239 ** MovetoUnpacked() to seek cursor pCur to (pKey,nKey) has already
66240 ** been performed. In other words, if seekResult!=0 then the cursor
66241 ** is currently pointing to a cell that will be adjacent to the cell
66242 ** to be inserted. If seekResult<0 then pCur points to a cell that is
66243 ** smaller then (pKey,nKey). If seekResult>0 then pCur points to a cell
66244 ** that is larger than (pKey,nKey).
66245 **
66246 ** If seekResult==0, that means pCur is pointing at some unknown location.
66247 ** In that case, this routine must seek the cursor to the correct insertion
66248 ** point for (pKey,nKey) before doing the insertion. For index btrees,
66249 ** if pX->nMem is non-zero, then pX->aMem contains pointers to the unpacked
66250 ** key values and pX->aMem can be used instead of pX->pKey to avoid having
66251 ** to decode the key.
66252 */
66253 SQLITE_PRIVATE int sqlite3BtreeInsert(
66254 BtCursor *pCur, /* Insert data into the table of this cursor */
66255 const BtreePayload *pX, /* Content of the row to be inserted */
66256 int appendBias, /* True if this is likely an append */
@@ -66288,19 +66307,30 @@
66307 invalidateIncrblobCursors(p, pX->nKey, 0);
66308
66309 /* If the cursor is currently on the last row and we are appending a
66310 ** new row onto the end, set the "loc" to avoid an unnecessary
66311 ** btreeMoveto() call */
66312 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
66313 loc = 0;
66314 }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
66315 && pCur->info.nKey==pX->nKey-1 ){
66316 loc = -1;
66317 }else if( loc==0 ){
66318 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, appendBias, &loc);
66319 if( rc ) return rc;
66320 }
66321 }else if( loc==0 ){
66322 if( pX->nMem ){
66323 UnpackedRecord r;
66324 memset(&r, 0, sizeof(r));
66325 r.pKeyInfo = pCur->pKeyInfo;
66326 r.aMem = pX->aMem;
66327 r.nField = pX->nMem;
66328 rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc);
66329 }else{
66330 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
66331 }
66332 if( rc ) return rc;
66333 }
66334 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
66335
66336 pPage = pCur->apPage[pCur->iPage];
@@ -66838,31 +66868,11 @@
66868 MemPage *pPage = 0;
66869 BtShared *pBt = p->pBt;
66870
66871 assert( sqlite3BtreeHoldsMutex(p) );
66872 assert( p->inTrans==TRANS_WRITE );
66873 assert( iTable>=2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66874
66875 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
66876 if( rc ) return rc;
66877 rc = sqlite3BtreeClearTable(p, iTable, 0);
66878 if( rc ){
@@ -81675,19 +81685,14 @@
81685 ** If the OPFLAG_NCHANGE flag of P5 is set, then the row change count is
81686 ** incremented (otherwise not). If the OPFLAG_LASTROWID flag of P5 is set,
81687 ** then rowid is stored for subsequent return by the
81688 ** sqlite3_last_insert_rowid() function (otherwise it is unmodified).
81689 **
81690 ** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
81691 ** run faster by avoiding an unnecessary seek on cursor P1. However,
81692 ** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
81693 ** seeks on the cursor or if the most recent seek used a key equal to P3.
 
 
 
 
 
81694 **
81695 ** If the OPFLAG_ISUPDATE flag is set, then this opcode is part of an
81696 ** UPDATE operation. Otherwise (if the flag is clear) then this opcode
81697 ** is part of an INSERT operation. The difference is only important to
81698 ** the update hook.
@@ -81907,10 +81912,11 @@
81912 }
81913 #endif
81914
81915 rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5);
81916 pC->cacheStatus = CACHE_STALE;
81917 pC->seekResult = 0;
81918 if( rc ) goto abort_due_to_error;
81919
81920 /* Invoke the update-hook if required. */
81921 if( opflags & OPFLAG_NCHANGE ){
81922 p->nChange++;
@@ -82156,10 +82162,17 @@
82162 ** to the following instruction.
82163 **
82164 ** This opcode leaves the cursor configured to move in reverse order,
82165 ** from the end toward the beginning. In other words, the cursor is
82166 ** configured to use Prev, not Next.
82167 **
82168 ** If P3 is -1, then the cursor is positioned at the end of the btree
82169 ** for the purpose of appending a new entry onto the btree. In that
82170 ** case P2 must be 0. It is assumed that the cursor is used only for
82171 ** appending and so if the cursor is valid, then the cursor must already
82172 ** be pointing at the end of the btree and so no changes are made to
82173 ** the cursor.
82174 */
82175 case OP_Last: { /* jump */
82176 VdbeCursor *pC;
82177 BtCursor *pCrsr;
82178 int res;
@@ -82169,22 +82182,26 @@
82182 assert( pC!=0 );
82183 assert( pC->eCurType==CURTYPE_BTREE );
82184 pCrsr = pC->uc.pCursor;
82185 res = 0;
82186 assert( pCrsr!=0 );
 
 
 
 
82187 pC->seekResult = pOp->p3;
82188 #ifdef SQLITE_DEBUG
82189 pC->seekOp = OP_Last;
82190 #endif
82191 if( pOp->p3==0 || !sqlite3BtreeCursorIsValidNN(pCrsr) ){
82192 rc = sqlite3BtreeLast(pCrsr, &res);
82193 pC->nullRow = (u8)res;
82194 pC->deferredMoveto = 0;
82195 pC->cacheStatus = CACHE_STALE;
82196 if( rc ) goto abort_due_to_error;
82197 if( pOp->p2>0 ){
82198 VdbeBranchTaken(res!=0,2);
82199 if( res ) goto jump_to_p2;
82200 }
82201 }else{
82202 assert( pOp->p2==0 );
82203 }
82204 break;
82205 }
82206
82207
@@ -82369,27 +82386,34 @@
82386 pC->nullRow = 1;
82387 }
82388 goto check_for_interrupt;
82389 }
82390
82391 /* Opcode: IdxInsert P1 P2 P3 P4 P5
82392 ** Synopsis: key=r[P2]
82393 **
82394 ** Register P2 holds an SQL index key made using the
82395 ** MakeRecord instructions. This opcode writes that key
82396 ** into the index P1. Data for the entry is nil.
82397 **
82398 ** If P4 is not zero, then it is the number of values in the unpacked
82399 ** key of reg(P2). In that case, P3 is the index of the first register
82400 ** for the unpacked key. The availability of the unpacked key can sometimes
82401 ** be an optimization.
82402 **
82403 ** If P5 has the OPFLAG_APPEND bit set, that is a hint to the b-tree layer
82404 ** that this insert is likely to be an append.
82405 **
82406 ** If P5 has the OPFLAG_NCHANGE bit set, then the change counter is
82407 ** incremented by this instruction. If the OPFLAG_NCHANGE bit is clear,
82408 ** then the change counter is unchanged.
82409 **
82410 ** If the OPFLAG_USESEEKRESULT flag of P5 is set, the implementation might
82411 ** run faster by avoiding an unnecessary seek on cursor P1. However,
82412 ** the OPFLAG_USESEEKRESULT flag must only be set if there have been no prior
82413 ** seeks on the cursor or if the most recent seek used a key equivalent
82414 ** to P2.
82415 **
82416 ** This instruction only works for indices. The equivalent instruction
82417 ** for tables is OP_Insert.
82418 */
82419 /* Opcode: SorterInsert P1 P2 * * *
@@ -82418,11 +82442,14 @@
82442 if( pOp->opcode==OP_SorterInsert ){
82443 rc = sqlite3VdbeSorterWrite(pC, pIn2);
82444 }else{
82445 x.nKey = pIn2->n;
82446 x.pKey = pIn2->z;
82447 x.aMem = aMem + pOp->p3;
82448 x.nMem = (u16)pOp->p4.i;
82449 rc = sqlite3BtreeInsert(pC->uc.pCursor, &x,
82450 (pOp->p5 & OPFLAG_APPEND)!=0,
82451 ((pOp->p5 & OPFLAG_USESEEKRESULT) ? pC->seekResult : 0)
82452 );
82453 assert( pC->deferredMoveto==0 );
82454 pC->cacheStatus = CACHE_STALE;
82455 }
@@ -82462,10 +82489,11 @@
82489 rc = sqlite3BtreeDelete(pCrsr, BTREE_AUXDELETE);
82490 if( rc ) goto abort_due_to_error;
82491 }
82492 assert( pC->deferredMoveto==0 );
82493 pC->cacheStatus = CACHE_STALE;
82494 pC->seekResult = 0;
82495 break;
82496 }
82497
82498 /* Opcode: Seek P1 * P3 P4 *
82499 ** Synopsis: Move P3 to P1.rowid
@@ -84648,12 +84676,11 @@
84676 {OP_Variable, 1, 1, 0}, /* 2: Move ?1 into reg[1] */
84677 {OP_NotExists, 0, 7, 1}, /* 3: Seek the cursor */
84678 {OP_Column, 0, 0, 1}, /* 4 */
84679 {OP_ResultRow, 1, 0, 0}, /* 5 */
84680 {OP_Goto, 0, 2, 0}, /* 6 */
84681 {OP_Halt, 0, 0, 0}, /* 7 */
 
84682 };
84683 Vdbe *v = (Vdbe *)pBlob->pStmt;
84684 int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
84685 VdbeOp *aOp;
84686
@@ -88636,10 +88663,14 @@
88663 assert( pExpr->x.pSelect==0 );
88664 pOrig = pEList->a[j].pExpr;
88665 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
88666 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
88667 return WRC_Abort;
88668 }
88669 if( sqlite3ExprVectorSize(pOrig)!=1 ){
88670 sqlite3ErrorMsg(pParse, "row value misused");
88671 return WRC_Abort;
88672 }
88673 resolveAlias(pParse, pEList, j, pExpr, "", nSubquery);
88674 cnt = 1;
88675 pMatch = 0;
88676 assert( zTab==0 && zDb==0 );
@@ -89013,10 +89044,11 @@
89044 }
89045 case TK_VARIABLE: {
89046 notValid(pParse, pNC, "parameters", NC_IsCheck|NC_PartIdx|NC_IdxExpr);
89047 break;
89048 }
89049 case TK_BETWEEN:
89050 case TK_EQ:
89051 case TK_NE:
89052 case TK_LT:
89053 case TK_LE:
89054 case TK_GT:
@@ -89023,23 +89055,31 @@
89055 case TK_GE:
89056 case TK_IS:
89057 case TK_ISNOT: {
89058 int nLeft, nRight;
89059 if( pParse->db->mallocFailed ) break;
 
89060 assert( pExpr->pLeft!=0 );
89061 nLeft = sqlite3ExprVectorSize(pExpr->pLeft);
89062 if( pExpr->op==TK_BETWEEN ){
89063 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[0].pExpr);
89064 if( nRight==nLeft ){
89065 nRight = sqlite3ExprVectorSize(pExpr->x.pList->a[1].pExpr);
89066 }
89067 }else{
89068 assert( pExpr->pRight!=0 );
89069 nRight = sqlite3ExprVectorSize(pExpr->pRight);
89070 }
89071 if( nLeft!=nRight ){
89072 testcase( pExpr->op==TK_EQ );
89073 testcase( pExpr->op==TK_NE );
89074 testcase( pExpr->op==TK_LT );
89075 testcase( pExpr->op==TK_LE );
89076 testcase( pExpr->op==TK_GT );
89077 testcase( pExpr->op==TK_GE );
89078 testcase( pExpr->op==TK_IS );
89079 testcase( pExpr->op==TK_ISNOT );
89080 testcase( pExpr->op==TK_BETWEEN );
89081 sqlite3ErrorMsg(pParse, "row value misused");
89082 }
89083 break;
89084 }
89085 }
@@ -92306,11 +92346,11 @@
92346 VdbeCoverage(v);
92347 sqlite3VdbeAddOp3(v, OP_Insert, pExpr->iTable, r2, r3);
92348 }else{
92349 sqlite3VdbeAddOp4(v, OP_MakeRecord, r3, 1, r2, &affinity, 1);
92350 sqlite3ExprCacheAffinityChange(pParse, r3, 1);
92351 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pExpr->iTable, r2, r3, 1);
92352 }
92353 }
92354 }
92355 sqlite3ReleaseTempReg(pParse, r1);
92356 sqlite3ReleaseTempReg(pParse, r2);
@@ -93854,12 +93894,17 @@
93894 assert( pParse->pVdbe!=0 ); /* Never gets this far otherwise */
93895 n = pList->nExpr;
93896 if( !ConstFactorOk(pParse) ) flags &= ~SQLITE_ECEL_FACTOR;
93897 for(pItem=pList->a, i=0; i<n; i++, pItem++){
93898 Expr *pExpr = pItem->pExpr;
93899 if( (flags & SQLITE_ECEL_REF)!=0 && (j = pItem->u.x.iOrderByCol)>0 ){
93900 if( flags & SQLITE_ECEL_OMITREF ){
93901 i--;
93902 n--;
93903 }else{
93904 sqlite3VdbeAddOp2(v, copyOp, j+srcReg-1, target+i);
93905 }
93906 }else if( (flags & SQLITE_ECEL_FACTOR)!=0 && sqlite3ExprIsConstant(pExpr) ){
93907 sqlite3ExprCodeAtInit(pParse, pExpr, target+i, 0);
93908 }else{
93909 int inReg = sqlite3ExprCodeTarget(pParse, pExpr, target+i);
93910 if( inReg!=target+i ){
@@ -97815,10 +97860,11 @@
97860 NameContext sName;
97861 Vdbe *v;
97862 sqlite3* db = pParse->db;
97863 int regArgs;
97864
97865 if( pParse->nErr ) goto attach_end;
97866 memset(&sName, 0, sizeof(NameContext));
97867 sName.pParse = pParse;
97868
97869 if(
97870 SQLITE_OK!=(rc = resolveAttachExpr(&sName, pFilename)) ||
@@ -98397,10 +98443,12 @@
98443 int i;
98444 int nBytes;
98445 TableLock *p;
98446 assert( iDb>=0 );
98447
98448 if( iDb==1 ) return;
98449 if( !sqlite3BtreeSharable(pParse->db->aDb[iDb].pBt) ) return;
98450 for(i=0; i<pToplevel->nTableLock; i++){
98451 p = &pToplevel->aTableLock[i];
98452 if( p->iDb==iDb && p->iTab==iTab ){
98453 p->isWriteLock = (p->isWriteLock || isWriteLock);
98454 return;
@@ -101154,11 +101202,11 @@
101202 }else{
101203 addr2 = sqlite3VdbeCurrentAddr(v);
101204 }
101205 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
101206 sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
101207 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, regRecord);
101208 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
101209 sqlite3ReleaseTempReg(pParse, regRecord);
101210 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
101211 sqlite3VdbeJumpHere(v, addr1);
101212
@@ -103702,11 +103750,11 @@
103750 /* Add the PK key for this row to the temporary table */
103751 iKey = ++pParse->nMem;
103752 nKey = 0; /* Zero tells OP_Found to use a composite key */
103753 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, iKey,
103754 sqlite3IndexAffinityStr(pParse->db, pPk), nPk);
103755 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEphCur, iKey, iPk, nPk);
103756 }else{
103757 /* Add the rowid of the row to be deleted to the RowSet */
103758 nKey = 1; /* OP_Seek always uses a single rowid */
103759 sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, iKey);
103760 }
@@ -103791,18 +103839,10 @@
103839 sqlite3VdbeJumpHere(v, addrLoop);
103840 }else{
103841 sqlite3VdbeGoto(v, addrLoop);
103842 sqlite3VdbeJumpHere(v, addrLoop);
103843 }
 
 
 
 
 
 
 
 
103844 } /* End non-truncate path */
103845
103846 /* Update the sqlite_sequence table by storing the content of the
103847 ** maximum rowid counter values recorded while inserting into
103848 ** autoincrement tables.
@@ -104360,10 +104400,12 @@
104400 isText = 0;
104401 }else{
104402 zHaystack = sqlite3_value_text(argv[0]);
104403 zNeedle = sqlite3_value_text(argv[1]);
104404 isText = 1;
104405 if( zNeedle==0 ) return;
104406 assert( zHaystack );
104407 }
104408 while( nNeedle<=nHaystack && memcmp(zHaystack, zNeedle, nNeedle)!=0 ){
104409 N++;
104410 do{
104411 nHaystack--;
@@ -107898,11 +107940,11 @@
107940 int onError /* How to handle constraint errors */
107941 ){
107942 sqlite3 *db; /* The main database structure */
107943 Table *pTab; /* The table to insert into. aka TABLE */
107944 char *zTab; /* Name of the table into which we are inserting */
107945 int i, j; /* Loop counters */
107946 Vdbe *v; /* Generate code into this virtual machine */
107947 Index *pIdx; /* For looping over indices of the table */
107948 int nColumn; /* Number of columns in the data */
107949 int nHidden = 0; /* Number of hidden columns if TABLE is virtual */
107950 int iDataCur = 0; /* VDBE cursor that is the main data repository */
@@ -108205,12 +108247,14 @@
108247 &iDataCur, &iIdxCur);
108248 aRegIdx = sqlite3DbMallocRawNN(db, sizeof(int)*(nIdx+1));
108249 if( aRegIdx==0 ){
108250 goto insert_cleanup;
108251 }
108252 for(i=0, pIdx=pTab->pIndex; i<nIdx; pIdx=pIdx->pNext, i++){
108253 assert( pIdx );
108254 aRegIdx[i] = ++pParse->nMem;
108255 pParse->nMem += pIdx->nColumn;
108256 }
108257 }
108258
108259 /* This is the top of the main insertion loop */
108260 if( useTempTable ){
@@ -108408,16 +108452,30 @@
108452 sqlite3MayAbort(pParse);
108453 }else
108454 #endif
108455 {
108456 int isReplace; /* Set to true if constraints may cause a replace */
108457 int bUseSeek; /* True to use OPFLAG_SEEKRESULT */
108458 sqlite3GenerateConstraintChecks(pParse, pTab, aRegIdx, iDataCur, iIdxCur,
108459 regIns, 0, ipkColumn>=0, onError, endOfLoop, &isReplace, 0
108460 );
108461 sqlite3FkCheck(pParse, pTab, 0, regIns, 0, 0);
108462
108463 /* Set the OPFLAG_USESEEKRESULT flag if either (a) there are no REPLACE
108464 ** constraints or (b) there are no triggers and this table is not a
108465 ** parent table in a foreign key constraint. It is safe to set the
108466 ** flag in the second case as if any REPLACE constraint is hit, an
108467 ** OP_Delete or OP_IdxDelete instruction will be executed on each
108468 ** cursor that is disturbed. And these instructions both clear the
108469 ** VdbeCursor.seekResult variable, disabling the OPFLAG_USESEEKRESULT
108470 ** functionality. */
108471 bUseSeek = (isReplace==0 || (pTrigger==0 &&
108472 ((db->flags & SQLITE_ForeignKeys)==0 || sqlite3FkReferences(pTab)==0)
108473 ));
108474 sqlite3CompleteInsertion(pParse, pTab, iDataCur, iIdxCur,
108475 regIns, aRegIdx, 0, appendFlag, bUseSeek
108476 );
108477 }
108478 }
108479
108480 /* Update the count of rows that are inserted
108481 */
@@ -108442,18 +108500,10 @@
108500 }else if( pSelect ){
108501 sqlite3VdbeGoto(v, addrCont);
108502 sqlite3VdbeJumpHere(v, addrInsTop);
108503 }
108504
 
 
 
 
 
 
 
 
108505 insert_end:
108506 /* Update the sqlite_sequence table by storing the content of the
108507 ** maximum rowid counter values recorded while inserting into
108508 ** autoincrement tables.
108509 */
@@ -108656,11 +108706,10 @@
108706 int nPkField; /* Number of fields in PRIMARY KEY. 1 for ROWID tables */
108707 int ipkTop = 0; /* Top of the rowid change constraint check */
108708 int ipkBottom = 0; /* Bottom of the rowid change constraint check */
108709 u8 isUpdate; /* True if this is an UPDATE operation */
108710 u8 bAffinityDone = 0; /* True if the OP_Affinity operation has been run */
 
108711
108712 isUpdate = regOldData!=0;
108713 db = pParse->db;
108714 v = sqlite3GetVdbe(pParse);
108715 assert( v!=0 );
@@ -108776,11 +108825,11 @@
108825 }else if( onError==OE_Default ){
108826 onError = OE_Abort;
108827 }
108828
108829 if( isUpdate ){
108830 /* pkChng!=0 does not mean that the rowid has changed, only that
108831 ** it might have changed. Skip the conflict logic below if the rowid
108832 ** is unchanged. */
108833 sqlite3VdbeAddOp3(v, OP_Eq, regNewData, addrRowidOk, regOldData);
108834 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
108835 VdbeCoverage(v);
@@ -108911,11 +108960,11 @@
108960 }
108961
108962 /* Create a record for this index entry as it should appear after
108963 ** the insert or update. Store that record in the aRegIdx[ix] register
108964 */
108965 regIdx = aRegIdx[ix]+1;
108966 for(i=0; i<pIdx->nColumn; i++){
108967 int iField = pIdx->aiColumn[i];
108968 int x;
108969 if( iField==XN_EXPR ){
108970 pParse->ckBase = regNewData+1;
@@ -108922,23 +108971,20 @@
108971 sqlite3ExprCodeCopy(pParse, pIdx->aColExpr->a[i].pExpr, regIdx+i);
108972 pParse->ckBase = 0;
108973 VdbeComment((v, "%s column %d", pIdx->zName, i));
108974 }else{
108975 if( iField==XN_ROWID || iField==pTab->iPKey ){
 
108976 x = regNewData;
 
108977 }else{
108978 x = iField + regNewData + 1;
108979 }
108980 sqlite3VdbeAddOp2(v, iField<0 ? OP_IntCopy : OP_SCopy, x, regIdx+i);
108981 VdbeComment((v, "%s", iField<0 ? "rowid" : pTab->aCol[iField].zName));
108982 }
108983 }
108984 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
108985 VdbeComment((v, "for %s", pIdx->zName));
 
108986
108987 /* In an UPDATE operation, if this index is the PRIMARY KEY index
108988 ** of a WITHOUT ROWID table and there has been no change the
108989 ** primary key, then no collision is possible. The collision detection
108990 ** logic below can all be skipped. */
@@ -108948,19 +108994,24 @@
108994 }
108995
108996 /* Find out what action to take in case there is a uniqueness conflict */
108997 onError = pIdx->onError;
108998 if( onError==OE_None ){
 
108999 sqlite3VdbeResolveLabel(v, addrUniqueOk);
109000 continue; /* pIdx is not a UNIQUE index */
109001 }
109002 if( overrideError!=OE_Default ){
109003 onError = overrideError;
109004 }else if( onError==OE_Default ){
109005 onError = OE_Abort;
109006 }
109007
109008 if( ix==0 && pPk==pIdx && onError==OE_Replace && pPk->pNext==0 ){
109009 sqlite3VdbeResolveLabel(v, addrUniqueOk);
109010 continue;
109011 }
109012
109013
109014 /* Check to see if the new index entry will be unique */
109015 sqlite3VdbeAddOp4Int(v, OP_NoConflict, iThisCur, addrUniqueOk,
109016 regIdx, pIdx->nKeyCol); VdbeCoverage(v);
109017
@@ -109047,11 +109098,10 @@
109098 seenReplace = 1;
109099 break;
109100 }
109101 }
109102 sqlite3VdbeResolveLabel(v, addrUniqueOk);
 
109103 if( regR!=regIdx ) sqlite3ReleaseTempRange(pParse, regR, nPkField);
109104 }
109105 if( ipkTop ){
109106 sqlite3VdbeGoto(v, ipkTop+1);
109107 sqlite3VdbeJumpHere(v, ipkBottom);
@@ -109097,11 +109147,13 @@
109147 bAffinityDone = 1;
109148 if( pIdx->pPartIdxWhere ){
109149 sqlite3VdbeAddOp2(v, OP_IsNull, aRegIdx[i], sqlite3VdbeCurrentAddr(v)+2);
109150 VdbeCoverage(v);
109151 }
109152 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iIdxCur+i, aRegIdx[i],
109153 aRegIdx[i]+1,
109154 pIdx->uniqNotNull ? pIdx->nKeyCol: pIdx->nColumn);
109155 pik_flags = 0;
109156 if( useSeekResult ) pik_flags = OPFLAG_USESEEKRESULT;
109157 if( IsPrimaryKeyIndex(pIdx) && !HasRowid(pTab) ){
109158 assert( pParse->nested==0 );
109159 pik_flags |= OPFLAG_NCHANGE;
@@ -109110,12 +109162,14 @@
109162 }
109163 if( !HasRowid(pTab) ) return;
109164 regData = regNewData + 1;
109165 regRec = sqlite3GetTempReg(pParse);
109166 sqlite3VdbeAddOp3(v, OP_MakeRecord, regData, pTab->nCol, regRec);
109167 if( !bAffinityDone ){
109168 sqlite3TableAffinity(v, pTab, 0);
109169 sqlite3ExprCacheAffinityChange(pParse, regData, pTab->nCol);
109170 }
109171 if( pParse->nested ){
109172 pik_flags = 0;
109173 }else{
109174 pik_flags = OPFLAG_NCHANGE;
109175 pik_flags |= (isUpdate?OPFLAG_ISUPDATE:OPFLAG_LASTROWID);
@@ -109509,10 +109563,11 @@
109563 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iDest, 0); VdbeCoverage(v);
109564 emptyDestTest = sqlite3VdbeAddOp0(v, OP_Goto);
109565 sqlite3VdbeJumpHere(v, addr1);
109566 }
109567 if( HasRowid(pSrc) ){
109568 u8 insFlags;
109569 sqlite3OpenTable(pParse, iSrc, iDbSrc, pSrc, OP_OpenRead);
109570 emptySrcTest = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
109571 if( pDest->iPKey>=0 ){
109572 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
109573 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
@@ -109525,13 +109580,20 @@
109580 }else{
109581 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
109582 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
109583 }
109584 sqlite3VdbeAddOp2(v, OP_RowData, iSrc, regData);
109585 if( db->flags & SQLITE_Vacuum ){
109586 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
109587 insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
109588 OPFLAG_APPEND|OPFLAG_USESEEKRESULT;
109589 }else{
109590 insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND;
109591 }
109592 sqlite3VdbeAddOp4(v, OP_Insert, iDest, regData, regRowid,
109593 (char*)pDest, P4_TABLE);
109594 sqlite3VdbeChangeP5(v, insFlags);
109595 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1); VdbeCoverage(v);
109596 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
109597 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
109598 }else{
109599 sqlite3TableLock(pParse, iDbDest, pDest->tnum, 1, pDest->zName);
@@ -109579,12 +109641,12 @@
109641 }
109642 }
109643 if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
109644 idxInsFlags |= OPFLAG_NCHANGE;
109645 }
109646 sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
109647 sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
109648 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
109649 sqlite3VdbeJumpHere(v, addr1);
109650 sqlite3VdbeAddOp2(v, OP_Close, iSrc, 0);
109651 sqlite3VdbeAddOp2(v, OP_Close, iDest, 0);
109652 }
@@ -114945,11 +115007,11 @@
115007 int nOBSat = pSort->nOBSat; /* ORDER BY terms to skip */
115008 int op; /* Opcode to add sorter record to sorter */
115009 int iLimit; /* LIMIT counter */
115010
115011 assert( bSeq==0 || bSeq==1 );
115012 assert( nData==1 || regData==regOrigData || regOrigData==0 );
115013 if( nPrefixReg ){
115014 assert( nPrefixReg==nExpr+bSeq );
115015 regBase = regData - nExpr - bSeq;
115016 }else{
115017 regBase = pParse->nMem + 1;
@@ -114957,15 +115019,15 @@
115019 }
115020 assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );
115021 iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
115022 pSort->labelDone = sqlite3VdbeMakeLabel(v);
115023 sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,
115024 SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));
115025 if( bSeq ){
115026 sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
115027 }
115028 if( nPrefixReg==0 && nData>0 ){
115029 sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);
115030 }
115031 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord);
115032 if( nOBSat>0 ){
115033 int regPrevKey; /* The first nOBSat columns of the previous row */
@@ -115011,11 +115073,12 @@
115073 if( pSort->sortFlags & SORTFLAG_UseSorter ){
115074 op = OP_SorterInsert;
115075 }else{
115076 op = OP_IdxInsert;
115077 }
115078 sqlite3VdbeAddOp4Int(v, op, pSort->iECursor, regRecord,
115079 regBase+nOBSat, nBase-nOBSat);
115080 if( iLimit ){
115081 int addr;
115082 int r1 = 0;
115083 /* Fill the sorter until it contains LIMIT+OFFSET entries. (The iLimit
115084 ** register is initialized with value of LIMIT+OFFSET.) After the sorter
@@ -115079,11 +115142,11 @@
115142
115143 v = pParse->pVdbe;
115144 r1 = sqlite3GetTempReg(pParse);
115145 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);
115146 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);
115147 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N);
115148 sqlite3ReleaseTempReg(pParse, r1);
115149 }
115150
115151 /*
115152 ** This routine generates the code for the inside of the inner loop
@@ -115090,11 +115153,11 @@
115153 ** of a SELECT.
115154 **
115155 ** If srcTab is negative, then the pEList expressions
115156 ** are evaluated in order to get the data for this row. If srcTab is
115157 ** zero or more, then data is pulled from srcTab and pEList is used only
115158 ** to get the number of columns and the collation sequence for each column.
115159 */
115160 static void selectInnerLoop(
115161 Parse *pParse, /* The parser context */
115162 Select *p, /* The complete select statement being coded */
115163 ExprList *pEList, /* List of values being extracted */
@@ -115105,17 +115168,24 @@
115168 int iContinue, /* Jump here to continue with next row */
115169 int iBreak /* Jump here to break out of the inner loop */
115170 ){
115171 Vdbe *v = pParse->pVdbe;
115172 int i;
115173 int hasDistinct; /* True if the DISTINCT keyword is present */
 
115174 int eDest = pDest->eDest; /* How to dispose of results */
115175 int iParm = pDest->iSDParm; /* First argument to disposal method */
115176 int nResultCol; /* Number of result columns */
115177 int nPrefixReg = 0; /* Number of extra registers before regResult */
115178
115179 /* Usually, regResult is the first cell in an array of memory cells
115180 ** containing the current result row. In this case regOrig is set to the
115181 ** same value. However, if the results are being sent to the sorter, the
115182 ** values for any expressions that are also part of the sort-key are omitted
115183 ** from this array. In this case regOrig is set to zero. */
115184 int regResult; /* Start of memory holding current results */
115185 int regOrig; /* Start of memory holding full result (or 0) */
115186
115187 assert( v );
115188 assert( pEList!=0 );
115189 hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
115190 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
115191 if( pSort==0 && !hasDistinct ){
@@ -115142,11 +115212,11 @@
115212 ** and reported later. But we need to make sure enough memory is allocated
115213 ** to avoid other spurious errors in the meantime. */
115214 pParse->nMem += nResultCol;
115215 }
115216 pDest->nSdst = nResultCol;
115217 regOrig = regResult = pDest->iSdst;
115218 if( srcTab>=0 ){
115219 for(i=0; i<nResultCol; i++){
115220 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
115221 VdbeComment((v, "%s", pEList->a[i].zName));
115222 }
@@ -115158,11 +115228,30 @@
115228 if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
115229 ecelFlags = SQLITE_ECEL_DUP;
115230 }else{
115231 ecelFlags = 0;
115232 }
115233 assert( eDest!=SRT_Table || pSort==0 );
115234 if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab ){
115235 /* For each expression in pEList that is a copy of an expression in
115236 ** the ORDER BY clause (pSort->pOrderBy), set the associated
115237 ** iOrderByCol value to one more than the index of the ORDER BY
115238 ** expression within the sort-key that pushOntoSorter() will generate.
115239 ** This allows the pEList field to be omitted from the sorted record,
115240 ** saving space and CPU cycles. */
115241 ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF);
115242 for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){
115243 int j;
115244 if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
115245 pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
115246 }
115247 }
115248 regOrig = 0;
115249 assert( eDest==SRT_Set || eDest==SRT_Mem
115250 || eDest==SRT_Coroutine || eDest==SRT_Output );
115251 }
115252 nResultCol = sqlite3ExprCodeExprList(pParse,pEList,regResult,0,ecelFlags);
115253 }
115254
115255 /* If the DISTINCT keyword was present on the SELECT statement
115256 ** and this row has been seen before, then do not make this row
115257 ** part of the result.
@@ -115232,11 +115321,11 @@
115321 #ifndef SQLITE_OMIT_COMPOUND_SELECT
115322 case SRT_Union: {
115323 int r1;
115324 r1 = sqlite3GetTempReg(pParse);
115325 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
115326 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
115327 sqlite3ReleaseTempReg(pParse, r1);
115328 break;
115329 }
115330
115331 /* Construct a record from the query result, but instead of
@@ -115269,11 +115358,11 @@
115358 ** current row to the index and proceed with writing it to the
115359 ** output table as well. */
115360 int addr = sqlite3VdbeCurrentAddr(v) + 4;
115361 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);
115362 VdbeCoverage(v);
115363 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm+1, r1,regResult,nResultCol);
115364 assert( pSort==0 );
115365 }
115366 #endif
115367 if( pSort ){
115368 pushOntoSorter(pParse, pSort, p, r1+nPrefixReg,regResult,1,nPrefixReg);
@@ -115298,18 +115387,18 @@
115387 /* At first glance you would think we could optimize out the
115388 ** ORDER BY in this case since the order of entries in the set
115389 ** does not matter. But there might be a LIMIT clause, in which
115390 ** case the order does matter */
115391 pushOntoSorter(
115392 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
115393 }else{
115394 int r1 = sqlite3GetTempReg(pParse);
115395 assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
115396 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
115397 r1, pDest->zAffSdst, nResultCol);
115398 sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
115399 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
115400 sqlite3ReleaseTempReg(pParse, r1);
115401 }
115402 break;
115403 }
115404
@@ -115324,15 +115413,16 @@
115413 /* If this is a scalar select that is part of an expression, then
115414 ** store the results in the appropriate memory cell or array of
115415 ** memory cells and break out of the scan loop.
115416 */
115417 case SRT_Mem: {
 
115418 if( pSort ){
115419 assert( nResultCol<=pDest->nSdst );
115420 pushOntoSorter(
115421 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
115422 }else{
115423 assert( nResultCol==pDest->nSdst );
115424 assert( regResult==iParm );
115425 /* The LIMIT clause will jump out of the loop for us */
115426 }
115427 break;
115428 }
@@ -115341,11 +115431,11 @@
115431 case SRT_Coroutine: /* Send data to a co-routine */
115432 case SRT_Output: { /* Return the results */
115433 testcase( eDest==SRT_Coroutine );
115434 testcase( eDest==SRT_Output );
115435 if( pSort ){
115436 pushOntoSorter(pParse, pSort, p, regResult, regOrig, nResultCol,
115437 nPrefixReg);
115438 }else if( eDest==SRT_Coroutine ){
115439 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
115440 }else{
115441 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
@@ -115391,11 +115481,11 @@
115481 regResult + pSO->a[i].u.x.iOrderByCol - 1,
115482 r2+i);
115483 }
115484 sqlite3VdbeAddOp2(v, OP_Sequence, iParm, r2+nKey);
115485 sqlite3VdbeAddOp3(v, OP_MakeRecord, r2, nKey+2, r1);
115486 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, r2, nKey+2);
115487 if( addrTest ) sqlite3VdbeJumpHere(v, addrTest);
115488 sqlite3ReleaseTempReg(pParse, r1);
115489 sqlite3ReleaseTempRange(pParse, r2, nKey+2);
115490 break;
115491 }
@@ -115626,18 +115716,17 @@
115716 ExprList *pOrderBy = pSort->pOrderBy;
115717 int eDest = pDest->eDest;
115718 int iParm = pDest->iSDParm;
115719 int regRow;
115720 int regRowid;
115721 int iCol;
115722 int nKey;
115723 int iSortTab; /* Sorter cursor to read from */
115724 int nSortData; /* Trailing values to read from sorter */
115725 int i;
115726 int bSeq; /* True if sorter record includes seq. no. */
 
115727 struct ExprList_item *aOutEx = p->pEList->a;
 
115728
115729 assert( addrBreak<0 );
115730 if( pSort->labelBkOut ){
115731 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
115732 sqlite3VdbeGoto(v, addrBreak);
@@ -115671,12 +115760,18 @@
115760 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
115761 codeOffset(v, p->iOffset, addrContinue);
115762 iSortTab = iTab;
115763 bSeq = 1;
115764 }
115765 for(i=0, iCol=nKey+bSeq; i<nSortData; i++){
115766 int iRead;
115767 if( aOutEx[i].u.x.iOrderByCol ){
115768 iRead = aOutEx[i].u.x.iOrderByCol-1;
115769 }else{
115770 iRead = iCol++;
115771 }
115772 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
115773 VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
115774 }
115775 switch( eDest ){
115776 case SRT_EphemTab: {
115777 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
@@ -115688,11 +115783,11 @@
115783 case SRT_Set: {
115784 assert( nColumn==sqlite3Strlen30(pDest->zAffSdst) );
115785 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, nColumn, regRowid,
115786 pDest->zAffSdst, nColumn);
115787 sqlite3ExprCacheAffinityChange(pParse, regRow, nColumn);
115788 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, regRowid, regRow, nColumn);
115789 break;
115790 }
115791 case SRT_Mem: {
115792 /* The LIMIT clause will terminate the loop for us */
115793 break;
@@ -117064,11 +117159,12 @@
117159 testcase( pIn->nSdst>1 );
117160 r1 = sqlite3GetTempReg(pParse);
117161 sqlite3VdbeAddOp4(v, OP_MakeRecord, pIn->iSdst, pIn->nSdst,
117162 r1, pDest->zAffSdst, pIn->nSdst);
117163 sqlite3ExprCacheAffinityChange(pParse, pIn->iSdst, pIn->nSdst);
117164 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
117165 pIn->iSdst, pIn->nSdst);
117166 sqlite3ReleaseTempReg(pParse, r1);
117167 break;
117168 }
117169
117170 /* If this is a scalar select that is part of an expression, then
@@ -121687,16 +121783,18 @@
121783 */
121784 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
121785 int reg;
121786 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
121787 reg = ++pParse->nMem;
121788 pParse->nMem += pIdx->nColumn;
121789 }else{
121790 reg = 0;
121791 for(i=0; i<pIdx->nKeyCol; i++){
121792 i16 iIdxCol = pIdx->aiColumn[i];
121793 if( iIdxCol<0 || aXRef[iIdxCol]>=0 ){
121794 reg = ++pParse->nMem;
121795 pParse->nMem += pIdx->nColumn;
121796 break;
121797 }
121798 }
121799 }
121800 if( reg==0 ) aToOpen[j+1] = 0;
@@ -121803,11 +121901,11 @@
121901 nKey = nPk;
121902 regKey = iPk;
121903 }else{
121904 sqlite3VdbeAddOp4(v, OP_MakeRecord, iPk, nPk, regKey,
121905 sqlite3IndexAffinityStr(db, pPk), nPk);
121906 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iEph, regKey, iPk, nPk);
121907 }
121908 sqlite3WhereEnd(pWInfo);
121909 }
121910
121911 /* Initialize the count of updated rows
@@ -122062,19 +122160,10 @@
122160 }else{
122161 sqlite3VdbeGoto(v, labelContinue);
122162 }
122163 sqlite3VdbeResolveLabel(v, labelBreak);
122164
 
 
 
 
 
 
 
 
 
122165 /* Update the sqlite_sequence table by storing the content of the
122166 ** maximum rowid counter values recorded while inserting into
122167 ** autoincrement tables.
122168 */
122169 if( pParse->nested==0 && pParse->pTriggerTab==0 ){
@@ -124822,10 +124911,11 @@
124911 if( (pX->flags & EP_xIsSelect)==0 || pX->x.pSelect->pEList->nExpr==1 ){
124912 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, 0);
124913 }else{
124914 Select *pSelect = pX->x.pSelect;
124915 sqlite3 *db = pParse->db;
124916 u16 savedDbOptFlags = db->dbOptFlags;
124917 ExprList *pOrigRhs = pSelect->pEList;
124918 ExprList *pOrigLhs = pX->pLeft->x.pList;
124919 ExprList *pRhs = 0; /* New Select.pEList for RHS */
124920 ExprList *pLhs = 0; /* New pX->pLeft vector */
124921
@@ -124865,11 +124955,13 @@
124955 pLeft->x.pList = pLhs;
124956 aiMap = (int*)sqlite3DbMallocZero(pParse->db, sizeof(int) * nEq);
124957 testcase( aiMap==0 );
124958 }
124959 pSelect->pEList = pRhs;
124960 db->dbOptFlags |= SQLITE_QueryFlattener;
124961 eType = sqlite3FindInIndex(pParse, pX, IN_INDEX_LOOP, 0, aiMap);
124962 db->dbOptFlags = savedDbOptFlags;
124963 testcase( aiMap!=0 && aiMap[0]!=0 );
124964 pSelect->pEList = pOrigRhs;
124965 pLeft->x.pList = pOrigLhs;
124966 pX->pLeft = pLeft;
124967 }
@@ -126220,11 +126312,12 @@
126312 jmp1 = sqlite3VdbeAddOp4Int(v, OP_Found, regRowset, 0, r, nPk);
126313 VdbeCoverage(v);
126314 }
126315 if( iSet>=0 ){
126316 sqlite3VdbeAddOp3(v, OP_MakeRecord, r, nPk, regRowid);
126317 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, regRowset, regRowid,
126318 r, nPk);
126319 if( iSet ) sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
126320 }
126321
126322 /* Release the array of temp registers */
126323 sqlite3ReleaseTempRange(pParse, r, nPk);
@@ -127684,10 +127777,12 @@
127777 #endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */
127778
127779 /* Prevent ON clause terms of a LEFT JOIN from being used to drive
127780 ** an index for tables to the left of the join.
127781 */
127782 testcase( pTerm!=&pWC->a[idxTerm] );
127783 pTerm = &pWC->a[idxTerm];
127784 pTerm->prereqRight |= extraRight;
127785 }
127786
127787 /***************************************************************************
127788 ** Routines with file scope above. Interface to the rest of the where.c
@@ -132767,31 +132862,10 @@
132862 translateColumnToCopy(v, pLevel->addrBody, pLevel->iTabCur,
132863 pTabItem->regResult, 0);
132864 continue;
132865 }
132866
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132867 /* If this scan uses an index, make VDBE code substitutions to read data
132868 ** from the index instead of from the table where possible. In some cases
132869 ** this optimization prevents the table from ever being read, which can
132870 ** yield a significant performance boost.
132871 **
@@ -165455,24 +165529,24 @@
165529 int nArg; /* Number of arguments */
165530 int enc; /* Optimal text encoding */
165531 void *pContext; /* sqlite3_user_data() context */
165532 void (*xFunc)(sqlite3_context*,int,sqlite3_value**);
165533 } scalars[] = {
165534 {"regexp", 2, SQLITE_ANY|SQLITE_DETERMINISTIC, 0, icuRegexpFunc},
165535
165536 {"lower", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
165537 {"lower", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
165538 {"upper", 1, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
165539 {"upper", 2, SQLITE_UTF16|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
165540
165541 {"lower", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
165542 {"lower", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuCaseFunc16},
165543 {"upper", 1, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
165544 {"upper", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, (void*)1, icuCaseFunc16},
165545
165546 {"like", 2, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
165547 {"like", 3, SQLITE_UTF8|SQLITE_DETERMINISTIC, 0, icuLikeFunc},
165548
165549 {"icu_load_collation", 2, SQLITE_UTF8, (void*)db, icuLoadCollation},
165550 };
165551
165552 int rc = SQLITE_OK;
@@ -176486,17 +176560,19 @@
176560 ** to pass signed char values.
176561 */
176562 #ifdef sqlite3Isdigit
176563 /* Use the SQLite core versions if this routine is part of the
176564 ** SQLite amalgamation */
176565 # define safe_isdigit(x) sqlite3Isdigit(x)
176566 # define safe_isalnum(x) sqlite3Isalnum(x)
176567 # define safe_isxdigit(x) sqlite3Isxdigit(x)
176568 #else
176569 /* Use the standard library for separate compilation */
176570 #include <ctype.h> /* amalgamator: keep */
176571 # define safe_isdigit(x) isdigit((unsigned char)(x))
176572 # define safe_isalnum(x) isalnum((unsigned char)(x))
176573 # define safe_isxdigit(x) isxdigit((unsigned char)(x))
176574 #endif
176575
176576 /*
176577 ** Growing our own isspace() routine this way is twice as fast as
176578 ** the library isspace() function, resulting in a 7% overall performance
@@ -177030,16 +177106,17 @@
177106 zOut[j++] = c;
177107 }else{
177108 c = z[++i];
177109 if( c=='u' ){
177110 u32 v = 0, k;
177111 for(k=0; k<4; i++, k++){
177112 assert( i<n-2 );
177113 c = z[i+1];
177114 assert( safe_isxdigit(c) );
177115 if( c<='9' ) v = v*16 + c - '0';
177116 else if( c<='F' ) v = v*16 + c - 'A' + 10;
177117 else v = v*16 + c - 'a' + 10;
177118 }
177119 if( v==0 ) break;
177120 if( v<=0x7f ){
177121 zOut[j++] = (char)v;
177122 }else if( v<=0x7ff ){
@@ -177138,10 +177215,19 @@
177215 p->iVal = 0;
177216 p->n = n;
177217 p->u.zJContent = zContent;
177218 return pParse->nNode++;
177219 }
177220
177221 /*
177222 ** Return true if z[] begins with 4 (or more) hexadecimal digits
177223 */
177224 static int jsonIs4Hex(const char *z){
177225 int i;
177226 for(i=0; i<4; i++) if( !safe_isxdigit(z[i]) ) return 0;
177227 return 1;
177228 }
177229
177230 /*
177231 ** Parse a single JSON value which begins at pParse->zJson[i]. Return the
177232 ** index of the first character past the end of the value parsed.
177233 **
@@ -177213,12 +177299,17 @@
177299 for(;;){
177300 c = pParse->zJson[j];
177301 if( c==0 ) return -1;
177302 if( c=='\\' ){
177303 c = pParse->zJson[++j];
177304 if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
177305 || c=='n' || c=='r' || c=='t'
177306 || (c=='u' && jsonIs4Hex(pParse->zJson+j+1)) ){
177307 jnFlags = JNODE_ESCAPE;
177308 }else{
177309 return -1;
177310 }
177311 }else if( c=='"' ){
177312 break;
177313 }
177314 j++;
177315 }
@@ -178082,11 +178173,11 @@
178173 JsonString *pStr;
178174 pStr = (JsonString*)sqlite3_aggregate_context(ctx, 0);
178175 if( pStr ){
178176 jsonAppendChar(pStr, '}');
178177 if( pStr->bErr ){
178178 if( pStr->bErr==1 ) sqlite3_result_error_nomem(ctx);
178179 assert( pStr->bStatic );
178180 }else{
178181 sqlite3_result_text(ctx, pStr->zBuf, pStr->nUsed,
178182 pStr->bStatic ? SQLITE_TRANSIENT : sqlite3_free);
178183 pStr->bStatic = 1;
@@ -178360,13 +178451,13 @@
178451 break;
178452 }
178453 /* For json_each() path and root are the same so fall through
178454 ** into the root case */
178455 }
178456 default: {
178457 const char *zRoot = p->zRoot;
178458 if( zRoot==0 ) zRoot = "$";
178459 sqlite3_result_text(ctx, zRoot, -1, SQLITE_STATIC);
178460 break;
178461 }
178462 case JEACH_JSON: {
178463 assert( i==JEACH_JSON );
@@ -184289,11 +184380,11 @@
184380 pNode->bEof = 1;
184381 return rc;
184382 }
184383 }else{
184384 Fts5IndexIter *pIter = pPhrase->aTerm[j].pIter;
184385 if( pIter->iRowid==iLast || pIter->bEof ) continue;
184386 bMatch = 0;
184387 if( fts5ExprAdvanceto(pIter, bDesc, &iLast, &rc, &pNode->bEof) ){
184388 return rc;
184389 }
184390 }
@@ -189429,10 +189520,11 @@
189520 Fts5Iter *pIter,
189521 int bFrom, /* True if argument iFrom is valid */
189522 i64 iFrom /* Advance at least as far as this */
189523 ){
189524 int bUseFrom = bFrom;
189525 assert( pIter->base.bEof==0 );
189526 while( p->rc==SQLITE_OK ){
189527 int iFirst = pIter->aFirst[1].iFirst;
189528 int bNewTerm = 0;
189529 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
189530 assert( p->rc==SQLITE_OK );
@@ -195693,11 +195785,11 @@
195785 int nArg, /* Number of args */
195786 sqlite3_value **apUnused /* Function arguments */
195787 ){
195788 assert( nArg==0 );
195789 UNUSED_PARAM2(nArg, apUnused);
195790 sqlite3_result_text(pCtx, "fts5: 2016-11-19 18:31:37 28393c413cc4505b94411730e728583c5d4baaae", -1, SQLITE_TRANSIENT);
195791 }
195792
195793 static int fts5Init(sqlite3 *db){
195794 static const sqlite3_module fts5Mod = {
195795 /* iVersion */ 2,
195796
+9 -7
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,15 +121,15 @@
121121
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122122
** [sqlite_version()] and [sqlite_source_id()].
123123
*/
124124
#define SQLITE_VERSION "3.16.0"
125125
#define SQLITE_VERSION_NUMBER 3016000
126
-#define SQLITE_SOURCE_ID "2016-11-02 14:50:19 3028845329c9b7acdec2ec8b01d00d782347454c"
126
+#define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9"
127127
128128
/*
129129
** CAPI3REF: Run-Time Library Version Numbers
130
-** KEYWORDS: sqlite3_version, sqlite3_sourceid
130
+** KEYWORDS: sqlite3_version sqlite3_sourceid
131131
**
132132
** These interfaces provide the same information as the [SQLITE_VERSION],
133133
** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
134134
** but are associated with the library instead of the header file. ^(Cautious
135135
** programmers might include assert() statements in their application to
@@ -8223,11 +8223,12 @@
82238223
** triggers; or 2 for changes resulting from triggers called by top-level
82248224
** triggers; and so forth.
82258225
**
82268226
** See also: [sqlite3_update_hook()]
82278227
*/
8228
-SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_preupdate_hook(
8228
+#if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
8229
+SQLITE_API void *sqlite3_preupdate_hook(
82298230
sqlite3 *db,
82308231
void(*xPreUpdate)(
82318232
void *pCtx, /* Copy of third arg to preupdate_hook() */
82328233
sqlite3 *db, /* Database handle */
82338234
int op, /* SQLITE_UPDATE, DELETE or INSERT */
@@ -8236,14 +8237,15 @@
82368237
sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
82378238
sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
82388239
),
82398240
void*
82408241
);
8241
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8242
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_count(sqlite3 *);
8243
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_depth(sqlite3 *);
8244
-SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
8242
+SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8243
+SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
8244
+SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
8245
+SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
8246
+#endif
82458247
82468248
/*
82478249
** CAPI3REF: Low-level system error code
82488250
**
82498251
** ^Attempt to return the underlying operating system error code or error
82508252
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,15 +121,15 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.0"
125 #define SQLITE_VERSION_NUMBER 3016000
126 #define SQLITE_SOURCE_ID "2016-11-02 14:50:19 3028845329c9b7acdec2ec8b01d00d782347454c"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
131 **
132 ** These interfaces provide the same information as the [SQLITE_VERSION],
133 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
134 ** but are associated with the library instead of the header file. ^(Cautious
135 ** programmers might include assert() statements in their application to
@@ -8223,11 +8223,12 @@
8223 ** triggers; or 2 for changes resulting from triggers called by top-level
8224 ** triggers; and so forth.
8225 **
8226 ** See also: [sqlite3_update_hook()]
8227 */
8228 SQLITE_API SQLITE_EXPERIMENTAL void *sqlite3_preupdate_hook(
 
8229 sqlite3 *db,
8230 void(*xPreUpdate)(
8231 void *pCtx, /* Copy of third arg to preupdate_hook() */
8232 sqlite3 *db, /* Database handle */
8233 int op, /* SQLITE_UPDATE, DELETE or INSERT */
@@ -8236,14 +8237,15 @@
8236 sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
8237 sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
8238 ),
8239 void*
8240 );
8241 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8242 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_count(sqlite3 *);
8243 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_depth(sqlite3 *);
8244 SQLITE_API SQLITE_EXPERIMENTAL int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
 
8245
8246 /*
8247 ** CAPI3REF: Low-level system error code
8248 **
8249 ** ^Attempt to return the underlying operating system error code or error
8250
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,15 +121,15 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.0"
125 #define SQLITE_VERSION_NUMBER 3016000
126 #define SQLITE_SOURCE_ID "2016-11-22 20:29:05 bee2859b953c935c413de2917588159d03c672d9"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
132 ** These interfaces provide the same information as the [SQLITE_VERSION],
133 ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
134 ** but are associated with the library instead of the header file. ^(Cautious
135 ** programmers might include assert() statements in their application to
@@ -8223,11 +8223,12 @@
8223 ** triggers; or 2 for changes resulting from triggers called by top-level
8224 ** triggers; and so forth.
8225 **
8226 ** See also: [sqlite3_update_hook()]
8227 */
8228 #if defined(SQLITE_ENABLE_PREUPDATE_HOOK)
8229 SQLITE_API void *sqlite3_preupdate_hook(
8230 sqlite3 *db,
8231 void(*xPreUpdate)(
8232 void *pCtx, /* Copy of third arg to preupdate_hook() */
8233 sqlite3 *db, /* Database handle */
8234 int op, /* SQLITE_UPDATE, DELETE or INSERT */
@@ -8236,14 +8237,15 @@
8237 sqlite3_int64 iKey1, /* Rowid of row about to be deleted/updated */
8238 sqlite3_int64 iKey2 /* New rowid value (for a rowid UPDATE) */
8239 ),
8240 void*
8241 );
8242 SQLITE_API int sqlite3_preupdate_old(sqlite3 *, int, sqlite3_value **);
8243 SQLITE_API int sqlite3_preupdate_count(sqlite3 *);
8244 SQLITE_API int sqlite3_preupdate_depth(sqlite3 *);
8245 SQLITE_API int sqlite3_preupdate_new(sqlite3 *, int, sqlite3_value **);
8246 #endif
8247
8248 /*
8249 ** CAPI3REF: Low-level system error code
8250 **
8251 ** ^Attempt to return the underlying operating system error code or error
8252

Keyboard Shortcuts

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